mirror of
https://github.com/DeusData/codebase-memory-mcp.git
synced 2026-12-02 04:17:04 +08:00
fix(codex): migrate skill to shared agents root
Signed-off-by: Benyamin <benyaminjmf@gmail.com>
This commit is contained in:
@@ -491,7 +491,7 @@ overwrite user-modified agents.
|
||||
| Agent | Activation | MCP config | Durable context / augmentation |
|
||||
|-------|------------|------------|--------------------------------|
|
||||
| Claude Code | Detected | `~/.claude.json` | Skill + three exact-tool graph agents; `SessionStart`, `SubagentStart`, non-blocking `PreToolUse` for `Grep`/`Glob`/`Bash`, and post-`Read` coverage |
|
||||
| Codex CLI | Detected | `$CODEX_HOME/config.toml` | Managed `AGENTS.md` activation pointer, skill, three read-only agents; `SessionStart` + `SubagentStart` |
|
||||
| Codex CLI | Detected | `$CODEX_HOME/config.toml` | Managed `AGENTS.md` activation pointer, `~/.agents/skills/codebase-memory/SKILL.md`, three read-only agents; `SessionStart` + `SubagentStart` |
|
||||
| Gemini CLI | Detected | `.gemini/settings.json` | `GEMINI.md`, three explicit read/graph-tool subagents; `BeforeTool`, `AfterTool` `read_file` coverage, and `SessionStart` |
|
||||
| Zed | Detected | platform `settings.json` (JSONC) | `AGENTS.md` + shared skill |
|
||||
| OpenCode | Detected | `$OPENCODE_CONFIG` or resolved global config | `AGENTS.md`, skill, three deny-by-default read-only agents; plugin adds grep/glob graph lookup, post-`read` coverage, first-tool-result session context, and post-compaction reinjection |
|
||||
@@ -540,6 +540,11 @@ For Codex, install keeps only a tiny managed activation pointer in global
|
||||
`$CODEX_HOME/AGENTS.md`; all detailed behavior lives in the installed `codebase-memory` skill.
|
||||
Fresh installs create the pointer, upgrades replace the legacy full managed block while preserving
|
||||
all user-owned bytes, and uninstall removes only the managed pointer.
|
||||
Skill placement follows the cross-client user skill root and does not follow
|
||||
`CODEX_HOME`. On upgrade, the installer migrates an installer-owned legacy
|
||||
`$CODEX_HOME/skills/codebase-memory/SKILL.md` only after verifying the canonical
|
||||
copy. Modified or foreign files are preserved; `--force` explicitly authorizes
|
||||
replacement before migration.
|
||||
|
||||
### Sessions, compaction, and subagents
|
||||
|
||||
|
||||
@@ -1313,6 +1313,108 @@ fi
|
||||
echo ""
|
||||
echo "=== Phase 8: agent config install E2E ==="
|
||||
|
||||
# Keep Codex skill placement independent from the broad multi-client fixture:
|
||||
# Warp and OpenHands share the canonical root and could otherwise mask a Codex
|
||||
# regression by creating the expected file themselves.
|
||||
CODEX_ONLY_HOME=$(smoke_mktemp_dir)
|
||||
CODEX_ONLY_CONFIG="$CODEX_ONLY_HOME/vendor-codex"
|
||||
CODEX_ONLY_INSTALL="$CODEX_ONLY_HOME/bin"
|
||||
CODEX_ONLY_SKILL="$CODEX_ONLY_HOME/.agents/skills/codebase-memory/SKILL.md"
|
||||
CODEX_ONLY_LEGACY="$CODEX_ONLY_CONFIG/skills/codebase-memory/SKILL.md"
|
||||
mkdir -p "$CODEX_ONLY_CONFIG" "$CODEX_ONLY_INSTALL"
|
||||
if [[ "$BINARY" == *.exe ]]; then
|
||||
CODEX_ONLY_BIN="$CODEX_ONLY_INSTALL/codebase-memory-mcp.exe"
|
||||
else
|
||||
CODEX_ONLY_BIN="$CODEX_ONLY_INSTALL/codebase-memory-mcp"
|
||||
fi
|
||||
CODEX_ONLY_LOG=$(smoke_mktemp_file)
|
||||
run_codex_only() {
|
||||
local executable="$1"
|
||||
shift
|
||||
HOME="$CODEX_ONLY_HOME" \
|
||||
XDG_CONFIG_HOME="$CODEX_ONLY_HOME/.config" \
|
||||
APPDATA="$CODEX_ONLY_HOME/AppData/Roaming" \
|
||||
LOCALAPPDATA="$CODEX_ONLY_HOME/AppData/Local" \
|
||||
CODEX_HOME="$CODEX_ONLY_CONFIG" \
|
||||
"$executable" "$@" > "$CODEX_ONLY_LOG" 2>&1
|
||||
}
|
||||
if ! run_codex_only "$BINARY" install -y --clients=codex --dir="$CODEX_ONLY_INSTALL"; then
|
||||
echo "FAIL 8-codex-1: isolated Codex install failed"
|
||||
cat "$CODEX_ONLY_LOG"
|
||||
exit 1
|
||||
fi
|
||||
if ! grep -q '^name: codebase-memory$' "$CODEX_ONLY_SKILL" 2>/dev/null ||
|
||||
! grep -q 'trace_path' "$CODEX_ONLY_SKILL" 2>/dev/null ||
|
||||
[ -e "$CODEX_ONLY_LEGACY" ]; then
|
||||
echo "FAIL 8-codex-1: Codex skill was not installed exclusively at the canonical path"
|
||||
cat "$CODEX_ONLY_LOG"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
CODEX_ONLY_HASH=$(smoke_file_sha256 "$CODEX_ONLY_SKILL")
|
||||
if ! run_codex_only "$CODEX_ONLY_BIN" install --plan --clients=codex \
|
||||
--dir="$CODEX_ONLY_INSTALL" ||
|
||||
[ "$(smoke_file_sha256 "$CODEX_ONLY_SKILL")" != "$CODEX_ONLY_HASH" ]; then
|
||||
echo "FAIL 8-codex-2: Codex install plan mutated the canonical skill"
|
||||
cat "$CODEX_ONLY_LOG"
|
||||
exit 1
|
||||
fi
|
||||
if ! run_codex_only "$CODEX_ONLY_BIN" install --dry-run -y --clients=codex \
|
||||
--dir="$CODEX_ONLY_INSTALL" ||
|
||||
[ "$(smoke_file_sha256 "$CODEX_ONLY_SKILL")" != "$CODEX_ONLY_HASH" ]; then
|
||||
echo "FAIL 8-codex-2: Codex dry-run mutated the canonical skill"
|
||||
cat "$CODEX_ONLY_LOG"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p "$(dirname "$CODEX_ONLY_LEGACY")"
|
||||
mv "$CODEX_ONLY_SKILL" "$CODEX_ONLY_LEGACY"
|
||||
if ! run_codex_only "$CODEX_ONLY_BIN" install -y --clients=codex \
|
||||
--dir="$CODEX_ONLY_INSTALL"; then
|
||||
echo "FAIL 8-codex-3: isolated Codex legacy migration failed"
|
||||
cat "$CODEX_ONLY_LOG"
|
||||
exit 1
|
||||
fi
|
||||
if ! grep -q '^name: codebase-memory$' "$CODEX_ONLY_SKILL" 2>/dev/null ||
|
||||
[ -e "$CODEX_ONLY_LEGACY" ]; then
|
||||
echo "FAIL 8-codex-3: Codex legacy skill was not migrated to the canonical path"
|
||||
cat "$CODEX_ONLY_LOG"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
rm -f "$CODEX_ONLY_SKILL"
|
||||
mkdir -p "$(dirname "$CODEX_ONLY_LEGACY")"
|
||||
printf '%s\n' '---' 'name: codebase-memory' '---' 'User-owned legacy skill.' \
|
||||
> "$CODEX_ONLY_LEGACY"
|
||||
CODEX_ONLY_FOREIGN_HASH=$(smoke_file_sha256 "$CODEX_ONLY_LEGACY")
|
||||
if ! run_codex_only "$CODEX_ONLY_BIN" install -y --clients=codex \
|
||||
--dir="$CODEX_ONLY_INSTALL" ||
|
||||
[ -e "$CODEX_ONLY_SKILL" ] ||
|
||||
[ "$(smoke_file_sha256 "$CODEX_ONLY_LEGACY")" != "$CODEX_ONLY_FOREIGN_HASH" ]; then
|
||||
echo "FAIL 8-codex-4: non-force install did not preserve a foreign legacy skill"
|
||||
cat "$CODEX_ONLY_LOG"
|
||||
exit 1
|
||||
fi
|
||||
if ! run_codex_only "$CODEX_ONLY_BIN" install --force -y --clients=codex \
|
||||
--dir="$CODEX_ONLY_INSTALL" ||
|
||||
! grep -q '^name: codebase-memory$' "$CODEX_ONLY_SKILL" 2>/dev/null ||
|
||||
[ -e "$CODEX_ONLY_LEGACY" ]; then
|
||||
echo "FAIL 8-codex-5: force did not converge a foreign legacy skill"
|
||||
cat "$CODEX_ONLY_LOG"
|
||||
exit 1
|
||||
fi
|
||||
CODEX_ONLY_HASH=$(smoke_file_sha256 "$CODEX_ONLY_SKILL")
|
||||
if ! run_codex_only "$CODEX_ONLY_BIN" install -y --clients=codex \
|
||||
--dir="$CODEX_ONLY_INSTALL" ||
|
||||
[ "$(smoke_file_sha256 "$CODEX_ONLY_SKILL")" != "$CODEX_ONLY_HASH" ]; then
|
||||
echo "FAIL 8-codex-6: repeated Codex install was not idempotent"
|
||||
cat "$CODEX_ONLY_LOG"
|
||||
exit 1
|
||||
fi
|
||||
echo "OK: Codex skill placement, previews, migration, force, and idempotence"
|
||||
smoke_rmtree "$CODEX_ONLY_HOME"
|
||||
rm -f "$CODEX_ONLY_LOG"
|
||||
|
||||
# Set up an isolated HOME. Directory-only agents get only the root required for
|
||||
# detection; CLI-detected agents use stubs below so install must create their
|
||||
# config parents from scratch.
|
||||
|
||||
+324
-7
@@ -8112,7 +8112,7 @@ static void print_detected_agents(const cbm_detected_agents_t *a, const char *ho
|
||||
* behavior (it is the same code path with mutations disabled). */
|
||||
typedef struct {
|
||||
char agent[CLI_BUF_32];
|
||||
char kind[CLI_BUF_32]; /* mcp_config | instructions | skills | hook */
|
||||
char kind[CLI_BUF_32]; /* mcp_config | instructions | skill | cleanup_skill | hook */
|
||||
char path[CLI_BUF_1K];
|
||||
} cbm_plan_entry_t;
|
||||
|
||||
@@ -8125,6 +8125,7 @@ typedef struct {
|
||||
static cbm_install_plan_t *g_install_plan = NULL;
|
||||
static int g_agent_install_errors = 0;
|
||||
static int g_agent_uninstall_errors = 0;
|
||||
static char g_blocked_shared_skill_dir[CLI_BUF_1K];
|
||||
|
||||
/* Every agent configuration uninstall could not clean, kept for the closing
|
||||
* summary. A cleanup failure no longer stops executable and index removal
|
||||
@@ -8610,6 +8611,14 @@ static void install_agent_skill(const char *label, const char *skills_dir, bool
|
||||
if (written < 0 || (size_t)written >= sizeof(skill_path)) {
|
||||
return;
|
||||
}
|
||||
if (g_blocked_shared_skill_dir[0] &&
|
||||
(cbm_json_mcp_paths_equal(skills_dir, g_blocked_shared_skill_dir) ||
|
||||
cbm_same_file(skills_dir, g_blocked_shared_skill_dir))) {
|
||||
if (!g_install_plan) {
|
||||
printf(" skill: %s (skipped to avoid a duplicate Codex skill)\n", skill_path);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (g_install_plan) {
|
||||
plan_record(label, "skill", skill_path);
|
||||
return;
|
||||
@@ -8618,6 +8627,272 @@ static void install_agent_skill(const char *label, const char *skills_dir, bool
|
||||
printf(" skill: %s (%d installed)\n", skill_path, installed);
|
||||
}
|
||||
|
||||
typedef enum {
|
||||
CBM_CODEX_SKILL_ABSENT,
|
||||
CBM_CODEX_SKILL_MANAGED,
|
||||
CBM_CODEX_SKILL_UNOWNED,
|
||||
CBM_CODEX_SKILL_UNSAFE,
|
||||
} cbm_codex_skill_state_t;
|
||||
|
||||
typedef struct {
|
||||
char canonical_dir[CLI_BUF_1K];
|
||||
char legacy_dir[CLI_BUF_1K];
|
||||
char canonical_file[CLI_BUF_1K];
|
||||
char legacy_file[CLI_BUF_1K];
|
||||
bool same_dir;
|
||||
} cbm_codex_skill_paths_t;
|
||||
|
||||
static bool cbm_codex_skill_paths_init(const char *home, const char *config_dir,
|
||||
cbm_codex_skill_paths_t *paths) {
|
||||
if (!home || !home[0] || !config_dir || !config_dir[0] || !paths) {
|
||||
return false;
|
||||
}
|
||||
memset(paths, 0, sizeof(*paths));
|
||||
int canonical_dir =
|
||||
snprintf(paths->canonical_dir, sizeof(paths->canonical_dir), "%s/.agents/skills", home);
|
||||
int legacy_dir =
|
||||
snprintf(paths->legacy_dir, sizeof(paths->legacy_dir), "%s/skills", config_dir);
|
||||
int canonical_file = snprintf(paths->canonical_file, sizeof(paths->canonical_file),
|
||||
"%s/codebase-memory/SKILL.md", paths->canonical_dir);
|
||||
int legacy_file = snprintf(paths->legacy_file, sizeof(paths->legacy_file),
|
||||
"%s/codebase-memory/SKILL.md", paths->legacy_dir);
|
||||
if (canonical_dir < 0 || (size_t)canonical_dir >= sizeof(paths->canonical_dir) ||
|
||||
legacy_dir < 0 || (size_t)legacy_dir >= sizeof(paths->legacy_dir) || canonical_file < 0 ||
|
||||
(size_t)canonical_file >= sizeof(paths->canonical_file) || legacy_file < 0 ||
|
||||
(size_t)legacy_file >= sizeof(paths->legacy_file)) {
|
||||
return false;
|
||||
}
|
||||
paths->same_dir = cbm_json_mcp_paths_equal(paths->canonical_dir, paths->legacy_dir) ||
|
||||
cbm_same_file(paths->canonical_dir, paths->legacy_dir);
|
||||
return true;
|
||||
}
|
||||
|
||||
static cbm_codex_skill_state_t cbm_codex_skill_state(const char *skills_dir,
|
||||
const char *skill_file) {
|
||||
char skill_dir[CLI_BUF_1K];
|
||||
int written = snprintf(skill_dir, sizeof(skill_dir), "%s/codebase-memory", skills_dir);
|
||||
if (written < 0 || (size_t)written >= sizeof(skill_dir)) {
|
||||
return CBM_CODEX_SKILL_UNSAFE;
|
||||
}
|
||||
|
||||
struct stat state;
|
||||
errno = 0;
|
||||
#ifndef _WIN32
|
||||
int result = lstat(skill_dir, &state);
|
||||
#else
|
||||
int result = stat(skill_dir, &state);
|
||||
#endif
|
||||
if (result != 0) {
|
||||
return errno == ENOENT ? CBM_CODEX_SKILL_ABSENT : CBM_CODEX_SKILL_UNSAFE;
|
||||
}
|
||||
if (!S_ISDIR(state.st_mode)) {
|
||||
return CBM_CODEX_SKILL_UNSAFE;
|
||||
}
|
||||
|
||||
errno = 0;
|
||||
#ifndef _WIN32
|
||||
result = lstat(skill_file, &state);
|
||||
#else
|
||||
result = stat(skill_file, &state);
|
||||
#endif
|
||||
if (result != 0) {
|
||||
return errno == ENOENT ? CBM_CODEX_SKILL_ABSENT : CBM_CODEX_SKILL_UNSAFE;
|
||||
}
|
||||
if (!S_ISREG(state.st_mode)) {
|
||||
return CBM_CODEX_SKILL_UNSAFE;
|
||||
}
|
||||
|
||||
int ownership = cbm_text_owned_document_status(skill_file, skill_content, NULL, 0);
|
||||
if (ownership == CLI_OK) {
|
||||
return CBM_CODEX_SKILL_MANAGED;
|
||||
}
|
||||
return ownership == CLI_TRUE ? CBM_CODEX_SKILL_UNOWNED : CBM_CODEX_SKILL_UNSAFE;
|
||||
}
|
||||
|
||||
static void cbm_warn_codex_skill_conflict(const cbm_codex_skill_paths_t *paths,
|
||||
const char *reason) {
|
||||
(void)fprintf(stderr,
|
||||
"warning: Codex skill migration skipped: %s; documented_location=%s legacy=%s\n",
|
||||
reason, paths->canonical_file, paths->legacy_file);
|
||||
}
|
||||
|
||||
static void cbm_block_shared_skill_install(const cbm_codex_skill_paths_t *paths) {
|
||||
(void)snprintf(g_blocked_shared_skill_dir, sizeof(g_blocked_shared_skill_dir), "%s",
|
||||
paths->canonical_dir);
|
||||
}
|
||||
|
||||
static void cbm_block_shared_skill_if_codex_conflicts(const char *home, const char *config_dir) {
|
||||
cbm_codex_skill_paths_t paths;
|
||||
if (!cbm_codex_skill_paths_init(home, config_dir, &paths) || paths.same_dir) {
|
||||
return;
|
||||
}
|
||||
|
||||
cbm_codex_skill_state_t canonical =
|
||||
cbm_codex_skill_state(paths.canonical_dir, paths.canonical_file);
|
||||
cbm_codex_skill_state_t legacy = cbm_codex_skill_state(paths.legacy_dir, paths.legacy_file);
|
||||
if (canonical == CBM_CODEX_SKILL_ABSENT && legacy != CBM_CODEX_SKILL_ABSENT) {
|
||||
cbm_block_shared_skill_install(&paths);
|
||||
}
|
||||
}
|
||||
|
||||
static bool cbm_remove_codex_managed_skill(const char *skills_dir, const char *skill_file,
|
||||
bool dry_run, bool uninstalling, const char *operation) {
|
||||
cbm_codex_skill_state_t state = cbm_codex_skill_state(skills_dir, skill_file);
|
||||
if (state == CBM_CODEX_SKILL_ABSENT) {
|
||||
return true;
|
||||
}
|
||||
if (state != CBM_CODEX_SKILL_MANAGED) {
|
||||
if (state == CBM_CODEX_SKILL_UNOWNED) {
|
||||
printf(" preserved non-owned Codex skill: %s\n", skill_file);
|
||||
} else if (dry_run) {
|
||||
printf(" preserved unsafe Codex skill path: %s\n", skill_file);
|
||||
} else if (!dry_run) {
|
||||
record_agent_config_error(uninstalling, "Codex CLI", operation, skill_file);
|
||||
}
|
||||
return state == CBM_CODEX_SKILL_UNOWNED;
|
||||
}
|
||||
if (dry_run) {
|
||||
printf(" Codex skill: %s (would remove)\n", skill_file);
|
||||
return true;
|
||||
}
|
||||
int removed = cbm_remove_skills(skills_dir, false);
|
||||
if (removed == CBM_SKILL_COUNT &&
|
||||
cbm_codex_skill_state(skills_dir, skill_file) == CBM_CODEX_SKILL_ABSENT) {
|
||||
return true;
|
||||
}
|
||||
record_agent_config_error(uninstalling, "Codex CLI", operation, skill_file);
|
||||
return false;
|
||||
}
|
||||
|
||||
static void install_codex_skill(const char *home, const char *config_dir, bool force,
|
||||
bool dry_run) {
|
||||
cbm_codex_skill_paths_t paths;
|
||||
if (!cbm_codex_skill_paths_init(home, config_dir, &paths)) {
|
||||
if (!g_install_plan) {
|
||||
record_agent_config_error(false, "Codex CLI", "skill_path", config_dir);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
cbm_codex_skill_state_t canonical =
|
||||
cbm_codex_skill_state(paths.canonical_dir, paths.canonical_file);
|
||||
cbm_codex_skill_state_t legacy =
|
||||
paths.same_dir ? canonical : cbm_codex_skill_state(paths.legacy_dir, paths.legacy_file);
|
||||
|
||||
if (g_install_plan) {
|
||||
if (canonical == CBM_CODEX_SKILL_ABSENT &&
|
||||
(paths.same_dir || legacy == CBM_CODEX_SKILL_ABSENT ||
|
||||
legacy == CBM_CODEX_SKILL_MANAGED)) {
|
||||
plan_record("Codex CLI", "skill", paths.canonical_file);
|
||||
}
|
||||
if (!paths.same_dir && legacy == CBM_CODEX_SKILL_MANAGED &&
|
||||
(canonical == CBM_CODEX_SKILL_ABSENT || canonical == CBM_CODEX_SKILL_MANAGED)) {
|
||||
plan_record("Codex CLI", "cleanup_skill", paths.legacy_file);
|
||||
}
|
||||
if (canonical == CBM_CODEX_SKILL_ABSENT &&
|
||||
(legacy == CBM_CODEX_SKILL_UNOWNED || legacy == CBM_CODEX_SKILL_UNSAFE)) {
|
||||
cbm_block_shared_skill_install(&paths);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (paths.same_dir) {
|
||||
if (canonical == CBM_CODEX_SKILL_UNSAFE) {
|
||||
record_agent_config_error(false, "Codex CLI", "skill_install", paths.canonical_file);
|
||||
return;
|
||||
}
|
||||
if (!force && canonical == CBM_CODEX_SKILL_UNOWNED) {
|
||||
printf(" preserved non-owned Codex skill: %s\n", paths.canonical_file);
|
||||
return;
|
||||
}
|
||||
install_agent_skill("Codex CLI", paths.canonical_dir, force, dry_run);
|
||||
if (!dry_run && cbm_codex_skill_state(paths.canonical_dir, paths.canonical_file) !=
|
||||
CBM_CODEX_SKILL_MANAGED) {
|
||||
record_agent_config_error(false, "Codex CLI", "skill_install", paths.canonical_file);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (canonical == CBM_CODEX_SKILL_UNSAFE) {
|
||||
if (dry_run) {
|
||||
cbm_warn_codex_skill_conflict(&paths, "the canonical skill path is unsafe");
|
||||
} else {
|
||||
record_agent_config_error(false, "Codex CLI", "skill_install", paths.canonical_file);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (legacy == CBM_CODEX_SKILL_UNSAFE) {
|
||||
if (canonical == CBM_CODEX_SKILL_ABSENT) {
|
||||
cbm_block_shared_skill_install(&paths);
|
||||
}
|
||||
if (force && !dry_run) {
|
||||
record_agent_config_error(false, "Codex CLI", "legacy_skill_migration",
|
||||
paths.legacy_file);
|
||||
} else {
|
||||
cbm_warn_codex_skill_conflict(&paths, "the legacy skill path is unsafe");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!force && legacy == CBM_CODEX_SKILL_UNOWNED) {
|
||||
if (canonical == CBM_CODEX_SKILL_ABSENT) {
|
||||
cbm_block_shared_skill_install(&paths);
|
||||
}
|
||||
cbm_warn_codex_skill_conflict(&paths, "the legacy skill is not installer-owned");
|
||||
return;
|
||||
}
|
||||
if (!force && canonical == CBM_CODEX_SKILL_UNOWNED) {
|
||||
if (legacy == CBM_CODEX_SKILL_MANAGED) {
|
||||
cbm_warn_codex_skill_conflict(&paths, "the canonical skill is not installer-owned");
|
||||
} else {
|
||||
printf(" preserved non-owned Codex skill: %s\n", paths.canonical_file);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
bool remove_legacy = legacy == CBM_CODEX_SKILL_MANAGED;
|
||||
if (force && legacy == CBM_CODEX_SKILL_UNOWNED) {
|
||||
remove_legacy = true;
|
||||
if (dry_run) {
|
||||
printf(" legacy Codex skill: %s (would replace for migration)\n", paths.legacy_file);
|
||||
} else {
|
||||
int replaced = cbm_install_skills(paths.legacy_dir, true, false);
|
||||
printf(" legacy Codex skill: %s (%d updated for migration)\n", paths.legacy_file,
|
||||
replaced);
|
||||
if (cbm_codex_skill_state(paths.legacy_dir, paths.legacy_file) !=
|
||||
CBM_CODEX_SKILL_MANAGED) {
|
||||
record_agent_config_error(false, "Codex CLI", "legacy_skill_migration",
|
||||
paths.legacy_file);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool install_canonical = force || canonical == CBM_CODEX_SKILL_ABSENT;
|
||||
if (install_canonical) {
|
||||
install_agent_skill("Codex CLI", paths.canonical_dir, force, dry_run);
|
||||
} else {
|
||||
printf(" skill: %s (0 installed)\n", paths.canonical_file);
|
||||
}
|
||||
|
||||
if (dry_run) {
|
||||
if (remove_legacy) {
|
||||
printf(" legacy Codex skill: %s (would remove after canonical install)\n",
|
||||
paths.legacy_file);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (cbm_codex_skill_state(paths.canonical_dir, paths.canonical_file) !=
|
||||
CBM_CODEX_SKILL_MANAGED) {
|
||||
record_agent_config_error(false, "Codex CLI", "skill_install", paths.canonical_file);
|
||||
return;
|
||||
}
|
||||
if (remove_legacy && cbm_remove_codex_managed_skill(paths.legacy_dir, paths.legacy_file, false,
|
||||
false, "legacy_skill_cleanup")) {
|
||||
printf(" legacy Codex skill: %s (removed)\n", paths.legacy_file);
|
||||
}
|
||||
}
|
||||
|
||||
/* Derive tier siblings only from the exact shipped Verify basename. This keeps
|
||||
* vendor-specific suffixes such as .agent.md, .toml, and .json intact. */
|
||||
static int cbm_tiered_profile_path(const char *verify_path, cbm_graph_tier_t tier, char *output,
|
||||
@@ -9502,12 +9777,10 @@ static void install_cli_agent_configs(const cbm_detected_agents_t *agents, const
|
||||
char config_dir[CLI_BUF_1K];
|
||||
char cp[CLI_BUF_1K];
|
||||
char ip[CLI_BUF_1K];
|
||||
char skills_dir[CLI_BUF_1K];
|
||||
char ap[CLI_BUF_1K];
|
||||
cbm_codex_config_dir(home, config_dir, sizeof(config_dir));
|
||||
snprintf(cp, sizeof(cp), "%s/config.toml", config_dir);
|
||||
snprintf(ip, sizeof(ip), "%s/AGENTS.md", config_dir);
|
||||
snprintf(skills_dir, sizeof(skills_dir), "%s/skills", config_dir);
|
||||
snprintf(ap, sizeof(ap), "%s/agents/codebase-memory.toml", config_dir);
|
||||
/* A broken hook config must not keep legacy full guidance active. */
|
||||
bool pointer_installed = install_codex_activation_pointer(ip, dry_run);
|
||||
@@ -9528,6 +9801,7 @@ static void install_cli_agent_configs(const cbm_detected_agents_t *agents, const
|
||||
true, &preflight_failure)
|
||||
: CLI_ERR;
|
||||
if (preflight_result != CLI_OK) {
|
||||
cbm_block_shared_skill_if_codex_conflicts(home, config_dir);
|
||||
if (!g_install_plan) {
|
||||
printf("Codex CLI:\n");
|
||||
fflush(stdout);
|
||||
@@ -9548,7 +9822,7 @@ static void install_cli_agent_configs(const cbm_detected_agents_t *agents, const
|
||||
if (!g_install_plan) {
|
||||
report_codex_activation_pointer_install(ip, pointer_installed);
|
||||
}
|
||||
install_agent_skill("Codex CLI", skills_dir, force, dry_run);
|
||||
install_codex_skill(home, config_dir, force, dry_run);
|
||||
install_tiered_agent_profiles(
|
||||
(cbm_tiered_profile_set_t){
|
||||
.label = "Codex CLI",
|
||||
@@ -10332,6 +10606,7 @@ static int cbm_install_agent_configs_in_scope(const char *home, const char *bina
|
||||
|
||||
int cbm_install_agent_configs(const char *home, const char *binary_path, bool force, bool dry_run) {
|
||||
g_agent_install_errors = 0;
|
||||
g_blocked_shared_skill_dir[0] = '\0';
|
||||
cbm_detected_agents_t agents = cbm_detect_agents(home);
|
||||
if (g_client_selection && !cli_clients_apply_selection(g_client_selection, &agents)) {
|
||||
return CLI_ERR;
|
||||
@@ -10837,6 +11112,7 @@ static char *cbm_build_install_plan_json_options(const char *home, const char *b
|
||||
yyjson_mut_val *agent_files = yyjson_mut_arr(doc);
|
||||
yyjson_mut_val *prompt_files = yyjson_mut_arr(doc);
|
||||
yyjson_mut_val *hooks = yyjson_mut_arr(doc);
|
||||
yyjson_mut_val *cleanup_actions = yyjson_mut_arr(doc);
|
||||
for (int i = 0; i < plan.count; i++) {
|
||||
cbm_plan_entry_t *e = &plan.items[i];
|
||||
if (strcmp(e->kind, "mcp_config") == 0) {
|
||||
@@ -10855,6 +11131,14 @@ static char *cbm_build_install_plan_json_options(const char *home, const char *b
|
||||
} else if (strcmp(e->kind, "prompt") == 0) {
|
||||
yyjson_mut_arr_add_strcpy(doc, prompt_files, e->path);
|
||||
yyjson_mut_arr_add_strcpy(doc, instrs, e->path);
|
||||
} else if (strcmp(e->kind, "cleanup_skill") == 0) {
|
||||
yyjson_mut_val *cleanup = yyjson_mut_obj(doc);
|
||||
yyjson_mut_obj_add_strcpy(doc, cleanup, "agent", e->agent);
|
||||
yyjson_mut_obj_add_str(doc, cleanup, "kind", "skill");
|
||||
yyjson_mut_obj_add_str(doc, cleanup, "operation",
|
||||
"remove_owned_legacy_copy_if_migrated");
|
||||
yyjson_mut_obj_add_strcpy(doc, cleanup, "path", e->path);
|
||||
yyjson_mut_arr_add_val(cleanup_actions, cleanup);
|
||||
} else {
|
||||
yyjson_mut_arr_add_strcpy(doc, instrs, e->path);
|
||||
}
|
||||
@@ -10865,6 +11149,7 @@ static char *cbm_build_install_plan_json_options(const char *home, const char *b
|
||||
yyjson_mut_obj_add_val(doc, root, "agent_files_planned", agent_files);
|
||||
yyjson_mut_obj_add_val(doc, root, "prompt_files_planned", prompt_files);
|
||||
yyjson_mut_obj_add_val(doc, root, "hooks_planned", hooks);
|
||||
yyjson_mut_obj_add_val(doc, root, "cleanup_actions_planned", cleanup_actions);
|
||||
yyjson_mut_obj_add_bool(doc, root, "writes_started", false);
|
||||
yyjson_mut_obj_add_bool(doc, root, "network_after_install", false);
|
||||
yyjson_mut_obj_add_str(doc, root, "next_safe_command", "codebase-memory-mcp install -y");
|
||||
@@ -11568,6 +11853,40 @@ static void uninstall_agent_skill(const char *label, const char *skills_dir, boo
|
||||
printf(" %s skill: %d removed\n", label, removed);
|
||||
}
|
||||
|
||||
static void uninstall_codex_skills(const char *home, const char *config_dir, bool dry_run) {
|
||||
cbm_codex_skill_paths_t paths;
|
||||
if (!cbm_codex_skill_paths_init(home, config_dir, &paths)) {
|
||||
if (!dry_run) {
|
||||
record_agent_config_error(true, "Codex CLI", "skill_path", config_dir);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
int removed = 0;
|
||||
if (cbm_codex_skill_state(paths.canonical_dir, paths.canonical_file) ==
|
||||
CBM_CODEX_SKILL_MANAGED) {
|
||||
if (cbm_remove_codex_managed_skill(paths.canonical_dir, paths.canonical_file, dry_run, true,
|
||||
"skill_uninstall")) {
|
||||
removed++;
|
||||
}
|
||||
} else {
|
||||
(void)cbm_remove_codex_managed_skill(paths.canonical_dir, paths.canonical_file, dry_run,
|
||||
true, "skill_uninstall");
|
||||
}
|
||||
|
||||
if (!paths.same_dir &&
|
||||
cbm_codex_skill_state(paths.legacy_dir, paths.legacy_file) == CBM_CODEX_SKILL_MANAGED) {
|
||||
if (cbm_remove_codex_managed_skill(paths.legacy_dir, paths.legacy_file, dry_run, true,
|
||||
"legacy_skill_uninstall")) {
|
||||
removed++;
|
||||
}
|
||||
} else if (!paths.same_dir) {
|
||||
(void)cbm_remove_codex_managed_skill(paths.legacy_dir, paths.legacy_file, dry_run, true,
|
||||
"legacy_skill_uninstall");
|
||||
}
|
||||
printf(" Codex CLI skills: %d removed\n", removed);
|
||||
}
|
||||
|
||||
static void uninstall_copilot_durable_context(const char *home, bool dry_run) {
|
||||
char config_dir[CLI_BUF_1K];
|
||||
char hook_path[CLI_BUF_1K];
|
||||
@@ -11989,13 +12308,11 @@ static void uninstall_cli_agents(const cbm_detected_agents_t *agents, const char
|
||||
char config_dir[CLI_BUF_1K];
|
||||
char cp[CLI_BUF_1K];
|
||||
char ip[CLI_BUF_1K];
|
||||
char skills_dir[CLI_BUF_1K];
|
||||
char ap[CLI_BUF_1K];
|
||||
char installed_binary[CLI_BUF_1K];
|
||||
cbm_codex_config_dir(home, config_dir, sizeof(config_dir));
|
||||
snprintf(cp, sizeof(cp), "%s/config.toml", config_dir);
|
||||
snprintf(ip, sizeof(ip), "%s/AGENTS.md", config_dir);
|
||||
snprintf(skills_dir, sizeof(skills_dir), "%s/skills", config_dir);
|
||||
snprintf(ap, sizeof(ap), "%s/agents/codebase-memory.toml", config_dir);
|
||||
bool pointer_removed = uninstall_codex_activation_pointer(ip, dry_run);
|
||||
cbm_agent_installed_binary_path(home, installed_binary, sizeof(installed_binary));
|
||||
@@ -12030,7 +12347,7 @@ static void uninstall_cli_agents(const cbm_detected_agents_t *agents, const char
|
||||
record_agent_config_error(true, "Codex CLI", "hook_uninstall", cp);
|
||||
}
|
||||
codex_toml_done:
|
||||
uninstall_agent_skill("Codex CLI", skills_dir, dry_run);
|
||||
uninstall_codex_skills(home, config_dir, dry_run);
|
||||
uninstall_tiered_agent_profiles(
|
||||
(cbm_tiered_profile_set_t){
|
||||
.label = "Codex CLI",
|
||||
|
||||
+329
-8
@@ -6799,7 +6799,6 @@ TEST(cli_durable_profiles_follow_current_vendor_paths) {
|
||||
strstr(plan, "\"instruction_files_planned\"");
|
||||
const char *const planned[] = {
|
||||
"/.claude/agents/codebase-memory.md",
|
||||
"/vendor-codex/skills/codebase-memory/SKILL.md",
|
||||
"/vendor-codex/agents/codebase-memory.toml",
|
||||
"/.cursor/skills/codebase-memory/SKILL.md",
|
||||
"/.cursor/agents/codebase-memory.md",
|
||||
@@ -6962,13 +6961,12 @@ TEST(cli_durable_profiles_follow_current_vendor_paths) {
|
||||
free(profile);
|
||||
|
||||
const char *const skill_files[] = {
|
||||
"/skills/codebase-memory/SKILL.md",
|
||||
"/.cursor/skills/codebase-memory/SKILL.md",
|
||||
"/.config/opencode/skills/codebase-memory/SKILL.md",
|
||||
"/.factory/skills/codebase-memory/SKILL.md",
|
||||
"/.agents/skills/codebase-memory/SKILL.md",
|
||||
};
|
||||
const char *const skill_roots[] = {codex_home, tmpdir, tmpdir, tmpdir, tmpdir};
|
||||
const char *const skill_roots[] = {tmpdir, tmpdir, tmpdir, tmpdir};
|
||||
for (size_t i = 0U; files_ok && i < sizeof(skill_files) / sizeof(skill_files[0]); i++) {
|
||||
snprintf(path, sizeof(path), "%s%s", skill_roots[i], skill_files[i]);
|
||||
files_ok = test_file_contains_all(path, graph_terms, 3);
|
||||
@@ -9382,12 +9380,21 @@ TEST(cli_codex_respects_codex_home) {
|
||||
char *json = cbm_build_install_plan_json(tmpdir, "/usr/local/bin/codebase-memory-mcp");
|
||||
char expected_config[640];
|
||||
snprintf(expected_config, sizeof(expected_config), "%s/config.toml", codex_home);
|
||||
char expected_skill[640];
|
||||
char legacy_skill[640];
|
||||
snprintf(expected_skill, sizeof(expected_skill), "%s/.agents/skills/codebase-memory/SKILL.md",
|
||||
tmpdir);
|
||||
snprintf(legacy_skill, sizeof(legacy_skill), "%s/skills/codebase-memory/SKILL.md", codex_home);
|
||||
yyjson_doc *plan_doc = json ? yyjson_read(json, strlen(json), 0) : NULL;
|
||||
yyjson_val *plan_root = plan_doc ? yyjson_doc_get_root(plan_doc) : NULL;
|
||||
bool plans_config = test_json_string_array_contains(plan_root, "config_files_planned",
|
||||
expected_config);
|
||||
bool plans_instructions = test_json_string_array_contains(
|
||||
plan_root, "instruction_files_planned", expected_instructions);
|
||||
bool plans_canonical_skill =
|
||||
test_json_string_array_contains(plan_root, "skill_files_planned", expected_skill);
|
||||
bool plans_legacy_skill =
|
||||
test_json_string_array_contains(plan_root, "skill_files_planned", legacy_skill);
|
||||
bool plans_cleanup = json && strstr(json, "remove_managed_block_if_present") != NULL;
|
||||
char *instructions_after = read_test_file_alloc(expected_instructions);
|
||||
bool plan_preserved_user_file =
|
||||
@@ -9401,9 +9408,10 @@ TEST(cli_codex_respects_codex_home) {
|
||||
|
||||
if (!agents.codex)
|
||||
FAIL("Codex detection must honor CODEX_HOME");
|
||||
if (!plans_config || !plans_instructions || plans_cleanup || !plan_preserved_user_file)
|
||||
if (!plans_config || !plans_instructions || !plans_canonical_skill || plans_legacy_skill ||
|
||||
plans_cleanup || !plan_preserved_user_file)
|
||||
FAIL("Codex plan must include the managed activation pointer under CODEX_HOME without "
|
||||
"mutating existing user content");
|
||||
"mutating existing user content, and use HOME/.agents for the skill");
|
||||
PASS();
|
||||
}
|
||||
|
||||
@@ -9529,7 +9537,6 @@ TEST(cli_codex_install_uses_global_activation_pointer_issue1689) {
|
||||
restore_test_env("PATH", saved_path);
|
||||
restore_test_env("CODEX_HOME", saved_codex);
|
||||
test_rmdir_r(tmpdir);
|
||||
|
||||
if (!fresh_pointer_installed || !other_surfaces_installed || !unowned_preserved ||
|
||||
!managed_migrated_once || !marker_only_migrated || !malformed_preserved ||
|
||||
!uninstall_preserved_foreign)
|
||||
@@ -9581,6 +9588,300 @@ TEST(cli_grok_respects_grok_home) {
|
||||
PASS();
|
||||
}
|
||||
|
||||
static bool cli_test_file_equals(const char *path, const char *expected) {
|
||||
char *data = read_test_file_alloc(path);
|
||||
bool equal = data && strcmp(data, expected) == 0;
|
||||
free(data);
|
||||
return equal;
|
||||
}
|
||||
|
||||
TEST(cli_codex_skill_migrates_owned_legacy_to_agents_root) {
|
||||
char tmpdir[256];
|
||||
snprintf(tmpdir, sizeof(tmpdir), "/tmp/cli-codex-skill-migrate-XXXXXX");
|
||||
if (!cbm_mkdtemp(tmpdir))
|
||||
FAIL("cbm_mkdtemp failed");
|
||||
|
||||
char codex_home[512];
|
||||
char legacy_root[640];
|
||||
char legacy_file[768];
|
||||
char sibling_file[768];
|
||||
char canonical_file[768];
|
||||
snprintf(codex_home, sizeof(codex_home), "%s/vendor-codex", tmpdir);
|
||||
snprintf(legacy_root, sizeof(legacy_root), "%s/skills", codex_home);
|
||||
snprintf(legacy_file, sizeof(legacy_file), "%s/codebase-memory/SKILL.md", legacy_root);
|
||||
snprintf(sibling_file, sizeof(sibling_file), "%s/codebase-memory/notes.md", legacy_root);
|
||||
snprintf(canonical_file, sizeof(canonical_file), "%s/.agents/skills/codebase-memory/SKILL.md",
|
||||
tmpdir);
|
||||
test_mkdirp(codex_home);
|
||||
ASSERT_EQ(cbm_install_skills(legacy_root, false, false), CBM_SKILL_COUNT);
|
||||
write_test_file(sibling_file, "user notes\n");
|
||||
|
||||
char *saved_home = save_test_env("HOME");
|
||||
char *saved_path = save_test_env("PATH");
|
||||
char *saved_codex = save_test_env("CODEX_HOME");
|
||||
cbm_setenv("HOME", tmpdir, 1);
|
||||
cbm_setenv("PATH", tmpdir, 1);
|
||||
cbm_setenv("CODEX_HOME", codex_home, 1);
|
||||
|
||||
int dry_rc = cbm_install_agent_configs(tmpdir, "/opt/codebase-memory-mcp", false, true);
|
||||
struct stat state;
|
||||
bool dry_safe = dry_rc == 0 && stat(canonical_file, &state) != 0 &&
|
||||
cli_test_file_equals(legacy_file, cbm_get_skills()[0].content);
|
||||
char *plan = cbm_build_install_plan_json(tmpdir, "/opt/codebase-memory-mcp");
|
||||
bool plan_ok = plan && strstr(plan, canonical_file) && strstr(plan, legacy_file) &&
|
||||
strstr(plan, "cleanup_actions_planned") &&
|
||||
strstr(plan, "remove_owned_legacy_copy_if_migrated");
|
||||
bool plan_safe = stat(canonical_file, &state) != 0 &&
|
||||
cli_test_file_equals(legacy_file, cbm_get_skills()[0].content);
|
||||
free(plan);
|
||||
|
||||
int install_rc = cbm_install_agent_configs(tmpdir, "/opt/codebase-memory-mcp", false, false);
|
||||
bool migrated =
|
||||
install_rc == 0 && cli_test_file_equals(canonical_file, cbm_get_skills()[0].content) &&
|
||||
stat(legacy_file, &state) != 0 && cli_test_file_equals(sibling_file, "user notes\n");
|
||||
|
||||
restore_test_env("HOME", saved_home);
|
||||
restore_test_env("PATH", saved_path);
|
||||
restore_test_env("CODEX_HOME", saved_codex);
|
||||
test_rmdir_r(tmpdir);
|
||||
|
||||
if (!dry_safe || !plan_ok || !plan_safe || !migrated)
|
||||
FAIL("Codex owned legacy skill migration must be previewable, destination-first, and "
|
||||
"sibling-safe");
|
||||
PASS();
|
||||
}
|
||||
|
||||
TEST(cli_codex_skill_preserves_foreign_legacy_until_force) {
|
||||
char tmpdir[256];
|
||||
snprintf(tmpdir, sizeof(tmpdir), "/tmp/cli-codex-skill-foreign-legacy-XXXXXX");
|
||||
if (!cbm_mkdtemp(tmpdir))
|
||||
FAIL("cbm_mkdtemp failed");
|
||||
|
||||
const char *foreign = "---\nname: codebase-memory\n---\nUser-owned legacy skill.\n";
|
||||
char codex_home[512];
|
||||
char legacy_dir[768];
|
||||
char legacy_file[768];
|
||||
char sibling_file[768];
|
||||
char canonical_file[768];
|
||||
snprintf(codex_home, sizeof(codex_home), "%s/vendor-codex", tmpdir);
|
||||
snprintf(legacy_dir, sizeof(legacy_dir), "%s/skills/codebase-memory", codex_home);
|
||||
snprintf(legacy_file, sizeof(legacy_file), "%s/SKILL.md", legacy_dir);
|
||||
snprintf(sibling_file, sizeof(sibling_file), "%s/user.txt", legacy_dir);
|
||||
snprintf(canonical_file, sizeof(canonical_file), "%s/.agents/skills/codebase-memory/SKILL.md",
|
||||
tmpdir);
|
||||
test_mkdirp(legacy_dir);
|
||||
write_test_file(legacy_file, foreign);
|
||||
write_test_file(sibling_file, "keep\n");
|
||||
|
||||
char *saved_home = save_test_env("HOME");
|
||||
char *saved_path = save_test_env("PATH");
|
||||
char *saved_codex = save_test_env("CODEX_HOME");
|
||||
cbm_setenv("HOME", tmpdir, 1);
|
||||
cbm_setenv("PATH", tmpdir, 1);
|
||||
cbm_setenv("CODEX_HOME", codex_home, 1);
|
||||
|
||||
int normal_rc = cbm_install_agent_configs(tmpdir, "/opt/codebase-memory-mcp", false, false);
|
||||
struct stat state;
|
||||
bool preserved = normal_rc == 0 && cli_test_file_equals(legacy_file, foreign) &&
|
||||
stat(canonical_file, &state) != 0;
|
||||
int force_rc = cbm_install_agent_configs(tmpdir, "/opt/codebase-memory-mcp", true, false);
|
||||
bool forced = force_rc == 0 &&
|
||||
cli_test_file_equals(canonical_file, cbm_get_skills()[0].content) &&
|
||||
stat(legacy_file, &state) != 0 && cli_test_file_equals(sibling_file, "keep\n");
|
||||
|
||||
restore_test_env("HOME", saved_home);
|
||||
restore_test_env("PATH", saved_path);
|
||||
restore_test_env("CODEX_HOME", saved_codex);
|
||||
test_rmdir_r(tmpdir);
|
||||
if (!preserved || !forced)
|
||||
FAIL("Codex must preserve foreign legacy content unless --force authorizes replacement");
|
||||
PASS();
|
||||
}
|
||||
|
||||
TEST(cli_codex_skill_preserves_foreign_canonical_and_owned_legacy) {
|
||||
char tmpdir[256];
|
||||
snprintf(tmpdir, sizeof(tmpdir), "/tmp/cli-codex-skill-foreign-canonical-XXXXXX");
|
||||
if (!cbm_mkdtemp(tmpdir))
|
||||
FAIL("cbm_mkdtemp failed");
|
||||
|
||||
const char *foreign = "---\nname: codebase-memory\n---\nUser-owned canonical skill.\n";
|
||||
char codex_home[512];
|
||||
char legacy_root[640];
|
||||
char legacy_file[768];
|
||||
char canonical_dir[768];
|
||||
char canonical_file[768];
|
||||
snprintf(codex_home, sizeof(codex_home), "%s/vendor-codex", tmpdir);
|
||||
snprintf(legacy_root, sizeof(legacy_root), "%s/skills", codex_home);
|
||||
snprintf(legacy_file, sizeof(legacy_file), "%s/codebase-memory/SKILL.md", legacy_root);
|
||||
snprintf(canonical_dir, sizeof(canonical_dir), "%s/.agents/skills/codebase-memory", tmpdir);
|
||||
snprintf(canonical_file, sizeof(canonical_file), "%s/SKILL.md", canonical_dir);
|
||||
test_mkdirp(codex_home);
|
||||
ASSERT_EQ(cbm_install_skills(legacy_root, false, false), CBM_SKILL_COUNT);
|
||||
test_mkdirp(canonical_dir);
|
||||
write_test_file(canonical_file, foreign);
|
||||
|
||||
char *saved_home = save_test_env("HOME");
|
||||
char *saved_path = save_test_env("PATH");
|
||||
char *saved_codex = save_test_env("CODEX_HOME");
|
||||
cbm_setenv("HOME", tmpdir, 1);
|
||||
cbm_setenv("PATH", tmpdir, 1);
|
||||
cbm_setenv("CODEX_HOME", codex_home, 1);
|
||||
|
||||
int normal_rc = cbm_install_agent_configs(tmpdir, "/opt/codebase-memory-mcp", false, false);
|
||||
bool preserved = normal_rc == 0 && cli_test_file_equals(canonical_file, foreign) &&
|
||||
cli_test_file_equals(legacy_file, cbm_get_skills()[0].content);
|
||||
int force_rc = cbm_install_agent_configs(tmpdir, "/opt/codebase-memory-mcp", true, false);
|
||||
struct stat state;
|
||||
bool forced = force_rc == 0 &&
|
||||
cli_test_file_equals(canonical_file, cbm_get_skills()[0].content) &&
|
||||
stat(legacy_file, &state) != 0;
|
||||
|
||||
restore_test_env("HOME", saved_home);
|
||||
restore_test_env("PATH", saved_path);
|
||||
restore_test_env("CODEX_HOME", saved_codex);
|
||||
test_rmdir_r(tmpdir);
|
||||
if (!preserved || !forced)
|
||||
FAIL("Codex must preserve conflicting canonical bytes and its owned legacy copy until "
|
||||
"--force");
|
||||
PASS();
|
||||
}
|
||||
|
||||
TEST(cli_codex_skill_failed_destination_preserves_owned_legacy) {
|
||||
char tmpdir[256];
|
||||
snprintf(tmpdir, sizeof(tmpdir), "/tmp/cli-codex-skill-failed-destination-XXXXXX");
|
||||
if (!cbm_mkdtemp(tmpdir))
|
||||
FAIL("cbm_mkdtemp failed");
|
||||
|
||||
char codex_home[512];
|
||||
char legacy_root[640];
|
||||
char legacy_file[768];
|
||||
char canonical_root[640];
|
||||
char blocked_path[768];
|
||||
snprintf(codex_home, sizeof(codex_home), "%s/vendor-codex", tmpdir);
|
||||
snprintf(legacy_root, sizeof(legacy_root), "%s/skills", codex_home);
|
||||
snprintf(legacy_file, sizeof(legacy_file), "%s/codebase-memory/SKILL.md", legacy_root);
|
||||
snprintf(canonical_root, sizeof(canonical_root), "%s/.agents/skills", tmpdir);
|
||||
snprintf(blocked_path, sizeof(blocked_path), "%s/codebase-memory", canonical_root);
|
||||
test_mkdirp(codex_home);
|
||||
ASSERT_EQ(cbm_install_skills(legacy_root, false, false), CBM_SKILL_COUNT);
|
||||
test_mkdirp(canonical_root);
|
||||
write_test_file(blocked_path, "not a directory\n");
|
||||
|
||||
char *saved_home = save_test_env("HOME");
|
||||
char *saved_path = save_test_env("PATH");
|
||||
char *saved_codex = save_test_env("CODEX_HOME");
|
||||
cbm_setenv("HOME", tmpdir, 1);
|
||||
cbm_setenv("PATH", tmpdir, 1);
|
||||
cbm_setenv("CODEX_HOME", codex_home, 1);
|
||||
int rc = cbm_install_agent_configs(tmpdir, "/opt/codebase-memory-mcp", false, false);
|
||||
bool safe = rc != 0 && cli_test_file_equals(blocked_path, "not a directory\n") &&
|
||||
cli_test_file_equals(legacy_file, cbm_get_skills()[0].content);
|
||||
|
||||
restore_test_env("HOME", saved_home);
|
||||
restore_test_env("PATH", saved_path);
|
||||
restore_test_env("CODEX_HOME", saved_codex);
|
||||
test_rmdir_r(tmpdir);
|
||||
if (!safe)
|
||||
FAIL("Codex migration must retain the owned legacy copy when canonical publication fails");
|
||||
PASS();
|
||||
}
|
||||
|
||||
TEST(cli_codex_skill_uninstall_cleans_both_owned_locations) {
|
||||
char tmpdir[256];
|
||||
snprintf(tmpdir, sizeof(tmpdir), "/tmp/cli-codex-skill-uninstall-XXXXXX");
|
||||
if (!cbm_mkdtemp(tmpdir))
|
||||
FAIL("cbm_mkdtemp failed");
|
||||
|
||||
char codex_home[512];
|
||||
char canonical_root[640];
|
||||
char legacy_root[640];
|
||||
char canonical_file[768];
|
||||
char legacy_file[768];
|
||||
char binary_dir[640];
|
||||
char binary_path[768];
|
||||
snprintf(codex_home, sizeof(codex_home), "%s/.codex", tmpdir);
|
||||
snprintf(canonical_root, sizeof(canonical_root), "%s/.agents/skills", tmpdir);
|
||||
snprintf(legacy_root, sizeof(legacy_root), "%s/skills", codex_home);
|
||||
snprintf(canonical_file, sizeof(canonical_file), "%s/codebase-memory/SKILL.md", canonical_root);
|
||||
snprintf(legacy_file, sizeof(legacy_file), "%s/codebase-memory/SKILL.md", legacy_root);
|
||||
snprintf(binary_dir, sizeof(binary_dir), "%s/.local/bin", tmpdir);
|
||||
#ifdef _WIN32
|
||||
snprintf(binary_path, sizeof(binary_path), "%s/codebase-memory-mcp.exe", binary_dir);
|
||||
#else
|
||||
snprintf(binary_path, sizeof(binary_path), "%s/codebase-memory-mcp", binary_dir);
|
||||
#endif
|
||||
test_mkdirp(codex_home);
|
||||
test_mkdirp(binary_dir);
|
||||
write_test_file(binary_path, "installed binary\n");
|
||||
ASSERT_EQ(cbm_install_skills(canonical_root, false, false), CBM_SKILL_COUNT);
|
||||
ASSERT_EQ(cbm_install_skills(legacy_root, false, false), CBM_SKILL_COUNT);
|
||||
|
||||
char *saved_home = save_test_env("HOME");
|
||||
char *saved_path = save_test_env("PATH");
|
||||
char *saved_codex = save_test_env("CODEX_HOME");
|
||||
cbm_setenv("HOME", tmpdir, 1);
|
||||
cbm_setenv("PATH", tmpdir, 1);
|
||||
cbm_unsetenv("CODEX_HOME");
|
||||
char *argv[] = {"uninstall", "--yes"};
|
||||
int owned_rc = cli_test_cmd_uninstall(2, argv);
|
||||
struct stat state;
|
||||
bool owned_removed =
|
||||
owned_rc == 0 && stat(canonical_file, &state) != 0 && stat(legacy_file, &state) != 0;
|
||||
|
||||
const char *foreign = "---\nname: codebase-memory\n---\nUser-owned canonical skill.\n";
|
||||
write_test_file(binary_path, "installed binary\n");
|
||||
bool mixed_seeded = cbm_install_skills(canonical_root, false, false) == CBM_SKILL_COUNT &&
|
||||
cbm_install_skills(legacy_root, false, false) == CBM_SKILL_COUNT;
|
||||
if (mixed_seeded) {
|
||||
write_test_file(canonical_file, foreign);
|
||||
}
|
||||
int mixed_rc = mixed_seeded ? cli_test_cmd_uninstall(2, argv) : 1;
|
||||
bool mixed_safe = mixed_rc == 0 && cli_test_file_equals(canonical_file, foreign) &&
|
||||
stat(legacy_file, &state) != 0;
|
||||
|
||||
restore_test_env("HOME", saved_home);
|
||||
restore_test_env("PATH", saved_path);
|
||||
restore_test_env("CODEX_HOME", saved_codex);
|
||||
test_rmdir_r(tmpdir);
|
||||
if (!owned_removed || !mixed_safe)
|
||||
FAIL("Codex uninstall must clean both owned roots while preserving foreign skill bytes");
|
||||
PASS();
|
||||
}
|
||||
|
||||
TEST(cli_codex_skill_deduplicates_agents_codex_home) {
|
||||
char tmpdir[256];
|
||||
snprintf(tmpdir, sizeof(tmpdir), "/tmp/cli-codex-skill-same-root-XXXXXX");
|
||||
if (!cbm_mkdtemp(tmpdir))
|
||||
FAIL("cbm_mkdtemp failed");
|
||||
|
||||
char codex_home[512];
|
||||
char skill_file[768];
|
||||
snprintf(codex_home, sizeof(codex_home), "%s/.agents", tmpdir);
|
||||
snprintf(skill_file, sizeof(skill_file), "%s/skills/codebase-memory/SKILL.md", codex_home);
|
||||
test_mkdirp(codex_home);
|
||||
char *saved_home = save_test_env("HOME");
|
||||
char *saved_path = save_test_env("PATH");
|
||||
char *saved_codex = save_test_env("CODEX_HOME");
|
||||
cbm_setenv("HOME", tmpdir, 1);
|
||||
cbm_setenv("PATH", tmpdir, 1);
|
||||
cbm_setenv("CODEX_HOME", codex_home, 1);
|
||||
|
||||
int install_rc = cbm_install_agent_configs(tmpdir, "/opt/codebase-memory-mcp", false, false);
|
||||
char *plan = cbm_build_install_plan_json(tmpdir, "/opt/codebase-memory-mcp");
|
||||
bool deduplicated = install_rc == 0 &&
|
||||
cli_test_file_equals(skill_file, cbm_get_skills()[0].content) && plan &&
|
||||
!strstr(plan, "remove_owned_legacy_copy_if_migrated");
|
||||
free(plan);
|
||||
|
||||
restore_test_env("HOME", saved_home);
|
||||
restore_test_env("PATH", saved_path);
|
||||
restore_test_env("CODEX_HOME", saved_codex);
|
||||
test_rmdir_r(tmpdir);
|
||||
if (!deduplicated)
|
||||
FAIL("Codex must treat HOME/.agents and CODEX_HOME as one skill root when they coincide");
|
||||
PASS();
|
||||
}
|
||||
|
||||
TEST(cli_gemini_session_hook_uses_json_for_all_sources) {
|
||||
char tmpdir[256];
|
||||
snprintf(tmpdir, sizeof(tmpdir), "/tmp/cli-gemini-session-XXXXXX");
|
||||
@@ -11761,7 +12062,7 @@ TEST(cli_codex_migrates_to_single_hook_representation) {
|
||||
int uninstall_rc = cli_test_cmd_uninstall(1, uninstall_argv);
|
||||
char skill_path[768];
|
||||
char agent_path[768];
|
||||
snprintf(skill_path, sizeof(skill_path), "%s/skills/codebase-memory/SKILL.md", codex_dir);
|
||||
snprintf(skill_path, sizeof(skill_path), "%s/.agents/skills/codebase-memory/SKILL.md", tmpdir);
|
||||
snprintf(agent_path, sizeof(agent_path), "%s/agents/codebase-memory.toml", codex_dir);
|
||||
struct stat state;
|
||||
hooks = read_test_file_alloc(hooks_path);
|
||||
@@ -11908,9 +12209,16 @@ TEST(cli_codex_preflight_reports_heading_and_reason) {
|
||||
char codex_dir[512];
|
||||
char config_path[640];
|
||||
char agents_path[640];
|
||||
char legacy_root[640];
|
||||
char legacy_file[768];
|
||||
char canonical_file[768];
|
||||
snprintf(codex_dir, sizeof(codex_dir), "%s/.codex", tmpdir);
|
||||
snprintf(config_path, sizeof(config_path), "%s/config.toml", codex_dir);
|
||||
snprintf(agents_path, sizeof(agents_path), "%s/AGENTS.md", codex_dir);
|
||||
snprintf(legacy_root, sizeof(legacy_root), "%s/skills", codex_dir);
|
||||
snprintf(legacy_file, sizeof(legacy_file), "%s/codebase-memory/SKILL.md", legacy_root);
|
||||
snprintf(canonical_file, sizeof(canonical_file), "%s/.agents/skills/codebase-memory/SKILL.md",
|
||||
tmpdir);
|
||||
if (test_mkdirp(codex_dir) != 0) {
|
||||
test_rmdir_r(tmpdir);
|
||||
FAIL("failed to create Codex preflight fixture directory");
|
||||
@@ -11923,6 +12231,10 @@ TEST(cli_codex_preflight_reports_heading_and_reason) {
|
||||
test_rmdir_r(tmpdir);
|
||||
FAIL("failed to write Codex preflight fixture config");
|
||||
}
|
||||
if (cbm_install_skills(legacy_root, false, false) != CBM_SKILL_COUNT) {
|
||||
test_rmdir_r(tmpdir);
|
||||
FAIL("failed to seed owned legacy Codex skill");
|
||||
}
|
||||
|
||||
char *saved_home = save_test_env("HOME");
|
||||
char *saved_path = save_test_env("PATH");
|
||||
@@ -11964,8 +12276,11 @@ TEST(cli_codex_preflight_reports_heading_and_reason) {
|
||||
}
|
||||
char *after = read_test_file_alloc(config_path);
|
||||
char *agents_after = read_test_file_alloc(agents_path);
|
||||
struct stat state;
|
||||
bool unchanged = after && strcmp(after, ambiguous) == 0 && agents_after &&
|
||||
strcmp(agents_after, test_codex_activation_block) == 0;
|
||||
strcmp(agents_after, test_codex_activation_block) == 0 &&
|
||||
stat(canonical_file, &state) != 0 &&
|
||||
cli_test_file_equals(legacy_file, cbm_get_skills()[0].content);
|
||||
bool diagnostic =
|
||||
strstr(output, "Codex CLI:\nerror: agent_config agent=Codex CLI op=hook_preflight path=") !=
|
||||
NULL &&
|
||||
@@ -16175,6 +16490,12 @@ SUITE(cli) {
|
||||
RUN_TEST(cli_codex_respects_codex_home);
|
||||
RUN_TEST(cli_grok_respects_grok_home);
|
||||
RUN_TEST(cli_codex_install_uses_global_activation_pointer_issue1689);
|
||||
RUN_TEST(cli_codex_skill_migrates_owned_legacy_to_agents_root);
|
||||
RUN_TEST(cli_codex_skill_preserves_foreign_legacy_until_force);
|
||||
RUN_TEST(cli_codex_skill_preserves_foreign_canonical_and_owned_legacy);
|
||||
RUN_TEST(cli_codex_skill_failed_destination_preserves_owned_legacy);
|
||||
RUN_TEST(cli_codex_skill_uninstall_cleans_both_owned_locations);
|
||||
RUN_TEST(cli_codex_skill_deduplicates_agents_codex_home);
|
||||
RUN_TEST(cli_gemini_session_hook_uses_json_for_all_sources);
|
||||
RUN_TEST(cli_gemini_installs_dedicated_graph_subagent);
|
||||
RUN_TEST(cli_antigravity_does_not_imply_gemini);
|
||||
|
||||
Reference in New Issue
Block a user