You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CLAUDE.md
+63-4Lines changed: 63 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,10 @@
1
1
# CLAUDE.md
2
2
3
-
This file provides guidance to Claude Code when working in this monorepo.
3
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
4
5
5
## Project
6
6
7
-
`gds-core` — monorepo for the Generalized Dynamical Systems ecosystem. Contains four packages managed as a uv workspace.
7
+
`gds-core` — monorepo for the Generalized Dynamical Systems ecosystem. Typed compositional specifications for complex systems, grounded in [GDS theory](https://doi.org/10.57938/e8d456ea-d975-4111-ac41-052ce73cb0cc). Four packages managed as a uv workspace.
Domain-neutral engine. Blocks with bidirectional typed interfaces, composed via four operators (`>>`, `|`, `.feedback()`, `.loop()`). A 3-stage compiler flattens composition trees into flat IR (blocks + wirings + hierarchy). Six generic verification checks (G-001..G-006) validate structural properties on the IR.
Where GDS theory lives. `GDSSpec` is the central registry for types, spaces, entities, blocks, wirings, and parameters. `project_canonical()` derives the formal `h = f ∘ g` decomposition. Seven semantic checks (SC-001..SC-007) validate domain properties on the spec.
71
+
72
+
These layers are loosely coupled — you can use the composition algebra without `GDSSpec`, and `GDSSpec` does not depend on the compiler.
73
+
74
+
### Two Type Systems
75
+
76
+
These coexist at different levels:
77
+
78
+
1.**Token-based** (`types/tokens.py`) — structural set matching at composition/wiring time. Port names auto-tokenize (split on spaces, lowercase → frozenset). The `>>` operator and auto-wiring use token overlap for matching. `"Heater Command"` auto-wires to `"Command Signal"` because they share the token `"command"`.
79
+
80
+
2.**TypeDef-based** (`types/typedef.py`) — runtime validation at the data level. TypeDef wraps a Python type + optional constraint predicate. Used by Spaces and Entities to validate actual data values. Never called during compilation.
81
+
82
+
### Compilation Pipeline
83
+
84
+
```
85
+
Block tree → flatten() → list[AtomicBlock] → block_compiler() → list[BlockIR]
`gds-games` subclasses `AtomicBlock` as `OpenGame`, adding a `Signature(Interface)` that maps game theory's `(X, Y, R, S)` to GDS's `(forward_in, forward_out, backward_in, backward_out)`. It adds 6 atomic game types, a `Pattern` container (analogous to `GDSSpec`), its own compiler (`compile_to_ir()` → `PatternIR`), and 13 OGS-specific verification checks.
94
+
95
+
The critical interop bridge is `PatternIR.to_system_ir()` — projects OGS IR to GDS `SystemIR`, enabling reuse of all 6 generic GDS verification checks without duplication. OGS also adds `CorecursiveLoop` (`.corecursive()`), which maps to GDS `TemporalLoop` at the IR level.
96
+
97
+
### Block Hierarchy (Sealed)
98
+
99
+
Only 5 concrete Block types exist — domain packages subclass `AtomicBlock` only, never the operators:
-`ParallelComposition` (`|`) — independent, no validation
103
+
-`FeedbackLoop` (`.feedback()`) — backward within timestep, CONTRAVARIANT
104
+
-`TemporalLoop` (`.loop()`) — forward across timesteps, COVARIANT only
105
+
106
+
Block roles (`BoundaryAction`, `Policy`, `Mechanism`, `ControlAction`) subclass `AtomicBlock` and enforce constraints at construction via `@model_validator`.
107
+
108
+
### Verification: Two Registries
109
+
110
+
Both use the pluggable pattern: `Callable[[T], list[Finding]]`.
111
+
112
+
-**Generic checks (G-001..G-006)** operate on `SystemIR` — structural topology only
113
+
-**Semantic checks (SC-001..SC-007)** operate on `GDSSpec` — domain properties (completeness, determinism, reachability, type safety, parameter references, canonical wellformedness)
114
+
61
115
### Key Conventions
62
116
63
-
- All data models are Pydantic v2 BaseModel
117
+
- All data models are Pydantic v2 `BaseModel` — frozen for value objects, mutable for registries
118
+
-`@model_validator(mode="after")` returning `Self` for construction-time invariant enforcement
64
119
- Absolute imports only (never relative)
65
-
- Ruff config inherited from root (line-length 88)
120
+
-`TYPE_CHECKING` guard in `blocks/base.py` to break circular dependency with `blocks/composition.py`
121
+
- Ruff config at root: line-length 88, rules `E, W, F, I, UP, B, SIM, TCH, RUF`
122
+
- Tags (`Tagged` mixin) are inert — stripped at compile time, never affect verification
123
+
- Parameters (Θ) are structural metadata — GDS never assigns values or binds them
124
+
-`GDSSpec.collect()` type-dispatches TypeDef/Space/Entity/Block/ParameterDef; SpecWiring stays explicit via `register_wiring()`
66
125
- Each package published independently to PyPI via tag-based workflow (`gds-framework/v0.3.1`)
0 commit comments