@teqfw/di 2.0.2 → 2.0.4

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/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.0.4 - 2026-03-10 - LLM-first project positioning
4
+
5
+ - Reframed `README.md` around TeqFW architecture, runtime linking, and LLM-agent-oriented development.
6
+ - Rewrote `PHILOSOPHY.md` into a concise statement of TeqFW principles for human and machine-oriented development.
7
+ - Updated package version metadata to `2.0.4`.
8
+
9
+ ## 2.0.3 - 2026-03-07 - Package agent interface
10
+
11
+ - Added `ai/` to the published package file list.
12
+ - Updated package version metadata to `2.0.3`.
13
+
3
14
  ## 2.0.2 - 2026-03-05
4
15
 
5
16
  - Replaced `tsconfig.json` with `jsconfig.json` for JavaScript type-checking configuration.
package/README.md CHANGED
@@ -3,17 +3,141 @@
3
3
  ![npms.io](https://img.shields.io/npm/dm/@teqfw/di)
4
4
  ![jsdelivr](https://img.shields.io/jsdelivr/npm/hm/@teqfw/di)
5
5
 
6
- Deterministic runtime DI container for native ES modules.
6
+ **Runtime dependency linker for JavaScript applications designed for development with LLM agents.**
7
7
 
8
- `@teqfw/di` uses explicit dependency contracts (CDC strings) and module-level dependency descriptors (`__deps__`).
9
- It does not infer dependencies from constructor signatures.
8
+ `@teqfw/di` is the core infrastructure of the **Tequila Framework (TeqFW)** — an architectural approach for building web applications in which **humans design system architecture and specifications, while LLM agents generate and maintain the implementation.**
10
9
 
11
- ## Version Line
10
+ Instead of wiring modules through static imports, TeqFW applications declare **explicit dependency contracts**, and the container performs **deterministic runtime linking**.
12
11
 
13
- This branch is the v2 line.
12
+ The result is an application architecture that is easier to:
14
13
 
15
- - package version: `2.0.0`
16
- - changelog starts from `2.0.0`
14
+ - analyze
15
+ - generate
16
+ - refactor
17
+ - extend
18
+
19
+ — both for **human developers and AI agents**.
20
+
21
+ ## The Shift in Software Development
22
+
23
+ Large language models are becoming a permanent part of the development process.
24
+
25
+ However, most software architectures were designed for **human-written code**, not for **code generated and maintained by AI agents**.
26
+
27
+ Typical JavaScript applications rely on:
28
+
29
+ - static imports
30
+ - implicit dependency graphs
31
+ - tight coupling to file structure
32
+ - constructor-based dependency inference
33
+
34
+ These patterns work well for humans but are difficult for automated agents to reason about reliably.
35
+
36
+ **TeqFW proposes a different architecture.**
37
+
38
+ Modules declare **explicit dependency contracts**, and a runtime container resolves those contracts deterministically.
39
+
40
+ This transforms the dependency graph into something that can be **analyzed, generated and modified programmatically.**
41
+
42
+ ## What This Library Provides
43
+
44
+ `@teqfw/di` implements the runtime container that enables this architecture.
45
+
46
+ It provides:
47
+
48
+ - deterministic runtime linking of ES modules
49
+ - explicit dependency contracts (**CDC — Canonical Dependency Codes**)
50
+ - module dependency descriptors (`__deps__`)
51
+ - namespace-based module resolution
52
+ - runtime lifecycle management
53
+ - wrapper-based behavioral extensions
54
+
55
+ The container acts as a **runtime linker for JavaScript applications**.
56
+
57
+ ## Designed for Development with LLM Agents
58
+
59
+ When software is generated or maintained by LLM agents, several structural problems appear.
60
+
61
+ | Problem | Traditional Architecture | TeqFW Approach |
62
+ | ---------------- | ------------------------ | ------------------ |
63
+ | Dependencies | implicit imports | explicit contracts |
64
+ | Dependency graph | implicit | deterministic |
65
+ | Refactoring | fragile | stable |
66
+ | Testing | manual wiring | container driven |
67
+ | AI compatibility | accidental | intentional |
68
+
69
+ TeqFW structures the application so that **LLM agents can reliably understand and modify the system.**
70
+
71
+ ## Agent-Driven Implementation
72
+
73
+ Starting from version **2.0.0**, the source code of this library is **written primarily by Codex agents**.
74
+
75
+ The development workflow follows **specification-driven development**:
76
+
77
+ 1. The human architect defines **product specifications**
78
+ 2. LLM agents generate the implementation
79
+ 3. The generated code is reviewed and integrated
80
+
81
+ This workflow follows the **ADSM methodology (Agent-Driven Software Management)** developed by **Alex Gusev**.
82
+
83
+ Earlier versions of the library (<2.0.0) were written manually.
84
+ The current version demonstrates how software can be developed using **human-defined architecture and AI-generated code**.
85
+
86
+ ## Learn the Architecture (Interactive Onboarding)
87
+
88
+ Understanding this architecture can take time.
89
+
90
+ To make onboarding easier, an **interactive AI assistant** [is available](https://fly.wiredgeese.com/flancer/gpt/teqfw/guide/di/).
91
+
92
+ The assistant can explain:
93
+
94
+ - how the container works
95
+ - what Canonical Dependency Codes are
96
+ - how modules declare dependencies
97
+ - how runtime linking works
98
+ - how to integrate the library in real applications
99
+
100
+ The assistant acts as **interactive documentation** for the project.
101
+
102
+ Custom onboarding assistants like this can also be created **as a service** for other projects and libraries.
103
+
104
+ ## Agent Interface (Documentation for LLM Agents)
105
+
106
+ This package includes **agent interface documentation** intended for LLM agents that use the library as an npm dependency.
107
+
108
+ These documents are distributed inside the package in:
109
+
110
+ ```txt
111
+ ./ai/
112
+ ```
113
+
114
+ The files in this directory describe the **public interface of the package in an agent-friendly form**.
115
+
116
+ They explain:
117
+
118
+ - the container API
119
+ - dependency descriptors (`__deps__`)
120
+ - Canonical Dependency Codes (CDC)
121
+ - dependency resolution behavior
122
+ - integration patterns
123
+
124
+ Human developers typically read the README and source code, while **LLM agents can rely on the documentation in `./ai/`.**
125
+
126
+ ## Tequila Framework Philosophy
127
+
128
+ `@teqfw/di` is the core building block of the **Tequila Framework (TeqFW)** ecosystem.
129
+
130
+ TeqFW is based on several architectural principles:
131
+
132
+ - runtime late binding between components
133
+ - namespace-based module organization
134
+ - modular monolith architecture
135
+ - pure JavaScript without compilation
136
+ - system structures optimized for collaboration with LLM agents
137
+
138
+ Full philosophy:
139
+
140
+ `PHILOSOPHY.md`
17
141
 
18
142
  ## Installation
19
143
 
@@ -21,13 +145,13 @@ This branch is the v2 line.
21
145
  npm install @teqfw/di
22
146
  ```
23
147
 
24
- ## Quick Start
148
+ ## Quick Example
25
149
 
26
- ### 1. Define modules with `__deps__`
150
+ ### Define modules
27
151
 
28
152
  `src/App/Child.mjs`
29
153
 
30
- ```js
154
+ ```javascript
31
155
  export default function App_Child() {
32
156
  return { name: "child" };
33
157
  }
@@ -35,7 +159,7 @@ export default function App_Child() {
35
159
 
36
160
  `src/App/Root.mjs`
37
161
 
38
- ```js
162
+ ```javascript
39
163
  export const __deps__ = {
40
164
  child: "App_Child$",
41
165
  };
@@ -48,9 +172,9 @@ export default function App_Root({ child }) {
48
172
  }
49
173
  ```
50
174
 
51
- ### 2. Configure container in composition root
175
+ ### Configure container
52
176
 
53
- ```js
177
+ ```javascript
54
178
  import path from "node:path";
55
179
  import { fileURLToPath } from "node:url";
56
180
  import Container from "@teqfw/di";
@@ -59,68 +183,73 @@ const __filename = fileURLToPath(import.meta.url);
59
183
  const __dirname = path.dirname(__filename);
60
184
 
61
185
  const container = new Container();
186
+
62
187
  container.addNamespaceRoot("App_", path.resolve(__dirname, "./src/App"), ".mjs");
63
188
 
64
189
  const root = await container.get("App_Root$");
65
- console.log(root.name); // root
66
- console.log(root.child.name); // child
67
- console.log(Object.isFrozen(root)); // true
190
+
191
+ console.log(root.name);
192
+ console.log(root.child.name);
68
193
  ```
69
194
 
70
- ## Dependency Descriptor (`__deps__`)
195
+ The container:
71
196
 
72
- `__deps__` is a static module export:
197
+ - loads modules
198
+ - resolves dependency contracts
199
+ - constructs the object graph
200
+ - returns **frozen linked objects**
73
201
 
74
- ```js
202
+ ## Dependency Contracts (`__deps__`)
203
+
204
+ Modules declare dependencies using a static export.
205
+
206
+ ```javascript
75
207
  export const __deps__ = {
76
- localName: "Some_CDC",
208
+ localName: "Dependency_CDC",
77
209
  };
78
210
  ```
79
211
 
80
- Rules used by container runtime:
212
+ Rules:
213
+
214
+ - if `__deps__` is absent — module has no dependencies
215
+ - keys correspond to constructor argument names
216
+ - values are CDC dependency identifiers
217
+ - dependencies are resolved recursively
81
218
 
82
- - if `__deps__` is missing: module has zero dependencies
83
- - keys are local argument names passed into factory/class constructor
84
- - values are CDC strings
85
- - dependencies are resolved recursively before instantiation
219
+ ## Canonical Dependency Codes (CDC)
86
220
 
87
- ## CDC Grammar (Default Profile)
221
+ CDC identifiers describe **how dependencies should be resolved**.
88
222
 
89
- Surface form:
223
+ General form:
90
224
 
91
- ```text
225
+ ```txt
92
226
  [PlatformPrefix]ModuleName[__ExportName][LifecycleAndWrappers]
93
227
  ```
94
228
 
95
- Where:
96
-
97
- - `PlatformPrefix`: `node_` | `npm_` | omitted (`teq` by default)
98
- - `Export segment`: `__ExportName`
99
- - `Lifecycle marker`: `$` | `$$` | `$$$`
100
- - `Wrappers`: `_<wrapperId>` suffixes after lifecycle marker
101
-
102
229
  Examples:
103
230
 
104
- - `App_Service` - whole module (`as-is`)
105
- - `App_Service$` - default export as factory with lifecycle marker
106
- - `App_Service__build$$` - named export `build` with lifecycle marker
107
- - `App_Service$$_wrapLog_wrapTrace` - wrapper chain in declared order
108
- - `node_fs` - Node builtin
109
- - `npm_lodash` - npm package
231
+ ```txt
232
+ App_Service
233
+ App_Service$
234
+ App_Service__build$$
235
+ App_Service$$_wrapLog_wrapTrace
236
+ node_fs
237
+ npm_lodash
238
+ ```
110
239
 
111
- Notes:
240
+ Where:
112
241
 
113
- - explicit `teq_` prefix is forbidden
114
- - wrappers without lifecycle marker are invalid
115
- - parser is deterministic and fail-fast
242
+ - `$` singleton lifecycle
243
+ - `$$` new instance lifecycle
244
+ - wrappers modify runtime behavior
116
245
 
117
246
  ## Public API
118
247
 
119
- ```js
248
+ ```javascript
120
249
  const container = new Container();
121
250
  ```
122
251
 
123
- Builder stage methods (only before first `get`):
252
+ Configuration methods (before first `get`):
124
253
 
125
254
  - `setParser(parser)`
126
255
  - `addNamespaceRoot(prefix, target, defaultExt)`
@@ -128,137 +257,79 @@ Builder stage methods (only before first `get`):
128
257
  - `addPostprocess(fn)`
129
258
  - `enableLogging()`
130
259
  - `enableTestMode()`
131
- - `register(cdc, mock)` (only in test mode)
132
-
133
- Resolution:
134
-
135
- - `await container.get(cdc)`
136
-
137
- Behavioral guarantees:
138
-
139
- - configuration is locked after first `get`
140
- - fail-fast pipeline
141
- - deterministic linking under identical contracts and config
142
- - produced values are frozen
143
- - container enters failed state after fatal linking error
144
-
145
- ## Wrappers
146
-
147
- Wrappers are postprocess plugins registered during container configuration.
148
- They are activated by wrapper markers in the CDC string and applied to the produced value after instantiation.
149
-
150
- Wrappers:
260
+ - `register(cdc, mock)`
151
261
 
152
- - are **container-level plugins**
153
- - are **not module exports**
154
- - are applied in declared order
155
- - must return synchronously
156
- - run before lifecycle enforcement and freeze
262
+ Dependency resolution:
157
263
 
158
- Surface form:
159
-
160
- ```text
161
- ModuleName$$_wrapperA_wrapperB
264
+ ```javascript
265
+ await container.get(cdc);
162
266
  ```
163
267
 
164
- Wrappers are part of the dependency contract (CDC).
165
- They declaratively modify how a resolved value behaves.
166
-
167
- ---
168
-
169
- ### Example: Logging Wrapper
268
+ Behavior:
170
269
 
171
- Suppose we want to log all method calls of a service without modifying the service itself.
270
+ - deterministic linking
271
+ - fail-fast resolution pipeline
272
+ - immutable returned objects
273
+ - container enters failed state on fatal errors
172
274
 
173
- #### Service module
174
-
175
- ```js
176
- export default function App_Service() {
177
- return {
178
- sum(a, b) {
179
- return a + b;
180
- },
181
- multiply(a, b) {
182
- return a * b;
183
- },
184
- };
185
- }
186
- ```
187
-
188
- #### Container configuration
189
-
190
- ```js
191
- container.addPostprocessWrapper("logIO", (value) => {
192
- return new Proxy(value, {
193
- get(target, prop, receiver) {
194
- const original = Reflect.get(target, prop, receiver);
195
-
196
- if (typeof original !== "function") {
197
- return original;
198
- }
199
-
200
- return function (...args) {
201
- console.log(`[CALL] ${String(prop)} ->`, args);
202
- const result = original.apply(this, args);
203
- console.log(`[RETURN] ${String(prop)} ->`, result);
204
- return result;
205
- };
206
- },
207
- });
208
- });
209
- ```
275
+ ## Wrappers
210
276
 
211
- #### Request
277
+ Wrappers allow cross-cutting behavior to be applied declaratively.
212
278
 
213
- ```js
214
- const service = await container.get("App_Service$$_logIO");
279
+ Example CDC:
215
280
 
216
- service.sum(2, 3);
217
- // [CALL] sum -> [2, 3]
218
- // [RETURN] sum -> 5
281
+ ```txt
282
+ App_Service$$_log_trace
219
283
  ```
220
284
 
221
- The module remains unaware of logging.
222
- The wrapper applies cross-cutting behavior declaratively through CDC.
223
-
224
- This allows:
285
+ Wrappers can implement:
225
286
 
287
+ - logging
288
+ - metrics
226
289
  - tracing
227
- - metrics collection
228
- - access control
290
+ - security checks
229
291
  - behavioral instrumentation
230
292
 
231
- without modifying business logic or module structure.
232
-
233
- Wrappers therefore act as a declarative DI-level AOP mechanism.
293
+ This acts as a lightweight **DI-level AOP mechanism.**
234
294
 
235
- ## Test Mode and Mocks
295
+ ## Test Mode
236
296
 
237
- ```js
297
+ ```javascript
238
298
  container.enableTestMode();
239
- container.register("App_Service$", { name: "mock-service" });
299
+
300
+ container.register("App_Service$", mockService);
240
301
  ```
241
302
 
242
- Mock lookup uses canonical parsed dependency identity and is applied before resolver/instantiation.
303
+ Mocks are resolved before module instantiation.
243
304
 
244
305
  ## Browser Usage
245
306
 
246
- ESM via jsDelivr:
247
-
248
307
  ```html
249
308
  <script type="module">
250
309
  import Container from "https://cdn.jsdelivr.net/npm/@teqfw/di@2/+esm";
310
+
251
311
  const container = new Container();
252
312
  </script>
253
313
  ```
254
314
 
255
- ## Documentation Source
315
+ ## Documentation
316
+
317
+ Detailed documentation lives in `ctx/`:
318
+
319
+ - `ctx/docs/product/overview.md`
320
+ - `ctx/docs/product/default-cdc-profile.md`
321
+ - `ctx/docs/architecture/cdc-profile/default/grammar.md`
322
+ - `ctx/docs/architecture/cdc-profile/default/transformation.md`
323
+ - `ctx/docs/architecture/cdc-profile/default/validation.md`
324
+ - `ctx/docs/code/components/container.md`
325
+
326
+ ## Author
327
+
328
+ **Alex Gusev**
329
+
330
+ Creator of:
256
331
 
257
- Normative docs live in `ctx/`:
332
+ - **Tequila Framework (TeqFW)**
333
+ - **ADSM (Agent-Driven Software Management)**
258
334
 
259
- - product overview: `ctx/docs/product/overview.md`
260
- - default CDC profile: `ctx/docs/product/default-cdc-profile.md`
261
- - grammar: `ctx/docs/architecture/cdc-profile/default/grammar.md`
262
- - transformation: `ctx/docs/architecture/cdc-profile/default/transformation.md`
263
- - validation: `ctx/docs/architecture/cdc-profile/default/validation.md`
264
- - container contract: `ctx/docs/code/components/container.md`
335
+ The project explores how software architecture evolves when **LLM agents become active participants in the development process**.
package/ai/AGENTS.md ADDED
@@ -0,0 +1,75 @@
1
+ # AGENTS.md
2
+
3
+ Version: 20260307
4
+
5
+ ## Package Purpose
6
+
7
+ This directory provides the **Agent Interface** of the package. It contains a compact usage-oriented description intended for LLM agents that use the package as a dependency. The documents describe how the package is applied by external code and exclude development methodology, repository organization, testing infrastructure, and other internal aspects of the project.
8
+
9
+ The package implements a **dependency container for ES modules** based on runtime late binding. Dependencies between modules are resolved by the container using structured dependency identifiers and deterministic namespace resolution rules rather than static imports. The container dynamically loads ES modules, instantiates exported factories, and returns linked objects according to dependency identifier semantics.
10
+
11
+ ## When to Use This Package
12
+
13
+ This package should be used when a system requires the following capabilities:
14
+
15
+ - runtime dependency injection
16
+ - late binding between ES modules
17
+ - deterministic dependency resolution
18
+ - controlled instantiation of components
19
+ - modules that remain environment-agnostic across Node.js and browser runtimes
20
+
21
+ The container serves as the **composition root** of the application. Application modules declare dependencies and receive instantiated objects from the container rather than resolving dependencies directly.
22
+
23
+ ## Architectural Model
24
+
25
+ The system is based on four mechanisms:
26
+
27
+ - **Late binding of dependencies at runtime**, allowing modules to remain independent of specific implementations.
28
+ - **A container responsible for dependency resolution and instantiation**, which loads modules and produces linked objects.
29
+ - **Structured dependency identifiers**, interpreted by the container to determine how a dependency must be resolved.
30
+ - **Namespace mapping rules**, which deterministically translate identifiers into module locations.
31
+
32
+ Together these mechanisms form a deterministic runtime linking system for ES modules.
33
+
34
+ ## Runtime Linking Model
35
+
36
+ The container acts as a runtime linker for ES modules.
37
+
38
+ Instead of relying on static `import` statements, modules declare dependency contracts through `__deps__` descriptors and CDC identifiers. When a dependency is requested, the container resolves the identifier, loads the required module, constructs the object graph, and returns the linked result.
39
+
40
+ In this model:
41
+
42
+ - ES modules provide implementations.
43
+ - CDC identifiers define dependency contracts.
44
+ - the container performs deterministic runtime linking.
45
+
46
+ This mechanism separates module implementation from dependency binding and allows systems to assemble component graphs dynamically while preserving deterministic behavior.
47
+
48
+ ## Reading Order
49
+
50
+ Agents should read the documents in this directory in the following order:
51
+
52
+ 1. **AGENTS.md** — overview of the package and navigation of the Agent Interface.
53
+ 2. **package-api.ts** — machine-readable contract of the supported programmatic API, public entrypoints, structural contracts, and internal exclusions.
54
+ 3. **concepts.md** — architectural concepts and design principles.
55
+ 4. **container.md** — container responsibilities and dependency resolution pipeline.
56
+ 5. **dependency-id.md** — syntax and semantics of dependency identifiers.
57
+ 6. **extensions.md** — extension mechanisms such as preprocessors and wrappers.
58
+ 7. **usage.md** — minimal usage scenarios and examples.
59
+
60
+ This sequence reflects the intended agent workflow: contract surface first, then architectural model, operational mechanism, dependency addressing, extension points, and practical usage.
61
+
62
+ ## Interface Scope
63
+
64
+ The documents in this directory define the supported usage semantics of the package. Behaviors not described here should be treated as undefined and should not be inferred. The interface intentionally contains only the information required to correctly apply the package in external code.
65
+
66
+ ## Relation to TeqFW
67
+
68
+ The package follows architectural principles used in the **Tequila Framework (TeqFW)** platform, including:
69
+
70
+ - late binding between components
71
+ - separation of data structures and logic handlers
72
+ - namespace-based module organization
73
+ - development in modern JavaScript without compilation
74
+
75
+ Understanding the broader TeqFW ecosystem is not required to use the package, but the container follows the same architectural philosophy.
package/ai/concepts.md ADDED
@@ -0,0 +1,66 @@
1
+ # concepts.md
2
+
3
+ Version: 20260307
4
+
5
+ ## Purpose of the Container
6
+
7
+ The container provides a deterministic mechanism for linking ES modules at runtime. Instead of static imports between modules, dependencies are resolved through a central container that loads modules, instantiates exported factories, and returns linked objects. This approach separates module implementation from dependency resolution and allows systems to assemble components dynamically.
8
+
9
+ ## Late Binding
10
+
11
+ Dependencies between modules are resolved at runtime rather than during module loading. Modules do not import their collaborators directly and therefore remain independent of concrete implementations. The container performs dependency resolution when an object is requested, which allows components to be replaced, extended, or mocked without modifying module code.
12
+
13
+ Late binding enables the following properties:
14
+
15
+ - reduced coupling between modules
16
+ - runtime replacement of implementations
17
+ - simplified testing through dependency substitution
18
+ - compatibility with different runtime environments
19
+
20
+ ## Dependency Container
21
+
22
+ The container acts as the composition root of the application. It receives dependency requests expressed as identifiers, resolves them into module locations, loads the corresponding ES modules, and produces linked objects.
23
+
24
+ The container is responsible for:
25
+
26
+ - translating dependency identifiers into module references
27
+ - loading ES modules dynamically
28
+ - instantiating exported factories
29
+ - applying preprocessing and postprocessing steps
30
+ - returning fully linked objects to the caller
31
+
32
+ Application modules do not construct their dependencies directly and do not perform dependency resolution.
33
+
34
+ ## Dependency Identifiers
35
+
36
+ Dependencies are addressed using structured identifiers interpreted by the container. An identifier describes how the dependency should be resolved and how the resulting object should be instantiated.
37
+
38
+ Dependency identifiers define:
39
+
40
+ - which module provides the dependency
41
+ - which export must be used
42
+ - whether the dependency represents a singleton or a new instance
43
+
44
+ The identifier syntax and resolution rules are described in **dependency-id.md**.
45
+
46
+ ## Namespaces
47
+
48
+ Namespaces provide deterministic mapping between logical identifiers and module locations. Each package defines a namespace root that corresponds to a directory containing source modules.
49
+
50
+ The container resolves identifiers by applying namespace rules that translate identifier prefixes into filesystem paths. This mechanism allows modules to be referenced through stable logical names instead of file paths.
51
+
52
+ Namespace resolution ensures:
53
+
54
+ - predictable module addressing
55
+ - isolation between packages
56
+ - consistent mapping between identifiers and modules
57
+
58
+ ## Immutable Linked Objects
59
+
60
+ Objects returned by the container represent linked components of the application and are treated as immutable values. After an object is created and linked, it is frozen to prevent runtime modification.
61
+
62
+ Immutability ensures that:
63
+
64
+ - components behave consistently after linking
65
+ - shared instances cannot be altered by consumers
66
+ - the container remains the single authority responsible for object construction