@documentation-robotics/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/PYTHON_CLI_PARITY.md +265 -0
- package/PYTHON_CLI_STRUCTURE_UPDATE.md +246 -0
- package/README.md +926 -0
- package/biome.json +42 -0
- package/bunfig.toml +3 -0
- package/dist/ai/claude-client.js +71 -0
- package/dist/ai/claude-client.js.map +7 -0
- package/dist/ai/context-provider.js +129 -0
- package/dist/ai/context-provider.js.map +7 -0
- package/dist/ai/tools.js +231 -0
- package/dist/ai/tools.js.map +7 -0
- package/dist/cli.js +224 -0
- package/dist/cli.js.map +7 -0
- package/dist/commands/add.js +51 -0
- package/dist/commands/add.js.map +7 -0
- package/dist/commands/changeset.js +174 -0
- package/dist/commands/changeset.js.map +7 -0
- package/dist/commands/chat.js +111 -0
- package/dist/commands/chat.js.map +7 -0
- package/dist/commands/conformance.js +132 -0
- package/dist/commands/conformance.js.map +7 -0
- package/dist/commands/delete.js +31 -0
- package/dist/commands/delete.js.map +7 -0
- package/dist/commands/element.js +28 -0
- package/dist/commands/element.js.map +7 -0
- package/dist/commands/export.js +65 -0
- package/dist/commands/export.js.map +7 -0
- package/dist/commands/info.js +40 -0
- package/dist/commands/info.js.map +7 -0
- package/dist/commands/init.js +45 -0
- package/dist/commands/init.js.map +7 -0
- package/dist/commands/list.js +32 -0
- package/dist/commands/list.js.map +7 -0
- package/dist/commands/migrate.js +36 -0
- package/dist/commands/migrate.js.map +7 -0
- package/dist/commands/project.js +74 -0
- package/dist/commands/project.js.map +7 -0
- package/dist/commands/relationship.js +118 -0
- package/dist/commands/relationship.js.map +7 -0
- package/dist/commands/search.js +48 -0
- package/dist/commands/search.js.map +7 -0
- package/dist/commands/show.js +38 -0
- package/dist/commands/show.js.map +7 -0
- package/dist/commands/trace.js +60 -0
- package/dist/commands/trace.js.map +7 -0
- package/dist/commands/update.js +37 -0
- package/dist/commands/update.js.map +7 -0
- package/dist/commands/upgrade.js +152 -0
- package/dist/commands/upgrade.js.map +7 -0
- package/dist/commands/validate.js +71 -0
- package/dist/commands/validate.js.map +7 -0
- package/dist/commands/version.js +20 -0
- package/dist/commands/version.js.map +7 -0
- package/dist/commands/visualize.js +51 -0
- package/dist/commands/visualize.js.map +7 -0
- package/dist/core/active-changeset.js +52 -0
- package/dist/core/active-changeset.js.map +7 -0
- package/dist/core/changeset.js +244 -0
- package/dist/core/changeset.js.map +7 -0
- package/dist/core/dependency-tracker.js +322 -0
- package/dist/core/dependency-tracker.js.map +7 -0
- package/dist/core/element.js +65 -0
- package/dist/core/element.js.map +7 -0
- package/dist/core/layer.js +75 -0
- package/dist/core/layer.js.map +7 -0
- package/dist/core/manifest.js +57 -0
- package/dist/core/manifest.js.map +7 -0
- package/dist/core/migration-registry.js +131 -0
- package/dist/core/migration-registry.js.map +7 -0
- package/dist/core/model.js +455 -0
- package/dist/core/model.js.map +7 -0
- package/dist/core/projection-engine.js +288 -0
- package/dist/core/projection-engine.js.map +7 -0
- package/dist/core/reference-registry.js +188 -0
- package/dist/core/reference-registry.js.map +7 -0
- package/dist/core/relationship-registry.js +114 -0
- package/dist/core/relationship-registry.js.map +7 -0
- package/dist/core/relationships.js +78 -0
- package/dist/core/relationships.js.map +7 -0
- package/dist/export/archimate-exporter.js +111 -0
- package/dist/export/archimate-exporter.js.map +7 -0
- package/dist/export/export-manager.js +63 -0
- package/dist/export/export-manager.js.map +7 -0
- package/dist/export/graphml-exporter.js +39 -0
- package/dist/export/graphml-exporter.js.map +7 -0
- package/dist/export/index.js +17 -0
- package/dist/export/index.js.map +7 -0
- package/dist/export/json-schema-exporter.js +60 -0
- package/dist/export/json-schema-exporter.js.map +7 -0
- package/dist/export/markdown-exporter.js +99 -0
- package/dist/export/markdown-exporter.js.map +7 -0
- package/dist/export/openapi-exporter.js +85 -0
- package/dist/export/openapi-exporter.js.map +7 -0
- package/dist/export/plantuml-exporter.js +60 -0
- package/dist/export/plantuml-exporter.js.map +7 -0
- package/dist/export/types.js +36 -0
- package/dist/export/types.js.map +7 -0
- package/dist/schemas/bundled/01-motivation-layer.schema.json +942 -0
- package/dist/schemas/bundled/02-business-layer.schema.json +1293 -0
- package/dist/schemas/bundled/03-security-layer.schema.json +2177 -0
- package/dist/schemas/bundled/04-application-layer.schema.json +1328 -0
- package/dist/schemas/bundled/05-technology-layer.schema.json +1465 -0
- package/dist/schemas/bundled/06-api-layer.schema.json +1743 -0
- package/dist/schemas/bundled/07-data-model-layer.schema.json +1253 -0
- package/dist/schemas/bundled/08-datastore-layer.schema.json +892 -0
- package/dist/schemas/bundled/09-ux-layer.schema.json +1506 -0
- package/dist/schemas/bundled/10-navigation-layer.schema.json +843 -0
- package/dist/schemas/bundled/11-apm-observability-layer.schema.json +1430 -0
- package/dist/schemas/bundled/12-testing-layer.schema.json +1091 -0
- package/dist/schemas/bundled/common/layer-extensions.schema.json +266 -0
- package/dist/schemas/bundled/common/predicates.schema.json +493 -0
- package/dist/schemas/bundled/common/relationships.schema.json +791 -0
- package/dist/schemas/bundled/common/source-references.schema.json +71 -0
- package/dist/schemas/bundled/link-registry.json +1839 -0
- package/dist/schemas/bundled/link-registry.schema.json +339 -0
- package/dist/schemas/bundled/relationship-catalog.json +1302 -0
- package/dist/schemas/bundled/relationship-type.schema.json +221 -0
- package/dist/server/server.js +1207 -0
- package/dist/server/server.js.map +7 -0
- package/dist/server/telemetry-middleware.js +24 -0
- package/dist/server/telemetry-middleware.js.map +7 -0
- package/dist/telemetry/console-interceptor.js +34 -0
- package/dist/telemetry/console-interceptor.js.map +7 -0
- package/dist/telemetry/index.js +54 -0
- package/dist/telemetry/index.js.map +7 -0
- package/dist/telemetry/resilient-exporter.js +41 -0
- package/dist/telemetry/resilient-exporter.js.map +7 -0
- package/dist/telemetry/resilient-log-exporter.js +41 -0
- package/dist/telemetry/resilient-log-exporter.js.map +7 -0
- package/dist/telemetry/test-instrumentation.js +32 -0
- package/dist/telemetry/test-instrumentation.js.map +7 -0
- package/dist/types/index.js +1 -0
- package/dist/types/index.js.map +7 -0
- package/dist/utils/element-utils.js +11 -0
- package/dist/utils/element-utils.js.map +7 -0
- package/dist/utils/errors.js +105 -0
- package/dist/utils/errors.js.map +7 -0
- package/dist/utils/file-io.js +69 -0
- package/dist/utils/file-io.js.map +7 -0
- package/dist/utils/globals.js +28 -0
- package/dist/utils/globals.js.map +7 -0
- package/dist/utils/model-path.js +22 -0
- package/dist/utils/model-path.js.map +7 -0
- package/dist/utils/project-paths.js +45 -0
- package/dist/utils/project-paths.js.map +7 -0
- package/dist/utils/spec-installer.js +85 -0
- package/dist/utils/spec-installer.js.map +7 -0
- package/dist/utils/spec-version.js +33 -0
- package/dist/utils/spec-version.js.map +7 -0
- package/dist/validators/index.js +15 -0
- package/dist/validators/index.js.map +7 -0
- package/dist/validators/naming-validator.js +82 -0
- package/dist/validators/naming-validator.js.map +7 -0
- package/dist/validators/reference-validator.js +106 -0
- package/dist/validators/reference-validator.js.map +7 -0
- package/dist/validators/schema-validator.js +148 -0
- package/dist/validators/schema-validator.js.map +7 -0
- package/dist/validators/semantic-validator.js +80 -0
- package/dist/validators/semantic-validator.js.map +7 -0
- package/dist/validators/types.js +48 -0
- package/dist/validators/types.js.map +7 -0
- package/dist/validators/validator.js +67 -0
- package/dist/validators/validator.js.map +7 -0
- package/docs/TEST-INSTRUMENTATION.md +405 -0
- package/docs/telemetry.md +427 -0
- package/package.json +70 -0
- package/test-debug.js +33 -0
- package/test-special.mjs +46 -0
- package/test_runner.ts +7 -0
package/README.md
ADDED
|
@@ -0,0 +1,926 @@
|
|
|
1
|
+
# Documentation Robotics CLI
|
|
2
|
+
|
|
3
|
+
TypeScript-based CLI for managing federated architecture data models across 12 interconnected layers.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This is the Documentation Robotics CLI - a production-ready command-line tool for creating, managing, and exporting comprehensive architecture models that span business requirements through technical implementation.
|
|
8
|
+
|
|
9
|
+
## Foundation
|
|
10
|
+
|
|
11
|
+
- ✅ Project structure initialized
|
|
12
|
+
- ✅ TypeScript configuration (strict mode)
|
|
13
|
+
- ✅ Core domain models (Element, Layer, Model, Manifest)
|
|
14
|
+
- ✅ Reference and Relationship registries for tracking dependencies
|
|
15
|
+
- ✅ File I/O utilities with atomic writes
|
|
16
|
+
- ✅ JSON schemas bundled (all 12 layers)
|
|
17
|
+
- ✅ Comprehensive unit tests
|
|
18
|
+
- ✅ Code formatted and configured for linting
|
|
19
|
+
|
|
20
|
+
## Directory Structure
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
cli/
|
|
24
|
+
├── src/
|
|
25
|
+
│ ├── cli.ts # Entry point
|
|
26
|
+
│ ├── core/ # Domain models
|
|
27
|
+
│ │ ├── element.ts # Individual architecture items
|
|
28
|
+
│ │ ├── layer.ts # Layer containers
|
|
29
|
+
│ │ ├── model.ts # Complete model orchestration
|
|
30
|
+
│ │ ├── manifest.ts # Model metadata (JSON)
|
|
31
|
+
│ │ ├── reference-registry.ts # Cross-layer reference tracking
|
|
32
|
+
│ │ └── relationship-registry.ts # Intra-layer relationship management
|
|
33
|
+
│ ├── types/
|
|
34
|
+
│ │ └── index.ts # TypeScript type definitions
|
|
35
|
+
│ ├── utils/
|
|
36
|
+
│ │ └── file-io.ts # File operations (atomic writes)
|
|
37
|
+
│ └── schemas/
|
|
38
|
+
│ └── bundled/ # All JSON schemas from spec/
|
|
39
|
+
│ ├── 01-motivation-layer.schema.json
|
|
40
|
+
│ ├── 02-business-layer.schema.json
|
|
41
|
+
│ ├── ... (all 12 layer schemas)
|
|
42
|
+
│ ├── relationship-catalog.json
|
|
43
|
+
│ ├── link-registry.json
|
|
44
|
+
│ └── common/
|
|
45
|
+
│ ├── relationships.schema.json
|
|
46
|
+
│ ├── predicates.schema.json
|
|
47
|
+
│ └── ...
|
|
48
|
+
├── tests/
|
|
49
|
+
│ └── unit/
|
|
50
|
+
│ ├── core/
|
|
51
|
+
│ │ ├── element.test.ts
|
|
52
|
+
│ │ ├── layer.test.ts
|
|
53
|
+
│ │ ├── manifest.test.ts
|
|
54
|
+
│ │ ├── model.test.ts
|
|
55
|
+
│ │ ├── reference-registry.test.ts
|
|
56
|
+
│ │ ├── relationship-registry.test.ts
|
|
57
|
+
│ │ └── element.integration.test.js
|
|
58
|
+
│ └── utils/
|
|
59
|
+
│ └── file-io.test.ts
|
|
60
|
+
├── dist/ # Compiled JavaScript
|
|
61
|
+
├── package.json
|
|
62
|
+
├── tsconfig.json
|
|
63
|
+
├── biome.json
|
|
64
|
+
└── README.md
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Installation & Setup
|
|
68
|
+
|
|
69
|
+
### Prerequisites
|
|
70
|
+
|
|
71
|
+
- **Node.js 18+** (npm included)
|
|
72
|
+
- **Bun 1.3+** (optional, recommended for best performance)
|
|
73
|
+
- A Documentation Robotics model directory (`.dr/`)
|
|
74
|
+
|
|
75
|
+
### Quick Start
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
# Install the CLI globally
|
|
79
|
+
npm install -g @documentation-robotics/cli
|
|
80
|
+
|
|
81
|
+
# Or install locally in your project
|
|
82
|
+
npm install @documentation-robotics/cli
|
|
83
|
+
|
|
84
|
+
# Run CLI
|
|
85
|
+
dr --version
|
|
86
|
+
dr --help
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Development Setup
|
|
90
|
+
|
|
91
|
+
For contributing to the CLI:
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
# Clone the repository
|
|
95
|
+
git clone https://github.com/tinkermonkey/documentation_robotics.git
|
|
96
|
+
cd documentation_robotics/cli
|
|
97
|
+
|
|
98
|
+
# Install dependencies
|
|
99
|
+
npm install
|
|
100
|
+
|
|
101
|
+
# Build TypeScript
|
|
102
|
+
npm run build
|
|
103
|
+
|
|
104
|
+
# Run tests with Bun (preferred)
|
|
105
|
+
bun test
|
|
106
|
+
|
|
107
|
+
# Or run tests with Node.js
|
|
108
|
+
npm test
|
|
109
|
+
|
|
110
|
+
# Format code
|
|
111
|
+
npm run format
|
|
112
|
+
|
|
113
|
+
# Run CLI locally during development
|
|
114
|
+
node dist/cli.js --help
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Installation Methods
|
|
118
|
+
|
|
119
|
+
#### Option 1: Global Installation (Recommended)
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
# Using npm
|
|
123
|
+
npm install -g @documentation-robotics/cli
|
|
124
|
+
|
|
125
|
+
# Using bun
|
|
126
|
+
bun add -g @documentation-robotics/cli
|
|
127
|
+
|
|
128
|
+
# Verify installation
|
|
129
|
+
dr --version
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
#### Option 2: Project-Local Installation
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
# Install as a dev dependency
|
|
136
|
+
npm install --save-dev @documentation-robotics/cli
|
|
137
|
+
|
|
138
|
+
# Or add to package.json and run npm install
|
|
139
|
+
{
|
|
140
|
+
"devDependencies": {
|
|
141
|
+
"@documentation-robotics/cli": "^0.1.0"
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
# Run via npx
|
|
146
|
+
npx dr --help
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
#### Option 3: Build from Source
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
# Clone and build
|
|
153
|
+
git clone https://github.com/tinkermonkey/documentation_robotics.git
|
|
154
|
+
cd documentation_robotics/cli
|
|
155
|
+
npm install
|
|
156
|
+
npm run build
|
|
157
|
+
|
|
158
|
+
# Install globally from built dist
|
|
159
|
+
npm install -g .
|
|
160
|
+
|
|
161
|
+
# Or run directly
|
|
162
|
+
node dist/cli.js --help
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### Configuration
|
|
166
|
+
|
|
167
|
+
#### Claude Code CLI Setup (for Chat Features)
|
|
168
|
+
|
|
169
|
+
Chat functionality requires **Claude Code CLI** to be installed and authenticated with your Anthropic account.
|
|
170
|
+
|
|
171
|
+
**Install Claude Code:**
|
|
172
|
+
|
|
173
|
+
1. Visit https://claude.ai/download
|
|
174
|
+
2. Follow installation instructions for your platform
|
|
175
|
+
3. Authenticate with your Anthropic account when prompted
|
|
176
|
+
|
|
177
|
+
Verify installation:
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
# Check Claude Code CLI is available
|
|
181
|
+
which claude
|
|
182
|
+
|
|
183
|
+
# Run without a model directory to test
|
|
184
|
+
claude --version
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
#### Visualization Server
|
|
188
|
+
|
|
189
|
+
```bash
|
|
190
|
+
# Run visualization server with custom port
|
|
191
|
+
dr visualize --port 3000
|
|
192
|
+
|
|
193
|
+
# Run without auto-opening browser
|
|
194
|
+
dr visualize --no-browser
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
#### Telemetry & Observability (Optional)
|
|
198
|
+
|
|
199
|
+
The CLI supports comprehensive OpenTelemetry instrumentation for tracing, logging, and observability during development and testing. Telemetry is completely optional and incurs **zero overhead in production builds** due to compile-time constant elimination.
|
|
200
|
+
|
|
201
|
+
##### Features
|
|
202
|
+
|
|
203
|
+
- **Command Tracing**: All CLI commands create root spans with command name, arguments, and working directory
|
|
204
|
+
- **Validator Instrumentation**: Schema, naming, reference, and semantic validation stages produce nested spans
|
|
205
|
+
- **Console Logging**: Console output (`console.log`, `console.error`, etc.) is automatically captured and correlated with traces
|
|
206
|
+
- **Test Instrumentation**: Tests can emit spans with test file names, test case names, pass/fail status, and error details
|
|
207
|
+
- **Project Context**: All telemetry includes your project name from the manifest for easy filtering
|
|
208
|
+
- **Circuit-Breaker Protection**: Graceful degradation if the telemetry collector is unavailable—no user-facing errors or blocking
|
|
209
|
+
- **Compile-Time Configuration**: Telemetry code is completely eliminated from production builds via dead-code elimination
|
|
210
|
+
|
|
211
|
+
##### Setup
|
|
212
|
+
|
|
213
|
+
###### Prerequisites
|
|
214
|
+
|
|
215
|
+
- Node.js 18+
|
|
216
|
+
- An OpenTelemetry collector (optional, for viewing traces/logs)
|
|
217
|
+
|
|
218
|
+
###### Start an OTEL Collector (Optional)
|
|
219
|
+
|
|
220
|
+
**Option 1: Use Your Own Collector**
|
|
221
|
+
|
|
222
|
+
The CLI works with any OTLP-compatible collector (Jaeger, Zipkin, Grafana Tempo, Honeycomb, etc.).
|
|
223
|
+
|
|
224
|
+
**Option 2: Use the Example SigNoz Stack**
|
|
225
|
+
|
|
226
|
+
An example SigNoz configuration is provided in `docs/otel_example/`:
|
|
227
|
+
|
|
228
|
+
```bash
|
|
229
|
+
# From the repository root
|
|
230
|
+
./docs/otel_example/signoz-stack.sh start
|
|
231
|
+
|
|
232
|
+
# Wait for services to initialize (~30 seconds)
|
|
233
|
+
# Access SigNoz UI at http://localhost:3301
|
|
234
|
+
# OTEL Collector is available at http://localhost:4318
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
**⚠️ Note:** This is an example configuration only. See [`docs/otel_example/README.md`](../docs/otel_example/README.md) for details.
|
|
238
|
+
|
|
239
|
+
###### Build and Run CLI with Telemetry
|
|
240
|
+
|
|
241
|
+
```bash
|
|
242
|
+
# Build CLI with telemetry enabled
|
|
243
|
+
npm run build:debug
|
|
244
|
+
|
|
245
|
+
# Set telemetry endpoint (optional - defaults to localhost:4318)
|
|
246
|
+
export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318
|
|
247
|
+
|
|
248
|
+
# Run CLI commands - traces and logs will be sent to SigNoz
|
|
249
|
+
node dist/cli.js validate
|
|
250
|
+
node dist/cli.js list motivation
|
|
251
|
+
node dist/cli.js add business service my-service --name "My Service"
|
|
252
|
+
|
|
253
|
+
# View traces and logs in SigNoz UI
|
|
254
|
+
# http://localhost:3301
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
###### Verify Tracing
|
|
258
|
+
|
|
259
|
+
In SigNoz UI (http://localhost:3301):
|
|
260
|
+
|
|
261
|
+
1. **View Command Traces**:
|
|
262
|
+
- Navigate to "Traces" section
|
|
263
|
+
- Look for spans named `cli.execute`
|
|
264
|
+
- Expand to see nested validator spans (`validation.stage.schema`, `validation.stage.naming`, etc.)
|
|
265
|
+
- Each span shows command name, arguments, working directory, and project name
|
|
266
|
+
|
|
267
|
+
2. **View Correlated Logs**:
|
|
268
|
+
- Click on a command span to view details
|
|
269
|
+
- Switch to "Logs" tab to see console output captured during command execution
|
|
270
|
+
- Logs include severity level (INFO, WARN, ERROR) and trace context (traceId, spanId)
|
|
271
|
+
|
|
272
|
+
3. **Filter by Project**:
|
|
273
|
+
- Use the filter `dr.project.name = "YourProjectName"` to isolate telemetry for a specific project
|
|
274
|
+
- Useful when multiple projects share the same collector
|
|
275
|
+
|
|
276
|
+
###### Test Instrumentation
|
|
277
|
+
|
|
278
|
+
Tests can emit telemetry to verify logging behavior. Use the test instrumentation utilities:
|
|
279
|
+
|
|
280
|
+
```typescript
|
|
281
|
+
import { describe, test, beforeAll, afterAll } from 'bun:test';
|
|
282
|
+
import {
|
|
283
|
+
startTestFileSpan,
|
|
284
|
+
endTestFileSpan,
|
|
285
|
+
instrumentTest,
|
|
286
|
+
} from '../../src/telemetry/test-instrumentation.js';
|
|
287
|
+
|
|
288
|
+
beforeAll(() => {
|
|
289
|
+
startTestFileSpan('tests/unit/my-feature.test.ts');
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
afterAll(() => {
|
|
293
|
+
endTestFileSpan();
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
describe('MyFeature', () => {
|
|
297
|
+
test(
|
|
298
|
+
'should validate input',
|
|
299
|
+
instrumentTest(
|
|
300
|
+
'should validate input',
|
|
301
|
+
async () => {
|
|
302
|
+
// Test logic here
|
|
303
|
+
expect(result).toBe(expected);
|
|
304
|
+
},
|
|
305
|
+
'MyFeature' // Suite name for organization
|
|
306
|
+
)
|
|
307
|
+
);
|
|
308
|
+
});
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
Run tests with telemetry:
|
|
312
|
+
|
|
313
|
+
```bash
|
|
314
|
+
npm run build:debug
|
|
315
|
+
npm run test
|
|
316
|
+
|
|
317
|
+
# View test spans in SigNoz UI with attributes:
|
|
318
|
+
# - test.file: Path to test file
|
|
319
|
+
# - test.name: Test case name
|
|
320
|
+
# - test.suite: Describe block name
|
|
321
|
+
# - test.status: 'pass', 'fail', or 'skip'
|
|
322
|
+
# - test.error.message and test.error.stack (for failed tests)
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
###### Stop the Example Stack (if using)
|
|
326
|
+
|
|
327
|
+
```bash
|
|
328
|
+
./docs/otel_example/signoz-stack.sh stop
|
|
329
|
+
|
|
330
|
+
# To remove all data and start fresh:
|
|
331
|
+
./docs/otel_example/signoz-stack.sh clean
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
##### Configuration
|
|
335
|
+
|
|
336
|
+
| Variable | Default | Purpose |
|
|
337
|
+
|----------|---------|---------|
|
|
338
|
+
| `OTEL_EXPORTER_OTLP_ENDPOINT` | `http://localhost:4318` | OTLP collector endpoint (applies to both traces and logs) |
|
|
339
|
+
| `OTEL_EXPORTER_OTLP_LOGS_ENDPOINT` | Derived from OTLP_ENDPOINT | Override for logs endpoint specifically |
|
|
340
|
+
| `DR_TELEMETRY` | Determined by build | Build-time flag (set via `npm run build:debug`) |
|
|
341
|
+
|
|
342
|
+
##### Architecture
|
|
343
|
+
|
|
344
|
+
The telemetry system consists of:
|
|
345
|
+
|
|
346
|
+
1. **Resilient OTLP Exporter** - Exports traces with circuit-breaker pattern (30s backoff on failure)
|
|
347
|
+
2. **Resilient Log Exporter** - Exports logs with same circuit-breaker protection
|
|
348
|
+
3. **Console Interceptor** - Captures console output without modifying application code
|
|
349
|
+
4. **Test Instrumentation** - Provides utilities for creating test spans with standard attributes
|
|
350
|
+
5. **Resource Attributes** - Every trace and log includes:
|
|
351
|
+
- `service.name`: `dr-cli`
|
|
352
|
+
- `service.version`: CLI version from package.json
|
|
353
|
+
- `dr.project.name`: Project name from manifest (if available, else `unknown`)
|
|
354
|
+
|
|
355
|
+
##### Troubleshooting
|
|
356
|
+
|
|
357
|
+
###### Traces not appearing in SigNoz
|
|
358
|
+
|
|
359
|
+
1. **Verify SigNoz is running:**
|
|
360
|
+
```bash
|
|
361
|
+
curl http://localhost:13133 # OTEL Collector health check
|
|
362
|
+
curl http://localhost:3301 # SigNoz UI
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
2. **Check telemetry build:**
|
|
366
|
+
```bash
|
|
367
|
+
# Verify build was done with DR_TELEMETRY=true
|
|
368
|
+
npm run build:debug
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
3. **Verify endpoint connectivity:**
|
|
372
|
+
```bash
|
|
373
|
+
node dist/cli.js validate
|
|
374
|
+
# If SigNoz is unavailable, circuit-breaker activates silently after 500ms timeout
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
4. **Check resource attributes:**
|
|
378
|
+
- In SigNoz, search for traces with filter `service.name = "dr-cli"`
|
|
379
|
+
- Verify `dr.project.name` appears in span attributes
|
|
380
|
+
|
|
381
|
+
###### "Circuit-breaker activated" messages
|
|
382
|
+
|
|
383
|
+
These are internal debug messages and do not affect CLI execution. They appear when:
|
|
384
|
+
- The OTLP collector is unreachable
|
|
385
|
+
- Export timeout (500ms) is exceeded
|
|
386
|
+
|
|
387
|
+
The CLI continues normally—no errors are shown to users.
|
|
388
|
+
|
|
389
|
+
##### Production Deployment
|
|
390
|
+
|
|
391
|
+
- **Development builds** (`npm run build:debug`): Includes full telemetry code (~50KB overhead)
|
|
392
|
+
- **Production builds** (`npm run build`): Zero telemetry overhead via dead-code elimination
|
|
393
|
+
- Telemetry code is completely removed from production bundles at compile time
|
|
394
|
+
|
|
395
|
+
##### Notes
|
|
396
|
+
|
|
397
|
+
- Telemetry is **entirely optional** and disabled in production builds
|
|
398
|
+
- The CLI gracefully handles missing SigNoz (no blocking, no user-visible errors)
|
|
399
|
+
- Traces and logs are sent asynchronously without blocking CLI commands
|
|
400
|
+
- Default OTLP collection endpoint: `http://localhost:4318` (standard OpenTelemetry receiver)
|
|
401
|
+
- Supported log severity levels: DEBUG, INFO, WARN, ERROR
|
|
402
|
+
- Automatic trace-log correlation via traceId and spanId
|
|
403
|
+
|
|
404
|
+
### System Requirements
|
|
405
|
+
|
|
406
|
+
| Feature | Requirement | Notes |
|
|
407
|
+
| ------------- | ----------------- | ---------------------------------- |
|
|
408
|
+
| Basic CLI | Node.js 18+ | All commands work |
|
|
409
|
+
| Visualization | Node.js 18+ | WebSocket support required |
|
|
410
|
+
| Chat | Claude Code CLI | OAuth authentication via Claude Code |
|
|
411
|
+
| Telemetry | Docker Compose | Optional, for local SigNoz/OTLP tracing |
|
|
412
|
+
| Performance | Bun 1.3+ | Optional but recommended |
|
|
413
|
+
|
|
414
|
+
### Troubleshooting
|
|
415
|
+
|
|
416
|
+
#### Command Not Found
|
|
417
|
+
|
|
418
|
+
```bash
|
|
419
|
+
# If "dr" is not found after global installation
|
|
420
|
+
npm install -g @documentation-robotics/cli
|
|
421
|
+
|
|
422
|
+
# Check npm global location
|
|
423
|
+
npm config get prefix
|
|
424
|
+
|
|
425
|
+
# Add to PATH if needed (macOS/Linux)
|
|
426
|
+
export PATH="$(npm config get prefix)/bin:$PATH"
|
|
427
|
+
|
|
428
|
+
# Add to PATH permanently (.bashrc or .zshrc)
|
|
429
|
+
echo 'export PATH="$(npm config get prefix)/bin:$PATH"' >> ~/.bashrc
|
|
430
|
+
source ~/.bashrc
|
|
431
|
+
```
|
|
432
|
+
|
|
433
|
+
#### Module Not Found Errors
|
|
434
|
+
|
|
435
|
+
```bash
|
|
436
|
+
# Clear and reinstall
|
|
437
|
+
rm -rf node_modules package-lock.json
|
|
438
|
+
npm install
|
|
439
|
+
|
|
440
|
+
# Rebuild
|
|
441
|
+
npm run build
|
|
442
|
+
```
|
|
443
|
+
|
|
444
|
+
#### Test Failures
|
|
445
|
+
|
|
446
|
+
```bash
|
|
447
|
+
# Check that all dependencies are installed
|
|
448
|
+
npm list
|
|
449
|
+
|
|
450
|
+
# Reinstall with clean cache
|
|
451
|
+
npm cache clean --force
|
|
452
|
+
npm install
|
|
453
|
+
|
|
454
|
+
# Run tests with verbose output
|
|
455
|
+
DEBUG=* npm test
|
|
456
|
+
```
|
|
457
|
+
|
|
458
|
+
## Command Reference
|
|
459
|
+
|
|
460
|
+
All commands include detailed help. View help for any command:
|
|
461
|
+
|
|
462
|
+
```bash
|
|
463
|
+
dr --help # Show all commands
|
|
464
|
+
dr <command> --help # Show command-specific help
|
|
465
|
+
dr element add --help # Show element add help
|
|
466
|
+
```
|
|
467
|
+
|
|
468
|
+
### Quick Command Summary
|
|
469
|
+
|
|
470
|
+
| Category | Command | Purpose |
|
|
471
|
+
| ----------------- | --------------------- | ---------------------------------------------------- |
|
|
472
|
+
| **Model** | `init` | Initialize a new architecture model |
|
|
473
|
+
| | `info` | Show model information and statistics |
|
|
474
|
+
| | `validate` | Validate the complete model |
|
|
475
|
+
| **Elements** | `add` | Add an element to a layer |
|
|
476
|
+
| | `update` | Update an element |
|
|
477
|
+
| | `delete` | Delete an element |
|
|
478
|
+
| | `show` | Display element details |
|
|
479
|
+
| | `list` | List elements in a layer |
|
|
480
|
+
| | `search` | Search for elements by name/ID |
|
|
481
|
+
| **Relationships** | `relationship add` | Add intra-layer relationship |
|
|
482
|
+
| | `relationship delete` | Delete a relationship |
|
|
483
|
+
| | `relationship list` | List relationships for an element |
|
|
484
|
+
| **Dependencies** | `trace` | Trace element dependencies |
|
|
485
|
+
| | `project` | Project dependencies to a target layer |
|
|
486
|
+
| **Export** | `export` | Export to various formats (ArchiMate, OpenAPI, etc.) |
|
|
487
|
+
| **Visualization** | `visualize` | Launch interactive visualization server |
|
|
488
|
+
| **AI** | `chat` | Interactive Claude AI chat about model |
|
|
489
|
+
| **Advanced** | `migrate` | Migrate model to new spec version |
|
|
490
|
+
| | `upgrade` | Check for version upgrades |
|
|
491
|
+
| | `conformance` | Check spec conformance |
|
|
492
|
+
| | `changeset` | Manage model change tracking |
|
|
493
|
+
|
|
494
|
+
### Common Workflows
|
|
495
|
+
|
|
496
|
+
#### Create a New Model
|
|
497
|
+
|
|
498
|
+
```bash
|
|
499
|
+
# Initialize model
|
|
500
|
+
dr init --name "My Architecture" --author "Team A"
|
|
501
|
+
|
|
502
|
+
# Add some elements
|
|
503
|
+
dr add motivation goal customer-satisfaction --name "Ensure customer satisfaction"
|
|
504
|
+
dr add business service-category order-mgmt --name "Order Management"
|
|
505
|
+
dr add api endpoint create-order --properties '{"method":"POST","path":"/orders"}'
|
|
506
|
+
|
|
507
|
+
# View the model
|
|
508
|
+
dr info
|
|
509
|
+
dr list api
|
|
510
|
+
```
|
|
511
|
+
|
|
512
|
+
#### Search and Update Elements
|
|
513
|
+
|
|
514
|
+
```bash
|
|
515
|
+
# Search for elements
|
|
516
|
+
dr search customer
|
|
517
|
+
|
|
518
|
+
# Show details
|
|
519
|
+
dr show api-endpoint-create-order
|
|
520
|
+
|
|
521
|
+
# Update an element
|
|
522
|
+
dr update api-endpoint-create-order --name "Create Order API (v2)"
|
|
523
|
+
|
|
524
|
+
# Delete an element
|
|
525
|
+
dr delete api-endpoint-old-endpoint --force
|
|
526
|
+
```
|
|
527
|
+
|
|
528
|
+
#### Analyze Dependencies
|
|
529
|
+
|
|
530
|
+
```bash
|
|
531
|
+
# Trace dependencies for an element
|
|
532
|
+
dr trace api-endpoint-create-order
|
|
533
|
+
|
|
534
|
+
# Show dependencies in a specific direction
|
|
535
|
+
dr trace api-endpoint-create-order --direction up
|
|
536
|
+
|
|
537
|
+
# Show element metrics
|
|
538
|
+
dr trace api-endpoint-create-order --metrics
|
|
539
|
+
|
|
540
|
+
# Project to another layer
|
|
541
|
+
dr project api-endpoint-create-order business
|
|
542
|
+
```
|
|
543
|
+
|
|
544
|
+
#### Manage Relationships
|
|
545
|
+
|
|
546
|
+
```bash
|
|
547
|
+
# Add a relationship
|
|
548
|
+
dr relationship add business-process-1 business-process-2 --predicate depends-on
|
|
549
|
+
|
|
550
|
+
# List relationships
|
|
551
|
+
dr relationship list business-process-1
|
|
552
|
+
|
|
553
|
+
# Show only outgoing relationships
|
|
554
|
+
dr relationship list business-process-1 --direction outgoing
|
|
555
|
+
|
|
556
|
+
# Delete a relationship
|
|
557
|
+
dr relationship delete business-process-1 business-process-2 --force
|
|
558
|
+
```
|
|
559
|
+
|
|
560
|
+
#### Export and Visualize
|
|
561
|
+
|
|
562
|
+
```bash
|
|
563
|
+
# Export to multiple formats
|
|
564
|
+
dr export archimate --output model.xml
|
|
565
|
+
dr export openapi --layers api --output api-spec.yaml
|
|
566
|
+
dr export markdown --output docs/architecture.md
|
|
567
|
+
|
|
568
|
+
# Launch visualization server
|
|
569
|
+
dr visualize
|
|
570
|
+
dr visualize --port 3000 --no-browser
|
|
571
|
+
```
|
|
572
|
+
|
|
573
|
+
#### Chat
|
|
574
|
+
|
|
575
|
+
Interactive conversation with Claude about your architecture model.
|
|
576
|
+
|
|
577
|
+
**Requirements**: Claude Code CLI must be installed and authenticated. The chat functionality uses your Claude Code OAuth token, not an API key.
|
|
578
|
+
|
|
579
|
+
**Install Claude Code**:
|
|
580
|
+
1. Visit https://claude.ai/download
|
|
581
|
+
2. Follow installation instructions for your platform
|
|
582
|
+
3. Authenticate with your Anthropic account
|
|
583
|
+
|
|
584
|
+
**CLI Usage**:
|
|
585
|
+
|
|
586
|
+
```bash
|
|
587
|
+
dr chat
|
|
588
|
+
```
|
|
589
|
+
|
|
590
|
+
The chat command:
|
|
591
|
+
- Launches an interactive conversation loop
|
|
592
|
+
- Uses Claude Code CLI with restricted tools (Bash, Read)
|
|
593
|
+
- Provides context about your model (manifest, layer statistics)
|
|
594
|
+
- Streams responses in real-time
|
|
595
|
+
- Exit with "exit", "quit", or "q"
|
|
596
|
+
|
|
597
|
+
**Example**:
|
|
598
|
+
|
|
599
|
+
```bash
|
|
600
|
+
$ dr chat
|
|
601
|
+
┌ Documentation Robotics Chat
|
|
602
|
+
└ Powered by Claude Code - Ask about your architecture model
|
|
603
|
+
|
|
604
|
+
You: What are the dependencies for the create-order endpoint?
|
|
605
|
+
Claude: Let me check the model for you...
|
|
606
|
+
[Using tool: Bash]
|
|
607
|
+
[Tool result: Found dependencies...]
|
|
608
|
+
|
|
609
|
+
You: Show me the critical path in the business layer
|
|
610
|
+
Claude: I'll analyze the business layer relationships...
|
|
611
|
+
|
|
612
|
+
You: exit
|
|
613
|
+
└ Goodbye!
|
|
614
|
+
```
|
|
615
|
+
|
|
616
|
+
**WebSocket Chat** (via `dr visualize`):
|
|
617
|
+
|
|
618
|
+
The visualization server provides WebSocket-based chat using JSON-RPC 2.0:
|
|
619
|
+
|
|
620
|
+
**Request** (send message):
|
|
621
|
+
```json
|
|
622
|
+
{
|
|
623
|
+
"jsonrpc": "2.0",
|
|
624
|
+
"method": "chat.send",
|
|
625
|
+
"params": {
|
|
626
|
+
"message": "What layers are in this model?"
|
|
627
|
+
},
|
|
628
|
+
"id": 1
|
|
629
|
+
}
|
|
630
|
+
```
|
|
631
|
+
|
|
632
|
+
**Notifications** (streaming response):
|
|
633
|
+
|
|
634
|
+
Text content chunk:
|
|
635
|
+
```json
|
|
636
|
+
{
|
|
637
|
+
"jsonrpc": "2.0",
|
|
638
|
+
"method": "chat.response.chunk",
|
|
639
|
+
"params": {
|
|
640
|
+
"conversation_id": "conv-1-12345",
|
|
641
|
+
"content": "This model has 12 layers...",
|
|
642
|
+
"is_final": false,
|
|
643
|
+
"timestamp": "2025-01-02T12:00:00.000Z"
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
```
|
|
647
|
+
|
|
648
|
+
Tool invocation notification:
|
|
649
|
+
```json
|
|
650
|
+
{
|
|
651
|
+
"jsonrpc": "2.0",
|
|
652
|
+
"method": "chat.tool.invoke",
|
|
653
|
+
"params": {
|
|
654
|
+
"conversation_id": "conv-1-12345",
|
|
655
|
+
"tool_name": "Bash",
|
|
656
|
+
"tool_input": { "command": "dr list api" },
|
|
657
|
+
"timestamp": "2025-01-02T12:00:00.000Z"
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
```
|
|
661
|
+
|
|
662
|
+
Tool result notification:
|
|
663
|
+
```json
|
|
664
|
+
{
|
|
665
|
+
"jsonrpc": "2.0",
|
|
666
|
+
"method": "chat.tool.result",
|
|
667
|
+
"params": {
|
|
668
|
+
"conversation_id": "conv-1-12345",
|
|
669
|
+
"result": "output from tool execution",
|
|
670
|
+
"timestamp": "2025-01-02T12:00:00.000Z"
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
```
|
|
674
|
+
|
|
675
|
+
**Completion response**:
|
|
676
|
+
```json
|
|
677
|
+
{
|
|
678
|
+
"jsonrpc": "2.0",
|
|
679
|
+
"result": {
|
|
680
|
+
"conversation_id": "conv-1-12345",
|
|
681
|
+
"status": "complete",
|
|
682
|
+
"exit_code": 0,
|
|
683
|
+
"full_response": "Complete response text...",
|
|
684
|
+
"timestamp": "2025-01-02T12:00:00.000Z"
|
|
685
|
+
},
|
|
686
|
+
"id": 1
|
|
687
|
+
}
|
|
688
|
+
```
|
|
689
|
+
|
|
690
|
+
**Error response**:
|
|
691
|
+
```json
|
|
692
|
+
{
|
|
693
|
+
"jsonrpc": "2.0",
|
|
694
|
+
"error": {
|
|
695
|
+
"code": -32001,
|
|
696
|
+
"message": "Claude Code CLI not available"
|
|
697
|
+
},
|
|
698
|
+
"id": 1
|
|
699
|
+
}
|
|
700
|
+
```
|
|
701
|
+
|
|
702
|
+
**Error Codes**:
|
|
703
|
+
- `-32001`: Claude Code CLI not available (install Claude Code)
|
|
704
|
+
- `-32002`: Invalid parameters
|
|
705
|
+
- `-32603`: Internal error (process failure, timeout)
|
|
706
|
+
|
|
707
|
+
#### Manage Changesets
|
|
708
|
+
|
|
709
|
+
```bash
|
|
710
|
+
# Create a changeset
|
|
711
|
+
dr changeset create "v1.1 migration" --description "Migrate to new API structure"
|
|
712
|
+
|
|
713
|
+
# List changesets
|
|
714
|
+
dr changeset list
|
|
715
|
+
|
|
716
|
+
# Apply a changeset
|
|
717
|
+
dr changeset apply "v1.1 migration"
|
|
718
|
+
|
|
719
|
+
# Revert a changeset
|
|
720
|
+
dr changeset revert "v1.1 migration"
|
|
721
|
+
```
|
|
722
|
+
|
|
723
|
+
## Core Classes
|
|
724
|
+
|
|
725
|
+
### Element
|
|
726
|
+
|
|
727
|
+
Individual architecture items in the model. Supports:
|
|
728
|
+
|
|
729
|
+
- Properties with type-safe getters/setters
|
|
730
|
+
- Array properties with add/get operations
|
|
731
|
+
- References to other elements (cross-layer)
|
|
732
|
+
- Relationships with other elements (intra-layer)
|
|
733
|
+
|
|
734
|
+
```typescript
|
|
735
|
+
const element = new Element({
|
|
736
|
+
id: "motivation-goal-test",
|
|
737
|
+
type: "Goal",
|
|
738
|
+
name: "Test Goal",
|
|
739
|
+
description: "A test goal",
|
|
740
|
+
properties: { priority: "high" },
|
|
741
|
+
});
|
|
742
|
+
|
|
743
|
+
element.setProperty("owner", "team-a");
|
|
744
|
+
element.addToArrayProperty("tags", "important");
|
|
745
|
+
```
|
|
746
|
+
|
|
747
|
+
### Layer
|
|
748
|
+
|
|
749
|
+
Container for elements within a single layer. Supports:
|
|
750
|
+
|
|
751
|
+
- Add/get/delete/list operations
|
|
752
|
+
- Dirty tracking (unsaved changes)
|
|
753
|
+
- JSON serialization/deserialization
|
|
754
|
+
|
|
755
|
+
```typescript
|
|
756
|
+
const layer = new Layer("motivation");
|
|
757
|
+
layer.addElement(element);
|
|
758
|
+
|
|
759
|
+
if (layer.isDirty()) {
|
|
760
|
+
await model.saveLayer("motivation");
|
|
761
|
+
layer.markClean();
|
|
762
|
+
}
|
|
763
|
+
```
|
|
764
|
+
|
|
765
|
+
### Manifest
|
|
766
|
+
|
|
767
|
+
Model metadata (JSON-based). Supports:
|
|
768
|
+
|
|
769
|
+
- Automatic timestamp management
|
|
770
|
+
- JSON serialization/deserialization
|
|
771
|
+
- Version tracking
|
|
772
|
+
|
|
773
|
+
```typescript
|
|
774
|
+
const manifest = new Manifest({
|
|
775
|
+
name: "Test Model",
|
|
776
|
+
version: "1.0.0",
|
|
777
|
+
description: "A test model",
|
|
778
|
+
specVersion: "0.6.0",
|
|
779
|
+
});
|
|
780
|
+
|
|
781
|
+
const json = JSON.stringify(manifest.toJSON());
|
|
782
|
+
const deserialized = Manifest.fromJSON(json);
|
|
783
|
+
```
|
|
784
|
+
|
|
785
|
+
### Model
|
|
786
|
+
|
|
787
|
+
Central orchestrator for the complete architecture model. Supports:
|
|
788
|
+
|
|
789
|
+
- Lazy layer loading
|
|
790
|
+
- Manifest management
|
|
791
|
+
- Atomic persistence to `.dr/` directory structure
|
|
792
|
+
|
|
793
|
+
```typescript
|
|
794
|
+
// Initialize a new model
|
|
795
|
+
const model = await Model.init(".", {
|
|
796
|
+
name: "My Model",
|
|
797
|
+
version: "1.0.0",
|
|
798
|
+
});
|
|
799
|
+
|
|
800
|
+
// Load an existing model
|
|
801
|
+
const loaded = await Model.load(".");
|
|
802
|
+
|
|
803
|
+
// Save changes
|
|
804
|
+
await model.saveManifest();
|
|
805
|
+
await model.saveDirtyLayers();
|
|
806
|
+
```
|
|
807
|
+
|
|
808
|
+
### ReferenceRegistry
|
|
809
|
+
|
|
810
|
+
Tracks cross-layer references between architecture elements. Provides:
|
|
811
|
+
|
|
812
|
+
- Add/query references by source, target, or type
|
|
813
|
+
- Reference validation and integrity checking
|
|
814
|
+
- Impact analysis (find all references to/from an element)
|
|
815
|
+
- Statistics on reference usage
|
|
816
|
+
|
|
817
|
+
```typescript
|
|
818
|
+
const refRegistry = new ReferenceRegistry();
|
|
819
|
+
|
|
820
|
+
refRegistry.addReference({
|
|
821
|
+
source: "01-motivation-goal-create-customer",
|
|
822
|
+
target: "02-business-process-create-order",
|
|
823
|
+
type: "realizes",
|
|
824
|
+
});
|
|
825
|
+
|
|
826
|
+
const refsFrom = refRegistry.getReferencesFrom("01-motivation-goal-create-customer");
|
|
827
|
+
const refsTo = refRegistry.getReferencesTo("02-business-process-create-order");
|
|
828
|
+
```
|
|
829
|
+
|
|
830
|
+
### RelationshipRegistry
|
|
831
|
+
|
|
832
|
+
Manages intra-layer relationships and their semantic metadata. Provides:
|
|
833
|
+
|
|
834
|
+
- Register relationship types with predicates and metadata
|
|
835
|
+
- Query relationships by source, layer, or predicate
|
|
836
|
+
- Validate relationship predicates
|
|
837
|
+
- Layer-specific relationship rules
|
|
838
|
+
|
|
839
|
+
```typescript
|
|
840
|
+
const relRegistry = new RelationshipRegistry();
|
|
841
|
+
|
|
842
|
+
relRegistry.registerType({
|
|
843
|
+
id: "depends-on",
|
|
844
|
+
predicate: "depends-on",
|
|
845
|
+
category: "dependency",
|
|
846
|
+
});
|
|
847
|
+
|
|
848
|
+
relRegistry.addRelationship({
|
|
849
|
+
source: "02-process-create-order",
|
|
850
|
+
target: "02-process-validate-order",
|
|
851
|
+
predicate: "depends-on",
|
|
852
|
+
});
|
|
853
|
+
```
|
|
854
|
+
|
|
855
|
+
## File I/O Utilities
|
|
856
|
+
|
|
857
|
+
Atomic file operations for safe persistence:
|
|
858
|
+
|
|
859
|
+
```typescript
|
|
860
|
+
import { ensureDir, writeFile, readFile, writeJSON, readJSON, atomicWrite } from "@/utils/file-io";
|
|
861
|
+
|
|
862
|
+
// Ensure directory exists
|
|
863
|
+
await ensureDir(".dr/layers");
|
|
864
|
+
|
|
865
|
+
// Atomic write (safe for crash recovery)
|
|
866
|
+
await atomicWrite(".dr/manifest.json", content);
|
|
867
|
+
|
|
868
|
+
// JSON operations
|
|
869
|
+
await writeJSON(".dr/layers/motivation.json", data, true);
|
|
870
|
+
const loaded = await readJSON(".dr/layers/motivation.json");
|
|
871
|
+
```
|
|
872
|
+
|
|
873
|
+
## Type Definitions
|
|
874
|
+
|
|
875
|
+
Core types defined in `src/types/index.ts`:
|
|
876
|
+
|
|
877
|
+
- `Element` - Architecture item representation
|
|
878
|
+
- `LayerData` - Layer serialization format
|
|
879
|
+
- `ManifestData` - Manifest metadata
|
|
880
|
+
- `Reference` - Cross-layer references
|
|
881
|
+
- `Relationship` - Intra-layer relationships
|
|
882
|
+
- `ModelOptions` - Model configuration
|
|
883
|
+
|
|
884
|
+
## Testing
|
|
885
|
+
|
|
886
|
+
Comprehensive test coverage for core classes:
|
|
887
|
+
|
|
888
|
+
```bash
|
|
889
|
+
# Run Bun tests (requires Bun runtime)
|
|
890
|
+
bun test
|
|
891
|
+
|
|
892
|
+
# Run specific test file
|
|
893
|
+
bun test tests/unit/core/element.test.ts
|
|
894
|
+
|
|
895
|
+
# With coverage
|
|
896
|
+
bun test --coverage
|
|
897
|
+
|
|
898
|
+
# Node.js integration test
|
|
899
|
+
node tests/unit/core/element.integration.test.js
|
|
900
|
+
```
|
|
901
|
+
|
|
902
|
+
## Bundled Schemas
|
|
903
|
+
|
|
904
|
+
All JSON schemas from `spec/schemas/` are bundled:
|
|
905
|
+
|
|
906
|
+
- **Layer Schemas**: 01-motivation through 12-testing
|
|
907
|
+
- **Catalogs**: relationship-catalog.json, link-registry.json
|
|
908
|
+
- **Common Schemas**: predicates, relationships, source-references, layer-extensions
|
|
909
|
+
|
|
910
|
+
These schemas are loaded at build time and do not require filesystem access at runtime.
|
|
911
|
+
|
|
912
|
+
## Code Quality
|
|
913
|
+
|
|
914
|
+
- **TypeScript**: Strict mode with comprehensive type coverage
|
|
915
|
+
- **Linting**: Biome configured for code quality checks
|
|
916
|
+
- **Formatting**: Code formatted to project standards
|
|
917
|
+
|
|
918
|
+
## Related Resources
|
|
919
|
+
|
|
920
|
+
- Specification: `/workspace/spec/`
|
|
921
|
+
- Design Discussion: [GitHub Discussion #68](https://github.com/tinkermonkey/documentation_robotics/discussions/68)
|
|
922
|
+
- Migration Guide: [Migrating from Python CLI](../docs/migration-from-python-cli.md)
|
|
923
|
+
|
|
924
|
+
## License
|
|
925
|
+
|
|
926
|
+
MIT
|