@caddis/cli 0.4.97 → 0.4.98
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/bundles/antigravity-plugin/plugin.json +1 -1
- package/bundles/antigravity-plugin/repo_hygiene.py +134 -20
- package/bundles/antigravity-plugin/scripts/__pycache__/caddis_exit.cpython-311.pyc +0 -0
- package/bundles/antigravity-plugin/scripts/__pycache__/caddis_file_lock.cpython-311.pyc +0 -0
- package/bundles/antigravity-plugin/scripts/__pycache__/caddis_frontmatter.cpython-311.pyc +0 -0
- package/bundles/antigravity-plugin/scripts/__pycache__/caddis_redact.cpython-311.pyc +0 -0
- package/bundles/antigravity-plugin/scripts/__pycache__/caddis_roadmap.cpython-311.pyc +0 -0
- package/bundles/antigravity-plugin/scripts/__pycache__/caddis_rows.cpython-311.pyc +0 -0
- package/bundles/antigravity-plugin/scripts/__pycache__/caddis_status.cpython-311.pyc +0 -0
- package/bundles/antigravity-plugin/scripts/__pycache__/caddis_tidy.cpython-311.pyc +0 -0
- package/bundles/antigravity-plugin/scripts/__pycache__/caddis_todo.cpython-311.pyc +0 -0
- package/bundles/antigravity-plugin/scripts/__pycache__/caddis_workstreams.cpython-311.pyc +0 -0
- package/bundles/antigravity-plugin/scripts/__pycache__/caddis_worktree_safety.cpython-311.pyc +0 -0
- package/bundles/antigravity-plugin/scripts/caddis_gate.py +18 -1
- package/bundles/antigravity-plugin/scripts/caddis_guide.json +2 -2
- package/bundles/antigravity-plugin/scripts/caddis_handoff.py +235 -0
- package/bundles/antigravity-plugin/scripts/caddis_hub_collect.py +23 -12
- package/bundles/antigravity-plugin/scripts/caddis_review.py +12 -0
- package/bundles/antigravity-plugin/scripts/caddis_tidy.py +152 -51
- package/bundles/antigravity-plugin/scripts/caddis_todo.py +136 -17
- package/bundles/antigravity-plugin/scripts/schemas/hub-collect.schema.json +60 -1
- package/bundles/antigravity-plugin/scripts/schemas/hub-plans.schema.json +60 -1
- package/bundles/antigravity-plugin/scripts/setup_project_ai.py +60 -2
- package/bundles/antigravity-plugin/skills/cross-review/SKILL.md +6 -0
- package/bundles/antigravity-plugin/skills/handoff/SKILL.md +80 -15
- package/bundles/antigravity-plugin/skills/implement/SKILL.md +6 -0
- package/bundles/antigravity-plugin/skills/park/SKILL.md +7 -2
- package/bundles/antigravity-plugin/skills/pr-merge/SKILL.md +1 -0
- package/bundles/antigravity-plugin/skills/ship-pr/SKILL.md +1 -0
- package/bundles/manifest.json +2 -2
- package/dist/cli.js +71 -14
- package/dist/export/assets/export-B3cUoxL1.js +150 -0
- package/dist/export/assets/export-DQss44R1.css +1 -0
- package/dist/export/index.html +2 -2
- package/dist/ui/assets/Activity-CvEIJlnE.js +6 -0
- package/dist/ui/assets/{Guide-D-lZVEKf.js → Guide-BxS9L55s.js} +1 -1
- package/dist/ui/assets/Guide-DTd261-c.css +1 -0
- package/dist/ui/assets/RoadmapTab-CqlWs7dJ.js +31 -0
- package/dist/ui/assets/index-9pdDzLVp.css +1 -0
- package/dist/ui/assets/index-DSxeWPax.js +231 -0
- package/dist/ui/index.html +2 -2
- package/package.json +1 -1
- package/dist/export/assets/export-B5Lzo-9e.css +0 -1
- package/dist/export/assets/export-PF4z_ff4.js +0 -150
- package/dist/ui/assets/Activity-DN1XBfsH.js +0 -6
- package/dist/ui/assets/Guide-D-Zy4cUT.css +0 -1
- package/dist/ui/assets/RoadmapTab-tqQd2sYq.js +0 -31
- package/dist/ui/assets/index-CWslZIzV.js +0 -231
- package/dist/ui/assets/index-CwgRPpjT.css +0 -1
- package/dist/ui/assets/time-D00tu2ZP.js +0 -1
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
2
|
"""Batched hub collector: every repo's roadmaps, plans and relays, plus agy spend and the guide, as one JSON object.
|
|
3
3
|
|
|
4
|
-
Usage: caddis_hub_collect.py --repos PATH [PATH ...] [--only roadmaps,plans,relays,spend,guide] [--known PATH=FP ...]
|
|
4
|
+
Usage: caddis_hub_collect.py --repos PATH [PATH ...] [--only roadmaps,plans,relays,spend,guide] [--known PATH=FP ...]
|
|
5
|
+
[--prs-file PATH] [--done-known PATH=TREE ...] --json
|
|
5
6
|
|
|
6
7
|
The hub runs this once per cycle. It runs in ONE Python process for all repos (hub rule R15, spawn cost L8). It
|
|
7
8
|
never calls gh, claude or agy, and never runs `git fetch`: the roadmap reader sees the origin refs the repo
|
|
@@ -70,9 +71,11 @@ def _fetch_time(common: Path) -> int | None:
|
|
|
70
71
|
return None
|
|
71
72
|
|
|
72
73
|
|
|
73
|
-
def _plans_json(root: Path, prs: list[dict] | None = None, off_reason: str | None = None
|
|
74
|
+
def _plans_json(root: Path, prs: list[dict] | None = None, off_reason: str | None = None,
|
|
75
|
+
done_known: str | None = None) -> dict:
|
|
74
76
|
"""Plans from the origin ref the repo already has (R15: local git only), so a pushed Tracker edit shows with no
|
|
75
|
-
pull. A folder that is not a git checkout, or has no origin default branch, reads the working tree.
|
|
77
|
+
pull. A folder that is not a git checkout, or has no origin default branch, reads the working tree.
|
|
78
|
+
`done_known` is the done tree the hub already holds: the same tree comes back as `unchanged` (D2)."""
|
|
76
79
|
branch = None
|
|
77
80
|
common = git_common_dir(Path(root))
|
|
78
81
|
if common is None:
|
|
@@ -98,7 +101,8 @@ def _plans_json(root: Path, prs: list[dict] | None = None, off_reason: str | Non
|
|
|
98
101
|
branch = None
|
|
99
102
|
finally:
|
|
100
103
|
roadmap.FETCH = saved
|
|
101
|
-
|
|
104
|
+
extra = {"done_known": done_known} if done_known is not None else {} # an older plans_json takes no such key
|
|
105
|
+
out = _sibling("caddis_todo").plans_json(root, branch=branch, prs=prs, **extra)
|
|
102
106
|
if common is not None and isinstance(out, dict):
|
|
103
107
|
out["fetched_at"] = _fetch_time(common)
|
|
104
108
|
if off_reason is not None and isinstance(out, dict):
|
|
@@ -264,20 +268,22 @@ def fingerprint(repo: Path, prs: list[dict] | None = None) -> str:
|
|
|
264
268
|
return hashlib.sha256(json.dumps(sorted(rows)).encode("utf-8")).hexdigest()
|
|
265
269
|
|
|
266
270
|
|
|
267
|
-
def parse_known(values: list[str]) -> dict[str, str]:
|
|
271
|
+
def parse_known(values: list[str], flag: str = "--known") -> dict[str, str]:
|
|
272
|
+
"""`PATH=VALUE` items as {PATH: VALUE}, split on the last `=`. Used for --known and --done-known."""
|
|
268
273
|
known: dict[str, str] = {}
|
|
269
274
|
for value in values:
|
|
270
275
|
if "=" not in value:
|
|
271
|
-
raise ValueError(f"bad
|
|
276
|
+
raise ValueError(f"bad {flag} value: {value}")
|
|
272
277
|
path, fp = value.rsplit("=", 1)
|
|
273
278
|
if not path or not fp:
|
|
274
|
-
raise ValueError(f"bad
|
|
279
|
+
raise ValueError(f"bad {flag} value: {value}")
|
|
275
280
|
known[path] = fp
|
|
276
281
|
return known
|
|
277
282
|
|
|
278
283
|
|
|
279
284
|
def collect_repo(path: str, kinds: tuple[str, ...], known: dict[str, str] | None = None,
|
|
280
|
-
prs_map: dict[str, list[dict]] | None = None, overlay: bool = False
|
|
285
|
+
prs_map: dict[str, list[dict]] | None = None, overlay: bool = False,
|
|
286
|
+
done_known: dict[str, str] | None = None) -> dict:
|
|
281
287
|
repo = Path(path)
|
|
282
288
|
if not repo.is_dir():
|
|
283
289
|
return {"path": path, "error": "not a folder"}
|
|
@@ -301,7 +307,8 @@ def collect_repo(path: str, kinds: tuple[str, ...], known: dict[str, str] | None
|
|
|
301
307
|
continue
|
|
302
308
|
try:
|
|
303
309
|
if kind == "plans":
|
|
304
|
-
entry[kind] = _plans_json(repo, prs=repo_prs, off_reason=off
|
|
310
|
+
entry[kind] = _plans_json(repo, prs=repo_prs, off_reason=off,
|
|
311
|
+
done_known=(done_known or {}).get(path)) # keyed like --known
|
|
305
312
|
else:
|
|
306
313
|
entry[kind] = _REPO_COLLECTORS[kind](repo)
|
|
307
314
|
except Exception as exc:
|
|
@@ -310,9 +317,10 @@ def collect_repo(path: str, kinds: tuple[str, ...], known: dict[str, str] | None
|
|
|
310
317
|
|
|
311
318
|
|
|
312
319
|
def collect(repos: list[str], kinds: tuple[str, ...], known: dict[str, str] | None = None,
|
|
313
|
-
prs_map: dict[str, list[dict]] | None = None, overlay: bool = False
|
|
320
|
+
prs_map: dict[str, list[dict]] | None = None, overlay: bool = False,
|
|
321
|
+
done_known: dict[str, str] | None = None) -> dict:
|
|
314
322
|
out: dict = {"schema": SCHEMA, "generated_at": datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ"),
|
|
315
|
-
"repos": [collect_repo(path, kinds, known, prs_map, overlay) for path in repos]}
|
|
323
|
+
"repos": [collect_repo(path, kinds, known, prs_map, overlay, done_known) for path in repos]}
|
|
316
324
|
for kind, call in (("spend", _spend_json), ("guide", _guide_json)):
|
|
317
325
|
if kind not in kinds:
|
|
318
326
|
continue
|
|
@@ -339,6 +347,8 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
339
347
|
parser.add_argument("--only", default=",".join(KINDS), help="comma list of: " + ", ".join(KINDS))
|
|
340
348
|
parser.add_argument("--known", nargs="+", default=[], metavar="PATH=FP")
|
|
341
349
|
parser.add_argument("--prs-file", default=None, metavar="PATH")
|
|
350
|
+
parser.add_argument("--done-known", nargs="+", default=[], metavar="PATH=TREE",
|
|
351
|
+
help="the done-plans tree the hub holds per repo; the same tree comes back as unchanged")
|
|
342
352
|
parser.add_argument("--json", action="store_true", required=True)
|
|
343
353
|
args = parser.parse_args(argv)
|
|
344
354
|
kinds = tuple(k.strip() for k in args.only.split(",") if k.strip())
|
|
@@ -347,11 +357,12 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
347
357
|
parser.error(f"unknown --only kind: {', '.join(unknown) or '(empty)'}; use {', '.join(KINDS)}")
|
|
348
358
|
try:
|
|
349
359
|
known = parse_known(args.known)
|
|
360
|
+
done_known = parse_known(args.done_known, "--done-known")
|
|
350
361
|
except ValueError as exc:
|
|
351
362
|
parser.error(str(exc))
|
|
352
363
|
overlay = args.prs_file is not None
|
|
353
364
|
prs_map = load_prs(args.prs_file) if overlay else None
|
|
354
|
-
print(json.dumps(collect(args.repos, kinds, known, prs_map, overlay), ensure_ascii=False))
|
|
365
|
+
print(json.dumps(collect(args.repos, kinds, known, prs_map, overlay, done_known), ensure_ascii=False))
|
|
355
366
|
return 0
|
|
356
367
|
|
|
357
368
|
|
|
@@ -527,6 +527,18 @@ def phase_risk(plan: Path, n: int | str) -> str:
|
|
|
527
527
|
return max(values, key=_RISK_ORDER.index) if values else "normal"
|
|
528
528
|
|
|
529
529
|
|
|
530
|
+
_TYPE_RE = re.compile(r"^[\s>*_`~#+\-\[\]]*type\s*[*_`~]*\s*:[*_`~\s]*([a-z]+)", re.IGNORECASE)
|
|
531
|
+
|
|
532
|
+
|
|
533
|
+
def phase_type(plan: Path, n: int | str) -> str | None:
|
|
534
|
+
"""The phase's `Type:` value: the first word of the first `Type:` line, lower case. None when there is none."""
|
|
535
|
+
for raw in phase_section(plan, n).splitlines():
|
|
536
|
+
m = _TYPE_RE.match(_normalize(raw))
|
|
537
|
+
if m:
|
|
538
|
+
return m.group(1).lower()
|
|
539
|
+
return None
|
|
540
|
+
|
|
541
|
+
|
|
530
542
|
def plan_card(plan: Path, n: int | str, plan_ref: str | None = None) -> str:
|
|
531
543
|
"""The review card for one plan phase: its heading, Goal, Touches and Exit gate."""
|
|
532
544
|
lines = phase_section(plan, n).splitlines()
|
|
@@ -42,14 +42,23 @@ DESIGN (locked, see the plan doc — do not re-litigate here)
|
|
|
42
42
|
crash/scratch files at the repo root (`*.stackdump`, `run*.ps1`, `nul`, ...); a `.caddis/` file whose
|
|
43
43
|
`type:` belongs to another folder; a plan `status: current` with no commit for 14 days. The first is
|
|
44
44
|
repo-wide and so never appears under `--commit-range`; the other two follow the range like any file.
|
|
45
|
-
- `--only <
|
|
46
|
-
stamped. `/implement` closes the plan it finished with it,
|
|
47
|
-
is never swept
|
|
45
|
+
- `--only <path> [<path> ...]` limits a run to those top-level plans, prompts and parking-lot
|
|
46
|
+
items: nothing else is moved or stamped. `/implement` closes the plan it finished with it, and
|
|
47
|
+
`/handoff` the artifacts this session closed, so another session's finished work is never swept in.
|
|
48
|
+
- `--apply` needs a scope (2026-11-07: a handoff's bare `--apply` moved and staged 5 committed items
|
|
49
|
+
of other sessions): `--only <path>...` for this session's artifacts, or `--all` for an owner's
|
|
50
|
+
explicit sweep. A bare `--apply` exits 1 and changes nothing. The dry run needs no scope.
|
|
51
|
+
- Under `--all` a file with uncommitted changes never moves. Under `--only` a named file moves even with
|
|
52
|
+
an uncommitted edit (its own status flip), and its working copy is staged at the new path.
|
|
53
|
+
- `--apply` refuses when the index already holds staged changes (other than a named file's), so its own
|
|
54
|
+
staged moves are alone there; it stages each status flip with its rename; it never plain-renames a tracked file when
|
|
55
|
+
`git mv` fails. It prints one `STAGED:` line per move and a pathspec `git commit` line to commit them.
|
|
48
56
|
|
|
49
57
|
Usage:
|
|
50
58
|
python scripts/caddis_tidy.py # report only (default = dry-run)
|
|
51
|
-
python scripts/caddis_tidy.py --apply # actually move terminal-status artifacts
|
|
52
59
|
python scripts/caddis_tidy.py --apply --only .caddis/plans/<plan>.md # close this plan only
|
|
60
|
+
python scripts/caddis_tidy.py --apply --only .caddis/parking-lot/<item>.md .caddis/prompts/<p>.md
|
|
61
|
+
python scripts/caddis_tidy.py --apply --all # owner sweep: move every terminal-status artifact
|
|
53
62
|
python scripts/caddis_tidy.py --check # conformance check; exit 1 on a violation
|
|
54
63
|
python scripts/caddis_tidy.py --repo-root <p> # scan a different repo (default: cwd)
|
|
55
64
|
python scripts/caddis_tidy.py --commit-range origin/main..HEAD # also read parking trailers
|
|
@@ -366,8 +375,10 @@ class Report:
|
|
|
366
375
|
tracker_done_open: list[tuple[Path, str]] = field(default_factory=list)
|
|
367
376
|
# --commit-range only: repo-relative posix paths the range changed.
|
|
368
377
|
in_range: set[str] | None = None
|
|
369
|
-
# --only only: named
|
|
378
|
+
# --only only: named files that did not move, with the reason.
|
|
370
379
|
not_moved: list[tuple[Path, str]] = field(default_factory=list)
|
|
380
|
+
# --apply only: moves `git mv` staged, as (old path, new path). Each waits in the index for a commit.
|
|
381
|
+
staged: list[tuple[Path, Path]] = field(default_factory=list)
|
|
371
382
|
# --apply only: files left alone because git shows uncommitted changes in them (another
|
|
372
383
|
# session's edit in a shared checkout). Neither moved nor rewritten; not an error.
|
|
373
384
|
dirty_skipped: list[Path] = field(default_factory=list)
|
|
@@ -404,7 +415,7 @@ def _is_git_repo(repo_root: Path) -> bool:
|
|
|
404
415
|
|
|
405
416
|
|
|
406
417
|
def _run_git_mv(repo_root: Path, src: Path, dst: Path) -> bool:
|
|
407
|
-
"""Returns True on success.
|
|
418
|
+
"""Returns True on success. On a failure the caller decides: a plain rename only for an untracked file."""
|
|
408
419
|
try:
|
|
409
420
|
result = subprocess.run(
|
|
410
421
|
["git", "mv", "--", str(src), str(dst)],
|
|
@@ -448,19 +459,51 @@ def _dirty_paths(repo_root: Path) -> set[str] | None:
|
|
|
448
459
|
return dirty
|
|
449
460
|
|
|
450
461
|
|
|
451
|
-
def
|
|
452
|
-
"""
|
|
453
|
-
|
|
462
|
+
def _is_tracked(repo_root: Path, path: Path) -> bool:
|
|
463
|
+
"""True when git tracks `path`, or when git cannot say (fail closed: never plain-rename then)."""
|
|
464
|
+
try:
|
|
465
|
+
rel_path = path.relative_to(repo_root).as_posix()
|
|
466
|
+
except ValueError:
|
|
467
|
+
return True
|
|
468
|
+
done = _git_run(repo_root, "ls-files", "--error-unmatch", "--", rel_path)
|
|
469
|
+
if done is None or done.returncode == 0:
|
|
470
|
+
return True
|
|
471
|
+
return b"did not match" not in (done.stderr or b"")
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
def _move_one(repo_root: Path, src: Path, report: Report, restage: bool = False) -> None:
|
|
475
|
+
"""One named `git mv` into the sibling `done/`; a plain rename only for a file git does not
|
|
476
|
+
track (no repo, or an untracked file). A tracked file whose `git mv` failed (for example a peer
|
|
477
|
+
holds `index.lock`) stays where it is, with an error: a plain rename would leave a tracked
|
|
478
|
+
delete that a commit of all changes records, and the file would drop out of history.
|
|
479
|
+
`restage` also stages the moved file's content (tidy rewrote its status before the move), so the
|
|
480
|
+
index copy in `done/` holds the new status. Only called once every destination is known to be free."""
|
|
454
481
|
dst = _destination(src)
|
|
455
482
|
dst.parent.mkdir(parents=True, exist_ok=True)
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
483
|
+
if _is_git_repo(repo_root) and _is_tracked(repo_root, src):
|
|
484
|
+
if not _run_git_mv(repo_root, src, dst):
|
|
485
|
+
report.errors.append(f"git mv failed for tracked {src.relative_to(repo_root).as_posix()}: "
|
|
486
|
+
"left in place (run again when no other git command runs)")
|
|
487
|
+
return
|
|
488
|
+
if restage:
|
|
489
|
+
added = _git_run(repo_root, "add", "--", dst.relative_to(repo_root).as_posix())
|
|
490
|
+
if added is None or added.returncode != 0:
|
|
491
|
+
report.errors.append(f"moved, but the status flip of {dst.relative_to(repo_root).as_posix()} "
|
|
492
|
+
"is not staged: git add it by name before you commit")
|
|
493
|
+
report.staged.append((src, dst))
|
|
494
|
+
else:
|
|
460
495
|
src.rename(dst)
|
|
461
496
|
report.moved.append(src)
|
|
462
497
|
|
|
463
498
|
|
|
499
|
+
def _staged_paths(repo_root: Path) -> list[str] | None:
|
|
500
|
+
"""Repo-relative paths the index holds as staged changes; None when git cannot say."""
|
|
501
|
+
done = _git_run(repo_root, "diff", "--cached", "--name-only", "-z")
|
|
502
|
+
if done is None or done.returncode != 0:
|
|
503
|
+
return None
|
|
504
|
+
return [p for p in done.stdout.decode("utf-8", "replace").split("\0") if p]
|
|
505
|
+
|
|
506
|
+
|
|
464
507
|
@dataclass
|
|
465
508
|
class Resolution:
|
|
466
509
|
"""One parking-lot trailer from one commit in the range."""
|
|
@@ -661,19 +704,23 @@ def dirty_paths(root: Path, paths: set[str]) -> list[str]:
|
|
|
661
704
|
return sorted(dirty)
|
|
662
705
|
|
|
663
706
|
|
|
664
|
-
def _only_targets(root: Path, only: list[str]) -> tuple[
|
|
665
|
-
"""The resolved `--only`
|
|
666
|
-
|
|
667
|
-
|
|
707
|
+
def _only_targets(root: Path, only: list[str]) -> tuple[dict[Path, str], list[str]]:
|
|
708
|
+
"""The resolved `--only` files with their kind, and a message for each name that is not a
|
|
709
|
+
top-level file of `.caddis/plans/`, `.caddis/prompts/` or `.caddis/parking-lot/` (a `done/`
|
|
710
|
+
subfolder, another folder and a path outside the repo are all refused)."""
|
|
711
|
+
homes = {(root / ".caddis" / kind).resolve(): kind for kind in _KINDS}
|
|
712
|
+
targets: dict[Path, str] = {}
|
|
668
713
|
problems: list[str] = []
|
|
669
714
|
for name in only:
|
|
670
715
|
path = Path(name)
|
|
671
716
|
path = (path if path.is_absolute() else root / path).resolve()
|
|
672
|
-
|
|
717
|
+
kind = homes.get(path.parent)
|
|
718
|
+
if (kind is None or path.suffix != ".md" or path.name.lower() == "readme.md"
|
|
673
719
|
or not path.is_file()):
|
|
674
|
-
problems.append(f"--only {name}: not a top-level
|
|
720
|
+
problems.append(f"--only {name}: not a top-level file in .caddis/plans/, .caddis/prompts/ "
|
|
721
|
+
"or .caddis/parking-lot/")
|
|
675
722
|
else:
|
|
676
|
-
targets
|
|
723
|
+
targets[path] = kind
|
|
677
724
|
return targets, problems
|
|
678
725
|
|
|
679
726
|
|
|
@@ -856,7 +903,8 @@ def tidy(repo_root: Path, apply: bool = False, check: bool = False,
|
|
|
856
903
|
|
|
857
904
|
Nothing is written until the whole set is known and every destination is free. One existing
|
|
858
905
|
`done/<name>` (or an unreadable commit range) leaves every file exactly as it was. `only`
|
|
859
|
-
names the plans this run may touch; nothing else is moved or
|
|
906
|
+
names the plans, prompts and parking-lot items this run may touch; nothing else is moved or
|
|
907
|
+
stamped, and no commit trailer is read.
|
|
860
908
|
"""
|
|
861
909
|
report = Report()
|
|
862
910
|
if commit_range is not None:
|
|
@@ -878,19 +926,22 @@ def tidy(repo_root: Path, apply: bool = False, check: bool = False,
|
|
|
878
926
|
f"{', '.join(dirty)}; commit them first")
|
|
879
927
|
only_set: set[Path] | None = None
|
|
880
928
|
if only is not None:
|
|
881
|
-
|
|
882
|
-
if problems or not
|
|
883
|
-
report.errors.extend(problems or ["--only names no
|
|
929
|
+
only_kinds, problems = _only_targets(repo_root, only)
|
|
930
|
+
if problems or not only_kinds:
|
|
931
|
+
report.errors.extend(problems or ["--only names no file"])
|
|
884
932
|
report.refused = True
|
|
885
933
|
return report
|
|
886
|
-
|
|
934
|
+
only_set = set(only_kinds)
|
|
935
|
+
kinds = tuple(k for k in _KINDS if k in only_kinds.values()) # only the named files' folders
|
|
887
936
|
moves: list[Path] = []
|
|
937
|
+
named: list[tuple[str, Item]] = [] # --only: the named files this run read, with their kind
|
|
888
938
|
rewrites: dict[Path, str] = {} # applied before the moves, so a failed move leaves a
|
|
889
939
|
# finished status at the top level, where the next run moves it by status alone
|
|
890
940
|
for kind in kinds:
|
|
891
941
|
items = scan(repo_root / ".caddis" / kind)
|
|
892
942
|
if only_set is not None:
|
|
893
943
|
items = [item for item in items if item.path.resolve() in only_set]
|
|
944
|
+
named.extend((kind, item) for item in items)
|
|
894
945
|
for item in items:
|
|
895
946
|
if kind == PARKING_LOT_DIR:
|
|
896
947
|
_check_parking_lot_item(item, report)
|
|
@@ -941,7 +992,7 @@ def tidy(repo_root: Path, apply: bool = False, check: bool = False,
|
|
|
941
992
|
continue
|
|
942
993
|
if item.phases_all_done:
|
|
943
994
|
report.stale_suspects.append(item.path)
|
|
944
|
-
if commit_range is not None and PARKING_LOT_DIR in kinds:
|
|
995
|
+
if commit_range is not None and PARKING_LOT_DIR in kinds and only_set is None:
|
|
945
996
|
_plan_parked(repo_root, commit_range, report, moves, rewrites)
|
|
946
997
|
if check:
|
|
947
998
|
_check_wider(repo_root, report)
|
|
@@ -951,14 +1002,18 @@ def tidy(repo_root: Path, apply: bool = False, check: bool = False,
|
|
|
951
1002
|
planned = {src.resolve() for src in moves}
|
|
952
1003
|
# A plan held for open Tracker rows is already reported (exit 2); it is not a failed request.
|
|
953
1004
|
held = {p.resolve() for p, _ in report.open_rows_held}
|
|
954
|
-
for item in
|
|
1005
|
+
for kind, item in named:
|
|
955
1006
|
if item.path.resolve() not in planned and item.path.resolve() not in held:
|
|
956
|
-
|
|
957
|
-
|
|
1007
|
+
if classify_status(item.status, kind) == "none":
|
|
1008
|
+
why = "no frontmatter status"
|
|
1009
|
+
elif kind == "plans":
|
|
1010
|
+
why = f"status {item.status} and the Tracker is not all done"
|
|
1011
|
+
else:
|
|
1012
|
+
why = f"status {item.status} is not finished"
|
|
958
1013
|
report.not_moved.append((item.path, why))
|
|
959
|
-
seen = {item.path.resolve() for item in
|
|
1014
|
+
seen = {item.path.resolve() for _, item in named}
|
|
960
1015
|
for path in sorted(only_set - seen):
|
|
961
|
-
report.not_moved.append((path, "not a
|
|
1016
|
+
report.not_moved.append((path, "not a file this run reads"))
|
|
962
1017
|
|
|
963
1018
|
report.collisions.extend(src for src in moves if _collides(src))
|
|
964
1019
|
if not apply:
|
|
@@ -969,33 +1024,56 @@ def tidy(repo_root: Path, apply: bool = False, check: bool = False,
|
|
|
969
1024
|
# Past this point only an I/O failure can stop the run. Every step is safe to repeat: a
|
|
970
1025
|
# written status or stamp that did not move yet is moved by status on the next run, and a
|
|
971
1026
|
# note already present is not appended again.
|
|
972
|
-
#
|
|
973
|
-
# that is another session's edit, and a `git mv` stages it for whoever commits next
|
|
974
|
-
# serve-sight).
|
|
975
|
-
#
|
|
976
|
-
|
|
1027
|
+
# A file with uncommitted changes to tracked content: under `--all` it is never moved, staged or rewritten.
|
|
1028
|
+
# In a shared checkout that is another session's edit, and a `git mv` stages it for whoever commits next
|
|
1029
|
+
# (2026-10-15, serve-sight). Under `--only` the caller owns each named file, and its uncommitted edit is
|
|
1030
|
+
# usually the status flip that finished it, so a named file moves anyway and its working copy is staged at
|
|
1031
|
+
# the new path (2026-11-08). This check runs before tidy writes anything, so a status that tidy itself
|
|
1032
|
+
# writes below does not count: that plan moves in this run, its new content staged with the rename.
|
|
1033
|
+
named_dirty: set[Path] = set()
|
|
1034
|
+
if _is_git_repo(repo_root) and (moves or rewrites):
|
|
1035
|
+
root_abs = repo_root.resolve()
|
|
1036
|
+
|
|
1037
|
+
def _rel(path: Path) -> str | None:
|
|
1038
|
+
try:
|
|
1039
|
+
return path.resolve().relative_to(root_abs).as_posix()
|
|
1040
|
+
except ValueError:
|
|
1041
|
+
return None
|
|
1042
|
+
|
|
1043
|
+
# Owned: a file `--only` names that this run moves. A named file that stays (a held plan) is not.
|
|
1044
|
+
owned = {_rel(p) for p in moves} if only_set is not None else set()
|
|
1045
|
+
# Tidy's staged moves must be alone in the index: a staged change of this or another session would
|
|
1046
|
+
# go into the same next commit (2026-11-07). Only a named file that this run moves may already be staged.
|
|
1047
|
+
staged = _staged_paths(repo_root)
|
|
1048
|
+
if staged is None:
|
|
1049
|
+
return report.refuse("git could not list the staged changes; nothing was moved")
|
|
1050
|
+
staged = [path for path in staged if path not in owned]
|
|
1051
|
+
if staged:
|
|
1052
|
+
return report.refuse("the index already holds staged changes: " + ", ".join(staged[:10])
|
|
1053
|
+
+ (" ..." if len(staged) > 10 else "")
|
|
1054
|
+
+ "; commit or unstage them first. Nothing was moved.")
|
|
977
1055
|
dirty = _dirty_paths(repo_root)
|
|
978
1056
|
if dirty is None:
|
|
979
1057
|
report.dirty_check_failed = "git status could not be read"
|
|
980
1058
|
return report
|
|
981
1059
|
|
|
982
|
-
def _is_dirty(path: Path) -> bool:
|
|
983
|
-
try:
|
|
984
|
-
rel_path = path.relative_to(repo_root).as_posix()
|
|
985
|
-
except ValueError:
|
|
986
|
-
return True # cannot place it in the repo: fail closed, leave it alone
|
|
987
|
-
return rel_path in dirty
|
|
988
|
-
|
|
989
1060
|
for path in sorted({*moves, *rewrites}, key=str):
|
|
990
|
-
|
|
991
|
-
|
|
1061
|
+
rel_path = _rel(path)
|
|
1062
|
+
if rel_path is None: # cannot place it in the repo: fail closed, leave it alone
|
|
1063
|
+
if path not in report.dirty_skipped:
|
|
1064
|
+
report.dirty_skipped.append(path)
|
|
1065
|
+
elif rel_path in dirty:
|
|
1066
|
+
if rel_path in owned:
|
|
1067
|
+
named_dirty.add(path)
|
|
1068
|
+
elif path not in report.dirty_skipped:
|
|
1069
|
+
report.dirty_skipped.append(path)
|
|
992
1070
|
moves = [src for src in moves if src not in report.dirty_skipped]
|
|
993
1071
|
rewrites = {path: text for path, text in rewrites.items() if path not in report.dirty_skipped}
|
|
994
1072
|
try:
|
|
995
1073
|
for path, text in rewrites.items():
|
|
996
1074
|
atomic_write(path, text)
|
|
997
1075
|
for src in moves:
|
|
998
|
-
_move_one(repo_root, src, report)
|
|
1076
|
+
_move_one(repo_root, src, report, restage=src in rewrites or src in named_dirty)
|
|
999
1077
|
except (OSError, ValueError) as exc:
|
|
1000
1078
|
report.errors.append(f"stopped part-way, run again to finish: {exc}")
|
|
1001
1079
|
return report
|
|
@@ -1009,14 +1087,17 @@ def nudge_line(repo_root: Path) -> str | None:
|
|
|
1009
1087
|
except Exception:
|
|
1010
1088
|
return None
|
|
1011
1089
|
if report.collisions:
|
|
1012
|
-
#
|
|
1090
|
+
# Nothing can move while this stands, so do not send people to --apply.
|
|
1013
1091
|
return (f"[caddis] tidy is blocked by {len(report.collisions)} done/ name collision(s) "
|
|
1014
1092
|
"— run scripts/caddis_tidy.py to see them")
|
|
1015
1093
|
n = len(report.would_move)
|
|
1016
1094
|
if not n:
|
|
1017
1095
|
return None
|
|
1018
1096
|
plural = "artifact" if n == 1 else "artifacts"
|
|
1019
|
-
|
|
1097
|
+
# Never send people to /handoff for these: that invited a repo-wide sweep of other sessions' items
|
|
1098
|
+
# (2026-11-07). Each session closes its own; the owner may sweep.
|
|
1099
|
+
return (f"[caddis] {n} finished {plural} awaiting tidy — close your own with "
|
|
1100
|
+
"scripts/caddis_tidy.py --apply --only <path> (owner sweep: --all)")
|
|
1020
1101
|
|
|
1021
1102
|
|
|
1022
1103
|
# ── prune: old local state on fixed ages (R2 Phase 11) ──────────────────────────────────────────
|
|
@@ -1262,9 +1343,11 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
1262
1343
|
help="also read Resolves-Parked / Partly-Resolves-Parked trailers in these "
|
|
1263
1344
|
"commits only, e.g. origin/main..HEAD (default: read no trailers); "
|
|
1264
1345
|
"with --check, check only the files this range changed")
|
|
1265
|
-
ap.add_argument("--only", nargs="+", default=None, metavar="
|
|
1266
|
-
help="touch only these top-level
|
|
1267
|
-
"else is moved or stamped")
|
|
1346
|
+
ap.add_argument("--only", nargs="+", default=None, metavar="PATH",
|
|
1347
|
+
help="touch only these top-level files of .caddis/plans/, .caddis/prompts/ or "
|
|
1348
|
+
".caddis/parking-lot/ (this session's artifacts); nothing else is moved or stamped")
|
|
1349
|
+
ap.add_argument("--all", action="store_true",
|
|
1350
|
+
help="with --apply: move every finished artifact in the repo (an owner's explicit sweep)")
|
|
1268
1351
|
ap.add_argument("--prune", action="store_true",
|
|
1269
1352
|
help="list old local state under .caddis/ (with --apply: delete it)")
|
|
1270
1353
|
ap.add_argument("--temp", action="store_true",
|
|
@@ -1288,6 +1371,8 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
1288
1371
|
repo_root = Path(args.repo_root).resolve()
|
|
1289
1372
|
if args.json and not args.hygiene:
|
|
1290
1373
|
ap.error("--json only works together with --hygiene")
|
|
1374
|
+
if args.all and (args.hygiene or args.prune):
|
|
1375
|
+
ap.error("--all is for the mover (--apply), not --hygiene or --prune")
|
|
1291
1376
|
if args.hygiene:
|
|
1292
1377
|
if args.check or args.commit_range or args.only or args.prune or args.temp or args.verbose:
|
|
1293
1378
|
ap.error("--hygiene runs alone: not with --check, --commit-range, --only, --prune, --temp or --verbose")
|
|
@@ -1317,6 +1402,12 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
1317
1402
|
return 1 if (code or temp_part.errors) else 0
|
|
1318
1403
|
if args.only and args.check:
|
|
1319
1404
|
ap.error("--only is for --apply (or its dry run), not --check")
|
|
1405
|
+
if args.all and args.only:
|
|
1406
|
+
ap.error("--all and --only exclude each other: --only names this session's artifacts, --all sweeps all")
|
|
1407
|
+
if args.apply and not args.only and not args.all:
|
|
1408
|
+
# 2026-11-07: a bare --apply moved and staged 5 committed items that other sessions owned.
|
|
1409
|
+
print("ERROR: --apply needs --only <path>... (this session's artifacts) or --all (owner sweep)")
|
|
1410
|
+
return 1
|
|
1320
1411
|
report = tidy(repo_root, apply=args.apply, check=args.check, commit_range=args.commit_range,
|
|
1321
1412
|
only=args.only)
|
|
1322
1413
|
if report.refused:
|
|
@@ -1343,6 +1434,16 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
1343
1434
|
label = "moved" if args.apply else "would move"
|
|
1344
1435
|
for p in moved_or_would:
|
|
1345
1436
|
print(f" {label}: {rel(p)}")
|
|
1437
|
+
for old, new in report.staged:
|
|
1438
|
+
print(f" STAGED: {rel(old)} -> {rel(new)}")
|
|
1439
|
+
if report.staged:
|
|
1440
|
+
def arg(p: Path) -> str:
|
|
1441
|
+
return f'"{rel(p)}"' if " " in rel(p) else rel(p)
|
|
1442
|
+
|
|
1443
|
+
paths = " ".join(f"{arg(old)} {arg(new)}" for old, new in report.staged)
|
|
1444
|
+
print(" These moves are staged, not committed. Commit them, and only them, with:")
|
|
1445
|
+
print(f' git commit -m "chore(tidy): move finished artifacts to done/" -- {paths}')
|
|
1446
|
+
print(" Or undo each move with: git mv <new> <old>")
|
|
1346
1447
|
for p, rows in report.open_rows_held:
|
|
1347
1448
|
print(f" held (open Tracker rows): {rel(p)}: rows {', '.join(rows)}")
|
|
1348
1449
|
for p in report.dirty_skipped:
|