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
1 change: 1 addition & 0 deletions docs/reference/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ Export a provider's remote configuration into a local `agents.yaml`.
| `--provider <name>` | Source provider to sync from. |
| `-o, --out <path>` | Output file (default `agents.synced.yaml`). |
| `--force` | Overwrite the output file if it exists. |
| `--skip-missing-files` | Do not prompt for remote files that cannot be downloaded; omit them from the synced output. |

## `agents migrate`

Expand Down
27 changes: 24 additions & 3 deletions packages/cli/src/commands/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ export function ensureSyncOutputWritable(outPath: string, force?: boolean): void
}
}

export async function syncCommand(options: { file: string; provider?: string; out?: string; force?: boolean }) {
export async function syncCommand(options: {
file: string;
provider?: string;
out?: string;
force?: boolean;
skipMissingFiles?: boolean;
}) {
const outPath = options.out ?? DEFAULT_SYNC_OUTPUT;
ensureSyncOutputWritable(outPath, options.force);

Expand All @@ -38,8 +44,10 @@ export async function syncCommand(options: { file: string; provider?: string; ou

const baseDir = dirname(outPath);

// Interactive file path association (before writing yaml — skipped files are removed)
const removedFiles = await promptFileAssociation(result.config, baseDir);
// File path association (before writing yaml — skipped files are removed)
const removedFiles = options.skipMissingFiles
? removeMissingFileAssociations(result.config, baseDir)
: await promptFileAssociation(result.config, baseDir);
if (removedFiles.length > 0) {
const files = (result.config.files ?? {}) as Record<string, unknown>;
for (const key of removedFiles) {
Expand Down Expand Up @@ -84,6 +92,19 @@ export async function syncCommand(options: { file: string; provider?: string; ou
}
}

export function removeMissingFileAssociations(config: Record<string, unknown>, baseDir: string): string[] {
const files = (config.files ?? {}) as Record<string, Record<string, unknown>>;
const removed = Object.entries(files)
.filter(([, decl]) => !fileExistsSync(join(baseDir, decl.source as string)))
.map(([key]) => key);

if (removed.length > 0) {
log.info(`${removed.length} file(s) removed (skipped).`);
}

return removed;
}

async function syncFromConfig(
configPath: string,
explicitProvider?: string,
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ program
.addOption(providerOption("Source provider to sync from (defaults from config when -f is set)"))
.option("-o, --out <path>", "Output file path", "agents.synced.yaml")
.option("--force", "Overwrite the output file if it already exists")
.option("--skip-missing-files", "Do not prompt for remote files that cannot be downloaded; omit them from output")
.action(withResolvedConfigFile(syncCommand));

program
Expand Down
16 changes: 15 additions & 1 deletion packages/cli/tests/unit/sync-file.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { mkdtemp, rm } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { UserError } from "@openagentpack/sdk";
import { syncCommand } from "../../src/commands/sync.ts";
import { removeMissingFileAssociations, syncCommand } from "../../src/commands/sync.ts";

const tempDirs: string[] = [];

Expand All @@ -30,3 +30,17 @@ test("syncCommand requires --provider when config file is missing", async () =>
"--provider when no config file exists",
);
});

test("removeMissingFileAssociations keeps existing sources and skips missing files", async () => {
const dir = await makeTempDir();
await Bun.write(join(dir, "present.txt"), "present\n");

const config = {
files: {
present: { source: "present.txt" },
missing: { source: "missing.txt" },
},
};

expect(removeMissingFileAssociations(config, dir)).toEqual(["missing"]);
});
Loading