feat(studio): improve compiler reliability and AI diagnostics
Preserve structured diagnostics, source attribution, phase outcomes and revision context through compiler, Studio, LSP, MCP and JavaFX. Add project service discovery and resilient VS Code reconnection. Correct all eight reproduced PBS production failures in expression context, sibling executable bindings and nominal owner identity. Consolidate specs, lessons, immutable baseline evidence and the maintained source-to-guest qualification runner. Validation: required Gradle gate recorded 724 tests, with 711 passed and 13 skipped. Full corpus passed 168 compilation observations and 108 guest runs (104 successes and four deliberate faults); supplemental controls passed 42 compilations and 16 guest runs. TypeScript compilation, two Node discovery tests and discussion validation passed.
This commit is contained in:
+40
@@ -0,0 +1,40 @@
|
||||
package p.studio.ui.javafx.diagnostics;
|
||||
|
||||
import java.nio.file.*;
|
||||
import java.net.URI;
|
||||
import java.util.*;
|
||||
|
||||
/** Read-only navigation: admission and revision checks precede any range selection. */
|
||||
public final class DiagnosticNavigation {
|
||||
private DiagnosticNavigation() {}
|
||||
public record Source(String status, Path path, String text, int start, int end) {}
|
||||
public static Source read(Path root, Map<String, Object> origin) {
|
||||
try {
|
||||
if (!(origin.get("uri") instanceof String uri) || !uri.startsWith("file:"))
|
||||
return new Source("Source unavailable; no admitted physical URI", null, "", 0, 0);
|
||||
var path = Path.of(URI.create(uri)).toRealPath();
|
||||
if (!path.startsWith(root.toRealPath()) || !Files.isRegularFile(path))
|
||||
return new Source("Source unavailable outside project admission", null, "", 0, 0);
|
||||
byte[] bytes;
|
||||
try (var input = Files.newInputStream(path)) { bytes = input.readNBytes(4 * 1024 * 1024 + 1); }
|
||||
if (bytes.length > 4 * 1024 * 1024) return new Source("Source exceeds navigation limit", null, "", 0, 0);
|
||||
var text = java.nio.charset.StandardCharsets.UTF_8.newDecoder().decode(java.nio.ByteBuffer.wrap(bytes)).toString();
|
||||
var digest = HexFormat.of().formatHex(java.security.MessageDigest.getInstance("SHA-256").digest(bytes));
|
||||
if (origin.get("source") instanceof Map<?, ?> identity && "mixed".equals(identity.get("revisionAvailability")))
|
||||
return new Source("Mixed analysis revisions; showing current source read-only", path, text, 0, 0);
|
||||
if (!digest.equals(origin.get("revision")))
|
||||
return new Source(origin.get("revision") == null ? "Revision unavailable; showing current source read-only" : "Stale diagnostic; showing changed source read-only", path, text, 0, 0);
|
||||
if (!(origin.get("range") instanceof Map<?, ?> range)) return new Source("Current source; diagnostic has no range", path, text, 0, 0);
|
||||
int start = offset(text, (Map<?, ?>) range.get("start")), end = offset(text, (Map<?, ?>) range.get("end"));
|
||||
if (start < 0 || end < start) return new Source("Current source; range unavailable", path, text, 0, 0);
|
||||
return new Source("Current source · read-only", path, text, start, end);
|
||||
} catch (Exception unavailable) { return new Source("Source unavailable", null, "", 0, 0); }
|
||||
}
|
||||
private static int offset(String text, Map<?, ?> position) {
|
||||
if (position == null || !(position.get("line") instanceof Number line) || !(position.get("character") instanceof Number character)) return -1;
|
||||
int start = 0;
|
||||
for (int i = 0; i < line.intValue(); i++) { start = text.indexOf('\n', start); if (start < 0) return -1; start++; }
|
||||
int end = text.indexOf('\n', start); if (end < 0) end = text.length();
|
||||
return character.intValue() < 0 || start + character.intValue() > end ? -1 : start + character.intValue();
|
||||
}
|
||||
}
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
package p.studio.ui.javafx.diagnostics;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.scene.Scene;
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
/** UI of the canonical bounded public view, shared by DEV and build. */
|
||||
public final class DiagnosticResultsPane extends VBox {
|
||||
private final Path root;
|
||||
private Map<String, Object> displayed = Map.of();
|
||||
private static final ObjectMapper JSON = new ObjectMapper();
|
||||
public DiagnosticResultsPane(Path root) { super(8); this.root = root; setId("diagnostic-results"); setFillWidth(true); setMaxWidth(Double.MAX_VALUE); }
|
||||
public void show(Map<String, Object> view) {
|
||||
if (displayed.equals(view)) return;
|
||||
displayed = view; getChildren().clear();
|
||||
if (view.isEmpty()) return;
|
||||
var summary = (Map<?, ?>)view.getOrDefault("summary", Map.of());
|
||||
var counts = (Map<?, ?>)summary.getOrDefault("counts", null);
|
||||
var status = new Label(Objects.toString(summary.get("scope"), "Result") + ": " + Objects.toString(summary.get("validationStatus"), "not evaluated")
|
||||
+ (counts == null ? "" : " · errors " + count(counts, "errors") + " · warnings " + count(counts, "warnings") + " · info " + count(counts, "infos")));
|
||||
status.setWrapText(true); getChildren().add(status);
|
||||
var stages = (List<?>)summary.getOrDefault("stages", null);
|
||||
if (stages != null && !stages.isEmpty()) {
|
||||
var stageText = new Label(stages.stream().map(raw -> { var stage = (Map<?, ?>)raw; return stage.get("stageId") + ": " + stage.get("status"); }).collect(java.util.stream.Collectors.joining(" · ")));
|
||||
stageText.setWrapText(true); getChildren().add(stageText);
|
||||
}
|
||||
var coverage = (Map<?, ?>)summary.getOrDefault("coverage", null);
|
||||
if (coverage != null) {
|
||||
var coverageText = new Label("Details: " + coverage.get("details") + " · input revisions: " + coverage.get("revisions"));
|
||||
coverageText.setWrapText(true); getChildren().add(coverageText);
|
||||
if (coverage.get("limitations") instanceof List<?> limits && !limits.isEmpty()) {
|
||||
var limitsText = new Label(pretty(limits)); limitsText.setWrapText(true); getChildren().add(limitsText);
|
||||
}
|
||||
}
|
||||
for (var raw : (List<?>) view.getOrDefault("issues", List.of())) {
|
||||
var issue = (Map<String, Object>) raw;
|
||||
var explanation = (Map<?, ?>) issue.getOrDefault("explanation", Map.of());
|
||||
var body = new VBox(6);
|
||||
var rule = new Label(Objects.toString(explanation.get("summary"), "Explanation unavailable")); rule.setWrapText(true);
|
||||
body.getChildren().add(rule);
|
||||
for (var key : List.of("checkId", "facts", "semanticContext", "origin", "related", "suggestedChecks", "limitations")) {
|
||||
var details = new TextArea(pretty(issue.get(key))); details.setEditable(false); details.setWrapText(true); details.setPrefRowCount(4);
|
||||
var section = new TitledPane(key, details); section.setAnimated(false); section.setExpanded(false); body.getChildren().add(section);
|
||||
}
|
||||
addOrigin(body, "Open source", issue.get("origin"));
|
||||
for (var related : (List<?>) issue.getOrDefault("related", List.of())) {
|
||||
var relation = (Map<?, ?>) related;
|
||||
addOrigin(body, "Open related source", relation.get("origin"));
|
||||
}
|
||||
var item = new TitledPane(issue.get("severity") + " · " + issue.get("code") + " · " + issue.get("message"), body);
|
||||
item.setAnimated(false); item.setExpanded(false); item.setId("diagnostic-" + issue.get("issueId")); getChildren().add(item);
|
||||
}
|
||||
}
|
||||
private void addOrigin(VBox body, String label, Object raw) {
|
||||
if (!(raw instanceof Map<?, ?>)) return;
|
||||
var origin = (Map<String, Object>) raw;
|
||||
var button = new Button(label); button.setDisable(origin.get("uri") == null);
|
||||
button.setOnAction(event -> {
|
||||
button.setDisable(true);
|
||||
CompletableFuture.supplyAsync(() -> DiagnosticNavigation.read(root, origin)).thenAccept(source -> Platform.runLater(() -> {
|
||||
button.setDisable(false);
|
||||
var text = new TextArea(source.text()); text.setEditable(false); text.selectRange(source.start(), source.end());
|
||||
var window = new Stage(); window.setTitle(source.status());
|
||||
window.setScene(new Scene(new VBox(8, new Label(source.status()), text), 900, 600));
|
||||
if (getScene() != null) window.initOwner(getScene().getWindow()); window.show();
|
||||
}));
|
||||
}); body.getChildren().add(button);
|
||||
}
|
||||
private static String count(Map<?, ?> counts, String key) { return Objects.toString(counts.get(key), "unknown"); }
|
||||
private static String pretty(Object value) {
|
||||
try { return JSON.writerWithDefaultPrettyPrinter().writeValueAsString(value); }
|
||||
catch (Exception impossible) { throw new IllegalArgumentException("Invalid diagnostic JSON", impossible); }
|
||||
}
|
||||
}
|
||||
+7
-3
@@ -18,6 +18,7 @@ import p.studio.ui.javafx.workspaces.WorkspaceId;
|
||||
|
||||
public class ShipperWorkspace extends Workspace {
|
||||
private final BorderPane root = new BorderPane();
|
||||
private final p.studio.ui.javafx.diagnostics.DiagnosticResultsPane diagnosticResults;
|
||||
private final TextArea logs = new TextArea();
|
||||
private final Button buildButton = new Button();
|
||||
private final Button clearButton = new Button();
|
||||
@@ -30,13 +31,15 @@ public class ShipperWorkspace extends Workspace {
|
||||
super(projectReference, eventBus);
|
||||
this.shipperService = java.util.Objects.requireNonNull(shipperService, "shipperService");
|
||||
this.i18n = java.util.Objects.requireNonNull(i18n, "i18n");
|
||||
diagnosticResults = new p.studio.ui.javafx.diagnostics.DiagnosticResultsPane(projectReference.rootPath());
|
||||
final var toolbar = buildToolBar();
|
||||
root.setTop(toolbar);
|
||||
|
||||
final var projectArea = buildProjectArea();
|
||||
final var logsPane = buildLogsPane();
|
||||
|
||||
final var split = new SplitPane(projectArea, logsPane);
|
||||
var diagnosticScroll = new ScrollPane(diagnosticResults); diagnosticScroll.setFitToWidth(true);
|
||||
final var split = new SplitPane(projectArea, diagnosticScroll, logsPane);
|
||||
split.setOrientation(Orientation.VERTICAL);
|
||||
split.setDividerPositions(0.5);
|
||||
|
||||
@@ -84,10 +87,11 @@ public class ShipperWorkspace extends Workspace {
|
||||
"[%s] %s%s".formatted(entry.source().name(), entry.message(), System.lineSeparator()))));
|
||||
buildOperation = operation;
|
||||
operation.completion()
|
||||
.whenComplete((result, failure) -> Platform.runLater(() -> {
|
||||
.whenComplete((result, failure) -> operation.termination().whenComplete((stopped, stopFailure) -> Platform.runLater(() -> {
|
||||
if (buildOperation != operation) {
|
||||
return;
|
||||
}
|
||||
if (result != null) diagnosticResults.show(result.diagnosticView());
|
||||
buildOperation = null;
|
||||
buildButton.setDisable(false);
|
||||
if (failure != null) {
|
||||
@@ -96,7 +100,7 @@ public class ShipperWorkspace extends Workspace {
|
||||
java.util.Objects.requireNonNullElse(cause.getMessage(), cause.getClass().getSimpleName()),
|
||||
System.lineSeparator()));
|
||||
}
|
||||
}));
|
||||
})));
|
||||
});
|
||||
|
||||
clearButton.textProperty().bind(i18n.bind(I18n.WORKSPACE_SHIPPER_BUTTON_CLEAR));
|
||||
|
||||
+4
-1
@@ -23,6 +23,7 @@ public final class DevWorkspace extends Workspace {
|
||||
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 p.studio.ui.javafx.diagnostics.DiagnosticResultsPane diagnosticResults;
|
||||
private final ImageView canvas = new ImageView();
|
||||
private final Button grant = new Button(), reclaim = new Button();
|
||||
private final Button configuration = new Button();
|
||||
@@ -44,6 +45,7 @@ public final class DevWorkspace extends Workspace {
|
||||
AgentConnectionGuide connectionGuide) {
|
||||
super(project, events); this.automation = automation; this.i18n = i18n;
|
||||
this.connectionGuide = java.util.Objects.requireNonNull(connectionGuide); projectRoot = project.rootPath();
|
||||
diagnosticResults = new p.studio.ui.javafx.diagnostics.DiagnosticResultsPane(projectRoot);
|
||||
localeListener = (o, before, after) -> apply(this.automation.snapshot());
|
||||
scroll.setFitToWidth(true);
|
||||
root.setPadding(new Insets(16)); root.getStyleClass().add("dev-workspace");
|
||||
@@ -77,7 +79,7 @@ public final class DevWorkspace extends Workspace {
|
||||
root.getChildren().addAll(new Label(project.name() + " — " + project.rootPath()),
|
||||
state, new HBox(10, grant, reclaim, configuration), discardGameData, availability, copyStatus, instructions, warning,
|
||||
operation, imageStatus, imagePane, identity,
|
||||
pane(I18n.DEV_DIAGNOSTICS, diagnostics), pane(I18n.DEV_HISTORY, history));
|
||||
pane(I18n.DEV_DIAGNOSTICS, diagnostics), diagnosticResults, pane(I18n.DEV_HISTORY, history));
|
||||
apply(automation.snapshot());
|
||||
}
|
||||
|
||||
@@ -136,6 +138,7 @@ public final class DevWorkspace extends Workspace {
|
||||
boolean blockedReturn = snapshot.state() == ControlState.RETURNING_CONTROL && !snapshot.diagnostics().isEmpty();
|
||||
discardGameData.setVisible(blockedReturn); discardGameData.setManaged(blockedReturn);
|
||||
identity.setText(view.identity()); operation.setText(view.operation());
|
||||
diagnosticResults.show(view.diagnosticResult());
|
||||
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()) {
|
||||
|
||||
+2
-2
@@ -3,7 +3,7 @@ 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) {
|
||||
boolean stale, CanonicalCapture capture, String identity, String operation, String diagnostics, String calls, java.util.Map<String, Object> diagnosticResult) {
|
||||
public static DevWorkspaceProjection from(AutomationSnapshot s) {
|
||||
var frame = s.capture();
|
||||
String identity = frame == null ? "" : "session=" + frame.sessionId() + " | build=" + frame.buildId()
|
||||
@@ -11,6 +11,6 @@ public record DevWorkspaceProjection(ControlState state, boolean grantEnabled, b
|
||||
+ " | " + 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()));
|
||||
String.join("\n", s.diagnostics()), String.join("\n", s.calls()), s.diagnosticResult());
|
||||
}
|
||||
}
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package p.studio.ui.javafx.diagnostics;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import java.nio.file.*;
|
||||
import java.util.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class DiagnosticNavigationTest {
|
||||
@TempDir Path root;
|
||||
@Test void unicodeRangeIsSelectedOnlyForMatchingAdmittedRevision() throws Exception {
|
||||
Path file = root.resolve("main.pbs"); byte[] bytes = "// á 😀\r\nfn x() {}\n".getBytes(java.nio.charset.StandardCharsets.UTF_8); Files.write(file, bytes);
|
||||
String sha = HexFormat.of().formatHex(java.security.MessageDigest.getInstance("SHA-256").digest(bytes));
|
||||
var origin = Map.<String, Object>of("uri", file.toUri().toString(), "revision", sha, "range", Map.of("start", Map.of("line", 1, "character", 3), "end", Map.of("line", 1, "character", 4)));
|
||||
var current = DiagnosticNavigation.read(root, origin); assertEquals("x", current.text().substring(current.start(), current.end()));
|
||||
Files.writeString(file, "changed"); var stale = DiagnosticNavigation.read(root, origin);
|
||||
assertTrue(stale.status().startsWith("Stale")); assertEquals(0, stale.start()); assertEquals(0, stale.end());
|
||||
assertNull(DiagnosticNavigation.read(root.resolve("other"), origin).path());
|
||||
assertNull(DiagnosticNavigation.read(root, Map.of("uri", "prometeu-source:unowned")).path());
|
||||
assertNull(DiagnosticNavigation.read(root, Map.of()).path());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user