@sponsio/sdk 0.1.0 → 0.2.0-alpha.10

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 (123) hide show
  1. package/contracts/benchmark/agentdojo.yaml +551 -0
  2. package/contracts/benchmark/odcv_bench.yaml +393 -0
  3. package/contracts/benchmark/redcode_exec.yaml +488 -0
  4. package/contracts/benchmark/swebench.yaml +176 -0
  5. package/contracts/benchmark/tau2_bench.yaml +984 -0
  6. package/contracts/capability/destructive.yaml +213 -0
  7. package/contracts/capability/factual-claims.yaml +79 -0
  8. package/contracts/capability/host-config-integrity.yaml +42 -9
  9. package/contracts/capability/self-modify.yaml +58 -12
  10. package/contracts/capability/shell.yaml +19 -10
  11. package/contracts/incident/claude-code-secret-bypass.yaml +48 -16
  12. package/contracts/incident/cursor-railway-wipe.yaml +60 -4
  13. package/contracts/incident/openclaw.yaml +9 -62
  14. package/contracts/premium/.gitkeep +5 -6
  15. package/dist/cli/cli.js +32 -0
  16. package/dist/cli/cli.js.map +1 -1
  17. package/dist/cli/packs.d.ts.map +1 -1
  18. package/dist/cli/packs.js +14 -8
  19. package/dist/cli/packs.js.map +1 -1
  20. package/dist/cli/patterns.d.ts +5 -4
  21. package/dist/cli/patterns.d.ts.map +1 -1
  22. package/dist/cli/patterns.js +11 -10
  23. package/dist/cli/patterns.js.map +1 -1
  24. package/dist/cli/prompt.js +5 -5
  25. package/dist/cli/prompt.js.map +1 -1
  26. package/dist/cli/scan.js +2 -2
  27. package/dist/cli/skill.d.ts +1 -1
  28. package/dist/cli/skill.js +1 -1
  29. package/dist/cli/validate.js +5 -5
  30. package/dist/cli/validate.js.map +1 -1
  31. package/dist/cloud/client.d.ts +76 -0
  32. package/dist/cloud/client.d.ts.map +1 -0
  33. package/dist/cloud/client.js +204 -0
  34. package/dist/cloud/client.js.map +1 -0
  35. package/dist/cloud/evidence.d.ts +108 -0
  36. package/dist/cloud/evidence.d.ts.map +1 -0
  37. package/dist/cloud/evidence.js +184 -0
  38. package/dist/cloud/evidence.js.map +1 -0
  39. package/dist/cloud/privacy.d.ts +67 -0
  40. package/dist/cloud/privacy.d.ts.map +1 -0
  41. package/dist/cloud/privacy.js +170 -0
  42. package/dist/cloud/privacy.js.map +1 -0
  43. package/dist/cloud/view-model.d.ts +49 -0
  44. package/dist/cloud/view-model.d.ts.map +1 -0
  45. package/dist/cloud/view-model.js +172 -0
  46. package/dist/cloud/view-model.js.map +1 -0
  47. package/dist/core/config-loader.d.ts.map +1 -1
  48. package/dist/core/config-loader.js +81 -9
  49. package/dist/core/config-loader.js.map +1 -1
  50. package/dist/core/evaluator.d.ts +11 -1
  51. package/dist/core/evaluator.d.ts.map +1 -1
  52. package/dist/core/evaluator.js +275 -13
  53. package/dist/core/evaluator.js.map +1 -1
  54. package/dist/core/formula.d.ts +76 -17
  55. package/dist/core/formula.d.ts.map +1 -1
  56. package/dist/core/formula.js +95 -1
  57. package/dist/core/formula.js.map +1 -1
  58. package/dist/core/grounding.d.ts +44 -8
  59. package/dist/core/grounding.d.ts.map +1 -1
  60. package/dist/core/grounding.js +208 -26
  61. package/dist/core/grounding.js.map +1 -1
  62. package/dist/core/nl-parser.d.ts +2 -2
  63. package/dist/core/nl-parser.d.ts.map +1 -1
  64. package/dist/core/nl-parser.js +617 -41
  65. package/dist/core/nl-parser.js.map +1 -1
  66. package/dist/core/pack-loader.d.ts.map +1 -1
  67. package/dist/core/pack-loader.js +14 -2
  68. package/dist/core/pack-loader.js.map +1 -1
  69. package/dist/core/parser.d.ts.map +1 -1
  70. package/dist/core/parser.js +30 -1
  71. package/dist/core/parser.js.map +1 -1
  72. package/dist/core/pattern-factory.d.ts.map +1 -1
  73. package/dist/core/pattern-factory.js +14 -1
  74. package/dist/core/pattern-factory.js.map +1 -1
  75. package/dist/core/patterns.d.ts +118 -1
  76. package/dist/core/patterns.d.ts.map +1 -1
  77. package/dist/core/patterns.js +189 -10
  78. package/dist/core/patterns.js.map +1 -1
  79. package/dist/core/session-log.d.ts.map +1 -1
  80. package/dist/core/session-log.js +20 -1
  81. package/dist/core/session-log.js.map +1 -1
  82. package/dist/core/sto.d.ts +21 -27
  83. package/dist/core/sto.d.ts.map +1 -1
  84. package/dist/core/sto.js +30 -33
  85. package/dist/core/sto.js.map +1 -1
  86. package/dist/core/tool-names.d.ts +59 -0
  87. package/dist/core/tool-names.d.ts.map +1 -0
  88. package/dist/core/tool-names.js +128 -0
  89. package/dist/core/tool-names.js.map +1 -0
  90. package/dist/index.d.ts +181 -32
  91. package/dist/index.d.ts.map +1 -1
  92. package/dist/index.js +415 -67
  93. package/dist/index.js.map +1 -1
  94. package/dist/integrations/claude-agent.d.ts +5 -0
  95. package/dist/integrations/claude-agent.d.ts.map +1 -1
  96. package/dist/integrations/claude-agent.js +42 -13
  97. package/dist/integrations/claude-agent.js.map +1 -1
  98. package/dist/integrations/google-adk.d.ts +5 -3
  99. package/dist/integrations/google-adk.d.ts.map +1 -1
  100. package/dist/integrations/google-adk.js +9 -5
  101. package/dist/integrations/google-adk.js.map +1 -1
  102. package/dist/integrations/langchain.d.ts +7 -0
  103. package/dist/integrations/langchain.d.ts.map +1 -1
  104. package/dist/integrations/langchain.js +21 -3
  105. package/dist/integrations/langchain.js.map +1 -1
  106. package/dist/integrations/openai-agents.d.ts +22 -10
  107. package/dist/integrations/openai-agents.d.ts.map +1 -1
  108. package/dist/integrations/openai-agents.js +55 -15
  109. package/dist/integrations/openai-agents.js.map +1 -1
  110. package/dist/integrations/openai.d.ts +11 -0
  111. package/dist/integrations/openai.d.ts.map +1 -1
  112. package/dist/integrations/openai.js +130 -48
  113. package/dist/integrations/openai.js.map +1 -1
  114. package/dist/integrations/vercel-ai.d.ts +20 -9
  115. package/dist/integrations/vercel-ai.d.ts.map +1 -1
  116. package/dist/integrations/vercel-ai.js +131 -32
  117. package/dist/integrations/vercel-ai.js.map +1 -1
  118. package/package.json +17 -9
  119. package/prompts/onboard.md +26 -17
  120. package/prompts/scan.md +3 -5
  121. package/skills/SKILL.md +13 -83
  122. package/contracts/core/llm_safety.yaml +0 -140
  123. package/prompts/refresh.md +0 -118
@@ -4,7 +4,7 @@
4
4
  * Direct port of sponsio/formulas/formula.py.
5
5
  * Three families: Propositional, Temporal (LTL), Arithmetic.
6
6
  */
7
- export type Formula = Atom | Not | And | Or | Implies | G | F | X | U | Le | Lt | Ge | Gt | Eq | Var | Const;
7
+ export type Formula = Atom | Not | And | Or | Implies | G | F | X | U | Le | Lt | Ge | Gt | Eq | Var | Const | ArgValue | CtxValue | UnaryFn | ArgLength;
8
8
  export declare class Atom {
9
9
  readonly predicate: string;
10
10
  readonly args: readonly string[];
@@ -68,36 +68,95 @@ export declare class Const {
68
68
  readonly kind: "Const";
69
69
  constructor(value: number);
70
70
  }
71
- export type ArithExpr = Var | Const;
71
+ /**
72
+ * Read ``args[field]`` from the current event when it is a call to ``tool``.
73
+ *
74
+ * Returns ``undefined`` ("missing" signal) when the current event is a
75
+ * call to a different tool, or not a tool call, or args[field] absent.
76
+ * Pair with ``Implies(called(tool), ...)`` to scope the rule cleanly.
77
+ */
78
+ export declare class ArgValue {
79
+ readonly tool: string;
80
+ readonly field: string;
81
+ readonly kind: "ArgValue";
82
+ constructor(tool: string, field: string);
83
+ }
84
+ /**
85
+ * Read a fact pushed via ``guard.observeContext({ key: value })``.
86
+ *
87
+ * Returns ``undefined`` when the key has never been pushed for this trace.
88
+ */
89
+ export declare class CtxValue {
90
+ readonly key: string;
91
+ readonly kind: "CtxValue";
92
+ constructor(key: string);
93
+ }
94
+ /**
95
+ * Apply a JavaScript callable to another Term's value.
96
+ *
97
+ * Common cases:
98
+ * new UnaryFn(s => String(s).toLowerCase(),
99
+ * new ArgValue("send_email", "subject"))
100
+ *
101
+ * If the inner Term resolves to undefined, UnaryFn also returns undefined.
102
+ * If the callable throws, UnaryFn returns undefined rather than crashing.
103
+ *
104
+ * The ``name`` field is for debug repr only.
105
+ */
106
+ export declare class UnaryFn {
107
+ readonly fn: (v: unknown) => unknown;
108
+ readonly arg: Term;
109
+ readonly name: string;
110
+ readonly kind: "UnaryFn";
111
+ constructor(fn: (v: unknown) => unknown, arg: Term, name?: string);
112
+ }
113
+ /**
114
+ * Convenience: ``args[field].length`` for the current event.
115
+ *
116
+ * Equivalent to ``new UnaryFn(v => (v as { length: number }).length,
117
+ * new ArgValue(tool, field))`` but exposed as its own class for clean
118
+ * repr and faster eval. Returns ``undefined`` when missing or not a
119
+ * .length-bearing value.
120
+ */
121
+ export declare class ArgLength {
122
+ readonly tool: string;
123
+ readonly field: string;
124
+ readonly kind: "ArgLength";
125
+ constructor(tool: string, field: string);
126
+ }
127
+ /** A Term is anything that resolves to a value at evaluation time. */
128
+ export type Term = Var | Const | ArgValue | CtxValue | UnaryFn | ArgLength;
129
+ /** Backward-compatible alias. */
130
+ export type ArithExpr = Term;
72
131
  export declare class Le {
73
- readonly left: ArithExpr;
74
- readonly right: ArithExpr;
132
+ readonly left: Term;
133
+ readonly right: Term;
75
134
  readonly kind: "Le";
76
- constructor(left: ArithExpr, right: ArithExpr);
135
+ constructor(left: Term, right: Term);
77
136
  }
78
137
  export declare class Lt {
79
- readonly left: ArithExpr;
80
- readonly right: ArithExpr;
138
+ readonly left: Term;
139
+ readonly right: Term;
81
140
  readonly kind: "Lt";
82
- constructor(left: ArithExpr, right: ArithExpr);
141
+ constructor(left: Term, right: Term);
83
142
  }
84
143
  export declare class Ge {
85
- readonly left: ArithExpr;
86
- readonly right: ArithExpr;
144
+ readonly left: Term;
145
+ readonly right: Term;
87
146
  readonly kind: "Ge";
88
- constructor(left: ArithExpr, right: ArithExpr);
147
+ constructor(left: Term, right: Term);
89
148
  }
90
149
  export declare class Gt {
91
- readonly left: ArithExpr;
92
- readonly right: ArithExpr;
150
+ readonly left: Term;
151
+ readonly right: Term;
93
152
  readonly kind: "Gt";
94
- constructor(left: ArithExpr, right: ArithExpr);
153
+ constructor(left: Term, right: Term);
95
154
  }
96
155
  export declare class Eq {
97
- readonly left: ArithExpr;
98
- readonly right: ArithExpr;
156
+ readonly left: Term;
157
+ readonly right: Term;
99
158
  readonly kind: "Eq";
100
- constructor(left: ArithExpr, right: ArithExpr);
159
+ constructor(left: Term, right: Term);
101
160
  }
102
161
  export declare function predKey(predicate: string, ...args: string[]): string;
103
162
  //# sourceMappingURL=formula.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"formula.d.ts","sourceRoot":"","sources":["../../src/core/formula.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,MAAM,MAAM,OAAO,GACf,IAAI,GAAG,GAAG,GAAG,GAAG,GAAG,EAAE,GAAG,OAAO,GAC/B,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GACb,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GACtB,GAAG,GAAG,KAAK,CAAC;AAIhB,qBAAa,IAAI;IAGb,QAAQ,CAAC,SAAS,EAAE,MAAM;IAC1B,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE;IAHlC,QAAQ,CAAC,IAAI,EAAG,MAAM,CAAU;gBAErB,SAAS,EAAE,MAAM,EACjB,IAAI,GAAE,SAAS,MAAM,EAAO;IAGvC,GAAG,IAAI,MAAM;CAGd;AAED,qBAAa,GAAG;IAEF,QAAQ,CAAC,KAAK,EAAE,OAAO;IADnC,QAAQ,CAAC,IAAI,EAAG,KAAK,CAAU;gBACV,KAAK,EAAE,OAAO;CACpC;AAED,qBAAa,GAAG;IAEF,QAAQ,CAAC,IAAI,EAAE,OAAO;IAAE,QAAQ,CAAC,KAAK,EAAE,OAAO;IAD3D,QAAQ,CAAC,IAAI,EAAG,KAAK,CAAU;gBACV,IAAI,EAAE,OAAO,EAAW,KAAK,EAAE,OAAO;CAC5D;AAED,qBAAa,EAAE;IAED,QAAQ,CAAC,IAAI,EAAE,OAAO;IAAE,QAAQ,CAAC,KAAK,EAAE,OAAO;IAD3D,QAAQ,CAAC,IAAI,EAAG,IAAI,CAAU;gBACT,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,IAAI,CAAU;gBACT,IAAI,EAAE,IAAI,EAAW,KAAK,EAAE,IAAI;CACtD;AAED,qBAAa,EAAE;IAED,QAAQ,CAAC,IAAI,EAAE,IAAI;IAAE,QAAQ,CAAC,KAAK,EAAE,IAAI;IADrD,QAAQ,CAAC,IAAI,EAAG,IAAI,CAAU;gBACT,IAAI,EAAE,IAAI,EAAW,KAAK,EAAE,IAAI;CACtD;AAED,qBAAa,EAAE;IAED,QAAQ,CAAC,IAAI,EAAE,IAAI;IAAE,QAAQ,CAAC,KAAK,EAAE,IAAI;IADrD,QAAQ,CAAC,IAAI,EAAG,IAAI,CAAU;gBACT,IAAI,EAAE,IAAI,EAAW,KAAK,EAAE,IAAI;CACtD;AAsBD,wBAAgB,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,CAMpE"}
@@ -4,6 +4,7 @@
4
4
  * Direct port of sponsio/formulas/formula.py.
5
5
  * Three families: Propositional, Temporal (LTL), Arithmetic.
6
6
  */
7
+ import { canonicalTool } from "./tool-names.js";
7
8
  // --- Propositional ---
8
9
  export class Atom {
9
10
  predicate;
@@ -82,7 +83,21 @@ export class U {
82
83
  this.right = right;
83
84
  }
84
85
  }
85
- // --- Arithmetic ---
86
+ // --- Arithmetic / Term abstraction ---
87
+ //
88
+ // Comparison nodes (Eq, Le, Lt, Ge, Gt) accept any ``Term`` on either
89
+ // side. A Term is anything that knows how to evaluate(state) -> value;
90
+ // the evaluator dispatches on `kind`. This lets contract authors
91
+ // compose runtime-bound values (``new ArgValue("issue_refund",
92
+ // "amount")``) against constants (``new Const(50)``) or against other
93
+ // runtime values (``new CtxValue("approved_amount")``) in the same
94
+ // comparison.
95
+ //
96
+ // Returning ``undefined`` from evaluation is the canonical "missing"
97
+ // signal: comparison evaluation treats either operand being missing as
98
+ // false (the comparison cannot decide). Wrap fragile comparisons in
99
+ // ``Implies(scopePredicate, comparison)`` to suppress them where the
100
+ // relevant arg is not applicable.
86
101
  export class Var {
87
102
  name;
88
103
  kind = "Var";
@@ -105,6 +120,74 @@ export class Const {
105
120
  this.value = value;
106
121
  }
107
122
  }
123
+ /**
124
+ * Read ``args[field]`` from the current event when it is a call to ``tool``.
125
+ *
126
+ * Returns ``undefined`` ("missing" signal) when the current event is a
127
+ * call to a different tool, or not a tool call, or args[field] absent.
128
+ * Pair with ``Implies(called(tool), ...)`` to scope the rule cleanly.
129
+ */
130
+ export class ArgValue {
131
+ tool;
132
+ field;
133
+ kind = "ArgValue";
134
+ constructor(tool, field) {
135
+ this.tool = tool;
136
+ this.field = field;
137
+ }
138
+ }
139
+ /**
140
+ * Read a fact pushed via ``guard.observeContext({ key: value })``.
141
+ *
142
+ * Returns ``undefined`` when the key has never been pushed for this trace.
143
+ */
144
+ export class CtxValue {
145
+ key;
146
+ kind = "CtxValue";
147
+ constructor(key) {
148
+ this.key = key;
149
+ }
150
+ }
151
+ /**
152
+ * Apply a JavaScript callable to another Term's value.
153
+ *
154
+ * Common cases:
155
+ * new UnaryFn(s => String(s).toLowerCase(),
156
+ * new ArgValue("send_email", "subject"))
157
+ *
158
+ * If the inner Term resolves to undefined, UnaryFn also returns undefined.
159
+ * If the callable throws, UnaryFn returns undefined rather than crashing.
160
+ *
161
+ * The ``name`` field is for debug repr only.
162
+ */
163
+ export class UnaryFn {
164
+ fn;
165
+ arg;
166
+ name;
167
+ kind = "UnaryFn";
168
+ constructor(fn, arg, name = "fn") {
169
+ this.fn = fn;
170
+ this.arg = arg;
171
+ this.name = name;
172
+ }
173
+ }
174
+ /**
175
+ * Convenience: ``args[field].length`` for the current event.
176
+ *
177
+ * Equivalent to ``new UnaryFn(v => (v as { length: number }).length,
178
+ * new ArgValue(tool, field))`` but exposed as its own class for clean
179
+ * repr and faster eval. Returns ``undefined`` when missing or not a
180
+ * .length-bearing value.
181
+ */
182
+ export class ArgLength {
183
+ tool;
184
+ field;
185
+ kind = "ArgLength";
186
+ constructor(tool, field) {
187
+ this.tool = tool;
188
+ this.field = field;
189
+ }
190
+ }
108
191
  export class Le {
109
192
  left;
110
193
  right;
@@ -159,7 +242,18 @@ function escape(s) {
159
242
  .replace(/,/g, "\\,")
160
243
  .replace(/ /g, "\\ ");
161
244
  }
245
+ /**
246
+ * Predicates whose first argument is a tool name and whose key must meet
247
+ * the grounded event on one spelling. Mirrors ``_TOOL_KEYED`` in
248
+ * sponsio/formulas/_pred_key.py: canonicalising here, in the one function
249
+ * both sides call, lets ``called(Issue_Refund)`` in YAML/LTL and an event
250
+ * grounded as ``mcp__finance__issue_refund`` agree.
251
+ */
252
+ const TOOL_KEYED = new Set(["called", "count", "consecutive_count", "arg_value"]);
162
253
  export function predKey(predicate, ...args) {
254
+ if (TOOL_KEYED.has(predicate) && args.length > 0) {
255
+ args = [canonicalTool(args[0]), ...args.slice(1)];
256
+ }
163
257
  if (args.length === 0)
164
258
  return `${predicate}()`;
165
259
  return `${predicate}(${args.map(escape).join(", ")})`;
@@ -1 +1 @@
1
- {"version":3,"file":"formula.js","sourceRoot":"","sources":["../../src/core/formula.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AASH,wBAAwB;AAExB,MAAM,OAAO,IAAI;IAGJ;IACA;IAHF,IAAI,GAAG,MAAe,CAAC;IAChC,YACW,SAAiB,EACjB,OAA0B,EAAE;QAD5B,cAAS,GAAT,SAAS,CAAQ;QACjB,SAAI,GAAJ,IAAI,CAAwB;IACpC,CAAC;IAEJ,GAAG;QACD,OAAO,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;IAC/C,CAAC;CACF;AAED,MAAM,OAAO,GAAG;IAEO;IADZ,IAAI,GAAG,KAAc,CAAC;IAC/B,YAAqB,KAAc;QAAd,UAAK,GAAL,KAAK,CAAS;IAAG,CAAC;CACxC;AAED,MAAM,OAAO,GAAG;IAEO;IAAwB;IADpC,IAAI,GAAG,KAAc,CAAC;IAC/B,YAAqB,IAAa,EAAW,KAAc;QAAtC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AAC,IAAI,EAAE,KAAK,CAAC;SACpB,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AAC1B,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,OAAO,EAAE,mBAAmB,EAAE,WAAW,CAAC,CAAC,CAAC;AAElF,MAAM,UAAU,OAAO,CAAC,SAAiB,EAAE,GAAG,IAAc;IAC1D,IAAI,UAAU,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACjD,IAAI,GAAG,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACpD,CAAC;IACD,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,GAAG,SAAS,IAAI,CAAC;IAC/C,OAAO,GAAG,SAAS,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;AACxD,CAAC"}
@@ -38,11 +38,22 @@ export interface ToolEvent {
38
38
  content?: string;
39
39
  /** Optional event timestamp; if omitted, the grounding state's monotonic clock advances by 1. */
40
40
  ts?: number;
41
+ /**
42
+ * Subject of the event, for kinds whose subject is not a tool name.
43
+ * An ``evidence`` event puts the predicate name here.
44
+ */
45
+ key?: string;
41
46
  }
42
47
  export interface GroundingState {
43
48
  callCounts: Record<string, number>;
44
49
  callWithCounts: Record<string, number>;
50
+ /** Canonical spelling of the previous tool (see core/tool-names.ts). */
45
51
  lastTool: string | null;
52
+ /**
53
+ * Every spelling the previous call was grounded under, so a tool change
54
+ * zeroes all of them rather than only the raw name.
55
+ */
56
+ lastToolAliases: string[];
46
57
  consecutiveCounts: Record<string, number>;
47
58
  tokenCounts: Record<string, number>;
48
59
  delegationDepth: number;
@@ -75,16 +86,41 @@ export declare function newGroundingState(): GroundingState;
75
86
  * These are atoms whose grounding depends on event content (arg patterns).
76
87
  */
77
88
  export declare function collectContentAtoms(formulas: Formula[]): Record<string, Set<string>>;
89
+ export declare function pathWithin(path: string, prefix: string): boolean;
78
90
  /**
79
- * Ground a single event into a predicate valuation dict.
91
+ * Fail at construction on a contract pattern that is not a valid regular
92
+ * expression. Mirrors Python, where a malformed contract raises when the
93
+ * guard is built. Without this an ``llm_said`` / ``ctx_matches`` pattern
94
+ * that never compiles silently never matches (fail-open), and an
95
+ * ``arg_*`` pattern throws on the first tool call instead of at startup.
80
96
  *
81
- * Routes by ``event.event_type``:
82
- * - ``tool_call`` (default) — emits the full tool-call atom set
83
- * - ``llm_response`` — emits ``llm_said(pattern)`` + length atoms
84
- * - ``context_update`` — merges ``event.args`` into ``state.currentCtx``
97
+ * Patterns are stored as ``args.join("|")``; each predicate knows which
98
+ * tail of that string is the regex, exactly as ``groundEvent`` reads it.
99
+ */
100
+ export declare function validateContentPatterns(atoms: Record<string, Set<string>>): void;
101
+ /**
102
+ * Read a tool argument as a number, the way a numeric cap needs it.
103
+ *
104
+ * ``"$5,000"``, ``"5,000"`` and ``"5000 USD"`` are the shapes a model
105
+ * writes for an amount. ``parseFloat`` read ``"5,000"`` as ``5`` and
106
+ * ``"$5,000"`` as nothing at all, and the evaluator reads a missing
107
+ * ``arg_numeric`` as ``0``, so ``argValueRange`` waved them through a cap
108
+ * that stopped ``5000``. The normalisation is the one ordered comparisons
109
+ * already use (``numericString`` in core/evaluator.ts), so both paths
110
+ * agree. Parity with Python ``numeric_arg`` in sponsio/tracer/grounding.py:
111
+ * a boolean reads as 0/1, a number as itself, anything else as undefined.
112
+ */
113
+ export declare function numericArg(value: unknown): number | undefined;
114
+ /**
115
+ * Does a contract's target tool name the tool this event called?
85
116
  *
86
- * Ctx atoms (``ctx(k, v)``), accumulator snapshots, and ``time_since``
87
- * fire on every event regardless of type (matching Python parity).
117
+ * The target is canonicalised and looked up among every spelling the
118
+ * event answers to (see core/tool-names.ts), so a rule on ``issue_refund``
119
+ * binds ``Issue_Refund``, ``"issue_refund "`` and
120
+ * ``mcp__finance__issue_refund``. Parity with Python ``_tool_matches``
121
+ * for plain names; the ``tool:argpattern`` form is split by the pattern
122
+ * factories before it reaches grounding in this runtime.
88
123
  */
89
- export declare function groundEvent(event: ToolEvent, state: GroundingState, contentAtoms?: Record<string, Set<string>>): Record<string, boolean | number>;
124
+ export declare function toolMatches(targetTool: string, aliases: Iterable<string>): boolean;
125
+ export declare function groundEvent(event: ToolEvent, state: GroundingState, contentAtoms?: Record<string, Set<string>>): Record<string, unknown>;
90
126
  //# sourceMappingURL=grounding.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"grounding.d.ts","sourceRoot":"","sources":["../../src/core/grounding.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAGH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C;;;;;GAKG;AACH,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,gGAAgG;IAChG,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,2FAA2F;IAC3F,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,iGAAiG;IACjG,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,cAAc;IAC7B,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACnC,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACvC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1C,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,eAAe,EAAE,MAAM,CAAC;IAC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