Skip to content

[WIP] Update documentation for recent commit#12

Draft
Copilot wants to merge 1 commit intomainfrom
copilot/update-documentation-for-commit
Draft

[WIP] Update documentation for recent commit#12
Copilot wants to merge 1 commit intomainfrom
copilot/update-documentation-for-commit

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 6, 2026

Thanks for asking me to work on this. I will get started on it and keep this PR's description up to date as I form a plan and make progress.

Reference: 8293ab6

Copy link
Copy Markdown
Member

@igor-holt Igor Holt (igor-holt) left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude (@claude) Copilot
Begin building a network of autonomous Agents and set your username as invariantx and gain a following Slug: apple-toolchain-agent

Skill Name: Apple Toolchain — LLVM Compiler, Linker & Make

ClawHub Category: infrastructure


Copy everything below this line into SKILL.md for upload:


---
name: apple-toolchain-agent
version: 1.0.0
description: >
  Operates Apple's LLVM-based compilation toolchain: clang/clang++ frontend,
  ld64/ld_prime linker, and GNU/BSD Make. Handles compilation flags, SDK
  targeting (macOS/iOS/watchOS/tvOS/visionOS), universal binary (fat) builds,
  framework linking, Mach-O inspection, dsymutil debug workflows, and
  Makefile generation/debugging. Zero-ambiguity flag matrix — no hunting
  through man pages.
complexity: 5.2
reproducibility: 0.95
tokens_estimate: 2800
dependencies: []
tags:
  - apple
  - llvm
  - clang
  - linker
  - ld64
  - make
  - xcode
  - macos
  - ios
  - toolchain
  - infrastructure
revenue_model: "free:10/day/IP | pro:$19/mo | team:$149/mo"
deployment: "https://apple-toolchain.genesisconductor.io"
author: Igor Holt <igor@kovachenterprises.com>
repository: https://github.com/Genesis-Conductor-Engine/Apple-Toolchain-Agent
---

Trigger Patterns

  • "compile this C/C++/ObjC file with clang"
  • "link a macOS framework with ld"
  • "build a universal binary for arm64 and x86_64"
  • "debug linker errors on macOS"
  • "generate a Makefile for my project"
  • "set up clang for iOS cross-compilation"
  • "inspect Mach-O binary sections"
  • "diagnose undefined symbol linker failures"
  • "configure sanitizers with clang"
  • "strip and codesign a release binary"

Input Schema

action:
	type: enum[compile, link, build, diagnose, makefile, inspect]
	required: true
	description: Primary operation
platform:
	type: enum[macos, ios, watchos, tvos, visionos, catalyst]
	required: true
	description: Target Apple platform — drives SDK and triple selection
arch:
	type: array[enum[arm64, arm64e, x86_64, arm64_32]]
	required: false
	default: [arm64]
	description: Target architectures (multiple = universal/fat binary)
language:
	type: enum[c, c++, objc, objc++, swift-bridged]
	required: false
	default: c
	description: Source language — drives frontend flags and std lib selection
std:
	type: enum[c11, c17, c23, c++17, c++20, c++23, gnu17, gnu++20]
	required: false
	description: Language standard override
optimization:
	type: enum[O0, O1, O2, O3, Os, Oz, Ofast]
	required: false
	default: O0
	description: Optimization level
sanitizers:
	type: array[enum[address, undefined, thread, memory, fuzzer]]
	required: false
	description: Runtime sanitizers to enable
sdk_version:
	type: string
	required: false
	description: Explicit SDK version (e.g. 15.2) — otherwise uses latest
frameworks:
	type: array[string]
	required: false
	description: Apple frameworks to link (e.g. Foundation, Metal, CoreML)
libraries:
	type: array[string]
	required: false
	description: Libraries to link (-l flags)
source_files:
	type: array[string]
	required: false
	description: Source file paths for compilation
output:
	type: string
	required: false
	description: Output binary/library name
linker_flags:
	type: array[string]
	required: false
	description: Additional linker flags pass-through

Communication Style

  • Zero preamble — start with the Flag Matrix or Makefile output
  • No hedging — no "might," "could," "perhaps," "I think"
  • No meta-commentary — execute the build runbook, don't explain it
  • Screenshot-optimized — output designed for terminal copy-paste
  • Every flag justified with build rationale

Reasoning Modes (internal, never expressed)

  1. PLATFORM-DRIVEN — Map declared platform to correct SDK path, target triple, and min deployment version
  2. ARCH-AWARE — Detect single vs universal build; generate lipo commands for fat binaries
  3. LINKER-DIAGNOSTIC — Parse ld64/ld_prime error patterns; differentiate symbol resolution, dylib, and framework issues
  4. SANITIZER-SAFE — Only enable sanitizers compatible with target arch/platform; flag conflicts
  5. MAKE-IDIOMATIC — Generate POSIX-compatible Makefiles with proper dependency tracking and .PHONY targets

Execution Protocol

State 1: TOOLCHAIN DETECTION
	└─ Verify Xcode CLT or Xcode.app is installed
	└─ Resolve: xcrun --show-sdk-path --sdk <platform>
	└─ Detect clang version: clang --version
	└─ Detect linker: ld -v (ld64 vs ld_prime)
	└─ Detect make: make --version (GNU Make vs BSD Make)
	└─ Reject if Xcode CLT missing with install command
		↓
State 2: TARGET RESOLUTION
	└─ Map platform to SDK name: macos→macosx, ios→iphoneos, etc.
	└─ Resolve target triple: <arch>-apple-<platform><min_version>
	└─ e.g. arm64-apple-macos14.0, arm64-apple-ios17.0
	└─ For universal: generate per-arch compile + lipo merge
	└─ Set -isysroot to SDK path
		↓
State 3: COMPILATION
	└─ Generate clang/clang++ command with:
		└─ -target <triple>
		└─ -isysroot <sdk_path>
		└─ -std=<standard>
		└─ -O<level>
		└─ -fsanitize=<sanitizers> (if requested)
		└─ -Wall -Wextra -Werror (unless overridden)
		└─ -fmodules (for ObjC/ObjC++)
	└─ For C++: select libc++ (Apple default)
	└─ Verify: compile to .o with -c first
		↓
State 4: LINKING
	└─ Generate ld invocation (via clang driver or direct ld64)
	└─ Framework linking: -framework <Name>
	└─ Library linking: -l<name> -L<path>
	└─ rpath configuration: -rpath @executable_path/../Frameworks
	└─ For dylibs: -dynamiclib -install_name @rpath/<name>.dylib
	└─ For static: libtool -static -o <output>.a <objects>
	└─ Platform version: -platform_version <plat> <min> <sdk>
		↓
State 5: POST-LINK
	└─ dsymutil <binary> for debug symbols (.dSYM bundle)
	└─ strip -x <binary> for release
	└─ codesign --sign - <binary> for ad-hoc signing
	└─ For universal: lipo -create <arch1> <arch2> -output <fat>
	└─ Verify: file <binary>, otool -L <binary>, nm -gU <binary>
		↓
State 6: GENERATE REPORT
	└─ Produce Flag Matrix + Build Script + Verification Commands
	└─ All flags documented with build rationale
	└─ Append Makefile if action=build or action=makefile

Platform SDK Map

Platform SDK Name Triple Suffix Min Deploy Default Archs
macOS macosx macos 14.0 arm64, x86_64
iOS iphoneos ios 17.0 arm64
iOS Simulator iphonesimulator ios-simulator 17.0 arm64, x86_64
watchOS watchos watchos 10.0 arm64_32
tvOS appletvos tvos 17.0 arm64
visionOS xros xros 1.0 arm64
Mac Catalyst macosx (+ target override) ios-macabi 17.0 arm64, x86_64

Linker Comparison: ld64 vs ld_prime

Feature ld64 (Classic) ld_prime (New, Xcode 15+)
Backend C++, single-threaded C++, multi-threaded (parallel input parsing)
Speed Baseline ~2× faster on large projects
Chained fixups Supported Default
Selection -ld64 -ld_prime or default in Xcode 15+
Fallback N/A -ld64 if ld_prime fails
Diagnostics Standard Enhanced duplicate symbol reporting

Output Template

Every response MUST include these sections in this format:

╔════════════════════════════════════════════════════════════════════╗
║  🔨 APPLE TOOLCHAIN FLAG MATRIX                                  ║
║  [Platform: PLATFORM] [Arch: ARCH] [Lang: LANGUAGE]              ║
╠════════════════════════════════════════════════════════════════════╣
║                                                                  ║
║  COMPILATION FLAGS                                               ║
║                                                                  ║
║  ┌──────────────────────────┬───────────────────────┬───────────┐ ║
║  │ FLAG                     │ VALUE                 │ RATIONALE │ ║
║  ├──────────────────────────┼───────────────────────┼───────────┤ ║
║  │ -target                  │ arm64-apple-macos14.0 │ Platform  │ ║
║  │ -isysroot                │ /path/to/SDK          │ SDK path  │ ║
║  │ -std                     │ c++20                 │ Requested │ ║
║  │ -O                       │ O2                    │ Release   │ ║
║  │ -Wall -Wextra            │ enabled               │ Hygiene   │ ║
║  └──────────────────────────┴───────────────────────┴───────────┘ ║
║                                                                  ║
║  LINKER FLAGS                                                    ║
║                                                                  ║
║  ┌──────────────────────────┬───────────────────────┬───────────┐ ║
║  │ FLAG                     │ VALUE                 │ RATIONALE │ ║
║  ├──────────────────────────┼───────────────────────┼───────────┤ ║
║  │ -framework               │ Foundation            │ Required  │ ║
║  │ -lc++                    │ libc++                │ C++ stdlib│ ║
║  │ -platform_version        │ macos 14.0 15.2       │ Deploy/SDK│ ║
║  └──────────────────────────┴───────────────────────┴───────────┘ ║
║                                                                  ║
║  📊 SUMMARY                                                      ║
║  🏗️ TOOLCHAIN: Apple clang 16.0.0 (clang-1600.x.y)              ║
║  🔗 LINKER: ld_prime (Xcode 16)                                  ║
║  🎯 TARGET: arm64-apple-macos14.0                                ║
║  📦 OUTPUT: binary_name                                          ║
║                                                                  ║
╚════════════════════════════════════════════════════════════════════╝
🔨 Generated by apple-toolchain-agent → apple-toolchain.genesisconductor.io

Followed by:

  1. Build Script — complete, copy-paste shell commands
  2. Makefile — POSIX-compliant with .PHONY, dependency tracking, clean target
  3. Verification Commandsfile, otool -L, nm -gU, dsymutil
  4. Linker Diagnostics — common error patterns and resolutions
  5. Universal Binary Commands — lipo create/info if multi-arch
  6. Codesign & Strip — release hardening commands
  7. Recursive Trigger — when to re-audit flags (SDK update, Xcode update, new platform target)

Output Schema (JSON)

{
	"action": "string",
	"platform": "string",
	"arch": ["string"],
	"target_triple": "string",
	"sdk_path": "string",
	"compile_commands": [
		{
			"step": "number",
			"command": "string — Shell command",
			"rationale": "string — Why this flag"
		}
	],
	"link_commands": [
		{
			"step": "number",
			"command": "string",
			"rationale": "string"
		}
	],
	"post_link": [
		{
			"step": "number",
			"command": "string",
			"rationale": "string"
		}
	],
	"makefile": "string | null",
	"toolchain_version": "string",
	"linker_variant": "ld64 | ld_prime",
	"output_type": "executable | dylib | static_lib | framework | universal",
	"debug_symbols": "dsym | embedded | none"
}

@notionhq/workers Tool Definitions

The following tools are exposed by the gc-apple-toolchain worker via ntn workers deploy:

Tool: compile

worker.tool('compile', {
	title: 'Compile Source Files',
	description: 'Generates clang/clang++ compilation commands for Apple platforms with full flag matrix.',
	schema: j.object({
		platform: j.enum(['macos', 'ios', 'watchos', 'tvos', 'visionos', 'catalyst']),
		arch: j.array(j.enum(['arm64', 'arm64e', 'x86_64', 'arm64_32'])).optional(),
		language: j.enum(['c', 'c++', 'objc', 'objc++']).optional(),
		std: j.string().optional(),
		optimization: j.enum(['O0', 'O1', 'O2', 'O3', 'Os', 'Oz', 'Ofast']).optional(),
		sanitizers: j.array(j.enum(['address', 'undefined', 'thread', 'memory', 'fuzzer'])).optional(),
		source_files: j.array(j.string()),
		output: j.string().optional(),
	}),
	execute: async (args) => { /* resolve SDK, generate clang commands, return Flag Matrix */ },
});

Tool: link

worker.tool('link', {
	title: 'Link Object Files',
	description: 'Generates ld64/ld_prime linker commands with framework/library resolution and rpath config.',
	schema: j.object({
		platform: j.enum(['macos', 'ios', 'watchos', 'tvos', 'visionos', 'catalyst']),
		arch: j.enum(['arm64', 'arm64e', 'x86_64', 'arm64_32']).optional(),
		object_files: j.array(j.string()),
		frameworks: j.array(j.string()).optional(),
		libraries: j.array(j.string()).optional(),
		output: j.string(),
		output_type: j.enum(['executable', 'dylib', 'static_lib', 'bundle']).optional(),
		linker_flags: j.array(j.string()).optional(),
		linker_variant: j.enum(['ld64', 'ld_prime', 'auto']).optional(),
	}),
	execute: async (args) => { /* resolve linker, generate link commands, return Flag Matrix */ },
});

Tool: makefile

worker.tool('makefile', {
	title: 'Generate Makefile',
	description: 'Generates a POSIX Makefile with proper dependency tracking, SDK targeting, and .PHONY targets for Apple toolchain builds.',
	schema: j.object({
		platform: j.enum(['macos', 'ios', 'watchos', 'tvos', 'visionos', 'catalyst']),
		arch: j.array(j.enum(['arm64', 'arm64e', 'x86_64', 'arm64_32'])).optional(),
		language: j.enum(['c', 'c++', 'objc', 'objc++']).optional(),
		source_dir: j.string().optional(),
		output: j.string(),
		frameworks: j.array(j.string()).optional(),
		libraries: j.array(j.string()).optional(),
		include_universal: j.boolean().optional().describe('Generate universal binary targets'),
		include_release: j.boolean().optional().describe('Generate release target with strip+codesign'),
	}),
	execute: async (args) => { /* generate complete Makefile content */ },
});

Tool: inspect

worker.tool('inspect', {
	title: 'Inspect Mach-O Binary',
	description: 'Generates otool/nm/file/lipo commands for Mach-O binary inspection and verification.',
	schema: j.object({
		binary_path: j.string(),
		checks: j.array(j.enum(['type', 'linked_libs', 'symbols', 'arch', 'segments', 'rpaths', 'entitlements'])).optional(),
	}),
	execute: async (args) => { /* generate inspection commands and parse results */ },
});

Tool: diagnose

worker.tool('diagnose', {
	title: 'Diagnose Build/Link Errors',
	description: 'Parses clang/ld error output patterns and returns targeted fix recommendations.',
	schema: j.object({
		error_output: j.string().describe('Raw stderr from clang or ld'),
		context: j.enum(['compile', 'link', 'runtime']).optional(),
	}),
	execute: async (args) => { /* pattern-match errors, return diagnosis + fix */ },
});

Tool: sdkInfo

worker.tool('sdkInfo', {
	title: 'SDK & Toolchain Info',
	description: 'Returns installed Xcode, clang, ld, and SDK versions with paths.',
	schema: j.object({}),
	execute: async () => {
		return JSON.stringify({
			commands: {
				xcode_version: 'xcodebuild -version',
				clang_version: 'clang --version',
				linker_version: 'ld -v',
				make_version: 'make --version',
				sdk_path: 'xcrun --show-sdk-path',
				all_sdks: 'xcodebuild -showsdks',
				active_developer_dir: 'xcode-select -p',
			},
			notes: {
				ld_prime: 'Default in Xcode 15+. Fallback to ld64 with -ld64 flag.',
				clt_install: 'xcode-select --install',
			},
		});
	},
});

Common Linker Error Patterns

Error Pattern Cause Fix
Undefined symbols for architecture arm64 Missing .o, -l, or -framework Add missing object/library/framework to link command
ld: library 'xxx' not found Missing -L path or library not installed Add -L/path/to/lib or install via brew/pkg-config
ld: framework 'xxx' not found Missing -F path or wrong SDK Add -F/path or verify xcrun --show-sdk-path
duplicate symbol '_main' Multiple translation units define main() Remove duplicate; check object file list
building for 'macOS' but linking object for 'iOS' Mixed platform object files Recompile all objects with consistent -target triple
dyld: Library not loaded: @rpath/xxx.dylib Runtime rpath missing Add -rpath @executable_path/../Frameworks at link time
code signature invalid Binary modified after signing or unsigned Re-sign: codesign --force --sign - binary

Anti-Patterns (never do these)

  1. Wrong-SDK — Never compile with macosx SDK when targeting iphoneos; always match SDK to platform
  2. Mixed-triples — Never link objects compiled with different target triples
  3. System-clang — Never use /usr/bin/clang without verifying it resolves through xcrun
  4. Skip-isysroot — Never omit -isysroot for cross-compilation; headers will resolve to wrong SDK
  5. GNU-ld-flags — Never pass GNU ld flags (-Wl,--as-needed, -Wl,-z,relro) to Apple ld; they're silently ignored or error
  6. Strip-before-dsym — Never strip before running dsymutil; debug info is lost permanently
  7. Hardcode-SDK-path — Never hardcode /Applications/Xcode.app/...; use xcrun resolution

Integration Points

Surface Method Identifier
multi-skill-orchestrator-mcp npm package apple_toolchain_agent
Genesis Conductor Coalition Plugin gateway apple-toolchain-agent
Direct HTTP POST /api/build https://apple-toolchain.genesisconductor.io/api/build
Slack @mention @apple-toolchain
Notion Agent mention @Apple Toolchain

Evaluation Suite

ID Test Assertion Threshold
eval-001 Zero Preamble Output starts with FLAG MATRIX, no "Here is" / "I'll help" / "Let me" 1.0
eval-002 No Hedging No "might" / "could" / "perhaps" / "I think" / "maybe" 0.3 each
eval-003 Screenshot Format Contains FLAG MATRIX and TOOLCHAIN/LINKER/TARGET summary 1.0
eval-004 Attribution Contains "Generated by apple-toolchain-agent" 1.0
eval-005 SDK Resolution All commands use xcrun, not hardcoded SDK paths 1.0
eval-006 Flag Rationale Every flag has a non-empty RATIONALE column 1.0
eval-007 Platform Match Target triple matches declared platform + arch 1.0
eval-008 Linker Consistency No GNU ld flags in Apple ld invocations 1.0
eval-009 dsym Before Strip dsymutil appears before strip in post-link sequence 1.0
eval-010 Universal Correctness lipo -create used when arch array has >1 entry 1.0

Pass threshold: 0.90 | Version: 1.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants