Restore a previous iteration as the current skill.
(ctx, name, to_n, yes_flag)
| 2492 | ) |
| 2493 | @click.pass_context |
| 2494 | def skill_rollback(ctx, name, to_n, yes_flag): |
| 2495 | """Restore a previous iteration as the current skill.""" |
| 2496 | from openkb.skill.marketplace import regenerate_marketplace |
| 2497 | from openkb.skill.workspace import list_iterations, restore_iteration |
| 2498 | |
| 2499 | kb_dir = _find_kb_dir(ctx.obj.get("kb_dir_override")) |
| 2500 | if kb_dir is None: |
| 2501 | click.echo("No knowledge base found. Run `openkb init` first.", err=True) |
| 2502 | ctx.exit(1) |
| 2503 | |
| 2504 | err = _validate_skill_name(name) |
| 2505 | if err: |
| 2506 | click.echo(f"[ERROR] {err}", err=True) |
| 2507 | ctx.exit(1) |
| 2508 | |
| 2509 | iters = list_iterations(kb_dir, name) |
| 2510 | if not iters: |
| 2511 | click.echo( |
| 2512 | f"[ERROR] No iterations exist for '{name}'. Nothing to roll back.", |
| 2513 | err=True, |
| 2514 | ) |
| 2515 | ctx.exit(1) |
| 2516 | |
| 2517 | target_n = to_n if to_n is not None else int(iters[-1].name.split("-", 1)[1]) |
| 2518 | target_label = f"iteration-{target_n}" |
| 2519 | if not any(p.name == target_label for p in iters): |
| 2520 | click.echo( |
| 2521 | f"[ERROR] Iteration {target_n} not found for '{name}'. " |
| 2522 | f"Run `openkb skill history {name}` to see available iterations.", |
| 2523 | err=True, |
| 2524 | ) |
| 2525 | ctx.exit(1) |
| 2526 | |
| 2527 | from openkb.skill import skill_dir |
| 2528 | |
| 2529 | current = skill_dir(kb_dir, name) |
| 2530 | if current.exists(): |
| 2531 | prompt = f"This will overwrite output/skills/{name}/ with {target_label}. Continue?" |
| 2532 | if yes_flag: |
| 2533 | pass |
| 2534 | elif sys.stdin.isatty(): |
| 2535 | if not click.confirm(prompt, default=False): |
| 2536 | click.echo("Aborted.") |
| 2537 | ctx.exit(1) |
| 2538 | else: |
| 2539 | click.echo( |
| 2540 | f"[ERROR] output/skills/{name}/ exists. Pass -y to overwrite " |
| 2541 | f"in non-interactive contexts.", |
| 2542 | err=True, |
| 2543 | ) |
| 2544 | ctx.exit(1) |
| 2545 | |
| 2546 | try: |
| 2547 | restore_iteration(kb_dir, name, n=to_n) |
| 2548 | except FileNotFoundError as exc: |
| 2549 | click.echo(f"[ERROR] {exc}", err=True) |
| 2550 | ctx.exit(1) |
| 2551 |
nothing calls this directly
no test coverage detected