Skip to content

Commit f333279

Browse files
committed
Merge remote-tracking branch 'github/main' into feat/gitlab-overview-threads
# Conflicts: # apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx # packages/source-control-gitlab/src/server/GitLabPullRequestCli.test.ts # packages/source-control-gitlab/src/server/gitLabMergeRequestJson.ts
2 parents 567edcf + c52df24 commit f333279

200 files changed

Lines changed: 11382 additions & 1358 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.macroscope/ignore.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,3 +279,7 @@ native/libghostty-vt/include/**
279279
# it needs. Regenerated by apps/mobile/scripts/generate-highlights.mts; review
280280
# that script and cpp/t3_highlights.c instead.
281281
apps/mobile/modules/t3-highlights/Vendor/**
282+
283+
# Nitro bindings for T3Highlights. Regenerated by `vp run generate:nitro` in
284+
# apps/mobile from modules/t3-highlights/src/T3Highlights.nitro.ts.
285+
apps/mobile/modules/t3-highlights/nitrogen/generated/**

‎apps/mobile/.swiftlint.yml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
included:
22
- ios/T3Code
33
- modules/t3-composer-editor/ios
4-
- modules/t3-highlights/ios
54
- modules/t3-native-controls/ios
65
- modules/t3-terminal/ios
76
- modules/t3-review-diff/ios

‎apps/mobile/modules/t3-agent-notifications/android/src/main/java/expo/modules/t3agentnotifications/AgentActivityPresentation.kt‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ internal class ActivityPresentation(data: Map<String, String>, private val activ
126126

127127
fun applyTo(builder: NotificationCompat.Builder, context: Context) {
128128
val tint = phase?.let { ContextCompat.getColor(context, it.color) }
129-
builder.setSmallIcon(R.drawable.agent_activity_mark)
130129
if (tint != null) builder.setColor(tint)
131130
// Tint the summary only when it names an outcome or a request; a plain
132131
// "3 working" stays neutral so the accent keeps meaning something.

‎apps/mobile/modules/t3-agent-notifications/android/src/main/java/expo/modules/t3agentnotifications/AgentNotifications.kt‎

Lines changed: 51 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ object AgentNotifications {
127127
if (registered && fresh && NotificationManagerCompat.from(context).areNotificationsEnabled()) {
128128
channels(context)
129129
val scheme = prefs.getString("scheme", "t3code") ?: "t3code"
130-
showAlert(context, prefs, scheme, data)
131-
updateActivity(context, prefs, scheme, data, updatedAt)
130+
val alerted = showAlert(context, prefs, scheme, data)
131+
updateActivity(context, prefs, data, updatedAt, alerted)
132132
}
133133
}
134134

@@ -137,7 +137,7 @@ object AgentNotifications {
137137
prefs: SharedPreferences,
138138
scheme: String,
139139
data: Map<String, String>
140-
) {
140+
): Boolean {
141141
// Queue retries carry the same alert id. Keep a bounded history even when
142142
// notification A is retried after notification B has already arrived.
143143
val alertId = data["alert_id"]
@@ -157,7 +157,14 @@ object AgentNotifications {
157157
"seenAlertsOrdered",
158158
(seen.takeLast(63) + alertId).joinToString("\n")
159159
).apply()
160+
// Android drops posts to a blocked channel, so that alert shows nothing.
161+
return !onScreen && (
162+
Build.VERSION.SDK_INT < 26 ||
163+
manager(context).getNotificationChannel(ALERT_CHANNEL)?.importance !=
164+
NotificationManager.IMPORTANCE_NONE
165+
)
160166
}
167+
return false
161168
}
162169

163170
private fun postAlert(
@@ -215,12 +222,21 @@ object AgentNotifications {
215222
private fun updateActivity(
216223
context: Context,
217224
prefs: SharedPreferences,
218-
scheme: String,
219225
data: Map<String, String>,
220-
updatedAt: Long
226+
updatedAt: Long,
227+
alerted: Boolean
221228
) {
222-
if (updatedAt < prefs.getLong("lastUpdate", 0)) return
223-
prefs.edit().putLong("lastUpdate", updatedAt).apply()
229+
val terminal = singleTerminal(data)
230+
// Only a one-row card on the alert's own thread is known to show nothing more
231+
// than the alert. Grouped alerts and cards with other rows stay visible.
232+
val covered = terminal?.takeIf { alerted && data["alert_path"] == data["activity_path"] }
233+
if (covered != null) coverTerminal(prefs, covered, updatedAt)
234+
if (updatedAt < prefs.getLong("lastUpdate", 0)) {
235+
// A newer replay of this same finish may already show the card.
236+
if (isCovered(prefs, prefs.getString("lastTerminal", null))) cancelActivity(context)
237+
return
238+
}
239+
prefs.edit().putLong("lastUpdate", updatedAt).putString("lastTerminal", terminal).apply()
224240
val active = data["active"] == "true"
225241
// Use absolute state expiry: a replay must not extend a finished card or
226242
// make an abandoned host look active indefinitely. Older relays omit it.
@@ -237,11 +253,35 @@ object AgentNotifications {
237253
// Dismissing a run includes its finished card. A new run, or toggling
238254
// activity off/on, arms it again; terminal replays stay dismissed.
239255
if (active && !wasActive) prefs.edit().putBoolean("dismissed", false).apply()
240-
if (!prefs.getBoolean("dismissed", false)) {
256+
if (prefs.getBoolean("dismissed", false) || isCovered(prefs, terminal)) {
257+
cancelActivity(context)
258+
} else {
259+
val scheme = prefs.getString("scheme", "t3code") ?: "t3code"
241260
showActivity(context, scheme, data, active, remainingMs)
242261
}
243262
}
244263

264+
/** Identifies a finished one-thread card by its path, phase and absolute expiry. */
265+
private fun singleTerminal(data: Map<String, String>): String? {
266+
val phase = data["activity_phase"]
267+
val finished = phase == "completed" || phase == "failed"
268+
val single = data.containsKey("activity_line_0") && !data.containsKey("activity_line_1")
269+
val expiresAt = data["activity_expires_at"]
270+
return "${data["activity_path"]}\n$phase\n$expiresAt"
271+
.takeIf { finished && single && expiresAt != null }
272+
}
273+
274+
private fun isCovered(prefs: SharedPreferences, terminal: String?) =
275+
terminal != null && terminal == prefs.getString("coveredTerminal", null)
276+
277+
private fun coverTerminal(prefs: SharedPreferences, terminal: String?, updatedAt: Long) {
278+
if (updatedAt >= prefs.getLong("lastUpdate", 0) ||
279+
prefs.getString("lastTerminal", null) == terminal
280+
) {
281+
prefs.edit().putString("coveredTerminal", terminal).apply()
282+
}
283+
}
284+
245285
private fun showActivity(
246286
context: Context,
247287
scheme: String,
@@ -318,9 +358,8 @@ object AgentNotifications {
318358
}
319359
}
320360

321-
private fun base(context: Context, channel: String): NotificationCompat.Builder {
322-
val icon = context.resources.getIdentifier("notification_icon", "drawable", context.packageName)
323-
return NotificationCompat.Builder(context, channel)
361+
private fun base(context: Context, channel: String): NotificationCompat.Builder =
362+
NotificationCompat.Builder(context, channel)
324363
.setPriority(
325364
if (channel ==
326365
ALERT_CHANNEL
@@ -331,10 +370,9 @@ object AgentNotifications {
331370
}
332371
)
333372
.setDefaults(if (channel == ALERT_CHANNEL) Notification.DEFAULT_ALL else 0)
334-
.setSmallIcon(if (icon != 0) icon else android.R.drawable.ic_dialog_info)
373+
.setSmallIcon(R.drawable.agent_activity_mark)
335374
.setVisibility(NotificationCompat.VISIBILITY_PRIVATE)
336375
.setShowWhen(false)
337-
}
338376

339377
private fun contentIntent(
340378
context: Context,

‎apps/mobile/modules/t3-agent-notifications/android/src/test/java/expo/modules/t3agentnotifications/AgentNotificationsTest.kt‎

Lines changed: 97 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,10 @@ import org.robolectric.RuntimeEnvironment
2424
import org.robolectric.Shadows.shadowOf
2525
import org.robolectric.annotation.Config
2626

27-
@RunWith(RobolectricTestRunner::class)
28-
@Config(sdk = [24, 26, 33, 36], manifest = Config.NONE)
29-
class AgentNotificationsTest {
30-
private lateinit var context: Application
31-
private lateinit var manager: NotificationManager
32-
private lateinit var lifecycle: LifecycleRegistry
27+
abstract class AgentNotificationsFixture {
28+
protected lateinit var context: Application
29+
protected lateinit var manager: NotificationManager
30+
protected lateinit var lifecycle: LifecycleRegistry
3331

3432
@Before
3533
fun setUp() {
@@ -52,7 +50,7 @@ class AgentNotificationsTest {
5250
AgentNotifications.setThreadOnScreen("/threads/environment/thread")
5351
}
5452

55-
private fun update(alertId: String, active: Boolean) = mapOf(
53+
protected fun update(alertId: String, active: Boolean) = mapOf(
5654
"device_id" to "device",
5755
"user_id" to "user",
5856
"updated_at" to System.currentTimeMillis().toString(),
@@ -66,7 +64,11 @@ class AgentNotificationsTest {
6664
"alert_body" to "Done: Test project",
6765
"alert_path" to "/threads/environment/thread",
6866
)
67+
}
6968

69+
@RunWith(RobolectricTestRunner::class)
70+
@Config(sdk = [24, 26, 33, 36], manifest = Config.NONE)
71+
class AgentNotificationsTest : AgentNotificationsFixture() {
7072
@Test
7173
fun alertHistoryEvictsOnlyTheOldestEntryAfterCapacity() {
7274
lifecycle.currentState = Lifecycle.State.RESUMED
@@ -118,20 +120,6 @@ class AgentNotificationsTest {
118120
assertTrue(manager.activeNotifications.isEmpty())
119121
}
120122

121-
@Test
122-
fun backgroundCompletionAlertsAndClearsOngoingActivity() {
123-
lifecycle.currentState = Lifecycle.State.RESUMED
124-
AgentNotifications.receive(context, update("running", true))
125-
lifecycle.currentState = Lifecycle.State.CREATED
126-
127-
AgentNotifications.receive(context, update("completion", false))
128-
129-
val alert = manager.activeNotifications.single()
130-
assertEquals("t3-agent-alert", alert.tag)
131-
assertEquals("Test thread", alert.notification.extras.getString(Notification.EXTRA_TITLE))
132-
assertFalse(alert.notification.flags and Notification.FLAG_ONGOING_EVENT != 0)
133-
}
134-
135123
@Test
136124
fun retryOfForegroundSuppressedAlertDoesNotAppearAfterBackgrounding() {
137125
lifecycle.currentState = Lifecycle.State.RESUMED
@@ -313,21 +301,6 @@ class AgentNotificationsTest {
313301
assertTrue(manager.activeNotifications.isEmpty())
314302
}
315303

316-
@Test
317-
fun reorderedActivityDoesNotEraseNewerCardOrDropAnIndependentAlert() {
318-
val now = System.currentTimeMillis()
319-
AgentNotifications.receive(context, update("new", true) + ("updated_at" to now.toString()))
320-
AgentNotifications.receive(
321-
context,
322-
update("older-alert", false) + ("updated_at" to (now - 1000).toString())
323-
)
324-
assertEquals(4, manager.activeNotifications.size)
325-
assertEquals(1, manager.activeNotifications.count { it.tag == "t3-agent-activity" })
326-
shadowOf(manager).setNotificationsEnabled(false)
327-
AgentNotifications.receive(context, update("revoked-permission", true))
328-
assertEquals(4, manager.activeNotifications.size)
329-
}
330-
331304
@Test
332305
fun severalThreadsListEveryRowWithItsStatusAndActionsFollowThePriorityThread() {
333306
lifecycle.currentState = Lifecycle.State.RESUMED
@@ -661,3 +634,91 @@ class AgentNotificationsTest {
661634
assertEquals(2, manager.activeNotifications.size)
662635
}
663636
}
637+
638+
@RunWith(RobolectricTestRunner::class)
639+
@Config(sdk = [24, 26, 33, 36], manifest = Config.NONE)
640+
class AgentNotificationsCompletionTest : AgentNotificationsFixture() {
641+
private fun finished(alertId: String, expiresAt: Long) = update(alertId, false) + mapOf(
642+
"activity_line_0" to "Done\tTest thread\tTest project",
643+
"activity_phase" to "completed",
644+
"activity_expires_at" to expiresAt.toString(),
645+
)
646+
647+
@Test
648+
fun backgroundCompletionAlertsAndClearsOngoingActivity() {
649+
lifecycle.currentState = Lifecycle.State.RESUMED
650+
AgentNotifications.receive(context, update("running", true))
651+
lifecycle.currentState = Lifecycle.State.CREATED
652+
653+
val expiresAt = System.currentTimeMillis() + 900000
654+
val completion = finished("completion", expiresAt)
655+
AgentNotifications.receive(context, completion)
656+
AgentNotifications.receive(context, completion)
657+
AgentNotifications.receive(context, completion.filterKeys { !it.startsWith("alert_") })
658+
659+
val alert = manager.activeNotifications.single()
660+
assertEquals("t3-agent-alert", alert.tag)
661+
assertEquals("Test thread", alert.notification.extras.getString(Notification.EXTRA_TITLE))
662+
assertFalse(alert.notification.flags and Notification.FLAG_ONGOING_EVENT != 0)
663+
AgentNotifications.receive(context, update("next-run", true))
664+
assertEquals(1, manager.activeNotifications.count { it.tag == "t3-agent-activity" })
665+
666+
// An alert for another thread, or a card that also lists another result, stays.
667+
AgentNotifications.receive(
668+
context,
669+
finished("other-thread", expiresAt + 60000) + ("alert_path" to "/threads/other/thread")
670+
)
671+
assertEquals(1, manager.activeNotifications.count { it.tag == "t3-agent-activity" })
672+
AgentNotifications.receive(
673+
context,
674+
finished("with-muted-result", expiresAt + 120000) +
675+
("activity_line_1" to "Done\tMuted thread\tOther project")
676+
)
677+
assertEquals(1, manager.activeNotifications.count { it.tag == "t3-agent-activity" })
678+
}
679+
680+
@Test
681+
@Config(sdk = [26, 33, 36])
682+
fun blockedAlertChannelKeepsTheFinishedCard() {
683+
manager.getNotificationChannel("agent-alerts").importance = NotificationManager.IMPORTANCE_NONE
684+
AgentNotifications.receive(
685+
context,
686+
finished("completion", System.currentTimeMillis() + 900000)
687+
)
688+
assertEquals(1, manager.activeNotifications.count { it.tag == "t3-agent-activity" })
689+
}
690+
691+
@Test
692+
fun reorderedActivityDoesNotEraseNewerCardOrDropAnIndependentAlert() {
693+
val now = System.currentTimeMillis()
694+
AgentNotifications.receive(context, update("new", true) + ("updated_at" to now.toString()))
695+
AgentNotifications.receive(
696+
context,
697+
finished("older-alert", now + 900000) + ("updated_at" to (now - 1000).toString())
698+
)
699+
assertEquals(4, manager.activeNotifications.size)
700+
assertEquals(1, manager.activeNotifications.count { it.tag == "t3-agent-activity" })
701+
// A newer replay of a finish can show its card before the original alert lands.
702+
val finish = finished("finish", now + 960000)
703+
AgentNotifications.receive(
704+
context,
705+
finish.filterKeys { !it.startsWith("alert_") } + ("updated_at" to (now + 2000).toString())
706+
)
707+
assertEquals(1, manager.activeNotifications.count { it.tag == "t3-agent-activity" })
708+
AgentNotifications.receive(context, finish + ("updated_at" to (now + 1000).toString()))
709+
assertTrue(manager.activeNotifications.none { it.tag == "t3-agent-activity" })
710+
assertTrue(manager.activeNotifications.any { it.id == "finish".hashCode() })
711+
AgentNotifications.receive(
712+
context,
713+
finished("previous-run", now + 900000) + ("updated_at" to now.toString())
714+
)
715+
AgentNotifications.receive(
716+
context,
717+
finish.filterKeys { !it.startsWith("alert_") } + ("updated_at" to (now + 3000).toString())
718+
)
719+
assertTrue(manager.activeNotifications.none { it.tag == "t3-agent-activity" })
720+
shadowOf(manager).setNotificationsEnabled(false)
721+
AgentNotifications.receive(context, update("revoked-permission", true))
722+
assertEquals(5, manager.activeNotifications.size)
723+
}
724+
}

‎apps/mobile/modules/t3-composer-editor/android/src/main/java/expo/modules/t3composereditor/T3ComposerEditorView.kt‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import android.os.Build
1212
import android.text.Editable
1313
import android.text.InputType
1414
import android.text.InputFilter
15+
import android.text.Layout
1516
import android.text.Spanned
1617
import android.text.TextUtils
1718
import android.text.TextWatcher
@@ -22,6 +23,7 @@ import android.view.Gravity
2223
import android.view.GestureDetector
2324
import android.view.MotionEvent
2425
import android.view.KeyEvent
26+
import android.view.View
2527
import android.view.ViewGroup
2628
import android.view.inputmethod.EditorInfo
2729
import android.view.inputmethod.InputConnection
@@ -32,6 +34,7 @@ import expo.modules.kotlin.AppContext
3234
import expo.modules.kotlin.viewevent.EventDispatcher
3335
import expo.modules.kotlin.views.ExpoView
3436
import org.json.JSONObject
37+
import kotlin.math.ceil
3538
import kotlin.math.max
3639

3740
class T3ComposerEditorView(context: Context, appContext: AppContext) : ExpoView(
@@ -435,7 +438,7 @@ class T3ComposerEditorView(context: Context, appContext: AppContext) : ExpoView(
435438
// wrapping it, so getLineMax leaves it out.
436439
val layout = editor.layout
437440
val contentHeight = layout?.height ?: editor.measuredHeight
438-
val contentWidth = if (layout?.lineCount == 1) layout.getLineMax(0).toInt() else 0
441+
val contentWidth = singleLineContentWidth(layout)
439442
if (contentHeight == lastContentHeight && contentWidth == lastContentWidth) return
440443
lastContentHeight = contentHeight
441444
lastContentWidth = contentWidth
@@ -497,6 +500,11 @@ class T3ComposerEditorView(context: Context, appContext: AppContext) : ExpoView(
497500
}
498501
}
499502

503+
// Round up: a truncated width can match a slot the line overflows, and the composer
504+
// then flips between its compact and expanded rows.
505+
internal fun singleLineContentWidth(layout: Layout?): Int =
506+
if (layout?.lineCount == 1) ceil(layout.getLineMax(0)).toInt() else 0
507+
500508
private fun Int.withAlpha(alpha: Int): Int = (this and 0x00FFFFFF) or (alpha shl 24)
501509

502510
private fun Context.resolveThemeColor(attribute: Int, fallback: Int): Int {
@@ -589,6 +597,9 @@ internal class SelectionAwareEditText(
589597
var maxInputChars = Int.MAX_VALUE
590598
var clipboardFragment = ""
591599

600+
// Keeps autofill services such as SMS verification codes from writing into the draft.
601+
override fun getAutofillType(): Int = View.AUTOFILL_TYPE_NONE
602+
592603
/**
593604
* Editable TextView hints do not ellipsize, so long placeholders wrap and grow the composer.
594605
* Truncate the hint to the measured width instead.

0 commit comments

Comments
 (0)