Files
marqdo-cli/docs/developers/extensions.md
T
cflmy a67f344b6b ext(00-08): RFC-EXT-0003 core/extension boundary, math detach and release stdlib
Implements issue #3 (RFC-EXT-0003) slices on the post-3.0.0-beta.1 tree.

PR-00/01/H-06: reproduce and fix sibling heading mode inheritance.
build_units now pops the current and same-or-higher-level headings from the
ancestor stack before deriving the inherited mode, so an unmarked heading can never
inherit the previous sibling. Covered by the units matrix, conformance fixtures
22/23, and black-box heading_inheritance through check --emit/run/call.

PR-02/H-08: the deterministic release archive now ships the complete verified
stdlib/ tree. package.py and smoke.py recompute the runtime tree/alias digests,
record them in RELEASE_INFO.json.stdlib, and fail on mismatch; smoke removes the
bundle and requires a fail-closed run. Release discovery no longer falls back to the
compile-time source tree (debug builds keep that development convenience).

PR-03/H-04: one marqdo_host::CORE_RESOURCE_KINDS registry is used by both the CLI
provider-manifest validator and every trusted host registration path; all six core
kinds are rejected as provider name or declared kind before registration.
H-03: docs/architecture/resource-operations.md records every reviewed
resource_request operation and architecture_boundaries pins the exact allowlist; new
domain operations are forbidden in core (ADR-0062).

PR-04/H-01: remove math.parse/eval/substitute/simplify/differentiate from
BUILTINS, HostOp, the runtime, the host kernel and the workspace
(crates/marqdo-math deleted). Formula stays inert; Int/Float arithmetic stays.
Math algorithms are a pure examples/math-library package plus an optional
examples/math-backend ABI plugin that requests the math.compute capability
(ADR-0061). Removed calls are static symbol.unknown; the math import namespace is
released again. Tests/examples/specs migrated; new math_library black-box test.

PR-05/06 Step A: ADR-0060 classifies @exec/@knowledge as the closed Core Modes
and specifies the Proposed metadata-only Heading Annotations v1 (target 3.1,
sem.invalid_mode_marker unchanged, Analysis v2 unchanged). ADR-0063 records the
foreign F-A retention and deferred F-B removal.

Docs/status/compatibility/changelog and the RFC-EXT-0003 evidence file are updated.
Full local gate: cargo fmt PASS, clippy -D warnings PASS, workspace tests 586
passed/0 failed/2 ignored, python tools/ci 28 passed.
2026-11-22 18:57:33 +08:00

7.8 KiB

Plugins, foreign kernels, resource providers and lock v4

Three independent extension kinds share one principle: selection is not authorization. A manifest makes a name visible; the user still grants the exact name or flag at run time. None of these extensions may add a language keyword or a built-in function to the core.

Kind Descriptor Execution form Authorization
Callable plugin plugin.yaml (Plugin ABI v1) native in-process only with trust, or worker child process --plugin PATH + --allow-plugin NAME (+ --trust-native-plugin for native)
Foreign kernel kernel.json (Foreign wire v1) one-shot child process --kernel PATH + --allow-foreign
Resource provider provider.json (Provider manifest v2) marqdo-provider-worker + C ABI v1 library in a child process --provider PATH + --allow-provider NAME

pure and strict refuse all three. Worker/child-process transports are crash isolation, not OS sandboxes; a C ABI is not a sandbox.

1. Callable plugins

plugin:
  name: demo.solver
  version: 0.1.0             # plugin package version (independent axis)
  abi: "^1.0"                # Plugin ABI major 1
  kind: worker               # native | worker; wasm is rejected
  exports:
    - name: solver.add
      signature: "($a: Int, $b: Int) -> Int"
  requires:
    - math.compute
  artifacts:
    - target: x86_64-unknown-linux-gnu
      file: libsolver.so
      sha256: "<64 lowercase hex of the actual artifact>"
marqdo plugin inspect path/to/plugin.yaml        # static; never loads the library
marqdo check index.mq.md --plugin path/to/plugin.yaml
marqdo run index.mq.md --plugin path/to/plugin.yaml --allow-plugin demo.solver
  • check --plugin validates the manifest and export signatures without loading the artifact; run verifies target triple, file SHA-256, grant, and then reconciles loaded exports/signatures/owners/digests one-to-one with the manifest (ext.plugin_binding_mismatch on any difference).
  • Calls use named arguments; positional arguments are normalised to manifest order but ABI v1 configuration defaults are rejected.
  • kind: native shares the host address space and can crash or compromise it; it requires the explicit unsafe --trust-native-plugin. kind: worker runs the same library in a child process with framed JSON and timeouts; the C ABI header/SDK is include/marqdo_plugin_abi_v1.h and crates/marqdo-plugin-sdk.
  • A runnable host-built example is examples/plugin-demo/ (native) and its generated manifest; the release archive includes the built artifact.
  • Normative contract: ../../spec/plugin-abi.md, ../../spec/callable-resolution.md.

2. Foreign kernels

{
  "provider_id": "mocklang",
  "languages": ["mocklang", "mock"],
  "wire_version": 1,
  "entrypoint": "./mocklang",
  "permissions_requested": [],
  "digest": "<sha256 of the executable/environment artifact>",
  "environment_id": "mocklang-env-1"
}
marqdo run demo.mq.md --kernel path/to/kernel.json --allow-foreign

Fenced Code and Formula values are inert; the program must call foreign.run/foreign.call explicitly. The host refuses unauthorized execution, digest mismatch, unexpected exit, timeout and an incompatible wire version. Add a language tag by writing a provider, not by adding an if language == … branch to the core. Example: examples/kernel-mock/. Normative contract: ../../spec/foreign.md.

3. Resource providers v2

{
  "schema": "marqdo.provider",
  "schema_version": 2,
  "name": "demo.sensor",
  "version": "0.1.0",
  "abi": "c-abi-1",
  "transport": "worker",
  "kinds": ["demo.sensor"],
  "artifacts": [{
    "target": "x86_64-unknown-linux-gnu",
    "path": "lib/libsensor.so",
    "sha256": "<64 lowercase hex>"
  }],
  "permissions_requested": []
}
marqdo run demo.mq.md \
  --provider path/to/provider.json \
  --allow-provider demo.sensor

The program still uses the ordinary language surface resource.open("demo.sensor", "unit-1", ["read"]) plus resource.read/write/close and Memory for bytes. There is no provider-specific keyword or built-in. The selected provider is verified (schema version, target, artifact SHA-256, duplicate kind, grant) before the sibling marqdo-provider-worker starts; a missing helper is ext.worker_unavailable and never falls back to PATH or in-process loading. Linux x86_64 only for this beta; not an OS sandbox. Runnable example: examples/provider-demo/ (build with its build.sh; the tracked manifest has a zero digest template). Normative contract: ../../spec/resource-provider-v2.md.

4. Reproducible selection: extensions + lock v4

Declare activation sources in the project manifest:

extensions:
  plugins:
    - from: ./adapter/plugin.yaml
  kernels: []
  providers:
    - from: "@vendor/device/provider.json"

from is exactly ./relative/path inside the project or @alias/relative/path inside a declared dependency. Absolute/rooted paths, URLs, globs, .., symlink escapes and duplicate entries are rejected; the alias must exist in dependencies.

marqdo lock
marqdo inspect index.mq.md --extensions --json   # identities + lock status; no execution

lock records manifest and artifact identities (including the selected target) in lock v4. check/sync compare the declaration to the lock (ext.extension_lock_mismatch), and run re-verifies the real artifact bytes before starting a worker. Lock v3 gets an explicit marqdo lock migration error. Normative contract: ../../spec/extension-selection.md.

5. Frozen-binary test matrix

Your external repository must pass with an unchanged CLI binary:

  • positive: pinned pure library; plugin under correct grant; kernel under --allow-foreign; provider under --allow-provider; extension selection locked and re-verified;
  • negative: wrong export/arity, duplicate export, missing/edited artifact, digest or target mismatch, missing helper, unauthorized grant, wrong lock version, unknown schema major, worker crash/timeout — all must fail with their documented diagnostics and no silent fallback.

The reference suite is marqdo-extension-conformance; the core's evidence generator is tools/ci/verify_extension_contracts.py.

6. Optional math ABI backend (post core math removal)

After the math.* builtins were removed (ADR-0061) an accelerated math function is just an ordinary callable plugin export. examples/math-backend/ exports math_backend.add through the same frozen ABI v1 and requests the math.compute capability category; math.compute does not promise any core solver. Selection is not authorization:

./examples/math-backend/build.sh
marqdo check examples/math-backend/demo.mq.md --plugin examples/math-backend/build
marqdo run examples/math-backend/demo.mq.md \
  --plugin examples/math-backend/build --trust-native-plugin --allow-plugin math.backend
# 42 ; without the grant: permission.denied

A pure package is still preferred; see libraries.md §6. Domain operations must not be added to the core resource_request table (ADR-0062).

7. Heading annotations are Proposed, not implemented

@exec/@knowledge are the closed Core Modes and alone decide execution; third-party heading annotations are a Proposed metadata-only contract (ADR-0060, target 3.1.x). This build still rejects an unknown leading @foo with sem.invalid_mode_marker; there is no annotation manifest, annotation.unknown, Analysis v3 or sidecar yet. Do not document annotations as available until Step B ships: ../../spec/heading-annotations-v1.md.