latticerb 0.3.0 → 0.3.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e1cd02dabe1821baf68283ad31fb90aa688bd1642943fa2f5d914cad759389fe
4
- data.tar.gz: 4c1f1118737aa6fe2a2917db077fd6badf3f03fc169c110bf5c5255a1b8376aa
3
+ metadata.gz: f977e711ce31ec3c0355472e32dcff2f95cb82c173d8cbb983f05d9f8c49fb83
4
+ data.tar.gz: 73384303ddfe7fe6cbfef0cc72166d3a79ec975251a1be88a2c1560e02c594db
5
5
  SHA512:
6
- metadata.gz: '087a54e0c2896d3a71ffb4eb8737dbf3ad2a0e04ed36682d8fa232cee7b7a131f706cdf5456277c2c6b3eef59446c263dd8ff4277879345160b386c64b06f8d0'
7
- data.tar.gz: 0fceafc2667a8042a38c7dc292b42d185b7305cf57cbf2a7d21bab7d1915723d0fd5fb33c27a444a349b9bff148357a7313f55542af393a69cf69402551426f3
6
+ metadata.gz: 3d50633f9b3c3e6824811806ad8732fbfa7e12812eb94685a03cf2263254195243f44887cbe8984c297f8d05b800063367d7d5aca6413216cace5f7e3d869262
7
+ data.tar.gz: 2b0a3695bb8c6a00a8856aaa143aec10e488088e5f0800738dd3ddeefdd299fde8fd13010f406f680e085ee8c52ec6a6d0a0b7157eb993bbcbb04f8c58678817
data/README.md CHANGED
@@ -97,7 +97,7 @@ constraints:
97
97
  applies_when: [credit_card]
98
98
  ```
99
99
 
100
- Constraint types: `invalid_pair`, `higher_order`, `forward_dep`, `bidirectional`, `conditional`, `forced`. Run `lattice agent instructions` for the full reference.
100
+ Constraint types: `invalid_pair`, `higher_order`, `forward_dep`, `bidirectional`, `conditional`, `forced`. Every constraint needs a `type` key. Run `lattice agent instructions` for an example of each type.
101
101
 
102
102
  ### Values keep their text
103
103
 
data/lib/lattice/agent.rb CHANGED
@@ -21,7 +21,58 @@ module Lattice
21
21
  "template, or config matrix; extract a Lattice schema; validate it; generate pairwise " \
22
22
  "rows; and use the rows to strengthen the plan, tests, fixtures, or visual review."
23
23
 
24
- GENERIC_AGENT_INSTRUCTIONS = <<~INSTRUCTIONS
24
+ SCHEMA_REFERENCE = <<~REFERENCE
25
+
26
+ Schema format, with one example of each constraint type:
27
+
28
+ ```yaml
29
+ model_name: checkout
30
+ strength: 2
31
+ parameters:
32
+ user: [guest, member]
33
+ payment: [card, paypal, apple_pay, invoice]
34
+ device: [desktop, ios, android]
35
+ region: [us, eu]
36
+ currency: [usd, eur]
37
+ shipping: [standard, express, pickup]
38
+ constraints:
39
+ # invalid_pair: these two assignments never appear in the same row.
40
+ - type: invalid_pair
41
+ if: { parameter: payment, value: apple_pay }
42
+ then_not: { parameter: device, value: android }
43
+ # bidirectional: each assignment requires the other.
44
+ - type: bidirectional
45
+ pair:
46
+ - { parameter: region, value: eu }
47
+ - { parameter: currency, value: eur }
48
+ # forward_dep: the source requires the target; the target may appear elsewhere.
49
+ - type: forward_dep
50
+ source: { parameter: shipping, value: pickup }
51
+ target: { parameter: region, value: us }
52
+ # conditional: defines a child parameter that only applies for some parent values.
53
+ - type: conditional
54
+ parameter: card_type
55
+ values: [visa, mastercard]
56
+ parent: payment
57
+ applies_when: [card]
58
+ # forced: this combination must appear in at least one row.
59
+ - type: forced
60
+ assignments:
61
+ - { parameter: user, value: guest }
62
+ - { parameter: device, value: ios }
63
+ - { parameter: shipping, value: express }
64
+ # higher_order: the last assignment is excluded only when all of if_all hold.
65
+ - type: higher_order
66
+ if_all:
67
+ - { parameter: user, value: guest }
68
+ - { parameter: region, value: eu }
69
+ then_not: { parameter: shipping, value: pickup }
70
+ ```
71
+
72
+ Every constraint needs a `type` key. Each assignment is `{ parameter: <name>, value: <value> }`.
73
+ REFERENCE
74
+
75
+ GENERIC_AGENT_INSTRUCTIONS = <<~INSTRUCTIONS + SCHEMA_REFERENCE
25
76
  # Lattice Agent Instructions
26
77
 
27
78
  Lattice is harness-agnostic. Use these instructions in OpenClaw, Hermes, Codex, xAI-backed agents, Claude Code, or any agent that can run shell commands.
@@ -18,6 +18,17 @@ module Lattice
18
18
  module Parser
19
19
  extend self
20
20
 
21
+ # Each constraint type and the keys written beside `type`.
22
+ CONSTRAINT_FIELDS = {
23
+ "invalid_pair" => "`if` and `then_not`",
24
+ "bidirectional" => "`pair`",
25
+ "forward_dep" => "`source` and `target`",
26
+ "conditional" => "`parameter`, `values`, `parent` and `applies_when`",
27
+ "forced" => "`assignments`",
28
+ "higher_order" => "`if_all` and `then_not`"
29
+ }.freeze
30
+ CONSTRAINT_TYPE_LIST = CONSTRAINT_FIELDS.keys.map { |name| "`#{name}`" }.join(", ").freeze
31
+
21
32
  def load_model(path, strength_override: nil)
22
33
  text, source_name, extension = read_model_input(path)
23
34
  data = deserialize_model(text, source_name, extension)
@@ -177,7 +188,17 @@ module Lattice
177
188
  next
178
189
  end
179
190
 
180
- case raw_constraint["type"]
191
+ constraint_type = raw_constraint["type"]
192
+ if constraint_type.nil?
193
+ errors << missing_type_message(index, raw_constraint)
194
+ next
195
+ end
196
+ unless constraint_type.is_a?(String)
197
+ errors << "`constraints[#{index}].type` must be a string, one of: #{CONSTRAINT_TYPE_LIST}."
198
+ next
199
+ end
200
+
201
+ case constraint_type
181
202
  when "invalid_pair"
182
203
  if_assignment = parse_assignment(raw_constraint["if"], parameters, "`constraints[#{index}].if`", errors)
183
204
  then_not = parse_assignment(raw_constraint["then_not"], parameters, "`constraints[#{index}].then_not`", errors)
@@ -205,12 +226,23 @@ module Lattice
205
226
  constraint = parse_higher_order_constraint(raw_constraint, index, parameters, errors)
206
227
  parsed << constraint if constraint
207
228
  else
208
- errors << "`constraints[#{index}]` has unknown type `#{raw_constraint['type']}`."
229
+ errors << "`constraints[#{index}]` has unknown type `#{constraint_type}`. Use one of: #{CONSTRAINT_TYPE_LIST}."
209
230
  end
210
231
  end
211
232
  parsed
212
233
  end
213
234
 
235
+ # Explains a constraint without `type`. A type name used as a key, as in
236
+ # `- invalid_pair: {...}`, gets the correct form spelled out.
237
+ def missing_type_message(index, raw_constraint)
238
+ shorthand = raw_constraint.keys.find { |key| CONSTRAINT_FIELDS.key?(key) }
239
+ return "`constraints[#{index}]` is missing `type`. Use one of: #{CONSTRAINT_TYPE_LIST}." if shorthand.nil?
240
+
241
+ "`constraints[#{index}]` is missing `type`. Write `type: #{shorthand}` as its own key, " \
242
+ "with #{CONSTRAINT_FIELDS.fetch(shorthand)} beside it. " \
243
+ "Run `lattice agent instructions` for an example of each type."
244
+ end
245
+
214
246
  def parse_conditional_constraint(raw_constraint, index, parameters, errors)
215
247
  parent = Lattice.normalize_scalar(raw_constraint["parent"])
216
248
  parameter_name = Lattice.normalize_scalar(raw_constraint["parameter"])
@@ -35,7 +35,9 @@ parameters:
35
35
  payment: [card, apple_pay, paypal]
36
36
  cart: [empty, single, multi]
37
37
  constraints:
38
- - invalid_pair: {payment: apple_pay, cart: empty}
38
+ - type: invalid_pair
39
+ if: { parameter: payment, value: apple_pay }
40
+ then_not: { parameter: cart, value: empty }
39
41
  ```
40
42
 
41
43
  One generated row (JSON):
@@ -35,7 +35,9 @@ parameters:
35
35
  payment: [card, apple_pay, paypal]
36
36
  cart: [empty, single, multi]
37
37
  constraints:
38
- - invalid_pair: {payment: apple_pay, cart: empty}
38
+ - type: invalid_pair
39
+ if: { parameter: payment, value: apple_pay }
40
+ then_not: { parameter: cart, value: empty }
39
41
  ```
40
42
 
41
43
  One generated row (JSON):
@@ -35,7 +35,9 @@ parameters:
35
35
  payment: [card, apple_pay, paypal]
36
36
  cart: [empty, single, multi]
37
37
  constraints:
38
- - invalid_pair: {payment: apple_pay, cart: empty}
38
+ - type: invalid_pair
39
+ if: { parameter: payment, value: apple_pay }
40
+ then_not: { parameter: cart, value: empty }
39
41
  ```
40
42
 
41
43
  One generated row (JSON):
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Lattice
4
- VERSION = "0.3.0"
4
+ VERSION = "0.3.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: latticerb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Klose