아키텍처

CLI-JAW는 Node.js 22 기반의 다중 AI 런타임 서버입니다. 루트 핸들러와 200개의 API/미디어 엔드포인트가 CLI, TUI, Web PWA, Electron 데스크톱, Telegram, Discord, Manager 대시보드에 동일한 세션, 메모리, 프로젝트 컨텍스트를 제공합니다.

시스템 개요

모든 런타임 표면은 server.ts를 거칩니다. 서버는 인증, 보안, SSE 이벤트, 부트스트랩을 처리한 뒤 src/routes/와 핵심 하위 시스템으로 위임합니다.

CLI/TUI/Electron/Web/Telegram/Discord ──HTTP──→ server.ts
Web events                             ──SSE──→ GET /api/events
Dashboard (port 24576)                 ─proxy→ src/manager/
Agent streams                          ─NDJSON→ provider runtime + traces

server.ts ──→ src/routes/* ──→ src/core/ | src/agent/ | src/orchestrator/
                         └──→ src/memory/ | src/messaging/ | src/browser/

런타임 표면

표면진입점전송 방식
CLIbin/cli-jaw.ts + bin/commands/*.ts서버로의 HTTP
Terminal TUIsrc/tui/터미널 렌더링 + 서버 명령
Web UIpublic/index.htmlHTTP + SSE
Electron Desktopelectron/src/번들 sidecar 서버 + WebView
Telegramsrc/telegram/bot.tsGrammy 봇 폴링
Discordsrc/discord/bot.tsdiscord.js 게이트웨이
Manager Dashboardsrc/manager/ + public/manager/별도 포트 스캔, 프록시, 인스턴스 관리

라우트 모듈

서버는 루트 핸들러와 라우트 모듈을 합쳐 201개의 핸들러를 등록합니다. 각 모듈은 Express 앱과 인증 미들웨어를 받는 독립적인 등록 함수입니다.

모듈라우트 수역할
server.ts (기본)14헬스체크, 세션, 메시지, 인증, 명령, 중지, 초기화
settings.ts18설정, 프롬프트, heartbeat-md, MCP, CLI 레지스트리, 쿼터
browser.ts43브라우저 기본 동작, 탭 관리, web-ai 자동화 및 code-mode 회수
memory.ts13메모리 런타임, KV 저장소, 메모리 파일
jaw-memory.ts11Jaw 메모리 검색, 읽기, 저장, 소울, 플러시, 리플렉션
orchestrate.ts11PABCD 상태, 워커, 디스패치, 큐 관리
goal.ts3지속적 목표 상태, 이력
goal-run.ts3범위 제한 목표 실행 생명주기
messaging.ts6업로드, 파일 열기, 음성, 채널 전송
employees.ts5직원 CRUD 및 초기화
skills.ts5스킬 목록, 활성화, 비활성화, 초기화
avatar.ts4에이전트/사용자 아바타 이미지 관리
traces.ts3공개 트레이스 요약 및 이벤트 조회
heartbeat.ts2하트비트 GET 및 검증된 PUT
i18n.ts2언어 목록 및 로케일 번들

파일 트리 개요

cli-jaw/
├── bin/                    # CLI entry + 30 command files
│   ├── cli-jaw.ts          # Root CLI router
│   └── commands/           # serve, init, doctor, chat, browser, ...
├── server.ts               # Express/SSE bootstrap (593L)
├── src/
│   ├── core/               # 30 files — config, DB, bus, i18n, employees
│   ├── agent/              # 37 files — spawn, events, lifecycle, ACP
│   ├── orchestrator/       # 10 files — PABCD pipeline, state machine
│   ├── prompt/             # builder + templates
│   ├── memory/             # 13 files — runtime, indexing, flush, identity
│   ├── cli/                # registry, commands, handlers, ACP client
│   ├── messaging/          # shared Telegram/Discord runtime
│   ├── telegram/           # Telegram bot transport
│   ├── discord/            # Discord bot transport
│   ├── browser/            # CDP control + web-ai automation
│   ├── routes/             # 32 route registrars
│   ├── manager/            # Dashboard server
│   ├── security/           # Path guards, input validation
│   └── shared/             # Tool-log sanitization
├── public/                 # Web UI (Vanilla TS + Vite 8)
│   ├── js/                 # 86 TypeScript modules
│   ├── css/                # 11 CSS files
│   ├── manager/            # React 19 dashboard app
│   └── dist/               # Build output
├── electron/               # Electron desktop shell + packaged sidecar
├── native/                 # jaw-claude-i Rust helper
│   └── jaw-claude-i/       # 15 Rust source files
└── tests/                  # 447 test files

핵심 하위 시스템

하위 시스템위치역할
에이전트 런타임src/agent/CLI 프로세스 생성, NDJSON 이벤트 스트리밍, 세션 관리, 큐, 폴백, 재시도
오케스트레이터src/orchestrator/PABCD 상태 머신, 직원 디스패치, 워커 모니터링
메모리src/memory/3계층 메모리(구조화/에피소드/시맨틱), FTS5 인덱싱, 플러시, 리플렉션
프롬프트 빌더src/prompt/9단계 프롬프트 파이프라인: A1, A2, 메모리, 오케스트레이션, 하트비트, 스킬, 위임
브라우저src/browser/Chrome CDP 제어, 탭 생명주기, Web AI 자동화, provider별 어댑터
메시징src/messaging/공유 Telegram/Discord 채널 라우팅, 대상 추적

보안 모델

데이터 저장소

CLI-JAW는 better-sqlite3를 통해 SQLite를 사용하여 세션, 메시지, 메모리, 직원, 오케스트레이션 상태, 대기 중인 메시지를 저장합니다. 데이터베이스 스키마는 src/core/db.ts에 정의되어 있습니다.

session           # active CLI, session ID, model, working directory
messages          # conversation history with trace and tool log
memory            # key-value memory store
employees         # registered employee agents
employee_sessions # per-employee session tracking
orc_state         # PABCD orchestration state
queued_messages   # pending message queue