forked from ringhyacinth/Star-Office-UI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathset_state.py
More file actions
70 lines (59 loc) · 2.02 KB
/
set_state.py
File metadata and controls
70 lines (59 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python3
"""Update Star Office UI state (for testing or agent-driven sync).
For automatic state sync from OpenClaw: add a rule in your agent SOUL.md or AGENTS.md:
Before starting a task: run `python3 set_state.py writing "doing XYZ"`.
After finishing: run `python3 set_state.py idle "ready"`.
The office UI reads state from the same state.json this script writes.
"""
import json
import os
import sys
from datetime import datetime
STATE_FILE = os.environ.get(
"STAR_OFFICE_STATE_FILE",
os.path.join(os.path.dirname(os.path.abspath(__file__)), "state.json"),
)
VALID_STATES = [
"idle",
"writing",
"receiving",
"replying",
"researching",
"executing",
"syncing",
"error"
]
def load_state():
if os.path.exists(STATE_FILE):
with open(STATE_FILE, "r", encoding="utf-8") as f:
return json.load(f)
return {
"state": "idle",
"detail": "Idle...",
"progress": 0,
"updated_at": datetime.now().isoformat()
}
def save_state(state):
with open(STATE_FILE, "w", encoding="utf-8") as f:
json.dump(state, f, ensure_ascii=False, indent=2)
if __name__ == "__main__":
if len(sys.argv) < 2:
print("Usage: python set_state.py <state> [detail]")
print(f"State options: {', '.join(VALID_STATES)}")
print("\nExamples:")
print(" python set_state.py idle")
print(" python set_state.py researching \"Researching Godot MCP...\"")
print(" python set_state.py writing \"Writing daily report template...\"")
sys.exit(1)
state_name = sys.argv[1]
detail = sys.argv[2] if len(sys.argv) > 2 else ""
if state_name not in VALID_STATES:
print(f"无效状态: {state_name}")
print(f"有效选项: {', '.join(VALID_STATES)}")
sys.exit(1)
state = load_state()
state["state"] = state_name
state["detail"] = detail
state["updated_at"] = datetime.now().isoformat()
save_state(state)
print(f"状态已更新: {state_name} - {detail}")