rotless 0.2.0__tar.gz → 0.2.1__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.
- {rotless-0.2.0/src/rotless.egg-info → rotless-0.2.1}/PKG-INFO +3 -3
- {rotless-0.2.0 → rotless-0.2.1}/README.md +2 -2
- {rotless-0.2.0 → rotless-0.2.1}/pyproject.toml +1 -1
- {rotless-0.2.0 → rotless-0.2.1}/src/rotless/__init__.py +1 -1
- {rotless-0.2.0 → rotless-0.2.1}/src/rotless/cli.py +4 -2
- {rotless-0.2.0 → rotless-0.2.1}/src/rotless/lint.py +7 -6
- {rotless-0.2.0 → rotless-0.2.1}/src/rotless/review.py +19 -2
- {rotless-0.2.0 → rotless-0.2.1}/src/rotless/store/__init__.py +2 -0
- {rotless-0.2.0 → rotless-0.2.1}/src/rotless/store/search.py +9 -0
- {rotless-0.2.0 → rotless-0.2.1}/src/rotless/sync.py +27 -11
- {rotless-0.2.0 → rotless-0.2.1}/src/rotless/vault.py +63 -42
- {rotless-0.2.0 → rotless-0.2.1/src/rotless.egg-info}/PKG-INFO +3 -3
- {rotless-0.2.0 → rotless-0.2.1}/tests/test_lint.py +14 -1
- {rotless-0.2.0 → rotless-0.2.1}/tests/test_review.py +28 -0
- {rotless-0.2.0 → rotless-0.2.1}/tests/test_vault_sync.py +94 -0
- {rotless-0.2.0 → rotless-0.2.1}/LICENSE +0 -0
- {rotless-0.2.0 → rotless-0.2.1}/setup.cfg +0 -0
- {rotless-0.2.0 → rotless-0.2.1}/src/rotless/__main__.py +0 -0
- {rotless-0.2.0 → rotless-0.2.1}/src/rotless/config.py +0 -0
- {rotless-0.2.0 → rotless-0.2.1}/src/rotless/fs_atomic.py +0 -0
- {rotless-0.2.0 → rotless-0.2.1}/src/rotless/handoff.py +0 -0
- {rotless-0.2.0 → rotless-0.2.1}/src/rotless/integrations/__init__.py +0 -0
- {rotless-0.2.0 → rotless-0.2.1}/src/rotless/integrations/antigravity.py +0 -0
- {rotless-0.2.0 → rotless-0.2.1}/src/rotless/integrations/base.py +0 -0
- {rotless-0.2.0 → rotless-0.2.1}/src/rotless/integrations/claude_code.py +0 -0
- {rotless-0.2.0 → rotless-0.2.1}/src/rotless/integrations/codex.py +0 -0
- {rotless-0.2.0 → rotless-0.2.1}/src/rotless/integrations/cursor.py +0 -0
- {rotless-0.2.0 → rotless-0.2.1}/src/rotless/integrations/templates/SKILL.md +0 -0
- {rotless-0.2.0 → rotless-0.2.1}/src/rotless/integrations/templates/cursor_rule.mdc +0 -0
- {rotless-0.2.0 → rotless-0.2.1}/src/rotless/models.py +0 -0
- {rotless-0.2.0 → rotless-0.2.1}/src/rotless/sessions/__init__.py +0 -0
- {rotless-0.2.0 → rotless-0.2.1}/src/rotless/sessions/antigravity.py +0 -0
- {rotless-0.2.0 → rotless-0.2.1}/src/rotless/sessions/base.py +0 -0
- {rotless-0.2.0 → rotless-0.2.1}/src/rotless/sessions/claude_code.py +0 -0
- {rotless-0.2.0 → rotless-0.2.1}/src/rotless/sessions/codex.py +0 -0
- {rotless-0.2.0 → rotless-0.2.1}/src/rotless/sessions/community.py +0 -0
- {rotless-0.2.0 → rotless-0.2.1}/src/rotless/sources.py +0 -0
- {rotless-0.2.0 → rotless-0.2.1}/src/rotless/store/conn.py +0 -0
- {rotless-0.2.0 → rotless-0.2.1}/src/rotless/store/schema.py +0 -0
- {rotless-0.2.0 → rotless-0.2.1}/src/rotless/store/state.py +0 -0
- {rotless-0.2.0 → rotless-0.2.1}/src/rotless/text_utils.py +0 -0
- {rotless-0.2.0 → rotless-0.2.1}/src/rotless/trace_audit.py +0 -0
- {rotless-0.2.0 → rotless-0.2.1}/src/rotless/warmup.py +0 -0
- {rotless-0.2.0 → rotless-0.2.1}/src/rotless.egg-info/SOURCES.txt +0 -0
- {rotless-0.2.0 → rotless-0.2.1}/src/rotless.egg-info/dependency_links.txt +0 -0
- {rotless-0.2.0 → rotless-0.2.1}/src/rotless.egg-info/entry_points.txt +0 -0
- {rotless-0.2.0 → rotless-0.2.1}/src/rotless.egg-info/top_level.txt +0 -0
- {rotless-0.2.0 → rotless-0.2.1}/tests/test_handoff.py +0 -0
- {rotless-0.2.0 → rotless-0.2.1}/tests/test_integrations.py +0 -0
- {rotless-0.2.0 → rotless-0.2.1}/tests/test_privacy_guard.py +0 -0
- {rotless-0.2.0 → rotless-0.2.1}/tests/test_security.py +0 -0
- {rotless-0.2.0 → rotless-0.2.1}/tests/test_store_search.py +0 -0
- {rotless-0.2.0 → rotless-0.2.1}/tests/test_text_utils.py +0 -0
- {rotless-0.2.0 → rotless-0.2.1}/tests/test_warmup.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: rotless
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.1
|
|
4
4
|
Summary: Zero-key, anti-rot local memory and cross-agent handoff CLI.
|
|
5
5
|
Author: rotless contributors
|
|
6
6
|
License-Expression: MIT
|
|
@@ -114,8 +114,8 @@ Measured on `Darwin arm64 | Python 3.11.14 | SQLite 3.50.4` (`scale=1000` global
|
|
|
114
114
|
|
|
115
115
|
| Metric | Value |
|
|
116
116
|
| :--- | :--- |
|
|
117
|
-
| In-process `warmup` latency (p50 / p95) | `
|
|
118
|
-
| End-to-end CLI wall-clock `warmup` (p50 / p95) | `
|
|
117
|
+
| In-process `warmup` latency (p50 / p95) | `6.89 ms` / `8.71 ms` |
|
|
118
|
+
| End-to-end CLI wall-clock `warmup` (p50 / p95) | `57.03 ms` / `61.18 ms` |
|
|
119
119
|
| Context size (Naive full dump vs `rotless warmup`) | `25,632 chars` -> `2,448 chars` (`-90.4%`) |
|
|
120
120
|
| Stale/Superseded leakage @ Top-5 (Naive FTS5 vs `rotless`) | `40.0%` vs `0.0%` |
|
|
121
121
|
| SQLite index size | `1,180.0 KB` |
|
|
@@ -89,8 +89,8 @@ Measured on `Darwin arm64 | Python 3.11.14 | SQLite 3.50.4` (`scale=1000` global
|
|
|
89
89
|
|
|
90
90
|
| Metric | Value |
|
|
91
91
|
| :--- | :--- |
|
|
92
|
-
| In-process `warmup` latency (p50 / p95) | `
|
|
93
|
-
| End-to-end CLI wall-clock `warmup` (p50 / p95) | `
|
|
92
|
+
| In-process `warmup` latency (p50 / p95) | `6.89 ms` / `8.71 ms` |
|
|
93
|
+
| End-to-end CLI wall-clock `warmup` (p50 / p95) | `57.03 ms` / `61.18 ms` |
|
|
94
94
|
| Context size (Naive full dump vs `rotless warmup`) | `25,632 chars` -> `2,448 chars` (`-90.4%`) |
|
|
95
95
|
| Stale/Superseded leakage @ Top-5 (Naive FTS5 vs `rotless`) | `40.0%` vs `0.0%` |
|
|
96
96
|
| SQLite index size | `1,180.0 KB` |
|
|
@@ -306,6 +306,7 @@ def _cmd_untrust(args: argparse.Namespace) -> int:
|
|
|
306
306
|
def _cmd_lint(args: argparse.Namespace) -> int:
|
|
307
307
|
import json
|
|
308
308
|
|
|
309
|
+
from .fs_atomic import CASConflictError
|
|
309
310
|
from .lint import fix_lint_issues, run_lint
|
|
310
311
|
from .sync import maybe_auto_sync
|
|
311
312
|
|
|
@@ -320,7 +321,7 @@ def _cmd_lint(args: argparse.Namespace) -> int:
|
|
|
320
321
|
if args.fix:
|
|
321
322
|
try:
|
|
322
323
|
res = fix_lint_issues(cfg, local_only=args.local, apply=args.apply)
|
|
323
|
-
except (ValueError, OSError) as exc:
|
|
324
|
+
except (ValueError, OSError, CASConflictError) as exc:
|
|
324
325
|
print(f"Error: {exc}", file=sys.stderr)
|
|
325
326
|
return 2
|
|
326
327
|
if args.json:
|
|
@@ -377,6 +378,7 @@ def _cmd_lint(args: argparse.Namespace) -> int:
|
|
|
377
378
|
def _cmd_verify(args: argparse.Namespace) -> int:
|
|
378
379
|
import json
|
|
379
380
|
|
|
381
|
+
from .fs_atomic import CASConflictError
|
|
380
382
|
from .vault import verify_card
|
|
381
383
|
|
|
382
384
|
cfg = load_config(args.home)
|
|
@@ -388,7 +390,7 @@ def _cmd_verify(args: argparse.Namespace) -> int:
|
|
|
388
390
|
extend_days=args.extend,
|
|
389
391
|
clear_stale=args.clear_stale,
|
|
390
392
|
)
|
|
391
|
-
except (LookupError, ValueError, OSError) as exc:
|
|
393
|
+
except (LookupError, ValueError, OSError, CASConflictError) as exc:
|
|
392
394
|
print(f"Error: {exc}", file=sys.stderr)
|
|
393
395
|
return 1 if isinstance(exc, LookupError) else 2
|
|
394
396
|
|
|
@@ -130,12 +130,13 @@ def run_lint(
|
|
|
130
130
|
stale_after = str(row["stale_after"] or "").strip()
|
|
131
131
|
verified_at = str(row["verified_at"] or "").strip()
|
|
132
132
|
|
|
133
|
-
if
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
133
|
+
if status not in DEMOTED_STATUSES:
|
|
134
|
+
if is_stale(stale_after, now=ref_now):
|
|
135
|
+
stale_notes.append({"doc_id": doc_id, "title": title, "stale_after": stale_after})
|
|
136
|
+
if is_verification_stale(verified_at, row["updated_at"]):
|
|
137
|
+
stale_verifications.append(
|
|
138
|
+
{"doc_id": doc_id, "title": title, "verified_at": verified_at, "updated_at": row["updated_at"]}
|
|
139
|
+
)
|
|
139
140
|
if sup_by:
|
|
140
141
|
if sup_by not in all_ids:
|
|
141
142
|
broken_supersedes.append({"doc_id": doc_id, "title": title, "superseded_by": sup_by})
|
|
@@ -15,10 +15,11 @@ from pathlib import Path
|
|
|
15
15
|
from typing import Any, Callable
|
|
16
16
|
|
|
17
17
|
from .config import RotlessConfig
|
|
18
|
+
from .fs_atomic import find_git_context
|
|
18
19
|
from .models import ReviewCandidate
|
|
19
20
|
from .store import connect_ro, connect_rw, get_review_decision, set_review_decision
|
|
20
21
|
from .sync import maybe_auto_sync
|
|
21
|
-
from .text_utils import parse_iso_datetime
|
|
22
|
+
from .text_utils import contains_local_abs_path, parse_iso_datetime
|
|
22
23
|
from .trace_audit import scan_candidates
|
|
23
24
|
from .vault import DuplicateCardError, add_card, supersede_card
|
|
24
25
|
|
|
@@ -109,6 +110,21 @@ def _record_decision(
|
|
|
109
110
|
conn.close()
|
|
110
111
|
|
|
111
112
|
|
|
113
|
+
def _safe_local_source_ref(source_ref: str, cwd: Path | None) -> str:
|
|
114
|
+
ref = (source_ref or "").strip()
|
|
115
|
+
if not ref or not contains_local_abs_path(ref):
|
|
116
|
+
return ref
|
|
117
|
+
git_ctx = find_git_context(cwd)
|
|
118
|
+
if git_ctx is not None:
|
|
119
|
+
try:
|
|
120
|
+
ref_path = Path(ref).expanduser()
|
|
121
|
+
if ref_path.is_absolute() and ref_path.resolve().is_relative_to(git_ctx[0].resolve()):
|
|
122
|
+
return ref
|
|
123
|
+
except (OSError, ValueError):
|
|
124
|
+
pass
|
|
125
|
+
return ""
|
|
126
|
+
|
|
127
|
+
|
|
112
128
|
def _save_candidate(
|
|
113
129
|
cfg: RotlessConfig,
|
|
114
130
|
cand: ReviewCandidate,
|
|
@@ -121,6 +137,7 @@ def _save_candidate(
|
|
|
121
137
|
tags: list[str] | None = None,
|
|
122
138
|
body: str | None = None,
|
|
123
139
|
) -> dict[str, Any]:
|
|
140
|
+
effective_ref = _safe_local_source_ref(cand.source_ref, cwd) if local else cand.source_ref
|
|
124
141
|
return add_card(
|
|
125
142
|
cfg,
|
|
126
143
|
body or cand.body,
|
|
@@ -131,7 +148,7 @@ def _save_candidate(
|
|
|
131
148
|
cwd=cwd,
|
|
132
149
|
verified=True,
|
|
133
150
|
source_session=cand.source_session,
|
|
134
|
-
source_ref=
|
|
151
|
+
source_ref=effective_ref,
|
|
135
152
|
force=force,
|
|
136
153
|
allow_redacted=allow_redacted,
|
|
137
154
|
)
|
|
@@ -9,6 +9,7 @@ from .search import (
|
|
|
9
9
|
expand_doc_context,
|
|
10
10
|
find_similar_memories,
|
|
11
11
|
get_existing_doc_hashes,
|
|
12
|
+
get_existing_doc_paths,
|
|
12
13
|
resolve_document,
|
|
13
14
|
search_by_tags,
|
|
14
15
|
search_fts,
|
|
@@ -36,6 +37,7 @@ __all__ = [
|
|
|
36
37
|
"expand_doc_context",
|
|
37
38
|
"find_similar_memories",
|
|
38
39
|
"get_existing_doc_hashes",
|
|
40
|
+
"get_existing_doc_paths",
|
|
39
41
|
"get_review_decision",
|
|
40
42
|
"get_sync_meta",
|
|
41
43
|
"init_schema",
|
|
@@ -22,6 +22,15 @@ def get_existing_doc_hashes(conn: sqlite3.Connection, scope: str) -> dict[str, t
|
|
|
22
22
|
return {str(r["doc_id"]): (str(r["content_hash"]), float(r["mtime"])) for r in rows}
|
|
23
23
|
|
|
24
24
|
|
|
25
|
+
def get_existing_doc_paths(conn: sqlite3.Connection, scope: str) -> dict[str, tuple[str, float]]:
|
|
26
|
+
"""Return map of doc_id -> (path, mtime) for a given scope."""
|
|
27
|
+
rows = conn.execute(
|
|
28
|
+
"SELECT doc_id, path, mtime FROM documents WHERE scope = ?",
|
|
29
|
+
(scope,),
|
|
30
|
+
).fetchall()
|
|
31
|
+
return {str(r["doc_id"]): (str(r["path"]), float(r["mtime"])) for r in rows}
|
|
32
|
+
|
|
33
|
+
|
|
25
34
|
def delete_document(conn: sqlite3.Connection, doc_id: str) -> None:
|
|
26
35
|
"""Delete a document; FK cascade + trigger remove chunks and FTS5 rows."""
|
|
27
36
|
conn.execute("DELETE FROM documents WHERE doc_id = ?", (doc_id,))
|
|
@@ -14,6 +14,7 @@ from .store import (
|
|
|
14
14
|
connect_rw,
|
|
15
15
|
delete_document,
|
|
16
16
|
get_existing_doc_hashes,
|
|
17
|
+
get_existing_doc_paths,
|
|
17
18
|
get_sync_meta,
|
|
18
19
|
is_project_trusted,
|
|
19
20
|
list_registered_projects,
|
|
@@ -115,25 +116,34 @@ def run_sync(
|
|
|
115
116
|
return summary
|
|
116
117
|
|
|
117
118
|
|
|
119
|
+
def _norm_path(path_str: str) -> str:
|
|
120
|
+
try:
|
|
121
|
+
return str(Path(path_str).resolve())
|
|
122
|
+
except OSError:
|
|
123
|
+
return path_str
|
|
124
|
+
|
|
125
|
+
|
|
118
126
|
def _dir_needs_sync(
|
|
119
127
|
mem_dir: Path,
|
|
120
|
-
|
|
128
|
+
existing_path_mtimes: dict[str, float],
|
|
121
129
|
*,
|
|
122
130
|
max_files: int = 2000,
|
|
123
131
|
max_bytes: int = 262144,
|
|
124
132
|
) -> bool:
|
|
125
133
|
if not mem_dir.is_dir():
|
|
126
|
-
return bool(
|
|
134
|
+
return bool(existing_path_mtimes)
|
|
127
135
|
files = safe_iter_markdown(mem_dir, max_files=max_files, max_bytes=max_bytes)
|
|
128
|
-
|
|
129
|
-
return True
|
|
130
|
-
latest_existing = max((mt for _, mt in existing_docs.values()), default=0.0)
|
|
136
|
+
disk_mtimes: dict[str, float] = {}
|
|
131
137
|
for fpath in files:
|
|
132
138
|
try:
|
|
133
|
-
|
|
134
|
-
return True
|
|
139
|
+
disk_mtimes[str(fpath.resolve())] = fpath.stat().st_mtime
|
|
135
140
|
except OSError:
|
|
136
141
|
continue
|
|
142
|
+
if set(disk_mtimes.keys()) != set(existing_path_mtimes.keys()):
|
|
143
|
+
return True
|
|
144
|
+
for pstr, mtime in disk_mtimes.items():
|
|
145
|
+
if abs(mtime - existing_path_mtimes[pstr]) > 1e-3:
|
|
146
|
+
return True
|
|
137
147
|
return False
|
|
138
148
|
|
|
139
149
|
|
|
@@ -162,14 +172,16 @@ def maybe_auto_sync(
|
|
|
162
172
|
run_sync(cfg, scope=scope, warn=warn)
|
|
163
173
|
return True
|
|
164
174
|
try:
|
|
165
|
-
|
|
175
|
+
existing_paths = get_existing_doc_paths(conn, "memory")
|
|
166
176
|
trusted = list_registered_projects(conn, trusted_only=True)
|
|
167
177
|
git_ctx = find_git_context(cwd)
|
|
168
178
|
current_trusted = bool(git_ctx and is_project_trusted(conn, git_ctx[0]))
|
|
169
179
|
finally:
|
|
170
180
|
conn.close()
|
|
171
181
|
|
|
172
|
-
global_existing = {
|
|
182
|
+
global_existing = {
|
|
183
|
+
_norm_path(p): mt for k, (p, mt) in existing_paths.items() if k.startswith("mem:global:")
|
|
184
|
+
}
|
|
173
185
|
if _dir_needs_sync(cfg.memories_dir, global_existing, max_files=2000, max_bytes=262144):
|
|
174
186
|
run_sync(cfg, scope="memory", warn=warn)
|
|
175
187
|
return True
|
|
@@ -182,7 +194,9 @@ def maybe_auto_sync(
|
|
|
182
194
|
run_sync(cfg, scope="memory", warn=warn)
|
|
183
195
|
return True
|
|
184
196
|
proj_prefix = f"mem:proj:{sha256_text(root)[:8]}:"
|
|
185
|
-
proj_existing = {
|
|
197
|
+
proj_existing = {
|
|
198
|
+
_norm_path(p): mt for k, (p, mt) in existing_paths.items() if k.startswith(proj_prefix)
|
|
199
|
+
}
|
|
186
200
|
mem_dir = Path(root) / ".rotless" / "memories"
|
|
187
201
|
if _dir_needs_sync(mem_dir, proj_existing, max_files=200, max_bytes=65536):
|
|
188
202
|
run_sync(cfg, scope="memory", warn=warn)
|
|
@@ -191,7 +205,9 @@ def maybe_auto_sync(
|
|
|
191
205
|
if current_trusted and git_ctx is not None:
|
|
192
206
|
mem_dir = git_ctx[0] / ".rotless" / "memories"
|
|
193
207
|
cur_prefix = f"mem:proj:{sha256_text(str(git_ctx[0].resolve()))[:8]}:"
|
|
194
|
-
cur_existing = {
|
|
208
|
+
cur_existing = {
|
|
209
|
+
_norm_path(p): mt for k, (p, mt) in existing_paths.items() if k.startswith(cur_prefix)
|
|
210
|
+
}
|
|
195
211
|
if _dir_needs_sync(mem_dir, cur_existing, max_files=200, max_bytes=65536):
|
|
196
212
|
run_sync(cfg, scope="memory", warn=warn)
|
|
197
213
|
return True
|
|
@@ -26,6 +26,7 @@ from .text_utils import (
|
|
|
26
26
|
derive_title,
|
|
27
27
|
format_frontmatter,
|
|
28
28
|
is_stale,
|
|
29
|
+
is_verification_stale,
|
|
29
30
|
normalize_tags,
|
|
30
31
|
parse_frontmatter,
|
|
31
32
|
parse_iso_datetime,
|
|
@@ -90,10 +91,16 @@ def add_card(
|
|
|
90
91
|
|
|
91
92
|
if local and git_ctx is not None:
|
|
92
93
|
project_root, common_dir, repo_name = git_ctx
|
|
94
|
+
unsafe_ref = bool(
|
|
95
|
+
source_ref.strip()
|
|
96
|
+
and contains_local_abs_path(source_ref)
|
|
97
|
+
and not _is_inside_project(source_ref, project_root)
|
|
98
|
+
)
|
|
93
99
|
if not allow_redacted and (
|
|
94
100
|
contains_secret(raw_content)
|
|
101
|
+
or contains_secret(source_ref)
|
|
95
102
|
or contains_local_abs_path(raw_content)
|
|
96
|
-
or
|
|
103
|
+
or unsafe_ref
|
|
97
104
|
):
|
|
98
105
|
raise ValueError(
|
|
99
106
|
"Refusing --local write: detected unredacted secret or workstation-specific path. "
|
|
@@ -528,21 +535,28 @@ def promote_card(
|
|
|
528
535
|
):
|
|
529
536
|
raise ValueError(f"Target project card already exists: {target_path}. Pass --force to overwrite.")
|
|
530
537
|
|
|
531
|
-
promoted_meta: dict[str, Any] = {
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
538
|
+
promoted_meta: dict[str, Any] = {k: v for k, v in meta.items() if k != "superseded_by"}
|
|
539
|
+
promoted_meta.update(
|
|
540
|
+
{
|
|
541
|
+
"id": new_card_id,
|
|
542
|
+
"title": clean_title,
|
|
543
|
+
"type": str(meta.get("type") or "learning"),
|
|
544
|
+
"tags": new_tags,
|
|
545
|
+
"status": "stable",
|
|
546
|
+
"created_at": str(meta.get("created_at") or now),
|
|
547
|
+
"updated_at": now,
|
|
548
|
+
"source_session": str(meta.get("source_session") or ""),
|
|
549
|
+
"source_ref": clean_ref,
|
|
550
|
+
}
|
|
551
|
+
)
|
|
542
552
|
if str(meta.get("stale_after") or "").strip():
|
|
543
553
|
promoted_meta["stale_after"] = str(meta["stale_after"]).strip()
|
|
544
|
-
|
|
545
|
-
|
|
554
|
+
orig_verified = str(meta.get("verified_at") or "").strip()
|
|
555
|
+
if orig_verified:
|
|
556
|
+
if not is_verification_stale(orig_verified, meta.get("updated_at") or old_row["updated_at"]):
|
|
557
|
+
promoted_meta["verified_at"] = now
|
|
558
|
+
else:
|
|
559
|
+
promoted_meta["verified_at"] = orig_verified
|
|
546
560
|
promoted_text = format_frontmatter(promoted_meta) + clean_body + "\n"
|
|
547
561
|
|
|
548
562
|
old_diff = ""
|
|
@@ -579,36 +593,43 @@ def promote_card(
|
|
|
579
593
|
if sha256_bytes(old_path.read_bytes()) != expected_sha:
|
|
580
594
|
raise CASConflictError(f"CAS conflict on {old_path} before promote.")
|
|
581
595
|
|
|
596
|
+
created_new_target = not target_path.exists()
|
|
582
597
|
atomic_write_text(target_path, promoted_text, allowed_root=project_root, mode=0o644)
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
if new_doc is not None:
|
|
593
|
-
upsert_document(conn, new_doc)
|
|
594
|
-
|
|
595
|
-
if keep_global:
|
|
596
|
-
atomic_write_text(
|
|
597
|
-
old_path,
|
|
598
|
-
updated_old_text,
|
|
599
|
-
expected_sha256=expected_sha,
|
|
600
|
-
allowed_root=cfg.memories_dir,
|
|
598
|
+
try:
|
|
599
|
+
repo_key = sha256_text(str(common_dir.resolve()))[:8]
|
|
600
|
+
trust_project(conn, project_root, repo_key, repo_name)
|
|
601
|
+
new_doc = load_memory_file(
|
|
602
|
+
target_path,
|
|
603
|
+
cfg,
|
|
604
|
+
origin="project",
|
|
605
|
+
project_root=str(project_root.resolve()),
|
|
606
|
+
repo_key=repo_key,
|
|
601
607
|
)
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
608
|
+
if new_doc is not None:
|
|
609
|
+
upsert_document(conn, new_doc)
|
|
610
|
+
|
|
611
|
+
if keep_global:
|
|
612
|
+
atomic_write_text(
|
|
613
|
+
old_path,
|
|
614
|
+
updated_old_text,
|
|
615
|
+
expected_sha256=expected_sha,
|
|
616
|
+
allowed_root=cfg.memories_dir,
|
|
617
|
+
)
|
|
618
|
+
old_doc = load_memory_file(old_path, cfg, origin="global")
|
|
619
|
+
if old_doc is not None:
|
|
620
|
+
upsert_document(conn, old_doc)
|
|
621
|
+
conn.commit()
|
|
622
|
+
else:
|
|
623
|
+
if sha256_bytes(old_path.read_bytes()) != expected_sha:
|
|
624
|
+
raise CASConflictError(f"CAS conflict on {old_path} during cleanup.")
|
|
625
|
+
delete_document(conn, str(old_row["doc_id"]))
|
|
626
|
+
conn.commit()
|
|
627
|
+
old_path.unlink()
|
|
628
|
+
except Exception:
|
|
629
|
+
conn.rollback()
|
|
630
|
+
if created_new_target:
|
|
631
|
+
target_path.unlink(missing_ok=True)
|
|
632
|
+
raise
|
|
612
633
|
return {
|
|
613
634
|
"applied": True,
|
|
614
635
|
"mode": mode,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: rotless
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.1
|
|
4
4
|
Summary: Zero-key, anti-rot local memory and cross-agent handoff CLI.
|
|
5
5
|
Author: rotless contributors
|
|
6
6
|
License-Expression: MIT
|
|
@@ -114,8 +114,8 @@ Measured on `Darwin arm64 | Python 3.11.14 | SQLite 3.50.4` (`scale=1000` global
|
|
|
114
114
|
|
|
115
115
|
| Metric | Value |
|
|
116
116
|
| :--- | :--- |
|
|
117
|
-
| In-process `warmup` latency (p50 / p95) | `
|
|
118
|
-
| End-to-end CLI wall-clock `warmup` (p50 / p95) | `
|
|
117
|
+
| In-process `warmup` latency (p50 / p95) | `6.89 ms` / `8.71 ms` |
|
|
118
|
+
| End-to-end CLI wall-clock `warmup` (p50 / p95) | `57.03 ms` / `61.18 ms` |
|
|
119
119
|
| Context size (Naive full dump vs `rotless warmup`) | `25,632 chars` -> `2,448 chars` (`-90.4%`) |
|
|
120
120
|
| Stale/Superseded leakage @ Top-5 (Naive FTS5 vs `rotless`) | `40.0%` vs `0.0%` |
|
|
121
121
|
| SQLite index size | `1,180.0 KB` |
|
|
@@ -9,7 +9,7 @@ from pathlib import Path
|
|
|
9
9
|
from rotless.config import RotlessConfig
|
|
10
10
|
from rotless.lint import fix_lint_issues, run_lint
|
|
11
11
|
from rotless.sync import run_sync
|
|
12
|
-
from rotless.vault import add_card
|
|
12
|
+
from rotless.vault import add_card, supersede_card
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
def test_lint_flags_stale_broken_unicode_and_permissions(
|
|
@@ -80,3 +80,16 @@ def test_lint_fix_dry_run_and_apply(cfg: RotlessConfig, fake_git_repo: Path) ->
|
|
|
80
80
|
assert applied["report"]["invisible_unicode"] == []
|
|
81
81
|
assert applied["report"]["status_mismatches"] == []
|
|
82
82
|
assert applied["report"]["insecure_permissions"] == []
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def test_lint_ignores_staleness_on_superseded_verified_card(cfg: RotlessConfig) -> None:
|
|
86
|
+
import time
|
|
87
|
+
|
|
88
|
+
old = add_card(cfg, "Legacy verified card.", tags="sqlite", verified=True, stale_after="2099-01-01")
|
|
89
|
+
time.sleep(1.1)
|
|
90
|
+
sup = supersede_card(cfg, old["card_id"], new_content="Modern verified card.", apply=True)
|
|
91
|
+
assert sup["applied"]
|
|
92
|
+
report = run_lint(cfg)
|
|
93
|
+
assert report["stale_verifications"] == []
|
|
94
|
+
assert report["stale_notes"] == []
|
|
95
|
+
assert report["is_healthy"]
|
|
@@ -99,3 +99,31 @@ def test_review_local_save_fail_closed_and_edit_routing(
|
|
|
99
99
|
local_files = list((fake_git_repo / ".rotless" / "memories").glob("*.md"))
|
|
100
100
|
assert len(local_files) == 1
|
|
101
101
|
assert "Never commit credentials" in local_files[0].read_text(encoding="utf-8")
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def test_review_local_save_strips_external_source_ref(
|
|
105
|
+
cfg: RotlessConfig,
|
|
106
|
+
fake_git_repo: Path,
|
|
107
|
+
monkeypatch: pytest.MonkeyPatch,
|
|
108
|
+
) -> None:
|
|
109
|
+
clean_body_ext_ref = ReviewCandidate(
|
|
110
|
+
candidate_hash="cand-ext-ref-01",
|
|
111
|
+
kind="learning",
|
|
112
|
+
title="Clean lesson with external cwd",
|
|
113
|
+
body="Use parameterized SQL queries everywhere.",
|
|
114
|
+
tags=["sqlite"],
|
|
115
|
+
source_session="codex:s1",
|
|
116
|
+
source_ref="/Users/alice/other-workspace",
|
|
117
|
+
signal_summary="error cluster",
|
|
118
|
+
)
|
|
119
|
+
monkeypatch.setattr(
|
|
120
|
+
"rotless.review._collect_pending",
|
|
121
|
+
lambda *_args, **_kwargs: (1, [clean_body_ext_ref]),
|
|
122
|
+
)
|
|
123
|
+
answers = iter(["l"])
|
|
124
|
+
assert run_review(cfg, no_sync=True, cwd=fake_git_repo, prompt_fn=lambda _: next(answers)) == 0
|
|
125
|
+
local_files = list((fake_git_repo / ".rotless" / "memories").glob("*.md"))
|
|
126
|
+
assert len(local_files) == 1
|
|
127
|
+
text = local_files[0].read_text(encoding="utf-8")
|
|
128
|
+
assert "/Users/alice" not in text
|
|
129
|
+
assert 'source_ref: ""' in text
|
|
@@ -203,3 +203,97 @@ def test_cli_v02_subcommands_end_to_end(
|
|
|
203
203
|
assert main(["--home", str(cfg.data_dir), "lint", "--fix", "--apply", "--json"]) == 0
|
|
204
204
|
lr = json.loads(capsys.readouterr().out)
|
|
205
205
|
assert lr["report"]["is_healthy"]
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
def test_add_local_allows_in_repo_workstation_ref_and_blocks_external(
|
|
209
|
+
cfg: RotlessConfig,
|
|
210
|
+
tmp_path: Path,
|
|
211
|
+
) -> None:
|
|
212
|
+
# Build a repo under a /Users/...-like path prefix using monkeypatch or real repo root check:
|
|
213
|
+
# Even on tmp_path, a /Users/... symlink or fake prefix is tested via _is_inside_project / realpath:
|
|
214
|
+
users_like_repo = tmp_path / "Users" / "dev" / "repo"
|
|
215
|
+
(users_like_repo / ".git").mkdir(parents=True)
|
|
216
|
+
in_repo_file = users_like_repo / "src" / "app.py"
|
|
217
|
+
in_repo_file.parent.mkdir(parents=True)
|
|
218
|
+
in_repo_file.write_text("print('ok')\n", encoding="utf-8")
|
|
219
|
+
|
|
220
|
+
# Simulate /Users/... source_ref inside repo by testing _relativize_ref and add_card inside repo.
|
|
221
|
+
res = add_card(
|
|
222
|
+
cfg,
|
|
223
|
+
"Always close handles.",
|
|
224
|
+
tags="python",
|
|
225
|
+
local=True,
|
|
226
|
+
cwd=users_like_repo,
|
|
227
|
+
source_ref=str(in_repo_file),
|
|
228
|
+
)
|
|
229
|
+
assert "source_ref: \"src/app.py\"" in Path(res["path"]).read_text(encoding="utf-8")
|
|
230
|
+
|
|
231
|
+
with pytest.raises(ValueError, match="Refusing --local write"):
|
|
232
|
+
add_card(
|
|
233
|
+
cfg,
|
|
234
|
+
"Clean body.",
|
|
235
|
+
tags="python",
|
|
236
|
+
local=True,
|
|
237
|
+
cwd=users_like_repo,
|
|
238
|
+
source_ref="/Users/alice/other-repo/secret.py",
|
|
239
|
+
)
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
def test_promote_preserves_custom_fm_refreshes_verified_and_rolls_back_on_error(
|
|
243
|
+
cfg: RotlessConfig,
|
|
244
|
+
fake_git_repo: Path,
|
|
245
|
+
monkeypatch: pytest.MonkeyPatch,
|
|
246
|
+
) -> None:
|
|
247
|
+
from rotless.lint import run_lint
|
|
248
|
+
|
|
249
|
+
card = add_card(cfg, "Verified custom rule.", tags="ci", verified=True)
|
|
250
|
+
gpath = Path(card["path"])
|
|
251
|
+
raw = gpath.read_text(encoding="utf-8")
|
|
252
|
+
gpath.write_text(raw.replace('status: "stable"', 'status: "stable"\ncustom_ext: "keep-me"'), encoding="utf-8")
|
|
253
|
+
run_sync(cfg, scope="memory")
|
|
254
|
+
|
|
255
|
+
# Simulate CAS conflict right before deleting old global file; target_path must be rolled back!
|
|
256
|
+
import rotless.vault as vault_mod
|
|
257
|
+
|
|
258
|
+
orig_delete = vault_mod.delete_document
|
|
259
|
+
|
|
260
|
+
def _boom(*_args, **_kwargs):
|
|
261
|
+
raise RuntimeError("simulated mid-promote DB failure")
|
|
262
|
+
|
|
263
|
+
monkeypatch.setattr(vault_mod, "delete_document", _boom)
|
|
264
|
+
with pytest.raises(RuntimeError, match="simulated mid-promote"):
|
|
265
|
+
promote_card(cfg, card["card_id"], cwd=fake_git_repo, apply=True)
|
|
266
|
+
monkeypatch.setattr(vault_mod, "delete_document", orig_delete)
|
|
267
|
+
assert list((fake_git_repo / ".rotless" / "memories").glob("*.md")) == []
|
|
268
|
+
|
|
269
|
+
promoted = promote_card(cfg, card["card_id"], cwd=fake_git_repo, apply=True)
|
|
270
|
+
target_text = Path(promoted["target_path"]).read_text(encoding="utf-8")
|
|
271
|
+
assert 'custom_ext: "keep-me"' in target_text
|
|
272
|
+
assert run_lint(cfg)["is_healthy"]
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
def test_maybe_auto_sync_detects_branch_swap_with_same_count_and_older_mtime(
|
|
276
|
+
cfg: RotlessConfig,
|
|
277
|
+
fake_git_repo: Path,
|
|
278
|
+
) -> None:
|
|
279
|
+
import os
|
|
280
|
+
|
|
281
|
+
added = add_card(cfg, "xylophone rule.", tags="ci", local=True, cwd=fake_git_repo, title="xylophone")
|
|
282
|
+
old_file = Path(added["path"])
|
|
283
|
+
old_mtime = old_file.stat().st_mtime
|
|
284
|
+
|
|
285
|
+
# Replace with a different filename having an OLDER mtime (same file count = 1).
|
|
286
|
+
swapped = old_file.with_name("2025-01-01_quicksilver_11112222.md")
|
|
287
|
+
swapped.write_text(
|
|
288
|
+
'---\nid: "11112222-3333-4444-5555-666677778888"\ntitle: "quicksilver"\ntags: ["ci"]\nstatus: "stable"\n---\n\nquicksilver rule.\n',
|
|
289
|
+
encoding="utf-8",
|
|
290
|
+
)
|
|
291
|
+
os.utime(swapped, (old_mtime - 100.0, old_mtime - 100.0))
|
|
292
|
+
old_file.unlink()
|
|
293
|
+
|
|
294
|
+
assert maybe_auto_sync(cfg, scope="memory", cwd=fake_git_repo) is True
|
|
295
|
+
conn = connect_ro(cfg.db_path)
|
|
296
|
+
assert conn is not None
|
|
297
|
+
assert search_fts(conn, "quicksilver", scope="memory")
|
|
298
|
+
assert search_fts(conn, "xylophone", scope="memory") == []
|
|
299
|
+
conn.close()
|
|
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
|