Skip to content
Merged
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
10 changes: 5 additions & 5 deletions engine/PROVENANCE.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
"schema": "cloudcell.om-engine-artifact.v1",
"component": "om-engine-zig",
"artifact": "engine/om_engine.wasm",
"size_bytes": 1439713,
"git_blob_sha1": "06c0e1189186a7efb606c1dde494b11608b8bb04",
"sha256": "48de5ad073c09573692feb46990ccc271cdba3e92b90d93ebcd2332cf18a5515",
"size_bytes": 1439857,
"git_blob_sha1": "7e25ccbe056a4fd881e212b66bd16c239f06f39b",
"sha256": "bba9178528c18a17430fd176f28bf93adf70566eff76b7493fc0b16d7e5f850c",
"engine_repository": "cloudcell/om-engine-zig-dev",
"engine_commit": "ec66571a0a82b06ee421c3d4b2ac931d37874715",
"engine_commit": "156ca496a7b50816801c7cc46a47d54a7c081fd1",
"engine_commit_verified": true,
"source_provenance": "Matched local clean Zig repository build and git commit",
"ts_runtime_version": "ts_runtime 0.1.0 @ 0e50bc0 (synced 2026-11-24T04:32:43Z)",
"ts_runtime_version": "ts_runtime 0.1.0 @ 9564c6f (synced 2026-11-24T22:07:13Z)",
"binary_license": "legal/ENGINE-BINARY-LICENSE.md",
"third_party_notices": [
"legal/CORE-MATH-MIT.txt"
Expand Down
2 changes: 1 addition & 1 deletion engine/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ts_runtime 0.1.0 @ 0e50bc0 (synced 2026-11-24T04:32:43Z)
ts_runtime 0.1.0 @ 9564c6f (synced 2026-11-24T22:07:13Z)
Binary file modified engine/om_engine.wasm
Binary file not shown.
16 changes: 15 additions & 1 deletion shared/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ export interface UiOptions {
docking?: boolean;
/** Experimental panels: Performance Watch and Timeline in the View menu. Off by default. */
advancedPanels?: boolean;
/** Contextual first-use tips (T-tips). Managed in Tools → Options and Help → Show Tips. */
showTips?: boolean;
}

/** What a fresh install uses — shown next to each control in the Options dialog. */
Expand All @@ -182,6 +184,7 @@ export const DEFAULT_OPTIONS: Required<UiOptions> = {
assistant: true,
docking: true,
advancedPanels: false,
showTips: true,
};

/** Aggregate-sign choices offered in Tools → Options. The first entry is the default. */
Expand All @@ -193,11 +196,22 @@ export const AGGREGATE_SIGN_CHOICES: { value: string; label: string }[] = [
{ value: "#", label: "# Hash" },
];

/** Everything the webview persists. `saveUiState` params: `{ state: UiState }`. */
/** Contextual-tip memory: ids the user acknowledged with "Got it". Dismissed-but-unacknowledged
* tips are absent, so they may re-fire — `seen` is deliberately small. */
export interface UiTips {
seen?: string[];
/** First-run guided tour completed/skipped/declined — suppresses the invite. */
tourDone?: boolean;
}

/** Everything the webview persists. `saveUiState` params: `{ state: UiState }`.
* NOTE: every field added here must also gain a whitelist branch in the host's
* `sanitizeUiState` (src/uiState.ts) or it is silently stripped in VS Code. */
export interface UiState {
layout?: UiLayout;
theme?: UiTheme;
options?: UiOptions;
tips?: UiTips;
}

/** Name of the `<meta>` tag through which the VS Code host hands the saved UiState to a new webview
Expand Down
44 changes: 39 additions & 5 deletions src/uiState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,22 @@
// The webview is the less trusted side, so the host re-validates instead of storing whatever object it is handed.
// Pure, no `vscode` import.

import type { UiState, UiLayout, UiTheme } from "../shared/messages";
import { AGGREGATE_SIGN_CHOICES } from "../shared/messages";
import type { UiState, UiLayout, UiTheme, UiOptions, UiTips } from "../shared/messages";

/** Hard cap on the stored JSON (a real state is ~100 bytes). */
export const UI_STATE_MAX_BYTES = 4096;
const THEMES: readonly UiTheme[] = ["light", "dark"];
const NUMBER_FIELDS: (keyof UiLayout)[] = ["leftDockWidth", "rulePanelHeight"];
const BOOL_FIELDS: (keyof UiLayout)[] = ["leftCollapsed", "rulePanelCollapsed"];
/** Cap on the serialized `tips` member alone — ~100+ tip ids, effectively unlimited
* for any real registry while staying well under UI_STATE_MAX_BYTES. */
const TIPS_MAX_BYTES = 2048;
/** Cap on the serialized `dock` member — zone/tab layout is nested but stays small. */
const DOCK_MAX_BYTES = 3072;
const TIP_ID_MAX_CHARS = 64;
const MAX_PX = 20000;
const THEMES: readonly UiTheme[] = ["light", "dark"];
const NUMBER_FIELDS: (keyof UiLayout)[] = ["leftDockWidth", "rightDockWidth", "rulePanelHeight"];
const BOOL_FIELDS: (keyof UiLayout)[] = ["leftCollapsed", "rightCollapsed", "rulePanelCollapsed"];
const OPTION_BOOL_FIELDS: (keyof UiOptions)[] = ["markHardvalues", "assistant", "docking", "advancedPanels", "showTips"];

/** A clean copy with only the known, valid fields, or null when nothing usable is left or the input is not an object. */
export function sanitizeUiState(input: unknown): UiState | null {
Expand All @@ -26,8 +34,34 @@ export function sanitizeUiState(input: unknown): UiState | null {
if (typeof v === "number" && Number.isFinite(v) && v >= 0 && v <= MAX_PX) (clean as any)[k] = v;
}
for (const k of BOOL_FIELDS) if (typeof l[k] === "boolean") (clean as any)[k] = l[k];
// The dock-zone layout is nested; bound it by size rather than deep-whitelisting its shape.
if (l.dock && typeof l.dock === "object" && !Array.isArray(l.dock) && JSON.stringify(l.dock).length <= DOCK_MAX_BYTES)
clean.dock = l.dock as UiLayout["dock"];
if (Object.keys(clean).length) out.layout = clean;
}
if (!out.theme && !out.layout) return null;
const options = src.options;
if (options && typeof options === "object" && !Array.isArray(options)) {
const o = options as Record<string, unknown>;
const clean: UiOptions = {};
for (const k of OPTION_BOOL_FIELDS) if (typeof o[k] === "boolean") (clean as any)[k] = o[k];
if (typeof o.aggregateSign === "string" && AGGREGATE_SIGN_CHOICES.some((c) => c.value === o.aggregateSign))
clean.aggregateSign = o.aggregateSign;
if (Object.keys(clean).length) out.options = clean;
}
const tips = src.tips;
if (tips && typeof tips === "object" && !Array.isArray(tips)) {
const cleanTips: UiTips = {};
const seen = (tips as Record<string, unknown>).seen;
if (Array.isArray(seen)) {
const clean = seen.filter((s): s is string => typeof s === "string" && s.length > 0 && s.length <= TIP_ID_MAX_CHARS);
// Bound by serialized size, not entry count — drop oldest (FIFO) until it fits.
while (clean.length && JSON.stringify(clean).length > TIPS_MAX_BYTES) clean.shift();
if (clean.length) cleanTips.seen = clean;
}
// tourDone is only meaningful when true; absent/false both mean "not done".
if ((tips as Record<string, unknown>).tourDone === true) cleanTips.tourDone = true;
if (Object.keys(cleanTips).length) out.tips = cleanTips;
}
if (!out.theme && !out.layout && !out.options && !out.tips) return null;
return JSON.stringify(out).length <= UI_STATE_MAX_BYTES ? out : null;
}
7 changes: 7 additions & 0 deletions webview/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { AppShell } from "./components/appShell";
import { applyTheme, sanitizeTheme } from "./theme";
import { parseSession } from "../shared/session";
import { alertDialog } from "./components/dialogs";
import { initTips } from "./tips";
import { initTour } from "./tour";
import type { Transport } from "./transport";
import "./styles.css";

Expand Down Expand Up @@ -35,6 +37,11 @@ export async function mount(root: HTMLElement, opts: MountOptions): Promise<OmGu
const shell = new AppShell(store);
root.replaceWith(shell.render());

// Contextual first-use tips (T-tips): subscribes to the store's UI-event channel.
initTips(store);
// First-run guided tour: registers the tips suppression gate + first-run invite.
initTour(store);

// Status updates from the host (connecting/connected/disconnected/error).
transport.onStatus((status, message, extra) => {
if (status === "connected") {
Expand Down
15 changes: 12 additions & 3 deletions webview/components/appShell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { makeBundle, BUNDLE_MODEL_MEMBER, BUNDLE_EXT } from "../../shared/omz";
import { applyTheme, currentTheme } from "../theme";
import { el, clear, ICONS, NOT_IN_MVP_TITLE } from "../dom";
import { materialIconSvg as msym, brandIconSvg, type MaterialIcon } from "../menuIcons";
import { tipsEnabled, setTipsEnabled, resetTips } from "../tips";
import { startTour } from "../tour";
import { ModelBrowser } from "./modelBrowser";
import { MultilevelGrid } from "./multilevelGrid";
import { RulePanel } from "./rulePanel";
Expand Down Expand Up @@ -437,7 +439,7 @@ export class AppShell {

// ---- Menu bar ----
private menuBar(): HTMLElement {
const mb = el("div", { class: "menubar" });
const mb = el("div", { class: "menubar", "data-tour": "menubar" });
// Item lists are produced on each open so checked/disabled states reflect current store state.
const menus: [string, () => MenuItem[]][] = [
["File", () => this.fileMenuItems()],
Expand All @@ -450,7 +452,7 @@ export class AppShell {
["Help", () => this.helpMenuItems()],
];
for (const [label, getItems] of menus) {
const mi = el("div", { class: "menu-item" }, [label]);
const mi = el("div", { class: "menu-item", ...(label === "Help" ? { "data-tour": "help-menu" } : {}) }, [label]);
let dd = this.buildMenuList(getItems(), "menu-dropdown");
mi.appendChild(dd);
const open = () => {
Expand Down Expand Up @@ -730,7 +732,7 @@ export class AppShell {
}

private async openOptions() {
const result = await optionsDialog(this.store.state.options);
const result = await optionsDialog(this.store.state.options, () => resetTips());
if (result) this.store.setOptions(result);
}

Expand All @@ -755,6 +757,10 @@ export class AppShell {
...(this.store.api.supportsNativeExternalLinks
? [{ icon: msym("water_drop"), label: "Welcome Screen…", fn: () => window.dispatchEvent(new CustomEvent("om-show-welcome")) } as MenuItem]
: []),
{ icon: msym("menu_book"), label: "Take the Tour…", fn: () => startTour() },
{ icon: msym("info"), label: "Show Tips", checked: tipsEnabled(), fn: () => setTipsEnabled(!tipsEnabled()) },
{ icon: msym("refresh"), label: "Reset Tips…", fn: () => resetTips() },
{ sep: true },
{ icon: msym("info"), label: "About OM Core", fn: () => alertDialog("About OM Core", "OM Core — multidimensional modeling engine GUI.\nVSCode/VSCodium extension connecting to the om-core runtime.\n\nhttps://cloudcell.github.io/om-docs/") },
];
}
Expand Down Expand Up @@ -947,6 +953,8 @@ export class AppShell {
let skips: string[] = [];
try { skips = await this.store.applySession(session, sessionPath); }
catch (e: any) { await alertDialog("Open Session", e?.message || String(e)); return; }
// example-opened fires only on real apply success — errors are swallowed above (F4).
if (sessionPath?.startsWith("om-example:")) this.store.emitUiEvent("example-opened");
if (session.theme && session.theme !== currentTheme()) {
applyTheme(session.theme);
this.store.api.updateUiState({ theme: session.theme });
Expand Down Expand Up @@ -991,6 +999,7 @@ export class AppShell {
const res = await this.store.api.saveBinaryFile(b.suggested, b.bytes).catch(() => null);
if (res?.downloaded)
await alertDialog("Saved to Downloads", "Your browser doesn't support choosing a save location — the bundle was downloaded to your default Downloads folder.");
if (res) this.store.emitUiEvent("bundle-saved");
}

/** File → Share Session… (web build only — the menu item is gated on
Expand Down
26 changes: 24 additions & 2 deletions webview/components/dialogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ export function formDialog(title: string, fields: FormField[], opts: { okLabel?:
/** Tools → Options… — display preferences, persisted in UiState. Each row shows
* what the default setup uses; "Restore defaults" resets every control.
* Resolves with the full options map on OK, or null on Cancel/Escape/outside click. */
export function optionsDialog(current: Required<UiOptions>): Promise<UiOptions | null> {
export function optionsDialog(current: Required<UiOptions>, onResetTips?: () => void): Promise<UiOptions | null> {
return new Promise((resolve) => {
const ov = ensureOverlay();
clear(ov);
Expand Down Expand Up @@ -537,6 +537,27 @@ export function optionsDialog(current: Required<UiOptions>): Promise<UiOptions |
advDefault,
]));

// — Contextual tips —
const tipsCb = document.createElement("input");
tipsCb.type = "checkbox"; tipsCb.checked = current.showTips;
const tipsDefault = el("span", { style: { fontSize: "11px", color: "var(--text-label)", marginLeft: "auto" } },
[`default: ${DEFAULT_OPTIONS.showTips ? "on" : "off"}`]);
dlg.appendChild(el("label", { style: { display: "flex", gap: "6px", alignItems: "center", fontSize: "13px", marginBottom: "16px", cursor: "pointer" } }, [
tipsCb,
document.createTextNode("Show contextual tips"),
el("span", { style: { fontSize: "11px", color: "var(--text-label)" } }, ["first-use hints — Help → Reset Tips… replays them"]),
tipsDefault,
]));
if (onResetTips) {
const tipsReset = el("button", { style: {
padding: "4px 10px", border: "1px solid var(--dlg-border)", borderRadius: "6px",
background: "var(--dlg-btn-bg)", fontSize: "12px", cursor: "pointer", fontFamily: "inherit",
color: "var(--text)", margin: "-6px 0 16px 22px", display: "block",
} }, ["Reset tips…"]) as HTMLButtonElement;
tipsReset.addEventListener("click", () => { onResetTips(); });
dlg.appendChild(tipsReset);
}

// — Buttons —
const btnRow = el("div", { style: { display: "flex", justifyContent: "flex-end", gap: "8px" } }) as HTMLElement;
const resetBtn = el("button", { style: {
Expand All @@ -561,6 +582,7 @@ export function optionsDialog(current: Required<UiOptions>): Promise<UiOptions |
aiCb.checked = DEFAULT_OPTIONS.assistant;
dockCb.checked = DEFAULT_OPTIONS.docking;
advCb.checked = DEFAULT_OPTIONS.advancedPanels;
tipsCb.checked = DEFAULT_OPTIONS.showTips;
signTag.textContent = "(default)";
});
signSelect.addEventListener("change", () => {
Expand All @@ -569,7 +591,7 @@ export function optionsDialog(current: Required<UiOptions>): Promise<UiOptions |

const done = (v: UiOptions | null) => { closeOverlay(); resolve(v); };
cancelBtn.addEventListener("click", () => done(null));
okBtn.addEventListener("click", () => done({ markHardvalues: hvCb.checked, aggregateSign: signSelect.value, assistant: aiCb.checked, docking: dockCb.checked, advancedPanels: advCb.checked }));
okBtn.addEventListener("click", () => done({ markHardvalues: hvCb.checked, aggregateSign: signSelect.value, assistant: aiCb.checked, docking: dockCb.checked, advancedPanels: advCb.checked, showTips: tipsCb.checked }));
dlg.addEventListener("keydown", (e) => {
if (e.key === "Escape") { e.preventDefault(); done(null); }
});
Expand Down
2 changes: 1 addition & 1 deletion webview/components/dockZone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class DockZone {

constructor(readonly id: DockZoneId, private ctl: DockController) {
this.el = el("div", { class: `dock-zone dock-${id}` });
this.tabsEl = el("div", { class: "lower-tabs dock-tabs" });
this.tabsEl = el("div", { class: "lower-tabs dock-tabs", "data-tour": "dock-tabs" });
this.bodyEl = el("div", { class: "dock-body" });
this.el.append(this.tabsEl, this.bodyEl);
}
Expand Down
2 changes: 1 addition & 1 deletion webview/components/statusBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class StatusBar {
}

render(): HTMLElement {
const bar = el("div", { class: "statusbar" });
const bar = el("div", { class: "statusbar", "data-tour": "statusbar" });
const focusPath = el("span", { class: "sb-section" }, ["OM Core"]);
const sep1 = el("span", { class: "sb-sep" }, ["|"]);
const cellAddr = el("span", { class: "sb-section" }, ["—"]);
Expand Down
3 changes: 2 additions & 1 deletion webview/components/viewGroups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { ViewTabDrag } from "./viewTabDrag";
* The tree is rebuilt ONLY when the group structure changes (signature compare) —
* grids and rule panels keep living DOM/subscriptions across ordinary notifies. */
export class ViewArea {
private root = el("div", { class: "view-area" });
private root = el("div", { class: "view-area", "data-tour": "view-area" });
private grids = new Map<string, MultilevelGrid>();
private drag: ViewTabDrag;
private sig = "";
Expand Down Expand Up @@ -139,6 +139,7 @@ export class ViewArea {
const rp = new RulePanel(this.store, gid);
const rules = rp.render();
rules.classList.add("va-rules");
rules.dataset.tour = "rules";
const layout = this.store.state.layout;
const sep = new Splitter({
axis: "y", grow: -1, min: 60, collapsedSize: 28,
Expand Down
31 changes: 30 additions & 1 deletion webview/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@ export class Store {
};
api: OmApi;
private listeners = new Set<Listener>();
private uiEventListeners = new Set<(name: string) => void>();
/** Set for the whole duration of applySession — restored panes/tabs/subpanes are not
* "first use". UI-event subscribers check it to suppress tips mid-restore (T-tips). */
private restoring = false;
isRestoring() { return this.restoring; }
/** Why the in-flight notify() is running — a subscriber whose rebuild is expensive,
* or whose DOM may be the target of a press in progress, can skip a reason that
* cannot change what it renders. "focus" = only focusedGroup moved. Rebuilding
Expand Down Expand Up @@ -222,6 +227,20 @@ export class Store {
this.notifyReason = null;
}

/** Typed UI-action events for app-level observers (T-tips onboarding): a GUI-local
* signal channel (a-07 permits it for UI-only concerns), not the engine MessageBus.
* Kebab-case names; `emitUiEvent` is fire-and-forget like `notify()` — a throwing
* subscriber is logged and dropped, it must never unwind into the caller. */
onUiEvent(fn: (name: string) => void): () => void {
this.uiEventListeners.add(fn);
return () => this.uiEventListeners.delete(fn);
}
emitUiEvent(name: string) {
for (const l of [...this.uiEventListeners]) {
try { l(name); } catch (e) { console.error("uiEvent subscriber failed", e); }
}
}

/** While set, every subscribe() also lands in this bag. See captureSubscriptions(). */
private capture: Set<() => void> | null = null;

Expand Down Expand Up @@ -548,6 +567,7 @@ export class Store {
this.state.viewGroups.push(ng);
this.splitGroupNode(targetGid, side, ng.id);
this.state.focusedGroup = ng.id;
this.emitUiEvent("view-split");
}
if (src && src.tabs.length === 0 && this.state.viewGroups.length > 1) this.removeGroup(src.id);
this.syncViewMirror();
Expand Down Expand Up @@ -594,6 +614,7 @@ export class Store {
if (!g) return;
g.rulesOpen = !g.rulesOpen;
this.notify();
if (g.rulesOpen) this.emitUiEvent("rules-opened");
}

groupRulesOpen(gid?: string): boolean {
Expand Down Expand Up @@ -1031,6 +1052,7 @@ export class Store {
async loadWorkspaceFile(path: string) {
try { await this.api.loadWorkspace(path); } catch (e: any) { await alertDialog("Load failed", e?.message || String(e)); return; }
await this.resetWorkspaceUi(path, true);
if (/^om-example:/.test(path)) this.emitUiEvent("example-opened");
}

/** The host launched a new runtime since this page was last connected (Stop Runtime, then Start Runtime): what the page
Expand Down Expand Up @@ -1130,8 +1152,14 @@ export class Store {
/** Load the descriptor's model then overlay pane/tab/subpane/chip/selection/scroll
* state. Never dirties the model; every unknown ID is skipped and reported. Returns
* the skip notes (empty = fully applied). Throws on fatal model-load failures —
* the caller shows the alert. */
* the caller shows the alert. `restoring` marks the whole duration (T-tips). */
async applySession(session: SessionDescriptor, sessionPath: string | null): Promise<string[]> {
this.restoring = true;
try { return await this.applySessionBody(session, sessionPath); }
finally { this.restoring = false; }
}

private async applySessionBody(session: SessionDescriptor, sessionPath: string | null): Promise<string[]> {
const skips: string[] = [];
const target = this.sessionModelTarget(session, sessionPath);
// A URL reaches the engine only in the browser host (fetch → bytes); the
Expand Down Expand Up @@ -1341,6 +1369,7 @@ export class Store {
toggleDock(name: keyof AppState["dockVisible"]) {
this.state.dockVisible[name] = !this.state.dockVisible[name];
this.notify();
if (name === "rules" && this.state.dockVisible.rules) this.emitUiEvent("rules-opened");
}

// ---- Dock-zone layout (T-dock) ----
Expand Down
Loading
Loading