feat(studio): coordinate integrated AI activity and internal language services
Start project-owned language and authenticated MCP services when opening a project, reusing the embedded LSP backend without a desktop TCP listener. Keep editor overlays separate from saved-file MCP queries. Reserve conflicting editing before ACP prompt delivery and retain protection through native/tool termination, runtime cleanup and document refresh. Preserve drafts on rejected admission, provide cleanup/preparation recovery, distinguish terminal outcomes and redact permission previews. Add lifecycle, language parity, activity, composition and UI regressions and update the canonical Studio contracts. Keep distribution update alignment as the separate WRK-002A follow-up. Validation: complete make -C tooling verify PASSED in 20261127T035822Z-ec5d9266 (1172 unit, 131 compiler fixture, 31 headless tests). Opt-in real-model and native AI-view qualification are outside that gate. Work: WRK-0029; decision: DEC-0001.
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import java.time.Duration
|
||||
|
||||
plugins {
|
||||
id("gradle.java-application-conventions")
|
||||
alias(libs.plugins.javafx)
|
||||
@@ -59,3 +61,17 @@ tasks.register<Test>("desktopTest") {
|
||||
outputs.upToDateWhen { false }
|
||||
testLogging.showStandardStreams = true
|
||||
}
|
||||
|
||||
|
||||
tasks.register<Test>("aiWorkspaceDesktopTest") {
|
||||
group = "verification"
|
||||
description = "Checks the actual AI project view and recovery labels with a controlled agent (requires a desktop)."
|
||||
testClassesDirs = sourceSets["test"].output.classesDirs
|
||||
classpath = sourceSets["test"].runtimeClasspath
|
||||
useJUnitPlatform()
|
||||
include("**/AiWorkspaceDesktopTest.class")
|
||||
systemProperty("java.awt.headless", "false")
|
||||
systemProperty("javafx.cachedir", layout.buildDirectory.dir("javafx-test-cache").get().asFile.absolutePath)
|
||||
timeout.set(Duration.ofSeconds(60))
|
||||
outputs.upToDateWhen { false }
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ final class AgentChats implements AutoCloseable {
|
||||
boolean busy(){return running!=null;}
|
||||
boolean running(long id){return Objects.equals(running,id);}
|
||||
String runningTitle(){return running==null?"":drafts.chats().stream().filter(c->c.id()==running).map(LocalChats.Chat::title).findFirst().orElse("");}
|
||||
boolean canSend(long id){return !closing&&!closed&&!busy()&&agent.available()&&agent.status().state()==AgentConnection.State.READY
|
||||
boolean canSend(long id){return !closing&&!closed&&!busy()&&!agent.busy()&&agent.servicesReady()&&agent.available()&&agent.status().state()==AgentConnection.State.READY
|
||||
&&!entry(id).invalid&&!drafts.draft(id).isBlank();}
|
||||
Conversation conversation(long id){return entry(id).conversation;}
|
||||
String activity(long id){return entry(id).invalid?text.apply("ai.session.expired"):entry(id).activity;}
|
||||
@@ -95,8 +95,13 @@ final class AgentChats implements AutoCloseable {
|
||||
private void finish(long id,String stop,Throwable failure){
|
||||
if(closed||!Objects.equals(running,id))return;
|
||||
var chat=entry(id);
|
||||
chat.activity=failure==null?text.apply("cancelled".equals(stop)?"ai.cancelled":"ai.done"):text.apply("ai.error")+": "+failureMessage(failure);
|
||||
chat.conversation.finish(failure!=null?"error":"cancelled".equals(stop)?"cancelled":"done",failure==null?"":failureMessage(failure));
|
||||
String outcome=failure!=null?"error":switch(Objects.toString(stop,"unknown")){
|
||||
case "end_turn" -> "done";case "cancelled" -> "cancelled";
|
||||
case "max_tokens","max_turn_requests" -> "limited";case "refusal" -> "refused";
|
||||
default -> "interrupted";
|
||||
};
|
||||
chat.activity=failure==null?text.apply("ai."+outcome):text.apply("ai.error")+": "+failureMessage(failure);
|
||||
chat.conversation.finish(outcome,failure==null?Objects.toString(stop,""):failureMessage(failure));
|
||||
running=null;cancelling=false;
|
||||
var done=settled;changed.run();done.complete(null);
|
||||
}
|
||||
|
||||
@@ -57,7 +57,11 @@ public final class AiWorkspace extends SplitPane implements AutoCloseable {
|
||||
private boolean deleting;
|
||||
private boolean closed;
|
||||
private boolean synchronizing;
|
||||
private final ChangeListener<Tab> selection = (o, before, after) -> placeComposer();
|
||||
private final ChangeListener<Tab> selection = (o, before, after) -> selectionChanged(after);
|
||||
private void selectionChanged(Tab after) {
|
||||
if(execution!=null&&(execution.busy()||agent.busy())&&after!=ai){tabs.getSelectionModel().select(ai);return;}
|
||||
placeComposer();
|
||||
}
|
||||
private final ChangeListener<LocalChats.Chat> chatSelection = (o, before, after) -> {
|
||||
if (!synchronizing && !closed) {
|
||||
if (after != null) {
|
||||
@@ -135,6 +139,8 @@ public final class AiWorkspace extends SplitPane implements AutoCloseable {
|
||||
});
|
||||
cancel=actionButton("ai.cancel","ai-cancel",this::cancelTurn);
|
||||
recover=actionButton("ai.recover","ai-recover",this::recover);
|
||||
// refreshAgent owns this localized label as the recovery action changes.
|
||||
recover.textProperty().unbind();
|
||||
var commands = new HBox(8, unavailableButton("ai.attach", "ai-attach"), recover, spacer, cancel, send);
|
||||
commands.setAlignment(Pos.CENTER_LEFT);
|
||||
composer.setId("ai-composer");
|
||||
@@ -296,6 +302,11 @@ public final class AiWorkspace extends SplitPane implements AutoCloseable {
|
||||
private void send(){var chat=chats.active();if(chat!=null)execution.send(chat.id());}
|
||||
private void cancelTurn(){cancelPermissions();execution.cancel();}
|
||||
private void recover(){
|
||||
if((agent.busy()||!agent.servicesReady())&&!execution.busy()){
|
||||
agent.recoverActivity().whenComplete((v,f)->Platform.runLater(()->{
|
||||
if(!closed){refreshAgent();if(f!=null)activity.setText(AgentChats.failureMessage(f));}
|
||||
}));return;
|
||||
}
|
||||
var chat=chats.active();if(chat!=null&&chats.draft().isBlank())chats.write(execution.lastRequest(chat.id()));
|
||||
refreshSelection();focusPrompt();
|
||||
}
|
||||
@@ -315,7 +326,12 @@ public final class AiWorkspace extends SplitPane implements AutoCloseable {
|
||||
var chat=chats.active();
|
||||
send.setDisable(chat==null||deleting||!execution.canSend(chat.id()));
|
||||
cancel.setDisable(!execution.busy());
|
||||
recover.setDisable(chat==null||!chats.draft().isBlank()||execution.lastRequest(chat.id()).isBlank());
|
||||
boolean cleanup=(agent.busy()||!agent.servicesReady())&&!execution.busy();
|
||||
recover.setText(context.text(cleanup?(agent.busy()?"ai.cleanup":"ai.tools.retry"):"ai.recover"));
|
||||
recover.setDisable(!cleanup&&(chat==null||!chats.draft().isBlank()||execution.lastRequest(chat.id()).isBlank()));
|
||||
boolean protectedActivity=execution.busy()||agent.busy();
|
||||
for(var tab:tabs.getTabs())if(tab!=ai)tab.setDisable(protectedActivity);
|
||||
if(protectedActivity)tabs.getSelectionModel().select(ai);
|
||||
transcript.show(chat==null?null:execution.conversation(chat.id()));
|
||||
activity.setText(chat==null?"":execution.activity(chat.id()));
|
||||
var status=agent.status();
|
||||
|
||||
+1
-1
@@ -162,7 +162,7 @@ public final class StudioConversation extends BorderPane implements AutoCloseabl
|
||||
}
|
||||
private void refreshFooter(){var footer=getBottom();boolean show=!view.following&&view.unread;footer.setVisible(show);footer.setManaged(show);}
|
||||
private String state(String value){return context.text("conversation.state."+switch(value){
|
||||
case "sending","sent","failed","cancelled","streaming","pending","in_progress","completed","interrupted","done","error" -> value;
|
||||
case "sending","sent","failed","cancelled","streaming","pending","in_progress","completed","interrupted","done","error","limited","refused" -> value;
|
||||
default -> "unknown";
|
||||
});}
|
||||
|
||||
|
||||
+6
-3
@@ -374,6 +374,9 @@ public final class StudioWindowCoordinator2 implements AutoCloseable {
|
||||
gameplay=new Tab(c.text("gameplay.title"),split);gameplay.setId("gameplay-tab");gameplay.setClosable(false);
|
||||
tabs=new StudioTabs(gameplay);tabs.setId("project-tabs");
|
||||
agent=agentConnections.create(ref.rootPath());
|
||||
var projectAgent=agent;
|
||||
var agentState=agent.observe(status->Platform.runLater(()->{if(!closed&&agent==projectAgent)refresh();}));
|
||||
c.onClose(()->{try{agentState.close();}catch(Exception ignored){}});
|
||||
aiWorkspace=new AiWorkspace(c,tabs,()->resources.child(c),agent);
|
||||
var statusFooter=new TabStatusFooter(tabs);
|
||||
var gameplayInfo=Bindings.createStringBinding(()->viewport.scale()>0?
|
||||
@@ -403,7 +406,7 @@ public final class StudioWindowCoordinator2 implements AutoCloseable {
|
||||
shell.workspace().getChildren().setAll(workspaceScroll);lastLog=-1;refresh();
|
||||
}
|
||||
private void play(){
|
||||
if(busy||closing||controller!=null&&controller.ownsExecution())return;
|
||||
if(busy||closing||agent!=null&&agent.busy()||controller!=null&&controller.ownsExecution())return;
|
||||
var original=localSetup;var ref=project.projectReference();boolean discard=ref.memcardSlots()!=null&&disposableSave;
|
||||
if(ref.memcardSlots()!=null&&!discard&&(original.memcardPath()==null||original.memcardPath().isBlank())){
|
||||
configurationNeeded(context.text("play.memcard.required"),false,true);return;
|
||||
@@ -445,12 +448,12 @@ public final class StudioWindowCoordinator2 implements AutoCloseable {
|
||||
var snapshot=project.executionSession().snapshot();var state=snapshot.state();boolean owned=controller!=null&&controller.ownsExecution();
|
||||
if(diagnostics!=null)diagnostics.show(snapshot.diagnostics());
|
||||
play.setText(context.text(owned?"play.stop":"play.start"));play.setAccessibleText(play.getText());
|
||||
play.setDisable(busy||closing||state==ExecutionState.STOPPING);
|
||||
play.setDisable(busy||closing||agent!=null&&agent.busy()||state==ExecutionState.STOPPING);
|
||||
pause.setDisable(busy||closing||state!=ExecutionState.RUNNING&&state!=ExecutionState.PAUSED);
|
||||
pause.setSelected(state==ExecutionState.PAUSED||state==ExecutionState.PAUSING);
|
||||
pause.setText(context.text(state==ExecutionState.PAUSED?"play.resume":"play.pause"));pause.setAccessibleText(pause.getText());
|
||||
if(closeProject!=null)closeProject.setDisable(closing||busy);
|
||||
if(projectSettings!=null)projectSettings.setDisable(closing||busy||owned);
|
||||
if(projectSettings!=null)projectSettings.setDisable(closing||busy||owned||agent!=null&&agent.busy());
|
||||
if(displayedState!=state){displayedState=state;
|
||||
stateLabel.setText(viewContext.text("state."+state.name())+(owned&&disposableSave?" · "+context.text("play.disposable.short"):""));
|
||||
play.getTooltip().hide();pause.getTooltip().hide();
|
||||
|
||||
+8
@@ -243,3 +243,11 @@ diagnostic.source.sdk=SDK
|
||||
diagnostic.source.generated=generated source
|
||||
diagnostic.source.source=source
|
||||
diagnostic.source.dependency=dependency source
|
||||
|
||||
ai.limited=Agent limit reached
|
||||
ai.refused=Request refused
|
||||
ai.interrupted=Stopped with an unconfirmed outcome
|
||||
ai.cleanup=Retry project cleanup
|
||||
conversation.state.limited=Limit reached
|
||||
conversation.state.refused=Refused
|
||||
ai.tools.retry=Retry Studio tools
|
||||
|
||||
+8
@@ -243,3 +243,11 @@ diagnostic.source.sdk=SDK
|
||||
diagnostic.source.generated=fonte gerado
|
||||
diagnostic.source.source=fonte
|
||||
diagnostic.source.dependency=fonte de dependência
|
||||
|
||||
ai.limited=Limite do agente atingido
|
||||
ai.refused=Solicitação recusada
|
||||
ai.interrupted=Interrompido com resultado não confirmado
|
||||
ai.cleanup=Tentar finalizar o projeto
|
||||
conversation.state.limited=Limite atingido
|
||||
conversation.state.refused=Recusado
|
||||
ai.tools.retry=Verificar ferramentas do Studio
|
||||
|
||||
@@ -64,4 +64,15 @@ class AgentChatsTest {
|
||||
var close=m.closeAgent();assertFalse(m.canSend(b.id()));agent.cancelled.completeExceptionally(new IllegalStateException("close failed"));
|
||||
assertTrue(close.toCompletableFuture().isCompletedExceptionally());assertTrue(m.canSend(b.id()));
|
||||
}
|
||||
@Test void stopReasonsPreserveLimitedRefusedAndInterruptedOutcomes() {
|
||||
var reasons=Map.of("end_turn","done","cancelled","cancelled","max_tokens","limited",
|
||||
"max_turn_requests","limited","refusal","refused","future_reason","interrupted");
|
||||
for(var reason:reasons.entrySet()) {
|
||||
var drafts=new LocalChats();var chat=drafts.create();drafts.write("request");
|
||||
var agent=new Agent();var m=model(drafts,agent);m.send(chat.id());agent.ack.complete(null);agent.done.complete(reason.getKey());
|
||||
var terminal=m.conversation(chat.id()).items().getLast();
|
||||
assertEquals(reason.getValue(),terminal.state());assertTrue(terminal.text().contains(reason.getKey()));assertFalse(m.busy());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
package p.studio.ui.javafx2.ai;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.stage.Stage;
|
||||
import org.junit.jupiter.api.*;
|
||||
import p.studio.api.ai.*;
|
||||
import p.studio.ui.javafx2.appearance.*;
|
||||
import p.studio.ui.javafx2.i18n.*;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.function.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/** Actual project AI view and controls; controlled agent, no model or personal preference writes. */
|
||||
@Tag("integration")
|
||||
class AiWorkspaceDesktopTest {
|
||||
private static boolean toolkitStarted;
|
||||
@BeforeAll static void startToolkit() throws Exception {
|
||||
var ready=new CompletableFuture<Void>();
|
||||
Thread.ofPlatform().daemon().name("ai-view-test-startup").start(()->{
|
||||
try{Platform.startup(()->ready.complete(null));}catch(Throwable failure){ready.completeExceptionally(failure);}
|
||||
});
|
||||
ready.get(15,TimeUnit.SECONDS);toolkitStarted=true;Platform.setImplicitExit(false);
|
||||
}
|
||||
@AfterAll static void stopToolkit(){if(toolkitStarted)Platform.exit();}
|
||||
static <T>T fx(Callable<T> action) throws Exception {
|
||||
var task=new FutureTask<>(action);Platform.runLater(task);return task.get(15,TimeUnit.SECONDS);
|
||||
}
|
||||
@Test void projectViewOpensAndRecoveryLabelsFollowReadinessActivityAndLanguage() throws Exception {
|
||||
var agent=new Peer();
|
||||
var window=fx(()->{
|
||||
var context=new AppearanceContext(PresentationSettings.defaults(Locale.ENGLISH),Messages.load(s->fail(s)),
|
||||
FontResources.load(s->fail(s)),value->{});
|
||||
var tabs=new TabPane(new Tab("Gameplay"));
|
||||
var view=new AiWorkspace(context,tabs,()->context,agent);
|
||||
context.attach(view);
|
||||
var stage=new Stage();stage.setScene(new Scene(view,1000,700));stage.show();
|
||||
return new Window(stage,context,view);
|
||||
});
|
||||
try {
|
||||
for(var language:StudioLanguage.values()) {
|
||||
fx(()->{window.context.update(window.context.settings().withLanguage(language));return null;});
|
||||
fx(()->{
|
||||
var button=(Button)window.view.lookup("#ai-recover");assertNotNull(button);
|
||||
assertEquals(window.context.text("ai.recover"),button.getText());return null;
|
||||
});
|
||||
fx(()->{agent.ready=false;agent.changed();return null;});
|
||||
fx(()->{
|
||||
var button=(Button)window.view.lookup("#ai-recover");
|
||||
assertEquals(window.context.text("ai.tools.retry"),button.getText());assertFalse(button.isDisabled());
|
||||
button.fire();assertEquals(1,agent.recoveries);agent.recoveries=0;return null;
|
||||
});
|
||||
fx(()->{agent.occupied=true;agent.changed();return null;});
|
||||
fx(()->{
|
||||
assertEquals(window.context.text("ai.cleanup"),((Button)window.view.lookup("#ai-recover")).getText());return null;
|
||||
});
|
||||
fx(()->{agent.occupied=false;agent.ready=true;agent.changed();return null;});
|
||||
fx(()->{
|
||||
assertEquals(window.context.text("ai.recover"),((Button)window.view.lookup("#ai-recover")).getText());return null;
|
||||
});
|
||||
}
|
||||
} finally {fx(()->{window.view.close();window.context.close();window.stage.close();return null;});}
|
||||
}
|
||||
record Window(Stage stage,AppearanceContext context,AiWorkspace view){}
|
||||
static final class Peer implements AgentConnection {
|
||||
boolean ready=true,occupied;int recoveries;Consumer<Status> observer=s->{};
|
||||
public boolean available(){return true;}public boolean servicesReady(){return ready;}public boolean busy(){return occupied;}
|
||||
public Status status(){return new Status(State.READY,"");}
|
||||
public AutoCloseable observe(Consumer<Status> listener){observer=listener;listener.accept(status());return ()->observer=s->{};}
|
||||
void changed(){observer.accept(status());}
|
||||
public void events(Consumer<Event> listener){}public void permissions(Function<Permission,CompletionStage<String>> handler){}
|
||||
public CompletionStage<Void> connect(AcpSettings settings){return CompletableFuture.completedFuture(null);}
|
||||
public CompletionStage<Void> login(){throw new AssertionError("No login in UI fixture");}
|
||||
public CompletionStage<String> newSession(){throw new AssertionError("No prompt in UI fixture");}
|
||||
public Turn prompt(String id,String text){throw new AssertionError("No model in UI fixture");}
|
||||
public CompletionStage<Void> cancel(String id){return CompletableFuture.completedFuture(null);}
|
||||
public CompletionStage<Void> recoverActivity(){recoveries++;return CompletableFuture.completedFuture(null);}
|
||||
public CompletionStage<Void> closeAsync(){return CompletableFuture.completedFuture(null);}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user