From 77a966560f185fe0cb98d7391987b58d60e1d209 Mon Sep 17 00:00:00 2001 From: Juan Barbat Date: Fri, 23 Oct 2026 18:50:48 -0300 Subject: [PATCH 1/5] feat(cli): name conflicting asset paths on install ownership_conflict ApplyGroup now returns a typed ConflictError carrying the conflicting LogicalIDs, and the install/update CLI resolves them to runtime-relative paths in the status line (conflict_paths=..., deduplicated). Status line shape, exit codes, and the opaque stderr contract are unchanged (issue #373, specs S1/S4/S5). --- internal/cli/install.go | 43 ++++++++++++++++++++++++-- internal/cli/install_test.go | 18 +++++++++++ internal/installtxn/installtxn.go | 29 ++++++++++++++++- internal/installtxn/installtxn_test.go | 21 +++++++++++++ 4 files changed, 108 insertions(+), 3 deletions(-) diff --git a/internal/cli/install.go b/internal/cli/install.go index dc0720c..6f7422d 100644 --- a/internal/cli/install.go +++ b/internal/cli/install.go @@ -135,7 +135,11 @@ func runDirectoryInstall(stdout, stderr io.Writer, target string, deps installDe group, err := deps.applyGroup(requests, home, backupName) if err != nil { reason, code := installFailureReason(err) - return writeInstallResult(stdout, stderr, "install", "status=not_applied reason="+reason+" touch=denied", "", results, false, installtxn.Counts{}, code) + status := "status=not_applied reason=" + reason + " touch=denied" + if paths := installConflictPaths(requests, err); paths != "" { + status += " conflict_paths=" + paths + } + return writeInstallResult(stdout, stderr, "install", status, "", results, false, installtxn.Counts{}, code) } return writeInstallResult(stdout, stderr, "install", "status=completed touch=applied", "", results, true, group.Counts(), exitOK) } @@ -221,11 +225,46 @@ func runInstall(ctx context.Context, stdout, stderr io.Writer, runner runtimepro group, err := deps.applyGroup(requests, home, backupName) if err != nil { reason, code := installFailureReason(err) - return writeInstallResult(stdout, stderr, operation, "status=not_applied reason="+reason+" touch=denied", "", results, false, installtxn.Counts{}, code) + status := "status=not_applied reason=" + reason + " touch=denied" + if paths := installConflictPaths(requests, err); paths != "" { + status += " conflict_paths=" + paths + } + return writeInstallResult(stdout, stderr, operation, status, "", results, false, installtxn.Counts{}, code) } return writeInstallResult(stdout, stderr, operation, "status=completed touch=applied", warning, results, true, group.Counts(), exitOK) } +// installConflictPaths renders the conflicting logical assets as runtime-relative +// paths for the operator diagnostic (issue #373). LogicalIDs without a file in +// the composed requests map to their own identity, so the state artifact still +// names itself. Output is deduplicated and sorted by the transaction layer. +func installConflictPaths(requests []installtxn.GroupRequest, err error) string { + var conflict *installtxn.ConflictError + if !errors.As(err, &conflict) || len(conflict.LogicalIDs) == 0 { + return "" + } + relative := make(map[string]string) + for _, request := range requests { + for _, file := range request.Plan.Files() { + relative[file.LogicalID()] = file.RelativePath() + } + } + paths := make([]string, 0, len(conflict.LogicalIDs)) + seen := make(map[string]bool, len(conflict.LogicalIDs)) + for _, id := range conflict.LogicalIDs { + path, ok := relative[id] + if !ok { + continue + } + if seen[path] { + continue + } + seen[path] = true + paths = append(paths, path) + } + return strings.Join(paths, ",") +} + // installFailureReason maps a grouped-transaction failure to the operator reason // and exit code. Fail-closed refusals name their cause and remedy instead of the // opaque transaction_failed (issue #281). diff --git a/internal/cli/install_test.go b/internal/cli/install_test.go index 23473ed..4b2b1a4 100644 --- a/internal/cli/install_test.go +++ b/internal/cli/install_test.go @@ -211,6 +211,24 @@ func TestRunInstallUnrepresentableProjectionIsNotApplied(t *testing.T) { t.Fatalf("install = (%q, %q)", stdout.String(), stderr.String()) } } +func TestRunInstallConflictListsConflictingPaths(t *testing.T) { + deps := compatibleInstallDependencies(t, t.TempDir()) + deps.applyGroup = func([]installtxn.GroupRequest, string, string) (installtxn.GroupResult, error) { + return installtxn.GroupResult{}, &installtxn.ConflictError{LogicalIDs: []string{"skills/requirements-analyst"}} + } + var stdout, stderr bytes.Buffer + if code := runWithInstallDependencies(context.Background(), []string{"install"}, &stdout, &stderr, certifiedPiOnlyRunner(), deps); code != exitConflict { + t.Fatalf("install exit = %d, want %d", code, exitConflict) + } + if stderr.Len() != 0 { + t.Fatalf("stderr = %q, want empty", stderr.String()) + } + want := "status=not_applied reason=ownership_conflict touch=denied conflict_paths=skills/cortex-requirements-analyst/SKILL.md" + if !strings.Contains(stdout.String(), want) { + t.Fatalf("stdout = %q, want conflict paths %q", stdout.String(), want) + } +} + func TestRunInstallFailuresDoNotReportCompletion(t *testing.T) { for _, tc := range []struct { name string diff --git a/internal/installtxn/installtxn.go b/internal/installtxn/installtxn.go index 4354223..d932d9f 100644 --- a/internal/installtxn/installtxn.go +++ b/internal/installtxn/installtxn.go @@ -31,6 +31,33 @@ var ( ErrFailed = errors.New("install transaction: failed") ) +// ConflictError wraps ErrConflict with the LogicalIDs whose ownership decisions +// conflicted, so callers can render path-level diagnostics. It carries no path, +// content, or touch authority: the transaction result contract stays intact. +type ConflictError struct { + LogicalIDs []string +} + +// Error keeps the sentinel text so errors.Is(ErrConflict) compatibility and the +// opaque stderr contract are unchanged. +func (e *ConflictError) Error() string { return ErrConflict.Error() } + +// Unwrap preserves errors.Is(err, ErrConflict) for every existing caller. +func (e *ConflictError) Unwrap() error { return ErrConflict } + +// conflictLogicalIDs extracts the LogicalIDs whose action is ownership conflict +// from a prepared result, sorted for deterministic diagnostics. +func conflictLogicalIDs(result Result) []string { + ids := make([]string, 0, len(result.actions)) + for _, action := range result.actions { + if action.Action == ownership.Conflict { + ids = append(ids, action.LogicalID) + } + } + sort.Strings(ids) + return ids +} + const stateRelativePath = ".cortex/install-state.json" var errPriorOwnership = errors.New("install transaction: prior ownership index is invalid") @@ -593,7 +620,7 @@ func applyGroupWith(requests []GroupRequest, backupRoot, backupName string, appl sequenced, single, err := prepareSequenced(request.Plan, current[index], request.CWD) if err != nil { if errors.Is(err, ErrConflict) { - return GroupResult{}, ErrConflict + return GroupResult{}, &ConflictError{LogicalIDs: conflictLogicalIDs(single)} } return GroupResult{}, errors.Join(ErrInvalid, err) } diff --git a/internal/installtxn/installtxn_test.go b/internal/installtxn/installtxn_test.go index 7defc8f..6545952 100644 --- a/internal/installtxn/installtxn_test.go +++ b/internal/installtxn/installtxn_test.go @@ -217,6 +217,27 @@ func TestApplyGroupRejectsConflictBeforeMutation(t *testing.T) { } } +func TestApplyGroupConflictErrorNamesConflictingLogicalIDs(t *testing.T) { + home := t.TempDir() + plans := groupCandidates(t, home, "one") + conflicted := plans[1].Files()[0] + must(t, os.MkdirAll(filepath.Dir(conflicted.AbsolutePath()), 0o700)) + must(t, os.WriteFile(conflicted.AbsolutePath(), []byte("user"), 0o600)) + _, err := applyGroupRequest(t, plans...) + var conflict *ConflictError + if !errors.As(err, &conflict) { + t.Fatalf("ApplyGroup() error = %v, want *ConflictError", err) + } + if len(conflict.LogicalIDs) != 1 || conflict.LogicalIDs[0] != conflicted.LogicalID() { + t.Fatalf("ConflictError.LogicalIDs = %v, want [%s]", conflict.LogicalIDs, conflicted.LogicalID()) + } + for _, id := range conflict.LogicalIDs { + if id == "" { + t.Fatal("ConflictError carries an empty LogicalID") + } + } +} + func TestApplyGroupRejectsInjectedTransactionFailureAndInvalidGroups(t *testing.T) { home := t.TempDir() plans := groupCandidates(t, home, "one") From c4d7f3f68aaad4a4b2757c7533366e2a8b415227 Mon Sep 17 00:00:00 2001 From: Juan Barbat Date: Fri, 23 Oct 2026 18:57:48 -0300 Subject: [PATCH 2/5] feat(cli): name conflicting paths on uninstall conflict ObserveUninstall now records the runtime-relative paths of drifted prior-owned artifacts and exposes them detached via ConflictPaths(); the uninstall result line appends conflict_paths=... next to conflict=%d (issue #373, specs S3/S4/S5). --- internal/cli/doctor.go | 3 +++ internal/cli/uninstall_test.go | 14 ++++++++++++-- internal/installobserve/uninstall.go | 19 ++++++++++++++++++- internal/installobserve/uninstall_test.go | 14 ++++++++++++++ 4 files changed, 47 insertions(+), 3 deletions(-) diff --git a/internal/cli/doctor.go b/internal/cli/doctor.go index 14e8a70..713f7c5 100644 --- a/internal/cli/doctor.go +++ b/internal/cli/doctor.go @@ -754,6 +754,9 @@ func writeUninstallResult(stdout, stderr io.Writer, results []uninstallPreflight for _, result := range results { remove, absent, conflict := uninstallCounts(result.observation) _, _ = fmt.Fprintf(&output, "runtime=%s uninstall=%s remove=%d absent=%d conflict=%d", result.root.RuntimeID(), result.status, remove, absent, conflict) + if paths := result.observation.ConflictPaths(); len(paths) > 0 { + _, _ = fmt.Fprintf(&output, " conflict_paths=%s", strings.Join(paths, ",")) + } if paths := result.observation.UnsupportedActorPaths(); len(paths) > 0 { unsupported = true _, _ = fmt.Fprintf(&output, " reason=unsupported_installation state=validated_canonical_v3 recorded_actor_paths=%s", strings.Join(paths, ",")) diff --git a/internal/cli/uninstall_test.go b/internal/cli/uninstall_test.go index e615718..6e8fb20 100644 --- a/internal/cli/uninstall_test.go +++ b/internal/cli/uninstall_test.go @@ -46,7 +46,7 @@ func TestRunUninstallRuntimeHarness(t *testing.T) { t.Fatal(err) } code, stdout, stderr := runUninstallForTest(t, roots, nil) - if code != exitConflict || stderr != "" || stdout != uninstallLines("blocked", "conflict", "blocked") { + if code != exitConflict || stderr != "" || stdout != uninstallLines("blocked", "conflict", "blocked", "skills/cortex-alpha/SKILL.md") { t.Fatalf("uninstall = (%d, %q, %q)", code, stdout, stderr) } for i := range roots { @@ -216,6 +216,11 @@ func writeInstalled(t *testing.T, root skillroot.UninstallRoot, content string) } func uninstallLines(statuses ...string) string { + var conflictPaths string + if len(statuses) > 3 { + conflictPaths = statuses[3] + statuses = statuses[:3] + } var output strings.Builder for i, runtime := range []string{"pi", "opencode", "claude-code"} { remove, conflict := 2, 0 @@ -224,7 +229,12 @@ func uninstallLines(statuses ...string) string { } else if statuses[i] == "conflict" { remove, conflict = 1, 1 } - _, _ = fmt.Fprintf(&output, "runtime=%s uninstall=%s remove=%d absent=0 conflict=%d\n", runtime, statuses[i], remove, conflict) + line := fmt.Sprintf("runtime=%s uninstall=%s remove=%d absent=0 conflict=%d", runtime, statuses[i], remove, conflict) + if statuses[i] == "conflict" && conflictPaths != "" { + line += " conflict_paths=" + conflictPaths + } + output.WriteString(line) + output.WriteByte('\n') } return output.String() } diff --git a/internal/installobserve/uninstall.go b/internal/installobserve/uninstall.go index 690d5c9..650f04b 100644 --- a/internal/installobserve/uninstall.go +++ b/internal/installobserve/uninstall.go @@ -5,6 +5,7 @@ import ( "errors" "io/fs" "os" + "sort" "github.com/refactor-ia/cortex/internal/installstate" "github.com/refactor-ia/cortex/internal/runtimematrix" @@ -77,6 +78,7 @@ type UninstallObservation struct { removals map[string]RemovalEvidence ready bool unsupportedActorPaths []string + conflictPaths map[string]string } // UnsupportedActorPaths returns detached, bounded recorded relative actor paths @@ -86,6 +88,19 @@ func (observation UninstallObservation) UnsupportedActorPaths() []string { return append([]string(nil), observation.unsupportedActorPaths...) } +// ConflictPaths returns the detached runtime-relative paths of prior-owned +// artifacts whose observed content drifted from the recorded state (issue +// #373). Paths carry no touch authority; they exist only so conflict refusals +// can name which assets conflict. +func (observation UninstallObservation) ConflictPaths() []string { + paths := make([]string, 0, len(observation.conflictPaths)) + for _, path := range observation.conflictPaths { + paths = append(paths, path) + } + sort.Strings(paths) + return paths +} + // Records returns detached logical records in canonical prior-state order, with the // state file record always final when state exists. func (observation UninstallObservation) Records() []UninstallRecord { @@ -174,6 +189,7 @@ func ObserveUninstall(root UninstallRoot, options Options) (UninstallObservation } artifacts := manifest.Artifacts() + conflictPaths := make(map[string]string) records := make([]UninstallRecord, 0, len(artifacts)+1) exact := make(map[string]ExactFile, len(artifacts)+1) removals := make(map[string]RemovalEvidence, len(artifacts)+1) @@ -193,6 +209,7 @@ func ObserveUninstall(root UninstallRoot, options Options) (UninstallObservation } else { record.Status = UninstallConflict conflict = true + conflictPaths[record.LogicalID] = artifact.RelativePath() } } records = append(records, record) @@ -201,7 +218,7 @@ func ObserveUninstall(root UninstallRoot, options Options) (UninstallObservation exact["state/install-state"] = ExactFile{bytes: append([]byte{}, state...), mode: stateMode} removals["state/install-state"] = RemovalEvidence{destination: ".cortex/install-state.json", exact: exact["state/install-state"]} records = append(records, UninstallRecord{LogicalID: "state/install-state", Status: UninstallRemove, SHA256: stateHash}) - return UninstallObservation{runtimeID: root.runtimeID, rootPath: root.rootPath, records: records, exact: exact, removals: removals, ready: !conflict}, nil + return UninstallObservation{runtimeID: root.runtimeID, rootPath: root.rootPath, records: records, exact: exact, removals: removals, ready: !conflict, conflictPaths: conflictPaths}, nil } func validUninstallRoot(root UninstallRoot) bool { diff --git a/internal/installobserve/uninstall_test.go b/internal/installobserve/uninstall_test.go index a9377c7..18606b9 100644 --- a/internal/installobserve/uninstall_test.go +++ b/internal/installobserve/uninstall_test.go @@ -88,6 +88,20 @@ func TestObserveUninstallClassifiesCanonicalPriorState(t *testing.T) { if err != nil || got.Ready() != tc.ready || !reflect.DeepEqual(got.Records(), want) { t.Fatalf("ObserveUninstall() = (%#v, %v)", got, err) } + if !tc.ready { + var conflicting bool + for _, record := range want { + if record.Status == installobserve.UninstallConflict { + conflicting = true + } + } + if conflicting { + wantPaths := []string{candidate.Files()[0].RelativePath()} + if got := got.ConflictPaths(); !reflect.DeepEqual(got, wantPaths) { + t.Fatalf("ConflictPaths() = %v, want %v", got, wantPaths) + } + } + } if tc.ready && len(want) > 0 { candidates := make([]installobserve.UninstallRecord, 0, len(want)) for _, record := range want { From bdc870441cf65ab9a80cc49703c0ca92e604ceeb Mon Sep 17 00:00:00 2001 From: Juan Barbat Date: Fri, 23 Oct 2026 19:56:10 -0300 Subject: [PATCH 3/5] docs(operating): document conflict path diagnostics for install, uninstall, and update refusals --- docs/operating.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/operating.md b/docs/operating.md index 2b0ba42..05d3847 100644 --- a/docs/operating.md +++ b/docs/operating.md @@ -54,7 +54,7 @@ operation=install status=completed touch=applied create=33 replace=0 remove=0 un - `status=completed touch=applied` — the transaction applied and was read back. Running install again is a no-op reported honestly as `create=0 unchanged=33`. - `status=not_applied reason=compatibility_uncertified touch=denied` — no compatible runtime was found; nothing was written. - `status=not_applied reason=projection_unrepresentable touch=denied` — a runtime exists but cannot represent a capability honestly; Cortex refused rather than approximating. Report it; do not work around it. -- `status=not_applied reason=ownership_conflict touch=denied` (exit 3) — a target file exists without verified Cortex ownership. Someone else wrote there. Stop and ask the user; never delete or rewrite foreign files to clear the path. +- `status=not_applied reason=ownership_conflict touch=denied` (exit 3) — a target file exists without verified Cortex ownership. Someone else wrote there. Stop and ask the user; never delete or rewrite foreign files to clear the path. The status line appends `conflict_paths=` naming every asset whose ownership decision conflicted, so the conflicting files are named without reading transaction internals. - `warning=uncertified_admission runtimes=N certification=not_certified` — the transaction configured N runtimes whose exact version has no verified evidence. This is disclosed non-certified admission, not a failure; the user may accept it once they know. ## Directory targets @@ -104,7 +104,7 @@ Default mode touches nothing — run the plan first, read it, then decide. `--ap - `uninstall=completed remove=N` — removed exactly what it owned. - `not_installed` — nothing of Cortex's there; nothing done. -- `conflict` / `blocked` — shared actor state or unverified ownership blocks removal; the whole grouped uninstall fails closed and nothing is removed. Report the diagnostic notes to the user instead of forcing it. +- `conflict` / `blocked` — shared actor state or unverified ownership blocks removal; the whole grouped uninstall fails closed and nothing is removed. The runtime line appends `conflict_paths=` naming the drifted prior-owned assets. Report the diagnostic notes to the user instead of forcing it. ## Never do this From 4ed52ab476ceaeb2156e34d5d6090f6ec0094285 Mon Sep 17 00:00:00 2001 From: Juan Barbat Date: Fri, 23 Oct 2026 20:16:23 -0300 Subject: [PATCH 4/5] chore: trigger fresh validate run after PR body edit From f5144ba93642977fcca0b69b83fb8a8deae4707d Mon Sep 17 00:00:00 2001 From: Juan Barbat Date: Thu, 12 Nov 2026 17:38:08 -0300 Subject: [PATCH 5/5] fix(cli): name conflicting asset paths in update conflict output Refs #385 --- docs/operating.md | 2 ++ internal/cli/install.go | 32 ++++++++++++++++++++------------ internal/cli/update.go | 30 +++++++++++++++++++++--------- internal/cli/update_test.go | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 79 insertions(+), 21 deletions(-) diff --git a/docs/operating.md b/docs/operating.md index b136540..7495b50 100644 --- a/docs/operating.md +++ b/docs/operating.md @@ -100,6 +100,8 @@ cortex update --runtime pi --catalog ./catalog --apply # the plan, applied Default mode touches nothing — run the plan first, read it, then decide. `--apply` writes only inside that runtime's Cortex-owned root. On Pi, if legacy externally-modified guidance is detected, the plan asks for explicit consent with `--adopt-guidance`: that is a one-time adoption of external bytes (they are preserved, not overwritten), not a drift override, and drift is always refused. +A plan or apply that hits an asset without verified Cortex ownership reports `operation= action=conflict` and ends with `status=conflict conflict_paths=` (exit 3), naming each conflicting asset by its path under the runtime root. Nothing is written; stop and ask the user rather than removing the file. + ## Upgrade to alpha20 Use the [published alpha20 archive and checksum procedure](verification.md#verify-an-archive) for the machine's platform. Keep the extracted binary, catalog and licenses together in a versioned directory. Do not replace user model routes or runtime configuration with release defaults. diff --git a/internal/cli/install.go b/internal/cli/install.go index 6f7422d..bd8488b 100644 --- a/internal/cli/install.go +++ b/internal/cli/install.go @@ -235,28 +235,36 @@ func runInstall(ctx context.Context, stdout, stderr io.Writer, runner runtimepro } // installConflictPaths renders the conflicting logical assets as runtime-relative -// paths for the operator diagnostic (issue #373). LogicalIDs without a file in -// the composed requests map to their own identity, so the state artifact still -// names itself. Output is deduplicated and sorted by the transaction layer. +// paths for the operator diagnostic (issue #373). Output is deduplicated and +// sorted by the transaction layer. func installConflictPaths(requests []installtxn.GroupRequest, err error) string { var conflict *installtxn.ConflictError if !errors.As(err, &conflict) || len(conflict.LogicalIDs) == 0 { return "" } - relative := make(map[string]string) + plans := make([]installplan.Plan, 0, len(requests)) for _, request := range requests { - for _, file := range request.Plan.Files() { + plans = append(plans, request.Plan) + } + return conflictRelativePaths(plans, conflict.LogicalIDs) +} + +// conflictRelativePaths maps conflicting LogicalIDs to the runtime-relative +// paths their plans compose, preserving the given order and dropping +// duplicates. LogicalIDs without a file in the plans (the state artifact) are +// omitted, so every caller renders the same conflict_paths representation. +func conflictRelativePaths(plans []installplan.Plan, logicalIDs []string) string { + relative := make(map[string]string) + for _, plan := range plans { + for _, file := range plan.Files() { relative[file.LogicalID()] = file.RelativePath() } } - paths := make([]string, 0, len(conflict.LogicalIDs)) - seen := make(map[string]bool, len(conflict.LogicalIDs)) - for _, id := range conflict.LogicalIDs { + paths := make([]string, 0, len(logicalIDs)) + seen := make(map[string]bool, len(logicalIDs)) + for _, id := range logicalIDs { path, ok := relative[id] - if !ok { - continue - } - if seen[path] { + if !ok || seen[path] { continue } seen[path] = true diff --git a/internal/cli/update.go b/internal/cli/update.go index 01a9880..e9d573b 100644 --- a/internal/cli/update.go +++ b/internal/cli/update.go @@ -7,6 +7,7 @@ import ( "io" "os" "path/filepath" + "sort" "strconv" "strings" "time" @@ -128,7 +129,7 @@ func runWithUpdateDependencies(ctx context.Context, args []string, stdout, stder } if !apply { header := fmt.Sprintf("runtime=%s outcome=%s action=%s root=%s mode=plan%s", decision.ID, decision.Outcome, decision.Action, plan.RootPath(), warning) - return writeUpdateOperations(stdout, header, classified, "planned") + return writeUpdateOperations(stdout, header, plan, classified, "planned") } return applyUpdate(stdout, stderr, plan, observation, classified, observations, warning) } @@ -266,7 +267,7 @@ func runDirectoryUpdate(stdout, stderr io.Writer, targetDir, catalogDir string, } header := fmt.Sprintf("runtime=%s outcome=%s action=%s root=%s mode=plan", decision.ID, decision.Outcome, decision.Action, plan.RootPath()) if !apply { - return writeUpdateOperations(stdout, header, classified, "planned") + return writeUpdateOperations(stdout, header, plan, classified, "planned") } return applyDirectoryUpdate(stdout, stderr, plan, observation, classified, header) } @@ -306,7 +307,7 @@ func applyDirectoryUpdate(stdout, stderr io.Writer, plan installplan.Plan, obser return exitFailure } if !report.Ready() { - return writeUpdateOperations(stdout, header, classified, "conflict") + return writeUpdateOperations(stdout, header, plan, classified, "conflict") } backupRoot := filepath.Join(plan.RootPath(), ".cortex") if err := os.MkdirAll(backupRoot, 0o700); err != nil { @@ -317,7 +318,7 @@ func applyDirectoryUpdate(stdout, stderr io.Writer, plan installplan.Plan, obser result, txErr := applyCandidate(plan, observation, backupRoot, backupName) if txErr != nil { if errors.Is(txErr, installtxn.ErrConflict) { - return writeUpdateOperations(stdout, header, classified, "conflict") + return writeUpdateOperations(stdout, header, plan, classified, "conflict") } writeError(stderr, "update_transaction_failed") return exitTransaction @@ -386,12 +387,16 @@ func updateRefusalReason(outcome runtimematrix.Outcome) string { } // writeUpdateOperations prints one read-only operation report with its status. -func writeUpdateOperations(stdout io.Writer, header string, classified installobserve.Result, status string) int { +// A conflict status names the conflicting assets by runtime-relative path in +// the same conflict_paths form install and uninstall use (issue #373). +func writeUpdateOperations(stdout io.Writer, header string, plan installplan.Plan, classified installobserve.Result, status string) int { output := strings.Builder{} output.WriteString(header + "\n") + var conflicts []string for _, item := range classified.ArtifactDecisions() { if item.Action == ownership.Conflict { status = "conflict" + conflicts = append(conflicts, item.LogicalID) } if item.ModeDrift { fmt.Fprintf(&output, "operation=%s action=%s mode_drift=true observed_mode=%04o canonical_mode=0600\n", item.LogicalID, item.Action, item.ObservedMode.Perm()) @@ -402,7 +407,14 @@ func writeUpdateOperations(stdout io.Writer, header string, classified installob if classified.StateAction() == ownership.Conflict { status = "conflict" } - fmt.Fprintf(&output, "operation=state/install-state action=%s\nstatus=%s\n", classified.StateAction(), status) + fmt.Fprintf(&output, "operation=state/install-state action=%s\nstatus=%s", classified.StateAction(), status) + if status == "conflict" { + sort.Strings(conflicts) + if paths := conflictRelativePaths([]installplan.Plan{plan}, conflicts); paths != "" { + output.WriteString(" conflict_paths=" + paths) + } + } + output.WriteString("\n") _, _ = io.WriteString(stdout, output.String()) if status == "conflict" { return exitConflict @@ -423,7 +435,7 @@ func applyUpdate(stdout, stderr io.Writer, plan installplan.Plan, observation in return exitFailure } if !report.Ready() { - return writeUpdateOperations(stdout, header, classified, "conflict") + return writeUpdateOperations(stdout, header, plan, classified, "conflict") } backupRoot := filepath.Join(plan.RootPath(), ".cortex") if err := os.MkdirAll(backupRoot, 0o700); err != nil { @@ -434,7 +446,7 @@ func applyUpdate(stdout, stderr io.Writer, plan installplan.Plan, observation in result, txErr := applyCandidate(plan, observation, backupRoot, backupName) if txErr != nil { if errors.Is(txErr, installtxn.ErrConflict) { - return writeUpdateOperations(stdout, header, classified, "conflict") + return writeUpdateOperations(stdout, header, plan, classified, "conflict") } writeError(stderr, "update_transaction_failed") return exitTransaction @@ -511,7 +523,7 @@ func updateActorGuidance(stdout, stderr io.Writer, canonical installplan.Plan, o } proof := preflight.Proof() // Retain the exact immutable candidate and evidence. if !apply { - return writeUpdateOperations(stdout, header, proof.Result(), "planned") + return writeUpdateOperations(stdout, header, canonical, proof.Result(), "planned") } backupName := nextUpdateBackupName() result, err := installtxn.ApplyActorGuidance(canonical, observation, proof, cwd, filepath.Join(canonical.RootPath(), ".cortex"), backupName) diff --git a/internal/cli/update_test.go b/internal/cli/update_test.go index 47a4efb..d466100 100644 --- a/internal/cli/update_test.go +++ b/internal/cli/update_test.go @@ -478,3 +478,39 @@ func TestUpdatePlanReportsModeDrift(t *testing.T) { t.Fatalf("stdout %q does not have status=planned or contains status=conflict", stdout) } } + +// TestUpdateConflictNamesUserOwnedPaths pins issue #373 for the explicit-runtime +// update path: a user-owned file occupying a catalog target is named by its +// runtime-relative path in both plan and apply refusals, and is never touched. +func TestUpdateConflictNamesUserOwnedPaths(t *testing.T) { + fixture := newUpdateFixture(t) + root := updateRootPath(t, fixture, runtimematrix.RuntimeOpenCode) + const relative = "skills/cortex-requirements-analyst/SKILL.md" + userFile := filepath.Join(root, filepath.FromSlash(relative)) + mustOK(os.MkdirAll(filepath.Dir(userFile), 0o700)) + mustOK(os.WriteFile(userFile, []byte("user-owned"), 0o600)) + for _, apply := range []bool{false, true} { + args := []string{"update", "--runtime", "opencode", "--catalog", fixture.catalog} + mode := "plan" + if apply { + args = append(args, "--apply") + mode = "apply" + } + code, stdout, stderr := runUpdateCommand(t, fixture.dependencies(runtimematrix.RuntimeOpenCode), args...) + if code != exitConflict || stderr != "" { + t.Fatalf("conflict update (%s) = (%d, %q, %q)", mode, code, stdout, stderr) + } + if !strings.Contains(stdout, "mode="+mode) || !strings.Contains(stdout, "\noperation=skills/requirements-analyst action=conflict\n") { + t.Fatalf("conflict update (%s) stdout = %q", mode, stdout) + } + if !strings.HasSuffix(stdout, "\nstatus=conflict conflict_paths="+relative+"\n") { + t.Fatalf("conflict update (%s) status line lacks conflict_paths: %q", mode, stdout) + } + if string(must(os.ReadFile(userFile))) != "user-owned" { + t.Fatalf("conflict update (%s) changed the user-owned file", mode) + } + if _, err := os.Lstat(filepath.Join(root, ".cortex", "install-state.json")); !errors.Is(err, fs.ErrNotExist) { + t.Fatalf("conflict update (%s) wrote install state: %v", mode, err) + } + } +}