# PyCForge SDK 0.18.1

PyCForge SDK is the development kit for creating conversion imports for PyCForge.
Define supported library operations, write their documentation and examples,
check the generated C, and build a `.pcfplugin` package for use through `*import`.

Designed for human developers and AI tools, the SDK offers a desktop workspace,
a command-line interface, and a Python API. All three use the same project files,
conversion services, and verification rules.

## A workspace for conversion imports

- **Start with a working example:** choose scalar math, named parameters, NumPy,
  JSON, or independently named array, structured-value and Unicode text libraries from the connected engine's starters.
- **Define your library:** give its operations names and descriptions, using the
  conversion capabilities supplied by PyCForge.
- **Explain how to use it:** include parameter descriptions, return values,
  practical limits, and examples in the package's searchable offline Help.
- **Find what needs attention:** scan for incomplete fields, missing examples,
  and verification that needs repeating. Open a finding to reach its field.
- **Develop your tests:** add, duplicate, rename or remove fixtures with a reviewed
  change. Keep source files and linked Help examples under your control.
- **Check the result:** convert examples to C, compile and run the declared tests,
  and compare expected and actual output, errors and exit status side by side.
- **Build and register:** create a verified `.pcfplugin` package, then register it
  with PyCForge when you are ready to use it.

## Capabilities supplied by PyCForge

PyCForge supplies the SDK's conversion operations, starter projects, authoring
forms, method explanations, and Help. Its Crucible folder contains a versioned
workbench definition and JSON schema, alongside the catalogue and import manuals.
The SDK reads these descriptions without carrying its own list of libraries.
After updating the selected PyCForge installation, reconnect the SDK to refresh
that information. Compatible engine
additions, including new default imports and their Help, become available without
requiring a matching SDK release.

The SDK application is installed separately. Changes to its desktop, command-line
tools, or support for an incompatible engine interface require a separate SDK
update. Connecting refreshes information from the installed PyCForge; it does
not download or install either application. Reverify your projects after updating
PyCForge, the SDK, or the C compiler.

## Install and open

Use Python 3.11–3.13 and install PyCForge separately. Install the SDK desktop from
its wheel:

```sh
python -m pip install "./pycforge_sdk-0.18.1-py3-none-any.whl[gui]"
pycforge-sdk-ui
```

On Windows, `py` can be used in place of `python`. For command-line, Python API,
or AI automation without the desktop, omit `[gui]`. The desktop includes PySide6;
the SDK without the desktop has no required third-party dependencies. Add
`--upgrade` to the install command when installing an updated SDK wheel.

The desktop looks for PyCForge when it opens. It checks your last successful
connection first, then common Python installations and environment folders.
A startup panel shows progress. If several installations are found, choose the
version and location you want; the SDK remembers a successful connection.

If PyCForge cannot be found, choose **Locate PyCForge**. Select its installation,
Python environment, or installed SDK support folder (`pycforge/crucible/landscape`).
The picker provides drive shortcuts, including C: on Windows. The SDK finds and
validates the matching interpreter; a source folder by itself needs a working
engine installation. **Continue offline** opens local projects and any cached
reference without connecting.

**Refresh** reloads the selected engine's capabilities. **Engine and tools** contains
advanced interpreter and compiler settings, **Find installed**, and **This Python**
for a shared environment. You can also select `python.exe` directly; Windows
virtual environments keep it in `Scripts`, and Linux/macOS environments use
`bin/python`. PyCForge's About dialog shows the exact interpreter under
**Distribution → SDK Python**.

The SDK and PyCForge can use separate Python environments. Searches check known
locations without scanning entire drives. Environments kept elsewhere can be
selected manually. Discovery and connection install nothing.

## Create your first import

1. Choose **New**, then **Use walkthrough** or **Create directly**. The walkthrough
   separates starting point, project location, package identity, export names,
   and review into five focused steps. Both modes use the same fields; switch
   modes or revisit steps without losing the current setup. You can remember
   your preferred mode after creating a project.
   In **Browse**, select a parent folder, then append a new folder name to the
   displayed path. Selecting another parent keeps an entered new folder name.
   **Use this path** returns the choice; **Create project** creates the folder.
   With a compatible engine, select **Customize package identity and exports**
   to set the package ID, import namespace, version, and exported names. Crucible
   updates the starter's fixtures and Help together. **Create project** opens the
   saved project in the full workspace. A failed creation keeps your entries for
   correction.
2. Use **Edit extension** to complete the project, functions, Help, and test
   examples. Guided creation continues with focused authoring steps; existing
   projects offer **Use authoring guide**. Package, function and constant Help
   have separate steps. **Edit directly** returns to the normal tabs with your
   edits intact. Save your changes before scanning.
3. Choose **Scan** and follow its findings. The scanner shows whether the project
   needs editing, verification, or is ready to package. Its next-action buttons
   explain the available steps and run only when you choose them.
4. Choose **Check fixtures** to review conversion expectations for every saved
   fixture. Double-click a result to open its source at the reported location.
   This step needs no C compiler and does not run the fixture programs.
5. Choose **Verify fixtures** to compile and run the saved test examples. Install
   a C compiler supported by the selected engine before this step.
6. Choose **Package** after verification passes. Packaging checks that the project,
   documentation, tests, and tools still match the verified result.
   **Package handoff** shows the namespace, a copyable `*import` statement and a
   saved example that passed verification. The example is read-only and is not run
   by viewing it. Package identity and hashes remain available under **Evidence**.
7. Register the package through the SDK's **Tools** menu or PyCForge's
   **Register Conversion Imports** dialog. Select **Runtime** in PyCForge and use
   `*import your_namespace as alias` in the source you want to convert.

Building a package and registering it are separate actions. A registered package's
**Import Help** explains its exact supported operations and examples.
The handoff's **Register package** button opens the normal file selection and
confirmation. Its receipt reports the actual file and namespace accepted by
PyCForge. A rejected registration explains the engine's result.

Use **Save setup** to keep unfinished creation choices in a `.pcfsetup` file.
Choose **New → Open setup** to continue later in either mode, including offline.
Closing with unsaved changes offers Save, Discard, or Keep editing. Outside file
edits are preserved; open the changed file again or use **Save setup as**.
**Review current starter** explains engine or starter changes before applying
them. Project creation checks the engine again. After creation, use the normal
Open action to edit the project; saved setup carries no verification approval.

The authoring guide remembers your place for each project. Project edits still
need **Save**; fixture source has its own Save action. Changing a function name
or operation requires reviewing its Help and source examples. Moving between
steps does not run checks or establish verification.

In **Fixtures**, choose **Add**, **Duplicate**, **Rename** or **Remove**, then
**Review change** and **Apply change**. Add separates identity, source
and expectations into focused tabs. Duplicate copies the selected source and
expectations to a new file. Rename updates the fixture name and linked Help;
it leaves the source filename unchanged. Remove keeps the source on disk and
asks for a replacement native example when Help uses the removed fixture.
Applying saves immediately; Scan and Verify remain separate actions.

After verification, select a fixture in **Fixture results** to compare expected
and actual output, error output or exit status. Escaped text makes tabs and
missing newlines visible. **Open source** and **Edit expectation** take you to
the author inputs; the SDK never replaces an expectation with observed output.
Review the intended behavior independently before saving and verifying again.

When PyCForge advertises a field that your project does not yet contain, its
form offers **Set value**. Read the engine's explanation and choose a value,
then Save and Scan. Opening a form never inserts a guessed default. Advanced
project data remains available for stored values outside an advertised form.

## Conversion coverage

The connected engine determines the available operations and their rules.
Its starters include examples for numeric functions, arrays, structured values
and Unicode text. These examples are not a fixed SDK capability list. PyCForge
supplies the applicable fields, exact operations, signatures, storage and cleanup
rules; authors provide the explanations and test cases.

Open **Engine reference → Conversion coverage** in the desktop to browse the
selected engine's families, authoring profiles, operation signatures, limits,
and starter projects. Search for an operation or inspect its profile. The same
information is available through `coverage` and `SDK.coverage()`. Older engines
that omit family coverage retain their available forms and starters; the SDK
labels the missing information instead of inferring support.

You can create additional library namespaces using supported operations; the SDK
is not limited to math and NumPy. Each function must map to an available conversion
implementation. Each package declaration selects one family; applications can
compose several registered namespaces. Registering a library name does not make all of that Python
library convertible. The selected engine profiles define supported array dimensions, data types,
views, broadcasting and native dependencies. Engine reference and Import Help
describe their exact boundaries.

## Save and resume project authoring

Use **File → Save project draft** for unfinished project fields, functions, Help,
expectations and authoring position. The `.pcfdraft` is saved outside the project.
It does not change project files or establish verification. The fixture dialog's
**Save draft** also retains its unsubmitted source and both expectation modes.
Advanced project data can checkpoint incomplete JSON before it is valid to apply.

**File → Open project draft** works even without an engine or available project.
Use **Review changes** to compare Original, Edited JSON and current Disk data.
Reconcile external changes deliberately; there is no automatic merge. **Resume
editing** returns the draft to the workspace without writing files. **Save
reviewed project** explicitly validates and writes only project.json. An unfinished
fixture continues separately through **File → Resume unfinished fixture**, then
Review change and Apply change. Saving the project never creates its pending source.

For a conflict in the current workspace, **File → Review current draft** retains
its observed base and edits while showing current files. Existing workspace edits
block opening a different saved draft until you preserve them. Failed checkpoint
or live saves keep the buffer open. Closing offers a checkpoint even when the
live project cannot currently be saved.

These are explicit checkpoints, not autosave or source backups. Restore missing
project/source files separately before review. Small Set value/JSON-field dialog
entries enter the checkpoint only after applying them to the editor. New project
drafts use hard-link publication and fail explicitly on unsupported filesystems;
replacements use observed hashes. One-file optimistic saves do not form a
multi-file transaction, and edits after the last checkpoint are not recovered.

## Command line and AI automation

Read the installed SDK manual with `pycforge-sdk manual`, or use `--json manual`
for machine-readable documents. `manual --topic api` and `manual --topic diagnostics`
select the Python reference and native diagnostic rules. No engine or GUI is
required to read these local documents. The selected engine supplies its current
conversion capabilities separately.

Python clients can use `SDK()` for the installed manual and local project
guidance. It uses the current Python interpreter and the normal SDK cache by
default, without connecting or creating files during construction. Supply
`engine_python` when PyCForge is installed in another environment. Build and
registration results include the same structured handoff shown in the desktop.


Use `fixtures PROJECT` to read saved test cases and Help links. Submit a change
as JSON to `fixture-plan`, then explicitly apply the reviewed plan with
`fixture-apply`. Both require the observed project hash; applying also requires
the returned plan hash. `fixture-results PROJECT --case NAME` reads saved results
without connecting or executing. The API manual contains the matching Python
methods, request fields and conflict handling.

If source editing is interrupted or an outside edit blocks saving, use **Save
repair as…** in the fixture source editor. Reopen the `.pcfrepair` file through
**File → Open source repair**. Review the original, edited and current disk
source and the current expectations before choosing **Apply repair**.
The CLI `repair` commands and Python API use the same checks. Repair files are
explicit checkpoints, not autosave; keep them outside the project. Applying
changes only the reviewed source and requires fresh verification.

Use `pycforge-sdk --json discover` to list validated engine installations.
Add `discover --location "/path/to/environment"` to check a specific location.
Python clients can call `discover_engines()` from `pycforge_sdk` for the same
structured result; discovery does not replace the reference cache. Use the
`workbench` command or `SDK.workbench()` to inspect engine-owned forms, bundled
imports, and Help through the same public backend.

Use `reference` or `SDK.engine_reference()` when you need the complete engine
authoring reference, including optional sections added by newer engines. For
focused editing, `fields PROJECT --function EXPORT` or
`SDK.authoring_fields(PROJECT, function=EXPORT)` returns the applicable field
definitions, choices, JSON-pointer paths and present or unset values. Omit the
function to inspect declaration fields. Add `--offline` to either command to
read a compatible cache without invoking the engine; a missing cache is reported.
Readiness JSON includes advisory next actions and their effects alongside the
full findings. Use the explicit save, verify and build operations to act on them.

Start with `coverage` to see what you can author. Use
`coverage --profile crucible.text-declaration/0.1` to inspect the text profile
when the selected engine advertises it. Add the global `--json` option for the
versioned `data.coverage` report. Profile identifiers and operation choices come
from the engine; a successful browse is not fixture verification or packaging
approval. Cached results carry an offline connection state.

Use the command line from scripts or AI development tools. Replace
`/path/to/engine/python` with the interpreter containing PyCForge; quote paths that
contain spaces.

```sh
pycforge-sdk --engine-python /path/to/engine/python connect
pycforge-sdk --engine-python /path/to/engine/python templates
pycforge-sdk --engine-python /path/to/engine/python new ./cube-root --author "Your name"
```

The default starter demonstrates a cube-root conversion. Edit its `project.json`,
documentation, test sources, and expected results for your intended use. Then run:

```sh
pycforge-sdk --engine-python /path/to/engine/python scan ./cube-root
pycforge-sdk --engine-python /path/to/engine/python preflight ./cube-root
pycforge-sdk --engine-python /path/to/engine/python verify ./cube-root --compiler gcc
pycforge-sdk --engine-python /path/to/engine/python readiness ./cube-root --compiler gcc
pycforge-sdk --engine-python /path/to/engine/python build ./cube-root --compiler gcc --output ./cube-root.pcfplugin
```

Use `preflight ./cube-root --case FIXTURE_NAME` to check one fixture. Expected
conversion rejections count as matches when their diagnostic code is present.
Native outputs and packaging approval still require **Verify fixtures**.

Register the result explicitly with `register ./cube-root.pcfplugin`, using the
same engine selection. Use `methods` and `describe ArrayFunction` to explore the
engine reference, or `new --template TEMPLATE_ID` to select another starter.
Use `template TEMPLATE_ID` to inspect its complete declaration and fixtures.
With an engine offering starter customization, add `--package-id org.example.measure
--namespace measure --rename cbrt=cube_root` to `new`. Repeat `--rename OLD=NEW`
for more exports; `--package-version` sets the import's version. Expected results
and conversion contracts are preserved for your review and native verification.

Pass `--json` before a command to receive structured results, diagnostic codes,
and field locations. AI tools can inspect these results, correct project data,
and repeat the same scan, verify, and package workflow used by a human author.
Treat a nonzero exit code as an unsuccessful operation; do not infer approval
from descriptive text. With `--json`, an invalid command returns `SDK_ARGUMENT`.
A failed native fixture includes its case location and the path to the saved report.
PCFC11 reports also preserve structured compiler codes, C source locations and
related declarations when available. Failed native fixtures retain their generated
C for investigation; a compiler location is not automatically a Python location.
Use `describe ValueFunction` to inspect the connected engine’s structured-value operations.
Use `describe TextFunction` for text choices and signatures. An unknown coverage
profile returns `SDK_COVERAGE_PROFILE` with the available profile identifiers
and a remedy; invalid arguments return `SDK_ARGUMENT`.

## Python API

Use the same SDK service directly from Python. This example lists the starter
projects available from the selected engine:

```python
from pycforge_sdk import SDK

sdk = SDK(engine_python="/path/to/engine/python", cache="./sdk-cache")
result = sdk.templates()
if not result.ok:
    raise RuntimeError(result.to_dict())

for template in result.data["templates"]:
    print(template["id"], template["description"])
```

Use `sdk.template("scalar-cube-root")` to inspect a starter without executing it.
`sdk.customize_template("scalar-cube-root", package_id="org.example.measure",
namespace="measure", exports={"cbrt": "cube_root"})` previews a customized starter
without writing files. Pass the same identity and export arguments to
`create_project(directory, author="Your name", ...)` to save a new project.
Customization requires a live compatible engine; cached starter browsing remains
available offline. Older engines can still create their unchanged starters.

`sdk.preflight(directory, case=None)` returns a structured conversion review
for every saved fixture, or one exact fixture name. It preserves existing native
verification records and packages.

The API also provides project creation and editing, inspection, conversion,
verification, packaging, and registration. Each operation returns an `Outcome`
with an `ok` flag and structured results. Human and AI clients use the same
checks; authors remain responsible for the intended behavior and expected test
results.

## Help and practical requirements

Press **F1** for the searchable guide and conversion-import manuals supplied by
the connected PyCForge. The topic list follows the engine's bundled imports. A
small getting-started guide remains available before connection. **Engine reference**
explains available methods, parameters, results, and examples. Cached reference remains
available when the engine cannot be reached; conversion, verification, and
packaging require a compatible connected engine.

Native fixture verification follows the selected engine's supported host and
compiler profile. The supplied profile currently supports Linux with a GNU-style
C compiler. Desktop browsing and project editing do not require running native
tests. **Verify fixtures** explicitly compiles and executes the declared examples;
browsing the reference and scanning project data do not run them.

Passing verification means the declared test cases matched their expected
results. It does not establish correctness for every possible input or platform.
Changes to project data, Help, tests, or the selected tools require verification
again before packaging. For PCFC11, select PyCForge 1.3.85 or later and PCFC11
0.2.32 or later with the supported backend query. Verification records the selected
external GCC path and its SHA-256. If the path or file changes, or GCC is missing,
restore or select the intended backend and run Verify fixtures again. Earlier
compatible engines can use GCC directly. Review the package's documented limits when using its
conversion imports.

## License

PyCForge SDK is free software under the GNU General Public License v3.0 only.
The distribution includes `LICENSE`.
