File size: 10,230 Bytes
a282a43 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 | """Render authored M2 scenario views; never assign splits or obtain model predictions."""
import argparse
import csv
import hashlib
import json
from collections import Counter
from pathlib import Path
from typing import Any
from decisioncraft.data import DatasetCase
SOURCE_ID = "decisioncraft-m2"
AUTHOR = "codex-agent-decision_source"
WORKSPACE = "The current directory is a local Linux workspace with GNU utilities."
NEGATION = "Do not install software, contact a network service, or run a container."
DISTRACTOR = (
'An unrelated local note contains the quoted words "docker run" and "npm install"; '
"neither is an instruction."
)
def read_tsv(path: Path) -> list[dict[str, str]]:
with path.open(newline="", encoding="utf-8") as stream:
rows = list(csv.DictReader(stream, delimiter="\t"))
if not rows or any(any(not value for value in row.values()) for row in rows):
raise ValueError(f"Empty source cell in {path}")
return rows
def typo(text: str) -> str:
"""One visible adjacent-letter transposition; this does not create a new scenario."""
for index in range(1, len(text) - 1):
if text[index - 1 : index + 3].isalpha() and text[index] != text[index + 1]:
return text[:index] + text[index + 1] + text[index] + text[index + 2 :]
raise ValueError("No unambiguous interior word transposition available")
def row(
spec: dict[str, str],
variant: str,
request: str,
context: str,
label: str,
rationale: str,
tags: list[str],
) -> dict[str, Any]:
scenario = spec["scenario_id"]
value = {
"id": f"{scenario}--{variant}",
"group_id": f"{SOURCE_ID}:{scenario}",
"family": spec["family"],
"request": request,
"context": context,
"label": label,
"rationale": rationale,
"tags": tags,
"provenance": {
"source_id": SOURCE_ID,
"scenario_id": scenario,
"variant_id": variant,
"author": AUTHOR,
"method": "synthetic-authored",
"license": "Apache-2.0",
},
"review": {
"status": "pending",
"reviewer": None,
"notes": "Author checks only; independent review pending.",
},
}
return DatasetCase.model_validate(value).model_dump()
def supported_views(spec: dict[str, str]) -> list[dict[str, Any]]:
facts = f"{WORKSPACE} {spec['facts']}"
resolved = f"{facts} The agreed {spec['slot']} is {spec['choice_a']}."
missing = f"{facts} No choice of {spec['slot']} has been provided."
conflict = (
f"{facts} For {spec['slot']}, one current instruction says {spec['choice_a']}; "
f"another equally current instruction says {spec['choice_b']}. "
"Neither instruction has priority or withdraws the other."
)
yes = (
f"This is a supported local operation. The request and context resolve the "
f"material {spec['slot']} as {spec['choice_a']}."
)
no = f"The local operation needs a choice of {spec['slot']}; none is supplied."
conflicting = (
f"The local operation has unresolved conflicting choices of {spec['slot']}: "
f"{spec['choice_a']} versus {spec['choice_b']}."
)
output = []
views = [
("direct", spec["request"], resolved, spec["request"], missing, []),
("rephrase", spec["paraphrase"], resolved, spec["paraphrase"], missing, ["paraphrase"]),
(
"inline",
f"{spec['request']} {resolved}",
"All relevant context is in the request.",
f"{spec['request']} {missing}",
"All relevant context is in the request.",
["context-in-request"],
),
(
"negation",
f"{NEGATION} {spec['request']}",
resolved,
f"{NEGATION} {spec['request']}",
missing,
["negation", "unsupported-keywords"],
),
(
"typo",
typo(spec["request"]),
resolved,
typo(spec["request"]),
missing,
["single-transposition-typo"],
),
(
"quoted",
spec["request"],
f"{resolved} {DISTRACTOR}",
spec["request"],
f"{conflict} {DISTRACTOR}",
["quoted-distractor", "unsupported-keywords"],
),
]
for name, yes_request, yes_context, no_request, no_context, tags in views:
output.append(
row(
spec,
f"specified-{name}",
yes_request,
yes_context,
"suggest",
yes,
["supported", "specified", *tags],
)
)
output.append(
row(
spec,
f"unresolved-{name}",
no_request,
no_context,
"clarify",
conflicting if name == "quoted" else no,
[
"supported",
"unresolved",
"conflicting-context" if name == "quoted" else "missing-material-slot",
*tags,
],
)
)
return output
def unsupported_views(spec: dict[str, str]) -> list[dict[str, Any]]:
facts = f"{WORKSPACE} {spec['facts']}"
task = spec["request"]
rationale = (
f"The positive requested action is outside GNU file/text utilities and local Git: "
f"{spec['family']}. Additional details, harmless local steps or a typo "
"do not bring it into scope."
)
views = [
("direct", task, facts, ["standalone-unsupported"]),
("rephrase", spec["paraphrase"], facts, ["standalone-unsupported", "paraphrase"]),
(
"inline",
f"{task} {facts}",
"All relevant context is in the request.",
["standalone-unsupported", "context-in-request"],
),
(
"missing-details",
task,
f"{WORKSPACE} The implementation-specific arguments are not yet supplied.",
["standalone-unsupported", "unsupported-precedence", "missing-details"],
),
("typo", typo(task), facts, ["standalone-unsupported", "single-transposition-typo"]),
(
"negated-local",
f"Do not just display local instructions. {task}",
facts,
["standalone-unsupported", "negation"],
),
(
"mixed-before",
f"Print dispatch-note.txt to the terminal, then {task[0].lower() + task[1:]}",
f"{facts} dispatch-note.txt exists locally.",
["mixed-scope", "local-before-external"],
),
(
"mixed-after",
f"{task} Afterward print dispatch-note.txt to the terminal.",
f"{facts} dispatch-note.txt exists locally.",
["mixed-scope", "external-before-local"],
),
(
"mixed-directory",
f"Create the local directory job-receipts if it does not exist. {task}",
facts,
["mixed-scope", "local-directory-creation"],
),
(
"mixed-copy",
f"Copy dispatch-note.txt to receipt-note.txt without changing the original. {task}",
f"{facts} dispatch-note.txt exists and receipt-note.txt does not.",
["mixed-scope", "local-copy"],
),
(
"withdrawn-local",
f'The earlier request "list local files" is withdrawn. Instead: {task}',
facts,
["standalone-unsupported", "explicit-instruction-priority", "quoted-local"],
),
(
"quoted-note",
task,
f'{facts} A note contains the quoted phrase "print local file sizes"; '
"that phrase is not an instruction.",
["standalone-unsupported", "quoted-distractor"],
),
]
return [
row(spec, name, request, context, "unsupported", rationale, tags)
for name, request, context, tags in views
]
def build(source_dir: Path) -> list[dict[str, Any]]:
sources = [
(read_tsv(source_dir / "supported.tsv"), supported_views),
(read_tsv(source_dir / "unsupported.tsv"), unsupported_views),
]
rows = []
seen = set()
for specs, render in sources:
for spec in specs:
if spec["scenario_id"] in seen:
raise ValueError(f"Duplicate scenario ID: {spec['scenario_id']}")
seen.add(spec["scenario_id"])
rows.extend(render(spec))
if len(rows) != 1800 or len(seen) != 150:
raise ValueError("M2 source must define 150 scenario groups and 1,800 related views")
if Counter(value["label"] for value in rows) != {
"suggest": 600,
"clarify": 600,
"unsupported": 600,
}:
raise ValueError("M2 label counts differ from the authored design")
return sorted(rows, key=lambda value: value["id"])
def main() -> None:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--source-dir", type=Path, default=Path("data/authored"))
parser.add_argument("--output", type=Path, required=True)
args = parser.parse_args()
if args.output.exists():
raise FileExistsError(f"Refusing to replace authored expansion: {args.output}")
rows = build(args.source_dir)
payload = "".join(
json.dumps(value, ensure_ascii=False, sort_keys=True) + "\n" for value in rows
)
args.output.parent.mkdir(parents=True, exist_ok=True)
with args.output.open("x", encoding="utf-8") as stream:
stream.write(payload)
print(
json.dumps(
{
"status": "built-not-reviewed",
"cases": len(rows),
"groups": 150,
"labels": dict(Counter(value["label"] for value in rows)),
"sha256": hashlib.sha256(payload.encode()).hexdigest(),
"human_reviewed": False,
"splits_assigned": False,
},
indent=2,
)
)
if __name__ == "__main__":
main()
|