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
5 changes: 5 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version: '22'
- uses: pnpm/action-setup@v4
with:
version: 10.15.0
- run: pnpm install --frozen-lockfile
- run: pnpm run prepare:assets
- uses: actions/setup-java@v5
with:
distribution: temurin
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,6 @@ src/apps/mobile/android/.kotlin/
/docs/superpowers/

AGENTS.override.md

# Bundled Local GenUI documents projected by prepare:assets.
/src/shared/generative-ui/generated/mobile/
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"harmony:genui-runtime": "pnpm run prepare:design && node scripts/build-harmony-genui-runtime.mjs",
"harmony:genui-runtime:check": "node scripts/build-harmony-genui-runtime.mjs --check",
"prepare:design": "pnpm --filter @openbitfun/design-tokens run build && pnpm --filter @openbitfun/theme-openbitfun run build",
"prepare:assets": "pnpm run prepare:design && node scripts/build-mobile-terminal.mjs --harmony && node src/apps/mobile/miniapps/generate.cjs android && node src/apps/mobile/miniapps/generate.cjs ios",
"prepare:assets": "pnpm run prepare:design && node scripts/build-mobile-terminal.mjs --harmony && node src/apps/mobile/miniapps/generate.cjs android && node src/apps/mobile/miniapps/generate.cjs ios && node scripts/build-harmony-genui-runtime.mjs --stage-mobile-document",
"harmony:architecture": "node scripts/check-harmonyos-architecture.mjs",
"mobile:architecture": "node scripts/check-mobile-architecture.mjs && node --test scripts/mobile-client-build.contract.test.mjs",
"mobile:ui:generate": "node scripts/mobile-ui-design-system.mjs",
Expand Down
13 changes: 12 additions & 1 deletion scripts/build-harmony-genui-runtime.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* under rawfile/genui/runtime is generated and verified by the HAP build.
*/
import { execFileSync } from 'node:child_process';
import { copyFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
import { copyFileSync, cpSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { createRequire } from 'node:module';
Expand Down Expand Up @@ -54,4 +54,15 @@ if (process.argv.includes('--check')) {
const manifest = JSON.parse(readFileSync(manifestPath, 'utf8'));
writeFileSync(buildInfoPath, JSON.stringify({ catalogHash: manifest.catalogHash, rendererRevision: manifest.rendererRevision }, null, 2) + '\n');
console.log('Built Harmony Local GenUI runtime for ' + manifest.rendererRevision);
if (process.argv.includes('--stage-mobile-document')) {
// Native shells package the existing product-owned OpenUI document. They
// retain their own views, permission boundaries and WebView lifecycle.
const output = path.join(root, 'src/shared/generative-ui/generated/mobile');
mkdirSync(output, { recursive: true });
cpSync(runtimeDir, path.join(output, 'genui/runtime'), { recursive: true });
writeFileSync(path.join(output, 'genui/runtime/index.html'), HTML.replace('img-src data: blob:', 'img-src data: blob: openbitfun-genui:'));
for (const file of ['runtime-manifest.json', 'harmony-prompt.txt', 'local-tool-schema.json', 'catalog.json']) {
copyFileSync(path.join(genuiDir, file), path.join(output, 'genui', file));
}
}
}
5 changes: 4 additions & 1 deletion scripts/mobile-ui-design-system.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,10 @@ function renderSharedLayoutTokens(contract) {
const breakpoints = Object.entries(contract.breakpoints)
.map(([name, value]) => ` public const val ${pascal(name)}: Int = ${value}`)
.join('\n');
return `// Generated by scripts/mobile-ui-design-system.mjs. Do not edit.\npackage com.openbitfun.mobile.core.feature.layout.generated\n\npublic object MobileDesignBreakpoints {\n${breakpoints}\n}\n`;
const settingsPanel = ['settings_wide_panel_width', 'settings_wide_panel_height']
.map((name) => ` const val ${pascal(name)}: Int = ${contract.geometry[name]}`)
.join('\n');
return `// Generated by scripts/mobile-ui-design-system.mjs. Do not edit.\npackage com.openbitfun.mobile.core.feature.layout.generated\n\npublic object MobileDesignBreakpoints {\n${breakpoints}\n}\n\ninternal object MobileDesignLayoutGeometry {\n${settingsPanel}\n}\n`;
}

function renderPreviewData(tokenContract, componentContract, scenarioContract) {
Expand Down
7 changes: 5 additions & 2 deletions src/apps/mobile/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ This directory contains the native mobile product surfaces for OpenBitFun:

The mobile apps are remote controllers: OpenBitFun account sign-in and the device
directory select a desktop or CLI host that owns configuration and Agent Runtime
execution. Phones submit tasks and display results; they do not synchronize model
configuration or execute agents locally.
execution. Phones submit remote tasks and display results. The separate **Create mini
apps** flow uses a provider configured on the phone to generate local OpenUI
documents. Its sessions, provider profiles, and generated app state are independent
of the selected remote device.

The official Relay needs no user deployment. Use the same login method and
account on the phone and host; GitHub and email-code accounts are independent.
Expand Down Expand Up @@ -81,6 +83,7 @@ metadata, execution-mode IDs, speech draft merging, and completion observation i
| Next-input suggestions | Android, iOS and HarmonyOS show the host's suggestion above an empty, idle composer; tapping fills and focuses the editor without sending | Uses the existing host session stream. Hints retain their exact text and retire on newer turns, session changes or host restarts. Older hosts simply show no hint; no new Relay API or migration is needed. |
| Plans | Legacy CreatePlan, structured plans and `.plan.md` writes show a plan card with file preview and Build | Build requires `plan_build_v1`, a completed plan tool and an idle connected session. Paths remain remote; the mobile app never runs the plan locally. |
| Offline Mini Apps | Gomoku, Regex Playground and Daily Divination open from welcome and sidebar without login | Product-owned sources are bundled by `miniapps/generate.cjs`; native WebView hosts expose only per-app allowlisted storage and clipboard. No network, Node or shell bridge. |
| Local GenUI | The sidebar opens local creation sessions, direct model generation and the bundled OpenUI runtime | The current per-platform capability gaps and simulator procedure are in the [native parity audit](docs/native-parity-audit.md). |
| Code preview | Native lexical colors, line numbers and referenced-line backgrounds | Both apps use the core-feature highlighter with native theme tokens; large files retain its bounded plain-text fallback. |
| Account profile | Public GitHub login and avatar replace the numeric-ID placeholder | The immutable Relay user ID still authorizes devices. Display metadata uses a separate encrypted 24-hour cache; offline refreshes preserve credentials and cached display. |
| Task completion | Notify for a previously observed successful remote turn while backgrounded | Identity includes target, session and turn. Replayed, failed and cancelled turns do not notify. These are local notifications, not server push. iOS observes within its OS background-task allowance; Android observes while the controller process remains alive. Neither promises notification after process termination. |
Expand Down
3 changes: 3 additions & 0 deletions src/apps/mobile/android/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ JAVA_HOME='/Applications/Android Studio.app/Contents/jbr/Contents/Home' ./gradle

## Focused Verification

Run `pnpm run prepare:assets` from the repository root to stage the local GenUI
document before building a clean checkout or after its source changes.

Run commands from `src/apps/mobile/android` unless a command says otherwise.

```bash
Expand Down
12 changes: 11 additions & 1 deletion src/apps/mobile/android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ val allowUnsignedRelease = providers.gradleProperty("allowUnsignedRelease")
.orElse(false)
.get()
android {
sourceSets.getByName("main").assets.srcDir(file("../../../../shared/terminal/webview/generated"))
sourceSets.getByName("main").assets.apply {
srcDir(file("../../../../shared/terminal/webview/generated"))
srcDir(file("../../../../shared/generative-ui/generated/mobile"))
}
namespace = "com.openbitfun.mobile.app"
compileSdk = libs.versions.androidCompileSdk.get().toInt()

Expand Down Expand Up @@ -85,6 +88,13 @@ dependencies {
implementation(libs.androidx.lifecycle.viewmodel.compose)
implementation(libs.androidx.lifecycle.runtime.compose)
implementation(libs.androidx.window)
implementation(libs.androidx.camera.camera2)
implementation(libs.androidx.camera.lifecycle)
implementation(libs.androidx.camera.view)
implementation(libs.mlkit.pose)
implementation(libs.mlkit.document.scanner)
implementation(libs.mlkit.code.scanner)
implementation(libs.zxing.core)

testImplementation("junit:junit:4.13.2")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
package com.openbitfun.mobile.app

import android.content.res.Configuration
import android.graphics.Bitmap
import androidx.compose.ui.Modifier
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalContext
import com.openbitfun.mobile.core.feature.session.RemoteSessionIntent
import com.openbitfun.mobile.core.feature.session.RemoteSessionFailureReason
import com.openbitfun.mobile.app.ui.chat.CONVERSATION_LOADING_TEST_TAG
import androidx.compose.ui.test.assertCountEquals
import androidx.compose.ui.test.assertHeightIsEqualTo
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.assertIsNotEnabled
import androidx.compose.ui.test.assertWidthIsEqualTo
import androidx.compose.ui.test.junit4.v2.createComposeRule
import androidx.compose.ui.test.onAllNodesWithText
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performScrollTo
import androidx.compose.ui.unit.dp
import androidx.test.platform.app.InstrumentationRegistry
import com.openbitfun.mobile.app.platform.rememberWindowMetrics
import com.openbitfun.mobile.app.ui.common.AdaptiveModalSurface
import com.openbitfun.mobile.app.ui.remote.CONNECT_ACCOUNT_DEVICE_REFRESH_TEST_TAG
import com.openbitfun.mobile.app.ui.remote.CONNECT_ACCOUNT_DEVICE_ROW_TEST_TAG_PREFIX
import com.openbitfun.mobile.app.ui.remote.ConnectAccountDeviceScreen
Expand All @@ -21,10 +35,15 @@ import com.openbitfun.mobile.app.ui.theme.OpenBitFunTheme
import com.openbitfun.mobile.core.feature.account.AccountDeviceUi
import com.openbitfun.mobile.core.feature.account.AccountUiState
import com.openbitfun.mobile.core.feature.connection.ConnectionPhase
import com.openbitfun.mobile.core.feature.layout.AdaptiveLayoutInput
import com.openbitfun.mobile.core.feature.layout.SettingsPlacement
import com.openbitfun.mobile.core.feature.layout.SettingsPlacementMode
import com.openbitfun.mobile.core.feature.layout.SettingsPlacementPolicy
import com.openbitfun.mobile.core.feature.layout.SettingsSheetKind
import com.openbitfun.mobile.core.feature.session.RemoteSessionUiState
import com.openbitfun.mobile.core.feature.workspace.RemoteWorkspaceUiState
import java.io.File
import java.util.Locale
import org.junit.Rule
import org.junit.Test
import org.junit.Assert.assertEquals
Expand All @@ -33,6 +52,93 @@ class AccountRemoteScreenTest {
@get:Rule
val composeRule = createComposeRule()

@Test
fun accountPickerKeepsAllDeviceRowsInOneScrollSurface() {
val account = AccountUiState.Ready(
userId = "fixture", username = "octocat",
devices = (1..9).map { index ->
AccountDeviceUi("account-desktop-$index", "Account desktop $index", index % 3 != 0, index.toLong())
},
selectedDeviceId = "account-desktop-1", selectedDeviceName = "Account desktop 1",
)
val switching = mutableStateOf<String?>(null)
val failed = mutableStateOf(false)
val directory = mutableStateOf(account)
composeRule.setContent {
val context = LocalContext.current
val configuration = LocalConfiguration.current
val chinese = remember(configuration) {
Configuration(configuration).apply { setLocale(Locale.SIMPLIFIED_CHINESE) }
}
val localized = remember(context, chinese) { context.createConfigurationContext(chinese) }
CompositionLocalProvider(LocalConfiguration provides chinese, LocalContext provides localized) {
OpenBitFunTheme(dark = false) {
val window = rememberWindowMetrics()
val expanded = window.widthDp >= 600
val placement = SettingsPlacementPolicy.resolve(AdaptiveLayoutInput(
viewportWidth = window.widthDp, viewportHeight = window.heightDp,
isFolded = !expanded, isExpandedFoldable = expanded, isHoverOperate = false,
wideLayoutMatched = expanded, verticalCreases = emptyList(),
horizontalCreases = emptyList(), isRtl = false,
), SettingsSheetKind.CONNECT)
AdaptiveModalSurface(
visible = true, placement = placement, onDismissRequest = {},
edgeToEdgeContent = true, connectChrome = true,
) { modifier ->
ConnectAccountDeviceScreen(
state = directory.value, onBack = {}, onRefresh = { failed.value = false },
onSelect = { switching.value = it }, modifier = modifier, connected = true,
switchingDeviceId = switching.value, connectionFailed = failed.value,
)
}
}
}
}
val title = composeRule.onAllNodesWithText("选择桌面设备")
composeRule.waitUntil(5_000) {
composeRule.onAllNodesWithText("选择桌面设备").fetchSemanticsNodes().isNotEmpty()
}
title.assertCountEquals(1)[0].assertIsDisplayed()
val instrument = InstrumentationRegistry.getInstrumentation()
instrument.uiAutomation.waitForIdle(400, 4000)
val bitmap = instrument.uiAutomation.takeScreenshot()
val suffix = if (bitmap.width > 1800) "expanded" else "compact"
if (suffix == "expanded") {
composeRule.onNodeWithTag("connect-centered-panel")
.assertWidthIsEqualTo(480.dp).assertHeightIsEqualTo(560.dp)
}
File(instrument.targetContext.getExternalFilesDir(null), "connect-account-$suffix.png").outputStream().use {
bitmap.compress(Bitmap.CompressFormat.PNG, 100, it)
}
bitmap.recycle()
fun row(index: Int) = composeRule.onNodeWithTag(CONNECT_ACCOUNT_DEVICE_ROW_TEST_TAG_PREFIX + "account-desktop-$index")
composeRule.runOnIdle {
directory.value = account.copy(devices = account.devices.map {
if (it.id == "account-desktop-5") it.copy(compatible = false) else it
})
}
row(5).performScrollTo().assertIsNotEnabled()
composeRule.onNodeWithText("客户端版本不兼容,无法互控。").assertIsDisplayed()
val blocked = instrument.uiAutomation.takeScreenshot()
File(instrument.targetContext.getExternalFilesDir(null), "connect-incompatible-$suffix.png").outputStream().use {
blocked.compress(Bitmap.CompressFormat.PNG, 100, it)
}
blocked.recycle()
row(9).performScrollTo().assertIsDisplayed()
title.assertCountEquals(1)[0].assertIsDisplayed()
row(3).performScrollTo().assertIsNotEnabled()
row(2).performScrollTo().performClick()
composeRule.onAllNodesWithText("正在连接").assertCountEquals(1)
row(1).assertIsNotEnabled()
composeRule.runOnIdle {
switching.value = null
failed.value = true
}
composeRule.onNodeWithTag(CONNECT_ACCOUNT_DEVICE_REFRESH_TEST_TAG).performScrollTo()
composeRule.onNodeWithText("重试").assertIsDisplayed()
row(2).assertIsDisplayed()
}

@Test
fun aSelectedAccountDeviceBypassesThePairingForm() {
composeRule.setContent {
Expand Down Expand Up @@ -135,14 +241,14 @@ class AccountRemoteScreenTest {
composeRule.onNodeWithText(testString(R.string.connect_account_devices_title)).assertIsDisplayed()
composeRule.onNodeWithTag(CONNECT_ACCOUNT_DEVICE_REFRESH_TEST_TAG).performClick()
composeRule.onNodeWithTag(CONNECT_ACCOUNT_DEVICE_ROW_TEST_TAG_PREFIX + "desk-1").performClick()
composeRule.onNodeWithTag(CONNECT_ACCOUNT_DEVICE_ROW_TEST_TAG_PREFIX + "desk-2").performClick()
composeRule.onNodeWithTag(CONNECT_ACCOUNT_DEVICE_ROW_TEST_TAG_PREFIX + "desk-2").assertIsNotEnabled()

assertEquals(1, refreshes)
assertEquals("desk-1", selected)
}

@Test
fun aSelectedOfflineAccountDeviceCanReconnect() {
fun thePreviousOfflineDeviceRemainsVisibleAndCannotBeSelectedFromThePicker() {
var selected = ""
composeRule.setContent {
OpenBitFunTheme(dark = false) {
Expand All @@ -165,8 +271,9 @@ class AccountRemoteScreenTest {
}
}

composeRule.onNodeWithTag(CONNECT_ACCOUNT_DEVICE_ROW_TEST_TAG_PREFIX + "desk-2").performClick()
composeRule.onNodeWithTag(CONNECT_ACCOUNT_DEVICE_ROW_TEST_TAG_PREFIX + "desk-2").assertIsNotEnabled()
composeRule.onNodeWithText(testString(R.string.account_offline), substring = true).assertIsDisplayed()

assertEquals("desk-2", selected)
assertEquals("", selected)
}
}
Loading
Loading