Refactor executable library handbooks and improve document reading

This commit is contained in:
cflmy committed 2026-11-08 22:19:11 +08:00
1 parent 16c44588d5
commit c50c515c4a
191 files changed
+29572 -7816

No files matched your search

+68
View File
@@ -0,0 +1,68 @@
---
markup: occlusion
---
Optional ZIP tasks: native defaults include ZIP; minimal/browser builds report unavailable. Returns Result.
ZIP tasks are optional native capabilities, with no standalone plugin to install.
The pack/unpack contracts below define both operations. Both return
Result and require fs.write. Source and destination paths stay under the granted
root; output must not already exist. Extraction preflights paths, duplicate
entries, symlinks and the uncompressed byte limit before creating its directory.
Failed extraction removes only the newly-created destination. Minimal/browser
builds report unavailable; they never pretend to have written an archive.
This single source file is the usage and development manual. Import it directly, or use marqdo call with a function heading below. Parameter tables give types and defaults; required parameters must be supplied. Return tables are progressive contracts; prose describes failure and limits.
Relative IO paths use --fs-root, or the called file directory when omitted. Writes require explicit fs.write grants, subprocesses require process.exec, and pure transforms require no IO grant.
Implementation: [src/host/archive.rs](../src/host/archive.rs)
For development, keep EN/ZH behavior aligned and compose public libraries first. Add host primitives only at OS or algorithm boundaries and declare their effects. Run marqdo check --narrative-ratio on this file and the real workflows in tests/stdlib_tasks.rs after edits.
## pack
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| src | text | required | Source path; archive packing expects a directory |
| dest | text | required | Destination path; overwrite is allowed only where documented |
| max_bytes | number | 1073741824 | Maximum bytes read or expanded; exceeding it fails |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | map | Result containing the count of archived regular files, or a structured error |
Use `src`, `dest`, `max_bytes`=1073741824 as the inputs for this operation.
Effects: fs.write.
For this example, set MQ_WORK to an existing disposable directory with regular files in an input subdirectory. bundle.zip and output must not exist. Keep or clean the produced artifacts explicitly.
```sh
marqdo call lib/archive.mq.md pack 'src="input"' 'dest="bundle.zip"' --fs-root "$MQ_WORK" --effects fs.write --json
marqdo call lib/archive.mq.md unpack 'src="bundle.zip"' 'dest="output"' --fs-root "$MQ_WORK" --effects fs.write --json
```
Destination must not exist. Caps total uncompressed bytes and 100000 entries; rejects symlinks and escaping paths. Pack includes regular files; failed unpack removes only its newly-created destination.
Return *[Pack regular files into ZIP without overwriting an existing destination](> host_zip_pack src=`src` dest=`dest` max_bytes=`max_bytes`)*.
## unpack
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| src | text | required | Source path; archive packing expects a directory |
| dest | text | required | Destination path; overwrite is allowed only where documented |
| max_bytes | number | 1073741824 | Maximum bytes read or expanded; exceeding it fails |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | map | Result containing the extracted entry count, or a structured error |
Use `src`, `dest`, `max_bytes`=1073741824 as the inputs for this operation.
Effects: fs.write.
Destination must not exist. Caps total uncompressed bytes and 100000 entries; rejects symlinks and escaping paths. Pack includes regular files; failed unpack removes only its newly-created destination.
Return *[Validate and extract ZIP entries without escaping the root or overwriting a destination](> host_zip_unpack src=`src` dest=`dest` max_bytes=`max_bytes`)*.
+490 -120
View File
@@ -10,107 +10,255 @@ import:
Readable browser effect helpers for WASM clients. Prefer GFM tables + these helpers; do not build effects with json.set chains.
Build browser effects as ordinary structured values.
Behavior and limits: Constructing an effect is pure; the official WASM bridge performs it in a browser. Native construction does not prove a DOM update occurred. Keep business logic in Marqdo.
This single source file is the usage and development manual. Import it directly, or use marqdo call with a function heading below. Parameter tables give types and defaults; required parameters must be supplied. Return tables are progressive contracts; prose describes failure and limits.
Implementation: [crates/marqdo-wasm/js/marqdo-bridge.js](../crates/marqdo-wasm/js/marqdo-bridge.js)
For development, keep EN/ZH behavior aligned and compose public libraries first. Add host primitives only at OS or algorithm boundaries and declare their effects. Run marqdo check --narrative-ratio on this file and the real workflows in tests/stdlib_tasks.rs after edits.
## set_text
+ `sel`
+ `text`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| sel | any | required | CSS selector of the target browser element |
| text | text | required | Text supplied by the caller |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Build set_text effect map for the official bridge |
Use `sel`, `text` as the inputs for this operation.
Effects: pure.
Call this function directly:
```sh
marqdo call lib/browser.mq.md set_text 'sel="#status"' 'text="Ready"' --effects none --json
```
Build set_text effect map for the official bridge.
**`m` = > table.put in=None at=sel value=text**
*> table.put in=None at="set_text" value=m*
We retain **`m` = [Return the updated structured value](table.put(in=None, at=`sel`, value=`text`))**.
Return *[Set the set_text field in the new record](table.put(in=None, at="set_text", value=`m`))*.
## set_html
+ `sel`
+ `html`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| sel | any | required | CSS selector of the target browser element |
| html | any | required | HTML fragment; use set_text for ordinary untrusted text |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Build set_html effect map |
Use `sel`, `html` as the inputs for this operation.
Effects: pure.
Build set_html effect map.
**`m` = > table.put in=None at=sel value=html**
*> table.put in=None at="set_html" value=m*
We retain **`m` = [Return the updated structured value](table.put(in=None, at=`sel`, value=`html`))**.
Return *[Set the set_html field in the new record](table.put(in=None, at="set_html", value=`m`))*.
## set_value
+ `sel`
+ `value`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| sel | any | required | CSS selector of the target browser element |
| value | any | required | Value to transform or store, without mutating the input |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Build set_value effect map |
Use `sel`, `value` as the inputs for this operation.
Effects: pure.
Build set_value effect map.
**`m` = > table.put in=None at=sel value=value**
*> table.put in=None at="set_value" value=m*
We retain **`m` = [Return the updated structured value](table.put(in=None, at=`sel`, value=`value`))**.
Return *[Set the set_value field in the new record](table.put(in=None, at="set_value", value=`m`))*.
## set_class
+ `sel`
+ `class`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| sel | any | required | CSS selector of the target browser element |
| class | any | required | Space-separated CSS class names |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Build set_class effect map |
Use `sel`, `class` as the inputs for this operation.
Effects: pure.
Build set_class effect map.
**`m` = > table.put in=None at=sel value=class**
*> table.put in=None at="set_class" value=m*
We retain **`m` = [Return the updated structured value](table.put(in=None, at=`sel`, value=`class`))**.
Return *[Set the set_class field in the new record](table.put(in=None, at="set_class", value=`m`))*.
## add_class
+ `sel`
+ `class`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| sel | any | required | CSS selector of the target browser element |
| class | any | required | Space-separated CSS class names |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Build add_class effect map (classList.add; space-separated names OK) |
Use `sel`, `class` as the inputs for this operation.
Effects: pure.
Build add_class effect map (classList.add; space-separated names OK).
**`m` = > table.put in=None at=sel value=class**
*> table.put in=None at="add_class" value=m*
We retain **`m` = [Return the updated structured value](table.put(in=None, at=`sel`, value=`class`))**.
Return *[Set the add_class field in the new record](table.put(in=None, at="add_class", value=`m`))*.
## remove_class
+ `sel`
+ `class`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| sel | any | required | CSS selector of the target browser element |
| class | any | required | Space-separated CSS class names |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Build remove_class effect map |
Use `sel`, `class` as the inputs for this operation.
Effects: pure.
Build remove_class effect map.
**`m` = > table.put in=None at=sel value=class**
*> table.put in=None at="remove_class" value=m*
We retain **`m` = [Return the updated structured value](table.put(in=None, at=`sel`, value=`class`))**.
Return *[Set the remove_class field in the new record](table.put(in=None, at="remove_class", value=`m`))*.
## toggle_class
+ `sel`
+ `class`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| sel | any | required | CSS selector of the target browser element |
| class | any | required | Space-separated CSS class names |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Build toggle_class effect map |
Use `sel`, `class` as the inputs for this operation.
Effects: pure.
Build toggle_class effect map.
**`m` = > table.put in=None at=sel value=class**
*> table.put in=None at="toggle_class" value=m*
We retain **`m` = [Return the updated structured value](table.put(in=None, at=`sel`, value=`class`))**.
Return *[Set the toggle_class field in the new record](table.put(in=None, at="toggle_class", value=`m`))*.
## set_style
+ `sel`
+ `style`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| sel | any | required | CSS selector of the target browser element |
| style | any | required | CSS property/value record for the target element |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Build set_style effect map; style is a map of CSS properties or a cssText string |
Use `sel`, `style` as the inputs for this operation.
Effects: pure.
Build set_style effect map; style is a map of CSS properties or a cssText string.
**`m` = > table.put in=None at=sel value=style**
*> table.put in=None at="set_style" value=m*
We retain **`m` = [Return the updated structured value](table.put(in=None, at=`sel`, value=`style`))**.
Return *[Set the set_style field in the new record](table.put(in=None, at="set_style", value=`m`))*.
## set_attr
+ `sel`
+ `attrs`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| sel | any | required | CSS selector of the target browser element |
| attrs | any | required | HTML attribute/value record for the target element |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Build set_attr effect map; attrs is usually a small map of attribute names to values |
Use `sel`, `attrs` as the inputs for this operation.
Effects: pure.
Build set_attr effect map; attrs is usually a small map of attribute names to values.
**`m` = > table.put in=None at=sel value=attrs**
*> table.put in=None at="set_attr" value=m*
We retain **`m` = [Return the updated structured value](table.put(in=None, at=`sel`, value=`attrs`))**.
Return *[Set the set_attr field in the new record](table.put(in=None, at="set_attr", value=`m`))*.
## wrap
+ `key`
+ `value`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| key | text | required | Field name or key required by this operation |
| value | any | required | Value to transform or store, without mutating the input |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Single-key effect map wrapper |
Use `key`, `value` as the inputs for this operation.
Effects: pure.
Single-key effect map wrapper.
*> table.put in=None at=key value=value*
Return *[Return the updated structured value](table.put(in=None, at=`key`, value=`value`))*.
## merge
+ `a`
+ `b`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| a | any | required | First browser effect record |
| b | any | required | Browser effect record to merge over a |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Merge two effect maps; right-hand keys win |
Use `a`, `b` as the inputs for this operation.
Effects: pure.
Merge two effect maps; right-hand keys win.
*> table.merge a=`a` b=`b`*
Return *[Merge](table.merge(a=`a`, b=`b`))*.
## canvas
+ `sel`
+ `commands`
+ `clear`=True
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| sel | any | required | CSS selector of the target browser element |
| commands | any | required | Ordered list of canvas drawing commands |
| clear | any | True | Whether the canvas is cleared before drawing commands |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Build canvas effect; commands is usually an @ GFM table |
Use `sel`, `commands`, `clear`=True as the inputs for this operation.
Effects: pure.
Build canvas effect; commands is usually an @ GFM table.
@@ -120,34 +268,58 @@ Build canvas effect; commands is usually an @ GFM table.
|-----|-------|----------|
| `sel` | `clear` | `commands` |
*> table.put in=None at="canvas" value=spec*
Return *[Set the canvas field in the new record](table.put(in=None, at="canvas", value=`spec`))*.
## audio
+ `op`="play"
+ `id`="default"
+ `src`=""
+ `freq`=None
+ `ms`=None
+ `sel`=""
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| op | any | "play" | Audio command: play, pause or stop |
| id | any | "default" | Audio channel identifier |
| src | text | "" | Audio URL, or beep for a synthesized tone |
| freq | any | None | Oscillator frequency in hertz |
| ms | any | None | Duration or delay in milliseconds |
| sel | any | "" | CSS selector of the target browser element |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Build audio effect for the bridge |
Use `op`="play", `id`="default", `src`="", `freq`=None, `ms`=None, `sel`="" as the inputs for this operation.
Effects: pure.
Build audio effect for the bridge.
**`spec` = > table.put in=None at="op" value=op**
**`spec` = > table.put in=`spec` at="id" value=id**
This function returns an effect record and plays no sound immediately. The bridge selects a source, synthesized frequency or audio element; browsers may require a prior user gesture.
We retain **`spec` = [Set the op field in the new record](table.put(in=None, at="op", value=`op`))**.
We retain **`spec` = [Set the id field in the new record](table.put(in=`spec`, at="id", value=`id`))**.
1. `src` != ""
**`spec` = > table.put in=`spec` at="src" value=src**
We retain **`spec` = [Set the src field in the new record](table.put(in=`spec`, at="src", value=`src`))**.
1. `freq` != None
**`spec` = > table.put in=`spec` at="freq" value=freq**
We retain **`spec` = [Set the freq field in the new record](table.put(in=`spec`, at="freq", value=`freq`))**.
1. `ms` != None
**`spec` = > table.put in=`spec` at="ms" value=ms**
We retain **`spec` = [Set the ms field in the new record](table.put(in=`spec`, at="ms", value=`ms`))**.
1. `sel` != ""
**`spec` = > table.put in=`spec` at="sel" value=sel**
*> table.put in=None at="audio" value=spec*
We retain **`spec` = [Set the sel field in the new record](table.put(in=`spec`, at="sel", value=`sel`))**.
Return *[Set the audio field in the new record](table.put(in=None, at="audio", value=`spec`))*.
## read_file
+ `sel`
+ `then`
+ `as`="text"
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| sel | any | required | CSS selector of the target browser element |
| then | any | required | Marqdo callback name for the bridge result; empty text omits callback |
| as | any | "text" | File content representation expected by the browser bridge |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Build read_file effect |
Use `sel`, `then`, `as`="text" as the inputs for this operation.
Effects: pure.
Build read_file effect.
@@ -157,32 +329,80 @@ Build read_file effect.
|-----|----|------|
| `sel` | `as` | `then` |
*> table.put in=None at="read_file" value=spec*
Return *[Set the read_file field in the new record](table.put(in=None, at="read_file", value=`spec`))*.
## observe
+ `specs`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| specs | any | required | Effect specifications; use a record or an @ row-record list |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Build observe effect; specs is one map or an @ list of maps |
Use `specs` as the inputs for this operation.
Effects: pure.
Build observe effect; specs is one map or an @ list of maps.
*> table.put in=None at="observe" value=specs*
Return *[Set the observe field in the new record](table.put(in=None, at="observe", value=`specs`))*.
## unobserve
+ `specs`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| specs | any | required | Effect specifications; use a record or an @ row-record list |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Build unobserve effect; specs is a map or @ list with id |
Use `specs` as the inputs for this operation.
Effects: pure.
Build unobserve effect; specs is a map or @ list with id.
*> table.put in=None at="unobserve" value=specs*
Return *[Set the unobserve field in the new record](table.put(in=None, at="unobserve", value=`specs`))*.
## focus
+ `sel`
focus.
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| sel | any | required | CSS selector of the target browser element |
*> table.put in=None at="focus" value=sel*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Build a focus effect for the selected element; the browser bridge applies it after the handler returns |
Use `sel` as the inputs for this operation.
Effects: pure.
Build a focus effect for the selected element; the browser bridge applies it after the handler returns.
Build the focus effect record. The browser bridge consumes this record; this function itself does not change the page.
Return *[Set the focus field in the new record](table.put(in=None, at="focus", value=`sel`))*.
## navigate
+ `url`
+ `replace`=False
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| url | text | required | Target URL; HTTP helpers accept http or https |
| replace | any | False | Whether navigation replaces the current history entry |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Build the navigate effect record |
Use `url`, `replace`=False as the inputs for this operation.
Effects: pure.
Build the navigate effect record. The browser bridge consumes this record; this function itself does not change the page.
`spec` =
@@ -190,13 +410,24 @@ focus.
|-----|---------|
| `url` | `replace` |
*> table.put in=None at="navigate" value=spec*
Return *[Set the navigate field in the new record](table.put(in=None, at="navigate", value=`spec`))*.
## store_set
+ `key`
+ `value`
+ `scope`="memory"
+ `then`=""
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| key | text | required | Field name or key required by this operation |
| value | any | required | Value to transform or store, without mutating the input |
| scope | any | "memory" | Storage scope: memory, local or session |
| then | any | "" | Marqdo callback name for the bridge result; empty text omits callback |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | In-memory (or local/session) key write for SPA client state |
Use `key`, `value`, `scope`="memory", `then`="" as the inputs for this operation.
Effects: pure.
In-memory (or local/session) key write for SPA client state. Prefer `scope=memory` for tab-local app state.
Optional `then` is called after the write with `{ok, op, key, scope}`.
@@ -204,31 +435,53 @@ Optional `then` is called after the write with `{ok, op, key, scope}`.
`spec` =
| op | key | value | scope |
|----|-----|-------|-------|
| ---- | ----- | ------- | ------- |
| set | `key` | `value` | `scope` |
1. `then` != ""
**`spec` = > table.put in=spec at="then" value=then**
*> table.put in=None at="storage" value=spec*
We retain **`spec` = [Set the then field in the new record](table.put(in=`spec`, at="then", value=`then`))**.
Return *[Set the storage field in the new record](table.put(in=None, at="storage", value=`spec`))*.
## store_get
+ `key`
+ `then`
+ `scope`="memory"
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| key | text | required | Field name or key required by this operation |
| then | any | required | Marqdo callback name for the bridge result; empty text omits callback |
| scope | any | "memory" | Storage scope: memory, local or session |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Read a key then call `then` with `{ok, value, found, key, scope}` |
Use `key`, `then`, `scope`="memory" as the inputs for this operation.
Effects: pure.
Read a key then call `then` with `{ok, value, found, key, scope}`.
`spec` =
| op | key | then | scope |
|----|-----|------|-------|
| ---- | ----- | ------ | ------- |
| get | `key` | `then` | `scope` |
*> table.put in=None at="storage" value=spec*
Return *[Set the storage field in the new record](table.put(in=None, at="storage", value=`spec`))*.
## spa_goto
+ `url`
+ `replace`=False
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| url | text | required | Target URL; HTTP helpers accept http or https |
| replace | any | False | Whether navigation replaces the current history entry |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | SPA navigation: `history.pushState` / `replaceState` via bridge `navigate` effect |
Use `url`, `replace`=False as the inputs for this operation.
Effects: pure.
SPA navigation: `history.pushState` / `replaceState` via bridge `navigate` effect.
@@ -238,19 +491,45 @@ SPA navigation: `history.pushState` / `replaceState` via bridge `navigate` effec
|-----|---------|
| `url` | `replace` |
*> table.put in=None at="navigate" value=spec*
Return *[Set the navigate field in the new record](table.put(in=None, at="navigate", value=`spec`))*.
## storage
+ `spec`
storage.
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| spec | any | required | Storage operation record: op, key, scope and optional value/then |
*> table.put in=None at="storage" value=spec*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Wrap one storage specification as a browser effect; the bridge handles op, key, value, scope and then |
Use `spec` as the inputs for this operation.
Effects: pure.
Wrap one storage specification as a browser effect; the bridge handles op, key, value, scope and then.
Build the storage effect record. The browser bridge consumes this record; this function itself does not change the page.
Return *[Set the storage field in the new record](table.put(in=None, at="storage", value=`spec`))*.
## interval
+ `ms`
+ `then`
+ `id`="default"
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| ms | any | required | Duration or delay in milliseconds |
| then | any | required | Marqdo callback name for the bridge result; empty text omits callback |
| id | any | "default" | Timer identifier, later passed to clear_interval |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Build the interval effect record |
Use `ms`, `then`, `id`="default" as the inputs for this operation.
Effects: pure.
Build the interval effect record. The browser bridge consumes this record; this function itself does not change the page.
`spec` =
@@ -258,20 +537,46 @@ storage.
|----|------|----|
| `ms` | `then` | `id` |
*> table.put in=None at="interval" value=spec*
Return *[Set the interval field in the new record](table.put(in=None, at="interval", value=`spec`))*.
## clear_interval
+ `id`="default"
clear_interval.
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| id | any | "default" | Identifier returned by the corresponding create/spawn operation |
**`spec` = > table.put in=None at="id" value=id**
*> table.put in=None at="clear_interval" value=spec*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Build a cancellation effect using the same identifier previously supplied to interval |
Use `id`="default" as the inputs for this operation.
Effects: pure.
Build a cancellation effect using the same identifier previously supplied to interval.
Build the clear_interval effect record. The browser bridge consumes this record; this function itself does not change the page.
We retain **`spec` = [Set the id field in the new record](table.put(in=None, at="id", value=`id`))**.
Return *[Set the clear_interval field in the new record](table.put(in=None, at="clear_interval", value=`spec`))*.
## fetch
+ `url`
+ `then`
+ `method`="GET"
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| url | text | required | Target URL; HTTP helpers accept http or https |
| then | any | required | Marqdo callback name for the bridge result; empty text omits callback |
| method | text | "GET" | HTTP method, for example GET or POST |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Build the fetch effect record |
Use `url`, `then`, `method`="GET" as the inputs for this operation.
Effects: pure.
Build the fetch effect record. The browser bridge consumes this record; this function itself does not change the page.
`spec` =
@@ -279,11 +584,24 @@ clear_interval.
|-----|------|--------|
| `url` | `then` | `method` |
*> table.put in=None at="fetch" value=spec*
Return *[Set the fetch field in the new record](table.put(in=None, at="fetch", value=`spec`))*.
## fetch_all
+ `requests`
+ `then`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| requests | any | required | Ordered list of browser request specification records |
| then | any | required | Marqdo callback name for the bridge result; empty text omits callback |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Build the fetch_all effect record |
Use `requests`, `then` as the inputs for this operation.
Effects: pure.
Build the fetch_all effect record. The browser bridge consumes this record; this function itself does not change the page.
`spec` =
@@ -291,11 +609,24 @@ clear_interval.
|----------|------|
| `requests` | `then` |
*> table.put in=None at="fetch_all" value=spec*
Return *[Set the fetch_all field in the new record](table.put(in=None, at="fetch_all", value=`spec`))*.
## after
+ `ms`
+ `then`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| ms | any | required | Duration or delay in milliseconds |
| then | any | required | Marqdo callback name for the bridge result; empty text omits callback |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Build the after effect record |
Use `ms`, `then` as the inputs for this operation.
Effects: pure.
Build the after effect record. The browser bridge consumes this record; this function itself does not change the page.
`spec` =
@@ -303,27 +634,66 @@ clear_interval.
|----|------|
| `ms` | `then` |
*> table.put in=None at="after" value=spec*
Return *[Set the after field in the new record](table.put(in=None, at="after", value=`spec`))*.
## ws
+ `spec`
ws.
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| spec | any | required | One bridge effect specification record |
*> table.put in=None at="ws" value=spec*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Wrap a WebSocket operation specification for the browser bridge; this function opens no native socket |
Use `spec` as the inputs for this operation.
Effects: pure.
Wrap a WebSocket operation specification for the browser bridge; this function opens no native socket.
Build the ws effect record. The browser bridge consumes this record; this function itself does not change the page.
Return *[Set the ws field in the new record](table.put(in=None, at="ws", value=`spec`))*.
## clipboard
+ `text`
clipboard.
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| text | text | required | Text supplied by the caller |
**`spec` = > table.put in=None at="text" value=text**
*> table.put in=None at="clipboard" value=spec*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Build a clipboard effect from the text; browser permissions and user-gesture requirements apply when consumed |
Use `text` as the inputs for this operation.
Effects: pure.
Build a clipboard effect from the text; browser permissions and user-gesture requirements apply when consumed.
Build the clipboard effect record. The browser bridge consumes this record; this function itself does not change the page.
We retain **`spec` = [Set the text field in the new record](table.put(in=None, at="text", value=`text`))**.
Return *[Set the clipboard field in the new record](table.put(in=None, at="clipboard", value=`spec`))*.
## download
+ `body`
+ `filename`="download.txt"
+ `mime`="text/plain;charset=utf-8"
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| body | any | required | Request body, or replacement text for document operations |
| filename | any | "download.txt" | Suggested download filename |
| mime | any | "text/plain;charset=utf-8" | Content MIME type |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Build the download effect record |
Use `body`, `filename`="download.txt", `mime`="text/plain;charset=utf-8" as the inputs for this operation.
Effects: pure.
Build the download effect record. The browser bridge consumes this record; this function itself does not change the page.
`spec` =
@@ -331,4 +701,4 @@ clipboard.
|------|----------|------|
| `body` | `filename` | `mime` |
*> table.put in=None at="download" value=spec*
Return *[Set the download field in the new record](table.put(in=None, at="download", value=`spec`))*.
+132
View File
@@ -0,0 +1,132 @@
---
markup: occlusion
title: bytes
---
Bytes are ordinary records with `_type: bytes` and `base64`, portable across CLI, JSON, plugins and sessions; no new language type.
Carry arbitrary binary data through ordinary portable records.
Behavior and limits: A bytes record contains _type=bytes and canonical Base64. Byte offsets are zero-based; UTF-8 decoding is explicit and strict. read_chunk has no long-lived file handle.
This single source file is the usage and development manual. Import it directly, or use marqdo call with a function heading below. Parameter tables give types and defaults; required parameters must be supplied. Return tables are progressive contracts; prose describes failure and limits.
Implementation: [src/host/fs_ops.rs](../src/host/fs_ops.rs)、[src/host/encoding.rs](../src/host/encoding.rs)
For development, keep EN/ZH behavior aligned and compose public libraries first. Add host primitives only at OS or algorithm boundaries and declare their effects. Run marqdo check --narrative-ratio on this file and the real workflows in tests/stdlib_tasks.rs after edits.
## from_text
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| text | text | required | Text to read, transform or emit as described by this operation |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | map | Encode text as UTF-8 bytes |
Use `text` as the inputs for this operation.
Effects: pure.
Call this function directly:
```sh
marqdo call lib/bytes.mq.md from_text 'text="Marqdo"' --effects none --json
```
Encode text as UTF-8 bytes.
Return *[Encode text as UTF-8 bytes](> host_bytes_from_text text=`text`)*.
## from_base64
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| text | text | required | Text to read, transform or emit as described by this operation |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | map | Decode Base64 as arbitrary bytes; no UTF-8 assumption |
Use `text` as the inputs for this operation.
Effects: pure.
Decode Base64 as arbitrary bytes; no UTF-8 assumption.
Return *[Decode Base64 as arbitrary bytes; no UTF-8 assumption](> host_bytes_from_base64 text=`text`)*.
## to_text
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| data | map | required | Portable bytes record containing _type=bytes and base64 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | text | Decode UTF-8 strictly; invalid byte sequences fail |
Use `data` as the inputs for this operation.
Effects: pure.
Decode UTF-8 strictly; invalid byte sequences fail.
Return *[Decode UTF-8 strictly; invalid byte sequences fail](> host_bytes_to_text data=`data`)*.
## to_base64
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| data | map | required | Portable bytes record containing _type=bytes and base64 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | text | Return canonical padded Base64 |
Use `data` as the inputs for this operation.
Effects: pure.
Return canonical padded Base64.
Return *[Return canonical padded Base64](> host_bytes_to_base64 data=`data`)*.
## len
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| data | map | required | Portable bytes record containing _type=bytes and base64 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | number | Count bytes, not characters |
Use `data` as the inputs for this operation.
Effects: pure.
Count bytes, not characters.
Return *[Count bytes, not characters](> host_bytes_len data=`data`)*.
## slice
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| data | map | required | Portable bytes record containing _type=bytes and base64 |
| start | number | required | Inclusive zero-based slice start |
| end | number | required | Exclusive zero-based slice end; None selects through the end |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | map | Return a zero-based half-open byte slice; endpoints clamp to length |
Use `data`, `start`, `end` as the inputs for this operation.
Effects: pure.
Return a zero-based half-open byte slice; endpoints clamp to length.
Return *[Return a zero-based half-open byte slice; endpoints clamp to length](> host_bytes_slice data=`data` start=`start` end=`end`)*.
+29 -2
View File
@@ -6,11 +6,38 @@ description: Parse argv flags (Mid M5). --key value / --key=value / --flag; posi
Parse process argv into a map. Flags and positionals (under _).
Convert argv tokens to a small flag/positional map.
Behavior and limits: Values stay text; bare flags become booleans and positionals live under _. Omitted args use host argv. This is a small parser, not an argparse schema system.
This single source file is the usage and development manual. Import it directly, or use marqdo call with a function heading below. Parameter tables give types and defaults; required parameters must be supplied. Return tables are progressive contracts; prose describes failure and limits.
Implementation: [src/host/cli.rs](../src/host/cli.rs)
For development, keep EN/ZH behavior aligned and compose public libraries first. Add host primitives only at OS or algorithm boundaries and declare their effects. Run marqdo check --narrative-ratio on this file and the real workflows in tests/stdlib_tasks.rs after edits.
## parse
+ `args`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| args | any | None | List of argv tokens; None reads the current host argv |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Parse --key value / --key=value / --flag |
Use `args`=None as the inputs for this operation.
Effects: pure.
Call this function directly:
```sh
marqdo call lib/cli.mq.md parse 'args=["report","--count=3","--quiet"]' --effects none --json
```
Parse --key value / --key=value / --flag. A bare --flag must not be followed by a non-option token if you need it as boolean (put flags last, or use --flag=true). Positionals land under _. Omit args to use process argv.
Caller: [cli.parse]
*> host_cli_parse args=`args`*
Return *[Parse --key value / --key=value / --flag](> host_cli_parse args=`args`)*.
+60 -4
View File
@@ -6,18 +6,74 @@ description: RFC4180-ish CSV parse/stringify (Mid M4). First row = headers → l
CSV parse and stringify. First row is headers; rows become a list of maps.
Parse and serialize header-based CSV records.
Behavior and limits: Parsed cells are text; use table.cast for explicit types. stringify follows the first row field order. Use row records, not a column map.
This single source file is the usage and development manual. Import it directly, or use marqdo call with a function heading below. Parameter tables give types and defaults; required parameters must be supplied. Return tables are progressive contracts; prose describes failure and limits.
Implementation: [src/host/csv.rs](../src/host/csv.rs)
For development, keep EN/ZH behavior aligned and compose public libraries first. Add host primitives only at OS or algorithm boundaries and declare their effects. Run marqdo check --narrative-ratio on this file and the real workflows in tests/stdlib_tasks.rs after edits.
## parse
+ `text`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| text | text | required | Text supplied by the caller |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | list | Parse CSV text into a list of maps |
Use `text` as the inputs for this operation.
Effects: pure.
Parse CSV text into a list of maps.
Caller: [csv.parse] text=`raw`
*> host_csv_parse text=`text`*
Return *[Parse CSV text into a list of maps](> host_csv_parse text=`text`)*.
## stringify
+ `rows`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| rows | list | required | List of row records |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | Serialize a list of maps to CSV text |
Use `rows` as the inputs for this operation.
Effects: pure.
Serialize a list of maps to CSV text.
*> host_csv_stringify rows=`rows`*
Return *[Serialize a list of maps to CSV text](> host_csv_stringify rows=`rows`)*.
## try_parse
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| text | text | required | Text to read, transform or emit as described by this operation |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | map | Return {ok,value,error}; parse failures are recoverable data |
Use `text` as the inputs for this operation.
Effects: pure.
Call this function directly:
```sh
marqdo call lib/csv.mq.md try_parse 'text="name,n"' --effects none --json
```
Return {ok,value,error}; parse failures are recoverable data.
Return *[Return {ok,value,error}; parse failures are recoverable data](> host_try_csv_parse text=`text`)*.
+163 -27
View File
@@ -1,63 +1,199 @@
---
markup: occlusion
title: lib/datetime
description: Calendar moments as maps {unix, zone, iso} (Mid2 M7). Fixed offsets + a few IANA aliases.
description: Calendar moments as maps {unix, zone, iso} (Mid2 M7). Fixed offsets and embedded IANA timezone/DST rules.
---
Calendar moments as maps {unix, zone, iso} (Mid2 M7). Fixed offsets + a few IANA aliases.
Calendar moments as maps {unix, zone, iso} (Mid2 M7). Fixed offsets and embedded IANA timezone/DST rules.
Convert timestamps, IANA zones and local calendar dates.
Behavior and limits: zone remains the numeric offset; timezone preserves the IANA identity. add uses elapsed seconds; add_calendar preserves local wall time. DST gaps fail; folds require an explicit policy.
This single source file is the usage and development manual. Import it directly, or use marqdo call with a function heading below. Parameter tables give types and defaults; required parameters must be supplied. Return tables are progressive contracts; prose describes failure and limits.
Implementation: [src/host/datetime.rs](../src/host/datetime.rs)、[src/host/data_ops.rs](../src/host/data_ops.rs)
For development, keep EN/ZH behavior aligned and compose public libraries first. Add host primitives only at OS or algorithm boundaries and declare their effects. Run marqdo check --narrative-ratio on this file and the real workflows in tests/stdlib_tasks.rs after edits.
## now
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Read the clock and return the current UTC datetime record |
Effects: time.read.
Current UTC moment map.
*> host_datetime_now*
Read the clock and return the current UTC datetime record.
Return *[Read the clock and return the current UTC datetime record](host_datetime_now())*.
## from_unix
+ `unix`
+ `zone`=None
from_unix.
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| unix | number | required | Unix timestamp in seconds |
| zone | any | None | Fixed offset or named timezone accepted by this operation |
*> host_datetime_from_unix unix=`unix` zone=`zone`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Convert Unix seconds to a datetime record in the selected zone; None means UTC |
Use `unix`, `zone`=None as the inputs for this operation.
Effects: pure.
Convert Unix seconds to a datetime record in the selected zone; None means UTC.
Return *[Convert Unix seconds to a datetime record in the selected zone; None means UTC](> host_datetime_from_unix unix=`unix` zone=`zone`)*.
## to_unix
+ `dt`
to_unix.
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| dt | any | required | Datetime record returned by this library, not formatted text |
*> host_datetime_to_unix dt=`dt`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | Read unix seconds from a datetime record; formatting and timezone do not change the instant |
Use `dt` as the inputs for this operation.
Effects: pure.
Read unix seconds from a datetime record; formatting and timezone do not change the instant.
Return *[Read unix seconds from a datetime record; formatting and timezone do not change the instant](> host_datetime_to_unix dt=`dt`)*.
## parse
+ `text`
+ `pattern`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| text | text | required | Text supplied by the caller |
| pattern | any | None | None for default parsing, rfc3339 or a strftime format |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Parse RFC3339 or YYYY-MM-DD with optional time; an explicit pattern uses strftime or rfc3339 |
Use `text`, `pattern`=None as the inputs for this operation.
Effects: pure.
RFC3339 / `YYYY-MM-DD[ HH:MM:SS]` by default; `pattern=` is strftime or `rfc3339`.
*> host_datetime_parse text=`text` pattern=`pattern`*
Parse RFC3339 or YYYY-MM-DD with optional time; an explicit pattern uses strftime or rfc3339.
Return *[Parse RFC3339 or YYYY-MM-DD with optional time; an explicit pattern uses strftime or rfc3339](> host_datetime_parse text=`text` pattern=`pattern`)*.
## format
+ `dt`
+ `style`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| dt | any | required | Datetime record returned by this library, not formatted text |
| style | any | None | Formatting style accepted by the host date formatter |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | Format a datetime record as rfc3339, date, time, or an explicit strftime pattern |
Use `dt`, `style`=None as the inputs for this operation.
Effects: pure.
Styles: `rfc3339` (default), `date`, `time`, or a strftime pattern.
*> host_datetime_format dt=`dt` style=`style`*
Format a datetime record as rfc3339, date, time, or an explicit strftime pattern.
Return *[Format a datetime record as rfc3339, date, time, or an explicit strftime pattern](> host_datetime_format dt=`dt` style=`style`)*.
## add
+ `dt`
+ `days`=None
+ `hours`=None
+ `minutes`=None
+ `seconds`=None
add.
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| dt | any | required | Datetime record returned by this library, not formatted text |
| days | any | None | Number of elapsed 24-hour days to add |
| hours | any | None | Number of elapsed hours to add |
| minutes | any | None | Number of elapsed minutes to add |
| seconds | any | None | Number of elapsed seconds to add |
*> host_datetime_add dt=`dt` days=`days` hours=`hours` minutes=`minutes` seconds=`seconds`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Add elapsed days, hours, minutes and seconds; a day here is exactly 24 hours |
Use `dt`, `days`=None, `hours`=None, `minutes`=None, `seconds`=None as the inputs for this operation.
Effects: pure.
Add elapsed days, hours, minutes and seconds; a day here is exactly 24 hours. Named zones recompute their offset after the move.
Return *[Add elapsed days, hours, minutes and seconds; a day here is exactly 24 hours](> host_datetime_add dt=`dt` days=`days` hours=`hours` minutes=`minutes` seconds=`seconds`)*.
## in_zone
+ `dt`
+ `zone`
Re-express the same instant in `+08:00` / `UTC` / fixed aliases like `Asia/Shanghai`.
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| dt | any | required | Datetime record returned by this library, not formatted text |
| zone | any | required | Fixed offset or named timezone accepted by this operation |
*> host_datetime_in_zone dt=`dt` zone=`zone`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Re-express the same instant in a fixed offset or an IANA zone, retaining its Unix timestamp |
Use `dt`, `zone` as the inputs for this operation.
Effects: pure.
Re-express the same instant in `+08:00` / `UTC` / IANA zones like `Asia/Shanghai`.
Re-express the same instant in a fixed offset or an IANA zone, retaining its Unix timestamp.
Return *[Re-express the same instant in a fixed offset or an IANA zone, retaining its Unix timestamp](> host_datetime_in_zone dt=`dt` zone=`zone`)*.
## parse_local
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| text | text | required | Text to read, transform or emit as described by this operation |
| zone | text | required | Fixed offset or named timezone accepted by this operation |
| ambiguity | text | "reject" | DST fold policy: reject, earliest or latest |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | map | Parse YYYY-MM-DD HH:MM:SS in an IANA timezone as Result |
Use `text`, `zone`, `ambiguity`="reject" as the inputs for this operation.
Effects: pure.
Call this function directly:
```sh
marqdo call lib/datetime.mq.md parse_local 'text="2024-11-03 01:30:00"' 'zone="America/New_York"' 'ambiguity="earliest"' --effects none --json
```
Parse YYYY-MM-DD HH:MM:SS in an IANA timezone as Result. DST gaps fail; folds require reject/earliest/latest.
Return *[Parse YYYY-MM-DD HH:MM:SS in an IANA timezone as Result](> host_datetime_local text=`text` zone=`zone` ambiguity=`ambiguity`)*.
## add_calendar
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| dt | map | required | Datetime record returned by this library, not formatted text |
| days | number | required | Local calendar days to add, preserving wall time across DST |
| ambiguity | text | "reject" | DST fold policy: reject, earliest or latest |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | map | Add local calendar days as Result, preserving wall-clock time across DST |
Use `dt`, `days`, `ambiguity`="reject" as the inputs for this operation.
Effects: pure.
Add local calendar days as Result, preserving wall-clock time across DST. Legacy add uses elapsed duration: one day is 24 hours.
Return *[Add local calendar days as Result, preserving wall-clock time across DST](> host_datetime_calendar_add dt=`dt` days=`days` ambiguity=`ambiguity`)*.
+155
View File
@@ -0,0 +1,155 @@
---
markup: occlusion
---
Inert document operations share the renderer Markdown parser. Every function is pure.
Inspect and transform Markdown without executing its contents.
Behavior and limits: Shares the Markdown parser with rendering and recognizes YAML frontmatter. Spans are original UTF-8 byte offsets. Duplicate section names fail. Replacement preserves surrounding source; persist via fs.write_checked.
This single source file is the usage and development manual. Import it directly, or use marqdo call with a function heading below. Parameter tables give types and defaults; required parameters must be supplied. Return tables are progressive contracts; prose describes failure and limits.
Implementation: [src/host/document.rs](../src/host/document.rs)
For development, keep EN/ZH behavior aligned and compose public libraries first. Add host primitives only at OS or algorithm boundaries and declare their effects. Run marqdo check --narrative-ratio on this file and the real workflows in tests/stdlib_tasks.rs after edits.
## sections
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| text | text | required | Text to read, transform or emit as described by this operation |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | list | List headings with original UTF-8 byte spans and body text; nested sections end at the next same-or-higher heading |
Use `text` as the inputs for this operation.
Effects: pure.
Call this function directly:
```sh
marqdo call lib/document.mq.md sections 'text="# Notes"' --effects none --json
```
List headings with original UTF-8 byte spans and body text; nested sections end at the next same-or-higher heading. No execution.
Return *[List headings with original UTF-8 byte spans and body text; nested sections end at the next same-or-higher heading](> host_document_sections text=`text`)*.
## section
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| text | text | required | Text to read, transform or emit as described by this operation |
| title | text | required | Exact, unique Markdown heading title |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | text | Read the body under one exact heading; missing or duplicate headings fail |
Use `text`, `title` as the inputs for this operation.
Effects: pure.
Read the body under one exact heading; missing or duplicate headings fail.
Return *[Read the body under one exact heading; missing or duplicate headings fail](> host_document_section text=`text` title=`title`)*.
## replace_section
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| text | text | required | Text to read, transform or emit as described by this operation |
| title | text | required | Exact, unique Markdown heading title |
| body | text | required | Request body, or replacement text for document operations |
| expected_sha256 | any | None | Digest of the exact prior text; None disables the check where allowed |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | map | Return Result with replaced section body, preserving its heading and surrounding source |
Use `text`, `title`, `body`, `expected_sha256`=None as the inputs for this operation.
Effects: pure.
Return Result with replaced section body, preserving its heading and surrounding source. Optional digest checks the whole source. Pure transform; persist via fs.write_checked.
Return *[Return Result with replaced section body, preserving its heading and surrounding source](> host_document_replace_section text=`text` title=`title` body=`body` expected_sha256=`expected_sha256`)*.
## tables
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| text | text | required | Text to read, transform or emit as described by this operation |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | list | Extract inert GFM headers and cell text, plus original byte ranges; cells are never evaluated |
Use `text` as the inputs for this operation.
Effects: pure.
Extract inert GFM headers and cell text, plus original byte ranges; cells are never evaluated.
Return *[Extract inert GFM headers and cell text, plus original byte ranges; cells are never evaluated](> host_document_tables text=`text`)*.
## replace_table
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| text | text | required | Text to read, transform or emit as described by this operation |
| index | number | required | Zero-based table index in source order |
| headers | list | required | Ordered list of table header text |
| rows | list | required | List of cell-text lists; each row must match the header width |
| expected_sha256 | any | None | Digest of the exact prior text; None disables the check where allowed |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | map | Replace the zero-based table from text headers and rows, preserving all surrounding source; return Result |
Use `text`, `index`, `headers`, `rows`, `expected_sha256`=None as the inputs for this operation.
Effects: pure.
Replace the zero-based table from text headers and rows, preserving all surrounding source; return Result.
Return *[Replace the zero-based table from text headers and rows, preserving all surrounding source; return Result](> host_document_replace_table text=`text` index=`index` headers=`headers` rows=`rows` expected_sha256=`expected_sha256`)*.
## links
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| text | text | required | Text to read, transform or emit as described by this operation |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | list | List Markdown link labels and targets with byte spans; never follow or execute them |
Use `text` as the inputs for this operation.
Effects: pure.
List Markdown link labels and targets with byte spans; never follow or execute them.
Return *[List Markdown link labels and targets with byte spans; never follow or execute them](> host_document_links text=`text`)*.
## code_blocks
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| text | text | required | Text to read, transform or emit as described by this operation |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | list | List code fence language and literal source with byte spans; never run foreign or Marqdo code |
Use `text` as the inputs for this operation.
Effects: pure.
List code fence language and literal source with byte spans; never run foreign or Marqdo code.
Return *[List code fence language and literal source with byte spans; never run foreign or Marqdo code](> host_document_code_blocks text=`text`)*.
+94 -12
View File
@@ -6,46 +6,128 @@ description: Base64, hex, and base32 encode/decode (Mid M1 + Mid2 M8). UTF-8 tex
Base64, hex, and base32 encode/decode. UTF-8 text round-trip.
Encode and decode UTF-8 text as Base64, hex or Base32.
Behavior and limits: These historical helpers round-trip text. Use bytes.from_base64 for arbitrary binary; decoding invalid UTF-8 as text is an error.
This single source file is the usage and development manual. Import it directly, or use marqdo call with a function heading below. Parameter tables give types and defaults; required parameters must be supplied. Return tables are progressive contracts; prose describes failure and limits.
Implementation: [src/host/encoding.rs](../src/host/encoding.rs)
For development, keep EN/ZH behavior aligned and compose public libraries first. Add host primitives only at OS or algorithm boundaries and declare their effects. Run marqdo check --narrative-ratio on this file and the real workflows in tests/stdlib_tasks.rs after edits.
## base64_encode
+ `text`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| text | text | required | Text supplied by the caller |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | Base64-encode text |
Use `text` as the inputs for this operation.
Effects: pure.
Call this function directly:
```sh
marqdo call lib/encoding.mq.md base64_encode 'text="Marqdo"' --effects none --json
```
Base64-encode text.
Caller: [encoding.base64_encode] text=`s`
*> host_encoding_base64_encode text=`text`*
Return *[Base64-encode text](> host_encoding_base64_encode text=`text`)*.
## base64_decode
+ `text`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| text | text | required | Text supplied by the caller |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | Base64-decode text |
Use `text` as the inputs for this operation.
Effects: pure.
Base64-decode text.
*> host_encoding_base64_decode text=`text`*
Return *[Base64-decode text](> host_encoding_base64_decode text=`text`)*.
## hex_encode
+ `text`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| text | text | required | Text supplied by the caller |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | Hex-encode text |
Use `text` as the inputs for this operation.
Effects: pure.
Hex-encode text.
*> host_encoding_hex_encode text=`text`*
Return *[Hex-encode text](> host_encoding_hex_encode text=`text`)*.
## hex_decode
+ `text`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| text | text | required | Text supplied by the caller |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | Hex-decode text |
Use `text` as the inputs for this operation.
Effects: pure.
Hex-decode text.
*> host_encoding_hex_decode text=`text`*
Return *[Hex-decode text](> host_encoding_hex_decode text=`text`)*.
## base32_encode
+ `text`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| text | text | required | Text supplied by the caller |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | Base32-encode text (RFC 4648 alphabet; padding with =) |
Use `text` as the inputs for this operation.
Effects: pure.
Base32-encode text (RFC 4648 alphabet; padding with =).
*> host_encoding_base32_encode text=`text`*
Return *[Base32-encode text (RFC 4648 alphabet; padding with =)](> host_encoding_base32_encode text=`text`)*.
## base32_decode
+ `text`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| text | text | required | Text supplied by the caller |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | Base32-decode text |
Use `text` as the inputs for this operation.
Effects: pure.
Base32-decode text.
*> host_encoding_base32_decode text=`text`*
Return *[Base32-decode text](> host_encoding_base32_decode text=`text`)*.
+373 -117
View File
@@ -8,59 +8,113 @@ import:
Run bound code fences and inline sources via local interpreters.
Bridge explicit values to external language processes and sessions.
Behavior and limits: Configured languages are not proof that interpreters are installed. invoke exposes exit/timeout/output limits. External execution requires process.exec; close owned persistent sessions.
This single source file is the usage and development manual. Import it directly, or use marqdo call with a function heading below. Parameter tables give types and defaults; required parameters must be supplied. Return tables are progressive contracts; prose describes failure and limits.
Implementation: [src/host/foreign.rs](../src/host/foreign.rs)
For development, keep EN/ZH behavior aligned and compose public libraries first. Add host primitives only at OS or algorithm boundaries and declare their effects. Run marqdo check --narrative-ratio on this file and the real workflows in tests/stdlib_tasks.rs after edits.
## set_cmd
+ `lang`
+ `cmd`
+ `args`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| lang | text | required | Registered interpreter language identifier, such as python |
| cmd | any | required | Executable command or interpreter override |
| args | any | None | Argument list passed to the called command or function |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Bind interpreter command cmd for language lang; optional extra argv |
Use `lang`, `cmd`, `args`=None as the inputs for this operation.
Effects: pure.
Bind interpreter command cmd for language lang; optional extra argv.
*> host_foreign_set_cmd lang=`lang` cmd=`cmd` args=`args`*
Return *[Bind interpreter command cmd for language lang; optional extra argv](> host_foreign_set_cmd lang=`lang` cmd=`cmd` args=`args`)*.
## run
+ `code`
+ `stdin`=None
+ `env`=None
+ `cwd`=None
+ `timeout`=None
+ `args`=None
+ `max_output`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| code | any | required | Bound code-fence value; supply lang and source for inline text |
| stdin | any | None | Text written to the child process standard input |
| env | any | None | Environment variable/value record for the child process |
| cwd | any | None | Child process working directory |
| timeout | any | None | Execution timeout in seconds; None uses the host default |
| args | any | None | Argument list passed to the called command or function |
| max_output | any | None | Maximum captured output bytes; None uses the host default |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Run a bound code fence value; optional stdin, env map, cwd, timeout (seconds), extra argv and output cap |
Use `code`, `stdin`=None, `env`=None, `cwd`=None, `timeout`=None, `args`=None, `max_output`=None as the inputs for this operation.
Effects: process.exec.
Run a bound code fence value; optional stdin, env map, cwd, timeout (seconds),
extra argv and output cap. Returns stdout text; non-zero exit is an error.
Caller: [foreign.run] code=`block`
*> host_foreign_run code=`code` stdin=`stdin` env=`env` cwd=`cwd` timeout=`timeout` args=`args` max_output=`max_output`*
Return *[Run a bound code fence value; optional stdin, env map, cwd, timeout (seconds), extra argv and output cap](> host_foreign_run code=`code` stdin=`stdin` env=`env` cwd=`cwd` timeout=`timeout` args=`args` max_output=`max_output`)*.
## run_lang
+ `lang`
+ `source`
+ `stdin`=None
+ `env`=None
+ `cwd`=None
+ `timeout`=None
+ `args`=None
+ `max_output`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| lang | text | required | Registered interpreter language identifier, such as python |
| source | any | required | Source text to run with the selected interpreter |
| stdin | any | None | Text written to the child process standard input |
| env | any | None | Environment variable/value record for the child process |
| cwd | any | None | Child process working directory |
| timeout | any | None | Execution timeout in seconds; None uses the host default |
| args | any | None | Argument list passed to the called command or function |
| max_output | any | None | Maximum captured output bytes; None uses the host default |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Run source text with language lang; same options as run |
Use `lang`, `source`, `stdin`=None, `env`=None, `cwd`=None, `timeout`=None, `args`=None, `max_output`=None as the inputs for this operation.
Effects: process.exec.
Run source text with language lang; same options as run.
*> host_foreign_run_lang lang=`lang` source=`source` stdin=`stdin` env=`env` cwd=`cwd` timeout=`timeout` args=`args` max_output=`max_output`*
Return *[Run source text with language lang; same options as run](> host_foreign_run_lang lang=`lang` source=`source` stdin=`stdin` env=`env` cwd=`cwd` timeout=`timeout` args=`args` max_output=`max_output`)*.
## invoke
+ `code`=None
+ `lang`=None
+ `source`=None
+ `stdin`=None
+ `input`=None
+ `env`=None
+ `cwd`=None
+ `timeout`=None
+ `args`=None
+ `output`=auto
+ `max_output`=None
+ `cmd`=None
+ `keep`=False
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| code | any | None | Bound code-fence value; supply lang and source for inline text |
| lang | any | None | Registered interpreter language identifier, such as python |
| source | any | None | Source text to run with the selected interpreter |
| stdin | any | None | Text written to the child process standard input |
| input | any | None | Structured value JSON-encoded on stdin; cannot combine with stdin |
| env | any | None | Environment variable/value record for the child process |
| cwd | any | None | Child process working directory |
| timeout | any | None | Execution timeout in seconds; None uses the host default |
| args | any | None | Argument list passed to the called command or function |
| output | any | "auto" | Result decoding mode: auto, text, json or lines |
| max_output | any | None | Maximum captured output bytes; None uses the host default |
| cmd | any | None | Executable command or interpreter override |
| keep | any | False | Whether to retain the generated script for inspection |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Run code or lang+source and return a record map instead of raising on process failure |
Use `code`=None, `lang`=None, `source`=None, `stdin`=None, `input`=None, `env`=None, `cwd`=None, `timeout`=None, `args`=None, `output`="auto", `max_output`=None, `cmd`=None, `keep`=False as the inputs for this operation.
Effects: process.exec.
Run code or lang+source and return a record map instead of raising on process
failure. Fields: ok, code, stdout, stderr, ms, lang, cmd, timed_out, truncated,
@@ -69,200 +123,402 @@ result, result_error, error, script, cached.
`input` is encoded as JSON on stdin (mutually exclusive with `stdin`). `output`
is auto | text | json | lines. `cmd` overrides the interpreter for this call.
*> host_foreign_invoke code=`code` lang=`lang` source=`source` stdin=`stdin` input=`input` env=`env` cwd=`cwd` timeout=`timeout` args=`args` output=`output` max_output=`max_output` cmd=`cmd` keep=`keep`*
Return *[Run code or lang+source and return a record map instead of raising on process failure](> host_foreign_invoke code=`code` lang=`lang` source=`source` stdin=`stdin` input=`input` env=`env` cwd=`cwd` timeout=`timeout` args=`args` output=`output` max_output=`max_output` cmd=`cmd` keep=`keep`)*.
## probe
+ `lang`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| lang | any | None | Registered interpreter language identifier, such as python |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Probe one language, or every known language when lang is omitted |
Use `lang`=None as the inputs for this operation.
Effects: process.exec.
Probe one language, or every known language when lang is omitted. Returns
{lang, cmd, path, ok, version, error} (a list when lang is omitted).
*> host_foreign_probe lang=`lang`*
Return *[Probe one language, or every known language when lang is omitted](> host_foreign_probe lang=`lang`)*.
## register
+ `lang`
+ `cmd`=None
+ `args`=None
+ `template`=None
+ `ext`=None
+ `env`=None
+ `version_args`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| lang | text | required | Registered interpreter language identifier, such as python |
| cmd | any | None | Executable command or interpreter override |
| args | any | None | Argument list passed to the called command or function |
| template | any | None | Interpreter launch template |
| ext | any | None | Temporary script filename extension |
| env | any | None | Environment variable/value record for the child process |
| version_args | any | None | Arguments used to query the interpreter version |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Register a language invocation |
Use `lang`, `cmd`=None, `args`=None, `template`=None, `ext`=None, `env`=None, `version_args`=None as the inputs for this operation.
Effects: pure.
Register a language invocation. Provide cmd (+args) or template (placeholders
{file}, {dir}, {base}, {inline}, {lang}, {cwd}); they are mutually exclusive.
*> host_foreign_register lang=`lang` cmd=`cmd` args=`args` template=`template` ext=`ext` env=`env` version_args=`version_args`*
Return *[Register a language invocation](> host_foreign_register lang=`lang` cmd=`cmd` args=`args` template=`template` ext=`ext` env=`env` version_args=`version_args`)*.
## unset
+ `lang`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| lang | text | required | Registered interpreter language identifier, such as python |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Remove a process-local registration |
Use `lang` as the inputs for this operation.
Effects: pure.
Remove a process-local registration. Presets/config/env still apply.
*> host_foreign_unset lang=`lang`*
Return *[Remove a process-local registration](> host_foreign_unset lang=`lang`)*.
## load_config
+ `path`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| path | any | None | Path relative to the granted filesystem root |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Load .marqdo/foreign.toml (or an explicit path); returns the number of language tables read |
Use `path`=None as the inputs for this operation.
Effects: fs.read.
Load .marqdo/foreign.toml (or an explicit path); returns the number of language
tables read.
*> host_foreign_load_config path=`path`*
Return *[Load .marqdo/foreign.toml (or an explicit path); returns the number of language tables read](> host_foreign_load_config path=`path`)*.
## call
+ `code`=None
+ `lang`=None
+ `source`=None
+ `input`=None
+ `stdin`=None
+ `env`=None
+ `cwd`=None
+ `timeout`=None
+ `args`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| code | any | None | Bound code-fence value; supply lang and source for inline text |
| lang | any | None | Registered interpreter language identifier, such as python |
| source | any | None | Source text to run with the selected interpreter |
| input | any | None | Structured value JSON-encoded on stdin; cannot combine with stdin |
| stdin | any | None | Text written to the child process standard input |
| env | any | None | Environment variable/value record for the child process |
| cwd | any | None | Child process working directory |
| timeout | any | None | Execution timeout in seconds; None uses the host default |
| args | any | None | Argument list passed to the called command or function |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | JSON-in / JSON-out call: encode `input` on stdin, parse stdout JSON and return the value (empty stdout -> None) |
Use `code`=None, `lang`=None, `source`=None, `input`=None, `stdin`=None, `env`=None, `cwd`=None, `timeout`=None, `args`=None as the inputs for this operation.
Effects: process.exec.
JSON-in / JSON-out call: encode `input` on stdin, parse stdout JSON and return
the value (empty stdout -> None). Raises on process failure or invalid JSON.
*> host_foreign_call code=`code` lang=`lang` source=`source` input=`input` stdin=`stdin` env=`env` cwd=`cwd` timeout=`timeout` args=`args`*
Return *[JSON-in / JSON-out call: encode input on stdin, parse stdout JSON and return the value (empty stdout -> None)](> host_foreign_call code=`code` lang=`lang` source=`source` input=`input` stdin=`stdin` env=`env` cwd=`cwd` timeout=`timeout` args=`args`)*.
## run_many
+ `runs`
+ `concurrency`=4
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| runs | any | required | Ordered per-run code or language/source records |
| concurrency | any | 4 | Maximum number of concurrent operations |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Run a list of code values or invoke-option maps in parallel; returns records in input order |
Use `runs`, `concurrency`=4 as the inputs for this operation.
Effects: process.exec.
Run a list of code values or invoke-option maps in parallel; returns records in
input order. One failing item does not stop the others.
*> host_foreign_run_many runs=`runs` concurrency=`concurrency`*
Return *[Run a list of code values or invoke-option maps in parallel; returns records in input order](> host_foreign_run_many runs=`runs` concurrency=`concurrency`)*.
## call_many
+ `inputs`
+ `code`=None
+ `lang`=None
+ `source`=None
+ `cmd`=None
+ `env`=None
+ `cwd`=None
+ `timeout`=None
+ `args`=None
+ `max_output`=None
+ `concurrency`=4
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| inputs | any | required | Input values for the batched calls |
| code | any | None | Bound code-fence value; supply lang and source for inline text |
| lang | any | None | Registered interpreter language identifier, such as python |
| source | any | None | Source text to run with the selected interpreter |
| cmd | any | None | Executable command or interpreter override |
| env | any | None | Environment variable/value record for the child process |
| cwd | any | None | Child process working directory |
| timeout | any | None | Execution timeout in seconds; None uses the host default |
| args | any | None | Argument list passed to the called command or function |
| max_output | any | None | Maximum captured output bytes; None uses the host default |
| concurrency | any | 4 | Maximum number of concurrent operations |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Apply one code/function to each input in parallel; returns parsed JSON results in input order |
Use `inputs`, `code`=None, `lang`=None, `source`=None, `cmd`=None, `env`=None, `cwd`=None, `timeout`=None, `args`=None, `max_output`=None, `concurrency`=4 as the inputs for this operation.
Effects: process.exec.
Apply one code/function to each input in parallel; returns parsed JSON results
in input order. Raises with the failing index after all workers finish.
*> host_foreign_call_many inputs=`inputs` code=`code` lang=`lang` source=`source` cmd=`cmd` env=`env` cwd=`cwd` timeout=`timeout` args=`args` max_output=`max_output` concurrency=`concurrency`*
Return *[Apply one code/function to each input in parallel; returns parsed JSON results in input order](> host_foreign_call_many inputs=`inputs` code=`code` lang=`lang` source=`source` cmd=`cmd` env=`env` cwd=`cwd` timeout=`timeout` args=`args` max_output=`max_output` concurrency=`concurrency`)*.
## session
+ `kernels`=None
+ `cells`=None
+ `values`=None
+ `inputs`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| kernels | any | None | Kernel/session specifications for persistent interpreters |
| cells | any | None | Code cells to evaluate in a persistent interpreter |
| values | any | None | Variable/value record to inject into a session |
| inputs | any | None | Input values for the batched calls |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Declare a document view session |
Use `kernels`=None, `cells`=None, `values`=None, `inputs`=None as the inputs for this operation.
Effects: pure.
Declare a document view session. `kernels` and `cells` are ordinary tables:
kernels are `|名称|语言|命令|` (ZH or EN), cells are `|单元|内核|`.
Returns a foreign session handle consumed by `view`; without this handle the
view has no persistent kernel state.
**p = > table.empty_map**
**p = > table.put in=`p` at="kind" value="foreign-session"**
**p = > table.put in=`p` at="kernels" value=`kernels`**
**p = > table.put in=`p` at="cells" value=`cells`**
**p = > table.put in=`p` at="values" value=`values`**
**p = > table.put in=`p` at="inputs" value=`inputs`**
*p*
We retain **`p` = [Empty map](table.empty_map())**.
We retain **`p` = [Set the kind field in the new record](table.put(in=`p`, at="kind", value="foreign-session"))**.
We retain **`p` = [Set the kernels field in the new record](table.put(in=`p`, at="kernels", value=`kernels`))**.
We retain **`p` = [Set the cells field in the new record](table.put(in=`p`, at="cells", value=`cells`))**.
We retain **`p` = [Set the values field in the new record](table.put(in=`p`, at="values", value=`values`))**.
We retain **`p` = [Set the inputs field in the new record](table.put(in=`p`, at="inputs", value=`inputs`))**.
Return *p*.
## session_open
+ `lang`
+ `cmd`=None
+ `env`=None
+ `cwd`=None
+ `timeout`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| lang | text | required | Registered interpreter language identifier, such as python |
| cmd | any | None | Executable command or interpreter override |
| env | any | None | Environment variable/value record for the child process |
| cwd | any | None | Child process working directory |
| timeout | any | None | Execution timeout in seconds; None uses the host default |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Start a persistent Python/Node kernel; returns an opaque `handle` value |
Use `lang`, `cmd`=None, `env`=None, `cwd`=None, `timeout`=None as the inputs for this operation.
Effects: process.exec.
Start a persistent Python/Node kernel; returns an opaque `handle` value.
Text fabrications are refused by session ops; handles cannot cross the JSON
bridge. `timeout` is the default per-eval timeout.
*> host_foreign_session_open lang=`lang` cmd=`cmd` env=`env` cwd=`cwd` timeout=`timeout`*
Return *[Start a persistent Python/Node kernel; returns an opaque handle value](> host_foreign_session_open lang=`lang` cmd=`cmd` env=`env` cwd=`cwd` timeout=`timeout`)*.
## session_eval
+ `id`
+ `code`=None
+ `source`=None
+ `input`=None
+ `stdin`=None
+ `timeout`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| id | any | required | Identifier returned by the corresponding create/spawn operation |
| code | any | None | Bound code-fence value; supply lang and source for inline text |
| source | any | None | Source text to run with the selected interpreter |
| input | any | None | Structured value JSON-encoded on stdin; cannot combine with stdin |
| stdin | any | None | Text written to the child process standard input |
| timeout | any | None | Execution timeout in seconds; None uses the host default |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Evaluate code (a code value) or source text in session id; returns a record with id/alive |
Use `id`, `code`=None, `source`=None, `input`=None, `stdin`=None, `timeout`=None as the inputs for this operation.
Effects: process.exec.
Evaluate code (a code value) or source text in session id; returns a record
with id/alive. `input` is JSON-encoded for the kernel; `stdin` is raw program
stdin for this evaluation.
*> host_foreign_session_eval id=`id` code=`code` source=`source` input=`input` stdin=`stdin` timeout=`timeout`*
Return *[Evaluate code (a code value) or source text in session id; returns a record with id/alive](> host_foreign_session_eval id=`id` code=`code` source=`source` input=`input` stdin=`stdin` timeout=`timeout`)*.
## session_set
+ `id`
+ `name`
+ `value`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| id | any | required | Identifier returned by the corresponding create/spawn operation |
| name | text | required | Name to resolve, register or look up |
| value | any | required | Value to transform or store, without mutating the input |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Set one kernel variable from a Marqdo value (JSON copy) |
Use `id`, `name`, `value` as the inputs for this operation.
Effects: process.exec.
Set one kernel variable from a Marqdo value (JSON copy).
*> host_foreign_session_set id=`id` name=`name` value=`value`*
Return *[Set one kernel variable from a Marqdo value (JSON copy)](> host_foreign_session_set id=`id` name=`name` value=`value`)*.
## session_get
+ `id`
+ `name`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| id | any | required | Identifier returned by the corresponding create/spawn operation |
| name | text | required | Name to resolve, register or look up |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Read one kernel variable as a Marqdo value |
Use `id`, `name` as the inputs for this operation.
Effects: process.exec.
Read one kernel variable as a Marqdo value.
*> host_foreign_session_get id=`id` name=`name`*
Return *[Read one kernel variable as a Marqdo value](> host_foreign_session_get id=`id` name=`name`)*.
## session_names
+ `id`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| id | any | required | Identifier returned by the corresponding create/spawn operation |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | List kernel variable names |
Use `id` as the inputs for this operation.
Effects: process.exec.
List kernel variable names.
*> host_foreign_session_names id=`id`*
Return *[List kernel variable names](> host_foreign_session_names id=`id`)*.
## session_close
+ `id`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| id | any | required | Identifier returned by the corresponding create/spawn operation |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Consume (affine close) a live session handle: kill and remove it |
Use `id` as the inputs for this operation.
Effects: process.exec.
Consume (affine close) a live session handle: kill and remove it. Returns
`True` on success. Closing an unknown or already-closed id is a fault
(`foreign session … not found`), matching use-after-close on eval/set/get.
*> host_foreign_session_close id=`id`*
Return *[Consume (affine close) a live session handle: kill and remove it](> host_foreign_session_close id=`id`)*.
## session_interrupt
+ `id`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| id | any | required | Identifier returned by the corresponding create/spawn operation |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Interrupt the current evaluation of a persistent kernel |
Use `id` as the inputs for this operation.
Effects: process.exec.
Interrupt the current evaluation of a persistent kernel. The session remains
usable for the next evaluation when the worker supports interruption.
*> host_foreign_session_interrupt id=`id`*
Return *[Interrupt the current evaluation of a persistent kernel](> host_foreign_session_interrupt id=`id`)*.
## session_list
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | List live sessions with id/lang/cmd/evals/alive/started_ms |
Effects: process.exec.
List live sessions with id/lang/cmd/evals/alive/started_ms.
*> host_foreign_session_list*
Return *[List live sessions with id/lang/cmd/evals/alive/started_ms](host_foreign_session_list())*.
## langs
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | List configured foreign languages |
Effects: pure.
Call this function directly:
```sh
marqdo call lib/foreign.mq.md langs --effects none --json
```
List configured foreign languages.
*> host_foreign_langs*
Return configured language definitions without launching interpreters. Use probe separately to check executable availability.
Return *[List configured foreign languages](host_foreign_langs())*.
## oracle_journal
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Return this document evaluation's admitted eval/get/decode observations as ordinary records with index, channel, value |
Effects: pure.
Return this document evaluation's admitted eval/get/decode observations as
ordinary records with index, channel, value. Opening, setting and closing do
not append observations.
*> host_oracle_journal *
Return *[Return this document evaluation's admitted eval/get/decode observations as ordinary records with index, channel, value](> host_oracle_journal )*.
## replay_check
+ `expected`
+ `observed`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| expected | any | required | Expected observation record used for replay comparison |
| observed | any | required | Actual observation record used for replay comparison |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Compare two oracle journals without executing foreign code |
Use `expected`, `observed` as the inputs for this operation.
Effects: pure.
Compare two oracle journals without executing foreign code. Returns ok and
the least mismatching index, with the expected and observed records.
*> host_oracle_replay_check expected=`expected` observed=`observed`*
Return *[Compare two oracle journals without executing foreign code](> host_oracle_replay_check expected=`expected` observed=`observed`)*.
+685 -41
View File
@@ -1,129 +1,773 @@
---
markup: occlusion
import:
json: lib/json.mq.md
csv: lib/csv.mq.md
title: lib/fs
description: English filesystem wrappers
---
English filesystem wrappers
Read, write, find and organize files under an explicit root.
Behavior and limits: Legacy remove recursively deletes directories. Prefer remove_file/remove_empty_dir. Atomic operations replace one file; directory batches are not transactions. Native-only operations state their CoW boundary.
This single source file is the usage and development manual. Import it directly, or use marqdo call with a function heading below. Parameter tables give types and defaults; required parameters must be supplied. Return tables are progressive contracts; prose describes failure and limits.
Relative IO paths use --fs-root, or the called file directory when omitted. Writes require explicit fs.write grants, subprocesses require process.exec, and pure transforms require no IO grant.
Implementation: [src/host/fs.rs](../src/host/fs.rs)、[src/host/fs_ops.rs](../src/host/fs_ops.rs)、[src/host/sandbox_fs.rs](../src/host/sandbox_fs.rs)
For development, keep EN/ZH behavior aligned and compose public libraries first. Add host primitives only at OS or algorithm boundaries and declare their effects. Run marqdo check --narrative-ratio on this file and the real workflows in tests/stdlib_tasks.rs after edits.
## read_text
+ `path`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| path | text | required | Path relative to the granted filesystem root |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | Read UTF-8 text from path |
Use `path` as the inputs for this operation.
Effects: fs.read.
Read UTF-8 text from path.
*> host_read_text path=`path`*
Return *[Read UTF-8 text from path](> host_read_text path=`path`)*.
## write_text
+ `path`
+ `text`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| path | text | required | Path relative to the granted filesystem root |
| text | text | required | Text supplied by the caller |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | None after completion; filesystem failures produce a diagnostic |
Use `path`, `text` as the inputs for this operation.
Effects: fs.write.
Write text to path (overwrite).
*> host_write_text path=`path` text=`text`*
Return *[Write text to path (overwrite)](> host_write_text path=`path` text=`text`)*.
## append_text
+ `path`
+ `text`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| path | text | required | Path relative to the granted filesystem root |
| text | text | required | Text supplied by the caller |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | None after completion; filesystem failures produce a diagnostic |
Use `path`, `text` as the inputs for this operation.
Effects: fs.write.
Append text to path.
*> host_append_text path=`path` text=`text`*
Return *[Append text to path](> host_append_text path=`path` text=`text`)*.
## exists
+ `path`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| path | text | required | Path relative to the granted filesystem root |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | bool | Whether path exists |
Use `path` as the inputs for this operation.
Effects: fs.read.
Whether path exists.
*> host_exists path=`path`*
Return *[Whether path exists](> host_exists path=`path`)*.
## list_dir
+ `path`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| path | text | required | Path relative to the granted filesystem root |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | list | List directory entries at path |
Use `path` as the inputs for this operation.
Effects: fs.read.
List directory entries at path.
*> host_list_dir path=`path`*
Return *[List directory entries at path](> host_list_dir path=`path`)*.
## make_dir
+ `path`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| path | text | required | Path relative to the granted filesystem root |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | None after completion; filesystem failures produce a diagnostic |
Use `path` as the inputs for this operation.
Effects: fs.write.
Create directory at path.
*> host_make_dir path=`path`*
Return *[Create directory at path](> host_make_dir path=`path`)*.
## make_dirs
+ `path`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| path | text | required | Path relative to the granted filesystem root |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | None after completion; filesystem failures produce a diagnostic |
Use `path` as the inputs for this operation.
Effects: fs.write.
Create directories recursively (`mkdir -p`).
*> host_make_dirs path=`path`*
Return *[Create directories recursively (mkdir -p)](> host_make_dirs path=`path`)*.
## remove
+ `path`
Remove file or empty directory at path.
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| path | text | required | Path relative to the granted filesystem root |
*> host_remove path=`path`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | None after completion; filesystem failures produce a diagnostic |
Use `path` as the inputs for this operation.
Effects: fs.write.
Remove a file or recursively remove a directory. Legacy behavior; use remove_file or remove_empty_dir for narrow deletion.
Remove a file or recursively remove a directory. For narrow deletion use remove_file or remove_empty_dir.
Return *[Remove a file or recursively remove a directory](> host_remove path=`path`)*.
## remove_tree
+ `path`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| path | text | required | Path relative to the granted filesystem root |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | None after completion; filesystem failures produce a diagnostic |
Use `path` as the inputs for this operation.
Effects: fs.write.
Remove a directory recursively. Errors if `path` is a file.
*> host_remove_tree path=`path`*
Return *[Remove a directory recursively](> host_remove_tree path=`path`)*.
## stat
+ `path`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| path | text | required | Path relative to the granted filesystem root |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Returns `{size, mtime_unix, is_file, is_dir}` |
Use `path` as the inputs for this operation.
Effects: fs.read.
Returns `{size, mtime_unix, is_file, is_dir}`.
*> host_stat path=`path`*
Return *[Returns {size, mtime_unix, is_file, is_dir}](> host_stat path=`path`)*.
## walk
+ `path`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| path | text | required | Path relative to the granted filesystem root |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | list | Depth-first listing of relative paths under `path` (forward slashes) |
Use `path` as the inputs for this operation.
Effects: fs.read.
Depth-first listing of relative paths under `path` (forward slashes).
*> host_walk path=`path`*
Return *[Depth-first listing of relative paths under path (forward slashes)](> host_walk path=`path`)*.
## copy_file
+ `src`
+ `dest`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| src | text | required | Source path under the granted root |
| dest | text | required | Destination path under the granted root |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | None after completion; filesystem failures produce a diagnostic |
Use `src`, `dest` as the inputs for this operation.
Effects: fs.write.
Copy a file (overwrites `dest` if it exists). Paths are sandboxed like other fs ops.
*> host_copy_file src=`src` dest=`dest`*
Return *[Copy a file (overwrites dest if it exists)](> host_copy_file src=`src` dest=`dest`)*.
## move
+ `src`
+ `dest`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| src | text | required | Source path under the granted root |
| dest | text | required | Destination path under the granted root |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | None after completion; filesystem failures produce a diagnostic |
Use `src`, `dest` as the inputs for this operation.
Effects: fs.write.
Rename / move within the sandbox.
*> host_move src=`src` dest=`dest`*
Return *[Rename / move within the sandbox](> host_move src=`src` dest=`dest`)*.
## make_temp
+ `prefix`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| prefix | any | None | Prefix added to the generated name or tested against text |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | Create an empty temp file under the program directory; return its relative path |
Use `prefix`=None as the inputs for this operation.
Effects: fs.write.
Create an empty temp file under the program directory; return its relative path.
*> host_make_temp prefix=`prefix`*
Return *[Create an empty temp file under the program directory; return its relative path](> host_make_temp prefix=`prefix`)*.
## text_patch
+ `path`
+ `find`
+ `replace`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| path | text | required | Path relative to the granted filesystem root |
| find | any | required | Exact text to locate before replacement |
| replace | any | required | Replacement text for each exact match |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Exact FIND→REPLACE once in a UTF-8 text file |
Use `path`, `find`, `replace` as the inputs for this operation.
Effects: fs.write.
Exact FIND→REPLACE once in a UTF-8 text file. `find` must match exactly once.
*> host_text_patch path=`path` find=`find` replace=`replace`*
Return *[Exact FIND→REPLACE once in a UTF-8 text file](> host_text_patch path=`path` find=`find` replace=`replace`)*.
## apply_patch_blocks
+ `path`
+ `text`
+ `soft`=False
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| path | text | required | Path relative to the granted filesystem root |
| text | text | required | Text supplied by the caller |
| soft | bool | False | Whether a missing patch match becomes a recoverable outcome |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Apply plan-style triple-angle FIND/REPLACE blocks from `text` to `path` |
Use `path`, `text`, `soft`=False as the inputs for this operation.
Effects: fs.write.
Apply plan-style triple-angle FIND/REPLACE blocks from `text` to `path`.
Also accepts fenced find/replace pairs and minimal Begin Patch hunks.
When `soft=True`, only “FIND not found” returns `0` (run continues). Empty FIND, multi-match, parse errors, and whole-file FIND still abort — whole-file rewrite is forbidden.
*> host_apply_patch_blocks path=`path` text=`text` soft=`soft`*
Return *[Apply plan-style triple-angle FIND/REPLACE blocks from text to path](> host_apply_patch_blocks path=`path` text=`text` soft=`soft`)*.
## try_read_text
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| path | text | required | Path within the granted filesystem root |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | map | Read text as {ok,value,error}; file and permission failures are data |
Use `path` as the inputs for this operation.
Effects: fs.read.
Call this function directly:
```sh
marqdo call lib/fs.mq.md try_read_text 'path="lib/fs.mq.md"' --effects fs.read --fs-root . --json
```
Read at most 8 MiB of UTF-8 text as {ok,value,error}; file, encoding and permission failures are data. The function still requires fs.read.
Return *[Read at most 8 MiB of UTF-8 text as {ok,value,error}; file, encoding and permission failures are data](> host_fs_try_read_text path=`path`)*.
## try_write_text
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| path | text | required | Path within the granted filesystem root |
| text | text | required | Text to read, transform or emit as described by this operation |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | map | Overwrite UTF-8 text and return {ok,value,error}; requires fs |
Use `path`, `text` as the inputs for this operation.
Effects: fs.write.
Overwrite UTF-8 text and return {ok,value,error}; requires fs.write.
Return *[Overwrite UTF-8 text and return {ok,value,error}; requires fs.write](> host_fs_try_write_text path=`path` text=`text`)*.
## read_bytes
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| path | text | required | Path within the granted filesystem root |
| max_bytes | number | 8388608 | Maximum bytes read or expanded; exceeding it fails |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | map | Read binary data as a bytes record |
Use `path`, `max_bytes`=8388608 as the inputs for this operation.
Effects: fs.read.
Read binary data as a bytes record. Default limit is 8 MiB, maximum is 64 MiB; decoding is explicit via lib/bytes.
Return *[Read binary data as a bytes record](> host_fs_read_bytes path=`path` max_bytes=`max_bytes`)*.
## write_bytes
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| path | text | required | Path within the granted filesystem root |
| data | map | required | Portable bytes record containing _type=bytes and base64 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | None after completion; filesystem failures produce a diagnostic |
Use `path`, `data` as the inputs for this operation.
Effects: fs.write.
Atomically replace a file with bytes; no UTF-8 conversion. Requires fs.write.
Return *[Atomically replace a file with bytes; no UTF-8 conversion](> host_fs_write_bytes path=`path` data=`data`)*.
## read_chunk
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| path | text | required | Path within the granted filesystem root |
| offset | number | 0 | Zero-based byte offset of the next chunk |
| size | number | 65536 | Number of bytes to read in this chunk |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | map | Read at most size bytes from offset, returning data/next_offset/eof |
Use `path`, `offset`=0, `size`=65536 as the inputs for this operation.
Effects: fs.read.
Read at most size bytes from offset, returning data/next_offset/eof. Offsets are zero-based bytes; each call closes the file, so no handles escape sessions.
Return *[Read at most size bytes from offset, returning data/next_offset/eof](> host_fs_read_chunk path=`path` offset=`offset` size=`size`)*.
## append_bytes
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| path | text | required | Path within the granted filesystem root |
| data | map | required | Portable bytes record containing _type=bytes and base64 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | None after completion; filesystem failures produce a diagnostic |
Use `path`, `data` as the inputs for this operation.
Effects: fs.write.
Append bytes, creating a file if absent; parent directory must exist.
Return *[Append bytes, creating a file if absent; parent directory must exist](> host_fs_append_bytes path=`path` data=`data`)*.
## atomic_write
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| path | text | required | Path within the granted filesystem root |
| text | text | required | Text to read, transform or emit as described by this operation |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | None after completion; filesystem failures produce a diagnostic |
Use `path`, `text` as the inputs for this operation.
Effects: fs.write.
Replace text through a reserved sibling temporary file and rename; failures remove that temp file. This is one-file replacement, not a multi-file transaction.
Return *[Replace text through a reserved sibling temporary file and rename; failures remove that temp file](> host_fs_atomic_write path=`path` text=`text`)*.
## write_changed
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| path | text | required | Path within the granted filesystem root |
| text | text | required | Text to read, transform or emit as described by this operation |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | bool | Write atomically only when content differs; return whether it was written |
Use `path`, `text` as the inputs for this operation.
Effects: fs.write.
Write atomically only when content differs; return whether it was written.
Return *[Write atomically only when content differs; return whether it was written](> host_fs_write_changed path=`path` text=`text`)*.
## write_checked
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| path | text | required | Path within the granted filesystem root |
| text | text | required | Text to read, transform or emit as described by this operation |
| expected_sha256 | text | required | Digest of the exact prior text; None disables the check where allowed |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | map | Check current SHA-256 before atomic replacement, returning Result |
Use `path`, `text`, `expected_sha256` as the inputs for this operation.
Effects: fs.write.
Check current SHA-256 before atomic replacement, returning Result. Detects stale content; concurrent writers still need external coordination.
Return *[Check current SHA-256 before atomic replacement, returning Result](> host_fs_write_checked path=`path` text=`text` expected_sha256=`expected_sha256`)*.
## read_lines
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| path | text | required | Path within the granted filesystem root |
| max_bytes | number | 8388608 | Maximum bytes read or expanded; exceeding it fails |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | list | Read bounded UTF-8 lines without terminators; CRLF is accepted and a final newline does not create a phantom row |
Use `path`, `max_bytes`=8388608 as the inputs for this operation.
Effects: fs.read.
Read bounded UTF-8 lines without terminators; CRLF is accepted and a final newline does not create a phantom row.
Return *[Read bounded UTF-8 lines without terminators; CRLF is accepted and a final newline does not create a phantom row](> host_fs_read_lines path=`path` max_bytes=`max_bytes`)*.
## write_lines
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| path | text | required | Path within the granted filesystem root |
| lines | list | required | List of text lines to write |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | None after completion; filesystem failures produce a diagnostic |
Use `path`, `lines` as the inputs for this operation.
Effects: fs.write.
Atomically write text lines using LF and one final newline for nonempty input.
Return *[Atomically write text lines using LF and one final newline for nonempty input](> host_fs_write_lines path=`path` lines=`lines`)*.
## remove_file
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| path | text | required | Path within the granted filesystem root |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | None after completion; filesystem failures produce a diagnostic |
Use `path` as the inputs for this operation.
Effects: fs.write.
Delete a file, refusing directories; missing paths fail. Legacy remove remains recursive for compatibility.
Return *[Delete a file, refusing directories; missing paths fail](> host_fs_remove_file path=`path`)*.
## remove_empty_dir
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| path | text | required | Path within the granted filesystem root |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | None after completion; filesystem failures produce a diagnostic |
Use `path` as the inputs for this operation.
Effects: fs.write.
Delete only an empty directory; refuses nonempty directories. Native filesystem only.
Return *[Delete only an empty directory; refuses nonempty directories](> host_fs_remove_empty_dir path=`path`)*.
## temp_dir
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| prefix | text | "mqtmp" | Prefix added to the generated name or tested against text |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | text | Create a directory under the filesystem root and return its relative name |
Use `prefix`="mqtmp" as the inputs for this operation.
Effects: fs.write.
Create a directory under the filesystem root and return its relative name. Caller owns cleanup with remove_tree; never uses a global OS temp directory.
Return *[Create a directory under the filesystem root and return its relative name](> host_fs_temp_dir prefix=`prefix`)*.
## file_hash
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| path | text | required | Path within the granted filesystem root |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | text | Compute SHA-256 with a 64 KiB read buffer; supports binary and large files without loading the whole file |
Use `path` as the inputs for this operation.
Effects: fs.read.
Compute SHA-256 with a 64 KiB read buffer; supports binary and large files without loading the whole file.
Return *[Compute SHA-256 with a 64 KiB read buffer; supports binary and large files without loading the whole file](> host_fs_file_hash path=`path`)*.
## find
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| path | text | required | Path within the granted filesystem root |
| pattern | text | "**" | Relative path glob supporting *, ** and ? |
| exclude | any | None | Glob pattern list pruned during traversal; None excludes nothing |
| max_depth | number | 64 | Maximum traversal depth |
| kind | text | "file" | Entry kind filter: file, dir or any |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | list | Find sorted relative paths with star, double-star and question-mark globs; exclude patterns prune directories; kind is file/dir/all |
Use `path`, `pattern`="**", `exclude`=None, `max_depth`=64, `kind`="file" as the inputs for this operation.
Effects: fs.read.
Find sorted relative paths with star, double-star and question-mark globs; exclude patterns prune directories; kind is file/dir/all. No symlink traversal; at most 100000 results. Native filesystem snapshot.
Return *[Find sorted relative paths with star, double-star and question-mark globs; exclude patterns prune directories; kind is file/dir/all](> host_fs_find path=`path` pattern=`pattern` exclude=`exclude` max_depth=`max_depth` kind=`kind`)*.
## copy_tree
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| src | text | required | Source path; archive packing expects a directory |
| dest | text | required | Destination path; overwrite is allowed only where documented |
| overwrite | bool | False | Whether an existing destination file may be replaced |
| exclude | any | None | Glob pattern list pruned during traversal; None excludes nothing |
| dry_run | bool | False | Whether to return the plan without modifying files |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | list | Copy files between disjoint trees |
Use `src`, `dest`, `overwrite`=False, `exclude`=None, `dry_run`=False as the inputs for this operation.
Effects: fs.write.
Copy files between disjoint trees. Preflight conflicts; overwrite is opt-in. Returns relative changed files; dry_run plans only. Does not copy permissions, symlinks or empty directories.
Return *[Copy files between disjoint trees](> host_fs_copy_tree src=`src` dest=`dest` overwrite=`overwrite` exclude=`exclude` dry_run=`dry_run`)*.
## sync_tree
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| src | text | required | Source path; archive packing expects a directory |
| dest | text | required | Destination path; overwrite is allowed only where documented |
| overwrite | bool | False | Whether an existing destination file may be replaced |
| exclude | any | None | Glob pattern list pruned during traversal; None excludes nothing |
| dry_run | bool | False | Whether to return the plan without modifying files |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | list | Copy new or changed files with copy_tree conflict rules |
Use `src`, `dest`, `overwrite`=False, `exclude`=None, `dry_run`=False as the inputs for this operation.
Effects: fs.write.
Copy new or changed files with copy_tree conflict rules. Never deletes destination-only files; execution is not transactional.
Return *[Copy new or changed files with copy_tree conflict rules](> host_fs_sync_tree src=`src` dest=`dest` overwrite=`overwrite` exclude=`exclude` dry_run=`dry_run`)*.
## rename_many
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| moves | list | required | List of source/destination rename records |
| dry_run | bool | False | Whether to return the plan without modifying files |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | number | Preflight src/dest file records, reject existing or duplicate destinations, then rename in input order |
Use `moves`, `dry_run`=False as the inputs for this operation.
Effects: fs.write.
Preflight src/dest file records, reject existing or duplicate destinations, then rename in input order. No cycles or rollback; dry_run reports the planned count.
Return *[Preflight src/dest file records, reject existing or duplicate destinations, then rename in input order](> host_fs_rename_many moves=`moves` dry_run=`dry_run`)*.
## read_json
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| path | text | required | Path relative to filesystem root |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 解析后的数据 |
Use `path` as the inputs for this operation.
Effects: fs.read.
Read UTF-8 then use the standard parser; errors abort, so batch tasks should first use try_read_text.
We retain **`body` = [Read UTF-8 text from the selected file](read_text(path=`path`))**.
Return *[Parse the JSON transport text](json.parse(text=`body`))*.
## write_json
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| path | text | required | Path relative to filesystem root |
| value | any | required | Data to serialize |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | None after completion; filesystem failures produce a diagnostic |
Use `path`, `value` as the inputs for this operation.
Effects: fs.write.
Serialize then atomically replace the file; formatting and comments are not preserved.
We retain **`body` = [Encode the structured value as JSON text](json.stringify(value=`value`))**.
Return *[Atomic write](atomic_write(path=`path`, text=`body`))*.
## read_csv
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| path | text | required | Path relative to filesystem root |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 解析后的数据 |
Use `path` as the inputs for this operation.
Effects: fs.read.
Read UTF-8 then use the standard parser; errors abort, so batch tasks should first use try_read_text.
We retain **`body` = [Read UTF-8 text from the selected file](read_text(path=`path`))**.
Return *[Parse](csv.parse(text=`body`))*.
## write_csv
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| path | text | required | Path relative to filesystem root |
| value | list | required | Data to serialize |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | None after completion; filesystem failures produce a diagnostic |
Use `path`, `value` as the inputs for this operation.
Effects: fs.write.
Serialize then atomically replace the file; formatting and comments are not preserved.
We retain **`body` = [Stringify](csv.stringify(rows=`value`))**.
Return *[Atomic write](atomic_write(path=`path`, text=`body`))*.
+69 -9
View File
@@ -6,33 +6,93 @@ description: Digests and HMAC (Mid M3). Integrity / cache keys — not password
Digests and HMAC. For integrity and cache keys — not password storage.
Compute content digests and keyed message authentication.
Behavior and limits: MD5/SHA1 are compatibility checksums, not password storage. Use security auth for passwords and fs.file_hash for bounded-memory binary file hashing.
This single source file is the usage and development manual. Import it directly, or use marqdo call with a function heading below. Parameter tables give types and defaults; required parameters must be supplied. Return tables are progressive contracts; prose describes failure and limits.
Implementation: [src/host/hash.rs](../src/host/hash.rs)
For development, keep EN/ZH behavior aligned and compose public libraries first. Add host primitives only at OS or algorithm boundaries and declare their effects. Run marqdo check --narrative-ratio on this file and the real workflows in tests/stdlib_tasks.rs after edits.
## sha256
+ `text`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| text | text | required | Text supplied by the caller |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | SHA-256 hex digest of text |
Use `text` as the inputs for this operation.
Effects: pure.
Call this function directly:
```sh
marqdo call lib/hash.mq.md sha256 'text="abc"' --effects none --json
```
SHA-256 hex digest of text.
Caller: [hash.sha256] text=`s`
*> host_hash_sha256 text=`text`*
Return *[SHA-256 hex digest of text](> host_hash_sha256 text=`text`)*.
## sha1
+ `text`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| text | text | required | Text supplied by the caller |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | SHA-1 hex digest of text |
Use `text` as the inputs for this operation.
Effects: pure.
SHA-1 hex digest of text.
*> host_hash_sha1 text=`text`*
Return *[SHA-1 hex digest of text](> host_hash_sha1 text=`text`)*.
## md5
+ `text`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| text | text | required | Text supplied by the caller |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | MD5 hex digest of text |
Use `text` as the inputs for this operation.
Effects: pure.
MD5 hex digest of text.
*> host_hash_md5 text=`text`*
Return *[MD5 hex digest of text](> host_hash_md5 text=`text`)*.
## hmac_sha256
+ `key`
+ `text`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| key | text | required | Field name or key required by this operation |
| text | text | required | Text supplied by the caller |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | HMAC-SHA256 of text with key |
Use `key`, `text` as the inputs for this operation.
Effects: pure.
HMAC-SHA256 of text with key.
*> host_hash_hmac_sha256 key=`key` text=`text`*
Return *[HMAC-SHA256 of text with key](> host_hash_hmac_sha256 key=`key` text=`text`)*.
+42 -4
View File
@@ -6,18 +6,56 @@ description: HTML escape / unescape (Mid2 M8). XSS floor for string assembly.
HTML escape helpers. Use before stitching untrusted text into markup.
Escape or unescape HTML text.
Behavior and limits: Escaping text does not sanitize an arbitrary HTML document. Build web content as Markdown leaves and structured View nodes.
This single source file is the usage and development manual. Import it directly, or use marqdo call with a function heading below. Parameter tables give types and defaults; required parameters must be supplied. Return tables are progressive contracts; prose describes failure and limits.
Implementation: [src/host/html_ops.rs](../src/host/html_ops.rs)
For development, keep EN/ZH behavior aligned and compose public libraries first. Add host primitives only at OS or algorithm boundaries and declare their effects. Run marqdo check --narrative-ratio on this file and the real workflows in tests/stdlib_tasks.rs after edits.
## escape
+ `text`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| text | text | required | Text supplied by the caller |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | Escape text for HTML |
Use `text` as the inputs for this operation.
Effects: pure.
Call this function directly:
```sh
marqdo call lib/html.mq.md escape 'text="<strong>&"' --effects none --json
```
Escape text for HTML.
Caller: [html.escape] text=`s`
*> host_html_escape text=`text`*
Return *[Escape text for HTML](> host_html_escape text=`text`)*.
## unescape
+ `text`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| text | text | required | Text supplied by the caller |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | Unescape HTML entities in text |
Use `text` as the inputs for this operation.
Effects: pure.
Unescape HTML entities in text.
*> host_html_unescape text=`text`*
Return *[Unescape HTML entities in text](> host_html_unescape text=`text`)*.
+130 -19
View File
@@ -6,58 +6,169 @@ description: JSON parse/stringify (shared EN/ZH import). Not a dict builder —
Parse and stringify JSON. For maps/lists prefer GFM tables and lib/table put; do not chain json.set / json.append in new code.
Parse and serialize JSON at the data boundary.
Behavior and limits: Use table for collection operations. JSON boundary rejects unsafe integers, duplicate keys and nonfinite numbers; do not turn opaque handles into guessed records.
This single source file is the usage and development manual. Import it directly, or use marqdo call with a function heading below. Parameter tables give types and defaults; required parameters must be supplied. Return tables are progressive contracts; prose describes failure and limits.
Implementation: [src/host/json.rs](../src/host/json.rs)
For development, keep EN/ZH behavior aligned and compose public libraries first. Add host primitives only at OS or algorithm boundaries and declare their effects. Run marqdo check --narrative-ratio on this file and the real workflows in tests/stdlib_tasks.rs after edits.
## parse
+ `text`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| text | text | required | Text supplied by the caller |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Parse JSON text into a Marqdo value |
Use `text` as the inputs for this operation.
Effects: pure.
Parse JSON text into a Marqdo value.
Caller: [json.parse] text="{}"
*> host_json_parse text=`text`*
Return *[Parse JSON text into a Marqdo value](> host_json_parse text=`text`)*.
## stringify
+ `value`
+ `indent`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| value | any | required | Value to transform or store, without mutating the input |
| indent | any | None | JSON indentation setting; None uses compact output |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | Serialize value to JSON text; optional indent |
Use `value`, `indent`=None as the inputs for this operation.
Effects: pure.
Serialize value to JSON text; optional indent.
*> host_json_stringify value=`value` indent=`indent`*
Return *[Serialize value to JSON text; optional indent](> host_json_stringify value=`value` indent=`indent`)*.
## get
+ `value`
+ `key`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| value | any | required | Value to transform or store, without mutating the input |
| key | text | required | Field name or key required by this operation |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Shallow get from JSON object value at key |
Use `value`, `key` as the inputs for this operation.
Effects: pure.
Shallow get from JSON object value at key. Prefer link-index get or table.get in new code.
*> host_json_get value=`value` key=`key`*
Return *[Shallow get from JSON object value at key](> host_json_get value=`value` key=`key`)*.
## keys
+ `value`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| value | any | required | Value to transform or store, without mutating the input |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | list | Keys of JSON object value |
Use `value` as the inputs for this operation.
Effects: pure.
Keys of JSON object value.
*> host_json_keys value=`value`*
Return *[Keys of JSON object value](> host_json_keys value=`value`)*.
## quote
+ `text`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| text | text | required | Text supplied by the caller |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | JSON-quote string text (for building request bodies) |
Use `text` as the inputs for this operation.
Effects: pure.
JSON-quote string text (for building request bodies).
*> host_json_quote text=`text`*
Return *[JSON-quote string text (for building request bodies)](> host_json_quote text=`text`)*.
## set
+ `map`
+ `key`
+ `value`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| map | any | required | Input string-keyed map |
| key | text | required | Field name or key required by this operation |
| value | any | required | Value to transform or store, without mutating the input |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Compatibility shallow set |
Use `map`, `key`, `value` as the inputs for this operation.
Effects: pure.
Compatibility shallow set. Prefer table.put / table.set.
*> host_map_set map=`map` key=`key` value=`value`*
Return *[Compatibility shallow set](> host_map_set map=`map` key=`key` value=`value`)*.
## append
+ `list`
+ `item`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| list | any | required | Input list; updates return a new list |
| item | any | required | Element to insert, replace or compare |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | list | Compatibility append |
Use `list`, `item` as the inputs for this operation.
Effects: pure.
Compatibility append. Prefer table.append.
*> host_list_append list=`list` item=`item`*
Return *[Compatibility append](> host_list_append list=`list` item=`item`)*.
## try_parse
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| text | text | required | Text to read, transform or emit as described by this operation |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | map | Return {ok,value,error}; parse failures are recoverable data |
Use `text` as the inputs for this operation.
Effects: pure.
Call this function directly:
```sh
marqdo call lib/json.mq.md try_parse 'text="{"name":"Marqdo","n":2}"' --effects none --json
```
Return {ok,value,error}; parse failures are recoverable data.
Return *[Return {ok,value,error}; parse failures are recoverable data](> host_try_json_parse text=`text`)*.
+8 -13
View File
@@ -12,30 +12,25 @@ its headings are tools. The canonical path checker lives in the host as
marqdo check --narrative-ratio so directory dogfood does not need filesystem
effects inside a pure call.
## For AI agents
If you are an AI agent, run marqdo check --narrative-ratio on each extension
file you edit. Do not invent a second schema. Call remind on this file when you
need a short machine-readable reminder of the rule. Each double-hash heading is
a tool.
*None*
For AI agents: run marqdo check --narrative-ratio on edited library files.
This is a readability signal; parsing, contracts, executable examples and real
behavior tests provide correctness evidence. Headings name actual tools only.
## remind
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | rule reminder map |
Return a small map stating the narration threshold and the CLI to run. Takes no
parameters. Use this when an agent needs a tool-shaped reminder without opening
design docs. The threshold is one half. Contract tables count as narration;
call lines and bold statements count as code.
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | rule reminder map |
`out` =
| threshold | cli | tables |
|-----------|-----|--------|
| 0.5 | marqdo check --narrative-ratio FILE | narration |
*out*
Return *out*.
+93 -22
View File
@@ -6,57 +6,128 @@ description: Level-filtered one-line logs (Mid M6 + Mid2 M10 fields). Default le
Level-filtered one-line logs (Mid M6 + Mid2 M10 fields). Default level info.
Emit level-filtered diagnostic lines.
Behavior and limits: set_level changes this run only. Logs are side effects, not return values. call captures stdout separately from its JSON result.
This single source file is the usage and development manual. Import it directly, or use marqdo call with a function heading below. Parameter tables give types and defaults; required parameters must be supplied. Return tables are progressive contracts; prose describes failure and limits.
Implementation: [src/host/log.rs](../src/host/log.rs)
For development, keep EN/ZH behavior aligned and compose public libraries first. Add host primitives only at OS or algorithm boundaries and declare their effects. Run marqdo check --narrative-ratio on this file and the real workflows in tests/stdlib_tasks.rs after edits.
## set_level
+ `level`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| level | any | required | Log threshold: debug, info, warn or error |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | level is debug / info / warn / error |
Use `level` as the inputs for this operation.
Effects: pure.
level is debug / info / warn / error.
*> host_log_set_level level=`level`*
Return *[level is debug / info / warn / error](> host_log_set_level level=`level`)*.
## debug
+ `text`
+ `fields`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| text | text | required | Text supplied by the caller |
| fields | any | None | Structured field/value record attached to the log event |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Emit a debug log line; optional fields map |
Use `text`, `fields`=None as the inputs for this operation.
Effects: output.write.
Emit a debug log line; optional fields map.
**line = > host_log_line level="debug" text=`text` fields=`fields`**
We retain **`line` = [Log line]([Emit a debug log line; optional fields map](host_log_line(level="debug", text=`text`, fields=`fields`)))**.
1. `line`
> print text=`line`
We **[Print the prepared message](print(text=`line`))**.
2. *
****
Return *None*.
## info
+ `text`
+ `fields`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| text | text | required | Text supplied by the caller |
| fields | any | None | Structured field/value record attached to the log event |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Emit an info log line; optional fields map |
Use `text`, `fields`=None as the inputs for this operation.
Effects: output.write.
Call this function directly:
```sh
marqdo call lib/log.mq.md info 'text="handbook example"' 'fields={"task":"sample"}' --effects output.write --json
```
Emit an info log line; optional fields map.
**line = > host_log_line level="info" text=`text` fields=`fields`**
We retain **`line` = [Log line]([Emit an info log line; optional fields map](host_log_line(level="info", text=`text`, fields=`fields`)))**.
1. `line`
> print text=`line`
We **[Print the prepared message](print(text=`line`))**.
2. *
****
Return *None*.
## warn
+ `text`
+ `fields`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| text | text | required | Text supplied by the caller |
| fields | any | None | Structured field/value record attached to the log event |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Emit a warn log line; optional fields map |
Use `text`, `fields`=None as the inputs for this operation.
Effects: output.write.
Emit a warn log line; optional fields map.
**line = > host_log_line level="warn" text=`text` fields=`fields`**
We retain **`line` = [Log line]([Emit a warn log line; optional fields map](host_log_line(level="warn", text=`text`, fields=`fields`)))**.
1. `line`
> print text=`line`
We **[Print the prepared message](print(text=`line`))**.
2. *
****
Return *None*.
## error
+ `text`
+ `fields`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| text | text | required | Text supplied by the caller |
| fields | any | None | Structured field/value record attached to the log event |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Emit an error log line; optional fields map |
Use `text`, `fields`=None as the inputs for this operation.
Effects: output.write.
Emit an error log line; optional fields map.
**line = > host_log_line level="error" text=`text` fields=`fields`**
We retain **`line` = [Log line]([Emit an error log line; optional fields map](host_log_line(level="error", text=`text`, fields=`fields`)))**.
1. `line`
> print text=`line`
We **[Print the prepared message](print(text=`line`))**.
2. *
****
Return *None*.
+534 -137
View File
@@ -6,283 +6,680 @@ description: High-school math — num, random, formula, plot
High-school math — num, random, formula, plot
Compute numbers, symbolic expressions and plots.
Behavior and limits: Number contracts include symbolic formulas. Random values require random.read. Plotting emits an artifact and needs output.write; linear algebra and quantum workloads stay in ext.
This single source file is the usage and development manual. Import it directly, or use marqdo call with a function heading below. Parameter tables give types and defaults; required parameters must be supplied. Return tables are progressive contracts; prose describes failure and limits.
Implementation: [src/host/math.rs](../src/host/math.rs)
For development, keep EN/ZH behavior aligned and compose public libraries first. Add host primitives only at OS or algorithm boundaries and declare their effects. Run marqdo check --narrative-ratio on this file and the real workflows in tests/stdlib_tasks.rs after edits.
## pi
pi.
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | Return the mathematical constant pi |
*> host_pi*
Effects: pure.
Return the mathematical constant pi.
Return *[Return the mathematical constant pi](host_pi())*.
## e
e.
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | Return Euler constant e |
*> host_e*
Effects: pure.
Return Euler constant e.
Return *[Return Euler constant e](host_e())*.
## num
+ `value`
num.
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| value | any | required | Value to transform or store, without mutating the input |
*> host_num value=`value`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | Convert a numeric value or numeric text to a number |
Use `value` as the inputs for this operation.
Effects: pure.
Convert a numeric value or numeric text to a number.
Return *[Convert a numeric value or numeric text to a number](> host_num value=`value`)*.
## add
+ `a`
+ `b`
add.
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| a | any | required | First operand; its domain is described by this operation |
| b | any | required | Second operand; its domain is described by this operation |
*> host_math_add a=`a` b=`b`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | Add the two numeric or symbolic operands |
Use `a`, `b` as the inputs for this operation.
Effects: pure.
Add the two numeric or symbolic operands.
Return *[Add the two numeric or symbolic operands](> host_math_add a=`a` b=`b`)*.
## sub
+ `a`
+ `b`
sub.
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| a | any | required | First operand; its domain is described by this operation |
| b | any | required | Second operand; its domain is described by this operation |
*> host_math_sub a=`a` b=`b`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | Subtract b from a |
Use `a`, `b` as the inputs for this operation.
Effects: pure.
Subtract b from a.
Return *[Subtract b from a](> host_math_sub a=`a` b=`b`)*.
## mul
+ `a`
+ `b`
mul.
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| a | any | required | First operand; its domain is described by this operation |
| b | any | required | Second operand; its domain is described by this operation |
*> host_math_mul a=`a` b=`b`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | Multiply a by b |
Use `a`, `b` as the inputs for this operation.
Effects: pure.
Multiply a by b.
Return *[Multiply a by b](> host_math_mul a=`a` b=`b`)*.
## div
+ `a`
+ `b`
div.
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| a | any | required | First operand; its domain is described by this operation |
| b | any | required | Second operand; its domain is described by this operation |
*> host_math_div a=`a` b=`b`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | Divide a by b; zero divisor is an error |
Use `a`, `b` as the inputs for this operation.
Effects: pure.
Divide a by b; zero divisor is an error.
Return *[Divide a by b; zero divisor is an error](> host_math_div a=`a` b=`b`)*.
## pow
+ `a`
+ `b`
pow.
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| a | any | required | First operand; its domain is described by this operation |
| b | any | required | Second operand; its domain is described by this operation |
*> host_math_pow a=`a` b=`b`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | Raise a to the power b |
Use `a`, `b` as the inputs for this operation.
Effects: pure.
Raise a to the power b.
Return *[Raise a to the power b](> host_math_pow a=`a` b=`b`)*.
## neg
+ `value`
neg.
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| value | any | required | Value to transform or store, without mutating the input |
*> host_math_neg value=`value`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | Negate a numeric or symbolic value |
Use `value` as the inputs for this operation.
Effects: pure.
Negate a numeric or symbolic value.
Return *[Negate a numeric or symbolic value](> host_math_neg value=`value`)*.
## sin
+ `value`
sin.
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| value | any | required | Value to transform or store, without mutating the input |
*> host_math_sin value=`value`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | Compute sine; numeric angles are radians |
Use `value` as the inputs for this operation.
Effects: pure.
Compute sine; numeric angles are radians.
Return *[Compute sine; numeric angles are radians](> host_math_sin value=`value`)*.
## cos
+ `value`
cos.
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| value | any | required | Value to transform or store, without mutating the input |
*> host_math_cos value=`value`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | Compute cosine; numeric angles are radians |
Use `value` as the inputs for this operation.
Effects: pure.
Compute cosine; numeric angles are radians.
Return *[Compute cosine; numeric angles are radians](> host_math_cos value=`value`)*.
## tan
+ `value`
tan.
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| value | any | required | Value to transform or store, without mutating the input |
*> host_math_tan value=`value`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | Compute tangent; numeric angles are radians |
Use `value` as the inputs for this operation.
Effects: pure.
Compute tangent; numeric angles are radians.
Return *[Compute tangent; numeric angles are radians](> host_math_tan value=`value`)*.
## asin
+ `value`
asin.
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| value | any | required | Value to transform or store, without mutating the input |
*> host_math_asin value=`value`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | Compute arcsine in radians |
Use `value` as the inputs for this operation.
Effects: pure.
Compute arcsine in radians.
Return *[Compute arcsine in radians](> host_math_asin value=`value`)*.
## acos
+ `value`
acos.
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| value | any | required | Value to transform or store, without mutating the input |
*> host_math_acos value=`value`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | Compute arccosine in radians |
Use `value` as the inputs for this operation.
Effects: pure.
Compute arccosine in radians.
Return *[Compute arccosine in radians](> host_math_acos value=`value`)*.
## atan
+ `value`
atan.
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| value | any | required | Value to transform or store, without mutating the input |
*> host_math_atan value=`value`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | Compute arctangent in radians |
Use `value` as the inputs for this operation.
Effects: pure.
Compute arctangent in radians.
Return *[Compute arctangent in radians](> host_math_atan value=`value`)*.
## sqrt
+ `value`
sqrt.
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| value | any | required | Value to transform or store, without mutating the input |
*> host_math_sqrt value=`value`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | Compute the square root of value |
Use `value` as the inputs for this operation.
Effects: pure.
Call this function directly:
```sh
marqdo call lib/math.mq.md sqrt value=9 --effects none --json
```
Compute the square root of value.
Return *[Compute the square root of value](> host_math_sqrt value=`value`)*.
## abs
+ `value`
abs.
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| value | any | required | Value to transform or store, without mutating the input |
*> host_math_abs value=`value`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | Return absolute magnitude |
Use `value` as the inputs for this operation.
Effects: pure.
Return absolute magnitude.
Return *[Return absolute magnitude](> host_math_abs value=`value`)*.
## ln
+ `value`
ln.
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| value | any | required | Value to transform or store, without mutating the input |
*> host_math_ln value=`value`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | Compute natural logarithm |
Use `value` as the inputs for this operation.
Effects: pure.
Compute natural logarithm.
Return *[Compute natural logarithm](> host_math_ln value=`value`)*.
## exp
+ `value`
exp.
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| value | any | required | Value to transform or store, without mutating the input |
*> host_math_exp value=`value`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | Compute the exponential of value |
Use `value` as the inputs for this operation.
Effects: pure.
Compute the exponential of value.
Return *[Compute the exponential of value](> host_math_exp value=`value`)*.
## floor
+ `value`
floor.
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| value | any | required | Value to transform or store, without mutating the input |
*> host_math_floor value=`value`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | Round toward negative infinity |
Use `value` as the inputs for this operation.
Effects: pure.
Round toward negative infinity.
Return *[Round toward negative infinity](> host_math_floor value=`value`)*.
## ceil
+ `value`
ceil.
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| value | any | required | Value to transform or store, without mutating the input |
*> host_math_ceil value=`value`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | Round toward positive infinity |
Use `value` as the inputs for this operation.
Effects: pure.
Round toward positive infinity.
Return *[Round toward positive infinity](> host_math_ceil value=`value`)*.
## min
+ `a`
+ `b`
min.
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| a | any | required | First operand; its domain is described by this operation |
| b | any | required | Second operand; its domain is described by this operation |
*> host_math_min a=`a` b=`b`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | Return the smaller operand |
Use `a`, `b` as the inputs for this operation.
Effects: pure.
Return the smaller operand.
Return *[Return the smaller operand](> host_math_min a=`a` b=`b`)*.
## max
+ `a`
+ `b`
max.
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| a | any | required | First operand; its domain is described by this operation |
| b | any | required | Second operand; its domain is described by this operation |
*> host_math_max a=`a` b=`b`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | Return the larger operand |
Use `a`, `b` as the inputs for this operation.
Effects: pure.
Return the larger operand.
Return *[Return the larger operand](> host_math_max a=`a` b=`b`)*.
## random
random.
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | Return a pseudo-random number; seed controls reproducibility |
*> host_random*
Effects: random.read.
Return a pseudo-random number; seed controls reproducibility.
Return *[Return a pseudo-random number; seed controls reproducibility](host_random())*.
## random_int
+ `min`
+ `max`
random_int.
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| min | any | required | Inclusive lower bound or start of the search/plot interval |
| max | any | required | Upper bound or end of the search/plot interval |
*> host_random_int min=`min` max=`max`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | Return a pseudo-random integer in the documented bounds |
Use `min`, `max` as the inputs for this operation.
Effects: random.read.
Return a pseudo-random integer in the documented bounds.
Return *[Return a pseudo-random integer in the documented bounds](> host_random_int min=`min` max=`max`)*.
## seed
+ `value`
seed.
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| value | any | required | Integer seed for reproducible random sequences |
*> host_seed value=`value`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Set this run pseudo-random generator seed; not suitable for secrets |
Use `value` as the inputs for this operation.
Effects: pure.
Set this run pseudo-random generator seed; not suitable for secrets.
Return *[Set this run pseudo-random generator seed; not suitable for secrets](> host_seed value=`value`)*.
## formula
+ `text`
formula.
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| text | any | required | Text supplied by the caller |
*> host_formula value=`text`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | Parse expression text into a symbolic formula for later algebra or evaluation; invalid syntax produces a diagnostic |
Use `text` as the inputs for this operation.
Effects: pure.
Parse expression text into a symbolic formula for later algebra or evaluation; invalid syntax produces a diagnostic.
Return *[Parse expression text into a symbolic formula for later algebra or evaluation; invalid syntax produces a diagnostic](> host_formula value=`text`)*.
## simplify
+ `formula`
simplify.
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| formula | any | required | Symbolic formula returned by formula or a prior symbolic operation |
*> host_simplify value=`formula`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | Return a simplified formula without changing the input; this is symbolic algebra, not numeric evaluation |
Use `formula` as the inputs for this operation.
Effects: pure.
Return a simplified formula without changing the input; this is symbolic algebra, not numeric evaluation.
Return *[Return a simplified formula without changing the input; this is symbolic algebra, not numeric evaluation](> host_simplify value=`formula`)*.
## expand
+ `formula`
expand.
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| formula | any | required | Symbolic formula returned by formula or a prior symbolic operation |
*> host_expand value=`formula`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | Expand algebraic products and powers and return a new symbolic formula |
Use `formula` as the inputs for this operation.
Effects: pure.
Expand algebraic products and powers and return a new symbolic formula.
Return *[Expand algebraic products and powers and return a new symbolic formula](> host_expand value=`formula`)*.
## diff
+ `formula`
+ `var`
diff.
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| formula | any | required | Symbolic formula returned by formula or a prior symbolic operation |
| var | any | required | Symbol name to differentiate, substitute, evaluate or solve for |
*> host_diff formula=`formula` var=`var`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | Differentiate the formula with respect to the named symbol and return a symbolic derivative |
Use `formula`, `var` as the inputs for this operation.
Effects: pure.
Differentiate the formula with respect to the named symbol and return a symbolic derivative.
Return *[Differentiate the formula with respect to the named symbol and return a symbolic derivative](> host_diff formula=`formula` var=`var`)*.
## subs
+ `formula`
+ `var`
+ `value`
subs.
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| formula | any | required | Symbolic formula returned by formula or a prior symbolic operation |
| var | any | required | Symbol name to differentiate, substitute, evaluate or solve for |
| value | any | required | Value to transform or store, without mutating the input |
*> host_subs formula=`formula` var=`var` value=`value`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | Substitute a symbol with the supplied value; return a number if fully reduced, otherwise a formula |
Use `formula`, `var`, `value` as the inputs for this operation.
Effects: pure.
Substitute a symbol with the supplied value; return a number if fully reduced, otherwise a formula.
Return *[Substitute a symbol with the supplied value; return a number if fully reduced, otherwise a formula](> host_subs formula=`formula` var=`var` value=`value`)*.
## eval
+ `formula`
+ `var`
+ `value`
eval.
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| formula | any | required | Symbolic formula returned by formula or a prior symbolic operation |
| var | any | required | Symbol name to differentiate, substitute, evaluate or solve for |
| value | any | required | Value to transform or store, without mutating the input |
*> host_eval formula=`formula` var=`var` value=`value`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Evaluate a formula at one numeric variable value; unresolved symbols produce a diagnostic |
Use `formula`, `var`, `value` as the inputs for this operation.
Effects: pure.
Evaluate a formula at one numeric variable value; unresolved symbols produce a diagnostic.
Return *[Evaluate a formula at one numeric variable value; unresolved symbols produce a diagnostic](> host_eval formula=`formula` var=`var` value=`value`)*.
## solve
+ `formula`
+ `var`
+ `min`=None
+ `max`=None
solve.
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| formula | any | required | Symbolic formula returned by formula or a prior symbolic operation |
| var | any | required | Symbol name to differentiate, substitute, evaluate or solve for |
| min | any | None | Inclusive lower bound or start of the search/plot interval |
| max | any | None | Upper bound or end of the search/plot interval |
*> host_solve formula=`formula` var=`var` min=`min` max=`max`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Return roots for the named symbol within min and max; omitted bounds use -100 and 100 |
Use `formula`, `var`, `min`=None, `max`=None as the inputs for this operation.
Effects: pure.
Return roots for the named symbol within min and max; omitted bounds use -100 and 100.
Return *[Return roots for the named symbol within min and max; omitted bounds use -100 and 100](> host_solve formula=`formula` var=`var` min=`min` max=`max`)*.
## plot
+ `formula`
+ `var`
+ `min`
+ `max`
+ `steps`=None
+ `path`=None
+ `derivative`=None
+ `grid`=None
plot.
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| formula | any | required | Symbolic formula returned by formula or a prior symbolic operation |
| var | any | required | Symbol name to differentiate, substitute, evaluate or solve for |
| min | any | required | Inclusive lower bound or start of the search/plot interval |
| max | any | required | Upper bound or end of the search/plot interval |
| steps | any | None | Number of samples across the plotting interval |
| path | any | None | Path relative to the granted filesystem root |
| derivative | any | None | Whether to include the derivative in the plot |
| grid | any | None | Whether to draw a coordinate grid |
*> host_plot formula=`formula` var=`var` min=`min` max=`max` steps=`steps` path=`path` derivative=`derivative` grid=`grid`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Sample the formula over the interval and return SVG text; an optional path also writes the SVG under the granted root |
Use `formula`, `var`, `min`, `max`, `steps`=None, `path`=None, `derivative`=None, `grid`=None as the inputs for this operation.
Effects: output.write.
Sample the formula over the interval and return SVG text; an optional path also writes the SVG under the granted root.
Return *[Sample the formula over the interval and return SVG text; an optional path also writes the SVG under the granted root](> host_plot formula=`formula` var=`var` min=`min` max=`max` steps=`steps` path=`path` derivative=`derivative` grid=`grid`)*.
## plot_points
+ `xs`
+ `ys`
+ `path`=None
+ `grid`=None
plot_points.
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| xs | any | required | Input list or collection, as required by this operation |
| ys | any | required | Y-coordinate list paired with xs |
| path | any | None | Path relative to the granted filesystem root |
| grid | any | None | Whether to draw a coordinate grid |
*> host_plot_points xs=`xs` ys=`ys` path=`path` grid=`grid`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Plot paired x/y lists and return SVG text; unequal coordinate lengths are rejected |
Use `xs`, `ys`, `path`=None, `grid`=None as the inputs for this operation.
Effects: output.write.
Plot paired x/y lists and return SVG text; unequal coordinate lengths are rejected.
Return *[Plot paired x/y lists and return SVG text; unequal coordinate lengths are rejected](> host_plot_points xs=`xs` ys=`ys` path=`path` grid=`grid`)*.
## plot_conic
+ `kind`
+ `a`
+ `b`=None
+ `h`=None
+ `k`=None
+ `path`=None
+ `grid`=None
plot_conic.
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| kind | any | required | Conic type accepted by plot_conic |
| a | any | required | First operand; its domain is described by this operation |
| b | any | None | Second operand; its domain is described by this operation |
| h | any | None | Horizontal shift of the conic center |
| k | any | None | Vertical shift of the conic center |
| path | any | None | Path relative to the granted filesystem root |
| grid | any | None | Whether to draw a coordinate grid |
*> host_plot_conic kind=`kind` a=`a` b=`b` h=`h` k=`k` path=`path` grid=`grid`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Draw the selected conic with its dimensions and center offsets and return SVG text |
Use `kind`, `a`, `b`=None, `h`=None, `k`=None, `path`=None, `grid`=None as the inputs for this operation.
Effects: output.write.
Draw the selected conic with its dimensions and center offsets and return SVG text.
Return *[Draw the selected conic with its dimensions and center offsets and return SVG text](> host_plot_conic kind=`kind` a=`a` b=`b` h=`h` k=`k` path=`path` grid=`grid`)*.
+243 -33
View File
@@ -1,85 +1,295 @@
---
markup: occlusion
import:
table: lib/table.mq.md
text: lib/text.mq.md
title: lib/net
description: English HTTP(S) wrappers. Optional headers / content_type via host aliases.
---
English HTTP(S) wrappers. Optional headers / content_type via host aliases.
Use HTTP, response parsing and bounded downloads.
Behavior and limits: get requires network.read; configurable request conservatively requires network.write because its method is dynamic. request/get return Result with response headers; legacy http_* retain their historical contracts. Downloads also require fs.write.
This single source file is the usage and development manual. Import it directly, or use marqdo call with a function heading below. Parameter tables give types and defaults; required parameters must be supplied. Return tables are progressive contracts; prose describes failure and limits.
Implementation: [src/host/net.rs](../src/host/net.rs)、[src/host/net_ops.rs](../src/host/net_ops.rs)
For development, keep EN/ZH behavior aligned and compose public libraries first. Add host primitives only at OS or algorithm boundaries and declare their effects. Run marqdo check --narrative-ratio on this file and the real workflows in tests/stdlib_tasks.rs after edits.
## http_get
+ `url`
+ `headers`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| url | text | required | Target URL; HTTP helpers accept http or https |
| headers | any | None | HTTP header name/value record; None sends no extra headers |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | HTTPS supported |
Use `url`, `headers`=None as the inputs for this operation.
Effects: network.read.
HTTPS supported. Optional named arg `headers=` (map). Responses are capped at 8 MiB before decoding, so an upstream cannot exhaust the interpreter's memory.
*> host_http_get url=`url` headers=`headers`*
Return *[HTTPS supported](> host_http_get url=`url` headers=`headers`)*.
## http_post
+ `url`
+ `body`
+ `content_type`=None
+ `headers`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| url | text | required | Target URL; HTTP helpers accept http or https |
| body | any | required | Request body, or replacement text for document operations |
| content_type | any | None | HTTP content type override; None uses the helper default |
| headers | any | None | HTTP header name/value record; None sends no extra headers |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Default content type is JSON |
Use `url`, `body`, `content_type`=None, `headers`=None as the inputs for this operation.
Effects: network.write.
Default content type is JSON. Optional `content_type=` / `headers=` (map).
*> host_http_post url=`url` body=`body` content_type=`content_type` headers=`headers`*
Return *[Default content type is JSON](> host_http_post url=`url` body=`body` content_type=`content_type` headers=`headers`)*.
## http_post_sse
+ `url`
+ `body`
+ `content_type`=None
+ `headers`=None
+ `echo`=False
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| url | text | required | Target URL; HTTP helpers accept http or https |
| body | any | required | Request body, or replacement text for document operations |
| content_type | any | None | HTTP content type override; None uses the helper default |
| headers | any | None | HTTP header name/value record; None sends no extra headers |
| echo | bool | False | Whether to print streamed SSE text as it arrives |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | POST and consume OpenAI-compatible SSE |
Use `url`, `body`, `content_type`=None, `headers`=None, `echo`=False as the inputs for this operation.
Effects: network.write.
POST and consume OpenAI-compatible SSE. Returns `{status, events}` where `events` is a list of `{type, …}` maps (`delta` / `done` / `error`). Optional `echo=True` prints delta text to stdout as chunks arrive.
*> host_http_post_sse url=`url` body=`body` content_type=`content_type` headers=`headers` echo=`echo`*
Return *[POST and consume OpenAI-compatible SSE](> host_http_post_sse url=`url` body=`body` content_type=`content_type` headers=`headers` echo=`echo`)*.
## openai_sse_parse
+ `text`
+ `echo`=False
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| text | text | required | Text supplied by the caller |
| echo | bool | False | Whether to print streamed SSE text as it arrives |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | list | Offline: parse an OpenAI chat SSE body into the same event list (no network) |
Use `text`, `echo`=False as the inputs for this operation.
Effects: pure.
Offline: parse an OpenAI chat SSE body into the same event list (no network).
*> host_openai_sse_parse text=`text` echo=`echo`*
Return *[Offline: parse an OpenAI chat SSE body into the same event list (no network)](> host_openai_sse_parse text=`text` echo=`echo`)*.
## http_request
+ `method`
+ `url`
+ `body`=None
+ `content_type`=None
+ `headers`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| method | text | required | HTTP method, for example GET or POST |
| url | text | required | Target URL; HTTP helpers accept http or https |
| body | any | None | Request body, or replacement text for document operations |
| content_type | any | None | HTTP content type override; None uses the helper default |
| headers | any | None | HTTP header name/value record; None sends no extra headers |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Optional `body=` / `content_type=` / `headers=` |
Use `method`, `url`, `body`=None, `content_type`=None, `headers`=None as the inputs for this operation.
Effects: network.write.
Optional `body=` / `content_type=` / `headers=`.
*> host_http_request method=`method` url=`url` body=`body` content_type=`content_type` headers=`headers`*
Return *[Optional body= / content_type= / headers=](> host_http_request method=`method` url=`url` body=`body` content_type=`content_type` headers=`headers`)*.
## url_encode
+ `text`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| text | text | required | Text supplied by the caller |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | Percent-encode a URL segment |
Use `text` as the inputs for this operation.
Effects: pure.
Percent-encode a URL segment. Spaces become `%20` (not form/query `+`), so literal `+` remains unambiguous in paths.
*> host_url_encode text=`text`*
Return *[Percent-encode a URL segment](> host_url_encode text=`text`)*.
## cookie_parse
+ `text`
+ `is_response`=False
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| text | text | required | Text supplied by the caller |
| is_response | any | False | Whether to parse a response header block rather than a request |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | list | Parse a `Cookie` request header (default) or one or more `Set-Cookie` response headers (`is_response=True`) into a list of `{name, value, path, domain, expires, max_age, secure, http_only, same_site}` |
Use `text`, `is_response`=False as the inputs for this operation.
Effects: pure.
Call this function directly:
```sh
marqdo call lib/net.mq.md cookie_parse 'text="a=1; b=2"' --effects none --json
```
Parse a `Cookie` request header (default) or one or more `Set-Cookie` response headers (`is_response=True`) into a list of `{name, value, path, domain, expires, max_age, secure, http_only, same_site}`.
*> host_cookie_parse text=`text` is_response=`is_response`*
Return *[Parse a Cookie request header (default) or one or more Set-Cookie response headers (is_response=True) into a list of {name, value, path, domain, expires, max_age, secure,](> host_cookie_parse text=`text` is_response=`is_response`)*.
## multipart_parse
+ `body`
+ `boundary`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| body | any | required | Request body, or replacement text for document operations |
| boundary | any | required | Multipart delimiter from the Content-Type header |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | list | Parse a `multipart/form-data` request body (given its `boundary`) into a list of `{name, filename?, content_type?, value}` parts |
Use `body`, `boundary` as the inputs for this operation.
Effects: pure.
Parse a `multipart/form-data` request body (given its `boundary`) into a list of `{name, filename?, content_type?, value}` parts.
*> host_multipart_parse body=`body` boundary=`boundary`*
Return *[Parse a multipart/form-data request body (given its boundary) into a list of {name, filename?, content_type?, value} parts](> host_multipart_parse body=`body` boundary=`boundary`)*.
## markdown_parse
+ `text`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| text | text | required | Text supplied by the caller |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | Parse Markdown / GFM into HTML (pure transform, no network I/O) |
Use `text` as the inputs for this operation.
Effects: pure.
Parse Markdown / GFM into HTML (pure transform, no network I/O).
*> host_markdown_parse text=`text`*
Return *[Parse Markdown / GFM into HTML (pure transform, no network I/O)](> host_markdown_parse text=`text`)*.
## request
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| method | text | required | HTTP method, for example GET or POST |
| url | text | required | Target URL; HTTP helpers accept http or https |
| body | any | None | Request body, or replacement text for document operations |
| headers | any | None | HTTP header name/value record; None sends no extra headers |
| timeout_ms | number | 30000 | Timeout in milliseconds; inspect the operation result after waiting |
| max_bytes | number | 8388608 | Maximum bytes read or expanded; exceeding it fails |
| response | text | "text" | Response body representation: text or bytes |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | map | Return Result; value has status, headers and body |
Use `method`, `url`, `body`=None, `headers`=None, `timeout_ms`=30000, `max_bytes`=8388608, `response`="text" as the inputs for this operation.
Effects: network.write.
Body is text, a bytes record or None; serialize JSON with json.stringify first. Request headers are a map; response headers are name/values records. Output options and destinations are checked before network IO.
Return Result; value has status, headers and body. Timeout is milliseconds; response is text or bytes; headers are name/values records. HTTP error status is a valid response; transport failure is an error.
Return *[Body is text, a bytes record or None; serialize JSON with json.stringify first](> host_http_request_result method=`method` url=`url` body=`body` headers=`headers` timeout_ms=`timeout_ms` max_bytes=`max_bytes` response=`response`)*.
## download
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| url | text | required | Target URL; HTTP helpers accept http or https |
| path | text | required | Path within the granted filesystem root |
| headers | any | None | HTTP header name/value record; None sends no extra headers |
| timeout_ms | number | 30000 | Timeout in milliseconds; inspect the operation result after waiting |
| max_bytes | number | 67108864 | Maximum bytes read or expanded; exceeding it fails |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | map | Bounded streaming download; atomically replace destination only on successful status and complete transfer |
Use `url`, `path`, `headers`=None, `timeout_ms`=30000, `max_bytes`=67108864 as the inputs for this operation.
Effects: fs.write,network.read.
Bounded streaming download; atomically replace destination only on successful status and complete transfer. Result value has status/headers/size/path; requires network.read and fs.write.
Return *[Bounded streaming download; atomically replace destination only on successful status and complete transfer](> host_http_download url=`url` path=`path` headers=`headers` timeout_ms=`timeout_ms` max_bytes=`max_bytes`)*.
## get
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| url | text | required | Target URL; HTTP helpers accept http or https |
| headers | any | None | HTTP header name/value record; None sends no extra headers |
| timeout_ms | number | 30000 | Timeout in milliseconds; inspect the operation result after waiting |
| max_bytes | number | 8388608 | Maximum bytes read or expanded; exceeding it fails |
| response | text | "text" | Response body representation: text or bytes |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | map | Read-only GET as Result, requiring only network |
Use `url`, `headers`=None, `timeout_ms`=30000, `max_bytes`=8388608, `response`="text" as the inputs for this operation.
Effects: network.read.
Read-only GET as Result, requiring only network.read. Headers are name/values records; response is text or bytes.
Return *[Read-only GET as Result, requiring only network.read](> host_http_get_result url=`url` headers=`headers` timeout_ms=`timeout_ms` max_bytes=`max_bytes` response=`response`)*.
## header_values
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| headers | list | required | headers records from a response |
| name | text | required | Header name |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | list | All values for the header |
Use `headers`, `name` as the inputs for this operation.
Effects: pure.
Return all values for a case-insensitive response header; missing yields an empty list. Request headers remain a map; response headers use records to preserve arbitrary names and repeated values.
We retain **`lower` = [To lower](text.to_lower(text=`name`))**.
We retain **`matches` = [Where](table.where(list=`headers`, key="name", value=`lower`))**.
We retain **`values` = [Pluck](table.pluck(list=`matches`, key="values"))**.
Return *[Flatten](table.flatten(list=`values`))*.
+146 -15
View File
@@ -6,54 +6,185 @@ description: Path algebra (Mid M2). No I/O; OS separators.
Path algebra only. No I/O; separators follow the host OS.
Manipulate paths without accessing the filesystem.
Behavior and limits: Normalization is lexical, not an authorization check. IO paths are checked by the host filesystem root.
This single source file is the usage and development manual. Import it directly, or use marqdo call with a function heading below. Parameter tables give types and defaults; required parameters must be supplied. Return tables are progressive contracts; prose describes failure and limits.
Implementation: [src/host/path.rs](../src/host/path.rs)、[src/host/fs_ops.rs](../src/host/fs_ops.rs)
For development, keep EN/ZH behavior aligned and compose public libraries first. Add host primitives only at OS or algorithm boundaries and declare their effects. Run marqdo check --narrative-ratio on this file and the real workflows in tests/stdlib_tasks.rs after edits.
## join
+ `a`
+ `b`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| a | any | required | Base path |
| b | any | required | Path segment appended to the base |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | Join path segments a and b |
Use `a`, `b` as the inputs for this operation.
Effects: pure.
Join path segments a and b.
Caller: [path.join] a="a" b="b"
*> host_path_join a=`a` b=`b`*
Return *[Join path segments a and b](> host_path_join a=`a` b=`b`)*.
## split
+ `path`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| path | text | required | Path relative to the granted filesystem root |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | list | Split path into parts |
Use `path` as the inputs for this operation.
Effects: pure.
Split path into parts.
*> host_path_split path=`path`*
Return *[Split path into parts](> host_path_split path=`path`)*.
## file_name
+ `path`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| path | text | required | Path relative to the granted filesystem root |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | Final file name of path |
Use `path` as the inputs for this operation.
Effects: pure.
Final file name of path.
*> host_path_file_name path=`path`*
Return *[Final file name of path](> host_path_file_name path=`path`)*.
## parent
+ `path`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| path | text | required | Path relative to the granted filesystem root |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | Parent directory of path |
Use `path` as the inputs for this operation.
Effects: pure.
Parent directory of path.
*> host_path_parent path=`path`*
Return *[Parent directory of path](> host_path_parent path=`path`)*.
## extension
+ `path`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| path | text | required | Path relative to the granted filesystem root |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | File extension of path |
Use `path` as the inputs for this operation.
Effects: pure.
File extension of path.
*> host_path_extension path=`path`*
Return *[File extension of path](> host_path_extension path=`path`)*.
## normalize
+ `path`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| path | text | required | Path relative to the granted filesystem root |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | Normalize path (dot segments) |
Use `path` as the inputs for this operation.
Effects: pure.
Normalize path (dot segments).
*> host_path_normalize path=`path`*
Return *[Normalize path (dot segments)](> host_path_normalize path=`path`)*.
## is_absolute
+ `path`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| path | text | required | Path relative to the granted filesystem root |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | bool | Whether path is absolute |
Use `path` as the inputs for this operation.
Effects: pure.
Whether path is absolute.
*> host_path_is_absolute path=`path`*
Return *[Whether path is absolute](> host_path_is_absolute path=`path`)*.
## relative
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| path | text | required | Path within the granted filesystem root |
| base | text | required | Base directory for relative path calculation |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | text | Compute a lexical path relative to base; both arguments must share absolute/relative form |
Use `path`, `base` as the inputs for this operation.
Effects: pure.
Compute a lexical path relative to base; both arguments must share absolute/relative form. No disk access.
Return *[Compute a lexical path relative to base; both arguments must share absolute/relative form](> host_path_relative path=`path` base=`base`)*.
## with_extension
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| path | text | required | Path within the granted filesystem root |
| extension | text | required | New extension, with or without a leading dot |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | text | Replace the last extension; empty extension removes it |
Use `path`, `extension` as the inputs for this operation.
Effects: pure.
Call this function directly:
```sh
marqdo call lib/path.mq.md with_extension 'path="notes/draft.txt"' 'extension="md"' --effects none --json
```
Replace the last extension; empty extension removes it.
Return *[Replace the last extension; empty extension removes it](> host_path_with_extension path=`path` extension=`extension`)*.
+58 -6
View File
@@ -6,30 +6,82 @@ description: Load optional native ABI plugins (.dll / .so / .dylib)
Load optional native ABI plugins (.dll / .so / .dylib).
Locate and load native capabilities.
Behavior and limits: An empty list means no plugin is loaded in this process. Loading requires plugin.call. Prefer the relevant domain index for normal work; plugins are native-only.
This single source file is the usage and development manual. Import it directly, or use marqdo call with a function heading below. Parameter tables give types and defaults; required parameters must be supplied. Return tables are progressive contracts; prose describes failure and limits.
Implementation: [src/host/plugin.rs](../src/host/plugin.rs)
For development, keep EN/ZH behavior aligned and compose public libraries first. Add host primitives only at OS or algorithm boundaries and declare their effects. Run marqdo check --narrative-ratio on this file and the real workflows in tests/stdlib_tasks.rs after edits.
## load
+ `path`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| path | text | required | Path relative to the granted filesystem root |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Load a native plugin from path |
Use `path` as the inputs for this operation.
Effects: plugin.call.
Load a native plugin from path.
Caller: [plugin.load] path=`so`
*> host_plugin_load path=`path`*
Return *[Load a native plugin from path](> host_plugin_load path=`path`)*.
## unload
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Unload the current native plugin |
Effects: plugin.call.
Unload the current native plugin.
*> host_plugin_unload*
Return *[Unload the current native plugin](host_plugin_unload())*.
## list
| 返回 | 类型 | 说明 |
|---|---|---|
| result | list | List loaded native plugins |
Effects: pure.
Call this function directly:
```sh
marqdo call lib/plugin.mq.md list --effects none --json
```
List loaded native plugins.
*> host_plugin_list*
Return names loaded in this host process. Listing does not load a plugin, and a new process may have an empty list.
Return *[List loaded native plugins](host_plugin_list())*.
## native_path
+ `name`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| name | text | required | Installed extension identifier, for example agent |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Resolve installed or local native plugin path (e.g |
Use `name` as the inputs for this operation.
Effects: plugin.call.
Resolve installed or local native plugin path (e.g. agent).
*> host_ext_native_path name=`name`*
Return *[Resolve installed or local native plugin path (e.g](> host_ext_native_path name=`name`)*.
+88 -17
View File
@@ -6,46 +6,117 @@ description: Regular expressions (Mid M1). Unicode; no backreferences.
Regular expressions. Unicode; no backreferences. Prefer lib/text for literal replace.
Match Unicode regular expressions.
Behavior and limits: The engine has no backreferences. Current find functions return whole matches; capture groups and replacement callbacks are not promised. Literal replacement belongs in text.
This single source file is the usage and development manual. Import it directly, or use marqdo call with a function heading below. Parameter tables give types and defaults; required parameters must be supplied. Return tables are progressive contracts; prose describes failure and limits.
Implementation: [src/host/re.rs](../src/host/re.rs)
For development, keep EN/ZH behavior aligned and compose public libraries first. Add host primitives only at OS or algorithm boundaries and declare their effects. Run marqdo check --narrative-ratio on this file and the real workflows in tests/stdlib_tasks.rs after edits.
## is_match
+ `text`
+ `pattern`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| text | text | required | Text supplied by the caller |
| pattern | text | required | Regular expression supported by the regex host |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | bool | Whether text matches pattern |
Use `text`, `pattern` as the inputs for this operation.
Effects: pure.
Whether text matches pattern.
Caller: [re.is_match] text=`s` pattern="a+"
*> host_re_is_match text=`text` pattern=`pattern`*
Return *[Whether text matches pattern](> host_re_is_match text=`text` pattern=`pattern`)*.
## find
+ `text`
+ `pattern`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| text | text | required | Text supplied by the caller |
| pattern | text | required | Regular expression supported by the regex host |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | First match of pattern in text, or None |
Use `text`, `pattern` as the inputs for this operation.
Effects: pure.
First match of pattern in text, or None.
*> host_re_find text=`text` pattern=`pattern`*
Return *[First match of pattern in text, or None](> host_re_find text=`text` pattern=`pattern`)*.
## find_all
+ `text`
+ `pattern`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| text | text | required | Text supplied by the caller |
| pattern | text | required | Regular expression supported by the regex host |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | list | All matches of pattern in text |
Use `text`, `pattern` as the inputs for this operation.
Effects: pure.
Call this function directly:
```sh
marqdo call lib/re.mq.md find_all 'text="a12 b34"' 'pattern="[0-9]+"' --effects none --json
```
All matches of pattern in text.
*> host_re_find_all text=`text` pattern=`pattern`*
Return *[All matches of pattern in text](> host_re_find_all text=`text` pattern=`pattern`)*.
## replace
+ `text`
+ `pattern`
+ `with`
+ `count`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| text | text | required | Text supplied by the caller |
| pattern | text | required | Regular expression supported by the regex host |
| with | any | required | Replacement text applied to matched spans |
| count | any | None | Maximum replacement count; None uses the documented default |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | Replace matches of pattern in text with with; optional count limits replacements (None = all) |
Use `text`, `pattern`, `with`, `count`=None as the inputs for this operation.
Effects: pure.
Replace matches of pattern in text with with; optional count limits replacements (None = all).
*> host_re_replace text=`text` pattern=`pattern` with=`with` count=`count`*
Return *[Replace matches of pattern in text with with; optional count limits replacements (None = all)](> host_re_replace text=`text` pattern=`pattern` with=`with` count=`count`)*.
## split
+ `text`
+ `pattern`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| text | text | required | Text supplied by the caller |
| pattern | text | required | Regular expression supported by the regex host |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | list | Split text on pattern |
Use `text`, `pattern` as the inputs for this operation.
Effects: pure.
Split text on pattern.
*> host_re_split text=`text` pattern=`pattern`*
Return *[Split text on pattern](> host_re_split text=`text` pattern=`pattern`)*.
+101
View File
@@ -0,0 +1,101 @@
---
markup: occlusion
---
Recoverable outcomes use one ordinary record: ok/value/error. A failure's error
contains code/message/operation. Inspect ok before consuming value. Host policy
checks still apply; a Result wrapper never authorizes an effect.
Compose recoverable outcomes with one data contract.
Behavior and limits: Check ok before value; HTTP status and child exit code remain domain-level results; errors have code/message/operation. Use try_ operations to recover known IO/parse failures. Result construction does not catch arbitrary runtime errors or grant permission.
This single source file is the usage and development manual. Import it directly, or use marqdo call with a function heading below. Parameter tables give types and defaults; required parameters must be supplied. Return tables are progressive contracts; prose describes failure and limits.
Implementation: [src/host/result.rs](../src/host/result.rs)
For development, keep EN/ZH behavior aligned and compose public libraries first. Add host primitives only at OS or algorithm boundaries and declare their effects. Run marqdo check --narrative-ratio on this file and the real workflows in tests/stdlib_tasks.rs after edits.
## ok
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| value | any | required | Successful operation value, including None |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | map | Successful Result |
Use `value` as the inputs for this operation.
Delegate to ok with the supplied inputs, preserving its result and failure behavior.
Effects: pure.
`out` =
| ok | value | error |
|----|-------|-------|
| True | `value` | None |
Return *out*.
## error
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| code | text | required | Stable machine-readable category |
| message | text | required | Human-readable explanation |
| operation | text | "application" | Operation that failed |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | map | Failed Result |
Use `code`, `message`, `operation`="application" as the inputs for this operation.
Delegate to error with the supplied inputs, preserving its result and failure behavior.
Effects: pure.
`failure` =
| code | message | operation |
|------|---------|-----------|
| `code` | `message` | `operation` |
`out` =
| ok | value | error |
|----|-------|-------|
| False | None | `failure` |
Return *out*.
## value_or
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| result | map | required | Result from a recoverable operation |
| default | any | None | Explicit fallback on failure |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | Successful value or fallback |
Use `result`, `default`=None as the inputs for this operation.
Effects: pure.
Call this function directly:
```sh
marqdo call lib/result.mq.md value_or 'result={"ok":false,"value":null,"error":{"code":"missing","message":"absent","operation":"example"}}' 'default="fallback"' --effects none --json
```
Read value only when ok is true, including a successful None. Use the fallback only on failure; zero and empty text remain valid values.
1. [operation succeeded](access(`result`, "ok"))
Return *[successful value](access(result, "value"))*.
2. *
Return *default*.
+42 -4
View File
@@ -6,18 +6,56 @@ description: Cryptographic tokens (Mid M3). Do not use math.random for secrets.
Cryptographic tokens. Do not use math.random for secrets.
Generate cryptographically random tokens.
Behavior and limits: n counts input bytes. Do not use math.random for credentials. Browser entropy depends on the runtime bridge; do not silently substitute a pseudo-random generator.
This single source file is the usage and development manual. Import it directly, or use marqdo call with a function heading below. Parameter tables give types and defaults; required parameters must be supplied. Return tables are progressive contracts; prose describes failure and limits.
Implementation: [src/host/secrets.rs](../src/host/secrets.rs)
For development, keep EN/ZH behavior aligned and compose public libraries first. Add host primitives only at OS or algorithm boundaries and declare their effects. Run marqdo check --narrative-ratio on this file and the real workflows in tests/stdlib_tasks.rs after edits.
## token_hex
+ `n`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| n | any | None | Requested byte count; None uses the helper default |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | Byte length n (default 16) |
Use `n`=None as the inputs for this operation.
Effects: random.read.
Call this function directly:
```sh
marqdo call lib/secrets.mq.md token_hex n=16 --effects random.read --json
```
Byte length n (default 16). Returns lowercase hex of length 2*n.
Caller: [secrets.token_hex] n=16
*> host_secrets_token_hex n=`n`*
Return *[Byte length n (default 16)](> host_secrets_token_hex n=`n`)*.
## token_urlsafe
+ `n`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| n | any | None | Requested byte count; None uses the helper default |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | Byte length n (default 16) |
Use `n`=None as the inputs for this operation.
Effects: random.read.
Byte length n (default 16). URL-safe Base64 without padding.
*> host_secrets_token_urlsafe n=`n`*
Return *[Byte length n (default 16)](> host_secrets_token_urlsafe n=`n`)*.
+55 -6
View File
@@ -6,25 +6,74 @@ description: Thin mean / median / sample stdev (Mid2 M10). Not a dataframe libra
Thin numeric summaries. Not a dataframe library.
Compute small descriptive statistics.
Behavior and limits: mean/median require nonempty numeric lists. This is not a dataframe or numerical array runtime; ext/linalg owns matrix operations.
This single source file is the usage and development manual. Import it directly, or use marqdo call with a function heading below. Parameter tables give types and defaults; required parameters must be supplied. Return tables are progressive contracts; prose describes failure and limits.
Implementation: [src/host/stats.rs](../src/host/stats.rs)
For development, keep EN/ZH behavior aligned and compose public libraries first. Add host primitives only at OS or algorithm boundaries and declare their effects. Run marqdo check --narrative-ratio on this file and the real workflows in tests/stdlib_tasks.rs after edits.
## mean
+ `list`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| list | list | required | Input list; updates return a new list |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | Arithmetic mean of list |
Use `list` as the inputs for this operation.
Effects: pure.
Call this function directly:
```sh
marqdo call lib/stats.mq.md mean 'list=[1,2,3]' --effects none --json
```
Arithmetic mean of list.
Caller: [stats.mean] list=`xs`
*> host_stats_mean list=`list`*
Return *[Arithmetic mean of list](> host_stats_mean list=`list`)*.
## median
+ `list`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| list | list | required | Input list; updates return a new list |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | Median of list |
Use `list` as the inputs for this operation.
Effects: pure.
Median of list.
*> host_stats_median list=`list`*
Return *[Median of list](> host_stats_median list=`list`)*.
## stdev
+ `list`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| list | list | required | Input list; updates return a new list |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | Sample standard deviation; needs at least two values |
Use `list` as the inputs for this operation.
Effects: pure.
Sample standard deviation; needs at least two values.
*> host_stats_stdev list=`list`*
Return *[Sample standard deviation; needs at least two values](> host_stats_stdev list=`list`)*.
+136 -16
View File
@@ -6,45 +6,165 @@ description: Concurrent subtasks — file, function, or foreign code
Concurrent subtasks: file, function, or foreign code.
Run and observe concurrent work with explicit ownership.
Behavior and limits: File batches inherit parent caps and root. Each Result.ok reports completion of the wait protocol; inspect value.code for child exit success. wait_timeout keeps its handle unless cancel is requested. OS tasks can be killed/reaped; function-thread cancellation is logical only.
This single source file is the usage and development manual. Import it directly, or use marqdo call with a function heading below. Parameter tables give types and defaults; required parameters must be supplied. Return tables are progressive contracts; prose describes failure and limits.
Relative IO paths use --fs-root, or the called file directory when omitted. Writes require explicit fs.write grants, subprocesses require process.exec, and pure transforms require no IO grant.
Implementation: [src/host/subtask.rs](../src/host/subtask.rs)、[src/host/task_ops.rs](../src/host/task_ops.rs)
For development, keep EN/ZH behavior aligned and compose public libraries first. Add host primitives only at OS or algorithm boundaries and declare their effects. Run marqdo check --narrative-ratio on this file and the real workflows in tests/stdlib_tasks.rs after edits.
## spawn
+ `path`=None
+ `fn`=None
+ `args`=None
+ `code`=None
+ `lang`=None
+ `source`=None
+ `stdin`=None
+ `quiet`=True
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| path | any | None | Path relative to the granted filesystem root |
| fn | any | None | Marqdo function target used instead of a file task |
| args | any | None | Arguments supplied to the selected task |
| code | any | None | Bound code-fence value; supply lang and source for inline text |
| lang | any | None | Registered interpreter language identifier, such as python |
| source | any | None | Source text to run with the selected interpreter |
| stdin | any | None | Text written to the child process standard input |
| quiet | bool | True | Whether to suppress child output while retaining its result |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | Start a subtask |
Use `path`=None, `fn`=None, `args`=None, `code`=None, `lang`=None, `source`=None, `stdin`=None, `quiet`=True as the inputs for this operation.
Effects: process.exec.
Start a subtask. File children are silent by default (quiet=True: piped capture). Set quiet=False to inherit parent stdout/stderr. File wait returns {code, value} plus optional stdout/stderr tails when quiet-captured. value is the child main return (not stdout).
Caller: [subtask.spawn] path="child.mq.md"
*> host_subtask_spawn path=`path` fn=`fn` args=`args` code=`code` lang=`lang` source=`source` stdin=`stdin` quiet=`quiet`*
Return *[Start a subtask](> host_subtask_spawn path=`path` fn=`fn` args=`args` code=`code` lang=`lang` source=`source` stdin=`stdin` quiet=`quiet`)*.
## poll
+ `id`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| id | any | required | Identifier returned by the corresponding create/spawn operation |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Non-blocking status for subtask id |
Use `id` as the inputs for this operation.
Effects: process.exec.
Non-blocking status for subtask id.
*> host_subtask_poll id=`id`*
Return *[Non-blocking status for subtask id](> host_subtask_poll id=`id`)*.
## wait
+ `id`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| id | any | required | Identifier returned by the corresponding create/spawn operation |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Block until subtask id finishes |
Use `id` as the inputs for this operation.
Effects: process.exec.
Block until subtask id finishes.
*> host_subtask_join id=`id`*
Return *[Block until subtask id finishes](> host_subtask_join id=`id`)*.
## kill
+ `id`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| id | any | required | Identifier returned by the corresponding create/spawn operation |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Kill subtask id |
Use `id` as the inputs for this operation.
Effects: process.exec.
Kill subtask id.
*> host_subtask_kill id=`id`*
Return *[Kill subtask id](> host_subtask_kill id=`id`)*.
## wait_all
| 返回 | 类型 | 说明 |
|---|---|---|
| result | list | Wait until every spawned subtask finishes |
Effects: process.exec.
Wait until every spawned subtask finishes.
*> host_subtask_wait_all*
Return *[Wait until every spawned subtask finishes](host_subtask_wait_all())*.
## wait_timeout
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| id | number | required | Identifier returned by the corresponding create/spawn operation |
| timeout_ms | number | 30000 | Timeout in milliseconds; inspect the operation result after waiting |
| cancel | bool | False | Whether a timeout also cancels the outstanding task |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | map | Wait as Result; timeout retains the handle unless cancel=True |
Use `id`, `timeout_ms`=30000, `cancel`=False as the inputs for this operation.
Effects: process.exec.
Wait as Result; timeout retains the handle unless cancel=True. Cancellation reaps process tasks; function-thread cancellation is logical only.
Return *[Wait as Result; timeout retains the handle unless cancel=True](> host_subtask_wait_timeout id=`id` timeout_ms=`timeout_ms` cancel=`cancel`)*.
## cancel_all
| 返回 | 类型 | 说明 |
|------|------|------|
| result | number | Cancel all subtasks, reaping process tasks; return count |
Effects: process.exec.
Cancel all subtasks, reaping process tasks; return count. Function threads only support logical cancellation.
Return *[Cancel all subtasks, reaping process tasks; return count](> host_subtask_cancel_all )*.
## run_many
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| tasks | list | required | Ordered file task records containing path and optional args |
| limit | number | 4 | Maximum simultaneous file tasks, from 1 through 64 |
| timeout_ms | number | 30000 | Timeout in milliseconds; inspect the operation result after waiting |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | list | Run path/args file tasks with bounded concurrency; return ordered Results |
Use `tasks`, `limit`=4, `timeout_ms`=30000 as the inputs for this operation.
Effects: process.exec.
Call this function directly:
```sh
marqdo call lib/subtask.mq.md run_many 'tasks=[{"path":"examples/stdlib-handbook/worker.mq.md"}]' limit=2 --effects process.exec --fs-root . --json
```
Run path/args file tasks with bounded concurrency; return ordered Results. Timed-out children are killed and reaped; at most 10000 tasks, 64 workers; inherit parent caps and filesystem root.
Return *[Run path/args file tasks with bounded concurrency; return ordered Results](> host_subtask_run_many tasks=`tasks` limit=`limit` timeout_ms=`timeout_ms`)*.
+145 -22
View File
@@ -6,76 +6,188 @@ description: English system wrappers (load_dotenv accepts optional path via host
English system wrappers (load_dotenv accepts optional path via host alias)
Inspect execution metadata and interact with the host system.
Behavior and limits: Metadata describes the entry artifact. module_source is entry source, not the imported library. exec needs process.exec; environment operations declare separate effects.
This single source file is the usage and development manual. Import it directly, or use marqdo call with a function heading below. Parameter tables give types and defaults; required parameters must be supplied. Return tables are progressive contracts; prose describes failure and limits.
Implementation: [src/host/sys.rs](../src/host/sys.rs)
For development, keep EN/ZH behavior aligned and compose public libraries first. Add host primitives only at OS or algorithm boundaries and declare their effects. Run marqdo check --narrative-ratio on this file and the real workflows in tests/stdlib_tasks.rs after edits.
## env_get
+ `name`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| name | text | required | Environment variable name |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Get environment variable name |
Use `name` as the inputs for this operation.
Effects: environment.read.
Get environment variable name.
*> host_env_get name=`name`*
Return *[Get environment variable name](> host_env_get name=`name`)*.
## env_set
+ `name`
+ `value`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| name | text | required | Environment variable name |
| value | any | required | Value to transform or store, without mutating the input |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Set environment variable name to value |
Use `name`, `value` as the inputs for this operation.
Effects: environment.write.
Set environment variable name to value.
*> host_env_set name=`name` value=`value`*
Return *[Set environment variable name to value](> host_env_set name=`name` value=`value`)*.
## load_dotenv
+ `path`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| path | any | None | Path relative to the granted filesystem root |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Load `.env` (optional named arg `path=`) |
Use `path`=None as the inputs for this operation.
Effects: environment.write,fs.read.
Load `.env` (optional named arg `path=`). Existing process env is not overridden.
*> host_dotenv_load path=`path`*
Return *[Load .env (optional named arg path=)](> host_dotenv_load path=`path`)*.
## args
| 返回 | 类型 | 说明 |
|---|---|---|
| result | list | Process argv list |
Effects: pure.
Process argv list.
*> host_args*
Return *[Process argv list](host_args())*.
## cwd
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | Current working directory |
Effects: pure.
Current working directory.
*> host_cwd*
Return *[Current working directory](host_cwd())*.
## meta
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Bound Artifact Metadata from the entry `.mq.md` (map) |
Effects: pure.
Call this function directly:
```sh
marqdo call lib/sys.mq.md meta --effects none --json
```
Bound Artifact Metadata from the entry `.mq.md` (map). See `doc/design/binding.md`.
*> host_meta*
Return *[Bound Artifact Metadata from the entry .mq.md (map)](host_meta())*.
## meta_get
+ `key`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| key | text | required | Field name or key required by this operation |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Lookup one metadata key; missing → None |
Use `key` as the inputs for this operation.
Effects: pure.
Lookup one metadata key; missing → None.
*> host_meta_get key=`key`*
Return *[Lookup one metadata key; missing → None](> host_meta_get key=`key`)*.
## artifact_kind
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Classify entry Artifact Metadata: `web` / `endpoint` / `prompt` / `other`, or None if no `type`/`类型` |
Effects: pure.
Classify entry Artifact Metadata: `web` / `endpoint` / `prompt` / `other`, or None if no `type`/`类型`. ADR 0007.
*> host_artifact_kind*
Return *[Classify entry Artifact Metadata: web / endpoint / prompt / other, or None if no type/类型](host_artifact_kind())*.
## module_source
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | Entry `.mq.md` source text (for document-as-prompt) |
Effects: pure.
Entry `.mq.md` source text (for document-as-prompt). Empty string if unset.
*> host_module_source*
Return *[Entry .mq.md source text (for document-as-prompt)](host_module_source())*.
## exit
+ `code`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| code | any | required | Process exit status; zero means success |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Exit process with code |
Use `code` as the inputs for this operation.
Effects: process.control.
Exit process with code.
*> host_exit code=`code`*
Return *[Exit process with code](> host_exit code=`code`)*.
## exec
+ `cmd`
+ `args`=None
+ `capture`=False
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| cmd | any | required | Executable command or interpreter override |
| args | any | None | Argument list passed to the called command or function |
| capture | any | False | Whether to return command output instead of forwarding it |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Run a process |
Use `cmd`, `args`=None, `capture`=False as the inputs for this operation.
Effects: process.exec.
Run a process. Default return is the exit code (int).
@@ -83,11 +195,22 @@ With `capture=True`, return a map `{code, stdout, stderr}` (stdout/stderr may be
Inside `**…**` prefer bare `args=args` (variable); `` args=`args` `` is also accepted.
*> host_exec cmd=`cmd` args=`args` capture=`capture`*
Return *[Run a process](> host_exec cmd=`cmd` args=`args` capture=`capture`)*.
## stream_publish
+ `event`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| event | any | required | Structured event to publish to the active stream |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Publish a stream event map onto the process EventBus (`marqdo view` SSE) |
Use `event` as the inputs for this operation.
Effects: output.write.
Publish a stream event map onto the process EventBus (`marqdo view` SSE). No-op when nothing is subscribed.
*> host_stream_publish event=`event`*
Return *[Publish a stream event map onto the process EventBus (marqdo view SSE)](> host_stream_publish event=`event`)*.
+992 -102
View File
File diff suppressed because it is too large. Load diff
+171 -34
View File
@@ -6,93 +6,230 @@ description: Text helpers (Mid M4). Literal replace — use lib/re for regex.
Small text helpers. Prefer these over hand-rolled splits; regex belongs in lib/re.
Clean and combine Unicode text.
Behavior and limits: Use re for patterns and bytes for arbitrary binary. split and join use exact separators; no implicit document parsing.
This single source file is the usage and development manual. Import it directly, or use marqdo call with a function heading below. Parameter tables give types and defaults; required parameters must be supplied. Return tables are progressive contracts; prose describes failure and limits.
Implementation: [src/host/text_ops.rs](../src/host/text_ops.rs)
For development, keep EN/ZH behavior aligned and compose public libraries first. Add host primitives only at OS or algorithm boundaries and declare their effects. Run marqdo check --narrative-ratio on this file and the real workflows in tests/stdlib_tasks.rs after edits.
## str_trim
+ `s`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| s | text | required | Input text |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | Trim ends of string s |
Use `s` as the inputs for this operation.
Effects: pure.
Call this function directly:
```sh
marqdo call lib/text.mq.md str_trim 's=" readable text "' --effects none --json
```
Trim ends of string s.
*> trim `s`*
Return *[Trim](trim(`s`))*.
## str_split
+ `s`
+ `sep`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| s | text | required | Input text |
| sep | text | required | Text separator used for splitting or joining |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | list | Split string s on separator sep |
Use `s`, `sep` as the inputs for this operation.
Effects: pure.
Split string s on separator sep.
*> split value=`s` sep=`sep`*
Return *[Split](split(value=`s`, sep=`sep`))*.
## str_join
+ `xs`
+ `sep`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| xs | any | required | Input list or collection, as required by this operation |
| sep | text | required | Text separator used for splitting or joining |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | Join list xs with separator sep |
Use `xs`, `sep` as the inputs for this operation.
Effects: pure.
Join list xs with separator sep.
*> join value=`xs` sep=`sep`*
Return *[Join](join(value=`xs`, sep=`sep`))*.
## contains
+ `text`
+ `sub`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| text | text | required | Text supplied by the caller |
| sub | any | required | Substring to search for |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | bool | Whether text contains substring sub |
Use `text`, `sub` as the inputs for this operation.
Effects: pure.
Whether text contains substring sub.
Caller: [text.contains] text="hello" sub="ell"
*> host_text_contains text=`text` sub=`sub`*
Return *[Whether text contains substring sub](> host_text_contains text=`text` sub=`sub`)*.
## starts_with
+ `text`
+ `prefix`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| text | text | required | Text supplied by the caller |
| prefix | text | required | Prefix added to the generated name or tested against text |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | bool | Whether text starts with prefix |
Use `text`, `prefix` as the inputs for this operation.
Effects: pure.
Whether text starts with prefix.
*> host_text_starts_with text=`text` prefix=`prefix`*
Return *[Whether text starts with prefix](> host_text_starts_with text=`text` prefix=`prefix`)*.
## ends_with
+ `text`
+ `suffix`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| text | text | required | Text supplied by the caller |
| suffix | any | required | Text suffix to test |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | bool | Whether text ends with suffix |
Use `text`, `suffix` as the inputs for this operation.
Effects: pure.
Whether text ends with suffix.
*> host_text_ends_with text=`text` suffix=`suffix`*
Return *[Whether text ends with suffix](> host_text_ends_with text=`text` suffix=`suffix`)*.
## replace
+ `text`
+ `old`
+ `new`
+ `count`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| text | text | required | Text supplied by the caller |
| old | any | required | Exact substring to replace |
| new | any | required | Replacement text |
| count | any | None | Maximum replacement count; None uses the documented default |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | Literal replace in text: replace old with new, optional count |
Use `text`, `old`, `new`, `count`=None as the inputs for this operation.
Effects: pure.
Literal replace in text: replace old with new, optional count.
*> host_text_replace text=`text` old=`old` new=`new` count=`count`*
Return *[Literal replace in text: replace old with new, optional count](> host_text_replace text=`text` old=`old` new=`new` count=`count`)*.
## to_upper
+ `text`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| text | text | required | Text supplied by the caller |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | Uppercase text |
Use `text` as the inputs for this operation.
Effects: pure.
Uppercase text.
*> host_text_to_upper text=`text`*
Return *[Uppercase text](> host_text_to_upper text=`text`)*.
## to_lower
+ `text`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| text | text | required | Text supplied by the caller |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | Lowercase text |
Use `text` as the inputs for this operation.
Effects: pure.
Lowercase text.
*> host_text_to_lower text=`text`*
Return *[Lowercase text](> host_text_to_lower text=`text`)*.
## repeat
+ `text`
+ `n`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| text | text | required | Text supplied by the caller |
| n | number | required | Number of repetitions |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | Repeat text n times |
Use `text`, `n` as the inputs for this operation.
Effects: pure.
Repeat text n times.
*> host_text_repeat text=`text` n=`n`*
Return *[Repeat text n times](> host_text_repeat text=`text` n=`n`)*.
## pad
+ `text`
+ `width`
+ `fill`=None
+ `align`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| text | text | required | Text supplied by the caller |
| width | number | required | Target padded character width |
| fill | any | None | Single padding character |
| align | any | None | Padding alignment: left, right or center |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | Pad text to width with fill and align (left / right / center) |
Use `text`, `width`, `fill`=None, `align`=None as the inputs for this operation.
Effects: pure.
Pad text to width with fill and align (left / right / center).
*> host_text_pad text=`text` width=`width` fill=`fill` align=`align`*
Return *[Pad text to width with fill and align (left / right / center)](> host_text_pad text=`text` width=`width` fill=`fill` align=`align`)*.
+71 -10
View File
@@ -6,39 +6,100 @@ description: English time wrappers
Unix time, format, parse, and sleep helpers.
Format Unix time and control elapsed waits.
Behavior and limits: now reads the clock; sleep controls execution and is clamped in capture. Calendar arithmetic and IANA rules live in datetime.
This single source file is the usage and development manual. Import it directly, or use marqdo call with a function heading below. Parameter tables give types and defaults; required parameters must be supplied. Return tables are progressive contracts; prose describes failure and limits.
Implementation: [src/host/time.rs](../src/host/time.rs)
For development, keep EN/ZH behavior aligned and compose public libraries first. Add host primitives only at OS or algorithm boundaries and declare their effects. Run marqdo check --narrative-ratio on this file and the real workflows in tests/stdlib_tasks.rs after edits.
## now_unix
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | Current Unix time in seconds |
Effects: time.read.
Current Unix time in seconds.
Caller: [time.now_unix]
*> host_now_unix*
Return *[Current Unix time in seconds](host_now_unix())*.
## now_ms
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | Current Unix time in milliseconds |
Effects: time.read.
Current Unix time in milliseconds.
*> host_now_ms*
Return *[Current Unix time in milliseconds](host_now_ms())*.
## format
+ `unix`
+ `pattern`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| unix | number | required | Unix timestamp in seconds |
| pattern | text | required | strftime date/time format string |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | Format unix seconds with pattern |
Use `unix`, `pattern` as the inputs for this operation.
Effects: pure.
Call this function directly:
```sh
marqdo call lib/time.mq.md format unix=0 'pattern="%Y-%m-%d"' --effects none --json
```
Format unix seconds with pattern.
*> host_format_time unix=`unix` pattern=`pattern`*
Return *[Format unix seconds with pattern](> host_format_time unix=`unix` pattern=`pattern`)*.
## sleep_ms
+ `ms`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| ms | any | required | Duration or delay in milliseconds |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Sleep for ms milliseconds |
Use `ms` as the inputs for this operation.
Effects: process.control.
Sleep for ms milliseconds.
*> host_sleep_ms ms=`ms`*
Return *[Sleep for ms milliseconds](> host_sleep_ms ms=`ms`)*.
## parse
+ `text`
+ `pattern`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| text | text | required | Text supplied by the caller |
| pattern | text | required | strftime date/time format string |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | Parse text as time with pattern; returns unix seconds |
Use `text`, `pattern` as the inputs for this operation.
Effects: pure.
Parse text as time with pattern; returns unix seconds.
*> host_parse_time text=`text` pattern=`pattern`*
Return *[Parse text as time with pattern; returns unix seconds](> host_parse_time text=`text` pattern=`pattern`)*.
+67 -4
View File
@@ -1,16 +1,79 @@
---
markup: occlusion
title: lib/toml
description: Read-only TOML subset parse (Mid2 M8). Tables, scalars, arrays; no array-of-tables.
description: TOML parse/stringify with inline tables, multiline strings and arrays-of-tables. Dates become ISO text.
---
Read-only TOML subset. Prefer for config files; not a full TOML writer.
Read and write standard TOML configurations. Datetime scalars become ISO text; serialization does not preserve comments.
Read and write standard TOML configuration data.
Behavior and limits: Supports inline tables, multiline strings and arrays-of-tables. TOML dates become ISO text. Serialization rejects None and does not preserve original comments.
This single source file is the usage and development manual. Import it directly, or use marqdo call with a function heading below. Parameter tables give types and defaults; required parameters must be supplied. Return tables are progressive contracts; prose describes failure and limits.
Implementation: [src/host/toml_ops.rs](../src/host/toml_ops.rs)
For development, keep EN/ZH behavior aligned and compose public libraries first. Add host primitives only at OS or algorithm boundaries and declare their effects. Run marqdo check --narrative-ratio on this file and the real workflows in tests/stdlib_tasks.rs after edits.
## parse
+ `text`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| text | text | required | Text supplied by the caller |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Parse TOML text into maps/lists/scalars |
Use `text` as the inputs for this operation.
Effects: pure.
Parse TOML text into maps/lists/scalars.
Caller: [toml.parse] text=`cfg`
*> host_toml_parse text=`text`*
Return *[Parse TOML text into maps/lists/scalars](> host_toml_parse text=`text`)*.
## stringify
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| value | map | required | Value to transform or store, without mutating the input |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | text | Serialize a map as TOML, rejecting None and unsupported value kinds; does not preserve source comments |
Use `value` as the inputs for this operation.
Effects: pure.
Serialize a map as TOML, rejecting None and unsupported value kinds; does not preserve source comments.
Return *[Serialize a map as TOML, rejecting None and unsupported value kinds; does not preserve source comments](> host_toml_stringify value=`value`)*.
## try_parse
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| text | text | required | Text to read, transform or emit as described by this operation |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | map | Recoverable TOML parsing supports inline tables, multiline strings and arrays-of-tables; datetime scalars become ISO text |
Use `text` as the inputs for this operation.
Effects: pure.
Call this function directly:
```sh
marqdo call lib/toml.mq.md try_parse 'text="name="Marqdo""' --effects none --json
```
Recoverable TOML parsing supports inline tables, multiline strings and arrays-of-tables; datetime scalars become ISO text.
Return *[Recoverable TOML parsing supports inline tables, multiline strings and arrays-of-tables; datetime scalars become ISO text](> host_toml_try_parse text=`text`)*.
+55 -6
View File
@@ -6,25 +6,74 @@ description: Parse URLs and query strings (Mid2 M7). Segment encoding stays in n
Parse URLs and query strings. Segment encoding stays in net.url_encode.
Parse addresses and repeated query parameters.
Behavior and limits: Repeated query keys become lists; do not assume every map value is scalar. URL encoding is distinct from HTML escaping.
This single source file is the usage and development manual. Import it directly, or use marqdo call with a function heading below. Parameter tables give types and defaults; required parameters must be supplied. Return tables are progressive contracts; prose describes failure and limits.
Implementation: [src/host/url_ops.rs](../src/host/url_ops.rs)
For development, keep EN/ZH behavior aligned and compose public libraries first. Add host primitives only at OS or algorithm boundaries and declare their effects. Run marqdo check --narrative-ratio on this file and the real workflows in tests/stdlib_tasks.rs after edits.
## parse
+ `text`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| text | text | required | Text supplied by the caller |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Parse URL text into scheme, userinfo, host, port, path, query, fragment |
Use `text` as the inputs for this operation.
Effects: pure.
Parse URL text into scheme, userinfo, host, port, path, query, fragment.
Caller: [url.parse] text=`u`
*> host_url_parse text=`text`*
Return *[Parse URL text into scheme, userinfo, host, port, path, query, fragment](> host_url_parse text=`text`)*.
## query_parse
+ `text`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| text | text | required | Text supplied by the caller |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | Parse a=1&b=2 into a map; repeated keys become a list |
Use `text` as the inputs for this operation.
Effects: pure.
Call this function directly:
```sh
marqdo call lib/url.mq.md query_parse 'text="tag=a&tag=b&name=Marqdo"' --effects none --json
```
Parse a=1&b=2 into a map; repeated keys become a list.
*> host_url_query_parse text=`text`*
Return *[Parse a=1&b=2 into a map; repeated keys become a list](> host_url_query_parse text=`text`)*.
## query_stringify
+ `map`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| map | map | required | Input string-keyed map |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | Build a query string from map |
Use `map` as the inputs for this operation.
Effects: pure.
Build a query string from map.
*> host_url_query_stringify map=`map`*
Return *[Build a query string from map](> host_url_query_stringify map=`map`)*.
+23 -1
View File
@@ -6,10 +6,32 @@ description: UUID v4 (Mid M6). Cryptographic random via getrandom.
Random UUID helpers. Prefer this over rolling your own ids.
Create UUID v4 identifiers.
Behavior and limits: Identifiers use system entropy and are not reproducible constants. Do not treat UUID strings as authorization tokens.
This single source file is the usage and development manual. Import it directly, or use marqdo call with a function heading below. Parameter tables give types and defaults; required parameters must be supplied. Return tables are progressive contracts; prose describes failure and limits.
Implementation: [src/host/uuid_ops.rs](../src/host/uuid_ops.rs)
For development, keep EN/ZH behavior aligned and compose public libraries first. Add host primitives only at OS or algorithm boundaries and declare their effects. Run marqdo check --narrative-ratio on this file and the real workflows in tests/stdlib_tasks.rs after edits.
## v4
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | New UUID version 4 string |
Effects: random.read.
Call this function directly:
```sh
marqdo call lib/uuid.mq.md v4 --effects random.read --json
```
New UUID version 4 string.
Caller: [uuid.v4]
*> host_uuid_v4*
Return *[New UUID version 4 string](host_uuid_v4())*.
+101 -20
View File
@@ -6,52 +6,133 @@ description: Persist run output in .mq.md (Jupyter-style writeback)
Persist run output in .mq.md (Jupyter-style writeback)
Read and maintain persisted execution-output slots.
Behavior and limits: record/get default to the current entry call site. Named slots isolate outputs. This API does not edit arbitrary document sections; use document for structural transforms.
This single source file is the usage and development manual. Import it directly, or use marqdo call with a function heading below. Parameter tables give types and defaults; required parameters must be supplied. Return tables are progressive contracts; prose describes failure and limits.
Relative IO paths use --fs-root, or the called file directory when omitted. Writes require explicit fs.write grants, subprocesses require process.exec, and pure transforms require no IO grant.
Implementation: [src/host/writeback.rs](../src/host/writeback.rs)
For development, keep EN/ZH behavior aligned and compose public libraries first. Add host primitives only at OS or algorithm boundaries and declare their effects. Run marqdo check --narrative-ratio on this file and the real workflows in tests/stdlib_tasks.rs after edits.
## record
+ `value`
+ `at_end`=False
+ `key`=None
+ `line`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| value | any | required | Value to transform or store, without mutating the input |
| at_end | bool | False | Whether to append to the end of the target block |
| key | any | None | Field name or key required by this operation |
| line | any | None | Text line to add to the managed writeback block |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Write `value` into the entry file |
Use `value`, `at_end`=False, `key`=None, `line`=None as the inputs for this operation.
Effects: fs.write.
Write `value` into the entry file. Image-like values (`.png` / `.svg` / … or `data:image/…`) become `![marqdo-out](…)` (or `![marqdo-out key](…)`); other values use `<!-- marqdo-out … -->`. Default: insert or replace the block immediately below the call; `at_end=true` replaces the unkeyed EOF block. With `key=` (e.g. `ok` / `error`), replace or create that named slot only — slots do not overwrite each other. Optional `line=` anchors the block under that source line (needed when writing from a subtask).
*> host_writeback_record value=`value` at_end=`at_end` key=`key` line=`line`*
Return *[Write value into the entry file](> host_writeback_record value=`value` at_end=`at_end` key=`key` line=`line`)*.
## get
+ `at_end`=False
+ `key`=None
+ `line`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| at_end | bool | False | Whether to append to the end of the target block |
| key | any | None | Field name or key required by this operation |
| line | any | None | Text line to add to the managed writeback block |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Read persisted output for the current call site (adjacent unkeyed block), the unkeyed EOF block when `at_end=true`, or a named slot when `key=` is set |
Use `at_end`=False, `key`=None, `line`=None as the inputs for this operation.
Effects: fs.read.
Read persisted output for the current call site (adjacent unkeyed block), the unkeyed EOF block when `at_end=true`, or a named slot when `key=` is set.
*> host_writeback_get at_end=`at_end` key=`key` line=`line`*
Return *[Read persisted output for the current call site (adjacent unkeyed block), the unkeyed EOF block when at_end=true, or a named slot when key= is set](> host_writeback_get at_end=`at_end` key=`key` line=`line`)*.
## clear
+ `at_end`=False
+ `key`=None
+ `line`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| at_end | bool | False | Whether to append to the end of the target block |
| key | any | None | Field name or key required by this operation |
| line | any | None | Text line to add to the managed writeback block |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Remove the adjacent, EOF, or named output block |
Use `at_end`=False, `key`=None, `line`=None as the inputs for this operation.
Effects: fs.write.
Remove the adjacent, EOF, or named output block.
*> host_writeback_clear at_end=`at_end` key=`key` line=`line`*
Return *[Remove the adjacent, EOF, or named output block](> host_writeback_clear at_end=`at_end` key=`key` line=`line`)*.
## ensure
+ `key`
+ `placeholder`=pending
+ `line`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| key | text | required | Field name or key required by this operation |
| placeholder | any | "pending" | Placeholder used when creating the managed block |
| line | any | None | Text line to add to the managed writeback block |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | Create a named slot with `placeholder` if missing |
Use `key`, `placeholder`="pending", `line`=None as the inputs for this operation.
Effects: fs.write.
Create a named slot with `placeholder` if missing. Never overwrites an existing slot body.
*> host_writeback_ensure key=`key` placeholder=`placeholder` line=`line`*
Return *[Create a named slot with placeholder if missing](> host_writeback_ensure key=`key` placeholder=`placeholder` line=`line`)*.
## list
| 返回 | 类型 | 说明 |
|---|---|---|
| result | list | List managed output slots from the current entry source without writing or reading another file |
Effects: fs.read.
List all output blocks in the entry file (includes `key` when named).
*> host_writeback_list*
List managed output slots from the current entry source without writing or reading another file.
Return *[List managed output slots from the current entry source without writing or reading another file](host_writeback_list())*.
## scan_path
+ `path`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| path | text | required | Path relative to the granted filesystem root |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | list | List writeback slots in any file (HTML comment and `![marqdo-out](…)` image forms; workbook inspection) |
Use `path` as the inputs for this operation.
Effects: fs.read.
Call this function directly:
```sh
marqdo call lib/writeback.mq.md scan_path 'path="lib/writeback.mq.md"' --effects fs.read --fs-root . --json
```
List writeback slots in any file (HTML comment and `![marqdo-out](…)` image forms; workbook inspection).
*> host_writeback_scan_path path=`path`*
Return *[List writeback slots in any file (HTML comment and !marqdo-out(…) image forms; workbook inspection)](> host_writeback_scan_path path=`path`)*.
+29 -2
View File
@@ -6,11 +6,38 @@ description: 解析命令行参数(中层 M5)。--键 值 / --键=值 / --
把进程参数解析成映射。开关与位置参(落在 _)。
把命令行词元转换为标志和位置参数。
能力与边界:参数值保持文本,裸标志变为布尔值,位置参数位于下划线键。省略输入时使用宿主参数;不提供完整的参数约束模式系统。
本文件就是调用和开发手册:直接导入此文件,或用 marqdo call 按下面的函数标题调用。参数表说明类型和默认值;未填默认值的参数必须提供。返回表是渐进契约,后文说明失败与边界。
实现入口:[src/host/cli.rs](../src/host/cli.rs)
开发时保持中英文语义一致,先组合公开库;仅在 OS 或算法边界添加宿主原语并声明效应。修改后运行 marqdo check --narrative-ratio 本文件,并执行 tests/stdlib_tasks.rs 的真实任务。
## 解析
+ `参数`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 参数 | any | None | 命令行 token 列表;None 读取当前宿主 argv |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | 解析 --键 值 / --键=值 / --开关 |
这里使用`参数`=None。
调用效应:pure。
直接调用此函数:
```sh
marqdo call lib/命令行.mq.md 解析 '参数=["report","--count=3","--quiet"]' --effects none --json
```
解析 --键 值 / --键=值 / --开关。裸 --开关 若当布尔,后面不要紧跟非选项词(开关放最后,或写 --开关=true)。位置参进 _。省略参数时用进程 argv(系统.参数表)。
调用例:[命令行.解析]
*> host_cli_parse args=`参数`*
完成后返回*[解析 --键 值 / --键=值 / --开关](> host_cli_parse args=`参数`)*。
+69 -9
View File
@@ -6,33 +6,93 @@ description: 摘要与 HMAC(中层 M3)。完整性 / 缓存键 — 非密码
摘要与 HMAC。用于完整性与缓存键 — 不是密码存储。
计算内容摘要与消息认证。
能力与边界:MD5 和 SHA1 用于兼容性校验,不用于保存密码。密码使用安全扩展;大文件和二进制摘要使用文件库的文件摘要。
本文件就是调用和开发手册:直接导入此文件,或用 marqdo call 按下面的函数标题调用。参数表说明类型和默认值;未填默认值的参数必须提供。返回表是渐进契约,后文说明失败与边界。
实现入口:[src/host/hash.rs](../src/host/hash.rs)
开发时保持中英文语义一致,先组合公开库;仅在 OS 或算法边界添加宿主原语并声明效应。修改后运行 marqdo check --narrative-ratio 本文件,并执行 tests/stdlib_tasks.rs 的真实任务。
## 哈希256
+ `内容`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 内容 | any | 必填 | 本操作读取、转换或输出的文本 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | 内容的 SHA-256 十六进制摘要 |
这里使用`内容`。
调用效应:pure。
直接调用此函数:
```sh
marqdo call lib/哈希.mq.md 哈希256 '内容="abc"' --effects none --json
```
内容的 SHA-256 十六进制摘要。
调用例:[哈希.哈希256] 内容=`s`
*> host_hash_sha256 text=`内容`*
完成后返回*[内容的 SHA-256 十六进制摘要](> host_hash_sha256 text=`内容`)*。
## 哈希1
+ `内容`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 内容 | any | 必填 | 本操作读取、转换或输出的文本 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | 内容的 SHA-1 十六进制摘要 |
这里使用`内容`。
调用效应:pure。
内容的 SHA-1 十六进制摘要。
*> host_hash_sha1 text=`内容`*
完成后返回*[内容的 SHA-1 十六进制摘要](> host_hash_sha1 text=`内容`)*。
## md5
+ `内容`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 内容 | any | 必填 | 本操作读取、转换或输出的文本 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | 内容的 MD5 十六进制摘要 |
这里使用`内容`。
调用效应:pure。
内容的 MD5 十六进制摘要。
*> host_hash_md5 text=`内容`*
完成后返回*[内容的 MD5 十六进制摘要](> host_hash_md5 text=`内容`)*。
## 密钥哈希256
+ `密钥`
+ `内容`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 密钥 | any | 必填 | 要读取、比较或更新的字段名或存储键 |
| 内容 | any | 必填 | 本操作读取、转换或输出的文本 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | 用密钥对内容做 HMAC-SHA256 |
这里使用`密钥`、`内容`。
调用效应:pure。
用密钥对内容做 HMAC-SHA256。
*> host_hash_hmac_sha256 key=`密钥` text=`内容`*
完成后返回*[用密钥对内容做 HMAC-SHA256](> host_hash_hmac_sha256 key=`密钥` text=`内容`)*。
+55 -6
View File
@@ -6,25 +6,74 @@ description: 解析 URL 与查询串(中层 Mid2 M7)。单段编码仍用网
解析 URL 与查询串。单段编码仍用网络.网址编码。
解析地址与重复查询参数。
能力与边界:重复查询键返回列表,不应假设所有值都是标量。地址编码和 HTML 转义是不同操作。
本文件就是调用和开发手册:直接导入此文件,或用 marqdo call 按下面的函数标题调用。参数表说明类型和默认值;未填默认值的参数必须提供。返回表是渐进契约,后文说明失败与边界。
实现入口:[src/host/url_ops.rs](../src/host/url_ops.rs)
开发时保持中英文语义一致,先组合公开库;仅在 OS 或算法边界添加宿主原语并声明效应。修改后运行 marqdo check --narrative-ratio 本文件,并执行 tests/stdlib_tasks.rs 的真实任务。
## 解析
+ `内容`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 内容 | any | 必填 | 本操作读取、转换或输出的文本 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | 把 URL 解析成 scheme / userinfo / host / port / path / query / fragment |
这里使用`内容`。
调用效应:pure。
把 URL 解析成 scheme / userinfo / host / port / path / query / fragment。
调用例:[地址.解析] 内容=`u`
*> host_url_parse text=`内容`*
完成后返回*[把 URL 解析成 scheme / userinfo / host / port / path / query / fragment](> host_url_parse text=`内容`)*。
## 查询解析
+ `内容`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 内容 | any | 必填 | 本操作读取、转换或输出的文本 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | 把 a=1&b=2 解析成映射;重复键变成列表 |
这里使用`内容`。
调用效应:pure。
直接调用此函数:
```sh
marqdo call lib/地址.mq.md 查询解析 '内容="tag=a&tag=b&name=Marqdo"' --effects none --json
```
把 a=1&b=2 解析成映射;重复键变成列表。
*> host_url_query_parse text=`内容`*
完成后返回*[把 a=1&b=2 解析成映射;重复键变成列表](> host_url_query_parse text=`内容`)*。
## 查询串化
+ `表`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 表 | any | 必填 | 输入记录;操作说明允许时 None 可用作空记录种子 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | 把映射编成查询串 |
这里使用`表`。
调用效应:pure。
把映射编成查询串。
*> host_url_query_stringify map=`表`*
完成后返回*[把映射编成查询串](> host_url_query_stringify map=`表`)*。
+383 -113
View File
@@ -8,59 +8,113 @@ import:
通过本机解释器运行绑定的代码围栏与内联源码。
向外部语言进程与会话明确传递数据。
能力与边界:语言已配置不代表解释器已安装。执行接口提供退出码、超时和输出限额,需要 process.exec;持久会话由创建者负责关闭,不透明句柄不能伪造或 JSON 序列化。
本文件就是调用和开发手册:直接导入此文件,或用 marqdo call 按下面的函数标题调用。参数表说明类型和默认值;未填默认值的参数必须提供。返回表是渐进契约,后文说明失败与边界。
实现入口:[src/host/foreign.rs](../src/host/foreign.rs)
开发时保持中英文语义一致,先组合公开库;仅在 OS 或算法边界添加宿主原语并声明效应。修改后运行 marqdo check --narrative-ratio 本文件,并执行 tests/stdlib_tasks.rs 的真实任务。
## 设置命令
+ `语言`
+ `命令`
+ `参数`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 语言 | any | 必填 | 已注册的解释器语言标识,例如 python |
| 命令 | any | 必填 | 可执行命令或解释器覆盖配置 |
| 参数 | any | None | 传给命令或函数的实参列表 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 为语言绑定解释器命令;可选附加参数 |
这里使用`语言`、`命令`、`参数`=None。
调用效应:pure。
为语言绑定解释器命令;可选附加参数。
*> host_foreign_set_cmd lang=`语言` cmd=`命令` args=`参数`*
完成后返回*[为语言绑定解释器命令;可选附加参数](> host_foreign_set_cmd lang=`语言` cmd=`命令` args=`参数`)*。
## 运行
+ `代码`
+ `标准输入`=None
+ `环境`=None
+ `工作目录`=None
+ `超时`=None
+ `参数`=None
+ `最大输出`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 代码 | any | 必填 | 已绑定的代码围栏值;内联文本请使用语言与源码参数 |
| 标准输入 | any | None | 写入子进程标准输入的文本 |
| 环境 | any | None | 传给子进程的环境变量与值记录 |
| 工作目录 | any | None | 子进程工作目录 |
| 超时 | any | None | 执行超时秒数;None 使用宿主默认值 |
| 参数 | any | None | 传给命令或函数的实参列表 |
| 最大输出 | any | None | 捕获输出的字节上限;None 使用宿主默认值 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 运行已绑定的代码围栏值;可选标准输入、环境表、工作目录、超时(秒)、 附加参数与输出上限 |
这里使用`代码`、`标准输入`=None、`环境`=None、`工作目录`=None、`超时`=None、`参数`=None、`最大输出`=None。
调用效应:process.exec。
运行已绑定的代码围栏值;可选标准输入、环境表、工作目录、超时(秒)、
附加参数与输出上限。返回 stdout 文本;非 0 退出即报错。
调用例:[外联.运行] 代码=`块`
*> host_foreign_run code=`代码` stdin=`标准输入` env=`环境` cwd=`工作目录` timeout=`超时` args=`参数` max_output=`最大输出`*
完成后返回*[运行已绑定的代码围栏值;可选标准输入、环境表、工作目录、超时(秒)、 附加参数与输出上限](> host_foreign_run code=`代码` stdin=`标准输入` env=`环境` cwd=`工作目录` timeout=`超时` args=`参数` max_output=`最大输出`)*。
## 按语言运行
+ `语言`
+ `源码`
+ `标准输入`=None
+ `环境`=None
+ `工作目录`=None
+ `超时`=None
+ `参数`=None
+ `最大输出`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 语言 | any | 必填 | 已注册的解释器语言标识,例如 python |
| 源码 | any | 必填 | 交给指定解释器执行的源文本 |
| 标准输入 | any | None | 写入子进程标准输入的文本 |
| 环境 | any | None | 传给子进程的环境变量与值记录 |
| 工作目录 | any | None | 子进程工作目录 |
| 超时 | any | None | 执行超时秒数;None 使用宿主默认值 |
| 参数 | any | None | 传给命令或函数的实参列表 |
| 最大输出 | any | None | 捕获输出的字节上限;None 使用宿主默认值 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 用语言运行源码文本;选项同“运行” |
这里使用`语言`、`源码`、`标准输入`=None、`环境`=None、`工作目录`=None、`超时`=None、`参数`=None、`最大输出`=None。
调用效应:process.exec。
用语言运行源码文本;选项同“运行”。
*> host_foreign_run_lang lang=`语言` source=`源码` stdin=`标准输入` env=`环境` cwd=`工作目录` timeout=`超时` args=`参数` max_output=`最大输出`*
完成后返回*[用语言运行源码文本;选项同“运行”](> host_foreign_run_lang lang=`语言` source=`源码` stdin=`标准输入` env=`环境` cwd=`工作目录` timeout=`超时` args=`参数` max_output=`最大输出`)*。
## 执行
+ `代码`=None
+ `语言`=None
+ `源码`=None
+ `标准输入`=None
+ `输入`=None
+ `环境`=None
+ `工作目录`=None
+ `超时`=None
+ `参数`=None
+ `输出`=auto
+ `最大输出`=None
+ `命令`=None
+ `保留`=False
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 代码 | any | None | 已绑定的代码围栏值;内联文本请使用语言与源码参数 |
| 语言 | any | None | 已注册的解释器语言标识,例如 python |
| 源码 | any | None | 交给指定解释器执行的源文本 |
| 标准输入 | any | None | 写入子进程标准输入的文本 |
| 输入 | any | None | 编码为 JSON 后写入标准输入的结构化值;不能与标准输入文本同时使用 |
| 环境 | any | None | 传给子进程的环境变量与值记录 |
| 工作目录 | any | None | 子进程工作目录 |
| 超时 | any | None | 执行超时秒数;None 使用宿主默认值 |
| 参数 | any | None | 传给命令或函数的实参列表 |
| 输出 | any | "auto" | 结果解码方式:auto、text、json 或 lines |
| 最大输出 | any | None | 捕获输出的字节上限;None 使用宿主默认值 |
| 命令 | any | None | 可执行命令或解释器覆盖配置 |
| 保留 | any | False | 是否保留生成的脚本以便检查 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 运行代码或“语言+源码”,返回记录 map,而不是在进程失败时直接报错 |
这里使用`代码`=None、`语言`=None、`源码`=None、`标准输入`=None、`输入`=None、`环境`=None、`工作目录`=None、`超时`=None、`参数`=None、`输出`="auto"、`最大输出`=None、`命令`=None、`保留`=False。
调用效应:process.exec。
运行代码或“语言+源码”,返回记录 map,而不是在进程失败时直接报错。
字段:ok、code、stdout、stderr、ms、lang、cmd、timed_out、truncated、
@@ -69,173 +123,389 @@ result、result_error、error、script、cached。
`输入` 会编码为 JSON 写入 stdin(与 `标准输入` 互斥)。`输出` 可取
auto | text | json | lines。`命令` 仅本次覆盖解释器。
*> host_foreign_invoke code=`代码` lang=`语言` source=`源码` stdin=`标准输入` input=`输入` env=`环境` cwd=`工作目录` timeout=`超时` args=`参数` output=`输出` max_output=`最大输出` cmd=`命令` keep=`保留`*
完成后返回*[运行代码或“语言+源码”,返回记录 map,而不是在进程失败时直接报错](> host_foreign_invoke code=`代码` lang=`语言` source=`源码` stdin=`标准输入` input=`输入` env=`环境` cwd=`工作目录` timeout=`超时` args=`参数` output=`输出` max_output=`最大输出` cmd=`命令` keep=`保留`)*。
## 探测
+ `语言`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 语言 | any | None | 已注册的解释器语言标识,例如 python |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 探测一个语言;省略语言时探测所有已知语言 |
这里使用`语言`=None。
调用效应:process.exec。
探测一个语言;省略语言时探测所有已知语言。返回
{lang, cmd, path, ok, version, error}(省略语言时是列表)。
*> host_foreign_probe lang=`语言`*
完成后返回*[探测一个语言;省略语言时探测所有已知语言](> host_foreign_probe lang=`语言`)*。
## 注册
+ `语言`
+ `命令`=None
+ `参数`=None
+ `模板`=None
+ `扩展名`=None
+ `环境`=None
+ `版本参数`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 语言 | any | 必填 | 已注册的解释器语言标识,例如 python |
| 命令 | any | None | 可执行命令或解释器覆盖配置 |
| 参数 | any | None | 传给命令或函数的实参列表 |
| 模板 | any | None | 解释器启动模板 |
| 扩展名 | any | None | 临时脚本的文件扩展名 |
| 环境 | any | None | 传给子进程的环境变量与值记录 |
| 版本参数 | any | None | 查询解释器版本时使用的参数 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 注册语言调用 |
这里使用`语言`、`命令`=None、`参数`=None、`模板`=None、`扩展名`=None、`环境`=None、`版本参数`=None。
调用效应:pure。
注册语言调用。提供命令(+参数)或模板(占位符
{file}、{dir}、{base}、{inline}、{lang}、{cwd});二者互斥。
*> host_foreign_register lang=`语言` cmd=`命令` args=`参数` template=`模板` ext=`扩展名` env=`环境` version_args=`版本参数`*
完成后返回*[注册语言调用](> host_foreign_register lang=`语言` cmd=`命令` args=`参数` template=`模板` ext=`扩展名` env=`环境` version_args=`版本参数`)*。
## 注销
+ `语言`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 语言 | any | 必填 | 已注册的解释器语言标识,例如 python |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 移除进程内注册;预设 / 配置 / 环境变量仍然生效 |
这里使用`语言`。
调用效应:pure。
移除进程内注册;预设 / 配置 / 环境变量仍然生效。
*> host_foreign_unset lang=`语言`*
完成后返回*[移除进程内注册;预设 / 配置 / 环境变量仍然生效](> host_foreign_unset lang=`语言`)*。
## 加载配置
+ `路径`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 路径 | any | None | 授权文件根目录内的路径 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 加载 .marqdo/foreign.toml(或显式路径);返回读取到的语言表数量 |
这里使用`路径`=None。
调用效应:fs.read。
加载 .marqdo/foreign.toml(或显式路径);返回读取到的语言表数量。
*> host_foreign_load_config path=`路径`*
完成后返回*[加载 .marqdo/foreign.toml(或显式路径);返回读取到的语言表数量](> host_foreign_load_config path=`路径`)*。
## 调用
+ `代码`=None
+ `语言`=None
+ `源码`=None
+ `输入`=None
+ `标准输入`=None
+ `环境`=None
+ `工作目录`=None
+ `超时`=None
+ `参数`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 代码 | any | None | 已绑定的代码围栏值;内联文本请使用语言与源码参数 |
| 语言 | any | None | 已注册的解释器语言标识,例如 python |
| 源码 | any | None | 交给指定解释器执行的源文本 |
| 输入 | any | None | 编码为 JSON 后写入标准输入的结构化值;不能与标准输入文本同时使用 |
| 标准输入 | any | None | 写入子进程标准输入的文本 |
| 环境 | any | None | 传给子进程的环境变量与值记录 |
| 工作目录 | any | None | 子进程工作目录 |
| 超时 | any | None | 执行超时秒数;None 使用宿主默认值 |
| 参数 | any | None | 传给命令或函数的实参列表 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | JSON 进 / JSON 出:把 `输入` 编码到 stdin,解析 stdout JSON 返回值 (stdout 为空 → None) |
这里使用`代码`=None、`语言`=None、`源码`=None、`输入`=None、`标准输入`=None、`环境`=None、`工作目录`=None、`超时`=None、`参数`=None。
调用效应:process.exec。
JSON 进 / JSON 出:把 `输入` 编码到 stdin,解析 stdout JSON 返回值
(stdout 为空 → None)。进程失败或 JSON 非法时报错。
*> host_foreign_call code=`代码` lang=`语言` source=`源码` input=`输入` stdin=`标准输入` env=`环境` cwd=`工作目录` timeout=`超时` args=`参数`*
完成后返回*[JSON 进 / JSON 出:把 输入 编码到 stdin,解析 stdout JSON 返回值 (stdout 为空 → None)](> host_foreign_call code=`代码` lang=`语言` source=`源码` input=`输入` stdin=`标准输入` env=`环境` cwd=`工作目录` timeout=`超时` args=`参数`)*。
## 批量运行
+ `任务表`
+ `并发`=4
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 任务表 | any | 必填 | 按顺序排列的代码或语言与源码运行记录 |
| 并发 | any | 4 | 最大并发操作数 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 并行运行一组代码值或 invoke 选项 map;按输入顺序返回记录 |
这里使用`任务表`、`并发`=4。
调用效应:process.exec。
并行运行一组代码值或 invoke 选项 map;按输入顺序返回记录。单项失败不影响其它项。
*> host_foreign_run_many runs=`任务表` concurrency=`并发`*
完成后返回*[并行运行一组代码值或 invoke 选项 map;按输入顺序返回记录](> host_foreign_run_many runs=`任务表` concurrency=`并发`)*。
## 批量调用
+ `输入表`
+ `代码`=None
+ `语言`=None
+ `源码`=None
+ `命令`=None
+ `环境`=None
+ `工作目录`=None
+ `超时`=None
+ `参数`=None
+ `最大输出`=None
+ `并发`=4
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 输入表 | any | 必填 | 批量调用所用的输入值 |
| 代码 | any | None | 已绑定的代码围栏值;内联文本请使用语言与源码参数 |
| 语言 | any | None | 已注册的解释器语言标识,例如 python |
| 源码 | any | None | 交给指定解释器执行的源文本 |
| 命令 | any | None | 可执行命令或解释器覆盖配置 |
| 环境 | any | None | 传给子进程的环境变量与值记录 |
| 工作目录 | any | None | 子进程工作目录 |
| 超时 | any | None | 执行超时秒数;None 使用宿主默认值 |
| 参数 | any | None | 传给命令或函数的实参列表 |
| 最大输出 | any | None | 捕获输出的字节上限;None 使用宿主默认值 |
| 并发 | any | 4 | 最大并发操作数 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 把同一段代码并行作用到每个输入;按输入顺序返回解析后的 JSON 结果 |
这里使用`输入表`、`代码`=None、`语言`=None、`源码`=None、`命令`=None、`环境`=None、`工作目录`=None、`超时`=None、`参数`=None、`最大输出`=None、`并发`=4。
调用效应:process.exec。
把同一段代码并行作用到每个输入;按输入顺序返回解析后的 JSON 结果。
全部结束后若任一项失败,报错并指出下标。
*> host_foreign_call_many inputs=`输入表` code=`代码` lang=`语言` source=`源码` cmd=`命令` env=`环境` cwd=`工作目录` timeout=`超时` args=`参数` max_output=`最大输出` concurrency=`并发`*
完成后返回*[把同一段代码并行作用到每个输入;按输入顺序返回解析后的 JSON 结果](> host_foreign_call_many inputs=`输入表` code=`代码` lang=`语言` source=`源码` cmd=`命令` env=`环境` cwd=`工作目录` timeout=`超时` args=`参数` max_output=`最大输出` concurrency=`并发`)*。
## 会话
+ `内核表`=None
+ `单元表`=None
+ `值表`=None
+ `输入表`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 内核表 | any | None | 持久解释器的内核或会话规格 |
| 单元表 | any | None | 在持久解释器中求值的代码单元 |
| 值表 | any | None | 注入会话的变量与值记录 |
| 输入表 | any | None | 批量调用所用的输入值 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 声明文档视图会话 |
这里使用`内核表`=None、`单元表`=None、`值表`=None、`输入表`=None。
调用效应:pure。
声明文档视图会话。内核表和单元表都是普通表格;返回一个 foreign 会话句柄,
供 view 消费。没有这个句柄时,view 的 cells 是无状态的。
**p = > table.empty_map**
**p = > table.put in=`p` at="kind" value="foreign-session"**
**p = > table.put in=`p` at="kernels" value=`内核表`**
**p = > table.put in=`p` at="cells" value=`单元表`**
**p = > table.put in=`p` at="values" value=`值表`**
**p = > table.put in=`p` at="inputs" value=`输入表`**
*p*
得到**`p` = [调用 empty map](table.empty_map())**。
得到**`p` = [在新记录中设置 kind 字段](table.put(in=`p`, at="kind", value="foreign-session"))**。
得到**`p` = [在新记录中设置 kernels 字段](table.put(in=`p`, at="kernels", value=`内核表`))**。
得到**`p` = [在新记录中设置 cells 字段](table.put(in=`p`, at="cells", value=`单元表`))**。
得到**`p` = [在新记录中设置 values 字段](table.put(in=`p`, at="values", value=`值表`))**。
得到**`p` = [在新记录中设置 inputs 字段](table.put(in=`p`, at="inputs", value=`输入表`))**。
完成后返回*p*。
## 会话开启
+ `语言`
+ `命令`=None
+ `环境`=None
+ `工作目录`=None
+ `超时`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 语言 | any | 必填 | 已注册的解释器语言标识,例如 python |
| 命令 | any | None | 可执行命令或解释器覆盖配置 |
| 环境 | any | None | 传给子进程的环境变量与值记录 |
| 工作目录 | any | None | 子进程工作目录 |
| 超时 | any | None | 执行超时秒数;None 使用宿主默认值 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 启动一个持久的 Python / Node 内核;返回会话 id |
这里使用`语言`、`命令`=None、`环境`=None、`工作目录`=None、`超时`=None。
调用效应:process.exec。
启动一个持久的 Python / Node 内核;返回会话 id。`超时` 是每次求值的默认超时。
*> host_foreign_session_open lang=`语言` cmd=`命令` env=`环境` cwd=`工作目录` timeout=`超时`*
完成后返回*[启动一个持久的 Python / Node 内核;返回会话 id](> host_foreign_session_open lang=`语言` cmd=`命令` env=`环境` cwd=`工作目录` timeout=`超时`)*。
## 会话求值
+ `标识`
+ `代码`=None
+ `源码`=None
+ `输入`=None
+ `标准输入`=None
+ `超时`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 标识 | any | 必填 | 对应创建或启动操作返回的标识 |
| 代码 | any | None | 已绑定的代码围栏值;内联文本请使用语言与源码参数 |
| 源码 | any | None | 交给指定解释器执行的源文本 |
| 输入 | any | None | 编码为 JSON 后写入标准输入的结构化值;不能与标准输入文本同时使用 |
| 标准输入 | any | None | 写入子进程标准输入的文本 |
| 超时 | any | None | 执行超时秒数;None 使用宿主默认值 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 在会话中求值代码(code 值)或源码文本;返回带 id/alive 的记录 |
这里使用`标识`、`代码`=None、`源码`=None、`输入`=None、`标准输入`=None、`超时`=None。
调用效应:process.exec。
在会话中求值代码(code 值)或源码文本;返回带 id/alive 的记录。
`输入` 会编码为 JSON 交给内核。
*> host_foreign_session_eval id=`标识` code=`代码` source=`源码` input=`输入` stdin=`标准输入` timeout=`超时`*
完成后返回*[在会话中求值代码(code 值)或源码文本;返回带 id/alive 的记录](> host_foreign_session_eval id=`标识` code=`代码` source=`源码` input=`输入` stdin=`标准输入` timeout=`超时`)*。
## 会话设值
+ `标识`
+ `名称`
+ `值`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 标识 | any | 必填 | 对应创建或启动操作返回的标识 |
| 名称 | any | 必填 | 要解析、注册或查找的名称 |
| 值 | any | 必填 | 待转换或保存的值;不会就地修改输入 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 把一个 Marqdo 值写入内核变量(JSON 拷贝) |
这里使用`标识`、`名称`、`值`。
调用效应:process.exec。
把一个 Marqdo 值写入内核变量(JSON 拷贝)。
*> host_foreign_session_set id=`标识` name=`名称` value=`值`*
完成后返回*[把一个 Marqdo 值写入内核变量(JSON 拷贝)](> host_foreign_session_set id=`标识` name=`名称` value=`值`)*。
## 会话取值
+ `标识`
+ `名称`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 标识 | any | 必填 | 对应创建或启动操作返回的标识 |
| 名称 | any | 必填 | 要解析、注册或查找的名称 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 把一个内核变量读成 Marqdo 值 |
这里使用`标识`、`名称`。
调用效应:process.exec。
把一个内核变量读成 Marqdo 值。
*> host_foreign_session_get id=`标识` name=`名称`*
完成后返回*[把一个内核变量读成 Marqdo 值](> host_foreign_session_get id=`标识` name=`名称`)*。
## 会话中断
+ `标识`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 标识 | any | 必填 | 对应创建或启动操作返回的标识 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 中断持久内核当前求值;worker 支持时,会话仍可用于下一次求值 |
这里使用`标识`。
调用效应:process.exec。
中断持久内核当前求值;worker 支持时,会话仍可用于下一次求值。
*> host_foreign_session_interrupt id=`标识`*
完成后返回*[中断持久内核当前求值;worker 支持时,会话仍可用于下一次求值](> host_foreign_session_interrupt id=`标识`)*。
## 会话变量
+ `标识`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 标识 | any | 必填 | 对应创建或启动操作返回的标识 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 列出内核变量名 |
这里使用`标识`。
调用效应:process.exec。
列出内核变量名。
*> host_foreign_session_names id=`标识`*
完成后返回*[列出内核变量名](> host_foreign_session_names id=`标识`)*。
## 会话关闭
+ `标识`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 标识 | any | 必填 | 对应创建或启动操作返回的标识 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 终止并移除会话;返回是否存在 |
这里使用`标识`。
调用效应:process.exec。
终止并移除会话;返回是否存在。
*> host_foreign_session_close id=`标识`*
完成后返回*[终止并移除会话;返回是否存在](> host_foreign_session_close id=`标识`)*。
## 会话表
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 列出活动会话的 id/lang/cmd/evals/alive/started_ms |
调用效应:process.exec。
列出活动会话的 id/lang/cmd/evals/alive/started_ms。
*> host_foreign_session_list*
完成后返回*[列出活动会话的 id/lang/cmd/evals/alive/started_ms](host_foreign_session_list())*。
## 语言表
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 列出已配置的外联语言 |
调用效应:pure。
直接调用此函数:
```sh
marqdo call lib/外联.mq.md 语言表 --effects none --json
```
列出已配置的外联语言。
*> host_foreign_langs*
返回当前外联注册表里的语言配置,不会启动解释器;是否安装可执行程序应另用探测接口确认。
完成后返回*[列出已配置的外联语言](host_foreign_langs())*。
## 观测日志
| 返回 | 类型 | 说明 |
|------|------|------|
| result | list | 返回本次文档执行中已接纳的 eval/get/decode 观测记录,包含 index、channel、value;开启、赋值和关闭不新增观测。 |
调用效应:pure。
返回本次文档执行中已接纳的 eval/get/decode 观测记录,包含 index、channel、value;开启、赋值和关闭不新增观测。
完成后返回*[返回本次文档执行中已接纳的 eval/get/decode 观测记录,包含 index、channel、value;开启、赋值和关闭不新增观测](> host_oracle_journal )*。
## 重放检查
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 预期 | list | 必填 | 重放比较所用的预期观测记录 |
| 实际 | list | 必填 | 重放比较所用的实际观测记录 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | map | 不执行外部代码地比较两份观测日志;返回是否一致、最早差异位置和对应记录。 |
这里使用`预期`、`实际`。
调用效应:pure。
不执行外部代码地比较两份观测日志;返回是否一致、最早差异位置和对应记录。
完成后返回*[不执行外部代码地比较两份观测日志;返回是否一致、最早差异位置和对应记录](> host_oracle_replay_check expected=`预期` observed=`实际`)*。
+136 -16
View File
@@ -6,45 +6,165 @@ description: 并发子任务 — 文件、函数或外联代码
并发子任务:文件、函数或外联代码。
以明确所有权管理并发任务。
能力与边界:文件批处理继承父权限与根目录。每项 Result.ok 表示等待协议完成,子进程业务成败还须检查 value.code。限时等待默认保留句柄,取消需要明确选择。进程可以终止并回收;函数线程只能逻辑取消。
本文件就是调用和开发手册:直接导入此文件,或用 marqdo call 按下面的函数标题调用。参数表说明类型和默认值;未填默认值的参数必须提供。返回表是渐进契约,后文说明失败与边界。
相对文件路径以 --fs-root 为准,省略时以被调用文件所在目录为准。写入需要显式 fs.write 授权,子进程需要 process.exec;纯计算无需 IO 权限。
实现入口:[src/host/subtask.rs](../src/host/subtask.rs)、[src/host/task_ops.rs](../src/host/task_ops.rs)
开发时保持中英文语义一致,先组合公开库;仅在 OS 或算法边界添加宿主原语并声明效应。修改后运行 marqdo check --narrative-ratio 本文件,并执行 tests/stdlib_tasks.rs 的真实任务。
## 启动
+ `路径`=None
+ `函数`=None
+ `参数`=None
+ `代码`=None
+ `语言`=None
+ `源码`=None
+ `输入`=None
+ `静默`=True
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 路径 | any | None | 授权根目录内的文件路径 |
| 函数 | any | None | 调用方提供的函数 |
| 参数 | any | None | 调用方提供的参数 |
| 代码 | any | None | 调用方提供的代码 |
| 语言 | any | None | 调用方提供的语言 |
| 源码 | any | None | 本次检查或试跑的源码文本 |
| 输入 | any | None | 调用方提供的输入 |
| 静默 | any | True | 调用方提供的静默 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | 启动子任务 |
这里使用`路径`=None、`函数`=None、`参数`=None、`代码`=None、`语言`=None、`源码`=None、`输入`=None、`静默`=True。
调用效应:process.exec。
启动子任务。文件子任务默认静默(静默=真:管道捕获)。静默=假 时继承父终端。文件等待返回 {code, value},静默捕获时另含截断的 stdout/stderr;value 为子 main 返回值。
调用例:[子任务.启动] 路径="child.mq.md"
*> host_subtask_spawn path=`路径` fn=`函数` args=`参数` code=`代码` lang=`语言` source=`源码` stdin=`输入` quiet=`静默`*
完成后返回*[启动子任务](> host_subtask_spawn path=`路径` fn=`函数` args=`参数` code=`代码` lang=`语言` source=`源码` stdin=`输入` quiet=`静默`)*。
## 探测
+ `id`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| id | any | 必填 | 对应创建或启动操作返回的标识 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | 非阻塞查看子任务 id 状态 |
这里使用`id`。
调用效应:process.exec。
非阻塞查看子任务 id 状态。
*> host_subtask_poll id=`id`*
完成后返回*[非阻塞查看子任务 id 状态](> host_subtask_poll id=`id`)*。
## 等待
+ `id`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| id | any | 必填 | 对应创建或启动操作返回的标识 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 阻塞直到子任务 id 结束 |
这里使用`id`。
调用效应:process.exec。
阻塞直到子任务 id 结束。
*> host_subtask_join id=`id`*
完成后返回*[阻塞直到子任务 id 结束](> host_subtask_join id=`id`)*。
## 终止
+ `id`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| id | any | 必填 | 对应创建或启动操作返回的标识 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 终止子任务 id |
这里使用`id`。
调用效应:process.exec。
终止子任务 id。
*> host_subtask_kill id=`id`*
完成后返回*[终止子任务 id](> host_subtask_kill id=`id`)*。
## 等待全部
| 返回 | 类型 | 说明 |
|---|---|---|
| result | list | 等待全部已启动子任务结束 |
调用效应:process.exec。
等待全部已启动子任务结束。
*> host_subtask_wait_all*
完成后返回*[等待全部已启动子任务结束](host_subtask_wait_all())*。
## 限时等待
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 编号 | number | 必填 | 对应创建或启动操作返回的标识 |
| 超时毫秒 | number | 30000 | 超时毫秒数;等待后检查操作结果 |
| 取消 | bool | False | 超时后是否同时取消尚未结束的任务 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | map | 限时等待并返回结果记录;默认超时保留句柄。cancel=True 会终止并回收进程;函数线程只进行逻辑取消。 |
这里使用`编号`、`超时毫秒`=30000、`取消`=False。
调用效应:process.exec。
限时等待并返回结果记录;默认超时保留句柄。cancel=True 会终止并回收进程;函数线程只进行逻辑取消。
完成后返回*[限时等待并返回结果记录;默认超时保留句柄](> host_subtask_wait_timeout id=`编号` timeout_ms=`超时毫秒` cancel=`取消`)*。
## 全部取消
| 返回 | 类型 | 说明 |
|------|------|------|
| result | number | 取消所有子任务并回收子进程,返回数量;函数线程只能逻辑取消。 |
调用效应:process.exec。
取消所有子任务并回收子进程,返回数量;函数线程只能逻辑取消。
完成后返回*[取消所有子任务并回收子进程,返回数量;函数线程只能逻辑取消](> host_subtask_cancel_all )*。
## 批量执行
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 任务 | list | 必填 | 有序文件任务记录,包含 path 及可选 args |
| 并发上限 | number | 4 | 同时运行的文件任务上限,范围 1 到 64 |
| 超时毫秒 | number | 30000 | 超时毫秒数;等待后检查操作结果 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | list | 按并发上限执行 path/args 文件任务,结果按输入排序,每项是结果记录。超时终止回收对应进程;最多一万任务、六十四并发,继承父权限和文件根目录。 |
这里使用`任务`、`并发上限`=4、`超时毫秒`=30000。
调用效应:process.exec。
直接调用此函数:
```sh
marqdo call lib/子任务.mq.md 批量执行 '任务=[{"path":"examples/stdlib-handbook/worker.mq.md"}]' '并发上限=2' --effects process.exec --fs-root . --json
```
按并发上限执行 path/args 文件任务,结果按输入排序,每项是结果记录。超时终止回收对应进程;最多一万任务、六十四并发,继承父权限和文件根目录。
完成后返回*[按并发上限执行 path/args 文件任务,结果按输入排序,每项是结果记录](> host_subtask_run_many tasks=`任务` limit=`并发上限` timeout_ms=`超时毫秒`)*。
+132
View File
@@ -0,0 +1,132 @@
---
markup: occlusion
title: 字节
---
字节是 `_type: bytes` 与 `base64` 字段组成的普通记录,可跨 CLI、JSON、插件和会话保存;不新增语言类型。
通过普通可移植记录传递任意二进制数据。
能力与边界:字节记录包含 _type=bytes 和标准 Base64。字节偏移从零起;UTF-8 解码明确且严格。读块不会留下跨会话文件句柄。
本文件就是调用和开发手册:直接导入此文件,或用 marqdo call 按下面的函数标题调用。参数表说明类型和默认值;未填默认值的参数必须提供。返回表是渐进契约,后文说明失败与边界。
实现入口:[src/host/fs_ops.rs](../src/host/fs_ops.rs)、[src/host/encoding.rs](../src/host/encoding.rs)
开发时保持中英文语义一致,先组合公开库;仅在 OS 或算法边界添加宿主原语并声明效应。修改后运行 marqdo check --narrative-ratio 本文件,并执行 tests/stdlib_tasks.rs 的真实任务。
## 从文本
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 内容 | text | 必填 | 本操作读取、转换或输出的文本 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | map | 把文本编码为 UTF-8 字节。 |
这里使用`内容`。
调用效应:pure。
直接调用此函数:
```sh
marqdo call lib/字节.mq.md 从文本 '内容="Marqdo"' --effects none --json
```
把文本编码为 UTF-8 字节。
完成后返回*[把文本编码为 UTF-8 字节](> host_bytes_from_text text=`内容`)*。
## 从编码
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 内容 | text | 必填 | 本操作读取、转换或输出的文本 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | map | 把 Base64 解码为任意字节,不假设 UTF-8。 |
这里使用`内容`。
调用效应:pure。
把 Base64 解码为任意字节,不假设 UTF-8。
完成后返回*[把 Base64 解码为任意字节,不假设 UTF-8](> host_bytes_from_base64 text=`内容`)*。
## 转文本
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 数据 | map | 必填 | 含 _type=bytes 与 base64 的可移植字节记录 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | text | 严格解码 UTF-8;无效字节序列失败。 |
这里使用`数据`。
调用效应:pure。
严格解码 UTF-8;无效字节序列失败。
完成后返回*[严格解码 UTF-8;无效字节序列失败](> host_bytes_to_text data=`数据`)*。
## 转编码
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 数据 | map | 必填 | 含 _type=bytes 与 base64 的可移植字节记录 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | text | 返回带填充的标准 Base64。 |
这里使用`数据`。
调用效应:pure。
返回带填充的标准 Base64。
完成后返回*[返回带填充的标准 Base64](> host_bytes_to_base64 data=`数据`)*。
## 长度
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 数据 | map | 必填 | 含 _type=bytes 与 base64 的可移植字节记录 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | number | 计算字节数,不是字符数。 |
这里使用`数据`。
调用效应:pure。
计算字节数,不是字符数。
完成后返回*[计算字节数,不是字符数](> host_bytes_len data=`数据`)*。
## 切片
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 数据 | map | 必填 | 含 _type=bytes 与 base64 的可移植字节记录 |
| 起 | number | 必填 | 切片起点,从零开始且包含端点 |
| 止 | number | 必填 | 切片终点,从零开始且不包含端点;None 表示到末尾 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | map | 返回从零起、左闭右开的字节切片;端点截到长度。 |
这里使用`数据`、`起`、`止`。
调用效应:pure。
返回从零起、左闭右开的字节切片;端点截到长度。
完成后返回*[返回从零起、左闭右开的字节切片;端点截到长度](> host_bytes_slice data=`数据` start=`起` end=`止`)*。
+65
View File
@@ -0,0 +1,65 @@
---
markup: occlusion
---
可选 ZIP 任务;原生默认构建支持,精简与浏览器构建不支持。返回统一结果记录。
归档是可选原生能力。本文件的打包与解包就是生产接口;
两者需要 fs.write,返回统一结果记录,目标必须不存在。解包先预检路径、
重复条目、符号链接与总展开字节上限;失败只清理本次新建的目标目录。
不复制权限、符号链接和空目录;精简或浏览器构建明确返回不支持。
本文件就是调用和开发手册:直接导入此文件,或用 marqdo call 按下面的函数标题调用。参数表说明类型和默认值;未填默认值的参数必须提供。返回表是渐进契约,后文说明失败与边界。
相对文件路径以 --fs-root 为准,省略时以被调用文件所在目录为准。写入需要显式 fs.write 授权,子进程需要 process.exec;纯计算无需 IO 权限。
实现入口:[src/host/archive.rs](../src/host/archive.rs)
开发时保持中英文语义一致,先组合公开库;仅在 OS 或算法边界添加宿主原语并声明效应。修改后运行 marqdo check --narrative-ratio 本文件,并执行 tests/stdlib_tasks.rs 的真实任务。
## 打包
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 来源 | text | 必填 | 来源路径;归档打包时必须是目录 |
| 目标 | text | 必填 | 目标路径;仅在操作明确允许时才能覆盖 |
| 字节上限 | number | 1073741824 | 读取或展开的字节上限;超限则失败 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | map | 成功结果的 value 是已归档普通文件数;失败时包含结构化错误 |
这里使用`来源`、`目标`、`字节上限`=1073741824。
调用效应:fs.write。
示例先准备可丢弃的目录 MQ_WORK,其中 input 子目录放待归档普通文件;目标 bundle.zip 和 output 必须不存在。解包后自行保留产物或清理目录。
```sh
marqdo call lib/归档.mq.md 打包 '来源="input"' '目标="bundle.zip"' --fs-root "$MQ_WORK" --effects fs.write --json
marqdo call lib/归档.mq.md 解包 '来源="bundle.zip"' '目标="output"' --fs-root "$MQ_WORK" --effects fs.write --json
```
目标必须不存在;限制总展开字节数和十万条目,拒绝符号链接和越界路径。打包只收集普通文件;解包失败清理新建目标目录。
完成后返回*[把普通文件打包为 ZIP,拒绝覆盖已有目标](> host_zip_pack src=`来源` dest=`目标` max_bytes=`字节上限`)*。
## 解包
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 来源 | text | 必填 | 来源路径;归档打包时必须是目录 |
| 目标 | text | 必填 | 目标路径;仅在操作明确允许时才能覆盖 |
| 字节上限 | number | 1073741824 | 读取或展开的字节上限;超限则失败 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | map | 成功结果的 value 是解包条目数;失败时包含结构化错误 |
这里使用`来源`、`目标`、`字节上限`=1073741824。
调用效应:fs.write。
目标必须不存在;限制总展开字节数和十万条目,拒绝符号链接和越界路径。打包只收集普通文件;解包失败清理新建目标目录。
完成后返回*[校验 ZIP 条目后解包,拒绝越界路径及已有目标](> host_zip_unpack src=`来源` dest=`目标` max_bytes=`字节上限`)*。
+58 -6
View File
@@ -6,30 +6,82 @@ description: 加载可选原生 ABI 插件(.dll / .so / .dylib)
加载可选原生 ABI 插件(.dll / .so / .dylib)。
定位并加载原生能力。
能力与边界:空列表表示本进程尚未加载插件。插件发现与加载需要 plugin.call;普通使用先读对应领域扩展的入口。原生插件不支持浏览器构建。
本文件就是调用和开发手册:直接导入此文件,或用 marqdo call 按下面的函数标题调用。参数表说明类型和默认值;未填默认值的参数必须提供。返回表是渐进契约,后文说明失败与边界。
实现入口:[src/host/plugin.rs](../src/host/plugin.rs)
开发时保持中英文语义一致,先组合公开库;仅在 OS 或算法边界添加宿主原语并声明效应。修改后运行 marqdo check --narrative-ratio 本文件,并执行 tests/stdlib_tasks.rs 的真实任务。
## 加载
+ `路径`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 路径 | any | 必填 | 授权文件根目录内的路径 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 从路径加载原生插件 |
这里使用`路径`。
调用效应:plugin.call。
从路径加载原生插件。
调用例:[插件.加载] 路径=`so`
*> host_plugin_load path=`路径`*
完成后返回*[从路径加载原生插件](> host_plugin_load path=`路径`)*。
## 卸载
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 卸载当前原生插件 |
调用效应:plugin.call。
卸载当前原生插件。
*> host_plugin_unload*
完成后返回*[卸载当前原生插件](host_plugin_unload())*。
## 列出
| 返回 | 类型 | 说明 |
|---|---|---|
| result | list | 列出已加载的原生插件 |
调用效应:pure。
直接调用此函数:
```sh
marqdo call lib/插件.mq.md 列出 --effects none --json
```
列出已加载的原生插件。
*> host_plugin_list*
返回当前宿主进程已加载插件的名称列表;本函数不会加载插件,新进程的列表可能为空。
完成后返回*[列出已加载的原生插件](host_plugin_list())*。
## 原生路径
+ `名`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 名 | any | 必填 | 已安装拓展库标识,例如 agent |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 解析已安装或本地原生插件路径(如 agent) |
这里使用`名`。
调用效应:plugin.call。
解析已安装或本地原生插件路径(如 agent)。
*> host_ext_native_path name=`名`*
完成后返回*[解析已安装或本地原生插件路径(如 agent)](> host_ext_native_path name=`名`)*。
+534 -137
View File
@@ -6,283 +6,680 @@ description: 高中数学 — 数值、随机、公式、作图
高中数学 — 数值、随机、公式、作图
计算数字、符号表达式和绘图。
能力与边界:number 契约包括符号公式;三角函数使用弧度。随机数需要 random.read,绘图具有输出效应。矩阵和量子计算保留在扩展库。
本文件就是调用和开发手册:直接导入此文件,或用 marqdo call 按下面的函数标题调用。参数表说明类型和默认值;未填默认值的参数必须提供。返回表是渐进契约,后文说明失败与边界。
实现入口:[src/host/math.rs](../src/host/math.rs)
开发时保持中英文语义一致,先组合公开库;仅在 OS 或算法边界添加宿主原语并声明效应。修改后运行 marqdo check --narrative-ratio 本文件,并执行 tests/stdlib_tasks.rs 的真实任务。
## 圆周率
圆周率。
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | 返回数学常数圆周率 |
*> host_pi*
调用效应:pure。
返回数学常数圆周率。
完成后返回*[返回数学常数圆周率](host_pi())*。
## 自然底数
自然底数。
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | 返回自然常数 e |
*> host_e*
调用效应:pure。
返回自然常数 e。
完成后返回*[返回自然常数 e](host_e())*。
## 数
+ `value`
数。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| value | any | 必填 | 运行时值;具体规则见下方操作说明 |
*> host_num value=`value`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | 把数字或数字文本转换为数值 |
这里使用`value`。
调用效应:pure。
把数字或数字文本转换为数值。
完成后返回*[把数字或数字文本转换为数值](> host_num value=`value`)*。
## 加
+ `a`
+ `b`
加。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| a | any | 必填 | 第一个操作数;适用范围见本操作说明 |
| b | any | 必填 | 第二个操作数;适用范围见本操作说明 |
*> host_math_add a=`a` b=`b`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | 将两个数字或符号表达式相加 |
这里使用`a`、`b`。
调用效应:pure。
将两个数字或符号表达式相加。
完成后返回*[将两个数字或符号表达式相加](> host_math_add a=`a` b=`b`)*。
## 减
+ `a`
+ `b`
减。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| a | any | 必填 | 第一个操作数;适用范围见本操作说明 |
| b | any | 必填 | 第二个操作数;适用范围见本操作说明 |
*> host_math_sub a=`a` b=`b`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | 从 a 减去 b |
这里使用`a`、`b`。
调用效应:pure。
从 a 减去 b。
完成后返回*[从 a 减去 b](> host_math_sub a=`a` b=`b`)*。
## 乘
+ `a`
+ `b`
乘。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| a | any | 必填 | 第一个操作数;适用范围见本操作说明 |
| b | any | 必填 | 第二个操作数;适用范围见本操作说明 |
*> host_math_mul a=`a` b=`b`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | 计算 a 与 b 的乘积 |
这里使用`a`、`b`。
调用效应:pure。
计算 a 与 b 的乘积。
完成后返回*[计算 a 与 b 的乘积](> host_math_mul a=`a` b=`b`)*。
## 除
+ `a`
+ `b`
除。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| a | any | 必填 | 第一个操作数;适用范围见本操作说明 |
| b | any | 必填 | 第二个操作数;适用范围见本操作说明 |
*> host_math_div a=`a` b=`b`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | 计算 a 除以 b;除数为零时报错 |
这里使用`a`、`b`。
调用效应:pure。
计算 a 除以 b;除数为零时报错。
完成后返回*[计算 a 除以 b;除数为零时报错](> host_math_div a=`a` b=`b`)*。
## 幂
+ `a`
+ `b`
幂。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| a | any | 必填 | 第一个操作数;适用范围见本操作说明 |
| b | any | 必填 | 第二个操作数;适用范围见本操作说明 |
*> host_math_pow a=`a` b=`b`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | 计算 a 的 b 次幂 |
这里使用`a`、`b`。
调用效应:pure。
计算 a 的 b 次幂。
完成后返回*[计算 a 的 b 次幂](> host_math_pow a=`a` b=`b`)*。
## 负
+ `value`
负。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| value | any | 必填 | 运行时值;具体规则见下方操作说明 |
*> host_math_neg value=`value`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | 对数字或符号值取负 |
这里使用`value`。
调用效应:pure。
对数字或符号值取负。
完成后返回*[对数字或符号值取负](> host_math_neg value=`value`)*。
## 正弦
+ `value`
正弦。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| value | any | 必填 | 运行时值;具体规则见下方操作说明 |
*> host_math_sin value=`value`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | 计算正弦;数值角度使用弧度 |
这里使用`value`。
调用效应:pure。
计算正弦;数值角度使用弧度。
完成后返回*[计算正弦;数值角度使用弧度](> host_math_sin value=`value`)*。
## 余弦
+ `value`
余弦。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| value | any | 必填 | 运行时值;具体规则见下方操作说明 |
*> host_math_cos value=`value`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | 计算余弦;数值角度使用弧度 |
这里使用`value`。
调用效应:pure。
计算余弦;数值角度使用弧度。
完成后返回*[计算余弦;数值角度使用弧度](> host_math_cos value=`value`)*。
## 正切
+ `value`
正切。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| value | any | 必填 | 运行时值;具体规则见下方操作说明 |
*> host_math_tan value=`value`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | 计算正切;数值角度使用弧度 |
这里使用`value`。
调用效应:pure。
计算正切;数值角度使用弧度。
完成后返回*[计算正切;数值角度使用弧度](> host_math_tan value=`value`)*。
## 反正弦
+ `value`
反正弦。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| value | any | 必填 | 运行时值;具体规则见下方操作说明 |
*> host_math_asin value=`value`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | 计算反正弦,结果为弧度 |
这里使用`value`。
调用效应:pure。
计算反正弦,结果为弧度。
完成后返回*[计算反正弦,结果为弧度](> host_math_asin value=`value`)*。
## 反余弦
+ `value`
反余弦。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| value | any | 必填 | 运行时值;具体规则见下方操作说明 |
*> host_math_acos value=`value`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | 计算反余弦,结果为弧度 |
这里使用`value`。
调用效应:pure。
计算反余弦,结果为弧度。
完成后返回*[计算反余弦,结果为弧度](> host_math_acos value=`value`)*。
## 反正切
+ `value`
反正切。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| value | any | 必填 | 运行时值;具体规则见下方操作说明 |
*> host_math_atan value=`value`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | 计算反正切,结果为弧度 |
这里使用`value`。
调用效应:pure。
计算反正切,结果为弧度。
完成后返回*[计算反正切,结果为弧度](> host_math_atan value=`value`)*。
## 平方根
+ `value`
平方根。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| value | any | 必填 | 运行时值;具体规则见下方操作说明 |
*> host_math_sqrt value=`value`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | 计算 value 的平方根 |
这里使用`value`。
调用效应:pure。
直接调用此函数:
```sh
marqdo call lib/数学.mq.md 平方根 value=9 --effects none --json
```
计算 value 的平方根。
完成后返回*[计算 value 的平方根](> host_math_sqrt value=`value`)*。
## 绝对值
+ `value`
绝对值。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| value | any | 必填 | 运行时值;具体规则见下方操作说明 |
*> host_math_abs value=`value`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | 返回绝对值 |
这里使用`value`。
调用效应:pure。
返回绝对值。
完成后返回*[返回绝对值](> host_math_abs value=`value`)*。
## 对数
+ `value`
对数。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| value | any | 必填 | 运行时值;具体规则见下方操作说明 |
*> host_math_ln value=`value`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | 计算自然对数 |
这里使用`value`。
调用效应:pure。
计算自然对数。
完成后返回*[计算自然对数](> host_math_ln value=`value`)*。
## 指数
+ `value`
指数。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| value | any | 必填 | 运行时值;具体规则见下方操作说明 |
*> host_math_exp value=`value`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | 计算自然指数函数 |
这里使用`value`。
调用效应:pure。
计算自然指数函数。
完成后返回*[计算自然指数函数](> host_math_exp value=`value`)*。
## 向下取整
+ `value`
向下取整。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| value | any | 必填 | 运行时值;具体规则见下方操作说明 |
*> host_math_floor value=`value`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | 向负无穷取整 |
这里使用`value`。
调用效应:pure。
向负无穷取整。
完成后返回*[向负无穷取整](> host_math_floor value=`value`)*。
## 向上取整
+ `value`
向上取整。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| value | any | 必填 | 运行时值;具体规则见下方操作说明 |
*> host_math_ceil value=`value`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | 向正无穷取整 |
这里使用`value`。
调用效应:pure。
向正无穷取整。
完成后返回*[向正无穷取整](> host_math_ceil value=`value`)*。
## 最小
+ `a`
+ `b`
最小。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| a | any | 必填 | 第一个操作数;适用范围见本操作说明 |
| b | any | 必填 | 第二个操作数;适用范围见本操作说明 |
*> host_math_min a=`a` b=`b`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | 返回较小的操作数 |
这里使用`a`、`b`。
调用效应:pure。
返回较小的操作数。
完成后返回*[返回较小的操作数](> host_math_min a=`a` b=`b`)*。
## 最大
+ `a`
+ `b`
最大。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| a | any | 必填 | 第一个操作数;适用范围见本操作说明 |
| b | any | 必填 | 第二个操作数;适用范围见本操作说明 |
*> host_math_max a=`a` b=`b`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | 返回较大的操作数 |
这里使用`a`、`b`。
调用效应:pure。
返回较大的操作数。
完成后返回*[返回较大的操作数](> host_math_max a=`a` b=`b`)*。
## 随机
随机。
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | 返回伪随机数;可用种子控制复现 |
*> host_random*
调用效应:random.read。
返回伪随机数;可用种子控制复现。
完成后返回*[返回伪随机数;可用种子控制复现](host_random())*。
## 随机整数
+ `min`
+ `max`
随机整数。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| min | any | 必填 | 下界,或搜索与绘图区间的起点 |
| max | any | 必填 | 上界,或搜索与绘图区间的终点 |
*> host_random_int min=`min` max=`max`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | 在约定区间内返回伪随机整数 |
这里使用`min`、`max`。
调用效应:random.read。
在约定区间内返回伪随机整数。
完成后返回*[在约定区间内返回伪随机整数](> host_random_int min=`min` max=`max`)*。
## 设种子
+ `value`
设种子。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| value | any | 必填 | 运行时值;具体规则见下方操作说明 |
*> host_seed value=`value`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 设置本次运行的伪随机种子;不用于机密值 |
这里使用`value`。
调用效应:pure。
设置本次运行的伪随机种子;不用于机密值。
完成后返回*[设置本次运行的伪随机种子;不用于机密值](> host_seed value=`value`)*。
## 公式
+ `text`
公式。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| text | text | 必填 | 调用方提供的文本 |
*> host_formula value=`text`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | 把表达式文本解析为符号公式,供后续代数运算或求值使用;语法无效时返回诊断 |
这里使用`text`。
调用效应:pure。
把表达式文本解析为符号公式,供后续代数运算或求值使用;语法无效时返回诊断。
完成后返回*[把表达式文本解析为符号公式,供后续代数运算或求值使用;语法无效时返回诊断](> host_formula value=`text`)*。
## 化简
+ `formula`
化简。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| formula | any | 必填 | 公式函数或前序符号运算返回的符号公式 |
*> host_simplify value=`formula`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | 返回化简后的公式并保留输入;这是符号代数运算,不是数值求值 |
这里使用`formula`。
调用效应:pure。
返回化简后的公式并保留输入;这是符号代数运算,不是数值求值。
完成后返回*[返回化简后的公式并保留输入;这是符号代数运算,不是数值求值](> host_simplify value=`formula`)*。
## 展开
+ `formula`
展开。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| formula | any | 必填 | 公式函数或前序符号运算返回的符号公式 |
*> host_expand value=`formula`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | 展开代数乘积与幂,返回新的符号公式 |
这里使用`formula`。
调用效应:pure。
展开代数乘积与幂,返回新的符号公式。
完成后返回*[展开代数乘积与幂,返回新的符号公式](> host_expand value=`formula`)*。
## 求导
+ `formula`
+ `var`
求导。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| formula | any | 必填 | 公式函数或前序符号运算返回的符号公式 |
| var | any | 必填 | 求导、代入、求值或求根所针对的符号名 |
*> host_diff formula=`formula` var=`var`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | 对指定符号求导并返回符号导函数 |
这里使用`formula`、`var`。
调用效应:pure。
对指定符号求导并返回符号导函数。
完成后返回*[对指定符号求导并返回符号导函数](> host_diff formula=`formula` var=`var`)*。
## 代入
+ `formula`
+ `var`
+ `value`
代入。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| formula | any | 必填 | 公式函数或前序符号运算返回的符号公式 |
| var | any | 必填 | 求导、代入、求值或求根所针对的符号名 |
| value | any | 必填 | 运行时值;具体规则见下方操作说明 |
*> host_subs formula=`formula` var=`var` value=`value`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | 用指定值替换公式中的符号;完全化简时返回数字,否则保留公式 |
这里使用`formula`、`var`、`value`。
调用效应:pure。
用指定值替换公式中的符号;完全化简时返回数字,否则保留公式。
完成后返回*[用指定值替换公式中的符号;完全化简时返回数字,否则保留公式](> host_subs formula=`formula` var=`var` value=`value`)*。
## 求值
+ `formula`
+ `var`
+ `value`
求值。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| formula | any | 必填 | 公式函数或前序符号运算返回的符号公式 |
| var | any | 必填 | 求导、代入、求值或求根所针对的符号名 |
| value | any | 必填 | 运行时值;具体规则见下方操作说明 |
*> host_eval formula=`formula` var=`var` value=`value`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 在一个变量取指定数值时计算公式;仍有未绑定符号时返回诊断 |
这里使用`formula`、`var`、`value`。
调用效应:pure。
在一个变量取指定数值时计算公式;仍有未绑定符号时返回诊断。
完成后返回*[在一个变量取指定数值时计算公式;仍有未绑定符号时返回诊断](> host_eval formula=`formula` var=`var` value=`value`)*。
## 求解
+ `formula`
+ `var`
+ `min`=None
+ `max`=None
求解。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| formula | any | 必填 | 公式函数或前序符号运算返回的符号公式 |
| var | any | 必填 | 求导、代入、求值或求根所针对的符号名 |
| min | any | None | 下界,或搜索与绘图区间的起点 |
| max | any | None | 上界,或搜索与绘图区间的终点 |
*> host_solve formula=`formula` var=`var` min=`min` max=`max`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 返回指定符号在上下界内的根列表;省略边界时使用 -100 到 100 |
这里使用`formula`、`var`、`min`=None、`max`=None。
调用效应:pure。
返回指定符号在上下界内的根列表;省略边界时使用 -100 到 100。
完成后返回*[返回指定符号在上下界内的根列表;省略边界时使用 -100 到 100](> host_solve formula=`formula` var=`var` min=`min` max=`max`)*。
## 绘图
+ `formula`
+ `var`
+ `min`
+ `max`
+ `steps`=None
+ `path`=None
+ `derivative`=None
+ `grid`=None
绘图。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| formula | any | 必填 | 公式函数或前序符号运算返回的符号公式 |
| var | any | 必填 | 求导、代入、求值或求根所针对的符号名 |
| min | any | 必填 | 下界,或搜索与绘图区间的起点 |
| max | any | 必填 | 上界,或搜索与绘图区间的终点 |
| steps | any | None | 绘图区间内的采样数量 |
| path | any | None | 相对已授权文件根目录的路径 |
| derivative | any | None | 是否在图中包含导函数 |
| grid | any | None | 是否绘制坐标网格 |
*> host_plot formula=`formula` var=`var` min=`min` max=`max` steps=`steps` path=`path` derivative=`derivative` grid=`grid`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 在区间内采样公式并返回 SVG 文本;指定路径时还会在授权根目录内写出 SVG |
这里使用`formula`、`var`、`min`、`max`、`steps`=None、`path`=None、`derivative`=None、`grid`=None。
调用效应:output.write。
在区间内采样公式并返回 SVG 文本;指定路径时还会在授权根目录内写出 SVG。
完成后返回*[在区间内采样公式并返回 SVG 文本;指定路径时还会在授权根目录内写出 SVG](> host_plot formula=`formula` var=`var` min=`min` max=`max` steps=`steps` path=`path` derivative=`derivative` grid=`grid`)*。
## 绘点列
+ `xs`
+ `ys`
+ `path`=None
+ `grid`=None
绘点列。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| xs | any | 必填 | 本操作要求的输入列表或集合 |
| ys | any | 必填 | 与 xs 一一对应的 Y 坐标列表 |
| path | any | None | 相对已授权文件根目录的路径 |
| grid | any | None | 是否绘制坐标网格 |
*> host_plot_points xs=`xs` ys=`ys` path=`path` grid=`grid`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 将一一对应的横纵坐标列表绘成 SVG 文本;两列长度不等时拒绝绘制 |
这里使用`xs`、`ys`、`path`=None、`grid`=None。
调用效应:output.write。
将一一对应的横纵坐标列表绘成 SVG 文本;两列长度不等时拒绝绘制。
完成后返回*[将一一对应的横纵坐标列表绘成 SVG 文本;两列长度不等时拒绝绘制](> host_plot_points xs=`xs` ys=`ys` path=`path` grid=`grid`)*。
## 绘圆锥
+ `kind`
+ `a`
+ `b`=None
+ `h`=None
+ `k`=None
+ `path`=None
+ `grid`=None
绘圆锥。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| kind | any | 必填 | 圆锥曲线绘制函数接受的曲线类型 |
| a | any | 必填 | 第一个操作数;适用范围见本操作说明 |
| b | any | None | 第二个操作数;适用范围见本操作说明 |
| h | any | None | 圆锥曲线中心的水平偏移 |
| k | any | None | 圆锥曲线中心的垂直偏移 |
| path | any | None | 相对已授权文件根目录的路径 |
| grid | any | None | 是否绘制坐标网格 |
*> host_plot_conic kind=`kind` a=`a` b=`b` h=`h` k=`k` path=`path` grid=`grid`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 按曲线类型、尺寸和中心偏移绘制圆锥曲线,返回 SVG 文本 |
这里使用`kind`、`a`、`b`=None、`h`=None、`k`=None、`path`=None、`grid`=None。
调用效应:output.write。
按曲线类型、尺寸和中心偏移绘制圆锥曲线,返回 SVG 文本。
完成后返回*[按曲线类型、尺寸和中心偏移绘制圆锥曲线,返回 SVG 文本](> host_plot_conic kind=`kind` a=`a` b=`b` h=`h` k=`k` path=`path` grid=`grid`)*。
+685 -41
View File
@@ -1,127 +1,771 @@
---
markup: occlusion
import:
json: lib/json.mq.md
csv: lib/csv.mq.md
title: lib/文件
description: 中文文件系统包装
---
中文文件系统包装
在明确文件根目录内读写、筛选和整理文件。
能力与边界:旧删除会递归删除目录;窄操作请用只删文件或只删空目录。原子操作只替换一个文件,批量目录操作不是事务。字节和文本支持 CoW;目录状态操作的限制见能力矩阵。
本文件就是调用和开发手册:直接导入此文件,或用 marqdo call 按下面的函数标题调用。参数表说明类型和默认值;未填默认值的参数必须提供。返回表是渐进契约,后文说明失败与边界。
相对文件路径以 --fs-root 为准,省略时以被调用文件所在目录为准。写入需要显式 fs.write 授权,子进程需要 process.exec;纯计算无需 IO 权限。
实现入口:[src/host/fs.rs](../src/host/fs.rs)、[src/host/fs_ops.rs](../src/host/fs_ops.rs)、[src/host/sandbox_fs.rs](../src/host/sandbox_fs.rs)
开发时保持中英文语义一致,先组合公开库;仅在 OS 或算法边界添加宿主原语并声明效应。修改后运行 marqdo check --narrative-ratio 本文件,并执行 tests/stdlib_tasks.rs 的真实任务。
## 读文本
+ `路径`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 路径 | any | 必填 | 授权文件根目录内的路径 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | 从路径读取 UTF-8 文本 |
这里使用`路径`。
调用效应:fs.read。
从路径读取 UTF-8 文本。
*> host_read_text path=`路径`*
完成后返回*[从路径读取 UTF-8 文本](> host_read_text path=`路径`)*。
## 写文本
+ `路径`
+ `内容`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 路径 | any | 必填 | 授权文件根目录内的路径 |
| 内容 | any | 必填 | 本操作读取、转换或输出的文本 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 完成后返回 None;文件操作失败时返回诊断 |
这里使用`路径`、`内容`。
调用效应:fs.write。
把文本写入路径(覆盖)。
*> host_write_text path=`路径` text=`内容`*
完成后返回*[把文本写入路径(覆盖)](> host_write_text path=`路径` text=`内容`)*。
## 追加文本
+ `路径`
+ `内容`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 路径 | any | 必填 | 授权文件根目录内的路径 |
| 内容 | any | 必填 | 本操作读取、转换或输出的文本 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 完成后返回 None;文件操作失败时返回诊断 |
这里使用`路径`、`内容`。
调用效应:fs.write。
向路径追加文本。
*> host_append_text path=`路径` text=`内容`*
完成后返回*[向路径追加文本](> host_append_text path=`路径` text=`内容`)*。
## 存在
+ `路径`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 路径 | any | 必填 | 授权文件根目录内的路径 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | bool | 路径是否存在 |
这里使用`路径`。
调用效应:fs.read。
路径是否存在。
*> host_exists path=`路径`*
完成后返回*[路径是否存在](> host_exists path=`路径`)*。
## 列目录
+ `路径`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 路径 | any | 必填 | 授权文件根目录内的路径 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | list | 列出路径下的目录项 |
这里使用`路径`。
调用效应:fs.read。
列出路径下的目录项。
*> host_list_dir path=`路径`*
完成后返回*[列出路径下的目录项](> host_list_dir path=`路径`)*。
## 建目录
+ `路径`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 路径 | any | 必填 | 授权文件根目录内的路径 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 完成后返回 None;文件操作失败时返回诊断 |
这里使用`路径`。
调用效应:fs.write。
创建目录。
*> host_make_dir path=`路径`*
完成后返回*[创建目录](> host_make_dir path=`路径`)*。
## 建目录树
+ `路径`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 路径 | any | 必填 | 授权文件根目录内的路径 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 完成后返回 None;文件操作失败时返回诊断 |
这里使用`路径`。
调用效应:fs.write。
递归创建目录(等同 `mkdir -p`)。
*> host_make_dirs path=`路径`*
完成后返回*[递归创建目录(等同 mkdir -p)](> host_make_dirs path=`路径`)*。
## 删除
+ `路径`
删除路径上的文件或空目录。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 路径 | any | 必填 | 授权文件根目录内的路径 |
*> host_remove path=`路径`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 完成后返回 None;文件操作失败时返回诊断 |
这里使用`路径`。
调用效应:fs.write。
删除指定文件或递归删除目录;旧行为保持兼容,不能用于只允许删除空目录的场景。
删除指定文件或递归删除目录。仅删文件请用只删文件,仅删空目录请用只删空目录。
完成后返回*[删除指定文件或递归删除目录](> host_remove path=`路径`)*。
## 删目录树
+ `路径`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 路径 | any | 必填 | 授权文件根目录内的路径 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 完成后返回 None;文件操作失败时返回诊断 |
这里使用`路径`。
调用效应:fs.write。
递归删除目录;若路径是文件则报错。
*> host_remove_tree path=`路径`*
完成后返回*[递归删除目录;若路径是文件则报错](> host_remove_tree path=`路径`)*。
## 状态
+ `路径`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 路径 | any | 必填 | 授权文件根目录内的路径 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | 返回 `{size, mtime_unix, is_file, is_dir}` |
这里使用`路径`。
调用效应:fs.read。
返回 `{size, mtime_unix, is_file, is_dir}`。
*> host_stat path=`路径`*
完成后返回*[返回 {size, mtime_unix, is_file, is_dir}](> host_stat path=`路径`)*。
## 遍历
+ `路径`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 路径 | any | 必填 | 授权文件根目录内的路径 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | list | 深度优先列出相对路径(正斜杠) |
这里使用`路径`。
调用效应:fs.read。
深度优先列出相对路径(正斜杠)。
*> host_walk path=`路径`*
完成后返回*[深度优先列出相对路径(正斜杠)](> host_walk path=`路径`)*。
## 复制文件
+ `源`
+ `目标`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 源 | any | 必填 | 来源路径;归档打包时必须是目录 |
| 目标 | any | 必填 | 目标路径;仅在操作明确允许时才能覆盖 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 完成后返回 None;文件操作失败时返回诊断 |
这里使用`源`、`目标`。
调用效应:fs.write。
复制文件(目标已存在则覆盖)。路径沙箱同其他文件操作。
*> host_copy_file src=`源` dest=`目标`*
完成后返回*[复制文件(目标已存在则覆盖)](> host_copy_file src=`源` dest=`目标`)*。
## 移动
+ `源`
+ `目标`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 源 | any | 必填 | 来源路径;归档打包时必须是目录 |
| 目标 | any | 必填 | 目标路径;仅在操作明确允许时才能覆盖 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 完成后返回 None;文件操作失败时返回诊断 |
这里使用`源`、`目标`。
调用效应:fs.write。
在沙箱内重命名 / 移动。
*> host_move src=`源` dest=`目标`*
完成后返回*[在沙箱内重命名 / 移动](> host_move src=`源` dest=`目标`)*。
## 建临时
+ `前缀`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 前缀 | any | None | 生成名称的前缀,或需要匹配的文本前缀 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | 在程序目录下创建空临时文件,返回相对路径 |
这里使用`前缀`=None。
调用效应:fs.write。
在程序目录下创建空临时文件,返回相对路径。
*> host_make_temp prefix=`前缀`*
完成后返回*[在程序目录下创建空临时文件,返回相对路径](> host_make_temp prefix=`前缀`)*。
## 文本补丁
+ `路径`
+ `查找`
+ `替换`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 路径 | any | 必填 | 授权文件根目录内的路径 |
| 查找 | any | 必填 | 替换前需要精确查找的文本 |
| 替换 | any | 必填 | 每个精确匹配项的替换文本 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 对 UTF-8 文本文件做精确 FIND→REPLACE(`查找` 必须唯一匹配一次) |
这里使用`路径`、`查找`、`替换`。
调用效应:fs.write。
对 UTF-8 文本文件做精确 FIND→REPLACE(`查找` 必须唯一匹配一次)。
*> host_text_patch path=`路径` find=`查找` replace=`替换`*
完成后返回*[对 UTF-8 文本文件做精确 FIND→REPLACE(查找 必须唯一匹配一次)](> host_text_patch path=`路径` find=`查找` replace=`替换`)*。
## 应用补丁块
+ `路径`
+ `文本`
+ `软失败`=False
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 路径 | any | 必填 | 授权文件根目录内的路径 |
| 文本 | any | 必填 | 本操作读取、转换或输出的文本 |
| 软失败 | any | False | 补丁未匹配时是否软失败 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 解析规划回复中的 FIND/REPLACE 块并应用到 `路径` |
这里使用`路径`、`文本`、`软失败`=False。
调用效应:fs.write。
解析规划回复中的 FIND/REPLACE 块并应用到 `路径`。`软失败=真` 时仅「找不到 FIND」返回 0;空 FIND、多匹配、整文件重写仍报错。
*> host_apply_patch_blocks path=`路径` text=`文本` soft=`软失败`*
完成后返回*[解析规划回复中的 FIND/REPLACE 块并应用到 路径](> host_apply_patch_blocks path=`路径` text=`文本` soft=`软失败`)*。
## 尝试读文本
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 路径 | text | 必填 | 授权文件根目录内的路径 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | map | 以 {ok,value,error} 返回文本或错误;仍需 fs |
这里使用`路径`。
调用效应:fs.read。
直接调用此函数:
```sh
marqdo call lib/文件.mq.md 尝试读文本 '路径="lib/fs.mq.md"' --effects fs.read --fs-root . --json
```
以 {ok,value,error} 返回至多 8 MiB 的 UTF-8 文本或错误;仍需 fs.read 授权。
完成后返回*[以 {ok,value,error} 返回至多 8 MiB 的 UTF-8 文本或错误;仍需 fs.read 授权](> host_fs_try_read_text path=`路径`)*。
## 尝试写文本
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 路径 | text | 必填 | 授权文件根目录内的路径 |
| 内容 | text | 必填 | 本操作读取、转换或输出的文本 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | map | 覆盖写入 UTF-8 文本,返回 {ok,value,error};需要 fs |
这里使用`路径`、`内容`。
调用效应:fs.write。
覆盖写入 UTF-8 文本,返回 {ok,value,error};需要 fs.write。
完成后返回*[覆盖写入 UTF-8 文本,返回 {ok,value,error};需要 fs.write](> host_fs_try_write_text path=`路径` text=`内容`)*。
## 读字节
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 路径 | text | 必填 | 授权文件根目录内的路径 |
| 字节上限 | number | 8388608 | 读取或展开的字节上限;超限则失败 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | map | 读取 bytes 记录;默认上限 8 MiB,最大 64 MiB;解码须明确使用字节库。 |
这里使用`路径`、`字节上限`=8388608。
调用效应:fs.read。
读取 bytes 记录;默认上限 8 MiB,最大 64 MiB;解码须明确使用字节库。
完成后返回*[读取 bytes 记录;默认上限 8 MiB,最大 64 MiB;解码须明确使用字节库](> host_fs_read_bytes path=`路径` max_bytes=`字节上限`)*。
## 写字节
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 路径 | text | 必填 | 授权文件根目录内的路径 |
| 数据 | map | 必填 | 含 _type=bytes 与 base64 的可移植字节记录 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 完成后返回 None;文件操作失败时返回诊断 |
这里使用`路径`、`数据`。
调用效应:fs.write。
用字节原子替换文件,不进行 UTF-8 转换;需要 fs.write。
完成后返回*[用字节原子替换文件,不进行 UTF-8 转换;需要 fs.write](> host_fs_write_bytes path=`路径` data=`数据`)*。
## 读块
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 路径 | text | 必填 | 授权文件根目录内的路径 |
| 偏移 | number | 0 | 下一块的字节偏移,从零开始 |
| 大小 | number | 65536 | 本次块读取的字节数 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | map | 从零起字节偏移 offset 读取至多 size 字节,返回 data/next_offset/eof;每次调用关闭文件,不跨会话持有句柄。 |
这里使用`路径`、`偏移`=0、`大小`=65536。
调用效应:fs.read。
从零起字节偏移 offset 读取至多 size 字节,返回 data/next_offset/eof;每次调用关闭文件,不跨会话持有句柄。
完成后返回*[从零起字节偏移 offset 读取至多 size 字节,返回 data/next_offset/eof;每次调用关闭文件,不跨会话持有句柄](> host_fs_read_chunk path=`路径` offset=`偏移` size=`大小`)*。
## 追加字节
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 路径 | text | 必填 | 授权文件根目录内的路径 |
| 数据 | map | 必填 | 含 _type=bytes 与 base64 的可移植字节记录 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 完成后返回 None;文件操作失败时返回诊断 |
这里使用`路径`、`数据`。
调用效应:fs.write。
追加字节,不存在则创建文件;父目录必须存在。
完成后返回*[追加字节,不存在则创建文件;父目录必须存在](> host_fs_append_bytes path=`路径` data=`数据`)*。
## 原子写文本
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 路径 | text | 必填 | 授权文件根目录内的路径 |
| 内容 | text | 必填 | 本操作读取、转换或输出的文本 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 完成后返回 None;文件操作失败时返回诊断 |
这里使用`路径`、`内容`。
调用效应:fs.write。
经同目录独占临时文件和重命名替换文本;失败清理临时文件。这是单文件替换,不是多文件事务。
完成后返回*[经同目录独占临时文件和重命名替换文本;失败清理临时文件](> host_fs_atomic_write path=`路径` text=`内容`)*。
## 变化才写
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 路径 | text | 必填 | 授权文件根目录内的路径 |
| 内容 | text | 必填 | 本操作读取、转换或输出的文本 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | bool | 仅内容变化时原子写入;返回是否发生写入。 |
这里使用`路径`、`内容`。
调用效应:fs.write。
仅内容变化时原子写入;返回是否发生写入。
完成后返回*[仅内容变化时原子写入;返回是否发生写入](> host_fs_write_changed path=`路径` text=`内容`)*。
## 校验后写
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 路径 | text | 必填 | 授权文件根目录内的路径 |
| 内容 | text | 必填 | 本操作读取、转换或输出的文本 |
| 预期摘要 | text | 必填 | 前次精确文本的摘要;操作允许时 None 表示不检查 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | map | 核对当前 SHA-256 后原子替换,返回结果记录;可发现过期内容,并发写者仍需外部协调。 |
这里使用`路径`、`内容`、`预期摘要`。
调用效应:fs.write。
核对当前 SHA-256 后原子替换,返回结果记录;可发现过期内容,并发写者仍需外部协调。
完成后返回*[核对当前 SHA-256 后原子替换,返回结果记录;可发现过期内容,并发写者仍需外部协调](> host_fs_write_checked path=`路径` text=`内容` expected_sha256=`预期摘要`)*。
## 读行
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 路径 | text | 必填 | 授权文件根目录内的路径 |
| 字节上限 | number | 8388608 | 读取或展开的字节上限;超限则失败 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | list | 有界读取 UTF-8 行,去除行尾;接受 CRLF,末尾换行不产生额外行。 |
这里使用`路径`、`字节上限`=8388608。
调用效应:fs.read。
有界读取 UTF-8 行,去除行尾;接受 CRLF,末尾换行不产生额外行。
完成后返回*[有界读取 UTF-8 行,去除行尾;接受 CRLF,末尾换行不产生额外行](> host_fs_read_lines path=`路径` max_bytes=`字节上限`)*。
## 写行
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 路径 | text | 必填 | 授权文件根目录内的路径 |
| 行表 | list | 必填 | 待写入的文本行列表 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 完成后返回 None;文件操作失败时返回诊断 |
这里使用`路径`、`行表`。
调用效应:fs.write。
按 LF 原子写入文本行;非空输入追加一个末尾换行。
完成后返回*[按 LF 原子写入文本行;非空输入追加一个末尾换行](> host_fs_write_lines path=`路径` lines=`行表`)*。
## 只删文件
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 路径 | text | 必填 | 授权文件根目录内的路径 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 完成后返回 None;文件操作失败时返回诊断 |
这里使用`路径`。
调用效应:fs.write。
删除文件,拒绝目录;不存在则失败。旧删除接口保持递归兼容行为。
完成后返回*[删除文件,拒绝目录;不存在则失败](> host_fs_remove_file path=`路径`)*。
## 只删空目录
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 路径 | text | 必填 | 授权文件根目录内的路径 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 完成后返回 None;文件操作失败时返回诊断 |
这里使用`路径`。
调用效应:fs.write。
只删除空目录;非空目录失败。仅原生文件系统支持。
完成后返回*[只删除空目录;非空目录失败](> host_fs_remove_empty_dir path=`路径`)*。
## 临时目录
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 前缀 | text | "mqtmp" | 生成名称的前缀,或需要匹配的文本前缀 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | text | 在文件根目录内创建临时目录,返回相对名称;调用方负责删目录树清理,不使用系统全局临时目录。 |
这里使用`前缀`="mqtmp"。
调用效应:fs.write。
在文件根目录内创建临时目录,返回相对名称;调用方负责删目录树清理,不使用系统全局临时目录。
完成后返回*[在文件根目录内创建临时目录,返回相对名称;调用方负责删目录树清理,不使用系统全局临时目录](> host_fs_temp_dir prefix=`前缀`)*。
## 文件摘要
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 路径 | text | 必填 | 授权文件根目录内的路径 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | text | 以 64 KiB 缓冲区计算 SHA-256;支持二进制大文件,不整文件载入内存。 |
这里使用`路径`。
调用效应:fs.read。
以 64 KiB 缓冲区计算 SHA-256;支持二进制大文件,不整文件载入内存。
完成后返回*[以 64 KiB 缓冲区计算 SHA-256;支持二进制大文件,不整文件载入内存](> host_fs_file_hash path=`路径`)*。
## 查找文件
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 路径 | text | 必填 | 授权文件根目录内的路径 |
| 模式 | text | "**" | 相对路径 glob,支持 *、** 与 ? |
| 排除 | any | None | 遍历时剪枝的 glob 模式列表;None 表示不排除 |
| 深度上限 | number | 64 | 最大遍历深度 |
| 类型 | text | "file" | 条目类型过滤:file、dir 或 any |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | list | 按 单星号、双星号与问号 模式查找有序相对路径;exclude 可剪除目录,kind 为 file/dir/all;不跟随符号链接,最多十万项。读取原生文件系统快照。 |
这里使用`路径`、`模式`="**"、`排除`=None、`深度上限`=64、`类型`="file"。
调用效应:fs.read。
按 单星号、双星号与问号 模式查找有序相对路径;exclude 可剪除目录,kind 为 file/dir/all;不跟随符号链接,最多十万项。读取原生文件系统快照。
完成后返回*[按 单星号、双星号与问号 模式查找有序相对路径;exclude 可剪除目录,kind 为 file/dir/all;不跟随符号链接,最多十万项](> host_fs_find path=`路径` pattern=`模式` exclude=`排除` max_depth=`深度上限` kind=`类型`)*。
## 复制目录树
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 来源 | text | 必填 | 来源路径;归档打包时必须是目录 |
| 目标 | text | 必填 | 目标路径;仅在操作明确允许时才能覆盖 |
| 覆盖 | bool | False | 是否允许替换已存在的目标文件 |
| 排除 | any | None | 遍历时剪枝的 glob 模式列表;None 表示不排除 |
| 预演 | bool | False | 是否仅返回计划而不修改文件 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | list | 在不相交目录树间复制文件;先检查冲突,覆盖须明确开启。返回相对文件列表;dry_run 仅计划。不复制权限、链接和空目录。 |
这里使用`来源`、`目标`、`覆盖`=False、`排除`=None、`预演`=False。
调用效应:fs.write。
在不相交目录树间复制文件;先检查冲突,覆盖须明确开启。返回相对文件列表;dry_run 仅计划。不复制权限、链接和空目录。
完成后返回*[在不相交目录树间复制文件;先检查冲突,覆盖须明确开启](> host_fs_copy_tree src=`来源` dest=`目标` overwrite=`覆盖` exclude=`排除` dry_run=`预演`)*。
## 同步目录树
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 来源 | text | 必填 | 来源路径;归档打包时必须是目录 |
| 目标 | text | 必填 | 目标路径;仅在操作明确允许时才能覆盖 |
| 覆盖 | bool | False | 是否允许替换已存在的目标文件 |
| 排除 | any | None | 遍历时剪枝的 glob 模式列表;None 表示不排除 |
| 预演 | bool | False | 是否仅返回计划而不修改文件 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | list | 按复制目录树的冲突规则复制新增或变化文件;不删除目标独有文件,执行不是事务。 |
这里使用`来源`、`目标`、`覆盖`=False、`排除`=None、`预演`=False。
调用效应:fs.write。
按复制目录树的冲突规则复制新增或变化文件;不删除目标独有文件,执行不是事务。
完成后返回*[按复制目录树的冲突规则复制新增或变化文件;不删除目标独有文件,执行不是事务](> host_fs_sync_tree src=`来源` dest=`目标` overwrite=`覆盖` exclude=`排除` dry_run=`预演`)*。
## 批量改名
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 改名表 | list | 必填 | 来源与目标路径组成的改名记录列表 |
| 预演 | bool | False | 是否仅返回计划而不修改文件 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | number | 预检 src/dest 文件记录,拒绝已有或重复目标,然后按输入顺序改名。不支持环路或回滚;dry_run 返回计划数量。 |
这里使用`改名表`、`预演`=False。
调用效应:fs.write。
预检 src/dest 文件记录,拒绝已有或重复目标,然后按输入顺序改名。不支持环路或回滚;dry_run 返回计划数量。
完成后返回*[预检 src/dest 文件记录,拒绝已有或重复目标,然后按输入顺序改名](> host_fs_rename_many moves=`改名表` dry_run=`预演`)*。
## 读JSON
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 路径 | text | 必填 | 相对文件根目录的路径 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 解析后的数据 |
这里使用`路径`。
调用效应:fs.read。
读取 UTF-8 文本后使用同一标准解析器;错误会终止,批处理请先尝试读文本。
得到**`body` = [读取指定文件的 UTF-8 正文](读文本(路径=`路径`))**。
完成后返回*[解析 JSON 传输文本](json.parse(text=`body`))*。
## 写JSON
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 路径 | text | 必填 | 相对文件根目录的路径 |
| 数据 | any | 必填 | 待序列化的数据 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 完成后返回 None;文件操作失败时返回诊断 |
这里使用`路径`、`数据`。
调用效应:fs.write。
序列化后以原子写入替换文件;不保留旧格式与注释。
得到**`body` = [将结构化值编码为 JSON 文本](json.stringify(value=`数据`))**。
完成后返回*[将准备好的文本写入指定文件](原子写文本(路径=`路径`, 内容=`body`))*。
## 读CSV
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 路径 | text | 必填 | 相对文件根目录的路径 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 解析后的数据 |
这里使用`路径`。
调用效应:fs.read。
读取 UTF-8 文本后使用同一标准解析器;错误会终止,批处理请先尝试读文本。
得到**`body` = [读取指定文件的 UTF-8 正文](读文本(路径=`路径`))**。
完成后返回*[调用 parse](csv.parse(text=`body`))*。
## 写CSV
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 路径 | text | 必填 | 相对文件根目录的路径 |
| 数据 | list | 必填 | 待序列化的数据 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 完成后返回 None;文件操作失败时返回诊断 |
这里使用`路径`、`数据`。
调用效应:fs.write。
序列化后以原子写入替换文件;不保留旧格式与注释。
得到**`body` = [调用 stringify](csv.stringify(rows=`数据`))**。
完成后返回*[将准备好的文本写入指定文件](原子写文本(路径=`路径`, 内容=`body`))*。
+171 -34
View File
@@ -6,93 +6,230 @@ description: 文本库加厚(中层 M4)。字面替换 — 正则请用 lib/
常用文本助手。手写拆分不如走这里;正则请用 lib/正则。
清理与组合 Unicode 文本。
能力与边界:字面替换使用本库,模式匹配使用正则库,任意二进制使用字节库。拆分和拼接使用明确分隔符,不隐式解析文档。
本文件就是调用和开发手册:直接导入此文件,或用 marqdo call 按下面的函数标题调用。参数表说明类型和默认值;未填默认值的参数必须提供。返回表是渐进契约,后文说明失败与边界。
实现入口:[src/host/text_ops.rs](../src/host/text_ops.rs)
开发时保持中英文语义一致,先组合公开库;仅在 OS 或算法边界添加宿主原语并声明效应。修改后运行 marqdo check --narrative-ratio 本文件,并执行 tests/stdlib_tasks.rs 的真实任务。
## 去空白
+ `s`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| s | text | 必填 | 输入文本 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | 去掉字符串 s 两端空白 |
这里使用`s`。
调用效应:pure。
直接调用此函数:
```sh
marqdo call lib/文本.mq.md 去空白 's=" readable text "' --effects none --json
```
去掉字符串 s 两端空白。
*> trim `s`*
完成后返回*[调用 trim](trim(`s`))*。
## 拆分
+ `s`
+ `sep`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| s | text | 必填 | 输入文本 |
| sep | text | 必填 | 拆分或连接文本所用的分隔符 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | list | 按分隔符 sep 拆分字符串 s |
这里使用`s`、`sep`。
调用效应:pure。
按分隔符 sep 拆分字符串 s。
*> split value=`s` sep=`sep`*
完成后返回*[调用 split](split(value=`s`, sep=`sep`))*。
## 拼接
+ `xs`
+ `sep`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| xs | any | 必填 | 本操作要求的输入列表或集合 |
| sep | text | 必填 | 拆分或连接文本所用的分隔符 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | 用分隔符 sep 拼接列表 xs |
这里使用`xs`、`sep`。
调用效应:pure。
用分隔符 sep 拼接列表 xs。
*> join value=`xs` sep=`sep`*
完成后返回*[调用 join](join(value=`xs`, sep=`sep`))*。
## 包含
+ `内容`
+ `子串`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 内容 | any | 必填 | 本操作读取、转换或输出的文本 |
| 子串 | any | 必填 | 需要查找的子串 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | bool | 内容是否包含子串 |
这里使用`内容`、`子串`。
调用效应:pure。
内容是否包含子串。
调用例:[文本.包含] 内容="你好" 子串="好"
*> host_text_contains text=`内容` sub=`子串`*
完成后返回*[内容是否包含子串](> host_text_contains text=`内容` sub=`子串`)*。
## 开头是
+ `内容`
+ `前缀`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 内容 | any | 必填 | 本操作读取、转换或输出的文本 |
| 前缀 | any | 必填 | 生成名称的前缀,或需要匹配的文本前缀 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | bool | 内容是否以前缀开头 |
这里使用`内容`、`前缀`。
调用效应:pure。
内容是否以前缀开头。
*> host_text_starts_with text=`内容` prefix=`前缀`*
完成后返回*[内容是否以前缀开头](> host_text_starts_with text=`内容` prefix=`前缀`)*。
## 结尾是
+ `内容`
+ `后缀`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 内容 | any | 必填 | 本操作读取、转换或输出的文本 |
| 后缀 | any | 必填 | 需要匹配的文本后缀 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | bool | 内容是否以后缀结尾 |
这里使用`内容`、`后缀`。
调用效应:pure。
内容是否以后缀结尾。
*> host_text_ends_with text=`内容` suffix=`后缀`*
完成后返回*[内容是否以后缀结尾](> host_text_ends_with text=`内容` suffix=`后缀`)*。
## 替换
+ `内容`
+ `旧`
+ `新`
+ `次数`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 内容 | any | 必填 | 本操作读取、转换或输出的文本 |
| 旧 | any | 必填 | 需要替换的精确子串 |
| 新 | any | 必填 | 替换后使用的文本 |
| 次数 | any | None | 最大替换次数;None 使用操作说明中的默认值 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | 在内容里把字面旧换成新,可选次数 |
这里使用`内容`、`旧`、`新`、`次数`=None。
调用效应:pure。
在内容里把字面旧换成新,可选次数。
*> host_text_replace text=`内容` old=`旧` new=`新` count=`次数`*
完成后返回*[在内容里把字面旧换成新,可选次数](> host_text_replace text=`内容` old=`旧` new=`新` count=`次数`)*。
## 大写
+ `内容`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 内容 | any | 必填 | 本操作读取、转换或输出的文本 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | 内容转大写 |
这里使用`内容`。
调用效应:pure。
内容转大写。
*> host_text_to_upper text=`内容`*
完成后返回*[内容转大写](> host_text_to_upper text=`内容`)*。
## 小写
+ `内容`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 内容 | any | 必填 | 本操作读取、转换或输出的文本 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | 内容转小写 |
这里使用`内容`。
调用效应:pure。
内容转小写。
*> host_text_to_lower text=`内容`*
完成后返回*[内容转小写](> host_text_to_lower text=`内容`)*。
## 重复
+ `内容`
+ `次数`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 内容 | any | 必填 | 本操作读取、转换或输出的文本 |
| 次数 | any | 必填 | 重复次数 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | 把内容重复次数遍 |
这里使用`内容`、`次数`。
调用效应:pure。
把内容重复次数遍。
*> host_text_repeat text=`内容` n=`次数`*
完成后返回*[把内容重复次数遍](> host_text_repeat text=`内容` n=`次数`)*。
## 填充
+ `内容`
+ `宽度`
+ `填充符`=None
+ `对齐`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 内容 | any | 必填 | 本操作读取、转换或输出的文本 |
| 宽度 | any | 必填 | 填充后的目标字符宽度 |
| 填充符 | any | None | 单个填充字符 |
| 对齐 | any | None | 填充对齐方式:left、right 或 center |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | 把内容填充到宽度,可选填充符与对齐(left / right / center) |
这里使用`内容`、`宽度`、`填充符`=None、`对齐`=None。
调用效应:pure。
把内容填充到宽度,可选填充符与对齐(left / right / center)。
*> host_text_pad text=`内容` width=`宽度` fill=`填充符` align=`对齐`*
完成后返回*[把内容填充到宽度,可选填充符与对齐(left / right / center)](> host_text_pad text=`内容` width=`宽度` fill=`填充符` align=`对齐`)*。
+155
View File
@@ -0,0 +1,155 @@
---
markup: occlusion
---
通过渲染器共用的 Markdown 解析器读取文档结构。全部接口均为纯函数。
不执行内容地读取与变换 Markdown 结构。
能力与边界:复用 Markdown 解析器并识别 YAML 前置信息;区间是原始 UTF-8 字节偏移。不执行文档。重复章节名失败;替换保留周围源码,持久化使用校验后写。
本文件就是调用和开发手册:直接导入此文件,或用 marqdo call 按下面的函数标题调用。参数表说明类型和默认值;未填默认值的参数必须提供。返回表是渐进契约,后文说明失败与边界。
实现入口:[src/host/document.rs](../src/host/document.rs)
开发时保持中英文语义一致,先组合公开库;仅在 OS 或算法边界添加宿主原语并声明效应。修改后运行 marqdo check --narrative-ratio 本文件,并执行 tests/stdlib_tasks.rs 的真实任务。
## 章节列表
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 内容 | text | 必填 | 本操作读取、转换或输出的文本 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | list | 列出标题、原始 UTF-8 字节区间和正文;章节结束于下一个同级或更高级标题。不执行文档。 |
这里使用`内容`。
调用效应:pure。
直接调用此函数:
```sh
marqdo call lib/文档.mq.md 章节列表 '内容="# Notes"' --effects none --json
```
列出标题、原始 UTF-8 字节区间和正文;章节结束于下一个同级或更高级标题。不执行文档。
完成后返回*[列出标题、原始 UTF-8 字节区间和正文;章节结束于下一个同级或更高级标题](> host_document_sections text=`内容`)*。
## 读取章节
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 内容 | text | 必填 | 本操作读取、转换或输出的文本 |
| 标题 | text | 必填 | 精确且唯一的 Markdown 标题文字 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | text | 按完整标题读取正文;缺失或重复标题失败。 |
这里使用`内容`、`标题`。
调用效应:pure。
按完整标题读取正文;缺失或重复标题失败。
完成后返回*[按完整标题读取正文;缺失或重复标题失败](> host_document_section text=`内容` title=`标题`)*。
## 替换章节
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 内容 | text | 必填 | 本操作读取、转换或输出的文本 |
| 标题 | text | 必填 | 精确且唯一的 Markdown 标题文字 |
| 正文 | text | 必填 | 请求正文;文档操作中为替换正文 |
| 预期摘要 | any | None | 前次精确文本的摘要;操作允许时 None 表示不检查 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | map | 返回替换章节正文的结果记录,保留标题和周围源码;可校验整份来源摘要。这是纯转换,持久化使用文件库校验后写。 |
这里使用`内容`、`标题`、`正文`、`预期摘要`=None。
调用效应:pure。
返回替换章节正文的结果记录,保留标题和周围源码;可校验整份来源摘要。这是纯转换,持久化使用文件库校验后写。
完成后返回*[返回替换章节正文的结果记录,保留标题和周围源码;可校验整份来源摘要](> host_document_replace_section text=`内容` title=`标题` body=`正文` expected_sha256=`预期摘要`)*。
## 表格列表
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 内容 | text | 必填 | 本操作读取、转换或输出的文本 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | list | 提取惰性的 GFM 表头、单元格文本和原始字节区间;不求值单元格。 |
这里使用`内容`。
调用效应:pure。
提取惰性的 GFM 表头、单元格文本和原始字节区间;不求值单元格。
完成后返回*[提取惰性的 GFM 表头、单元格文本和原始字节区间;不求值单元格](> host_document_tables text=`内容`)*。
## 替换表格
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 内容 | text | 必填 | 本操作读取、转换或输出的文本 |
| 序号 | number | 必填 | 按源码顺序排列的表格下标,从零开始 |
| 表头 | list | 必填 | 按列顺序排列的表头文本列表 |
| 行 | list | 必填 | 单元格文本列表组成的行列表;每行宽度必须与表头一致 |
| 预期摘要 | any | None | 前次精确文本的摘要;操作允许时 None 表示不检查 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | map | 按从零起的表序号,用文本表头和行替换表格,保留周围源码;返回结果记录。 |
这里使用`内容`、`序号`、`表头`、`行`、`预期摘要`=None。
调用效应:pure。
按从零起的表序号,用文本表头和行替换表格,保留周围源码;返回结果记录。
完成后返回*[按从零起的表序号,用文本表头和行替换表格,保留周围源码;返回结果记录](> host_document_replace_table text=`内容` index=`序号` headers=`表头` rows=`行` expected_sha256=`预期摘要`)*。
## 链接列表
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 内容 | text | 必填 | 本操作读取、转换或输出的文本 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | list | 列出 Markdown 链接描述、目标和字节区间;不访问或执行链接。 |
这里使用`内容`。
调用效应:pure。
列出 Markdown 链接描述、目标和字节区间;不访问或执行链接。
完成后返回*[列出 Markdown 链接描述、目标和字节区间;不访问或执行链接](> host_document_links text=`内容`)*。
## 代码块列表
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 内容 | text | 必填 | 本操作读取、转换或输出的文本 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | list | 列出代码块语言、字面源码和字节区间;不运行其中的外联或 Marqdo 代码。 |
这里使用`内容`。
调用效应:pure。
列出代码块语言、字面源码和字节区间;不运行其中的外联或 Marqdo 代码。
完成后返回*[列出代码块语言、字面源码和字节区间;不运行其中的外联或 Marqdo 代码](> host_document_code_blocks text=`内容`)*。
+93 -22
View File
@@ -6,57 +6,128 @@ description: 按级别过滤的一行日志(中层 M6 + Mid2 M10 字段)。
按级别过滤的一行日志(中层 M6 + Mid2 M10 字段)。默认级别 info。
输出按等级过滤的诊断日志。
能力与边界:日志等级只影响本次运行;日志是输出效应,不是返回值。call 将捕获输出与 JSON 结果分开。
本文件就是调用和开发手册:直接导入此文件,或用 marqdo call 按下面的函数标题调用。参数表说明类型和默认值;未填默认值的参数必须提供。返回表是渐进契约,后文说明失败与边界。
实现入口:[src/host/log.rs](../src/host/log.rs)
开发时保持中英文语义一致,先组合公开库;仅在 OS 或算法边界添加宿主原语并声明效应。修改后运行 marqdo check --narrative-ratio 本文件,并执行 tests/stdlib_tasks.rs 的真实任务。
## 设级别
+ `级别`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 级别 | any | 必填 | 日志阈值:debug、info、warn 或 error |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 级别:debug / info / warn / error(或 调试/信息/警告/错误) |
这里使用`级别`。
调用效应:pure。
级别:debug / info / warn / error(或 调试/信息/警告/错误)。
*> host_log_set_level level=`级别`*
完成后返回*[级别:debug / info / warn / error(或 调试/信息/警告/错误)](> host_log_set_level level=`级别`)*。
## 调试
+ `内容`
+ `字段`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 内容 | any | 必填 | 本操作读取、转换或输出的文本 |
| 字段 | any | None | 附加到日志事件的结构化字段与值记录 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 写出调试日志行;可选字段映射 |
这里使用`内容`、`字段`=None。
调用效应:output.write。
写出调试日志行;可选字段映射。
**line = > host_log_line level="debug" text=`内容` fields=`字段`**
得到**`line` = [调用 log line]([写出调试日志行;可选字段映射](host_log_line(level="debug", text=`内容`, fields=`字段`)))**。
1. `line`
> 打印 内容=`line`
这里**[输出本步已准备的消息](打印(内容=`line`))**。
2. *
****
完成后返回*None*。
## 信息
+ `内容`
+ `字段`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 内容 | any | 必填 | 本操作读取、转换或输出的文本 |
| 字段 | any | None | 附加到日志事件的结构化字段与值记录 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 写出信息日志行;可选字段映射 |
这里使用`内容`、`字段`=None。
调用效应:output.write。
直接调用此函数:
```sh
marqdo call lib/日志.mq.md 信息 '内容="handbook example"' '字段={"task":"sample"}' --effects output.write --json
```
写出信息日志行;可选字段映射。
**line = > host_log_line level="info" text=`内容` fields=`字段`**
得到**`line` = [调用 log line]([写出信息日志行;可选字段映射](host_log_line(level="info", text=`内容`, fields=`字段`)))**。
1. `line`
> 打印 内容=`line`
这里**[输出本步已准备的消息](打印(内容=`line`))**。
2. *
****
完成后返回*None*。
## 警告
+ `内容`
+ `字段`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 内容 | any | 必填 | 本操作读取、转换或输出的文本 |
| 字段 | any | None | 附加到日志事件的结构化字段与值记录 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 写出警告日志行;可选字段映射 |
这里使用`内容`、`字段`=None。
调用效应:output.write。
写出警告日志行;可选字段映射。
**line = > host_log_line level="warn" text=`内容` fields=`字段`**
得到**`line` = [调用 log line]([写出警告日志行;可选字段映射](host_log_line(level="warn", text=`内容`, fields=`字段`)))**。
1. `line`
> 打印 内容=`line`
这里**[输出本步已准备的消息](打印(内容=`line`))**。
2. *
****
完成后返回*None*。
## 错误
+ `内容`
+ `字段`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 内容 | any | 必填 | 本操作读取、转换或输出的文本 |
| 字段 | any | None | 附加到日志事件的结构化字段与值记录 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 写出错误日志行;可选字段映射 |
这里使用`内容`、`字段`=None。
调用效应:output.write。
写出错误日志行;可选字段映射。
**line = > host_log_line level="error" text=`内容` fields=`字段`**
得到**`line` = [调用 log line]([写出错误日志行;可选字段映射](host_log_line(level="error", text=`内容`, fields=`字段`)))**。
1. `line`
> 打印 内容=`line`
这里**[输出本步已准备的消息](打印(内容=`line`))**。
2. *
****
完成后返回*None*。
+158 -30
View File
@@ -1,63 +1,191 @@
---
markup: occlusion
title: lib/日期时间
description: 日历时刻 map `{unix, zone, iso}`(中层 Mid2 M7)。固定偏移与少量 IANA 别名。
description: 日历时刻 map `{unix, zone, iso}`(中层 Mid2 M7)。固定偏移和内嵌 IANA 时区与夏令时规则。
---
日历时刻 map `{unix, zone, iso}`(中层 Mid2 M7)。固定偏移与少量 IANA 别名。
日历时刻 map `{unix, zone, iso}`(中层 Mid2 M7)。固定偏移和内嵌 IANA 时区与夏令时规则。
处理时间戳、IANA 时区和当地日历。
能力与边界:zone 保留数值偏移,timezone 保留 IANA 身份。加按经过的秒数计算;加日历日保持当地钟点。夏令时缺口失败,重叠时间须明确选择策略。
本文件就是调用和开发手册:直接导入此文件,或用 marqdo call 按下面的函数标题调用。参数表说明类型和默认值;未填默认值的参数必须提供。返回表是渐进契约,后文说明失败与边界。
实现入口:[src/host/datetime.rs](../src/host/datetime.rs)、[src/host/data_ops.rs](../src/host/data_ops.rs)
开发时保持中英文语义一致,先组合公开库;仅在 OS 或算法边界添加宿主原语并声明效应。修改后运行 marqdo check --narrative-ratio 本文件,并执行 tests/stdlib_tasks.rs 的真实任务。
## 现在
现在。
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | 读取时钟并返回当前 UTC 日期时间记录 |
*> host_datetime_now*
调用效应:time.read。
读取时钟并返回当前 UTC 日期时间记录。
完成后返回*[读取时钟并返回当前 UTC 日期时间记录](host_datetime_now())*。
## 自戳
+ `秒`
+ `区`=None
自戳。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 秒 | any | 必填 | 以秒为单位的 Unix 时间戳 |
| 区 | any | None | 本操作接受的固定偏移或命名时区 |
*> host_datetime_from_unix unix=`秒` zone=`区`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | 把 Unix 秒数转换为指定时区的日期时间记录;未指定时区时使用 UTC |
这里使用`秒`、`区`=None。
调用效应:pure。
把 Unix 秒数转换为指定时区的日期时间记录;未指定时区时使用 UTC。
完成后返回*[把 Unix 秒数转换为指定时区的日期时间记录;未指定时区时使用 UTC](> host_datetime_from_unix unix=`秒` zone=`区`)*。
## 成戳
+ `时刻`
成戳。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 时刻 | any | 必填 | 本库返回的日期时间记录,不是格式化文本 |
*> host_datetime_to_unix dt=`时刻`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | 从日期时间记录读取 Unix 秒数;格式与时区表示不改变同一时刻 |
这里使用`时刻`。
调用效应:pure。
从日期时间记录读取 Unix 秒数;格式与时区表示不改变同一时刻。
完成后返回*[从日期时间记录读取 Unix 秒数;格式与时区表示不改变同一时刻](> host_datetime_to_unix dt=`时刻`)*。
## 解析
+ `内容`
+ `格式`=None
解析。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 内容 | any | 必填 | 本操作读取、转换或输出的文本 |
| 格式 | any | None | None 使用默认解析,或指定 rfc3339、strftime 格式 |
*> host_datetime_parse text=`内容` pattern=`格式`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | 解析 RFC3339 或带可选时分秒的 YYYY-MM-DD 文本;显式格式使用 strftime 或 rfc3339 |
这里使用`内容`、`格式`=None。
调用效应:pure。
解析 RFC3339 或带可选时分秒的 YYYY-MM-DD 文本;显式格式使用 strftime 或 rfc3339。
完成后返回*[解析 RFC3339 或带可选时分秒的 YYYY-MM-DD 文本;显式格式使用 strftime 或 rfc3339](> host_datetime_parse text=`内容` pattern=`格式`)*。
## 格式化
+ `时刻`
+ `样式`=None
格式化。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 时刻 | any | 必填 | 本库返回的日期时间记录,不是格式化文本 |
| 样式 | any | None | 宿主日期格式化接口接受的格式样式 |
*> host_datetime_format dt=`时刻` style=`样式`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | 把日期时间记录格式化为 rfc3339、date、time,或显式 strftime 格式的文本 |
这里使用`时刻`、`样式`=None。
调用效应:pure。
把日期时间记录格式化为 rfc3339、date、time,或显式 strftime 格式的文本。
完成后返回*[把日期时间记录格式化为 rfc3339、date、time,或显式 strftime 格式的文本](> host_datetime_format dt=`时刻` style=`样式`)*。
## 加
+ `时刻`
+ `天`=None
+ `小时`=None
+ `分钟`=None
+ `秒数`=None
加。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 时刻 | any | 必填 | 本库返回的日期时间记录,不是格式化文本 |
| 天 | any | None | 增加的完整 24 小时时段数量 |
| 小时 | any | None | 增加的小时数 |
| 分钟 | any | None | 增加的分钟数 |
| 秒数 | any | None | 增加的秒数 |
*> host_datetime_add dt=`时刻` days=`天` hours=`小时` minutes=`分钟` seconds=`秒数`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | 增加经过的天、小时、分钟与秒;这里一天固定为 24 小时,命名时区在移动后重新计算偏移 |
这里使用`时刻`、`天`=None、`小时`=None、`分钟`=None、`秒数`=None。
调用效应:pure。
增加经过的天、小时、分钟与秒;这里一天固定为 24 小时,命名时区在移动后重新计算偏移。
完成后返回*[增加经过的天、小时、分钟与秒;这里一天固定为 24 小时,命名时区在移动后重新计算偏移](> host_datetime_add dt=`时刻` days=`天` hours=`小时` minutes=`分钟` seconds=`秒数`)*。
## 时区
+ `时刻`
+ `区`
时区。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 时刻 | any | 必填 | 本库返回的日期时间记录,不是格式化文本 |
| 区 | any | 必填 | 本操作接受的固定偏移或命名时区 |
*> host_datetime_in_zone dt=`时刻` zone=`区`*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | 用固定偏移或 IANA 时区重新表示同一时刻,保留其 Unix 时间戳 |
这里使用`时刻`、`区`。
调用效应:pure。
用固定偏移或 IANA 时区重新表示同一时刻,保留其 Unix 时间戳。
完成后返回*[用固定偏移或 IANA 时区重新表示同一时刻,保留其 Unix 时间戳](> host_datetime_in_zone dt=`时刻` zone=`区`)*。
## 解析当地时间
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 内容 | text | 必填 | 本操作读取、转换或输出的文本 |
| 时区 | text | 必填 | 本操作接受的固定偏移或命名时区 |
| 歧义处理 | text | "reject" | 夏令时重叠处理:reject、earliest 或 latest |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | map | 解析 IANA 时区的当地时间并返回结果记录;夏令时缺口失败,重叠须选择 reject/earliest/latest。格式为年-月-日 时:分:秒。 |
这里使用`内容`、`时区`、`歧义处理`="reject"。
调用效应:pure。
直接调用此函数:
```sh
marqdo call lib/日期时间.mq.md 解析当地时间 '内容="2024-11-03 01:30:00"' '时区="America/New_York"' '歧义处理="earliest"' --effects none --json
```
解析 IANA 时区的当地时间并返回结果记录;夏令时缺口失败,重叠须选择 reject/earliest/latest。格式为年-月-日 时:分:秒。
完成后返回*[解析 IANA 时区的当地时间并返回结果记录;夏令时缺口失败,重叠须选择 reject/earliest/latest](> host_datetime_local text=`内容` zone=`时区` ambiguity=`歧义处理`)*。
## 加日历日
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 时刻 | map | 必填 | 本库返回的日期时间记录,不是格式化文本 |
| 天数 | number | 必填 | 增加的当地日历天数;跨夏令时保持墙钟时间 |
| 歧义处理 | text | "reject" | 夏令时重叠处理:reject、earliest 或 latest |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | map | 按当地日历增加日期并返回结果记录,跨夏令时保持当地钟点。旧 add 按持续秒数计算,一天为二十四小时。 |
这里使用`时刻`、`天数`、`歧义处理`="reject"。
调用效应:pure。
按当地日历增加日期并返回结果记录,跨夏令时保持当地钟点。旧 add 按持续秒数计算,一天为二十四小时。
完成后返回*[按当地日历增加日期并返回结果记录,跨夏令时保持当地钟点](> host_datetime_calendar_add dt=`时刻` days=`天数` ambiguity=`歧义处理`)*。
+71 -10
View File
@@ -6,39 +6,100 @@ description: 中文时间包装
Unix 时间、格式化、解析与睡眠。
格式化时间戳并控制等待。
能力与边界:读取当前时间需要时钟效应;等待具有控制效应,在捕获模式下会被限制。日历和 IANA 时区规则由日期时间库负责。
本文件就是调用和开发手册:直接导入此文件,或用 marqdo call 按下面的函数标题调用。参数表说明类型和默认值;未填默认值的参数必须提供。返回表是渐进契约,后文说明失败与边界。
实现入口:[src/host/time.rs](../src/host/time.rs)
开发时保持中英文语义一致,先组合公开库;仅在 OS 或算法边界添加宿主原语并声明效应。修改后运行 marqdo check --narrative-ratio 本文件,并执行 tests/stdlib_tasks.rs 的真实任务。
## 此刻秒
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | 当前 Unix 秒 |
调用效应:time.read。
当前 Unix 秒。
调用例:[时间.此刻秒]
*> host_now_unix*
完成后返回*[当前 Unix 秒](host_now_unix())*。
## 此刻毫秒
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | 当前 Unix 毫秒 |
调用效应:time.read。
当前 Unix 毫秒。
*> host_now_ms*
完成后返回*[当前 Unix 毫秒](host_now_ms())*。
## 格式化
+ `秒`
+ `格式`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 秒 | any | 必填 | 以秒为单位的 Unix 时间戳 |
| 格式 | any | 必填 | strftime 日期时间格式文本 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | 用格式把秒格式化成文本 |
这里使用`秒`、`格式`。
调用效应:pure。
直接调用此函数:
```sh
marqdo call lib/时间.mq.md 格式化 '秒=0' '格式="%Y-%m-%d"' --effects none --json
```
用格式把秒格式化成文本。
*> host_format_time unix=`秒` pattern=`格式`*
完成后返回*[用格式把秒格式化成文本](> host_format_time unix=`秒` pattern=`格式`)*。
## 睡眠毫秒
+ `毫秒`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 毫秒 | any | 必填 | 时长或延迟,单位毫秒 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 睡眠指定的毫秒数 |
这里使用`毫秒`。
调用效应:process.control。
睡眠指定的毫秒数。
*> host_sleep_ms ms=`毫秒`*
完成后返回*[睡眠指定的毫秒数](> host_sleep_ms ms=`毫秒`)*。
## 解析时间
+ `内容`
+ `格式`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 内容 | any | 必填 | 本操作读取、转换或输出的文本 |
| 格式 | any | 必填 | strftime 日期时间格式文本 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | 按格式解析内容,得到 Unix 秒 |
这里使用`内容`、`格式`。
调用效应:pure。
按格式解析内容,得到 Unix 秒。
*> host_parse_time text=`内容` pattern=`格式`*
完成后返回*[按格式解析内容,得到 Unix 秒](> host_parse_time text=`内容` pattern=`格式`)*。
+42 -4
View File
@@ -6,18 +6,56 @@ description: 安全随机令牌(中层 M3)。勿用 math.random 生成令牌
安全随机令牌。勿用 math.random 生成令牌。
生成密码学随机令牌。
能力与边界:字节数是输入字节长度,不是输出文本长度。不能用数学伪随机数生成凭证;浏览器熵源依赖运行时桥接,不可悄悄替换为伪随机。
本文件就是调用和开发手册:直接导入此文件,或用 marqdo call 按下面的函数标题调用。参数表说明类型和默认值;未填默认值的参数必须提供。返回表是渐进契约,后文说明失败与边界。
实现入口:[src/host/secrets.rs](../src/host/secrets.rs)
开发时保持中英文语义一致,先组合公开库;仅在 OS 或算法边界添加宿主原语并声明效应。修改后运行 marqdo check --narrative-ratio 本文件,并执行 tests/stdlib_tasks.rs 的真实任务。
## 十六进制令牌
+ `字节数`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 字节数 | any | None | 请求的字节数;None 使用接口默认值 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | 字节长度(默认 16),返回长度为 2*字节数 的小写 hex |
这里使用`字节数`=None。
调用效应:random.read。
直接调用此函数:
```sh
marqdo call lib/机密.mq.md 十六进制令牌 '字节数=16' --effects random.read --json
```
字节长度(默认 16),返回长度为 2*字节数 的小写 hex。
调用例:[机密.十六进制令牌] 字节数=16
*> host_secrets_token_hex n=`字节数`*
完成后返回*[字节长度(默认 16),返回长度为 2*字节数 的小写 hex](> host_secrets_token_hex n=`字节数`)*。
## 网址安全令牌
+ `字节数`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 字节数 | any | None | 请求的字节数;None 使用接口默认值 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | 字节长度(默认 16),URL-safe Base64(无填充) |
这里使用`字节数`=None。
调用效应:random.read。
字节长度(默认 16),URL-safe Base64(无填充)。
*> host_secrets_token_urlsafe n=`字节数`*
完成后返回*[字节长度(默认 16),URL-safe Base64(无填充)](> host_secrets_token_urlsafe n=`字节数`)*。
+25 -1
View File
@@ -6,10 +6,34 @@ description: UUID 版本 4(中层 M6)。经 getrandom 安全随机。
随机 UUID。不要自己拼不可靠的标识。
生成 UUID v4 标识。
能力与边界:使用系统熵生成 UUID v4,不是可复现常量;不能把普通标识当作授权令牌。
本文件就是调用和开发手册:直接导入此文件,或用 marqdo call 按下面的函数标题调用。参数表说明类型和默认值;未填默认值的参数必须提供。返回表是渐进契约,后文说明失败与边界。
实现入口:
实现入口:[src/host/uuid_ops.rs](../src/host/uuid_ops.rs)
开发时保持中英文语义一致,先组合公开库;仅在 OS 或算法边界添加宿主原语并声明效应。修改后运行 marqdo check --narrative-ratio 本文件,并执行 tests/stdlib_tasks.rs 的真实任务。
## 版本4
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | 生成 UUID 版本 4 字符串 |
调用效应:random.read。
直接调用此函数:
```sh
marqdo call lib/标识.mq.md 版本4 --effects random.read --json
```
生成 UUID 版本 4 字符串。
调用例:[标识.版本4]
*> host_uuid_v4*
完成后返回*[生成 UUID 版本 4 字符串](host_uuid_v4())*。
+88 -17
View File
@@ -6,46 +6,117 @@ description: 正则表达式(中层 M1)。Unicode;无回溯引用。
正则表达式。Unicode;无回溯引用。字面替换请用 lib/文本。
进行 Unicode 正则匹配。
能力与边界:不支持反向引用;当前查找返回完整匹配,不承诺捕获组对象或替换回调。字面字符串替换使用文本库。
本文件就是调用和开发手册:直接导入此文件,或用 marqdo call 按下面的函数标题调用。参数表说明类型和默认值;未填默认值的参数必须提供。返回表是渐进契约,后文说明失败与边界。
实现入口:[src/host/re.rs](../src/host/re.rs)
开发时保持中英文语义一致,先组合公开库;仅在 OS 或算法边界添加宿主原语并声明效应。修改后运行 marqdo check --narrative-ratio 本文件,并执行 tests/stdlib_tasks.rs 的真实任务。
## 匹配
+ `内容`
+ `模式`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 内容 | any | 必填 | 本操作读取、转换或输出的文本 |
| 模式 | any | 必填 | 宿主 regex 实现支持的正则表达式 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | bool | 内容是否匹配模式 |
这里使用`内容`、`模式`。
调用效应:pure。
内容是否匹配模式。
调用例:[正则.匹配] 内容=`s` 模式="a+"
*> host_re_is_match text=`内容` pattern=`模式`*
完成后返回*[内容是否匹配模式](> host_re_is_match text=`内容` pattern=`模式`)*。
## 查找
+ `内容`
+ `模式`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 内容 | any | 必填 | 本操作读取、转换或输出的文本 |
| 模式 | any | 必填 | 宿主 regex 实现支持的正则表达式 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 在内容中查找模式的首个匹配;没有 → None |
这里使用`内容`、`模式`。
调用效应:pure。
在内容中查找模式的首个匹配;没有 → None。
*> host_re_find text=`内容` pattern=`模式`*
完成后返回*[在内容中查找模式的首个匹配;没有 → None](> host_re_find text=`内容` pattern=`模式`)*。
## 查找全部
+ `内容`
+ `模式`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 内容 | any | 必填 | 本操作读取、转换或输出的文本 |
| 模式 | any | 必填 | 宿主 regex 实现支持的正则表达式 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | list | 在内容中查找模式的全部匹配 |
这里使用`内容`、`模式`。
调用效应:pure。
直接调用此函数:
```sh
marqdo call lib/正则.mq.md 查找全部 '内容="a12 b34"' '模式="[0-9]+"' --effects none --json
```
在内容中查找模式的全部匹配。
*> host_re_find_all text=`内容` pattern=`模式`*
完成后返回*[在内容中查找模式的全部匹配](> host_re_find_all text=`内容` pattern=`模式`)*。
## 替换
+ `内容`
+ `模式`
+ `为`
+ `次数`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 内容 | any | 必填 | 本操作读取、转换或输出的文本 |
| 模式 | any | 必填 | 宿主 regex 实现支持的正则表达式 |
| 为 | any | 必填 | 替换匹配片段所用的文本 |
| 次数 | any | None | 最大替换次数;None 使用操作说明中的默认值 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | 用为替换内容中匹配模式的部分;可选次数限制(缺省 = 全部) |
这里使用`内容`、`模式`、`为`、`次数`=None。
调用效应:pure。
用为替换内容中匹配模式的部分;可选次数限制(缺省 = 全部)。
*> host_re_replace text=`内容` pattern=`模式` with=`为` count=`次数`*
完成后返回*[用为替换内容中匹配模式的部分;可选次数限制(缺省 = 全部)](> host_re_replace text=`内容` pattern=`模式` with=`为` count=`次数`)*。
## 拆分
+ `内容`
+ `模式`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 内容 | any | 必填 | 本操作读取、转换或输出的文本 |
| 模式 | any | 必填 | 宿主 regex 实现支持的正则表达式 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | list | 按模式拆分内容 |
这里使用`内容`、`模式`。
调用效应:pure。
按模式拆分内容。
*> host_re_split text=`内容` pattern=`模式`*
完成后返回*[按模式拆分内容](> host_re_split text=`内容` pattern=`模式`)*。
+480 -120
View File
@@ -9,107 +9,255 @@ import:
浏览器效应助手(WASM 客户端)。优先 GFM 表格 + 本库;勿用 json.set 链拼效应。
使用普通结构化值构造浏览器效果。
能力与边界:构造效果是纯数据变换,由官方 WASM 桥接在浏览器中执行。原生进程生成效果记录不表示 DOM 已更新;业务逻辑仍写在 Marqdo 中。
本文件就是调用和开发手册:直接导入此文件,或用 marqdo call 按下面的函数标题调用。参数表说明类型和默认值;未填默认值的参数必须提供。返回表是渐进契约,后文说明失败与边界。
实现入口:[crates/marqdo-wasm/js/marqdo-bridge.js](../crates/marqdo-wasm/js/marqdo-bridge.js)
开发时保持中英文语义一致,先组合公开库;仅在 OS 或算法边界添加宿主原语并声明效应。修改后运行 marqdo check --narrative-ratio 本文件,并执行 tests/stdlib_tasks.rs 的真实任务。
## 设文本
+ `选择器`
+ `文本`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 选择器 | any | 必填 | 目标浏览器元素的 CSS 选择器 |
| 文本 | any | 必填 | 本操作读取、转换或输出的文本 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | 构造 set_text 效应 |
这里使用`选择器`、`文本`。
调用效应:pure。
直接调用此函数:
```sh
marqdo call lib/浏览器.mq.md 设文本 '选择器="#status"' '文本="Ready"' --effects none --json
```
构造 set_text 效应。
**`m` = > table.put in=None at=选择器 value=文本**
*> table.put in=None at="set_text" value=m*
得到**`m` = [返回更新后的结构化值](table.put(in=None, at=`选择器`, value=`文本`))**。
完成后返回*[在新记录中设置 set_text 字段](table.put(in=None, at="set_text", value=`m`))*。
## 设HTML
+ `选择器`
+ `html`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 选择器 | any | 必填 | 目标浏览器元素的 CSS 选择器 |
| html | any | 必填 | HTML 片段;普通不可信文本应使用设文本 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | 构造 set_html 效应 |
这里使用`选择器`、`html`。
调用效应:pure。
构造 set_html 效应。
**`m` = > table.put in=None at=选择器 value=html**
*> table.put in=None at="set_html" value=m*
得到**`m` = [返回更新后的结构化值](table.put(in=None, at=`选择器`, value=`html`))**。
完成后返回*[在新记录中设置 set_html 字段](table.put(in=None, at="set_html", value=`m`))*。
## 设值
+ `选择器`
+ `值`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 选择器 | any | 必填 | 目标浏览器元素的 CSS 选择器 |
| 值 | any | 必填 | 待转换或保存的值;不会就地修改输入 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | 构造 set_value 效应 |
这里使用`选择器`、`值`。
调用效应:pure。
构造 set_value 效应。
**`m` = > table.put in=None at=选择器 value=值**
*> table.put in=None at="set_value" value=m*
得到**`m` = [返回更新后的结构化值](table.put(in=None, at=`选择器`, value=`值`))**。
完成后返回*[在新记录中设置 set_value 字段](table.put(in=None, at="set_value", value=`m`))*。
## 设类
+ `选择器`
+ `类`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 选择器 | any | 必填 | 目标浏览器元素的 CSS 选择器 |
| 类 | any | 必填 | 以空格分隔的 CSS 类名 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | 构造 set_class 效应 |
这里使用`选择器`、`类`。
调用效应:pure。
构造 set_class 效应。
**`m` = > table.put in=None at=选择器 value=类**
*> table.put in=None at="set_class" value=m*
得到**`m` = [返回更新后的结构化值](table.put(in=None, at=`选择器`, value=`类`))**。
完成后返回*[在新记录中设置 set_class 字段](table.put(in=None, at="set_class", value=`m`))*。
## 加类
+ `选择器`
+ `类`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 选择器 | any | 必填 | 目标浏览器元素的 CSS 选择器 |
| 类 | any | 必填 | 以空格分隔的 CSS 类名 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | 构造 add_class 效应(classList.add;可用空格分隔多个类名) |
这里使用`选择器`、`类`。
调用效应:pure。
构造 add_class 效应(classList.add;可用空格分隔多个类名)。
**`m` = > table.put in=None at=选择器 value=类**
*> table.put in=None at="add_class" value=m*
得到**`m` = [返回更新后的结构化值](table.put(in=None, at=`选择器`, value=`类`))**。
完成后返回*[在新记录中设置 add_class 字段](table.put(in=None, at="add_class", value=`m`))*。
## 去类
+ `选择器`
+ `类`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 选择器 | any | 必填 | 目标浏览器元素的 CSS 选择器 |
| 类 | any | 必填 | 以空格分隔的 CSS 类名 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | 构造 remove_class 效应 |
这里使用`选择器`、`类`。
调用效应:pure。
构造 remove_class 效应。
**`m` = > table.put in=None at=选择器 value=类**
*> table.put in=None at="remove_class" value=m*
得到**`m` = [返回更新后的结构化值](table.put(in=None, at=`选择器`, value=`类`))**。
完成后返回*[在新记录中设置 remove_class 字段](table.put(in=None, at="remove_class", value=`m`))*。
## 切类
+ `选择器`
+ `类`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 选择器 | any | 必填 | 目标浏览器元素的 CSS 选择器 |
| 类 | any | 必填 | 以空格分隔的 CSS 类名 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | 构造 toggle_class 效应 |
这里使用`选择器`、`类`。
调用效应:pure。
构造 toggle_class 效应。
**`m` = > table.put in=None at=选择器 value=类**
*> table.put in=None at="toggle_class" value=m*
得到**`m` = [返回更新后的结构化值](table.put(in=None, at=`选择器`, value=`类`))**。
完成后返回*[在新记录中设置 toggle_class 字段](table.put(in=None, at="toggle_class", value=`m`))*。
## 设样式
+ `选择器`
+ `样式`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 选择器 | any | 必填 | 目标浏览器元素的 CSS 选择器 |
| 样式 | any | 必填 | 目标元素的 CSS 属性与值记录 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | 构造 set_style 效应;样式为属性表或 cssText 字符串 |
这里使用`选择器`、`样式`。
调用效应:pure。
构造 set_style 效应;样式为属性表或 cssText 字符串。
**`m` = > table.put in=None at=选择器 value=样式**
*> table.put in=None at="set_style" value=m*
得到**`m` = [返回更新后的结构化值](table.put(in=None, at=`选择器`, value=`样式`))**。
完成后返回*[在新记录中设置 set_style 字段](table.put(in=None, at="set_style", value=`m`))*。
## 设属性
+ `选择器`
+ `属性`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 选择器 | any | 必填 | 目标浏览器元素的 CSS 选择器 |
| 属性 | any | 必填 | 目标元素的 HTML 属性与值记录 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | 构造 set_attr 效应 |
这里使用`选择器`、`属性`。
调用效应:pure。
构造 set_attr 效应。
**`m` = > table.put in=None at=选择器 value=属性**
*> table.put in=None at="set_attr" value=m*
得到**`m` = [返回更新后的结构化值](table.put(in=None, at=`选择器`, value=`属性`))**。
完成后返回*[在新记录中设置 set_attr 字段](table.put(in=None, at="set_attr", value=`m`))*。
## 包装
+ `键`
+ `值`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 键 | any | 必填 | 要读取、比较或更新的字段名或存储键 |
| 值 | any | 必填 | 待转换或保存的值;不会就地修改输入 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | 单键效应包装 |
这里使用`键`、`值`。
调用效应:pure。
单键效应包装。
*> table.put in=None at=键 value=值*
完成后返回*[返回更新后的结构化值](table.put(in=None, at=`键`, value=`值`))*。
## 合并
+ `甲`
+ `乙`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 甲 | any | 必填 | 第一个浏览器效果记录 |
| 乙 | any | 必填 | 合入第一个记录的浏览器效果记录 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | 合并两张效应表,右侧优先 |
这里使用`甲`、`乙`。
调用效应:pure。
合并两张效应表,右侧优先。
*> table.merge a=`甲` b=`乙`*
完成后返回*[调用 merge](table.merge(a=`甲`, b=`乙`))*。
## 画布
+ `选择器`
+ `命令`
+ `清空`=True
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 选择器 | any | 必填 | 目标浏览器元素的 CSS 选择器 |
| 命令 | any | 必填 | 按执行顺序排列的画布绘制命令列表 |
| 清空 | any | True | 绘制命令前是否清空画布 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | 构造 canvas 效应;命令一般为 @ 行表 |
这里使用`选择器`、`命令`、`清空`=True。
调用效应:pure。
构造 canvas 效应;命令一般为 @ 行表。
@@ -119,34 +267,58 @@ import:
|-----|-------|----------|
| `选择器` | `清空` | `命令` |
*> table.put in=None at="canvas" value=spec*
完成后返回*[在新记录中设置 canvas 字段](table.put(in=None, at="canvas", value=`spec`))*。
## 音频
+ `操作`="play"
+ `id`="default"
+ `源`=""
+ `频率`=None
+ `毫秒`=None
+ `选择器`=""
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 操作 | any | "play" | 音频命令:play、pause 或 stop |
| id | any | "default" | 音频通道标识 |
| 源 | any | "" | 音频 URL;beep 表示合成提示音 |
| 频率 | any | None | 振荡器频率,单位 Hz |
| 毫秒 | any | None | 时长或延迟,单位毫秒 |
| 选择器 | any | "" | 目标浏览器元素的 CSS 选择器 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | 构造 audio 效应 |
这里使用`操作`="play"、`id`="default"、`源`=""、`频率`=None、`毫秒`=None、`选择器`=""。
调用效应:pure。
构造 audio 效应。
**`spec` = > table.put in=None at="op" value=操作**
**`spec` = > table.put in=`spec` at="id" value=id**
本函数只返回效果记录,不会立刻播放声音。播放源、合成频率与音频元素按桥接规则选择;浏览器可能要求用户先交互。
得到**`spec` = [在新记录中设置 op 字段](table.put(in=None, at="op", value=`操作`))**。
得到**`spec` = [在新记录中设置 id 字段](table.put(in=`spec`, at="id", value=`id`))**。
1. `源` != ""
**`spec` = > table.put in=`spec` at="src" value=源**
得到**`spec` = [在新记录中设置 src 字段](table.put(in=`spec`, at="src", value=`源`))**。
1. `频率` != None
**`spec` = > table.put in=`spec` at="freq" value=频率**
得到**`spec` = [在新记录中设置 freq 字段](table.put(in=`spec`, at="freq", value=`频率`))**。
1. `毫秒` != None
**`spec` = > table.put in=`spec` at="ms" value=毫秒**
得到**`spec` = [在新记录中设置 ms 字段](table.put(in=`spec`, at="ms", value=`毫秒`))**。
1. `选择器` != ""
**`spec` = > table.put in=`spec` at="sel" value=选择器**
*> table.put in=None at="audio" value=spec*
得到**`spec` = [在新记录中设置 sel 字段](table.put(in=`spec`, at="sel", value=`选择器`))**。
完成后返回*[在新记录中设置 audio 字段](table.put(in=None, at="audio", value=`spec`))*。
## 读文件
+ `选择器`
+ `然后`
+ `格式`="text"
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 选择器 | any | 必填 | 目标浏览器元素的 CSS 选择器 |
| 然后 | any | 必填 | 桥接结果回调的 Marqdo 函数名;空文本表示无回调 |
| 格式 | any | "text" | 浏览器桥接读取文件所用的内容表示 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | 构造 read_file 效应 |
这里使用`选择器`、`然后`、`格式`="text"。
调用效应:pure。
构造 read_file 效应。
@@ -156,32 +328,78 @@ import:
|-----|----|------|
| `选择器` | `格式` | `然后` |
*> table.put in=None at="read_file" value=spec*
完成后返回*[在新记录中设置 read_file 字段](table.put(in=None, at="read_file", value=`spec`))*。
## 观察
+ `规格`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 规格 | any | 必填 | 效果规格;使用单条记录或 @ 行记录列表 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | 构造 observe 效应 |
这里使用`规格`。
调用效应:pure。
构造 observe 效应。
*> table.put in=None at="observe" value=规格*
完成后返回*[在新记录中设置 observe 字段](table.put(in=None, at="observe", value=`规格`))*。
## 取消观察
+ `规格`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 规格 | any | 必填 | 效果规格;使用单条记录或 @ 行记录列表 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | 构造 unobserve 效应 |
这里使用`规格`。
调用效应:pure。
构造 unobserve 效应。
*> table.put in=None at="unobserve" value=规格*
完成后返回*[在新记录中设置 unobserve 字段](table.put(in=None, at="unobserve", value=`规格`))*。
## 聚焦
+ `选择器`
聚焦。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 选择器 | any | 必填 | 目标浏览器元素的 CSS 选择器 |
*> table.put in=None at="focus" value=选择器*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | 构造目标元素的聚焦效果;浏览器桥接在处理函数返回后执行 |
这里使用`选择器`。
调用效应:pure。
构造目标元素的聚焦效果;浏览器桥接在处理函数返回后执行。
完成后返回*[在新记录中设置 focus 字段](table.put(in=None, at="focus", value=`选择器`))*。
## 导航
+ `url`
+ `替换`=False
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| url | text | 必填 | 目标 URL;HTTP 接口接受 http 或 https |
| 替换 | any | False | 导航时是否替换当前历史项 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | 构造 navigate 效果记录,由浏览器桥接消费后执行;调用本函数本身不修改页面 |
这里使用`url`、`替换`=False。
调用效应:pure。
构造 navigate 效果记录,由浏览器桥接消费后执行;调用本函数本身不修改页面。
`spec` =
@@ -189,13 +407,24 @@ import:
|-----|---------|
| `url` | `替换` |
*> table.put in=None at="navigate" value=spec*
完成后返回*[在新记录中设置 navigate 字段](table.put(in=None, at="navigate", value=`spec`))*。
## 存设
+ `键`
+ `值`
+ `作用域`="memory"
+ `然后`=""
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 键 | any | 必填 | 要读取、比较或更新的字段名或存储键 |
| 值 | any | 必填 | 待转换或保存的值;不会就地修改输入 |
| 作用域 | any | "memory" | 存储范围:memory、local 或 session |
| 然后 | any | "" | 桥接结果回调的 Marqdo 函数名;空文本表示无回调 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | SPA 客户端状态写入 |
这里使用`键`、`值`、`作用域`="memory"、`然后`=""。
调用效应:pure。
SPA 客户端状态写入。优先 `作用域=memory`(页内内存)。
可选 `然后`:写入后回调,参数含 `{ok, op, key, scope}`。
@@ -203,31 +432,53 @@ SPA 客户端状态写入。优先 `作用域=memory`(页内内存)。
`spec` =
| op | key | value | scope |
|----|-----|-------|-------|
| ---- | ----- | ------- | ------- |
| set | `键` | `值` | `作用域` |
1. `然后` != ""
**`spec` = > table.put in=spec at="then" value=然后**
*> table.put in=None at="storage" value=spec*
得到**`spec` = [在新记录中设置 then 字段](table.put(in=`spec`, at="then", value=`然后`))**。
完成后返回*[在新记录中设置 storage 字段](table.put(in=None, at="storage", value=`spec`))*。
## 存取
+ `键`
+ `然后`
+ `作用域`="memory"
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 键 | any | 必填 | 要读取、比较或更新的字段名或存储键 |
| 然后 | any | 必填 | 桥接结果回调的 Marqdo 函数名;空文本表示无回调 |
| 作用域 | any | "memory" | 存储范围:memory、local 或 session |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | 读取键并回调 `然后`,参数含 `{ok, value, found, key, scope}` |
这里使用`键`、`然后`、`作用域`="memory"。
调用效应:pure。
读取键并回调 `然后`,参数含 `{ok, value, found, key, scope}`。
`spec` =
| op | key | then | scope |
|----|-----|------|-------|
| ---- | ----- | ------ | ------- |
| get | `键` | `然后` | `作用域` |
*> table.put in=None at="storage" value=spec*
完成后返回*[在新记录中设置 storage 字段](table.put(in=None, at="storage", value=`spec`))*。
## 页跳
+ `url`
+ `替换`=False
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| url | text | 必填 | 目标 URL;HTTP 接口接受 http 或 https |
| 替换 | any | False | 导航时是否替换当前历史项 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | SPA 导航(bridge `navigate`) |
这里使用`url`、`替换`=False。
调用效应:pure。
SPA 导航(bridge `navigate`)。
@@ -237,19 +488,43 @@ SPA 导航(bridge `navigate`)。
|-----|---------|
| `url` | `替换` |
*> table.put in=None at="navigate" value=spec*
完成后返回*[在新记录中设置 navigate 字段](table.put(in=None, at="navigate", value=`spec`))*。
## 存储
+ `规格`
存储。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 规格 | any | 必填 | 存储操作记录:op、key、scope,以及可选 value 和 then |
*> table.put in=None at="storage" value=规格*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | 把存储规格包装为浏览器效果;桥接处理 op、key、value、scope 和 then |
这里使用`规格`。
调用效应:pure。
把存储规格包装为浏览器效果;桥接处理 op、key、value、scope 和 then。
完成后返回*[在新记录中设置 storage 字段](table.put(in=None, at="storage", value=`规格`))*。
## 定时
+ `毫秒`
+ `然后`
+ `id`="default"
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 毫秒 | any | 必填 | 时长或延迟,单位毫秒 |
| 然后 | any | 必填 | 桥接结果回调的 Marqdo 函数名;空文本表示无回调 |
| id | any | "default" | 定时器标识,之后传给清除定时器 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | 构造 interval 效果记录,由浏览器桥接消费后执行;调用本函数本身不修改页面 |
这里使用`毫秒`、`然后`、`id`="default"。
调用效应:pure。
构造 interval 效果记录,由浏览器桥接消费后执行;调用本函数本身不修改页面。
`spec` =
@@ -257,20 +532,44 @@ SPA 导航(bridge `navigate`)。
|----|------|----|
| `毫秒` | `然后` | `id` |
*> table.put in=None at="interval" value=spec*
完成后返回*[在新记录中设置 interval 字段](table.put(in=None, at="interval", value=`spec`))*。
## 清定时
+ `id`="default"
清定时。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| id | any | "default" | 对应创建或启动操作返回的标识 |
**`spec` = > table.put in=None at="id" value=id**
*> table.put in=None at="clear_interval" value=spec*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | 使用创建定时器时相同的标识,构造取消定时器效果 |
这里使用`id`="default"。
调用效应:pure。
使用创建定时器时相同的标识,构造取消定时器效果。
得到**`spec` = [在新记录中设置 id 字段](table.put(in=None, at="id", value=`id`))**。
完成后返回*[在新记录中设置 clear_interval 字段](table.put(in=None, at="clear_interval", value=`spec`))*。
## 拉取
+ `url`
+ `然后`
+ `方法`="GET"
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| url | text | 必填 | 目标 URL;HTTP 接口接受 http 或 https |
| 然后 | any | 必填 | 桥接结果回调的 Marqdo 函数名;空文本表示无回调 |
| 方法 | any | "GET" | HTTP 方法,例如 GET 或 POST |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | 构造 fetch 效果记录,由浏览器桥接消费后执行;调用本函数本身不修改页面 |
这里使用`url`、`然后`、`方法`="GET"。
调用效应:pure。
构造 fetch 效果记录,由浏览器桥接消费后执行;调用本函数本身不修改页面。
`spec` =
@@ -278,11 +577,24 @@ SPA 导航(bridge `navigate`)。
|-----|------|--------|
| `url` | `然后` | `方法` |
*> table.put in=None at="fetch" value=spec*
完成后返回*[在新记录中设置 fetch 字段](table.put(in=None, at="fetch", value=`spec`))*。
## 拉取全部
+ `请求`
+ `然后`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 请求 | any | 必填 | 按顺序排列的浏览器请求规格记录列表 |
| 然后 | any | 必填 | 桥接结果回调的 Marqdo 函数名;空文本表示无回调 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | 构造 fetch_all 效果记录,由浏览器桥接消费后执行;调用本函数本身不修改页面 |
这里使用`请求`、`然后`。
调用效应:pure。
构造 fetch_all 效果记录,由浏览器桥接消费后执行;调用本函数本身不修改页面。
`spec` =
@@ -290,11 +602,24 @@ SPA 导航(bridge `navigate`)。
|----------|------|
| `请求` | `然后` |
*> table.put in=None at="fetch_all" value=spec*
完成后返回*[在新记录中设置 fetch_all 字段](table.put(in=None, at="fetch_all", value=`spec`))*。
## 延后
+ `毫秒`
+ `然后`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 毫秒 | any | 必填 | 时长或延迟,单位毫秒 |
| 然后 | any | 必填 | 桥接结果回调的 Marqdo 函数名;空文本表示无回调 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | 构造 after 效果记录,由浏览器桥接消费后执行;调用本函数本身不修改页面 |
这里使用`毫秒`、`然后`。
调用效应:pure。
构造 after 效果记录,由浏览器桥接消费后执行;调用本函数本身不修改页面。
`spec` =
@@ -302,27 +627,62 @@ SPA 导航(bridge `navigate`)。
|----|------|
| `毫秒` | `然后` |
*> table.put in=None at="after" value=spec*
完成后返回*[在新记录中设置 after 字段](table.put(in=None, at="after", value=`spec`))*。
## 套接字
+ `规格`
套接字。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 规格 | any | 必填 | 一条桥接效果规格记录 |
*> table.put in=None at="ws" value=规格*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | 把 WebSocket 操作规格包装为浏览器桥接效果;本函数不会打开原生套接字 |
这里使用`规格`。
调用效应:pure。
把 WebSocket 操作规格包装为浏览器桥接效果;本函数不会打开原生套接字。
完成后返回*[在新记录中设置 ws 字段](table.put(in=None, at="ws", value=`规格`))*。
## 剪贴板
+ `文本`
剪贴板。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 文本 | any | 必填 | 本操作读取、转换或输出的文本 |
**`spec` = > table.put in=None at="text" value=文本**
*> table.put in=None at="clipboard" value=spec*
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | 按文本构造剪贴板效果;消费效果时仍受浏览器权限和用户手势要求约束 |
这里使用`文本`。
调用效应:pure。
按文本构造剪贴板效果;消费效果时仍受浏览器权限和用户手势要求约束。
得到**`spec` = [在新记录中设置 text 字段](table.put(in=None, at="text", value=`文本`))**。
完成后返回*[在新记录中设置 clipboard 字段](table.put(in=None, at="clipboard", value=`spec`))*。
## 下载
+ `正文`
+ `文件名`="download.txt"
+ `mime`="text/plain;charset=utf-8"
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 正文 | any | 必填 | 请求正文;文档操作中为替换正文 |
| 文件名 | any | "download.txt" | 建议的下载文件名 |
| mime | any | "text/plain;charset=utf-8" | 内容的 MIME 类型 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | 构造 download 效果记录,由浏览器桥接消费后执行;调用本函数本身不修改页面 |
这里使用`正文`、`文件名`="download.txt"、`mime`="text/plain;charset=utf-8"。
调用效应:pure。
构造 download 效果记录,由浏览器桥接消费后执行;调用本函数本身不修改页面。
`spec` =
@@ -330,4 +690,4 @@ SPA 导航(bridge `navigate`)。
|------|----------|------|
| `正文` | `文件名` | `mime` |
*> table.put in=None at="download" value=spec*
完成后返回*[在新记录中设置 download 字段](table.put(in=None, at="download", value=`spec`))*。
+145 -22
View File
@@ -6,76 +6,188 @@ description: 中文系统包装(加载环境 可选 路径=)
中文系统包装(加载环境 可选 路径=)
读取执行元数据并与宿主系统交互。
能力与边界:元信息与模块源码来自入口文档,不是被导入库。执行进程需要 process.exec;读写环境和读取配置具有独立效应。
本文件就是调用和开发手册:直接导入此文件,或用 marqdo call 按下面的函数标题调用。参数表说明类型和默认值;未填默认值的参数必须提供。返回表是渐进契约,后文说明失败与边界。
实现入口:[src/host/sys.rs](../src/host/sys.rs)
开发时保持中英文语义一致,先组合公开库;仅在 OS 或算法边界添加宿主原语并声明效应。修改后运行 marqdo check --narrative-ratio 本文件,并执行 tests/stdlib_tasks.rs 的真实任务。
## 取环境
+ `名`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 名 | any | 必填 | 环境变量名 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 读取环境变量名 |
这里使用`名`。
调用效应:environment.read。
读取环境变量名。
*> host_env_get name=`名`*
完成后返回*[读取环境变量名](> host_env_get name=`名`)*。
## 设环境
+ `名`
+ `值`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 名 | any | 必填 | 环境变量名 |
| 值 | any | 必填 | 待转换或保存的值;不会就地修改输入 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 设置环境变量名的值 |
这里使用`名`、`值`。
调用效应:environment.write。
设置环境变量名的值。
*> host_env_set name=`名` value=`值`*
完成后返回*[设置环境变量名的值](> host_env_set name=`名` value=`值`)*。
## 加载环境
+ `路径`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 路径 | any | None | 授权文件根目录内的路径 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 加载 `.env`(可选具名实参 `路径=`) |
这里使用`路径`=None。
调用效应:environment.write,fs.read。
加载 `.env`(可选具名实参 `路径=`)。不覆盖已有进程环境变量。
*> host_dotenv_load path=`路径`*
完成后返回*[加载 .env(可选具名实参 路径=)](> host_dotenv_load path=`路径`)*。
## 参数表
| 返回 | 类型 | 说明 |
|---|---|---|
| result | list | 进程参数表 |
调用效应:pure。
进程参数表。
*> host_args*
完成后返回*[进程参数表](host_args())*。
## 工作目录
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | 当前工作目录 |
调用效应:pure。
当前工作目录。
*> host_cwd*
完成后返回*[当前工作目录](host_cwd())*。
## 元信息
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | 入口 `.mq.md` 已绑定的 Artifact Metadata(映射) |
调用效应:pure。
直接调用此函数:
```sh
marqdo call lib/系统.mq.md 元信息 --effects none --json
```
入口 `.mq.md` 已绑定的 Artifact Metadata(映射)。见 `doc/design/binding.md`。
*> host_meta*
完成后返回*[入口 .mq.md 已绑定的 Artifact Metadata(映射)](host_meta())*。
## 取元信息
+ `键`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 键 | any | 必填 | 要读取、比较或更新的字段名或存储键 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 按键取一条元信息;缺失 → None |
这里使用`键`。
调用效应:pure。
按键取一条元信息;缺失 → None。
*> host_meta_get key=`键`*
完成后返回*[按键取一条元信息;缺失 → None](> host_meta_get key=`键`)*。
## 工件种类
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 入口 Artifact 分类:`web` / `endpoint` / `prompt` / `other`;无 `type`/`类型` → None |
调用效应:pure。
入口 Artifact 分类:`web` / `endpoint` / `prompt` / `other`;无 `type`/`类型` → None。ADR 0007。
*> host_artifact_kind*
完成后返回*[入口 Artifact 分类:web / endpoint / prompt / other;无 type/类型 → None](host_artifact_kind())*。
## 模块源码
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | 入口 `.mq.md` 全文(供 document-as-prompt) |
调用效应:pure。
入口 `.mq.md` 全文(供 document-as-prompt)。未设置时为空文本。
*> host_module_source*
完成后返回*[入口 .mq.md 全文(供 document-as-prompt)](host_module_source())*。
## 退出
+ `码`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 码 | any | 必填 | 进程退出码;零表示成功 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 以代码退出进程 |
这里使用`码`。
调用效应:process.control。
以代码退出进程。
*> host_exit code=`码`*
完成后返回*[以代码退出进程](> host_exit code=`码`)*。
## 执行
+ `命令`
+ `参数`=None
+ `捕获`=False
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 命令 | any | 必填 | 可执行命令或解释器覆盖配置 |
| 参数 | any | None | 传给命令或函数的实参列表 |
| 捕获 | any | False | 是否返回命令输出而非直接转发 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 运行子进程 |
这里使用`命令`、`参数`=None、`捕获`=False。
调用效应:process.exec。
运行子进程。默认返回退出码(整数)。
@@ -83,11 +195,22 @@ description: 中文系统包装(加载环境 可选 路径=)
在 `**…**` 内优先写裸变量 `参数=参数`;`` 参数=`参数` `` 亦可。
*> host_exec cmd=`命令` args=`参数` capture=`捕获`*
完成后返回*[运行子进程](> host_exec cmd=`命令` args=`参数` capture=`捕获`)*。
## 发布流事件
+ `事件`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 事件 | any | 必填 | 发布到当前流的结构化事件 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 向进程内 EventBus 发布流事件(供 `marqdo view` SSE) |
这里使用`事件`。
调用效应:output.write。
向进程内 EventBus 发布流事件(供 `marqdo view` SSE)。无订阅者时为空操作。
*> host_stream_publish event=`事件`*
完成后返回*[向进程内 EventBus 发布流事件(供 marqdo view SSE)](> host_stream_publish event=`事件`)*。
+100
View File
@@ -0,0 +1,100 @@
---
markup: occlusion
---
可恢复结果使用普通记录 ok/value/error;error 内含 code/message/operation。
先判断 ok 再使用 value;结果包装不会绕过宿主权限检查。
以统一数据契约组合可恢复结果。
能力与边界:先检查 ok,再使用 value;HTTP 状态和子进程退出码仍需按领域规则判断;错误含 code/message/operation。尝试接口处理已定义的可恢复失败,不是捕获任意运行时错误的异常系统,也不会授予权限。
本文件就是调用和开发手册:直接导入此文件,或用 marqdo call 按下面的函数标题调用。参数表说明类型和默认值;未填默认值的参数必须提供。返回表是渐进契约,后文说明失败与边界。
实现入口:[src/host/result.rs](../src/host/result.rs)
开发时保持中英文语义一致,先组合公开库;仅在 OS 或算法边界添加宿主原语并声明效应。修改后运行 marqdo check --narrative-ratio 本文件,并执行 tests/stdlib_tasks.rs 的真实任务。
## 成功
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 值 | any | 必填 | 成功操作的值,包括 None |
| 返回 | 类型 | 说明 |
|------|------|------|
| 结果 | map | Successful Result |
这里使用`值`。
将当前输入交给 成功,保留同源能力的返回值和失败语义。
调用效应:pure。
`out` =
| ok | value | error |
|----|-------|-------|
| True | `值` | None |
完成后返回*out*。
## 失败
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 错误码 | text | 必填 | 供程序判断的稳定错误类别 |
| 消息 | text | 必填 | 供人阅读的错误解释 |
| 操作 | text | "application" | 发生失败的操作名 |
| 返回 | 类型 | 说明 |
|------|------|------|
| 结果 | map | Failed Result |
这里使用`错误码`、`消息`、`操作`="application"。
将当前输入交给 失败,保留同源能力的返回值和失败语义。
调用效应:pure。
`failure` =
| code | message | operation |
|------|---------|-----------|
| `错误码` | `消息` | `操作` |
`out` =
| ok | value | error |
|----|-------|-------|
| False | None | `failure` |
完成后返回*out*。
## 值或默认
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 结果 | map | 必填 | 可恢复操作返回的结果记录 |
| 默认值 | any | None | 操作失败时明确采用的替代值 |
| 返回 | 类型 | 说明 |
|------|------|------|
| 结果 | any | Successful value or fallback |
这里使用`结果`、`默认值`=None。
调用效应:pure。
直接调用此函数:
```sh
marqdo call lib/结果.mq.md 值或默认 '结果={"ok":false,"value":null,"error":{"code":"missing","message":"absent","operation":"example"}}' '默认值="fallback"' --effects none --json
```
只在 ok 为真时读取 value;成功且值为 None 时仍保留 None。仅在操作失败时使用默认值,不按真假性吞掉零或空文本。
1. [operation succeeded](access(`结果`, "ok"))
完成后返回*[successful value](access(结果, "value"))*。
2. *
完成后返回*默认值*。
+55 -6
View File
@@ -6,25 +6,74 @@ description: 薄均值 / 中位数 / 样本标准差(中层 Mid2 M10)。非
薄数值摘要。不是数据框库。
计算基础描述统计。
能力与边界:均值和中位数要求非空数字列表;这不是数据帧或数值数组运行时。矩阵计算由线性代数扩展负责。
本文件就是调用和开发手册:直接导入此文件,或用 marqdo call 按下面的函数标题调用。参数表说明类型和默认值;未填默认值的参数必须提供。返回表是渐进契约,后文说明失败与边界。
实现入口:[src/host/stats.rs](../src/host/stats.rs)
开发时保持中英文语义一致,先组合公开库;仅在 OS 或算法边界添加宿主原语并声明效应。修改后运行 marqdo check --narrative-ratio 本文件,并执行 tests/stdlib_tasks.rs 的真实任务。
## 均值
+ `列表`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 列表 | any | 必填 | 输入列表;不可变更新返回新列表 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | 列表的算术均值 |
这里使用`列表`。
调用效应:pure。
直接调用此函数:
```sh
marqdo call lib/统计.mq.md 均值 '列表=[1,2,3]' --effects none --json
```
列表的算术均值。
调用例:[统计.均值] 列表=`xs`
*> host_stats_mean list=`列表`*
完成后返回*[列表的算术均值](> host_stats_mean list=`列表`)*。
## 中位数
+ `列表`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 列表 | any | 必填 | 输入列表;不可变更新返回新列表 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | 列表的中位数 |
这里使用`列表`。
调用效应:pure。
列表的中位数。
*> host_stats_median list=`列表`*
完成后返回*[列表的中位数](> host_stats_median list=`列表`)*。
## 标准差
+ `列表`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 列表 | any | 必填 | 输入列表;不可变更新返回新列表 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | number | 样本标准差;至少两个值 |
这里使用`列表`。
调用效应:pure。
样本标准差;至少两个值。
*> host_stats_stdev list=`列表`*
完成后返回*[样本标准差;至少两个值](> host_stats_stdev list=`列表`)*。
+94 -12
View File
@@ -6,46 +6,128 @@ description: Base64、十六进制与基32编解码(中层 M1 + Mid2 M8)。U
Base64、十六进制与基32编解码。UTF-8 文本往返。
在 UTF-8 文本与 Base64、十六进制、Base32 之间转换。
能力与边界:这些历史接口用于文本往返。任意二进制应使用字节库的从编码;把无效 UTF-8 解码为文本会失败。
本文件就是调用和开发手册:直接导入此文件,或用 marqdo call 按下面的函数标题调用。参数表说明类型和默认值;未填默认值的参数必须提供。返回表是渐进契约,后文说明失败与边界。
实现入口:[src/host/encoding.rs](../src/host/encoding.rs)
开发时保持中英文语义一致,先组合公开库;仅在 OS 或算法边界添加宿主原语并声明效应。修改后运行 marqdo check --narrative-ratio 本文件,并执行 tests/stdlib_tasks.rs 的真实任务。
## 基64编码
+ `内容`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 内容 | any | 必填 | 本操作读取、转换或输出的文本 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | 对内容做 Base64 编码 |
这里使用`内容`。
调用效应:pure。
直接调用此函数:
```sh
marqdo call lib/编码.mq.md 基64编码 '内容="Marqdo"' --effects none --json
```
对内容做 Base64 编码。
调用例:[编码.基64编码] 内容=`s`
*> host_encoding_base64_encode text=`内容`*
完成后返回*[对内容做 Base64 编码](> host_encoding_base64_encode text=`内容`)*。
## 基64解码
+ `内容`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 内容 | any | 必填 | 本操作读取、转换或输出的文本 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | 对内容做 Base64 解码 |
这里使用`内容`。
调用效应:pure。
对内容做 Base64 解码。
*> host_encoding_base64_decode text=`内容`*
完成后返回*[对内容做 Base64 解码](> host_encoding_base64_decode text=`内容`)*。
## 十六进制编码
+ `内容`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 内容 | any | 必填 | 本操作读取、转换或输出的文本 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | 对内容做十六进制编码 |
这里使用`内容`。
调用效应:pure。
对内容做十六进制编码。
*> host_encoding_hex_encode text=`内容`*
完成后返回*[对内容做十六进制编码](> host_encoding_hex_encode text=`内容`)*。
## 十六进制解码
+ `内容`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 内容 | any | 必填 | 本操作读取、转换或输出的文本 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | 对内容做十六进制解码 |
这里使用`内容`。
调用效应:pure。
对内容做十六进制解码。
*> host_encoding_hex_decode text=`内容`*
完成后返回*[对内容做十六进制解码](> host_encoding_hex_decode text=`内容`)*。
## 基32编码
+ `内容`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 内容 | any | 必填 | 本操作读取、转换或输出的文本 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | 对内容做基32编码(RFC 4648;= 填充) |
这里使用`内容`。
调用效应:pure。
对内容做基32编码(RFC 4648;= 填充)。
*> host_encoding_base32_encode text=`内容`*
完成后返回*[对内容做基32编码(RFC 4648;= 填充)](> host_encoding_base32_encode text=`内容`)*。
## 基32解码
+ `内容`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 内容 | any | 必填 | 本操作读取、转换或输出的文本 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | 对内容做基32解码 |
这里使用`内容`。
调用效应:pure。
对内容做基32解码。
*> host_encoding_base32_decode text=`内容`*
完成后返回*[对内容做基32解码](> host_encoding_base32_decode text=`内容`)*。
+243 -33
View File
@@ -1,85 +1,295 @@
---
markup: occlusion
import:
table: lib/table.mq.md
text: lib/text.mq.md
title: lib/网络
description: 中文 HTTP(S) 包装。可选 headers / content_type 经宿主别名绑定。
---
中文 HTTP(S) 包装。可选 headers / content_type 经宿主别名绑定。
处理 HTTP、响应数据和有界下载。
能力与边界:读取只需 network.read;可恢复请求的方法可动态变化,因此保守要求 network.write。响应头是 name/values 行记录,可用响应头值取值。下载还需 fs.write;旧接口保留原契约。
本文件就是调用和开发手册:直接导入此文件,或用 marqdo call 按下面的函数标题调用。参数表说明类型和默认值;未填默认值的参数必须提供。返回表是渐进契约,后文说明失败与边界。
实现入口:[src/host/net.rs](../src/host/net.rs)、[src/host/net_ops.rs](../src/host/net_ops.rs)
开发时保持中英文语义一致,先组合公开库;仅在 OS 或算法边界添加宿主原语并声明效应。修改后运行 marqdo check --narrative-ratio 本文件,并执行 tests/stdlib_tasks.rs 的真实任务。
## 获取
+ `地址`
+ `headers`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 地址 | any | 必填 | 目标 URL;HTTP 接口接受 http 或 https |
| headers | any | None | HTTP 头名称与值记录;None 不附加额外头 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | 支持 HTTPS |
这里使用`地址`、`headers`=None。
调用效应:network.read。
支持 HTTPS。可选具名实参 `headers=`(映射)。
*> host_http_get url=`地址` headers=`headers`*
完成后返回*[支持 HTTPS](> host_http_get url=`地址` headers=`headers`)*。
## 提交
+ `地址`
+ `内容`
+ `content_type`=None
+ `headers`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 地址 | any | 必填 | 目标 URL;HTTP 接口接受 http 或 https |
| 内容 | any | 必填 | 请求正文;文档操作中为替换正文 |
| content_type | any | None | HTTP 内容类型覆盖;None 使用接口默认值 |
| headers | any | None | HTTP 头名称与值记录;None 不附加额外头 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | 默认 Content-Type 为 JSON |
这里使用`地址`、`内容`、`content_type`=None、`headers`=None。
调用效应:network.write。
默认 Content-Type 为 JSON。可选 `content_type=` / `headers=`。
*> host_http_post url=`地址` body=`内容` content_type=`content_type` headers=`headers`*
完成后返回*[默认 Content-Type 为 JSON](> host_http_post url=`地址` body=`内容` content_type=`content_type` headers=`headers`)*。
## 提交流式
+ `地址`
+ `内容`
+ `content_type`=None
+ `headers`=None
+ `打印增量`=False
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 地址 | any | 必填 | 目标 URL;HTTP 接口接受 http 或 https |
| 内容 | any | 必填 | 请求正文;文档操作中为替换正文 |
| content_type | any | None | HTTP 内容类型覆盖;None 使用接口默认值 |
| headers | any | None | HTTP 头名称与值记录;None 不附加额外头 |
| 打印增量 | any | False | 是否在接收 SSE 时打印增量文本 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | POST 并消费 OpenAI 兼容 SSE |
这里使用`地址`、`内容`、`content_type`=None、`headers`=None、`打印增量`=False。
调用效应:network.write。
POST 并消费 OpenAI 兼容 SSE。返回 `{status, events}`(`delta` / `done` / `error`)。`打印增量=真` 时边读边打印增量文本。
*> host_http_post_sse url=`地址` body=`内容` content_type=`content_type` headers=`headers` echo=`打印增量`*
完成后返回*[POST 并消费 OpenAI 兼容 SSE](> host_http_post_sse url=`地址` body=`内容` content_type=`content_type` headers=`headers` echo=`打印增量`)*。
## 解析流式
+ `内容`
+ `打印增量`=False
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 内容 | any | 必填 | 本操作读取、转换或输出的文本 |
| 打印增量 | any | False | 是否在接收 SSE 时打印增量文本 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | list | 离线解析 OpenAI 聊天 SSE 正文为事件列表(不联网) |
这里使用`内容`、`打印增量`=False。
调用效应:pure。
离线解析 OpenAI 聊天 SSE 正文为事件列表(不联网)。
*> host_openai_sse_parse text=`内容` echo=`打印增量`*
完成后返回*[离线解析 OpenAI 聊天 SSE 正文为事件列表(不联网)](> host_openai_sse_parse text=`内容` echo=`打印增量`)*。
## 请求
+ `方法`
+ `地址`
+ `body`=None
+ `content_type`=None
+ `headers`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 方法 | any | 必填 | HTTP 方法,例如 GET 或 POST |
| 地址 | any | 必填 | 目标 URL;HTTP 接口接受 http 或 https |
| 正文 | any | None | 请求正文;文档操作中为替换正文 |
| content_type | any | None | HTTP 内容类型覆盖;None 使用接口默认值 |
| 表头 | any | None | HTTP 头名称与值记录;None 不附加额外头 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | 可选 `body=` / `content_type=` / `headers=` |
这里使用`方法`、`地址`、`正文`=None、`content_type`=None、`表头`=None。
调用效应:network.write。
可选 `body=` / `content_type=` / `headers=`。
*> host_http_request method=`方法` url=`地址` body=`body` content_type=`content_type` headers=`headers`*
完成后返回*[可选 body= / content_type= / headers=](> host_http_request method=`方法` url=`地址` body=`正文` content_type=`content_type` headers=`表头`)*。
## 编码地址
+ `内容`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 内容 | any | 必填 | 本操作读取、转换或输出的文本 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | 对 URL 段做百分号编码 |
这里使用`内容`。
调用效应:pure。
对 URL 段做百分号编码。
*> host_url_encode text=`内容`*
完成后返回*[对 URL 段做百分号编码](> host_url_encode text=`内容`)*。
## 解析Cookie
+ `内容`
+ `是响应头`=False
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 内容 | any | 必填 | 本操作读取、转换或输出的文本 |
| 是响应头 | any | False | 是否按响应头而非请求头解析 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | list | 解析 `Cookie` 请求头(默认)或一个/多个 `Set-Cookie` 响应头(`是响应头=真`)为 `{name, value, path, domain, expires, max_age, secure, http_only, same_site}` 列表 |
这里使用`内容`、`是响应头`=False。
调用效应:pure。
直接调用此函数:
```sh
marqdo call lib/网络.mq.md 解析Cookie '内容="a=1; b=2"' --effects none --json
```
解析 `Cookie` 请求头(默认)或一个/多个 `Set-Cookie` 响应头(`是响应头=真`)为 `{name, value, path, domain, expires, max_age, secure, http_only, same_site}` 列表。
*> host_cookie_parse text=`内容` is_response=`是响应头`*
完成后返回*[解析 Cookie 请求头(默认)或一个/多个 Set-Cookie 响应头(是响应头=真)为 {name, value, path, domain, expires, max_age, secure, http_only, same_site} 列表](> host_cookie_parse text=`内容` is_response=`是响应头`)*。
## 解析多部分
+ `正文`
+ `边界`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 正文 | any | 必填 | 请求正文;文档操作中为替换正文 |
| 边界 | any | 必填 | Content-Type 头中的 multipart 分隔标记 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | list | 解析 `multipart/form-data` 请求体(给定 `boundary`)为 `{name, filename?, content_type?, value}` 部件列表 |
这里使用`正文`、`边界`。
调用效应:pure。
解析 `multipart/form-data` 请求体(给定 `boundary`)为 `{name, filename?, content_type?, value}` 部件列表。
*> host_multipart_parse body=`正文` boundary=`边界`*
完成后返回*[解析 multipart/form-data 请求体(给定 boundary)为 {name, filename?, content_type?, value} 部件列表](> host_multipart_parse body=`正文` boundary=`边界`)*。
## 解析Markdown
+ `文本`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 文本 | any | 必填 | 本操作读取、转换或输出的文本 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | 将 Markdown / GFM 解析为 HTML(纯转换,无网络 I/O) |
这里使用`文本`。
调用效应:pure。
将 Markdown / GFM 解析为 HTML(纯转换,无网络 I/O)。
*> host_markdown_parse text=`文本`*
完成后返回*[将 Markdown / GFM 解析为 HTML(纯转换,无网络 I/O)](> host_markdown_parse text=`文本`)*。
## 可恢复请求
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 方法 | text | 必填 | HTTP 方法,例如 GET 或 POST |
| 地址 | text | 必填 | 目标 URL;HTTP 接口接受 http 或 https |
| 正文 | any | None | 请求正文;文档操作中为替换正文 |
| 表头 | any | None | HTTP 头名称与值记录;None 不附加额外头 |
| 超时毫秒 | number | 30000 | 超时毫秒数;等待后检查操作结果 |
| 字节上限 | number | 8388608 | 读取或展开的字节上限;超限则失败 |
| 响应类型 | text | "text" | 响应正文表示:text 或 bytes |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | map | 返回统一结果记录;value 含 status、headers、body。响应头为 name/values 行记录。动态方法需要 network |
这里使用`方法`、`地址`、`正文`=None、`表头`=None、`超时毫秒`=30000、`字节上限`=8388608、`响应类型`="text"。
调用效应:network.write。
正文可为文本、字节记录或空值;发送 JSON 前使用 json.stringify。请求头使用字典,响应头使用 name/values 行记录。输出参数和目标路径在联网前预检。
返回统一结果记录;value 含 status、headers、body。响应头为 name/values 行记录。动态方法需要 network.write;只读请求使用读取。HTTP 错误状态仍是响应,传输失败是错误。
完成后返回*[正文可为文本、字节记录或空值;发送 JSON 前使用 json.stringify](> host_http_request_result method=`方法` url=`地址` body=`正文` headers=`表头` timeout_ms=`超时毫秒` max_bytes=`字节上限` response=`响应类型`)*。
## 下载
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 地址 | text | 必填 | 目标 URL;HTTP 接口接受 http 或 https |
| 路径 | text | 必填 | 授权文件根目录内的路径 |
| 表头 | any | None | HTTP 头名称与值记录;None 不附加额外头 |
| 超时毫秒 | number | 30000 | 超时毫秒数;等待后检查操作结果 |
| 字节上限 | number | 67108864 | 读取或展开的字节上限;超限则失败 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | map | 有界流式下载至文件;成功后原子替换,失败保留原文件。返回结果记录,value 含 status、headers、size、path;需要 network |
这里使用`地址`、`路径`、`表头`=None、`超时毫秒`=30000、`字节上限`=67108864。
调用效应:fs.write,network.read。
有界流式下载至文件;成功后原子替换,失败保留原文件。返回结果记录,value 含 status、headers、size、path;需要 network.read 与 fs.write。
完成后返回*[有界流式下载至文件;成功后原子替换,失败保留原文件](> host_http_download url=`地址` path=`路径` headers=`表头` timeout_ms=`超时毫秒` max_bytes=`字节上限`)*。
## 读取
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 地址 | text | 必填 | 目标 URL;HTTP 接口接受 http 或 https |
| 表头 | any | None | HTTP 头名称与值记录;None 不附加额外头 |
| 超时毫秒 | number | 30000 | 超时毫秒数;等待后检查操作结果 |
| 字节上限 | number | 8388608 | 读取或展开的字节上限;超限则失败 |
| 响应类型 | text | "text" | 响应正文表示:text 或 bytes |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | map | 只读 GET 请求,返回统一结果记录;只需 network |
这里使用`地址`、`表头`=None、`超时毫秒`=30000、`字节上限`=8388608、`响应类型`="text"。
调用效应:network.read。
只读 GET 请求,返回统一结果记录;只需 network.read。响应头为 name/values 行记录,响应类型可选 text/bytes。
完成后返回*[只读 GET 请求,返回统一结果记录;只需 network.read](> host_http_get_result url=`地址` headers=`表头` timeout_ms=`超时毫秒` max_bytes=`字节上限` response=`响应类型`)*。
## 响应头值
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 响应头 | list | 必填 | 响应中的 headers 行记录 |
| 名称 | text | 必填 | 头部名称 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | list | 同名头部的全部值 |
这里使用`响应头`、`名称`。
调用效应:pure。
从响应头行记录中按不区分大小写的名称取全部值;不存在返回空列表。请求的 headers 参数仍使用字典,响应 headers 使用行记录以保留任意名称和重复值。
得到**`lower` = [调用 to lower](text.to_lower(text=`名称`))**。
得到**`matches` = [调用 where](table.where(list=`响应头`, key="name", value=`lower`))**。
得到**`values` = [调用 pluck](table.pluck(list=`matches`, key="values"))**。
完成后返回*[调用 flatten](table.flatten(list=`values`))*。
+100 -21
View File
@@ -6,52 +6,131 @@ description: 将运行结果写回 .mq.md(Jupyter 式自写回)
将运行结果写回 .mq.md(Jupyter 式自写回)
读取并维护持久化执行输出槽位。
能力与边界:记录与读取默认锚定入口的当前调用点;命名槽互相隔离。结构化章节修改使用文档库,而不是把自写回当作任意文档编辑器。
本文件就是调用和开发手册:直接导入此文件,或用 marqdo call 按下面的函数标题调用。参数表说明类型和默认值;未填默认值的参数必须提供。返回表是渐进契约,后文说明失败与边界。
相对文件路径以 --fs-root 为准,省略时以被调用文件所在目录为准。写入需要显式 fs.write 授权,子进程需要 process.exec;纯计算无需 IO 权限。
实现入口:[src/host/writeback.rs](../src/host/writeback.rs)
开发时保持中英文语义一致,先组合公开库;仅在 OS 或算法边界添加宿主原语并声明效应。修改后运行 marqdo check --narrative-ratio 本文件,并执行 tests/stdlib_tasks.rs 的真实任务。
## 写回
+ `值`
+ `末尾`=False
+ `键`=None
+ `行`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 值 | any | 必填 | 待转换或保存的值;不会就地修改输入 |
| 末尾 | any | False | 是否追加到目标区块末尾 |
| 键 | any | None | 要读取、比较或更新的字段名或存储键 |
| 行 | any | None | 加入受管理写回区块的文本行 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 在入口文件中写入自写回块:若 `值` 像图片路径/URL(`.png` / `.svg` / … 或 `data:image/…`)则写成 `![marqdo-out](…)`,否则写成 `<!-- marqdo-out … -->` |
这里使用`值`、`末尾`=False、`键`=None、`行`=None。
调用效应:fs.write。
在入口文件中写入自写回块:若 `值` 像图片路径/URL(`.png` / `.svg` / … 或 `data:image/…`)则写成 `![marqdo-out](…)`,否则写成 `<!-- marqdo-out … -->`。默认在调用行下方插入或替换;`末尾=true` 时替换无键末尾块。带 `键=`(如 `ok` / `error` / `成功` / `失败`)时只更新该命名槽,互不覆盖。可选 `行=` 锚定到指定源码行(子任务写回时需要)。
*> host_writeback_record value=`值` at_end=`末尾` key=`键` line=`行`*
完成后返回*[在入口文件中写入自写回块:若 值 像图片路径/URL(.png / .svg / … 或 data:image/…)则写成 !marqdo-out(…),否则写成 <!-- marqdo-out … -->](> host_writeback_record value=`值` at_end=`末尾` key=`键` line=`行`)*。
## 取
+ `末尾`=False
+ `键`=None
+ `行`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 末尾 | any | False | 是否追加到目标区块末尾 |
| 键 | any | None | 要读取、比较或更新的字段名或存储键 |
| 行 | any | None | 加入受管理写回区块的文本行 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 读取当前调用处紧邻无键块、无键末尾块,或命名槽 |
这里使用`末尾`=False、`键`=None、`行`=None。
调用效应:fs.read。
读取当前调用处紧邻无键块、无键末尾块,或命名槽。
*> host_writeback_get at_end=`末尾` key=`键` line=`行`*
完成后返回*[读取当前调用处紧邻无键块、无键末尾块,或命名槽](> host_writeback_get at_end=`末尾` key=`键` line=`行`)*。
## 清除
+ `末尾`=False
+ `键`=None
+ `行`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 末尾 | any | False | 是否追加到目标区块末尾 |
| 键 | any | None | 要读取、比较或更新的字段名或存储键 |
| 行 | any | None | 加入受管理写回区块的文本行 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 删除紧邻块、末尾块或命名槽 |
这里使用`末尾`=False、`键`=None、`行`=None。
调用效应:fs.write。
删除紧邻块、末尾块或命名槽。
*> host_writeback_clear at_end=`末尾` key=`键` line=`行`*
完成后返回*[删除紧邻块、末尾块或命名槽](> host_writeback_clear at_end=`末尾` key=`键` line=`行`)*。
## 确保
+ `键`
+ `占位`=pending
+ `行`=None
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 键 | any | 必填 | 要读取、比较或更新的字段名或存储键 |
| 占位 | any | "pending" | 创建受管理区块时使用的占位文本 |
| 行 | any | None | 加入受管理写回区块的文本行 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | any | 若命名槽不存在则创建并写入占位;已存在则不改动 |
这里使用`键`、`占位`="pending"、`行`=None。
调用效应:fs.write。
若命名槽不存在则创建并写入占位;已存在则不改动。
*> host_writeback_ensure key=`键` placeholder=`占位` line=`行`*
完成后返回*[若命名槽不存在则创建并写入占位;已存在则不改动](> host_writeback_ensure key=`键` placeholder=`占位` line=`行`)*。
## 列出
列出。
| 返回 | 类型 | 说明 |
|---|---|---|
| result | list | 列出当前入口源码中的受管理输出槽位;不写入,也不读取其他文件 |
*> host_writeback_list*
调用效应:fs.read。
列出当前入口源码中的受管理输出槽位;不写入,也不读取其他文件。
完成后返回*[列出当前入口源码中的受管理输出槽位;不写入,也不读取其他文件](host_writeback_list())*。
## 扫描路径
+ `路径`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 路径 | any | 必填 | 授权文件根目录内的路径 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | list | 扫描任意文件中的自写回槽(注释块与 `![marqdo-out](…)` 图片;工作簿观察) |
这里使用`路径`。
调用效应:fs.read。
直接调用此函数:
```sh
marqdo call lib/自写回.mq.md 扫描路径 '路径="lib/writeback.mq.md"' --effects fs.read --fs-root . --json
```
扫描任意文件中的自写回槽(注释块与 `![marqdo-out](…)` 图片;工作簿观察)。
*> host_writeback_scan_path path=`路径`*
完成后返回*[扫描任意文件中的自写回槽(注释块与 !marqdo-out(…) 图片;工作簿观察)](> host_writeback_scan_path path=`路径`)*。
+988 -102
View File
File diff suppressed because it is too large. Load diff
+42 -4
View File
@@ -6,18 +6,56 @@ description: HTML 转义 / 还原(中层 Mid2 M8)。拼装字符串时的 XS
HTML 转义助手。把不可信文本拼进标记前先转义。
转义或还原 HTML 文本。
能力与边界:文本转义不等于清洗任意 HTML 文档。站点内容优先采用 Markdown 叶子和结构化视图节点。
本文件就是调用和开发手册:直接导入此文件,或用 marqdo call 按下面的函数标题调用。参数表说明类型和默认值;未填默认值的参数必须提供。返回表是渐进契约,后文说明失败与边界。
实现入口:[src/host/html_ops.rs](../src/host/html_ops.rs)
开发时保持中英文语义一致,先组合公开库;仅在 OS 或算法边界添加宿主原语并声明效应。修改后运行 marqdo check --narrative-ratio 本文件,并执行 tests/stdlib_tasks.rs 的真实任务。
## 转义
+ `内容`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 内容 | any | 必填 | 本操作读取、转换或输出的文本 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | 对内容做 HTML 转义 |
这里使用`内容`。
调用效应:pure。
直接调用此函数:
```sh
marqdo call lib/超文本.mq.md 转义 '内容="<strong>&"' --effects none --json
```
对内容做 HTML 转义。
调用例:[超文本.转义] 内容=`段`
*> host_html_escape text=`内容`*
完成后返回*[对内容做 HTML 转义](> host_html_escape text=`内容`)*。
## 还原
+ `内容`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 内容 | any | 必填 | 本操作读取、转换或输出的文本 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | 还原内容里的 HTML 实体 |
这里使用`内容`。
调用效应:pure。
还原内容里的 HTML 实体。
*> host_html_unescape text=`内容`*
完成后返回*[还原内容里的 HTML 实体](> host_html_unescape text=`内容`)*。
+146 -15
View File
@@ -6,54 +6,185 @@ description: 路径代数(中层 M2)。无 I/O;分隔符随宿主 OS。
只做路径代数。无 I/O;分隔符随宿主 OS。
不访问磁盘的路径运算。
能力与边界:归一化是词法运算,不代表已获得文件访问权限。真正的 IO 路径由宿主按文件根目录检查。
本文件就是调用和开发手册:直接导入此文件,或用 marqdo call 按下面的函数标题调用。参数表说明类型和默认值;未填默认值的参数必须提供。返回表是渐进契约,后文说明失败与边界。
实现入口:[src/host/path.rs](../src/host/path.rs)、[src/host/fs_ops.rs](../src/host/fs_ops.rs)
开发时保持中英文语义一致,先组合公开库;仅在 OS 或算法边界添加宿主原语并声明效应。修改后运行 marqdo check --narrative-ratio 本文件,并执行 tests/stdlib_tasks.rs 的真实任务。
## 拼接
+ `甲`
+ `乙`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 甲 | any | 必填 | 基础路径 |
| 乙 | any | 必填 | 追加到基础路径的路径片段 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | 拼接路径段甲与乙 |
这里使用`甲`、`乙`。
调用效应:pure。
拼接路径段甲与乙。
调用例:[路径.拼接] 甲="a" 乙="b"
*> host_path_join a=`甲` b=`乙`*
完成后返回*[拼接路径段甲与乙](> host_path_join a=`甲` b=`乙`)*。
## 拆分
+ `路径`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 路径 | any | 必填 | 授权文件根目录内的路径 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | list | 把路径拆成各段 |
这里使用`路径`。
调用效应:pure。
把路径拆成各段。
*> host_path_split path=`路径`*
完成后返回*[把路径拆成各段](> host_path_split path=`路径`)*。
## 文件名
+ `路径`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 路径 | any | 必填 | 授权文件根目录内的路径 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | 路径的末段文件名 |
这里使用`路径`。
调用效应:pure。
路径的末段文件名。
*> host_path_file_name path=`路径`*
完成后返回*[路径的末段文件名](> host_path_file_name path=`路径`)*。
## 父目录
+ `路径`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 路径 | any | 必填 | 授权文件根目录内的路径 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | 路径的父目录 |
这里使用`路径`。
调用效应:pure。
路径的父目录。
*> host_path_parent path=`路径`*
完成后返回*[路径的父目录](> host_path_parent path=`路径`)*。
## 扩展名
+ `路径`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 路径 | any | 必填 | 授权文件根目录内的路径 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | 路径的扩展名 |
这里使用`路径`。
调用效应:pure。
路径的扩展名。
*> host_path_extension path=`路径`*
完成后返回*[路径的扩展名](> host_path_extension path=`路径`)*。
## 规范化
+ `路径`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 路径 | any | 必填 | 授权文件根目录内的路径 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | 规范化路径(处理点段) |
这里使用`路径`。
调用效应:pure。
规范化路径(处理点段)。
*> host_path_normalize path=`路径`*
完成后返回*[规范化路径(处理点段)](> host_path_normalize path=`路径`)*。
## 是绝对
+ `路径`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 路径 | any | 必填 | 授权文件根目录内的路径 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | bool | 路径是否为绝对路径 |
这里使用`路径`。
调用效应:pure。
路径是否为绝对路径。
*> host_path_is_absolute path=`路径`*
完成后返回*[路径是否为绝对路径](> host_path_is_absolute path=`路径`)*。
## 相对路径
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 路径 | text | 必填 | 授权文件根目录内的路径 |
| 基准 | text | 必填 | 计算相对路径所用的基础目录 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | text | 计算相对 base 的词法路径;两个参数须同为绝对或相对路径,不访问磁盘。 |
这里使用`路径`、`基准`。
调用效应:pure。
计算相对 base 的词法路径;两个参数须同为绝对或相对路径,不访问磁盘。
完成后返回*[计算相对 base 的词法路径;两个参数须同为绝对或相对路径,不访问磁盘](> host_path_relative path=`路径` base=`基准`)*。
## 换扩展名
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 路径 | text | 必填 | 授权文件根目录内的路径 |
| 扩展名 | text | 必填 | 新扩展名,可带或不带开头的点 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | text | 替换最后的扩展名;空扩展名表示去除。 |
这里使用`路径`、`扩展名`。
调用效应:pure。
直接调用此函数:
```sh
marqdo call lib/路径.mq.md 换扩展名 '路径="notes/draft.txt"' '扩展名="md"' --effects none --json
```
替换最后的扩展名;空扩展名表示去除。
完成后返回*[替换最后的扩展名;空扩展名表示去除](> host_path_with_extension path=`路径` extension=`扩展名`)*。
+60 -4
View File
@@ -6,18 +6,74 @@ description: CSV 解析/序列化(中层 M4)。首行为表头 → 映射列
CSV 解析与序列化。首行为表头;各行变成映射列表。
解析并序列化带表头的 CSV 行记录。
能力与边界:解析后单元格是文本,使用表库明确转换类型;序列化依第一行字段顺序。输入应为行记录,不是列式字典。
本文件就是调用和开发手册:直接导入此文件,或用 marqdo call 按下面的函数标题调用。参数表说明类型和默认值;未填默认值的参数必须提供。返回表是渐进契约,后文说明失败与边界。
实现入口:
开发时保持中英文语义一致,先组合公开库;仅在 OS 或算法边界添加宿主原语并声明效应。修改后运行 marqdo check --narrative-ratio 本文件,并执行 tests/stdlib_tasks.rs 的真实任务。
## 解析
+ `内容`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 内容 | any | 必填 | 本操作读取、转换或输出的文本 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | list | 把 CSV 文本解析成映射列表 |
这里使用`内容`。
调用效应:pure。
把 CSV 文本解析成映射列表。
调用例:[逗号表.解析] 内容=`原文`
*> host_csv_parse text=`内容`*
完成后返回*[把 CSV 文本解析成映射列表](> host_csv_parse text=`内容`)*。
## 序列化
+ `行集`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 行集 | any | 必填 | 行记录列表,不是隐式列式表 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | text | 把映射列表序列化成 CSV 文本 |
这里使用`行集`。
调用效应:pure。
把映射列表序列化成 CSV 文本。
*> host_csv_stringify rows=`行集`*
完成后返回*[把映射列表序列化成 CSV 文本](> host_csv_stringify rows=`行集`)*。
## 尝试解析
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 内容 | text | 必填 | 本操作读取、转换或输出的文本 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | map | 返回 {ok,value,error};解析失败是可恢复的数据。 |
这里使用`内容`。
调用效应:pure。
直接调用此函数:
```sh
marqdo call lib/逗号表.mq.md 尝试解析 '内容="name,n"' --effects none --json
```
返回 {ok,value,error};解析失败是可恢复的数据。
完成后返回*[返回 {ok,value,error};解析失败是可恢复的数据](> host_try_csv_parse text=`内容`)*。
+67 -4
View File
@@ -1,16 +1,79 @@
---
markup: occlusion
title: lib/配置表
description: 只读 TOML 子集解析(中层 Mid2 M8)。表 / 标量 / 数组;无数组表。
description: 标准 TOML 配置读写,支持数组表、多行文本和内联表;日期转为 ISO 文本。
---
只读 TOML 子集。适合配置;不做完整 TOML 写出。
标准 TOML 配置读写;日期转为 ISO 文本,序列化不保留原注释。
读写标准 TOML 配置。
能力与边界:支持内联表、多行文本和数组表。TOML 日期转换成 ISO 文本;序列化不支持空值,也不保留原注释。
本文件就是调用和开发手册:直接导入此文件,或用 marqdo call 按下面的函数标题调用。参数表说明类型和默认值;未填默认值的参数必须提供。返回表是渐进契约,后文说明失败与边界。
实现入口:[src/host/toml_ops.rs](../src/host/toml_ops.rs)
开发时保持中英文语义一致,先组合公开库;仅在 OS 或算法边界添加宿主原语并声明效应。修改后运行 marqdo check --narrative-ratio 本文件,并执行 tests/stdlib_tasks.rs 的真实任务。
## 解析
+ `内容`
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 内容 | any | 必填 | 本操作读取、转换或输出的文本 |
| 返回 | 类型 | 说明 |
|---|---|---|
| result | map | 把 TOML 文本解析成映射/列表/标量 |
这里使用`内容`。
调用效应:pure。
把 TOML 文本解析成映射/列表/标量。
调用例:[配置表.解析] 内容=`配置`
*> host_toml_parse text=`内容`*
完成后返回*[把 TOML 文本解析成映射/列表/标量](> host_toml_parse text=`内容`)*。
## 序列化
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 值 | map | 必填 | 待转换或保存的值;不会就地修改输入 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | text | 序列化字典为 TOML,拒绝空值及不支持的数据类型;不保留原注释。 |
这里使用`值`。
调用效应:pure。
序列化字典为 TOML,拒绝空值及不支持的数据类型;不保留原注释。
完成后返回*[序列化字典为 TOML,拒绝空值及不支持的数据类型;不保留原注释](> host_toml_stringify value=`值`)*。
## 尝试解析
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 内容 | text | 必填 | 本操作读取、转换或输出的文本 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | map | 以结果记录返回 TOML 解析;支持内联表、多行文本、数组表,日期转换为 ISO 文本。 |
这里使用`内容`。
调用效应:pure。
直接调用此函数:
```sh
marqdo call lib/配置表.mq.md 尝试解析 '内容="name="Marqdo""' --effects none --json
```
以结果记录返回 TOML 解析;支持内联表、多行文本、数组表,日期转换为 ISO 文本。
完成后返回*[以结果记录返回 TOML 解析;支持内联表、多行文本、数组表,日期转换为 ISO 文本](> host_toml_try_parse text=`内容`)*。