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
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ class AndCodeApplication : Application() {
runtimeDirectory = runtimeDirectory,
abi = abi,
accessCoordinator = accessCoordinator,
userAgentInstructions = { settings.agentInstructions },
)
localRuntimeInstaller = installer
// Guest startup commands (issue #379): read from the workspace on every runtime start,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,16 @@ class SecureSettingsRepository(context: Context) :
get() = preferences.getBoolean(KEY_ANALYTICS_ENABLED, false)
set(value) = preferences.edit().putBoolean(KEY_ANALYTICS_ENABLED, value).apply()

/**
* Extra instructions appended to every agent's shared AndCode context.
*
* The bundled context is the part AndCode owns; this is the user's own addition, applied to
* OpenCode, Claude Code, Antigravity and Codex together so a rule only has to be written once.
*/
var agentInstructions: String
get() = preferences.getString(KEY_AGENT_INSTRUCTIONS, "") ?: ""
set(value) = preferences.edit().putString(KEY_AGENT_INSTRUCTIONS, value).apply()

/**
* Lets the in-guest agent drive the Guest Browser by exposing its WebView devtools socket.
*
Expand Down Expand Up @@ -616,6 +626,7 @@ class SecureSettingsRepository(context: Context) :
private const val KEY_LANGUAGE = "language"
private const val KEY_LIVE_TRANSCRIPT_ENABLED = "live_transcript_enabled"
private const val KEY_ANALYTICS_ENABLED = "analytics_enabled"
private const val KEY_AGENT_INSTRUCTIONS = "agent_instructions"
private const val KEY_GUEST_BROWSER_AGENT_CONTROL = "guest_browser_agent_control"
private const val KEY_LOCAL_RUNTIME_IDLE_STOP_ENABLED = "local_runtime_idle_stop_enabled"
private const val KEY_LOCAL_RUNTIME_STOPPED_BY_USER = "local_runtime_stopped_by_user"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ data class AppPreferences(
val language: String = "system",
val liveTranscriptEnabled: Boolean = false,
val analyticsEnabled: Boolean = false,
/** Extra instructions appended to every agent's shared AndCode context. */
val agentInstructions: String = "",
val guestBrowserAgentControlEnabled: Boolean = false,
val localRuntimeIdleStopEnabled: Boolean = true,
val autoArchiveStaleEnabled: Boolean = false,
Expand Down Expand Up @@ -106,6 +108,7 @@ class AppPreferencesRepository(
language = settings.language,
liveTranscriptEnabled = settings.liveTranscriptEnabled,
analyticsEnabled = settings.analyticsEnabled,
agentInstructions = settings.agentInstructions,
guestBrowserAgentControlEnabled = settings.guestBrowserAgentControlEnabled,
localRuntimeIdleStopEnabled = settings.localRuntimeIdleStopEnabled,
autoArchiveStaleEnabled = settings.autoArchiveStaleEnabled,
Expand Down Expand Up @@ -360,6 +363,11 @@ class AppPreferencesRepository(
mutableState.update { it.copy(analyticsEnabled = enabled) }
}

fun setAgentInstructions(instructions: String) {
settings.agentInstructions = instructions
mutableState.update { it.copy(agentInstructions = instructions) }
}

fun setGuestBrowserAgentControlEnabled(enabled: Boolean) {
settings.guestBrowserAgentControlEnabled = enabled
mutableState.update { it.copy(guestBrowserAgentControlEnabled = enabled) }
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/com/yugahashimoto/andcode/di/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,13 @@ val appModule =
single {
val runtimeDirectory: File = get()
val abi = Build.SUPPORTED_ABIS.firstOrNull().orEmpty()
val settings: SecureSettingsRepository = get()
LocalRuntimeInstaller(
context = androidContext(),
runtimeDirectory = runtimeDirectory,
abi = abi,
accessCoordinator = get(),
userAgentInstructions = { settings.agentInstructions },
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ val viewModelModule =
// Same Codex fast-mode wiring as the factory in ui/AndCodeApp.kt; keep the two in step.
onCodexFastModeChanged = preferences::setCodexFastMode,
initialCodexFastMode = settings.codexFastMode,
initialSendBehavior = preferences.state.value.sendBehavior,
isSessionRunning = { id -> id in app.activityRepository.state.value.activeSessionIds },
// Kept in step with the hand-rolled factory in ui/AndCodeApp.kt: both construction
// paths have to park the connection probe and stall watchdog while the app is
// backgrounded, or whichever one the screen happens to use decides whether those
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,12 @@ fun ChatHomeScreen(
supportsPermissions: Boolean = true,
onToggleAutoAccept: (Boolean) -> Unit = {},
sendBehavior: String = "interrupt",
/**
* True for a runtime that always queues a send behind a running turn instead of interrupting it
* (Antigravity), so the composer offers send-while-running the same way the "queue" setting
* does rather than hiding the send action behind the stop button.
*/
forcesQueue: Boolean = false,
enterToSend: Boolean = false,
/** Whether reasoning/thinking cards should start expanded when the activity sheet opens. */
autoExpandReasoning: Boolean = false,
Expand Down Expand Up @@ -769,6 +775,7 @@ fun ChatHomeScreen(
onSelectSystemPrompt = onSelectSystemPrompt,
onToggleAutoAccept = onToggleAutoAccept,
sendBehavior = sendBehavior,
forcesQueue = forcesQueue,
enterToSend = enterToSend,
contextTokensUsed = state.contextTokensUsed,
contextLimit =
Expand Down Expand Up @@ -1438,6 +1445,7 @@ private fun ChatComposer(
selectedSystemPromptId: String?,
onSelectSystemPrompt: (String?) -> Unit,
sendBehavior: String,
forcesQueue: Boolean,
enterToSend: Boolean,
contextTokensUsed: Long,
contextLimit: Long,
Expand Down Expand Up @@ -1748,7 +1756,11 @@ private fun ChatComposer(
}
}
if (isRunning) {
if (sendBehavior == "queue") {
// A queueing runtime (the "queue" setting, or Antigravity which always
// queues) keeps the send action available mid-turn: the prompt waits behind
// the running turn instead of interrupting it, and rejecting it here left
// the user with no way to add to a long-running turn at all.
if (sendBehavior == "queue" || forcesQueue) {
Surface(
shape = RoundedCornerShape(100.dp),
color = MaterialTheme.colorScheme.tertiaryContainer,
Expand All @@ -1760,6 +1772,17 @@ private fun ChatComposer(
style = MaterialTheme.typography.labelSmall,
)
}
FilledIconButton(
onClick = onSend,
enabled = input.isNotBlank() || attachments.isNotEmpty(),
modifier = Modifier.size(38.dp),
) {
Icon(
Icons.AutoMirrored.Filled.Send,
contentDescription = stringResource(R.string.send_description),
modifier = Modifier.size(20.dp),
)
}
}
FilledIconButton(onClick = onAbort, modifier = Modifier.size(38.dp)) {
Icon(Icons.Default.Stop, contentDescription = stringResource(R.string.stop_run))
Expand Down
Loading
Loading