feat(studio): integrate project MCP setup and lifecycle
This commit is contained in:
@@ -4,6 +4,7 @@ import lombok.Getter;
|
||||
|
||||
public enum I18n {
|
||||
WORKSPACE_DEV("workspace.dev"),
|
||||
DEV_MCP_WAITING("dev.mcpWaiting"), DEV_MCP_CONNECTED("dev.mcpConnected"), DEV_MCP_RECONNECTING("dev.mcpReconnecting"),
|
||||
DEV_GRANT("dev.grant"), DEV_RECLAIM("dev.reclaim"), DEV_COPY_CONFIG("dev.copyConfig"),
|
||||
DEV_MCP_UNAVAILABLE("dev.mcpUnavailable"), DEV_EXTERNAL_WARNING("dev.externalWarning"),
|
||||
DEV_MCP_INSTRUCTIONS("dev.mcpInstructions"), DEV_CONFIG_COPIED("dev.configCopied"), DEV_CONFIG_FAILED("dev.configFailed"),
|
||||
|
||||
+27
-16
@@ -33,6 +33,7 @@ public final class DevWorkspace extends Workspace {
|
||||
private OperationSubscription subscription;
|
||||
private long generation;
|
||||
private CanonicalCapture rendered;
|
||||
private boolean preparing;
|
||||
private final javafx.beans.value.ChangeListener<java.util.Locale> localeListener;
|
||||
|
||||
public DevWorkspace(ProjectReference project, AutomationSession automation, I18nService i18n, StudioEventBus events) {
|
||||
@@ -53,7 +54,7 @@ public final class DevWorkspace extends Workspace {
|
||||
reclaim.setOnAction(e -> automation.reclaim());
|
||||
configuration.setId("dev-mcp-config");
|
||||
configuration.textProperty().bind(i18n.bind(I18n.DEV_COPY_CONFIG));
|
||||
configuration.setOnAction(e -> copyConfiguration());
|
||||
configuration.setOnAction(e -> prepareConfiguration());
|
||||
availability.setId("dev-mcp-endpoint"); availability.setWrapText(true);
|
||||
copyStatus.setId("dev-mcp-copy-status");
|
||||
Label instructions = new Label(); instructions.setWrapText(true);
|
||||
@@ -82,12 +83,17 @@ public final class DevWorkspace extends Workspace {
|
||||
if (subscription != null) return;
|
||||
i18n.localeProperty().addListener(localeListener);
|
||||
long subscribed = ++generation;
|
||||
java.util.concurrent.CompletableFuture.supplyAsync(() -> connectionGuide.preparationStatus(projectRoot))
|
||||
.whenComplete((result, failure) -> Platform.runLater(() -> {
|
||||
if (generation == subscribed && !preparing && copyStatus.getText().isEmpty())
|
||||
copyStatus.setText(failure == null ? result.message() : i18n.text(I18n.DEV_CONFIG_FAILED));
|
||||
}));
|
||||
subscription = automation.subscribe(snapshot -> {
|
||||
Runnable update = () -> { if (generation == subscribed) apply(snapshot); };
|
||||
if (Platform.isFxApplicationThread()) update.run(); else Platform.runLater(update);
|
||||
});
|
||||
connectionSubscription = connectionGuide.subscribe(() -> {
|
||||
Runnable update = () -> { if (generation == subscribed) { copyStatus.setText(""); updateConnection(); } };
|
||||
Runnable update = () -> { if (generation == subscribed) { updateConnection(); } };
|
||||
if (Platform.isFxApplicationThread()) update.run(); else Platform.runLater(update);
|
||||
});
|
||||
}
|
||||
@@ -127,20 +133,25 @@ public final class DevWorkspace extends Workspace {
|
||||
}
|
||||
}
|
||||
private void updateConnection() {
|
||||
var endpoint = connectionGuide.endpoint();
|
||||
configuration.setDisable(automation.snapshot().closed() || endpoint.isEmpty());
|
||||
availability.setText(endpoint.orElseGet(() -> i18n.text(I18n.DEV_MCP_UNAVAILABLE)));
|
||||
configuration.setDisable(preparing || automation.snapshot().closed() || !connectionGuide.supportsPreparation());
|
||||
availability.setText(i18n.text(switch (connectionGuide.state(projectRoot)) {
|
||||
case UNAVAILABLE -> I18n.DEV_MCP_UNAVAILABLE;
|
||||
case WAITING_FOR_ACCESS -> I18n.DEV_MCP_WAITING;
|
||||
case CONNECTED -> I18n.DEV_MCP_CONNECTED;
|
||||
case RECONNECTING -> I18n.DEV_MCP_RECONNECTING;
|
||||
}));
|
||||
}
|
||||
private void copyConfiguration() {
|
||||
try {
|
||||
if (automation.snapshot().closed()) throw new IllegalStateException("Project closed");
|
||||
var content = new javafx.scene.input.ClipboardContent();
|
||||
content.putString(connectionGuide.configuration(projectRoot));
|
||||
boolean copied = javafx.scene.input.Clipboard.getSystemClipboard().setContent(content);
|
||||
copyStatus.setText(i18n.text(copied ? I18n.DEV_CONFIG_COPIED : I18n.DEV_CONFIG_FAILED));
|
||||
} catch (RuntimeException unavailable) {
|
||||
// Never render exception payloads or credential-bearing configuration in diagnostics.
|
||||
copyStatus.setText(i18n.text(I18n.DEV_CONFIG_FAILED)); updateConnection();
|
||||
}
|
||||
private void prepareConfiguration() {
|
||||
if (preparing) return;
|
||||
preparing = true;
|
||||
long requested = generation;
|
||||
configuration.setDisable(true);
|
||||
java.util.concurrent.CompletableFuture.supplyAsync(() -> connectionGuide.prepare(projectRoot))
|
||||
.whenComplete((result, failure) -> Platform.runLater(() -> {
|
||||
preparing = false;
|
||||
if (generation != requested) return;
|
||||
copyStatus.setText(failure == null ? result.message() : i18n.text(I18n.DEV_CONFIG_FAILED));
|
||||
updateConnection();
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -360,11 +360,11 @@ workspace.debug=Debug
|
||||
workspace.dev=DEV
|
||||
dev.grant=Grant control to AI
|
||||
dev.reclaim=Interrupt and reclaim control
|
||||
dev.copyConfig=Copy MCP configuration
|
||||
dev.copyConfig=Prepare assistant
|
||||
dev.mcpUnavailable=MCP connection is unavailable.
|
||||
dev.mcpInstructions=Copy the connection descriptor into your external client's MCP setup (adapt its format if needed). Connect → read project/language references → acquire after a human grant → edit saved files and validate with LSP/build → release. Copying does not grant control. Keep the token private and out of versioned files; recopy after restarting Studio. Only listed tools are available.
|
||||
dev.mcpInstructions=Prepare the assistant once for this project. Start the agent here, then grant access in DEV. Studio discovers the connection automatically, including after restart and a new grant.
|
||||
dev.configCopied=Connection descriptor and project instructions copied. Contains a private token.
|
||||
dev.configFailed=Could not copy the current connection configuration.
|
||||
dev.configFailed=Assistant preparation failed. Check the installation and project settings.
|
||||
dev.externalWarning=Reclaiming control stops Studio-managed work, not direct writes by your external agent. Stop that client separately. Existing edits are preserved.
|
||||
dev.manual=Manual control
|
||||
dev.waiting=Waiting for agent — project control granted
|
||||
@@ -377,3 +377,6 @@ dev.history=Recent Studio calls
|
||||
dev.noFrame=No runtime capture
|
||||
dev.staleFrame=Stale capture — previous build or execution
|
||||
dev.currentFrame=Canonical runtime capture
|
||||
dev.mcpWaiting=Assistant connection: waiting for access or connection
|
||||
dev.mcpConnected=Assistant connected
|
||||
dev.mcpReconnecting=Assistant reconnecting
|
||||
|
||||
@@ -31,11 +31,11 @@ workspace.debug.status.stopped=Parado
|
||||
workspace.dev=DEV
|
||||
dev.grant=Ceder controle à IA
|
||||
dev.reclaim=Interromper e retomar controle
|
||||
dev.copyConfig=Copiar configuração MCP
|
||||
dev.copyConfig=Preparar assistente
|
||||
dev.mcpUnavailable=A conexão MCP está indisponível.
|
||||
dev.mcpInstructions=Copie o descritor de conexão para a configuração MCP do cliente externo (adapte o formato se necessário). Conecte → consulte projeto/linguagens/referências → adquira após cessão humana → edite arquivos salvos e valide com LSP/build → devolva. Copiar não cede controle. Mantenha o token privado e fora de arquivos versionados; copie novamente após reiniciar o Studio. Somente as ferramentas listadas estão disponíveis.
|
||||
dev.mcpInstructions=Prepare o assistente uma vez neste projeto. Inicie o agente aqui e conceda acesso no DEV. A conexão é descoberta automaticamente, inclusive após reiniciar e conceder acesso novamente.
|
||||
dev.configCopied=Descritor de conexão e instruções do projeto copiados. Contém um token privado.
|
||||
dev.configFailed=Não foi possível copiar a configuração atual de conexão.
|
||||
dev.configFailed=Falha ao preparar assistente. Confira a instalação e as configurações do projeto.
|
||||
dev.externalWarning=Retomar controle encerra o trabalho gerenciado pelo Studio, não as escritas diretas do agente externo. Pare esse cliente separadamente. As alterações existentes são preservadas.
|
||||
dev.manual=Controle manual
|
||||
dev.waiting=Aguardando agente — controle do projeto cedido
|
||||
@@ -48,3 +48,6 @@ dev.history=Chamadas recentes ao Studio
|
||||
dev.noFrame=Nenhuma captura do runtime
|
||||
dev.staleFrame=Captura desatualizada — build ou execução anterior
|
||||
dev.currentFrame=Captura canônica do runtime
|
||||
dev.mcpWaiting=Conexão do assistente: aguardando acesso ou conexão
|
||||
dev.mcpConnected=Assistente conectado
|
||||
dev.mcpReconnecting=Assistente reconectando
|
||||
|
||||
Reference in New Issue
Block a user