feat(studio): improve compiler reliability and AI diagnostics
Test / Tests and coverage occurred while executing withChecks step.
Intrepid/Prometeu/Studio/pipeline/pr-master There was a failure building this commit

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:
2026-11-10 12:36:25 +00:00
parent 38f201a9c9
commit ea1cc26fe3
1216 changed files with 168017 additions and 354 deletions
+38
View File
@@ -0,0 +1,38 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.readEndpoint = readEndpoint;
exports.reconnectDelay = reconnectDelay;
const node_fs_1 = require("node:fs");
const node_path_1 = require("node:path");
function readEndpoint(root) {
const canonicalRoot = (0, node_fs_1.realpathSync)(root);
let text;
try {
text = (0, node_fs_1.readFileSync)((0, node_path_1.join)(canonicalRoot, ".studio", "lsp.json"), "utf8");
}
catch (error) {
if (error.code === "ENOENT")
return undefined;
throw error;
}
const value = JSON.parse(text);
if (!value || value.schemaVersion !== 1 || value.projectRoot !== canonicalRoot
|| value.host !== "127.0.0.1" || !Number.isInteger(value.port) || value.port < 1 || value.port > 65535
|| typeof value.sessionId !== "string" || !value.sessionId
|| !Number.isSafeInteger(value.processId) || value.processId < 1) {
throw new Error("Invalid project LSP discovery metadata. Reopen the project in Studio.");
}
try {
process.kill(value.processId, 0);
}
catch (error) {
if (error.code === "ESRCH")
return undefined;
throw error;
}
return value;
}
function reconnectDelay(attempt) {
return Math.min(30000, 2000 * 2 ** Math.min(attempt, 4));
}
//# sourceMappingURL=discovery.js.map
+127 -19
View File
@@ -35,6 +35,8 @@ var __importStar = (this && this.__importStar) || (function () {
Object.defineProperty(exports, "__esModule", { value: true });
exports.activate = activate;
exports.deactivate = deactivate;
const node_fs_1 = require("node:fs");
const discovery_1 = require("./discovery");
const net = __importStar(require("node:net"));
const vscode = __importStar(require("vscode"));
const externalSources_1 = require("./externalSources");
@@ -46,10 +48,58 @@ let reconnectContext;
let stoppingClient = false;
let lastAppliedThemeSignature;
const externalSources = new externalSources_1.ExternalSources();
const RECONNECT_DELAY_MS = 2000;
let reconnectAttempt = 0;
let connectionStatus;
let lastStatus = "";
let startPromise;
let restartQueue = Promise.resolve();
let disposed = false;
let endpointKey;
let endpointSession;
function status(message) {
connectionStatus.text = `$(plug) Prometeu: ${message}`;
connectionStatus.tooltip = message;
connectionStatus.show();
if (message !== lastStatus) {
output.appendLine(message);
lastStatus = message;
}
}
function restart(context) {
restartQueue = restartQueue.then(async () => {
await stopClient();
reconnectAttempt = 0;
if (!disposed)
await startClient(context);
}).catch(error => { status(String(error)); scheduleReconnect(); });
return restartQueue;
}
// The reconnect controller owns availability feedback; avoid languageclient's
// forced error notifications for expected offline/obsolete discovery endpoints.
class StudioLanguageClient extends node_1.LanguageClient {
async stop(timeout) {
// languageclient 9 invokes stop before its failed initialize has left
// Starting. Wait for that start to settle before disposing the transport.
if (this.state === node_1.State.Starting)
await this.start().catch(() => undefined);
await super.stop(timeout);
}
error(message, _data, _showNotification) {
status(`Studio unavailable: ${message}`);
}
}
const VSCODE_HOST_ID = "vscode";
function activate(context) {
disposed = false;
reconnectContext = context;
connectionStatus = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
connectionStatus.command = "prometeu.restartStudioLsp";
const watcher = vscode.workspace.createFileSystemWatcher("**/.studio/lsp.json");
const changed = () => { void restart(context); };
context.subscriptions.push(connectionStatus, watcher, watcher.onDidCreate(changed), watcher.onDidChange(changed), watcher.onDidDelete(changed), vscode.workspace.onDidChangeWorkspaceFolders(changed), vscode.workspace.onDidChangeConfiguration(event => {
if (event.affectsConfiguration("prometeu.studio"))
changed();
}));
output = vscode.window.createOutputChannel("Prometeu LSP");
output.appendLine("Prometeu VS Code extension activated.");
context.subscriptions.push(externalSources, vscode.languages.registerCodeLensProvider({ scheme: externalSources_1.externalScheme, language: "pbs" }, {
@@ -63,16 +113,20 @@ function activate(context) {
}
}), vscode.workspace.registerTextDocumentContentProvider(externalSources_1.externalScheme, externalSources), vscode.window.onDidChangeActiveTextEditor(() => externalSources.refreshStatus()), vscode.workspace.onDidOpenTextDocument(document => void externalSources.opened(document)), vscode.workspace.onDidCloseTextDocument(document => void externalSources.closeDocument(document)));
const connectCommand = vscode.commands.registerCommand("prometeu.connectStudioLsp", async () => {
reconnectAttempt = 0;
await startClient(context);
});
const restartCommand = vscode.commands.registerCommand("prometeu.restartStudioLsp", async () => {
await stopClient();
await startClient(context);
await restart(context);
});
context.subscriptions.push(output, connectCommand, restartCommand);
void startClient(context);
}
async function deactivate() {
disposed = true;
reconnectContext = undefined;
clearReconnectTimer();
await restartQueue;
try {
await externalSources.shutdown();
}
@@ -81,16 +135,60 @@ async function deactivate() {
}
}
async function startClient(context) {
if (disposed)
return;
if (startPromise)
return startPromise;
startPromise = startClientOnce(context).finally(() => { startPromise = undefined; });
return startPromise;
}
async function startClientOnce(context) {
clearReconnectTimer();
if (client) {
output.appendLine("Prometeu LSP client is already running.");
return;
}
const config = vscode.workspace.getConfiguration("prometeu.studio");
const host = config.get("host", "127.0.0.1");
const port = config.get("port", 7775);
output.show(true);
output.appendLine(`Connecting to Prometeu Studio LSP at ${host}:${port}...`);
const folders = vscode.workspace.workspaceFolders;
if (!folders || folders.length !== 1 || folders[0].uri.scheme !== "file") {
status("Open one local Prometeu project folder.");
return;
}
const folder = folders[0];
const config = vscode.workspace.getConfiguration("prometeu.studio", folder.uri);
let host;
let port;
let root;
let session;
try {
root = (0, node_fs_1.realpathSync)(folder.uri.fsPath);
if (config.get("connectionMode", "auto") === "manual") {
host = config.get("host", "127.0.0.1");
port = config.get("port", 7775);
}
else {
const endpoint = (0, discovery_1.readEndpoint)(root);
if (!endpoint) {
status("Waiting for Studio — open this project in Studio.");
scheduleReconnect();
return;
}
({ host, port } = endpoint);
session = endpoint.sessionId;
}
}
catch (error) {
status(error instanceof Error ? error.message : String(error));
scheduleReconnect();
return;
}
const key = `${root}:${host}:${port}`;
if (endpointKey !== key || (session !== undefined && endpointSession !== session)) {
externalSources.resetSession();
}
endpointKey = key;
if (session !== undefined)
endpointSession = session;
status(`Connecting to ${host}:${port}`);
const serverOptions = async () => {
return new Promise((resolve, reject) => {
const socket = net.createConnection({ host, port });
@@ -126,6 +224,7 @@ async function startClient(context) {
});
};
const clientOptions = {
workspaceFolder: { ...folder, uri: vscode.Uri.file(root) },
documentSelector: [
{
scheme: "file",
@@ -143,6 +242,8 @@ async function startClient(context) {
prometeuClientVersion: context.extension.packageJSON.version
},
outputChannel: output,
revealOutputChannelOn: node_1.RevealOutputChannelOn.Never,
initializationFailedHandler: () => false,
middleware: {
prepareRename: (document, position, token, next) => document.uri.scheme === externalSources_1.externalScheme ? null : next(document, position, token),
provideRenameEdits: (document, position, name, token, next) => document.uri.scheme === externalSources_1.externalScheme ? null : next(document, position, name, token),
@@ -158,12 +259,12 @@ async function startClient(context) {
return { action: node_1.ErrorAction.Continue };
},
closed: () => {
output.appendLine("Prometeu LSP transport closed.");
return { action: node_1.CloseAction.DoNotRestart };
status("Waiting for Studio — connection closed.");
return { action: node_1.CloseAction.DoNotRestart, handled: true };
}
}
};
const nextClient = new node_1.LanguageClient("prometeuStudioLsp", "Prometeu Studio LSP", serverOptions, clientOptions);
const nextClient = new StudioLanguageClient("prometeuStudioLsp", "Prometeu Studio LSP", serverOptions, clientOptions);
client = nextClient;
nextClient.registerFeature({
fillClientCapabilities(capabilities) {
@@ -172,7 +273,6 @@ async function startClient(context) {
initialize() { }, clear() { }, getState() { return { kind: "static" }; }
});
nextClient.onDidChangeState((event) => {
output.appendLine(`Prometeu LSP state changed: ${node_1.State[event.oldState]} -> ${node_1.State[event.newState]}`);
if (event.newState !== node_1.State.Stopped) {
return;
}
@@ -188,8 +288,8 @@ async function startClient(context) {
await nextClient.start();
await externalSources.connected(nextClient);
await applyPrometeuVisualTheme(nextClient.initializeResult);
output.appendLine("Prometeu Studio LSP client started.");
vscode.window.showInformationMessage("Connected to Prometeu Studio LSP.");
reconnectAttempt = 0;
status(`Connected to Studio at ${host}:${port}`);
}
catch (error) {
externalSources.resetSession();
@@ -197,14 +297,22 @@ async function startClient(context) {
client = undefined;
}
const message = error instanceof Error ? error.message : String(error);
output.appendLine(`Failed to start Prometeu LSP client: ${message}`);
vscode.window.showErrorMessage(`Could not connect to Prometeu Studio LSP: ${message}`);
status(`Studio unavailable: ${message}`);
try {
await nextClient.dispose();
}
catch { /* transport already stopped */ }
scheduleReconnect();
}
}
async function stopClient() {
clearReconnectTimer();
stoppingClient = true;
if (startPromise)
await startPromise;
clearReconnectTimer();
if (!client) {
stoppingClient = false;
return;
}
const currentClient = client;
@@ -224,17 +332,17 @@ async function stopClient() {
}
}
function scheduleReconnect() {
if (!reconnectContext) {
if (!reconnectContext || disposed || stoppingClient) {
return;
}
if (reconnectTimer || client) {
return;
}
output.appendLine(`Scheduling Prometeu LSP reconnect in ${RECONNECT_DELAY_MS}ms...`);
const delay = (0, discovery_1.reconnectDelay)(reconnectAttempt++);
reconnectTimer = setTimeout(() => {
reconnectTimer = undefined;
void startClient(reconnectContext);
}, RECONNECT_DELAY_MS);
}, delay);
}
function clearReconnectTimer() {
if (!reconnectTimer) {
@@ -85,7 +85,7 @@ class ExternalSources {
this.refreshStatus();
}
disconnected() { this.client = undefined; this.available.clear(); this.refreshStatus(); }
resetSession() { this.disconnected(); this.consumerId = undefined; }
resetSession() { this.disconnected(); this.consumerId = undefined; this.closed.clear(); }
request(operation, uri) {
if (!this.client || !this.consumerId)
return Promise.reject(new Error("External source unavailable: reconnect to Studio."));