diff --git a/.gitignore b/.gitignore index b6eeabb..7c00804 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,10 @@ node_modules/ # Build output dist/ runners/*/dist/ +apps/android/.gradle/ +apps/android/build/ +apps/android/app/build/ +apps/android/local.properties # Local data & auth store/ diff --git a/apps/android/.gitignore b/apps/android/.gitignore new file mode 100644 index 0000000..bf9b3aa --- /dev/null +++ b/apps/android/.gitignore @@ -0,0 +1,11 @@ +.gradle/ +build/ +local.properties +*.apk +*.ap_ +*.aab +*.iml +.idea/ +.cxx/ +captures/ +app/build/ diff --git a/apps/android/README.md b/apps/android/README.md new file mode 100644 index 0000000..8277b94 --- /dev/null +++ b/apps/android/README.md @@ -0,0 +1,54 @@ +# EJClaw Android + +Personal Android companion for EJClaw. This is a thin client: EJClaw still runs +on the existing Bun service, and the Android app talks to the dashboard API. + +## Build + +```bash +cd apps/android +cp local.properties.example local.properties +./gradlew assembleDebug +``` + +The debug APK is written to: + +```text +apps/android/app/build/outputs/apk/debug/app-debug.apk +``` + +Install with: + +```bash +adb install -r apps/android/app/build/outputs/apk/debug/app-debug.apk +``` + +## Runtime Setup + +- Keep EJClaw behind Tailscale, VPN, SSH tunnel, or localhost forwarding. +- Base URL defaults to `http://100.101.210.95:8734`. +- If `WEB_DASHBOARD_TOKEN` is enabled on the server, paste the same token into + the app. It sends `Authorization: Bearer `. + +## Current MVP + +- Connect to `/api/health`. +- Load rooms from `/api/rooms-timeline`. +- Open a room timeline from `/api/rooms/:jid/timeline`. +- Send text through `/api/rooms/:jid/messages`. +- Keep the Ray-Ban Display integration isolated behind `DisplaySurface`. + +## Meta DAT + +The default APK does not link the Meta DAT SDK yet. Meta's Android DAT SDK is +distributed through GitHub Packages and needs Developer Preview access, a +GitHub package token, and a Wearables Developer Center application id. + +The integration point is already present: + +```text +app/src/main/java/com/ejclaw/android/display/ +``` + +After DAT access is ready, replace `MetaDatDisplaySurface` with SDK calls and +keep `NoopDisplaySurface` for phone-only testing. diff --git a/apps/android/app/build.gradle.kts b/apps/android/app/build.gradle.kts new file mode 100644 index 0000000..4fd992b --- /dev/null +++ b/apps/android/app/build.gradle.kts @@ -0,0 +1,26 @@ +plugins { + id("com.android.application") + id("org.jetbrains.kotlin.android") +} + +android { + namespace = "com.ejclaw.android" + compileSdk = 36 + + defaultConfig { + applicationId = "com.ejclaw.android" + minSdk = 26 + targetSdk = 36 + versionCode = 1 + versionName = "0.1.0" + } + + compileOptions { + sourceCompatibility = JavaVersion.VERSION_21 + targetCompatibility = JavaVersion.VERSION_21 + } +} + +kotlin { + jvmToolchain(21) +} diff --git a/apps/android/app/src/main/AndroidManifest.xml b/apps/android/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..a8e9362 --- /dev/null +++ b/apps/android/app/src/main/AndroidManifest.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + diff --git a/apps/android/app/src/main/java/com/ejclaw/android/MainActivity.kt b/apps/android/app/src/main/java/com/ejclaw/android/MainActivity.kt new file mode 100644 index 0000000..35c53c2 --- /dev/null +++ b/apps/android/app/src/main/java/com/ejclaw/android/MainActivity.kt @@ -0,0 +1,166 @@ +package com.ejclaw.android + +import android.app.Activity +import android.os.Bundle +import android.widget.Toast +import com.ejclaw.android.api.EJClawApi +import com.ejclaw.android.display.DisplayBridge +import com.ejclaw.android.model.RoomActivity +import com.ejclaw.android.model.RoomSummary +import com.ejclaw.android.ui.EJClawView +import java.util.concurrent.Executors + +class MainActivity : Activity() { + private val executor = Executors.newSingleThreadExecutor() + private val displayBridge = DisplayBridge() + private lateinit var view: EJClawView + private var api: EJClawApi? = null + private var selectedRoom: RoomSummary? = null + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + view = EJClawView(this) + setContentView(view.root) + loadPrefs() + bindActions() + } + + override fun onDestroy() { + executor.shutdownNow() + super.onDestroy() + } + + private fun bindActions() { + view.connectButton.setOnClickListener { connectAndLoadRooms() } + view.refreshButton.setOnClickListener { loadRooms() } + view.sendButton.setOnClickListener { sendMessage() } + view.roomsList.setOnItemClickListener { _, _, position, _ -> + selectedRoom = view.roomsAdapter.getItem(position) + selectedRoom?.let { loadRoom(it) } + } + } + + private fun loadPrefs() { + val prefs = getPreferences(MODE_PRIVATE) + view.baseUrlInput.setText(prefs.getString("baseUrl", "http://100.101.210.95:8734")) + view.tokenInput.setText(prefs.getString("token", "")) + view.nicknameInput.setText(prefs.getString("nickname", "android")) + } + + private fun savePrefs() { + getPreferences(MODE_PRIVATE).edit() + .putString("baseUrl", view.baseUrlInput.text.toString().trim()) + .putString("token", view.tokenInput.text.toString()) + .putString("nickname", view.nicknameInput.text.toString().trim()) + .apply() + } + + private fun connectAndLoadRooms() { + savePrefs() + api = EJClawApi( + view.baseUrlInput.text.toString(), + view.tokenInput.text.toString(), + ) + runNetwork("Connecting") { + requireNotNull(api).health() + requireNotNull(api).rooms() + }.onSuccess { rooms -> + view.statusView.text = "Connected: ${rooms.size} rooms" + replaceRooms(rooms) + } + } + + private fun loadRooms() { + runNetwork("Loading rooms") { + requireNotNull(api ?: createApi()).rooms() + }.onSuccess { rooms -> + view.statusView.text = "Loaded: ${rooms.size} rooms" + replaceRooms(rooms) + } + } + + private fun loadRoom(room: RoomSummary) { + runNetwork("Loading ${room.name}") { + requireNotNull(api ?: createApi()).roomTimeline(room.jid) + }.onSuccess { activity -> + renderRoom(activity) + displayBridge.updateRoom(activity.summary.name, activity.summary.status, null) + displayBridge.showLatest(activity.summary.name, activity.summary.latestText) + } + } + + private fun sendMessage() { + val room = selectedRoom ?: return toast("Select a room first") + val text = view.messageInput.text.toString().trim() + if (text.isBlank()) return + runNetwork("Sending") { + requireNotNull(api ?: createApi()).sendRoomMessage( + room.jid, + text, + view.nicknameInput.text.toString(), + ) + requireNotNull(api).roomTimeline(room.jid) + }.onSuccess { activity -> + view.messageInput.setText("") + renderRoom(activity) + } + } + + private fun createApi(): EJClawApi { + savePrefs() + val next = EJClawApi(view.baseUrlInput.text.toString(), view.tokenInput.text.toString()) + api = next + return next + } + + private fun replaceRooms(rooms: List) { + view.roomsAdapter.clear() + view.roomsAdapter.addAll(rooms) + view.roomsAdapter.notifyDataSetChanged() + } + + private fun renderRoom(activity: RoomActivity) { + val lines = activity.messages.takeLast(40).joinToString("\n\n") { message -> + val marker = if (message.fromMe) "me" else message.senderName.ifBlank { "agent" } + "[$marker] ${message.content}" + } + view.threadView.text = lines.ifBlank { "No messages" } + view.statusView.text = "${activity.summary.name}: ${activity.summary.status}" + } + + private fun runNetwork(label: String, block: () -> T): PendingUi { + view.statusView.text = label + val pending = PendingUi() + executor.execute { + try { + val result = block() + runOnUiThread { pending.succeed(result) } + } catch (error: Throwable) { + runOnUiThread { + view.statusView.text = "Error: ${error.message}" + toast(error.message ?: "Request failed") + } + } + } + return pending + } + + private fun toast(message: String) { + Toast.makeText(this, message, Toast.LENGTH_SHORT).show() + } +} + +private class PendingUi { + private var callback: ((T) -> Unit)? = null + private var result: T? = null + + fun onSuccess(next: (T) -> Unit) { + callback = next + result?.let(next) + } + + fun succeed(value: T) { + result = value + callback?.invoke(value) + } +} diff --git a/apps/android/app/src/main/java/com/ejclaw/android/api/EJClawApi.kt b/apps/android/app/src/main/java/com/ejclaw/android/api/EJClawApi.kt new file mode 100644 index 0000000..ff4f241 --- /dev/null +++ b/apps/android/app/src/main/java/com/ejclaw/android/api/EJClawApi.kt @@ -0,0 +1,104 @@ +package com.ejclaw.android.api + +import com.ejclaw.android.model.RoomActivity +import com.ejclaw.android.model.RoomMessage +import com.ejclaw.android.model.RoomSummary +import java.io.BufferedReader +import java.io.InputStreamReader +import java.net.HttpURLConnection +import java.net.URL +import java.util.UUID +import org.json.JSONObject + +class EJClawApi( + baseUrl: String, + private val token: String, +) { + private val baseUrl = baseUrl.trim().trimEnd('/') + + fun health(): Boolean { + val payload = request("GET", "/api/health") + return JSONObject(payload).optBoolean("ok", false) + } + + fun rooms(): List { + val payload = request("GET", "/api/rooms-timeline") + val root = JSONObject(payload) + return root.keys().asSequence().mapNotNull { key -> + root.optJSONObject(key)?.let { parseRoomSummary(it) } + }.sortedBy { it.name.lowercase() }.toList() + } + + fun roomTimeline(jid: String): RoomActivity { + val payload = request("GET", "/api/rooms/${encode(jid)}/timeline") + val room = JSONObject(payload) + val messages = room.optJSONArray("messages") ?: return RoomActivity(parseRoomSummary(room), emptyList()) + return RoomActivity( + parseRoomSummary(room), + (0 until messages.length()).mapNotNull { index -> + messages.optJSONObject(index)?.let { message -> + RoomMessage( + senderName = message.optString("senderName", message.optString("sender", "")), + content = message.optString("content", ""), + timestamp = message.optString("timestamp", ""), + fromMe = message.optBoolean("isFromMe", false), + ) + } + }, + ) + } + + fun sendRoomMessage(jid: String, text: String, nickname: String): Boolean { + val body = JSONObject() + .put("requestId", UUID.randomUUID().toString()) + .put("text", text) + .put("nickname", nickname.ifBlank { "android" }) + val payload = request("POST", "/api/rooms/${encode(jid)}/messages", body.toString()) + return JSONObject(payload).optBoolean("ok", false) + } + + private fun parseRoomSummary(room: JSONObject): RoomSummary { + val messages = room.optJSONArray("messages") + val latest = if (messages != null && messages.length() > 0) { + messages.optJSONObject(messages.length() - 1)?.optString("content", "") ?: "" + } else { + "" + } + return RoomSummary( + jid = room.optString("jid"), + name = room.optString("name", room.optString("jid")), + status = room.optString("status", "unknown"), + latestText = latest.take(120), + ) + } + + private fun request(method: String, path: String, body: String? = null): String { + val connection = URL("$baseUrl$path").openConnection() as HttpURLConnection + connection.requestMethod = method + connection.connectTimeout = 8_000 + connection.readTimeout = 12_000 + connection.setRequestProperty("Accept", "application/json") + if (token.isNotBlank()) connection.setRequestProperty("Authorization", "Bearer $token") + if (body != null) { + val bytes = body.toByteArray(Charsets.UTF_8) + connection.doOutput = true + connection.setRequestProperty("Content-Type", "application/json") + connection.setRequestProperty("Content-Length", bytes.size.toString()) + connection.outputStream.use { it.write(bytes) } + } + val status = connection.responseCode + val stream = if (status in 200..299) connection.inputStream else connection.errorStream + val response = stream?.use { + BufferedReader(InputStreamReader(it, Charsets.UTF_8)).readText() + } ?: "" + connection.disconnect() + if (status !in 200..299) { + val message = response.ifBlank { "HTTP $status" } + throw IllegalStateException(message) + } + return response + } + + private fun encode(value: String): String = + java.net.URLEncoder.encode(value, Charsets.UTF_8.name()).replace("+", "%20") +} diff --git a/apps/android/app/src/main/java/com/ejclaw/android/display/DisplayBridge.kt b/apps/android/app/src/main/java/com/ejclaw/android/display/DisplayBridge.kt new file mode 100644 index 0000000..ad23939 --- /dev/null +++ b/apps/android/app/src/main/java/com/ejclaw/android/display/DisplayBridge.kt @@ -0,0 +1,13 @@ +package com.ejclaw.android.display + +class DisplayBridge( + private val surface: DisplaySurface = NoopDisplaySurface(), +) { + fun updateRoom(roomName: String, status: String, progress: String?) { + surface.showStatus(roomName, status, progress) + } + + fun showLatest(roomName: String, text: String) { + if (text.isNotBlank()) surface.showMessage(roomName, text) + } +} diff --git a/apps/android/app/src/main/java/com/ejclaw/android/display/DisplaySurface.kt b/apps/android/app/src/main/java/com/ejclaw/android/display/DisplaySurface.kt new file mode 100644 index 0000000..d6f3f33 --- /dev/null +++ b/apps/android/app/src/main/java/com/ejclaw/android/display/DisplaySurface.kt @@ -0,0 +1,6 @@ +package com.ejclaw.android.display + +interface DisplaySurface { + fun showStatus(roomName: String, state: String, progress: String?) + fun showMessage(roomName: String, text: String) +} diff --git a/apps/android/app/src/main/java/com/ejclaw/android/display/MetaDatDisplaySurface.kt b/apps/android/app/src/main/java/com/ejclaw/android/display/MetaDatDisplaySurface.kt new file mode 100644 index 0000000..45fba5e --- /dev/null +++ b/apps/android/app/src/main/java/com/ejclaw/android/display/MetaDatDisplaySurface.kt @@ -0,0 +1,15 @@ +package com.ejclaw.android.display + +/** + * Meta DAT integration point. + * + * Keep this class dependency-free until the Wearables Developer Center project, + * GitHub Packages token, and DAT application id are available. The phone app can + * validate EJClaw connectivity through NoopDisplaySurface first, then this class + * can be swapped to call the Meta SDK. + */ +class MetaDatDisplaySurface : DisplaySurface { + override fun showStatus(roomName: String, state: String, progress: String?) = Unit + + override fun showMessage(roomName: String, text: String) = Unit +} diff --git a/apps/android/app/src/main/java/com/ejclaw/android/display/NoopDisplaySurface.kt b/apps/android/app/src/main/java/com/ejclaw/android/display/NoopDisplaySurface.kt new file mode 100644 index 0000000..9dc4271 --- /dev/null +++ b/apps/android/app/src/main/java/com/ejclaw/android/display/NoopDisplaySurface.kt @@ -0,0 +1,16 @@ +package com.ejclaw.android.display + +class NoopDisplaySurface : DisplaySurface { + var lastStatus: String = "" + private set + var lastMessage: String = "" + private set + + override fun showStatus(roomName: String, state: String, progress: String?) { + lastStatus = listOfNotNull(roomName, state, progress).joinToString(" / ") + } + + override fun showMessage(roomName: String, text: String) { + lastMessage = "$roomName: $text" + } +} diff --git a/apps/android/app/src/main/java/com/ejclaw/android/model/Models.kt b/apps/android/app/src/main/java/com/ejclaw/android/model/Models.kt new file mode 100644 index 0000000..cc27f99 --- /dev/null +++ b/apps/android/app/src/main/java/com/ejclaw/android/model/Models.kt @@ -0,0 +1,25 @@ +package com.ejclaw.android.model + +data class RoomSummary( + val jid: String, + val name: String, + val status: String, + val latestText: String, +) { + override fun toString(): String { + val suffix = if (latestText.isBlank()) "" else "\n$latestText" + return "$name [$status]$suffix" + } +} + +data class RoomMessage( + val senderName: String, + val content: String, + val timestamp: String, + val fromMe: Boolean, +) + +data class RoomActivity( + val summary: RoomSummary, + val messages: List, +) diff --git a/apps/android/app/src/main/java/com/ejclaw/android/ui/EJClawView.kt b/apps/android/app/src/main/java/com/ejclaw/android/ui/EJClawView.kt new file mode 100644 index 0000000..13c77c7 --- /dev/null +++ b/apps/android/app/src/main/java/com/ejclaw/android/ui/EJClawView.kt @@ -0,0 +1,80 @@ +package com.ejclaw.android.ui + +import android.app.Activity +import android.graphics.Typeface +import android.text.InputType +import android.view.View +import android.widget.ArrayAdapter +import android.widget.Button +import android.widget.EditText +import android.widget.LinearLayout +import android.widget.ListView +import android.widget.ScrollView +import android.widget.TextView +import com.ejclaw.android.model.RoomSummary + +class EJClawView( + activity: Activity, +) { + val baseUrlInput = EditText(activity) + val tokenInput = EditText(activity) + val nicknameInput = EditText(activity) + val connectButton = Button(activity) + val refreshButton = Button(activity) + val sendButton = Button(activity) + val messageInput = EditText(activity) + val statusView = TextView(activity) + val threadView = TextView(activity) + val roomsAdapter = ArrayAdapter(activity, android.R.layout.simple_list_item_1) + val roomsList = ListView(activity) + val root: View + + init { + baseUrlInput.hint = "http://100.101.210.95:8734" + baseUrlInput.inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_URI + tokenInput.hint = "WEB_DASHBOARD_TOKEN" + tokenInput.inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_PASSWORD + nicknameInput.hint = "nickname" + nicknameInput.inputType = InputType.TYPE_CLASS_TEXT + messageInput.hint = "message" + messageInput.minLines = 2 + + connectButton.text = "Connect" + refreshButton.text = "Refresh" + sendButton.text = "Send" + statusView.text = "Disconnected" + threadView.text = "Select a room" + threadView.setTypeface(Typeface.MONOSPACE) + roomsList.adapter = roomsAdapter + + val controls = LinearLayout(activity).apply { + orientation = LinearLayout.VERTICAL + setPadding(24, 24, 24, 12) + addView(baseUrlInput) + addView(tokenInput) + addView(nicknameInput) + addView(LinearLayout(activity).apply { + orientation = LinearLayout.HORIZONTAL + addView(connectButton, LinearLayout.LayoutParams(0, -2, 1f)) + addView(refreshButton, LinearLayout.LayoutParams(0, -2, 1f)) + }) + addView(statusView) + } + val scroll = ScrollView(activity).apply { + addView(threadView) + } + val sendRow = LinearLayout(activity).apply { + orientation = LinearLayout.HORIZONTAL + addView(messageInput, LinearLayout.LayoutParams(0, -2, 1f)) + addView(sendButton) + } + + root = LinearLayout(activity).apply { + orientation = LinearLayout.VERTICAL + addView(controls) + addView(roomsList, LinearLayout.LayoutParams(-1, 0, 1f)) + addView(scroll, LinearLayout.LayoutParams(-1, 0, 1f)) + addView(sendRow) + } + } +} diff --git a/apps/android/app/src/main/res/values/strings.xml b/apps/android/app/src/main/res/values/strings.xml new file mode 100644 index 0000000..f74f311 --- /dev/null +++ b/apps/android/app/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + EJClaw + diff --git a/apps/android/app/src/main/res/values/styles.xml b/apps/android/app/src/main/res/values/styles.xml new file mode 100644 index 0000000..77f9795 --- /dev/null +++ b/apps/android/app/src/main/res/values/styles.xml @@ -0,0 +1,7 @@ + + + diff --git a/apps/android/app/src/main/res/xml/network_security_config.xml b/apps/android/app/src/main/res/xml/network_security_config.xml new file mode 100644 index 0000000..fef849a --- /dev/null +++ b/apps/android/app/src/main/res/xml/network_security_config.xml @@ -0,0 +1,6 @@ + + + + 100.101.210.95 + + diff --git a/apps/android/build.gradle.kts b/apps/android/build.gradle.kts new file mode 100644 index 0000000..e2572a7 --- /dev/null +++ b/apps/android/build.gradle.kts @@ -0,0 +1,4 @@ +plugins { + id("com.android.application") version "8.13.0" apply false + id("org.jetbrains.kotlin.android") version "2.2.21" apply false +} diff --git a/apps/android/gradle.properties b/apps/android/gradle.properties new file mode 100644 index 0000000..bae9034 --- /dev/null +++ b/apps/android/gradle.properties @@ -0,0 +1,3 @@ +android.useAndroidX=true +android.nonTransitiveRClass=true +org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 diff --git a/apps/android/gradle/wrapper/gradle-wrapper.jar b/apps/android/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..1b33c55 Binary files /dev/null and b/apps/android/gradle/wrapper/gradle-wrapper.jar differ diff --git a/apps/android/gradle/wrapper/gradle-wrapper.properties b/apps/android/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..d4081da --- /dev/null +++ b/apps/android/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/apps/android/gradlew b/apps/android/gradlew new file mode 100755 index 0000000..23d15a9 --- /dev/null +++ b/apps/android/gradlew @@ -0,0 +1,251 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH="\\\"\\\"" + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/apps/android/gradlew.bat b/apps/android/gradlew.bat new file mode 100644 index 0000000..db3a6ac --- /dev/null +++ b/apps/android/gradlew.bat @@ -0,0 +1,94 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH= + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/apps/android/local.properties.example b/apps/android/local.properties.example new file mode 100644 index 0000000..e45563e --- /dev/null +++ b/apps/android/local.properties.example @@ -0,0 +1,7 @@ +## Copy to local.properties when building outside Android Studio. +## Do not commit local.properties. +sdk.dir=/home/ejclaw/android-sdk + +## Optional later, when enabling Meta Wearables DAT dependencies. +## github_token=ghp_xxx +## meta_dat_application_id=your_meta_wearables_application_id diff --git a/apps/android/settings.gradle.kts b/apps/android/settings.gradle.kts new file mode 100644 index 0000000..4ac0ad0 --- /dev/null +++ b/apps/android/settings.gradle.kts @@ -0,0 +1,18 @@ +pluginManagement { + repositories { + google() + mavenCentral() + gradlePluginPortal() + } +} + +dependencyResolutionManagement { + repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) + repositories { + google() + mavenCentral() + } +} + +rootProject.name = "EJClawAndroid" +include(":app") diff --git a/package.json b/package.json index ba5493d..0438aac 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,8 @@ "dashboard:build": "vite build --config apps/dashboard/vite.config.ts", "dashboard:preview": "vite preview --config apps/dashboard/vite.config.ts", "dashboard:ux": "bun scripts/dashboard-ux.ts", + "android:build": "cd apps/android && ./gradlew assembleDebug", + "android:install": "cd apps/android && ./gradlew installDebug", "install:runners": "bun install --frozen-lockfile --cwd runners/shared && bun install --frozen-lockfile --cwd runners/agent-runner && bun install --frozen-lockfile --cwd runners/codex-runner", "build:runners": "bun run install:runners && bun run --cwd runners/shared build && bun run --cwd runners/agent-runner build && bun run --cwd runners/codex-runner build", "build:all": "bun run build && bun run dashboard:build && bun run build:runners",