observation: deliver one execution event sequence to stream and snapshot
This commit is contained in:
1 parent
f83d992c61
commit
404d559b86
97 files changed
+2672
-3128
No files matched your search
@@ -32,7 +32,7 @@ markdown profile `marqdo.md.v1`.
|
||||
Trace v2.
|
||||
4. [extensions.md](extensions.md) — plugins, foreign kernels, resource
|
||||
providers, extension selection and lock v4.
|
||||
5. [analysis-trace.md](analysis-trace.md) — the public static/dynamic data
|
||||
5. [analysis-observation.md](analysis-observation.md) — the public static/dynamic data
|
||||
contracts, Execution Events v1 and digest binding.
|
||||
6. [compatibility.md](compatibility.md) — version axes, platform matrix and the
|
||||
prerelease policy.
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
# Analysis and Observation
|
||||
|
||||
Run the same public CLI that users install.
|
||||
|
||||
```sh
|
||||
marqdo check index.mq.md --emit ./analysis.json
|
||||
marqdo call index.mq.md main --output jsonl --observation-file ./run.json
|
||||
```
|
||||
|
||||
A tool can use [Analysis](../../spec/analysis.md) to locate functions, imports,
|
||||
references, resources and calls. Validate its identifier before walking the
|
||||
module and statement arrays. Use the original UTF-8 bytes for offsets and
|
||||
digest checks. The format is the same for a simple document and one using
|
||||
structured loop transfers.
|
||||
|
||||
[Observation](../../spec/observation.md) carries frames, control flow, committed
|
||||
output and the final result. Consume JSONL for live updates, or use
|
||||
`--output json` for one JSON snapshot on stdout. The snapshot's `events`
|
||||
array has the same objects as the live stream. The first event opens the run
|
||||
and the terminal event gives its outcome. Treat a stream that ends before a
|
||||
terminal as incomplete. Base64 decode each stdout and stderr chunk and verify
|
||||
its byte count. Read the typed return from `run.completed.payload.value`.
|
||||
|
||||
Before highlighting source locations, compare the `run.started` root and
|
||||
SHA-256 of the exact Analysis artifact, then check the source file digest.
|
||||
A different report or edited source requires a fresh check and run.
|
||||
The repository's independent consumer implements both delivery modes.
|
||||
|
||||
```sh
|
||||
python3 tests/consumers/observation_consumer.py ./run.json --snapshot \
|
||||
--analysis ./analysis.json --source-root .
|
||||
```
|
||||
|
||||
Value capture uses exact names and explicit Text consent. Use
|
||||
`--observe-variable NAME` and `--observe-parameter NAME` only for the
|
||||
values the feature needs. Request `--observe-text-values` when the caller
|
||||
has opted into this disclosure. Program output and explicit returned values
|
||||
can themselves contain sensitive data.
|
||||
|
||||
Update integrations that previously used the retired run/call JSON,
|
||||
Trace or Execution Events options. Use the commands above, remove the old
|
||||
reader, and rebuild and reinstall the Tool with the
|
||||
[current manifest](../../spec/cli-tool.md).
|
||||
@@ -1,121 +0,0 @@
|
||||
# Analysis and Trace v2 consumers
|
||||
|
||||
Both are public, versioned JSON artifacts. A consumer must read them as files,
|
||||
never link Marqdo's Rust internals or depend on `inspect --ir`.
|
||||
|
||||
## Analysis v2 and v3 (static)
|
||||
|
||||
```bash
|
||||
marqdo check index.mq.md --emit ./analysis.json
|
||||
```
|
||||
|
||||
- Write atomically; only publish after `check` exits 0. `--refs` is an
|
||||
independent Markdown-link check and can make `check` fail; on failure the emit
|
||||
target is removed. Do not generate a consumer artifact with
|
||||
`check --refs --emit` without checking the exit code.
|
||||
- `schema: "marqdo.analysis"`. The writer emits `schema_version: 2` for
|
||||
projects without loop transfers and `3` when a function body contains
|
||||
`break` or `continue`. Check the version before walking function bodies.
|
||||
Both versions encode `else if` in the ordered `branch.arms` array.
|
||||
- Top level: `producer` (`name`, `version` = product version,
|
||||
`markdown_profile`), `project`, `modules`, `diagnostics`.
|
||||
- `project`: `root_id` (`root:<name>@<version>` for manifest projects),
|
||||
`identity_kind`, `lock_digest` (`""` without a lock), `stdlib`
|
||||
(`version`, `digest`, `instance_id`; may be null).
|
||||
- `modules[]`: `id`, `package_instance_id`, `relative_path`, `source_digest`,
|
||||
`units`, `functions`, `imports`, `references`, `calls`, `resources`.
|
||||
Diagnostics are top-level, not per-module.
|
||||
- Byte offsets are UTF-8 source offsets. Stable index keys are logical package
|
||||
instance ids, never absolute paths.
|
||||
- `check` does not load plugin libraries, start kernels/providers or execute the
|
||||
program.
|
||||
- Contracts: [Analysis v2](../../spec/analysis-v2.md) and
|
||||
[Analysis v3](../../spec/analysis-v3.md). Each links to its schema.
|
||||
The independent consumers in `tests/consumers/` check the version and
|
||||
decode the public nodes.
|
||||
|
||||
View must render the **original Markdown** and use Analysis only to correlate
|
||||
source offsets/heading units/callable mapping. Knowledge must use heading
|
||||
anchors, links, resources, package identity and source digests; it must not
|
||||
assume a `@knowledge` unit has runtime effects. Prove must map only the public
|
||||
proveable subset and distinguish `proved / disproved / unknown / unsupported`;
|
||||
a proof certificate needs matching source digest, semantics and contract
|
||||
identity.
|
||||
|
||||
## Trace v2 (dynamic)
|
||||
|
||||
```bash
|
||||
marqdo run index.mq.md --trace-file ./trace.json
|
||||
```
|
||||
|
||||
- `schema: "marqdo.trace"`, `schema_version: 2`.
|
||||
- `source.analysis_digest` must equal SHA-256 of the **Analysis JSON bytes** for
|
||||
the same project/projection configuration. A mismatch means the trace is
|
||||
stale; do not bind it to the new source. `run --trace-file` does not emit
|
||||
Analysis itself.
|
||||
- Event kinds: `call.enter`, `call.exit`, `branch.eval`, `loop.iteration`,
|
||||
`control.break`, `control.continue`, `return`, `effect` and possibly
|
||||
`trace.truncated`. Sourced events carry a
|
||||
module id and a UTF-8 span.
|
||||
- Defaults are 100,000 events / 32 MiB; `--trace-max-events` and
|
||||
`--trace-max-bytes` adjust them (`0` = unlimited). A consumer must tolerate
|
||||
truncation and must not assume the trace is complete.
|
||||
- Trace records no argument values, secrets or file contents.
|
||||
- Contract: `spec/trace-v2.md`; schema:
|
||||
`spec/schemas/trace-v2.schema.json`; consumer:
|
||||
`tests/consumers/trace_consumer.py`.
|
||||
|
||||
## Execution Events v1 (live)
|
||||
|
||||
```bash
|
||||
marqdo run index.mq.md --event-stream jsonl
|
||||
marqdo call index.mq.md main --arg n=5 --event-stream jsonl
|
||||
marqdo run index.mq.md --event-stream jsonl --trace-file ./trace.json
|
||||
```
|
||||
|
||||
- `schema: "marqdo.execution-events"`, `schema_version: 1`. This is a separate
|
||||
protocol from Analysis/Trace and has its own version axis.
|
||||
- While active, the CLI stdout is a **pure NDJSON channel**: one JSON object per
|
||||
line, `seq` starts at 0 and is strictly increasing. Program stdout/stderr are
|
||||
only `stdout.chunk`/`stderr.chunk` events with `encoding: "base64"`,
|
||||
`data_base64` and a matching `byte_count`. Concatenated decoded bytes equal a
|
||||
normal run's output; invalid UTF-8/NUL/binary bytes are preserved.
|
||||
- `stream.opened` is always seq 0. A run then has at most one `run.started` and
|
||||
exactly one terminal event (`run.completed`, `run.failed`, `run.rejected`) on
|
||||
a complete stream. An EOF without a terminal event is `incomplete`
|
||||
(SIGKILL/crash/broken pipe); never synthesize success.
|
||||
- `run.started.source` contains `root_id` and the `sha256:` digest of the exact
|
||||
Analysis bytes. `--trace-file` may be combined; both writers share one
|
||||
opaque run id, and Trace v2 remains atomic and value-free.
|
||||
- Structural events: `call.enter`/`call.exit` (`frame_id`, `parent_frame_id`),
|
||||
`return`, `branch.eval`, `loop.iteration`, `control.break`,
|
||||
`control.continue` and `effect`. Frames identify call
|
||||
instances, not functions; a failed argument binding creates no frame.
|
||||
- Values are off by default (`value_state: not_requested`).
|
||||
`--observe-variable NAME` and `--observe-parameter NAME` are exact-name
|
||||
selections. `Int`/`Float`/`Bool` are bounded by
|
||||
`--observe-max-value-bytes` (default 256); selected `Text` is `redacted` until
|
||||
`--observe-text-values` is also passed. Containers, `Memory`, resources and
|
||||
plugin handles are `unsupported`; handles are never serialized.
|
||||
- Structural/value events have a separate budget
|
||||
(`--observe-max-events`, `--observe-max-bytes`; defaults 100 000 / 16 MiB).
|
||||
Exhaustion emits one `observation.truncated` and still delivers stdout/stderr
|
||||
and the terminal event. A broken output pipe fails the run with
|
||||
`observe.transport_failed`; it never keeps executing side effects silently.
|
||||
- `--event-stream` is mutually exclusive with `--json`, rejected by
|
||||
`check`/`inspect`/`fmt`/`tool`, and currently rejected by `--mode strict`
|
||||
(fail-closed, no downgrade). It is not a capability grant.
|
||||
- Contract: [`../../spec/execution-events-v1.md`](../../spec/execution-events-v1.md);
|
||||
schema: `spec/schemas/execution-events-v1.schema.json`; consumer:
|
||||
`tests/consumers/execution_events_consumer.py`; fixtures and Rust gate:
|
||||
`tests/consumers/fixtures/execution-events/` and
|
||||
`crates/cli/tests/execution_events.rs`.
|
||||
|
||||
## Consumer rules
|
||||
|
||||
1. Reject unknown schema majors; there is no silent "use latest" fallback.
|
||||
2. Verify `source.analysis_digest` against the actual Analysis file bytes.
|
||||
3. Verify `source.root_id`/package identity; do not key on absolute paths.
|
||||
4. Be deterministic and offline; never execute `.mq.md` yourself, never invent
|
||||
host effects, and never inherit Marqdo grants.
|
||||
5. Report an unsupported/stale artifact explicitly; do not silently downgrade.
|
||||
@@ -38,7 +38,7 @@ Strict is Linux-only and probe-gated. Plugin/provider worker transports are not
|
||||
OS sandboxes. `pure`/`project` are execution modes, not security boundaries.
|
||||
Execution Events v1 is a live observation protocol: it is not a capability
|
||||
grant, values are off by default, and `--mode strict` currently refuses
|
||||
`--event-stream` explicitly (no downgrade).
|
||||
`--output jsonl` explicitly (no downgrade).
|
||||
|
||||
## Language compatibility
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ marqdo call index.mq.md main
|
||||
```
|
||||
|
||||
`run` executes the entry function (`main` by default) and prints program output;
|
||||
`call` prints the returned value. Use `--json` for machine-readable
|
||||
`call` prints the returned value. Use `--output json` for machine-readable
|
||||
results (`{"command":"run","success":true,...}`), including embedded program
|
||||
stdout and diagnostics.
|
||||
|
||||
@@ -76,8 +76,8 @@ stdout and diagnostics.
|
||||
|
||||
```bash
|
||||
marqdo check index.mq.md --json
|
||||
marqdo run index.mq.md --json
|
||||
marqdo call index.mq.md main --json
|
||||
marqdo run index.mq.md --output json
|
||||
marqdo call index.mq.md main --output json
|
||||
```
|
||||
|
||||
## 5. Where next
|
||||
@@ -85,6 +85,6 @@ marqdo call index.mq.md main --json
|
||||
- Publish/consume a pure library: [libraries.md](libraries.md).
|
||||
- Build an external tool: [tools.md](tools.md).
|
||||
- Plugins, kernels, providers: [extensions.md](extensions.md).
|
||||
- Analysis/Trace consumers: [analysis-trace.md](analysis-trace.md).
|
||||
- Analysis/Trace consumers: [analysis-observation.md](analysis-observation.md).
|
||||
- Version axes and platform support: [compatibility.md](compatibility.md).
|
||||
- Beta limitations: [release-limits.md](release-limits.md).
|
||||
@@ -84,7 +84,7 @@ an untrusted Git URL does not make the code trustworthy.
|
||||
* Not implemented: memory region/budget metadata (OBS-06/P2), raw memory
|
||||
content, breakpoints/stepping/time travel, and a bidirectional debug
|
||||
protocol. Do not infer a debugger from this protocol.
|
||||
* `--mode strict` currently rejects `--event-stream` explicitly; there is no
|
||||
* `--mode strict` currently rejects `--output jsonl` explicitly; there is no
|
||||
silent fallback to `project`.
|
||||
* The live lane is tested on Linux x86_64; macOS/Windows are unverified for
|
||||
this option for this candidate.
|
||||
|
||||
@@ -5,7 +5,7 @@ product command. A tool is a **separate executable** registered by the user; the
|
||||
CLI only dispatches unknown top-level commands to registered tools and never
|
||||
scans `PATH` for a guessed name.
|
||||
|
||||
Normative contract: [`../../spec/tool-v1.md`](../../spec/tool-v1.md)
|
||||
Normative contract: [`../../spec/cli-tool.md`](../../spec/cli-tool.md)
|
||||
(implemented and frozen for protocol v1).
|
||||
|
||||
## 1. Package layout
|
||||
@@ -106,7 +106,7 @@ stream to its own SSE/websocket transport; the CLI never implements HTTP/SSE.
|
||||
This option is unavailable under `--mode strict` in the current tree and the
|
||||
tool must surface that refusal instead of pretending real-time support.
|
||||
|
||||
See [analysis-trace.md](analysis-trace.md) for fields and digest rules. Do not
|
||||
See [analysis-observation.md](analysis-observation.md) for fields and digest rules. Do not
|
||||
depend on `inspect --ir`: that JSON is not a frozen cross-repository protocol.
|
||||
The `view` tool renders the **original Markdown**, not the Analysis JSON; the
|
||||
Analysis is an index, not a replacement for the source text.
|
||||
|
||||
Reference in new issue
Block a user