Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
162 commits
Select commit Hold shift + click to select a range
ff347dd
Fix named local song resolution and matching
GWSDeveloper Oct 17, 2026
93240e8
Apply brightness changes and prioritize named local tracks
GWSDeveloper Oct 17, 2026
74ceddf
Match Hindi spoken contact names to Latin-script contacts
GWSDeveloper Oct 17, 2026
5cde955
Expose safe Tavily response diagnostics
GWSDeveloper Oct 17, 2026
c00a880
Declare system brightness write permission
GWSDeveloper Oct 17, 2026
929c7bb
Make mic button stop without speech or auto-rearming
GWSDeveloper Oct 17, 2026
fc4873b
Improve phonetic matching for Hindi contact names
GWSDeveloper Oct 17, 2026
bd08738
Add friendly music and brightness permission feedback
GWSDeveloper Oct 17, 2026
8993781
Keep contact matching conservative and remove duplicate helper
GWSDeveloper Oct 17, 2026
49c3178
Extract named song requests from Hindi and Hinglish commands
GWSDeveloper Oct 17, 2026
e68f992
Support explicit selection of an ambiguous contact number
GWSDeveloper Oct 17, 2026
9c75f37
Route explicit contact-number selection
GWSDeveloper Oct 17, 2026
c5141ef
Resolve selected call numbers and surface web-search failures
GWSDeveloper Oct 17, 2026
ceafd72
Strip spoken filler from named-song requests
GWSDeveloper Oct 17, 2026
db9cf15
Strengthen music-title and web-search tool instructions
GWSDeveloper Oct 17, 2026
1fbd98c
Route music requests directly through the LLM media agent
GWSDeveloper Oct 17, 2026
958267c
Prefer Roman Hinglish recognition and default Hindi female TTS voice
GWSDeveloper Oct 17, 2026
99d4cfc
Make built-in Android TTS the default
GWSDeveloper Oct 17, 2026
5cdddda
Set Hinglish-first replies and direct media tool guidance
GWSDeveloper Oct 17, 2026
3e0fe0a
Set Hinglish-first assistant behavior and direct media tool routing
GWSDeveloper Oct 17, 2026
253e2c2
Prefer network Hindi female TTS voice by default
GWSDeveloper Oct 17, 2026
942d187
Unify SIA planning and iterative tool execution
GWSDeveloper Oct 17, 2026
33bf431
Harden Gemini tool planning and response parsing
GWSDeveloper Oct 17, 2026
308bf4a
Wire tool results into the iterative planner
GWSDeveloper Oct 17, 2026
9be3913
Correct planner context separators
GWSDeveloper Oct 17, 2026
5190643
Correct Gemini instruction separators
GWSDeveloper Oct 17, 2026
30e5f61
Preserve full tool history and partial outcomes
GWSDeveloper Oct 17, 2026
8bd6369
Preserve partial results when one action needs clarification
GWSDeveloper Oct 17, 2026
cdfe0ad
Remove deterministic routing gate from unified planner
GWSDeveloper Oct 17, 2026
b1377a4
Fix Gemini multi-part response newline handling
GWSDeveloper Oct 17, 2026
82c50ff
Clarify device tool parameters for compound actions
GWSDeveloper Oct 17, 2026
fad5476
Strengthen compound action planning and brightness instructions
GWSDeveloper Oct 17, 2026
2f7eb29
Replace feature-specific prompt rules with generic task planning
GWSDeveloper Oct 17, 2026
c90c270
Keep agent tool descriptions capability-focused and generic
GWSDeveloper Oct 17, 2026
8602a75
Parse nested and compound tool calls with balanced JSON scanning
GWSDeveloper Oct 17, 2026
43a0254
Fix escaped JSON string scanning
GWSDeveloper Oct 17, 2026
45de600
Preserve full voice transcription for compound commands
GWSDeveloper Oct 17, 2026
76a0b83
Require a track query before named music playback
GWSDeveloper Oct 17, 2026
4cb941e
Ground music confirmations and reject empty web acknowledgements
GWSDeveloper Oct 17, 2026
1915cfb
Use actual playback result instead of model-generated song claims
GWSDeveloper Oct 17, 2026
e6afe22
Avoid duplicate current turn and cap tool execution rounds
GWSDeveloper Oct 18, 2026
37f3fbf
Keep tool-call responses separate from final confirmations
GWSDeveloper Oct 18, 2026
ea1e5fb
Keep tool-call responses separate from final confirmations
GWSDeveloper Oct 18, 2026
2709d64
Separate tool planning output from final user response
GWSDeveloper Oct 18, 2026
ca9d415
Never acknowledge web search without an answer
GWSDeveloper Oct 18, 2026
f9c50e8
Align Gemini tool-call protocol with result feedback loop
GWSDeveloper Oct 18, 2026
b8d7f49
Fix Gemini prompt newline escape
GWSDeveloper Oct 18, 2026
da12be3
Retry answer synthesis when web search yields only an acknowledgement
GWSDeveloper Oct 18, 2026
9ab02f9
Correct web synthesis prompt and avoid redundant synthesis retries
GWSDeveloper Oct 18, 2026
2fdb9e7
Fix escaped newlines in web evidence synthesis
GWSDeveloper Oct 18, 2026
862a7c5
Remove feature-specific planner rules from system prompt
GWSDeveloper Oct 18, 2026
48643bc
Keep Gemini tool policy generic and registry-driven
GWSDeveloper Oct 18, 2026
306bfd9
Keep OpenAI-compatible tool policy generic and registry-driven
GWSDeveloper Oct 18, 2026
7ac29c1
Remove music-specific planner instruction
GWSDeveloper Oct 18, 2026
a534c1b
Remove duplicate provider tool protocol instruction
GWSDeveloper Oct 18, 2026
fed6821
Fix system prompt tool policy newline
GWSDeveloper Oct 18, 2026
1f83b85
Restore canonical tool-call instruction in OpenAI-compatible provider
GWSDeveloper Oct 18, 2026
4a4ec8e
refactor: expose simple individual Android tools to LLM
GWSDeveloper Oct 18, 2026
bc5cee3
refactor: route individual tool calls to Android action handlers
GWSDeveloper Oct 18, 2026
38425d5
refactor: remove deterministic intent parser from tool registry
GWSDeveloper Oct 18, 2026
25d0cda
cleanup: remove unused intent registry import from speech manager
GWSDeveloper Oct 18, 2026
a6d8530
fix: handle simple call and music tool results consistently
GWSDeveloper Oct 18, 2026
86fb9dd
fix: normalize parsed response line breaks
GWSDeveloper Oct 18, 2026
4c8d37e
cleanup: remove duplicate legacy tool dispatch branches
GWSDeveloper Oct 18, 2026
106343d
feat: expose camera, vibration, SMS draft and memory tools
GWSDeveloper Oct 18, 2026
9e9a58f
feat: implement vibration, SMS draft and permanent memory tools
GWSDeveloper Oct 18, 2026
3f54fd7
fix: restore line boundaries in action executor
GWSDeveloper Oct 18, 2026
f525db8
refactor: expose simple tools and remove intent parser
GWSDeveloper Oct 18, 2026
356b36a
feat: implement individual device, SMS, vibration and memory tool dis…
GWSDeveloper Oct 18, 2026
3087208
cleanup: remove duplicate legacy action dispatch
GWSDeveloper Oct 18, 2026
9a21e65
cleanup: remove unused speech intent parser dependency
GWSDeveloper Oct 18, 2026
ad98bcb
fix: retry only retryable tool errors and support individual tool res…
GWSDeveloper Oct 18, 2026
125f693
refactor: remove hardcoded intent matching from local provider
GWSDeveloper Oct 18, 2026
2b32934
refactor: route floating commands through the same LLM tool loop
GWSDeveloper Oct 18, 2026
f26eabe
fix: deduplicate identical tool calls within each planning round
GWSDeveloper Oct 18, 2026
ca58410
fix: deduplicate identical tool calls within each planning round
GWSDeveloper Oct 18, 2026
75b9347
fix: confirm individual media and device tools from actual results
GWSDeveloper Oct 18, 2026
fee897e
test: replace intent parser tests with individual tool registry checks
GWSDeveloper Oct 18, 2026
514444a
test: remove obsolete deterministic intent parser assertions
GWSDeveloper Oct 18, 2026
8a12531
feat: list local music tracks without changing playback queue
GWSDeveloper Oct 18, 2026
2872695
feat: expose local music listing as a simple tool
GWSDeveloper Oct 18, 2026
99f2cc7
feat: route list_music tool to local library
GWSDeveloper Oct 18, 2026
c35405d
refactor: share the SIA tool execution loop
GWSDeveloper Oct 18, 2026
f86468f
refactor: use shared tool execution coordinator
GWSDeveloper Oct 18, 2026
a87bf38
refactor: share tool execution with floating overlay
GWSDeveloper Oct 18, 2026
e78bd21
refactor: share SIA system prompt across interfaces
GWSDeveloper Oct 18, 2026
b343694
refactor: share SIA prompt instructions
GWSDeveloper Oct 18, 2026
be2aae8
refactor: share SIA prompt instructions
GWSDeveloper Oct 18, 2026
0f46384
fix: avoid parsing ordinary JSON as tool calls
GWSDeveloper Oct 18, 2026
8498ef9
test: cover compound tool parsing and registry consistency
GWSDeveloper Oct 18, 2026
08660de
fix: report action limit only when work remains
GWSDeveloper Oct 18, 2026
2e95529
refactor: remove obsolete local action execution path
GWSDeveloper Oct 18, 2026
9490688
refactor: keep one canonical tool registry
GWSDeveloper Oct 18, 2026
f6d331e
test: assert one canonical tool catalogue
GWSDeveloper Oct 18, 2026
4406c73
fix: validate tool names and parameters before execution
GWSDeveloper Oct 18, 2026
9f03ac0
fix: normalize integer tool arguments from JSON
GWSDeveloper Oct 18, 2026
4bf96c9
test: normalize numeric tool parameters
GWSDeveloper Oct 18, 2026
db1e2be
fix: reject invalid numeric tool arguments
GWSDeveloper Oct 18, 2026
6ed0d82
docs: clarify the canonical Android tool registry
GWSDeveloper Oct 18, 2026
44f899b
test: keep prompt and registered tool names aligned
GWSDeveloper Oct 18, 2026
7a57d07
fix: keep overlay error responses honest and user-friendly
GWSDeveloper Oct 18, 2026
632b0c5
fix: stop redundant web answer synthesis retries
GWSDeveloper Oct 18, 2026
96b418f
refactor: use only canonical tool names in result handling
GWSDeveloper Oct 18, 2026
00705b3
refactor: make action confirmations match registered tools
GWSDeveloper Oct 18, 2026
82896e9
fix: keep Hinglish fallback responses in Roman script
GWSDeveloper Oct 18, 2026
1017fdd
Fix local music stop and playback control routing
GWSDeveloper Oct 18, 2026
83993e2
Improve web search evidence for current and news queries
GWSDeveloper Oct 18, 2026
7ccb6e3
Make app launches more reliable and avoid unverified open claims
GWSDeveloper Oct 18, 2026
e96c031
Avoid claiming apps opened before foreground launch is verified
GWSDeveloper Oct 18, 2026
5ee94f7
Require direct title or artist matches for requested songs
GWSDeveloper Oct 18, 2026
378e094
Prevent false call success and require dialer confirmation
GWSDeveloper Oct 18, 2026
8329a0b
Tell users clearly when a call still needs dialer confirmation
GWSDeveloper Oct 18, 2026
9397a08
Expose verified current local track state
GWSDeveloper Oct 18, 2026
c3a7bbe
Hide malformed tool protocol blocks from chat
GWSDeveloper Oct 18, 2026
ce3462c
Fix current date context and action reliability
GWSDeveloper Oct 18, 2026
866cb62
Add generic task continuation, provider fallback, and user personaliz…
GWSDeveloper Oct 19, 2026
45e6f8b
Fix Kotlin source formatting in task protocol
GWSDeveloper Oct 19, 2026
04095f2
Add SIA persona status protocol and first-run name setup
GWSDeveloper Oct 19, 2026
c10d2ac
Correct status marker parsing
GWSDeveloper Oct 19, 2026
4d10362
Wire saved user name into SIA persona and settings
GWSDeveloper Oct 19, 2026
5835c01
Remove duplicate Compose import
GWSDeveloper Oct 19, 2026
85d04ec
Fix malformed user name state declaration
GWSDeveloper Oct 19, 2026
bed2f6e
Add AI rolling memory and per-provider model persistence
GWSDeveloper Oct 19, 2026
5af83f1
Fix model preference declaration and add confirmed memory editing
GWSDeveloper Oct 19, 2026
e6a7ec7
Validate latest memory and settings changes in CI
GWSDeveloper Oct 19, 2026
1215d86
Import memory edit icon for settings screen
GWSDeveloper Oct 19, 2026
e187e18
Refine SIA assistant screen and remove duplicate mic control
GWSDeveloper Oct 19, 2026
f03f1e1
Give SIA orb a restrained dimensional cyan visual identity
GWSDeveloper Oct 19, 2026
c877e08
Redesign SIA interface with warm surfaces and dimensional glass orb
GWSDeveloper Oct 20, 2026
e20425f
Make SIA orb an organic, animated light form
GWSDeveloper Oct 20, 2026
f7c8de5
Refine SIA home, settings, and workspace layouts
GWSDeveloper Oct 20, 2026
c7b4297
Redesign SIA product surfaces with evergreen palette and compact scre…
GWSDeveloper Oct 20, 2026
ee1e1ee
Redesign SIA screen hierarchy, settings cards and workspace layout
GWSDeveloper Oct 20, 2026
38788e0
Rebuild SIA navigation and chat UI with layered color and Markdown re…
GWSDeveloper Oct 20, 2026
79b584e
Redesign SIA mode switcher, action tiles, settings cards and Markdown…
GWSDeveloper Oct 20, 2026
665fc90
Fix Markdown code block newline rendering
GWSDeveloper Oct 20, 2026
b3d7565
Fix Markdown inline styling scope in Compose renderer
GWSDeveloper Oct 20, 2026
f682f18
Use imported Compose withStyle in Markdown renderer
GWSDeveloper Oct 20, 2026
36930a9
Keep bottom navigation clear of system bar and lift chat composer wit…
GWSDeveloper Oct 20, 2026
a8093e4
Avoid double keyboard inset on chat composer
GWSDeveloper Oct 20, 2026
bbf0c5f
Redesign SIA orb as hollow fluid-glass energy loop with two moving nodes
GWSDeveloper Oct 20, 2026
bae4800
Redesign floating overlay as compact draggable energy-orb dock
GWSDeveloper Oct 20, 2026
0aaca09
Use Android Color channel helpers in floating orb
GWSDeveloper Oct 20, 2026
413662d
Remove duplicate legacy full-screen overlay params
GWSDeveloper Oct 20, 2026
27cd0b6
Strengthen SIA strict execution and concise voice persona
GWSDeveloper Oct 20, 2026
4a33f5f
Avoid overlay recognizer reset and shorten spoken action confirmations
GWSDeveloper Oct 20, 2026
7d01fcb
Run one action per verification round while preserving queued actions
GWSDeveloper Oct 20, 2026
90ab2aa
Integrate Gnani Vachana speech-to-text
GWSDeveloper Oct 20, 2026
c65948c
Keep Gnani STT off main thread and localize wake-word listening
GWSDeveloper Oct 20, 2026
ceeb629
Normalize Hindi voice commands to Roman Hinglish
GWSDeveloper Oct 20, 2026
4332f7e
Improve tool error recovery and add stop listening tool
GWSDeveloper Oct 20, 2026
00f75ae
Add generic call_again orchestration and update v2.1.1 model defaults
GWSDeveloper Oct 20, 2026
0b9b6ae
Execute call_again as an AI orchestration step
GWSDeveloper Oct 20, 2026
f4c33be
Require AI follow-up reasoning and friend-like final answers (v2.1.2)
GWSDeveloper Oct 20, 2026
e26062a
Add immersive voice overlay and direct calls for exact contacts (v2.1.3)
GWSDeveloper Oct 20, 2026
14f5a90
Add immersive voice overlay (v2.1.3)
GWSDeveloper Oct 20, 2026
8bf2fd5
Fix duplicate overlay method and bump version to 2.1.5
GWSDeveloper Oct 20, 2026
b95c095
Redesign SIA orb with glass plasma core (v2.1.6)
GWSDeveloper Oct 20, 2026
2186d65
Improve SIA Nexus overlay contrast and backdrop
GWSDeveloper Oct 21, 2026
6e403da
Redesign floating orb as high-contrast Nexus energy ring
GWSDeveloper Oct 21, 2026
dbf3b92
Apply Nexus palette to SIA app orb
GWSDeveloper Oct 21, 2026
580fe14
Bump SIA to v2.1.7
GWSDeveloper Oct 21, 2026
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
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ android {
applicationId = "com.aistudio.siaassistant.vnkjqz"
minSdk = 24
targetSdk = 36
versionCode = 1
versionName = "1.0"
versionCode = 20107
versionName = "2.1.7"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="32" />

Expand Down
155 changes: 63 additions & 92 deletions app/src/main/java/com/example/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,42 @@ import androidx.activity.enableEdgeToEdge
import androidx.activity.result.contract.ActivityResultContracts
import androidx.activity.viewModels
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.ui.draw.clip
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.systemBars
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.AutoAwesome
import androidx.compose.material.icons.filled.Folder
import androidx.compose.material.icons.filled.Settings
import androidx.compose.material3.Icon
import androidx.compose.material3.NavigationBar
import androidx.compose.material3.NavigationBarItem
import androidx.compose.material3.NavigationBarItemDefaults
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.material3.LocalContentColor
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.getValue
import androidx.compose.runtime.setValue
import androidx.compose.runtime.collectAsState
import androidx.compose.ui.Modifier
import androidx.compose.ui.Alignment
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
Expand Down Expand Up @@ -95,6 +110,11 @@ fun MainAppScaffold(
onStartVoiceRequest: () -> Unit
) {
val currentTab by viewModel.currentTab.collectAsState()
var nameDraft by remember { mutableStateOf(viewModel.preferences.getUserName()) }
var showNameSetup by remember { mutableStateOf(nameDraft.isBlank()) }
if (showNameSetup) {
AlertDialog(onDismissRequest = {}, title = { Text("Hey! Main SIA hoon 💗") }, text = { OutlinedTextField(value = nameDraft, onValueChange = { nameDraft = it }, label = { Text("Tumhara naam kya hai?") }, singleLine = true) }, confirmButton = { Button(onClick = { if (nameDraft.isNotBlank()) { viewModel.preferences.setUserName(nameDraft); showNameSetup = false } }, enabled = nameDraft.isNotBlank()) { Text("Chalo, start karein") } })
}

// Request runtime permissions on launch
val permissionLauncher = rememberLauncherForActivityResult(
Expand Down Expand Up @@ -133,97 +153,25 @@ fun MainAppScaffold(
Scaffold(
contentWindowInsets = WindowInsets.systemBars,
bottomBar = {
NavigationBar(
containerColor = SiaSurfaceDark,
contentColor = SiaTextPrimary,
tonalElevation = 8.dp,
modifier = Modifier.testTag("main_bottom_nav_bar")
Box(
modifier = Modifier.fillMaxWidth().background(Color.Transparent).navigationBarsPadding().padding(horizontal = 16.dp, vertical = 10.dp)
) {
// Workspace
NavigationBarItem(
selected = currentTab == MainScreenTab.WORKSPACE,
onClick = { viewModel.setTab(MainScreenTab.WORKSPACE) },
icon = {
Icon(
imageVector = Icons.Default.Folder,
contentDescription = "Workspace",
modifier = Modifier.size(24.dp)
)
},
label = {
Text(
text = "Workspace",
fontSize = 12.sp,
fontWeight = if (currentTab == MainScreenTab.WORKSPACE) FontWeight.Bold else FontWeight.Normal
)
},
colors = NavigationBarItemDefaults.colors(
selectedIconColor = SiaCyan,
selectedTextColor = SiaCyan,
unselectedIconColor = SiaTextMuted,
unselectedTextColor = SiaTextMuted,
indicatorColor = SiaCyan.copy(alpha = 0.15f)
),
modifier = Modifier.testTag("nav_tab_workspace")
)

// AI Agent (Default Center Destination)
NavigationBarItem(
selected = currentTab == MainScreenTab.AI_AGENT,
onClick = { viewModel.setTab(MainScreenTab.AI_AGENT) },
icon = {
Icon(
imageVector = Icons.Default.AutoAwesome,
contentDescription = "AI Agent",
modifier = Modifier.size(26.dp)
)
},
label = {
Text(
text = "AI Agent",
fontSize = 12.sp,
fontWeight = if (currentTab == MainScreenTab.AI_AGENT) FontWeight.Bold else FontWeight.Normal
)
},
colors = NavigationBarItemDefaults.colors(
selectedIconColor = SiaCyan,
selectedTextColor = SiaCyan,
unselectedIconColor = SiaTextMuted,
unselectedTextColor = SiaTextMuted,
indicatorColor = SiaCyan.copy(alpha = 0.15f)
),
modifier = Modifier.testTag("nav_tab_ai_agent")
)

// Settings
NavigationBarItem(
selected = currentTab == MainScreenTab.SETTINGS,
onClick = { viewModel.setTab(MainScreenTab.SETTINGS) },
icon = {
Icon(
imageVector = Icons.Default.Settings,
contentDescription = "Settings",
modifier = Modifier.size(24.dp)
)
},
label = {
Text(
text = "Settings",
fontSize = 12.sp,
fontWeight = if (currentTab == MainScreenTab.SETTINGS) FontWeight.Bold else FontWeight.Normal
)
},
colors = NavigationBarItemDefaults.colors(
selectedIconColor = SiaCyan,
selectedTextColor = SiaCyan,
unselectedIconColor = SiaTextMuted,
unselectedTextColor = SiaTextMuted,
indicatorColor = SiaCyan.copy(alpha = 0.15f)
),
modifier = Modifier.testTag("nav_tab_settings")
)
Row(
modifier = Modifier.fillMaxWidth()
.clip(RoundedCornerShape(30.dp))
.background(SiaSurfaceDark.copy(alpha = 0.98f))
.border(1.dp, SiaBorder, RoundedCornerShape(30.dp))
.padding(7.dp)
.testTag("main_bottom_nav_bar"),
verticalAlignment = Alignment.CenterVertically
) {
FloatingNavItem("Workspace", { Icon(Icons.Default.Folder, contentDescription = "Workspace", modifier = Modifier.size(21.dp)) }, currentTab == MainScreenTab.WORKSPACE, { viewModel.setTab(MainScreenTab.WORKSPACE) }, Modifier.weight(1f).testTag("nav_tab_workspace"))
FloatingNavItem("SIA", { Icon(Icons.Default.AutoAwesome, contentDescription = "AI Agent", modifier = Modifier.size(22.dp)) }, currentTab == MainScreenTab.AI_AGENT, { viewModel.setTab(MainScreenTab.AI_AGENT) }, Modifier.weight(1f).testTag("nav_tab_ai_agent"))
FloatingNavItem("Settings", { Icon(Icons.Default.Settings, contentDescription = "Settings", modifier = Modifier.size(21.dp)) }, currentTab == MainScreenTab.SETTINGS, { viewModel.setTab(MainScreenTab.SETTINGS) }, Modifier.weight(1f).testTag("nav_tab_settings"))
}
}
},

modifier = Modifier.fillMaxSize()
) { innerPadding ->
Box(
Expand All @@ -240,3 +188,26 @@ fun MainAppScaffold(
}
}
}


@Composable
private fun FloatingNavItem(
label: String,
icon: @Composable () -> Unit,
selected: Boolean,
onClick: () -> Unit,
modifier: Modifier = Modifier
) {
val foreground = if (selected) SiaTextPrimary else SiaTextMuted
Column(
modifier = modifier.clip(RoundedCornerShape(24.dp))
.background(if (selected) SiaCyan.copy(alpha = 0.17f) else Color.Transparent)
.clickable(onClick = onClick)
.padding(vertical = 9.dp, horizontal = 5.dp),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = androidx.compose.foundation.layout.Arrangement.spacedBy(3.dp)
) {
CompositionLocalProvider(LocalContentColor provides foreground) { icon() }
Text(label, color = if (selected) SiaCyan else SiaTextMuted, fontSize = 11.sp, fontWeight = if (selected) FontWeight.SemiBold else FontWeight.Medium, maxLines = 1)
}
}
3 changes: 3 additions & 0 deletions app/src/main/java/com/example/data/SiaDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ interface SiaDao {
@Update
suspend fun updateMessage(message: ConversationEntity)

@Query("DELETE FROM conversation_messages WHERE id <= :messageId")
suspend fun deleteMessagesUpTo(messageId: Long)

@Query("DELETE FROM conversation_messages")
suspend fun clearAllMessages()

Expand Down
91 changes: 63 additions & 28 deletions app/src/main/java/com/example/memory/MemoryManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ import com.example.data.ConversationEntity
import com.example.data.ConversationSummaryEntity
import com.example.data.MemoryEntity
import com.example.data.SiaDatabase
import com.example.preferences.SiaPreferences
import com.example.provider.PromptContext
import com.example.provider.ProviderFactory
import org.json.JSONObject
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.withContext

class MemoryManager(context: Context) {
class MemoryManager(private val context: Context) {

private val db = SiaDatabase.getDatabase(context)
private val dao = db.siaDao()
Expand Down Expand Up @@ -58,38 +62,69 @@ class MemoryManager(context: Context) {
}

/**
* Checks if conversation exceeds 15 messages; if so, produces a compact summary
* of older context while preserving recent messages in active window.
* AI compacts old conversation history and extracts stable profile facts separately.
* Recent eight messages are kept. Old rows are deleted only after the summary is saved.
*/
suspend fun checkAndSummarizeIfNeeded() = withContext(Dispatchers.IO) {
val count = dao.getMessageCount()
if (count > 16) {
val allMessages = dao.getRecentMessages(25).reversed()
val olderMessages = allMessages.take(allMessages.size - 8)
if (olderMessages.isNotEmpty()) {
val summaryBullets = olderMessages.takeLast(6).map {
val sender = if (it.sender == "user") "User" else "SIA"
val snippet = it.text.take(60).replace("\n", " ")
val toolNote = if (!it.toolName.isNullOrBlank()) " [Action: ${it.toolName} -> ${it.toolStatus}]" else ""
"- $sender: $snippet$toolNote"
}.joinToString("\n")
if (count <= 16) return@withContext
val messages = dao.getRecentMessages(count.coerceAtMost(200)).reversed()
if (messages.size <= 8) return@withContext
val older = messages.dropLast(8)
val existingSummary = dao.getSummary()?.summaryText.orEmpty()
val transcript = older.joinToString("\n") { msg ->
"${if (msg.sender == "user") "USER" else "SIA"}: ${msg.text}" +
if (msg.toolName.isNullOrBlank()) "" else " [tool=${msg.toolName}; status=${msg.toolStatus}]"
}.takeLast(24000)
val currentProfile = dao.getAllMemories().joinToString("\n") { "${it.key}: ${it.content}" }
val request = PromptContext(
systemPrompt = "Return ONLY valid JSON with keys rolling_summary and permanent_profile. rolling_summary is a concise useful summary of conversation, preserving ongoing tasks, decisions, important entities and unresolved questions while removing chatter. permanent_profile is concise plain text containing ONLY stable user facts, name, communication style, enduring preferences, long-term interests and relationships explicitly stated. Never put conversation summaries, one-off tasks, temporary states, secrets, credentials, or guesses in permanent_profile. Preserve existing valid profile facts; do not invent anything.",
permanentMemory = currentProfile,
rollingSummary = existingSummary,
recentMessages = emptyList(),
currentUserMessage = "PREVIOUS SUMMARY:\n${existingSummary.ifBlank { "(none)" }}\n\nEXISTING PERMANENT PROFILE:\n${currentProfile.ifBlank { "(none)" }}\n\nOLDER MESSAGES:\n$transcript",
availableTools = emptyList()
)
val result = ProviderFactory.createProvider(context).generateResponse(request)
if (result.isFailure) return@withContext
val raw = result.getOrThrow().textReply
val json = raw.substringAfter("{", "").let { if (it.isBlank()) "" else "{$it" }
.substringBeforeLast("}", "").let { if (it.isBlank()) "" else "$it}" }
val parsed = try { JSONObject(json) } catch (_: Exception) { return@withContext }
val summary = parsed.optString("rolling_summary").trim()
val profile = parsed.optString("permanent_profile").trim()
if (summary.isBlank()) return@withContext

val existing = dao.getSummary()?.summaryText ?: ""
val merged = if (existing.isNotBlank()) {
"$existing\n$summaryBullets".takeLast(500)
} else {
summaryBullets
}
dao.insertOrUpdateSummary(ConversationSummaryEntity(
id = 1, summaryText = summary, lastSummarizedMessageId = older.last().id,
updatedAtMs = System.currentTimeMillis()
))
if (profile.isNotBlank() && profile != currentProfile) {
val existing = dao.getAllMemories().firstOrNull { it.key == "User Profile" }
if (existing == null) dao.insertMemory(MemoryEntity(key = "User Profile", content = profile))
else dao.updateMemory(existing.copy(content = profile, updatedAtMs = System.currentTimeMillis()))
}
dao.deleteMessagesUpTo(older.last().id)
persistJsonSnapshot()
}

dao.insertOrUpdateSummary(
ConversationSummaryEntity(
id = 1,
summaryText = merged,
lastSummarizedMessageId = olderMessages.last().id,
updatedAtMs = System.currentTimeMillis()
)
)
}
/** Persist summary plus the active transcript as readable JSON in app-private storage; this file mirrors Room's active memory state. */
suspend fun persistJsonSnapshot() = withContext(Dispatchers.IO) {
val root = JSONObject()
root.put("summarized", dao.getSummary()?.summaryText.orEmpty())
val array = org.json.JSONArray()
dao.getRecentMessages(200).reversed().forEach { msg ->
val item = JSONObject()
item.put("role", msg.sender)
item.put("content", msg.text)
item.put("timestamp", msg.timestamp)
if (!msg.toolName.isNullOrBlank()) item.put("tool", msg.toolName)
if (!msg.toolStatus.isNullOrBlank()) item.put("tool_status", msg.toolStatus)
array.put(item)
}
root.put("messages", array)
context.openFileOutput("sia_chat_memory.json", Context.MODE_PRIVATE).use {
it.write(root.toString(2).toByteArray(Charsets.UTF_8))
}
}

Expand Down
Loading
Loading