@tuzi-ince/hi-loop 0.3.0 → 0.3.1
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.
- package/package.json +1 -1
- package/src/mcp-server.js +21 -7
package/package.json
CHANGED
package/src/mcp-server.js
CHANGED
|
@@ -14,6 +14,17 @@ const log = (line) => process.stderr.write(`[hi-loop-mcp] ${line}\n`);
|
|
|
14
14
|
const text = (t) => ({ content: [{ type: 'text', text: t }] });
|
|
15
15
|
const fail = (t) => ({ content: [{ type: 'text', text: t }], isError: true });
|
|
16
16
|
|
|
17
|
+
/**
|
|
18
|
+
* MCP 경로의 기본 작업 디렉터리.
|
|
19
|
+
*
|
|
20
|
+
* CLI 는 `process.cwd()` 만 본다 — 터미널에서 cd 한 곳이 곧 사용자의 명시 의도이기 때문이다.
|
|
21
|
+
* 그러나 MCP 는 호스트(클로드코드/커서)가 서버를 띄우는 경로이고, "어느 프로젝트인가"의
|
|
22
|
+
* 정답은 호스트가 주입하는 `CLAUDE_PROJECT_DIR` 다. 서버 프로세스의 cwd 가 프로젝트 루트와
|
|
23
|
+
* 다른 호스트에서도 올바른 루트를 잡으려면 이 env 를 먼저 본다. 호출자가 cwd 를 명시하면
|
|
24
|
+
* 그것이 최우선이다(각 핸들러의 인자가 이 기본값을 덮는다).
|
|
25
|
+
*/
|
|
26
|
+
const defaultCwd = () => process.env.CLAUDE_PROJECT_DIR || process.cwd();
|
|
27
|
+
|
|
17
28
|
/** 도구 구현 (SDK 없이도 단위 테스트 가능하도록 분리) */
|
|
18
29
|
export const tools = {
|
|
19
30
|
hiloop_run: {
|
|
@@ -28,7 +39,7 @@ export const tools = {
|
|
|
28
39
|
ship,
|
|
29
40
|
watch,
|
|
30
41
|
stopAfter,
|
|
31
|
-
cwd =
|
|
42
|
+
cwd = defaultCwd(),
|
|
32
43
|
}) => {
|
|
33
44
|
if (!goal) return fail('goal 은 필수입니다.');
|
|
34
45
|
const result = await runLoop({
|
|
@@ -66,7 +77,7 @@ export const tools = {
|
|
|
66
77
|
hiloop_answer: {
|
|
67
78
|
description:
|
|
68
79
|
'hiloop_run 이 반환한 대기 중인 질문에 답한다. choice 는 제시된 선택지의 키(a, b, ...)이고, note 로 자유 서술을 덧붙이거나 대신할 수 있다. 답한 뒤 hiloop_run 을 같은 goal 로 다시 호출하면 이어서 진행된다.',
|
|
69
|
-
handler: async ({ choice, note = '', cwd =
|
|
80
|
+
handler: async ({ choice, note = '', cwd = defaultCwd() } = {}) => {
|
|
70
81
|
const statePath = statePathFor(cwd);
|
|
71
82
|
const state = loadState(statePath);
|
|
72
83
|
if (!state?.ask) return fail('대기 중인 질문이 없습니다.');
|
|
@@ -79,17 +90,17 @@ export const tools = {
|
|
|
79
90
|
},
|
|
80
91
|
hiloop_status: {
|
|
81
92
|
description: '현재 워크스페이스의 .agent-state.json 루프 상태 요약을 반환한다.',
|
|
82
|
-
handler: async ({ cwd =
|
|
93
|
+
handler: async ({ cwd = defaultCwd() } = {}) => text(summarizeState(loadState(statePathFor(cwd)))),
|
|
83
94
|
},
|
|
84
95
|
hiloop_reset: {
|
|
85
96
|
description: '.agent-state.json 을 삭제해 루프 상태를 초기화한다.',
|
|
86
|
-
handler: async ({ cwd =
|
|
97
|
+
handler: async ({ cwd = defaultCwd() } = {}) =>
|
|
87
98
|
text(resetState(statePathFor(cwd)) ? '상태를 초기화했습니다.' : '초기화할 상태가 없습니다.'),
|
|
88
99
|
},
|
|
89
100
|
hiloop_rollback: {
|
|
90
101
|
description:
|
|
91
102
|
'git 체크포인트로 파일을 되돌린다. to(회차)를 주면 그 회차 직전 스냅샷으로, 없으면 가장 최근 체크포인트로 복원한다.',
|
|
92
|
-
handler: async ({ to, cwd =
|
|
103
|
+
handler: async ({ to, cwd = defaultCwd() } = {}) => {
|
|
93
104
|
const state = loadState(statePathFor(cwd));
|
|
94
105
|
const checkpoints = state?.checkpoints ?? [];
|
|
95
106
|
if (checkpoints.length === 0)
|
|
@@ -112,7 +123,7 @@ export const tools = {
|
|
|
112
123
|
hiloop_setup: {
|
|
113
124
|
description:
|
|
114
125
|
'프로젝트에 hi-loop 설정(.mcp.json MCP 서버 등록, .gitignore 항목, docs/tests 디렉터리)을 자동 주입한다. dryRun 이면 변경 없이 계획만 보여준다.',
|
|
115
|
-
handler: async ({ dryRun = false, cwd =
|
|
126
|
+
handler: async ({ dryRun = false, cwd = defaultCwd() } = {}) => {
|
|
116
127
|
const report = runSetup({ cwd, dryRun: Boolean(dryRun) });
|
|
117
128
|
return text(report.lines.join('\n'));
|
|
118
129
|
},
|
|
@@ -147,7 +158,10 @@ export async function startMcpServer({ version = '0.1.0' } = {}) {
|
|
|
147
158
|
}
|
|
148
159
|
|
|
149
160
|
const server = new McpServer({ name: 'hi-loop', version });
|
|
150
|
-
const cwdSchema = z
|
|
161
|
+
const cwdSchema = z
|
|
162
|
+
.string()
|
|
163
|
+
.optional()
|
|
164
|
+
.describe('작업 디렉터리 (기본: CLAUDE_PROJECT_DIR → 없으면 서버 프로세스의 cwd)');
|
|
151
165
|
|
|
152
166
|
server.registerTool(
|
|
153
167
|
'hiloop_run',
|