@yoonion/mimi-seed-mcp 0.25.0 → 0.25.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.
@@ -10,14 +10,26 @@ export type DataKeyLookup = {
10
10
  } | {
11
11
  state: 'absent';
12
12
  backend: string;
13
- } | {
13
+ }
14
+ /** `locked` — macOS 로그인 키체인이 잠겨 있다(잠금 해제하면 풀린다). CLI 가 잠금 해제를 제안하는 근거. */
15
+ | {
14
16
  state: 'unavailable';
15
17
  backend: string;
16
18
  reason: string;
19
+ locked?: boolean;
17
20
  };
18
21
  export type DataKeySource = () => DataKeyLookup;
19
22
  /** 키가 없을 때 새로 만들고, 최종적으로 저장소에 남은 키(경쟁에서 이긴 쪽)를 돌려준다. */
20
23
  export type DataKeyCreator = () => DataKeyLookup;
24
+ /** macOS 로그인 키체인 파일. 추가와 조회가 같은 키체인을 보도록 둘 다 이 경로를 명시한다. */
25
+ export declare function macosLoginKeychain(home?: string): string;
26
+ /**
27
+ * `security` 의 종료 코드(= OSStatus 의 하위 바이트)를 사용자가 할 일로 바꾼다. stderr 는 싣지 않는다.
28
+ * 36 = -25308 errSecInteractionNotAllowed: 로그인 키체인이 잠겼는데 확인 창을 띄울 수 없다(대개 SSH 세션).
29
+ */
30
+ export declare function macosFailure(status: number | null, keychain: string): Extract<DataKeyLookup, {
31
+ state: 'unavailable';
32
+ }>;
21
33
  /** 이 OS 의 저장소에 키를 만든다(이미 있으면 그 키). 쓰기 경로만 부른다. */
22
34
  export declare function osCreateDataKey(home?: string, platform?: NodeJS.Platform): DataKeyLookup;
23
35
  export declare function osDataKeySource(home?: string, platform?: NodeJS.Platform): DataKeyLookup;
@@ -33,5 +45,7 @@ export declare function lookupDataKey(now?: number): DataKeyLookup;
33
45
  * "키가 없다"가 아니라 "지금 못 닿는다"이고, 거기서 새 키를 만들면 기존 파일들이 영영 잠긴다.
34
46
  */
35
47
  export declare function obtainDataKey(): DataKeyLookup;
48
+ /** 기억해 둔 실패를 지운다 — CLI 가 키체인 잠금을 풀어 준 직후 곧바로 다시 시도할 수 있게. */
49
+ export declare function forgetFailedDataKeyLookup(): void;
36
50
  /** 테스트용 — 키 출처(와 생성기)를 바꾸고 캐시를 비운다. 인자 없이 부르면 OS 저장소로 되돌린다. 제품 코드는 부르지 않는다(가드 테스트). */
37
51
  export declare function setDataKeySourceForTests(next?: DataKeySource, create?: DataKeyCreator): void;
@@ -22,12 +22,24 @@ const R = catalog({
22
22
  timeout: (cmd) => `${cmd} 응답 없음(시간 초과)`,
23
23
  badKey: '저장된 키의 형식이 올바르지 않음',
24
24
  noBackend: (platform) => `이 OS(${platform})에는 지원하는 키 저장소가 없음`,
25
+ lockedRemote: (keychain) => `로그인 키체인이 잠겨 있음 — SSH·원격 세션(VS Code Remote-SSH 포함)에서는 화면 세션과 따로 잠기고 확인 창도 뜨지 않는다. \`security unlock-keychain ${keychain}\` 로 이 세션에서 풀거나, 주로 원격으로 쓰는 컴퓨터라면 \`mimi-seed credentials mode file\``,
26
+ lockedLocal: '로그인 키체인이 잠겨 있음 — 키체인 접근(Keychain Access)에서 잠금을 해제하세요',
27
+ wrongPassword: '로그인 키체인 비밀번호가 맞지 않음(로그인 비밀번호와 어긋났을 수 있음)',
28
+ noKeychain: '기본 키체인이 없거나 찾을 수 없음',
29
+ cancelled: '키체인 확인 창에서 취소됨',
30
+ waiting: '키체인 확인 창이 응답을 기다리다 시간이 초과됨',
25
31
  }, {
26
32
  exit: (cmd, status) => `${cmd} exited with status ${status}`,
27
33
  missingTool: (cmd) => `${cmd} is not installed`,
28
34
  timeout: (cmd) => `${cmd} did not respond (timed out)`,
29
35
  badKey: 'the stored key is not in the expected format',
30
36
  noBackend: (platform) => `no supported key store on this OS (${platform})`,
37
+ lockedRemote: (keychain) => `the login keychain is locked — an SSH or remote session (including VS Code Remote-SSH) has its own lock and cannot show the unlock dialog. Run \`security unlock-keychain ${keychain}\` to unlock it for this session, or use \`mimi-seed credentials mode file\` on a machine you mostly use remotely`,
38
+ lockedLocal: 'the login keychain is locked — unlock it in Keychain Access',
39
+ wrongPassword: 'the login keychain password is wrong (it may be out of sync with the login password)',
40
+ noKeychain: 'there is no default keychain, or it cannot be found',
41
+ cancelled: 'the keychain dialog was cancelled',
42
+ waiting: 'timed out waiting for the keychain dialog',
31
43
  });
32
44
  // PowerShell 콜드 스타트가 1초 안팎이라 넉넉히. 키체인 GUI 확인 창이 떠도 여기서 끝난다.
33
45
  const SPAWN_TIMEOUT_MS = 20_000;
@@ -57,17 +69,54 @@ function decodeKey(text, backend) {
57
69
  ? { state: 'ok', key, backend }
58
70
  : { state: 'unavailable', backend, reason: R().badKey };
59
71
  }
60
- /** macOS 로그인 키체인. `security` 의 항목 없음 종료 코드는 44. */
61
- function macosLookup() {
72
+ /** spawn 오류 코드(ENOENT · ETIMEDOUT …). */
73
+ function errorCode(result) {
74
+ const error = result.error;
75
+ return error?.code;
76
+ }
77
+ /** macOS 로그인 키체인 파일. 추가와 조회가 같은 키체인을 보도록 둘 다 이 경로를 명시한다. */
78
+ export function macosLoginKeychain(home = os.homedir()) {
79
+ return path.join(home, 'Library', 'Keychains', 'login.keychain-db');
80
+ }
81
+ /** SSH·원격 세션인가 — 그 보안 세션에서는 로그인 키체인이 따로 잠기고 잠금 해제 창을 띄울 수 없다. */
82
+ function isRemoteSession() {
83
+ if (process.env.SSH_CONNECTION || process.env.SSH_TTY || process.env.SSH_CLIENT)
84
+ return true;
85
+ const manager = run('/bin/launchctl', ['managername']);
86
+ return manager.status === 0 && manager.stdout.trim() !== 'Aqua';
87
+ }
88
+ /**
89
+ * `security` 의 종료 코드(= OSStatus 의 하위 바이트)를 사용자가 할 일로 바꾼다. stderr 는 싣지 않는다.
90
+ * 36 = -25308 errSecInteractionNotAllowed: 로그인 키체인이 잠겼는데 확인 창을 띄울 수 없다(대개 SSH 세션).
91
+ */
92
+ export function macosFailure(status, keychain) {
62
93
  const backend = 'macOS Keychain';
63
- const result = run('/usr/bin/security', ['find-generic-password', '-s', KEYCHAIN_SERVICE, '-a', KEYCHAIN_ACCOUNT, '-w']);
94
+ switch (status) {
95
+ case 36:
96
+ return { state: 'unavailable', backend, locked: true, reason: isRemoteSession() ? R().lockedRemote(keychain) : R().lockedLocal };
97
+ case 51:
98
+ return { state: 'unavailable', backend, reason: R().wrongPassword };
99
+ case 37:
100
+ case 50:
101
+ return { state: 'unavailable', backend, reason: R().noKeychain };
102
+ case 128:
103
+ return { state: 'unavailable', backend, reason: R().cancelled };
104
+ default:
105
+ return { state: 'unavailable', backend, reason: R().exit('security', String(status)) };
106
+ }
107
+ }
108
+ /** macOS 로그인 키체인. `security` 의 항목 없음 종료 코드는 44. 잠긴 키체인에서는 항목이 있어도 36 이다. */
109
+ function macosLookup(home = os.homedir()) {
110
+ const backend = 'macOS Keychain';
111
+ const keychain = macosLoginKeychain(home);
112
+ const result = run('/usr/bin/security', ['find-generic-password', '-s', KEYCHAIN_SERVICE, '-a', KEYCHAIN_ACCOUNT, '-w', keychain]);
64
113
  const problem = spawnProblem('security', result);
65
114
  if (problem)
66
- return { state: 'unavailable', backend, reason: problem };
115
+ return { state: 'unavailable', backend, reason: errorCode(result) === 'ETIMEDOUT' ? R().waiting : problem };
67
116
  if (result.status === 44)
68
117
  return { state: 'absent', backend };
69
118
  if (result.status !== 0)
70
- return { state: 'unavailable', backend, reason: R().exit('security', String(result.status)) };
119
+ return macosFailure(result.status, keychain);
71
120
  return decodeKey(result.stdout, backend);
72
121
  }
73
122
  // 입력(DPAPI 블롭 base64)은 stdin 으로, 출력(키 base64)은 stdout 으로 — 명령줄 인자에는 아무것도 싣지 않는다.
@@ -112,24 +161,27 @@ function linuxLookup() {
112
161
  }
113
162
  // ── 생성 ────────────────────────────────────────────────────────────────────────────────────────────────
114
163
  /**
115
- * macOS: `security -i` 의 **stdin** 으로 add-generic-password 를 보낸다 — `-w <키>` 를 argv 로 넘기면 ps 에 보인다.
116
- * `-U` 없이 추가하므로 이미 있으면 실패한다. 성공 여부는 종료 코드 대신 다시 읽어서 판정한다(대화형 모드의
117
- * 종료 코드는 명령 실패를 싣지 않는다) — 다시 읽은 키가 곧 이긴 쪽 키다.
164
+ * macOS: `security -i` 의 **stdin** 으로 add-generic-password 를 보낸다 — `-w <키>` 를 argv 로 넘기면 ps 에 보인다
165
+ * (macOS 의 ps 는 setuid root 라 다른 사용자의 프로세스 인자도 읽는다). `-U` 없이 추가하므로 이미 있으면 45 다.
166
+ * 대화형 모드도 마지막 명령의 실패를 종료 코드로 돌려준다(36 등): 0 이나 45(경쟁에서 짐)면 다시 읽어 이긴 쪽 키를 쓰고,
167
+ * 그 밖의 실패는 다시 읽지 않는다 — 잠긴 키체인에서 확인 창을 기다리며 두 번 멈추지 않게.
168
+ * 키체인 경로는 공백·따옴표가 없을 때만 명시한다(대화형 모드의 인용 규칙에 기대지 않는다). 생성과 조회는 같은 Apple
169
+ * 바이너리(security)가 하므로 그 항목의 신뢰 앱 목록이 Node 업그레이드와 무관하다 — 다른 생성기를 섞지 말 것.
118
170
  */
119
- function macosCreate() {
171
+ function macosCreate(home = os.homedir()) {
172
+ const keychain = macosLoginKeychain(home);
173
+ const target = /^[^\s"'\\]+$/.test(keychain) ? ` ${keychain}` : '';
120
174
  const key = randomBytes(DATA_KEY_BYTES).toString('base64');
121
- const command = `add-generic-password -s ${KEYCHAIN_SERVICE} -a ${KEYCHAIN_ACCOUNT} -w ${key}\n`;
175
+ const command = `add-generic-password -s ${KEYCHAIN_SERVICE} -a ${KEYCHAIN_ACCOUNT} -w ${key}${target}\n`;
122
176
  const result = run('/usr/bin/security', ['-i'], command);
123
177
  const problem = spawnProblem('security', result);
124
- if (problem)
125
- return { state: 'unavailable', backend: 'macOS Keychain', reason: problem };
126
- const stored = macosLookup();
127
- // 추가가 거부됐는데(잠긴 키체인 · SSH · 샌드박스: -25308 "User interaction is not allowed") 다른 프로세스가 만든
128
- // 키도 없으면 "키 없음"이 아니라 "닿지 못함"이다 — keychain 모드의 오류가 이유(종료 코드)를 싣게.
129
- if (stored.state === 'absent' && result.status !== 0) {
130
- return { state: 'unavailable', backend: 'macOS Keychain', reason: R().exit('security', String(result.status)) };
178
+ if (problem) {
179
+ const timedOut = errorCode(result) === 'ETIMEDOUT';
180
+ return { state: 'unavailable', backend: 'macOS Keychain', reason: timedOut ? R().waiting : problem };
131
181
  }
132
- return stored;
182
+ if (result.status !== 0 && result.status !== 45)
183
+ return macosFailure(result.status, keychain);
184
+ return macosLookup(home);
133
185
  }
134
186
  const DPAPI_PROTECT = DPAPI_UNPROTECT.replace('::Unprotect(', '::Protect(');
135
187
  /** Windows: DPAPI 로 보호한 키를 temp 에 쓰고 link(2) 로 게시한다 — 이미 있으면 EEXIST, 진 쪽은 있는 키를 읽는다. */
@@ -210,7 +262,7 @@ function linuxCreate(home) {
210
262
  /** 이 OS 의 저장소에 키를 만든다(이미 있으면 그 키). 쓰기 경로만 부른다. */
211
263
  export function osCreateDataKey(home = os.homedir(), platform = process.platform) {
212
264
  if (platform === 'darwin')
213
- return macosCreate();
265
+ return macosCreate(home);
214
266
  if (platform === 'win32')
215
267
  return windowsCreate(home);
216
268
  if (platform === 'linux')
@@ -219,7 +271,7 @@ export function osCreateDataKey(home = os.homedir(), platform = process.platform
219
271
  }
220
272
  export function osDataKeySource(home = os.homedir(), platform = process.platform) {
221
273
  if (platform === 'darwin')
222
- return macosLookup();
274
+ return macosLookup(home);
223
275
  if (platform === 'win32')
224
276
  return windowsLookup(home);
225
277
  if (platform === 'linux')
@@ -266,6 +318,10 @@ export function obtainDataKey() {
266
318
  }
267
319
  return made;
268
320
  }
321
+ /** 기억해 둔 실패를 지운다 — CLI 가 키체인 잠금을 풀어 준 직후 곧바로 다시 시도할 수 있게. */
322
+ export function forgetFailedDataKeyLookup() {
323
+ failed = undefined;
324
+ }
269
325
  /** 테스트용 — 키 출처(와 생성기)를 바꾸고 캐시를 비운다. 인자 없이 부르면 OS 저장소로 되돌린다. 제품 코드는 부르지 않는다(가드 테스트). */
270
326
  export function setDataKeySourceForTests(next, create) {
271
327
  source = next ?? (() => osDataKeySource());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yoonion/mimi-seed-mcp",
3
- "version": "0.25.0",
3
+ "version": "0.25.1",
4
4
  "description": "Mimi Seed MCP server \u2014 Firebase + AdMob + Google Play + App Store management for Claude Code / Codex / Cursor / any MCP client.",
5
5
  "type": "module",
6
6
  "imports": {