feat(client): deliver items only to clients with a matching label

- Add internal/labels: parse and validate the optional work-repo file
  agent-lib.labels.json (version 1; unlabeled items go to every client;
  names match across types)
- Add "labels" to the client config: absent = no filtering, [] = unlabeled
  items only; labels from the admin default config are pinned and cannot be
  overridden by user, env or flag configs; a broken admin config aborts
- Filter in prepare() before planning; deselected items follow the
  upstream-deletion rules (unmodified removed, modified kept + warn,
  --force removes) with reason "not selected for this client's labels"
- Abort sync before any change when the labels file does not validate;
  names that match no item only warn on the client
- Report the active selection in sync output and status (--json: labels
  object with client, source, labels_file, not_selected, unknown_names)
- validate checks the labels file, including that every name resolves to
  an own, vendored or MCP item
- Document in README ("Client labels"), fleet handoff and the proposal;
  revise the "client-side selection" non-goal
- Tests: labels parser, config precedence, planner deselection, e2e for
  filter/remove/keep-modified/abort/unknown names, validate

Refs: agent_lib-fh4

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
m3ta-chironandClaude Opus 5.5 committed 2026-11-14 10:36:07 +01:00
1 parent 39952ceb02
commit 59735c3b24
16 files changed
+904 -38

No files matched your search

+16 -8
View File
@@ -15,14 +15,15 @@ type StatusEntry struct {
// StatusReport is the machine-readable local-state report.
type StatusReport struct {
Version string `json:"agent_lib_version"`
DeployedRev string `json:"deployed_revision"`
RepoRev string `json:"repository_revision"`
InSync bool `json:"in_sync"`
Drift bool `json:"problematic_drift"`
Pending []StatusEntry `json:"pending_changes,omitempty"`
Skipped []StatusEntry `json:"skipped_items,omitempty"`
Unrecognized []StatusEntry `json:"unrecognized_items,omitempty"`
Version string `json:"agent_lib_version"`
DeployedRev string `json:"deployed_revision"`
RepoRev string `json:"repository_revision"`
InSync bool `json:"in_sync"`
Drift bool `json:"problematic_drift"`
Pending []StatusEntry `json:"pending_changes,omitempty"`
Skipped []StatusEntry `json:"skipped_items,omitempty"`
Unrecognized []StatusEntry `json:"unrecognized_items,omitempty"`
Labels *LabelSelection `json:"labels,omitempty"`
}
// Status reports the local state without mutating anything. Drift is true
@@ -38,6 +39,7 @@ func Status(opts SyncOptions) (*StatusReport, error) {
Version: version.Version,
DeployedRev: p.manifest.Revision,
RepoRev: p.pull.Rev,
Labels: p.labels,
}
for _, e := range p.plan {
item := e.Type + "/" + e.Name
@@ -85,6 +87,12 @@ func PrintStatus(w io.Writer, r *StatusReport) bool {
fmt.Fprintln(w)
}
}
if r.Labels != nil {
fmt.Fprintln(w, r.Labels.Summary())
for _, n := range r.Labels.Unknown {
fmt.Fprintf(w, " warning: labels file names %q, which matches no item\n", n)
}
}
printSection("pending changes", r.Pending)
printSection("skipped (local modifications)", r.Skipped)
printSection("unrecognized local items", r.Unrecognized)