@bushscad/cli 0.0.0-stage → 0.3.1

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.
@@ -0,0 +1,195 @@
1
+ /**
2
+ * @author Aidan Boissonneault
3
+ * @file types.ts
4
+ * @purpose Provides types behavior for the dto in cli package.
5
+ * @last-edited October 6, 2026
6
+ */
7
+
8
+ import type {
9
+ CompileError,
10
+ DrawingResult,
11
+ ExportFormat,
12
+ IRProgram,
13
+ InteractionSnapshot,
14
+ MaterialAppearance,
15
+ OcctTraceEvent,
16
+ ResolvedJointData,
17
+ ValidationResult,
18
+ } from '@bushscad/ir';
19
+ import type { EnvManifestEntry } from '@bushscad/compiler';
20
+ import type {
21
+ CompileEntrypointMode,
22
+ FileOverlayMap,
23
+ } from '@bushscad/compiler/node';
24
+
25
+ /**
26
+ * Mesh dto, including part name, body name, color, uses default color, and material.
27
+ */
28
+ export type MeshDto = {
29
+ partName: string;
30
+ bodyName?: string;
31
+ color: string;
32
+ usesDefaultColor?: boolean;
33
+ material?: MaterialAppearance;
34
+ vertices: number[];
35
+ normals: number[];
36
+ indices: number[];
37
+ isHardwareVisual?: boolean;
38
+ hardwareKind?: 'bolt' | 'insert';
39
+ };
40
+
41
+ /**
42
+ * Buffer dto, including name and encoded geometry data.
43
+ */
44
+ export type BufferDto = {
45
+ name: string;
46
+ dataBase64: string;
47
+ };
48
+
49
+ /**
50
+ * Accepted values for compiler engine are 'classic' and 'parallel'.
51
+ */
52
+ export type CompilerEngine = 'classic' | 'parallel';
53
+ /**
54
+ * Accepted values for drawing output mode are 'write-source-paths' and 'return-content'.
55
+ */
56
+ export type DrawingOutputMode = 'write-source-paths' | 'return-content';
57
+
58
+ /**
59
+ * Measurements for compiler, including engine, fallback reason, worker count, ready worker
60
+ * count, and IR compilation time.
61
+ */
62
+ export type CompilerMetrics = {
63
+ engine: CompilerEngine;
64
+ fallbackReason?: string;
65
+ workerCount: number;
66
+ readyWorkerCount: number;
67
+ compileIrMs: number;
68
+ geometryMs: number;
69
+ assemblyMs: number;
70
+ workerStartupMs: number;
71
+ reusedWarmWorkers: boolean;
72
+ schedulerTaskCount?: number;
73
+ workerBusyMs?: number;
74
+ workerCpuMs?: number;
75
+ queueWaitMs?: number;
76
+ transportMs?: number;
77
+ workerUtilization?: number;
78
+ longestWorkerTaskMs?: number;
79
+ aggregateWorkerRssBytes?: number;
80
+ peakWorkerRssBytes?: number;
81
+ componentPreparationMs?: number;
82
+ componentReductionMs?: number;
83
+ preparedComponentCount?: number;
84
+ componentRecipeCount?: number;
85
+ componentCacheHitCount?: number;
86
+ nativeBooleanBatchCount?: number;
87
+ nativeBooleanAvoidedBuildCount?: number;
88
+ nativeBooleanRejectionCount?: number;
89
+ };
90
+
91
+ /**
92
+ * Accepted values for compiler request kind are 'check', 'preview', 'export', and
93
+ * 'exportDrawings'.
94
+ */
95
+ export type CompilerRequestKind =
96
+ | 'check'
97
+ | 'preview'
98
+ | 'export'
99
+ | 'exportDrawings';
100
+
101
+ /**
102
+ * Request to compiler, including operation kind, source file path, workspace root, entrypoint
103
+ * mode, and source overlays.
104
+ */
105
+ export type CompilerRequest = {
106
+ kind: CompilerRequestKind;
107
+ filePath: string;
108
+ rootPath?: string | null;
109
+ entrypointMode?: CompileEntrypointMode;
110
+ overlays?: FileOverlayMap;
111
+ env?: Record<string, string>;
112
+ format?: ExportFormat;
113
+ cursorOpIndex?: number;
114
+ suppressedOpIndices?: number[];
115
+ occtTrace?: boolean;
116
+ engine?: CompilerEngine;
117
+ drawingOutputMode?: DrawingOutputMode;
118
+ };
119
+
120
+ /**
121
+ * Derives `ServiceRequest` from `CompilerRequest & { id: number }` to preserve its type relationship
122
+ * in the dto layer.
123
+ */
124
+ export type ServiceRequest = CompilerRequest & { id: number };
125
+
126
+ /**
127
+ * Written drawing dto, including name, path, and export format.
128
+ */
129
+ type WrittenDrawingDto = { name: string; path: string; format: string };
130
+
131
+ /**
132
+ * Response from service is tagged by ok: 'true' carries program, meshes, interaction and 'false'
133
+ * carries errors.
134
+ */
135
+ export type ServiceResponse =
136
+ | {
137
+ id: number;
138
+ kind: ServiceRequest['kind'];
139
+ ok: true;
140
+ program?: IRProgram;
141
+ meshes?: MeshDto[];
142
+ interaction?: InteractionSnapshot;
143
+ drawings?: DrawingResult[];
144
+ buffers?: BufferDto[];
145
+ validations?: ValidationResult[];
146
+ joints?: ResolvedJointData[];
147
+ writtenDrawings?: WrittenDrawingDto[];
148
+ occtTraceEvents?: OcctTraceEvent[];
149
+ env: EnvManifestEntry[];
150
+ dependents?: Record<string, string[]>;
151
+ elapsedMs: number;
152
+ compilerMetrics?: CompilerMetrics;
153
+ }
154
+ | {
155
+ id: number;
156
+ kind: ServiceRequest['kind'];
157
+ ok: false;
158
+ errors: CompileError[];
159
+ occtTraceEvents?: OcctTraceEvent[];
160
+ env: EnvManifestEntry[];
161
+ elapsedMs: number;
162
+ compilerMetrics?: CompilerMetrics;
163
+ };
164
+
165
+ /**
166
+ * Message for service trace, including identifier, operation kind, and event.
167
+ */
168
+ export type ServiceTraceMessage = {
169
+ id: number;
170
+ kind: 'occt-trace';
171
+ event: OcctTraceEvent;
172
+ };
173
+
174
+ /**
175
+ * Message for service pool, including operation kind and status.
176
+ */
177
+ export type ServicePoolMessage = {
178
+ kind: 'pool-status';
179
+ status: CompilerPoolStatus;
180
+ };
181
+
182
+ /**
183
+ * status of compiler pool represented by
184
+ * import('../service/parallel/worker-protocol.js').ParallelPoolStatus.
185
+ */
186
+ export type CompilerPoolStatus =
187
+ import('../service/parallel/worker-protocol.js').ParallelPoolStatus;
188
+
189
+ /**
190
+ * Message for service accepts ServiceResponse, ServiceTraceMessage, and ServicePoolMessage.
191
+ */
192
+ export type ServiceMessage =
193
+ | ServiceResponse
194
+ | ServiceTraceMessage
195
+ | ServicePoolMessage;
@@ -0,0 +1,164 @@
1
+ /**
2
+ * @author Aidan Boissonneault
3
+ * @file worker-protocol.ts
4
+ * @purpose Provides worker protocol behavior for the service parallel in cli package.
5
+ * @last-edited October 6, 2026
6
+ */
7
+
8
+ import type {
9
+ CompileAssets,
10
+ DrawingProgram,
11
+ DrawingResult,
12
+ SourceSpan,
13
+ ExportFormat,
14
+ IRProgram,
15
+ InteractionSnapshot,
16
+ MeshData,
17
+ NativeBooleanBatchPlan,
18
+ OcctTraceEvent,
19
+ PreparedComponentArtifact,
20
+ ResolvedJointData,
21
+ ValidationResult,
22
+ } from '@bushscad/ir';
23
+
24
+ /**
25
+ * Parallel build task, including task id, part name, source index, auto color offset, and
26
+ * program.
27
+ */
28
+ export type ParallelBuildTask = {
29
+ taskId: number;
30
+ partName: string;
31
+ sourceIndex: number;
32
+ autoColorOffset: number;
33
+ program: IRProgram;
34
+ assets: CompileAssets;
35
+ trace: boolean;
36
+ drawingProgram?: DrawingProgram;
37
+ preparedComponents?: PreparedComponentArtifact[];
38
+ nativeBooleanPlan?: NativeBooleanBatchPlan;
39
+ nativeBooleanConcurrencyLimit?: number;
40
+ };
41
+
42
+ /**
43
+ * Parallel worker telemetry, including worker cpu milliseconds and worker rss bytes.
44
+ */
45
+ export type ParallelWorkerTelemetry = {
46
+ workerCpuMs: number;
47
+ workerRssBytes: number;
48
+ };
49
+
50
+ /**
51
+ * Derives `ParallelBuildOutput` from `ParallelWorkerTelemetry & { taskId: number; partName: string;
52
+ * sourceIndex: number; meshes: MeshData[]; drawings: DrawingResult[]; interaction?:
53
+ * InteractionSnapshot; validations: ValidationResult[]; joints: ResolvedJointData[]; traceEvents:
54
+ * OcctTraceEvent[]; elapsedMs: number; }` to preserve its type relationship in the service parallel
55
+ * layer.
56
+ */
57
+ export type ParallelBuildOutput = ParallelWorkerTelemetry & {
58
+ taskId: number;
59
+ partName: string;
60
+ sourceIndex: number;
61
+ meshes: MeshData[];
62
+ drawings: DrawingResult[];
63
+ interaction?: InteractionSnapshot;
64
+ validations: ValidationResult[];
65
+ joints: ResolvedJointData[];
66
+ traceEvents: OcctTraceEvent[];
67
+ elapsedMs: number;
68
+ };
69
+
70
+ /**
71
+ * Parallel component task, including task id, part name, source index, name, and recipe digest.
72
+ */
73
+ export type ParallelComponentTask = {
74
+ taskId: number;
75
+ partName: string;
76
+ sourceIndex: number;
77
+ name: string;
78
+ recipeDigest: string;
79
+ program: IRProgram;
80
+ assets: CompileAssets;
81
+ semanticConsumerIds: string[];
82
+ trace: boolean;
83
+ };
84
+
85
+ /**
86
+ * Derives `ParallelComponentOutput` from `ParallelWorkerTelemetry & { taskId: number; partName:
87
+ * string; sourceIndex: number; recipeDigest: string; artifact: PreparedComponentArtifact; traceEvents:
88
+ * OcctTraceEvent[]; startedAtMs: number; finishedAtMs: number; elapsedMs: number; }` to preserve its
89
+ * type relationship in the service parallel layer.
90
+ */
91
+ export type ParallelComponentOutput = ParallelWorkerTelemetry & {
92
+ taskId: number;
93
+ partName: string;
94
+ sourceIndex: number;
95
+ recipeDigest: string;
96
+ artifact: PreparedComponentArtifact;
97
+ traceEvents: OcctTraceEvent[];
98
+ startedAtMs: number;
99
+ finishedAtMs: number;
100
+ elapsedMs: number;
101
+ };
102
+
103
+ /**
104
+ * Parallel export task, including task id, program, assets, drawing program, and export format.
105
+ */
106
+ export type ParallelExportTask = {
107
+ taskId: number;
108
+ program: IRProgram;
109
+ assets: CompileAssets;
110
+ drawingProgram: DrawingProgram;
111
+ format: ExportFormat;
112
+ nativeBooleanPlan?: NativeBooleanBatchPlan;
113
+ };
114
+
115
+ /**
116
+ * Derives `ParallelExportOutput` from `ParallelWorkerTelemetry & { taskId: number; buffers: { name:
117
+ * string; data: ArrayBuffer }[]; drawings: DrawingResult[]; elapsedMs: number; }` to preserve its type
118
+ * relationship in the service parallel layer.
119
+ */
120
+ export type ParallelExportOutput = ParallelWorkerTelemetry & {
121
+ taskId: number;
122
+ buffers: { name: string; data: ArrayBuffer }[];
123
+ drawings: DrawingResult[];
124
+ elapsedMs: number;
125
+ };
126
+
127
+ /**
128
+ * Request to parallel worker is tagged by kind: 'build' carries task, 'prepare-component'
129
+ * carries task, 'export' carries task, and 'shutdown'.
130
+ */
131
+ export type ParallelWorkerRequest =
132
+ | { kind: 'build'; task: ParallelBuildTask }
133
+ | { kind: 'prepare-component'; task: ParallelComponentTask }
134
+ | { kind: 'export'; task: ParallelExportTask }
135
+ | { kind: 'shutdown' };
136
+
137
+ /**
138
+ * Message for parallel worker is tagged by kind: 'ready' carries startup duration, worker rss
139
+ * bytes, 'trace' carries task id, event, 'result' carries output, 'component-result' carries
140
+ * output, 'export-result' carries output, and 'error' carries task id, message, span.
141
+ */
142
+ export type ParallelWorkerMessage =
143
+ | { kind: 'ready'; startupMs: number; workerRssBytes: number }
144
+ | { kind: 'trace'; taskId: number; event: OcctTraceEvent }
145
+ | { kind: 'result'; output: ParallelBuildOutput }
146
+ | { kind: 'component-result'; output: ParallelComponentOutput }
147
+ | { kind: 'export-result'; output: ParallelExportOutput }
148
+ | { kind: 'error'; taskId: number; message: string; span?: SourceSpan };
149
+
150
+ /**
151
+ * Status of parallel pool, including current state, desired worker count, warming workers, ready
152
+ * worker count, and busy workers.
153
+ */
154
+ export type ParallelPoolStatus = {
155
+ state: 'warming' | 'ready' | 'busy' | 'degraded' | 'failed' | 'stopped';
156
+ desiredWorkers: number;
157
+ warmingWorkers: number;
158
+ readyWorkers: number;
159
+ busyWorkers: number;
160
+ failedWorkers: number;
161
+ startupMs: number;
162
+ aggregateWorkerRssBytes: number;
163
+ peakAggregateWorkerRssBytes: number;
164
+ };