Add v0.2 surface syntax, writeback/subtask stdlib, and view input deferral.

Use + for parameters, ordered-list branches, backtick identifiers, and quoted strings with escapes. Add writeback and subtask host libs, optional parameter defaults, narrative-bold comment fix, and defer view execution until preset stdin is submitted.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
cflmyandCursor committed 2026-08-06 17:52:33 +08:00
1 parent 92d88fe761
commit 63e5be80ab
116 files changed
+2226 -559

No files matched your search

+78
View File
@@ -0,0 +1,78 @@
#!/usr/bin/env python3
"""Migrate branch arms: + cond -> N. cond (params + `name` unchanged)."""
from __future__ import annotations
import re
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
SKIP_DIRS = {"target", ".git", "node_modules"}
PARAM_LINE = re.compile(r"^(\s{4,})\+ `([^`]+)`(=.*)?\s*$")
ORDERED = re.compile(r"^(\s*)(\d+)\.\s+(.*)$")
PLUS_BRANCH = re.compile(r"^(\s*)\+ (.+)$")
def migrate_text(text: str) -> str:
lines = text.splitlines(keepends=True)
out: list[str] = []
arm = 0
for line in lines:
raw = line.rstrip("\n\r")
end = line[len(raw) :]
if not raw.strip():
arm = 0
out.append(line)
continue
if PARAM_LINE.match(raw):
arm = 0
out.append(line)
continue
m = PLUS_BRANCH.match(raw)
if m:
arm += 1
indent, rest = m.groups()
out.append(f"{indent}{arm}. {rest}{end}")
continue
om = ORDERED.match(raw)
if om:
arm = int(om.group(2))
out.append(line)
continue
stripped = raw.lstrip()
indent = raw[: len(raw) - len(stripped)]
if indent == 0 and (
stripped.startswith("#")
or stripped.startswith(">")
or (stripped.startswith("*") and stripped.endswith("*"))
or stripped.startswith("`")
or stripped.startswith("|")
or stripped.startswith("---")
):
arm = 0
out.append(line)
return "".join(out)
def should_skip(path: Path) -> bool:
return any(part in SKIP_DIRS for part in path.parts)
def main() -> int:
changed = 0
for path in sorted(ROOT.rglob("*.mq.md")):
if should_skip(path):
continue
text = path.read_text(encoding="utf-8")
new_text = migrate_text(text)
if new_text != text:
path.write_text(new_text, encoding="utf-8")
print(path.relative_to(ROOT))
changed += 1
print(f"migrated {changed} files")
return 0
if __name__ == "__main__":
sys.exit(main())
+61
View File
@@ -0,0 +1,61 @@
#!/usr/bin/env python3
"""One-shot migrate v0.2: params + `name`, foreach [`i`](`xs`)."""
from __future__ import annotations
import re
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
SKIP_DIRS = {"man-test", "target", ".git", "node_modules"}
PARAM_RE = re.compile(
r"^(\s+)- ([A-Za-z_\u4e00-\u9fff][A-Za-z0-9_\u4e00-\u9fff]*)(=(.*))?\s*$"
)
FOREACH_RE = re.compile(r"^(\s*)- \[([^\]]+)\]\(([^)]+)\)\s*$")
def wrap_id(name: str) -> str:
name = name.strip()
if name.startswith("`") and name.endswith("`"):
return name
return f"`{name}`"
def migrate_line(line: str) -> str:
m = FOREACH_RE.match(line)
if m:
indent, item, coll = m.groups()
return f"{indent}- [{wrap_id(item)}]({wrap_id(coll)})\n"
m = PARAM_RE.match(line)
if m:
indent, name, _, default = m.groups()
if default is not None:
return f"{indent}+ {wrap_id(name)}={default.rstrip()}\n"
return f"{indent}+ {wrap_id(name)}\n"
return line
def should_skip(path: Path) -> bool:
return any(part in SKIP_DIRS for part in path.parts)
def main() -> int:
changed = 0
for path in sorted(ROOT.rglob("*.mq.md")):
if should_skip(path):
continue
text = path.read_text(encoding="utf-8")
lines = text.splitlines(keepends=True)
out = [migrate_line(ln) for ln in lines]
new_text = "".join(out)
if new_text != text:
path.write_text(new_text, encoding="utf-8")
print(path.relative_to(ROOT))
changed += 1
print(f"migrated {changed} files")
return 0
if __name__ == "__main__":
sys.exit(main())