@pennixrv/trellis 0.7.2-beta.18 → 0.7.2-beta.19
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/dist/commands/teamwork/artifact.d.ts +1 -0
- package/dist/commands/teamwork/artifact.d.ts.map +1 -1
- package/dist/commands/teamwork/artifact.js +1 -1
- package/dist/commands/teamwork/artifact.js.map +1 -1
- package/dist/commands/teamwork/batch.d.ts +14 -1
- package/dist/commands/teamwork/batch.d.ts.map +1 -1
- package/dist/commands/teamwork/batch.js +165 -21
- package/dist/commands/teamwork/batch.js.map +1 -1
- package/dist/commands/teamwork/evidence-references.d.ts +19 -0
- package/dist/commands/teamwork/evidence-references.d.ts.map +1 -0
- package/dist/commands/teamwork/evidence-references.js +249 -0
- package/dist/commands/teamwork/evidence-references.js.map +1 -0
- package/dist/commands/teamwork/foreground-wait.d.ts.map +1 -1
- package/dist/commands/teamwork/foreground-wait.js +7 -0
- package/dist/commands/teamwork/foreground-wait.js.map +1 -1
- package/dist/commands/teamwork/index.d.ts.map +1 -1
- package/dist/commands/teamwork/index.js +5 -2
- package/dist/commands/teamwork/index.js.map +1 -1
- package/dist/commands/teamwork/rm.d.ts +27 -4
- package/dist/commands/teamwork/rm.d.ts.map +1 -1
- package/dist/commands/teamwork/rm.js +155 -51
- package/dist/commands/teamwork/rm.js.map +1 -1
- package/dist/commands/teamwork/run.d.ts.map +1 -1
- package/dist/commands/teamwork/run.js +10 -1
- package/dist/commands/teamwork/run.js.map +1 -1
- package/dist/commands/teamwork/runtime.d.ts.map +1 -1
- package/dist/commands/teamwork/runtime.js +2 -2
- package/dist/commands/teamwork/runtime.js.map +1 -1
- package/dist/commands/update.d.ts.map +1 -1
- package/dist/commands/update.js +32 -1
- package/dist/commands/update.js.map +1 -1
- package/dist/migrations/manifests/0.7.2-beta.19.json +11 -0
- package/dist/templates/common/bundled-skills/trellis-delivery-review-and-closeout/workflow.md +2 -0
- package/dist/templates/shared-hooks/guard-teamwork-wait.py +11 -3
- package/dist/templates/trellis/gitignore.txt +4 -0
- package/dist/templates/trellis/index.d.ts +1 -0
- package/dist/templates/trellis/index.d.ts.map +1 -1
- package/dist/templates/trellis/index.js +2 -0
- package/dist/templates/trellis/index.js.map +1 -1
- package/dist/templates/trellis/scripts/common/active_task.py +23 -31
- package/dist/templates/trellis/scripts/common/session_context.py +25 -50
- package/dist/templates/trellis/scripts/common/task_context.py +2 -0
- package/dist/templates/trellis/scripts/common/task_continuity.py +31 -9
- package/dist/templates/trellis/scripts/common/task_runtime.py +211 -0
- package/dist/templates/trellis/scripts/common/task_workflow.py +3 -24
- package/dist/templates/trellis/scripts/common/worktree_delegation.py +9 -0
- package/dist/templates/trellis/scripts/task.py +6 -0
- package/dist/templates/trellis/workflow.md +4 -0
- package/package.json +2 -2
|
@@ -9,21 +9,20 @@ Provides:
|
|
|
9
9
|
get_context_text_record - Text for record mode
|
|
10
10
|
output_json - Print JSON
|
|
11
11
|
output_text - Print text
|
|
12
|
-
get_update_hint - Once-per-
|
|
12
|
+
get_update_hint - Once-per-version-pair "update available" line
|
|
13
13
|
"""
|
|
14
14
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
17
|
import json
|
|
18
|
-
import os
|
|
19
18
|
import re
|
|
20
19
|
import subprocess
|
|
21
20
|
import sys
|
|
22
21
|
from pathlib import Path
|
|
23
22
|
|
|
24
|
-
from .active_task import resolve_context_key
|
|
25
23
|
from .config import get_git_packages
|
|
26
24
|
from .git import run_git
|
|
25
|
+
from .io import read_json, write_json
|
|
27
26
|
from .packages_context import get_packages_section
|
|
28
27
|
from .tasks import iter_active_tasks, load_task, get_all_statuses, children_progress
|
|
29
28
|
from .paths import (
|
|
@@ -419,55 +418,17 @@ def _compare_versions(left: str, right: str) -> int | None:
|
|
|
419
418
|
|
|
420
419
|
|
|
421
420
|
def _update_marker_path(repo_root: Path, context_key: str | None = None) -> Path:
|
|
422
|
-
"""
|
|
423
|
-
|
|
424
|
-
`context_key` lets a caller that already resolved session identity pass it
|
|
425
|
-
in — the SessionStart hook reads the session id from hook stdin, which is
|
|
426
|
-
more reliable than this function's environment-only fallback chain. Shell
|
|
427
|
-
entry points leave it None and keep the previous behavior.
|
|
428
|
-
"""
|
|
429
|
-
if not context_key:
|
|
430
|
-
context_key = resolve_context_key()
|
|
431
|
-
if not context_key:
|
|
432
|
-
terminal_key = os.environ.get("TERM_SESSION_ID", "").strip()
|
|
433
|
-
context_key = terminal_key or f"ppid-{os.getppid()}"
|
|
434
|
-
safe_key = re.sub(r"[^A-Za-z0-9._-]+", "_", context_key).strip("._-")
|
|
435
|
-
if not safe_key:
|
|
436
|
-
safe_key = "session"
|
|
437
|
-
return (
|
|
438
|
-
repo_root
|
|
439
|
-
/ DIR_WORKFLOW
|
|
440
|
-
/ ".runtime"
|
|
441
|
-
/ f"update-check-{safe_key[:160]}.marker"
|
|
442
|
-
)
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
def _mark_update_check_attempted(
|
|
446
|
-
repo_root: Path,
|
|
447
|
-
context_key: str | None = None,
|
|
448
|
-
) -> bool:
|
|
449
|
-
marker_path = _update_marker_path(repo_root, context_key)
|
|
450
|
-
if marker_path.exists():
|
|
451
|
-
return False
|
|
452
|
-
try:
|
|
453
|
-
marker_path.parent.mkdir(parents=True, exist_ok=True)
|
|
454
|
-
marker_path.write_text("checked\n", encoding="utf-8")
|
|
455
|
-
except OSError:
|
|
456
|
-
pass
|
|
457
|
-
return True
|
|
421
|
+
"""Keep one advisory record, independent of the number of sessions."""
|
|
422
|
+
return repo_root / DIR_WORKFLOW / ".runtime" / "update-check.json"
|
|
458
423
|
|
|
459
424
|
|
|
460
425
|
def get_update_hint(repo_root: Path, context_key: str | None = None) -> str | None:
|
|
461
|
-
"""Return the
|
|
426
|
+
"""Return the local CLI hint once per project/installed version pair.
|
|
462
427
|
|
|
463
428
|
Public because the SessionStart hook imports it: the text-mode CLI path
|
|
464
429
|
(`get_context.py`) used to be the only caller, so hook-driven platforms —
|
|
465
430
|
Claude Code included — never saw the reminder at all.
|
|
466
431
|
"""
|
|
467
|
-
marker_path = _update_marker_path(repo_root, context_key)
|
|
468
|
-
if marker_path.exists():
|
|
469
|
-
return None
|
|
470
|
-
|
|
471
432
|
current_version = _read_project_version(repo_root)
|
|
472
433
|
if not current_version:
|
|
473
434
|
return None
|
|
@@ -476,7 +437,19 @@ def get_update_hint(repo_root: Path, context_key: str | None = None) -> str | No
|
|
|
476
437
|
if not latest_version:
|
|
477
438
|
return None
|
|
478
439
|
|
|
479
|
-
|
|
440
|
+
from .task_move import layout_lock
|
|
441
|
+
|
|
442
|
+
pair = {"project_version": current_version, "installed_version": latest_version}
|
|
443
|
+
marker_path = _update_marker_path(repo_root, context_key)
|
|
444
|
+
try:
|
|
445
|
+
with layout_lock(repo_root):
|
|
446
|
+
if read_json(marker_path) == pair:
|
|
447
|
+
return None
|
|
448
|
+
marker_path.parent.mkdir(parents=True, exist_ok=True)
|
|
449
|
+
if not write_json(marker_path, pair):
|
|
450
|
+
print("Warning: could not persist the Trellis update hint.", file=sys.stderr)
|
|
451
|
+
except OSError:
|
|
452
|
+
pass
|
|
480
453
|
comparison = _compare_versions(current_version, latest_version)
|
|
481
454
|
if comparison is None or comparison >= 0:
|
|
482
455
|
return None
|
|
@@ -527,6 +500,7 @@ def get_context_json(repo_root: Path | None = None) -> dict:
|
|
|
527
500
|
"parent": t.parent,
|
|
528
501
|
}
|
|
529
502
|
for t in iter_active_tasks(tasks_dir)
|
|
503
|
+
if t.status in {"planning", "in_progress"}
|
|
530
504
|
]
|
|
531
505
|
|
|
532
506
|
# Package git repos (independent sub-repositories)
|
|
@@ -652,8 +626,9 @@ def get_context_text(repo_root: Path | None = None) -> str:
|
|
|
652
626
|
task_count = 0
|
|
653
627
|
|
|
654
628
|
# Collect all task data for hierarchy display
|
|
655
|
-
|
|
656
|
-
all_statuses = {name: t.status for name, t in
|
|
629
|
+
task_records = {t.dir_name: t for t in iter_active_tasks(tasks_dir)}
|
|
630
|
+
all_statuses = {name: t.status for name, t in task_records.items()}
|
|
631
|
+
all_tasks = {name: t for name, t in task_records.items() if t.status in {"planning", "in_progress"}}
|
|
657
632
|
|
|
658
633
|
def _print_task_tree(name: str, indent: int = 0) -> None:
|
|
659
634
|
nonlocal task_count
|
|
@@ -667,7 +642,7 @@ def get_context_text(repo_root: Path | None = None) -> str:
|
|
|
667
642
|
_print_task_tree(child, indent + 1)
|
|
668
643
|
|
|
669
644
|
for dir_name in sorted(all_tasks.keys()):
|
|
670
|
-
if
|
|
645
|
+
if all_tasks[dir_name].parent not in all_tasks:
|
|
671
646
|
_print_task_tree(dir_name)
|
|
672
647
|
|
|
673
648
|
if task_count == 0:
|
|
@@ -744,7 +719,7 @@ def get_context_record_json(repo_root: Path | None = None) -> dict:
|
|
|
744
719
|
|
|
745
720
|
my_tasks = []
|
|
746
721
|
for t in all_tasks_list:
|
|
747
|
-
if t.assignee == developer:
|
|
722
|
+
if t.assignee == developer and t.status in {"planning", "in_progress"}:
|
|
748
723
|
done = sum(
|
|
749
724
|
1 for c in t.children
|
|
750
725
|
if all_statuses.get(c) in ("completed", "done")
|
|
@@ -834,7 +809,7 @@ def get_context_text_record(repo_root: Path | None = None) -> str:
|
|
|
834
809
|
all_statuses = get_all_statuses(tasks_dir)
|
|
835
810
|
|
|
836
811
|
for t in iter_active_tasks(tasks_dir):
|
|
837
|
-
if t.assignee == developer:
|
|
812
|
+
if t.assignee == developer and t.status in {"planning", "in_progress"}:
|
|
838
813
|
progress = children_progress(t.children, all_statuses)
|
|
839
814
|
lines.append(f"- [{t.priority}] {t.title} ({t.status}){progress} — {t.dir_name}")
|
|
840
815
|
my_task_count += 1
|
|
@@ -153,6 +153,8 @@ def cmd_validate(args: argparse.Namespace) -> int:
|
|
|
153
153
|
task_json_path = target_dir / FILE_TASK_JSON
|
|
154
154
|
if task_json_path.is_file():
|
|
155
155
|
task_data = read_json(task_json_path)
|
|
156
|
+
if task_data and task_data.get("status") in {"completed", "cancelled"}:
|
|
157
|
+
print("Historical context diagnostic: missing references do not revoke accepted task history or authorize deletion.")
|
|
156
158
|
stored_branch = task_data.get("branch") if task_data else None
|
|
157
159
|
if stored_branch and not branch_exists_locally(stored_branch, repo_root):
|
|
158
160
|
print(
|
|
@@ -308,6 +308,15 @@ def continuity_show(args: argparse.Namespace) -> int:
|
|
|
308
308
|
|
|
309
309
|
|
|
310
310
|
def continuity_capture(args: argparse.Namespace) -> int:
|
|
311
|
+
from .task_move import layout_lock
|
|
312
|
+
|
|
313
|
+
with layout_lock(get_repo_root()):
|
|
314
|
+
return _continuity_capture_locked(args)
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
def _continuity_capture_locked(args: argparse.Namespace) -> int:
|
|
318
|
+
from .task_move import layout_lock
|
|
319
|
+
|
|
311
320
|
root = get_repo_root()
|
|
312
321
|
try:
|
|
313
322
|
directory, data, task_id, _ = _task(root)
|
|
@@ -315,7 +324,8 @@ def continuity_capture(args: argparse.Namespace) -> int:
|
|
|
315
324
|
source_digest = _digest(current)
|
|
316
325
|
task_path = directory.relative_to(root).as_posix()
|
|
317
326
|
path = _continuity_path(root, task_path)
|
|
318
|
-
with
|
|
327
|
+
with layout_lock(root):
|
|
328
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
319
329
|
record, _ = _read_record(path)
|
|
320
330
|
actual = record.get("source_digest") if record else "absent"
|
|
321
331
|
if actual != args.expected_source_digest:
|
|
@@ -380,6 +390,15 @@ def _current_projection_digest(root: Path, task_dir: Path, data: dict, task_id:
|
|
|
380
390
|
|
|
381
391
|
|
|
382
392
|
def transfer_task_ownership(args: argparse.Namespace) -> int:
|
|
393
|
+
from .task_move import layout_lock
|
|
394
|
+
|
|
395
|
+
with layout_lock(get_repo_root()):
|
|
396
|
+
return _transfer_task_ownership_locked(args)
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
def _transfer_task_ownership_locked(args: argparse.Namespace) -> int:
|
|
400
|
+
from .task_move import layout_lock
|
|
401
|
+
|
|
383
402
|
root = get_repo_root()
|
|
384
403
|
operation = args.transfer_action
|
|
385
404
|
try:
|
|
@@ -400,7 +419,7 @@ def transfer_task_ownership(args: argparse.Namespace) -> int:
|
|
|
400
419
|
if operation != "status" and data.get("status") in {"completed", "cancelled"}:
|
|
401
420
|
raise ContinuityError("TASK_TRANSFER_WITHHELD", "terminal tasks cannot change ownership")
|
|
402
421
|
path = _ownership_path(root, task_path)
|
|
403
|
-
with
|
|
422
|
+
with layout_lock(root):
|
|
404
423
|
record = _load_owner(path)
|
|
405
424
|
if record and (record["task_id"] != task_id or record["task_path"] != task_path):
|
|
406
425
|
raise ContinuityError("TASK_TRANSFER_WITHHELD", "ownership record does not match the requested task")
|
|
@@ -417,6 +436,7 @@ def transfer_task_ownership(args: argparse.Namespace) -> int:
|
|
|
417
436
|
raise ContinuityError("TASK_TRANSFER_NOT_AUTHORIZED", "ownership changes require an explicit user request")
|
|
418
437
|
if args.expected_generation is None or args.expected_generation < 0:
|
|
419
438
|
raise ContinuityError("TASK_TRANSFER_INVALID_INPUT", "a non-negative expected generation is required")
|
|
439
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
420
440
|
if operation == "quiesce":
|
|
421
441
|
context_key, current_path = _direct_pointer(root, task_path)
|
|
422
442
|
if current_path is None:
|
|
@@ -606,10 +626,10 @@ def add_continuity_commands(subparsers) -> None:
|
|
|
606
626
|
|
|
607
627
|
def clear_task_runtime_records(repo_root: Path, task_path: str) -> bool:
|
|
608
628
|
"""Remove only this task's current continuity and ownership projections."""
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
629
|
+
from .task_move import layout_lock
|
|
630
|
+
|
|
631
|
+
with layout_lock(repo_root):
|
|
632
|
+
for path in (_continuity_path(repo_root, task_path), _ownership_path(repo_root, task_path)):
|
|
613
633
|
try:
|
|
614
634
|
path.unlink(missing_ok=True)
|
|
615
635
|
except OSError:
|
|
@@ -630,7 +650,7 @@ def active_task_change_guard(repo_root: Path, context_key: str, task_path: str,
|
|
|
630
650
|
return
|
|
631
651
|
task_path = directory.relative_to(repo_root).as_posix()
|
|
632
652
|
path = _ownership_path(repo_root, task_path)
|
|
633
|
-
with
|
|
653
|
+
with layout_lock(repo_root):
|
|
634
654
|
try:
|
|
635
655
|
record = _load_owner(path)
|
|
636
656
|
except ContinuityError:
|
|
@@ -664,9 +684,11 @@ def assert_task_mutation_allowed(repo_root: Path, task_dir: Path, data: dict) ->
|
|
|
664
684
|
|
|
665
685
|
def assert_task_identity_change_allowed(repo_root: Path, task_dir: Path, data: dict) -> None:
|
|
666
686
|
"""Keep an active ownership record addressable while the task ID is fixed."""
|
|
687
|
+
from .task_move import layout_lock
|
|
688
|
+
|
|
667
689
|
task_path = task_dir.relative_to(repo_root).as_posix()
|
|
668
690
|
path = _ownership_path(repo_root, task_path)
|
|
669
|
-
with
|
|
691
|
+
with layout_lock(repo_root):
|
|
670
692
|
try:
|
|
671
693
|
record = _load_owner(path)
|
|
672
694
|
except ContinuityError as error:
|
|
@@ -687,7 +709,7 @@ def task_mutation_guard(repo_root: Path, task_dir: Path, data: dict):
|
|
|
687
709
|
require_settled_layout(repo_root)
|
|
688
710
|
task_path = task_dir.relative_to(repo_root).as_posix()
|
|
689
711
|
path = _ownership_path(repo_root, task_path)
|
|
690
|
-
with
|
|
712
|
+
with layout_lock(repo_root):
|
|
691
713
|
try:
|
|
692
714
|
record = _load_owner(path)
|
|
693
715
|
except ContinuityError:
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
"""Bounded retirement of Trellis-owned projections; never task evidence."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import ast
|
|
7
|
+
import hashlib
|
|
8
|
+
from itertools import islice
|
|
9
|
+
import json
|
|
10
|
+
import os
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
import re
|
|
13
|
+
import stat
|
|
14
|
+
import sys
|
|
15
|
+
|
|
16
|
+
from .io import read_json_checked
|
|
17
|
+
from .paths import get_repo_root
|
|
18
|
+
from .task_move import layout_lock, require_settled_layout
|
|
19
|
+
from .task_utils import is_within_tasks_dir, resolve_task_dir
|
|
20
|
+
|
|
21
|
+
MAX_FILES = 2048
|
|
22
|
+
MAX_BYTES = 256 * 1024
|
|
23
|
+
SESSION_KEYS = {"current_task", "current_run", "platform", "last_seen_at"}
|
|
24
|
+
MARKER = re.compile(r"update-check-[A-Za-z0-9_.-]+\.marker\Z")
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _fingerprint(path: Path) -> dict:
|
|
28
|
+
info = path.lstat()
|
|
29
|
+
if not stat.S_ISREG(info.st_mode) or info.st_size > MAX_BYTES:
|
|
30
|
+
raise ValueError("not a bounded regular file")
|
|
31
|
+
return {"device": info.st_dev, "inode": info.st_ino, "size": info.st_size,
|
|
32
|
+
"mtime_ns": info.st_mtime_ns, "mode": info.st_mode,
|
|
33
|
+
"sha256": hashlib.sha256(path.read_bytes()).hexdigest()}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _protocol(root: Path) -> dict:
|
|
37
|
+
"""Check the materialized writers, not merely the executing CLI version."""
|
|
38
|
+
scripts = root / ".trellis/scripts"
|
|
39
|
+
result = {}
|
|
40
|
+
checks = {"common/active_task.py": "_session_file_lock",
|
|
41
|
+
"common/task_workflow.py": "_task_lock",
|
|
42
|
+
"common/task_continuity.py": "continuity_capture",
|
|
43
|
+
"task.py": "main"}
|
|
44
|
+
for relative, function in checks.items():
|
|
45
|
+
path = scripts / relative
|
|
46
|
+
try:
|
|
47
|
+
if path.resolve() != path.absolute():
|
|
48
|
+
return {"ready": False, "reason": "redirected native writer"}
|
|
49
|
+
raw = path.read_bytes()
|
|
50
|
+
tree = ast.parse(raw)
|
|
51
|
+
node = next(n for n in tree.body if isinstance(n, ast.FunctionDef) and n.name == function)
|
|
52
|
+
calls = {n.func.id for n in ast.walk(node)
|
|
53
|
+
if isinstance(n, ast.Call) and isinstance(n.func, ast.Name)}
|
|
54
|
+
if "layout_lock" not in calls:
|
|
55
|
+
return {"ready": False, "reason": "native writers still use the old protocol"}
|
|
56
|
+
if relative == "common/task_continuity.py" and any(
|
|
57
|
+
isinstance(n, ast.Call) and isinstance(n.func, ast.Name) and n.func.id == "_record_lock"
|
|
58
|
+
for n in ast.walk(tree)
|
|
59
|
+
):
|
|
60
|
+
return {"ready": False, "reason": "per-record continuity writer remains"}
|
|
61
|
+
result[relative] = hashlib.sha256(raw).hexdigest()
|
|
62
|
+
except (OSError, SyntaxError, StopIteration, ValueError):
|
|
63
|
+
return {"ready": False, "reason": "cannot verify materialized native writers"}
|
|
64
|
+
return {"ready": True, "writers": result}
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def _open_anchors(identities: set[tuple[int, int]]) -> tuple[set[tuple[int, int]], str | None]:
|
|
68
|
+
# Open descriptors include flock waiters; an empty /proc/locks snapshot does not.
|
|
69
|
+
if not identities:
|
|
70
|
+
return set(), None
|
|
71
|
+
if sys.platform != "linux":
|
|
72
|
+
return set(), "legacy anchor retirement requires descriptor verification on this platform"
|
|
73
|
+
opened: set[tuple[int, int]] = set()
|
|
74
|
+
inspected = 0
|
|
75
|
+
try:
|
|
76
|
+
processes = list(Path("/proc").iterdir())
|
|
77
|
+
if len(processes) > 8192:
|
|
78
|
+
return opened, "process inspection limit exceeded"
|
|
79
|
+
for process in processes:
|
|
80
|
+
if not process.name.isdigit():
|
|
81
|
+
continue
|
|
82
|
+
try:
|
|
83
|
+
if process.stat().st_uid != os.getuid():
|
|
84
|
+
continue
|
|
85
|
+
for descriptor in (process / "fd").iterdir():
|
|
86
|
+
inspected += 1
|
|
87
|
+
if inspected > 50000:
|
|
88
|
+
return opened, "descriptor inspection limit exceeded"
|
|
89
|
+
try:
|
|
90
|
+
info = descriptor.stat()
|
|
91
|
+
identity = (info.st_dev, info.st_ino)
|
|
92
|
+
if identity in identities:
|
|
93
|
+
opened.add(identity)
|
|
94
|
+
except FileNotFoundError:
|
|
95
|
+
pass
|
|
96
|
+
except FileNotFoundError:
|
|
97
|
+
pass
|
|
98
|
+
except OSError:
|
|
99
|
+
return opened, "cannot completely inspect same-user open descriptors"
|
|
100
|
+
return opened, None
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def preview(root: Path, task: str | None = None) -> dict:
|
|
104
|
+
runtime = root / ".trellis/.runtime"
|
|
105
|
+
if runtime.resolve() != runtime.absolute():
|
|
106
|
+
raise ValueError("redirected runtime directory")
|
|
107
|
+
task_dir = resolve_task_dir(task, root) if task else None
|
|
108
|
+
if task and (task_dir is None or not is_within_tasks_dir(task_dir, root)):
|
|
109
|
+
raise ValueError("task scope must resolve to an existing native task")
|
|
110
|
+
task_path = task_dir.relative_to(root).as_posix() if task_dir else None
|
|
111
|
+
task_key = hashlib.sha256(task_path.encode()).hexdigest() if task_path else None
|
|
112
|
+
protocol = _protocol(root)
|
|
113
|
+
items: list[dict] = []
|
|
114
|
+
for family in ("sessions", "task-phase", "task-ownership", "continuity", ""):
|
|
115
|
+
directory = runtime / family
|
|
116
|
+
if not directory.exists():
|
|
117
|
+
continue
|
|
118
|
+
if directory.resolve() != directory.absolute() or not directory.is_dir():
|
|
119
|
+
raise ValueError("redirected or invalid runtime family")
|
|
120
|
+
paths = list(islice(directory.iterdir(), MAX_FILES + 1))
|
|
121
|
+
if len(paths) > MAX_FILES:
|
|
122
|
+
raise ValueError("runtime family scan limit exceeded; nothing may be removed")
|
|
123
|
+
for path in sorted(paths):
|
|
124
|
+
if family == "" and (task or not MARKER.fullmatch(path.name)):
|
|
125
|
+
continue
|
|
126
|
+
if family and path.suffix not in {".json", ".lock"}:
|
|
127
|
+
continue
|
|
128
|
+
if task_dir and not (family == "task-phase" and path.stem == task_dir.name or
|
|
129
|
+
family in {"continuity", "task-ownership"} and path.stem == task_key):
|
|
130
|
+
continue
|
|
131
|
+
if len(items) >= MAX_FILES:
|
|
132
|
+
raise ValueError("runtime preview limit exceeded; nothing may be removed")
|
|
133
|
+
item = {"path": path.relative_to(root).as_posix(), "family": family or "update-hint",
|
|
134
|
+
"eligible": False, "reason": "business record or unknown content"}
|
|
135
|
+
try:
|
|
136
|
+
fingerprint = _fingerprint(path)
|
|
137
|
+
item["fingerprint"] = fingerprint
|
|
138
|
+
if path.suffix == ".lock":
|
|
139
|
+
item["role"] = "retired-anchor"
|
|
140
|
+
if family in {"continuity", "task-ownership"}:
|
|
141
|
+
pattern = r"[0-9a-f]{64}"
|
|
142
|
+
elif family == "task-phase":
|
|
143
|
+
pattern = r"\d{2}-\d{2}-[A-Za-z0-9_.-]+"
|
|
144
|
+
else:
|
|
145
|
+
pattern = r"[A-Za-z0-9_.-]{1,128}"
|
|
146
|
+
known_name = bool(re.fullmatch(pattern, path.stem))
|
|
147
|
+
item["eligible"] = known_name and protocol["ready"] and path.read_bytes() in {b"", b"\0"}
|
|
148
|
+
item["reason"] = "native writers use the fixed layout anchor" if item["eligible"] else "writer protocol or anchor content is not verified"
|
|
149
|
+
elif family == "":
|
|
150
|
+
item["role"] = "obsolete-update-hint"
|
|
151
|
+
item["eligible"] = protocol["ready"] and path.read_bytes() == b"checked\n"
|
|
152
|
+
item["reason"] = "replaced by one version-pair record" if item["eligible"] else "unknown marker or old writer protocol"
|
|
153
|
+
elif family == "sessions":
|
|
154
|
+
data, _ = read_json_checked(path)
|
|
155
|
+
item["role"] = "session-projection"
|
|
156
|
+
item["eligible"] = (
|
|
157
|
+
data is not None and set(data) <= SESSION_KEYS
|
|
158
|
+
and data.get("current_task") in (None, "") and data.get("current_run") is None
|
|
159
|
+
and all(data.get(key) is None or isinstance(data[key], str) for key in ("platform", "last_seen_at"))
|
|
160
|
+
)
|
|
161
|
+
item["reason"] = "known empty business projection" if item["eligible"] else "task, run, unknown field or invalid record is retained"
|
|
162
|
+
else:
|
|
163
|
+
item["role"] = "control-evidence"
|
|
164
|
+
except (OSError, ValueError):
|
|
165
|
+
item["reason"] = "unreadable, redirected, nonregular or oversized object"
|
|
166
|
+
items.append(item)
|
|
167
|
+
anchors = {(i["fingerprint"]["device"], i["fingerprint"]["inode"])
|
|
168
|
+
for i in items if i.get("role") == "retired-anchor" and i["eligible"]}
|
|
169
|
+
opened, error = _open_anchors(anchors)
|
|
170
|
+
for item in items:
|
|
171
|
+
if item.get("role") != "retired-anchor" or not item["eligible"]:
|
|
172
|
+
continue
|
|
173
|
+
info = item["fingerprint"]
|
|
174
|
+
if error or (info["device"], info["inode"]) in opened:
|
|
175
|
+
item.update(eligible=False, reason=error or "an existing writer or waiter has the anchor open")
|
|
176
|
+
result = {"owner": "trellis-task", "scope": task_path or "project-runtime",
|
|
177
|
+
"writer_protocol": protocol, "items": items}
|
|
178
|
+
result["digest"] = hashlib.sha256(json.dumps(result, sort_keys=True, separators=(",", ":")).encode()).hexdigest()
|
|
179
|
+
return result
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def cmd_runtime(args: argparse.Namespace) -> int:
|
|
183
|
+
root = get_repo_root()
|
|
184
|
+
with layout_lock(root):
|
|
185
|
+
require_settled_layout(root)
|
|
186
|
+
result = preview(root, args.dir)
|
|
187
|
+
result["dry_run"] = not bool(args.confirm)
|
|
188
|
+
result["removed"] = []
|
|
189
|
+
result["failed"] = []
|
|
190
|
+
if args.confirm:
|
|
191
|
+
if args.confirm != result["digest"]:
|
|
192
|
+
print(json.dumps({"status": "stale", "preview": result}, ensure_ascii=False))
|
|
193
|
+
return 1
|
|
194
|
+
for item in result["items"]:
|
|
195
|
+
if not item["eligible"]:
|
|
196
|
+
continue
|
|
197
|
+
path = root / item["path"]
|
|
198
|
+
try:
|
|
199
|
+
if _fingerprint(path) != item["fingerprint"]:
|
|
200
|
+
raise ValueError("object changed after confirmation")
|
|
201
|
+
if item["role"] == "retired-anchor":
|
|
202
|
+
info = item["fingerprint"]
|
|
203
|
+
opened, error = _open_anchors({(info["device"], info["inode"])})
|
|
204
|
+
if error or opened:
|
|
205
|
+
raise ValueError(error or "anchor became open")
|
|
206
|
+
path.unlink()
|
|
207
|
+
result["removed"].append(item["path"])
|
|
208
|
+
except (OSError, ValueError) as error:
|
|
209
|
+
result["failed"].append({"path": item["path"], "reason": str(error)})
|
|
210
|
+
print(json.dumps(result, ensure_ascii=False, sort_keys=True))
|
|
211
|
+
return 1 if result["failed"] else 0
|
|
@@ -207,31 +207,10 @@ def _save(task_file: Path, data: dict) -> None:
|
|
|
207
207
|
|
|
208
208
|
@contextlib.contextmanager
|
|
209
209
|
def _task_lock(task_dir: Path):
|
|
210
|
-
|
|
211
|
-
lock_file.parent.mkdir(parents=True, exist_ok=True)
|
|
212
|
-
with lock_file.open("a+b") as handle:
|
|
213
|
-
if os.name == "nt":
|
|
214
|
-
import msvcrt
|
|
215
|
-
|
|
216
|
-
handle.seek(0)
|
|
217
|
-
if handle.read(1) == b"":
|
|
218
|
-
handle.write(b"\0")
|
|
219
|
-
handle.flush()
|
|
220
|
-
handle.seek(0)
|
|
221
|
-
msvcrt.locking(handle.fileno(), msvcrt.LK_LOCK, 1)
|
|
222
|
-
try:
|
|
223
|
-
yield
|
|
224
|
-
finally:
|
|
225
|
-
handle.seek(0)
|
|
226
|
-
msvcrt.locking(handle.fileno(), msvcrt.LK_UNLCK, 1)
|
|
227
|
-
else:
|
|
228
|
-
import fcntl
|
|
210
|
+
from .task_move import layout_lock
|
|
229
211
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
yield
|
|
233
|
-
finally:
|
|
234
|
-
fcntl.flock(handle.fileno(), fcntl.LOCK_UN)
|
|
212
|
+
with layout_lock(get_repo_root()):
|
|
213
|
+
yield
|
|
235
214
|
|
|
236
215
|
|
|
237
216
|
def _expected_route(state: dict, value: str | None) -> None:
|
|
@@ -370,6 +370,15 @@ def run(args):
|
|
|
370
370
|
with _task_lock(child_dir):
|
|
371
371
|
path = runtime_path(root, child_dir.name)
|
|
372
372
|
operation = args.command.removeprefix("delegate-")
|
|
373
|
+
if operation == "inspect":
|
|
374
|
+
from .task_workflow import _load
|
|
375
|
+
|
|
376
|
+
child, _ = _load(child_dir)
|
|
377
|
+
if child.get("status") in {"completed", "cancelled"}:
|
|
378
|
+
record = resolve_record(root, child_dir, child)
|
|
379
|
+
print(json.dumps({"record": record, "historical": True,
|
|
380
|
+
"observations": {}, "candidates": {}}, ensure_ascii=False))
|
|
381
|
+
return 0
|
|
373
382
|
if operation == "bind":
|
|
374
383
|
if getattr(args, "result_path", None):
|
|
375
384
|
fail("legacy --result-path cannot start protocol v1; reconcile old attempts first")
|
|
@@ -900,6 +900,10 @@ def main() -> int:
|
|
|
900
900
|
migration_mode.add_argument("--apply", action="store_true", help="Recheck and apply the migration")
|
|
901
901
|
migration_mode.add_argument("--recover", action="store_true", help="Roll back an interrupted relocation")
|
|
902
902
|
|
|
903
|
+
p_runtime = subparsers.add_parser("runtime", help="Preview retired Trellis task projections and anchors")
|
|
904
|
+
p_runtime.add_argument("dir", nargs="?", help="Optional existing task scope")
|
|
905
|
+
p_runtime.add_argument("--confirm", help="Exact digest from a fresh native preview")
|
|
906
|
+
|
|
903
907
|
args = parser.parse_args()
|
|
904
908
|
|
|
905
909
|
if os.environ.get("TRELLIS_DELEGATION_CONTEXT") and args.command not in {"current", "list", "list-context", "validate"}:
|
|
@@ -911,6 +915,7 @@ def main() -> int:
|
|
|
911
915
|
return 1
|
|
912
916
|
|
|
913
917
|
from common.task_move import cmd_migrate_layout, layout_lock, require_settled_layout
|
|
918
|
+
from common.task_runtime import cmd_runtime
|
|
914
919
|
|
|
915
920
|
commands = {
|
|
916
921
|
"create": cmd_create,
|
|
@@ -937,6 +942,7 @@ def main() -> int:
|
|
|
937
942
|
"remove-subtask": cmd_remove_subtask,
|
|
938
943
|
"list": cmd_list,
|
|
939
944
|
"migrate-layout": cmd_migrate_layout,
|
|
945
|
+
"runtime": cmd_runtime,
|
|
940
946
|
}
|
|
941
947
|
|
|
942
948
|
try:
|
|
@@ -180,6 +180,10 @@ flowchart LR
|
|
|
180
180
|
|
|
181
181
|
只有交付审查与现场收尾阶段结果获接受且必需资源安全时才使用 `complete`。只有用户明确撤回并完成交付审查与现场收尾阶段中的取消审查后才使用 `cancel --reason`。正式会话交接仍是独立操作。
|
|
182
182
|
|
|
183
|
+
完成或取消只退出当前任务投影,不删除任务产物、交接包或证据。需要清理退役运行资产时,使用 `python3 ./.trellis/scripts/task.py runtime [<task>]` 先预览,再以当前摘要 `--confirm <digest>` 精确执行。该入口仅处理已知空业务 session、旧更新提示及完成协议切换且无使用者或等待者的旧锁;固定 `task-layout.lock`、有效 ownership/continuity、未知字段与恢复材料始终保留。无法核验旧 writer 或文件描述符时保留对应旧锁,不以空文件、时间或任务终态推定可删。
|
|
184
|
+
|
|
185
|
+
Teamwork 的报告、工作日志、事件及诊断先审查用途与引用,再使用其原生 `cleanup-artifacts`、`rm` 或 `prune`;任务完成不是删除证据的授权。正式交接包及其生命周期材料由 handoff owner 保留、压缩和恢复,不能用 Task runtime 或全目录删除代替。终态任务可通过 `delegate-inspect` 读取历史记录;历史 manifest 中缺失的引用只作诊断,不自动修改已接受产物或恢复旧授权。
|
|
186
|
+
|
|
183
187
|
## 跨组件职责
|
|
184
188
|
|
|
185
189
|
| 组件 | 在任务路线中的职责 |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pennixrv/trellis",
|
|
3
|
-
"version": "0.7.2-beta.
|
|
3
|
+
"version": "0.7.2-beta.19",
|
|
4
4
|
"description": "AI capabilities grow like ivy — Trellis provides the structure to guide them along a disciplined path",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"inquirer": "^9.3.7",
|
|
36
36
|
"undici": "^6.21.0",
|
|
37
37
|
"zod": "^4.4.2",
|
|
38
|
-
"@pennixrv/trellis-core": "0.7.2-beta.
|
|
38
|
+
"@pennixrv/trellis-core": "0.7.2-beta.19"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@eslint/js": "^9.18.0",
|