@ebowwa/logic-spec 1.0.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/README.md +125 -0
- package/REFERENCE.md +147 -0
- package/SPEC.md +783 -0
- package/dist/cli.js +6713 -0
- package/dist/index.js +6663 -0
- package/examples/minimal.yaml +49 -0
- package/examples/smart-glass-supervisor.yaml +330 -0
- package/examples/state-machine.yaml +106 -0
- package/package.json +50 -0
- package/schema.json +409 -0
package/README.md
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# Logic Specification Framework
|
|
2
|
+
|
|
3
|
+
A language-agnostic standard for extracting pure logic from implementations into `logic.yaml`.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
```yaml
|
|
8
|
+
# logic.yaml
|
|
9
|
+
meta:
|
|
10
|
+
spec_version: "1.0"
|
|
11
|
+
name: my-module
|
|
12
|
+
version: "1.0.0"
|
|
13
|
+
|
|
14
|
+
inputs:
|
|
15
|
+
- name: data
|
|
16
|
+
type: string
|
|
17
|
+
|
|
18
|
+
outputs:
|
|
19
|
+
- name: result
|
|
20
|
+
type: string
|
|
21
|
+
|
|
22
|
+
logic:
|
|
23
|
+
- id: process
|
|
24
|
+
type: transform
|
|
25
|
+
input: data
|
|
26
|
+
output: result
|
|
27
|
+
algorithm: |
|
|
28
|
+
1. Transform input
|
|
29
|
+
2. Return output
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Why
|
|
33
|
+
|
|
34
|
+
| Problem | Solution |
|
|
35
|
+
|----------|----------|
|
|
36
|
+
| AI agents drown in implementation details | Clean spec they can parse |
|
|
37
|
+
| Logic locked to one language | Portable across any runtime |
|
|
38
|
+
| Tests scattered in codebase | Assertions in the spec |
|
|
39
|
+
| State machines implicit | Explicit state definitions |
|
|
40
|
+
| Errors handled inconsistently | Declared failure modes |
|
|
41
|
+
|
|
42
|
+
## Documentation
|
|
43
|
+
|
|
44
|
+
| File | Purpose |
|
|
45
|
+
|------|---------|
|
|
46
|
+
| [skill.md](skill.md) | Skill definition and workflow |
|
|
47
|
+
| [SPEC.md](SPEC.md) | Full specification |
|
|
48
|
+
| [REFERENCE.md](REFERENCE.md) | Quick reference card |
|
|
49
|
+
| [schema.json](schema.json) | JSON Schema for validation |
|
|
50
|
+
| [examples/](examples/) | Example logic.yaml files |
|
|
51
|
+
|
|
52
|
+
## Examples
|
|
53
|
+
|
|
54
|
+
| Example | Demonstrates |
|
|
55
|
+
|---------|--------------|
|
|
56
|
+
| [minimal.yaml](examples/minimal.yaml) | Basic transform |
|
|
57
|
+
| [state-machine.yaml](examples/state-machine.yaml) | State machine |
|
|
58
|
+
| [smart-glass-supervisor.yaml](examples/smart-glass-supervisor.yaml) | Full complex system |
|
|
59
|
+
|
|
60
|
+
## Core Principles
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
┌────────────────────────┬─────────────────────────────────────────┐
|
|
64
|
+
│ Principle │ Why │
|
|
65
|
+
├────────────────────────┼─────────────────────────────────────────┤
|
|
66
|
+
│ I/O at edges │ Logic blocks are pure │
|
|
67
|
+
│ Algorithm as text │ Human-readable, language-agnostic │
|
|
68
|
+
│ Types explicit │ Schema validation │
|
|
69
|
+
│ State first-class │ State machines are explicit │
|
|
70
|
+
│ Constraints separate │ Performance not buried in code │
|
|
71
|
+
│ Failures declared │ Errors part of the contract │
|
|
72
|
+
│ Composable blocks │ Logic chains, not monoliths │
|
|
73
|
+
│ Versioned │ Spec can evolve without breaking │
|
|
74
|
+
│ Observable │ Metrics/logging hooks built-in │
|
|
75
|
+
│ Testable │ Assertions in spec │
|
|
76
|
+
└────────────────────────┴─────────────────────────────────────────┘
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Sections
|
|
80
|
+
|
|
81
|
+
| Section | Required | Purpose |
|
|
82
|
+
|---------|----------|---------|
|
|
83
|
+
| `meta` | ✅ | Identity, version |
|
|
84
|
+
| `inputs` | ✅ | Entry points |
|
|
85
|
+
| `outputs` | ✅ | Exit points |
|
|
86
|
+
| `types` | ❌ | Custom type definitions |
|
|
87
|
+
| `logic` | ✅ | Pure function blocks |
|
|
88
|
+
| `state` | ❌ | State machine |
|
|
89
|
+
| `flows` | ❌ | Logic composition |
|
|
90
|
+
| `failures` | ❌ | Error handling |
|
|
91
|
+
| `constraints` | ❌ | Performance bounds |
|
|
92
|
+
| `dependencies` | ❌ | External services |
|
|
93
|
+
| `observability` | ❌ | Metrics/logging |
|
|
94
|
+
| `tests` | ❌ | Built-in assertions |
|
|
95
|
+
|
|
96
|
+
## Validate
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
# Using ajv-cli
|
|
100
|
+
bunx ajv-cli validate -s schema.json -d logic.yaml
|
|
101
|
+
|
|
102
|
+
# Or using yajsv
|
|
103
|
+
bunx yajsv -s schema.json logic.yaml
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Use with AI
|
|
107
|
+
|
|
108
|
+
### Extract from code:
|
|
109
|
+
```
|
|
110
|
+
"Extract logic.yaml from this authentication module"
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Generate from spec:
|
|
114
|
+
```
|
|
115
|
+
"Generate TypeScript from this logic.yaml"
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Validate spec:
|
|
119
|
+
```
|
|
120
|
+
"Validate this logic.yaml against the spec"
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## License
|
|
124
|
+
|
|
125
|
+
MIT
|
package/REFERENCE.md
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# logic.yaml Quick Reference
|
|
2
|
+
|
|
3
|
+
## Minimal Valid Spec
|
|
4
|
+
|
|
5
|
+
```yaml
|
|
6
|
+
meta:
|
|
7
|
+
spec_version: "1.0"
|
|
8
|
+
name: my-module
|
|
9
|
+
version: "1.0.0"
|
|
10
|
+
|
|
11
|
+
inputs:
|
|
12
|
+
- name: data
|
|
13
|
+
type: any
|
|
14
|
+
|
|
15
|
+
outputs:
|
|
16
|
+
- name: result
|
|
17
|
+
type: any
|
|
18
|
+
|
|
19
|
+
logic:
|
|
20
|
+
- id: process
|
|
21
|
+
type: transform
|
|
22
|
+
input: data
|
|
23
|
+
output: result
|
|
24
|
+
algorithm: |
|
|
25
|
+
Transform data to result
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## All Sections
|
|
29
|
+
|
|
30
|
+
| Section | Required | Purpose |
|
|
31
|
+
|---------|----------|---------|
|
|
32
|
+
| `meta` | ✅ | Identity, version |
|
|
33
|
+
| `inputs` | ✅ | Entry points |
|
|
34
|
+
| `outputs` | ✅ | Exit points |
|
|
35
|
+
| `types` | ❌ | Custom type definitions |
|
|
36
|
+
| `logic` | ✅ | Pure function blocks |
|
|
37
|
+
| `state` | ❌ | State machine |
|
|
38
|
+
| `flows` | ❌ | Logic composition |
|
|
39
|
+
| `failures` | ❌ | Error handling |
|
|
40
|
+
| `constraints` | ❌ | Performance bounds |
|
|
41
|
+
| `dependencies` | ❌ | External services |
|
|
42
|
+
| `observability` | ❌ | Metrics/logging |
|
|
43
|
+
| `tests` | ❌ | Built-in assertions |
|
|
44
|
+
|
|
45
|
+
## Logic Block Types
|
|
46
|
+
|
|
47
|
+
| Type | Use For |
|
|
48
|
+
|------|---------|
|
|
49
|
+
| `transform` | Data transformation |
|
|
50
|
+
| `validate` | Input validation |
|
|
51
|
+
| `compute` | Calculations |
|
|
52
|
+
| `decision` | Conditionals, branching |
|
|
53
|
+
| `aggregate` | Combine multiple inputs |
|
|
54
|
+
| `inference` | AI/ML model calls |
|
|
55
|
+
| `query` | External data fetch |
|
|
56
|
+
|
|
57
|
+
## Primitives
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
string | number | boolean | array | object | null | any
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Test Matchers
|
|
64
|
+
|
|
65
|
+
| Matcher | Meaning |
|
|
66
|
+
|---------|---------|
|
|
67
|
+
| `value` | Exact match |
|
|
68
|
+
| `">= n"` | Greater/equal |
|
|
69
|
+
| `"<= n"` | Less/equal |
|
|
70
|
+
| `"type:Name"` | Type check |
|
|
71
|
+
| `"/regex/"` | Pattern match |
|
|
72
|
+
| `"!null"` | Not null |
|
|
73
|
+
| `"any"` | Just check presence |
|
|
74
|
+
|
|
75
|
+
## Recovery Strategies
|
|
76
|
+
|
|
77
|
+
| Strategy | Action |
|
|
78
|
+
|----------|--------|
|
|
79
|
+
| `retry` | Retry N times |
|
|
80
|
+
| `fallback` | Use alternative |
|
|
81
|
+
| `escalate` | Raise severity |
|
|
82
|
+
| `ignore` | Log and continue |
|
|
83
|
+
|
|
84
|
+
## State Machine
|
|
85
|
+
|
|
86
|
+
```yaml
|
|
87
|
+
state:
|
|
88
|
+
initial: state_a
|
|
89
|
+
transitions:
|
|
90
|
+
- from: state_a
|
|
91
|
+
to: state_b
|
|
92
|
+
trigger: event_name
|
|
93
|
+
action: logic_block_id # optional
|
|
94
|
+
guard: condition # optional
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Flows
|
|
98
|
+
|
|
99
|
+
```yaml
|
|
100
|
+
flows:
|
|
101
|
+
- name: my_flow
|
|
102
|
+
steps: [step1, step2, step3]
|
|
103
|
+
parallel: false # or true
|
|
104
|
+
timeout_ms: 5000
|
|
105
|
+
retry:
|
|
106
|
+
count: 3
|
|
107
|
+
backoff: exponential
|
|
108
|
+
delay_ms: 100
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Constraints
|
|
112
|
+
|
|
113
|
+
```yaml
|
|
114
|
+
constraints:
|
|
115
|
+
latency_max_ms: 500
|
|
116
|
+
throughput_min_rps: 1000
|
|
117
|
+
memory_limit_mb: 512
|
|
118
|
+
cpu_limit_percent: 80
|
|
119
|
+
availability_percent: 99.9
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Observability
|
|
123
|
+
|
|
124
|
+
```yaml
|
|
125
|
+
observability:
|
|
126
|
+
metrics:
|
|
127
|
+
- name: metric_name
|
|
128
|
+
type: counter | gauge | histogram
|
|
129
|
+
unit: ms
|
|
130
|
+
labels: [label1, label2]
|
|
131
|
+
logs:
|
|
132
|
+
level: info
|
|
133
|
+
include: [field1]
|
|
134
|
+
exclude: [sensitive_field]
|
|
135
|
+
traces:
|
|
136
|
+
enabled: true
|
|
137
|
+
sample_rate: 0.1
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Validation Checklist
|
|
141
|
+
|
|
142
|
+
- [ ] `meta`, `inputs`, `outputs`, `logic` present
|
|
143
|
+
- [ ] All IDs unique
|
|
144
|
+
- [ ] Type references resolved
|
|
145
|
+
- [ ] Input/output connectivity valid
|
|
146
|
+
- [ ] State transitions reference defined states
|
|
147
|
+
- [ ] Each flow has test coverage
|