feat: support shared project registration
This commit is contained in:
76
dist/cli.cjs
vendored
76
dist/cli.cjs
vendored
@@ -15108,7 +15108,7 @@ async function writeSingleFileAtomically(target, content) {
|
||||
fail(`Failed to update ${target}: ${detail}`);
|
||||
}
|
||||
}
|
||||
async function registerProject(harnessRoot, projectId, projectPathInput) {
|
||||
async function registerProject(harnessRoot, projectId, projectPathInput, scope = "local") {
|
||||
if (!SLUG_PATTERN.test(projectId)) {
|
||||
fail(`Invalid project id: ${projectId}`);
|
||||
}
|
||||
@@ -15125,7 +15125,12 @@ async function registerProject(harnessRoot, projectId, projectPathInput) {
|
||||
if (existing) {
|
||||
const existingPath = import_node_path.default.resolve(context.workspaceRoot, existing.path);
|
||||
if (comparablePath(existingPath) === comparablePath(candidate)) {
|
||||
return { changed: false, path: projectPath };
|
||||
if (scope === "shared" && existing.source === "local") {
|
||||
fail(
|
||||
`Project ${projectId} is already registered locally. Remove it from workspace.local.yml before shared registration.`
|
||||
);
|
||||
}
|
||||
return { changed: false, path: projectPath, source: existing.source };
|
||||
}
|
||||
fail(`Project id is already registered with another path: ${projectId}`);
|
||||
}
|
||||
@@ -15136,25 +15141,40 @@ async function registerProject(harnessRoot, projectId, projectPathInput) {
|
||||
if (profile.project.id !== projectId) {
|
||||
fail(`Profile project id does not match registration: ${profile.project.id} != ${projectId}`);
|
||||
}
|
||||
const localPath = import_node_path.default.join(context.harnessRoot, "workspace.local.yml");
|
||||
let local = { schema_version: 1, projects: {} };
|
||||
if (await pathExists(localPath)) {
|
||||
local = await loadWorkspaceDocument(localPath, context.validators);
|
||||
if (local.workspace_root !== void 0) {
|
||||
fail(`${localPath} must not override workspace_root.`);
|
||||
const registryPath = import_node_path.default.join(
|
||||
context.harnessRoot,
|
||||
scope === "shared" ? "workspace.yml" : "workspace.local.yml"
|
||||
);
|
||||
let registry = { schema_version: 1, projects: {} };
|
||||
if (await pathExists(registryPath)) {
|
||||
registry = await loadWorkspaceDocument(registryPath, context.validators);
|
||||
if (scope === "local" && registry.workspace_root !== void 0) {
|
||||
fail(`${registryPath} must not override workspace_root.`);
|
||||
}
|
||||
}
|
||||
if (local.projects[projectId]) {
|
||||
fail(`Project id already exists in ${localPath}: ${projectId}`);
|
||||
if (scope === "shared" && !registry.workspace_root) {
|
||||
fail(`${registryPath} must declare workspace_root.`);
|
||||
}
|
||||
local.projects[projectId] = { path: projectPath };
|
||||
const sortedProjects = Object.fromEntries(
|
||||
Object.entries(local.projects).sort(([left], [right]) => left.localeCompare(right))
|
||||
if (registry.projects[projectId]) {
|
||||
fail(`Project id already exists in ${registryPath}: ${projectId}`);
|
||||
}
|
||||
registry.projects[projectId] = { path: projectPath };
|
||||
const projects = scope === "local" ? Object.fromEntries(
|
||||
Object.entries(registry.projects).sort(([left], [right]) => left.localeCompare(right))
|
||||
) : registry.projects;
|
||||
const document = scope === "shared" ? {
|
||||
schema_version: 1,
|
||||
workspace_root: registry.workspace_root,
|
||||
projects
|
||||
} : { schema_version: 1, projects };
|
||||
const normalized = normalizeNewlines((0, import_yaml.stringify)(document));
|
||||
const serialized = scope === "shared" ? normalized.replace("\nprojects:\n", "\n\nprojects:\n") : normalized;
|
||||
await writeSingleFileAtomically(
|
||||
registryPath,
|
||||
serialized.endsWith("\n") ? serialized : `${serialized}
|
||||
`
|
||||
);
|
||||
const serialized = normalizeNewlines((0, import_yaml.stringify)({ schema_version: 1, projects: sortedProjects }));
|
||||
await writeSingleFileAtomically(localPath, serialized.endsWith("\n") ? serialized : `${serialized}
|
||||
`);
|
||||
return { changed: true, path: projectPath };
|
||||
return { changed: true, path: projectPath, source: scope };
|
||||
}
|
||||
async function listProjects(harnessRoot) {
|
||||
const context = await loadHarnessContext(harnessRoot);
|
||||
@@ -15180,14 +15200,14 @@ Usage:
|
||||
agent-harness compose --project <id>
|
||||
agent-harness compose --contract <contract-id>
|
||||
agent-harness compose --all
|
||||
agent-harness register --project <id> --path <workspace-relative-path>
|
||||
agent-harness register --project <id> --path <workspace-relative-path> [--shared]
|
||||
|
||||
Commands:
|
||||
list List registered projects without modifying files.
|
||||
plan Resolve and validate inputs, then report proposed output state.
|
||||
verify Compare generated output byte for byte without modifying files.
|
||||
compose Write managed AGENTS.md and CLAUDE.md files.
|
||||
register Add a project to workspace.local.yml.
|
||||
register Add a project to workspace.local.yml, or workspace.yml with --shared.
|
||||
`;
|
||||
}
|
||||
function requireValue(args, index, option) {
|
||||
@@ -15199,11 +15219,12 @@ function requireValue(args, index, option) {
|
||||
}
|
||||
function parseArgs(args) {
|
||||
if (args[0] === "--help" || args[0] === "-h") {
|
||||
return { command: void 0, all: false, help: true };
|
||||
return { command: void 0, all: false, shared: false, help: true };
|
||||
}
|
||||
const options = {
|
||||
command: args[0],
|
||||
all: false,
|
||||
shared: false,
|
||||
help: false
|
||||
};
|
||||
for (let index = 1; index < args.length; index += 1) {
|
||||
@@ -15224,6 +15245,9 @@ function parseArgs(args) {
|
||||
case "--all":
|
||||
options.all = true;
|
||||
break;
|
||||
case "--shared":
|
||||
options.shared = true;
|
||||
break;
|
||||
case "--help":
|
||||
case "-h":
|
||||
options.help = true;
|
||||
@@ -15282,6 +15306,9 @@ async function run() {
|
||||
return;
|
||||
}
|
||||
const harnessRoot = process.env.KRI_AGENT_HARNESS_ROOT ? import_node_path2.default.resolve(process.env.KRI_AGENT_HARNESS_ROOT) : import_node_path2.default.resolve(__dirname, "..");
|
||||
if (options.shared && options.command !== "register") {
|
||||
throw new HarnessError("--shared is accepted only by register.");
|
||||
}
|
||||
switch (options.command) {
|
||||
case "list": {
|
||||
if (options.project || options.contract || options.all || options.projectPath) {
|
||||
@@ -15353,9 +15380,14 @@ async function run() {
|
||||
if (!options.project || !options.projectPath) {
|
||||
throw new HarnessError("register requires --project <id> and --path <relative-path>.");
|
||||
}
|
||||
const result = await registerProject(harnessRoot, options.project, options.projectPath);
|
||||
const result = await registerProject(
|
||||
harnessRoot,
|
||||
options.project,
|
||||
options.projectPath,
|
||||
options.shared ? "shared" : "local"
|
||||
);
|
||||
console.log(
|
||||
result.changed ? `registered: ${options.project} -> ${result.path}` : `registered: unchanged (${options.project} -> ${result.path})`
|
||||
result.changed ? `registered (${result.source}): ${options.project} -> ${result.path}` : `registered: unchanged (${result.source}, ${options.project} -> ${result.path})`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user