@gaonjs/cli 0.4.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/dist/commands/check.d.ts +50 -0
  2. package/dist/commands/check.js +286 -0
  3. package/dist/commands/console.d.ts +46 -0
  4. package/dist/commands/console.js +129 -0
  5. package/dist/commands/db.d.ts +3 -1
  6. package/dist/commands/db.js +8 -2
  7. package/dist/commands/g.d.ts +1 -1
  8. package/dist/commands/g.js +27 -3
  9. package/dist/commands/mcp.d.ts +15 -0
  10. package/dist/commands/mcp.js +78 -0
  11. package/dist/commands/new.d.ts +45 -0
  12. package/dist/commands/new.js +274 -0
  13. package/dist/commands/test.d.ts +11 -0
  14. package/dist/commands/test.js +119 -0
  15. package/dist/db/diff.js +5 -0
  16. package/dist/db/journal.d.ts +34 -0
  17. package/dist/db/journal.js +71 -0
  18. package/dist/db/migrate.d.ts +6 -1
  19. package/dist/db/migrate.js +120 -102
  20. package/dist/db/replay.d.ts +49 -0
  21. package/dist/db/replay.js +148 -0
  22. package/dist/db/status.d.ts +12 -0
  23. package/dist/db/status.js +61 -0
  24. package/dist/dev/index.d.ts +2 -0
  25. package/dist/dev/index.js +2 -0
  26. package/dist/dev/vite.d.ts +67 -0
  27. package/dist/dev/vite.js +126 -0
  28. package/dist/dev.d.ts +18 -0
  29. package/dist/dev.js +15 -0
  30. package/dist/doctor/agents-doc-index.d.ts +4 -0
  31. package/dist/doctor/agents-doc-index.js +80 -0
  32. package/dist/doctor/fixers/dependency-direction.d.ts +9 -0
  33. package/dist/doctor/fixers/dependency-direction.js +98 -0
  34. package/dist/doctor/fixers/index.d.ts +15 -0
  35. package/dist/doctor/fixers/index.js +66 -0
  36. package/dist/doctor/fixers/schema-filename.d.ts +14 -0
  37. package/dist/doctor/fixers/schema-filename.js +104 -0
  38. package/dist/doctor/fixers/types.d.ts +59 -0
  39. package/dist/doctor/fixers/types.js +15 -0
  40. package/dist/doctor/no-auto-import.d.ts +10 -0
  41. package/dist/doctor/no-auto-import.js +158 -0
  42. package/dist/doctor/schema-filename.d.ts +6 -0
  43. package/dist/doctor/schema-filename.js +81 -0
  44. package/dist/doctor/shared-composable-purity.d.ts +8 -0
  45. package/dist/doctor/shared-composable-purity.js +164 -0
  46. package/dist/doctor/types.d.ts +1 -1
  47. package/dist/doctor/types.js +6 -5
  48. package/dist/doctor.d.ts +51 -0
  49. package/dist/doctor.js +191 -7
  50. package/dist/generate.js +2 -2
  51. package/dist/hub.d.ts +1 -1
  52. package/dist/index.d.ts +6 -2
  53. package/dist/index.js +154 -16
  54. package/dist/mcp/index.d.ts +7 -0
  55. package/dist/mcp/index.js +7 -0
  56. package/dist/mcp/server.d.ts +50 -0
  57. package/dist/mcp/server.js +102 -0
  58. package/dist/mcp/tools.d.ts +109 -0
  59. package/dist/mcp/tools.js +485 -0
  60. package/dist/scaffold/app.d.ts +5 -0
  61. package/dist/scaffold/app.js +172 -0
  62. package/dist/scaffold/controller.js +2 -2
  63. package/dist/scaffold/index.d.ts +2 -1
  64. package/dist/scaffold/index.js +2 -1
  65. package/dist/scaffold/job.d.ts +5 -0
  66. package/dist/scaffold/job.js +35 -0
  67. package/dist/scaffold/model.js +8 -8
  68. package/dist/templates/auth/auth.wiring.ts.tpl +1 -1
  69. package/dist/templates/auth/registration.controller.ts.tpl +1 -1
  70. package/dist/templates/auth/session.controller.ts.tpl +1 -1
  71. package/dist/templates/auth/user.model.ts.tpl +1 -1
  72. package/dist/templates/index.d.ts +23 -0
  73. package/dist/templates/index.js +66 -0
  74. package/dist/templates/index.ts +85 -0
  75. package/dist/templates/project/.env.example.tpl +18 -0
  76. package/dist/templates/project/.gitignore.tpl +24 -0
  77. package/dist/templates/project/.npmrc.tpl +4 -0
  78. package/dist/templates/project/AGENTS.md.tpl +210 -0
  79. package/dist/templates/project/CLAUDE.md.tpl +119 -0
  80. package/dist/templates/project/agents/async.md.tpl +218 -0
  81. package/dist/templates/project/agents/data.md.tpl +532 -0
  82. package/dist/templates/project/agents/frontend.md.tpl +201 -0
  83. package/dist/templates/project/agents/realtime.md.tpl +157 -0
  84. package/dist/templates/project/agents/security.md.tpl +92 -0
  85. package/dist/templates/project/agents/testing.md.tpl +101 -0
  86. package/dist/templates/project/agents/web.md.tpl +177 -0
  87. package/dist/templates/project/apps/web/channels/.gitkeep.tpl +1 -0
  88. package/dist/templates/project/apps/web/components/.gitkeep.tpl +1 -0
  89. package/dist/templates/project/apps/web/composables/useApiPing.ts.tpl +25 -0
  90. package/dist/templates/project/apps/web/controllers/home.ts.tpl +19 -0
  91. package/dist/templates/project/apps/web/index.html.tpl +18 -0
  92. package/dist/templates/project/apps/web/layouts/Default.vue.tpl +43 -0
  93. package/dist/templates/project/apps/web/main.ts.tpl +24 -0
  94. package/dist/templates/project/apps/web/pages/Home/Index.vue.tpl +36 -0
  95. package/dist/templates/project/apps/web/routes.ts.tpl +8 -0
  96. package/dist/templates/project/docker-compose.yaml.tpl +73 -0
  97. package/dist/templates/project/domain/events/.gitkeep.tpl +1 -0
  98. package/dist/templates/project/domain/jobs/.gitkeep.tpl +1 -0
  99. package/dist/templates/project/domain/listeners/.gitkeep.tpl +1 -0
  100. package/dist/templates/project/domain/mails/.gitkeep.tpl +1 -0
  101. package/dist/templates/project/domain/models/.gitkeep.tpl +1 -0
  102. package/dist/templates/project/domain/schema/.gitkeep.tpl +1 -0
  103. package/dist/templates/project/domain/services/.gitkeep.tpl +1 -0
  104. package/dist/templates/project/gaon.config.ts.tpl +27 -0
  105. package/dist/templates/project/package.json.tpl +30 -0
  106. package/dist/templates/project/pnpm-workspace.yaml.tpl +11 -0
  107. package/dist/templates/project/shared/components/.gitkeep.tpl +1 -0
  108. package/dist/templates/project/shared/composables/useDebounce.ts.tpl +21 -0
  109. package/dist/templates/project/tsconfig.json.tpl +25 -0
  110. package/dist/templates/project/vite.config.ts.tpl +23 -0
  111. package/dist/tsResolve.js +1 -1
  112. package/dist/work.d.ts +2 -2
  113. package/dist/work.js +3 -1
  114. package/package.json +13 -11
  115. package/dist/__fixtures__/db-minimal/domain/schema/widgets.d.ts +0 -12
  116. package/dist/__fixtures__/db-minimal/domain/schema/widgets.js +0 -7
  117. package/dist/__fixtures__/db-minimal/gaon.config.d.ts +0 -2
  118. package/dist/__fixtures__/db-minimal/gaon.config.js +0 -11
  119. package/dist/check.d.ts +0 -29
  120. package/dist/check.js +0 -92
@@ -0,0 +1,50 @@
1
+ /**
2
+ * @gaonjs/cli · MCP 서버 배선 — v0.15 §13.5 M10 · 질문 8.
3
+ *
4
+ * `gaon mcp` 가 이 함수를 stdio 트랜스포트로 부트업한다. Node.js MCP SDK
5
+ * (@modelcontextprotocol/sdk) 의 Server + StdioServerTransport 를 사용해
6
+ * JSON-RPC 2.0 over stdio 로 4 도구를 노출한다(§9 실 프로토콜).
7
+ *
8
+ * 도구 목록/호출은 tools.ts 의 TOOLS 카탈로그를 그대로 소비 — 카탈로그가
9
+ * 단일 진실 원천(SSOT). 여기서 도구를 추가하지 않는다.
10
+ *
11
+ * transport:
12
+ * - stdio (기본 · MCP 표준)
13
+ * - http 는 v1 범위 외(§13.5 M10 명시 X · 필요 시 후속 마일스톤에서 추가)
14
+ *
15
+ * 종료: transport 가 닫히면(SIGINT / stdin 종료) close() 로 정리한다.
16
+ */
17
+ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
18
+ /** 서버 이름·버전 — MCP initialize 응답의 serverInfo. */
19
+ export declare const SERVER_NAME = "gaon";
20
+ /**
21
+ * 서버 버전 — CLI 가 주입한다(호출자가 넘긴 값 · 미주입 시 'dev').
22
+ * 실제 값은 packages/cli/package.json 의 version(파사드 gaonjs 로 재수출됨).
23
+ */
24
+ export type McpServerVersion = string;
25
+ export interface McpServerOptions {
26
+ /** 프로젝트 루트 — 각 도구가 이 cwd 기준으로 관례를 해석. */
27
+ readonly cwd: string;
28
+ /** 서버 버전 — 미주입 시 'dev'. */
29
+ readonly version?: McpServerVersion;
30
+ }
31
+ /** 서버 핸들 — 종료 대기·강제 종료용. */
32
+ export interface McpServerHandle {
33
+ /** transport 가 종료될 때까지 대기. stdin close / SIGINT 시 resolve. */
34
+ wait(): Promise<void>;
35
+ /** 강제 종료 — server + transport 정리. */
36
+ close(): Promise<void>;
37
+ }
38
+ /**
39
+ * MCP 서버 인스턴스 만들기 + tool handlers 등록.
40
+ * transport 연결은 startMcpServer 에서 한다(테스트 격리를 위해 분리).
41
+ */
42
+ export declare function createMcpServer(opts: McpServerOptions): Server;
43
+ /**
44
+ * `gaon mcp` 본체 — stdio transport 로 서버를 부트업하고 stdin close 를 기다린다.
45
+ * 반환 핸들의 wait() 는 transport 가 종료될 때 resolve.
46
+ *
47
+ * 테스트에서는 stdio 를 파이프로 감싼 자식 프로세스로 실행하고, 이 함수는
48
+ * 자식 프로세스 내부에서 호출된다(§9 실 프로토콜 왕복).
49
+ */
50
+ export declare function startMcpServer(opts: McpServerOptions): Promise<McpServerHandle>;
@@ -0,0 +1,102 @@
1
+ /**
2
+ * @gaonjs/cli · MCP 서버 배선 — v0.15 §13.5 M10 · 질문 8.
3
+ *
4
+ * `gaon mcp` 가 이 함수를 stdio 트랜스포트로 부트업한다. Node.js MCP SDK
5
+ * (@modelcontextprotocol/sdk) 의 Server + StdioServerTransport 를 사용해
6
+ * JSON-RPC 2.0 over stdio 로 4 도구를 노출한다(§9 실 프로토콜).
7
+ *
8
+ * 도구 목록/호출은 tools.ts 의 TOOLS 카탈로그를 그대로 소비 — 카탈로그가
9
+ * 단일 진실 원천(SSOT). 여기서 도구를 추가하지 않는다.
10
+ *
11
+ * transport:
12
+ * - stdio (기본 · MCP 표준)
13
+ * - http 는 v1 범위 외(§13.5 M10 명시 X · 필요 시 후속 마일스톤에서 추가)
14
+ *
15
+ * 종료: transport 가 닫히면(SIGINT / stdin 종료) close() 로 정리한다.
16
+ */
17
+ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
18
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
19
+ import { CallToolRequestSchema, ListToolsRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
20
+ import { TOOLS, findTool } from './tools.js';
21
+ /** 서버 이름·버전 — MCP initialize 응답의 serverInfo. */
22
+ export const SERVER_NAME = 'gaon';
23
+ /**
24
+ * MCP 서버 인스턴스 만들기 + tool handlers 등록.
25
+ * transport 연결은 startMcpServer 에서 한다(테스트 격리를 위해 분리).
26
+ */
27
+ export function createMcpServer(opts) {
28
+ const version = opts.version ?? 'dev';
29
+ const server = new Server({ name: SERVER_NAME, version }, { capabilities: { tools: {} } });
30
+ // tools/list — TOOLS 카탈로그를 그대로 노출.
31
+ server.setRequestHandler(ListToolsRequestSchema, async () => {
32
+ return {
33
+ tools: TOOLS.map((t) => ({
34
+ name: t.name,
35
+ description: t.description,
36
+ inputSchema: t.inputSchema,
37
+ })),
38
+ };
39
+ });
40
+ // tools/call — 이름으로 도구를 찾아 실행. 결과를 MCP 스키마로 감싼다.
41
+ server.setRequestHandler(CallToolRequestSchema, async (req) => {
42
+ const { name, arguments: args } = req.params;
43
+ const tool = findTool(name);
44
+ if (!tool) {
45
+ const known = TOOLS.map((t) => t.name).join(', ');
46
+ return {
47
+ content: [
48
+ {
49
+ type: 'text',
50
+ text: `[gaon mcp] 알 수 없는 도구: '${name}'\n 사용 가능: ${known}`,
51
+ },
52
+ ],
53
+ isError: true,
54
+ };
55
+ }
56
+ const result = await tool.run((args ?? {}), opts.cwd);
57
+ return {
58
+ content: [{ type: 'text', text: result.text }],
59
+ structuredContent: result.data,
60
+ isError: result.isError,
61
+ };
62
+ });
63
+ return server;
64
+ }
65
+ /**
66
+ * `gaon mcp` 본체 — stdio transport 로 서버를 부트업하고 stdin close 를 기다린다.
67
+ * 반환 핸들의 wait() 는 transport 가 종료될 때 resolve.
68
+ *
69
+ * 테스트에서는 stdio 를 파이프로 감싼 자식 프로세스로 실행하고, 이 함수는
70
+ * 자식 프로세스 내부에서 호출된다(§9 실 프로토콜 왕복).
71
+ */
72
+ export async function startMcpServer(opts) {
73
+ const server = createMcpServer(opts);
74
+ const transport = new StdioServerTransport();
75
+ // transport 가 닫힐 때(=stdin EOF · 상대편이 pipe 닫음)를 감지하기 위한 gate.
76
+ let resolveClosed = () => { };
77
+ const closed = new Promise((r) => {
78
+ resolveClosed = r;
79
+ });
80
+ // MCP SDK 의 Server 는 close() 로 transport 도 함께 닫는다.
81
+ // onclose 는 transport 레벨에서 발생 — Server 의 onclose 핸들러가 이를 위임한다.
82
+ server.onclose = () => {
83
+ resolveClosed();
84
+ };
85
+ await server.connect(transport);
86
+ // StdioServerTransport 는 stdin 'end' 를 감지하지 않고 'data' 만 청취한다.
87
+ // 클라이언트가 파이프를 닫으면(=stdin EOF) 자동 종료가 되지 않아 서버가
88
+ // 무한 대기한다. 그래서 여기서 stdin.on('end') 를 잡아 명시적으로 close.
89
+ // (SDK 자체 이슈 회피 — MCP 프로토콜상 stdin close = 세션 종료 관례.)
90
+ const stdin = process.stdin;
91
+ const onStdinEnd = () => {
92
+ void server.close();
93
+ };
94
+ stdin.on('end', onStdinEnd);
95
+ return {
96
+ wait: () => closed,
97
+ close: async () => {
98
+ stdin.off('end', onStdinEnd);
99
+ await server.close();
100
+ },
101
+ };
102
+ }
@@ -0,0 +1,109 @@
1
+ /**
2
+ * MCP 도구의 실행 결과. text 는 사람 UI(Claude Desktop 에 그대로 표시),
3
+ * data 는 에이전트가 파싱하기 좋은 구조화 형태. isError 는 도구 실행 자체가
4
+ * 실패했음을 알린다(에러도 도구 응답으로 낸다 — MCP 관례).
5
+ */
6
+ export interface ToolResult {
7
+ readonly text: string;
8
+ readonly data: unknown;
9
+ readonly isError: boolean;
10
+ }
11
+ /** 도구가 받는 인자 — 각 도구가 구체 타입으로 사용. */
12
+ export type ToolArgs = Record<string, unknown>;
13
+ /**
14
+ * `list_routes` — 프로젝트의 모든 앱과 라우트를 나열한다.
15
+ *
16
+ * 관례(§3.3): apps/<name>/routes.ts 의 default export 가 routes(...) 결과
17
+ * (RouteDef · entries[]). @gaonjs/config resolveApps 가 발견·로드한다.
18
+ *
19
+ * 인자:
20
+ * { app?: string } — 지정 시 그 앱만. 없으면 전 앱.
21
+ *
22
+ * 반환:
23
+ * data.apps: [{ name, routeCount, routes: [{ method, path, controller, action }] }]
24
+ */
25
+ export declare function listRoutesTool(args: ToolArgs, cwd: string): Promise<ToolResult>;
26
+ /**
27
+ * `get_schema` — domain/schema/ 의 테이블 정의를 조회한다.
28
+ *
29
+ * 관례(§4.1): domain/schema/*.ts 의 export 로 table(...) 결과가 놓인다.
30
+ * @gaonjs/data scanSchemaDir 로 모듈을 로드하고, TableDef 만 추려 컬럼 메타를
31
+ * 함께 낸다. 커넥션 키(§4.5) · 복합 제약(§4.2) 도 포함.
32
+ *
33
+ * 인자:
34
+ * { table?: string, db?: string }
35
+ * table — 지정 시 그 테이블만
36
+ * db — 지정 시 그 커넥션 것만 (기본: 전 커넥션)
37
+ *
38
+ * 반환:
39
+ * data.tables: [{ name, db, columns: [...], constraints: { unique, index, check } }]
40
+ */
41
+ export declare function getSchemaTool(args: ToolArgs, cwd: string): Promise<ToolResult>;
42
+ /**
43
+ * `run_migration` — 스키마 diff 를 계산해 DB 에 적용한다.
44
+ *
45
+ * 실제 로직은 `../db/migrate.ts` (M9-D · gaon db migrate) 를 그대로 재사용.
46
+ * 실 DB 필요(§9) — 목업 없이 진짜 커넥션에 실행한다.
47
+ *
48
+ * 인자:
49
+ * { db?: string, dryRun?: boolean }
50
+ * db — 커넥션 키(§4.5). 기본 'main'.
51
+ * dryRun — true 면 SQL 만 계산·출력, DB 미변경.
52
+ *
53
+ * 반환: runDbMigrate 의 결과 그대로(text + json).
54
+ */
55
+ export declare function runMigrationTool(args: ToolArgs, cwd: string): Promise<ToolResult>;
56
+ /**
57
+ * `run_tests` — 프로젝트 테스트를 실 실행한다(§9 · vitest spawn).
58
+ *
59
+ * `gaon test` 와 같은 경로를 쓰되, MCP 컨텍스트에서는 stdout 을 파이프로
60
+ * 캡처해서 결과를 도구 응답에 담아 돌려준다(자식이 종료할 때까지 대기).
61
+ *
62
+ * 인자:
63
+ * { scope?: 'unit'|'integration'|'all', filter?: string }
64
+ * scope — 기본 'all'
65
+ * filter — vitest 위치 인자(파일 패턴 substring)
66
+ *
67
+ * 반환:
68
+ * data: { exitCode, scope, filter, output }
69
+ * text: vitest 자체 출력(사람 UI 그대로)
70
+ */
71
+ export declare function runTestsTool(args: ToolArgs, cwd: string): Promise<ToolResult>;
72
+ /**
73
+ * `read_agent_doc` — 관례 문서 2층 구조(결정 40)의 카테고리 문서를 조회한다.
74
+ *
75
+ * 루트 AGENTS.md(코어) 색인은 "해당 영역 작업 전에 agents/<카테고리>.md 를
76
+ * 읽어라" 고 지시한다. 파일시스템 접근이 제한된 MCP 클라이언트도 이 지시를
77
+ * 이행할 수 있도록 문서 조회를 구조화 도구로 노출한다 — grep 대체 원칙
78
+ * (§7.5.3) 의 문서판.
79
+ *
80
+ * 인자:
81
+ * { category?: string } — data·web·frontend·async·realtime·testing·security.
82
+ * 생략 시 사용 가능한 카테고리 목록을 반환.
83
+ */
84
+ export declare function readAgentDocTool(args: ToolArgs, cwd: string): Promise<ToolResult>;
85
+ /** MCP 도구 스펙 — MCP 클라이언트에게 노출할 이름·설명·입력 스키마. */
86
+ export interface McpToolSpec {
87
+ readonly name: string;
88
+ readonly description: string;
89
+ readonly inputSchema: Record<string, unknown>;
90
+ readonly run: (args: ToolArgs, cwd: string) => Promise<ToolResult>;
91
+ }
92
+ /**
93
+ * 정본 §12 질문 8 확정 명세 4종을 카탈로그로 제공한다. 순서 = 원문 순서
94
+ * (라우트 · 스키마 · 마이그레이션 · 테스트).
95
+ */
96
+ export declare const TOOLS: readonly McpToolSpec[];
97
+ /**
98
+ * 이름으로 도구를 찾는다. 없으면 undefined.
99
+ */
100
+ export declare function findTool(name: string): McpToolSpec | undefined;
101
+ /**
102
+ * 앱 관례 검사(진단용) — apps/ 존재만 확인. 도구 실행 전에 조기 종료를 하지 않고,
103
+ * 각 도구가 자체 관례 검사를 하도록 한다(에러 = 수리 안내 · §7.5.3).
104
+ * 이 함수는 외부에서 문서 생성용으로만 쓴다(현재 unused 지만 진단 훅 자리).
105
+ */
106
+ export declare function projectSummary(cwd: string): {
107
+ hasApps: boolean;
108
+ hasSchema: boolean;
109
+ };