feat: support shared project registration
This commit is contained in:
@@ -22,11 +22,12 @@ Run commands from this repository root:
|
|||||||
.\scripts\agent-harness.cmd compose --project kri-contact-front
|
.\scripts\agent-harness.cmd compose --project kri-contact-front
|
||||||
.\scripts\agent-harness.cmd compose --contract kri-common
|
.\scripts\agent-harness.cmd compose --contract kri-common
|
||||||
.\scripts\agent-harness.cmd register --project kri-contact-front --path _KriContact/contact-front
|
.\scripts\agent-harness.cmd register --project kri-contact-front --path _KriContact/contact-front
|
||||||
|
.\scripts\agent-harness.cmd register --project new-service --path ____Project/new-service --shared
|
||||||
```
|
```
|
||||||
|
|
||||||
The `.cmd` launcher invokes the PowerShell wrapper with a process-scoped execution-policy bypass. It does not change the user or machine execution policy. When local scripts are already allowed, `scripts\agent-harness.ps1` may be called directly.
|
The `.cmd` launcher invokes the PowerShell wrapper with a process-scoped execution-policy bypass. It does not change the user or machine execution policy. When local scripts are already allowed, `scripts\agent-harness.ps1` may be called directly.
|
||||||
|
|
||||||
`plan`, `verify`, and `list` are read-only. `compose` writes only generated `AGENTS.md` and `CLAUDE.md`. `register` writes only `workspace.local.yml`. No command performs Git, database, deployment, or network operations.
|
`plan`, `verify`, and `list` are read-only. `compose` writes only generated `AGENTS.md` and `CLAUDE.md`. `register` writes `workspace.local.yml` by default; `register --shared` writes `workspace.yml`. No command performs Git, database, deployment, or network operations.
|
||||||
|
|
||||||
Use `--contract <contract-id>` to select the registered provider first and then only registered consumers of that contract, ordered by project ID. Use `--all` only when every registered project is intentionally in scope. `--project`, `--contract`, and `--all` are mutually exclusive.
|
Use `--contract <contract-id>` to select the registered provider first and then only registered consumers of that contract, ordered by project ID. Use `--all` only when every registered project is intentionally in scope. `--project`, `--contract`, and `--all` are mutually exclusive.
|
||||||
|
|
||||||
|
|||||||
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}`);
|
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)) {
|
if (!SLUG_PATTERN.test(projectId)) {
|
||||||
fail(`Invalid project id: ${projectId}`);
|
fail(`Invalid project id: ${projectId}`);
|
||||||
}
|
}
|
||||||
@@ -15125,7 +15125,12 @@ async function registerProject(harnessRoot, projectId, projectPathInput) {
|
|||||||
if (existing) {
|
if (existing) {
|
||||||
const existingPath = import_node_path.default.resolve(context.workspaceRoot, existing.path);
|
const existingPath = import_node_path.default.resolve(context.workspaceRoot, existing.path);
|
||||||
if (comparablePath(existingPath) === comparablePath(candidate)) {
|
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}`);
|
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) {
|
if (profile.project.id !== projectId) {
|
||||||
fail(`Profile project id does not match registration: ${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");
|
const registryPath = import_node_path.default.join(
|
||||||
let local = { schema_version: 1, projects: {} };
|
context.harnessRoot,
|
||||||
if (await pathExists(localPath)) {
|
scope === "shared" ? "workspace.yml" : "workspace.local.yml"
|
||||||
local = await loadWorkspaceDocument(localPath, context.validators);
|
);
|
||||||
if (local.workspace_root !== void 0) {
|
let registry = { schema_version: 1, projects: {} };
|
||||||
fail(`${localPath} must not override workspace_root.`);
|
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]) {
|
if (scope === "shared" && !registry.workspace_root) {
|
||||||
fail(`Project id already exists in ${localPath}: ${projectId}`);
|
fail(`${registryPath} must declare workspace_root.`);
|
||||||
}
|
}
|
||||||
local.projects[projectId] = { path: projectPath };
|
if (registry.projects[projectId]) {
|
||||||
const sortedProjects = Object.fromEntries(
|
fail(`Project id already exists in ${registryPath}: ${projectId}`);
|
||||||
Object.entries(local.projects).sort(([left], [right]) => left.localeCompare(right))
|
}
|
||||||
|
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 }));
|
return { changed: true, path: projectPath, source: scope };
|
||||||
await writeSingleFileAtomically(localPath, serialized.endsWith("\n") ? serialized : `${serialized}
|
|
||||||
`);
|
|
||||||
return { changed: true, path: projectPath };
|
|
||||||
}
|
}
|
||||||
async function listProjects(harnessRoot) {
|
async function listProjects(harnessRoot) {
|
||||||
const context = await loadHarnessContext(harnessRoot);
|
const context = await loadHarnessContext(harnessRoot);
|
||||||
@@ -15180,14 +15200,14 @@ Usage:
|
|||||||
agent-harness compose --project <id>
|
agent-harness compose --project <id>
|
||||||
agent-harness compose --contract <contract-id>
|
agent-harness compose --contract <contract-id>
|
||||||
agent-harness compose --all
|
agent-harness compose --all
|
||||||
agent-harness register --project <id> --path <workspace-relative-path>
|
agent-harness register --project <id> --path <workspace-relative-path> [--shared]
|
||||||
|
|
||||||
Commands:
|
Commands:
|
||||||
list List registered projects without modifying files.
|
list List registered projects without modifying files.
|
||||||
plan Resolve and validate inputs, then report proposed output state.
|
plan Resolve and validate inputs, then report proposed output state.
|
||||||
verify Compare generated output byte for byte without modifying files.
|
verify Compare generated output byte for byte without modifying files.
|
||||||
compose Write managed AGENTS.md and CLAUDE.md 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) {
|
function requireValue(args, index, option) {
|
||||||
@@ -15199,11 +15219,12 @@ function requireValue(args, index, option) {
|
|||||||
}
|
}
|
||||||
function parseArgs(args) {
|
function parseArgs(args) {
|
||||||
if (args[0] === "--help" || args[0] === "-h") {
|
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 = {
|
const options = {
|
||||||
command: args[0],
|
command: args[0],
|
||||||
all: false,
|
all: false,
|
||||||
|
shared: false,
|
||||||
help: false
|
help: false
|
||||||
};
|
};
|
||||||
for (let index = 1; index < args.length; index += 1) {
|
for (let index = 1; index < args.length; index += 1) {
|
||||||
@@ -15224,6 +15245,9 @@ function parseArgs(args) {
|
|||||||
case "--all":
|
case "--all":
|
||||||
options.all = true;
|
options.all = true;
|
||||||
break;
|
break;
|
||||||
|
case "--shared":
|
||||||
|
options.shared = true;
|
||||||
|
break;
|
||||||
case "--help":
|
case "--help":
|
||||||
case "-h":
|
case "-h":
|
||||||
options.help = true;
|
options.help = true;
|
||||||
@@ -15282,6 +15306,9 @@ async function run() {
|
|||||||
return;
|
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, "..");
|
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) {
|
switch (options.command) {
|
||||||
case "list": {
|
case "list": {
|
||||||
if (options.project || options.contract || options.all || options.projectPath) {
|
if (options.project || options.contract || options.all || options.projectPath) {
|
||||||
@@ -15353,9 +15380,14 @@ async function run() {
|
|||||||
if (!options.project || !options.projectPath) {
|
if (!options.project || !options.projectPath) {
|
||||||
throw new HarnessError("register requires --project <id> and --path <relative-path>.");
|
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(
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
54
dist/index.cjs
vendored
54
dist/index.cjs
vendored
@@ -15124,7 +15124,7 @@ async function writeSingleFileAtomically(target, content) {
|
|||||||
fail(`Failed to update ${target}: ${detail}`);
|
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)) {
|
if (!SLUG_PATTERN.test(projectId)) {
|
||||||
fail(`Invalid project id: ${projectId}`);
|
fail(`Invalid project id: ${projectId}`);
|
||||||
}
|
}
|
||||||
@@ -15141,7 +15141,12 @@ async function registerProject(harnessRoot, projectId, projectPathInput) {
|
|||||||
if (existing) {
|
if (existing) {
|
||||||
const existingPath = import_node_path.default.resolve(context.workspaceRoot, existing.path);
|
const existingPath = import_node_path.default.resolve(context.workspaceRoot, existing.path);
|
||||||
if (comparablePath(existingPath) === comparablePath(candidate)) {
|
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}`);
|
fail(`Project id is already registered with another path: ${projectId}`);
|
||||||
}
|
}
|
||||||
@@ -15152,25 +15157,40 @@ async function registerProject(harnessRoot, projectId, projectPathInput) {
|
|||||||
if (profile.project.id !== projectId) {
|
if (profile.project.id !== projectId) {
|
||||||
fail(`Profile project id does not match registration: ${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");
|
const registryPath = import_node_path.default.join(
|
||||||
let local = { schema_version: 1, projects: {} };
|
context.harnessRoot,
|
||||||
if (await pathExists(localPath)) {
|
scope === "shared" ? "workspace.yml" : "workspace.local.yml"
|
||||||
local = await loadWorkspaceDocument(localPath, context.validators);
|
);
|
||||||
if (local.workspace_root !== void 0) {
|
let registry = { schema_version: 1, projects: {} };
|
||||||
fail(`${localPath} must not override workspace_root.`);
|
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]) {
|
if (scope === "shared" && !registry.workspace_root) {
|
||||||
fail(`Project id already exists in ${localPath}: ${projectId}`);
|
fail(`${registryPath} must declare workspace_root.`);
|
||||||
}
|
}
|
||||||
local.projects[projectId] = { path: projectPath };
|
if (registry.projects[projectId]) {
|
||||||
const sortedProjects = Object.fromEntries(
|
fail(`Project id already exists in ${registryPath}: ${projectId}`);
|
||||||
Object.entries(local.projects).sort(([left], [right]) => left.localeCompare(right))
|
}
|
||||||
|
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 }));
|
return { changed: true, path: projectPath, source: scope };
|
||||||
await writeSingleFileAtomically(localPath, serialized.endsWith("\n") ? serialized : `${serialized}
|
|
||||||
`);
|
|
||||||
return { changed: true, path: projectPath };
|
|
||||||
}
|
}
|
||||||
async function listProjects(harnessRoot) {
|
async function listProjects(harnessRoot) {
|
||||||
const context = await loadHarnessContext(harnessRoot);
|
const context = await loadHarnessContext(harnessRoot);
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ Codex uses a 32 KiB default combined project-instruction limit. To leave room fo
|
|||||||
- `plan`: resolve, validate, compose in memory, and report fragments, size, warnings, and output state.
|
- `plan`: resolve, validate, compose in memory, and report fragments, size, warnings, and output state.
|
||||||
- `verify`: compare expected and stored output byte for byte without modifying files; return a failure exit code for drift.
|
- `verify`: compare expected and stored output byte for byte without modifying files; return a failure exit code for drift.
|
||||||
- `compose`: atomically replace only managed or missing `AGENTS.md` and `CLAUDE.md` files, then verify them again.
|
- `compose`: atomically replace only managed or missing `AGENTS.md` and `CLAUDE.md` files, then verify them again.
|
||||||
- `register`: validate a relative project path and matching profile, then atomically update only `workspace.local.yml`.
|
- `register`: validate a relative project path and matching profile, then atomically update `workspace.local.yml` by default or `workspace.yml` when `--shared` is explicit.
|
||||||
|
|
||||||
For `plan`, `verify`, and `compose`, select exactly one scope with `--project <id>`, `--contract <contract-id>`, or `--all`. Contract scope processes the provider first and consumers in project-ID order. No command performs Git, database, deployment, paid API, or network operations. `--all` must be explicit; a single project is the normal scope.
|
For `plan`, `verify`, and `compose`, select exactly one scope with `--project <id>`, `--contract <contract-id>`, or `--all`. Contract scope processes the provider first and consumers in project-ID order. No command performs Git, database, deployment, paid API, or network operations. `--all` must be explicit; a single project is the normal scope.
|
||||||
|
|
||||||
|
|||||||
26
src/cli.ts
26
src/cli.ts
@@ -16,6 +16,7 @@ interface CliOptions {
|
|||||||
contract?: string;
|
contract?: string;
|
||||||
projectPath?: string;
|
projectPath?: string;
|
||||||
all: boolean;
|
all: boolean;
|
||||||
|
shared: boolean;
|
||||||
help: boolean;
|
help: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,14 +34,14 @@ Usage:
|
|||||||
agent-harness compose --project <id>
|
agent-harness compose --project <id>
|
||||||
agent-harness compose --contract <contract-id>
|
agent-harness compose --contract <contract-id>
|
||||||
agent-harness compose --all
|
agent-harness compose --all
|
||||||
agent-harness register --project <id> --path <workspace-relative-path>
|
agent-harness register --project <id> --path <workspace-relative-path> [--shared]
|
||||||
|
|
||||||
Commands:
|
Commands:
|
||||||
list List registered projects without modifying files.
|
list List registered projects without modifying files.
|
||||||
plan Resolve and validate inputs, then report proposed output state.
|
plan Resolve and validate inputs, then report proposed output state.
|
||||||
verify Compare generated output byte for byte without modifying files.
|
verify Compare generated output byte for byte without modifying files.
|
||||||
compose Write managed AGENTS.md and CLAUDE.md 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.
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,11 +55,12 @@ function requireValue(args: string[], index: number, option: string): string {
|
|||||||
|
|
||||||
function parseArgs(args: string[]): CliOptions {
|
function parseArgs(args: string[]): CliOptions {
|
||||||
if (args[0] === "--help" || args[0] === "-h") {
|
if (args[0] === "--help" || args[0] === "-h") {
|
||||||
return { command: undefined, all: false, help: true };
|
return { command: undefined, all: false, shared: false, help: true };
|
||||||
}
|
}
|
||||||
const options: CliOptions = {
|
const options: CliOptions = {
|
||||||
command: args[0],
|
command: args[0],
|
||||||
all: false,
|
all: false,
|
||||||
|
shared: false,
|
||||||
help: false,
|
help: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -80,6 +82,9 @@ function parseArgs(args: string[]): CliOptions {
|
|||||||
case "--all":
|
case "--all":
|
||||||
options.all = true;
|
options.all = true;
|
||||||
break;
|
break;
|
||||||
|
case "--shared":
|
||||||
|
options.shared = true;
|
||||||
|
break;
|
||||||
case "--help":
|
case "--help":
|
||||||
case "-h":
|
case "-h":
|
||||||
options.help = true;
|
options.help = true;
|
||||||
@@ -152,6 +157,10 @@ async function run(): Promise<void> {
|
|||||||
? path.resolve(process.env.KRI_AGENT_HARNESS_ROOT)
|
? path.resolve(process.env.KRI_AGENT_HARNESS_ROOT)
|
||||||
: path.resolve(__dirname, "..");
|
: path.resolve(__dirname, "..");
|
||||||
|
|
||||||
|
if (options.shared && options.command !== "register") {
|
||||||
|
throw new HarnessError("--shared is accepted only by register.");
|
||||||
|
}
|
||||||
|
|
||||||
switch (options.command) {
|
switch (options.command) {
|
||||||
case "list": {
|
case "list": {
|
||||||
if (options.project || options.contract || options.all || options.projectPath) {
|
if (options.project || options.contract || options.all || options.projectPath) {
|
||||||
@@ -229,11 +238,16 @@ async function run(): Promise<void> {
|
|||||||
if (!options.project || !options.projectPath) {
|
if (!options.project || !options.projectPath) {
|
||||||
throw new HarnessError("register requires --project <id> and --path <relative-path>.");
|
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(
|
console.log(
|
||||||
result.changed
|
result.changed
|
||||||
? `registered: ${options.project} -> ${result.path}`
|
? `registered (${result.source}): ${options.project} -> ${result.path}`
|
||||||
: `registered: unchanged (${options.project} -> ${result.path})`,
|
: `registered: unchanged (${result.source}, ${options.project} -> ${result.path})`,
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,6 +42,8 @@ export type ProjectType =
|
|||||||
|
|
||||||
export type ProjectLayer = "frontend" | "backend" | "fullstack" | "standalone";
|
export type ProjectLayer = "frontend" | "backend" | "fullstack" | "standalone";
|
||||||
|
|
||||||
|
export type RegistrationScope = "local" | "shared";
|
||||||
|
|
||||||
export interface ProjectProfile {
|
export interface ProjectProfile {
|
||||||
schema_version: 1;
|
schema_version: 1;
|
||||||
project: {
|
project: {
|
||||||
@@ -880,7 +882,8 @@ export async function registerProject(
|
|||||||
harnessRoot: string,
|
harnessRoot: string,
|
||||||
projectId: string,
|
projectId: string,
|
||||||
projectPathInput: string,
|
projectPathInput: string,
|
||||||
): Promise<{ changed: boolean; path: string }> {
|
scope: RegistrationScope = "local",
|
||||||
|
): Promise<{ changed: boolean; path: string; source: RegistrationScope }> {
|
||||||
if (!SLUG_PATTERN.test(projectId)) {
|
if (!SLUG_PATTERN.test(projectId)) {
|
||||||
fail(`Invalid project id: ${projectId}`);
|
fail(`Invalid project id: ${projectId}`);
|
||||||
}
|
}
|
||||||
@@ -898,7 +901,12 @@ export async function registerProject(
|
|||||||
if (existing) {
|
if (existing) {
|
||||||
const existingPath = path.resolve(context.workspaceRoot, existing.path);
|
const existingPath = path.resolve(context.workspaceRoot, existing.path);
|
||||||
if (comparablePath(existingPath) === comparablePath(candidate)) {
|
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}`);
|
fail(`Project id is already registered with another path: ${projectId}`);
|
||||||
}
|
}
|
||||||
@@ -911,24 +919,46 @@ export async function registerProject(
|
|||||||
fail(`Profile project id does not match registration: ${profile.project.id} != ${projectId}`);
|
fail(`Profile project id does not match registration: ${profile.project.id} != ${projectId}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const localPath = path.join(context.harnessRoot, "workspace.local.yml");
|
const registryPath = path.join(
|
||||||
let local: WorkspaceDocument = { schema_version: 1, projects: {} };
|
context.harnessRoot,
|
||||||
if (await pathExists(localPath)) {
|
scope === "shared" ? "workspace.yml" : "workspace.local.yml",
|
||||||
local = await loadWorkspaceDocument(localPath, context.validators);
|
);
|
||||||
if (local.workspace_root !== undefined) {
|
let registry: WorkspaceDocument = { schema_version: 1, projects: {} };
|
||||||
fail(`${localPath} must not override workspace_root.`);
|
if (await pathExists(registryPath)) {
|
||||||
|
registry = await loadWorkspaceDocument(registryPath, context.validators);
|
||||||
|
if (scope === "local" && registry.workspace_root !== undefined) {
|
||||||
|
fail(`${registryPath} must not override workspace_root.`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (local.projects[projectId]) {
|
if (scope === "shared" && !registry.workspace_root) {
|
||||||
fail(`Project id already exists in ${localPath}: ${projectId}`);
|
fail(`${registryPath} must declare workspace_root.`);
|
||||||
}
|
}
|
||||||
local.projects[projectId] = { path: projectPath };
|
if (registry.projects[projectId]) {
|
||||||
const sortedProjects = Object.fromEntries(
|
fail(`Project id already exists in ${registryPath}: ${projectId}`);
|
||||||
Object.entries(local.projects).sort(([left], [right]) => left.localeCompare(right)),
|
}
|
||||||
|
|
||||||
|
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 as const,
|
||||||
|
workspace_root: registry.workspace_root!,
|
||||||
|
projects,
|
||||||
|
}
|
||||||
|
: { schema_version: 1 as const, projects };
|
||||||
|
const normalized = normalizeNewlines(stringifyYaml(document));
|
||||||
|
const serialized = scope === "shared"
|
||||||
|
? normalized.replace("\nprojects:\n", "\n\nprojects:\n")
|
||||||
|
: normalized;
|
||||||
|
await writeSingleFileAtomically(
|
||||||
|
registryPath,
|
||||||
|
serialized.endsWith("\n") ? serialized : `${serialized}\n`,
|
||||||
);
|
);
|
||||||
const serialized = normalizeNewlines(stringifyYaml({ schema_version: 1, projects: sortedProjects }));
|
return { changed: true, path: projectPath, source: scope };
|
||||||
await writeSingleFileAtomically(localPath, serialized.endsWith("\n") ? serialized : `${serialized}\n`);
|
|
||||||
return { changed: true, path: projectPath };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function listProjects(harnessRoot: string): Promise<Array<WorkspaceProject & { exists: boolean }>> {
|
export async function listProjects(harnessRoot: string): Promise<Array<WorkspaceProject & { exists: boolean }>> {
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import { promisify } from "node:util";
|
|||||||
const require = createRequire(import.meta.url);
|
const require = createRequire(import.meta.url);
|
||||||
const {
|
const {
|
||||||
composeProject,
|
composeProject,
|
||||||
|
listProjects,
|
||||||
planProject,
|
planProject,
|
||||||
registerProject,
|
registerProject,
|
||||||
selectProjectIdsByContract,
|
selectProjectIdsByContract,
|
||||||
@@ -270,6 +271,49 @@ stack:
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("registers a project in the shared workspace only when explicitly requested", async (t) => {
|
||||||
|
const { temporaryRoot, harnessRoot } = await createFixture(t);
|
||||||
|
const newProjectRoot = path.join(temporaryRoot, "apps", "shared-tool");
|
||||||
|
await writeText(
|
||||||
|
path.join(newProjectRoot, ".agent", "profile.yml"),
|
||||||
|
`schema_version: 1
|
||||||
|
project:
|
||||||
|
id: shared-tool
|
||||||
|
name: Shared Tool
|
||||||
|
type: scaffold-cli
|
||||||
|
layer: standalone
|
||||||
|
legacy: false
|
||||||
|
stack:
|
||||||
|
- typescript
|
||||||
|
`,
|
||||||
|
);
|
||||||
|
|
||||||
|
const result = await registerProject(
|
||||||
|
harnessRoot,
|
||||||
|
"shared-tool",
|
||||||
|
"apps/shared-tool",
|
||||||
|
"shared",
|
||||||
|
);
|
||||||
|
assert.deepEqual(result, {
|
||||||
|
changed: true,
|
||||||
|
path: "apps/shared-tool",
|
||||||
|
source: "shared",
|
||||||
|
});
|
||||||
|
|
||||||
|
const sharedWorkspace = await readFile(path.join(harnessRoot, "workspace.yml"), "utf8");
|
||||||
|
assert.match(sharedWorkspace, /workspace_root: \.\.\n\nprojects:/);
|
||||||
|
assert.match(sharedWorkspace, /shared-tool:/);
|
||||||
|
assert.match(sharedWorkspace, /path: apps\/shared-tool/);
|
||||||
|
assert.equal(
|
||||||
|
await readFile(path.join(harnessRoot, "workspace.local.yml"), "utf8").catch(() => null),
|
||||||
|
null,
|
||||||
|
);
|
||||||
|
assert.equal(
|
||||||
|
(await listProjects(harnessRoot)).find((project) => project.id === "shared-tool")?.source,
|
||||||
|
"shared",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
test("registers, composes, and verifies a project path containing Korean text and spaces", async (t) => {
|
test("registers, composes, and verifies a project path containing Korean text and spaces", async (t) => {
|
||||||
const { temporaryRoot, harnessRoot } = await createFixture(t);
|
const { temporaryRoot, harnessRoot } = await createFixture(t);
|
||||||
const projectRoot = path.join(temporaryRoot, "___NEW 출구조사", "legacy-app");
|
const projectRoot = path.join(temporaryRoot, "___NEW 출구조사", "legacy-app");
|
||||||
|
|||||||
Reference in New Issue
Block a user