Download src/utils/cli-profile-scope.js from VanyaJ/bada-terminal: direct link, hf CLI and curl.
- Browser
- Download file 3.19 kB
-
https://huggingface.co/VanyaJ/bada-terminal/resolve/main/src/utils/cli-profile-scope.js
- Command line
-
hf download hf://VanyaJ/bada-terminal/src/utils/cli-profile-scope.js
-
curl -L -o cli-profile-scope.js https://huggingface.co/VanyaJ/bada-terminal/resolve/main/src/utils/cli-profile-scope.js
3.19 kB
| /** ํ CLI ์คํ์ด ์ฐธ์กฐํ๋ ํ๋กํ ๋ฌธ๋งฅ๊ณผ route์ ์๋ช ์ ํจ๊ป ๊ด๋ฆฌํ๋ค. | |
| * ์ค๋ช ๋ฌธ์: /docs/specs/cli-profile-request-context.md (v1.2.0) | |
| */ | |
| const contexts = require('../config/profile-request-context'); | |
| function acquire({ command, profile, cwd, prompt, terminalReplyLanguage }) { | |
| const cli = require('../config/cli-paths').normalizeExecutableName(command); | |
| if (!['claude', 'opencode', 'codeagent'].includes(cli)) { | |
| const credential = require('../services/mcp-session-credentials').issue({ cwd }); | |
| return { profile, mcpCredential: credential.token, release: credential.release }; | |
| } | |
| require('../config/profile-application').assertReady(); | |
| const replyLanguage = terminalReplyLanguage ? require('./agent-reply-language').restore(terminalReplyLanguage, []) : undefined; | |
| const hasLanguage = replyLanguage && replyLanguage.defaultLocale !== 'auto'; | |
| const selected = require('../config/profile-execution-config').resolveProfile(cwd, profile); | |
| // ํ๋กํ ๋ฏธ์ ํ ์คํ๋ ๋ ๋ฆฝ๋ MCP ์๊ฒฉ์ ๊ฐ๋๋ค. ๋ด์ฉ ํด์์ธ contextId๋ฅผ ์ธ์ฆ์ ์ฐ์ง ์๋๋ค. | |
| const credential = require('../services/mcp-session-credentials').issue({ cwd }); | |
| let contextId; | |
| try { contextId = selected?.id || hasLanguage ? contexts.register(selected, cwd, cli, | |
| { prompt, ...(hasLanguage ? { terminalReplyLanguage: replyLanguage } : {}) }) : undefined; } | |
| catch (error) { credential.release(); throw error; } | |
| let released = false; | |
| return { profile: selected, contextId, mcpCredential: credential.token, release() { | |
| if (released) return; released = true; | |
| // ์๊ฒฉ ํด์ ์ค๋ฅ๋ ๋ณ๋ ์์ ํ ๋ฌธ๋งฅ/๋ผ์ฐํธ์ ์ ๋ฆฌ๋ฅผ ๊ฑด๋๋ฐ์ง ์๋๋ค. | |
| try { credential.release(); } | |
| finally { | |
| if (contextId) { | |
| contexts.release(contextId); | |
| if (!contexts.has(contextId)) require('./headroom-routes').removeContextRoutes(contextId); | |
| } | |
| } | |
| } }; | |
| } | |
| function ready(signal, timeoutMs, isCancelled = () => false) { | |
| return new Promise((resolve, reject) => { | |
| let timer, cancellation, settled = false; | |
| const finish = (error, value) => { if (settled) return; settled = true; clearTimeout(timer); clearInterval(cancellation); signal?.removeEventListener('abort', abort); error ? reject(error) : resolve(value); }; | |
| const abort = () => finish(signal.reason || new Error('Profile context preparation cancelled')); | |
| if (signal?.aborted || isCancelled()) { finish(signal?.reason || new Error('Profile context preparation cancelled')); return; } | |
| signal?.addEventListener('abort', abort, { once: true }); | |
| timer = setTimeout(() => finish(new Error('Profile context preparation timed out')), Math.max(1, timeoutMs)); | |
| cancellation = setInterval(() => { try { if (isCancelled()) finish(new Error('Profile context preparation cancelled')); } catch (error) { finish(error); } }, 50); | |
| try { | |
| Promise.resolve(require('./headroom-manager').startProxy({ write() {} })).then(result => finish(result?.success ? null : new Error('Profile context proxy could not start'), result), error => finish(error)); | |
| } catch (error) { finish(error); } | |
| }); | |
| } | |
| module.exports = { acquire, ready }; | |