feat: JspaceAI 自主智慧架构

基于第一性原理 + Anthropic 2026 J-space 论文实现的具身智慧系统。

核心架构:
- ODE 动力系统 + 并行专家 + J-space 工作空间广播
- 12 个异构专家(视觉/屏幕/听觉/语言/鼠标/跨模态)
- workspace 256 维 + LayerNorm + RK4 积分

自主心智(最重要的能力):
- 好奇心驱动探索(内在奖励 + 世界模型)
- 跨会话状态持久化(海洋不蒸发)
- 自我模型(知道自己会什么不会什么)
- 元学习(自适应学习率 + 策略选择)

具身 Agent(完整神经系统):
- 感知层:摄像头 + 麦克风 + 屏幕 + 键盘 + 鼠标
- 大脑皮层(workspace)+ 小脑(运动控制)+ 中枢神经(门控)
- 海马体(情景记忆)+ 基底神经节(动作选择)
- 执行器:鼠标控制 + 键盘输出 + 音频播放 + 屏幕绘制

多模态支持:
- 原生图像/音频/视频/文本/键盘/鼠标 6 种模态
- 跨平台(macOS/Windows/Linux)

外挂模块系统:
- 可热插拔的外部能力(小模型/知识库/工具)
- 核心心智不依赖外挂,断开后继续工作

守护进程:
- 用户主动 start/stop(不自启)
- 后台静默运行,持续感知学习
- 状态自动保存,跨会话继续

J-lens 可解释性:
- 观测模型内部每个 ODE 子步的想法
- Directed Modulation 验证 workspace 因果作用
- Selectivity 验证(ablate workspace)

小模型蒸馏:
- 接 GPT-2/Qwen 等迁移理解能力
- 蒸馏完成后小模型可断开

验证结果:
- 连续序列:JSpace 胜 Flat 39.7%
- 语言进化:loss 3.95→2.40
- workspace ||w||:v1 0.05 → v2 16.0
- 实时五通道感知 + 具身闭环运行
This commit is contained in:
2026-07-07 09:19:31 +08:00
commit e782ef4db1
30 changed files with 7446 additions and 0 deletions

128
jspaceai/platform.py Normal file
View File

@@ -0,0 +1,128 @@
"""
平台抽象层——跨平台支持macOS / Windows / Linux
统一封装各平台差异:屏幕尺寸、权限检查、路径等。
所有平台相关代码集中在这里。
"""
from __future__ import annotations
import sys
import platform
from dataclasses import dataclass
@dataclass
class PlatformInfo:
"""平台信息"""
system: str
machine: str
python_version: str
is_macos: bool
is_windows: bool
is_linux: bool
@classmethod
def detect(cls) -> "PlatformInfo":
s = platform.system()
return cls(
system=s,
machine=platform.machine(),
python_version=sys.version,
is_macos=(s == 'Darwin'),
is_windows=(s == 'Windows'),
is_linux=(s == 'Linux'),
)
def __str__(self) -> str:
return f"{self.system}/{self.machine} (Python {self.python_version.split()[0]})"
PLATFORM = PlatformInfo.detect()
def get_screen_size() -> tuple[int, int]:
"""获取主屏幕尺寸(跨平台)"""
try:
import mss
with mss.MSS() as sct:
mon = sct.monitors[1]
return (mon['width'], mon['height'])
except Exception:
pass
if PLATFORM.is_windows:
try:
import ctypes
user32 = ctypes.windll.user32
return (user32.GetSystemMetrics(0), user32.GetSystemMetrics(1))
except Exception:
pass
return (1920, 1080)
def check_camera_permission() -> bool:
"""检查摄像头权限"""
if not PLATFORM.is_macos:
return True
try:
import cv2
cap = cv2.VideoCapture(0)
ok = cap.isOpened()
cap.release()
return ok
except Exception:
return False
def check_microphone_permission() -> bool:
"""检查麦克风权限"""
try:
import sounddevice as sd
sd.query_devices(kind='input')
return True
except Exception:
return False
def check_input_monitoring_permission() -> bool:
"""检查键盘/鼠标监听权限"""
if PLATFORM.is_windows:
return True
if PLATFORM.is_linux:
return True
if PLATFORM.is_macos:
try:
import subprocess
result = subprocess.run(
['osascript', '-e',
'tell application "System Events" to keystroke ""'],
capture_output=True, timeout=2,
)
return result.returncode == 0
except Exception:
return False
return True
def print_permission_guide():
"""打印权限配置指南"""
print("\n权限配置指南:")
print("-" * 50)
if PLATFORM.is_macos:
print("macOS 权限设置:")
print(" 1. 摄像头: 系统设置 → 隐私与安全 → 摄像头")
print(" 2. 麦克风: 系统设置 → 隐私与安全 → 麦克风")
print(" 3. 键盘/鼠标监听: 系统设置 → 隐私与安全 → 辅助功能")
print(" 4. 屏幕录制: 系统设置 → 隐私与安全 → 屏幕录制")
elif PLATFORM.is_linux:
print("Linux 权限设置:")
print(" 1. 摄像头: 确保用户在 video 组 (sudo usermod -aG video $USER)")
print(" 2. 音频: 确保用户在 audio 组")
print(" 3. 键盘/鼠标: 需要 X11 或 Wayland 输入权限")
print(" 4. 屏幕捕获: 需要 X11 或安装 grim/slurp (Wayland)")
elif PLATFORM.is_windows:
print("Windows 权限设置:")
print(" 1. 摄像头/麦克风: 设置 → 隐私 → 摄像头/麦克风")
print(" 2. 键盘/鼠标: 通常不需要额外权限")
print("-" * 50)