@lexq/cli 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.
package/AGENTS.md ADDED
@@ -0,0 +1,117 @@
1
+ # AGENTS.md — LexQ CLI Agent Guide
2
+
3
+ > **For AI Agents and AI-powered IDEs** (Claude Code, Cursor, Windsurf, Cline, Gemini CLI, Copilot, and others).
4
+
5
+ ## What is this?
6
+
7
+ LexQ CLI (`@lexq/cli`, binary: `lexq`) manages a policy execution engine. Policies are business rules (if-then) that evaluate input facts and produce actions (discounts, blocks, notifications, etc.).
8
+
9
+ This file tells you how to use the CLI as an AI agent.
10
+
11
+ ## Quick Start
12
+
13
+ ```bash
14
+ # 1. Install
15
+ npm install -g @lexq/cli
16
+ # or: npx @lexq/cli
17
+
18
+ # 2. Authenticate
19
+ lexq auth login
20
+ # Enter API key when prompted
21
+
22
+ # 3. Verify
23
+ lexq auth whoami
24
+ ```
25
+
26
+ ## Skills
27
+
28
+ Detailed documentation lives in the `skills/` directory. **Read the relevant skill before executing commands.**
29
+
30
+ | Skill | File | What it covers |
31
+ |---|---|---|
32
+ | **Shared** | `skills/lexq-shared/SKILL.md` | Core concepts, auth, workflow, error codes. **Read first.** |
33
+ | **Groups** | `skills/lexq-groups/SKILL.md` | Policy groups, conflict resolution, A/B testing |
34
+ | **Rules** | `skills/lexq-rules/SKILL.md` | Condition syntax, action types, mutex, examples |
35
+ | **Simulation** | `skills/lexq-simulation/SKILL.md` | Dry run, batch simulation, compare |
36
+ | **Execution** | `skills/lexq-execution/SKILL.md` | History, stats, failure logs, integrations |
37
+ | **Recipes** | `skills/lexq-recipes/SKILL.md` | 10 end-to-end workflows (copy-paste ready) |
38
+
39
+ ## Agent Rules
40
+
41
+ 1. **Always read `lexq-shared/SKILL.md` before any task.** It contains ordering constraints you must follow.
42
+ 2. **Always dry-run before publishing.** Run `lexq analytics dry-run` to validate.
43
+ 3. **Never modify a non-DRAFT version.** Check version status first. Clone if needed.
44
+ 4. **Always check facts before creating rules.** Run `lexq facts list` to know available keys and types.
45
+ 5. **Use `--format json` for parsing.** This is the default. Don't change it.
46
+ 6. **Copy full UUIDs from output.** Never guess or truncate IDs.
47
+ 7. **Handle errors gracefully.** Check the error code and follow the action table in `lexq-shared/SKILL.md`.
48
+
49
+ ## Complete Command Inventory (61 commands)
50
+
51
+ ```
52
+ lexq auth login|logout|whoami
53
+ lexq status
54
+ lexq groups list|get|create|update|delete
55
+ lexq groups ab-test start|stop|adjust
56
+ lexq versions list|get|create|update|delete|clone
57
+ lexq rules list|get|create|update|delete|reorder|toggle
58
+ lexq facts list|create|update|delete
59
+ lexq deploy publish|live|rollback|undeploy|history|detail|overview
60
+ lexq analytics dry-run|dry-run-compare|requirements
61
+ lexq analytics simulation start|status|list|cancel|export
62
+ lexq history list|get|stats
63
+ lexq integrations list|get|save|delete|config-spec
64
+ lexq logs list|get|action|bulk-action
65
+ ```
66
+
67
+ ## Example: Create and Deploy a Policy (Minimal)
68
+
69
+ ```bash
70
+ # 1. Create group
71
+ GROUP=$(lexq groups create --json '{"name":"my-policy","priority":0}')
72
+ GID=$(echo $GROUP | jq -r '.id')
73
+
74
+ # 2. Create version
75
+ VERSION=$(lexq versions create --group-id $GID --json '{"commitMessage":"v1"}')
76
+ VID=$(echo $VERSION | jq -r '.id')
77
+
78
+ # 3. Register fact
79
+ lexq facts create --key age --name "User Age" --type NUMBER
80
+
81
+ # 4. Add rule
82
+ lexq rules create --group-id $GID --version-id $VID --json '{
83
+ "name": "Adult Check",
84
+ "priority": 0,
85
+ "condition": {"type":"SINGLE","field":"age","operator":"GREATER_THAN_OR_EQUAL","value":18,"valueType":"NUMBER"},
86
+ "actions": [{"type":"SET_FACT","parameters":{"key":"is_adult","value":"true"}}]
87
+ }'
88
+
89
+ # 5. Test
90
+ lexq analytics dry-run --version-id $VID --debug --mock --json '{"facts":{"age":25}}'
91
+
92
+ # 6. Deploy
93
+ lexq deploy publish --group-id $GID --version-id $VID --memo "v1"
94
+ lexq deploy live --group-id $GID --version-id $VID --memo "Initial deploy"
95
+ ```
96
+
97
+ ## IDE-Specific Notes
98
+
99
+ ### Cursor / Windsurf / Cline
100
+ Place this file in the project root. The IDE will auto-discover it.
101
+
102
+ ### Claude Code
103
+ See `.claude/CLAUDE.md` for additional project-specific context (code structure, build commands, architecture principles).
104
+
105
+ ### Gemini CLI
106
+ Read this file and the skills directory. All commands are documented with full examples.
107
+
108
+ ## Troubleshooting
109
+
110
+ | Problem | Solution |
111
+ |---|---|
112
+ | `Not authenticated` | Run `lexq auth login` |
113
+ | `ENTITY_NOT_FOUND` | Verify the ID exists via the corresponding `list` command |
114
+ | `CANNOT_MODIFY` | Version is not DRAFT. Clone it: `lexq versions clone` |
115
+ | `EMPTY_RULES` | Add at least one rule before publishing |
116
+ | `ACTIVATION_CONFIG_MISMATCH` | All groups in the same activationGroup must share the same mode/strategy |
117
+ | Network error | Check `lexq status` for API health |
package/CONTEXT.md ADDED
@@ -0,0 +1,158 @@
1
+ # CONTEXT.md — LexQ Platform Architecture
2
+
3
+ ## What is LexQ?
4
+
5
+ LexQ is a **B2B SaaS policy execution engine**. Customers define business rules (conditions → actions), test them via simulation, deploy to production, and execute via REST API — all without modifying application code.
6
+
7
+ **Core differentiators:**
8
+ - Pre-deploy simulation against real data
9
+ - A/B testing for rule versions
10
+ - Git-style versioning with full audit trail
11
+
12
+ ## Platform Components
13
+
14
+ ```
15
+ ┌─────────────┐ ┌──────────────┐ ┌──────────────┐
16
+ │ lexq-web │ │ lexq-console │ │ lexq-cli │
17
+ │ (Next.js) │ │ (React 18) │ │ (TypeScript) │
18
+ │ Marketing │ │ Admin UI │ │ Agent Tool │
19
+ └──────┬──────┘ └──────┬───────┘ └──────┬───────┘
20
+ │ │ │
21
+ │ ┌───────▼────────┐ │
22
+ │ │ lexq-engine │◄──────────┘
23
+ │ │ (Spring Boot) │
24
+ │ ├────────────────┤
25
+ │ │ module-admin │ :8081 ── Console API (JWT)
26
+ │ │ module-partner │ :8080 ── Partner API (API Key) ◄── CLI
27
+ │ │ module-engine │ :8082 ── Execution API (API Key)
28
+ │ │ module-batch │ :8083 ── Background Jobs
29
+ │ │ module-core │ ── Shared domain
30
+ │ └───────┬────────┘
31
+ │ │
32
+ │ ┌───────▼────────┐
33
+ │ │ PostgreSQL │ Aurora Serverless v2
34
+ │ │ Redis │ ElastiCache Serverless
35
+ │ └────────────────┘
36
+
37
+ ┌──────▼──────┐
38
+ │ lexq-docs │
39
+ │ (Mintlify) │
40
+ └─────────────┘
41
+ ```
42
+
43
+ ## CLI ↔ Engine Relationship
44
+
45
+ The CLI exclusively calls `module-partner-api` (port 8080) via API Key authentication.
46
+
47
+ **Base URL:** `https://api.lexq.io/api/v1/partners`
48
+
49
+ The CLI does NOT call:
50
+ - `module-admin-api` (JWT auth, console only)
51
+ - `module-engine-api` (runtime execution, application code only)
52
+ - `module-batch` (internal scheduler)
53
+
54
+ ## Domain Model
55
+
56
+ ```
57
+ Tenant
58
+ └── PolicyGroup (ACTIVE | DISABLED | ARCHIVED)
59
+ ├── PolicyVersion (DRAFT → ACTIVE → ARCHIVED | EXPIRED)
60
+ │ └── PolicyRule (condition + actions, priority-ordered)
61
+ ├── PolicyDeployment (PUBLISH | DEPLOY | ROLLBACK | UNDEPLOY)
62
+ └── A/B Test (testVersionId + trafficRate)
63
+
64
+ Tenant
65
+ └── FactDefinition (key, type, displayName — shared across all groups)
66
+
67
+ Tenant
68
+ └── Integration (WEBHOOK | COUPON | POINT | NOTIFICATION | CRM | MESSENGER)
69
+ ```
70
+
71
+ ## Key Enums
72
+
73
+ ### Policy Group Status
74
+ | Value | Description |
75
+ |---|---|
76
+ | `ACTIVE` | Normal operation |
77
+ | `DISABLED` | Execution blocked (emergency stop) |
78
+ | `ARCHIVED` | Permanently removed |
79
+
80
+ ### Policy Version Status
81
+ | Value | Description |
82
+ |---|---|
83
+ | `DRAFT` | Editable. Rules can be added/modified. |
84
+ | `ACTIVE` | Published. Locked — no modifications allowed. |
85
+ | `ARCHIVED` | Superseded by a newer version. |
86
+ | `EXPIRED` | Past `effectiveTo` date. Auto-transitioned by scheduler. |
87
+
88
+ ### Condition Operators
89
+ `EQUALS`, `NOT_EQUALS`, `GREATER_THAN`, `GREATER_THAN_OR_EQUAL`, `LESS_THAN`, `LESS_THAN_OR_EQUAL`, `CONTAINS`, `IN`, `NOT_IN`
90
+
91
+ ### Value Types
92
+ `STRING`, `NUMBER`, `BOOLEAN`, `LIST_STRING`, `LIST_NUMBER`
93
+
94
+ ### Action Types
95
+ `DISCOUNT`, `POINT`, `COUPON_ISSUE`, `BLOCK`, `NOTIFICATION`, `WEBHOOK`, `SET_FACT`, `ADD_TAG`
96
+
97
+ ### Conflict Resolution Modes
98
+ `NONE` (all fire), `EXCLUSIVE` (one winner), `MAX_N` (up to N winners)
99
+
100
+ ### Conflict Resolution Strategies
101
+ `FIRST_MATCH`, `HIGHEST_PRIORITY`, `MAX_BENEFIT`
102
+
103
+ ### Deployment Types
104
+ `PUBLISH` (DRAFT → ACTIVE), `DEPLOY` (ACTIVE → live traffic), `ROLLBACK` (revert to previous), `UNDEPLOY` (remove from live)
105
+
106
+ ### Execution Statuses
107
+ `SUCCESS`, `NO_MATCH`, `ERROR`, `TIMEOUT`
108
+
109
+ ### Simulation Statuses
110
+ `PENDING`, `RUNNING`, `COMPLETED`, `FAILED`, `CANCELLED`
111
+
112
+ ### Decision Statuses
113
+ `SELECTED`, `NO_MATCH`, `NOT_SELECTED`, `BLOCKED_MUTEX`, `LOST_PRIORITY`, `DROPPED_LIMIT`, `ERROR`
114
+
115
+ ## Glossary
116
+
117
+ | Term | Definition |
118
+ |---|---|
119
+ | **Policy Group** | Top-level container for rule versions. Controls deployment lifecycle, conflict resolution, and A/B testing. |
120
+ | **Policy Version** | An immutable snapshot of rules. Only DRAFT versions can be modified. |
121
+ | **Policy Rule** | A condition → actions pair. Evaluated in priority order within a version. |
122
+ | **Fact** | An input variable passed during execution. Declared via Fact Definitions with key, type, and name. |
123
+ | **Fact Definition** | Schema declaration for a fact — its key (snake_case), value type, display name, and description. |
124
+ | **Dry Run** | Single-input test execution. Returns which rules matched, what actions would fire, and decision traces. |
125
+ | **Simulation** | Batch test replaying historical executions against a version. Compares with a baseline. |
126
+ | **Activation Group** | A logical grouping of Policy Groups for cross-group conflict resolution. |
127
+ | **Mutex Group** | A logical grouping of Policy Rules within a version for intra-version conflict resolution. |
128
+ | **Deployment** | The act of putting an ACTIVE version into production to receive traffic. |
129
+ | **Rollback** | Reverting to the previously deployed version. Creates a new deployment record. |
130
+ | **Undeploy** | Removing a group from live traffic. No version serves requests until re-deployed. |
131
+ | **A/B Test** | Splitting traffic between the current live version and a test version by percentage. |
132
+ | **Execution Trace** | Per-rule evaluation result showing whether the condition matched and what actions were generated. |
133
+ | **Decision Trace** | Final disposition of a rule after conflict resolution (SELECTED, BLOCKED_MUTEX, etc.). |
134
+ | **Snapshot Hash** | SHA-256 hash of a version's rule snapshot at deployment time. Used to verify integrity. |
135
+ | **Traffic Rate** | Percentage (0–100) of traffic routed to the A/B test version. |
136
+
137
+ ## Infrastructure
138
+
139
+ | Component | Service | Region |
140
+ |---|---|---|
141
+ | Compute | AWS ECS Fargate | us-east-1 |
142
+ | Database | Aurora PostgreSQL Serverless v2 | us-east-1 |
143
+ | Cache | ElastiCache Redis Serverless | us-east-1 |
144
+ | CDN | CloudFront + S3 | Global |
145
+ | DNS | Cloudflare | — |
146
+ | Email | AWS SES | us-east-1 |
147
+ | Docs | Mintlify | — |
148
+ | IaC | Terraform | — |
149
+ | CI/CD | GitHub Actions (OIDC) | — |
150
+
151
+ ## Domains
152
+
153
+ | Domain | Target |
154
+ |---|---|
155
+ | `lexq.io` | Vercel (marketing site) |
156
+ | `console.lexq.io` | CloudFront → S3 (React SPA) |
157
+ | `api.lexq.io` | ALB → ECS (all backend modules) |
158
+ | `docs.lexq.io` | Mintlify |
package/README.md ADDED
@@ -0,0 +1,153 @@
1
+ # LexQ CLI
2
+
3
+ > Manage policies, simulate rules, and deploy from the terminal. Built for humans and AI agents.
4
+
5
+ [![npm](https://img.shields.io/npm/v/@lexq/cli)](https://www.npmjs.com/package/@lexq/cli)
6
+ [![License](https://img.shields.io/github/license/lexq-io/lexq-cli)](LICENSE)
7
+
8
+ ## Install
9
+
10
+ ```bash
11
+ npm install -g @lexq/cli
12
+ ```
13
+
14
+ Or run without installing:
15
+
16
+ ```bash
17
+ npx @lexq/cli
18
+ ```
19
+
20
+ Requires **Node.js 18+**.
21
+
22
+ ## Quick Start
23
+
24
+ ```bash
25
+ # 1. Authenticate
26
+ lexq auth login
27
+ # Enter your API key (create one at console.lexq.io → Management → API Keys)
28
+
29
+ # 2. Verify
30
+ lexq auth whoami
31
+
32
+ # 3. Create a policy group
33
+ lexq groups create --json '{"name":"my-policy","priority":0}'
34
+
35
+ # 4. Create a draft version
36
+ lexq versions create --group-id <GROUP_ID> --json '{"commitMessage":"v1"}'
37
+
38
+ # 5. Add a rule
39
+ lexq rules create --group-id <GROUP_ID> --version-id <VERSION_ID> --json '{
40
+ "name": "VIP Discount",
41
+ "priority": 0,
42
+ "condition": {
43
+ "type": "SINGLE",
44
+ "field": "customer_tier",
45
+ "operator": "EQUALS",
46
+ "value": "VIP",
47
+ "valueType": "STRING"
48
+ },
49
+ "actions": [{
50
+ "type": "DISCOUNT",
51
+ "parameters": {"method":"PERCENTAGE","rate":10,"referenceFactKey":"payment_amount"}
52
+ }]
53
+ }'
54
+
55
+ # 6. Test
56
+ lexq analytics dry-run --version-id <VERSION_ID> --debug --mock \
57
+ --json '{"facts":{"customer_tier":"VIP","payment_amount":100000}}'
58
+
59
+ # 7. Deploy
60
+ lexq deploy publish --group-id <GROUP_ID> --version-id <VERSION_ID> --memo "v1"
61
+ lexq deploy live --group-id <GROUP_ID> --version-id <VERSION_ID> --memo "Initial deploy"
62
+ ```
63
+
64
+ ## Commands
65
+
66
+ ```
67
+ lexq auth login | logout | whoami
68
+ lexq status API health check
69
+ lexq groups list | get | create | update | delete
70
+ lexq groups ab-test start | stop | adjust
71
+ lexq versions list | get | create | update | delete | clone
72
+ lexq rules list | get | create | update | delete | reorder | toggle
73
+ lexq facts list | create | update | delete
74
+ lexq deploy publish | live | rollback | undeploy | history | detail | overview
75
+ lexq analytics dry-run | dry-run-compare | requirements
76
+ lexq analytics simulation start | status | list | cancel | export
77
+ lexq history list | get | stats
78
+ lexq integrations list | get | save | delete | config-spec
79
+ lexq logs list | get | action | bulk-action
80
+ ```
81
+
82
+ ## Global Options
83
+
84
+ | Flag | Description |
85
+ |---|---|
86
+ | `--format <json\|table>` | Output format (default: `json`) |
87
+ | `--api-key <key>` | Override stored API key |
88
+ | `--base-url <url>` | Override API base URL |
89
+ | `--dry-run` | Preview the HTTP request without executing |
90
+ | `--verbose` | Show request/response details |
91
+ | `--no-color` | Disable colored output |
92
+
93
+ ## AI Agent Skills
94
+
95
+ LexQ CLI ships with **AI Agent Skills** — structured documentation that AI coding agents can read to autonomously manage policies.
96
+
97
+ ```
98
+ skills/
99
+ ├── lexq-shared/SKILL.md Core concepts, auth, workflow
100
+ ├── lexq-groups/SKILL.md Policy groups, conflict resolution, A/B testing
101
+ ├── lexq-rules/SKILL.md Condition syntax, action types, mutex
102
+ ├── lexq-simulation/SKILL.md Dry run, batch simulation, compare
103
+ ├── lexq-execution/SKILL.md Execution history, stats, failure logs
104
+ └── lexq-recipes/SKILL.md 10 end-to-end recipes
105
+
106
+ .claude/CLAUDE.md Claude Code project context
107
+ AGENTS.md Universal agent guide (Cursor, Windsurf, Gemini CLI, Cline)
108
+ CONTEXT.md Platform architecture & glossary
109
+ ```
110
+
111
+ ### For AI Agent Developers
112
+
113
+ Skills are included in the npm package. After installing `@lexq/cli`, agents can read skills from:
114
+
115
+ ```
116
+ node_modules/@lexq/cli/skills/
117
+ node_modules/@lexq/cli/AGENTS.md
118
+ node_modules/@lexq/cli/CONTEXT.md
119
+ ```
120
+
121
+ Or reference them directly in your project by copying the `skills/` directory.
122
+
123
+ ## Configuration
124
+
125
+ Config is stored at `~/.lexq/config.json`:
126
+
127
+ ```json
128
+ {
129
+ "apiKey": "lxk_xxxxxxxxxxxxx",
130
+ "baseUrl": "https://api.lexq.io/api/v1/partners",
131
+ "format": "json"
132
+ }
133
+ ```
134
+
135
+ ## Development
136
+
137
+ ```bash
138
+ git clone https://github.com/sanghyunp-dev/lexq-cli.git
139
+ cd lexq-cli
140
+ pnpm install
141
+ pnpm build
142
+ pnpm start -- groups list
143
+ ```
144
+
145
+ ```bash
146
+ pnpm typecheck # Type check
147
+ pnpm lint # ESLint
148
+ bash tests/e2e.sh # E2E tests (requires API key)
149
+ ```
150
+
151
+ ## License
152
+
153
+ [Apache-2.0](LICENSE)