@@ -398,6 +398,116 @@ export const GenericTool: AppStory = {
398398 } ,
399399} ;
400400
401+ /** Shows auto-compact warning when context usage approaches threshold */
402+ export const AutoCompactWarning : AppStory = {
403+ render : ( ) => (
404+ < AppWithMocks
405+ setup = { ( ) =>
406+ setupSimpleChatStory ( {
407+ workspaceId : "ws-compaction-warning" ,
408+ messages : [
409+ createUserMessage ( "msg-1" , "Help me set up authentication for this app" , {
410+ historySequence : 1 ,
411+ timestamp : STABLE_TIMESTAMP - 600000 ,
412+ } ) ,
413+ createAssistantMessage (
414+ "msg-2" ,
415+ "I'll help you set up authentication. Let me first examine your current project structure and dependencies." ,
416+ {
417+ historySequence : 2 ,
418+ timestamp : STABLE_TIMESTAMP - 580000 ,
419+ toolCalls : [
420+ createFileReadTool (
421+ "call-1" ,
422+ "package.json" ,
423+ '{\n "name": "my-app",\n "dependencies": {\n "express": "^4.18.0",\n "mongoose": "^7.0.0"\n }\n}'
424+ ) ,
425+ ] ,
426+ }
427+ ) ,
428+ createUserMessage ( "msg-3" , "I want to use JWT tokens for the auth" , {
429+ historySequence : 3 ,
430+ timestamp : STABLE_TIMESTAMP - 500000 ,
431+ } ) ,
432+ createAssistantMessage (
433+ "msg-4" ,
434+ "Great choice! I'll implement JWT-based authentication. Let me create the auth middleware and user routes." ,
435+ {
436+ historySequence : 4 ,
437+ timestamp : STABLE_TIMESTAMP - 480000 ,
438+ toolCalls : [
439+ createFileEditTool (
440+ "call-2" ,
441+ "src/middleware/auth.ts" ,
442+ "+ import jwt from 'jsonwebtoken';\n+ export const authenticate = (req, res, next) => {\n+ const token = req.headers.authorization?.split(' ')[1];\n+ // ... verification logic\n+ };"
443+ ) ,
444+ ] ,
445+ }
446+ ) ,
447+ createUserMessage ( "msg-5" , "Add password hashing too" , {
448+ historySequence : 5 ,
449+ timestamp : STABLE_TIMESTAMP - 400000 ,
450+ } ) ,
451+ createAssistantMessage (
452+ "msg-6" ,
453+ "I'll add bcrypt for secure password hashing. Here's the updated user model with password hashing on save." ,
454+ {
455+ historySequence : 6 ,
456+ timestamp : STABLE_TIMESTAMP - 380000 ,
457+ toolCalls : [
458+ createTerminalTool ( "call-3" , "bun add bcrypt" , "added bcrypt@5.1.0" ) ,
459+ createFileEditTool (
460+ "call-4" ,
461+ "src/models/user.ts" ,
462+ "+ import bcrypt from 'bcrypt';\n+ userSchema.pre('save', async function() {\n+ this.password = await bcrypt.hash(this.password, 10);\n+ });"
463+ ) ,
464+ ] ,
465+ }
466+ ) ,
467+ createUserMessage ( "msg-7" , "Now add refresh token support" , {
468+ historySequence : 7 ,
469+ timestamp : STABLE_TIMESTAMP - 300000 ,
470+ } ) ,
471+ createAssistantMessage (
472+ "msg-8" ,
473+ "I've implemented refresh token support with secure rotation. The access token expires in 15 minutes and the refresh token in 7 days." ,
474+ {
475+ historySequence : 8 ,
476+ timestamp : STABLE_TIMESTAMP - 280000 ,
477+ // High context usage to trigger warning (65% of 200k)
478+ contextUsage : { inputTokens : 130000 , outputTokens : 5000 , totalTokens : 135000 } ,
479+ }
480+ ) ,
481+ ] ,
482+ } )
483+ }
484+ />
485+ ) ,
486+ play : async ( { canvasElement } : { canvasElement : HTMLElement } ) => {
487+ const canvas = within ( canvasElement ) ;
488+
489+ // Wait for last assistant message to render (unique text from assistant)
490+ await waitFor ( ( ) => {
491+ canvas . getByText ( / a c c e s s t o k e n e x p i r e s i n 1 5 m i n u t e s / ) ;
492+ } ) ;
493+
494+ // Wait a bit for auto-scroll to settle, then scroll up
495+ await new Promise ( ( r ) => setTimeout ( r , 100 ) ) ;
496+ const messageWindow = canvasElement . querySelector ( '[data-testid="message-window"]' ) ;
497+ if ( messageWindow ) {
498+ messageWindow . scrollTop = messageWindow . scrollHeight - messageWindow . clientHeight - 150 ;
499+ }
500+ } ,
501+ parameters : {
502+ docs : {
503+ description : {
504+ story :
505+ "Displays the auto-compact warning indicator above the chat input when context usage is approaching the compaction threshold. The indicator shows remaining headroom and is clickable to insert /compact command." ,
506+ } ,
507+ } ,
508+ } ,
509+ } ;
510+
401511/** Streaming compaction with shimmer effect - tests GPU-accelerated animation */
402512export const StreamingCompaction : AppStory = {
403513 render : ( ) => (
0 commit comments