pinglet-cli 0.2.3 โ†’ 0.2.4

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.
@@ -35,9 +35,11 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.runLogin = runLogin;
37
37
  const child_process_1 = require("child_process");
38
+ const http = __importStar(require("http"));
38
39
  const readline = __importStar(require("readline"));
39
40
  const config_1 = require("../config");
40
41
  const api_1 = require("../api");
42
+ const LOGIN_TIMEOUT_MS = 180_000;
41
43
  function prompt(question) {
42
44
  const rl = readline.createInterface({
43
45
  input: process.stdin,
@@ -48,10 +50,72 @@ function prompt(question) {
48
50
  resolve(answer);
49
51
  }));
50
52
  }
53
+ function openBrowser(url) {
54
+ const cmd = process.platform === "darwin"
55
+ ? ["open", url]
56
+ : process.platform === "win32"
57
+ ? ["cmd", "/c", "start", "", url]
58
+ : ["xdg-open", url];
59
+ try {
60
+ (0, child_process_1.spawn)(cmd[0], cmd.slice(1), { stdio: "ignore" }).unref();
61
+ return true;
62
+ }
63
+ catch {
64
+ return false;
65
+ }
66
+ }
67
+ const RESULT_HTML = (ok) => `<!doctype html>
68
+ <html lang="ko"><head><meta charset="utf-8"><title>Pinglet</title>
69
+ <style>body{font-family:-apple-system,sans-serif;display:flex;align-items:center;
70
+ justify-content:center;height:100vh;margin:0;background:#0f1115;color:#e6e9ef}
71
+ div{text-align:center}p{color:#8b93a3}</style></head><body><div>
72
+ <h1>${ok ? "๐Ÿ’Œ ๋กœ๊ทธ์ธ ์™„๋ฃŒ" : "โœ— ๋กœ๊ทธ์ธ ์‹คํŒจ"}</h1>
73
+ <p>${ok ? "์ด ์ฐฝ์„ ๋‹ซ๊ณ  ํ„ฐ๋ฏธ๋„๋กœ ๋Œ์•„๊ฐ€์„ธ์š”." : "ํ„ฐ๋ฏธ๋„์—์„œ ๋‹ค์‹œ ์‹œ๋„ํ•ด ์ฃผ์„ธ์š”."}</p>
74
+ </div></body></html>`;
51
75
  /**
52
- * GitHub OAuth ๋กœ๊ทธ์ธ.
53
- * ๋ธŒ๋ผ์šฐ์ €์—์„œ /auth/github โ†’ callback JSON์˜ token์„ CLI์— ๋ถ™์—ฌ๋„ฃ๋Š” ๋ฐฉ์‹ (MVP).
76
+ * ๋ฃจํ”„๋ฐฑ ๋กœ๊ทธ์ธ: ์ผํšŒ์šฉ ๋กœ์ปฌ ์„œ๋ฒ„๋ฅผ ๋„์šฐ๊ณ  ๋ธŒ๋ผ์šฐ์ €์—์„œ OAuth๋ฅผ ๋งˆ์น˜๋ฉด
77
+ * ์„œ๋ฒ„๊ฐ€ http://127.0.0.1:{port}/callback?token=... ์œผ๋กœ ํ† ํฐ์„ ๋„˜๊ฒจ์ค€๋‹ค.
78
+ * ํƒ€์ž„์•„์›ƒ/์‹คํŒจ ์‹œ null โ€” ํ˜ธ์ถœ๋ถ€๊ฐ€ ์ˆ˜๋™ ๋ถ™์—ฌ๋„ฃ๊ธฐ๋กœ ํด๋ฐฑํ•œ๋‹ค.
54
79
  */
80
+ function loginViaLoopback(apiBaseUrl) {
81
+ return new Promise((resolve) => {
82
+ let finished = false;
83
+ const done = (token) => {
84
+ if (finished)
85
+ return;
86
+ finished = true;
87
+ clearTimeout(timer);
88
+ // ๋งˆ์ง€๋ง‰ ์‘๋‹ต์ด flush๋  ์‹œ๊ฐ„์„ ์ฃผ๊ณ  ๋‹ซ๋Š”๋‹ค.
89
+ setTimeout(() => {
90
+ server.closeAllConnections?.();
91
+ server.close();
92
+ }, 200).unref();
93
+ resolve(token);
94
+ };
95
+ const timer = setTimeout(() => done(null), LOGIN_TIMEOUT_MS);
96
+ const server = http.createServer((req, res) => {
97
+ const url = new URL(req.url ?? "/", "http://127.0.0.1");
98
+ if (url.pathname !== "/callback") {
99
+ res.statusCode = 404;
100
+ res.end();
101
+ return;
102
+ }
103
+ const token = url.searchParams.get("token");
104
+ res.setHeader("content-type", "text/html; charset=utf-8");
105
+ res.end(RESULT_HTML(Boolean(token)));
106
+ done(token);
107
+ });
108
+ server.on("error", () => done(null));
109
+ server.listen(0, "127.0.0.1", () => {
110
+ const port = server.address().port;
111
+ const url = `${apiBaseUrl}/auth/github?cli_port=${port}`;
112
+ console.log("๋ธŒ๋ผ์šฐ์ €์—์„œ GitHub ๋กœ๊ทธ์ธ์„ ์™„๋ฃŒํ•ด ์ฃผ์„ธ์š”โ€ฆ");
113
+ console.log(` ${url}\n`);
114
+ openBrowser(url);
115
+ });
116
+ });
117
+ }
118
+ /** GitHub OAuth ๋กœ๊ทธ์ธ โ€” ๋ฃจํ”„๋ฐฑ ์ž๋™ ์ˆ˜์‹ , ์‹คํŒจ ์‹œ ์ˆ˜๋™ ๋ถ™์—ฌ๋„ฃ๊ธฐ ํด๋ฐฑ. */
55
119
  async function runLogin(args) {
56
120
  const config = (0, config_1.loadConfig)();
57
121
  let token;
@@ -60,19 +124,14 @@ async function runLogin(args) {
60
124
  token = args[tokenIndex + 1];
61
125
  }
62
126
  if (!token) {
63
- const url = `${config.apiBaseUrl}/auth/github`;
64
127
  console.log(`\n๋กœ๊ทธ์ธํ•˜๋ฉด ์ด์šฉ์•ฝ๊ด€(${config.apiBaseUrl}/terms)๊ณผ ๊ฐœ์ธ์ •๋ณด์ฒ˜๋ฆฌ๋ฐฉ์นจ(${config.apiBaseUrl}/privacy)์— ๋™์˜ํ•˜๋Š” ๊ฒƒ์œผ๋กœ ๊ฐ„์ฃผ๋ฉ๋‹ˆ๋‹ค.`);
65
- console.log("๋ธŒ๋ผ์šฐ์ €์—์„œ GitHub ๋กœ๊ทธ์ธ ํ›„, ์‘๋‹ต JSON์˜ token ๊ฐ’์„ ๋ถ™์—ฌ๋„ฃ์–ด ์ฃผ์„ธ์š”.");
66
- console.log(` ${url}\n`);
67
- if (process.platform === "darwin") {
68
- try {
69
- (0, child_process_1.spawn)("open", [url], { stdio: "ignore" }).unref();
70
- }
71
- catch {
72
- // ๋ธŒ๋ผ์šฐ์ €๋ฅผ ๋ชป ์—ด์–ด๋„ URL์€ ์ถœ๋ ฅํ–ˆ์œผ๋ฏ€๋กœ ์ง„ํ–‰
73
- }
128
+ token = (await loginViaLoopback(config.apiBaseUrl)) ?? undefined;
129
+ if (!token) {
130
+ // SSH ๋“ฑ ๋ธŒ๋ผ์šฐ์ €์™€ ํ„ฐ๋ฏธ๋„์ด ๋‹ค๋ฅธ ๊ธฐ๊ณ„์ธ ๊ฒฝ์šฐ๋ฅผ ์œ„ํ•œ ํด๋ฐฑ.
131
+ console.log("์ž๋™ ๋กœ๊ทธ์ธ์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค. ์•„๋ž˜ URL์—์„œ ๋กœ๊ทธ์ธ ํ›„ ์‘๋‹ต JSON์˜ token ๊ฐ’์„ ๋ถ™์—ฌ๋„ฃ์–ด ์ฃผ์„ธ์š”.");
132
+ console.log(` ${config.apiBaseUrl}/auth/github\n`);
133
+ token = (await prompt("token: ")).trim();
74
134
  }
75
- token = (await prompt("token: ")).trim();
76
135
  }
77
136
  if (!token) {
78
137
  console.log("โœ— token์ด ๋น„์–ด ์žˆ์Šต๋‹ˆ๋‹ค.");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinglet-cli",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "AI๊ฐ€ ์ƒ๊ฐํ•˜๋Š” ๋™์•ˆ ๋‹ค๋ฅธ ๊ฐœ๋ฐœ์ž์˜ Ping์„ ๋งŒ๋‚˜๋Š” ๋ฉ”์‹œ์ง€ ๋„คํŠธ์›Œํฌ โ€” Claude Code / Codex integration",
5
5
  "license": "MIT",
6
6
  "repository": {