ring-cli 0.17.4__tar.gz → 0.17.5__tar.gz

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.
Files changed (70) hide show
  1. {ring_cli-0.17.4 → ring_cli-0.17.5}/PKG-INFO +1 -1
  2. {ring_cli-0.17.4 → ring_cli-0.17.5}/pyproject.toml +1 -1
  3. {ring_cli-0.17.4 → ring_cli-0.17.5}/pyproject.toml.orig +1 -1
  4. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/cli.py +4 -4
  5. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/gc.py +22 -7
  6. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/hook.py +12 -8
  7. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/ipc.py +26 -23
  8. ring_cli-0.17.5/src/ring/locale/en/LC_MESSAGES/ring.mo +0 -0
  9. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/locale/en/LC_MESSAGES/ring.po +6 -0
  10. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/locale/ring.pot +111 -101
  11. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/notify_queue.py +88 -17
  12. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/sources/__init__.py +50 -1
  13. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/tui.py +73 -29
  14. ring_cli-0.17.4/src/ring/locale/en/LC_MESSAGES/ring.mo +0 -0
  15. {ring_cli-0.17.4 → ring_cli-0.17.5}/LICENSE +0 -0
  16. {ring_cli-0.17.4 → ring_cli-0.17.5}/README.en.md +0 -0
  17. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/__init__.py +0 -0
  18. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/__main__.py +0 -0
  19. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/agent_notify.py +0 -0
  20. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/commands/__init__.py +0 -0
  21. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/commands/_args.py +0 -0
  22. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/commands/completion.py +0 -0
  23. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/commands/digest.py +0 -0
  24. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/commands/doctor.py +0 -0
  25. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/commands/focus.py +0 -0
  26. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/commands/gc.py +0 -0
  27. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/commands/hook.py +0 -0
  28. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/commands/quiet.py +0 -0
  29. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/commands/stats.py +0 -0
  30. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/config.py +0 -0
  31. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/focus/__init__.py +0 -0
  32. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/focus/applescript.py +0 -0
  33. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/focus/base.py +0 -0
  34. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/focus/iterm2.py +0 -0
  35. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/focus/kitty.py +0 -0
  36. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/focus/linux_wm.py +0 -0
  37. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/focus/neovim.py +0 -0
  38. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/focus/terminal.py +0 -0
  39. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/focus/tmux.py +0 -0
  40. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/focus/trace.py +0 -0
  41. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/hook_protocol.py +0 -0
  42. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/i18n.py +0 -0
  43. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/labels.py +0 -0
  44. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/notify/__init__.py +0 -0
  45. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/notify/base.py +0 -0
  46. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/notify/command.py +0 -0
  47. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/notify/notify_send.py +0 -0
  48. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/notify/ntfy.py +0 -0
  49. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/notify/osascript_notifier.py +0 -0
  50. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/notify/terminal_notifier.py +0 -0
  51. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/notify/webhook.py +0 -0
  52. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/osascript.py +0 -0
  53. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/pathutil.py +0 -0
  54. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/payload_log.py +0 -0
  55. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/permission.py +0 -0
  56. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/plugins.py +0 -0
  57. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/ps_parse.py +0 -0
  58. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/question_detect.py +0 -0
  59. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/registry.py +0 -0
  60. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/sources/base.py +0 -0
  61. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/sources/claude_code.py +0 -0
  62. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/sources/codex.py +0 -0
  63. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/sources/hook_registry.py +0 -0
  64. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/sources/local_llm.py +0 -0
  65. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/stats.py +0 -0
  66. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/subproc.py +0 -0
  67. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/tmux_scan.py +0 -0
  68. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/transcript.py +0 -0
  69. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/waiting.py +0 -0
  70. {ring_cli-0.17.4 → ring_cli-0.17.5}/src/ring/watcher.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ring-cli
3
- Version: 0.17.4
3
+ Version: 0.17.5
4
4
  Summary: RiNG — Realtime Instance Notification Grid for active agent CLI sessions.
5
5
  Keywords: claude-code,codex,ollama,llama-cpp,tui,dashboard,session,monitor,rich
6
6
  Author: Wei Lee
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "ring-cli"
3
- version = "0.17.4"
3
+ version = "0.17.5"
4
4
  description = "RiNG — Realtime Instance Notification Grid for active agent CLI sessions."
5
5
  readme = "README.en.md"
6
6
  requires-python = ">=3.13"
@@ -2,7 +2,7 @@
2
2
  # import 的 module(見 [tool.uv.build-backend] module-name)與 CLI 指令仍是 `ring`。
3
3
  [project]
4
4
  name = "ring-cli"
5
- version = "0.17.4"
5
+ version = "0.17.5"
6
6
  description = "RiNG — Realtime Instance Notification Grid for active agent CLI sessions."
7
7
  readme = "README.en.md"
8
8
  requires-python = ">=3.13"
@@ -407,7 +407,7 @@ def run_config(args: list[str]) -> int:
407
407
  return 2
408
408
 
409
409
 
410
- def _watch_flush_if_due() -> None:
410
+ def _watch_flush_if_due(sessions: list[Session]) -> None:
411
411
  """headless watch 輪詢時的懶惰 flush 觸發點(同 hook.py / tui.py 既有呼叫慣例)。
412
412
 
413
413
  quiet active 或仍在 debounce 視窗內時,``flush_if_due`` 內部本來就會 skip(跟
@@ -415,7 +415,7 @@ def _watch_flush_if_due() -> None:
415
415
  失敗安靜吞掉,不影響看板本身。
416
416
  """
417
417
  with contextlib.suppress(Exception):
418
- flush_if_due()
418
+ flush_if_due(current_sessions=sessions)
419
419
 
420
420
 
421
421
  def watch(interval: float, count: int, show_all: bool, show_legend: bool) -> int:
@@ -430,9 +430,9 @@ def watch(interval: float, count: int, show_all: bool, show_legend: bool) -> int
430
430
  if not HAVE_RICH:
431
431
  try:
432
432
  while True:
433
- _watch_flush_if_due()
434
433
  sys.stdout.write("\033[2J\033[H")
435
434
  sessions = board(show_all)
435
+ _watch_flush_if_due(sessions)
436
436
  print(_render_plain(sessions, show_legend, show_tool_column(sessions)))
437
437
  print(f"\n{footer_text}")
438
438
  sys.stdout.flush()
@@ -447,8 +447,8 @@ def watch(interval: float, count: int, show_all: bool, show_legend: bool) -> int
447
447
  try:
448
448
  with Live(console=console, screen=True, auto_refresh=False) as live:
449
449
  while True:
450
- _watch_flush_if_due()
451
450
  sessions = board(show_all)
451
+ _watch_flush_if_due(sessions)
452
452
  body = _rich_renderable(sessions, show_legend, show_tool_column(sessions))
453
453
  live.update(Group(body, Text(f"\n{footer_text}", style=_MUTED)), refresh=True)
454
454
  frames += 1
@@ -11,7 +11,7 @@ import time
11
11
  from dataclasses import dataclass, field
12
12
  from pathlib import Path
13
13
 
14
- from ring.ipc import _FOCUS_REQUEST_PATH, _PRESENCE_PATH, _PRESENCE_TTL, _REQUEST_TTL
14
+ from ring.ipc import _FOCUS_REQUEST_PATH, _PRESENCE_PATH, _PRESENCE_TTL, _REQUEST_TTL, _focus_request_lock
15
15
  from ring.registry import (
16
16
  _SESSION_START_SOURCES,
17
17
  RING_REGISTRY,
@@ -81,7 +81,9 @@ def run_gc(
81
81
  # 隱藏清單本來就空時,不必為了「找不到就清」去掃全部 source(省掉一輪 process/檔案掃描)。
82
82
  known_ids = _known_session_ids() if hidden_now else set()
83
83
  hidden_stale_preview = {
84
- sid: hidden_at for sid, hidden_at in hidden_now.items() if sid not in known_ids or now - hidden_at >= older_than
84
+ sid: hidden_at
85
+ for sid, hidden_at in hidden_now.items()
86
+ if (known_ids is not None and sid not in known_ids) or now - hidden_at >= older_than
85
87
  }
86
88
 
87
89
  if dry_run:
@@ -98,8 +100,8 @@ def run_gc(
98
100
  errors: list[tuple[GcCandidate, str]] = []
99
101
  for candidate in candidates:
100
102
  try:
101
- candidate.path.unlink(missing_ok=True)
102
- deleted.append(candidate)
103
+ if _delete_candidate(candidate, now=now):
104
+ deleted.append(candidate)
103
105
  except OSError as e:
104
106
  errors.append((candidate, str(e)))
105
107
 
@@ -114,19 +116,32 @@ def run_gc(
114
116
  )
115
117
 
116
118
 
117
- def _known_session_ids() -> set[str]:
119
+ def _delete_candidate(candidate: GcCandidate, *, now: float) -> bool:
120
+ if candidate.path == _FOCUS_REQUEST_PATH:
121
+ # GC 也會刪 request:不能在盤點過期檔後,把 writer 剛送來的新 request 一起刪掉。
122
+ with _focus_request_lock(candidate.path):
123
+ if not _stale_json_file(candidate.path, ttl=_REQUEST_TTL, now=now, label="focus-request"):
124
+ return False
125
+ candidate.path.unlink(missing_ok=True)
126
+ return True
127
+ candidate.path.unlink(missing_ok=True)
128
+ return True
129
+
130
+
131
+ def _known_session_ids() -> set[str] | None:
118
132
  """目前任何已註冊來源(不管有沒有被手動隱藏)找得到的 session id。
119
133
 
120
134
  只用來判斷隱藏清單裡的條目是不是「哪裡都找不到了」;不碰、不引用
121
135
  ``discover_sessions()`` 的 merge / tmux 配對邏輯。
122
136
  """
137
+ from ring.sources import discover_source_sessions, source_errors
123
138
  from ring.sources import sources as _registered_sources
124
139
 
125
140
  ids: set[str] = set()
126
141
  for source in _registered_sources():
127
- for s in source.discover():
142
+ for s in discover_source_sessions(source):
128
143
  ids.add(s.session_id)
129
- return ids
144
+ return None if source_errors() else ids
130
145
 
131
146
 
132
147
  def _registry_candidates(*, older_than: float, all_ended: bool, now: float) -> list[GcCandidate]:
@@ -168,17 +168,10 @@ def run_hook(provider: str = "claude-code") -> int:
168
168
  收按鈕、把決策寫到 stdout 回給 Claude(這條路下 ``_ring_waiting_now`` 自動短路、不重複發)。
169
169
  其餘情況 RiNG 記狀態 + 發通知後 exit 0(你在終端自己回答)。
170
170
 
171
- 每次執行開頭先嘗試懶惰 flush 合流 queue(見 ``notify_queue.flush_if_due``)——沒有常駐
171
+ 更新 registry 後嘗試懶惰 flush 合流 queue(見 ``notify_queue.flush_if_due``)——沒有常駐
172
172
  daemon,任何 hook 事件(不限於這次自己是不是 waiting 事件)都是「debounce 視窗過期」的
173
173
  天然觸發點,讓 headless(沒開 TUI)也能補發彙總通知。失敗安靜吞掉,不影響本次事件記錄。
174
174
  """
175
- try:
176
- from ring.notify_queue import flush_if_due
177
-
178
- flush_if_due()
179
- except Exception:
180
- pass
181
-
182
175
  try:
183
176
  raw = sys.stdin.read()
184
177
  except OSError:
@@ -227,6 +220,12 @@ def _record_session_state(data: dict[str, Any], selected_provider: str) -> None:
227
220
  notification = _update_session_state(path, event, data, adapter.process_names)
228
221
  except OSError:
229
222
  return
223
+ try:
224
+ from ring.notify_queue import flush_if_due
225
+
226
+ flush_if_due()
227
+ except Exception:
228
+ pass
230
229
  # 系統通知可能等待外部程序,不可持鎖阻擋後續解除等待的 hook。
231
230
  if notification is not None:
232
231
  _ring_waiting_now(*notification)
@@ -559,6 +558,11 @@ def _ring_waiting_now(event: Any, payload: dict[str, Any], last_action: str) ->
559
558
  provider=event.provider,
560
559
  waiting_kind=str(payload.get("waiting_kind", "")),
561
560
  waiting_detail=str(payload.get("waiting_detail", "")),
561
+ waiting_requests=tuple(
562
+ request
563
+ for owner, request in read_waiting_requests(payload).items()
564
+ if owner == payload.get("last_event_owner", FOREGROUND_OWNER)
565
+ ),
562
566
  origin_cwd=event.cwd,
563
567
  )
564
568
  ]
@@ -16,10 +16,12 @@
16
16
  from __future__ import annotations
17
17
 
18
18
  import contextlib
19
+ import fcntl
19
20
  import json
20
21
  import os
21
22
  import sys
22
23
  import time
24
+ from collections.abc import Iterator
23
25
  from pathlib import Path
24
26
  from typing import TypedDict
25
27
 
@@ -53,6 +55,18 @@ class _TuiPresence(TypedDict):
53
55
  # --------------------------------------------------------------------------- focus-request 相關
54
56
 
55
57
 
58
+ @contextlib.contextmanager
59
+ def _focus_request_lock(path: Path) -> Iterator[None]:
60
+ path.parent.mkdir(parents=True, exist_ok=True)
61
+ # 鎖檔獨立於會被消費/替換的 request inode,reader 與 writer 才會鎖到同一把鎖。
62
+ with path.with_name(path.name + ".lock").open("a", encoding="utf-8") as handle:
63
+ fcntl.flock(handle, fcntl.LOCK_EX)
64
+ try:
65
+ yield
66
+ finally:
67
+ fcntl.flock(handle, fcntl.LOCK_UN)
68
+
69
+
56
70
  def write_focus_request(session_id: str, *, request_path: Path | None = None) -> None:
57
71
  """把 focus-request 寫入磁碟,供 TUI poll 讀取。
58
72
 
@@ -62,8 +76,10 @@ def write_focus_request(session_id: str, *, request_path: Path | None = None) ->
62
76
  path = request_path or _FOCUS_REQUEST_PATH
63
77
  payload: _FocusRequest = {"session_id": session_id, "ts": time.time()}
64
78
  try:
65
- path.parent.mkdir(parents=True, exist_ok=True)
66
- path.write_text(json.dumps(payload), encoding="utf-8")
79
+ with _focus_request_lock(path):
80
+ tmp = path.with_name(path.name + ".tmp")
81
+ tmp.write_text(json.dumps(payload), encoding="utf-8")
82
+ tmp.replace(path)
67
83
  except Exception:
68
84
  pass
69
85
 
@@ -86,29 +102,16 @@ def read_focus_request(
86
102
  """
87
103
  path = request_path or _FOCUS_REQUEST_PATH
88
104
  try:
89
- raw = path.read_text(encoding="utf-8")
90
- except Exception:
91
- return None
92
-
93
- try:
94
- data: _FocusRequest = json.loads(raw)
95
- session_id = str(data["session_id"])
96
- ts = float(data["ts"])
97
- except Exception:
98
- # 解析失敗:刪掉爛檔
99
- with contextlib.suppress(Exception):
105
+ with _focus_request_lock(path):
106
+ raw = path.read_text(encoding="utf-8")
107
+ # 讀取與消費在同一臨界區,後來的 writer 不會被這次 unlink 刪掉。
100
108
  path.unlink()
109
+ data: _FocusRequest = json.loads(raw)
110
+ session_id = str(data["session_id"])
111
+ ts = float(data["ts"])
112
+ except Exception:
101
113
  return None
102
-
103
- age = time.time() - ts
104
- # 不論有效或過期,都刪掉(消費即焚;過期的也不留)
105
- with contextlib.suppress(Exception):
106
- path.unlink()
107
-
108
- if age > ttl:
109
- return None
110
-
111
- return session_id
114
+ return session_id if time.time() - ts <= ttl else None
112
115
 
113
116
 
114
117
  # --------------------------------------------------------------------------- tui-presence 相關
@@ -845,3 +845,9 @@ msgstr "to keep only RiNG"
845
845
 
846
846
  msgid "把 preferredNotifChannel 設成 notifications_disabled"
847
847
  msgstr "set preferredNotifChannel to notifications_disabled"
848
+
849
+ msgid "⚠️ session 來源 '{name}' 讀取失敗,保留上次資料:{error}"
850
+ msgstr "⚠️ session source '{name}' failed; keeping the last snapshot: {error}"
851
+
852
+ msgid "看板刷新失敗,保留上次資料:{error}"
853
+ msgstr "Dashboard refresh failed; keeping the last snapshot: {error}"