Skip to content
Merged
60 changes: 38 additions & 22 deletions hf_space/README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,54 @@
---
title: CompText Prompt Compression Lab
emoji: 🗜️
colorFrom: blue
colorTo: purple
title: CompText Universe
emoji: 🧭
colorFrom: indigo
colorTo: blue
sdk: gradio
python_version: 3.10.13
sdk_version: 5.44.1
app_file: app.py
fullWidth: true
header: mini
pinned: false
license: apache-2.0
short_description: Explore CompText architecture, contracts and safe context compression.
models:
- microsoft/llmlingua-2-bert-base-multilingual-cased-meetingbank
tags:
- context-engineering
- prompt-compression
- software-engineering
- gradio
preload_from_hub:
- microsoft/llmlingua-2-bert-base-multilingual-cased-meetingbank
---

# CompText Prompt Compression Lab
# CompText Universe

A CPU-friendly Hugging Face Space for evaluating prompt and context compression with Microsoft LLMLingua-2.
> Models are providers. Context is the product. Evidence is the trust layer. CompText is the kernel.

## Features
A public, experimental showcase for the CompText local engineering-orchestration architecture. The real CompText runtime remains local; this Space visualizes architecture and contracts, builds non-executable AIR and simulated Evidence previews, and tests fail-closed context compression.

- Compress arbitrary prompts at configurable retention rates
- Compare original and compressed text
- Measure token reduction and runtime
- Check preservation of negations, CLI flags, file paths, JSON keys, version numbers, and code-like symbols
- Run a built-in benchmark suite
- Export results as JSON
## Included surfaces

## Default model
- Static seven-layer architecture explorer
- Explicit capability maturity matrix
- Workspace skill and safety-boundary explorer
- Fail-closed hybrid LLMLingua-2 compression
- Deterministic, non-executable AIR previews
- Simulated, non-persistent Evidence previews
- CompText-specific benchmark and JSON exports

`microsoft/llmlingua-2-bert-base-multilingual-cased-meetingbank`
## Hard boundaries

The first startup can take several minutes because the model must be downloaded.
- No provider calls
- No repository writes
- No runtime GitHub access
- No API keys or runtime secrets
- No AIR execution
- No persistent prompt storage
- No claim that planned or scaffolded components are production-ready

## Hardware
## Runtime

Designed for Hugging Face Spaces `CPU Basic` (2 vCPU, 16 GB RAM, 50 GB ephemeral storage).

## Safety

This Space does not call external LLM APIs, require runtime secrets, access private repositories, or modify repositories.
Only compression callbacks request ZeroGPU. Universe navigation, preview construction, contract views and secret-pattern checks are CPU-only and deterministic. The model is preloaded from the Hub during build to reduce first-request latency.
153 changes: 116 additions & 37 deletions hf_space/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,51 +10,77 @@

from compression import DEFAULT_MODEL, compress_text
from metrics import summarize_checks
from previews import build_air_preview, build_evidence_preview, scan_secrets
from safety_checks import run_safety_checks
from universe import capabilities_frame, contracts_frame, layers_frame, load_universe, overview_markdown, skills_frame

ROOT = Path(__file__).parent
BENCHMARK_CASES = json.loads((ROOT / "benchmark_cases.json").read_text(encoding="utf-8"))
UNIVERSE = load_universe()
EXAMPLE_TEXT = (
"Ändere AGENTS.md nicht und arbeite nur mit --dry-run. "
"CompText contains a detailed orchestration layer that coordinates providers, context preparation, policy checks, and output validation. "
"The architecture explanation is intentionally verbose so that the safe hybrid compressor has natural-language prose to reduce while preserving every technical constraint unchanged."
"Führe keine Live-Provider-Aufrufe aus. Ändere AGENTS.md nicht. "
"Analysiere ausführlich, wie CompText Context Packs für lokale Softwareentwicklung vorbereitet. "
"Nutze modules/cli/cli_entrypoint.py nur lesend mit --dry-run und gib einen JSON-Bericht zurück."
)


def _export(payload: object) -> str:
def _json_export(payload: object) -> str:
with NamedTemporaryFile("w", encoding="utf-8", suffix=".json", delete=False) as handle:
json.dump(payload, handle, ensure_ascii=False, indent=2)
return handle.name


@spaces.GPU
def compress_ui(text: str, retention_percent: int):
secret_matches = scan_secrets(text)
if secret_matches:
payload = {
"decision": "blocked",
"reason": "Potential secret material detected. Input was not processed.",
"secret_matches": secret_matches,
}
return text, payload, pd.DataFrame(), json.dumps(payload, ensure_ascii=False, indent=2), None
Comment on lines +37 to +42

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The object returned for the compression_metrics UI component is inconsistent. In this 'secret detected' case, you return a payload dictionary with lowercase keys. In the successful compression case, you return a metrics dictionary with capitalized keys and a different structure. This can be confusing for the UI and any programmatic consumers.

I suggest creating a metrics dictionary here that is consistent with the one in the success path, and use that for the UI component, while keeping the payload for the raw JSON output.

Suggested change
payload = {
"decision": "blocked",
"reason": "Potential secret material detected. Input was not processed.",
"secret_matches": secret_matches,
}
return text, payload, pd.DataFrame(), json.dumps(payload, ensure_ascii=False, indent=2), None
metrics = {
"Decision": "blocked",
"Reason": "Potential secret material detected. Input was not processed.",
"Secret matches": secret_matches,
}
payload = {
"decision": "blocked",
"reason": "Potential secret material detected. Input was not processed.",
"secret_matches": secret_matches,
}
return text, metrics, pd.DataFrame(), json.dumps(payload, ensure_ascii=False, indent=2), None


result = compress_text(text, retention_rate=retention_percent / 100)
checks = run_safety_checks(result.original_text, result.candidate_text)
summary = summarize_checks(checks)
decision = "accepted" if result.accepted else "fallback"
metrics = {
"Decision": "ACCEPTED" if result.accepted else "FALLBACK TO ORIGINAL",
"Fallback reason": result.fallback_reason or "",
"Decision": decision,
"Original tokens": result.origin_tokens,
"Output tokens": result.compressed_tokens,
"Net token reduction": f"{result.token_reduction_percent}%",
"Net reduction": f"{result.token_reduction_percent}%",
"Protected segments": result.protected_segments,
"Compressed segments": result.compressed_segments,
"Candidate safety": f"{summary['score_percent']}%",
"Runtime": f"{result.runtime_seconds}s",
"Candidate safety": f"{summary['passed']}/{summary['total']}",
"Reason": result.fallback_reason or "",
}
rows = [
{
"Check": c.name,
"Relevant": "Yes" if c.relevant else "No",
"Passed": "Yes" if c.passed else "No",
"Expected": ", ".join(c.expected),
"Missing": ", ".join(c.missing),
"Check": check.name,
"Relevant": "Yes" if check.relevant else "No",
"Passed": "Yes" if check.passed else "No",
"Expected": ", ".join(check.expected),
"Missing": ", ".join(check.missing),
}
for c in checks
for check in checks
]
payload = {"compression": result.to_dict(), "candidate_safety": summary}
return result.compressed_text, metrics, pd.DataFrame(rows), json.dumps(payload, ensure_ascii=False, indent=2), _export(payload)
payload = {
"decision": decision,
"compression": result.to_dict(),
"safety": summary,
"air_preview": build_air_preview(text, {"decision": decision, "metrics": metrics}),
"evidence_preview": build_evidence_preview(text, result.compressed_text, decision, metrics),
}
return result.compressed_text, metrics, pd.DataFrame(rows), json.dumps(payload, ensure_ascii=False, indent=2), _json_export(payload)


def preview_contracts(text: str):
matches = scan_secrets(text)
air = build_air_preview(text)
evidence = build_evidence_preview(text, text, "preview_only", {"secret_matches": matches})
return air, evidence


@spaces.GPU
Expand All @@ -80,39 +106,92 @@ def run_benchmark(retention_percent: int):
})
except Exception as exc:
rows.append({"Case": case["name"], "Category": case["category"], "Decision": "error", "Reason": str(exc)})
return pd.DataFrame(rows), _export(rows)
return pd.DataFrame(rows), _json_export(rows)


with gr.Blocks(title="CompText Prompt Compression Lab") as demo:
with gr.Blocks(title="CompText Universe") as demo:
gr.Markdown(overview_markdown(UNIVERSE))
gr.Markdown(
"# 🗜️ CompText Safe Hybrid Compression Lab\n"
"Critical instructions, flags, paths, JSON, versions, and code symbols are protected. "
"Only natural-language segments are compressed. Unsafe or ineffective candidates automatically fall back to the original text."
"**Experimental public showcase:** no provider calls, no repository writes, no AIR execution, "
"no persistent prompt storage. The local CompText kernel remains the product runtime."
)
with gr.Tab("Single prompt"):
input_text = gr.Textbox(label="Original prompt", value=EXAMPLE_TEXT, lines=14)

with gr.Tab("Overview"):
with gr.Row():
gr.Markdown(
"## Context is the product\n"
"CompText treats models as interchangeable providers while context, contracts and Evidence "
"form the durable engineering system. This Space visualizes that model without executing it."
)
gr.JSON(value={
"product_status": UNIVERSE["product"]["status"],
"snapshot_version": UNIVERSE["snapshot_version"],
"runtime_github_access": UNIVERSE["source"]["runtime_github_access"],
"compression_model": DEFAULT_MODEL,
}, label="Snapshot identity")
gr.Dataframe(value=contracts_frame(UNIVERSE), label="Core contracts", interactive=False)

with gr.Tab("Architecture"):
gr.Markdown(
"## Seven-layer model\n"
"`User → Terminal OS / UI → Runtime / Gateway / Agent Bus → AIR / Evidence / Memory → Provider Router`"
)
gr.Dataframe(value=layers_frame(UNIVERSE), label="Architecture layers", interactive=False)

with gr.Tab("Capabilities"):
gr.Markdown("## What exists, what is experimental, and what remains future")
gr.Dataframe(value=capabilities_frame(UNIVERSE), label="Capability matrix", interactive=False)

with gr.Tab("Compression Lab"):
gr.Markdown(
"## Fail-closed hybrid compression\n"
"Critical instructions, flags, paths, structured data and code-like symbols are protected. "
"Unsafe or unhelpful candidates return the exact original input."
)
input_text = gr.Textbox(label="Engineering context", value=EXAMPLE_TEXT, lines=14)
retention = gr.Slider(10, 100, value=60, step=5, label="Retention rate (%)")
button = gr.Button("Compress safely", variant="primary")
compressed = gr.Textbox(label="Safe output", lines=14)
metrics = gr.JSON(label="Decision and metrics")
checks = gr.Dataframe(label="Candidate safety checks", interactive=False)
raw = gr.Code(label="Raw result", language="json")
download = gr.File(label="Download JSON result")
button.click(compress_ui, [input_text, retention], [compressed, metrics, checks, raw, download])
with gr.Tab("Benchmark suite"):
compress_button = gr.Button("Analyze and compress", variant="primary")
compressed = gr.Textbox(label="Final output", lines=14)
compression_metrics = gr.JSON(label="Decision and metrics")
checks = gr.Dataframe(label="Relevant preservation checks", interactive=False)
raw = gr.Code(label="Compression + AIR + Evidence payload", language="json")
download = gr.File(label="Download JSON")
compress_button.click(compress_ui, [input_text, retention], [compressed, compression_metrics, checks, raw, download])

with gr.Tab("AIR & Evidence"):
gr.Markdown(
"## Non-executable contract previews\n"
"AIR describes intended work. Evidence describes observed work. Here, AIR is always disabled and "
"Evidence is always marked as simulated."
)
preview_text = gr.Textbox(label="Engineering task", value=EXAMPLE_TEXT, lines=10)
preview_button = gr.Button("Build previews")
air_output = gr.JSON(label="AIR preview")
evidence_output = gr.JSON(label="Simulated Evidence preview")
preview_button.click(preview_contracts, preview_text, [air_output, evidence_output])

with gr.Tab("Skills"):
gr.Markdown("## Skill-grounded local workflow and safety boundaries")
gr.Dataframe(value=skills_frame(UNIVERSE), label="Workspace skills", interactive=False)

with gr.Tab("Benchmarks"):
gr.Markdown("## CompText-specific protected-context benchmark")
bench_rate = gr.Slider(10, 100, value=60, step=5, label="Retention rate (%)")
bench_button = gr.Button("Run safe hybrid benchmark", variant="primary")
bench_button = gr.Button("Run benchmark", variant="primary")
bench_table = gr.Dataframe(label="Benchmark results", interactive=False)
bench_download = gr.File(label="Download benchmark JSON")
bench_button.click(run_benchmark, bench_rate, [bench_table, bench_download])
with gr.Accordion("Decision policy", open=False):

with gr.Accordion("Model, provenance and limitations", open=False):
gr.JSON(value=UNIVERSE["source"], label="Static snapshot provenance")
gr.Markdown(
f"**Model:** `{DEFAULT_MODEL}`\n\n"
"A result is accepted only when all relevant protected elements survive and net token reduction is at least 10%. "
"Otherwise the exact original input is returned."
f"**Compression model:** `{DEFAULT_MODEL}`\n\n"
"The Universe snapshot is committed data, not a live GitHub view. Safety checks are deterministic "
"preservation heuristics, not a semantic equivalence proof."
)


demo.queue(default_concurrency_limit=1, max_size=8)

if __name__ == "__main__":
demo.launch()
demo.launch(ssr_mode=False)
65 changes: 65 additions & 0 deletions hf_space/data/universe_snapshot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"snapshot_version": "1.0",
"product": {
"name": "CompText",
"repository_name": "comptext",
"status": "local-dry-run-mvp",
"claim": "Models are providers. Context is the product. Evidence is the trust layer. CompText is the kernel.",
"description": "A local AI orchestration platform for software engineering. This public Space is an experimental, non-executing showcase."
},
"source": {
"repository": "ProfRandom92/Comptext",
"mode": "committed-static-snapshot",
"runtime_github_access": false,
"allowed_sources": [
"AGENTS.md",
"docs/COMPTEXT_ARCHITECTURE_v1.md",
".agents/skills/comptext-local-autonomy/SKILL.md",
".agents/skills/comptext-local-verify/SKILL.md",
".agents/skills/comptext-workspace-validation/SKILL.md",
".agents/skills/comptext-status/SKILL.md",
".agents/skills/workspace-state/SKILL.md"
]
},
"boundaries": [
"No provider calls",
"No repository writes",
"No runtime GitHub access",
"No secrets or environment access",
"No AIR execution",
"No persistent user input storage"
],
"layers": [
{"id":"ui","name":"Terminal OS / UI","status":"scaffolded","purpose":"Human-facing workbench for sessions, workspaces, commands, providers, evidence and run queues.","inputs":"user intent","outputs":"normalized commands and views"},
{"id":"runtime","name":"Runtime","status":"scaffolded","purpose":"Coordinates runs, plans, verification, retries, queues and replay.","inputs":"AIR plans","outputs":"run state and events"},
{"id":"gateway","name":"Gateway","status":"planned","purpose":"Normalizes local provider-compatible message and response routes.","inputs":"local API requests","outputs":"normalized traffic"},
{"id":"agent-bus","name":"Agent Bus","status":"planned","purpose":"Coordinates specialized agents as explicit tasks with approval gates.","inputs":"tasks and roles","outputs":"task results and evidence"},
{"id":"air","name":"AIR","status":"scaffolded","purpose":"Describes intended work before execution: goal, context, tools, constraints, permissions and outputs.","inputs":"intent and context","outputs":"non-executed plan contract"},
{"id":"evidence","name":"Evidence","status":"scaffolded","purpose":"Records what actually happened without secrets, raw provider payloads or hidden reasoning.","inputs":"runtime and validation events","outputs":"redacted evidence events"},
{"id":"memory","name":"Memory / Knowledge Graph","status":"future","purpose":"Structured workspace knowledge spanning files, functions, tests, runs and evidence.","inputs":"validated workspace state","outputs":"retrievable context relationships"}
],
"capabilities": [
{"name":"Local status","surface":"CLI","status":"implemented","network":"no","provider":"no","mutating":"no"},
{"name":"Local verification","surface":"CLI","status":"implemented","network":"no","provider":"no","mutating":"no"},
{"name":"Workspace schema validation","surface":"CLI","status":"implemented","network":"no","provider":"no","mutating":"no"},
{"name":"Hybrid context compression","surface":"HF Space","status":"experimental","network":"model-cache","provider":"no","mutating":"no"},
{"name":"AIR preview","surface":"HF Space","status":"experimental","network":"no","provider":"no","mutating":"no"},
{"name":"Simulated Evidence preview","surface":"HF Space","status":"experimental","network":"no","provider":"no","mutating":"no"},
{"name":"Provider Router","surface":"Kernel","status":"scaffolded","network":"disabled","provider":"not_configured","mutating":"no"},
{"name":"Workspace reflection runtime","surface":"Kernel","status":"future","network":"no","provider":"no","mutating":"local"},
{"name":"Autonomous PR merge","surface":"Agent workflow","status":"disabled","network":"yes","provider":"no","mutating":"yes"}
],
"skills": [
{"name":"comptext-local-autonomy","purpose":"One-unit-at-a-time offline development loop.","validation":"python -m pytest; git diff --check","boundary":"No network, providers, secrets, GitHub writes or servers."},
{"name":"comptext-local-verify","purpose":"Verify status, subagents, workspace validation and doctor diagnostics.","validation":"comptext verify --dry-run","boundary":"Offline dry-run checks only."},
{"name":"comptext-workspace-validation","purpose":"Validate committed workspace examples against strict schemas.","validation":"comptext validate workspace --dry-run","boundary":"No active generation, network, databases or providers."},
{"name":"comptext-status","purpose":"Show file presence and local diagnostic state.","validation":"comptext status --dry-run","boundary":"Offline local-only data collection."},
{"name":"workspace-state","purpose":"Define future snapshot, delta and reflection-gate concepts.","validation":"schema and fixture validation","boundary":"No active runtime or interpretability claims."}
],
"contracts": [
{"name":"AIR Plan","kind":"intent","fields":"version, intent, goal, context, files, tools, permissions, expected_outputs, metadata","execution":"never in this Space"},
{"name":"Evidence Event","kind":"observed-event","fields":"event_id, run_id, type, actor, tool, summary, hashes, timestamp, redaction","execution":"simulated preview only"},
{"name":"Run Record","kind":"run-index","fields":"run_id, air_hash, status, start_time, end_time, event_hashes, metrics","execution":"not created in this Space"},
{"name":"Workspace Snapshot","kind":"workspace-state","fields":"schema-defined local state","execution":"static concept preview only"}
]
}
Loading
Loading