kisch 1.0.2 → 1.0.3

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.
Files changed (3) hide show
  1. package/DSL.md +209 -0
  2. package/README.md +2 -0
  3. package/package.json +1 -1
package/DSL.md ADDED
@@ -0,0 +1,209 @@
1
+ # Kisch Schematic Script Reference
2
+
3
+ ## Overview
4
+
5
+ A Kisch schematic is defined as a JavaScript module exporting a default async function:
6
+
7
+ ```js
8
+ export default async function (sch, defines) {
9
+ // schematic definition here
10
+ }
11
+ ```
12
+
13
+ The function receives:
14
+
15
+ - `sch` — the schematic builder API
16
+ - `defines` — an object containing CLI-defined parameters
17
+
18
+ The script declares symbols (components) and connects their pins using wires or net labels.
19
+
20
+ # Core Concepts
21
+
22
+ ## 1. Declaring a Component
23
+
24
+ Use:
25
+
26
+ ```js
27
+ sch.declare(reference, options)
28
+ ```
29
+
30
+ ### Parameters
31
+
32
+ - `reference` (string)
33
+ The component reference (e.g., `"R1"`, `"J1"`).
34
+
35
+ - `options` (object)
36
+ - `symbol` (string, required) — KiCad symbol library identifier
37
+ - `footprint` (string, optional) — KiCad footprint library identifier
38
+
39
+ ### Example
40
+
41
+ ```js
42
+ let J1 = sch.declare("J1", {
43
+ symbol: "Connector_Generic:Conn_01x02",
44
+ footprint: "Connector_PinHeader_2.54mm:PinHeader_1x02_P2.54mm_Horizontal"
45
+ });
46
+ ```
47
+
48
+ `declare()` returns a symbol object.
49
+
50
+ ## 2. Accessing an Existing Symbol
51
+
52
+ If you did not store the return value from `declare`, you can retrieve it later:
53
+
54
+ ```js
55
+ sch.sym("J1")
56
+ ```
57
+
58
+ Returns the symbol instance with reference `"J1"`.
59
+
60
+ ## 3. Working with Pins
61
+
62
+ Access a pin using:
63
+
64
+ ```js
65
+ symbol.pin(pinNumber)
66
+ ```
67
+
68
+ Example:
69
+
70
+ ```js
71
+ J1.pin(2)
72
+ ```
73
+
74
+ Returns a pin object.
75
+
76
+ ## 4. Connecting Pins
77
+
78
+ `connect()` must always be called on a pin object.
79
+
80
+ It accepts exactly **two argument types**:
81
+
82
+ - A string → connect to a named net (via net label)
83
+ - A pin object → connect directly to another pin (via wire)
84
+
85
+ No other argument types are supported.
86
+
87
+ ### A) Connecting to a Net (String Argument)
88
+
89
+ ```js
90
+ J1.pin(2).connect("GND");
91
+ ```
92
+
93
+ Behavior:
94
+
95
+ - A net label with the given name is created next to the pin (if not already present at that location).
96
+ - The pin is connected to that net label.
97
+ - The connection is implemented as a 0-length wire between the pin and the label.
98
+ - Multiple pins using the same string connect electrically through that net name.
99
+
100
+ Important:
101
+
102
+ - This explicitly creates or uses a net label in the schematic.
103
+ - This does not implicitly merge abstract nets.
104
+ - If you want a named signal, use a string.
105
+
106
+ ### B) Connecting to Another Pin (Pin Object Argument)
107
+
108
+ ```js
109
+ J2.pin(1).connect(J1.pin(2));
110
+ ```
111
+
112
+ Behavior:
113
+
114
+ - A wire is created directly between the two pins.
115
+ - No net label is created automatically.
116
+ - This represents a physical wire in the schematic.
117
+
118
+ Important:
119
+
120
+ - Connecting pin-to-pin does NOT create a named net.
121
+ - If you want a named net, you must connect using a string.
122
+
123
+ ## 5. Conditional Configuration via `defines`
124
+
125
+ Scripts can adapt based on CLI-defined values.
126
+
127
+ ### Passing Defines from CLI
128
+
129
+ ```
130
+ kisch schema.kicad_sch -s script.js -Dtest=123 --define test2=456
131
+ ```
132
+
133
+ Both forms are equivalent:
134
+
135
+ - `-Dkey=value`
136
+ - `--define key=value`
137
+
138
+ Inside the script:
139
+
140
+ ```js
141
+ defines.test // "123"
142
+ defines.test2 // "456"
143
+ ```
144
+
145
+ All define values are strings.
146
+
147
+ ### Example Usage
148
+
149
+ ```js
150
+ if (defines.test === "123") {
151
+ sch.declare("J6", {
152
+ symbol: "Connector_Generic:Conn_01x04"
153
+ });
154
+ }
155
+ ```
156
+
157
+ This enables variant-based schematic generation.
158
+
159
+ # Minimal Complete Example
160
+
161
+ ```js
162
+ export default async function (sch, defines) {
163
+
164
+ let J1 = sch.declare("J1", {
165
+ symbol: "Connector_Generic:Conn_01x02",
166
+ footprint: "Connector_PinHeader_2.54mm:PinHeader_1x02_P2.54mm_Horizontal"
167
+ });
168
+
169
+ J1.pin(2).connect("GND");
170
+
171
+ let J5 = sch.declare("J5", {
172
+ symbol: "Connector_Generic:Conn_01x04"
173
+ });
174
+
175
+ J5.pin(1).connect(J1.pin(1));
176
+
177
+ if (defines.test === "123") {
178
+ sch.declare("J6", {
179
+ symbol: "Connector_Generic:Conn_01x04"
180
+ });
181
+ }
182
+ }
183
+ ```
184
+
185
+ # Design Constraints (Important for AI Generation)
186
+
187
+ When generating Kisch scripts:
188
+
189
+ - Always export a default async function.
190
+ - Always use `sch.declare()` to create components.
191
+ - Always access pins using `.pin(n)`.
192
+ - Only use `.connect()` with:
193
+ - a string (net name), or
194
+ - a pin object.
195
+ - Do not assume additional API methods unless explicitly documented.
196
+ - All `defines` values are strings.
197
+ - Connecting to a string creates a net label.
198
+ - Connecting to a pin creates a direct wire.
199
+
200
+ # Philosophy
201
+
202
+ Kisch treats schematics as deterministic, programmable structures.
203
+
204
+ - Wires are explicit.
205
+ - Net labels are explicit.
206
+ - There is no hidden net merging.
207
+ - Behavior depends strictly on argument type.
208
+
209
+ This makes schematic generation reproducible, scriptable, and suitable for AI-assisted workflows.
package/README.md CHANGED
@@ -125,6 +125,8 @@ A script typically:
125
125
 
126
126
  Scripts do **not** contain geometric layout information; placement is determined by KiCad or kisch heuristics.
127
127
 
128
+ Full scripting reference: [DSL.md](./DSL.md)
129
+
128
130
  ### Example Script
129
131
 
130
132
  ```js
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kisch",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "",
5
5
  "repository": {
6
6
  "type": "git",