Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion loopx/authority.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def _render_authority_markdown(

def render_authority_source_markdown(payload: PayloadView) -> str:
return _render_authority_markdown(
"LoopX Authority Source Registration",
"LoopX Authority Source Metadata Update" if payload.get("operation") == "update" else "LoopX Authority Source Registration",
payload,
entry_fields=(*_COMMON_MARKDOWN_ENTRY_FIELDS, "owner_status", "gate_status"),
include_registry=True,
Expand Down
66 changes: 47 additions & 19 deletions loopx/cli_commands/registry_authority.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
render_doc_registry_authority_import_markdown,
render_authority_source_markdown,
)
from .registry_authority_metadata import update_authority_source
from ..global_registry import sync_project_registry_to_global


Expand All @@ -22,6 +23,7 @@
REGISTRY_AUTHORITY_COMMANDS = {
"authority-sources",
"register-authority-source",
"update-authority-source",
"import-doc-registry-authority",
}

Expand All @@ -35,6 +37,15 @@ def register_registry_authority_commands(subparsers: argparse._SubParsersAction)
sources.add_argument("--topic", help="Exact registered topic key.")
sources.add_argument("--offset", type=int, default=0, help="Skip this many matches in stable source-id order.")
sources.add_argument("--limit", type=int, default=20, help="Maximum matches to return (1–100).")
update = subparsers.add_parser(
"update-authority-source", help="Update existing material metadata while preserving source provenance and topics.",
)
update.add_argument("--goal-id", required=True)
update.add_argument("--source-id", required=True)
for field in ("freshness", "owner-status", "gate-status", "revision", "conflict-rule"):
update.add_argument(f"--{field}", help="Recorded metadata only; omitted fields are preserved.")
update.add_argument("--dry-run", action="store_true", help="Preview without writing or syncing.")
update.add_argument("--no-global-sync", action="store_true", help="Skip shared registry summary refresh.")
authority_parser = subparsers.add_parser(
"register-authority-source",
help="Register a redacted local authority/material source for a goal.",
Expand Down Expand Up @@ -147,34 +158,50 @@ def handle_registry_authority_command(
print_payload(payload, args.format, render_authority_sources_markdown)
return 0 if payload["ok"] else 1

if args.command == "register-authority-source":
if args.command in {"register-authority-source", "update-authority-source"}:
local_written = False
try:
payload = register_authority_source(
registry_path=registry_path,
goal_id=args.goal_id,
source_id=args.source_id,
source_ref=args.source_ref,
source_kind=args.source_kind,
role=args.role,
freshness=args.freshness,
owner_status=args.owner_status,
gate_status=args.gate_status,
boundary=args.boundary,
revision=args.revision,
conflict_rule=args.conflict_rule,
topic=args.topic,
dry_run=bool(args.dry_run),
)
if args.command == "update-authority-source":
payload = update_authority_source(
registry_path=registry_path, goal_id=args.goal_id, source_id=args.source_id,
freshness=args.freshness, owner_status=args.owner_status, gate_status=args.gate_status,
revision=args.revision, conflict_rule=args.conflict_rule, dry_run=bool(args.dry_run),
)
else:
payload = register_authority_source(
registry_path=registry_path,
goal_id=args.goal_id,
source_id=args.source_id,
source_ref=args.source_ref,
source_kind=args.source_kind,
role=args.role,
freshness=args.freshness,
owner_status=args.owner_status,
gate_status=args.gate_status,
boundary=args.boundary,
revision=args.revision,
conflict_rule=args.conflict_rule,
topic=args.topic,
dry_run=bool(args.dry_run),
)
local_written = bool(payload.get("written"))
Comment thread
huangruiteng marked this conversation as resolved.
Resolved
if not bool(args.no_global_sync):
if args.dry_run:
payload["global_sync"] = {"enabled": True, "dry_run": True, "wrote": False}
else:
payload["global_sync"] = sync_project_registry_to_global(
sync_result = sync_project_registry_to_global(
registry_path=registry_path,
runtime_root_override=args.runtime_root,
goal_id=args.goal_id,
dry_run=False,
)
payload["global_sync"] = sync_result
if args.command == "update-authority-source" and sync_result.get("ok") is False:
payload["ok"] = False
payload["error"] = (
"Project metadata was written, but shared registry synchronization failed: "
+ str(sync_result.get("error") or "shared registry rejected the update")
)
else:
payload["global_sync"] = {"enabled": False}
except Exception as exc:
Expand All @@ -184,7 +211,8 @@ def handle_registry_authority_command(
"runtime_root": args.runtime_root,
"goal_id": args.goal_id,
"source_id": getattr(args, "source_id", None),
"written": False,
"written": local_written,
"operation": "update" if args.command == "update-authority-source" else "register",
"dry_run": bool(getattr(args, "dry_run", False)),
"error": str(exc),
}
Expand Down
71 changes: 71 additions & 0 deletions loopx/cli_commands/registry_authority_metadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
"""Explicit metadata patches over the existing project material registration owner."""
from __future__ import annotations

import copy
from pathlib import Path
from typing import cast

from ..authority import (
Payload, _apply_authority_entry, _dict_view, find_goal_index,
normalize_project_materials, now_local, public_safe_optional, validate_authority_source_id,
)
from ..control_plane.projects.registry_codec import (
load_project_registry, mutate_project_registry, require_runtime_compatible_project_registry,
)


def update_authority_source(
*, registry_path: Path, goal_id: str, source_id: str,
freshness: str | None = None, owner_status: str | None = None,
gate_status: str | None = None, revision: str | None = None,
conflict_rule: str | None = None, dry_run: bool = False,
) -> Payload:
"""Patch recorded metadata under the registry lock; never reopen the source."""
registry_path = registry_path.expanduser()
source_id = validate_authority_source_id(source_id)
changes: Payload = {}
for name, value in (("freshness", freshness), ("owner_status", owner_status),
("gate_status", gate_status), ("revision", revision),
("conflict_rule", conflict_rule)):
if value is not None:
cleaned = public_safe_optional(name, value)
if not cleaned:
raise ValueError(f"{name} must not be empty")
changes[name] = cleaned
if not changes:
raise ValueError("specify at least one metadata field to update")

def reduce(registry: Payload) -> tuple[Payload, Payload]:
require_runtime_compatible_project_registry(registry, operation="authority metadata update")
index = find_goal_index(registry, goal_id)
goal = cast(list[Payload], registry["goals"])[index]
authority = _dict_view(goal.get("authority_registry"))
materials = normalize_project_materials(authority.get("project_materials"))
if source_id not in materials:
raise ValueError("source_id is not registered in this authoritative project registry; "
"select the project registry or register the source first")
entry = dict(materials[source_id])
entry.update(changes)
entry["id"] = source_id
summary, _previous = _apply_authority_entry(
registry, goal_id=goal_id, entry=entry, registered_at=now_local(),
)
return entry, summary

if dry_run:
registry = load_project_registry(registry_path)
entry, summary = reduce(copy.deepcopy(registry))
else:
entry, summary = mutate_project_registry(
registry_path, operation="update_authority_source", reducer=reduce,
)
return {
"ok": True, "operation": "update", "dry_run": dry_run, "written": not dry_run,
"registry": str(registry_path), "goal_id": goal_id, "source_id": source_id,
"entry": entry, "updated_fields": sorted(changes),
"authority_registry_path": "authority_registry.project_materials",
"authority_registry_summary": summary, "raw_source_ref_stored": False,
"write_effect": "updated recorded metadata only; omitted fields, reference provenance and topics preserved; "
"no source access or permission change" if not dry_run else
"would update recorded metadata only; no registry writes or source access",
}
1 change: 1 addition & 0 deletions loopx/help_surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ def register_command_reference(subparsers: argparse._SubParsersAction[argparse.A
"refresh-state",
"reliability-diagnostics",
"register-authority-source",
"update-authority-source",
"registry-boundary",
"reward",
"reward-memory",
Expand Down
39 changes: 38 additions & 1 deletion skills/loopx-doc-registry/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,46 @@ reference interpretation for displayed topics, exact filters and text search.
Registration retains only a source-reference kind and digest, not its original
URL/path. Use the original DOC_REGISTRY or authorized connector to locate and
check the document, then reuse its listed source ID with
`register-authority-source` to update the recorded metadata. An inventory match
`update-authority-source` to update the recorded metadata. An inventory match
is not evidence that the document was read or is still accessible.

## Maintain Existing Material Metadata

After checking a material, preview a change to its recorded lifecycle metadata:

```bash
loopx --registry .loopx/registry.json update-authority-source \
--goal-id example-goal --source-id design-note \
--freshness stale --gate-status needs_access --dry-run
```

Remove `--dry-run` to apply and refresh the shared registry summary; use
`--no-global-sync` to update only the project registry. Read back with
`authority-sources --goal-id example-goal --topic design` (using the registered
topic), or search for the source ID. Optional update fields are `--freshness`,
`--owner-status`, `--gate-status`, `--revision` and `--conflict-rule`. At least one
nonempty field is required. Omitted fields, original registration time, reference
kind/digest, imported summary metadata and topic mappings remain unchanged.
The source must already exist in the selected project registry. A shared summary
is insufficient; select the authoritative project registry explicitly.

This records observations, not proof of reading, current access or permission to
access a source. No source is opened. Registration keeps its existing full-entry
replacement semantics; use it for deliberate replacement, supplying the complete
contract. Project writes use the existing registry transaction; shared-summary
sync follows separately. If sync fails after the project update, the failure
reports `ok: false` and `written: true`. Inspect the project readback; after
restoring shared registry access, sync the current project snapshot with the same
Goal and runtime root instead of replaying the metadata patch:

```bash
loopx --registry .loopx/registry.json --runtime-root /path/to/runtime \
sync-global --goal-id example-goal
```

Use the original resolved runtime root. Sync-only recovery preserves newer
metadata observations recorded since the failure.

## Stop Conditions

Stop and write a project-local todo or blocker instead of registering when:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"loopx/cli_runtime.py",
"loopx/cli_commands/coordination_shadow.py",
"loopx/cli_commands/manager_inbox.py",
"loopx/cli_commands/registry_authority_metadata.py",
"loopx/cli_commands/registry_authority_read.py",
"loopx/configure_goal.py",
"loopx/control_plane/collaboration/goal_instance_scope.py",
Expand Down
Loading
Loading