Skip to content

Commit ad846ac

Browse files
feat(app): add server-backed session empty states (anomalyco#1057)
* feat(app): seed blueprint-driven session empty states * fix(app): use server-backed session blueprints
1 parent fb5ab39 commit ad846ac

5 files changed

Lines changed: 355 additions & 53 deletions

File tree

‎ARCHITECTURE.md‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,23 @@ Auto-detection can exist as a convenience, but should be tiered and explainable:
3030

3131
The readiness check should be a clear, single command (e.g. `docker info`) and the UI should show the exact error output when it fails.
3232

33+
## Filesystem mutation policy
34+
35+
OpenWork should route filesystem mutations through the OpenWork server whenever possible.
36+
37+
Why:
38+
39+
- the server is the one place that can apply the same behavior for both local and remote workspaces
40+
- server-routed writes keep permission checks, approvals, audit trails, and reload events consistent
41+
- Tauri-only filesystem mutations only work in desktop host mode and break parity with remote execution
42+
43+
Guidelines:
44+
45+
- Any UI feature that changes workspace files or config should call an OpenWork server endpoint first.
46+
- Local Tauri filesystem commands are a host-mode fallback, not the primary product surface.
47+
- If a feature cannot yet write through the OpenWork server, treat that as an architecture gap and close it before depending on direct local writes.
48+
- Reads can fall back locally when necessary, but writes should be designed around the OpenWork server path.
49+
3350
## opencode primitives
3451
how to pick the right extension abstraction for
3552
@opencode

‎apps/app/src/app/app.tsx‎

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ import {
7272
mapConfigProvidersToList,
7373
providerPriorityRank,
7474
} from "./utils/providers";
75+
import {
76+
buildDefaultWorkspaceBlueprint,
77+
normalizeWorkspaceOpenworkConfig,
78+
} from "./lib/workspace-blueprints";
7579
import { SYNTHETIC_SESSION_ERROR_MESSAGE_PREFIX } from "./types";
7680
import type {
7781
Client,
@@ -105,6 +109,7 @@ import type {
105109
OpencodeConnectStatus,
106110
ScheduledJob,
107111
WorkspacePreset,
112+
WorkspaceOpenworkConfig,
108113
} from "./types";
109114
import {
110115
clearStartupPreference,
@@ -936,6 +941,8 @@ export default function App() {
936941
const [openworkAuditStatus, setOpenworkAuditStatus] = createSignal<"idle" | "loading" | "error">("idle");
937942
const [openworkAuditError, setOpenworkAuditError] = createSignal<string | null>(null);
938943
const [devtoolsWorkspaceId, setDevtoolsWorkspaceId] = createSignal<string | null>(null);
944+
const [activeWorkspaceServerConfig, setActiveWorkspaceServerConfig] =
945+
createSignal<WorkspaceOpenworkConfig | null>(null);
939946

940947
const openworkServerBaseUrl = createMemo(() => {
941948
const pref = startupPreference();
@@ -5014,6 +5021,9 @@ export default function App() {
50145021

50155022
const activeAuthorizedDirs = createMemo(() => workspaceStore.authorizedDirs());
50165023
const activeWorkspaceDisplay = createMemo(() => workspaceStore.activeWorkspaceDisplay());
5024+
const resolvedActiveWorkspaceConfig = createMemo(
5025+
() => activeWorkspaceServerConfig() ?? workspaceStore.workspaceConfig(),
5026+
);
50175027
const activePermissionMemo = createMemo(() => activePermission());
50185028
const migrationRepairUnavailableReason = createMemo<string | null>(() => {
50195029
if (workspaceStore.canRepairOpencodeMigration()) return null;
@@ -5046,6 +5056,57 @@ export default function App() {
50465056
});
50475057
const [autoConnectAttempted, setAutoConnectAttempted] = createSignal(false);
50485058

5059+
createEffect(() => {
5060+
const workspace = activeWorkspaceDisplay();
5061+
const openworkClient = openworkServerClient();
5062+
const workspaceId = openworkServerWorkspaceId();
5063+
const capabilities = resolvedOpenworkCapabilities();
5064+
const canReadConfig =
5065+
openworkServerStatus() === "connected" &&
5066+
Boolean(openworkClient && workspaceId && capabilities?.config?.read);
5067+
5068+
if (!canReadConfig || !openworkClient || !workspaceId) {
5069+
setActiveWorkspaceServerConfig(null);
5070+
return;
5071+
}
5072+
5073+
let cancelled = false;
5074+
5075+
const loadWorkspaceConfig = async () => {
5076+
try {
5077+
const config = await openworkClient.getConfig(workspaceId);
5078+
if (cancelled) return;
5079+
5080+
const normalized = normalizeWorkspaceOpenworkConfig(
5081+
config.openwork,
5082+
workspace.preset,
5083+
);
5084+
5085+
if (!normalized.blueprint) {
5086+
setActiveWorkspaceServerConfig({
5087+
...normalized,
5088+
blueprint: buildDefaultWorkspaceBlueprint(
5089+
normalized.workspace?.preset ?? workspace.preset ?? "starter",
5090+
),
5091+
});
5092+
return;
5093+
}
5094+
5095+
setActiveWorkspaceServerConfig(normalized);
5096+
} catch {
5097+
if (!cancelled) {
5098+
setActiveWorkspaceServerConfig(null);
5099+
}
5100+
}
5101+
};
5102+
5103+
void loadWorkspaceConfig();
5104+
5105+
onCleanup(() => {
5106+
cancelled = true;
5107+
});
5108+
});
5109+
50495110
const [appVersion, setAppVersion] = createSignal<string | null>(null);
50505111
const [launchUpdateCheckTriggered, setLaunchUpdateCheckTriggered] = createSignal(false);
50515112

@@ -7284,6 +7345,7 @@ export default function App() {
72847345
toggleSettings: () => toggleSettingsView("general"),
72857346
activeWorkspaceDisplay: activeWorkspaceDisplay(),
72867347
activeWorkspaceRoot: workspaceStore.activeWorkspaceRoot().trim(),
7348+
activeWorkspaceConfig: resolvedActiveWorkspaceConfig(),
72877349
workspaces: workspaceStore.workspaces(),
72887350
activeWorkspaceId: workspaceStore.activeWorkspaceId(),
72897351
connectingWorkspaceId: workspaceStore.connectingWorkspaceId(),
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
import type { WorkspaceBlueprint, WorkspaceBlueprintStarter, WorkspaceOpenworkConfig } from "../types";
2+
import { parseTemplateFrontmatter } from "../utils";
3+
4+
import browserSetupTemplate from "../data/commands/browser-setup.md?raw";
5+
6+
const BROWSER_AUTOMATION_QUICKSTART_PROMPT = (() => {
7+
const parsed = parseTemplateFrontmatter(browserSetupTemplate);
8+
return (parsed?.body ?? browserSetupTemplate).trim();
9+
})();
10+
11+
export const DEFAULT_EMPTY_STATE_COPY = {
12+
title: "What do you want to do?",
13+
body: "Pick a starting point or just type below.",
14+
};
15+
16+
export function defaultBlueprintStartersForPreset(preset: string): WorkspaceBlueprintStarter[] {
17+
switch (preset.trim().toLowerCase()) {
18+
case "automation":
19+
return [
20+
{
21+
id: "automation-command",
22+
kind: "prompt",
23+
title: "Create a reusable command",
24+
description: "Turn a repeated workflow into a slash command for this workspace.",
25+
prompt:
26+
"Help me create a reusable /command for this workspace. Ask what workflow I want to automate, then draft the command.",
27+
},
28+
{
29+
id: "automation-blueprint",
30+
kind: "session",
31+
title: "Plan an automation blueprint",
32+
description: "Design a repeatable workflow with skills, commands, and handoff steps.",
33+
prompt:
34+
"Help me design a reusable automation blueprint for this workspace. Ask what should be standardized, then propose the workflow.",
35+
},
36+
];
37+
case "minimal":
38+
return [
39+
{
40+
id: "minimal-explore",
41+
kind: "prompt",
42+
title: "Explore this workspace",
43+
description: "Summarize the files and suggest the best first task to tackle.",
44+
prompt: "Summarize this workspace, point out the most important files, and suggest the best first task.",
45+
},
46+
];
47+
default:
48+
return [
49+
{
50+
id: "starter-connect-anthropic",
51+
kind: "action",
52+
title: "Connect Claude",
53+
description: "Add your Anthropic provider so Claude models are ready in new sessions.",
54+
action: "connect-anthropic",
55+
},
56+
{
57+
id: "starter-browser",
58+
kind: "session",
59+
title: "Automate your browser",
60+
description: "Set up browser actions and run reliable web tasks from OpenWork.",
61+
prompt: BROWSER_AUTOMATION_QUICKSTART_PROMPT,
62+
},
63+
];
64+
}
65+
}
66+
67+
export function defaultBlueprintCopyForPreset(preset: string) {
68+
switch (preset.trim().toLowerCase()) {
69+
case "automation":
70+
return {
71+
title: "What do you want to automate?",
72+
body: "Start from a reusable workflow or type your own task below.",
73+
};
74+
case "minimal":
75+
return {
76+
title: "Start with a task",
77+
body: "Ask a question about this workspace or use a starter prompt.",
78+
};
79+
default:
80+
return DEFAULT_EMPTY_STATE_COPY;
81+
}
82+
}
83+
84+
export function buildDefaultWorkspaceBlueprint(preset: string): WorkspaceBlueprint {
85+
const copy = defaultBlueprintCopyForPreset(preset);
86+
return {
87+
emptyState: {
88+
title: copy.title,
89+
body: copy.body,
90+
starters: defaultBlueprintStartersForPreset(preset),
91+
},
92+
};
93+
}
94+
95+
export function normalizeWorkspaceOpenworkConfig(
96+
value: unknown,
97+
preset?: string | null,
98+
): WorkspaceOpenworkConfig {
99+
const candidate =
100+
value && typeof value === "object"
101+
? (value as Partial<WorkspaceOpenworkConfig>)
102+
: {};
103+
104+
const normalizedPreset =
105+
candidate.workspace?.preset?.trim() || preset?.trim() || null;
106+
107+
return {
108+
version: typeof candidate.version === "number" ? candidate.version : 1,
109+
workspace:
110+
candidate.workspace || normalizedPreset
111+
? {
112+
...(candidate.workspace ?? {}),
113+
preset: normalizedPreset,
114+
}
115+
: null,
116+
authorizedRoots: Array.isArray(candidate.authorizedRoots)
117+
? candidate.authorizedRoots.filter((item): item is string => typeof item === "string")
118+
: [],
119+
blueprint: candidate.blueprint ?? null,
120+
reload: candidate.reload ?? null,
121+
};
122+
}

0 commit comments

Comments
 (0)