Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
7798853
editor i18n: the Chinese UI names things the way SolidWorks does
lizaixi01 Nov 29, 2026
824608e
docs(design): record why the editor's Chinese wording follows SolidWorks
lizaixi01 Nov 29, 2026
97522cb
editor i18n: an assembly component is 零部件, as in SolidWorks
lizaixi01 Dec 1, 2026
8989e25
editor: manual mode can be switched on for development with VITE_MANU…
lizaixi01 Nov 29, 2026
be3760e
fix(editor): redo keeps a cell's id after an undo renamed it
lizaixi01 Nov 29, 2026
5284f9d
fix(editor): a slider value kept into its params cell no longer break…
lizaixi01 Nov 29, 2026
4b3556b
fix(editor): the left panel never scrolls sideways
lizaixi01 Nov 29, 2026
654594a
feat(editor): export says where the files went, writes STEP and STL, …
lizaixi01 Nov 29, 2026
71a9d66
editor: the feature tree and notices speak a person's words (step num…
lizaixi01 Nov 29, 2026
ccb0231
editor: clicking the picked tree row again or the empty list clears t…
lizaixi01 Nov 29, 2026
4992fae
editor: every slider has a box to type its value in
lizaixi01 Nov 29, 2026
437950b
editor: the inspector measures what is picked (sizes, and between two…
lizaixi01 Nov 29, 2026
5ec3006
editor: the floating cards can be dragged out of each other's way and…
lizaixi01 Nov 29, 2026
c4d1193
editor: the feature tree's name and note tags are matched without Chi…
lizaixi01 Nov 30, 2026
061f1d9
editor i18n: the inspector's word for an assembly component is 零部件 too
lizaixi01 Dec 1, 2026
1ef7c83
fix(editor): an exported file with a non-ASCII name downloads (RFC 59…
lizaixi01 Dec 1, 2026
791bdfe
fix(editor): a long export error keeps its beginning ("STEP export fa…
lizaixi01 Dec 1, 2026
04e7668
fix(editor): closing the export dialog by its button forgets what was…
lizaixi01 Dec 1, 2026
761b316
editor: the inspector says whether the pick reached the AI
lizaixi01 Nov 29, 2026
e20385e
feat(editor): leave the AI a request on picked geometry; a headless c…
lizaixi01 Nov 29, 2026
d83e1b5
docs(design): record how the editor hands a request on picked geometr…
lizaixi01 Nov 29, 2026
9ec1265
fix(editor): `sca` imports os where it reads the agent's request id
lizaixi01 Nov 29, 2026
97e769b
editor: Ask AI's progress and reasons are English in the library and …
lizaixi01 Nov 30, 2026
dcbdc2a
editor: Ask AI counts picked assembly components as 零部件
lizaixi01 Dec 1, 2026
9f0a6fb
fix(editor): Ask AI's agent run works on Windows and survives a close…
lizaixi01 Dec 1, 2026
96689a6
editor i18n: Ask AI counts what is picked through the translation tab…
lizaixi01 Dec 1, 2026
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
43 changes: 43 additions & 0 deletions design-docs/editor-ask-ai.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Ask AI: a request on picked geometry, done by a coding agent

Status: built on branch `feat/editor-manual-mode-ux` (2026-11-29), manual mode only.

## The need

A person modelling in the editor's manual mode often knows what they want ("a boss around this hole, 20 mm across") but not
the operations that make it. They asked to write that sentence right on the picked geometry.

## What was tried

Three clickable prototypes (2026-11-28):

1. **Stored comments.** The note is kept on the geometry; an agent reads them later. Rejected by the user: "还不如不加留言功能".
A person wants the change, not a note waiting for someone.
2. **Comment thread with replies.** Too heavy for one sentence.
3. **Request run at once.** Chosen: the note starts an agent right away and the page shows the result.

## How it works

- The person picks faces, edges, solids or components and opens "Ask AI" (in the context bar or the command bar).
- `POST /api/requests {note, items}` makes a request. `AgentRequests` (`src/simplecadapi/editor/agent_requests.py`) starts
`claude -p` in the workspace. The prompt holds the note, the picks as `ql` selectors (the code the selection cell holds),
the notebook's steps and the instruction to name a new step with `# 名称:` / `# 说明:` lines (the feature tree shows them).
- **What the agent may use:** `sca cell`, `sca snapshot`, `sca ops`, Read/Glob/Grep, and the SDK skill. Edit, Write, web
access and other shell commands are denied. So the running editor stays the one writer of the notebook, and the page
shows each edit live.
- **Progress:** the agent's stream (`--output-format stream-json`) is turned into stages (理解需求 → 查看零件 → 修改模型 → 检查结果 →
完成) and steps in plain words. They reach the pages as `request` messages.
- **One undo step:** the agent's cell commands carry its request id (`SCA_AGENT_REQUEST` in its environment, sent as the
header `X-Sca-Agent-Request` by `sca`). The server notes the cells each one touched. When the request ends, only those
cells' changes are recorded as one history entry (`FeatureService.record_changes(..., only=...)`). Edits the person made
meanwhile are not taken back by undoing the agent.
- **Kept across restarts:** requests are stored in `.sca-editor/requests.json` and ids go on from the last one. A request
cut off by a restart is marked failed.
- **Choosing an agent:** `SCA_AGENT_CMD` replaces the executable (the tests use a stand-in). `SCA_AGENT_MODEL` picks the
model, otherwise the CLI's default.

## Open

- **Cost:** a request is a full agent run. The user raised this. There is no budget or per-request limit yet.
- **Other agents:** another coding agent would need the same contract: edit only through `sca cell`, and pass the request id.
- **No cancel button:** a request ends by itself, after 10 minutes at most.
32 changes: 32 additions & 0 deletions design-docs/editor-sw-terms.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Editor wording follows SolidWorks (Chinese UI)

The editor's manual mode is used by people who learned CAD on SolidWorks. Where the editor named a thing differently, they
looked for the SolidWorks word and did not find it. The Chinese translation table (`editor-web/src/i18n/locales/zh-CN.json`)
now uses the SolidWorks Chinese terms. Only words a person reads changed: the SDK, the notebook code, the keys of the table and
everything an agent reads stay as they were, so the kernel stays agent-friendly.

| Thing | Was | Now (SolidWorks) |
|---|---|---|
| A plane to sketch on | 工作平面 | 基准面 |
| Sketch fully determined | 已求解 | 完全定义 |
| Sketch still free to move | 欠约束 N 自由度 | 欠定义(还有 N 个自由度) |
| Sketch over-determined | 冲突 | 过定义 |
| Sketch constraints (as a group) | 约束 | 几何关系/尺寸 |
| Automatic horizontal/vertical | 自动约束 | 自动添加几何关系 |
| Construction geometry | 构造线 | 构造几何线 |
| Mirror | 镜像 | 镜向 |
| Extrude that adds | 拉伸(合并) | 拉伸凸台 |
| Extrude that removes | 拉伸(切除) | 拉伸切除 |
| Push or pull a face | 推拉 | 移动面 |
| Hole on a face | 在此打孔 | 简单直孔 |
| An edge to pick | 边 | 边线 |
| Assembly joints | …约束 | …配合(铰链、滑块、齿轮、齿条小齿轮、皮带/链、锁定) |
| A part or sub-assembly placed in an assembly | 组件 | 零部件 |

Not changed on purpose:

- **基本体** (box, cylinder, …): SolidWorks has no primitives (it sketches and extrudes), so there is no word to copy.
- Behaviour that differs from SolidWorks (pick-kind chips instead of hover selection, connectors instead of face mates, no
rollback bar) is not a wording question; it is listed with the editor's open issues.

The SolidWorks terms are the ones its Chinese releases commonly use; a few may differ slightly between versions.
99 changes: 93 additions & 6 deletions editor-web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { viewPose } from "@/lib/sketch-plane";
import * as THREE from "three";
import { addConnectorFrame, connectorFrameFromFace, setConnectorsCommand, setRef } from "@/lib/assembly";
import { useAssemblyEditor, useConnectorDraft } from "@/lib/useAssembly";
import { ExportDialog, type ExportState } from "@/components/ExportDialog";
import { Header } from "@/components/Header";
import { Inspector } from "@/components/Inspector";
import { SketchMode, type FaceCheck, type SketchAfter, type SketchSession } from "@/components/sketch/SketchMode";
Expand All @@ -60,8 +61,11 @@ import { assertCellRan, cellFailure, isCellCommand, pickedPayload, suggestName,
import { useRunLog } from "@/lib/runlog";
import { useTheme } from "@/lib/theme";
import { selectionPayload, variableNames, type SelectionItem } from "@/lib/selection";
import { afterEcho, selectionKey, SYNC_TIMEOUT_MS, type SyncState } from "@/lib/selection-sync";
import { cn } from "@/lib/utils";
import { Boxes, Cable, Play, Square } from "lucide-react";
import { Boxes, Cable, MessageSquare, Play, Square } from "lucide-react";
import { AskAiPanel } from "@/components/AskAiPanel";
import { describeTargets, fetchRequests, isAgentRequest, mergeRequest, submitRequest, type AgentRequest } from "@/lib/agent-requests";
import { Viewport, type PickResult, type SelectionMode } from "@/scene/Viewport";
import type { SceneView } from "@/scene/scene-view";
import { t, useI18n } from "@/i18n";
Expand Down Expand Up @@ -90,7 +94,7 @@ const MANUAL_TABS = ["features", "assembly"];
const CODE_TABS = ["notebook", "module"];

export function App() {
useI18n(); // a change of language renders the whole editor again
const { language } = useI18n(); // a change of language renders the whole editor again
const viewRef = useRef<SceneView | null>(null);
// Whether a model of the open notebook is on screen (it may be the last run's,
// restored while the kernel boots): then nothing is being waited for.
Expand Down Expand Up @@ -137,11 +141,23 @@ export function App() {
const [currentPath, setCurrentPath] = useState<string | null>(null);
const [kernelAlive, setKernelAlive] = useState(false);
const [status, setStatus] = useState(() => t("Connecting…"));
const [exportState, setExportState] = useState<ExportState>(null);
const [askOpen, setAskOpen] = useState(false);
const [agentRequests, setAgentRequests] = useState<AgentRequest[]>([]);
const [agentRequestsLoaded, setAgentRequestsLoaded] = useState(false);
useEffect(() => {
void fetchRequests()
.then(setAgentRequests)
.catch(() => undefined)
.finally(() => setAgentRequestsLoaded(true));
}, []);

const [params, setParams] = useState<ParamMeta[]>([]);
const [cells, setCells] = useState<NotebookCell[]>([]);
const [features, setFeatures] = useState<NotebookFeature[]>([]);
const [picked, setPicked] = useState<Omit<SelectionItem, "variable">[]>([]);
const [syncState, setSyncState] = useState<SyncState>("idle");
const sentSelection = useRef<string | null>(null);
// The notebook's workplanes as the kernel reported them, and the one Space made (or chose) last: new sketches go on it.
const [workplanes, setWorkplanes] = useState<WorkplaneFrame[]>([]);
const [tagSplits, setTagSplits] = useState<TagSplit[]>([]);
Expand Down Expand Up @@ -458,12 +474,26 @@ export function App() {
);
});

// The server took the selection: it is in the notebook and the agent's snapshot.
socket.on("selection", (envelope) => {
const items = Array.isArray(envelope["items"]) ? (envelope["items"] as { entity_id?: unknown; node_id?: unknown }[]) : [];
setSyncState((state) => afterEcho(state, sentSelection.current, selectionKey(items)));
});

// Requests left for the coding agent: their state as the agent works (agent_requests.py).
socket.on("request", (envelope) => {
const request = envelope["request"];
if (isAgentRequest(request)) setAgentRequests((previous) => mergeRequest(previous, request));
});

// Messages of the server. Errors go to the log (the dock opens on one), not the header.
socket.on("status", (envelope) => {
if (typeof envelope["error"] === "string") {
if (envelope["error"]) {
log.push("error", envelope["error"]);
setLoading(null);
const message = envelope["error"];
setExportState((current) => (current?.phase === "working" ? { phase: "error", message } : current));
}
} else if (typeof envelope["info"] === "string") {
setStatus(t(envelope["info"]));
Expand All @@ -476,6 +506,10 @@ export function App() {
} else if (typeof envelope["exported"] === "string") {
setStatus(t("exported {{path}}", { path: envelope["exported"] }));
log.push("ok", t("exported {{file}}", { file: envelope["exported"] }));
setLoading(null);
const dir = envelope["export_dir"];
const files = envelope["export_files"];
if (typeof dir === "string" && Array.isArray(files)) setExportState({ phase: "done", dir, files: files.map(String) });
} else if (typeof envelope["created"] === "string") {
setStatus(t("created {{path}}", { path: envelope["created"] }));
log.push("ok", t("created {{name}}", { name: envelope["created"] }));
Expand Down Expand Up @@ -605,6 +639,11 @@ export function App() {
if (needsDetails && item.entityId) {
item.pending = true;
socketRef.current?.send({ type: "entity.info", entity_id: item.entityId, node_id: item.nodeId });
// a reply that never comes must not hold the pick back from the agent for ever: send it without its details
const entityId = item.entityId;
window.setTimeout(() => {
setPicked((previous) => previous.map((other) => (other.entityId === entityId && other.pending ? { ...other, pending: false } : other)));
}, SYNC_TIMEOUT_MS);
}
setPicked((previous) => {
if (!result.additive) return [item];
Expand Down Expand Up @@ -656,15 +695,22 @@ export function App() {
}
// The notebook gets the selection when every picked entity is described.
const waiting = selection.some((item) => item.pending);
const payload = selectionPayload(selection);
setSyncState(payload.length ? "syncing" : "idle");
let lost = 0;
const send = window.setTimeout(() => {
if (!waiting) socketRef.current?.send({ type: "selection.set", items: selectionPayload(selection) });
if (waiting) return;
sentSelection.current = selectionKey(payload);
socketRef.current?.send({ type: "selection.set", items: payload });
if (payload.length) lost = window.setTimeout(() => setSyncState((state) => (state === "syncing" ? "failed" : state)), SYNC_TIMEOUT_MS);
}, 40);
const snapshot = window.setTimeout(() => {
const png = viewRef.current?.snapshotPng();
if (png) void postViewport(png).catch(() => undefined);
}, 600);
return () => {
window.clearTimeout(send);
window.clearTimeout(lost);
window.clearTimeout(snapshot);
};
}, [selection]);
Expand Down Expand Up @@ -1332,6 +1378,16 @@ export function App() {
() => [
// The assembly layout is not a dialog: it is its own panel (registered below), so its spec is left out of the generic list.
...commandsFromSpecs((gui.catalog?.specs ?? []).filter((spec) => spec.id !== "assembly" && spec.id !== "workplane" && spec.id !== "curve"), openSpec, FEATURE_ICONS),
{
id: "ask_ai",
label: "Ask AI",
group: "More",
keywords: ["ai", "agent", "ask", "comment", "note", "request", "留言", "评论", "问 AI"],
description: "Tell the AI in one sentence what to do with what you picked; it edits the model for you and the page updates when it is done.",
icon: MessageSquare,
when: (context) => context.faces + context.edges + context.vertices + context.solids + context.components > 0,
run: () => setAskOpen(true),
},
{
id: "curve_draw",
label: "3D curve",
Expand Down Expand Up @@ -1699,7 +1755,19 @@ export function App() {
() => [...selection, ...livePickedSurfaces.map((name) => ({ nodeId: SURFACE_NODE_PREFIX + name, entityId: null }))],
[selection, livePickedSurfaces],
);
const inspectorPanel = <Inspector selection={selection} sketches={[...inspectedSketches, ...inspectedCurves, ...inspectedSurfaces]} />;
// the names the feature tree shows (# 名称:…, or the operation in the person's language), for notices about a step
const stepNames = useMemo(() => {
const names = new Map(cellTitles);
for (const feature of gui.state.features) {
const spec = feature.gui ? gui.catalog?.specs.find((item) => item.id === feature.gui?.spec) : undefined;
const name = feature.title || (spec ? t(plainLabel(spec.id, spec.label)) : "");
if (name) names.set(feature.cell, name);
}
return names;
// the names are translated: a change of language makes them again
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [cellTitles, gui.state.features, gui.catalog, language]);
const inspectorPanel = <Inspector selection={selection} sync={syncState} sketches={[...inspectedSketches, ...inspectedCurves, ...inspectedSurfaces]} />;

return (
<div className="flex h-screen flex-col overflow-hidden">
Expand All @@ -1711,7 +1779,12 @@ export function App() {
status={status}
themePreference={theme.preference}
onTheme={theme.cycle}
onExport={() => {
setExportState({ phase: "working" });
socketRef.current?.send({ type: "export.request" });
}}
/>
<ExportDialog state={exportState} onClose={() => setExportState(null)} />
</div>
<div className="relative flex min-h-0 flex-1 flex-col">
<ResizablePanelGroup className="min-h-0 flex-1">
Expand Down Expand Up @@ -1739,7 +1812,7 @@ export function App() {
</Button>
))}
</div>
<div inert={moving} className="min-h-0 flex-1 overflow-hidden">
<div inert={moving} className="min-h-0 flex-1 overflow-clip">
{!MANUAL_MODE ? (
panelFor("code")
) : (
Expand Down Expand Up @@ -1893,6 +1966,20 @@ export function App() {
{mode === "manual" && !session && !sketching && !dialog && !placing && !drawing && leftTab !== "assembly" && loading === null && viewRef.current && (
<SelectionBar view={viewRef.current} commands={commands} context={context} anchorMm={anchorMm} icons={FEATURE_ICONS} notice={barNote} disabled={barDisabled} />
)}
{mode === "manual" && (
<AskAiPanel
open={askOpen}
targets={describeTargets(selection)}
requests={agentRequests}
loaded={agentRequestsLoaded}
onClose={() => setAskOpen(false)}
onOpen={() => setAskOpen(true)}
onSubmit={async (note) => {
const made = await submitRequest(note, selectionPayload(selection));
setAgentRequests((previous) => mergeRequest(previous, made)); // the box stays open for a follow-up
}}
/>
)}
{(
<FloatingPanels
inspector={inspectorPanel}
Expand All @@ -1901,7 +1988,7 @@ export function App() {
task={taskOpen}
locked={sketching || moving}
leftNotice={!taskOpen && viewRef.current ? <TagSplits docked view={viewRef.current} splits={tagSplits} sceneVersion={sceneVersion} /> : null}
rightNotice={partial && !sketching ? <PartialNotice docked partial={partial} titles={cellTitles} /> : null}
rightNotice={partial && !sketching ? <PartialNotice docked partial={partial} titles={stepNames} /> : null}
/>
)}
{sketchSession && viewRef.current && (
Expand Down
Loading
Loading