Skip to content

Internal

Implementation details explicitly marked Internal by their source. They remain available to browse here, but are not intended as entry points for code written in a Field box.

20 source file(s), 156 public symbol(s), 55 of them carrying KDoc. Everything below is the documentation that lives beside the code — the same text the completion documentation panel shows in the editor. A blank summary means the declaration has no KDoc yet, not that this page dropped it.

extensions.kt

Box actions: named commands a box registers in its actions map, which resync gathers from the box and its ancestors and sends to the UI.

An Action carries a short description, a detail line, optional HTML or JavaScript documentation, and a target callback that receives the boxes it was invoked on. action builds one with the callback as a trailing lambda.

src/jvmMain/kotlin/afield/app/commands/extensions.kt — read the source

Top-level functions

Declaration Summary
fun action(desc : String = "", detail: String, docHtml: String = "", docJs: String = "", payload : (List<Box>) -> Unit) Builds an Action with payload as its target.

Top-level values

Declaration Summary
val Box.actions: MutableMap<String, Action> This box's actions by key; reading it marks the box for resync so the UI picks up changes.

Action

data class Action(val desc: String, val detail: String, val docHtml: String = "", val docJs: String = "", val target: (List<Box>) -> Unit = {})

A named command shown for a box; target runs with the boxes it was invoked on.

Declaration Summary
val desc: String
val detail: String
val docHtml: String
val docJs: String
val target: (List<Box>) -> Unit

FieldBrowserHosts.kt

src/jvmMain/kotlin/afield/app/server/FieldBrowserHosts.kt — read the source

binding.kt

Binds a property or one-argument function to a source of values with the < operator: ::speed < { mouseX } or ::speed < sequenceOf(1.0, 2.0, 3.0).

The callable reference must be bound to a receiver implementing BoundContext; the binding is stored there under the callable's name, replacing any earlier one. Each BoundContext.bindNow pulls the next value from every source, type-checks it against the property or parameter type, and applies it only when it differs from the last value applied. A sequence that runs out removes its binding; clear() on the reference removes it by hand.

Nothing in src/ implements BoundContext or calls bindNow yet, so this is the mechanism without a host.

src/jvmMain/kotlin/afield/document/properties/binding.kt — read the source

Top-level functions

Declaration Summary
fun boundReceiverForCallable(k: Any): Any? Binds a property or one-argument function to a source of values with the < operator: ::speed < { mouseX } or ::speed < sequenceOf(1.0, 2.0, 3.0).
operator fun <A, B> KFunction1<A, B>.compareTo(other: Sequence<A>): Int+1 overload · also () -> A
operator fun <T> KMutableProperty0<T>.compareTo(other: Sequence<T>): Int+1 overload · also () -> T
fun KFunction1<*, *>.clear(): Boolean
fun KMutableProperty0<*>.clear(): Boolean

BoundContext

interface BoundContext

Declaration Summary
val bindings: MutableMap<String, BoundBinding>
val previousValues: MutableMap<String, Any?>
fun bindNow()
fun clearBinding(name: String): Boolean

BoundNext

sealed interface BoundNext

Declaration Summary
data class Value(val value: Any?) : BoundNext
object Done : BoundNext

BoundSource

sealed interface BoundSource

Declaration Summary
fun next(): BoundNext

FunctionSource

class FunctionSource(private val fn: () -> Any?) : BoundSource

Declaration Summary
override fun next(): BoundNext

SequenceSource

class SequenceSource(private val iterator: Iterator<Any?>) : BoundSource

Declaration Summary
override fun next(): BoundNext

BoundBinding

data class BoundBinding(val source: BoundSource, val check: (Any?) -> Any?, val apply: (Any?) -> Unit)

Declaration Summary
val source: BoundSource
val check: (Any?) -> Any?
val apply: (Any?) -> Unit

ManifoldNative.kt

The FFM binding to libmanifoldc that Solid and Section are built on, plus the small public enums they take.

Box code needs only ManifoldLibrary, to ask whether the native library is installed, and the option enums BooleanOp, JoinType and FillRule; the native entry points themselves are internal.

src/jvmMain/kotlin/afield/geometry/solid/manifold/ManifoldNative.kt — read the source

Used in: Solids that cannot fail: Manifold in Field

ManifoldLibrary

object ManifoldLibrary

Where libmanifoldc is, and what to do when it is not there.

Declaration Summary
val fileName: String libmanifoldc.dylib / .so / manifoldc.dll, chosen for the platform actually running.
val searchedPaths: List<Path> Every path resolvedPath tries, in order — quoted in the "not installed" error.
val resolvedPath: Path? The first path that exists, or null.
val isAvailable: Boolean true when Solid and Section will work. Cheap enough to branch on in a box.
val reportedVersion: String? The upstream version, read off the .dylib/.so filename that the SO-versioned symlink points at — libmanifoldc.3.5.2.dylib reports 3.5.2.
val HOW_TO_INSTALL: String What to tell someone who has not got it, in the package manager they are likely to have.
fun describe(): String One line for a box or a smoke test to print: what was found, or why not.

ManifoldStatus

enum class ManifoldStatus(val code: Int)

ManifoldError, the status a Solid carries when an operation could not produce a valid solid.

Constants: NO_ERROR, NON_FINITE_VERTEX, NOT_MANIFOLD, VERTEX_INDEX_OUT_OF_BOUNDS, PROPERTIES_WRONG_LENGTH, MISSING_POSITION_PROPERTIES, MERGE_VECTORS_DIFFERENT_LENGTHS, MERGE_INDEX_OUT_OF_BOUNDS, TRANSFORM_WRONG_LENGTH, RUN_INDEX_WRONG_LENGTH, FACE_ID_WRONG_LENGTH, INVALID_CONSTRUCTION, RESULT_TOO_LARGE, INVALID_TANGENTS, CANCELLED.

Declaration Summary
val isError: Boolean true for everything except NO_ERROR.

BooleanOp

enum class BooleanOp(internal val code: Int)

ManifoldOpType, the operation Solid.batchBoolean and Section.batchBoolean apply.

Constants: UNION, DIFFERENCE, INTERSECTION.

JoinType

enum class JoinType(internal val code: Int)

ManifoldJoinType — how Section.offset treats a convex corner.

Constants: SQUARE, ROUND, MITER, BEVEL.

FillRule

enum class FillRule(internal val code: Int)

ManifoldFillRule — how a set of contours decides what is inside, when they overlap or nest.

Constants: EVEN_ODD, NON_ZERO, POSITIVE, NEGATIVE.

RayHit

data class RayHit(val faceId: Long, val distance: Double, val x: Double, val y: Double, val z: Double, val normalX: Double, val normalY: Double, val normalZ: Double)

One intersection from Solid.raycast.

Declaration Summary
val faceId: Long Which triangle of the solid was hit, as Manifold's face id.
val distance: Double Distance from the ray origin, in the units the solid is in.
val x: Double
val y: Double
val z: Double
val normalX: Double
val normalY: Double
val normalZ: Double

GestureReplayMain.kt

A command-line entry point that replays a recorded pen gesture through a brush and writes the painted PNG, so an agent can try a gesture without a browser.

GestureReplayMain reads a GestureReplayRequest (raw samples, or keyframe lanes in GestureReplayLanes) and prints a GestureReplayReport as JSON.

src/jvmMain/kotlin/afield/graphics/paint/GestureReplayMain.kt — read the source

GestureReplayMain

object GestureReplayMain

The gesture -> brush replay for an agent, without a browser: a take (or its keyframe lanes) in a JSON file, a painted PNG out. field_backdoor.py --command 'run-jvm-main afield.graphics.paint.GestureReplayMain --arg <request.json>', or the MCP tool field_paint_gesture.

Declaration Summary
fun main(args: Array<String>)
fun run(req: GestureReplayRequest): GestureReplayReport

GestureReplayRequest

data class GestureReplayRequest(val out: String, val samples: List<List<Double>> = emptyList(), val lanes: GestureReplayLanes? = null, val bake: Double? = null, val lanesOut: String? = null, val xRange: List<Double> = listOf(-1.0, 1.0), val yRange: List<Double> = listOf(-1.0, 1.0), val into: List<Double>? = null, val widthPx: Int = 800, val aspect: Double = 1.0, val sizeMm: Double = 200.0, val seed: Long = 1, val brush: String = "Round", val brushWidth: Double = 50.0, val dynamic: Boolean = true, val color: List<Double> = listOf(0.25, 0.15, 0.1), val pressure: Double = 0.6, val pressureScale: Double = 1.2, val tilt: Double = 30.0, val timeScale: Double = 1.0)

What GestureReplayMain reads. Ranges and into as in PaintCanvas.gesture; into is [x, y, w, h].

Declaration Summary
val out: String
val samples: List<List<Double>>
val lanes: GestureReplayLanes?
val bake: Double?
val lanesOut: String?
val xRange: List<Double>
val yRange: List<Double>
val into: List<Double>?
val widthPx: Int
val aspect: Double
val sizeMm: Double
val seed: Long
val brush: String
val brushWidth: Double
val dynamic: Boolean
val color: List<Double>
val pressure: Double
val pressureScale: Double
val tilt: Double
val timeScale: Double

GestureReplayLanes

data class GestureReplayLanes(val x: List<Keyframe>, val y: List<Keyframe>, val pressure: List<Keyframe>? = null, val tiltX: List<Keyframe>? = null, val tiltY: List<Keyframe>? = null, val twist: List<Keyframe>? = null)

Keyframe lanes as the keyframe editor stores them.

Declaration Summary
val x: List<Keyframe>, val y: List<Keyframe>
val pressure: List<Keyframe>?

GestureReplayReport

data class GestureReplayReport(val ok: Boolean, val error: String? = null, val out: String? = null, val samples: Int = 0, val seconds: Double = 0.0, val fromLanes: Boolean = false, val keys: Int? = null, val fit: String? = null, val brush: String? = null, val pressure: List<Double> = emptyList(), val tilt: List<Double> = emptyList())

What GestureReplayMain prints.

Declaration Summary
val ok: Boolean
val error: String?
val out: String?
val samples: Int
val seconds: Double
val fromLanes: Boolean
val keys: Int?
val fit: String?
val brush: String?
val pressure: List<Double>
val tilt: List<Double>

PaintNative.kt

The bindings to the native field-paint library: PaintLibrary finds the library file, and the internal FFM layer under PaintCanvas calls into it.

src/jvmMain/kotlin/afield/graphics/paint/PaintNative.kt — read the source

PaintLibrary

object PaintLibrary

Where native/field-paint is. Searched in order: -Dafield.paint.library, AFIELD_PAINT_LIBRARY, then build/field-paint/release in the working directory.

Declaration Summary
val fileName: String
val searchedPaths: List<Path>
val resolvedPath: Path? Not cached: building it during a live session is picked up by the next box run.
val isAvailable: Boolean
const val HOW_TO_BUILD
fun describe(): String

OpenDlssNrDiagnostics.kt

src/jvmMain/kotlin/afield/graphics/render/neural/OpenDlssNrDiagnostics.kt — read the source

OpenDlssNrNative.kt

src/jvmMain/kotlin/afield/graphics/render/neural/OpenDlssNrNative.kt — read the source

OpenDlssNrTemporalSmoke.kt

src/jvmMain/kotlin/afield/graphics/render/neural/OpenDlssNrTemporalSmoke.kt — read the source

SyphonNative.kt

The locator and foreign-function bindings for native/field-syphon, the optional macOS library under SyphonServer and SyphonClient.

The library is searched for in order: the afield.syphon.library system property, the AFIELD_SYPHON_LIBRARY environment variable, then build/field-syphon in the working directory.

src/jvmMain/kotlin/afield/io/syphon/SyphonNative.kt — read the source

SyphonLibrary

object SyphonLibrary

Locates libfield_syphon.dylib and reports whether it is available.

Declaration Summary
val isMac: Boolean
const val fileName
val searchedPaths: List<Path>
val resolvedPath: Path? Not cached: building it during a live session is picked up by the next box run.
val isAvailable: Boolean
val probePath: Path? The cross-process test peer built next to the library (field_syphon_probe).
const val HOW_TO_BUILD
fun describe(): String

FfmCeresBackend.kt

The Ceres solver backend that calls the native ken_ceres_jvm wrapper through the Java foreign-function API (java.lang.foreign), with no JNI glue.

FfmCeresBackend loads the library, binds its ken_ceres_* entry points as downcall handles and reports FfmCeresBackend.abiVersion; FfmCeresBackend.compile turns a seed PointCloud and a CeresProgram into a reusable compiled solver whose input, output and prior buffers are allocated once in a shared arena and reused across solves. CeresNativeLibrary says where the library is expected and how to build it.

src/jvmMain/kotlin/afield/math/optimization/ceres/FfmCeresBackend.kt — read the source

FfmCeresBackend

class FfmCeresBackend(libraryPath: Path = CeresNativeLibrary.defaultPath, private val reusableMetricCapacity: Int = 128) : CeresSolverBackend

A CeresSolverBackend backed by the native library at libraryPath, by default CeresNativeLibrary.defaultPath. Construction fails with UnsatisfiedLinkError when an expected symbol is missing, and with IllegalArgumentException when the library reports an ABI version other than the one Field needs.

Declaration Summary
val abiVersion: String The ken_ceres_jvm_abi_v* string the loaded library reports.
override fun compile(seedPoints: PointCloud, program: CeresProgram): CompiledCeresSolver

CeresNativeLibrary

object CeresNativeLibrary

Where to find the native wrapper.

Declaration Summary
val defaultPath: Path
val HOW_TO_BUILD: String What to tell someone whose defaultPath is not there, in the shell they are actually in.

PairedHeadsetInput.kt

src/jvmMain/kotlin/afield/media/browser/PairedHeadsetInput.kt — read the source

WiVRnEvdev.kt

src/jvmMain/kotlin/afield/media/browser/WiVRnEvdev.kt — read the source

WiVRnKeyboardMap.kt

src/jvmMain/kotlin/afield/media/browser/WiVRnKeyboardMap.kt — read the source

NgxNative.kt

src/jvmMain/kotlin/afield/media/reconstruction/NgxNative.kt — read the source

ReconstructionCapture.kt

src/jvmMain/kotlin/afield/media/reconstruction/ReconstructionCapture.kt — read the source

actors.kt

Typed messages between boxes: a box registers a handler with onMessage, and other code delivers to it with send (fire-and-forget) or sendAndAwait (suspend for a reply).

Messages are queued per box and delivered on the next RunLoop frame. Handlers run as coroutines on the RunLoop's dispatcher, so one can call MessageScope.frame to wait a frame or MessageScope.reply to answer. A box with no handler for a payload type passes it to its ancestors. go launches a suspendable block owned by a box, so stopping the box cancels it and its errors appear in the box's editor.

onMessage<String> { reply(payload.length) }
go { println(thisBox.sendAndAwait<String, Int>("hello")) }

src/jvmMain/kotlin/afield/runtime/execution/actors.kt — read the source

Used in: A Terminal in a Box

Top-level functions

Declaration Summary
inline fun <reified T : Any> Box.onMessage(noinline handler: suspend MessageScope<T>.() -> Unit) Register a typed, suspendable message handler on this box.
fun <T : Any> Box.onMessage(type: KClass<T>, handler: suspend MessageScope<T>.() -> Unit)
fun <T : Any> Box.send(payload: T) Enqueue payload for delivery to this box on the next RunLoop frame. The sender is inferred from Box.context (may be null if called outside a box execution context).
fun Box.go(block: suspend CoroutineScope.() -> Unit) Launch a suspendable block on the RunLoop's Framer dispatcher, owned by this box. Stopping the box cancels the block; uncaught errors appear in the editor.
suspend fun delay(ms: Number) Wait ms milliseconds inside go { } (or any coroutine) without holding the runloop.
suspend fun <T : Any, R> Box.sendAndAwait(payload: T): SendResult<R> Send payload and suspend until the handler finishes (or is not found).

Envelope

data class Envelope<T : Any>(val payload: T, val from: Box?, val to: Box, val time: Long = System.currentTimeMillis())

Envelope wrapping a user payload with sender/receiver metadata.

Declaration Summary
val payload: T
val from: Box?
val to: Box
val time: Long

MessageScope

class MessageScope<T : Any>(val envelope: Envelope<T>, private val deferred: CompletableDeferred<Any?>?, internal val handlerBox: Box?)

Receiver for suspend message handlers. Provides frame to suspend until the next RunLoop tick and reply to send a value back to a waiting sendAndAwait caller.

Declaration Summary
val payload: T
val from: Box?
val to: Box
val time: Long
suspend fun frame() Suspend until the next RunLoop frame. Because the handler coroutine is dispatched on Runloop.runLoop.main (the afield.runtime.lifecycle.Framer), calling kotlinx.coroutines.yield parks it until the Framer is pumped again.
fun reply(value: Any?) Provide a return value to a sendAndAwait caller. If the message was sent with plain send, this is a no-op. Can be called at most once; subsequent calls are ignored.

SendResult

sealed class SendResult<out T>

Declaration Summary
data class Ok<T>(val value: T?) : SendResult<T>() Handler ran to completion. value is whatever MessageScope.reply provided (null if reply was never called).
data object NoHandler : SendResult<Nothing>() No handler was found for this message type on the target box or any of its ancestors.
data class Error(val exception: Throwable) : SendResult<Nothing>() The handler threw an exception.
inline fun <R> map(transform: (T?) -> R): SendResult<R> Transform the value if Ok, otherwise pass through the failure unchanged.
fun getOrNull(): T? Return the value if Ok, otherwise null.
inline fun getOrElse(default: () -> @UnsafeVariance T?): T? Return the value if Ok, otherwise default.
inline fun onOk(action: (T?) -> Unit): SendResult<T> Run action if Ok, return this for chaining.
inline fun onFailure(action: (SendResult<@UnsafeVariance T>) -> Unit): SendResult<T> Run action if not Ok, return this for chaining.

scratch.kt

src/jvmMain/kotlin/afield/runtime/lifecycle/scratch.kt — read the source

Used in: Running code in a box, Why does this value resolve here?

Top-level values

Declaration Summary
val Box.once

Once

class Once(val inside : Box)

Property-delegate namespace bound to one Box; normally reached as box.once.

Onceing

class Onceing<T>()

Returns a lazy initializer for the generated property named by property.

Declaration Summary
operator fun getValue(f: Once, property: KProperty<*>): (() -> T) -> T

SourceBackedBlock.kt

A callable block that keeps the Kotlin source it was written as, and can be rebuilt from that source after it has been saved.

The sourceBlock macro makes a SourceBackedBlock holding both a live lambda and its source. A block restored from storage has only the source and rebuilds itself by evaluating it on its box's engine. Doing that while the same box's code is running would run that code again, so it is refused with SourceBackedBlockSelfBoxReentry or SourceBackedBlockDuringOwnBody, each of whose messages says where to invoke the block instead.

src/jvmMain/kotlin/afield/study/source/SourceBackedBlock.kt — read the source

Top-level functions

Declaration Summary
fun <T> sourceBackedBlock(boxId: String, source: String): SourceBackedBlock<T>
fun sourceBackedBlockBox(boxId: String): Box?

SourceBackedBlockSelfBoxReentry

class SourceBackedBlockSelfBoxReentry(box: Box, source: String) : IllegalStateException("This source-backed block is evaluating its stored source in box '${box.name}' (${box.id}) — the " + "box that is running it, whose body it therefore re-runs, once per invocation, until the stack " + "overflows. Source: '${source.take(80).replace('\n', ' ')}'. " + "Invoke it somewhere that is not this box's own body: " + "(1) from another box — construct it with that box's id, `SourceBackedBlock<Any?>(\"other_box\", source)`, " + "and invoke it there, which is the split `dev_docs/agents/transcripts/keyframe_code_blend.yaml` uses; " + "(2) from a frame loop or a control callback, after this body has finished; or " + "(3) not at all — a block the `sourceBlock { }` macro made in *this* execution carries a live " + "lambda, never hydrates, and is safe to call immediately. " + "See dev_docs/FN_REWRITE_SELF_BOX_REENTRY.md.")

Thrown when a rehydrating SourceBackedBlock would be evaluated in a box whose body is already running — the failure that was 327 nested body runs and 355 seconds before it was guarded.

SourceBackedBlockDuringOwnBody

class SourceBackedBlockDuringOwnBody(box: Box, source: String) : IllegalStateException("This saved block (source '${source.take(80).replace('\n', ' ')}') belongs to box '${box.name}', whose " + "code is running now, and hydrating it there would run that code again. Invoke it from a frame loop " + "or a control callback, after the box's code has finished, or from another box.")

A saved expression asked to hydrate on its own box's engine while that box's body is running. Evaluating it there would run the body again, so it is an error, raised before anything runs twice. A SourceBackedBlock no longer raises it (it hydrates on a side engine instead); the @{...} route of rewriteKotlin still does.

SourceBackedBlock

class SourceBackedBlock<out T>(val boxId: String, val source: String, private val block: (() -> T)? = null) : () -> T

A callable block that keeps the Kotlin source used to create it.

Declaration Summary
val boxId: String
val source: String
override fun invoke(): T
override fun toString(): String

PrettyStrings.kt

src/jvmMain/kotlin/afield/ui/output/PrettyStrings.kt — read the source