feat(ext/ai): land Agent/LLM optimize waves O1–O5

Wire opt-in sandbox trial into agent, require sandbox proof before OKF
promote, add step_route/EFI/cost surfaces, style lint + quarantine, and
offline policy optimize script—keeping GFM tables over json glue.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
cflmyandCursor committed 2026-10-16 11:47:28 +08:00
1 parent a707758d47
commit 0f72173d08
26 files changed
+1107 -272

No files matched your search

+26
View File
@@ -39,6 +39,32 @@ run tests/ext/agent-zero-llm.mq.md
run tests/ext/agent-plan-preserve.mq.md
run examples/agent-okf-flywheel/index.mq.md
run examples/agent-pong/index.mq.md
run examples/agent-sandbox-okf/index.mq.md
run tests/ext/agent-sandbox-optin.mq.md
run tests/ext/agent-sandbox-promote.mq.md
# Skill Lift subset (O2 B3/E1): with-skill vs without — constitution / writeback / call_site markers.
skill_lift_pass=0
skill_lift_fail=0
assert_out_has() {
local f="$1"
local needle="$2"
local label="$3"
local out
out="$("$MQ" run "$f" 2>/dev/null || true)"
if printf '%s' "$out" | grep -q -- "$needle"; then
echo "SkillLift OK $label ($needle)"
skill_lift_pass=$((skill_lift_pass + 1))
else
echo "SkillLift MISS $label (need $needle)" >&2
skill_lift_fail=$((skill_lift_fail + 1))
fail=1
fi
}
assert_out_has tests/ext/agent-constitution-b0.mq.md "constitution-ok" "constitution"
assert_out_has tests/ext/agent-writeback-shadow.mq.md "writeback-shadow-ok" "writeback"
assert_out_has tests/ext/agent-dump-context.mq.md "dump-context-ok" "call_site"
echo "SkillLift summary: pass=$skill_lift_pass fail=$skill_lift_fail"
if [[ "${AGENT_HARNESS_LIVE:-}" == "1" ]]; then
export AGENT_LIVE=1
+45
View File
@@ -0,0 +1,45 @@
#!/usr/bin/env bash
# O4 — style gate: flag json.set dict chains and mixed EN/ZH API hints in .mq.md.
# Exit 0 when clean; 1 when findings (unless MQ_STYLE_LINT_SOFT=1).
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
cd "$ROOT"
TARGETS=("$@")
if [[ ${#TARGETS[@]} -eq 0 ]]; then
TARGETS=(ext/ai/sandbox.mq.md ext/ai/policies examples/agent-sandbox-okf)
fi
fail=0
findings=0
scan_file() {
local f="$1"
[[ -f "$f" ]] || return 0
# Long json.set pipelines (3+ consecutive) — style bug per marqdo-dev.
if awk '
/json\.set/ { c++; if (c >= 3) { found=1 } next }
{ c=0 }
END { exit found ? 0 : 1 }
' "$f"; then
echo "STYLE json.set-chain: $f" >&2
findings=$((findings + 1))
fail=1
fi
# Same file imports both EN agent and ZH 智能体 (or web/网页) — mixed surface.
if grep -qE 'import[[:space:]]+agent:|import[[:space:]]+web:' "$f" \
&& grep -qE '导入[[:space:]]+(智能体|网页):' "$f"; then
echo "STYLE mixed-EN/ZH-import: $f" >&2
findings=$((findings + 1))
fail=1
fi
}
while IFS= read -r -d '' f; do
scan_file "$f"
done < <(find "${TARGETS[@]}" -type f -name '*.mq.md' -print0 2>/dev/null)
echo "mq-style-lint: findings=$findings"
if [[ "${MQ_STYLE_LINT_SOFT:-}" == "1" ]]; then
exit 0
fi
exit "$fail"
+58
View File
@@ -0,0 +1,58 @@
#!/usr/bin/env bash
# O5 — offline standing / policy rewrite hint (GEPA-like, products stay repo files).
# Does NOT change the runtime agent path. Reads harness failure log + current files,
# writes a suggested patch under .marqdo/optimize/ for human review.
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
cd "$ROOT"
LOG="${1:-}"
STANDING="${2:-ext/ai/agent.mq.md}"
POLICY="${3:-ext/ai/policies/step-route.mq.md}"
OUT_DIR="${OUT_DIR:-.marqdo/optimize}"
mkdir -p "$OUT_DIR"
STAMP="$(date -u +%Y%m%dT%H%M%SZ)"
REPORT="$OUT_DIR/standing-policy-$STAMP.md"
{
echo "# Offline standing / policy optimize suggestion"
echo
echo "Generated: $STAMP"
echo
echo "This is a **review artifact**, not an automatic runtime rewrite."
echo "Strong models may rewrite \`standing\` / \`policies/*.mq.md\` offline;"
echo "commit only after harness green."
echo
echo "## Inputs"
echo
echo "- standing source: \`$STANDING\`"
echo "- policy source: \`$POLICY\`"
if [[ -n "$LOG" && -f "$LOG" ]]; then
echo "- harness log: \`$LOG\`"
echo
echo "## Harness failure excerpt"
echo
echo '```'
tail -n 80 "$LOG" || true
echo '```'
else
echo "- harness log: _(none — pass path as \$1)_"
fi
echo
echo "## Current policy table (copy)"
echo
if [[ -f "$POLICY" ]]; then
echo '```markdown'
cat "$POLICY"
echo '```'
else
echo "_missing $POLICY_"
fi
echo
echo "## Suggested next edits"
echo
echo "1. Keep step-class → backend as a **GFM table** (no json glue)."
echo "2. Quarantine failing skills (\`status: quarantine\`) before promoting again."
echo "3. Re-run \`scripts/agent-harness.sh\` and confirm Skill Lift summary."
} > "$REPORT"
echo "wrote $REPORT"