Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
- 新增依赖前先确认离线可用,禁止引入 Firebase / Sentry / Retrofit / Room / Hilt / WorkManager。
- 修改文件前先读;一次只改一个明确目标,不顺手重构无关代码。
- 每次改动必须能通过 `:app:testDebugUnitTest`;新增行为补 JVM 单测。
- 不提交密钥、keystore、构建产物;版本号保持 `0.0.x`。
- 不提交密钥、keystore、构建产物;小迭代只增 `0.0.x` 最后一位,跨能力层才升到 `0.1.x`。
39 changes: 39 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,42 @@
# CodePocket 更新日志

## [0.1.0] — 2026-11-25

跨小数位的“可信移动 IDE”版本。重点不是再加面板,而是把 Python 引擎、Git 审阅、包安装和质量门禁补成能长期使用的地基。

### Python 引擎独立进程

- 新增 `EngineHostService`,运行在 `android:process=":engine"` 的独立进程;主进程只保留 `RemoteNativeEngine` 代理,不加载 `libpython` / `libpybridge`。
- 主进程与引擎进程通过 `Messenger` + JSON 交换 prepare/run/stdin/stop/event;`RunRequest` 与全部 `RunEvent` 有协议往返测试。
- 引擎卡死时,输出面板「重启引擎」只杀 `:engine` 进程,编辑器缓冲、Git、终端和未保存内容不受影响;不再需要重启整个 App。
- prepare 期间引擎进程死亡会立即回传失败,不再干等 120 秒;引擎事件流异常终止会补发 `Failed` 终态,避免 UI 永远停在“运行中”。

### Git 审阅闭环

- 单文件「暂存 / 取消暂存」、全部暂存;提交改为只提交暂存区,空暂存会明确拒绝。
- 点击变更文件打开 Diff 对话框:工作区 vs 暂存区优先,未跟踪文件显示全加行;输出上限 200KB。
- Diff 读取改为有界流:未跟踪大文件只读前 200KB,二进制文件不强行解码,`DiffFormatter` 超过 200KB 停止增长内存。
- `stageAll` 覆盖删除文件;同一路径暂存后再修改显示 `MM` 两列状态。

### 0.0.31 剩余风险关闭

- 文件树超过 10,000 项时顶部显示截断提示,不再静默丢节点。
- Markdown/HTML 预览单独限制 512K 字符,编辑器原文不动;截断有可见说明。
- `SettingsStore` 的加密字段改为单线程合并后台写;连续拖字号/输出高度只落最后一版,`onStop`/`onCleared` 主动 flush。
- `MonoText` 最小字号抬到 11sp;设置页在 fontScale 2.0 下有 Robolectric/Compose 冒烟。
- `PythonPackageInstaller` 支持纯 Python `.whl` / `.zip` 导入,解析 `dist-info` 名称与版本;拒绝 `.so/.pyd/.dll/.dylib/.wasm` 与路径穿越,安装失败按逆序回滚,不再留下半包。

### 质量与边界

- JVM/Robolectric 单测 **171 通过 / 0 失败 / 0 错误**(新增引擎协议、Git stage/diff、文件树截断、预览上限、设置异步、wheel 安装/回滚、Compose 冒烟)。
- `lintRelease` **0 Error / 27 Warning**;`assembleRelease` 成功,release APK 24,327,148 B,双 ABI,16KB 页对齐,签名证书 SHA-256 `1b02135746d1426d7beda47e706fdb2c77a7145ea41e0f7e14addb191b87fac5`。
- 明确不冒充:不做 Gradle/Java/Kotlin 工程构建、不提供完整 LSP、不支持含原生 `.so` 的 wheel;这些不是当前离线包体和 NDK 工具链能真实交付的能力。
- **仍未做 ARM64 真机验收**:本机无 `/dev/kvm`,x86_64 TCG 模拟器反复失败;引擎进程、Git UI、文件树/预览、wheel 导入没有 Android 运行截图,发布说明中如实标注。

### 版本

- `versionCode 40` / `versionName 0.1.0`。

# 更新日志(Changelog)

格式参考 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/)。
Expand Down
44 changes: 27 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Three runtimes are bundled inside the APK: a natively cross-compiled CPython 3.1
| Offline after install | ⚠️ extra setup | ⚠️ partial | ❌ needs network | ❌ needs network | ✅ **runtime bundled** |
| Modern IDE UI | ❌ terminal only | ⚠️ dated | ✅ | ✅ | ✅ |
| Multi-file tabs / find & replace | ❌ | ✅ | ✅ | ✅ | ✅ |
| Offline Git | ✅ | ❌ | ✅ | ✅ | ✅ **JGit** |
| Offline Git + stage/diff | ✅ | ❌ | ✅ | ✅ | ✅ **JGit + review** |
| Native performance | ✅ | ✅ | — | — | ✅ **native ARM64/x86_64 + pure-Java runtimes** |
| AI assistant (BYOK) | ❌ | ❌ | ✅ cloud | ✅ cloud | ✅ **custom endpoint** |
| Open source & ad-free | ✅ GPL | ❌ paid | ⚠️ ads | ⚠️ IAP | ✅ **Apache-2.0** |
Expand Down Expand Up @@ -63,22 +63,21 @@ Three runtimes are bundled inside the APK: a natively cross-compiled CPython 3.1
└──────────────────┬──────────────────────────┘
│ JNI (jobject callbacks)
┌──────────────────▼──────────────────────────┐
│ RuntimeRegistry │
│ Python: NativeEngine + pybridge.c (JNI) │
│ JavaScript: Rhino · Lua: LuaJ │
│ pdb debugger · streaming stdout/stderr │
│ timeout · stdin · real PTY (forkpty) │
│ Main process │
│ RuntimeRegistry · RemoteNativeEngine proxy │
│ JavaScript: Rhino · Lua: LuaJ │
│ pdb · streaming output · PTY (forkpty) │
└──────────────────┬──────────────────────────┘
│ dlopen + sys.path
│ Messenger + JSON
┌──────────────────▼──────────────────────────┐
│ jniLibs/<abi> (arm64-v8a / x86_64) │
│ :engine process │
│ NativeEngine + pybridge.c (JNI) │
│ libpython3.13.so · libpybridge.so │
│ libptybridge.so · C extensions │
│ assets/python-stdlib.zip (pure-Python std) │
│ C extensions · assets/python-stdlib.zip │
└─────────────────────────────────────────────┘
```

**Core trade-off**: no external native toolchain dependency, no cloud requirement. CPython 3.13 is cross-compiled with the NDK for both `arm64-v8a` and `x86_64`; JavaScript and Lua use pure-Java Rhino/LuaJ. The terminal now has a real `forkpty` backend, but its UI is line-oriented (not an ANSI terminal emulator); Java/Kotlin/TypeScript plus 14 other languages are editing-only.
**Core trade-off**: no external native toolchain dependency, no cloud requirement. CPython 3.13 is cross-compiled with the NDK for both `arm64-v8a` and `x86_64`; JavaScript and Lua use pure-Java Rhino/LuaJ. Python runs in a dedicated `:engine` process, so a stuck native call can be killed without taking the editor down. The terminal has a real `forkpty` backend and a local xterm.js ANSI screen. Java/Kotlin/TypeScript plus 14 other languages are editing-only.

---

Expand Down Expand Up @@ -107,12 +106,21 @@ Three runtimes are bundled inside the APK: a natively cross-compiled CPython 3.1
- **Python pdb debugger**: real stdlib `pdb`; breakpoints, next/step/continue, `p locals()`, stack, quit; quick-action bar in output panel
- **Offline by design**: no language server process, no model download, hard caps at 300 `.py` files / 512KB per file

### Trusted mobile IDE foundation (0.1.0)
- **Python engine isolation**: Python runs in `android:process=":engine"`; the main process holds only a Messenger proxy. The output panel's **重启引擎** action kills and rebinds only the engine process, preserving unsaved editor buffers, Git and terminal state
- **Git review loop**: per-file stage / unstage, stage-all, commit-staged-only, and a diff dialog (working tree vs index, untracked files as all-added); 200KB output cap with bounded streaming so a 100MB log does not OOM
- **Bounded previews**: Markdown/HTML preview is capped at 512K characters with a visible banner; the editor buffer itself is untouched
- **File-tree truncation banner**: 10,000-node budget is no longer silent
- **Async encrypted settings**: sensitive fields (AI key, Git remote token, MCP endpoint) coalesce on a single background writer; `onStop`/`onCleared` flush the last version
- **Pure-Python package import**: `.whl` / `.zip` with `dist-info` metadata, native `.so/.pyd/.dll/.wasm` rejection, Zip-Slip guards, and reverse-order rollback on failure
- **Quality gate**: 171 JVM/Robolectric tests, `lintRelease` 0 errors, Compose smoke for file-tree truncation, Git diff and fontScale 2.0

### Project migration & process teardown (0.0.34)
- **Clone from Git**: `GitManager.cloneInto` uses JGit to clone an HTTPS remote into a new project; credentials go through `UsernamePasswordCredentialsProvider` and are never written into `.git/config`, and the target must be absent or empty
- **Project zip import/export**: stream-based zip import with Zip Slip / absolute path / Windows drive rejection, 10,000-entry, 48MB-per-file and 256MB-total caps; a single top-level folder is promoted to the project root; export skips `.git`, `build`, `node_modules` and caches and caps at 256MB
- **Async-signal-safe PTY child**: `ptybridge.c` now builds `argv`/`envp` before `forkpty`; the child only calls `chdir` + `execve`, with no `setenv` after fork
- **Command process groups**: `ProcessGroup` writes the shell PID to a temp file, enters a new session via `/system/bin/setsid`, and sends `SIGTERM`/`SIGKILL` to the negative PID; when `setsid` is absent it falls back to the old direct-child behavior
- **Engine-stuck escape hatch**: if the native engine is still busy 8s after Stop, the output panel shows a **重启应用** action that saves the current file, relaunches via `AlarmManager`, then kills the process; this is recovery, not true interpreter process isolation
- **Engine-stuck escape hatch (historical)**: 0.0.34 detected a busy engine 8s after Stop and offered **重启应用**; 0.1.0 replaced this with true `:engine` process isolation and **重启引擎**

### Lifecycle & memory cleanup (0.0.33)
- **ViewModel teardown**: `onCleared` cancels AI/Agent/model jobs, stops the PTY, and releases the native Python engine + RuntimeRegistry instead of leaving them alive after the Activity is reclaimed
Expand All @@ -123,7 +131,7 @@ Three runtimes are bundled inside the APK: a natively cross-compiled CPython 3.1
### Packaging cleanup (0.0.32)
- **Stale toolchain note removed**: the 441MB `usrtar.zip` instructions are gone; the app uses the bundled native CPython runtime and JGit, not the retired Termux bundle
- **Stdlib slimmed**: CPython `test`, `idlelib` and `turtledemo` are excluded from `python-stdlib.zip`; 1740 files / 7.1MB removed, all runtime modules and 53 C extensions untouched
- **Git wording fixed**: 0.0.32 aligned docs and site to init / commit / push / pull; 0.0.34 adds HTTPS clone, so the current list is init / commit / push / pull / clone
- **Git wording fixed**: 0.0.32 aligned docs and site to init / commit / push / pull; 0.0.34 added HTTPS clone; 0.1.0 adds stage / unstage / stage-all / commit-staged / diff

### Data safety & lifecycle (0.0.31)
- **No silent data loss**: with auto-save off, switching files/tabs/projects now asks Save / Discard / Cancel instead of overwriting the dirty buffer
Expand Down Expand Up @@ -155,7 +163,7 @@ Three runtimes are bundled inside the APK: a natively cross-compiled CPython 3.1
- **Multi-project switching** (long-press to delete) · **4 Python templates**
- **JGit Git integration**: init / commit / push / pull / clone (HTTPS), pure Java, offline where possible
- **SAF import/export** (no storage permission needed): project zip in/out with traversal and size guards
- **Offline package management**: inspect built-in modules / import local .whl
- **Offline package management**: inspect built-in modules / import pure-Python `.whl` or `.zip`; native wheels are rejected before writing

### See results
- **Markdown / HTML split-pane live preview**, debounced refresh
Expand Down Expand Up @@ -196,7 +204,7 @@ The native runtime (`libpython3.13.so` + C extensions + pure-Python stdlib zip,

- **Pure-Python stdlib**: `assets/python-stdlib.zip` (extracted to the app's private dir, then added to `sys.path`)
- **C extension modules**: math, json, _random, _datetime, _socket, _ssl, _sqlite3, _ctypes, zlib, binascii etc. (`jniLibs/arm64-v8a` / `x86_64`)
- **numpy / pandas / matplotlib / pillow are NOT preinstalled** — `import numpy` shows a missing-module hint. Offline installation of third-party wheels is planned for a later release.
- **numpy / pandas / matplotlib / pillow are NOT preinstalled** — `import numpy` shows a missing-module hint. Pure-Python wheels can be imported offline; wheels containing Android-native `.so` files are rejected because the bundled CPython does not ship their ABI dependencies.

---

Expand Down Expand Up @@ -224,8 +232,10 @@ The native runtime (`libpython3.13.so` + C extensions + pure-Python stdlib zip,
| Python runtime | ✅ Full (native CPython 3.13, arm64 + x86_64) |
| Java runtime | ❌ JVM not yet integrated (editing/highlighting only) |
| Performance | ✅ Native execution, no WASM sandbox overhead |
| Sci-stack libraries | ⚠️ numpy/pandas/matplotlib not preinstalled; offline import planned |
| pip online install | ❌ Offline-first; extra libraries via manual wheel import |
| Sci-stack libraries | ⚠️ numpy/pandas/matplotlib not preinstalled; pure-Python wheels only |
| pip online install | ❌ Offline-first; extra pure-Python libraries via manual `.whl`/`.zip` import |
| Gradle/Java/Kotlin build | ❌ Not in 0.1.0; no JVM/Gradle toolchain bundled |
| Full LSP | ❌ Symbol index + static completion, not a language server |

---

Expand Down
13 changes: 11 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ android {
applicationId = "com.devterminal"
minSdk = libs.versions.minSdk.get().toInt()
targetSdk = libs.versions.targetSdk.get().toInt()
versionCode = 34
versionName = "0.0.34"
versionCode = 40
versionName = "0.1.0"
vectorDrawables { useSupportLibrary = true }
// 原生 CPython 引擎:同时打 arm64 与 x86_64(后者用于模拟器/ChromeOS)
ndk { abiFilters += listOf("arm64-v8a", "x86_64") }
Expand Down Expand Up @@ -80,6 +80,10 @@ android {
buildConfig = true
}

testOptions {
unitTests.isIncludeAndroidResources = true
}

packaging {
resources {
// SoraEditor 为 LGPL,排除其许可文件避免打包冲突(许可随源码提供)
Expand Down Expand Up @@ -142,4 +146,9 @@ dependencies {
testImplementation(libs.junit)
// Android 的 org.json 在 JVM 单测里是 stub;补一份真实实现给 AgentDecisionParser 测试
testImplementation("org.json:json:20240303")
testImplementation(libs.robolectric)
testImplementation(libs.androidx.test.core)
testImplementation(libs.androidx.test.ext.junit)
testImplementation(libs.compose.ui.test.junit4)
testImplementation(libs.compose.ui.test.manifest)
}
10 changes: 10 additions & 0 deletions app/src/debug/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 仅 debug 构建:Robolectric Compose 测试需要一个可解析的宿主 Activity。
正式 release 不包含此文件。 -->
<application>
<activity
android:name="androidx.activity.ComponentActivity"
android:exported="false" />
</application>
</manifest>
5 changes: 5 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
</intent-filter>
</activity>

<service
android:name=".engine.EngineHostService"
android:exported="false"
android:process=":engine" />

<service
android:name=".engine.ExecutionService"
android:exported="false"
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/com/devterminal/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ class MainActivity : ComponentActivity() {

private val viewModel: EditorViewModel by viewModels()

override fun onStop() {
// 设置页的敏感字段是合并后台写;进后台时主动落盘,别等进程被回收。
runCatching { viewModel.flushSettings() }
super.onStop()
}

override fun onCreate(savedInstanceState: Bundle?) {
// 启动屏:在 super.onCreate 之前安装,图标在深色背景上展示
installSplashScreen()
Expand Down
Loading
Loading