@typecad/cuttlefish 0.1.0-alpha.2 → 1.0.0-alpha.10

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 (222) hide show
  1. package/README.md +10 -10
  2. package/dist/api/board-types.d.ts +1 -1
  3. package/dist/api/config.d.ts +32 -0
  4. package/dist/api/index.d.ts +1 -1
  5. package/dist/api/schema/types.d.ts +15 -0
  6. package/dist/api/shared/async-runtime-static.d.ts +12 -1
  7. package/dist/api/shared/async-runtime-static.js +69 -24
  8. package/dist/api/shared/async-symbol-detector.d.ts +11 -0
  9. package/dist/api/shared/async-symbol-detector.js +140 -0
  10. package/dist/api/shared/async-types.d.ts +24 -0
  11. package/dist/api/shared/coop-scheduler.d.ts +60 -0
  12. package/dist/api/shared/coop-scheduler.js +149 -0
  13. package/dist/api/shared/display-adapter.d.ts +4 -3
  14. package/dist/api/shared/display-adapter.js +15 -118
  15. package/dist/api/shared/display-adapters/sdl.js +38 -31
  16. package/dist/api/shared/display-profile.d.ts +47 -25
  17. package/dist/api/shared/display-profile.js +31 -164
  18. package/dist/api/shared/framework-manifest-registry.d.ts +9 -0
  19. package/dist/api/shared/framework-manifest-registry.js +27 -0
  20. package/dist/api/shared/framework-manifest.d.ts +595 -0
  21. package/dist/api/shared/framework-manifest.js +193 -0
  22. package/dist/api/shared/glcdfont.d.ts +12 -0
  23. package/dist/api/shared/glcdfont.js +124 -0
  24. package/dist/api/shared/graphics-strategy.d.ts +37 -0
  25. package/dist/api/shared/hal-op-ir.d.ts +764 -1
  26. package/dist/api/shared/hal-op-ir.js +129 -1
  27. package/dist/api/shared/index.d.ts +20 -2
  28. package/dist/api/shared/index.js +25 -1
  29. package/dist/api/shared/ir-core.d.ts +4 -0
  30. package/dist/api/shared/ir-declarations.d.ts +6 -0
  31. package/dist/api/shared/native-display-op-resolver.d.ts +10 -0
  32. package/dist/api/shared/native-display-op-resolver.js +64 -0
  33. package/dist/api/shared/platform-strategy.d.ts +119 -2
  34. package/dist/api/shared/polyfill-helper-registry.js +18 -1
  35. package/dist/api/shared/promise-runtime.d.ts +1 -1
  36. package/dist/api/shared/promise-runtime.js +95 -13
  37. package/dist/api/shared/toolchain-types.d.ts +17 -0
  38. package/dist/api/shared/types.d.ts +8 -0
  39. package/dist/api/shared/validate-framework-manifest.d.ts +28 -0
  40. package/dist/api/shared/validate-framework-manifest.js +494 -0
  41. package/dist/api/shared/worker-runtime-polyfill.d.ts +22 -0
  42. package/dist/api/shared/worker-runtime-polyfill.js +34 -0
  43. package/dist/api/shared/worker-runtime.d.ts +69 -0
  44. package/dist/api/shared/worker-runtime.js +163 -0
  45. package/dist/cli-utils.d.ts +1 -0
  46. package/dist/cli-utils.js +3 -1
  47. package/dist/cli.js +249 -32
  48. package/dist/config-loader.d.ts +7 -2
  49. package/dist/config-loader.js +23 -3
  50. package/dist/config-schema.d.ts +112 -70
  51. package/dist/config-schema.js +14 -0
  52. package/dist/contract/board-generator.d.ts +17 -0
  53. package/dist/contract/board-generator.js +57 -0
  54. package/dist/contract/contract-parser.d.ts +217 -0
  55. package/dist/contract/contract-parser.js +224 -0
  56. package/dist/contract/index.d.ts +22 -0
  57. package/dist/contract/index.js +68 -0
  58. package/dist/create/board-codegen.js +4 -4
  59. package/dist/create/board-generators.js +4 -5
  60. package/dist/create/board-spec.d.ts +72 -75
  61. package/dist/create/board-spec.js +0 -1
  62. package/dist/create/framework-catalog.d.ts +64 -0
  63. package/dist/create/framework-catalog.js +136 -0
  64. package/dist/create/index.d.ts +5 -1
  65. package/dist/create/index.js +3 -1
  66. package/dist/create/init-scaffold.d.ts +12 -3
  67. package/dist/create/init-scaffold.js +49 -14
  68. package/dist/create/init-templates.d.ts +4 -0
  69. package/dist/create/init-templates.js +263 -17
  70. package/dist/create/init-wizard.js +41 -27
  71. package/dist/create/install-deps.d.ts +32 -0
  72. package/dist/create/install-deps.js +46 -0
  73. package/dist/debug/preprocessor.js +178 -39
  74. package/dist/debug/types.d.ts +23 -0
  75. package/dist/diagnostics/mermaid-builder.d.ts +1 -1
  76. package/dist/diagnostics/mermaid-builder.js +34 -24
  77. package/dist/emit/compliance/arxml-writer.d.ts +11 -0
  78. package/dist/emit/compliance/arxml-writer.js +34 -0
  79. package/dist/emit/compliance/compliance-context.d.ts +57 -0
  80. package/dist/emit/compliance/compliance-context.js +113 -0
  81. package/dist/emit/compliance/deviation-ledger.d.ts +27 -0
  82. package/dist/emit/compliance/deviation-ledger.js +47 -0
  83. package/dist/emit/compliance/deviation-writer.d.ts +30 -0
  84. package/dist/emit/compliance/deviation-writer.js +37 -0
  85. package/dist/emit/compliance/index.d.ts +7 -0
  86. package/dist/emit/compliance/index.js +6 -0
  87. package/dist/emit/compliance/rule-engine.d.ts +13 -0
  88. package/dist/emit/compliance/rule-engine.js +101 -0
  89. package/dist/emit/compliance/rules.d.ts +16 -0
  90. package/dist/emit/compliance/rules.js +191 -0
  91. package/dist/emit/compliance/types.d.ts +59 -0
  92. package/dist/emit/compliance/types.js +8 -0
  93. package/dist/emit/cpp-emitter.js +4 -3
  94. package/dist/emit/emitters/class-emitter.js +6 -1
  95. package/dist/emit/emitters/emitter-context.d.ts +28 -1
  96. package/dist/emit/emitters/function-emitter-impl.js +153 -53
  97. package/dist/emit/emitters/line-appender.js +19 -0
  98. package/dist/emit/emitters/line-marker.d.ts +38 -0
  99. package/dist/emit/emitters/line-marker.js +39 -0
  100. package/dist/emit/emitters/output-finalizer.d.ts +6 -0
  101. package/dist/emit/emitters/output-finalizer.js +101 -12
  102. package/dist/emit/emitters/setup.d.ts +17 -0
  103. package/dist/emit/emitters/setup.js +372 -30
  104. package/dist/emit/emitters/top-level-prep.js +8 -0
  105. package/dist/emit/emitters/type-decl-emitter.js +28 -3
  106. package/dist/emit/emitters/ui-emitter.js +33 -9
  107. package/dist/emit/expression-renderer.d.ts +1 -1
  108. package/dist/emit/expression-renderer.js +91 -6
  109. package/dist/emit/route-hal-op.js +18 -5
  110. package/dist/emit/snprintf-helpers.js +15 -4
  111. package/dist/emit/statement-renderer.d.ts +10 -0
  112. package/dist/emit/statement-renderer.js +34 -5
  113. package/dist/emit/utils/async-state-machine.js +221 -125
  114. package/dist/emit/utils/hal-op-cpp-type.d.ts +6 -0
  115. package/dist/emit/utils/hal-op-cpp-type.js +40 -0
  116. package/dist/framework-package.js +2 -0
  117. package/dist/framework-registry.d.ts +17 -0
  118. package/dist/install/framework-catalog.d.ts +53 -0
  119. package/dist/install/framework-catalog.js +107 -0
  120. package/dist/install/handle-install.d.ts +35 -0
  121. package/dist/install/handle-install.js +177 -0
  122. package/dist/install/index.d.ts +4 -0
  123. package/dist/install/index.js +3 -0
  124. package/dist/ir/adc-range-validation.js +40 -26
  125. package/dist/ir/build-ir-state.d.ts +1 -0
  126. package/dist/ir/build-ir-state.js +14 -0
  127. package/dist/ir/build-ir.js +9 -5
  128. package/dist/ir/call-graph.js +16 -0
  129. package/dist/ir/expression-to-ir.js +207 -6
  130. package/dist/ir/feature-registry.js +7 -25
  131. package/dist/ir/function-builder.js +22 -0
  132. package/dist/ir/hal/hal-emitter.d.ts +5 -2
  133. package/dist/ir/hal/hal-emitter.js +50 -18
  134. package/dist/ir/hal/hal-parser.d.ts +6 -0
  135. package/dist/ir/hal/hal-parser.js +81 -0
  136. package/dist/ir/hal/hal-plugins.js +733 -1
  137. package/dist/ir/identifier-collector.js +35 -0
  138. package/dist/ir/interrupt-analysis.d.ts +5 -1
  139. package/dist/ir/interrupt-analysis.js +16 -19
  140. package/dist/ir/memory-budget-validation.js +1 -0
  141. package/dist/ir/network-validation.d.ts +4 -0
  142. package/dist/ir/network-validation.js +184 -0
  143. package/dist/ir/ownership-analysis.js +39 -1
  144. package/dist/ir/peripheral-ownership.js +5 -0
  145. package/dist/ir/peripheral-validation.d.ts +1 -1
  146. package/dist/ir/peripheral-validation.js +6 -3
  147. package/dist/ir/pin-alias-conflict.d.ts +1 -1
  148. package/dist/ir/pin-alias-conflict.js +2 -1
  149. package/dist/ir/pin-capability-validation.js +71 -32
  150. package/dist/ir/pin-mode-validation.d.ts +2 -2
  151. package/dist/ir/pin-mode-validation.js +54 -18
  152. package/dist/ir/pin-safety.d.ts +1 -1
  153. package/dist/ir/pin-safety.js +2 -1
  154. package/dist/ir/program-analysis.d.ts +81 -0
  155. package/dist/ir/program-analysis.js +429 -0
  156. package/dist/ir/pulldown-validation.d.ts +1 -1
  157. package/dist/ir/pulldown-validation.js +2 -1
  158. package/dist/ir/pwm-timer-sharing.d.ts +1 -1
  159. package/dist/ir/pwm-timer-sharing.js +2 -1
  160. package/dist/ir/render-expr.js +11 -0
  161. package/dist/ir/resource-analysis.js +2 -0
  162. package/dist/ir/timer0-pwm-timing-conflict.d.ts +1 -1
  163. package/dist/ir/timer0-pwm-timing-conflict.js +2 -1
  164. package/dist/ir/timing-validation.d.ts +6 -1
  165. package/dist/ir/timing-validation.js +61 -13
  166. package/dist/ir/transformers/call-statement.js +105 -0
  167. package/dist/ir/transformers/expressions.js +62 -0
  168. package/dist/ir/transformers/hal-call-resolver.js +21 -0
  169. package/dist/ir/transformers/hal-emit-helpers.js +1 -1
  170. package/dist/ir/transformers/namespace-methods.js +17 -12
  171. package/dist/ir/transformers/ui-reactive.js +2 -2
  172. package/dist/ir/transformers/variables.js +137 -19
  173. package/dist/ir/try-catch-validation.js +2 -0
  174. package/dist/ir/type-resolution.js +20 -2
  175. package/dist/ir/ui-element-auto-wire.js +7 -5
  176. package/dist/ir/unit-suspicion-validation.js +9 -7
  177. package/dist/ir/utils/map-statements.d.ts +4 -0
  178. package/dist/ir/utils/map-statements.js +79 -0
  179. package/dist/ir/validation-orchestrator.js +15 -8
  180. package/dist/ir/worker-analysis.d.ts +10 -0
  181. package/dist/ir/worker-analysis.js +261 -0
  182. package/dist/libdef/c-to-decl.d.ts +27 -0
  183. package/dist/libdef/c-to-decl.js +397 -0
  184. package/dist/libdef/component-decls.d.ts +2 -0
  185. package/dist/libdef/component-decls.js +6 -0
  186. package/dist/libdef/component-discovery.d.ts +43 -0
  187. package/dist/libdef/component-discovery.js +83 -0
  188. package/dist/libdef/cpp-to-decl.d.ts +9 -0
  189. package/dist/libdef/cpp-to-decl.js +72 -0
  190. package/dist/libdef/registry.js +5 -2
  191. package/dist/lint-cache.d.ts +59 -0
  192. package/dist/lint-cache.js +257 -0
  193. package/dist/orchestrator/graph-builder.js +14 -9
  194. package/dist/platform/coop-scheduler-runtime.d.ts +19 -0
  195. package/dist/platform/coop-scheduler-runtime.js +41 -0
  196. package/dist/platform/generic-strategy.d.ts +15 -3
  197. package/dist/platform/generic-strategy.js +49 -4
  198. package/dist/safety/safety-bridge.d.ts +11 -0
  199. package/dist/safety/safety-bridge.js +48 -0
  200. package/dist/safety/sidecar-bridge.d.ts +5 -0
  201. package/dist/safety/sidecar-bridge.js +22 -0
  202. package/dist/safety-hook.d.ts +79 -0
  203. package/dist/safety-hook.js +35 -0
  204. package/dist/testing.d.ts +8 -2
  205. package/dist/testing.js +9 -2
  206. package/dist/transpile.d.ts +3 -0
  207. package/dist/transpile.js +191 -49
  208. package/dist/types.d.ts +22 -3
  209. package/dist/ui-hook.d.ts +17 -3
  210. package/dist/utils/cli.js +122 -2
  211. package/dist/utils/fs.d.ts +13 -0
  212. package/dist/utils/fs.js +50 -0
  213. package/dist/utils/ui.js +3 -1
  214. package/package.json +23 -3
  215. package/dist/api/shared/display-adapters/eink-mono.d.ts +0 -2
  216. package/dist/api/shared/display-adapters/eink-mono.js +0 -53
  217. package/dist/api/shared/display-adapters/ssd1309.d.ts +0 -2
  218. package/dist/api/shared/display-adapters/ssd1309.js +0 -136
  219. package/dist/api/shared/display-adapters/st7796.d.ts +0 -2
  220. package/dist/api/shared/display-adapters/st7796.js +0 -132
  221. package/dist/ir/heap-array-validation.d.ts +0 -24
  222. package/dist/ir/heap-array-validation.js +0 -29
package/dist/types.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { TargetProfile as CoreTargetProfile, PlatformContext as CorePlatformContext, SourceSpan as CoreSourceSpan, Diagnostic as CoreDiagnostic } from "./api/shared/index.js";
2
2
  export type EmitMode = "cpp" | "split";
3
+ export type ComplianceMode = "off" | "warn" | "strict";
3
4
  export type TargetProfile = CoreTargetProfile;
4
5
  export type PlatformContext = CorePlatformContext;
5
6
  export type SourceSpan = CoreSourceSpan;
@@ -95,6 +96,10 @@ export interface TranspileOptions {
95
96
  diagnostics?: boolean;
96
97
  /** Display profile config from cuttlefish.config.ts */
97
98
  display?: import("./api/shared/display-profile.js").DisplayConfig;
99
+ /** AUTOSAR C++14 compliance mode for emitted code (default: "off"). */
100
+ autosar?: ComplianceMode;
101
+ /** When true (and autosar is warn/strict), also emit the .autosar-deviations.arxml sidecar. */
102
+ autosarArxml?: boolean;
98
103
  }
99
104
  export interface LibraryDefinitionCondition {
100
105
  target?: TargetProfile;
@@ -114,7 +119,11 @@ export interface LibraryDefinition {
114
119
  variants?: LibraryDefinitionVariant[];
115
120
  }
116
121
  export interface CommandLineOptions {
117
- command: "default" | "build" | "gen-libdefs" | "gen-decls" | "map-error" | "preview";
122
+ command: "default" | "build" | "gen-libdefs" | "gen-decls" | "map-error" | "preview" | "doctor" | "licenses";
123
+ /** For `licenses`: treat unknown/missing licenses as failures (exit 1). */
124
+ strict?: boolean;
125
+ /** For `licenses`: scan all installed libraries (default: this project's only). */
126
+ all?: boolean;
118
127
  inputFile?: string;
119
128
  emitMode: EmitMode;
120
129
  target: TargetProfile;
@@ -130,8 +139,10 @@ export interface CommandLineOptions {
130
139
  monitor: boolean;
131
140
  /** Serial port for upload and monitor (e.g. COM4 or /dev/ttyACM0) */
132
141
  port?: string;
133
- /** Baud rate for monitor (default: 9600) */
134
- baud: number;
142
+ /** Baud rate for monitor. Undefined when --baud is absent so the consumer
143
+ * can fall back to config.console.baudRate (the framework monitor default
144
+ * applies only when neither is set). */
145
+ baud?: number;
135
146
  platformContext?: PlatformContext;
136
147
  mapFile?: string;
137
148
  cppFile?: string;
@@ -164,6 +175,10 @@ export interface CommandLineOptions {
164
175
  expectFile?: string;
165
176
  /** Generate diagnostics.md and diagnostics.json reports */
166
177
  diagnostics?: boolean;
178
+ /** AUTOSAR C++14 compliance mode for emitted code (default: "off"). */
179
+ autosar?: ComplianceMode;
180
+ /** When true (and autosar is warn/strict), also emit the .autosar-deviations.arxml sidecar. */
181
+ autosarArxml?: boolean;
167
182
  /** Config file for preview command */
168
183
  configPath?: string;
169
184
  /** Project root (dir of cuttlefish.config.ts); passed to transpileFile for the ESLint gate. */
@@ -181,6 +196,8 @@ export interface GeneratedOutputs {
181
196
  diagnostics: Diagnostic[];
182
197
  asyncTaskNames?: string[];
183
198
  usesTimers?: boolean;
199
+ /** Path to the diagnostics.md report, if --diagnostics was passed. */
200
+ diagnosticsReportPath?: string;
184
201
  }
185
202
  interface CompileErrorEntry {
186
203
  filePath: string;
@@ -208,6 +225,8 @@ export interface CreateCommandOptions {
208
225
  baud?: number;
209
226
  noSketch?: boolean;
210
227
  outDir?: string;
228
+ /** Skip the automatic `npm install` in the scaffolded project. */
229
+ noInstall?: boolean;
211
230
  }
212
231
  export interface BoardAddCommandOptions {
213
232
  command: "board-add";
package/dist/ui-hook.d.ts CHANGED
@@ -9,7 +9,6 @@ export interface LoweredUI {
9
9
  screenCount: number;
10
10
  imageTables: string;
11
11
  keyframeTables: string;
12
- scrollMemoryDiagnostics: Diagnostic[];
13
12
  diagnostics: Diagnostic[];
14
13
  }
15
14
  export interface UIModule {
@@ -58,7 +57,23 @@ export interface TranspilerUIHook {
58
57
  lowerOnMount(htmlPath: string, opts: LowerOptions): LoweredUI;
59
58
  resolveColor(input: string, format: "rgb565" | "rgb666" | "rgb888" | "mono"): number;
60
59
  resolveColorInternal(input: string, format: "rgb565" | "rgb666" | "rgb888" | "mono"): number;
61
- emitRuntimeHeader(): string;
60
+ /**
61
+ * Emits ONLY the CuttlefishGFX class definition (the shared GFX base for
62
+ * native display paths). Called separately from emitRuntimeHeader so the
63
+ * class can be emitted BEFORE display adapter declarations that
64
+ * instantiate CuttlefishGFX by value. Returns "" when active is false
65
+ * (Arduino path).
66
+ */
67
+ emitCuttlefishGfx(active: boolean): string;
68
+ /**
69
+ * Options controlling runtime-header emission.
70
+ * - nativeDisplayActive: when true, emit the shared CuttlefishGFX class
71
+ * (used by native display adapters on AVR/ESP32). Arduino paths pass
72
+ * false (default) and use Adafruit_GFX directly.
73
+ */
74
+ emitRuntimeHeader(opts?: {
75
+ nativeDisplayActive?: boolean;
76
+ }): string;
62
77
  splitUiFile(src: string): UiFileParts;
63
78
  generateProjectUITypeDeclarations(projectRoot: string): {
64
79
  written: string[];
@@ -67,7 +82,6 @@ export interface TranspilerUIHook {
67
82
  error: Error;
68
83
  }>;
69
84
  };
70
- analyzeScrollMemory(styled: unknown, budget: number): Diagnostic[];
71
85
  }
72
86
  /** Set the UI hook. Called by transpile.ts after dynamically loading
73
87
  * @typecad/ui/engine. Passing null clears it (end of transpile run). */
package/dist/utils/cli.js CHANGED
@@ -17,6 +17,8 @@ export function printHelp() {
17
17
  console.log(` cuttlefish board add <spec.jsonc> [--force] Generate board + MCU packages from a chip spec`);
18
18
  console.log(` cuttlefish gen-decls <input.cpp|--all <directory>>`);
19
19
  console.log(` cuttlefish map-error <mapFile> [options]`);
20
+ console.log(` cuttlefish doctor Check the active framework's environment (e.g. toolchain + board core)`);
21
+ console.log(` cuttlefish licenses [--all] [--strict] Scan this project's Arduino libraries for SPDX licenses (--all: every installed library)`);
20
22
  console.log();
21
23
  console.log(chalk.gray(`Transpilation is always performed first. Use --compile, --upload, and`));
22
24
  console.log(chalk.gray(`--monitor to chain operations after transpilation.`));
@@ -37,6 +39,16 @@ export function printHelp() {
37
39
  console.log(` --emit-maps <bool> Emit source maps: "true" or "false" (default: true)`);
38
40
  console.log(` Source maps enable mapping C++ errors back to TypeScript`);
39
41
  console.log();
42
+ console.log(` --autosar[=<mode>] AUTOSAR C++14 compliance mode for emitted code:`);
43
+ console.log(` off no enforcement (default)`);
44
+ console.log(` warn emit AUTOSAR_* diagnostics + sidecar, build still succeeds`);
45
+ console.log(` strict abort emit on unrecorded required violations`);
46
+ console.log(` A sidecar <name>.autosar-deviations.json is written next to the`);
47
+ console.log(` emitted artifact in warn/strict modes. See COMPLIANCE.md.`);
48
+ console.log();
49
+ console.log(` --autosar-arxml Also write <name>.autosar-deviations.arxml (Artop/DaVinci).`);
50
+ console.log(` No-op unless --autosar is warn or strict.`);
51
+ console.log();
40
52
  console.log(chalk.cyan(`BUILD COMMANDS`) + chalk.gray(` (chain in order: --compile → --upload → --monitor)`));
41
53
  console.log();
42
54
  console.log(` --compile Compile the generated output using the framework toolchain.`);
@@ -102,6 +114,12 @@ export function printHelp() {
102
114
  console.log(` --diagnostics Generate diagnostics.md and diagnostics.json reports`);
103
115
  console.log(` Includes IR graph, heap analysis, and task analysis`);
104
116
  console.log();
117
+ console.log(` --debug Inject Serial.println instrumentation at breakpoints.`);
118
+ console.log(` Reads .cuttlefish/breakpoints.json (written by the`);
119
+ console.log(` TypeCAD Debug VS Code extension). At each breakpoint the`);
120
+ console.log(` firmware prints the location, original line, and in-scope`);
121
+ console.log(` variables, then halts — press ENTER over serial to continue.`);
122
+ console.log();
105
123
  console.log(` --help, -h Show this help message`);
106
124
  console.log();
107
125
  console.log(chalk.cyan(`PROJECT CREATION`));
@@ -209,7 +227,11 @@ function parsePipelineCommand(argv, command, inputFile) {
209
227
  const emitMapsFlag = readFirstFlagValue(argv, ["--emit-maps"]);
210
228
  const buildTarget = readFirstFlagValue(argv, ["--build-target"]);
211
229
  const port = readFirstFlagValue(argv, ["--port"]);
212
- const baud = readNumberFlag(argv, ["--baud"], 9600) ?? 9600;
230
+ // Default to undefined (NOT 9600) so the build/upload/monitor flow's
231
+ // `options.baud ?? config.console.baudRate` falls through to the configured
232
+ // baud. Hardcoding 9600 here shadowed config.console.baudRate whenever --baud
233
+ // was absent (the monitor then opened the port at 9600, ignoring the config).
234
+ const baud = readNumberFlag(argv, ["--baud"]);
213
235
  const frameworkFlag = readFirstFlagValue(argv, ["--framework"]);
214
236
  const compile = readBooleanFlag(argv, ["--compile"]);
215
237
  const upload = readBooleanFlag(argv, ["--upload"]);
@@ -229,6 +251,32 @@ function parsePipelineCommand(argv, command, inputFile) {
229
251
  const keepUnusedTypes = readBooleanFlag(argv, ["--keep-unused-types"]);
230
252
  const keepUnusedVariables = readBooleanFlag(argv, ["--keep-unused-variables"]);
231
253
  const entryPoints = readRepeatedFlag(argv, "--entry-point");
254
+ // AUTOSAR C++14 compliance mode for emitted code. Accepts both
255
+ // `--autosar=strict` (= syntax) and `--autosar strict` (space syntax),
256
+ // plus the bare `--autosar` (treated as "strict"). Defaults to undefined,
257
+ // which the emitter treats as "off".
258
+ let autosar;
259
+ const autosarFlagIdx = argv.findIndex((a) => a === "--autosar" || a.startsWith("--autosar="));
260
+ if (autosarFlagIdx !== -1) {
261
+ const raw = argv[autosarFlagIdx];
262
+ if (raw === "--autosar") {
263
+ // Bare flag → strict. (No following value consumed.)
264
+ autosar = "strict";
265
+ }
266
+ else {
267
+ // --autosar=<mode>
268
+ const value = raw.slice("--autosar=".length);
269
+ if (value === "strict" || value === "warn" || value === "off") {
270
+ autosar = value;
271
+ }
272
+ else {
273
+ throw new Error(`--autosar must be one of: strict, warn, off (got: ${value})`);
274
+ }
275
+ }
276
+ }
277
+ // --autosar-arxml: also write the .autosar-deviations.arxml sidecar
278
+ // (Artop/DaVinci tooling). No-op unless --autosar is warn or strict.
279
+ const autosarArxml = readBooleanFlag(argv, ["--autosar-arxml"]);
232
280
  const emitMode = emitFlag === "cpp" || emitFlag === "split" ? emitFlag : "split";
233
281
  const emitMaps = emitMapsFlag === undefined ? true : emitMapsFlag !== "false";
234
282
  // Accept any target string — the framework package registers its own strategy id.
@@ -279,6 +327,8 @@ function parsePipelineCommand(argv, command, inputFile) {
279
327
  expect,
280
328
  expectFile,
281
329
  frameworkPackage: frameworkFlag,
330
+ autosar,
331
+ autosarArxml,
282
332
  };
283
333
  }
284
334
  export function parseCommandLine(argv) {
@@ -296,6 +346,7 @@ export function parseCommandLine(argv) {
296
346
  const baudRaw = readFirstFlagValue(argv, ["--baud"]);
297
347
  const outDir = readFirstFlagValue(argv, ["--outDir", "--out-dir", "-o"]);
298
348
  const noSketch = argv.includes("--no-sketch");
349
+ const noInstall = argv.includes("--no-install");
299
350
  const baud = baudRaw && !Number.isNaN(Number(baudRaw)) ? Number(baudRaw) : undefined;
300
351
  return {
301
352
  command: "create",
@@ -304,6 +355,7 @@ export function parseCommandLine(argv) {
304
355
  baud,
305
356
  framework,
306
357
  noSketch,
358
+ noInstall,
307
359
  outDir: outDir ? path.resolve(process.cwd(), outDir) : undefined,
308
360
  };
309
361
  }
@@ -337,6 +389,48 @@ export function parseCommandLine(argv) {
337
389
  port: port ? String(port) : undefined,
338
390
  };
339
391
  }
392
+ // doctor subcommand — verify the active framework's environment
393
+ if (firstArg === "doctor") {
394
+ return {
395
+ command: "doctor",
396
+ // The remaining pipeline fields are unused by doctor; fill with safe
397
+ // defaults, the same way the preview branch does.
398
+ inputFile: undefined,
399
+ emitMode: "split",
400
+ target: "generic",
401
+ outDir: undefined,
402
+ emitMaps: true,
403
+ noTranspile: false,
404
+ compile: false,
405
+ upload: false,
406
+ monitor: false,
407
+ watch: false,
408
+ baud: 9600,
409
+ platformContext: {},
410
+ };
411
+ }
412
+ // licenses subcommand — scan installed Arduino libraries for SPDX licenses
413
+ if (firstArg === "licenses") {
414
+ return {
415
+ command: "licenses",
416
+ strict: argv.includes("--strict"),
417
+ all: argv.includes("--all"),
418
+ // The remaining pipeline fields are unused by licenses; fill with safe
419
+ // defaults, the same way the doctor branch does.
420
+ inputFile: undefined,
421
+ emitMode: "split",
422
+ target: "generic",
423
+ outDir: undefined,
424
+ emitMaps: true,
425
+ noTranspile: false,
426
+ compile: false,
427
+ upload: false,
428
+ monitor: false,
429
+ watch: false,
430
+ baud: 9600,
431
+ platformContext: {},
432
+ };
433
+ }
340
434
  // Named subcommands
341
435
  if (firstArg === "gen-libdefs" || firstArg === "gen-decls" || firstArg === "map-error") {
342
436
  const command = firstArg;
@@ -387,12 +481,16 @@ export function parseCommandLine(argv) {
387
481
  // gen-decls - generate .d.ts from C++ files
388
482
  if (command === "gen-decls") {
389
483
  const allFlag = argv.includes("--all");
484
+ const componentsFlag = argv.includes("--components");
485
+ if (allFlag && componentsFlag) {
486
+ throw new Error("gen-decls: --components and --all are mutually exclusive. Use one or the other.");
487
+ }
390
488
  // The positional path may sit at argv[3] or argv[4] depending on whether
391
489
  // --all precedes or follows it. Scan argv starting after the subcommand
392
490
  // name (argv[2]) for the first token that is not a flag and not a known
393
491
  // flag's value. This mirrors the default-pipeline approach of "first
394
492
  // non-flag token wins".
395
- const booleanFlags = new Set(["--all"]);
493
+ const booleanFlags = new Set(["--all", "--components"]);
396
494
  const valueFlags = new Set([
397
495
  "--emit", "--target", "--outDir", "--out-dir", "--emit-maps", "--build-target",
398
496
  ]);
@@ -413,6 +511,28 @@ export function parseCommandLine(argv) {
413
511
  inputPath = tok;
414
512
  break;
415
513
  }
514
+ // --components mode: scan managed_components/ + components/ declared in
515
+ // cuttlefish.config.ts. Falls back to cwd when no path is given.
516
+ if (componentsFlag) {
517
+ const componentsDir = inputPath || process.cwd();
518
+ return {
519
+ command: "gen-decls",
520
+ inputFile: undefined,
521
+ emitMode,
522
+ target,
523
+ outDir: outDir ? path.resolve(process.cwd(), outDir) : undefined,
524
+ emitMaps,
525
+ noTranspile: false,
526
+ compile: false,
527
+ upload: false,
528
+ monitor: false,
529
+ watch: false,
530
+ baud: 9600,
531
+ platformContext,
532
+ scanDir: undefined,
533
+ componentsDir: path.resolve(process.cwd(), componentsDir),
534
+ };
535
+ }
416
536
  if (!inputPath && !allFlag) {
417
537
  throw new Error("Missing input C++ file path. Use: gen-decls <file.cpp> or gen-decls --all <directory>");
418
538
  }
@@ -2,3 +2,16 @@ export declare function ensureDir(dirPath: string): void;
2
2
  export declare function readText(filePath: string): string;
3
3
  export declare function writeText(filePath: string, content: string): void;
4
4
  export declare function listFiles(dirPath: string, extension: string): string[];
5
+ /**
6
+ * Recursive variant of {@link listFiles}. Walks `dirPath` depth-first and
7
+ * returns every file (in every subdirectory) whose name ends with `extension`.
8
+ *
9
+ * Used by {@link loadLibraryDefinitions} so libdefs under nested cache dirs
10
+ * like `.cuttlefish/component-decls/<component>/` are discovered. Purely
11
+ * additive vs. the non-recursive `listFiles` — single-level layouts keep
12
+ * working, nested layouts now also work.
13
+ *
14
+ * Returns absolute paths. Unreadable directories are silently skipped
15
+ * (matches `listFiles`'s not-exist behavior for non-existent roots).
16
+ */
17
+ export declare function listFilesRecursive(dirPath: string, extension: string): string[];
package/dist/utils/fs.js CHANGED
@@ -10,6 +10,15 @@ export function readText(filePath) {
10
10
  }
11
11
  export function writeText(filePath, content) {
12
12
  ensureDir(path.dirname(filePath));
13
+ // Skip writing when content is identical — preserves mtime so downstream
14
+ // build tools (idf.py/ninja, arduino-cli, make) can skip recompilation.
15
+ try {
16
+ if (fs.readFileSync(filePath, "utf8") === content)
17
+ return;
18
+ }
19
+ catch {
20
+ // File doesn't exist yet — fall through to write.
21
+ }
13
22
  fs.writeFileSync(filePath, content, "utf8");
14
23
  }
15
24
  export function listFiles(dirPath, extension) {
@@ -21,3 +30,44 @@ export function listFiles(dirPath, extension) {
21
30
  .filter((name) => name.toLowerCase().endsWith(extension.toLowerCase()))
22
31
  .map((name) => path.join(dirPath, name));
23
32
  }
33
+ /**
34
+ * Recursive variant of {@link listFiles}. Walks `dirPath` depth-first and
35
+ * returns every file (in every subdirectory) whose name ends with `extension`.
36
+ *
37
+ * Used by {@link loadLibraryDefinitions} so libdefs under nested cache dirs
38
+ * like `.cuttlefish/component-decls/<component>/` are discovered. Purely
39
+ * additive vs. the non-recursive `listFiles` — single-level layouts keep
40
+ * working, nested layouts now also work.
41
+ *
42
+ * Returns absolute paths. Unreadable directories are silently skipped
43
+ * (matches `listFiles`'s not-exist behavior for non-existent roots).
44
+ */
45
+ export function listFilesRecursive(dirPath, extension) {
46
+ if (!fs.existsSync(dirPath)) {
47
+ return [];
48
+ }
49
+ const ext = extension.toLowerCase();
50
+ const out = [];
51
+ const stack = [dirPath];
52
+ while (stack.length > 0) {
53
+ const cur = stack.pop();
54
+ let entries;
55
+ try {
56
+ entries = fs.readdirSync(cur, { withFileTypes: true });
57
+ }
58
+ catch {
59
+ // Permission error / race / etc. Skip this subtree.
60
+ continue;
61
+ }
62
+ for (const entry of entries) {
63
+ const full = path.join(cur, entry.name);
64
+ if (entry.isDirectory()) {
65
+ stack.push(full);
66
+ }
67
+ else if (entry.isFile() && entry.name.toLowerCase().endsWith(ext)) {
68
+ out.push(full);
69
+ }
70
+ }
71
+ }
72
+ return out;
73
+ }
package/dist/utils/ui.js CHANGED
@@ -86,7 +86,9 @@ export function printMonitoring(port, baud) {
86
86
  * Print success message
87
87
  */
88
88
  export function printSuccess(message = "Done") {
89
- console.log(chalk.green(`${ICON_SUCCESS} ${message}`));
89
+ // Cyan (not green) so the completion marker matches the cyan step indicators
90
+ // (⇉ Compiling / Uploading / Transpiling). The ✓ icon conveys success.
91
+ console.log(chalk.cyan(`${ICON_SUCCESS} ${message}`));
90
92
  }
91
93
  /**
92
94
  * Print error message
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typecad/cuttlefish",
3
- "version": "0.1.0-alpha.2",
3
+ "version": "1.0.0-alpha.10",
4
4
  "description": "TypeScript to C++ transpiler — native, Arduino, and bare-metal targets",
5
5
  "type": "module",
6
6
  "main": "./dist/transpile.js",
@@ -29,10 +29,22 @@
29
29
  "types": "./dist/ui-hook.d.ts",
30
30
  "default": "./dist/ui-hook.js"
31
31
  },
32
+ "./safety-hook-types": {
33
+ "types": "./dist/safety-hook.d.ts",
34
+ "default": "./dist/safety-hook.js"
35
+ },
36
+ "./build-ir-state": {
37
+ "types": "./dist/ir/build-ir-state.d.ts",
38
+ "default": "./dist/ir/build-ir-state.js"
39
+ },
32
40
  "./config-loader": {
33
41
  "types": "./dist/config-loader.d.ts",
34
42
  "default": "./dist/config-loader.js"
35
43
  },
44
+ "./utils/ui": {
45
+ "types": "./dist/utils/ui.d.ts",
46
+ "default": "./dist/utils/ui.js"
47
+ },
36
48
  "./stores/display-profile-store": {
37
49
  "types": "./dist/stores/display-profile-store.d.ts",
38
50
  "default": "./dist/stores/display-profile-store.js"
@@ -49,6 +61,10 @@
49
61
  "types": "./dist/emit/route-hal-op.d.ts",
50
62
  "default": "./dist/emit/route-hal-op.js"
51
63
  },
64
+ "./lib/component-decls": {
65
+ "types": "./dist/libdef/component-decls.d.ts",
66
+ "default": "./dist/libdef/component-decls.js"
67
+ },
52
68
  "./ir/transformers/ui-lowering": {
53
69
  "types": "./dist/ir/transformers/ui-lowering.d.ts",
54
70
  "default": "./dist/ir/transformers/ui-lowering.js"
@@ -83,15 +99,19 @@
83
99
  "zod": "^3.24.0"
84
100
  },
85
101
  "peerDependencies": {
86
- "@typecad/ui": "0.1.0-alpha.2"
102
+ "@typecad/ui": "1.0.0-alpha.10",
103
+ "@typecad/safety": "1.0.0-alpha.10"
87
104
  },
88
105
  "peerDependenciesMeta": {
89
106
  "@typecad/ui": {
90
107
  "optional": true
108
+ },
109
+ "@typecad/safety": {
110
+ "optional": true
91
111
  }
92
112
  },
93
113
  "optionalDependencies": {
94
- "@typecad/framework-native": "0.1.0-alpha.2"
114
+ "@typecad/framework-native": "1.0.0-alpha.10"
95
115
  },
96
116
  "devDependencies": {
97
117
  "@types/node": "^22.10.7"
@@ -1,2 +0,0 @@
1
- import type { DisplayAdapterGenerator } from "../display-adapter.js";
2
- export declare const einkMonoAdapter: DisplayAdapterGenerator;
@@ -1,53 +0,0 @@
1
- // ---------------------------------------------------------------------------
2
- // eink-mono display adapter — 1-bit B&W e-ink panels (SSD1680-class, e.g. the
3
- // common 296×128 / 250×122 breakouts). Deferred refresh: no fillScreen on init
4
- // (a full clear flashes), and a partial-refresh entry point the runtime's dirty-
5
- // rect union calls once per frame.
6
- //
7
- // Library note: targets Adafruit_EPD (Adafruit_SSD168x). The exact partial-
8
- // refresh method name varies by library (Adafruit_EPD: refreshPartial / GxEPD:
9
- // updateWindow). Verify against the target library before flashing — the shim
10
- // shape is correct; the method call is library-specific. TODO Phase 5.
11
- // ---------------------------------------------------------------------------
12
- export const einkMonoAdapter = (display) => {
13
- const cs = display._mountCs;
14
- const dc = display._mountDc;
15
- const rst = display._mountRst;
16
- const rotation = display.rotation ?? 0;
17
- const w = display.width;
18
- const h = display.height;
19
- return {
20
- includes: [
21
- "#include <Adafruit_GFX.h>",
22
- "#include <Adafruit_EPD.h>",
23
- ].join("\n"),
24
- // busy pin = -1 (unused); SRCS+D/C+RST+CS wiring. Adafruit_SSD168x(width, height, dc, rst, cs, busy).
25
- declaration: `Adafruit_SSD168x __tc_display(${w}, ${h}, ${dc}, ${rst}, ${cs}, -1);`,
26
- functions: [
27
- "// --- Display adapter: eink-mono (SSD1680-class, 1-bit, deferred refresh) ---",
28
- "static inline void display_init() {",
29
- " __tc_display.begin();",
30
- ` __tc_display.setRotation(${rotation});`,
31
- " // No full-screen clear here — e-ink flashes on a full clear. The runtime",
32
- " // marks all nodes dirty (UI_REFRESH_DEFERRED) and the first flush repaints",
33
- " // via partial refresh instead.",
34
- "}",
35
- "",
36
- "static inline CuttlefishDisplayTarget* display_defaultTarget() { return &__tc_display; }",
37
- "static inline int16_t display_width() { return __tc_display.width(); }",
38
- "static inline int16_t display_height() { return __tc_display.height(); }",
39
- "static inline void display_startWrite() {}",
40
- "static inline void display_endWrite() {}",
41
- "static inline void display_setAddrWindow(int16_t x, int16_t y, int16_t w, int16_t h) { (void)x; (void)y; (void)w; (void)h; }",
42
- // Partial refresh: push just the dirty region. The runtime draws into the
43
- // EPD's built-in GFX buffer (the display IS the backing store for 1-bit),
44
- // then calls this with the unioned dirty rect. TODO Phase 5: verify the
45
- // exact partial-refresh API for the target EPD library.
46
- "static inline void display_partial_refresh(int16_t x, int16_t y, int16_t w, int16_t h) {",
47
- " __tc_display.refreshPartial(x, y, (uint16_t)w, (uint16_t)h);",
48
- "}",
49
- // drawPixel goes through GFX into the EPD buffer; partial_refresh publishes it.
50
- "static inline void display_fillScreen(uint32_t color) { __tc_display.fillScreen(color ? EPD_WHITE : EPD_BLACK); }",
51
- ].join("\n"),
52
- };
53
- };
@@ -1,2 +0,0 @@
1
- import type { DisplayAdapterGenerator } from "../display-adapter.js";
2
- export declare const ssd1309Adapter: DisplayAdapterGenerator;