Zalohovani vsech podstatnych souboru
This commit is contained in:
83
skills/detach/scripts/create-task.py
Executable file
83
skills/detach/scripts/create-task.py
Executable file
@@ -0,0 +1,83 @@
|
||||
#!/usr/bin/env -S uv run --script
|
||||
# /// script
|
||||
# requires-python = ">=3.11"
|
||||
# dependencies = []
|
||||
# ///
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import sys
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).parent))
|
||||
from tasks_common import (
|
||||
TASKS,
|
||||
build_task_content,
|
||||
build_task_filename,
|
||||
load_preset_names,
|
||||
log,
|
||||
resolve_preset,
|
||||
)
|
||||
|
||||
|
||||
def ensure_queue_dirs() -> None:
|
||||
for name in ("new", "inbox", "running", "done", "failed"):
|
||||
(TASKS / name).mkdir(parents=True, exist_ok=True)
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser(description="Create a detach task and drop it in inbox/")
|
||||
parser.add_argument("--goal", required=True, help="Self-contained goal restatement")
|
||||
parser.add_argument("--slug", required=True, help="Short kebab-case identifier")
|
||||
parser.add_argument("--channel", required=True, help="Channel name (e.g. telegram, websocket)")
|
||||
parser.add_argument("--chat-id", required=True, dest="chat_id", help="Chat ID string")
|
||||
parser.add_argument("--constraint", action="append", default=[], dest="constraints",
|
||||
help="Extra constraint bullet (repeatable)")
|
||||
parser.add_argument("--model", default=None,
|
||||
help="Model preset to run the task on (fuzzy-matched against config.json); "
|
||||
"omit to use the agent default")
|
||||
args = parser.parse_args()
|
||||
|
||||
model = None
|
||||
if args.model:
|
||||
try:
|
||||
model = resolve_preset(args.model, load_preset_names())
|
||||
except KeyError as e:
|
||||
print(e.args[0], file=sys.stderr)
|
||||
return 1
|
||||
|
||||
ensure_queue_dirs()
|
||||
|
||||
now = datetime.now().astimezone()
|
||||
timestamp_str = now.strftime("%Y-%m-%d_%H_%M_%S_%f")
|
||||
created_iso = now.isoformat()
|
||||
|
||||
filename = build_task_filename(timestamp_str, args.slug)
|
||||
content = build_task_content(
|
||||
created_iso=created_iso,
|
||||
channel=args.channel,
|
||||
chat_id=args.chat_id,
|
||||
slug=args.slug,
|
||||
goal=args.goal,
|
||||
constraints=args.constraints,
|
||||
model=model,
|
||||
)
|
||||
|
||||
tmp_path = TASKS / "new" / filename
|
||||
inbox_path = TASKS / "inbox" / filename
|
||||
|
||||
try:
|
||||
tmp_path.write_text(content)
|
||||
os.replace(tmp_path, inbox_path)
|
||||
log(f"CREATE {filename} slug={args.slug}")
|
||||
except Exception as e:
|
||||
print(f"Error writing task: {e}", file=sys.stderr)
|
||||
return 1
|
||||
|
||||
print(args.slug)
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Reference in New Issue
Block a user