68 """Attach the ``sync`` subcommand."""
70 parser = subcommands.add_parser(
72 help=
"Render registry-backed filesystem artifacts.",
77 help=
"Registry SQLite path. Defaults to the discovery algorithm.",
82 help=
"Keep drifted local files instead of overwriting them.",
87 help=
"Report render actions without writing artifacts.",
92 choices=sorted(ALL_ARTIFACTS),
93 help=
"Render only this artifact kind. May be passed multiple times.",
95 parser.add_argument(
"--actor-slot", help=
"Actor slot. Defaults to active operator.")
96 parser.add_argument(
"--json", action=
"store_true")
97 parser.set_defaults(handler=_cmd_sync)
101 location = discover_registry_location(registry_path=args.registry)
104 actor_slot = args.actor_slot
or backend.active_operator_slot()
105 if actor_slot
is None:
106 print(
"no active operator slot found", file=sys.stderr)
108 lock = registry.acquire_lock(
112 metadata={
"command":
"sync"},
117 target_root=Path(location.workspace_root),
118 prefer_local=args.prefer_local,
119 dry_run=args.dry_run,
120 artifacts=args.artifact,
122 if args.prefer_local
and not args.dry_run:
124 _audit_sync(registry, actor_slot, report.to_dict())
127 for result
in report.results:
128 if result.drift_detected:
129 print(f
"drift detected: {result.artifact_path}", file=sys.stderr)
132 and result.action_taken ==
"skipped_local_kept"
133 and result.artifact_kind !=
"plan_status"
136 f
"prefer-local is unsupported for {result.artifact_kind}: "
137 f
"{result.artifact_path}",
141 print(json.dumps(report.to_dict(), indent=2, sort_keys=
True))
144 return 0
if report.ok
else 1
185 results: tuple[RenderResult, ...],
187 for result
in results:
188 if result.artifact_kind !=
"plan_status":
190 if result.action_taken !=
"skipped_local_kept":
192 row = plan_for_worktree(registry, result.artifact_path.parent)
195 previous_sha = str(row.get(
"body_sha256")
or "")
196 previous_observed = str(row.get(
"body_observed_at")
or registry.clock.now_wall())
197 new_sha = hashlib.sha256(result.artifact_path.read_bytes()).hexdigest()
200 plan_id=str(row[
"plan_id"]),
201 previous_body_sha256=previous_sha,
202 new_body_sha256=new_sha,
203 previous_body_observed_at=previous_observed,
204 new_body_observed_at=registry.clock.now_wall(),
205 actor_slot=actor_slot,
206 actor_type=
"human_operator",
207 command=
"sync --prefer-local plan-status",