Skip to content

feat(usage): Muse Code CLI로 META 구독 사용량 표시 - #357

Merged
dmae97 merged 1 commit into
mainfrom
meta-usage-20261106
Nov 6, 2026
Merged

dmae97 merged 1 commit into
mainfrom
meta-usage-20261106

Conversation

@dmae97

@dmae97 dmae97 commented Nov 6, 2026

Copy link
Copy Markdown
Owner

요약

Meta(meta) OAuth로 로그인되어 있으면, 상태 레일 USAGE에 META 사용량을 공식 Muse Code CLI에서 읽어 보여 줍니다. 지금 main에서는 quota API unavailable로 고정되어 있습니다.

이 PR은 #356(usage-allowlist-20261106) 위에 쌓았습니다. 공급자 source 표가 provider-usage-sources.ts로 옮겨진 상태에 의존합니다. #356을 먼저 병합해 주세요. 병합 후 base를 main으로 바꾸면 diff에는 이 커밋(81429b4)만 남습니다.

  • provider-usage-meta.ts(새 파일, 220줄) 동작
    • 5분에 최대 한 번 muse serve --provider meta --disable-write --disable-shell --no-session-log를 띄웁니다.
    • MSP initialize handshake 후 usage/read만 묻고 stdin을 닫아 host를 종료시킵니다. prompt를 보내지 않고 모델도 호출하지 않습니다.
    • 자식 프로세스에는 PATH, HOME, locale, temp/config 디렉터리처럼 정해진 비밀 아닌 환경 변수만 넘깁니다. OMK가 가진 키는 보내지 않습니다.
    • 제한: 15초 timeout, 응답 1MiB 상한. 종료가 늦으면 2초 뒤 SIGKILL합니다.
  • 화면에 나오는 결과
    • 현재 창(보통 5H)과 주간 창(7D)을 reset까지 남은 시간과 함께 보여 줍니다.
    • 아직 관측된 창이 없으면 no observed usage yet(tier가 있으면 함께)로, 0%가 아닙니다.
    • CLI가 없으면 connect: 안내, 실패나 timeout이면 usage unavailable입니다.
  • 문서: docs/providers.md, CHANGELOG.md.

원래 체크아웃의 미커밋 작업에서 이 부분만 골라 옮겼습니다. 원래 작업에는 이 모듈의 테스트가 없어서 새로 썼습니다.

검증 (로컬, 커밋 81429b4)

  • 새 테스트 provider-usage-meta.test.ts(8개)
    • 창 파싱과 reset 단위 변환(ms에서 s), 잘못된 값은 unavailable로 남는지
    • 상태별 메시지(CLI 없음, 실패, 관측 전, tier, 예외)
    • meta source가 OMK 자격 증명을 읽지 않는지
    • 넘기는 환경 변수가 제한되는지
    • PATH에 둔 가짜 muse로 실제 handshake와 serve 인자를 확인하고, 응답 전에 종료되는 경우와 CLI가 없는 경우도 확인
    • 모듈을 추가하기 전에는 import 실패, 연결 전에는 1개가 실패했습니다.
  • npx vitest --run: provider-usage, StatusSidebarComponent, statusPanelModel, loadSubscriptionUsage를 쓰는 10개 파일, 147개 통과
  • 종료 0: npx tsgo --noEmit, npx biome check --error-on-warnings ., check:module-size, check:import-cycles, check:ts-imports, check:doc-links, check:feature-claims, check:release-surface
  • 설치된 Muse Code 1.4.14
    • muse serve --help에 --disable-write, --disable-shell, --no-session-log, --provider가 모두 있습니다.
    • fetchMetaUsage를 한 번 실행해 471ms에 usage/read 응답(no observed usage yet)을 받았고, 남은 muse serve 프로세스는 없었습니다.
    • 실제 사용량 창이 있는 계정 상태는 확인하지 못했습니다. 창 파싱은 단위 테스트로만 확인했습니다.

- provider-usage-meta: `muse serve --provider meta --disable-write --disable-shell --no-session-log`를
  띄워 MSP initialize 후 usage/read만 묻고 stdin을 닫는다. prompt와 모델 호출은 없다.
  허용된 비밀 아닌 환경 변수만 넘기고, 15초 timeout과 응답 1MiB 상한, SIGKILL fallback을 둔다.
- meta source를 kind "meta", TTL 5분으로 바꾸고 loadSubscriptionUsage가 probe로 읽는다.
  CLI 없음은 connect 안내, 관측 전은 no observed usage yet, 실패는 usage unavailable.
- 테스트: 파서, 상태별 메시지, 자격 증명 미사용, 환경 변수 제한, PATH의 가짜 muse로 실제 handshake.
- providers 문서, CHANGELOG 갱신.
@dmae97

dmae97 commented Nov 6, 2026

Copy link
Copy Markdown
Owner Author

OMK Community

Thanks for opening this pull request. Mention @omk-community with reproduction steps, a question, or the review help you need.

Automated response. No code changes or merges are performed.

@dmae97 dmae97 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

81429b4 검토에서 병합 전 수정이 필요한 프로세스 종료 경로를 재현했습니다. 아래 stdin 오류 처리를 추가해 주세요. 클라우드의 Node 24.22.1에서 이 커밋의 provider-usage-meta.ts와 provider-usage-text.ts를 그대로 사용했고, 실제 Muse나 외부 API 대신 가짜 프로세스만 실행했습니다. 전체 저장소 테스트를 새로 실행한 것은 아닙니다.

현재 CI run 42183630509는 build/check/test는 통과했지만 secret-scan이 실패했습니다. 로그에는 git log ... --full-history --all을 대상으로 과거 테스트 파일의 17개 탐지가 기록되어 있어, 이 PR이 새 비밀을 추가했다고 판단할 근거는 아닙니다. 그렇더라도 검사를 건너뛸 수는 없으니 탐지 내용을 검토하고 통과한 결과가 필요합니다. #356 선행 병합과 main 기준 재검증도 필요해 병합은 보류합니다.

}

function write(child: ChildProcess, packet: Record<string, unknown>): void {
child.stdin?.write(`${JSON.stringify(packet)}\n`);

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Muse의 stdin 오류를 처리해야 합니다. child.on("error", ...)는 child.stdin Socket의 error 이벤트를 잡지 못합니다. 가짜 Muse가 fs.closeSync(0) 뒤 {jsonrpc:"2.0", id:1, result:{}}를 stdout에 쓰고 잠시 살아 있게 하면, 이어지는 initialized/usage/read write에서 처리되지 않은 EPIPE가 나며 부모가 exit 1로 종료됩니다. fetchMetaUsage의 try/catch도 이 비동기 EventEmitter 오류를 잡지 못하므로, 선택적인 사용량 조회 실패가 TUI 전체를 종료시킬 수 있습니다. stdin 오류를 finish({kind:"failed"})로 연결하고 종료 후 write를 막아 주세요. stdin이 닫힌 상태에서 initialize 응답이 도착해도 부모가 살아 있고 usage unavailable로 끝나는 회귀 테스트가 필요합니다.

@dmae97
dmae97 changed the base branch from usage-allowlist-20261106 to main November 6, 2026 08:14
@dmae97 dmae97 closed this Nov 6, 2026
@dmae97 dmae97 reopened this Nov 6, 2026
@dmae97
dmae97 merged commit f977108 into main Nov 6, 2026
3 of 4 checks passed
@dmae97
dmae97 deleted the meta-usage-20261106 branch November 6, 2026 08:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant