mini-trellis 0.3.8 → 0.4.0

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.
@@ -55,7 +55,7 @@ DEVELOPER_HINT = (
55
55
  # =============================================================================
56
56
 
57
57
  def get_repo_root(start_path: Path | None = None) -> Path:
58
- """Find the nearest directory containing .trellis/ folder.
58
+ """Find the nearest initialized project, bounded by an independent Git root.
59
59
 
60
60
  This handles nested git repos correctly (e.g., test project inside another repo).
61
61
 
@@ -63,17 +63,24 @@ def get_repo_root(start_path: Path | None = None) -> Path:
63
63
  start_path: Starting directory to search from. Defaults to current directory.
64
64
 
65
65
  Returns:
66
- Path to repository root, or current directory if no .trellis/ found.
66
+ Nearest initialized project or independent Git root; otherwise the
67
+ original starting directory.
67
68
  """
68
69
  current = (start_path or Path.cwd()).resolve()
69
70
 
70
- while current != current.parent:
71
- if (current / DIR_WORKFLOW).is_dir():
71
+ start = current
72
+ while True:
73
+ trellis = current / DIR_WORKFLOW
74
+ if trellis.is_dir() and not trellis.is_symlink():
72
75
  return current
76
+ if (current / ".git").exists():
77
+ return current
78
+ if current == current.parent:
79
+ break
73
80
  current = current.parent
74
81
 
75
82
  # Fallback to current directory if no .trellis/ found
76
- return Path.cwd().resolve()
83
+ return start
77
84
 
78
85
 
79
86
  # =============================================================================
@@ -0,0 +1,71 @@
1
+ """Process lock for the complete journal/index/optional-commit operation."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import errno
6
+ import os
7
+ import time
8
+ from contextlib import contextmanager
9
+ from pathlib import Path
10
+ from typing import Iterator
11
+
12
+
13
+ @contextmanager
14
+ def recording_lock(repo_root: Path, timeout: float = 30.0) -> Iterator[None]:
15
+ """Bounded, OS-owned lock. A killed writer releases it automatically.
16
+
17
+ Keep the file in place: unlinking a lock file lets waiters lock different
18
+ inodes. Its existence (and any old PID) does not mean it is still held.
19
+ This serializes one checkout, not uncommitted writes in other worktrees
20
+ or direct edits to topic files.
21
+ """
22
+ trellis = repo_root / ".trellis"
23
+ if not trellis.is_dir() or trellis.is_symlink():
24
+ raise OSError("project is not initialized; no recording files were created")
25
+ directory = trellis / ".runtime"
26
+ lock_path = directory / "session-recording.lock"
27
+ if not lock_path.resolve().is_relative_to(repo_root.resolve()):
28
+ raise OSError("recording lock escapes the project")
29
+ directory.mkdir(parents=True, exist_ok=True)
30
+ with lock_path.open("a+b") as handle:
31
+ if os.name == "nt":
32
+ import msvcrt
33
+ # Windows locks a byte range; initialize it without truncation.
34
+ if handle.seek(0, os.SEEK_END) == 0:
35
+ handle.write(b"\0")
36
+ handle.flush()
37
+
38
+ def acquire() -> None:
39
+ handle.seek(0)
40
+ msvcrt.locking(handle.fileno(), msvcrt.LK_NBLCK, 1)
41
+
42
+ def release() -> None:
43
+ handle.seek(0)
44
+ msvcrt.locking(handle.fileno(), msvcrt.LK_UNLCK, 1)
45
+ else:
46
+ import fcntl
47
+
48
+ def acquire() -> None:
49
+ fcntl.flock(handle.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB)
50
+
51
+ def release() -> None:
52
+ fcntl.flock(handle.fileno(), fcntl.LOCK_UN)
53
+
54
+ deadline = time.monotonic() + timeout
55
+ while True:
56
+ try:
57
+ acquire()
58
+ break
59
+ except OSError as exc:
60
+ if exc.errno not in (errno.EACCES, errno.EAGAIN, errno.EDEADLK):
61
+ raise
62
+ if time.monotonic() >= deadline:
63
+ raise TimeoutError(
64
+ f"recording lock busy: {lock_path}; another writer may "
65
+ "still be running. Retry after it finishes; do not delete the lock file."
66
+ ) from exc
67
+ time.sleep(0.05)
68
+ try:
69
+ yield
70
+ finally:
71
+ release()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mini-trellis",
3
- "version": "0.3.8",
3
+ "version": "0.4.0",
4
4
  "description": "Minimal memory layer for AI coding agents: spec, research, journal, and cross-session recall.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -35,7 +35,7 @@
35
35
  "commander": "^12.1.0",
36
36
  "figlet": "1.8.2",
37
37
  "inquirer": "^9.3.7",
38
- "mini-trellis-core": "0.3.8"
38
+ "mini-trellis-core": "0.4.0"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@eslint/js": "^9.18.0",