feat: register generated apps with agent harness

This commit is contained in:
2026-08-07 16:31:39 +09:00
parent 6b0cbc8b0a
commit 8eb440353b
10 changed files with 92 additions and 11 deletions

View File

@@ -18,7 +18,7 @@
### Harness Integration
- Generated projects default to `requested-project`; allow the supported explicit project-type override without changing the fixed `frontend` layer.
- When the central harness is available, register the project locally and run compose followed by verify. Central-harness absence must not prevent project creation.
- When the central harness is available, register the project in shared `workspace.yml` by default and run compose followed by verify. Allow an explicit local-registration override, and do not perform Git commits. Central-harness absence must not prevent project creation.
- `AGENTS.md` and `CLAUDE.md` in this repository are harness-generated outputs. Never edit either file directly; edit `.agent` sources and recompose.
- Do not commit user-specific absolute harness paths or credentials. Explicit paths are runtime inputs only.

View File

@@ -303,7 +303,7 @@ When implementing or changing frontend UI, use this order:
### Harness Integration
- Generated projects default to `requested-project`; allow the supported explicit project-type override without changing the fixed `frontend` layer.
- When the central harness is available, register the project locally and run compose followed by verify. Central-harness absence must not prevent project creation.
- When the central harness is available, register the project in shared `workspace.yml` by default and run compose followed by verify. Allow an explicit local-registration override, and do not perform Git commits. Central-harness absence must not prevent project creation.
- `AGENTS.md` and `CLAUDE.md` in this repository are harness-generated outputs. Never edit either file directly; edit `.agent` sources and recompose.
- Do not commit user-specific absolute harness paths or credentials. Explicit paths are runtime inputs only.

View File

@@ -40,6 +40,8 @@ Agent Harness 관련 기본값과 옵션:
--project-type <type> requested-project|internal-service|shared-service
--agent-project-id <id> 하네스 프로젝트 ID (기본: 프로젝트명 slug)
--harness-root <path> 중앙 Agent Harness 저장소 경로
--agent-registration <shared|local>
중앙 등록 범위 (기본 shared)
--skip-agent-compose 하네스 자동 등록·합성·검증 생략
```
@@ -53,7 +55,7 @@ Agent Harness 관련 기본값과 옵션:
4. KRI UI Registry 9개 항목 설치
5. TypeScript 검사
6. Next.js production build
7. Agent Harness 로컬 등록, `AGENTS.md`/`CLAUDE.md` 합성 및 검증
7. Agent Harness 공유 등록, `AGENTS.md`/`CLAUDE.md` 합성 및 검증
UI Registry: `https://ui-registry.kric.com/r`
@@ -67,7 +69,7 @@ UI Registry: `https://ui-registry.kric.com/r`
2. `KRI_AGENT_HARNESS_ROOT` 환경변수
3. 생성 경로의 상위 디렉터리
하네스를 발견하면 프로젝트를 `workspace.local.yml`에 등록하고 `compose`, `verify`를 실행합니다. 하네스를 찾지 못해도 프로젝트 생성은 완료되며, 이 경우 `.agent` 원본을 중앙 하네스에서 나중에 등록·합성해야 합니다.
하네스를 발견하면 기본적으로 프로젝트를 공유 `workspace.yml`에 등록하고 `compose`, `verify`를 실행합니다. 일회성 로컬 등록은 `--agent-registration local`로 선택할 수 있습니다. 하네스를 찾지 못해도 프로젝트 생성은 완료되며, 이 경우 `.agent` 원본을 중앙 하네스에서 나중에 등록·합성해야 합니다. 중앙 저장소와 생성 프로젝트의 Git 커밋은 자동으로 수행하지 않습니다.
## 생성되는 환경 파일

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "@kri/create-next-app",
"version": "0.1.2",
"version": "0.1.3",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@kri/create-next-app",
"version": "0.1.2",
"version": "0.1.3",
"license": "UNLICENSED",
"bin": {
"kri-create-next-app": "dist/cli.js"

View File

@@ -1,6 +1,6 @@
{
"name": "@kri/create-next-app",
"version": "0.1.2",
"version": "0.1.3",
"description": "Create a KRI standard Next.js application",
"type": "module",
"bin": {
@@ -15,6 +15,7 @@
"clean": "rimraf dist",
"build": "npm run clean && tsc -p tsconfig.json",
"typecheck": "tsc -p tsconfig.json --noEmit",
"test": "npm run build && node --test",
"prepack": "npm run build"
},
"engines": {

View File

@@ -1,5 +1,5 @@
import path from "node:path";
import type { ParsedArguments, ProjectType } from "./types.js";
import type { AgentRegistration, ParsedArguments, ProjectType } from "./types.js";
const requireValue = (args: string[], index: number, option: string): string => {
const value = args[index + 1];
@@ -18,6 +18,11 @@ export const parseProjectType = (value: string): ProjectType => {
);
};
export const parseAgentRegistration = (value: string): AgentRegistration => {
if (value === "shared" || value === "local") return value;
throw new Error("--agent-registration은 shared 또는 local이어야 합니다.");
};
export function parseArguments(argv: string[]): ParsedArguments {
const parsed: ParsedArguments = {
yes: false,
@@ -25,6 +30,7 @@ export function parseArguments(argv: string[]): ParsedArguments {
installUi: true,
build: true,
jenkins: true,
agentRegistration: "shared",
skipAgentCompose: false,
force: false,
help: false,
@@ -80,6 +86,10 @@ export function parseArguments(argv: string[]): ParsedArguments {
parsed.harnessRoot = path.resolve(requireValue(argv, index, arg));
index += 1;
break;
case "--agent-registration":
parsed.agentRegistration = parseAgentRegistration(requireValue(argv, index, arg));
index += 1;
break;
case "--target-dir":
parsed.targetDir = path.resolve(requireValue(argv, index, arg));
index += 1;
@@ -140,6 +150,8 @@ export function printHelp(): void {
--project-type <type> requested-project|internal-service|shared-service
--agent-project-id <id> 하네스 프로젝트 ID (기본: 프로젝트명 slug)
--harness-root <path> 중앙 Agent Harness 저장소 경로
--agent-registration <shared|local>
중앙 등록 범위 (기본 shared)
--port <number> 개발/실행 포트 (기본 4000)
--repo-url <url> Gitea 저장소 URL
--app-root <path> Ubuntu 배포 경로

View File

@@ -101,6 +101,7 @@ async function resolveOptions(): Promise<CliOptions> {
build: parsed.build,
jenkins,
harnessRoot: parsed.harnessRoot,
agentRegistration: parsed.agentRegistration,
skipAgentCompose: parsed.skipAgentCompose,
force: parsed.force,
};

View File

@@ -10,6 +10,7 @@ interface HarnessOptions {
targetDir: string;
agentProjectId: string;
harnessRoot?: string;
agentRegistration: "shared" | "local";
skipAgentCompose: boolean;
}
@@ -102,14 +103,16 @@ export async function composeAgentHarness(options: HarnessOptions): Promise<void
}
const projectPath = workspaceRelativePath(harnessRoot, options.targetDir);
console.log("\n[Agent Harness] 로컬 등록·합성·검증");
await runHarness(harnessRoot, [
console.log(`\n[Agent Harness] ${options.agentRegistration} 등록·합성·검증`);
const registerArgs = [
"register",
"--project",
options.agentProjectId,
"--path",
projectPath,
]);
];
if (options.agentRegistration === "shared") registerArgs.push("--shared");
await runHarness(harnessRoot, registerArgs);
await runHarness(harnessRoot, ["compose", "--project", options.agentProjectId]);
await runHarness(harnessRoot, ["verify", "--project", options.agentProjectId]);
}

View File

@@ -1,4 +1,5 @@
export type ProjectType = "requested-project" | "internal-service" | "shared-service";
export type AgentRegistration = "shared" | "local";
export interface CliOptions {
projectName: string;
@@ -19,6 +20,7 @@ export interface CliOptions {
build: boolean;
jenkins: boolean;
harnessRoot?: string;
agentRegistration: AgentRegistration;
skipAgentCompose: boolean;
force: boolean;
}
@@ -42,6 +44,7 @@ export interface ParsedArguments {
build: boolean;
jenkins: boolean;
harnessRoot?: string;
agentRegistration: AgentRegistration;
skipAgentCompose: boolean;
force: boolean;
help: boolean;

59
tests/harness.test.mjs Normal file
View File

@@ -0,0 +1,59 @@
import assert from "node:assert/strict";
import { mkdtemp, mkdir, readFile, rm, writeFile } from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import test from "node:test";
import { parseArguments } from "../dist/args.js";
import { composeAgentHarness } from "../dist/harness.js";
async function createFixture(t) {
const root = await mkdtemp(path.join(os.tmpdir(), "kri-create-next-harness-"));
const harnessRoot = path.join(root, "_________AgentHarnessBase");
const targetDir = path.join(root, "sample-front");
const logPath = path.join(root, "calls.jsonl");
await mkdir(path.join(harnessRoot, "dist"), { recursive: true });
await mkdir(targetDir, { recursive: true });
await writeFile(path.join(harnessRoot, "workspace.yml"), "schema_version: 1\nprojects: {}\n", "utf8");
await writeFile(
path.join(harnessRoot, "dist", "cli.cjs"),
`const { appendFileSync } = require("node:fs");\nappendFileSync(${JSON.stringify(logPath)}, JSON.stringify(process.argv.slice(2)) + "\\n");\n`,
"utf8",
);
t.after(() => rm(root, { recursive: true, force: true }));
return { harnessRoot, targetDir, logPath };
}
test("defaults to shared registration and accepts an explicit local override", () => {
assert.equal(parseArguments([]).agentRegistration, "shared");
assert.equal(
parseArguments(["--agent-registration", "local"]).agentRegistration,
"local",
);
assert.throws(
() => parseArguments(["--agent-registration", "invalid"]),
/shared 또는 local/,
);
});
test("registers shared, composes, and verifies in deterministic order", async (t) => {
const { harnessRoot, targetDir, logPath } = await createFixture(t);
await composeAgentHarness({
targetDir,
agentProjectId: "sample-front",
harnessRoot,
agentRegistration: "shared",
skipAgentCompose: false,
});
const calls = (await readFile(logPath, "utf8"))
.trim()
.split("\n")
.map((line) => JSON.parse(line));
assert.deepEqual(calls, [
["register", "--project", "sample-front", "--path", "sample-front", "--shared"],
["compose", "--project", "sample-front"],
["verify", "--project", "sample-front"],
]);
});