hte-cli 0.1.28__py3-none-any.whl → 0.2.1__py3-none-any.whl
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.
- hte_cli/api_client.py +25 -0
- hte_cli/cli.py +262 -3
- {hte_cli-0.1.28.dist-info → hte_cli-0.2.1.dist-info}/METADATA +5 -1
- {hte_cli-0.1.28.dist-info → hte_cli-0.2.1.dist-info}/RECORD +6 -6
- {hte_cli-0.1.28.dist-info → hte_cli-0.2.1.dist-info}/WHEEL +0 -0
- {hte_cli-0.1.28.dist-info → hte_cli-0.2.1.dist-info}/entry_points.txt +0 -0
hte_cli/api_client.py
CHANGED
|
@@ -201,6 +201,31 @@ class APIClient:
|
|
|
201
201
|
},
|
|
202
202
|
)
|
|
203
203
|
|
|
204
|
+
# =========================================================================
|
|
205
|
+
# Session-based API (new flow: hte-cli session join <session_id>)
|
|
206
|
+
# =========================================================================
|
|
207
|
+
|
|
208
|
+
def join_session(self, session_id: str) -> dict:
|
|
209
|
+
"""Join an existing session created by web UI.
|
|
210
|
+
|
|
211
|
+
Returns session info including task data, benchmark, mode, etc.
|
|
212
|
+
Sets cli_connected_at on the server.
|
|
213
|
+
"""
|
|
214
|
+
return self.post(f"/sessions/{session_id}/join")
|
|
215
|
+
|
|
216
|
+
def get_session_files(self, session_id: str) -> bytes:
|
|
217
|
+
"""Download task files for a session as zip."""
|
|
218
|
+
return self.get_raw(f"/sessions/{session_id}/files")
|
|
219
|
+
|
|
220
|
+
def get_session_compose(self, session_id: str) -> str:
|
|
221
|
+
"""Get compose.yaml content for a session."""
|
|
222
|
+
content = self.get_raw(f"/sessions/{session_id}/compose")
|
|
223
|
+
return content.decode("utf-8")
|
|
224
|
+
|
|
225
|
+
# =========================================================================
|
|
226
|
+
# Result Upload
|
|
227
|
+
# =========================================================================
|
|
228
|
+
|
|
204
229
|
def upload_result(
|
|
205
230
|
self,
|
|
206
231
|
session_id: str,
|
hte_cli/cli.py
CHANGED
|
@@ -147,13 +147,256 @@ def auth_status(ctx):
|
|
|
147
147
|
|
|
148
148
|
|
|
149
149
|
# =============================================================================
|
|
150
|
-
#
|
|
150
|
+
# Session Commands (New flow: session join <session_id>)
|
|
151
|
+
# =============================================================================
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
@cli.group()
|
|
155
|
+
def session():
|
|
156
|
+
"""Session management commands."""
|
|
157
|
+
pass
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
@session.command("join")
|
|
161
|
+
@click.argument("session_id")
|
|
162
|
+
@click.option("--force-setup", is_flag=True, help="Re-run setup even if reconnecting")
|
|
163
|
+
@click.pass_context
|
|
164
|
+
def session_join(ctx, session_id: str, force_setup: bool):
|
|
165
|
+
"""Join an existing session by ID.
|
|
166
|
+
|
|
167
|
+
This is the primary way to start working on a task:
|
|
168
|
+
1. Start the task from the web UI (creates session)
|
|
169
|
+
2. Run this command with the session ID shown in the web UI
|
|
170
|
+
3. The environment will be set up and the timer will start
|
|
171
|
+
"""
|
|
172
|
+
config: Config = ctx.obj["config"]
|
|
173
|
+
|
|
174
|
+
if not config.is_authenticated():
|
|
175
|
+
console.print("[red]Not logged in. Run: hte-cli auth login[/red]")
|
|
176
|
+
sys.exit(1)
|
|
177
|
+
|
|
178
|
+
api = APIClient(config)
|
|
179
|
+
|
|
180
|
+
# Step 1: Join session
|
|
181
|
+
console.print()
|
|
182
|
+
with Progress(
|
|
183
|
+
SpinnerColumn(),
|
|
184
|
+
TextColumn("[progress.description]{task.description}"),
|
|
185
|
+
console=console,
|
|
186
|
+
) as progress:
|
|
187
|
+
progress.add_task("Joining session...", total=None)
|
|
188
|
+
|
|
189
|
+
try:
|
|
190
|
+
session_info = api.join_session(session_id)
|
|
191
|
+
except APIError as e:
|
|
192
|
+
if "Invalid session ID format" in str(e):
|
|
193
|
+
console.print(f"[red]{e}[/red]")
|
|
194
|
+
elif e.status_code == 404:
|
|
195
|
+
console.print("[red]Session not found. Check the session ID and try again.[/red]")
|
|
196
|
+
elif e.status_code == 400 and "paused" in str(e).lower():
|
|
197
|
+
console.print("[yellow]Session is paused. Please resume from the web UI first.[/yellow]")
|
|
198
|
+
else:
|
|
199
|
+
console.print(f"[red]Error: {e}[/red]")
|
|
200
|
+
sys.exit(1)
|
|
201
|
+
|
|
202
|
+
# Check if reconnecting (session already in_progress)
|
|
203
|
+
is_reconnect = session_info.get("status") == "in_progress"
|
|
204
|
+
|
|
205
|
+
if is_reconnect and not force_setup:
|
|
206
|
+
console.print("[yellow]Reconnecting to existing session...[/yellow]")
|
|
207
|
+
console.print()
|
|
208
|
+
|
|
209
|
+
console.print(
|
|
210
|
+
Panel(
|
|
211
|
+
f"[bold]Task:[/bold] {session_info['task_id']}\n"
|
|
212
|
+
f"[bold]Benchmark:[/bold] {session_info['benchmark']}\n"
|
|
213
|
+
f"[bold]Mode:[/bold] {session_info['mode']}",
|
|
214
|
+
title="Session Joined",
|
|
215
|
+
)
|
|
216
|
+
)
|
|
217
|
+
console.print()
|
|
218
|
+
|
|
219
|
+
# Import runner components
|
|
220
|
+
import time
|
|
221
|
+
from hte_cli.events import EventStreamer
|
|
222
|
+
from hte_cli.runner import TaskRunner
|
|
223
|
+
from hte_cli.image_utils import extract_images_from_compose, pull_image_with_progress
|
|
224
|
+
|
|
225
|
+
# Create event streamer
|
|
226
|
+
events = EventStreamer(api, session_id)
|
|
227
|
+
|
|
228
|
+
# Step 2: Download task files and compose (skip if reconnecting without force)
|
|
229
|
+
files_zip = None
|
|
230
|
+
compose_yaml = None
|
|
231
|
+
|
|
232
|
+
if not is_reconnect or force_setup:
|
|
233
|
+
with Progress(
|
|
234
|
+
SpinnerColumn(),
|
|
235
|
+
TextColumn("[progress.description]{task.description}"),
|
|
236
|
+
console=console,
|
|
237
|
+
) as progress:
|
|
238
|
+
task_id_display = progress.add_task("Downloading task files...", total=None)
|
|
239
|
+
try:
|
|
240
|
+
files_zip = api.get_session_files(session_id)
|
|
241
|
+
except APIError as e:
|
|
242
|
+
# Files are optional for some benchmarks
|
|
243
|
+
console.print(f"[dim]Note: {e}[/dim]")
|
|
244
|
+
files_zip = None
|
|
245
|
+
|
|
246
|
+
progress.update(task_id_display, description="Downloading compose file...")
|
|
247
|
+
try:
|
|
248
|
+
compose_yaml = api.get_session_compose(session_id)
|
|
249
|
+
except APIError as e:
|
|
250
|
+
# Compose is optional for simple benchmarks
|
|
251
|
+
compose_yaml = None
|
|
252
|
+
|
|
253
|
+
# Validate compose for sandbox-required benchmarks
|
|
254
|
+
benchmark = session_info.get("benchmark", "").lower()
|
|
255
|
+
SANDBOX_REQUIRED_BENCHMARKS = {"cybench", "intercode-ctf", "cvebench", "cybergym", "nyuctf"}
|
|
256
|
+
if benchmark in SANDBOX_REQUIRED_BENCHMARKS and not compose_yaml and not is_reconnect:
|
|
257
|
+
console.print(
|
|
258
|
+
f"[red]Error: {benchmark} requires a Docker sandbox but no compose file was found.[/red]"
|
|
259
|
+
)
|
|
260
|
+
console.print()
|
|
261
|
+
console.print(
|
|
262
|
+
f"Please contact support: {SUPPORT_EMAIL}"
|
|
263
|
+
)
|
|
264
|
+
sys.exit(1)
|
|
265
|
+
|
|
266
|
+
# Build assignment dict for runner compatibility
|
|
267
|
+
assignment = {
|
|
268
|
+
"assignment_id": session_info.get("assignment_id"),
|
|
269
|
+
"session_id": session_id,
|
|
270
|
+
"task_id": session_info["task_id"],
|
|
271
|
+
"benchmark": session_info["benchmark"],
|
|
272
|
+
"mode": session_info["mode"],
|
|
273
|
+
"time_cap_seconds": session_info.get("time_cap_seconds"),
|
|
274
|
+
"task": {
|
|
275
|
+
"instructions": session_info.get("instructions", ""),
|
|
276
|
+
"metadata": session_info.get("metadata", {}),
|
|
277
|
+
"scorer_type": session_info.get("scorer_type"),
|
|
278
|
+
"intermediate_scoring": session_info.get("intermediate_scoring", False),
|
|
279
|
+
},
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
# Step 3: Run setup (skip if reconnecting without force)
|
|
283
|
+
setup_start_time = time.monotonic()
|
|
284
|
+
if not is_reconnect or force_setup:
|
|
285
|
+
# Send setup_started event
|
|
286
|
+
events.setup_started({"cli_version": __version__, "task_id": assignment["task_id"]})
|
|
287
|
+
|
|
288
|
+
# Pull images if we have compose
|
|
289
|
+
if compose_yaml:
|
|
290
|
+
images = extract_images_from_compose(compose_yaml)
|
|
291
|
+
if images:
|
|
292
|
+
console.print(f"[bold]Pulling {len(images)} Docker image(s)...[/bold]")
|
|
293
|
+
events.image_pull_started({})
|
|
294
|
+
for img in images:
|
|
295
|
+
short_name = img.split("/")[-1][:40]
|
|
296
|
+
with console.status(f"[yellow]↓[/yellow] {short_name}") as status:
|
|
297
|
+
success = pull_image_with_progress(img)
|
|
298
|
+
if success:
|
|
299
|
+
console.print(f" [green]✓[/green] {short_name}")
|
|
300
|
+
else:
|
|
301
|
+
console.print(f" [red]✗[/red] {short_name} (failed)")
|
|
302
|
+
events.image_pull_completed({})
|
|
303
|
+
console.print()
|
|
304
|
+
|
|
305
|
+
# Send setup_completed - THIS STARTS THE TIMER ON SERVER
|
|
306
|
+
total_setup = time.monotonic() - setup_start_time
|
|
307
|
+
events.setup_completed(total_seconds=total_setup)
|
|
308
|
+
console.print("[green]Environment ready! Timer started.[/green]")
|
|
309
|
+
console.print()
|
|
310
|
+
else:
|
|
311
|
+
# Reconnecting - compose should already be running
|
|
312
|
+
console.print("[dim]Skipping setup (use --force-setup to re-run)[/dim]")
|
|
313
|
+
console.print()
|
|
314
|
+
|
|
315
|
+
# Step 4: Show instructions
|
|
316
|
+
if session_info.get("instructions"):
|
|
317
|
+
console.print(Panel(session_info["instructions"], title="Task Instructions"))
|
|
318
|
+
console.print()
|
|
319
|
+
|
|
320
|
+
# Step 5: Run the task using TaskRunner
|
|
321
|
+
console.print("[bold]Starting task environment...[/bold]")
|
|
322
|
+
console.print("[dim]Launching Docker containers...[/dim]")
|
|
323
|
+
console.print()
|
|
324
|
+
|
|
325
|
+
events.docker_started()
|
|
326
|
+
|
|
327
|
+
runner = TaskRunner()
|
|
328
|
+
eval_log_bytes = None
|
|
329
|
+
try:
|
|
330
|
+
result = runner.run_from_assignment(
|
|
331
|
+
assignment=assignment,
|
|
332
|
+
compose_yaml=compose_yaml,
|
|
333
|
+
files_zip=files_zip,
|
|
334
|
+
)
|
|
335
|
+
# Read eval log before cleanup
|
|
336
|
+
if result.eval_log_path and result.eval_log_path.exists():
|
|
337
|
+
eval_log_bytes = result.eval_log_path.read_bytes()
|
|
338
|
+
except KeyboardInterrupt:
|
|
339
|
+
events.docker_stopped(exit_code=130)
|
|
340
|
+
console.print()
|
|
341
|
+
console.print("[yellow]Interrupted. Session remains active - you can reconnect later.[/yellow]")
|
|
342
|
+
sys.exit(0)
|
|
343
|
+
except Exception as e:
|
|
344
|
+
events.docker_stopped(exit_code=1)
|
|
345
|
+
console.print(f"[red]Task execution failed: {e}[/red]")
|
|
346
|
+
sys.exit(1)
|
|
347
|
+
finally:
|
|
348
|
+
runner.cleanup()
|
|
349
|
+
|
|
350
|
+
events.docker_stopped(exit_code=0)
|
|
351
|
+
|
|
352
|
+
# Step 6: Upload result
|
|
353
|
+
if result and result.answer:
|
|
354
|
+
events.session_completed(
|
|
355
|
+
elapsed_seconds=result.time_seconds,
|
|
356
|
+
answer=result.answer,
|
|
357
|
+
)
|
|
358
|
+
|
|
359
|
+
console.print()
|
|
360
|
+
console.print("[green]Task completed![/green]")
|
|
361
|
+
console.print(f"Answer: {result.answer}")
|
|
362
|
+
console.print(f"Time: {result.time_seconds:.1f}s")
|
|
363
|
+
|
|
364
|
+
# Upload to server
|
|
365
|
+
with Progress(
|
|
366
|
+
SpinnerColumn(),
|
|
367
|
+
TextColumn("[progress.description]{task.description}"),
|
|
368
|
+
console=console,
|
|
369
|
+
) as progress:
|
|
370
|
+
progress.add_task("Uploading result...", total=None)
|
|
371
|
+
try:
|
|
372
|
+
upload_result = api.upload_result(
|
|
373
|
+
session_id=session_id,
|
|
374
|
+
answer=result.answer or "",
|
|
375
|
+
client_active_seconds=result.time_seconds,
|
|
376
|
+
eval_log_bytes=eval_log_bytes,
|
|
377
|
+
score=result.score,
|
|
378
|
+
score_binarized=result.score_binarized,
|
|
379
|
+
agent_id=result.agent_id,
|
|
380
|
+
)
|
|
381
|
+
except APIError as e:
|
|
382
|
+
console.print(f"[red]Failed to upload result: {e}[/red]")
|
|
383
|
+
sys.exit(1)
|
|
384
|
+
|
|
385
|
+
if upload_result.get("score") is not None:
|
|
386
|
+
console.print(f"Score: {upload_result['score']}")
|
|
387
|
+
|
|
388
|
+
console.print()
|
|
389
|
+
console.print("[green]Done! Return to the web UI to see your results.[/green]")
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
# =============================================================================
|
|
393
|
+
# Tasks Commands (DEPRECATED - use 'session join' instead)
|
|
151
394
|
# =============================================================================
|
|
152
395
|
|
|
153
396
|
|
|
154
397
|
@cli.group()
|
|
155
398
|
def tasks():
|
|
156
|
-
"""Task commands."""
|
|
399
|
+
"""Task commands (deprecated - use 'session join' instead)."""
|
|
157
400
|
pass
|
|
158
401
|
|
|
159
402
|
|
|
@@ -223,7 +466,23 @@ def tasks_list(ctx):
|
|
|
223
466
|
@click.argument("task_id", required=False)
|
|
224
467
|
@click.pass_context
|
|
225
468
|
def tasks_run(ctx, task_id: str | None):
|
|
226
|
-
"""Run a task
|
|
469
|
+
"""[DEPRECATED] Run a task - use 'session join' instead."""
|
|
470
|
+
console.print()
|
|
471
|
+
console.print("[red]This command is deprecated.[/red]")
|
|
472
|
+
console.print()
|
|
473
|
+
console.print("The new workflow is:")
|
|
474
|
+
console.print(" 1. Start the task from the web UI: https://cyber-task-horizons.com")
|
|
475
|
+
console.print(" 2. Run the command shown: [bold]hte-cli session join <session_id>[/bold]")
|
|
476
|
+
console.print()
|
|
477
|
+
console.print("This ensures accurate timing by starting the timer only when")
|
|
478
|
+
console.print("the environment is ready, not including Docker setup time.")
|
|
479
|
+
console.print()
|
|
480
|
+
sys.exit(1)
|
|
481
|
+
|
|
482
|
+
|
|
483
|
+
# Keep the old implementation as _tasks_run_legacy for testing if needed
|
|
484
|
+
def _tasks_run_legacy(ctx, task_id: str | None):
|
|
485
|
+
"""Legacy implementation of tasks run (for testing only)."""
|
|
227
486
|
config: Config = ctx.obj["config"]
|
|
228
487
|
|
|
229
488
|
if not config.is_authenticated():
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: hte-cli
|
|
3
|
-
Version: 0.1
|
|
3
|
+
Version: 0.2.1
|
|
4
4
|
Summary: Human Time-to-Completion Evaluation CLI
|
|
5
5
|
Project-URL: Homepage, https://github.com/sean-peters-au/lyptus-mono
|
|
6
6
|
Author: Lyptus Research
|
|
@@ -23,6 +23,10 @@ Requires-Dist: platformdirs>=4.0
|
|
|
23
23
|
Requires-Dist: pydantic>=2.0
|
|
24
24
|
Requires-Dist: pyyaml>=6.0
|
|
25
25
|
Requires-Dist: rich>=13.0
|
|
26
|
+
Provides-Extra: dev
|
|
27
|
+
Requires-Dist: pexpect>=4.8; extra == 'dev'
|
|
28
|
+
Requires-Dist: pytest>=7.0; extra == 'dev'
|
|
29
|
+
Requires-Dist: requests>=2.28; extra == 'dev'
|
|
26
30
|
Description-Content-Type: text/markdown
|
|
27
31
|
|
|
28
32
|
# hte-cli
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
hte_cli/__init__.py,sha256=fDGXp-r8bIoLtlQnn5xJ_CpwMhonvk9bGjZQsjA2mDI,914
|
|
2
2
|
hte_cli/__main__.py,sha256=63n0gNGfskidWDU0aAIF2N8lylVCLYKVIkrN9QiORoo,107
|
|
3
|
-
hte_cli/api_client.py,sha256=
|
|
4
|
-
hte_cli/cli.py,sha256=
|
|
3
|
+
hte_cli/api_client.py,sha256=m42kfFZS72Nu_VuDwxRsLNy4ziCcvgk7KNWBh9gwqy0,9257
|
|
4
|
+
hte_cli/cli.py,sha256=ppVNUPxQVen3R90UVkA33Cy35N7Un5sh42ml0dPz9nw,39368
|
|
5
5
|
hte_cli/config.py,sha256=42Xv__YMSeRLs2zhGukJkIXFKtnBtYCHnONfViGyt2g,3387
|
|
6
6
|
hte_cli/errors.py,sha256=1J5PpxcUKBu6XjigMMCPOq4Zc12tnv8LhAsiaVFWLQM,2762
|
|
7
7
|
hte_cli/events.py,sha256=Zn-mroqaLHNzdT4DFf8st1Qclglshihdc09dBfCN070,5522
|
|
@@ -9,7 +9,7 @@ hte_cli/image_utils.py,sha256=454yoZEI1duNYrZC8UjhfZzDRP4Nxdrf2TvnZ_54G1k,4439
|
|
|
9
9
|
hte_cli/runner.py,sha256=DhC8FMjHwfLR193iP4thLDRZrNssYA9KH1WYKU2JKeg,13535
|
|
10
10
|
hte_cli/scorers.py,sha256=sFoPJePRt-K191-Ga4cVmrldruJclYXTOLkU_C9nCDI,6025
|
|
11
11
|
hte_cli/version_check.py,sha256=WVZyGy2XfAghQYdd2N9-0Qfg-7pgp9gt4761-PnmacI,1708
|
|
12
|
-
hte_cli-0.1.
|
|
13
|
-
hte_cli-0.1.
|
|
14
|
-
hte_cli-0.1.
|
|
15
|
-
hte_cli-0.1.
|
|
12
|
+
hte_cli-0.2.1.dist-info/METADATA,sha256=r2fEYVYX0wHf-S2pD7ysYt-Ln8Js9wfulcl4RgTWob4,3767
|
|
13
|
+
hte_cli-0.2.1.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
14
|
+
hte_cli-0.2.1.dist-info/entry_points.txt,sha256=XbyEEi1H14DFAt0Kdl22e_IRVEGzimSzYSh5HlhKlFA,41
|
|
15
|
+
hte_cli-0.2.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|