openreflex 0.5.0__tar.gz → 0.5.2__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.
- {openreflex-0.5.0/src/openreflex.egg-info → openreflex-0.5.2}/PKG-INFO +1 -1
- {openreflex-0.5.0 → openreflex-0.5.2}/pyproject.toml +1 -1
- {openreflex-0.5.0 → openreflex-0.5.2}/src/openreflex/__init__.py +1 -1
- {openreflex-0.5.0 → openreflex-0.5.2}/src/openreflex/cli.py +4 -1
- {openreflex-0.5.0 → openreflex-0.5.2}/src/openreflex/engine.py +1 -2
- {openreflex-0.5.0 → openreflex-0.5.2}/src/openreflex/entrypoint.py +8 -0
- {openreflex-0.5.0 → openreflex-0.5.2}/src/openreflex/hooks.py +6 -3
- {openreflex-0.5.0 → openreflex-0.5.2}/src/openreflex/project_memory.py +3 -1
- {openreflex-0.5.0 → openreflex-0.5.2}/src/openreflex/usage.py +41 -5
- {openreflex-0.5.0 → openreflex-0.5.2/src/openreflex.egg-info}/PKG-INFO +1 -1
- {openreflex-0.5.0 → openreflex-0.5.2}/src/openreflex.egg-info/SOURCES.txt +2 -0
- {openreflex-0.5.0 → openreflex-0.5.2}/tests/test_project_memory.py +40 -1
- openreflex-0.5.2/tests/test_token_receiver.py +46 -0
- openreflex-0.5.2/tests/test_tokens_cli.py +16 -0
- {openreflex-0.5.0 → openreflex-0.5.2}/tests/test_tui_memory.py +14 -2
- {openreflex-0.5.0 → openreflex-0.5.2}/tests/test_work_modes_tokens.py +63 -0
- {openreflex-0.5.0 → openreflex-0.5.2}/LICENSE +0 -0
- {openreflex-0.5.0 → openreflex-0.5.2}/README.md +0 -0
- {openreflex-0.5.0 → openreflex-0.5.2}/setup.cfg +0 -0
- {openreflex-0.5.0 → openreflex-0.5.2}/src/openreflex/__main__.py +0 -0
- {openreflex-0.5.0 → openreflex-0.5.2}/src/openreflex/benchmark.py +0 -0
- {openreflex-0.5.0 → openreflex-0.5.2}/src/openreflex/claude_ui.py +0 -0
- {openreflex-0.5.0 → openreflex-0.5.2}/src/openreflex/control.py +0 -0
- {openreflex-0.5.0 → openreflex-0.5.2}/src/openreflex/decision.py +0 -0
- {openreflex-0.5.0 → openreflex-0.5.2}/src/openreflex/detect.py +0 -0
- {openreflex-0.5.0 → openreflex-0.5.2}/src/openreflex/execution_state.py +0 -0
- {openreflex-0.5.0 → openreflex-0.5.2}/src/openreflex/install.py +0 -0
- {openreflex-0.5.0 → openreflex-0.5.2}/src/openreflex/integrations/opencode.ts +0 -0
- {openreflex-0.5.0 → openreflex-0.5.2}/src/openreflex/learning.py +0 -0
- {openreflex-0.5.0 → openreflex-0.5.2}/src/openreflex/mcp_contracts.py +0 -0
- {openreflex-0.5.0 → openreflex-0.5.2}/src/openreflex/mcp_server.py +0 -0
- {openreflex-0.5.0 → openreflex-0.5.2}/src/openreflex/metrics.py +0 -0
- {openreflex-0.5.0 → openreflex-0.5.2}/src/openreflex/models.py +0 -0
- {openreflex-0.5.0 → openreflex-0.5.2}/src/openreflex/policies/default.toml +0 -0
- {openreflex-0.5.0 → openreflex-0.5.2}/src/openreflex/policy.py +0 -0
- {openreflex-0.5.0 → openreflex-0.5.2}/src/openreflex/privacy.py +0 -0
- {openreflex-0.5.0 → openreflex-0.5.2}/src/openreflex/project.py +0 -0
- {openreflex-0.5.0 → openreflex-0.5.2}/src/openreflex/project_map.py +0 -0
- {openreflex-0.5.0 → openreflex-0.5.2}/src/openreflex/reflex_index.py +0 -0
- {openreflex-0.5.0 → openreflex-0.5.2}/src/openreflex/routing.py +0 -0
- {openreflex-0.5.0 → openreflex-0.5.2}/src/openreflex/store.py +0 -0
- {openreflex-0.5.0 → openreflex-0.5.2}/src/openreflex/tui.py +0 -0
- {openreflex-0.5.0 → openreflex-0.5.2}/src/openreflex/updater.py +0 -0
- {openreflex-0.5.0 → openreflex-0.5.2}/src/openreflex.egg-info/dependency_links.txt +0 -0
- {openreflex-0.5.0 → openreflex-0.5.2}/src/openreflex.egg-info/entry_points.txt +0 -0
- {openreflex-0.5.0 → openreflex-0.5.2}/src/openreflex.egg-info/requires.txt +0 -0
- {openreflex-0.5.0 → openreflex-0.5.2}/src/openreflex.egg-info/top_level.txt +0 -0
- {openreflex-0.5.0 → openreflex-0.5.2}/tests/test_completion_recap_semantics.py +0 -0
- {openreflex-0.5.0 → openreflex-0.5.2}/tests/test_engine.py +0 -0
- {openreflex-0.5.0 → openreflex-0.5.2}/tests/test_execution_state.py +0 -0
- {openreflex-0.5.0 → openreflex-0.5.2}/tests/test_hooks.py +0 -0
- {openreflex-0.5.0 → openreflex-0.5.2}/tests/test_install_cli.py +0 -0
- {openreflex-0.5.0 → openreflex-0.5.2}/tests/test_mcp_metrics_benchmark.py +0 -0
- {openreflex-0.5.0 → openreflex-0.5.2}/tests/test_outcome_closure.py +0 -0
- {openreflex-0.5.0 → openreflex-0.5.2}/tests/test_policy_recap.py +0 -0
- {openreflex-0.5.0 → openreflex-0.5.2}/tests/test_primer_background.py +0 -0
- {openreflex-0.5.0 → openreflex-0.5.2}/tests/test_project_map.py +0 -0
- {openreflex-0.5.0 → openreflex-0.5.2}/tests/test_project_scope.py +0 -0
- {openreflex-0.5.0 → openreflex-0.5.2}/tests/test_quality_hardening.py +0 -0
- {openreflex-0.5.0 → openreflex-0.5.2}/tests/test_reflex_index.py +0 -0
- {openreflex-0.5.0 → openreflex-0.5.2}/tests/test_release_consistency.py +0 -0
- {openreflex-0.5.0 → openreflex-0.5.2}/tests/test_reliability_lifecycle.py +0 -0
- {openreflex-0.5.0 → openreflex-0.5.2}/tests/test_routing_control.py +0 -0
- {openreflex-0.5.0 → openreflex-0.5.2}/tests/test_stress.py +0 -0
- {openreflex-0.5.0 → openreflex-0.5.2}/tests/test_update_cli.py +0 -0
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "openreflex"
|
|
7
|
-
version = "0.5.
|
|
7
|
+
version = "0.5.2"
|
|
8
8
|
description = "Muscle memory for AI coding agents: learns from every task, advises the next one, and flags failure loops live"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = "MIT"
|
|
@@ -395,7 +395,10 @@ def cmd_benchmark(args) -> int:
|
|
|
395
395
|
|
|
396
396
|
|
|
397
397
|
def build_parser() -> argparse.ArgumentParser:
|
|
398
|
-
parser = argparse.ArgumentParser(
|
|
398
|
+
parser = argparse.ArgumentParser(
|
|
399
|
+
prog="openreflex", description="Ambient execution intelligence for coding agents.",
|
|
400
|
+
epilog="Also available: tui, memory, tokens, statusline (run `openreflex <name> --help` for details).",
|
|
401
|
+
)
|
|
399
402
|
parser.add_argument("--version", action="version", version=__version__)
|
|
400
403
|
sub = parser.add_subparsers(dest="command", required=True)
|
|
401
404
|
|
|
@@ -48,8 +48,7 @@ class Engine:
|
|
|
48
48
|
if current is not None and not is_substantial(prompt):
|
|
49
49
|
self._reopen(current)
|
|
50
50
|
return None
|
|
51
|
-
if current is not None and current.waiting_for_future_work
|
|
52
|
-
self._task(current).description == redact(prompt, 1000):
|
|
51
|
+
if current is not None and current.waiting_for_future_work:
|
|
53
52
|
current.waiting_for_future_work = False
|
|
54
53
|
current.last_progress_at = now
|
|
55
54
|
self.store.put(current)
|
|
@@ -372,6 +372,12 @@ def _tokens(argv: list[str]) -> int:
|
|
|
372
372
|
from .usage import configured, disable, enable, receiver_running, serve
|
|
373
373
|
|
|
374
374
|
action = argv[0] if argv else "status"
|
|
375
|
+
if action in {"-h", "--help"}:
|
|
376
|
+
print("usage: openreflex tokens {enable,disable,status}\n")
|
|
377
|
+
print(" enable Turn on local Claude Code token accounting (loopback receiver)")
|
|
378
|
+
print(" disable Turn off token accounting and stop the receiver")
|
|
379
|
+
print(" status Show whether tracking is configured and whether the receiver is running")
|
|
380
|
+
return 0
|
|
375
381
|
if action == "serve":
|
|
376
382
|
serve()
|
|
377
383
|
return 0
|
|
@@ -402,6 +408,7 @@ def _tokens(argv: list[str]) -> int:
|
|
|
402
408
|
print(" content prompts/responses/thinking/tool arguments are not collected")
|
|
403
409
|
return 0
|
|
404
410
|
print(f"Unknown tokens action: {action}")
|
|
411
|
+
print("usage: openreflex tokens {enable,disable,status}")
|
|
405
412
|
return 2
|
|
406
413
|
|
|
407
414
|
|
|
@@ -425,6 +432,7 @@ def _augment_uninstall(argv: list[str], result: int) -> None:
|
|
|
425
432
|
|
|
426
433
|
|
|
427
434
|
def main(argv: list[str] | None = None) -> int:
|
|
435
|
+
cli._utf8_stdio()
|
|
428
436
|
argv = sys.argv[1:] if argv is None else argv
|
|
429
437
|
if not argv:
|
|
430
438
|
return _tui([])
|
|
@@ -20,7 +20,7 @@ import time
|
|
|
20
20
|
import traceback
|
|
21
21
|
from dataclasses import dataclass, field
|
|
22
22
|
|
|
23
|
-
from .engine import Engine
|
|
23
|
+
from .engine import Engine, is_substantial
|
|
24
24
|
from .privacy import categorize
|
|
25
25
|
from .project import approval, log_error, project_root, should_notify_unapproved
|
|
26
26
|
|
|
@@ -40,6 +40,7 @@ class Event:
|
|
|
40
40
|
error: str | None = None
|
|
41
41
|
output_chars: int = 0
|
|
42
42
|
assistant_response_chars: int = 0
|
|
43
|
+
assistant_response_substantial: bool = False
|
|
43
44
|
pending_background: int = 0
|
|
44
45
|
pending_crons: int = 0
|
|
45
46
|
|
|
@@ -154,7 +155,9 @@ def normalize(agent: str, name: str, payload: dict) -> Event:
|
|
|
154
155
|
failed, error = output_failure(categorize(event.tool, event.arguments), response)
|
|
155
156
|
event.success, event.error = not failed, error
|
|
156
157
|
elif name == "Stop":
|
|
157
|
-
|
|
158
|
+
message = _text(payload, "last_assistant_message").strip()
|
|
159
|
+
event.assistant_response_chars = len(message)
|
|
160
|
+
event.assistant_response_substantial = is_substantial(message)
|
|
158
161
|
background = payload.get("background_tasks")
|
|
159
162
|
crons = payload.get("session_crons")
|
|
160
163
|
event.pending_background = len(background) if isinstance(background, list) else 0
|
|
@@ -275,7 +278,7 @@ def handle(agent: str, name: str, payload: dict, engine_factory=Engine) -> str:
|
|
|
275
278
|
detail.append(f"{event.pending_crons} scheduled")
|
|
276
279
|
notice = f"↺ OpenReflex · WAITING\n{total} pending · " + " · ".join(detail)
|
|
277
280
|
else:
|
|
278
|
-
outcome = engine.stop(agent, event.session, assistant_completed=event.
|
|
281
|
+
outcome = engine.stop(agent, event.session, assistant_completed=event.assistant_response_substantial)
|
|
279
282
|
context = _closure_context(agent, name, payload, outcome)
|
|
280
283
|
if agent == "claude-code":
|
|
281
284
|
notice = engine.take_notice(agent, event.session)
|
|
@@ -22,8 +22,10 @@ SNAPSHOT_SCHEMA = "project-memory.v1"
|
|
|
22
22
|
STATE_SCHEMA = "openreflex-ui.v1"
|
|
23
23
|
FRESHNESS_CHECK_SECONDS = 15
|
|
24
24
|
STALE_LOCK_SECONDS = 180
|
|
25
|
+
# Stale must be well under the default timeout, or a lock abandoned by a crashed process is
|
|
26
|
+
# never reclaimed before a default caller times out instead.
|
|
25
27
|
STATE_LOCK_TIMEOUT_SECONDS = 2.0
|
|
26
|
-
STATE_LOCK_STALE_SECONDS =
|
|
28
|
+
STATE_LOCK_STALE_SECONDS = 1.0
|
|
27
29
|
IGNORE_DIRS = {
|
|
28
30
|
".git", ".hg", ".svn", ".idea", ".vscode", ".next", ".venv", "venv", "node_modules", "vendor",
|
|
29
31
|
"dist", "build", "target", "coverage", ".terraform", ".tox", ".nox", "__pycache__",
|
|
@@ -7,10 +7,11 @@ from __future__ import annotations
|
|
|
7
7
|
import hashlib
|
|
8
8
|
import json
|
|
9
9
|
import os
|
|
10
|
-
import socket
|
|
11
10
|
import subprocess
|
|
12
11
|
import sys
|
|
13
12
|
import time
|
|
13
|
+
import urllib.error
|
|
14
|
+
import urllib.request
|
|
14
15
|
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
|
|
15
16
|
from pathlib import Path
|
|
16
17
|
from typing import Any
|
|
@@ -22,6 +23,7 @@ from .store import Store, database_path
|
|
|
22
23
|
HOST = "127.0.0.1"
|
|
23
24
|
PORT = 4319
|
|
24
25
|
ENDPOINT = f"http://{HOST}:{PORT}/v1/logs"
|
|
26
|
+
SERVICE_ID = "openreflex-tokens-v1"
|
|
25
27
|
OWNED_ENV = {
|
|
26
28
|
"OPENREFLEX_TOKEN_TRACKING": "1",
|
|
27
29
|
"CLAUDE_CODE_ENABLE_TELEMETRY": "1",
|
|
@@ -213,7 +215,24 @@ def ingest_otlp_logs(payload: dict) -> int:
|
|
|
213
215
|
class _Handler(BaseHTTPRequestHandler):
|
|
214
216
|
server_version = "OpenReflexTokens/0.5"
|
|
215
217
|
|
|
218
|
+
def do_GET(self) -> None: # noqa: N802
|
|
219
|
+
if self.path.rstrip("/") != "/healthz":
|
|
220
|
+
self.send_response(404)
|
|
221
|
+
self.end_headers()
|
|
222
|
+
return
|
|
223
|
+
body = json.dumps({"service": SERVICE_ID}).encode("utf-8")
|
|
224
|
+
self.send_response(200)
|
|
225
|
+
self.send_header("Content-Type", "application/json")
|
|
226
|
+
self.send_header("Content-Length", str(len(body)))
|
|
227
|
+
self.end_headers()
|
|
228
|
+
self.wfile.write(body)
|
|
229
|
+
|
|
216
230
|
def do_POST(self) -> None: # noqa: N802
|
|
231
|
+
if self.path.rstrip("/") == "/shutdown":
|
|
232
|
+
self.send_response(200)
|
|
233
|
+
self.end_headers()
|
|
234
|
+
self.server.shutdown()
|
|
235
|
+
return
|
|
217
236
|
if self.path.rstrip("/") != "/v1/logs":
|
|
218
237
|
self.send_response(404)
|
|
219
238
|
self.end_headers()
|
|
@@ -238,15 +257,31 @@ class _Handler(BaseHTTPRequestHandler):
|
|
|
238
257
|
|
|
239
258
|
def receiver_running() -> bool:
|
|
240
259
|
try:
|
|
241
|
-
with
|
|
242
|
-
return
|
|
243
|
-
except OSError:
|
|
260
|
+
with urllib.request.urlopen(f"http://{HOST}:{PORT}/healthz", timeout=0.2) as response:
|
|
261
|
+
return json.loads(response.read()).get("service") == SERVICE_ID
|
|
262
|
+
except (OSError, urllib.error.URLError, ValueError):
|
|
244
263
|
return False
|
|
245
264
|
|
|
246
265
|
|
|
266
|
+
def stop_receiver() -> None:
|
|
267
|
+
if not receiver_running():
|
|
268
|
+
return
|
|
269
|
+
try:
|
|
270
|
+
urllib.request.urlopen(urllib.request.Request(f"http://{HOST}:{PORT}/shutdown", method="POST"), timeout=0.2)
|
|
271
|
+
except (OSError, urllib.error.URLError):
|
|
272
|
+
pass
|
|
273
|
+
for _ in range(20):
|
|
274
|
+
if not receiver_running():
|
|
275
|
+
return
|
|
276
|
+
time.sleep(0.025)
|
|
277
|
+
|
|
278
|
+
|
|
247
279
|
def serve() -> None:
|
|
248
280
|
server = ThreadingHTTPServer((HOST, PORT), _Handler)
|
|
249
|
-
|
|
281
|
+
try:
|
|
282
|
+
server.serve_forever(poll_interval=0.5)
|
|
283
|
+
finally:
|
|
284
|
+
server.server_close()
|
|
250
285
|
|
|
251
286
|
|
|
252
287
|
def ensure_receiver() -> bool:
|
|
@@ -320,6 +355,7 @@ def disable() -> dict[str, Any]:
|
|
|
320
355
|
else:
|
|
321
356
|
settings.pop("env", None)
|
|
322
357
|
_atomic_json(_settings_path(), settings)
|
|
358
|
+
stop_receiver()
|
|
323
359
|
return {"status": "disabled", "path": str(_settings_path())}
|
|
324
360
|
|
|
325
361
|
|
|
@@ -56,6 +56,8 @@ tests/test_release_consistency.py
|
|
|
56
56
|
tests/test_reliability_lifecycle.py
|
|
57
57
|
tests/test_routing_control.py
|
|
58
58
|
tests/test_stress.py
|
|
59
|
+
tests/test_token_receiver.py
|
|
60
|
+
tests/test_tokens_cli.py
|
|
59
61
|
tests/test_tui_memory.py
|
|
60
62
|
tests/test_update_cli.py
|
|
61
63
|
tests/test_work_modes_tokens.py
|
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import json
|
|
2
|
+
import os
|
|
3
|
+
import time
|
|
2
4
|
|
|
3
|
-
from openreflex.project_memory import
|
|
5
|
+
from openreflex.project_memory import (
|
|
6
|
+
_acquire_state_lock,
|
|
7
|
+
_release_state_lock,
|
|
8
|
+
build_snapshot,
|
|
9
|
+
context_for_task,
|
|
10
|
+
load_snapshot,
|
|
11
|
+
state_lock_path,
|
|
12
|
+
)
|
|
4
13
|
|
|
5
14
|
|
|
6
15
|
def _helm_project(project):
|
|
@@ -64,3 +73,33 @@ def test_snapshot_round_trip_uses_project_local_memory_directory(project):
|
|
|
64
73
|
loaded = load_snapshot(project)
|
|
65
74
|
assert loaded["source_fingerprint"] == built["source_fingerprint"]
|
|
66
75
|
assert loaded["generation"] == 1
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def test_default_timeout_reaches_stale_lock_reclaim(project):
|
|
79
|
+
"""A lock abandoned by a crashed process must be reclaimed before a default caller times out."""
|
|
80
|
+
path = state_lock_path(project)
|
|
81
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
82
|
+
path.write_text("99999 0\n", encoding="utf-8")
|
|
83
|
+
old = time.time() - 5
|
|
84
|
+
os.utime(path, (old, old))
|
|
85
|
+
|
|
86
|
+
acquired = _acquire_state_lock(project) # default timeout, must not raise TimeoutError
|
|
87
|
+
try:
|
|
88
|
+
assert acquired == path
|
|
89
|
+
finally:
|
|
90
|
+
_release_state_lock(acquired)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def test_stale_reclaim_never_fires_for_a_freshly_held_lock(project):
|
|
94
|
+
"""Normal, briefly-held contention must not be mistaken for an abandoned lock."""
|
|
95
|
+
path = state_lock_path(project)
|
|
96
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
97
|
+
path.write_text(f"{os.getpid()} {time.time()}\n", encoding="utf-8")
|
|
98
|
+
|
|
99
|
+
try:
|
|
100
|
+
_acquire_state_lock(project, timeout=0.05)
|
|
101
|
+
assert False, "expected TimeoutError while the lock is freshly held"
|
|
102
|
+
except TimeoutError:
|
|
103
|
+
pass
|
|
104
|
+
finally:
|
|
105
|
+
path.unlink(missing_ok=True)
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import socket
|
|
2
|
+
import threading
|
|
3
|
+
from http.server import ThreadingHTTPServer
|
|
4
|
+
|
|
5
|
+
import pytest
|
|
6
|
+
|
|
7
|
+
from openreflex.usage import HOST, PORT, _Handler, receiver_running, stop_receiver
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@pytest.fixture
|
|
11
|
+
def running_receiver():
|
|
12
|
+
if receiver_running():
|
|
13
|
+
pytest.skip(f"something is already answering on {HOST}:{PORT}")
|
|
14
|
+
server = ThreadingHTTPServer((HOST, PORT), _Handler)
|
|
15
|
+
thread = threading.Thread(target=server.serve_forever, kwargs={"poll_interval": 0.05}, daemon=True)
|
|
16
|
+
thread.start()
|
|
17
|
+
try:
|
|
18
|
+
yield server
|
|
19
|
+
finally:
|
|
20
|
+
if thread.is_alive():
|
|
21
|
+
server.shutdown()
|
|
22
|
+
server.server_close()
|
|
23
|
+
thread.join(timeout=2)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def test_receiver_running_identifies_the_real_receiver(running_receiver):
|
|
27
|
+
assert receiver_running() is True
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def test_receiver_running_rejects_an_unrelated_listener_on_the_same_port():
|
|
31
|
+
if receiver_running():
|
|
32
|
+
pytest.skip(f"something is already answering on {HOST}:{PORT}")
|
|
33
|
+
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
34
|
+
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
|
35
|
+
sock.bind((HOST, PORT))
|
|
36
|
+
sock.listen(1)
|
|
37
|
+
try:
|
|
38
|
+
assert receiver_running() is False
|
|
39
|
+
finally:
|
|
40
|
+
sock.close()
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def test_stop_receiver_actually_shuts_it_down(running_receiver):
|
|
44
|
+
assert receiver_running() is True
|
|
45
|
+
stop_receiver()
|
|
46
|
+
assert receiver_running() is False
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from openreflex.entrypoint import _tokens
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def test_tokens_help_shows_usage_instead_of_unknown_action(capsys):
|
|
5
|
+
code = _tokens(["--help"])
|
|
6
|
+
out = capsys.readouterr().out
|
|
7
|
+
assert code == 0
|
|
8
|
+
assert "Unknown tokens action" not in out
|
|
9
|
+
assert "enable" in out and "disable" in out and "status" in out
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def test_tokens_unknown_action_prints_usage(capsys):
|
|
13
|
+
code = _tokens(["bogus"])
|
|
14
|
+
out = capsys.readouterr().out
|
|
15
|
+
assert code == 2
|
|
16
|
+
assert "usage: openreflex tokens" in out
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import io
|
|
1
2
|
import json
|
|
2
3
|
|
|
3
|
-
from openreflex import __version__
|
|
4
|
+
from openreflex import __version__, entrypoint
|
|
4
5
|
from openreflex.claude_ui import configure_statusline, remove_statusline
|
|
5
6
|
from openreflex.entrypoint import (
|
|
6
7
|
_prompt_state,
|
|
@@ -196,4 +197,15 @@ def test_existing_user_statusline_is_never_replaced_or_removed(project):
|
|
|
196
197
|
assert configure_statusline(project) == "preserved-existing"
|
|
197
198
|
assert json.loads(settings.read_text(encoding="utf-8"))["statusLine"] == original["statusLine"]
|
|
198
199
|
assert remove_statusline(project) is False
|
|
199
|
-
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
def test_tui_survives_a_non_utf8_console(monkeypatch, project):
|
|
203
|
+
"""The dashboard's OpenReflex glyph (U+21BA) must not crash on a legacy Windows console codepage."""
|
|
204
|
+
monkeypatch.chdir(project)
|
|
205
|
+
stream = io.TextIOWrapper(io.BytesIO(), encoding="cp1252", errors="strict")
|
|
206
|
+
monkeypatch.setattr("sys.stdout", stream)
|
|
207
|
+
|
|
208
|
+
assert entrypoint.main([]) == 0
|
|
209
|
+
|
|
210
|
+
stream.seek(0)
|
|
211
|
+
assert "OPENREFLEX" in stream.buffer.getvalue().decode("utf-8")
|
|
@@ -163,6 +163,69 @@ def test_active_loop_reports_waiting_and_does_not_finalize(project, tmp_path, cl
|
|
|
163
163
|
engine.close()
|
|
164
164
|
|
|
165
165
|
|
|
166
|
+
def test_waiting_execution_resumes_on_a_non_identical_next_prompt(project, tmp_path, clock):
|
|
167
|
+
"""A real /loop iteration rarely resends byte-identical text (timestamps, tick counters); the
|
|
168
|
+
waiting execution must still resume rather than being silently finalized as unknown."""
|
|
169
|
+
approve(project)
|
|
170
|
+
database = tmp_path / "waiting.sqlite3"
|
|
171
|
+
|
|
172
|
+
def factory(root):
|
|
173
|
+
return Engine(root, Store(database), clock=clock)
|
|
174
|
+
|
|
175
|
+
base = {"session_id": "loop", "cwd": str(project)}
|
|
176
|
+
handle("claude-code", "UserPromptSubmit",
|
|
177
|
+
{**base, "prompt": "Investigate this deployment pipeline and report what is still changing"}, factory)
|
|
178
|
+
handle("claude-code", "Stop", {
|
|
179
|
+
**base,
|
|
180
|
+
"last_assistant_message": "Initial pass complete.",
|
|
181
|
+
"background_tasks": [],
|
|
182
|
+
"session_crons": [{"id": "loop-1", "schedule": "30m"}],
|
|
183
|
+
}, factory)
|
|
184
|
+
|
|
185
|
+
engine = factory(project)
|
|
186
|
+
try:
|
|
187
|
+
waiting = engine.store.latest("claude-code", "loop")
|
|
188
|
+
assert waiting.waiting_for_future_work is True
|
|
189
|
+
finally:
|
|
190
|
+
engine.close()
|
|
191
|
+
|
|
192
|
+
clock.advance(1800)
|
|
193
|
+
handle("claude-code", "UserPromptSubmit",
|
|
194
|
+
{**base, "prompt": "Investigate this deployment pipeline and report what is still changing (tick 2)"}, factory)
|
|
195
|
+
|
|
196
|
+
engine = factory(project)
|
|
197
|
+
try:
|
|
198
|
+
resumed = engine.store.latest("claude-code", "loop")
|
|
199
|
+
assert resumed.id == waiting.id
|
|
200
|
+
assert resumed.ended_at is None
|
|
201
|
+
assert resumed.waiting_for_future_work is False
|
|
202
|
+
assert engine.store.find("Outcome", execution_id=waiting.id) == []
|
|
203
|
+
finally:
|
|
204
|
+
engine.close()
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
def test_trivial_zero_tool_response_is_not_recorded_as_success(project, tmp_path, clock):
|
|
208
|
+
"""A one-character final response should not count as a completed reasoning answer."""
|
|
209
|
+
approve(project)
|
|
210
|
+
database = tmp_path / "trivial.sqlite3"
|
|
211
|
+
|
|
212
|
+
def factory(root):
|
|
213
|
+
return Engine(root, Store(database), clock=clock)
|
|
214
|
+
|
|
215
|
+
base = {"session_id": "think-1", "cwd": str(project)}
|
|
216
|
+
handle("claude-code", "UserPromptSubmit",
|
|
217
|
+
{**base, "prompt": "Why does the retry queue keep growing under load?"}, factory)
|
|
218
|
+
handle("claude-code", "Stop", {**base, "last_assistant_message": "."}, factory)
|
|
219
|
+
|
|
220
|
+
engine = factory(project)
|
|
221
|
+
try:
|
|
222
|
+
execution = engine.store.latest("claude-code", "think-1")
|
|
223
|
+
outcome = engine.store.find("Outcome", execution_id=execution.id)[0]
|
|
224
|
+
assert outcome.status != "success"
|
|
225
|
+
finally:
|
|
226
|
+
engine.close()
|
|
227
|
+
|
|
228
|
+
|
|
166
229
|
def test_otlp_token_usage_is_correlated_deduped_and_saved(project):
|
|
167
230
|
session = "tokens-1"
|
|
168
231
|
engine = Engine(project)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|