본문으로 건너뛰기

oneshim-automation

자동화 제어 크레이트. 정책 기반 명령 실행, 감사 로깅, OS 네이티브 샌드박스, UI 자동화 의도 해석, 워크플로우 프리셋을 담당합니다.


개요

서버에서 수신한 자동화 명령을 정책 토큰 검증 후 실행하며, 모든 명령은 감사 로그에 기록됩니다. 2-레이어 액션 모델을 사용: AutomationIntent (서버→클라이언트 고수준 의도) → AutomationAction (클라이언트 내부 저수준 액션).

자동화 시스템 전체 흐름

서버의 Intent 수신 → 정책 검증 → 감사 로그 기록 → OCR/LLM 기반 의도 해석 → 샌드박스 격리 실행 → 결과 반환 기본 비활성 상태이며, set_enabled(true) 호출로 활성화합니다.


모듈 구조

oneshim-automation/src/
├── lib.rs # 크레이트 루트 (9개 모듈)
├── audit.rs # AuditLogger — 감사 로깅 (14개 메서드)
├── controller.rs # AutomationController — 정책 검증 + 명령 실행
├── input_driver.rs # NoOpInputDriver — 테스트/기본 입력 드라이버
├── intent_resolver.rs # IntentResolver + IntentExecutor — 의도 해석 + 실행
├── local_llm.rs # LocalLlmProvider — 로컬 LLM (규칙 기반)
├── policy.rs # PolicyClient — 서버 정책 동기화 + 검증
├── presets.rs # builtin_presets() — 내장 워크플로우 10개
├── resolver.rs # 정책 → 샌드박스 프로필 리졸버 (순수 함수 3개)
└── sandbox/ # OS 네이티브 커널 샌드박스
├── mod.rs # create_platform_sandbox() 팩토리
├── noop.rs # NoOpSandbox — 비활성 시 기본
├── linux.rs # LinuxSandbox — seccomp + namespaces
├── macos.rs # MacOsSandbox — sandbox-exec + App Sandbox
└── windows.rs # WindowsSandbox — Job Objects + AppContainers

주요 모듈

AutomationController — 중심 제어기

정책 검증 + 명령 실행 + 감사 로깅 + 샌드박스 관리의 중심 제어기.

메서드설명
new(sandbox, sandbox_config)생성자 (Arc<dyn Sandbox> + SandboxConfig)
set_enabled(bool)자동화 활성화/비활성화
set_intent_executor(executor)IntentExecutor 주입
execute_command(cmd)정책 검증 → 감사 로그 → 액션 디스패치 → 결과 반환
execute_intent(intent, config)고수준 의도 실행 (IntentExecutor 위임)
resolve_for_command(command)정책 기반 동적 SandboxConfig 결정
dispatch_action_with_config(action, config)타임아웃 적용 액션 실행
실행 타임아웃

tokio::time::timeout 기반으로 모든 액션에 실행 시간 제한이 적용됩니다. 타임아웃 발생 시 CoreError::ExecutionTimeout이 반환되고 감사 로그에 기록됩니다.

PolicyClient — 정책 관리

서버 정책 동기화 + 명령 검증 + 프로세스 허가 관리.

메서드설명
update_policies(policies)서버에서 동기화된 정책 갱신
validate_command(cmd)캐시 유효성 + 토큰 검증
validate_args(policy, args)glob 패턴 기반 인자 검증 (* 와일드카드)
is_process_allowed(name)HashSet 기반 빠른 허가 조회
get_policy_for_process(name)프로세스별 정책 조회

ExecutionPolicy 모델:

pub struct ExecutionPolicy {
pub policy_id: String,
pub process_name: String,
pub process_hash: Option<String>, // 바이너리 해시 (변조 감지)
pub allowed_args: Vec<String>, // glob 패턴 기반
pub requires_sudo: bool,
pub max_execution_time_ms: u64,
pub audit_level: AuditLevel, // None | Basic | Detailed | Full
// 샌드박스 오버라이드
pub sandbox_profile: Option<SandboxProfile>,
pub allowed_paths: Vec<String>,
pub allow_network: Option<bool>,
}

AuditLogger — 감사 로깅 (14개 메서드)

로컬 VecDeque 버퍼 + 배치 전송 감사 로그. 비파괴 조회 메서드 포함.

타입

pub enum AuditStatus { Started, Completed, Failed, Denied, Timeout }

pub struct AuditEntry {
pub entry_id: String,
pub timestamp: DateTime<Utc>,
pub session_id: String,
pub command_id: String,
pub action_type: String,
pub status: AuditStatus,
pub details: Option<String>,
pub execution_time_ms: Option<u64>,
}

메서드

분류메서드설명
기본 로깅log_start()명령 시작 기록
log_complete()명령 완료 기록
log_denied()정책 거부 기록
log_failed()실행 실패 기록
조건부 로깅log_start_if(level, ...)AuditLevel::None이면 스킵
log_complete_with_time(level, ..., ms)실행 시간 포함 기록
log_timeout(...)타임아웃 기록
배치 관리has_pending_batch()전송 준비 여부
pending_count()대기 중 항목 수
drain_batch()배치 크기만큼 꺼내기
drain_all()전체 꺼내기 (셧다운 시)
비파괴 조회recent_entries(limit)최근 N개 조회 (API용)
entries_by_status(status, limit)상태별 필터링
stats()통계 집계 (total, success, failed, denied, timeout)

기본 설정: 최대 1,000개 버퍼, 50개 배치 크기. 버퍼 오버플로 시 가장 오래된 항목 자동 제거.

resolver.rs — 정책 → 샌드박스 리졸버

순수 함수 3개 (상태 없음, 테스트 용이):

함수설명
resolve_sandbox_profile(policy)AuditLevel → SandboxProfile 계단식 매핑
resolve_sandbox_config(policy, base)정책 기반 동적 SandboxConfig 생성
default_strict_config(base)정책 없는 명령용 Strict 설정

AuditLevel → SandboxProfile 매핑

AuditLevel::None     → SandboxProfile::Permissive
AuditLevel::Basic → SandboxProfile::Standard
AuditLevel::Detailed → SandboxProfile::Strict
AuditLevel::Full → SandboxProfile::Strict
  • requires_sudo=true 이면 Permissive → Standard 승격
  • 서버 sandbox_profile 오버라이드 우선 적용

IntentResolver + IntentExecutor — 의도 해석

고수준 의도(AutomationIntent)를 저수준 액션(AutomationAction) 시퀀스로 변환하고 실행.

  • IntentResolver — UI 요소 탐색 → 좌표 계산 → 액션 변환
    • OCR 기반 요소 탐색 (ElementFinder)
    • LLM 기반 의도 해석 (LlmProvider)
    • 신뢰도 검증 + 재시도 로직 (IntentConfig)
  • IntentExecutor — 변환된 액션 순차 실행 + 결과 검증
    • execute_intent(intent, config)IntentResult
    • 실행 후 텍스트 확인 (verify_after_action)
    • 재시도 (max_retries, retry_interval_ms)

presets.rs — 내장 워크플로우 프리셋

builtin_presets() 함수가 10개 내장 프리셋을 반환. 플랫폼별 키 매핑 자동 적용.

생산성 프리셋 (4개)

ID이름단계
save-file파일 저장ExecuteHotkey(["Cmd/Ctrl", "S"])
undo실행 취소ExecuteHotkey(["Cmd/Ctrl", "Z"])
select-all-copy전체 선택 후 복사Cmd/Ctrl+A → 200ms → Cmd/Ctrl+C
find-replace찾기/바꾸기ExecuteHotkey(["Cmd/Ctrl", "H"])

앱 관리 프리셋 (3개)

ID이름단계
switch-next-app다음 앱 전환Cmd/Alt+Tab
close-window현재 창 닫기Cmd/Ctrl+W
minimize-all전체 최소화macOS: Cmd+Option+H+M / Win: Win+D

워크플로우 프리셋 (3개)

ID이름단계
morning-routine업무 시작ActivateApp(Mail) → 2s → Calendar → 2s → VSCode
meeting-prep회의 준비ActivateApp(Zoom) → 1s → Notes
end-of-day업무 종료Cmd/Ctrl+S → 1s → Cmd/Ctrl+Q
플랫폼별 키 매핑

platform_modifier() — macOS: "Cmd", 기타: "Ctrl" platform_alt_modifier() — macOS: "Cmd", 기타: "Alt" 런타임에 cfg!(target_os) 분기로 자동 결정됩니다.

sandbox/ — OS 네이티브 커널 샌드박스

create_platform_sandbox() 팩토리 함수로 플랫폼별 샌드박스 생성.

플랫폼구현기술
config.enabled=falseNoOpSandbox패스스루 (제한 없음)
LinuxLinuxSandboxseccomp + namespaces
macOSMacOsSandboxsandbox-exec + App Sandbox
WindowsWindowsSandboxJob Objects + AppContainers
(미지원)NoOpSandbox (폴백)경고 로그 + 패스스루

input_driver.rs — NoOpInputDriver

테스트/기본 입력 드라이버. InputDriver trait 구현체로 모든 액션을 로그만 남기고 무시.

local_llm.rs — LocalLlmProvider

로컬 LLM/규칙 기반 의도 해석. LlmProvider trait 구현체. 외부 API 없이 규칙 매칭으로 동작.


의존성


보안

항목설명
정책 토큰 필수모든 자동화 명령은 서버 발급 정책 토큰 필요
바이너리 해시 검증ExecutionPolicy.process_hash로 변조 감지
인자 패턴 제한glob 패턴으로 허용 인자 제한
OS 네이티브 샌드박스커널 수준 격리 (seccomp, sandbox-exec, Job Objects)
정책 → 샌드박스 자동 바인딩AuditLevel에 따라 SandboxProfile 자동 결정
실행 타임아웃tokio::time::timeout 기반 강제 종료
감사 로그 기록모든 실행/거부/실패/타임아웃이 감사 로그에 기록
기본 비활성AutomationController는 기본 비활성 상태
Privacy Gateway외부 데이터 전송 시 PII 필터 + 민감 앱 차단 + 동의 검증

테스트

모듈테스트 수설명
controller6action/result 직렬화, 의도 실행, 타임아웃
policy7정책 직렬화, 인자 검증, 정책 업데이트, 샌드박스 필드
audit7로그/드레인, 버퍼 오버플로, 배치 부분 추출, 직렬화, 비파괴 조회, 통계
resolver5프로필 매핑, sudo 승격, 경로 병합, strict 기본값, 서버 오버라이드
presets3프리셋 로드, 플랫폼 키 매핑, 단계 검증
sandbox3팩토리 생성, NoOp 패스스루, 기능 보고
intent_resolver2의도 해석, 액션 변환
Total33-

관련 문서: