claude unstested update for moving from wp to project -> wp to task

This commit is contained in:
buenosairesam
2025-10-03 04:47:13 -03:00
parent 72f9e9d9a7
commit 71752c7d76
10 changed files with 237 additions and 146 deletions

View File

@@ -7,10 +7,11 @@ def save(
task: str | None = None,
workspace: str | None = None,
filetime: str | None = None,
config_mtime: float | None = None,
) -> None:
"""
Upsert a document with _id=doc_id, setting any of the provided fields.
Leave fields you dont pass unchanged.
Leave fields you don't pass unchanged.
"""
updates: dict = {}
if task is not None:
@@ -19,6 +20,8 @@ def save(
updates["workspace"] = workspace
if filetime is not None:
updates["filetime"] = filetime
if config_mtime is not None:
updates["config_mtime"] = config_mtime
if updates:
states.update_one(
@@ -30,40 +33,36 @@ def save(
def retrieve(doc_id: str) -> dict[str, str | None]:
"""
Fetches the document with _id=doc_id and returns its 'task' and 'workspace'.
If the document doesnt exist, both will be None.
Fetches the document with _id=doc_id and returns its fields.
If the document doesn't exist, all fields will be None.
"""
doc = states.find_one({"_id": doc_id})
return {
"task": doc.get("task") if doc else None,
"workspace": doc.get("workspace") if doc else None,
"filetime": doc.get("filetime") if doc else None,
"config_mtime": doc.get("config_mtime") if doc else None,
}
# just
def update_work_state(work: str, task_id: str):
def sync_desktop_tasks(work_desktop_tasks: dict):
"""
update work state
Sync work_desktop_tasks from config file to state
"""
states.update_one({"_id": "work"}, {"$set": {work: task_id}})
update_dict = {str(k): v for k, v in work_desktop_tasks.items()}
states.update_one(
{"_id": "work_desktop_tasks"},
{"$set": update_dict},
upsert=True,
)
def init_work_state(wd: dict):
def retrieve_desktop_state():
"""
init work states with default values
Get work_desktop_tasks mapping from state
"""
if not states.find_one({"_id": "work"}):
states.insert_one(
{
"_id": "work",
**{
wd[k]: tasks.find_one({"path": f"work/{wd[k]}"})["task_id"]
for k in wd
},
}
)
def retrieve_work_state():
return states.find_one({"_id": "work"})
doc = states.find_one({"_id": "work_desktop_tasks"})
if not doc:
return {}
# Convert string keys to int and exclude _id
return {int(k): v for k, v in doc.items() if k != "_id"}