@run-iq/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/LICENSE +21 -0
- package/README.md +114 -0
- package/bin/run-iq.js +2 -0
- package/dist/index.cjs +285 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +24 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +253 -0
- package/dist/index.js.map +1 -0
- package/package.json +61 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Abdou-Raouf ATARMLA
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# @run-iq/cli
|
|
2
|
+
|
|
3
|
+
CLI tool for testing and debugging **Parametric Policy Engine (PPE)** rules locally.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -g @run-iq/cli
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Commands
|
|
12
|
+
|
|
13
|
+
### `run-iq evaluate`
|
|
14
|
+
|
|
15
|
+
Evaluate rules against input data.
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
run-iq evaluate --rules rules.json --input input.json [--format json|table|compact] [--dry-run] [--strict]
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
**Options:**
|
|
22
|
+
|
|
23
|
+
| Option | Default | Description |
|
|
24
|
+
|--------|---------|-------------|
|
|
25
|
+
| `--rules <path>` | required | Path to rules JSON file |
|
|
26
|
+
| `--input <path>` | required | Path to input JSON file |
|
|
27
|
+
| `--format <fmt>` | `table` | Output format: `json`, `table`, `compact` |
|
|
28
|
+
| `--dry-run` | `true` | Run without snapshot persistence |
|
|
29
|
+
| `--strict` | `false` | Enable strict mode |
|
|
30
|
+
|
|
31
|
+
**Example:**
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
run-iq evaluate --rules ./rules.json --input ./input.json --format json
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### `run-iq validate`
|
|
38
|
+
|
|
39
|
+
Validate rule structure (required fields, checksum, types).
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
run-iq validate --rules rules.json [--format json|table|compact]
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
**Example:**
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
run-iq validate --rules ./rules.json
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Output:
|
|
52
|
+
```
|
|
53
|
+
=== Rule Validation ===
|
|
54
|
+
[OK ] rule-irpp-2024
|
|
55
|
+
[OK ] rule-tva-2024
|
|
56
|
+
[FAIL] rule-bad
|
|
57
|
+
- checksum must be a non-empty string
|
|
58
|
+
2/3 rules valid
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## File formats
|
|
62
|
+
|
|
63
|
+
### rules.json
|
|
64
|
+
|
|
65
|
+
```json
|
|
66
|
+
[
|
|
67
|
+
{
|
|
68
|
+
"id": "rule-1",
|
|
69
|
+
"version": 1,
|
|
70
|
+
"model": "FLAT_RATE",
|
|
71
|
+
"params": { "rate": 0.18, "base": "grossSalary" },
|
|
72
|
+
"priority": 1,
|
|
73
|
+
"effectiveFrom": "2024-01-01T00:00:00.000Z",
|
|
74
|
+
"effectiveUntil": null,
|
|
75
|
+
"tags": ["togo"],
|
|
76
|
+
"checksum": "abc123"
|
|
77
|
+
}
|
|
78
|
+
]
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### input.json
|
|
82
|
+
|
|
83
|
+
```json
|
|
84
|
+
{
|
|
85
|
+
"requestId": "req-001",
|
|
86
|
+
"data": { "grossSalary": 2500000 },
|
|
87
|
+
"meta": { "tenantId": "tenant-1" }
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Exit codes
|
|
92
|
+
|
|
93
|
+
| Code | Meaning |
|
|
94
|
+
|------|---------|
|
|
95
|
+
| 0 | Success |
|
|
96
|
+
| 1 | Evaluation or validation error |
|
|
97
|
+
| 2 | File not found or parse error |
|
|
98
|
+
|
|
99
|
+
## Programmatic usage
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
import { createCli } from '@run-iq/cli';
|
|
103
|
+
|
|
104
|
+
const cli = createCli({
|
|
105
|
+
stdout: (msg) => console.log(msg),
|
|
106
|
+
stderr: (msg) => console.error(msg),
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
await cli.parseAsync(['node', 'run-iq', 'evaluate', '--rules', 'r.json', '--input', 'i.json']);
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## License
|
|
113
|
+
|
|
114
|
+
MIT — Abdou-Raouf ATARMLA
|
package/bin/run-iq.js
ADDED
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
createCli: () => createCli,
|
|
24
|
+
formatResult: () => formatResult,
|
|
25
|
+
formatValidation: () => formatValidation,
|
|
26
|
+
loadInput: () => loadInput,
|
|
27
|
+
loadRules: () => loadRules,
|
|
28
|
+
run: () => run
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(index_exports);
|
|
31
|
+
|
|
32
|
+
// src/cli.ts
|
|
33
|
+
var import_commander = require("commander");
|
|
34
|
+
|
|
35
|
+
// src/commands/evaluate.ts
|
|
36
|
+
var import_core2 = require("@run-iq/core");
|
|
37
|
+
|
|
38
|
+
// src/utils/loader.ts
|
|
39
|
+
var import_promises = require("fs/promises");
|
|
40
|
+
var import_node_path = require("path");
|
|
41
|
+
var import_core = require("@run-iq/core");
|
|
42
|
+
async function loadRules(filePath) {
|
|
43
|
+
const absolute = (0, import_node_path.resolve)(filePath);
|
|
44
|
+
const content = await (0, import_promises.readFile)(absolute, "utf-8");
|
|
45
|
+
const raw = JSON.parse(content);
|
|
46
|
+
if (!Array.isArray(raw)) {
|
|
47
|
+
throw new Error(`Rules file must contain a JSON array: ${filePath}`);
|
|
48
|
+
}
|
|
49
|
+
return (0, import_core.hydrateRules)(raw);
|
|
50
|
+
}
|
|
51
|
+
async function loadInput(filePath) {
|
|
52
|
+
const absolute = (0, import_node_path.resolve)(filePath);
|
|
53
|
+
const content = await (0, import_promises.readFile)(absolute, "utf-8");
|
|
54
|
+
const raw = JSON.parse(content);
|
|
55
|
+
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
|
|
56
|
+
throw new Error(`Input file must contain a JSON object: ${filePath}`);
|
|
57
|
+
}
|
|
58
|
+
const meta = raw["meta"];
|
|
59
|
+
const input = {
|
|
60
|
+
requestId: raw["requestId"],
|
|
61
|
+
data: raw["data"] ?? {},
|
|
62
|
+
meta: {
|
|
63
|
+
tenantId: meta?.["tenantId"] ?? "",
|
|
64
|
+
userId: meta?.["userId"],
|
|
65
|
+
tags: meta?.["tags"],
|
|
66
|
+
context: meta?.["context"],
|
|
67
|
+
effectiveDate: meta?.["effectiveDate"] ? new Date(meta["effectiveDate"]) : void 0
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
return input;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// src/utils/formatter.ts
|
|
74
|
+
function formatResult(result, format) {
|
|
75
|
+
switch (format) {
|
|
76
|
+
case "json":
|
|
77
|
+
return formatJson(result);
|
|
78
|
+
case "compact":
|
|
79
|
+
return formatCompact(result);
|
|
80
|
+
case "table":
|
|
81
|
+
default:
|
|
82
|
+
return formatTable(result);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function formatJson(result) {
|
|
86
|
+
return JSON.stringify(result, null, 2);
|
|
87
|
+
}
|
|
88
|
+
function formatCompact(result) {
|
|
89
|
+
const parts = [
|
|
90
|
+
`requestId: ${result.requestId}`,
|
|
91
|
+
`value: ${String(result.value)}`,
|
|
92
|
+
`applied: ${result.appliedRules.length}`,
|
|
93
|
+
`skipped: ${result.skippedRules.length}`,
|
|
94
|
+
`duration: ${result.trace.totalDurationMs}ms`
|
|
95
|
+
];
|
|
96
|
+
return parts.join(" | ");
|
|
97
|
+
}
|
|
98
|
+
function formatTable(result) {
|
|
99
|
+
const lines = [];
|
|
100
|
+
lines.push("=== Evaluation Result ===");
|
|
101
|
+
lines.push(`Request ID : ${result.requestId}`);
|
|
102
|
+
lines.push(`Value : ${String(result.value)}`);
|
|
103
|
+
lines.push(`Engine : ${result.engineVersion}`);
|
|
104
|
+
lines.push(`Duration : ${result.trace.totalDurationMs}ms`);
|
|
105
|
+
lines.push("");
|
|
106
|
+
if (result.breakdown.length > 0) {
|
|
107
|
+
lines.push("--- Breakdown ---");
|
|
108
|
+
for (const item of result.breakdown) {
|
|
109
|
+
const label = item.label ? ` (${item.label})` : "";
|
|
110
|
+
lines.push(` [${item.ruleId}] ${item.modelUsed}${label} => ${String(item.contribution)}`);
|
|
111
|
+
}
|
|
112
|
+
lines.push("");
|
|
113
|
+
}
|
|
114
|
+
if (result.skippedRules.length > 0) {
|
|
115
|
+
lines.push("--- Skipped ---");
|
|
116
|
+
for (const skip of result.skippedRules) {
|
|
117
|
+
lines.push(` [${skip.rule.id}] ${skip.reason}`);
|
|
118
|
+
}
|
|
119
|
+
lines.push("");
|
|
120
|
+
}
|
|
121
|
+
if (result.trace.steps.length > 0) {
|
|
122
|
+
lines.push("--- Trace ---");
|
|
123
|
+
for (const step of result.trace.steps) {
|
|
124
|
+
const dsl = step.dslUsed ? ` (dsl: ${step.dslUsed})` : "";
|
|
125
|
+
lines.push(
|
|
126
|
+
` [${step.ruleId}] condition=${String(step.conditionResult)} model=${step.modelUsed} => ${String(step.contribution)} (${step.durationMs}ms)${dsl}`
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return lines.join("\n");
|
|
131
|
+
}
|
|
132
|
+
function formatValidation(entries, format) {
|
|
133
|
+
switch (format) {
|
|
134
|
+
case "json":
|
|
135
|
+
return JSON.stringify(entries, null, 2);
|
|
136
|
+
case "compact":
|
|
137
|
+
return entries.map((e) => `${e.ruleId}: ${e.status}`).join(" | ");
|
|
138
|
+
case "table":
|
|
139
|
+
default:
|
|
140
|
+
return formatValidationTable(entries);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
function formatValidationTable(entries) {
|
|
144
|
+
const lines = ["=== Rule Validation ==="];
|
|
145
|
+
for (const entry of entries) {
|
|
146
|
+
const mark = entry.status === "OK" ? "OK " : "FAIL";
|
|
147
|
+
lines.push(` [${mark}] ${entry.ruleId}`);
|
|
148
|
+
if (entry.errors && entry.errors.length > 0) {
|
|
149
|
+
for (const err of entry.errors) {
|
|
150
|
+
lines.push(` - ${err}`);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
const passed = entries.filter((e) => e.status === "OK").length;
|
|
155
|
+
lines.push("");
|
|
156
|
+
lines.push(`${passed}/${entries.length} rules valid`);
|
|
157
|
+
return lines.join("\n");
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// src/commands/evaluate.ts
|
|
161
|
+
function registerEvaluateCommand(program, writer) {
|
|
162
|
+
program.command("evaluate").description("Evaluate rules against input data").requiredOption("--rules <path>", "Path to rules JSON file").requiredOption("--input <path>", "Path to input JSON file").option("--format <format>", "Output format: json, table, compact", "table").option("--dry-run", "Run without snapshot persistence", true).option("--strict", "Enable strict mode", false).action(
|
|
163
|
+
async (options) => {
|
|
164
|
+
try {
|
|
165
|
+
const rules = await loadRules(options.rules);
|
|
166
|
+
const input = await loadInput(options.input);
|
|
167
|
+
const engine = new import_core2.PPEEngine({
|
|
168
|
+
plugins: [],
|
|
169
|
+
dsls: [],
|
|
170
|
+
strict: options.strict,
|
|
171
|
+
dryRun: options.dryRun
|
|
172
|
+
});
|
|
173
|
+
const result = await engine.evaluate(rules, input);
|
|
174
|
+
const output = formatResult(result, options.format);
|
|
175
|
+
writer.stdout(output);
|
|
176
|
+
} catch (error) {
|
|
177
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
178
|
+
writer.stderr(`Error: ${message}`);
|
|
179
|
+
process.exitCode = isFileError(error) ? 2 : 1;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
function isFileError(error) {
|
|
185
|
+
if (error instanceof Error) {
|
|
186
|
+
const code = error.code;
|
|
187
|
+
return code === "ENOENT" || code === "EACCES" || error.message.includes("JSON");
|
|
188
|
+
}
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// src/commands/validate.ts
|
|
193
|
+
var REQUIRED_FIELDS = [
|
|
194
|
+
"id",
|
|
195
|
+
"version",
|
|
196
|
+
"model",
|
|
197
|
+
"params",
|
|
198
|
+
"priority",
|
|
199
|
+
"effectiveFrom",
|
|
200
|
+
"tags",
|
|
201
|
+
"checksum"
|
|
202
|
+
];
|
|
203
|
+
function registerValidateCommand(program, writer) {
|
|
204
|
+
program.command("validate").description("Validate rule structure and checksum").requiredOption("--rules <path>", "Path to rules JSON file").option("--format <format>", "Output format: json, table, compact", "table").action(async (options) => {
|
|
205
|
+
try {
|
|
206
|
+
const rules = await loadRules(options.rules);
|
|
207
|
+
const entries = [];
|
|
208
|
+
for (const rule of rules) {
|
|
209
|
+
const errors = [];
|
|
210
|
+
for (const field of REQUIRED_FIELDS) {
|
|
211
|
+
if (rule[field] === void 0 || rule[field] === null) {
|
|
212
|
+
errors.push(`missing required field: ${field}`);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
if (typeof rule.id !== "string" || rule.id.length === 0) {
|
|
216
|
+
errors.push("id must be a non-empty string");
|
|
217
|
+
}
|
|
218
|
+
if (typeof rule.version !== "number") {
|
|
219
|
+
errors.push("version must be a number");
|
|
220
|
+
}
|
|
221
|
+
if (typeof rule.priority !== "number") {
|
|
222
|
+
errors.push("priority must be a number");
|
|
223
|
+
}
|
|
224
|
+
if (!(rule.effectiveFrom instanceof Date) || isNaN(rule.effectiveFrom.getTime())) {
|
|
225
|
+
errors.push("effectiveFrom must be a valid date");
|
|
226
|
+
}
|
|
227
|
+
if (typeof rule.checksum !== "string" || rule.checksum.length === 0) {
|
|
228
|
+
errors.push("checksum must be a non-empty string");
|
|
229
|
+
}
|
|
230
|
+
if (!Array.isArray(rule.tags)) {
|
|
231
|
+
errors.push("tags must be an array");
|
|
232
|
+
}
|
|
233
|
+
entries.push({
|
|
234
|
+
ruleId: rule.id,
|
|
235
|
+
status: errors.length === 0 ? "OK" : "FAIL",
|
|
236
|
+
errors: errors.length > 0 ? errors : void 0
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
const output = formatValidation(entries, options.format);
|
|
240
|
+
writer.stdout(output);
|
|
241
|
+
const hasFailures = entries.some((e) => e.status === "FAIL");
|
|
242
|
+
if (hasFailures) {
|
|
243
|
+
process.exitCode = 1;
|
|
244
|
+
}
|
|
245
|
+
} catch (error) {
|
|
246
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
247
|
+
writer.stderr(`Error: ${message}`);
|
|
248
|
+
process.exitCode = 2;
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// src/cli.ts
|
|
254
|
+
function createCli(writer) {
|
|
255
|
+
const program = new import_commander.Command();
|
|
256
|
+
program.name("run-iq").description("CLI for the Parametric Policy Engine (PPE)").version("0.1.0");
|
|
257
|
+
registerEvaluateCommand(program, writer);
|
|
258
|
+
registerValidateCommand(program, writer);
|
|
259
|
+
return program;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// src/index.ts
|
|
263
|
+
function run(argv) {
|
|
264
|
+
const writer = {
|
|
265
|
+
// eslint-disable-next-line no-console
|
|
266
|
+
stdout: (msg) => console.log(msg),
|
|
267
|
+
// eslint-disable-next-line no-console
|
|
268
|
+
stderr: (msg) => console.error(msg)
|
|
269
|
+
};
|
|
270
|
+
const cli = createCli(writer);
|
|
271
|
+
cli.parseAsync(argv).catch((err) => {
|
|
272
|
+
console.error(err instanceof Error ? err.message : String(err));
|
|
273
|
+
process.exitCode = 1;
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
277
|
+
0 && (module.exports = {
|
|
278
|
+
createCli,
|
|
279
|
+
formatResult,
|
|
280
|
+
formatValidation,
|
|
281
|
+
loadInput,
|
|
282
|
+
loadRules,
|
|
283
|
+
run
|
|
284
|
+
});
|
|
285
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/cli.ts","../src/commands/evaluate.ts","../src/utils/loader.ts","../src/utils/formatter.ts","../src/commands/validate.ts"],"sourcesContent":["export { createCli } from './cli.js';\nexport type { Writer } from './utils/loader.js';\nexport type { OutputFormat, ValidationEntry } from './utils/formatter.js';\nexport { formatResult, formatValidation } from './utils/formatter.js';\nexport { loadRules, loadInput } from './utils/loader.js';\n\nimport { createCli } from './cli.js';\n\nexport function run(argv: string[]): void {\n const writer = {\n // eslint-disable-next-line no-console\n stdout: (msg: string) => console.log(msg),\n // eslint-disable-next-line no-console\n stderr: (msg: string) => console.error(msg),\n };\n const cli = createCli(writer);\n cli.parseAsync(argv).catch((err: unknown) => {\n // eslint-disable-next-line no-console\n console.error(err instanceof Error ? err.message : String(err));\n process.exitCode = 1;\n });\n}\n","import { Command } from 'commander';\nimport { registerEvaluateCommand } from './commands/evaluate.js';\nimport { registerValidateCommand } from './commands/validate.js';\nimport type { Writer } from './utils/loader.js';\n\nexport function createCli(writer: Writer): Command {\n const program = new Command();\n\n program.name('run-iq').description('CLI for the Parametric Policy Engine (PPE)').version('0.1.0');\n\n registerEvaluateCommand(program, writer);\n registerValidateCommand(program, writer);\n\n return program;\n}\n","import type { Command } from 'commander';\nimport { PPEEngine } from '@run-iq/core';\nimport { loadRules, loadInput } from '../utils/loader.js';\nimport { formatResult } from '../utils/formatter.js';\nimport type { OutputFormat } from '../utils/formatter.js';\nimport type { Writer } from '../utils/loader.js';\n\nexport function registerEvaluateCommand(program: Command, writer: Writer): void {\n program\n .command('evaluate')\n .description('Evaluate rules against input data')\n .requiredOption('--rules <path>', 'Path to rules JSON file')\n .requiredOption('--input <path>', 'Path to input JSON file')\n .option('--format <format>', 'Output format: json, table, compact', 'table')\n .option('--dry-run', 'Run without snapshot persistence', true)\n .option('--strict', 'Enable strict mode', false)\n .action(\n async (options: {\n rules: string;\n input: string;\n format: string;\n dryRun: boolean;\n strict: boolean;\n }) => {\n try {\n const rules = await loadRules(options.rules);\n const input = await loadInput(options.input);\n\n const engine = new PPEEngine({\n plugins: [],\n dsls: [],\n strict: options.strict,\n dryRun: options.dryRun,\n });\n\n const result = await engine.evaluate(rules, input);\n const output = formatResult(result, options.format as OutputFormat);\n writer.stdout(output);\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n writer.stderr(`Error: ${message}`);\n process.exitCode = isFileError(error) ? 2 : 1;\n }\n },\n );\n}\n\nfunction isFileError(error: unknown): boolean {\n if (error instanceof Error) {\n const code = (error as NodeJS.ErrnoException).code;\n return code === 'ENOENT' || code === 'EACCES' || error.message.includes('JSON');\n }\n return false;\n}\n","import { readFile } from 'node:fs/promises';\nimport { resolve } from 'node:path';\nimport { hydrateRules } from '@run-iq/core';\nimport type { Rule, EvaluationInput } from '@run-iq/core';\n\nexport interface Writer {\n stdout(message: string): void;\n stderr(message: string): void;\n}\n\nexport async function loadRules(filePath: string): Promise<Rule[]> {\n const absolute = resolve(filePath);\n const content = await readFile(absolute, 'utf-8');\n const raw = JSON.parse(content) as Record<string, unknown>[];\n\n if (!Array.isArray(raw)) {\n throw new Error(`Rules file must contain a JSON array: ${filePath}`);\n }\n\n return hydrateRules(raw);\n}\n\nexport async function loadInput(filePath: string): Promise<EvaluationInput> {\n const absolute = resolve(filePath);\n const content = await readFile(absolute, 'utf-8');\n const raw = JSON.parse(content) as Record<string, unknown>;\n\n if (typeof raw !== 'object' || raw === null || Array.isArray(raw)) {\n throw new Error(`Input file must contain a JSON object: ${filePath}`);\n }\n\n const meta = raw['meta'] as Record<string, unknown> | undefined;\n\n const input: EvaluationInput = {\n requestId: raw['requestId'] as string,\n data: (raw['data'] as Record<string, unknown>) ?? {},\n meta: {\n tenantId: (meta?.['tenantId'] as string) ?? '',\n userId: meta?.['userId'] as string | undefined,\n tags: meta?.['tags'] as string[] | undefined,\n context: meta?.['context'] as Record<string, unknown> | undefined,\n effectiveDate: meta?.['effectiveDate']\n ? new Date(meta['effectiveDate'] as string)\n : undefined,\n },\n };\n\n return input;\n}\n","import type { EvaluationResult } from '@run-iq/core';\n\nexport type OutputFormat = 'json' | 'table' | 'compact';\n\nexport function formatResult(result: EvaluationResult, format: OutputFormat): string {\n switch (format) {\n case 'json':\n return formatJson(result);\n case 'compact':\n return formatCompact(result);\n case 'table':\n default:\n return formatTable(result);\n }\n}\n\nfunction formatJson(result: EvaluationResult): string {\n return JSON.stringify(result, null, 2);\n}\n\nfunction formatCompact(result: EvaluationResult): string {\n const parts: string[] = [\n `requestId: ${result.requestId}`,\n `value: ${String(result.value)}`,\n `applied: ${result.appliedRules.length}`,\n `skipped: ${result.skippedRules.length}`,\n `duration: ${result.trace.totalDurationMs}ms`,\n ];\n return parts.join(' | ');\n}\n\nfunction formatTable(result: EvaluationResult): string {\n const lines: string[] = [];\n\n lines.push('=== Evaluation Result ===');\n lines.push(`Request ID : ${result.requestId}`);\n lines.push(`Value : ${String(result.value)}`);\n lines.push(`Engine : ${result.engineVersion}`);\n lines.push(`Duration : ${result.trace.totalDurationMs}ms`);\n lines.push('');\n\n if (result.breakdown.length > 0) {\n lines.push('--- Breakdown ---');\n for (const item of result.breakdown) {\n const label = item.label ? ` (${item.label})` : '';\n lines.push(` [${item.ruleId}] ${item.modelUsed}${label} => ${String(item.contribution)}`);\n }\n lines.push('');\n }\n\n if (result.skippedRules.length > 0) {\n lines.push('--- Skipped ---');\n for (const skip of result.skippedRules) {\n lines.push(` [${skip.rule.id}] ${skip.reason}`);\n }\n lines.push('');\n }\n\n if (result.trace.steps.length > 0) {\n lines.push('--- Trace ---');\n for (const step of result.trace.steps) {\n const dsl = step.dslUsed ? ` (dsl: ${step.dslUsed})` : '';\n lines.push(\n ` [${step.ruleId}] condition=${String(step.conditionResult)} model=${step.modelUsed} => ${String(step.contribution)} (${step.durationMs}ms)${dsl}`,\n );\n }\n }\n\n return lines.join('\\n');\n}\n\nexport interface ValidationEntry {\n ruleId: string;\n status: 'OK' | 'FAIL';\n errors?: readonly string[] | undefined;\n}\n\nexport function formatValidation(entries: ValidationEntry[], format: OutputFormat): string {\n switch (format) {\n case 'json':\n return JSON.stringify(entries, null, 2);\n case 'compact':\n return entries.map((e) => `${e.ruleId}: ${e.status}`).join(' | ');\n case 'table':\n default:\n return formatValidationTable(entries);\n }\n}\n\nfunction formatValidationTable(entries: ValidationEntry[]): string {\n const lines: string[] = ['=== Rule Validation ==='];\n\n for (const entry of entries) {\n const mark = entry.status === 'OK' ? 'OK ' : 'FAIL';\n lines.push(` [${mark}] ${entry.ruleId}`);\n if (entry.errors && entry.errors.length > 0) {\n for (const err of entry.errors) {\n lines.push(` - ${err}`);\n }\n }\n }\n\n const passed = entries.filter((e) => e.status === 'OK').length;\n lines.push('');\n lines.push(`${passed}/${entries.length} rules valid`);\n\n return lines.join('\\n');\n}\n","import type { Command } from 'commander';\nimport { loadRules } from '../utils/loader.js';\nimport { formatValidation } from '../utils/formatter.js';\nimport type { OutputFormat, ValidationEntry } from '../utils/formatter.js';\nimport type { Writer } from '../utils/loader.js';\n\nconst REQUIRED_FIELDS = [\n 'id',\n 'version',\n 'model',\n 'params',\n 'priority',\n 'effectiveFrom',\n 'tags',\n 'checksum',\n] as const;\n\nexport function registerValidateCommand(program: Command, writer: Writer): void {\n program\n .command('validate')\n .description('Validate rule structure and checksum')\n .requiredOption('--rules <path>', 'Path to rules JSON file')\n .option('--format <format>', 'Output format: json, table, compact', 'table')\n .action(async (options: { rules: string; format: string }) => {\n try {\n const rules = await loadRules(options.rules);\n const entries: ValidationEntry[] = [];\n\n for (const rule of rules) {\n const errors: string[] = [];\n\n for (const field of REQUIRED_FIELDS) {\n if (rule[field] === undefined || rule[field] === null) {\n errors.push(`missing required field: ${field}`);\n }\n }\n\n if (typeof rule.id !== 'string' || rule.id.length === 0) {\n errors.push('id must be a non-empty string');\n }\n\n if (typeof rule.version !== 'number') {\n errors.push('version must be a number');\n }\n\n if (typeof rule.priority !== 'number') {\n errors.push('priority must be a number');\n }\n\n if (!(rule.effectiveFrom instanceof Date) || isNaN(rule.effectiveFrom.getTime())) {\n errors.push('effectiveFrom must be a valid date');\n }\n\n if (typeof rule.checksum !== 'string' || rule.checksum.length === 0) {\n errors.push('checksum must be a non-empty string');\n }\n\n if (!Array.isArray(rule.tags)) {\n errors.push('tags must be an array');\n }\n\n entries.push({\n ruleId: rule.id,\n status: errors.length === 0 ? 'OK' : 'FAIL',\n errors: errors.length > 0 ? errors : undefined,\n });\n }\n\n const output = formatValidation(entries, options.format as OutputFormat);\n writer.stdout(output);\n\n const hasFailures = entries.some((e) => e.status === 'FAIL');\n if (hasFailures) {\n process.exitCode = 1;\n }\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n writer.stderr(`Error: ${message}`);\n process.exitCode = 2;\n }\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,uBAAwB;;;ACCxB,IAAAA,eAA0B;;;ACD1B,sBAAyB;AACzB,uBAAwB;AACxB,kBAA6B;AAQ7B,eAAsB,UAAU,UAAm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,QAAyB;AACjD,QAAM,UAAU,IAAI,yBAAQ;AAE5B,UAAQ,KAAK,QAAQ,EAAE,YAAY,4CAA4C,EAAE,QAAQ,OAAO;AAEhG,0BAAwB,SAAS,MAAM;AACvC,0BAAwB,SAAS,MAAM;AAEvC,SAAO;AACT;;;ADNO,SAAS,IAAI,MAAsB;AACxC,QAAM,SAAS;AAAA;AAAA,IAEb,QAAQ,CAAC,QAAgB,QAAQ,IAAI,GAAG;AAAA;AAAA,IAExC,QAAQ,CAAC,QAAgB,QAAQ,MAAM,GAAG;AAAA,EAC5C;AACA,QAAM,MAAM,UAAU,MAAM;AAC5B,MAAI,WAAW,IAAI,EAAE,MAAM,CAAC,QAAiB;AAE3C,YAAQ,MAAM,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG,CAAC;AAC9D,YAAQ,WAAW;AAAA,EACrB,CAAC;AACH;","names":["import_core"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { EvaluationInput, Rule, EvaluationResult } from '@run-iq/core';
|
|
3
|
+
|
|
4
|
+
interface Writer {
|
|
5
|
+
stdout(message: string): void;
|
|
6
|
+
stderr(message: string): void;
|
|
7
|
+
}
|
|
8
|
+
declare function loadRules(filePath: string): Promise<Rule[]>;
|
|
9
|
+
declare function loadInput(filePath: string): Promise<EvaluationInput>;
|
|
10
|
+
|
|
11
|
+
declare function createCli(writer: Writer): Command;
|
|
12
|
+
|
|
13
|
+
type OutputFormat = 'json' | 'table' | 'compact';
|
|
14
|
+
declare function formatResult(result: EvaluationResult, format: OutputFormat): string;
|
|
15
|
+
interface ValidationEntry {
|
|
16
|
+
ruleId: string;
|
|
17
|
+
status: 'OK' | 'FAIL';
|
|
18
|
+
errors?: readonly string[] | undefined;
|
|
19
|
+
}
|
|
20
|
+
declare function formatValidation(entries: ValidationEntry[], format: OutputFormat): string;
|
|
21
|
+
|
|
22
|
+
declare function run(argv: string[]): void;
|
|
23
|
+
|
|
24
|
+
export { type OutputFormat, type ValidationEntry, type Writer, createCli, formatResult, formatValidation, loadInput, loadRules, run };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { EvaluationInput, Rule, EvaluationResult } from '@run-iq/core';
|
|
3
|
+
|
|
4
|
+
interface Writer {
|
|
5
|
+
stdout(message: string): void;
|
|
6
|
+
stderr(message: string): void;
|
|
7
|
+
}
|
|
8
|
+
declare function loadRules(filePath: string): Promise<Rule[]>;
|
|
9
|
+
declare function loadInput(filePath: string): Promise<EvaluationInput>;
|
|
10
|
+
|
|
11
|
+
declare function createCli(writer: Writer): Command;
|
|
12
|
+
|
|
13
|
+
type OutputFormat = 'json' | 'table' | 'compact';
|
|
14
|
+
declare function formatResult(result: EvaluationResult, format: OutputFormat): string;
|
|
15
|
+
interface ValidationEntry {
|
|
16
|
+
ruleId: string;
|
|
17
|
+
status: 'OK' | 'FAIL';
|
|
18
|
+
errors?: readonly string[] | undefined;
|
|
19
|
+
}
|
|
20
|
+
declare function formatValidation(entries: ValidationEntry[], format: OutputFormat): string;
|
|
21
|
+
|
|
22
|
+
declare function run(argv: string[]): void;
|
|
23
|
+
|
|
24
|
+
export { type OutputFormat, type ValidationEntry, type Writer, createCli, formatResult, formatValidation, loadInput, loadRules, run };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
// src/cli.ts
|
|
2
|
+
import { Command } from "commander";
|
|
3
|
+
|
|
4
|
+
// src/commands/evaluate.ts
|
|
5
|
+
import { PPEEngine } from "@run-iq/core";
|
|
6
|
+
|
|
7
|
+
// src/utils/loader.ts
|
|
8
|
+
import { readFile } from "fs/promises";
|
|
9
|
+
import { resolve } from "path";
|
|
10
|
+
import { hydrateRules } from "@run-iq/core";
|
|
11
|
+
async function loadRules(filePath) {
|
|
12
|
+
const absolute = resolve(filePath);
|
|
13
|
+
const content = await readFile(absolute, "utf-8");
|
|
14
|
+
const raw = JSON.parse(content);
|
|
15
|
+
if (!Array.isArray(raw)) {
|
|
16
|
+
throw new Error(`Rules file must contain a JSON array: ${filePath}`);
|
|
17
|
+
}
|
|
18
|
+
return hydrateRules(raw);
|
|
19
|
+
}
|
|
20
|
+
async function loadInput(filePath) {
|
|
21
|
+
const absolute = resolve(filePath);
|
|
22
|
+
const content = await readFile(absolute, "utf-8");
|
|
23
|
+
const raw = JSON.parse(content);
|
|
24
|
+
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
|
|
25
|
+
throw new Error(`Input file must contain a JSON object: ${filePath}`);
|
|
26
|
+
}
|
|
27
|
+
const meta = raw["meta"];
|
|
28
|
+
const input = {
|
|
29
|
+
requestId: raw["requestId"],
|
|
30
|
+
data: raw["data"] ?? {},
|
|
31
|
+
meta: {
|
|
32
|
+
tenantId: meta?.["tenantId"] ?? "",
|
|
33
|
+
userId: meta?.["userId"],
|
|
34
|
+
tags: meta?.["tags"],
|
|
35
|
+
context: meta?.["context"],
|
|
36
|
+
effectiveDate: meta?.["effectiveDate"] ? new Date(meta["effectiveDate"]) : void 0
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
return input;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// src/utils/formatter.ts
|
|
43
|
+
function formatResult(result, format) {
|
|
44
|
+
switch (format) {
|
|
45
|
+
case "json":
|
|
46
|
+
return formatJson(result);
|
|
47
|
+
case "compact":
|
|
48
|
+
return formatCompact(result);
|
|
49
|
+
case "table":
|
|
50
|
+
default:
|
|
51
|
+
return formatTable(result);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function formatJson(result) {
|
|
55
|
+
return JSON.stringify(result, null, 2);
|
|
56
|
+
}
|
|
57
|
+
function formatCompact(result) {
|
|
58
|
+
const parts = [
|
|
59
|
+
`requestId: ${result.requestId}`,
|
|
60
|
+
`value: ${String(result.value)}`,
|
|
61
|
+
`applied: ${result.appliedRules.length}`,
|
|
62
|
+
`skipped: ${result.skippedRules.length}`,
|
|
63
|
+
`duration: ${result.trace.totalDurationMs}ms`
|
|
64
|
+
];
|
|
65
|
+
return parts.join(" | ");
|
|
66
|
+
}
|
|
67
|
+
function formatTable(result) {
|
|
68
|
+
const lines = [];
|
|
69
|
+
lines.push("=== Evaluation Result ===");
|
|
70
|
+
lines.push(`Request ID : ${result.requestId}`);
|
|
71
|
+
lines.push(`Value : ${String(result.value)}`);
|
|
72
|
+
lines.push(`Engine : ${result.engineVersion}`);
|
|
73
|
+
lines.push(`Duration : ${result.trace.totalDurationMs}ms`);
|
|
74
|
+
lines.push("");
|
|
75
|
+
if (result.breakdown.length > 0) {
|
|
76
|
+
lines.push("--- Breakdown ---");
|
|
77
|
+
for (const item of result.breakdown) {
|
|
78
|
+
const label = item.label ? ` (${item.label})` : "";
|
|
79
|
+
lines.push(` [${item.ruleId}] ${item.modelUsed}${label} => ${String(item.contribution)}`);
|
|
80
|
+
}
|
|
81
|
+
lines.push("");
|
|
82
|
+
}
|
|
83
|
+
if (result.skippedRules.length > 0) {
|
|
84
|
+
lines.push("--- Skipped ---");
|
|
85
|
+
for (const skip of result.skippedRules) {
|
|
86
|
+
lines.push(` [${skip.rule.id}] ${skip.reason}`);
|
|
87
|
+
}
|
|
88
|
+
lines.push("");
|
|
89
|
+
}
|
|
90
|
+
if (result.trace.steps.length > 0) {
|
|
91
|
+
lines.push("--- Trace ---");
|
|
92
|
+
for (const step of result.trace.steps) {
|
|
93
|
+
const dsl = step.dslUsed ? ` (dsl: ${step.dslUsed})` : "";
|
|
94
|
+
lines.push(
|
|
95
|
+
` [${step.ruleId}] condition=${String(step.conditionResult)} model=${step.modelUsed} => ${String(step.contribution)} (${step.durationMs}ms)${dsl}`
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return lines.join("\n");
|
|
100
|
+
}
|
|
101
|
+
function formatValidation(entries, format) {
|
|
102
|
+
switch (format) {
|
|
103
|
+
case "json":
|
|
104
|
+
return JSON.stringify(entries, null, 2);
|
|
105
|
+
case "compact":
|
|
106
|
+
return entries.map((e) => `${e.ruleId}: ${e.status}`).join(" | ");
|
|
107
|
+
case "table":
|
|
108
|
+
default:
|
|
109
|
+
return formatValidationTable(entries);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
function formatValidationTable(entries) {
|
|
113
|
+
const lines = ["=== Rule Validation ==="];
|
|
114
|
+
for (const entry of entries) {
|
|
115
|
+
const mark = entry.status === "OK" ? "OK " : "FAIL";
|
|
116
|
+
lines.push(` [${mark}] ${entry.ruleId}`);
|
|
117
|
+
if (entry.errors && entry.errors.length > 0) {
|
|
118
|
+
for (const err of entry.errors) {
|
|
119
|
+
lines.push(` - ${err}`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
const passed = entries.filter((e) => e.status === "OK").length;
|
|
124
|
+
lines.push("");
|
|
125
|
+
lines.push(`${passed}/${entries.length} rules valid`);
|
|
126
|
+
return lines.join("\n");
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// src/commands/evaluate.ts
|
|
130
|
+
function registerEvaluateCommand(program, writer) {
|
|
131
|
+
program.command("evaluate").description("Evaluate rules against input data").requiredOption("--rules <path>", "Path to rules JSON file").requiredOption("--input <path>", "Path to input JSON file").option("--format <format>", "Output format: json, table, compact", "table").option("--dry-run", "Run without snapshot persistence", true).option("--strict", "Enable strict mode", false).action(
|
|
132
|
+
async (options) => {
|
|
133
|
+
try {
|
|
134
|
+
const rules = await loadRules(options.rules);
|
|
135
|
+
const input = await loadInput(options.input);
|
|
136
|
+
const engine = new PPEEngine({
|
|
137
|
+
plugins: [],
|
|
138
|
+
dsls: [],
|
|
139
|
+
strict: options.strict,
|
|
140
|
+
dryRun: options.dryRun
|
|
141
|
+
});
|
|
142
|
+
const result = await engine.evaluate(rules, input);
|
|
143
|
+
const output = formatResult(result, options.format);
|
|
144
|
+
writer.stdout(output);
|
|
145
|
+
} catch (error) {
|
|
146
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
147
|
+
writer.stderr(`Error: ${message}`);
|
|
148
|
+
process.exitCode = isFileError(error) ? 2 : 1;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
function isFileError(error) {
|
|
154
|
+
if (error instanceof Error) {
|
|
155
|
+
const code = error.code;
|
|
156
|
+
return code === "ENOENT" || code === "EACCES" || error.message.includes("JSON");
|
|
157
|
+
}
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// src/commands/validate.ts
|
|
162
|
+
var REQUIRED_FIELDS = [
|
|
163
|
+
"id",
|
|
164
|
+
"version",
|
|
165
|
+
"model",
|
|
166
|
+
"params",
|
|
167
|
+
"priority",
|
|
168
|
+
"effectiveFrom",
|
|
169
|
+
"tags",
|
|
170
|
+
"checksum"
|
|
171
|
+
];
|
|
172
|
+
function registerValidateCommand(program, writer) {
|
|
173
|
+
program.command("validate").description("Validate rule structure and checksum").requiredOption("--rules <path>", "Path to rules JSON file").option("--format <format>", "Output format: json, table, compact", "table").action(async (options) => {
|
|
174
|
+
try {
|
|
175
|
+
const rules = await loadRules(options.rules);
|
|
176
|
+
const entries = [];
|
|
177
|
+
for (const rule of rules) {
|
|
178
|
+
const errors = [];
|
|
179
|
+
for (const field of REQUIRED_FIELDS) {
|
|
180
|
+
if (rule[field] === void 0 || rule[field] === null) {
|
|
181
|
+
errors.push(`missing required field: ${field}`);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
if (typeof rule.id !== "string" || rule.id.length === 0) {
|
|
185
|
+
errors.push("id must be a non-empty string");
|
|
186
|
+
}
|
|
187
|
+
if (typeof rule.version !== "number") {
|
|
188
|
+
errors.push("version must be a number");
|
|
189
|
+
}
|
|
190
|
+
if (typeof rule.priority !== "number") {
|
|
191
|
+
errors.push("priority must be a number");
|
|
192
|
+
}
|
|
193
|
+
if (!(rule.effectiveFrom instanceof Date) || isNaN(rule.effectiveFrom.getTime())) {
|
|
194
|
+
errors.push("effectiveFrom must be a valid date");
|
|
195
|
+
}
|
|
196
|
+
if (typeof rule.checksum !== "string" || rule.checksum.length === 0) {
|
|
197
|
+
errors.push("checksum must be a non-empty string");
|
|
198
|
+
}
|
|
199
|
+
if (!Array.isArray(rule.tags)) {
|
|
200
|
+
errors.push("tags must be an array");
|
|
201
|
+
}
|
|
202
|
+
entries.push({
|
|
203
|
+
ruleId: rule.id,
|
|
204
|
+
status: errors.length === 0 ? "OK" : "FAIL",
|
|
205
|
+
errors: errors.length > 0 ? errors : void 0
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
const output = formatValidation(entries, options.format);
|
|
209
|
+
writer.stdout(output);
|
|
210
|
+
const hasFailures = entries.some((e) => e.status === "FAIL");
|
|
211
|
+
if (hasFailures) {
|
|
212
|
+
process.exitCode = 1;
|
|
213
|
+
}
|
|
214
|
+
} catch (error) {
|
|
215
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
216
|
+
writer.stderr(`Error: ${message}`);
|
|
217
|
+
process.exitCode = 2;
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// src/cli.ts
|
|
223
|
+
function createCli(writer) {
|
|
224
|
+
const program = new Command();
|
|
225
|
+
program.name("run-iq").description("CLI for the Parametric Policy Engine (PPE)").version("0.1.0");
|
|
226
|
+
registerEvaluateCommand(program, writer);
|
|
227
|
+
registerValidateCommand(program, writer);
|
|
228
|
+
return program;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// src/index.ts
|
|
232
|
+
function run(argv) {
|
|
233
|
+
const writer = {
|
|
234
|
+
// eslint-disable-next-line no-console
|
|
235
|
+
stdout: (msg) => console.log(msg),
|
|
236
|
+
// eslint-disable-next-line no-console
|
|
237
|
+
stderr: (msg) => console.error(msg)
|
|
238
|
+
};
|
|
239
|
+
const cli = createCli(writer);
|
|
240
|
+
cli.parseAsync(argv).catch((err) => {
|
|
241
|
+
console.error(err instanceof Error ? err.message : String(err));
|
|
242
|
+
process.exitCode = 1;
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
export {
|
|
246
|
+
createCli,
|
|
247
|
+
formatResult,
|
|
248
|
+
formatValidation,
|
|
249
|
+
loadInput,
|
|
250
|
+
loadRules,
|
|
251
|
+
run
|
|
252
|
+
};
|
|
253
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/cli.ts","../src/commands/evaluate.ts","../src/utils/loader.ts","../src/utils/formatter.ts","../src/commands/validate.ts","../src/index.ts"],"sourcesContent":["import { Command } from 'commander';\nimport { registerEvaluateCommand } from './commands/evaluate.js';\nimport { registerValidateCommand } from './commands/validate.js';\nimport type { Writer } from './utils/loader.js';\n\nexport function createCli(writer: Writer): Command {\n const program = new Command();\n\n program.name('run-iq').description('CLI for the Parametric Policy Engine (PPE)').version('0.1.0');\n\n registerEvaluateCommand(program, writer);\n registerValidateCommand(program, writer);\n\n return program;\n}\n","import type { Command } from 'commander';\nimport { PPEEngine } from '@run-iq/core';\nimport { loadRules, loadInput } from '../utils/loader.js';\nimport { formatResult } from '../utils/formatter.js';\nimport type { OutputFormat } from '../utils/formatter.js';\nimport type { Writer } from '../utils/loader.js';\n\nexport function registerEvaluateCommand(program: Command, writer: Writer): void {\n program\n .command('evaluate')\n .description('Evaluate rules against input data')\n .requiredOption('--rules <path>', 'Path to rules JSON file')\n .requiredOption('--input <path>', 'Path to input JSON file')\n .option('--format <format>', 'Output format: json, table, compact', 'table')\n .option('--dry-run', 'Run without snapshot persistence', true)\n .option('--strict', 'Enable strict mode', false)\n .action(\n async (options: {\n rules: string;\n input: string;\n format: string;\n dryRun: boolean;\n strict: boolean;\n }) => {\n try {\n const rules = await loadRules(options.rules);\n const input = await loadInput(options.input);\n\n const engine = new PPEEngine({\n plugins: [],\n dsls: [],\n strict: options.strict,\n dryRun: options.dryRun,\n });\n\n const result = await engine.evaluate(rules, input);\n const output = formatResult(result, options.format as OutputFormat);\n writer.stdout(output);\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n writer.stderr(`Error: ${message}`);\n process.exitCode = isFileError(error) ? 2 : 1;\n }\n },\n );\n}\n\nfunction isFileError(error: unknown): boolean {\n if (error instanceof Error) {\n const code = (error as NodeJS.ErrnoException).code;\n return code === 'ENOENT' || code === 'EACCES' || error.message.includes('JSON');\n }\n return false;\n}\n","import { readFile } from 'node:fs/promises';\nimport { resolve } from 'node:path';\nimport { hydrateRules } from '@run-iq/core';\nimport type { Rule, EvaluationInput } from '@run-iq/core';\n\nexport interface Writer {\n stdout(message: string): void;\n stderr(message: string): void;\n}\n\nexport async function loadRules(filePath: string): Promise<Rule[]> {\n const absolute = resolve(filePath);\n const content = await readFile(absolute, 'utf-8');\n const raw = JSON.parse(content) as Record<string, unknown>[];\n\n if (!Array.isArray(raw)) {\n throw new Error(`Rules file must contain a JSON array: ${filePath}`);\n }\n\n return hydrateRules(raw);\n}\n\nexport async function loadInput(filePath: string): Promise<EvaluationInput> {\n const absolute = resolve(filePath);\n const content = await readFile(absolute, 'utf-8');\n const raw = JSON.parse(content) as Record<string, unknown>;\n\n if (typeof raw !== 'object' || raw === null || Array.isArray(raw)) {\n throw new Error(`Input file must contain a JSON object: ${filePath}`);\n }\n\n const meta = raw['meta'] as Record<string, unknown> | undefined;\n\n const input: EvaluationInput = {\n requestId: raw['requestId'] as string,\n data: (raw['data'] as Record<string, unknown>) ?? {},\n meta: {\n tenantId: (meta?.['tenantId'] as string) ?? '',\n userId: meta?.['userId'] as string | undefined,\n tags: meta?.['tags'] as string[] | undefined,\n context: meta?.['context'] as Record<string, unknown> | undefined,\n effectiveDate: meta?.['effectiveDate']\n ? new Date(meta['effectiveDate'] as string)\n : undefined,\n },\n };\n\n return input;\n}\n","import type { EvaluationResult } from '@run-iq/core';\n\nexport type OutputFormat = 'json' | 'table' | 'compact';\n\nexport function formatResult(result: EvaluationResult, format: OutputFormat): string {\n switch (format) {\n case 'json':\n return formatJson(result);\n case 'compact':\n return formatCompact(result);\n case 'table':\n default:\n return formatTable(result);\n }\n}\n\nfunction formatJson(result: EvaluationResult): string {\n return JSON.stringify(result, null, 2);\n}\n\nfunction formatCompact(result: EvaluationResult): string {\n const parts: string[] = [\n `requestId: ${result.requestId}`,\n `value: ${String(result.value)}`,\n `applied: ${result.appliedRules.length}`,\n `skipped: ${result.skippedRules.length}`,\n `duration: ${result.trace.totalDurationMs}ms`,\n ];\n return parts.join(' | ');\n}\n\nfunction formatTable(result: EvaluationResult): string {\n const lines: string[] = [];\n\n lines.push('=== Evaluation Result ===');\n lines.push(`Request ID : ${result.requestId}`);\n lines.push(`Value : ${String(result.value)}`);\n lines.push(`Engine : ${result.engineVersion}`);\n lines.push(`Duration : ${result.trace.totalDurationMs}ms`);\n lines.push('');\n\n if (result.breakdown.length > 0) {\n lines.push('--- Breakdown ---');\n for (const item of result.breakdown) {\n const label = item.label ? ` (${item.label})` : '';\n lines.push(` [${item.ruleId}] ${item.modelUsed}${label} => ${String(item.contribution)}`);\n }\n lines.push('');\n }\n\n if (result.skippedRules.length > 0) {\n lines.push('--- Skipped ---');\n for (const skip of result.skippedRules) {\n lines.push(` [${skip.rule.id}] ${skip.reason}`);\n }\n lines.push('');\n }\n\n if (result.trace.steps.length > 0) {\n lines.push('--- Trace ---');\n for (const step of result.trace.steps) {\n const dsl = step.dslUsed ? ` (dsl: ${step.dslUsed})` : '';\n lines.push(\n ` [${step.ruleId}] condition=${String(step.conditionResult)} model=${step.modelUsed} => ${String(step.contribution)} (${step.durationMs}ms)${dsl}`,\n );\n }\n }\n\n return lines.join('\\n');\n}\n\nexport interface ValidationEntry {\n ruleId: string;\n status: 'OK' | 'FAIL';\n errors?: readonly string[] | undefined;\n}\n\nexport function formatValidation(entries: ValidationEntry[], format: OutputFormat): string {\n switch (format) {\n case 'json':\n return JSON.stringify(entries, null, 2);\n case 'compact':\n return entries.map((e) => `${e.ruleId}: ${e.status}`).join(' | ');\n case 'table':\n default:\n return formatValidationTable(entries);\n }\n}\n\nfunction formatValidationTable(entries: ValidationEntry[]): string {\n const lines: string[] = ['=== Rule Validation ==='];\n\n for (const entry of entries) {\n const mark = entry.status === 'OK' ? 'OK ' : 'FAIL';\n lines.push(` [${mark}] ${entry.ruleId}`);\n if (entry.errors && entry.errors.length > 0) {\n for (const err of entry.errors) {\n lines.push(` - ${err}`);\n }\n }\n }\n\n const passed = entries.filter((e) => e.status === 'OK').length;\n lines.push('');\n lines.push(`${passed}/${entries.length} rules valid`);\n\n return lines.join('\\n');\n}\n","import type { Command } from 'commander';\nimport { loadRules } from '../utils/loader.js';\nimport { formatValidation } from '../utils/formatter.js';\nimport type { OutputFormat, ValidationEntry } from '../utils/formatter.js';\nimport type { Writer } from '../utils/loader.js';\n\nconst REQUIRED_FIELDS = [\n 'id',\n 'version',\n 'model',\n 'params',\n 'priority',\n 'effectiveFrom',\n 'tags',\n 'checksum',\n] as const;\n\nexport function registerValidateCommand(program: Command, writer: Writer): void {\n program\n .command('validate')\n .description('Validate rule structure and checksum')\n .requiredOption('--rules <path>', 'Path to rules JSON file')\n .option('--format <format>', 'Output format: json, table, compact', 'table')\n .action(async (options: { rules: string; format: string }) => {\n try {\n const rules = await loadRules(options.rules);\n const entries: ValidationEntry[] = [];\n\n for (const rule of rules) {\n const errors: string[] = [];\n\n for (const field of REQUIRED_FIELDS) {\n if (rule[field] === undefined || rule[field] === null) {\n errors.push(`missing required field: ${field}`);\n }\n }\n\n if (typeof rule.id !== 'string' || rule.id.length === 0) {\n errors.push('id must be a non-empty string');\n }\n\n if (typeof rule.version !== 'number') {\n errors.push('version must be a number');\n }\n\n if (typeof rule.priority !== 'number') {\n errors.push('priority must be a number');\n }\n\n if (!(rule.effectiveFrom instanceof Date) || isNaN(rule.effectiveFrom.getTime())) {\n errors.push('effectiveFrom must be a valid date');\n }\n\n if (typeof rule.checksum !== 'string' || rule.checksum.length === 0) {\n errors.push('checksum must be a non-empty string');\n }\n\n if (!Array.isArray(rule.tags)) {\n errors.push('tags must be an array');\n }\n\n entries.push({\n ruleId: rule.id,\n status: errors.length === 0 ? 'OK' : 'FAIL',\n errors: errors.length > 0 ? errors : undefined,\n });\n }\n\n const output = formatValidation(entries, options.format as OutputFormat);\n writer.stdout(output);\n\n const hasFailures = entries.some((e) => e.status === 'FAIL');\n if (hasFailures) {\n process.exitCode = 1;\n }\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n writer.stderr(`Error: ${message}`);\n process.exitCode = 2;\n }\n });\n}\n","export { createCli } from './cli.js';\nexport type { Writer } from './utils/loader.js';\nexport type { OutputFormat, ValidationEntry } from './utils/formatter.js';\nexport { formatResult, formatValidation } from './utils/formatter.js';\nexport { loadRules, loadInput } from './utils/loader.js';\n\nimport { createCli } from './cli.js';\n\nexport function run(argv: string[]): void {\n const writer = {\n // eslint-disable-next-line no-console\n stdout: (msg: string) => console.log(msg),\n // eslint-disable-next-line no-console\n stderr: (msg: string) => console.error(msg),\n };\n const cli = createCli(writer);\n cli.parseAsync(argv).catch((err: unknown) => {\n // eslint-disable-next-line no-console\n console.error(err instanceof Error ? err.message : String(err));\n process.exitCode = 1;\n });\n}\n"],"mappings":";AAAA,SAAS,eAAe;;;ACCxB,SAAS,iBAAiB;;;ACD1B,SAAS,gBAAgB;AACzB,SAAS,eAAe;AACxB,SAAS,oBAAoB;AAQ7B,eAAsB,UAAU,UAAmC;AACjE,QAAM,WAAW,QAAQ,QAAQ;AACjC,QAAM,UAAU,MAAM,SAAS,UAAU,OAAO;AAChD,QAAM,MAAM,KAAK,MAAM,OAAO;AAE9B,MAAI,CAAC,MAAM,QAAQ,GAAG,GAAG;AACvB,UAAM,IAAI,MAAM,yCAAyC,QAAQ,EAAE;AAAA,EACrE;AAEA,SAAO,aAAa,GAAG;AACzB;AAEA,eAAsB,UAAU,UAA4C;AAC1E,QAAM,WAAW,QAAQ,QAAQ;AACjC,QAAM,UAAU,MAAM,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AG;AAAA,EAC5C;AACA,QAAM,MAAM,UAAU,MAAM;AAC5B,MAAI,WAAW,IAAI,EAAE,MAAM,CAAC,QAAiB;AAE3C,YAAQ,MAAM,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG,CAAC;AAC9D,YAAQ,WAAW;AAAA,EACrB,CAAC;AACH;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@run-iq/cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "PPE — CLI tool for testing and debugging Parametric Policy Engine rules",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"bin": {
|
|
10
|
+
"run-iq": "./bin/run-iq.js"
|
|
11
|
+
},
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"import": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"default": "./dist/index.js"
|
|
17
|
+
},
|
|
18
|
+
"require": {
|
|
19
|
+
"types": "./dist/index.d.cts",
|
|
20
|
+
"default": "./dist/index.cjs"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"files": ["dist", "bin"],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsup",
|
|
27
|
+
"test": "vitest run",
|
|
28
|
+
"typecheck": "tsc --noEmit",
|
|
29
|
+
"lint": "eslint src/ tests/ && prettier --check src/ tests/",
|
|
30
|
+
"lint:fix": "eslint src/ tests/ --fix && prettier --write src/ tests/",
|
|
31
|
+
"prepublishOnly": "npm run build && npm run typecheck && npm test && npm run lint"
|
|
32
|
+
},
|
|
33
|
+
"keywords": ["ppe", "policy-engine", "rules-engine", "parametric", "cli"],
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "https://github.com/Run-IQ/cli.git"
|
|
37
|
+
},
|
|
38
|
+
"homepage": "https://github.com/Run-IQ/cli#readme",
|
|
39
|
+
"bugs": {
|
|
40
|
+
"url": "https://github.com/Run-IQ/cli/issues"
|
|
41
|
+
},
|
|
42
|
+
"author": "Abdou-Raouf ATARMLA",
|
|
43
|
+
"license": "MIT",
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@run-iq/core": "^0.1.2",
|
|
46
|
+
"commander": "^12.0.0"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@types/node": "^20.11.0",
|
|
50
|
+
"@typescript-eslint/eslint-plugin": "^7.0.0",
|
|
51
|
+
"@typescript-eslint/parser": "^7.0.0",
|
|
52
|
+
"eslint": "^8.57.0",
|
|
53
|
+
"prettier": "^3.2.0",
|
|
54
|
+
"tsup": "^8.0.0",
|
|
55
|
+
"typescript": "^5.4.0",
|
|
56
|
+
"vitest": "^1.3.0"
|
|
57
|
+
},
|
|
58
|
+
"engines": {
|
|
59
|
+
"node": ">=20.0.0"
|
|
60
|
+
}
|
|
61
|
+
}
|