wydcode 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +100 -0
- package/NOTICE +5 -0
- package/README.md +434 -0
- package/SECURITY.md +64 -0
- package/SOCRA_SOURCE.md +36 -0
- package/TRADEMARKS.md +12 -0
- package/bin/wydcode.js +74 -0
- package/examples/behavior-preference-card.json +12 -0
- package/examples/exact-recurrence-card.json +11 -0
- package/examples/heldout-gene-evidence.json +6 -0
- package/examples/humaneval-ornith.md +29 -0
- package/examples/large_context_json_diagnostic.py +187 -0
- package/fixtures/failing-node-repo/package.json +9 -0
- package/fixtures/failing-node-repo/src/math.js +3 -0
- package/fixtures/failing-node-repo/test/math.test.js +8 -0
- package/package.json +55 -0
- package/pyproject.toml +24 -0
- package/socra_harness/__init__.py +3 -0
- package/socra_harness/attempts.py +76 -0
- package/socra_harness/central_traces.py +627 -0
- package/socra_harness/cli.py +265 -0
- package/socra_harness/eval/__init__.py +1 -0
- package/socra_harness/eval/humaneval.py +388 -0
- package/socra_harness/events.py +39 -0
- package/socra_harness/init.py +206 -0
- package/socra_harness/job/__init__.py +2 -0
- package/socra_harness/job/events.py +132 -0
- package/socra_harness/job/lock.py +90 -0
- package/socra_harness/job/manager.py +3785 -0
- package/socra_harness/job/planner.py +253 -0
- package/socra_harness/job/state.py +106 -0
- package/socra_harness/mumpix_trace_bridge.cjs +32 -0
- package/socra_harness/product.py +533 -0
- package/socra_harness/recurrence.py +263 -0
- package/socra_harness/scan/__init__.py +1 -0
- package/socra_harness/scan/repo.py +85 -0
- package/socra_harness/serve/__init__.py +1 -0
- package/socra_harness/serve/local_proxy.py +293 -0
- package/socra_harness/start.py +331 -0
- package/socra_harness/tui/__init__.py +1 -0
- package/socra_harness/tui/app.py +1114 -0
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import json
|
|
5
|
+
import os
|
|
6
|
+
import subprocess
|
|
7
|
+
import sys
|
|
8
|
+
import time
|
|
9
|
+
import urllib.request
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
from typing import Any
|
|
12
|
+
|
|
13
|
+
from .scan.repo import scan_main
|
|
14
|
+
from .serve.local_proxy import serve_main
|
|
15
|
+
from .tui.app import tui_main
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
COMMON_MODEL_DIRS = [
|
|
19
|
+
Path.home() / "Downloads",
|
|
20
|
+
Path.home() / "models",
|
|
21
|
+
Path.home() / "Desktop" / "dev" / "models",
|
|
22
|
+
Path.home() / "Desktop" / "dev" / "APM" / "dist",
|
|
23
|
+
Path.home() / "Desktop" / "dev" / "updates",
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def socra_home() -> Path:
|
|
28
|
+
override = os.environ.get("SOCRA_HARNESS_HOME")
|
|
29
|
+
if override:
|
|
30
|
+
return Path(override).expanduser().resolve()
|
|
31
|
+
return Path.home() / ".socra-harness"
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def recent_projects_path() -> Path:
|
|
35
|
+
return socra_home() / "recent-projects.json"
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def discover_models(extra_dirs: list[Path]) -> list[Path]:
|
|
39
|
+
seen = set()
|
|
40
|
+
models = []
|
|
41
|
+
for root in [*extra_dirs, *COMMON_MODEL_DIRS]:
|
|
42
|
+
if not root.exists():
|
|
43
|
+
continue
|
|
44
|
+
for path in root.rglob("*.gguf"):
|
|
45
|
+
if path in seen:
|
|
46
|
+
continue
|
|
47
|
+
seen.add(path)
|
|
48
|
+
models.append(path)
|
|
49
|
+
return sorted(models, key=lambda p: p.stat().st_mtime if p.exists() else 0, reverse=True)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def read_recent_projects() -> list[dict[str, Any]]:
|
|
53
|
+
path = recent_projects_path()
|
|
54
|
+
if not path.exists():
|
|
55
|
+
return []
|
|
56
|
+
try:
|
|
57
|
+
data = json.loads(path.read_text(encoding="utf-8"))
|
|
58
|
+
except Exception:
|
|
59
|
+
return []
|
|
60
|
+
projects = data.get("projects") if isinstance(data, dict) else data
|
|
61
|
+
if not isinstance(projects, list):
|
|
62
|
+
return []
|
|
63
|
+
clean = []
|
|
64
|
+
for item in projects:
|
|
65
|
+
if not isinstance(item, dict):
|
|
66
|
+
continue
|
|
67
|
+
raw_path = item.get("path")
|
|
68
|
+
if isinstance(raw_path, str) and raw_path:
|
|
69
|
+
clean.append(item)
|
|
70
|
+
return clean
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def write_recent_projects(projects: list[dict[str, Any]]) -> None:
|
|
74
|
+
path = recent_projects_path()
|
|
75
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
76
|
+
payload = {"version": 1, "projects": projects[:30]}
|
|
77
|
+
path.write_text(json.dumps(payload, indent=2) + "\n", encoding="utf-8")
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def remember_project(project: Path, model: Path | None = None, alias: str | None = None) -> None:
|
|
81
|
+
project = project.expanduser().resolve()
|
|
82
|
+
now = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())
|
|
83
|
+
existing = read_recent_projects()
|
|
84
|
+
kept = [item for item in existing if Path(str(item.get("path"))).expanduser().resolve() != project]
|
|
85
|
+
entry = {
|
|
86
|
+
"name": project.name,
|
|
87
|
+
"path": str(project),
|
|
88
|
+
"state_dir": str(project / ".socra"),
|
|
89
|
+
"last_opened_at": now,
|
|
90
|
+
}
|
|
91
|
+
if model:
|
|
92
|
+
entry["last_model"] = str(model)
|
|
93
|
+
if alias:
|
|
94
|
+
entry["last_alias"] = alias
|
|
95
|
+
write_recent_projects([entry, *kept])
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def discover_socra_projects() -> list[Path]:
|
|
99
|
+
roots = [Path.home() / "Desktop", Path.home() / "Desktop" / "dev"]
|
|
100
|
+
found: list[Path] = []
|
|
101
|
+
seen: set[Path] = set()
|
|
102
|
+
skip = {".git", "node_modules", ".next", "dist", "build", "DerivedData", ".venv", "venv", "__pycache__"}
|
|
103
|
+
for root in roots:
|
|
104
|
+
if not root.exists():
|
|
105
|
+
continue
|
|
106
|
+
root_depth = len(root.resolve().parts)
|
|
107
|
+
for dirpath, dirnames, _filenames in os.walk(root):
|
|
108
|
+
current = Path(dirpath)
|
|
109
|
+
depth = len(current.resolve().parts) - root_depth
|
|
110
|
+
dirnames[:] = [name for name in dirnames if name not in skip and not name.endswith(".xcarchive")]
|
|
111
|
+
if ".socra" in dirnames:
|
|
112
|
+
project = current.resolve()
|
|
113
|
+
if project not in seen:
|
|
114
|
+
seen.add(project)
|
|
115
|
+
found.append(project)
|
|
116
|
+
if len(found) >= 25:
|
|
117
|
+
return found
|
|
118
|
+
if depth >= 4:
|
|
119
|
+
dirnames[:] = []
|
|
120
|
+
return found
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def prompt_choice(title: str, choices: list[str], allow_custom: bool = False, custom_label: str = "New / custom path", custom_prompt: str = "Path") -> str:
|
|
124
|
+
print(f"\n{title}")
|
|
125
|
+
for index, item in enumerate(choices, start=1):
|
|
126
|
+
print(f" {index}. {item}")
|
|
127
|
+
if allow_custom:
|
|
128
|
+
print(f" n. {custom_label}")
|
|
129
|
+
while True:
|
|
130
|
+
raw = input("> ").strip()
|
|
131
|
+
if allow_custom and raw.lower() in {"n", "new"}:
|
|
132
|
+
return input(f"{custom_prompt}: ").strip()
|
|
133
|
+
if raw.isdigit() and 1 <= int(raw) <= len(choices):
|
|
134
|
+
return choices[int(raw) - 1]
|
|
135
|
+
print("Choose a listed number" + (" or n" if allow_custom else "") + ".")
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def choose_model(args: Any) -> Path:
|
|
139
|
+
if args.model:
|
|
140
|
+
return args.model.expanduser().resolve()
|
|
141
|
+
models = discover_models([Path(p).expanduser() for p in args.model_dir])
|
|
142
|
+
if not models:
|
|
143
|
+
raw = input("No GGUF models found. Enter model path: ").strip()
|
|
144
|
+
return Path(raw).expanduser().resolve()
|
|
145
|
+
labels = []
|
|
146
|
+
for path in models[:25]:
|
|
147
|
+
size_gb = path.stat().st_size / (1024 ** 3)
|
|
148
|
+
labels.append(f"{path.name} ({size_gb:.1f} GiB) {path}")
|
|
149
|
+
selected = prompt_choice("Pick a GGUF model", labels, allow_custom=True, custom_label="Custom model path", custom_prompt="Model path")
|
|
150
|
+
if selected.startswith("/") or selected.startswith("~"):
|
|
151
|
+
return Path(selected).expanduser().resolve()
|
|
152
|
+
return models[labels.index(selected)].resolve()
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def desktop_project_path(raw: str) -> Path:
|
|
156
|
+
value = raw.strip()
|
|
157
|
+
if not value:
|
|
158
|
+
raise SystemExit("Project name cannot be empty.")
|
|
159
|
+
path = Path(value).expanduser()
|
|
160
|
+
if path.is_absolute() or value.startswith("~") or "/" in value:
|
|
161
|
+
return path.resolve()
|
|
162
|
+
safe_name = "".join(char if char.isalnum() or char in {" ", "-", "_", "."} else "-" for char in value).strip()
|
|
163
|
+
if not safe_name:
|
|
164
|
+
raise SystemExit("Project name must contain at least one usable character.")
|
|
165
|
+
return (Path.home() / "Desktop" / safe_name).resolve()
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def choose_project(args: Any) -> Path:
|
|
169
|
+
if args.project:
|
|
170
|
+
return args.project.expanduser().resolve()
|
|
171
|
+
recent_paths = []
|
|
172
|
+
for item in read_recent_projects():
|
|
173
|
+
path = Path(str(item.get("path"))).expanduser()
|
|
174
|
+
if path.exists():
|
|
175
|
+
recent_paths.append(path.resolve())
|
|
176
|
+
recent_roots = [
|
|
177
|
+
Path.home() / "Desktop" / "dev" / "P" / "Vane-master",
|
|
178
|
+
Path.home() / "Desktop" / "dev" / "AxiomIOSBrowser",
|
|
179
|
+
Path.home() / "Desktop" / "dev" / "socra-harness",
|
|
180
|
+
Path.cwd(),
|
|
181
|
+
]
|
|
182
|
+
seen: set[Path] = set()
|
|
183
|
+
choices_paths: list[Path] = []
|
|
184
|
+
for path in [*recent_paths, *recent_roots, *discover_socra_projects()]:
|
|
185
|
+
resolved = path.expanduser().resolve()
|
|
186
|
+
if resolved in seen or not resolved.exists():
|
|
187
|
+
continue
|
|
188
|
+
seen.add(resolved)
|
|
189
|
+
choices_paths.append(resolved)
|
|
190
|
+
choices = [str(path) for path in choices_paths]
|
|
191
|
+
selected = prompt_choice(
|
|
192
|
+
"Pick a project folder",
|
|
193
|
+
choices,
|
|
194
|
+
allow_custom=True,
|
|
195
|
+
custom_label="New Desktop project or custom path",
|
|
196
|
+
custom_prompt="Project name or path",
|
|
197
|
+
)
|
|
198
|
+
project = desktop_project_path(selected)
|
|
199
|
+
created = not project.exists()
|
|
200
|
+
project.mkdir(parents=True, exist_ok=True)
|
|
201
|
+
if created:
|
|
202
|
+
(project / "README.md").write_text(f"# {project.name}\n\nCreated by Socra Harness.\n")
|
|
203
|
+
print(f"Created new project folder: {project}")
|
|
204
|
+
return project
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
def start_main(args: Any) -> int:
|
|
208
|
+
model = choose_model(args)
|
|
209
|
+
project = choose_project(args)
|
|
210
|
+
state_dir = project / ".socra"
|
|
211
|
+
state_dir.mkdir(parents=True, exist_ok=True)
|
|
212
|
+
|
|
213
|
+
alias = args.alias or model.stem
|
|
214
|
+
remember_project(project, model=model, alias=alias)
|
|
215
|
+
config = {
|
|
216
|
+
"model": str(model),
|
|
217
|
+
"alias": alias,
|
|
218
|
+
"project": str(project),
|
|
219
|
+
"endpoint": f"http://127.0.0.1:{args.port}/v1",
|
|
220
|
+
"state_dir": str(state_dir),
|
|
221
|
+
"local_first": True,
|
|
222
|
+
"hosted_fallback": False,
|
|
223
|
+
"sandbox": {
|
|
224
|
+
"network": bool(args.allow_sandbox_network),
|
|
225
|
+
"installs": bool(args.allow_sandbox_installs),
|
|
226
|
+
"root": str(state_dir / "run-sandbox" / "command-workspace"),
|
|
227
|
+
},
|
|
228
|
+
}
|
|
229
|
+
(state_dir / "session.json").write_text(json.dumps(config, indent=2) + "\n")
|
|
230
|
+
|
|
231
|
+
if not args.no_scan:
|
|
232
|
+
scan_args = argparse.Namespace(
|
|
233
|
+
folder=project,
|
|
234
|
+
out=state_dir / "candidates.json",
|
|
235
|
+
event_log=state_dir / "events.jsonl",
|
|
236
|
+
)
|
|
237
|
+
scan_main(scan_args)
|
|
238
|
+
|
|
239
|
+
serve_args = argparse.Namespace(
|
|
240
|
+
model=model,
|
|
241
|
+
alias=alias,
|
|
242
|
+
llama_server=args.llama_server,
|
|
243
|
+
host="127.0.0.1",
|
|
244
|
+
port=args.port,
|
|
245
|
+
backend_host="127.0.0.1",
|
|
246
|
+
backend_port=args.backend_port,
|
|
247
|
+
ctx_size=args.ctx_size,
|
|
248
|
+
gpu_layers=args.gpu_layers,
|
|
249
|
+
reuse_backend=False,
|
|
250
|
+
event_log=state_dir / "events.jsonl",
|
|
251
|
+
)
|
|
252
|
+
|
|
253
|
+
print("\nSocra Harness session")
|
|
254
|
+
print(f" Project: {project}")
|
|
255
|
+
print(f" Model: {alias} ({model})")
|
|
256
|
+
print(f" UI: socra-harness tui --state-dir {state_dir}")
|
|
257
|
+
print(f" API: http://127.0.0.1:{args.port}/v1")
|
|
258
|
+
print("\nPoint Codex/editor tools at the API URL to vibe code with model + Socra harness.\n")
|
|
259
|
+
if args.no_ui:
|
|
260
|
+
return serve_main(serve_args)
|
|
261
|
+
return start_runtime_with_tui(args, serve_args, state_dir)
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
def endpoint_ready(port: int) -> bool:
|
|
265
|
+
try:
|
|
266
|
+
with urllib.request.urlopen(f"http://127.0.0.1:{port}/health", timeout=2) as res:
|
|
267
|
+
return res.status == 200
|
|
268
|
+
except Exception:
|
|
269
|
+
return False
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
def wait_for_endpoint(port: int, timeout_seconds: int = 180) -> bool:
|
|
273
|
+
deadline = time.time() + timeout_seconds
|
|
274
|
+
while time.time() < deadline:
|
|
275
|
+
if endpoint_ready(port):
|
|
276
|
+
return True
|
|
277
|
+
time.sleep(1)
|
|
278
|
+
return False
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
def start_runtime_with_tui(args: Any, serve_args: argparse.Namespace, state_dir: Path) -> int:
|
|
282
|
+
out_log = state_dir / "socra-harness-serve.out.log"
|
|
283
|
+
err_log = state_dir / "socra-harness-serve.err.log"
|
|
284
|
+
cmd = [
|
|
285
|
+
sys.executable,
|
|
286
|
+
"-m",
|
|
287
|
+
"socra_harness.cli",
|
|
288
|
+
"serve",
|
|
289
|
+
"--model",
|
|
290
|
+
str(serve_args.model),
|
|
291
|
+
"--alias",
|
|
292
|
+
str(serve_args.alias),
|
|
293
|
+
"--llama-server",
|
|
294
|
+
str(serve_args.llama_server),
|
|
295
|
+
"--host",
|
|
296
|
+
serve_args.host,
|
|
297
|
+
"--port",
|
|
298
|
+
str(serve_args.port),
|
|
299
|
+
"--backend-host",
|
|
300
|
+
serve_args.backend_host,
|
|
301
|
+
"--backend-port",
|
|
302
|
+
str(serve_args.backend_port),
|
|
303
|
+
"--ctx-size",
|
|
304
|
+
str(serve_args.ctx_size),
|
|
305
|
+
"--gpu-layers",
|
|
306
|
+
str(serve_args.gpu_layers),
|
|
307
|
+
"--event-log",
|
|
308
|
+
str(serve_args.event_log),
|
|
309
|
+
]
|
|
310
|
+
env = os.environ.copy()
|
|
311
|
+
package_root = str(Path(__file__).resolve().parents[1])
|
|
312
|
+
env["PYTHONPATH"] = package_root + (os.pathsep + env["PYTHONPATH"] if env.get("PYTHONPATH") else "")
|
|
313
|
+
with out_log.open("a", encoding="utf-8") as out, err_log.open("a", encoding="utf-8") as err:
|
|
314
|
+
proc = subprocess.Popen(cmd, stdout=out, stderr=err, env=env)
|
|
315
|
+
print("Starting Socra Harness runtime in the background for this terminal session...")
|
|
316
|
+
print(f" stdout: {out_log}")
|
|
317
|
+
print(f" stderr: {err_log}")
|
|
318
|
+
if not wait_for_endpoint(serve_args.port):
|
|
319
|
+
proc.terminate()
|
|
320
|
+
raise SystemExit(f"Socra Harness endpoint did not become ready. Check {err_log}")
|
|
321
|
+
print("Runtime ready. Opening terminal dashboard. Press q to stop the session.")
|
|
322
|
+
try:
|
|
323
|
+
tui_args = argparse.Namespace(state_dir=state_dir, refresh=args.ui_refresh)
|
|
324
|
+
return tui_main(tui_args)
|
|
325
|
+
finally:
|
|
326
|
+
if proc.poll() is None:
|
|
327
|
+
proc.terminate()
|
|
328
|
+
try:
|
|
329
|
+
proc.wait(timeout=15)
|
|
330
|
+
except subprocess.TimeoutExpired:
|
|
331
|
+
proc.kill()
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|