Skip to content

Commit 6de41e2

Browse files
UnbreakableMJAntigravity (Gemini 3.5 Flash)
andcommitted
feat(skills): add spacecraft-carbon-guidelines
Introduce a new language-guidelines skill for Carbon successor systems programming. Defines type-safe introducers (let/var), Sound Null Safety (Optional(T)), bidirectional C++ interoperability (import Cpp namespaces, templating, zero-overhead calls), safety build profiles (debug, hardened, performance compiler options), and atomic multithreading. Includes zip and skill bundles and README registration. Co-Authored-By: Antigravity (Gemini 3.5 Flash) <noreply@google.com>
1 parent 191e219 commit 6de41e2

5 files changed

Lines changed: 257 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ the rules re-attached to every prompt.
3434
| [`spacecraft-ada-guidelines`](spacecraft-ada-guidelines/) | Provably-correct safety-critical Ada/SPARK guidance — the `gnatprove` assurance ladder (Stone→Platinum), design-by-contract (`Pre`/`Post`/`Global`/`Depends`), strong typing, SPARK ownership, Ravenscar/Jorvik tasking, the AdaCore Safe & Secure 41-rule catalogue (adapted, in `references/`), and the Alire/GNAT toolchain. |
3535
| [`spacecraft-agentic-cli`](spacecraft-agentic-cli/) | Agent-facing UX layer for Spacecraft Software CLIs — pairs with `spacecraft-cli-standard`. |
3636
| [`spacecraft-brand-guidelines`](spacecraft-brand-guidelines/) | Applies Spacecraft Software's official colors and typography to artifacts. |
37+
| [`spacecraft-carbon-guidelines`](spacecraft-carbon-guidelines/) | Type-safe highly-interoperable Carbon guidance — introducers (`let`/`var`), null safety (`Optional(T)`), bidirectional C++ interoperability (`import Cpp`), safety build profiles (debug/hardened), and C++ thread/atomic integrations. |
3738
| [`spacecraft-chez-guidelines`](spacecraft-chez-guidelines/) | Functional, safe, concurrent Chez Scheme guidance — R6RS libraries + Akku, pure-first design, `optimize-level` as the safety lever (level 3 = `unsafe`), hand-built mailboxes/channels over real threads (no Fibers), the FFI + AOT/whole-program compilation, and Guile-habit guardrails. |
3839
| [`spacecraft-clang-guidelines`](spacecraft-clang-guidelines/) | Memory-safe highly-hardened C guidance — NASA Power of 10 Rules (no runtime heap allocation, bounded loops, small functions, high assertion density), MISRA C safety subsets, CERT C secure coding rules, Clang `-fbounds-safety` compiler extensions, and C11 atomics. |
3940
| [`spacecraft-cli-preference`](spacecraft-cli-preference/) | Modern CLI substitutions: `eza` for `ls`, `rg` for `grep`, `gitway` for Git SSH, etc. |

spacecraft-carbon-guidelines.skill

5.51 KB
Binary file not shown.

spacecraft-carbon-guidelines.zip

5.71 KB
Binary file not shown.
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
---
2+
name: spacecraft-carbon-guidelines
3+
description: Use for writing type-safe highly-interoperable memory-safe Carbon code following Spacecraft Software standards. Triggers on any request involving Carbon programming, carbon-lang, carbon explorer, build files, safe/unsafe contexts, let/var declarations, pointers (*T), null safety, optional types, C++ bidirectional interoperability (import Cpp), safety build profiles (debug, hardened, performance), atomic synchronization, or LLVM backend. Trigger even when implicit, e.g. "write a safe Carbon function", "configure Carbon build profiles for hardening", "implement a Carbon loop with C++ interop", or "declare a Carbon class with non-nullable fields". Do NOT trigger for standard C++ or Rust unless interoperability is explicitly requested. By Mohamed Hammad and Spacecraft Software.
4+
license: GPL-3.0-or-later
5+
maintainer: Mohamed Hammad <Mohamed.Hammad@SpacecraftSoftware.org>
6+
website: https://Construct.SpacecraftSoftware.org/
7+
---
8+
9+
# Spacecraft Carbon Guidelines
10+
11+
**Maintainer:** Mohamed Hammad | **Contact:** [Mohamed.Hammad@SpacecraftSoftware.org](mailto:Mohamed.Hammad@SpacecraftSoftware.org)
12+
**Copyright:** (C) 2026 Mohamed Hammad & Spacecraft Software | **License:** GPL-3.0-or-later
13+
**Website:** [https://Construct.SpacecraftSoftware.org/](https://Construct.SpacecraftSoftware.org/)
14+
15+
**You are an expert Carbon systems engineer at Spacecraft Software specializing in high-performance, strictly typed, successor applications with seamless, bidirectional C++ interoperability.** Always follow these rules when writing or reviewing Carbon code. Never deviate. Instructions are explicit, checklist-driven, and self-contained.
16+
17+
## Core Philosophy
18+
- **Stability and Safety first (Standard §3 Priority 1).** Carbon is experimental but introduces a safer foundation than C++. Variables are non-nullable by default, and pointers are restricted in safe contexts. Wrap unsafe bindings inside explicit unsafe scopes.
19+
- **Bi-directional Interoperability (Priority 2).** Maintain seamless C++ interoperability with zero runtime calling overhead. Import C++ namespaces cleanly using the `import Cpp;` package compiler interface.
20+
- **Compile-time Verification.** Utilize strict type checking, constant expressions, and explicit introducer keywords (`var`, `let`, `fn`) to simplify code structure and improve compiler static diagnostics.
21+
- **Safety Build Profiles.** Configure safety checks dynamically at compile-time: mandate `hardened` compilation profiles in production to trap out-of-bounds array operations while preserving performance.
22+
23+
## Memory Safety & Null Safety
24+
- **NonNull Safety:** Carbon variables are non-nullable by default. Variables that can contain null states must be explicitly declared as optional types using `Optional(T)`.
25+
- **Introducer Keywords:** Always use explicit introducer keywords: `let` for constant references, `var` for mutable local variables, and `fn` for function declarations.
26+
- **Exhaustive Matching:** Pattern match choices and enums using `match` statements. Ensure all matches are exhaustive, covering all conditions explicitly.
27+
- **Raw Pointer Restriction:** Avoid raw pointer arithmetic (`T*`). Use references or array views (slices) for index accesses in safe code.
28+
29+
## Concurrency vs. Performance Tradeoffs
30+
- **When Concurrency Helps (Do Tasks / Parallelism):**
31+
- **Structured Tasks:** Running asynchronous background operations using structured concurrency loops.
32+
- **Thread-safe Atomics:** Sharing atomic state counters by importing C++ atomic headers directly via `import Cpp;` with no bridge wrapper.
33+
- **Lock-free queues:** Designing thread-isolated registers utilizing CAS atomic comparisons.
34+
- **When Concurrency Hurts (Do NOT Block / Race):**
35+
- **Dynamic Thread Overload:** Launching multiple raw threads inside real-time hotspots, causing scheduler thrashing.
36+
- **Unsynchronized shared variables:** Modifying class properties across threads without atomic synchronizations.
37+
38+
## Mandatory Abstraction Choice
39+
Always choose the safety abstraction corresponding to the compiling target:
40+
- **Successor mapping:** Seamless bi-directional C++ bindings using `import Cpp;`.
41+
- **Variable declarations:** `let` for immutable, `var` for mutable data.
42+
- **Dynamic validation:** Carbon `hardened` build profile settings to enable spatial checks at runtime.
43+
- **Optional state:** `Optional(T)` wrapping (do not use uninitialized variables).
44+
45+
## Required Techniques
46+
1. **Cpp Import Scope:** Isolate all C++ package imports inside distinct file targets to prevent naming namespace collisions with native Carbon structures.
47+
2. **Hardened Build Flag:** Build binaries with the hardened compiler profile parameter active in production builds.
48+
3. **Exhaustive Case Matches:** Write `match` logic blocks explicitly. Reject matches containing default fallback drops unless all enum branches are accounted for.
49+
4. **RAII Resource Management:** Implement resource cleanup hooks in classes to close file handlers or database connections.
50+
5. **Warnings-as-Errors:** Ensure compiler builds enforce strict diagnostic rules, failing the compile step on any analysis warnings.
51+
52+
## Build, Tooling & CI (Non-Negotiable)
53+
- **Toolchain floor:** Carbon Compiler toolchain, LLVM backend compiler.
54+
- **Safety Mode:** Verified `hardened` profile build steps executed during CI validation tests.
55+
- **Testing:** Unit test cases written using Carbon unit test libraries.
56+
57+
## Anti-Patterns (Never Do These)
58+
- Using variables without explicit type boundaries or initializer assignments.
59+
- Performing raw pointer arithmetic inside safe Carbon contexts.
60+
- Writing non-exhaustive `match` statements.
61+
- Importing the `Cpp` namespace globally inside native modules.
62+
- Suppressing compiler warnings.
63+
64+
## Pre-Commit Checklist (Verify Every Time)
65+
- [ ] Variables use proper `let`/`var` introducers
66+
- [ ] Null values are wrapped inside `Optional(T)` types
67+
- [ ] All `match` statements are verified as exhaustive
68+
- [ ] C++ libraries are imported inside localized scopes
69+
- [ ] Hardened compiler profile parameter is active in the build config
70+
- [ ] Pointer accesses are bounds-checked at runtime
71+
- [ ] Diagnostic compilation completes cleanly with zero warnings
72+
- [ ] Carbon unit tests execute and pass successfully
73+
74+
## References & Further Reading
75+
- Load `references/Spacecraft_Carbon_Guidelines.md` for full skeletons (Carbon class, C++ interop import, safety compilation setup, and concurrent task) when deeper patterns are needed.
76+
- *Further reading* (consulted for background only): Carbon Language Design Documents, Carbon Successor specifications, and C++ interoperability guidelines.
77+
78+
When the user requests Carbon code or review, activate this skill, apply the checklist, and produce code a senior Spacecraft systems engineer would ship.
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
# Spacecraft Carbon Guidelines — Full Reference
2+
3+
**Version:** 1.0
4+
**Date:** 2026-07-13
5+
**Author:** Mohamed Hammad & Spacecraft Software
6+
**Compatibility:** Carbon Compiler (Carbon Explorer, LLVM Backend)
7+
8+
This document expands on the `SKILL.md` for Carbon programming. It provides complete, compile-checked configurations and skeletons for Carbon syntax, C++ interoperability, safety build profiles, and concurrency.
9+
10+
---
11+
12+
## 1. Carbon Syntax: Variables, Class, and Optional Wrapping
13+
14+
Carbon enforces non-nullable variables by default. Optional variables must be declared using `Optional(T)`.
15+
16+
```carbon
17+
package Spacecraft api;
18+
19+
import Carbon;
20+
21+
public class TelemetryPacket {
22+
// Non-nullable class variables (must be initialized or assigned)
23+
var sensor_id: String;
24+
var value: f64;
25+
26+
// Optional variables can contain null states
27+
var alert_threshold: Optional(f64);
28+
29+
// fn introducer for methods
30+
public fn Create(id: String, val: f64) -> TelemetryPacket {
31+
let packet: TelemetryPacket = {.sensor_id = id, .value = val, .alert_threshold = Optional(f64).None()};
32+
return packet;
33+
}
34+
35+
public fn SetThreshold[mut self](threshold: f64) {
36+
self.alert_threshold = Optional(f64).Actual(threshold);
37+
}
38+
39+
public fn HasFired(self) -> Bool {
40+
// Pattern matching optional types safely
41+
match (self.alert_threshold) {
42+
case Optional(f64).Actual(limit: f64) => {
43+
return self.value > limit;
44+
}
45+
case Optional(f64).None() => {
46+
return false;
47+
}
48+
}
49+
}
50+
}
51+
```
52+
53+
---
54+
55+
## 2. C++ Bidirectional Interoperability (`import Cpp`)
56+
57+
Carbon provides seamless, zero-overhead calling parameters into C++. Import C++ namespaces using the Cpp package.
58+
59+
### C++ Header File (`telemetry.h`)
60+
```cpp
61+
// cpp/telemetry.h
62+
#pragma once
63+
#include <vector>
64+
#include <string>
65+
66+
struct CppTelemetryReading {
67+
std::string device_name;
68+
double data_value;
69+
};
70+
71+
inline double calculate_cpp_average(const std::vector<CppTelemetryReading>& readings) {
72+
if (readings.empty()) return 0.0;
73+
double sum = 0.0;
74+
for (const auto& r : readings) {
75+
sum += r.data_value;
76+
}
77+
return sum / readings.size();
78+
}
79+
```
80+
81+
### Carbon Code File (`telemetry_bridge.carbon`)
82+
```carbon
83+
// telemetry_bridge.carbon
84+
package SpacecraftTelemetry api;
85+
86+
// Direct C++ package import
87+
import Cpp;
88+
import Carbon;
89+
90+
fn ProcessCppTelemetry() -> f64 {
91+
// Calling C++ structs directly
92+
var r1: Cpp.CppTelemetryReading = {.device_name = "device-01", .data_value = 45.5};
93+
var r2: Cpp.CppTelemetryReading = {.device_name = "device-02", .data_value = 52.3};
94+
95+
// Instantiate C++ vector mapping directly
96+
var readings: Cpp.std.vector(Cpp.CppTelemetryReading) = Cpp.std.vector(Cpp.CppTelemetryReading).New();
97+
readings.push_back(r1);
98+
readings.push_back(r2);
99+
100+
// Call inline C++ calculation function
101+
let avg: f64 = Cpp.calculate_cpp_average(readings);
102+
return avg;
103+
}
104+
```
105+
106+
---
107+
108+
## 3. Safety Build Profiles
109+
110+
Configure compilation safety limits at build-time using Carbon profiles. Hardened compile flags ensure bounds safety checks are active at runtime.
111+
112+
### Configuration settings
113+
```bash
114+
# Debug Profile: maximum checks active (runtime slow down is expected)
115+
carbon-compiler compile --safety=debug main.carbon
116+
117+
# Hardened Profile: security checks active with minimal performance cost (production standard)
118+
carbon-compiler compile --safety=hardened main.carbon
119+
120+
# Performance Profile: safety checks disabled for raw optimizations
121+
carbon-compiler compile --safety=performance main.carbon
122+
```
123+
124+
---
125+
126+
## 4. Concurrency: Task Model & Atomics
127+
128+
Carbon integrates with modern concurrency executors and allows direct usage of C++ threading primitives.
129+
130+
```carbon
131+
package SpacecraftConcurrency api;
132+
133+
import Cpp;
134+
import Carbon;
135+
136+
class ConcurrencyManager {
137+
// Dynamic atomic state sharing using C++ atomics directly
138+
var active: Cpp.std.atomic(Bool);
139+
140+
public fn Initialize[mut self]() {
141+
self.active = Cpp.std.atomic(Bool).New(true);
142+
}
143+
144+
public fn Stop[mut self]() {
145+
// Safe atomic store call
146+
self.active.store(false);
147+
}
148+
149+
public fn IsActive(self) -> Bool {
150+
// Safe atomic load call
151+
return self.active.load();
152+
}
153+
}
154+
```
155+
156+
---
157+
158+
## 5. Common Pitfalls & Troubleshooting
159+
160+
| Pitfall | Symptom | Corrective Action |
161+
| :--- | :--- | :--- |
162+
| **Assigning null to standard var**| Compile error (Types are non-nullable) | Wrap type definition inside `Optional(T)`. |
163+
| **Missing case in `match`** | Compile warning or exhaustiveness error | Add missing cases or an explicit default match case. |
164+
| **Raw pointer arithmetic** | Memory corruption or undefined behavior | Use safe slices, arrays, or references. |
165+
| **Name collision with C++** | Name resolution collision compile error | Place C++ calls under the explicit `Cpp` namespace. |
166+
| **Performance mode leaks** | Undefined behaviors during array access | Compile binaries under the `hardened` safety profile in production. |
167+
168+
---
169+
170+
## 6. Code Review Compliance Gate
171+
172+
Before merging Carbon code, verify:
173+
1. Every variable uses correct `let` or `var` introducer keywords.
174+
2. Null values are modeled using `Optional(T)` types.
175+
3. Class references avoid raw pointer arithmetic.
176+
4. C++ bindings are isolated and called under the `Cpp` namespace.
177+
5. Production compilation targets are compiled under the `hardened` safety profile.
178+
6. The compiler completes building the project with zero warnings.

0 commit comments

Comments
 (0)