dsh-cad-studio 0.28.0 → 0.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/index.js +46 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@ DeepSeek Harness 的 CAD 插件:**把 FreeCAD 桥接成给 AI 用的工具**
|
|
|
26
26
|
| 几何自检 | `cad_studio_check {source}` 在导出/打印前问一次:是否有效实体、外壳是否闭合、每个实体体积多少,返回中文问题清单(零体积 / 外壳未闭合 / 几何无效 / 没有实体) |
|
|
27
27
|
| 拔模挤出 | `{kind:"extrude", sketch:"S1", h:20, draft:3}` 按 3° 拔模:截面按 `h*tan(3°)` 偏移后 loft 成体,正角度内收、负角度外放 |
|
|
28
28
|
| 展开图 | `cad_studio_unfold {source, target:"…/net.dxf"}` 把板类零件按共享边摊平成下料图(面片等距铺开,面积与模型一致;孔各自成环;圆柱/圆角等曲面报 `curvedSkipped` 而不是瞎编),可写 DXF 或 SVG |
|
|
29
|
-
| 改动记录 | `cad_studio_changes {model}` 看谁改了什么(会话 / 面板 / 外部);每次写都会涨 `rev` 并留一行,面板「信息」里也能看到。别的工具的结果里会顺带一句「自你上次之后,面板改了 N
|
|
29
|
+
| 改动记录 | `cad_studio_changes {model}` 看谁改了什么(会话 / 面板 / 外部);每次写都会涨 `rev` 并留一行,面板「信息」里也能看到。别的工具的结果里会顺带一句「自你上次之后,面板改了 N 处」。0.29.0 起「下一次动手」不再等于「先动手再知情」:人改过之后,会话的**写操作会被拒绝一次**(`needsReview`,不给文件动一下),看清了带 `ifRev=<rev>` 重发才算覆盖(或 `force:true` 硬盖并回报 `overwrote`)|
|
|
30
30
|
| 打印网格 | `cad_studio_mesh {source, target:"…/x.stl"}` 三角化 + 去重合并点/面、修形变、统一法向,可选 `fillHoles`、`targetSize`(减面);回报修复前后的 facets/points,避免「导出成功但网格是碎的」 |
|
|
31
31
|
| 旋转体与凹槽 | `revolve` 的 `axis` 取草图平面内的轴(`"Y"` 或 `[0,1,0]`)才是实体;垂直轴(XY 草图的 Z)只会扫出零厚度圆环,插件会直接报错。凹槽=`{kind:"cut", with:{kind:"revolve", …}}`,不需要单独 op |
|
|
32
32
|
| 面板改草图 | 特征抽屉里点「草图 N」展开:数值约束是可编辑输入框(`distance*`/`radius`/`angle` 按度),改完立刻重解并重建;解不出来就回滚并报错 |
|
package/index.js
CHANGED
|
@@ -4208,6 +4208,34 @@ else:
|
|
|
4208
4208
|
return (doc.changes || []).filter((c) => c.rev > seen && c.by !== by)
|
|
4209
4209
|
}
|
|
4210
4210
|
|
|
4211
|
+
/**
|
|
4212
|
+
* Read-before-write. A digest attached to the result arrives too late when the
|
|
4213
|
+
* very next call is a write — the damage is done before the agent reads it. So
|
|
4214
|
+
* a write from one side is refused once when the other side changed the model
|
|
4215
|
+
* since that side last looked. The agent re-issues with ifRev (the revision it
|
|
4216
|
+
* just saw) or force, which is the explicit "yes, overwrite that".
|
|
4217
|
+
*/
|
|
4218
|
+
const foreignWriteGuard = (doc, by, args) => {
|
|
4219
|
+
const pending = pendingChanges(doc, by)
|
|
4220
|
+
if (!pending.length) return null
|
|
4221
|
+
if (args && args.force === true) return { ok: true, rows: changeRows(pending) }
|
|
4222
|
+
const ifRev = Number(args && args.ifRev)
|
|
4223
|
+
if (Number.isFinite(ifRev) && ifRev === Number(doc.rev)) return { ok: true, rows: changeRows(pending) }
|
|
4224
|
+
return { ok: false, rows: changeRows(pending) }
|
|
4225
|
+
}
|
|
4226
|
+
|
|
4227
|
+
/** The refusal a guarded write returns: no file touched, rows in hand. */
|
|
4228
|
+
const guardRefusal = (doc, guard, by) => {
|
|
4229
|
+
const latest = guard.rows[guard.rows.length - 1]
|
|
4230
|
+
return {
|
|
4231
|
+
ok: false,
|
|
4232
|
+
needsReview: true,
|
|
4233
|
+
model: doc.name,
|
|
4234
|
+
conflict: { rev: Number(doc.rev) || 0, rows: guard.rows },
|
|
4235
|
+
hint: `${latest.by}刚在这个模型上改了 ${guard.rows.length} 处(最新一条:${latest.detail}),这次改动没有执行。看清楚了再重发:带 ifRev=${Number(doc.rev) || 0} 表示在最新版上改,或 force=true 表示认可覆盖。`,
|
|
4236
|
+
}
|
|
4237
|
+
}
|
|
4238
|
+
|
|
4211
4239
|
/** One line a human can read, so the digest means something without a lookup. */
|
|
4212
4240
|
const changeRows = (rows) => rows.map((c) => ({
|
|
4213
4241
|
rev: c.rev,
|
|
@@ -4557,6 +4585,8 @@ else:
|
|
|
4557
4585
|
to: { type: 'string', description: 'For action=rename / duplicate: the new model name.' },
|
|
4558
4586
|
sketches: { type: 'object', description: 'For kind="features": named sketches stored in the document, e.g. {S1:{geometry:[{id:"g1",type:"line",p1:[0,0,0],p2:[80,0,0]}, …],constraints:[…]}}. A feature extrudes/revolves/lofts one with {kind:"extrude",sketch:"S1"}.' },
|
|
4559
4587
|
export: { type: 'string', description: 'Also write the model out as STEP at this path (create / update / show). Saves the caller from re-implementing the feature emitter.' },
|
|
4588
|
+
ifRev: { type: 'number', description: 'Write guard. If someone edited this model in the panel since you last saw it, the write is refused once and tells you the revision; re-issue with ifRev=<that revision> to say "I saw those edits, write on top of them".' },
|
|
4589
|
+
force: { type: 'boolean', description: 'Write guard escape hatch: true means "I accept overwriting the panel edits I was just told about". Prefer ifRev — force skips the review.' },
|
|
4560
4590
|
},
|
|
4561
4591
|
required: ['action'],
|
|
4562
4592
|
additionalProperties: false,
|
|
@@ -4710,6 +4740,10 @@ else:
|
|
|
4710
4740
|
if (action === 'list') {
|
|
4711
4741
|
return { ok: true, model: doc.name, kind: doc.kind, features: publicFeatures(doc), sketches: doc.sketches ?? {}, graph: graphView(doc, { errors: [], executed: null }), stats: doc.stats ?? null }
|
|
4712
4742
|
}
|
|
4743
|
+
// Every other action writes — including undo/redo, which can undo a human's
|
|
4744
|
+
// edit as easily as the agent's own. Same read-before-write rule as above.
|
|
4745
|
+
const guard = by === 'agent' ? foreignWriteGuard(doc, by, args) : null
|
|
4746
|
+
if (guard && guard.ok === false) return guardRefusal(doc, guard, by)
|
|
4713
4747
|
if (action === 'sketch') {
|
|
4714
4748
|
// Sketches are document data (geometry + constraints), so editing one is
|
|
4715
4749
|
// a document edit: same rollback rule as a feature edit, and the sketch
|
|
@@ -4854,7 +4888,7 @@ else:
|
|
|
4854
4888
|
doc.history = doc.history.slice(-20)
|
|
4855
4889
|
recordChange(doc, { by, kind: `feature.${action}`, detail: label })
|
|
4856
4890
|
await writeModel(doc, dir)
|
|
4857
|
-
|
|
4891
|
+
const out = await withChanges(doc, by, {
|
|
4858
4892
|
ok: true,
|
|
4859
4893
|
evaluated: result.ok !== false && (result.errors ?? []).length === 0,
|
|
4860
4894
|
model: doc.name,
|
|
@@ -4875,6 +4909,8 @@ else:
|
|
|
4875
4909
|
computed: result.computed ?? null,
|
|
4876
4910
|
revalidated: result.revalidated === true,
|
|
4877
4911
|
}, dir)
|
|
4912
|
+
if (guard && guard.rows.length) out.overwrote = guard.rows
|
|
4913
|
+
return out
|
|
4878
4914
|
}
|
|
4879
4915
|
|
|
4880
4916
|
tool({
|
|
@@ -4894,6 +4930,8 @@ else:
|
|
|
4894
4930
|
feature: { type: 'object', description: 'add: the feature to append. update/toggle: {id, ...fields to change}. remove/move: {id}.' },
|
|
4895
4931
|
id: { type: 'string', description: 'Feature id (f1, f2 …); alternative to feature.id.' },
|
|
4896
4932
|
to: { type: 'integer', description: 'move: target index (0-based). Default: to the end.' },
|
|
4933
|
+
ifRev: { type: 'number', description: 'Write guard: if the panel edited this model since you last saw it, the write is refused once with the revision; re-issue with ifRev=<that revision> to write on top of those edits.' },
|
|
4934
|
+
force: { type: 'boolean', description: 'Write guard escape hatch (accepts overwriting the panel edits you were just told about). Prefer ifRev.' },
|
|
4897
4935
|
},
|
|
4898
4936
|
required: ['model', 'action'],
|
|
4899
4937
|
additionalProperties: false,
|
|
@@ -5058,6 +5096,8 @@ __out = {"ok": True, "exported": ${JSON.stringify(target)}, "volume": round(scen
|
|
|
5058
5096
|
|
|
5059
5097
|
if (action === 'update') {
|
|
5060
5098
|
const doc = await readModel(args.name, dir)
|
|
5099
|
+
const guard = by === 'agent' ? foreignWriteGuard(doc, by, args) : null
|
|
5100
|
+
if (guard && guard.ok === false) return guardRefusal(doc, guard, by)
|
|
5061
5101
|
if (args.vars !== undefined) doc.vars = normalizeVars(args.vars, doc.vars)
|
|
5062
5102
|
if (args.sketches !== undefined) doc.sketches = normalizeSketches(args.sketches, doc.sketches)
|
|
5063
5103
|
const before = {
|
|
@@ -5091,11 +5131,15 @@ __out = {"ok": True, "exported": ${JSON.stringify(target)}, "volume": round(scen
|
|
|
5091
5131
|
doc.history = doc.history.slice(-20)
|
|
5092
5132
|
recordChange(doc, { by, kind: 'doc.update', detail: describeDocUpdate(args, doc) })
|
|
5093
5133
|
await writeModel(doc, dir)
|
|
5094
|
-
|
|
5134
|
+
const out = await withChanges(doc, by, { ...result, kind: doc.kind, ...(doc.kind === 'features' ? { features: publicFeatures(doc) } : {}) }, dir)
|
|
5135
|
+
if (guard && guard.rows.length) out.overwrote = guard.rows
|
|
5136
|
+
return out
|
|
5095
5137
|
}
|
|
5096
5138
|
|
|
5097
5139
|
if (action === 'revert') {
|
|
5098
5140
|
const doc = await readModel(args.name, dir)
|
|
5141
|
+
const guard = by === 'agent' ? foreignWriteGuard(doc, by, args) : null
|
|
5142
|
+
if (guard && guard.ok === false) return guardRefusal(doc, guard, by)
|
|
5099
5143
|
const last = doc.history.pop()
|
|
5100
5144
|
if (!last) throw new Error(`${doc.name} 没有可回退的历史`)
|
|
5101
5145
|
if (last.prev) {
|