implement DEV workspace and project automation authority
This commit is contained in:
+16
@@ -16,6 +16,22 @@ public abstract class StudioFormSection extends StudioSection {
|
||||
private final VBox contentHost = new VBox();
|
||||
private boolean editAllowed = true;
|
||||
private VBox mountedSection;
|
||||
private java.util.concurrent.CompletableFuture<Void> handoffSave;
|
||||
|
||||
public final boolean hasUnsavedDraft() { return isDirty(); }
|
||||
public final java.util.concurrent.CompletionStage<Void> saveForHandoff() {
|
||||
if (!isDirty()) return java.util.concurrent.CompletableFuture.completedFuture(null);
|
||||
if (handoffSave != null && !handoffSave.isDone()) return handoffSave;
|
||||
handoffSave = new java.util.concurrent.CompletableFuture<>();
|
||||
try { apply(); } catch (RuntimeException failure) { handoffSave.completeExceptionally(failure); }
|
||||
return handoffSave;
|
||||
}
|
||||
protected final void finishHandoffSave(boolean success, String message) {
|
||||
if (handoffSave == null) return;
|
||||
if (success) handoffSave.complete(null);
|
||||
else handoffSave.completeExceptionally(new IllegalStateException(Objects.requireNonNullElse(message, "Save failed")));
|
||||
}
|
||||
public final void discardDraftForHandoff() { cancel(); renderSection(); }
|
||||
|
||||
protected StudioFormSection(I18nService i18n) {
|
||||
super();
|
||||
|
||||
@@ -3,6 +3,13 @@ package p.studio.ui.javafx.utilities.i18n;
|
||||
import lombok.Getter;
|
||||
|
||||
public enum I18n {
|
||||
WORKSPACE_DEV("workspace.dev"),
|
||||
DEV_GRANT("dev.grant"), DEV_RECLAIM("dev.reclaim"), DEV_COPY_CONFIG("dev.copyConfig"),
|
||||
DEV_MCP_UNAVAILABLE("dev.mcpUnavailable"), DEV_EXTERNAL_WARNING("dev.externalWarning"),
|
||||
DEV_MANUAL("dev.manual"), DEV_WAITING("dev.waiting"), DEV_WORKING("dev.working"), DEV_RETURNING("dev.returning"),
|
||||
DEV_SAVE_GRANT("dev.saveGrant"), DEV_UNSAVED("dev.unsaved"),
|
||||
DEV_DIAGNOSTICS("dev.diagnostics"), DEV_HISTORY("dev.history"),
|
||||
DEV_NO_FRAME("dev.noFrame"), DEV_STALE_FRAME("dev.staleFrame"), DEV_CURRENT_FRAME("dev.currentFrame"),
|
||||
APP_TITLE("app.title"),
|
||||
APP_PROJECT_TITLE("app.projectTitle"),
|
||||
SHIELD_LOADING_PROJECT("shield.loadingProject"),
|
||||
|
||||
@@ -44,6 +44,9 @@ public final class MainView extends BorderPane {
|
||||
private final ExecutionController playStopCoordinator;
|
||||
private boolean initializing;
|
||||
private boolean workspaceLifecycleInitialized;
|
||||
private p.studio.api.operation.OperationSubscription controlSubscription;
|
||||
private p.studio.api.operation.OperationSubscription documentRegistration;
|
||||
private boolean closed;
|
||||
|
||||
public MainView(final ProjectSession projectSession, final Shipper shipper,
|
||||
final ExecutionControllerFactory executionControllerFactory,
|
||||
@@ -93,12 +96,29 @@ public final class MainView extends BorderPane {
|
||||
assetWorkspace.restoreProjectLocalState(persistedState);
|
||||
assetWorkspace.setStateChangedAction(this::persistProjectLocalState);
|
||||
host.register(new DebugWorkspace(projectReference, projectSession.executionSession(), i18n, eventBus));
|
||||
host.register(new ShipperWorkspace(projectReference, shipper, i18n, eventBus));
|
||||
final var shipperWorkspace = new ShipperWorkspace(projectReference, shipper, i18n, eventBus);
|
||||
host.register(shipperWorkspace);
|
||||
host.register(new p.studio.ui.javafx.workspaces.dev.DevWorkspace(projectReference, projectSession.automation(), i18n, eventBus));
|
||||
documentRegistration = projectSession.automation().registerDocuments(assetWorkspace.documentHandoff());
|
||||
p.studio.ui.javafx.workspaces.dev.ManualProjectUiGuard.install(assetWorkspace.rootNode(),
|
||||
() -> projectSession.automation().snapshot().manualAllowed());
|
||||
p.studio.ui.javafx.workspaces.dev.ManualProjectUiGuard.install(shipperWorkspace.rootNode(),
|
||||
() -> projectSession.automation().snapshot().manualAllowed());
|
||||
controlSubscription = projectSession.automation().subscribe(snapshot -> {
|
||||
Runnable update = () -> {
|
||||
if (closed) return;
|
||||
runSurface.setDisable(!snapshot.manualAllowed());
|
||||
p.studio.ui.javafx.workspaces.dev.ManualProjectUiGuard.project(assetWorkspace.rootNode(), snapshot.manualAllowed());
|
||||
p.studio.ui.javafx.workspaces.dev.ManualProjectUiGuard.project(shipperWorkspace.rootNode(), snapshot.manualAllowed());
|
||||
};
|
||||
if (javafx.application.Platform.isFxApplicationThread()) update.run(); else javafx.application.Platform.runLater(update);
|
||||
});
|
||||
|
||||
workspaceRail = new StudioWorkspaceRailControl<>(
|
||||
List.of(
|
||||
new StudioWorkspaceRailItem<>(WorkspaceId.ASSETS, "📦", i18n.bind(I18n.WORKSPACE_ASSETS)),
|
||||
new StudioWorkspaceRailItem<>(WorkspaceId.DEBUG, "🎮", i18n.bind(I18n.WORKSPACE_DEBUG)),
|
||||
new StudioWorkspaceRailItem<>(WorkspaceId.DEV, "◇", i18n.bind(I18n.WORKSPACE_DEV)),
|
||||
new StudioWorkspaceRailItem<>(WorkspaceId.SHIPPER, "⚙️", i18n.bind(I18n.WORKSPACE_SHIPPER))
|
||||
),
|
||||
this::loadWorkspace);
|
||||
@@ -141,6 +161,10 @@ public final class MainView extends BorderPane {
|
||||
}
|
||||
|
||||
public void close() {
|
||||
if (closed) return;
|
||||
closed = true;
|
||||
controlSubscription.unsubscribe();
|
||||
documentRegistration.unsubscribe();
|
||||
playStopCoordinator.shutdown();
|
||||
persistProjectLocalState();
|
||||
host.deactivateCurrentWorkspace();
|
||||
|
||||
+8
-3
@@ -11,15 +11,18 @@ import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public final class StudioWorkspaceLifecycleSupport {
|
||||
private static final Object ACTIVATION = new Object();
|
||||
private StudioWorkspaceLifecycleSupport() {
|
||||
}
|
||||
|
||||
public static void activate(Workspace workspace) {
|
||||
final Workspace target = Objects.requireNonNull(workspace, "workspace");
|
||||
final Node rootNode = target.rootNode();
|
||||
final Object activation = new Object();
|
||||
rootNode.getProperties().put(ACTIVATION, activation);
|
||||
final Scene scene = rootNode.getScene();
|
||||
if (scene != null) {
|
||||
activateNow(target);
|
||||
activateNow(target, activation);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -33,13 +36,14 @@ public final class StudioWorkspaceLifecycleSupport {
|
||||
return;
|
||||
}
|
||||
rootNode.sceneProperty().removeListener(this);
|
||||
activateNow(target);
|
||||
activateNow(target, activation);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void deactivate(Workspace workspace) {
|
||||
final Workspace target = Objects.requireNonNull(workspace, "workspace");
|
||||
target.rootNode().getProperties().remove(ACTIVATION);
|
||||
target.unLoad();
|
||||
final List<StudioControlLifecycle> participants = target.lifecycleParticipants();
|
||||
for (int index = participants.size() - 1; index >= 0; index--) {
|
||||
@@ -47,8 +51,9 @@ public final class StudioWorkspaceLifecycleSupport {
|
||||
}
|
||||
}
|
||||
|
||||
private static void activateNow(Workspace workspace) {
|
||||
private static void activateNow(Workspace workspace, Object activation) {
|
||||
Platform.runLater(() -> {
|
||||
if (workspace.rootNode().getProperties().get(ACTIVATION) != activation) return;
|
||||
final List<StudioControlLifecycle> participants = workspace.lifecycleParticipants();
|
||||
for (StudioControlLifecycle participant : participants) {
|
||||
participant.subscribe();
|
||||
|
||||
+2
-1
@@ -3,5 +3,6 @@ package p.studio.ui.javafx.workspaces;
|
||||
public enum WorkspaceId {
|
||||
ASSETS,
|
||||
SHIPPER,
|
||||
DEBUG
|
||||
DEBUG,
|
||||
DEV
|
||||
}
|
||||
|
||||
+2
@@ -126,6 +126,8 @@ public final class AssetWorkspace extends Workspace {
|
||||
this.stateChangedAction = java.util.Objects.requireNonNull(stateChangedAction, "stateChangedAction");
|
||||
}
|
||||
|
||||
public p.studio.api.automation.DocumentHandoff documentHandoff() { return detailsControl.documentHandoff(); }
|
||||
|
||||
public void restoreProjectLocalState(final ProjectLocalStudioState projectLocalStudioState) {
|
||||
pendingAssetsLayoutState = projectLocalStudioState.shellLayout().assetsLayout();
|
||||
reapplyPendingLayoutState();
|
||||
|
||||
+58
@@ -85,6 +85,63 @@ public final class AssetDetailsControl extends VBox implements StudioEventAware
|
||||
private boolean actionRunning;
|
||||
private String actionFeedbackMessage;
|
||||
|
||||
public p.studio.api.automation.DocumentHandoff documentHandoff() {
|
||||
return new p.studio.api.automation.DocumentHandoff() {
|
||||
private volatile boolean disposed;
|
||||
private final java.util.Set<java.util.concurrent.CompletableFuture<Void>> pending = java.util.concurrent.ConcurrentHashMap.newKeySet();
|
||||
@Override public void close() {
|
||||
disposed = true;
|
||||
pending.forEach(future -> future.complete(null));
|
||||
pending.clear();
|
||||
}
|
||||
@Override public java.util.concurrent.CompletionStage<Boolean> hasUnsavedChanges() {
|
||||
return onFx(() -> handoffForms().stream().anyMatch(p.studio.ui.javafx.controls.forms.StudioFormSection::hasUnsavedDraft));
|
||||
}
|
||||
@Override public java.util.concurrent.CompletionStage<Void> saveAll() {
|
||||
return onFx(() -> {
|
||||
java.util.concurrent.CompletionStage<Void> saved = java.util.concurrent.CompletableFuture.completedFuture(null);
|
||||
for (var form : handoffForms()) saved = saved.thenCompose(v -> form.saveForHandoff());
|
||||
return saved;
|
||||
}).thenCompose(saved -> saved);
|
||||
}
|
||||
@Override public java.util.concurrent.CompletionStage<Void> refreshFromDisk() {
|
||||
var refreshed = new java.util.concurrent.CompletableFuture<Void>();
|
||||
pending.add(refreshed);
|
||||
refreshed.whenComplete((v, f) -> pending.remove(refreshed));
|
||||
if (disposed) { refreshed.complete(null); return refreshed; }
|
||||
onFx(() -> {
|
||||
if (disposed) { refreshed.complete(null); return null; }
|
||||
handoffForms().forEach(p.studio.ui.javafx.controls.forms.StudioFormSection::discardDraftForHandoff);
|
||||
var selected = viewState.selectedAssetReference();
|
||||
if (selected == null) { refreshed.complete(null); return refreshed; }
|
||||
long generation = loadGeneration.incrementAndGet();
|
||||
executor.execute(() -> {
|
||||
try {
|
||||
var details = mapDetails(assetDetails.get(projectReference, selected));
|
||||
Platform.runLater(() -> { if (!disposed) applyLoadedDetails(generation, selected, details); refreshed.complete(null); });
|
||||
} catch (RuntimeException failure) {
|
||||
Platform.runLater(() -> { if (!disposed) applyLoadFailure(generation, selected, failure); refreshed.completeExceptionally(failure); });
|
||||
}
|
||||
});
|
||||
return refreshed;
|
||||
}).whenComplete((v, failure) -> { if (failure != null) refreshed.completeExceptionally(failure); });
|
||||
return refreshed;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private java.util.List<p.studio.ui.javafx.controls.forms.StudioFormSection> handoffForms() {
|
||||
var forms = new java.util.ArrayList<>(contractControl.handoffForms());
|
||||
forms.add(bankCompositionControl); forms.add(colorSchemaGroupsControl); forms.add(paletteOverhaulingControl);
|
||||
return forms;
|
||||
}
|
||||
private static <T> java.util.concurrent.CompletableFuture<T> onFx(java.util.function.Supplier<T> action) {
|
||||
var result = new java.util.concurrent.CompletableFuture<T>();
|
||||
Runnable run = () -> { try { result.complete(action.get()); } catch (RuntimeException f) { result.completeExceptionally(f); } };
|
||||
if (Platform.isFxApplicationThread()) run.run(); else Platform.runLater(run);
|
||||
return result;
|
||||
}
|
||||
|
||||
public AssetDetailsControl(
|
||||
ProjectReference projectReference,
|
||||
StudioWorkspaceEventBus workspaceBus,
|
||||
@@ -382,6 +439,7 @@ public final class AssetDetailsControl extends VBox implements StudioEventAware
|
||||
AssetDetailsUiSupport.applyActionTone(analyseButton, "studio-button-warning");
|
||||
analyseButton.setDisable(actionRunning || viewState.selectedAssetDetails().diagnostics().isEmpty());
|
||||
analyseButton.setOnAction(ignored -> openDiagnosticsDialog());
|
||||
p.studio.ui.javafx.workspaces.dev.ManualProjectUiGuard.allowReadOnly(analyseButton);
|
||||
nodes.add(analyseButton);
|
||||
if (canGenerateTsx()) {
|
||||
final Button exportTsxButton = AssetDetailsUiSupport.createActionButton(i18n.text(I18n.ASSETS_ACTION_EXPORT_TSX));
|
||||
|
||||
+4
@@ -212,16 +212,20 @@ public final class AssetDetailsBankCompositionControl extends StudioFormSection
|
||||
final var response = assetCommands.applyBankComposition(projectReference, assetReference, selectedPaths);
|
||||
Platform.runLater(() -> {
|
||||
if (response.success()) {
|
||||
coordinator.apply();
|
||||
publishEditScope(workspaceBus, currentScopeKey(), null);
|
||||
finishHandoffSave(true, "");
|
||||
workspaceBus.publish(new StudioAssetBankCompositionAppliedEvent(assetReference));
|
||||
executor.execute(() -> publishAppliedBankComposition(assetReference));
|
||||
} else {
|
||||
finishHandoffSave(false, response.errorMessage());
|
||||
workspaceBus.publish(new StudioAssetBankCompositionApplyFailedEvent(
|
||||
assetReference,
|
||||
response.errorMessage()));
|
||||
}
|
||||
});
|
||||
} catch (Exception exception) {
|
||||
Platform.runLater(() -> finishHandoffSave(false, exception.getMessage()));
|
||||
Platform.runLater(() -> workspaceBus.publish(new StudioAssetBankCompositionApplyFailedEvent(
|
||||
assetReference,
|
||||
"Unable to apply bank composition.")));
|
||||
|
||||
+6
-2
@@ -48,6 +48,8 @@ public final class AssetDetailsContractControl extends HBox implements StudioCon
|
||||
|
||||
private AssetWorkspaceDetailsViewState viewState;
|
||||
|
||||
public java.util.List<StudioFormSection> handoffForms() { return java.util.List.of(runtimeSection, codecSection); }
|
||||
|
||||
public AssetDetailsContractControl(ProjectReference projectReference, StudioWorkspaceEventBus workspaceBus,
|
||||
p.studio.ui.javafx.utilities.i18n.I18nService i18n, java.util.concurrent.Executor executor,
|
||||
AssetCommands assetCommands) {
|
||||
@@ -283,14 +285,15 @@ public final class AssetDetailsContractControl extends HBox implements StudioCon
|
||||
private void handleApplyResponse(boolean success, String errorMessage) {
|
||||
if (success) {
|
||||
formSession().apply();
|
||||
finishHandoffSave(true, "");
|
||||
publishEditScope(workspaceBus, currentScopeKey(), null);
|
||||
logContractEvent("Runtime contract updated");
|
||||
requestRefresh();
|
||||
renderSection();
|
||||
return;
|
||||
}
|
||||
finishHandoffSave(false, errorMessage);
|
||||
logContractEvent(errorMessage);
|
||||
cancel();
|
||||
renderSection();
|
||||
}
|
||||
|
||||
@@ -447,14 +450,15 @@ public final class AssetDetailsContractControl extends HBox implements StudioCon
|
||||
private void handleApplyResponse(boolean success, String errorMessage) {
|
||||
if (success) {
|
||||
formSession().apply();
|
||||
finishHandoffSave(true, "");
|
||||
publishEditScope(workspaceBus, currentScopeKey(), null);
|
||||
logContractEvent("Codec updated");
|
||||
requestRefresh();
|
||||
renderSection();
|
||||
return;
|
||||
}
|
||||
finishHandoffSave(false, errorMessage);
|
||||
logContractEvent(errorMessage);
|
||||
cancel();
|
||||
renderSection();
|
||||
}
|
||||
|
||||
|
||||
+4
@@ -223,6 +223,7 @@ public final class AssetDetailsPaletteOverhaulingControl extends StudioFormSecti
|
||||
.filter(Objects::nonNull)
|
||||
.toList();
|
||||
if (selectedPalettes.isEmpty()) {
|
||||
finishHandoffSave(false, "No palette selected");
|
||||
workspaceBus.publish(new StudioAssetLogEvent("palette-overhauling", "Apply failed: no palette was selected."));
|
||||
workspaceBus.publish(new StudioPackerOperationEvent(
|
||||
UUID.randomUUID().toString(),
|
||||
@@ -240,15 +241,18 @@ public final class AssetDetailsPaletteOverhaulingControl extends StudioFormSecti
|
||||
Platform.runLater(() -> {
|
||||
if (response.success()) {
|
||||
coordinator.apply();
|
||||
finishHandoffSave(true, "");
|
||||
publishEditScope(workspaceBus, currentScopeKey(), null);
|
||||
renderSection();
|
||||
workspaceBus.publish(new StudioAssetsWorkspaceSelectionRequestedEvent(assetReference, true));
|
||||
} else {
|
||||
finishHandoffSave(false, response.errorMessage());
|
||||
workspaceBus.publish(new StudioAssetLogEvent("palette-overhauling",
|
||||
"Apply failed: " + Objects.requireNonNullElse(response.errorMessage(), "unknown error")));
|
||||
}
|
||||
});
|
||||
} catch (Exception exception) {
|
||||
Platform.runLater(() -> finishHandoffSave(false, exception.getMessage()));
|
||||
Platform.runLater(() -> workspaceBus.publish(new StudioAssetLogEvent(
|
||||
"palette-overhauling",
|
||||
"Apply failed due to an unexpected error.")));
|
||||
|
||||
+6
@@ -181,16 +181,19 @@ public final class AssetDetailsColorSchemaGroupsControl extends StudioFormSectio
|
||||
}
|
||||
final AssetColorSchemaState draft = coordinator.state();
|
||||
if (!draft.selected()) {
|
||||
finishHandoffSave(false, "Select or create a schema first");
|
||||
workspaceBus.publish(new StudioAssetLogEvent("color-schema-groups", "Apply failed: select or create a schema first."));
|
||||
return;
|
||||
}
|
||||
if (!draft.removeRequested()) {
|
||||
final List<String> orderedColors = draft.orderedColors();
|
||||
if (draft.assignedTiles().isEmpty() || orderedColors.isEmpty()) {
|
||||
finishHandoffSave(false, "Schema requires at least one tile");
|
||||
workspaceBus.publish(new StudioAssetLogEvent("color-schema-groups", "Apply failed: schema must contain at least one tile."));
|
||||
return;
|
||||
}
|
||||
if (orderedColors.size() > 16) {
|
||||
finishHandoffSave(false, "Schema exceeds palette capacity");
|
||||
workspaceBus.publish(new StudioAssetLogEvent(
|
||||
"color-schema-groups",
|
||||
i18n.text(I18n.ASSETS_COLOR_SCHEMA_DIALOG_TOO_MANY_COLORS)));
|
||||
@@ -207,6 +210,7 @@ public final class AssetDetailsColorSchemaGroupsControl extends StudioFormSectio
|
||||
: coordinator.upsertSchema(draft.schemaId(), draft.assignedTiles(), draft.orderedColors());
|
||||
final var writeResult = metadataService.writeGlyphMaterialMetadata(assetDetails.summary().assetRoot(), metadata);
|
||||
if (!writeResult.successful()) {
|
||||
Platform.runLater(() -> finishHandoffSave(false, writeResult.message()));
|
||||
Platform.runLater(() -> workspaceBus.publish(new StudioAssetLogEvent(
|
||||
"color-schema-groups",
|
||||
"Unable to save schema: " + writeResult.message())));
|
||||
@@ -214,6 +218,7 @@ public final class AssetDetailsColorSchemaGroupsControl extends StudioFormSectio
|
||||
}
|
||||
Platform.runLater(() -> {
|
||||
coordinator.apply();
|
||||
finishHandoffSave(true, "");
|
||||
selectedSchemaId = draft.removeRequested() ? null : draft.schemaId();
|
||||
publishEditScope(workspaceBus, currentScopeKey(), null);
|
||||
workspaceBus.publish(new StudioAssetLogEvent(
|
||||
@@ -223,6 +228,7 @@ public final class AssetDetailsColorSchemaGroupsControl extends StudioFormSectio
|
||||
renderSection();
|
||||
});
|
||||
} catch (RuntimeException exception) {
|
||||
Platform.runLater(() -> finishHandoffSave(false, exception.getMessage()));
|
||||
Platform.runLater(() -> workspaceBus.publish(new StudioAssetLogEvent(
|
||||
"color-schema-groups",
|
||||
"Unable to save schema.")));
|
||||
|
||||
+2
@@ -98,6 +98,7 @@ public final class AssetListControl extends VBox implements StudioEventAware {
|
||||
}
|
||||
|
||||
private TextField createSearchField() {
|
||||
p.studio.ui.javafx.workspaces.dev.ManualProjectUiGuard.allowReadOnly(searchField);
|
||||
searchField.setPromptText(i18n.text(I18n.ASSETS_SEARCH_PROMPT));
|
||||
searchField.getStyleClass().add("assets-workspace-search");
|
||||
return searchField;
|
||||
@@ -117,6 +118,7 @@ public final class AssetListControl extends VBox implements StudioEventAware {
|
||||
}
|
||||
|
||||
private ToggleButton configureFilterButton(ToggleButton button, I18n i18n) {
|
||||
p.studio.ui.javafx.workspaces.dev.ManualProjectUiGuard.allowReadOnly(button);
|
||||
button.textProperty().bind(this.i18n.bind(i18n));
|
||||
button.getStyleClass().addAll("studio-button", "studio-button-secondary", "studio-button-pill", "studio-button-toggle");
|
||||
return button;
|
||||
|
||||
+108
@@ -0,0 +1,108 @@
|
||||
package p.studio.ui.javafx.workspaces.dev;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.layout.*;
|
||||
import p.studio.api.automation.*;
|
||||
import p.studio.api.operation.OperationSubscription;
|
||||
import p.studio.api.project.ProjectReference;
|
||||
import p.studio.ui.javafx.events.StudioEventBus;
|
||||
import p.studio.ui.javafx.utilities.i18n.*;
|
||||
import p.studio.ui.javafx.workspaces.*;
|
||||
import java.io.ByteArrayInputStream;
|
||||
|
||||
/** Human authorization and observation only; never an embedded agent or a fake runtime. */
|
||||
public final class DevWorkspace extends Workspace {
|
||||
private final VBox root = new VBox(12);
|
||||
private final ScrollPane scroll = new ScrollPane(root);
|
||||
private final AutomationSession automation;
|
||||
private final I18nService i18n;
|
||||
private final Label state = new Label(), identity = new Label(), operation = new Label(), imageStatus = new Label();
|
||||
private final TextArea diagnostics = new TextArea(), history = new TextArea();
|
||||
private final ImageView canvas = new ImageView();
|
||||
private final Button grant = new Button(), reclaim = new Button();
|
||||
private OperationSubscription subscription;
|
||||
private long generation;
|
||||
private CanonicalCapture rendered;
|
||||
private final javafx.beans.value.ChangeListener<java.util.Locale> localeListener;
|
||||
|
||||
public DevWorkspace(ProjectReference project, AutomationSession automation, I18nService i18n, StudioEventBus events) {
|
||||
super(project, events); this.automation = automation; this.i18n = i18n;
|
||||
localeListener = (o, before, after) -> apply(this.automation.snapshot());
|
||||
scroll.setFitToWidth(true);
|
||||
root.setPadding(new Insets(16)); root.getStyleClass().add("dev-workspace");
|
||||
grant.setId("dev-grant"); reclaim.setId("dev-reclaim");
|
||||
grant.textProperty().bind(i18n.bind(I18n.DEV_GRANT));
|
||||
reclaim.textProperty().bind(i18n.bind(I18n.DEV_RECLAIM));
|
||||
grant.setOnAction(e -> grant(false));
|
||||
reclaim.setOnAction(e -> automation.reclaim());
|
||||
Button configuration = new Button(); configuration.setId("dev-mcp-config");
|
||||
configuration.textProperty().bind(i18n.bind(I18n.DEV_COPY_CONFIG)); configuration.setDisable(true);
|
||||
Label availability = new Label(); availability.textProperty().bind(i18n.bind(I18n.DEV_MCP_UNAVAILABLE));
|
||||
Label warning = new Label(); warning.setWrapText(true);
|
||||
warning.textProperty().bind(i18n.bind(I18n.DEV_EXTERNAL_WARNING));
|
||||
canvas.setPreserveRatio(true); canvas.setSmooth(false); canvas.setFitWidth(640); canvas.setFitHeight(360);
|
||||
StackPane imagePane = new StackPane(canvas); imagePane.setMinHeight(200); imagePane.getStyleClass().add("dev-canvas");
|
||||
diagnostics.setEditable(false); diagnostics.setPrefRowCount(3);
|
||||
history.setEditable(false); history.setPrefRowCount(5);
|
||||
root.getChildren().addAll(new Label(project.name() + " — " + project.rootPath()),
|
||||
state, new HBox(10, grant, reclaim, configuration), availability, warning,
|
||||
operation, imageStatus, imagePane, identity,
|
||||
pane(I18n.DEV_DIAGNOSTICS, diagnostics), pane(I18n.DEV_HISTORY, history));
|
||||
apply(automation.snapshot());
|
||||
}
|
||||
|
||||
private TitledPane pane(I18n key, Node content) {
|
||||
TitledPane pane = new TitledPane(); pane.textProperty().bind(i18n.bind(key));
|
||||
pane.setContent(content); pane.setCollapsible(false); return pane;
|
||||
}
|
||||
@Override public WorkspaceId workspaceId() { return WorkspaceId.DEV; }
|
||||
@Override public I18n title() { return I18n.WORKSPACE_DEV; }
|
||||
@Override public Node rootNode() { return scroll; }
|
||||
@Override public void load() {
|
||||
if (subscription != null) return;
|
||||
i18n.localeProperty().addListener(localeListener);
|
||||
long subscribed = ++generation;
|
||||
subscription = automation.subscribe(snapshot -> {
|
||||
Runnable update = () -> { if (generation == subscribed) apply(snapshot); };
|
||||
if (Platform.isFxApplicationThread()) update.run(); else Platform.runLater(update);
|
||||
});
|
||||
}
|
||||
@Override public void unLoad() {
|
||||
generation++;
|
||||
i18n.localeProperty().removeListener(localeListener);
|
||||
if (subscription != null) { subscription.unsubscribe(); subscription = null; }
|
||||
}
|
||||
private void grant(boolean save) {
|
||||
automation.grant(save).whenComplete((result, failure) -> Platform.runLater(() -> {
|
||||
if (failure != null) { diagnostics.setText(failure.getMessage()); return; }
|
||||
if (result.status() == ControlResult.Status.DIRTY_DOCUMENTS) {
|
||||
ButtonType confirm = new ButtonType(i18n.text(I18n.DEV_SAVE_GRANT), ButtonBar.ButtonData.OK_DONE);
|
||||
Alert dialog = new Alert(Alert.AlertType.CONFIRMATION, i18n.text(I18n.DEV_UNSAVED), confirm, ButtonType.CANCEL);
|
||||
if (root.getScene() != null) dialog.initOwner(root.getScene().getWindow());
|
||||
if (dialog.showAndWait().orElse(ButtonType.CANCEL) == confirm) grant(true);
|
||||
}
|
||||
}));
|
||||
}
|
||||
private void apply(AutomationSnapshot snapshot) {
|
||||
var view = DevWorkspaceProjection.from(snapshot);
|
||||
state.setText(i18n.text(switch (view.state()) {
|
||||
case MANUAL -> I18n.DEV_MANUAL;
|
||||
case WAITING_FOR_AGENT -> I18n.DEV_WAITING;
|
||||
case AGENT_WORKING -> I18n.DEV_WORKING;
|
||||
case RETURNING_CONTROL -> I18n.DEV_RETURNING;
|
||||
}));
|
||||
grant.setDisable(!view.grantEnabled()); reclaim.setDisable(!view.reclaimEnabled());
|
||||
identity.setText(view.identity()); operation.setText(view.operation());
|
||||
diagnostics.setText(view.diagnostics()); history.setText(view.calls());
|
||||
imageStatus.setText(i18n.text(view.capture() == null ? I18n.DEV_NO_FRAME : view.stale() ? I18n.DEV_STALE_FRAME : I18n.DEV_CURRENT_FRAME));
|
||||
if (rendered != view.capture()) {
|
||||
rendered = view.capture();
|
||||
canvas.setImage(rendered == null ? null : new Image(new ByteArrayInputStream(rendered.png())));
|
||||
}
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package p.studio.ui.javafx.workspaces.dev;
|
||||
|
||||
import p.studio.api.automation.*;
|
||||
|
||||
public record DevWorkspaceProjection(ControlState state, boolean grantEnabled, boolean reclaimEnabled,
|
||||
boolean stale, CanonicalCapture capture, String identity, String operation, String diagnostics, String calls) {
|
||||
public static DevWorkspaceProjection from(AutomationSnapshot s) {
|
||||
var frame = s.capture();
|
||||
String identity = frame == null ? "" : "session=" + frame.sessionId() + " | build=" + frame.buildId()
|
||||
+ " | logical=" + frame.logicalFrameIndex() + " | FrameId=" + frame.frameId()
|
||||
+ " | " + frame.width() + "×" + frame.height() + " | stride=" + frame.stridePixels();
|
||||
return new DevWorkspaceProjection(s.state(), s.canGrant(), s.canReclaim(), s.stale(), frame, identity,
|
||||
s.operation() == null ? "" : s.operation().id().value() + " | " + s.operation().state() + " | " + s.operation().summary(),
|
||||
String.join("\n", s.diagnostics()), String.join("\n", s.calls()));
|
||||
}
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
package p.studio.ui.javafx.workspaces.dev;
|
||||
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.control.ButtonBase;
|
||||
import javafx.scene.control.TextInputControl;
|
||||
import javafx.scene.input.KeyEvent;
|
||||
import javafx.scene.input.MouseEvent;
|
||||
import javafx.css.PseudoClass;
|
||||
import java.util.function.BooleanSupplier;
|
||||
|
||||
/** Presentation guard only. Core service admission remains authoritative. */
|
||||
public final class ManualProjectUiGuard {
|
||||
public static final String READ_ONLY_ACTION = "studio.readOnlyAction";
|
||||
private ManualProjectUiGuard() { }
|
||||
public static void allowReadOnly(Node node) {
|
||||
node.getProperties().put(READ_ONLY_ACTION, true);
|
||||
node.getStyleClass().add("studio-read-only-action");
|
||||
}
|
||||
public static void install(Node root, BooleanSupplier manualAllowed) {
|
||||
root.addEventFilter(ActionEvent.ACTION, event -> {
|
||||
if (!manualAllowed.getAsBoolean() && event.getTarget() instanceof Node target
|
||||
&& !Boolean.TRUE.equals(target.getProperties().get(READ_ONLY_ACTION))) event.consume();
|
||||
});
|
||||
root.addEventFilter(KeyEvent.KEY_TYPED, event -> {
|
||||
if (!manualAllowed.getAsBoolean() && mutationTarget(event.getTarget())) event.consume();
|
||||
});
|
||||
root.addEventFilter(MouseEvent.MOUSE_PRESSED, event -> {
|
||||
if (!manualAllowed.getAsBoolean() && mutationTarget(event.getTarget())) event.consume();
|
||||
});
|
||||
root.addEventFilter(KeyEvent.KEY_PRESSED, event -> {
|
||||
if (!manualAllowed.getAsBoolean() && mutationTarget(event.getTarget())) event.consume();
|
||||
});
|
||||
}
|
||||
public static void project(Node root, boolean manualAllowed) {
|
||||
root.pseudoClassStateChanged(PseudoClass.getPseudoClass("automation-locked"), !manualAllowed);
|
||||
}
|
||||
private static boolean mutationTarget(Object target) {
|
||||
Node node = target instanceof Node value ? value : null;
|
||||
while (node != null) {
|
||||
if (Boolean.TRUE.equals(node.getProperties().get(READ_ONLY_ACTION))) return false;
|
||||
if (node instanceof ButtonBase || node instanceof javafx.scene.control.ComboBoxBase<?>
|
||||
|| node instanceof TextInputControl text && text.isEditable()) return true;
|
||||
node = node.getParent();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -357,3 +357,20 @@ assets.packWizard.error.deepSync=Unable to complete deep sync for the current wo
|
||||
assets.packWizard.error.validation=Unable to validate the current pack set.
|
||||
assets.packWizard.error.pack=Unable to pack the current build set.
|
||||
workspace.debug=Debug
|
||||
workspace.dev=DEV
|
||||
dev.grant=Grant control to AI
|
||||
dev.reclaim=Interrupt and reclaim control
|
||||
dev.copyConfig=Copy MCP configuration
|
||||
dev.mcpUnavailable=MCP connection is not available yet. This stage provides project control and observation.
|
||||
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
|
||||
dev.working=Agent working — task acquired
|
||||
dev.returning=Returning control — stopping work and refreshing documents
|
||||
dev.saveGrant=Save all and grant
|
||||
dev.unsaved=Studio has unsaved changes. Save all before granting project control?
|
||||
dev.diagnostics=Diagnostics
|
||||
dev.history=Recent Studio calls
|
||||
dev.noFrame=No runtime capture
|
||||
dev.staleFrame=Stale capture — previous build or execution
|
||||
dev.currentFrame=Canonical runtime capture
|
||||
|
||||
@@ -28,3 +28,20 @@ workspace.debug.status.connecting=Conectando
|
||||
workspace.debug.status.running=Executando
|
||||
workspace.debug.status.runtimeFailed=Runtime falhou
|
||||
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.mcpUnavailable=A conexão MCP ainda não está disponível. Esta etapa oferece controle do projeto e acompanhamento.
|
||||
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
|
||||
dev.working=Agente trabalhando — tarefa adquirida
|
||||
dev.returning=Retomando controle — encerrando trabalho e atualizando documentos
|
||||
dev.saveGrant=Salvar tudo e ceder
|
||||
dev.unsaved=Existem alterações não salvas no Studio. Salvar tudo antes de ceder o controle?
|
||||
dev.diagnostics=Diagnósticos
|
||||
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
|
||||
|
||||
@@ -1583,3 +1583,8 @@
|
||||
-fx-text-fill: #b9cae0;
|
||||
-fx-font-size: 12px;
|
||||
}
|
||||
.dev-canvas { -fx-background-color: #16191f; -fx-padding: 12; }
|
||||
.automation-locked { -fx-opacity: 0.95; }
|
||||
.assets-workspace:automation-locked .button,
|
||||
.shipper-workspace:automation-locked .button { -fx-opacity: 0.45; }
|
||||
.assets-workspace:automation-locked .studio-read-only-action { -fx-opacity: 1; }
|
||||
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package p.studio.ui.javafx.workspaces.dev;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import p.studio.api.automation.*;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class DevWorkspaceProjectionTest {
|
||||
@Test void actionMappingUsesAuthorityAndNeverInventsAnEndpointOrFrame() {
|
||||
for (var state : ControlState.values()) {
|
||||
var view = DevWorkspaceProjection.from(snapshot(state, null, false, false));
|
||||
assertEquals(state == ControlState.MANUAL, view.grantEnabled());
|
||||
assertEquals(state != ControlState.MANUAL, view.reclaimEnabled());
|
||||
assertNull(view.capture()); assertEquals("", view.identity());
|
||||
}
|
||||
var closed = DevWorkspaceProjection.from(snapshot(ControlState.MANUAL, null, false, true));
|
||||
assertFalse(closed.grantEnabled()); assertFalse(closed.reclaimEnabled());
|
||||
}
|
||||
@Test void captureIdentityRetainsIndependentLogicalAndRenderCountersAndStaleness() {
|
||||
var frame = new CanonicalCapture("session-A", "build-B", 99, 7, 320, 180, 320, new byte[]{1});
|
||||
var view = DevWorkspaceProjection.from(snapshot(ControlState.AGENT_WORKING, frame, true, false));
|
||||
assertSame(frame, view.capture()); assertTrue(view.stale());
|
||||
assertTrue(view.identity().contains("logical=99")); assertTrue(view.identity().contains("FrameId=7"));
|
||||
assertTrue(view.identity().contains("session-A")); assertTrue(view.identity().contains("build-B"));
|
||||
assertEquals("diagnostic", view.diagnostics()); assertEquals("call", view.calls());
|
||||
}
|
||||
private AutomationSnapshot snapshot(ControlState state, CanonicalCapture frame, boolean stale, boolean closed) {
|
||||
return new AutomationSnapshot(Path.of("."), state, false, closed, 0, null, null, frame, stale, List.of("diagnostic"), List.of("call"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user