merge: bring master (issue #13 boundary + SDK revert) into issue #11 Phase A
ci/woodpecker/push/main Pipeline was successful
ci/woodpecker/pr/main Pipeline was successful

This commit is contained in:
cflmy committed 2026-11-26 23:00:32 +08:00
commit f8b82d4143
94 files changed
+3905 -546

No files matched your search

@@ -0,0 +1,156 @@
# ADR-0071 — Engine / Host Contract / Native Host / CLI boundaries
Status: **Accepted** for the pre-stable 3.0 line (2026-11-26).
Supersedes the historical review-RFC position that a Host contract crate is a
second-step, optional move. It does not supersede the language contract
(ADR-0052 / RFC-LANG-0002), the resource/operation ownership rules (ADR-0062),
the foreign F-A boundary (ADR-0063), the single-contract policy (ADR-0068) or
the explicit stdlib Bundle build input (ADR-0070 where landed). It replaces only
the old architecture-gate constraints that asserted `marqdo-runtime ->
marqdo-host` and a frozen crate count.
## Context
Issue #13 audited the tree at `4bbefc9…` and found:
- the runtime linked the native host (`marqdo-host`) even though the interpreter
already accepted `&mut dyn Host`;
- the `Host` trait, `HostOp` and `StdHost` lived in one module, and
`ResourceRead` sat beside real file/TCP/TLS implementations;
- the plugin ABI crate contained the C contract, the wire envelope, manifest
validation, artifact selection, `dlopen` and the worker process, so the
third-party SDK transitively carried execution-side dependencies;
- old architecture gates froze sixteen crate names and the
runtime-to-native-host edge, so the intended boundary could not be tested;
- historical planning documents competed with the current overview as a source
of truth.
The same audit fixed the scope: one language implementation, one contract per
public boundary, no second interpreter, no new runtime protocol, no mandatory
remote repository split, and no empty candidate repositories. Missing
independent-consumer evidence means "keep in the workspace" is the correct
repository decision.
## Decision
### Responsibilities
| Layer | Owns | Must not own |
|---|---|---|
| Engine | Span, Value, expression, the one Markdown profile, IR, frontend mapping/static binding, Runtime evaluation and `Memory`, and the neutral Host contract | concrete OS I/O, sandbox launch, plugin loading, project filesystem, CLI commands |
| `marqdo-host-contract` | `Host` trait, `HostOp`, `ExecutionContext`, `ResourceRead`, `FrameId`, `ParameterSource`, `LoopTransfer`, `RuntimeObservation` | native implementation, grant policy, the public Observation wire encoding, any wire/RPC protocol |
| Native Host (`marqdo-host` and its sandbox/foreign support crates) | capability broker, resources and handles, OS adapters, budgets/deadlines, observation sink, trusted plugin/provider/foreign execution | language parsing/evaluation, a second static binder, CLI projection |
| `marqdo-plugin-abi` | C ABI v1 layout/assertions, wire envelope and protocol errors | `dlopen`, worker/process management, artifact/manifest file execution, capability grants |
| `marqdo-host::plugin` | manifest/artifact validation, native loading, worker process, invocation dispatch | a second ABI or wire definition |
| `marqdo-plugin-sdk` | third-party developer helpers over the public contract | host, loader, CLI, worker execution, sandbox |
| CLI | arguments, single `project_prepare`, command routing, product Analysis/Observation projection, Tool install/dispatch, Host+Runtime assembly | language evaluation, domain algorithms, a second binding path |
### Dependency rules
- `marqdo-runtime -> marqdo-host-contract` only. The engine crates must not reach
`marqdo-host`, sandbox, foreign, plugin ABI/SDK, worker, package, CLI,
`libloading`, `rustls` or other native/domain dependencies on normal or build
edges.
- `marqdo-host-contract -> marqdo-value, marqdo-span` only.
- The native host may implement the contract and consume the public ABI, but it
must not depend back on runtime, frontend, IR or the CLI.
- The CLI is the only composition root allowed to combine engine + native host +
package. `check`/`inspect` never load a native library, start a worker or
access the network.
- `marqdo-plugin-sdk` consumes only `marqdo-plugin-abi`; it must not depend on a
loader, host, worker process, sandbox or CLI.
- There is no second `Host`/`HostOp`, no second Value encoding, no
`EngineValue`/`HostValue`/`WireIR`, no HTTP/RPC/JSON handshake for the
engine-to-host edge and no `legacy` feature. The Rust trait is an internal
compile-time interface inside one codebase.
### Invariants preserved (not moved, not weakened)
- Fuel, stack depth, deadline, output budget and `Memory` limits stay owned and
checked exactly where they were; replacing the host must not remove a check.
The contract carries the calls, not platform-neutral defaults that silently
grant unlimited budgets.
- Capability grants, resource identity/handles, cleanup, provider registration,
strict isolation, plugin trust, foreign supervision and observation privacy
stay owned by the native host and CLI. `check`/`inspect` stay non-executing.
- Static binding remains single: one registry, one `bind_program_calls`, one
`CallBindingTable`; the runtime never re-resolves names.
- Public protocols are unchanged: Analysis revision 3, Observation revision 1,
Tool revision 1, Plugin ABI 1.0, Value Wire 1, Provider v2, lock v4. Moving
Rust modules is not a protocol change.
- Stdlib runtime contract is unchanged. Phase A/B of issue #11/#12 remain a
separate delivery; the CLI does not gain a second Bundle format or a dev
fallback authority.
### Repository decision
The Engine and Native Host stay in this workspace. Issue #13 §9.2 admission is
not met: there is no real external Engine consumer or independent platform
maintainer, and an empty candidate repository would be a prohibited boundary
violation. This ADR records **keep in workspace** as the legal conclusion and
names the reopening conditions in `docs/architecture/CURRENT.md` §7.
The plugin SDK's physical move is a follow-up: the contract is decoupled now,
and the move requires a clean-directory build against a fixed contract revision
(issue #13 S07/S08). No gitlink/submodule or empty `marqdo-cli-*` repository is
created by this ADR.
## Verification
The acceptance gates are executable, not documentary:
- `tools/ci/check_dependency_boundaries.py` reads Cargo metadata for the
workspace and the independent consumer, checks the reviewed crate allowlist and
the forbidden transitive edges, and is itself covered by
`tools/ci/test_dependency_boundaries.py` negative cases.
- `tests/embedding` is a separate workspace and lock file; it executes a real
`.mq.md` through Markdown → frontend → static binding → runtime with a bounded
test host, and rejects fuel/stack/deadline/memory/resource violations.
- `tools/ci/check_engine_boundary.py` builds and runs that consumer, builds the
real CLI, executes the same file and compares terminal Value Wire results, and
checks the runtime build tree.
- `tools/ci/check_plugin_sdk.py` builds the SDK fixture with the public SDK and
loads it through the real CLI with explicit trust/grant, then rejects a
tampered artifact digest.
- `cargo test -p marqdo-cli --test architecture_boundaries` keeps the semantic
gates (single Host trait, plugin contract split, engine-only consumer, reviewed
HostOp/Value/builtin/resource-operation catalogues) and the existing security
and product checks.
- Evidence for the candidate commit lives in
`docs/evidence/2026-11-26-issue-13-engine-host-boundary.md` and
`docs/STATUS.md`. Platform lanes not executed here stay `UNVERIFIED`; no old
release evidence is reused as a new PASS.
## Rejected alternatives
- **Create `marqdo-engine`/`marqdo-host` remote repositories now.** No real
consumer, no ownership/release boundary, prohibited empty candidates; would
also create a cross-repository atomic-semantics tax.
- **Keep the runtime linked to `marqdo-host` and only rename the crate.** Does
not close the dependency edge; an embedded consumer would still link native
TLS, loading and process code.
- **Move the whole `observe` module or CLI projection into the contract.** The
interpreter needs only the emitted facts; the sink, redaction and public
envelope belong to the host/CLI, and moving them would create a second
protocol centre.
- **Leave manifest/artifact in the ABI crate.** The SDK would transitively keep
`serde_yaml`/digest/native-adjacent code and the contract crate would again own
execution-side choices.
- **Add a compatibility re-export of the old `marqdo_host::{Host, ...}` paths.**
Creates a second active path; all in-tree consumers are updated atomically.
- **Loosen the old gates instead of replacing them.** Security, product,
protocol and negative tests are retained; only the frozen crate-name and
runtime-to-native-host assertions are replaced by the responsibility graph.
## Consequences
- An independent consumer can build and compute without the native host or CLI.
- Adding a host capability does not change engine code; adding an engine semantic
change does not change host code.
- The workspace gains one small contract crate and one plugin module move; crate
count is explicitly not a KPI.
- Unfinished ecosystem work (stdlib Phase B, SDK physical repository, regex/
compression migration, foreign F-B, WASM probe, Windows/macOS/strict evidence)
remains open and honestly recorded; none of it is required to close the core
M0–M4 boundary work.
+108
View File
@@ -0,0 +1,108 @@
# ADR-0072 — Independent `marqdo-plugin-sdk` repository
Status: **Superseded by [ADR-0073](0073-sdk-stays-in-cli-workspace.md)**
(2026-11-26). The independent repository was deleted and the SDK returned to
the CLI workspace; this document is kept as decision history only.
Complements [ADR-0071](0071-engine-host-contract-boundary.md) and implements the
SDK follow-up tracked by issue [#15](https://git.cflmy.cn/cflmy/marqdo-cli/issues/15)
after the contract decoupling of issue #13.
## Context
Issue #13 / ADR-0071 separated the public plugin contract from its execution
side:
- `marqdo-plugin-abi` (CLI repository) now contains only the C ABI v1 layout,
the wire envelope and protocol errors;
- `dlopen`, manifest/artifact file handling, worker management and invocation
dispatch live in `marqdo-host::plugin`;
- `marqdo-plugin-sdk` consumed only the contract and was verified by a real
fixture loaded through the CLI.
The SDK is a leaf with a different consumer group (third-party plugin authors),
a different change cadence and an independent release need. Keeping it in the
CLI workspace made the architecture map imply that the CLI product owns SDK
publication and forced every SDK change through the CLI build. Issue #15
required either fixing the distribution input or recording a blocking ticket.
The CLI repository is public, so a fixed Cargo git `rev` is a fetchable
contract input; there is no need for a submodule, a vendored contract copy or a
second wire implementation.
This is a **deliberate, narrow repository split**, not a mechanical projection
of every crate: engine and native host remain in the CLI workspace (ADR-0071
reopening conditions unchanged), and no empty candidate repository is created.
## Decision
### Topology
| Item | Decision |
|---|---|
| SDK repository | Public `cflmy/marqdo-plugin-sdk` (`main`), own Cargo workspace and lock |
| Contract input | `marqdo-plugin-abi` from `https://git.cflmy.cn/cflmy/marqdo-cli.git` at exact `rev = 2585915e16906dac75f8571bed02e7f6f868c6bc` (the merge commit that landed ADR-0071) |
| CLI dependency on SDK | **None**. CLI normal/build/test lanes do not fetch or build the SDK |
| CLI workspace | `crates/marqdo-plugin-sdk` removed; the SDK is not a workspace member |
| Submodule/gitlink | **Not used** for this split; the SDK leaf must not create a CLI↔SDK identity cycle |
| Acceptance fixture | `tests/fixture` in the SDK repository only; real invocation uses a **frozen released CLI binary** via `tools/check_with_frozen_cli.py` |
| Contract authority | Unchanged: CLI owns the C header, Rust layout, Value Wire and error encodings; the SDK never defines a second contract |
| Publication | SDK releases are versioned independently against a contract generation; bumping the pinned CLI `rev` is a reviewed change |
### Rules
- The SDK repository must resolve and build from a clean clone without the CLI
checkout; only its fixed git dependency may reach the CLI repository.
- It must not depend on `libloading`, a native host, worker execution, sandbox
or CLI code.
- The SDK's fixture is a third-party plugin built with only the public SDK. It
is verified against a frozen CLI archive (same ABI 1.0 contract), not against a
locally rebuilt CLI.
- The CLI repository must not reintroduce the SDK as a workspace member, a
copied source tree or a compatibility path; `tools/ci/check_dependency_boundaries.py`
and `architecture_boundaries.rs` fail if it does.
- The CLI's public contract is authoritative; the SDK repository README and
AGENTS rules point back to `include/marqdo_plugin_abi_v1.h`,
`spec/plugin-abi.md` and the pinned commit.
- The existing security statement remains: a C ABI is not a sandbox, and native
loading requires explicit trust; the SDK grants no capability.
## Verification (candidate)
- SDK repository commit `b31187a` on `main`:
- clean-clone `cargo build --locked` and `cargo test --locked` pass;
- the fixture builds with only the SDK;
- `tools/check_with_frozen_cli.py --marqdo-bin <released marqdo 3.0.0-rc.4>`
returns `Int 42` and rejects a tampered artifact digest.
- CLI candidate removes the SDK crate, fixture and CLI-side gate; workspace
tests, architecture boundaries, docs consistency and dependency gates pass;
the SDK no longer appears in the workspace or lock file.
- Full evidence: `docs/evidence/2026-11-26-issue-15-sdk-independent-repository.md`.
## Rejected alternatives
- **Keep the SDK in the CLI workspace** while calling the contract "decoupled":
leaves two release cadences and ownership in one repo; issue #15 cannot close.
- **Git submodule/gitlink into the CLI repo**: CLI does not consume the SDK, so
a submodule would create an unnecessary recursive identity and checkout
failure mode.
- **Relative path dependency `../cli`**: not an independent build; forbidden by
issue #13 §6.2.
- **Copy `marqdo-plugin-abi`/Value Wire into the SDK repo**: would create a
second contract and wire encoder authority.
- **Publish the contract to a registry first**: no registry/release channel is
approved here; the public git `rev` is the available precise input. A future
published artifact can replace the git `rev` without changing authority.
## Consequences and rollback
- The architecture map now shows one CLI contract producer and one independent
SDK consumer; CLI CI no longer carries SDK-only checks, and SDK CI owns them.
- The SDK remains pinned to a CLI merge commit. Changing the contract or
advancing the pin is a deliberate cross-repository change with its own
evidence; a contract change must land in the CLI first, then the SDK pin is
bumped.
- Rollback is a complete known-good combination: keep the CLI commit and the SDK
pin that were verified together; do not restore a copied SDK or an old ABI.
- External SDK consumers can fetch the public CLI contract today. If a
registry-published contract or a different visibility policy is later chosen,
that is a new ADR, not an implicit change.
@@ -0,0 +1,99 @@
# ADR-0073 — Keep the plugin SDK in the CLI workspace; defer the repository split
Status: **Accepted** (2026-11-26).
Supersedes [ADR-0072](0072-sdk-independent-repository.md).
## Context
ADR-0072 split `marqdo-plugin-sdk` into the public repository
`cflmy/marqdo-plugin-sdk` and pinned it to one CLI contract `rev`. The
implementation itself was technically sound (clean-clone build, frozen-CLI
integration, no second ABI), but a re-evaluation against the pre-stable project's
architecture showed that the **repository boundary was premature**, even though
the **logical contract boundary is correct and stays**.
The relevant facts at this point in the prerelease line:
- the SDK is a small, contract-only consumer (six source files; dependencies are
`marqdo-plugin-abi`, `serde`, `serde_json`);
- plugin ABI 1.0, Value Wire 1 and the C header are frozen; the SDK has no
independent version or release story beyond the ABI generation;
- the C header, `spec/plugin-abi.md`, the `marqdo-plugin-abi` contract, the
loader/worker and the SDK helpers evolve together and are owned by the same
maintainers;
- no registry publication or independent maintenance exists for the SDK;
- the CLI product supports external plugin integration without the SDK (C ABI +
loader are in the CLI), so the SDK is a developer kit, not a runtime feature.
Under issue #13's own criteria, "keep in workspace" is a legal conclusion when
independent consumer/release evidence is absent. The split added a cross-repo
`rev` pin, a second CI lane, a second source location and a documentation
integrity burden (stale in-repo paths, weak entry links) without a current
release or consumer benefit. The CLI's developer-facing contract, header, spec,
SDK and examples should form one atomic change domain.
## Decision
1. **The plugin SDK returns to the CLI workspace** as
`crates/marqdo-plugin-sdk`, a contract-only crate. It keeps its current clean
dependency graph: `marqdo-plugin-abi` + `serde`/`serde_json`; no loader,
worker, host, sandbox or CLI dependency.
2. **The independent repository is deleted.** Its source was restored from CLI
Git history; no second copy of the SDK or contract remains. The SDK must not
be reintroduced as a remote repository or as a submodule in this stage.
3. **Logical boundaries stay exactly as ADR-0071 defined them**: the runtime
depends only on `marqdo-host-contract`; `marqdo-plugin-abi` is a pure
contract; execution-side loader/worker/manifest/artifact live in
`marqdo-host::plugin`; the CLI is the single assembly point.
4. **Atomicity is the priority for the pre-stable line.** ABI layout, header,
spec, contract crate, SDK helpers, fixture and the real CLI invocation test
land in one commit/PR/lock. There is no cross-repository pin to bump and no
second current source tree.
5. **External access remains in the CLI product.** The release archive and
repository carry the C header, public plugin spec, loader/worker and the SDK
source; plugin authors build their plugin against this repository (or use
the header from another language). The CLI itself is not compiled by plugin
users.
6. **Future extraction is a new decision, not an implicit step.** It requires
new evidence: independent SDK release (for example a published contract
artifact), a real non-CLI consumer/maintainer, or a distribution need that
the atomic workspace cannot serve. It then needs a new Accepted ADR and must
not create a CLI↔SDK gitlink cycle.
## Verification
- SDK crate, fixture, CLI-side SDK gate and workspace/lock are restored; the
CLI builds and tests them in the same workspace.
- `tools/ci/check_dependency_boundaries.py` enforces the SDK's contract-only
normal/build dependencies and its presence in the workspace as a reviewed
crate.
- `tools/ci/check_plugin_sdk.py` builds the SDK fixture with only the public SDK
and loads it through the real CLI with explicit trust/grant; a tampered
artifact digest is rejected.
- The remote split repository was deleted after this decision; no temporary
branch was created for the revert.
- Full evidence: `docs/evidence/2026-11-26-issue-15-sdk-split-reverted.md`.
## Rejected alternatives
- **Keep the split because it was already implemented.** Sunk-cost reasoning;
it does not satisfy the "necessary split" criterion for this stage.
- **Keep the remote repository as a mirror/copy.** Two current SDK sources and
a second contract consumer tree are explicitly forbidden; Git history already
preserves ADR-0072's implementation.
- **Make the SDK a submodule of the CLI.** Inverts the dependency direction and
risks the CLI gitlink ↔ SDK → CLI contract cycle; the CLI does not consume
the SDK at build time.
- **Turn the SDK into a prebuilt binary so users need not compile.** Native
plugins are compiled by their authors by definition; the SDK is a source-level
helper. A prebuilt SDK is neither a plugin nor a compiler target.
## Consequences
- One atomic language/plugin-development change domain; one lock and one
candidate SHA for ABI/header/spec/SDK/loader changes.
- External plugin integration keeps working through the CLI's contract and
loader; the SDK is discoverable in the same public repository as the header
and spec.
- The split work remains in Git history (ADR-0072, former PR #16) as decision
history; it is not current architecture.
+8
View File
@@ -73,3 +73,11 @@ Files: `0001`–`0050`, plus:
* [0070](0070-explicit-stdlib-bundle-build-input.md) — Phase A of the stdlib
extraction: one required `--stdlib-dir` build input, one pinned Bundle
identity for tests/perf/release CI; runtime contracts unchanged.
* [0071](0071-engine-host-contract-boundary.md) — Engine / Host Contract /
Native Host / CLI responsibilities, dependency rules, plugin ABI contract split
and the keep-in-workspace repository decision.
* [0072](0072-sdk-independent-repository.md) — **superseded**: the independent
public SDK repository was deleted and the SDK returned to the CLI workspace.
* [0073](0073-sdk-stays-in-cli-workspace.md) — keep the plugin SDK in the CLI
workspace for the pre-stable atomic line; repository split deferred.