Initial external conformance skeleton: contract, pure-lib/consumer, foreign kernel
extension-conformance / conformance (push) Canceled after 0s
extension-conformance / conformance (push) Canceled after 0s
This commit is contained in:
commit
e92448f863
20 files changed
+1044
No files matched your search
@@ -0,0 +1,27 @@
|
||||
# kernel/ — unknown-language Foreign Kernel
|
||||
|
||||
`mocklang` is **not** a built-in Marqdo language. `kernel.json` registers it at
|
||||
run time through the existing external-kernel registry:
|
||||
|
||||
```bash
|
||||
MARQDO_BIN=/abs/path/to/frozen/marqdo
|
||||
"$MARQDO_BIN" run kernel/demo.mq.md \
|
||||
--kernel kernel/kernel.json \
|
||||
--allow-foreign
|
||||
```
|
||||
|
||||
It implements `spec/foreign.md` v1:
|
||||
|
||||
* argv[1] is a path to the inert `Code` resource taken from `ref("#内核程序")`;
|
||||
* stdin receives one `{"wire_version":1,"kind":"request","input":...}` envelope;
|
||||
* stdout receives exactly one type-tagged Value Wire v1 value for
|
||||
`foreign.call`.
|
||||
|
||||
The descriptor pins the provider executable by SHA-256. `kernel.json.digest`
|
||||
is the SHA-256 of `mocklang`; `tests/test_positive.py` asserts the pin and
|
||||
`python3 scripts/refresh_kernel_digest.py` refreshes it after an edit. The
|
||||
suite also proves the digest is enforced by tampering with a copy.
|
||||
|
||||
The `demo.mq.md` file also shows that the code fence is **inert**: `check`
|
||||
succeeds without any kernel registered, and only the explicit `foreign.call`
|
||||
starts the process.
|
||||
@@ -0,0 +1,17 @@
|
||||
# @knowledge mocklang 外部内核演示
|
||||
|
||||
## @knowledge 内核程序
|
||||
|
||||
```mocklang
|
||||
// Inert code resource. It is read as a Code value and only executed through an
|
||||
// explicit foreign.call; a code fence never starts a process by itself.
|
||||
answer = 42
|
||||
```
|
||||
|
||||
## @exec main
|
||||
|
||||
`结果 = foreign.call(ref("#内核程序"), {})`
|
||||
|
||||
> **打印(结果)**
|
||||
|
||||
`return 结果`
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"provider_id": "mocklang",
|
||||
"languages": [
|
||||
"mocklang",
|
||||
"mock"
|
||||
],
|
||||
"wire_version": 1,
|
||||
"entrypoint": "./mocklang",
|
||||
"permissions_requested": [],
|
||||
"digest": "fc190c3d61de682597003bdd8bbef3429a89da8c1d7c2b6474bbbd3b93c3aa09",
|
||||
"environment_id": "mocklang-python3-v1"
|
||||
}
|
||||
Executable
+50
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Unknown-language foreign kernel for the Marqdo foreign JSON wire (v1).
|
||||
|
||||
The Marqdo host writes the inert code resource to a temporary file and passes
|
||||
its path as argv[1]; stdin receives exactly one JSON envelope:
|
||||
|
||||
{"wire_version": 1, "kind": "request", "input": <typed value or null>}
|
||||
|
||||
For foreign.call, stdout must contain exactly one type-tagged wire value
|
||||
(spec/value-wire.md). This provider is intentionally not a built-in language:
|
||||
`mocklang` is unknown to the Marqdo CLI and is registered only through
|
||||
kernel.json at run time.
|
||||
"""
|
||||
import hashlib
|
||||
import json
|
||||
import sys
|
||||
|
||||
|
||||
def main() -> int:
|
||||
source_path = sys.argv[1] if len(sys.argv) > 1 else ""
|
||||
try:
|
||||
envelope = json.load(sys.stdin)
|
||||
except json.JSONDecodeError as error: # pragma: no cover - protocol failure
|
||||
print(f"mocklang: invalid request envelope: {error}", file=sys.stderr)
|
||||
return 1
|
||||
if envelope.get("wire_version") != 1 or envelope.get("kind") != "request":
|
||||
print("mocklang: expected wire_version 1 request envelope", file=sys.stderr)
|
||||
return 1
|
||||
try:
|
||||
with open(source_path, "rb") as source_file:
|
||||
source = source_file.read()
|
||||
except OSError as error: # pragma: no cover - protocol failure
|
||||
print(f"mocklang: cannot read code resource: {error}", file=sys.stderr)
|
||||
return 1
|
||||
input_value = envelope.get("input")
|
||||
result = {
|
||||
"type": "map",
|
||||
"entries": {
|
||||
"engine": {"type": "text", "value": "mocklang"},
|
||||
"answer": {"type": "int", "decimal": "42"},
|
||||
"source_digest": {"type": "text", "value": hashlib.sha256(source).hexdigest()},
|
||||
"input_kind": {"type": "text", "value": "null" if input_value is None else "typed"},
|
||||
},
|
||||
}
|
||||
sys.stdout.write(json.dumps(result, ensure_ascii=False))
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Reference in new issue
Block a user