@lexq/cli 0.1.40 → 0.1.42

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/AGENTS.md CHANGED
@@ -7,7 +7,7 @@
7
7
  LexQ CLI (`@lexq/cli`, binary: `lexq`) manages a policy execution engine. Policies are business rules (if-then) that
8
8
  evaluate input facts and produce actions (discounts, blocks, notifications, etc.).
9
9
 
10
- The CLI also doubles as an **MCP server** — run `lexq serve --mcp` to expose 63 tools to any MCP-compatible AI client.
10
+ The CLI also doubles as an **MCP server** — run `lexq serve --mcp` to expose 75 tools to any MCP-compatible AI client.
11
11
 
12
12
  This file tells you how to use the CLI as an AI agent.
13
13
 
@@ -30,14 +30,14 @@ lexq auth whoami
30
30
 
31
31
  Detailed documentation lives in the `skills/` directory. **Read the relevant skill before executing commands.**
32
32
 
33
- | Skill | File | What it covers |
34
- |----------------|-----------------------------------|-------------------------------------------------------------------|
35
- | **Shared** | `skills/lexq-shared/SKILL.md` | Core concepts, auth, workflow, error codes. **Read first.** |
36
- | **Groups** | `skills/lexq-groups/SKILL.md` | Policy groups, conflict resolution, A/B testing |
37
- | **Rules** | `skills/lexq-rules/SKILL.md` | Condition syntax, action types, mutex, examples |
38
- | **Simulation** | `skills/lexq-simulation/SKILL.md` | Dry run, Impact Simulation, compare |
39
- | **Execution** | `skills/lexq-execution/SKILL.md` | History, stats, failure logs, integrations, webhook subscriptions |
40
- | **Recipes** | `skills/lexq-recipes/SKILL.md` | End-to-end workflows (copy-paste ready) |
33
+ | Skill | File | What it covers |
34
+ |----------------|-----------------------------------|------------------------------------------------------------------------------------------|
35
+ | **Shared** | `skills/lexq-shared/SKILL.md` | Core concepts, auth, workflow, error codes. **Read first.** |
36
+ | **Groups** | `skills/lexq-groups/SKILL.md` | Policy groups, conflict resolution, A/B testing |
37
+ | **Rules** | `skills/lexq-rules/SKILL.md` | Condition syntax, action types, mutex, examples |
38
+ | **Simulation** | `skills/lexq-simulation/SKILL.md` | Dry run, Impact Simulation, compare |
39
+ | **Execution** | `skills/lexq-execution/SKILL.md` | History, stats, failure logs, provenance, replay, latency profile, deployment monitoring |
40
+ | **Recipes** | `skills/lexq-recipes/SKILL.md` | End-to-end workflows (copy-paste ready) |
41
41
 
42
42
  ## Agent Rules
43
43
 
@@ -48,27 +48,28 @@ Detailed documentation lives in the `skills/` directory. **Read the relevant ski
48
48
  5. **Use `--format json` for parsing.** This is the default. Don't change it.
49
49
  6. **Copy full UUIDs from output.** Never guess or truncate IDs.
50
50
  7. **Memo is required for all deploy operations.** `publish`, `live`, `rollback`, `undeploy` — every one needs `--memo`.
51
- 8. **For deployment lifecycle notifications use webhook subscriptions, not integrations.** Integrations fire on rule
52
- match; webhook subscriptions fire on platform events (VERSION_PUBLISHED, DEPLOYED, ROLLED_BACK, UNDEPLOYED).
53
- 9. **Handle errors gracefully.** Check the error code and follow the action table in `lexq-shared/SKILL.md`.
51
+ 8. **Handle errors gracefully.** Check the error code and follow the action table in `lexq-shared/SKILL.md`.
54
52
 
55
- ## Complete Command Inventory (67 commands)
53
+ ## Complete Command Inventory
56
54
 
57
55
  ```
58
56
  lexq auth login|logout|whoami
59
57
  lexq status
60
58
  lexq serve --mcp # MCP stdio server mode
61
- lexq groups list|get|create|update|delete
59
+ lexq groups list|get|create|update|delete|reorder
62
60
  lexq groups ab-test start|stop|adjust
63
61
  lexq versions list|get|create|update|delete|clone
64
62
  lexq rules list|get|create|update|delete|reorder|toggle
65
- lexq facts list|create|update|delete|action-metadata
66
- lexq deploy publish|live|rollback|undeploy|history|detail|overview|deployable|diff
63
+ lexq facts list|create|update|delete|action-metadata|unregistered
64
+ lexq domain-templates list|preview|apply
65
+ lexq deploy publish|live|rollback|undeploy|history|detail|overview|deployable|diff|schedule|unschedule|schedules
67
66
  lexq analytics dry-run|dry-run-compare|requirements
68
67
  lexq analytics simulation start|status|list|cancel|export
69
68
  lexq analytics dataset upload|template
69
+ lexq profile <groupId>
70
70
  lexq history list|get|stats
71
- lexq integrations list|get|save|delete|config-spec
71
+ lexq replay decision|start|list|get|cancel
72
+ lexq provenance get|reveal-audits
72
73
  lexq logs list|get|action|bulk-action
73
74
  lexq webhook-subscriptions list|get|save|delete|test
74
75
  ```
@@ -77,7 +78,7 @@ lexq webhook-subscriptions list|get|save|delete|test
77
78
 
78
79
  ```bash
79
80
  # 1. Create group
80
- GROUP=$(lexq groups create --json '{"name":"my-policy","priority":0}')
81
+ GROUP=$(lexq groups create --json '{"name":"my-policy"}')
81
82
  GID=$(echo $GROUP | jq -r '.id')
82
83
 
83
84
  # 2. Create version
@@ -90,13 +91,12 @@ lexq facts create --key age --name "User Age" --type NUMBER
90
91
  # 4. Add rule
91
92
  lexq rules create --group-id $GID --version-id $VID --json '{
92
93
  "name": "Adult Check",
93
- "priority": 0,
94
94
  "condition": {"type":"SINGLE","field":"age","operator":"GREATER_THAN_OR_EQUAL","value":18,"valueType":"NUMBER"},
95
- "actions": [{"type":"SET_FACT","parameters":{"key":"is_adult","value":"true"}}]
95
+ "actions": [{"type":"SET_FACT","parameters":{"targetVar":"is_adult","value":true}}]
96
96
  }'
97
97
 
98
98
  # 5. Test
99
- lexq analytics dry-run --version-id $VID --debug --mock --json '{"facts":{"age":25}}'
99
+ lexq analytics dry-run --version-id $VID --debug --json '{"facts":{"age":25}}'
100
100
 
101
101
  # 6. Deploy
102
102
  lexq deploy publish --group-id $GID --version-id $VID --memo "v1"
@@ -112,7 +112,7 @@ Webhook subscriptions fire on platform events — separate from rule-level webho
112
112
  lexq webhook-subscriptions save --json '{
113
113
  "name": "Slack Deploy Notifications",
114
114
  "webhookUrl": "https://hooks.slack.com/services/XXX/YYY/ZZZ",
115
- "subscribedEvents": ["VERSION_PUBLISHED", "DEPLOYED", "ROLLED_BACK", "UNDEPLOYED"],
115
+ "subscribedEvents": ["VERSION_PUBLISHED", "DEPLOYED", "ROLLED_BACK", "UNDEPLOYED", "DEPLOY_SCHEDULED"],
116
116
  "payloadFormat": "SLACK"
117
117
  }'
118
118
 
@@ -142,16 +142,18 @@ Connect via:
142
142
  - **Cloud:** `https://mcp.lexq.io` (OAuth 2.1)
143
143
  - **Local stdio:** `npx @lexq/cli serve --mcp`
144
144
 
145
- 63 tools mirror the CLI command inventory.
145
+ 75 tools mirror the CLI command inventory.
146
146
 
147
147
  ## Troubleshooting
148
148
 
149
- | Problem | Solution |
150
- |------------------------------|--------------------------------------------------------------------------|
151
- | `Not authenticated` | Run `lexq auth login` |
152
- | `ENTITY_NOT_FOUND` | Verify the ID exists via the corresponding `list` command |
153
- | `CANNOT_MODIFY` | Version is not DRAFT. Clone it: `lexq versions clone` |
154
- | `EMPTY_RULES` | Add at least one rule before publishing |
155
- | `ACTIVATION_CONFIG_MISMATCH` | All groups in the same activationGroup must share the same mode/strategy |
156
- | `WH_URL_INVALID` | Webhook URL must be HTTPS and return 2xx for a POST |
157
- | Network error | Check `lexq status` for API health |
149
+ | Problem | Solution |
150
+ |-----------------------------|---------------------------------------------------------------------|
151
+ | `Not authenticated` | Run `lexq auth login` |
152
+ | `P-` error on get/update | Verify the ID exists via the corresponding `list` command |
153
+ | Version is not DRAFT | Clone it: `lexq versions clone` |
154
+ | Publish rejected, 0 rules | Add at least one rule before publishing |
155
+ | `activationGroup` mismatch | All groups in the same activationGroup must share mode and strategy |
156
+ | `WH-` error on subscription | Webhook URL must be HTTPS and return 2xx for a POST |
157
+ | Network error | Check `lexq status` for API health |
158
+
159
+ `errorCode` is of the form `<domain>-<number>` (`P-002`, `ACT-016`). See `lexq-shared/SKILL.md` for the prefix table.
package/CONTEXT.md CHANGED
@@ -11,6 +11,8 @@ simulation, deploy to production, and execute via REST API — all without modif
11
11
  - A/B testing for rule versions
12
12
  - Git-style versioning with full audit trail
13
13
  - Platform event webhooks for deployment lifecycle notifications
14
+ - Decision Replay — re-evaluate past decisions against a candidate version
15
+ - Decision Provenance — deterministic "why" for every recorded decision
14
16
 
15
17
  ## Architecture
16
18
 
@@ -49,14 +51,11 @@ Tenant
49
51
  ├── PolicyGroup (ACTIVE | DISABLED | ARCHIVED)
50
52
  │ ├── PolicyVersion (DRAFT → ACTIVE → ARCHIVED | EXPIRED)
51
53
  │ │ └── PolicyRule (condition + actions, priority-ordered)
52
- │ ├── PolicyDeployment (PUBLISH | DEPLOY | ROLLBACK | UNDEPLOY)
54
+ │ ├── PolicyDeployment (DEPLOY | ROLLBACK | UNDEPLOY)
53
55
  │ └── A/B Test (testVersionId + trafficRate)
54
56
 
55
57
  ├── FactDefinition (key, type, displayName — shared across all groups)
56
58
 
57
- ├── Integration (WEBHOOK | COUPON | POINT | NOTIFICATION | CRM | MESSENGER)
58
- │ — fires on rule match (per-rule configured)
59
-
60
59
  └── WebhookSubscription (subscribedEvents + webhookUrl + payloadFormat)
61
60
  — fires on platform events (deployment lifecycle)
62
61
  ```
@@ -83,7 +82,9 @@ Tenant
83
82
  ### Condition Operators
84
83
 
85
84
  `EQUALS`, `NOT_EQUALS`, `GREATER_THAN`, `GREATER_THAN_OR_EQUAL`, `LESS_THAN`, `LESS_THAN_OR_EQUAL`, `CONTAINS`, `IN`,
86
- `NOT_IN`
85
+ `NOT_IN`, `HAS_ANY`, `HAS_ALL`, `HAS_NONE`
86
+
87
+ `HAS_*` are for LIST-typed facts only. `IN` / `NOT_IN` are their mirror — scalar fact, list value.
87
88
 
88
89
  ### Value Types
89
90
 
@@ -91,7 +92,7 @@ Tenant
91
92
 
92
93
  ### Action Types
93
94
 
94
- `MUTATE_FACT`, `INCREMENT_FACT`, `EMIT_EVENT`, `BLOCK`, `EMIT_NOTIFICATION`, `EMIT_WEBHOOK`, `SET_FACT`, `ADD_TAG`
95
+ `MUTATE_FACT`, `SET_FACT`, `BLOCK`
95
96
 
96
97
  ### Conflict Resolution Modes
97
98
 
@@ -99,12 +100,13 @@ Tenant
99
100
 
100
101
  ### Conflict Resolution Strategies
101
102
 
102
- `FIRST_MATCH`, `HIGHEST_PRIORITY`, `MAX_BENEFIT`
103
+ `HIGHEST_PRIORITY`
103
104
 
104
105
  ### Deployment Types
105
106
 
106
- `PUBLISH` (DRAFT → ACTIVE), `DEPLOY` (ACTIVE → live traffic), `ROLLBACK` (revert to previous), `UNDEPLOY` (remove from
107
- live)
107
+ `DEPLOY` (ACTIVE → live traffic), `ROLLBACK` (revert to previous), `UNDEPLOY` (remove from live)
108
+
109
+ Publishing (DRAFT → ACTIVE) is a qualification event, not a deployment — it has no `DeploymentType`.
108
110
 
109
111
  ### Execution Statuses
110
112
 
@@ -116,51 +118,43 @@ live)
116
118
 
117
119
  ### Decision Statuses
118
120
 
119
- `SELECTED`, `NO_MATCH`, `NOT_SELECTED`, `BLOCKED_MUTEX`, `LOST_PRIORITY`, `DROPPED_LIMIT`, `ERROR`
121
+ `SELECTED`, `NO_MATCH`, `BLOCKED`, `ERROR`
122
+
123
+ `BLOCKED` means the rule matched but lost conflict resolution — the round and reason are in `reasonCode` (
124
+ `MUTEX_PRIORITY_LOST`, `GROUP_LIMIT_REACHED`, …). It is unrelated to the `BLOCK` action, whose rule stays `SELECTED`.
125
+
126
+ `NOT_SELECTED` exists in the enum but the engine never produces it (reserved for effective-date filtering, not yet
127
+ implemented).
120
128
 
121
129
  ### Platform Event Types (for webhook subscriptions)
122
130
 
123
- `VERSION_PUBLISHED`, `DEPLOYED`, `ROLLED_BACK`, `UNDEPLOYED`
131
+ `VERSION_PUBLISHED`, `DEPLOYED`, `ROLLED_BACK`, `UNDEPLOYED`, `DEPLOY_SCHEDULED`, `DEPLOY_SCHEDULE_CANCELED`
124
132
 
125
133
  ### Webhook Payload Formats
126
134
 
127
135
  `GENERIC` (full JSON payload), `SLACK` (`{"text": "..."}` simplified)
128
136
 
129
- ## Integration vs Webhook Subscription
130
-
131
- Two distinct webhook mechanisms — do not confuse them:
132
-
133
- | Concern | **Integration** (WEBHOOK type) | **WebhookSubscription** |
134
- |---------------|--------------------------------------------|---------------------------------------------------|
135
- | When it fires | Rule match during execution | Platform event (publish/deploy/rollback/undeploy) |
136
- | Configured at | Per-rule action | Per-tenant subscription |
137
- | Payload | Rule-defined template | Standard platform event schema |
138
- | Use case | "Notify when VIP makes a purchase" | "Notify Slack when a policy is deployed" |
139
- | Signing | Optional (HMAC via Integration.credential) | Optional HMAC-SHA256 via `secret` |
140
- | Formats | Free-form (any) | GENERIC or SLACK |
141
-
142
137
  ## Glossary
143
138
 
144
- | Term | Definition |
145
- |--------------------------|--------------------------------------------------------------------------------------------------------------------------------------|
146
- | **Policy Group** | Top-level container for rule versions. Controls deployment lifecycle, conflict resolution, and A/B testing. |
147
- | **Policy Version** | An immutable snapshot of rules. Only DRAFT versions can be modified. |
148
- | **Policy Rule** | A condition → actions pair. Evaluated in priority order within a version. |
149
- | **Fact** | An input variable passed during execution. Declared via Fact Definitions with key, type, and name. |
150
- | **Fact Definition** | Schema declaration for a fact — its key (snake_case), value type, display name, and description. |
151
- | **Dry Run** | Single-input test execution. Returns which rules matched, what actions would fire, and decision traces. |
152
- | **Simulation** | Batch test replaying historical executions against a version. Compares with a baseline. |
153
- | **Activation Group** | A logical grouping of Policy Groups for cross-group conflict resolution. |
154
- | **Mutex Group** | A logical grouping of Policy Rules within a version for intra-version conflict resolution. |
155
- | **Deployment** | The act of putting an ACTIVE version into production to receive traffic. |
156
- | **Rollback** | Reverting to the previously deployed version. Creates a new deployment record. |
157
- | **Undeploy** | Removing a group from live traffic. No version serves requests until re-deployed. |
158
- | **A/B Test** | Splitting traffic between the current live version and a test version by percentage. |
159
- | **Execution Trace** | Per-rule evaluation result showing whether the condition matched and what actions were generated. |
160
- | **Decision Trace** | Final disposition of a rule after conflict resolution (SELECTED, BLOCKED_MUTEX, etc.). |
161
- | **Snapshot Hash** | SHA-256 hash of a version's rule snapshot at deployment time. Used to verify integrity. |
162
- | **Traffic Rate** | Percentage (0100) of traffic routed to the A/B test version. |
163
- | **Integration** | An external service binding (WEBHOOK, COUPON, POINT, NOTIFICATION, CRM, MESSENGER) referenced by rule actions. Fires per rule match. |
164
- | **Webhook Subscription** | A platform event listener receives notifications on deployment lifecycle events. Tenant-level, independent from Integrations. |
165
- | **Platform Event** | A lifecycle event emitted by the engine itself (VERSION_PUBLISHED, DEPLOYED, ROLLED_BACK, UNDEPLOYED). |
166
- | **Failure Log** | A record of a background task failure (webhook delivery, coupon issuance, etc.) available for retry/resolve/ignore. |
139
+ | Term | Definition |
140
+ |--------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|
141
+ | **Policy Group** | Top-level container for rule versions. Controls deployment lifecycle, conflict resolution, and A/B testing. |
142
+ | **Policy Version** | An immutable snapshot of rules. Only DRAFT versions can be modified. |
143
+ | **Policy Rule** | A condition → actions pair. Evaluated in priority order within a version. |
144
+ | **Fact** | An input variable passed during execution. Declared via Fact Definitions with key, type, and name. |
145
+ | **Fact Definition** | Schema declaration for a fact — its key (snake_case), value type, display name, and description. |
146
+ | **Dry Run** | Single-input test execution. Returns which rules matched, what actions would fire, and decision traces. |
147
+ | **Simulation** | Batch test replaying historical executions against a version. Compares with a baseline. |
148
+ | **Activation Group** | A logical grouping of Policy Groups for cross-group conflict resolution. |
149
+ | **Mutex Group** | A logical grouping of Policy Rules within a version for intra-version conflict resolution. |
150
+ | **Deployment** | The act of putting an ACTIVE version into production to receive traffic. |
151
+ | **Rollback** | Reverting to the previously deployed version. Creates a new deployment record. |
152
+ | **Undeploy** | Removing a group from live traffic. No version serves requests until re-deployed. |
153
+ | **A/B Test** | Splitting traffic between the current live version and a test version by percentage. |
154
+ | **Execution Trace** | Per-rule evaluation result showing whether the condition matched and what actions were generated. |
155
+ | **Decision Trace** | Final disposition of a rule after conflict resolution (`SELECTED`, `BLOCKED`, …), with a `reasonCode` explaining why. |
156
+ | **Snapshot Hash** | SHA-256 hash of a version's rule snapshot at deployment time. Used to verify integrity. |
157
+ | **Traffic Rate** | Percentage (199) of traffic routed to the A/B test version. |
158
+ | **Webhook Subscription** | A platform event listener receives notifications on deployment lifecycle events. Tenant-level. |
159
+ | **Platform Event** | A lifecycle event emitted by the engine itself (`VERSION_PUBLISHED`, `DEPLOYED`, `ROLLED_BACK`, `UNDEPLOYED`, `DEPLOY_SCHEDULED`, `DEPLOY_SCHEDULE_CANCELED`). |
160
+ | **Failure Log** | A record of a background task failure (platform webhook delivery, scheduled deployment). Mark as `RESOLVE` or `IGNORE` — there is no retry. |
package/README.md CHANGED
@@ -59,7 +59,7 @@ lexq domain-templates apply --template ECOMMERCE
59
59
  # Returns: policyGroupId, policyVersionId, factsCreated, rulesCreated
60
60
 
61
61
  # 4. Test a rule against your data before shipping
62
- lexq analytics dry-run --version-id <VERSION_ID> --debug --mock \
62
+ lexq analytics dry-run --version-id <VERSION_ID> --debug \
63
63
  --json '{"facts":{"loyalty_tier":"PLATINUM","purchase_subtotal_usd":150}}'
64
64
 
65
65
  # 5. Deploy
@@ -159,7 +159,7 @@ skills/
159
159
  ├── lexq-groups/SKILL.md Policy groups, conflict resolution, A/B testing
160
160
  ├── lexq-rules/SKILL.md Condition syntax, action types, mutex
161
161
  ├── lexq-simulation/SKILL.md Dry run, Impact Simulation, compare
162
- ├── lexq-execution/SKILL.md Execution history, stats, failure logs
162
+ ├── lexq-execution/SKILL.md History, stats, failure logs, provenance, replay, latency profile
163
163
  └── lexq-recipes/SKILL.md End-to-end recipes
164
164
 
165
165
  .claude/CLAUDE.md Claude Code project context
@@ -181,19 +181,21 @@ node_modules/@lexq/cli/CONTEXT.md
181
181
  lexq auth login | logout | whoami
182
182
  lexq status API health check
183
183
  lexq serve Run as MCP stdio server (--mcp)
184
- lexq groups list | get | create | update | delete
184
+ lexq groups list | get | create | update | delete | reorder
185
185
  lexq groups ab-test start | stop | adjust
186
186
  lexq versions list | get | create | update | delete | clone
187
187
  lexq rules list | get | create | update | delete | reorder | toggle
188
- lexq facts list | create | update | delete | action-metadata
188
+ lexq facts list | create | update | delete | action-metadata | unregistered
189
189
  lexq domain-templates list | preview | apply
190
- lexq deploy publish | live | rollback | undeploy | history | detail | overview | deployable | diff
190
+ lexq deploy publish | live | rollback | undeploy | history | detail | overview | deployable | diff | schedule | unschedule | schedules
191
191
  lexq analytics dry-run | dry-run-compare | requirements
192
192
  lexq analytics simulation start | status | list | cancel | export
193
193
  lexq analytics dataset upload | template
194
+ lexq profile <groupId> — per-rule latency profile
194
195
  lexq history list | get | stats
195
- lexq integrations list | get | save | delete | config-spec
196
+ lexq replay decision | start | list | get | cancel
196
197
  lexq logs list | get | action | bulk-action
198
+ lexq provenance get | reveal-audits
197
199
  lexq webhook-subscriptions list | get | save | delete | test
198
200
  ```
199
201