426e9eeabd
Voice Workbench / headless workbench (mocked backends) (push) Has been cancelled
Voice Workbench / real acoustic lane (nightly, provisioned only) (push) Has been cancelled
ci / test (push) Has been cancelled
ci / lint-and-format (push) Has been cancelled
ci / build (push) Has been cancelled
ci / dev-startup (push) Has been cancelled
gitleaks / gitleaks (push) Has been cancelled
Markdown Links / Relative Markdown Links (push) Has been cancelled
Quality (Extended) / Homepage Build (PR smoke) (push) Has been cancelled
Quality (Extended) / Comment-only diff guard (push) Has been cancelled
Quality (Extended) / Format + Type Safety Ratchet (push) Has been cancelled
Quality (Extended) / Develop Gate (secret scan + UI determinism) (push) Has been cancelled
Quality (Extended) / Develop Gate (lint) (push) Has been cancelled
Chat shell gestures / Chat shell gesture + parity e2e (push) Has been cancelled
Cloud Gateway Discord / Test (push) Has been cancelled
Benchmark Bridge Tests / benchmark (bunx @biomejs/biome check packages/lifeops-bench/src, benchmark-lint) (push) Has been cancelled
Benchmark Bridge Tests / benchmark (bunx vitest run --config packages/lifeops-bench/vitest.config.ts --root packages/lifeops-bench --passWithNoTests, benchmark-tests) (push) Has been cancelled
Build Agent Image / build-and-push (push) Has been cancelled
Dev Smoke / bun run dev onboarding chat (push) Has been cancelled
Dev Smoke / Vite HMR dependency-level smoke (push) Has been cancelled
Electrobun Submodule Guard / electrobun gitlink is fetchable (push) Has been cancelled
Publish @elizaos/example-code / check_npm (push) Has been cancelled
Publish @elizaos/example-code / publish_npm (push) Has been cancelled
Publish @elizaos/plugin-elizacloud / verify_version (push) Has been cancelled
Publish @elizaos/plugin-elizacloud / publish_npm (push) Has been cancelled
Sandbox Live Smoke / Sandbox live smoke (push) Has been cancelled
Snap Build & Test / Build Snap (amd64) (push) Has been cancelled
Snap Build & Test / Build Snap (arm64) (push) Has been cancelled
Test Packaging / elizaos CLI global-install smoke (node + bun) (push) Has been cancelled
Cloud Gateway Webhook / Test (push) Has been cancelled
Cloud Tests / lint-and-types (push) Has been cancelled
Cloud Tests / unit-tests (push) Has been cancelled
Cloud Tests / integration-tests (push) Has been cancelled
Cloud Tests / e2e-tests (push) Has been cancelled
CodeQL Advanced / Analyze (javascript-typescript) (push) Has been cancelled
Deploy Apps Worker (Product 2) / Determine environment (push) Has been cancelled
Deploy Apps Worker (Product 2) / Deploy apps worker to apps-control host (${{ needs.determine-env.outputs.environment }}) (push) Has been cancelled
Deploy Eliza Provisioning Worker / Determine environment (push) Has been cancelled
Deploy Eliza Provisioning Worker / Deploy worker to Hetzner host (${{ needs.determine-env.outputs.environment }} @ ${{ needs.determine-env.outputs.deployment_sha }}) (push) Has been cancelled
Dev Smoke / Classify changed paths (push) Has been cancelled
supply-chain / sbom (push) Has been cancelled
supply-chain / vulnerability-scan (push) Has been cancelled
Build, Push & Deploy to Phala Cloud / build-and-push (push) Has been cancelled
Test Packaging / Validate Packaging Configs (push) Has been cancelled
Test Packaging / Build & Test PyPI Package (push) Has been cancelled
Test Packaging / PyPI on Python ${{ matrix.python }} (push) Has been cancelled
Test Packaging / Pack & Test JS Tarballs (push) Has been cancelled
UI Fixture E2E / ui-fixture-e2e (push) Has been cancelled
UI Fixture E2E / fixture-e2e (push) Has been cancelled
UI Story Gate / story-gate (push) Has been cancelled
vault-ci / test (macos-latest) (push) Has been cancelled
vault-ci / test (ubuntu-latest) (push) Has been cancelled
vault-ci / test (windows-latest) (push) Has been cancelled
vault-ci / app-core wiring tests (push) Has been cancelled
verify-patches / verify patches/CHECKSUMS.sha256 (push) Has been cancelled
Voice Benchmark Smoke / voice-emotion fixture smoke (push) Has been cancelled
Voice Benchmark Smoke / voiceagentbench fixture smoke (push) Has been cancelled
Voice Benchmark Smoke / voicebench-quality unit smoke (push) Has been cancelled
Voice Benchmark Smoke / voicebench TypeScript unit (no audio) (push) Has been cancelled
Voice Benchmark Smoke / voice bench smoke summary (push) Has been cancelled
Windows CI / windows ([bun run --cwd packages/app-core test bun run --cwd packages/elizaos test bun run --cwd packages/cloud/shared test], app-and-cli) (push) Has been cancelled
Windows CI / windows ([bun run --cwd packages/scenario-runner test bun run --cwd packages/vault test bun run --cwd packages/security test bun run --cwd plugins/plugin-coding-tools test], framework-packages) (push) Has been cancelled
Windows CI / windows ([bun run --cwd plugins/plugin-elizacloud test bun run --cwd plugins/plugin-discord test bun run --cwd plugins/plugin-anthropic test bun run --cwd plugins/plugin-openai test bun run --cwd plugins/plugin-app-control test bun run --cwd plugins/pl… (push) Has been cancelled
Windows CI / windows ([node packages/scripts/run-turbo.mjs run build --filter=@elizaos/core --filter=@elizaos/shared --filter=@elizaos/agent --concurrency=4 node packages/scripts/run-bash-linux-only.mjs scripts/verify-riscv64-buildpaths.sh node packages/scripts/run… (push) Has been cancelled
Windows CI / windows ([node packages/scripts/run-turbo.mjs run typecheck --filter=@elizaos/core --filter=@elizaos/shared --filter=@elizaos/cloud-shared --concurrency=4 bun run --cwd packages/core test bun run --cwd packages/shared test], core-runtime, 75) (push) Has been cancelled
135 lines
5.1 KiB
Python
135 lines
5.1 KiB
Python
#!/usr/bin/env python3
|
|
"""Caveman-compress the `thought:` field in native JSON expectedResponse.
|
|
|
|
For task_types that contain a `thought:` block (reply, agent_trace, tool_call,
|
|
mcp_tool_call), extract the thought string, compress it via
|
|
`scripts.lib.caveman.compress`, and write back.
|
|
|
|
Keeps the original alongside in
|
|
`data/intermediate/caveman_thoughts.jsonl` keyed by line index, so we have a
|
|
mapping from {idx: {original, caveman}} for review/rollback.
|
|
|
|
Reads `data/final/train_deslopped.jsonl` (or whatever upstream is current)
|
|
Writes `data/final/train_caveman.jsonl`.
|
|
|
|
The compress function falls back to the original text when compression
|
|
collapses below 3 tokens, so we never produce a degenerate thought.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import re
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
|
|
from lib.caveman import compress, compression_ratio # noqa: E402
|
|
|
|
ROOT = Path(__file__).resolve().parent.parent
|
|
SRC = ROOT / "data" / "final" / "train_deslopped.jsonl"
|
|
DST = ROOT / "data" / "final" / "train_caveman.jsonl"
|
|
INTERMEDIATE = ROOT / "data" / "intermediate" / "caveman_thoughts.jsonl"
|
|
MANIFEST = ROOT / "data" / "final" / "manifest_caveman.json"
|
|
|
|
THOUGHT_TASK_TYPES = {"reply", "agent_trace", "tool_call", "mcp_tool_call"}
|
|
|
|
# Match `thought: "<value>"` line in native JSON. Same shape as transform_deslop.
|
|
NATIVE_JSON_THOUGHT_RE = re.compile(
|
|
r'(^|\n)(thought:\s*)("(?:[^"\\]|\\.)*")(\s*(?=\n|$))',
|
|
re.DOTALL,
|
|
)
|
|
NATIVE_JSON_QUOTED_THOUGHT_RE = re.compile(
|
|
r'(^|\n)("thought":\s*)("(?:[^"\\]|\\.)*")(\s*(?=,|\n|$))',
|
|
re.DOTALL,
|
|
)
|
|
|
|
|
|
def replace_thought(payload: str, *, intermediate_writer, idx: int, stats: dict) -> str:
|
|
"""Replace `thought: "<x>"` with caveman version. Records original."""
|
|
captured: list[tuple[str, str]] = []
|
|
|
|
def _replace(match: re.Match) -> str:
|
|
prefix, key, quoted, suffix = match.groups()
|
|
try:
|
|
inner = json.loads(quoted)
|
|
except json.JSONDecodeError:
|
|
return match.group(0)
|
|
if not isinstance(inner, str) or not inner.strip():
|
|
return match.group(0)
|
|
compressed = compress(inner)
|
|
captured.append((inner, compressed))
|
|
if compressed == inner:
|
|
stats["unchanged"] = stats.get("unchanged", 0) + 1
|
|
return match.group(0)
|
|
stats["compressed"] = stats.get("compressed", 0) + 1
|
|
ratio = compression_ratio(inner, compressed)
|
|
stats["ratio_sum"] = stats.get("ratio_sum", 0.0) + ratio
|
|
return f"{prefix}{key}{json.dumps(compressed, ensure_ascii=False)}{suffix}"
|
|
|
|
new_payload = NATIVE_JSON_THOUGHT_RE.sub(_replace, payload)
|
|
new_payload = NATIVE_JSON_QUOTED_THOUGHT_RE.sub(_replace, new_payload)
|
|
|
|
for original, compressed in captured:
|
|
intermediate_writer.write(json.dumps({
|
|
"idx": idx,
|
|
"original": original,
|
|
"caveman": compressed,
|
|
}, ensure_ascii=False) + "\n")
|
|
|
|
return new_payload
|
|
|
|
|
|
def caveman_record(rec: dict, *, intermediate_writer, idx: int, stats: dict) -> dict:
|
|
tt = rec.get("metadata", {}).get("task_type") or rec.get("task_type", "")
|
|
if tt not in THOUGHT_TASK_TYPES:
|
|
return rec
|
|
er = rec.get("expectedResponse")
|
|
if not isinstance(er, str) or not er:
|
|
return rec
|
|
new_er = replace_thought(er, intermediate_writer=intermediate_writer, idx=idx, stats=stats)
|
|
if new_er != er:
|
|
rec["expectedResponse"] = new_er
|
|
stats["records_changed"] = stats.get("records_changed", 0) + 1
|
|
return rec
|
|
|
|
|
|
def main() -> int:
|
|
if not SRC.exists():
|
|
print(f"error: {SRC} missing", file=sys.stderr)
|
|
return 2
|
|
INTERMEDIATE.parent.mkdir(parents=True, exist_ok=True)
|
|
stats = {"total": 0, "decode_errors": 0, "compressed": 0, "unchanged": 0,
|
|
"records_changed": 0, "ratio_sum": 0.0}
|
|
print(f"[caveman] {SRC} -> {DST}", file=sys.stderr)
|
|
print(f"[caveman] intermediate -> {INTERMEDIATE}", file=sys.stderr)
|
|
with SRC.open() as fin, DST.open("w") as fout, INTERMEDIATE.open("w") as fmid:
|
|
for idx, line in enumerate(fin):
|
|
stats["total"] += 1
|
|
try:
|
|
rec = json.loads(line)
|
|
except json.JSONDecodeError:
|
|
stats["decode_errors"] += 1
|
|
fout.write(line)
|
|
continue
|
|
rec = caveman_record(rec, intermediate_writer=fmid, idx=idx, stats=stats)
|
|
fout.write(json.dumps(rec, ensure_ascii=False) + "\n")
|
|
if stats["total"] % 100000 == 0:
|
|
avg = stats["ratio_sum"] / max(1, stats["compressed"])
|
|
print(
|
|
f"[caveman] {stats['total']:>7d} "
|
|
f"compressed={stats['compressed']:>6d} "
|
|
f"unchanged={stats['unchanged']:>6d} "
|
|
f"avg_ratio={avg:.2f}",
|
|
file=sys.stderr,
|
|
)
|
|
if stats["compressed"]:
|
|
stats["avg_ratio"] = stats["ratio_sum"] / stats["compressed"]
|
|
MANIFEST.write_text(json.dumps(stats, indent=2))
|
|
print(json.dumps(stats, indent=2), file=sys.stderr)
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|