@jxtools/promptline 1.3.8 → 1.3.9
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.
- package/package.json +1 -1
- package/promptline-session-end.sh +29 -7
package/package.json
CHANGED
|
@@ -32,10 +32,11 @@ else
|
|
|
32
32
|
exit 0
|
|
33
33
|
fi
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
QUEUE_DIR="$(dirname "$QUEUE_FILE")"
|
|
36
|
+
export QUEUE_FILE QUEUE_DIR SESSION_ID
|
|
36
37
|
|
|
37
38
|
python3 << 'PYEOF'
|
|
38
|
-
import json, os, tempfile
|
|
39
|
+
import json, os, glob, tempfile
|
|
39
40
|
from datetime import datetime, timezone
|
|
40
41
|
|
|
41
42
|
def atomic_write(path, obj):
|
|
@@ -50,18 +51,39 @@ def atomic_write(path, obj):
|
|
|
50
51
|
except OSError: pass
|
|
51
52
|
raise
|
|
52
53
|
|
|
54
|
+
def close_session(path, now):
|
|
55
|
+
with open(path, "r") as f:
|
|
56
|
+
data = json.load(f)
|
|
57
|
+
data["closedAt"] = now
|
|
58
|
+
data["lastActivity"] = now
|
|
59
|
+
atomic_write(path, data)
|
|
60
|
+
|
|
53
61
|
queue_file = os.environ["QUEUE_FILE"]
|
|
62
|
+
queue_dir = os.environ["QUEUE_DIR"]
|
|
63
|
+
session_id = os.environ["SESSION_ID"]
|
|
54
64
|
now = datetime.now(timezone.utc).isoformat()
|
|
55
65
|
|
|
56
66
|
try:
|
|
57
|
-
|
|
58
|
-
data = json.load(f)
|
|
59
|
-
data["closedAt"] = now
|
|
60
|
-
data["lastActivity"] = now
|
|
61
|
-
atomic_write(queue_file, data)
|
|
67
|
+
close_session(queue_file, now)
|
|
62
68
|
except (json.JSONDecodeError, IOError, OSError):
|
|
63
69
|
pass
|
|
64
70
|
|
|
71
|
+
# Close orphaned sessions in the same project
|
|
72
|
+
for path in glob.glob(os.path.join(queue_dir, "*.json")):
|
|
73
|
+
if os.path.basename(path) == f"{session_id}.json":
|
|
74
|
+
continue
|
|
75
|
+
try:
|
|
76
|
+
with open(path, "r") as f:
|
|
77
|
+
data = json.load(f)
|
|
78
|
+
if data.get("closedAt") is not None:
|
|
79
|
+
continue
|
|
80
|
+
has_pending = any(p.get("status") in ("pending", "running") for p in data.get("prompts", []))
|
|
81
|
+
if has_pending:
|
|
82
|
+
continue
|
|
83
|
+
close_session(path, now)
|
|
84
|
+
except (json.JSONDecodeError, IOError, OSError):
|
|
85
|
+
continue
|
|
86
|
+
|
|
65
87
|
PYEOF
|
|
66
88
|
|
|
67
89
|
exit 0
|