Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Compilation is delegated to the project's own npm scripts rather than reimplemen

## Extension architecture

- **[`src/model.ts`](src/model.ts)** — the logic layer, near-free of UI: graph discovery (`findGraphFile` probes `.fallout/temp` then `.nuke/temp` across workspace folders), parsing, `checkCompatibility`, and `toMermaid`. The schema `version` is a **hard gate**; the extension-vs-framework `major.minor` comparison is a **soft warning**, deduplicated via a module-level `warned` set.
- **[`src/model.ts`](src/model.ts)** — the logic layer, near-free of UI: graph discovery (`findGraphFile` probes `.fallout/temp` then `.nuke/temp` across workspace folders), parsing, `checkCompatibility`, `toMermaid`, and `loadDeclarations` (declared parameters and verbosity levels for Run Configuration: `parameters[]` from the graph once Fallout#499 ships, otherwise `.fallout/build.schema.json`, where a `[Secret]` member is marked by a placeholder `default`). The schema `version` is a **hard gate**; the extension-vs-framework `major.minor` comparison is a **soft warning**, deduplicated via a module-level `warned` set.
- **[`src/extension.ts`](src/extension.ts)** — tree data provider plus command registration. Relations (`dependsOn`, `after`, `triggeredBy`, `triggers`) render as recursively expandable children. A `**/build-graph.json` watcher refreshes both tree and panel; parse failures during refresh are swallowed deliberately, because the build may be mid-write and the next watcher event re-reads it.
- **[`src/goToTarget.ts`](src/goToTarget.ts)** — C# workspace symbol provider first (precise, needs Roslyn warmed up), regex scan over `**/*.cs` as fallback. `declaredIn` from the graph disambiguates same-named targets declared across component interfaces.
- **[`src/graphPanel.ts`](src/graphPanel.ts)** — singleton webview, CSP-locked with a nonce, `localResourceRoots` scoped to Mermaid's `dist`. Talks to the page via `ready` / `graph` / `run` messages.
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ Inline ▶ on any target runs it in an integrated terminal — `./build.ps1` on

### Run Configuration

A form for the parameters and secrets your build takes:
A form for the parameters and secrets your build takes. Everything the build declares is listed up front, read from the `build.schema.json` the build writes on every run, so `NuGetApiKey` and its peers appear without typing. Free-form rows remain for anything else.

- **Parameters** are passed as `--name value` arguments and stored per workspace.
- **Secrets** are stored in VS Code's [SecretStorage](https://code.visualstudio.com/api/references/vscode-api#SecretStorage) — OS keychain-backed — and passed as **environment variables**, so they never reach your shell history, the process list, or a log. Values are never rendered back into the view; only names are.
- **Verbosity** is a drop-down of the levels your Fallout version supports (`Information` on 10.5+).
- **Secrets** read *not set* until you enter a value. They are stored in VS Code's [SecretStorage](https://code.visualstudio.com/api/references/vscode-api#SecretStorage) — OS keychain-backed — and passed as **environment variables**, so they never reach your shell history, the process list, or a log. Values are never rendered back into the view; only names are.

![The Run Configuration view with a parameter and a secret](https://raw.githubusercontent.com/Fallout-build/Fallout.Extensions.VSCode/develop/.assets/screenshots/run-configuration.png)

Expand Down
17 changes: 15 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as vscode from 'vscode';
import { BuildGraph, GraphSource, Relation, Target, checkCompatibility, findGraphFile, loadGraph } from './model';
import { BuildGraph, GraphSource, Relation, Target, checkCompatibility, findGraphFile, loadDeclarations, loadGraph } from './model';
import { GraphPanel } from './graphPanel';
import { goToTarget } from './goToTarget';
import { RunConfigStore, RunConfigViewProvider } from './runConfig';
Expand Down Expand Up @@ -163,8 +163,14 @@ export function activate(context: vscode.ExtensionContext): void {
runInTerminal(root, edited, await runConfig.buildEnv());
};

const runConfigView = new RunConfigViewProvider(
runConfig,
context.subscriptions,
() => loadDeclarations(workspaceRoot(), provider.graph));

const refreshAll = () => {
provider.refresh();
runConfigView.refreshDeclarations();
const source = findGraphFile();
if (source) {
try {
Expand All @@ -180,14 +186,21 @@ export function activate(context: vscode.ExtensionContext): void {
watcher.onDidCreate(refreshAll);
watcher.onDidDelete(() => provider.refresh());

// The build rewrites build.schema.json on every initialization, next to the graph.
const schemaWatcher = vscode.workspace.createFileSystemWatcher('**/build.schema.json');
schemaWatcher.onDidChange(() => runConfigView.refreshDeclarations());
schemaWatcher.onDidCreate(() => runConfigView.refreshDeclarations());
schemaWatcher.onDidDelete(() => runConfigView.refreshDeclarations());

context.subscriptions.push(
// Same provider instance backs both the Fallout-container Build view and the
// mirrored Explorer dock — one graph, two homes; refresh() updates both.
vscode.window.registerTreeDataProvider('fallout.build', provider),
vscode.window.registerTreeDataProvider('fallout.buildExplorer', provider),
vscode.window.registerTreeDataProvider('fallout.deployment', new DeploymentProvider()),
vscode.window.registerWebviewViewProvider('fallout.runConfig', new RunConfigViewProvider(runConfig, context.subscriptions)),
vscode.window.registerWebviewViewProvider('fallout.runConfig', runConfigView),
watcher,
schemaWatcher,
vscode.commands.registerCommand('fallout.refreshTargets', refreshAll),
vscode.commands.registerCommand('fallout.runTarget', (item?: TargetItem) => {
if (item?.target) {
Expand Down
74 changes: 74 additions & 0 deletions src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,30 @@ export interface Target {
triggers: string[];
}

/** A declared build parameter: `parameters[]` in build-graph.json (Fallout#499) or a property of build.schema.json. */
export interface ParameterDecl {
name: string;
description?: string;
secret: boolean;
/** Allowed values, when the parameter is an enumeration or has a value set. */
values?: string[];
declaredIn?: string;
}

/** What the build declares, for the Run Configuration view. */
export interface BuildDeclarations {
parameters: ParameterDecl[];
/** Verbosity levels the running Fallout version supports; empty when unknown. */
verbosityLevels: string[];
}

/** Parsed contents of build-graph.json. */
export interface BuildGraph {
version: number;
falloutVersion?: string;
targets: Target[];
/** Additive, once the framework emits it (Fallout#499). */
parameters?: ParameterDecl[];
}

/** Where the graph was found: the workspace root plus the absolute file path. */
Expand Down Expand Up @@ -79,6 +98,61 @@ export function loadGraph(source: GraphSource): BuildGraph {
return JSON.parse(fs.readFileSync(source.file, 'utf8'));
}

const SCHEMA_LOCATIONS = ['.fallout/build.schema.json', '.nuke/build.schema.json'];

/** The framework writes this placeholder as the `default` of every `[Secret]` parameter. */
const SECRET_DEFAULT_MARKER = 'Secrets must be entered via';

/**
* What the build declares: `parameters[]` from the graph when the framework emits it, otherwise
* the `[Parameter]` members in build.schema.json (the build writes it next to the graph on every
* initialization). Empty when neither exists, which leaves Run Configuration free-form.
*/
export function loadDeclarations(root: string | undefined, graph?: BuildGraph): BuildDeclarations {
const schema = readSchema(root);
return {
parameters: graph?.parameters ?? parametersFromSchema(schema),
verbosityLevels: schema?.definitions?.Verbosity?.enum ?? [],
};
}

function readSchema(root: string | undefined): any {
const file = root
? SCHEMA_LOCATIONS.map(rel => path.join(root, ...rel.split('/'))).find(f => fs.existsSync(f))
: undefined;
if (!file) {
return undefined;
}
try {
return JSON.parse(fs.readFileSync(file, 'utf8'));
} catch {
return undefined; // the build may be mid-write; the next watcher event re-reads it
}
}

// Shape: { definitions, allOf: [ <consumer parameters>, { $ref: FalloutBuild } ] }. Only the first
// part holds declared parameters; the framework's own (Target, Skip, Verbosity, ...) are not run inputs.
function parametersFromSchema(schema: any): ParameterDecl[] {
const properties: Record<string, any> = schema?.allOf?.[0]?.properties ?? {};
return Object.entries(properties)
.map(([name, p]): ParameterDecl => {
const resolved = resolveRef(schema, p);
const values = resolved.enum ?? resolved.items?.enum ?? resolveRef(schema, resolved.items).enum;
return {
name,
description: p.description ?? resolved.description,
secret: typeof p.default === 'string' && p.default.startsWith(SECRET_DEFAULT_MARKER),
values: Array.isArray(values) && values.length > 0 ? values : undefined,
};
})
.sort((a, b) => a.name.localeCompare(b.name));
}

function resolveRef(schema: any, node: any): any {
const ref: string | undefined = node?.$ref;
return ref?.startsWith('#/definitions/') ? schema?.definitions?.[ref.slice('#/definitions/'.length)] ?? {} : node ?? {};
}

/**
* Builds the Mermaid flowchart definition. Same edge semantics as the --plan HTML:
* solid = execution dependency, dashed = order dependency, thick = trigger.
Expand Down
Loading