Skip to content

Add Private Cloud Compute CLI and development signing - #301

Draft
scouzi1966 wants to merge 1 commit into
mainfrom
codex/add-pcc-cli
Draft

scouzi1966 wants to merge 1 commit into
mainfrom
codex/add-pcc-cli

Conversation

@scouzi1966

@scouzi1966 scouzi1966 commented Sep 12, 2026

Copy link
Copy Markdown
Owner

Add afm pcc status, respond, chat, and serve using the native PCC provider already present in the pinned AFMKit version. PCC is explicitly selected, never falls back to on-device inference, and exits with an actionable message on macOS 26 before constructing a PCC model.

Add a development app packager that validates the explicit AFM App ID, PCC entitlement, profile expiry, Apple Development certificate, and the Mac’s provisioning UDID. It packages runtime resources, signs nested code and the app, and verifies the resulting signature. No provider implementation, dependency pin, certificate, or provisioning profile is added to the repository.

The HTTP route identifies the Apple model and distinguishes provider availability/generation failures from invalid requests. The pinned provider currently erases native quota error types, so this PR preserves generic 503/502 failures rather than guessing HTTP 429 from localized text.

Validation:

  • Passed: 6 offline packaging authorization tests; consumer-boundary check; diff whitespace checks.
  • A release build completed through Scripts/swiftpm-reliable.sh with its automatic native-driver retry. Final edits made afterward have not been rebuilt.
  • On that binary, help/parsing and missing-entitlement/noninteractive/empty-input checks passed. The invalid-port check exposed a validation path that was corrected afterward; its rerun is pending.
  • Added XCTest coverage for unsupported macOS versions, status/configuration, and fixture-backed streaming/nonstreaming HTTP behavior. These tests have not been run: further local builds and Swift test runs were stopped at the user’s request because another build is in progress.
  • Live signed PCC inference remains unverified. It requires a PCC development profile for com.scouzi1966.afm and its matching signing identity; a profile for Vesta cannot authorize AFM.

Draft pending final build/XCTest/CLI validation and the signed PCC smoke test. Setup, commands, limits, and exact verification commands are in docs/private-cloud-compute.md.

Summary by Sourcery

Add explicitly provisioned Private Cloud Compute support to the CLI, HTTP server, and local development workflow.

New Features:

  • Add afm pcc commands for status checks, one-shot responses, terminal chat, and an OpenAI-compatible HTTP server using Apple’s native Private Cloud Compute provider.

Bug Fixes:

  • Return distinct HTTP errors for invalid requests, provider unavailability, and generation failures instead of treating provider failures as bad requests.

Enhancements:

  • Require macOS 27 and explicit PCC availability without falling back to on-device inference.
  • Add PCC status diagnostics covering entitlement, locale, system availability, and quota state.

Build:

  • Add a development app packager that validates PCC provisioning, App ID, signing identity, profile expiry, and device authorization before signing the app bundle.

Documentation:

  • Document PCC commands, development signing setup, packaging, API behavior, limitations, and validation procedures.

Tests:

  • Add offline packaging authorization tests and XCTest coverage for PCC runtime policy, configuration, status mapping, and HTTP streaming/non-streaming behavior.

@sourcery-ai

sourcery-ai Bot commented Sep 12, 2026

Copy link
Copy Markdown

Reviewer's Guide

Introduces an explicitly selected native Private Cloud Compute integration with macOS 27 gating, CLI and HTTP access, and a local development packager that validates provisioning authorization and signs/verifies the complete app bundle without adding credentials or provider dependencies.

Sequence diagram for a PCC CLI request

sequenceDiagram
    participant User
    participant CLI as afm pcc
    participant Runtime as PCCConfiguration
    participant Status as PCCStatus
    participant Provider as AFMKit PCC provider
    participant PCC as Apple PCC
    User->>CLI: pcc respond or serve
    CLI->>Runtime: requireSupportedRuntime()
    alt macOS below 27
        Runtime-->>CLI: RuntimeError.unsupported
        CLI-->>User: Actionable error, no model created
    else macOS 27 or later
        CLI->>Status: current()
        alt unavailable or missing entitlement
            Status-->>CLI: unavailable status
            CLI-->>User: ValidationError
        else available
            CLI->>Runtime: makeEngine() or makeModel()
            Runtime->>Provider: makeModel(privateCloudComputeModelID)
            Provider->>PCC: Generate response
            PCC-->>Provider: Stream or complete response
            Provider-->>CLI: Response
            CLI-->>User: Text or HTTP response
        end
    end
Loading

Flow diagram for PCC development app packaging

flowchart TD
    Start["Built AFM executable"] --> Profile["Decode provisioning profile"]
    Profile --> Validate["Validate AFM App ID, PCC entitlement, expiry, device UDID"]
    Validate --> Identity["Select matching Apple Development identity"]
    Identity --> Resources["Copy executable and runtime resources"]
    Resources --> Nested["Sign nested Mach-O code"]
    Nested --> App["Sign AFM.app with validated entitlements"]
    App --> Verify["codesign verify and entitlement comparison"]
    Verify --> Bundle["Signed local development AFM.app"]
Loading

Flow diagram for PCC HTTP error classification

flowchart LR
    Request["Chat completion request"] --> Provider["AFMKit PCC provider"]
    Provider --> Result{"Provider result"}
    Result --> Invalid["Invalid request or unsupported capability"]
    Result --> Unavailable["Provider unavailable or loading failed"]
    Result --> Generation["Generation failed"]
    Result --> InvalidResponse["HTTP 400 invalid_request_error"]
    Result --> UnavailableResponse["HTTP 503 provider_unavailable"]
    Result --> GenerationResponse["HTTP 502 provider_error"]
Loading

File-Level Changes

Change Details Files
Add explicit Private Cloud Compute CLI commands backed by AFMKit’s native provider.
  • Register pcc with status, respond, chat, and serve subcommands.
  • Require macOS 27 and report entitlement, locale, quota, and availability diagnostics.
  • Construct the PCC provider by explicit model ID with no on-device fallback.
  • Support configurable instructions/reasoning, streaming or complete responses, terminal chat, and OpenAI-compatible serving.
Sources/AFMCLI/PCCCommand.swift
Sources/AFMCLI/main.swift
Sources/AFMKit/PCCConfiguration.swift
Sources/AFMTerminalUI/TerminalChatUI.swift
README.md
docs/private-cloud-compute.md
Add development packaging and signing validation for a PCC-enabled AFM app.
  • Validate the explicit AFM bundle ID, PCC entitlement, profile expiry/platform/device binding, and authorized Apple Development identity.
  • Read the linked binary identity, package runtime bundles/libraries/resources, sign nested Mach-O code before the app, and verify the final signature and entitlements.
  • Refuse to modify keychains, reuse unrelated app identities, overwrite outputs, or imply notarized distribution.
Scripts/package-pcc-app.py
Scripts/test-pcc-packaging.py
docs/private-cloud-compute.md
Map provider failures to appropriate HTTP responses without inferring quota errors from localized messages.
  • Return 400 for invalid requests, 503 for provider unavailability, 502 for generation failures, and preserve existing model/provider mappings.
  • Exercise fixture-backed streaming and nonstreaming success and failure responses.
Sources/AFMServer/AFMProviderHTTPError.swift
Sources/AFMServer/Controllers/MLXChatCompletionsController.swift
Sources/AFMServer/Server.swift
Tests/MacLocalAPITests/PCCHTTPTests.swift
Add offline, unit, HTTP, and CLI validation coverage plus setup documentation.
  • Cover unsupported OS versions, PCC configuration/status mapping, profile authorization, signing identity/device checks, and embedded Info.plist parsing.
  • Document build, signing, packaging, verification, CLI usage, HTTP behavior, limits, and live smoke-test prerequisites.
  • Add a no-inference CLI regression script for parsing and graceful failure paths.
Tests/MacLocalAPITests/PCCConfigurationTests.swift
Tests/MacLocalAPITests/PCCHTTPTests.swift
Scripts/test-pcc-cli.py
Scripts/test-pcc-packaging.py
docs/private-cloud-compute.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

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.

1 participant