@yakovlev-i-a/dsh-openfoam-workbench 0.0.0-stage → 0.9.27
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/CHANGELOG.md +692 -0
- package/CORE.md +50 -0
- package/LICENSE +202 -0
- package/NOTICE +29 -0
- package/README.md +373 -2
- package/client.js +48 -0
- package/cordis.patch.yml +18 -0
- package/icon.png +0 -0
- package/lib/buildlib.js +42 -0
- package/lib/caselib.js +212 -0
- package/lib/core.js +47 -0
- package/lib/discover.js +139 -0
- package/lib/escalations.js +92 -0
- package/lib/explib.js +149 -0
- package/lib/impact.js +55 -0
- package/lib/index.js +109 -0
- package/lib/knowledge.js +108 -0
- package/lib/meshlib.js +375 -0
- package/lib/needs-input.js +32 -0
- package/lib/of-case.js +485 -0
- package/lib/of-engine.js +1061 -0
- package/lib/paperlib.js +200 -0
- package/lib/presentation.js +365 -0
- package/lib/registry.js +142 -0
- package/lib/routing-guard.js +126 -0
- package/lib/runtime.js +580 -0
- package/lib/scaffold-cht.js +318 -0
- package/lib/scaffold-compressible.js +171 -0
- package/lib/scaffold.js +355 -0
- package/lib/settings-schema.js +86 -0
- package/lib/skills.js +53 -0
- package/lib/tools/build.js +90 -0
- package/lib/tools/case.js +1082 -0
- package/lib/tools/env.js +592 -0
- package/lib/tools/experience.js +165 -0
- package/lib/tools/mesh.js +408 -0
- package/lib/tools/meta.js +95 -0
- package/lib/tools/papers.js +105 -0
- package/lib/tools/render.js +94 -0
- package/lib/tools/run.js +331 -0
- package/lib/versions.js +133 -0
- package/licenses/dsh-openfoam-doctor-MIT.txt +21 -0
- package/locale/en.json +6 -0
- package/locale/ru.json +6 -0
- package/package.json +44 -4
- package/skills/openfoam-analyze/SKILL.md +27 -0
- package/skills/openfoam-case-builder/SKILL.md +61 -0
- package/skills/openfoam-cht/SKILL.md +83 -0
- package/skills/openfoam-code-modify/SKILL.md +32 -0
- package/skills/openfoam-mesh-independence/SKILL.md +55 -0
- package/skills/openfoam-meshing/SKILL.md +30 -0
- package/skills/openfoam-paper-reproduction/SKILL.md +36 -0
- package/skills/openfoam-self-evolution/SKILL.md +21 -0
- package/skills/openfoam-solver-development/SKILL.md +61 -0
- package/skills/openfoam-stats/SKILL.md +46 -0
- package/skills/openfoam-viz/SKILL.md +35 -0
package/lib/scaffold.js
ADDED
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
// Case scaffold: the dictionaries no other tool writes.
|
|
2
|
+
//
|
|
3
|
+
// `mesh_plan` writes the mesh dictionaries; `clone_tutorial` copies a whole
|
|
4
|
+
// tutorial. A case built from scratch needs controlDict, fvSchemes, fvSolution
|
|
5
|
+
// and the initial fields, generated for the mesh the user actually has — the
|
|
6
|
+
// tutorial alternative would carry patch names that do not exist here.
|
|
7
|
+
//
|
|
8
|
+
// v1 covers incompressible laminar flow only, because that is the family this
|
|
9
|
+
// generator can validate end to end (blockMesh -> solver -> solve_verify) on
|
|
10
|
+
// both distributions. The distribution branch is real:
|
|
11
|
+
// org 14 : application foamRun; + solver incompressibleFluid; + momentumTransport/physicalProperties
|
|
12
|
+
// com 2606: application simpleFoam; + turbulenceProperties/transportProperties (no foamRun)
|
|
13
|
+
|
|
14
|
+
import { versionCaps } from './versions.js'
|
|
15
|
+
|
|
16
|
+
const BANNER = (cls, object) => `/*--------------------------------*- C++ -*----------------------------------*\\
|
|
17
|
+
| ========= | |
|
|
18
|
+
| \\\\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
|
|
19
|
+
| \\\\ / O peration | |
|
|
20
|
+
| \\\\ / A nd | |
|
|
21
|
+
| \\\\/ M anipulation | |
|
|
22
|
+
\\*---------------------------------------------------------------------------*/
|
|
23
|
+
FoamFile
|
|
24
|
+
{
|
|
25
|
+
version 2.0;
|
|
26
|
+
format ascii;
|
|
27
|
+
class ${cls};
|
|
28
|
+
object ${object};
|
|
29
|
+
}
|
|
30
|
+
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
31
|
+
|
|
32
|
+
`
|
|
33
|
+
|
|
34
|
+
/** org 14 modular vs com legacy: `vYYMM` means com. */
|
|
35
|
+
export function distributionKind(distribution) {
|
|
36
|
+
return /^(v\d|com)/i.test(String(distribution || '')) ? 'com' : 'org'
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Role of a patch from its name and type; drives the boundary conditions. */
|
|
40
|
+
export function classifyPatch(name, type = 'patch') {
|
|
41
|
+
const n = String(name || '').toLowerCase()
|
|
42
|
+
const t = String(type || '').toLowerCase()
|
|
43
|
+
if (t === 'empty' || n === 'empty' || /empty/.test(n)) return 'empty'
|
|
44
|
+
if (t.startsWith('symmetry') || /symmetry|symm/.test(n)) return 'symmetry'
|
|
45
|
+
if (t.startsWith('cyclic') || /cyclic|periodic/.test(n)) return 'cyclic'
|
|
46
|
+
if (/inlet|inflow|entry|^in$|^inlet|^left|^front$/.test(n)) return 'inlet'
|
|
47
|
+
if (/outlet|outflow|exit|^out$|^right|^back$/.test(n)) return 'outlet'
|
|
48
|
+
if (t === 'wall' || /wall|bottom|top|side|surface|body|cylinder|sphere|ball|obstacle|airfoil|aerofoil|blade|rod|disc|rotor|stator|impeller|propeller/.test(n)) return 'wall'
|
|
49
|
+
return 'other'
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const vec = (v, fallback = [1, 0, 0]) => {
|
|
53
|
+
const a = Array.isArray(v) && v.length === 3 ? v.map(Number) : fallback
|
|
54
|
+
return `(${a.map((x) => (Number.isFinite(x) ? x : 0)).join(' ')})`
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function uBC(role, U) {
|
|
58
|
+
switch (role) {
|
|
59
|
+
case 'inlet': return ` {\n type fixedValue;\n value uniform ${U};\n }`
|
|
60
|
+
case 'outlet': return ' {\n type zeroGradient;\n }'
|
|
61
|
+
case 'wall': return ' {\n type noSlip;\n }'
|
|
62
|
+
case 'empty': return ' {\n type empty;\n }'
|
|
63
|
+
case 'symmetry': return ' {\n type symmetry;\n }'
|
|
64
|
+
case 'cyclic': return ' {\n type cyclic;\n }'
|
|
65
|
+
default: return ' {\n type zeroGradient;\n }'
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function pBC(role, p) {
|
|
70
|
+
switch (role) {
|
|
71
|
+
case 'inlet': return ' {\n type zeroGradient;\n }'
|
|
72
|
+
case 'outlet': return ` {\n type fixedValue;\n value uniform ${p};\n }`
|
|
73
|
+
case 'wall': return ' {\n type zeroGradient;\n }'
|
|
74
|
+
case 'empty': return ' {\n type empty;\n }'
|
|
75
|
+
case 'symmetry': return ' {\n type symmetry;\n }'
|
|
76
|
+
case 'cyclic': return ' {\n type cyclic;\n }'
|
|
77
|
+
default: return ' {\n type zeroGradient;\n }'
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function fieldsDict(object, fieldClass, patchList) {
|
|
82
|
+
const dims = fieldClass === 'volVectorField' ? '[0 1 -1 0 0 0 0]' : '[0 2 -2 0 0 0 0]'
|
|
83
|
+
return `${BANNER(fieldClass, object)}
|
|
84
|
+
dimensions ${dims};
|
|
85
|
+
|
|
86
|
+
internalField uniform ${fieldClass === 'volVectorField' ? '(0 0 0)' : '0'};
|
|
87
|
+
|
|
88
|
+
boundaryField
|
|
89
|
+
{
|
|
90
|
+
${patchList}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// ************************************************************************* //
|
|
94
|
+
`
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Build every file a fresh incompressible laminar case needs.
|
|
99
|
+
* Returns { files: {relPath: text}, notes, warnings, patchRoles }.
|
|
100
|
+
*/
|
|
101
|
+
export function scaffoldFiles({
|
|
102
|
+
distribution = 'org',
|
|
103
|
+
caps: capsArg = null,
|
|
104
|
+
patches = [],
|
|
105
|
+
algorithm = 'SIMPLE',
|
|
106
|
+
U = [1, 0, 0],
|
|
107
|
+
p = 0,
|
|
108
|
+
nu = 1e-5,
|
|
109
|
+
endTime,
|
|
110
|
+
deltaT,
|
|
111
|
+
writeInterval,
|
|
112
|
+
} = {}) {
|
|
113
|
+
// Capabilities decide the conventions: modular vs legacy application form and
|
|
114
|
+
// the dictionary names the solver module reads.
|
|
115
|
+
const caps = capsArg || versionCaps(distribution, '')
|
|
116
|
+
const kind = caps.family || distributionKind(distribution)
|
|
117
|
+
const transient = String(algorithm).toUpperCase() === 'PIMPLE'
|
|
118
|
+
const roles = patches.map((patch) => ({ ...patch, role: classifyPatch(patch.name, patch.type) }))
|
|
119
|
+
const warnings = []
|
|
120
|
+
const notes = []
|
|
121
|
+
const hasOutlet = roles.some((r) => r.role === 'outlet')
|
|
122
|
+
const hasInlet = roles.some((r) => r.role === 'inlet')
|
|
123
|
+
if (!hasOutlet) warnings.push('no outlet patch: pressure needs a reference cell (pRefCell 0 / pRefValue 0 added to fvSolution)')
|
|
124
|
+
if (!hasInlet) warnings.push('no inlet patch: velocity has no fixed value yet — set the real inflow in 0/U')
|
|
125
|
+
const unknown = roles.filter((r) => r.role === 'other')
|
|
126
|
+
if (unknown.length) warnings.push(`${unknown.length} patch(es) of unknown role use zeroGradient: ${unknown.map((r) => r.name).join(', ')}`)
|
|
127
|
+
const hasEmpty = roles.some((r) => r.role === 'empty')
|
|
128
|
+
if (hasEmpty) notes.push('empty patches found: the case is treated as 2D')
|
|
129
|
+
|
|
130
|
+
const modular = Boolean(caps.modular)
|
|
131
|
+
// Legacy solver name follows the algorithm: simpleFoam is steady, pimpleFoam transient.
|
|
132
|
+
const app = modular ? 'foamRun' : (transient ? 'pimpleFoam' : 'simpleFoam')
|
|
133
|
+
const solverLine = modular ? 'solver incompressibleFluid;\n' : ''
|
|
134
|
+
const endT = Number(endTime) || (transient ? 1 : 500)
|
|
135
|
+
const dT = Number(deltaT) || (transient ? 0.001 : 1)
|
|
136
|
+
const writeEvery = Number(writeInterval) || (transient ? 20 : 100)
|
|
137
|
+
|
|
138
|
+
const controlDict = `${BANNER('dictionary', 'controlDict')}application ${app};
|
|
139
|
+
|
|
140
|
+
${solverLine}startFrom startTime;
|
|
141
|
+
|
|
142
|
+
startTime 0;
|
|
143
|
+
|
|
144
|
+
stopAt endTime;
|
|
145
|
+
|
|
146
|
+
endTime ${endT};
|
|
147
|
+
|
|
148
|
+
deltaT ${dT};
|
|
149
|
+
|
|
150
|
+
writeControl timeStep;
|
|
151
|
+
|
|
152
|
+
writeInterval ${writeEvery};
|
|
153
|
+
|
|
154
|
+
purgeWrite 0;
|
|
155
|
+
|
|
156
|
+
writeFormat ascii;
|
|
157
|
+
|
|
158
|
+
writePrecision 6;
|
|
159
|
+
|
|
160
|
+
writeCompression off;
|
|
161
|
+
|
|
162
|
+
timeFormat general;
|
|
163
|
+
|
|
164
|
+
timePrecision 6;
|
|
165
|
+
|
|
166
|
+
runTimeModifiable true;
|
|
167
|
+
|
|
168
|
+
// ************************************************************************* //
|
|
169
|
+
`
|
|
170
|
+
|
|
171
|
+
const fvSchemes = `${BANNER('dictionary', 'fvSchemes')}ddtSchemes
|
|
172
|
+
{
|
|
173
|
+
default ${transient ? 'Euler' : 'steadyState'};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
gradSchemes
|
|
177
|
+
{
|
|
178
|
+
default Gauss linear;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
divSchemes
|
|
182
|
+
{
|
|
183
|
+
default none;
|
|
184
|
+
div(phi,U) bounded Gauss linearUpwind grad(U);
|
|
185
|
+
div((nuEff*dev2(T(grad(U))))) Gauss linear;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
laplacianSchemes
|
|
189
|
+
{
|
|
190
|
+
default Gauss linear corrected;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
interpolationSchemes
|
|
194
|
+
{
|
|
195
|
+
default linear;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
snGradSchemes
|
|
199
|
+
{
|
|
200
|
+
default corrected;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
wallDist
|
|
204
|
+
{
|
|
205
|
+
method meshWave;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
fluxRequired
|
|
209
|
+
{
|
|
210
|
+
default no;
|
|
211
|
+
p;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// ************************************************************************* //
|
|
215
|
+
`
|
|
216
|
+
|
|
217
|
+
const solverBlocks = transient
|
|
218
|
+
? `solvers
|
|
219
|
+
{
|
|
220
|
+
p
|
|
221
|
+
{
|
|
222
|
+
solver GAMG;
|
|
223
|
+
smoother GaussSeidel;
|
|
224
|
+
tolerance 1e-08;
|
|
225
|
+
relTol 0;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
pFinal
|
|
229
|
+
{
|
|
230
|
+
$p;
|
|
231
|
+
relTol 0;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
U
|
|
235
|
+
{
|
|
236
|
+
solver smoothSolver;
|
|
237
|
+
smoother symGaussSeidel;
|
|
238
|
+
tolerance 1e-09;
|
|
239
|
+
relTol 0;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
UFinal
|
|
243
|
+
{
|
|
244
|
+
$U;
|
|
245
|
+
relTol 0;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
PIMPLE
|
|
250
|
+
{
|
|
251
|
+
nOuterCorrectors 2;
|
|
252
|
+
nCorrectors 2;
|
|
253
|
+
nNonOrthogonalCorrectors 1;
|
|
254
|
+
${hasOutlet ? '' : ' pRefCell 0;\n pRefValue 0;\n'}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
relaxationFactors
|
|
258
|
+
{
|
|
259
|
+
fields
|
|
260
|
+
{
|
|
261
|
+
p 1;
|
|
262
|
+
}
|
|
263
|
+
equations
|
|
264
|
+
{
|
|
265
|
+
U 1;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
`
|
|
269
|
+
: `solvers
|
|
270
|
+
{
|
|
271
|
+
p
|
|
272
|
+
{
|
|
273
|
+
solver GAMG;
|
|
274
|
+
smoother GaussSeidel;
|
|
275
|
+
tolerance 1e-07;
|
|
276
|
+
relTol 0.1;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
U
|
|
280
|
+
{
|
|
281
|
+
solver smoothSolver;
|
|
282
|
+
smoother symGaussSeidel;
|
|
283
|
+
tolerance 1e-08;
|
|
284
|
+
relTol 0.1;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
SIMPLE
|
|
289
|
+
{
|
|
290
|
+
nNonOrthogonalCorrectors 1;
|
|
291
|
+
residualControl
|
|
292
|
+
{
|
|
293
|
+
p 1e-04;
|
|
294
|
+
U 1e-05;
|
|
295
|
+
}
|
|
296
|
+
${hasOutlet ? '' : ' pRefCell 0;\n pRefValue 0;\n'}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
relaxationFactors
|
|
300
|
+
{
|
|
301
|
+
fields
|
|
302
|
+
{
|
|
303
|
+
p 0.3;
|
|
304
|
+
}
|
|
305
|
+
equations
|
|
306
|
+
{
|
|
307
|
+
U 0.7;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
`
|
|
311
|
+
const fvSolution = `${BANNER('dictionary', 'fvSolution')}${solverBlocks}// ************************************************************************* //
|
|
312
|
+
`
|
|
313
|
+
|
|
314
|
+
// Legacy applications (com any version, org <= 9) read transportProperties/
|
|
315
|
+
// turbulenceProperties; the modular solver reads physicalProperties/momentumTransport.
|
|
316
|
+
const transportName = modular ? (caps.transportFile || 'physicalProperties') : 'transportProperties'
|
|
317
|
+
const turbulenceName = modular ? (caps.turbulenceFile || 'momentumTransport') : 'turbulenceProperties'
|
|
318
|
+
const constFiles = modular
|
|
319
|
+
? {
|
|
320
|
+
[`constant/${transportName}`]: `${BANNER('dictionary', transportName)}viscosityModel constant;
|
|
321
|
+
|
|
322
|
+
nu ${nu} [0 2 -1 0 0 0 0];
|
|
323
|
+
|
|
324
|
+
// ************************************************************************* //
|
|
325
|
+
`,
|
|
326
|
+
[`constant/${turbulenceName}`]: `${BANNER('dictionary', turbulenceName)}simulationType laminar;
|
|
327
|
+
|
|
328
|
+
// ************************************************************************* //
|
|
329
|
+
`,
|
|
330
|
+
}
|
|
331
|
+
: {
|
|
332
|
+
[`constant/${transportName}`]: `${BANNER('dictionary', transportName)}transportModel Newtonian;
|
|
333
|
+
|
|
334
|
+
nu [0 2 -1 0 0 0 0] ${nu};
|
|
335
|
+
|
|
336
|
+
// ************************************************************************* //
|
|
337
|
+
`,
|
|
338
|
+
[`constant/${turbulenceName}`]: `${BANNER('dictionary', turbulenceName)}simulationType laminar;
|
|
339
|
+
|
|
340
|
+
// ************************************************************************* //
|
|
341
|
+
`,
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
const patchText = (fn) => roles.map((r) => ` ${r.name}\n${fn(r.role)}`).join('\n\n')
|
|
345
|
+
const files = {
|
|
346
|
+
'system/controlDict': controlDict,
|
|
347
|
+
'system/fvSchemes': fvSchemes,
|
|
348
|
+
'system/fvSolution': fvSolution,
|
|
349
|
+
...constFiles,
|
|
350
|
+
'0/U': fieldsDict('U', 'volVectorField', patchText((role) => uBC(role, vec(U)))),
|
|
351
|
+
'0/p': fieldsDict('p', 'volScalarField', patchText((role) => pBC(role, Number(p) || 0))),
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
return { files, notes, warnings, patchRoles: roles, application: app, kind, modular, transient, caps }
|
|
355
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// DSH Settings schema for this plugin.
|
|
2
|
+
//
|
|
3
|
+
// DSH projects a plugin's Config into the Settings page only when the module
|
|
4
|
+
// exports a *native* schemastery schema (Symbol.for('schemastery') === true).
|
|
5
|
+
// The library ships inside the DSH installation and is a dependency of the Host
|
|
6
|
+
// itself, so it is resolved from there at runtime instead of being vendored —
|
|
7
|
+
// the plugin keeps zero npm dependencies and degrades gracefully (no Settings
|
|
8
|
+
// form, config still honoured) when the library cannot be found.
|
|
9
|
+
import { existsSync } from 'node:fs'
|
|
10
|
+
import { createRequire } from 'node:module'
|
|
11
|
+
import { dirname, join, resolve } from 'node:path'
|
|
12
|
+
|
|
13
|
+
const require = createRequire(import.meta.url)
|
|
14
|
+
|
|
15
|
+
/** Locate @deepseek-ai/schemastery: local install first, then the Host install. */
|
|
16
|
+
export function resolveSchemastery() {
|
|
17
|
+
try {
|
|
18
|
+
return require.resolve('@deepseek-ai/schemastery')
|
|
19
|
+
} catch {}
|
|
20
|
+
const execDir = dirname(process.execPath)
|
|
21
|
+
const bases = [
|
|
22
|
+
dirname(String(process.argv[1] || '')),
|
|
23
|
+
process.cwd(),
|
|
24
|
+
join(execDir, '..', 'lib', 'node_modules', '@deepseek-ai', 'dsh', 'node_modules'),
|
|
25
|
+
join(execDir, '..', 'lib', 'node_modules'),
|
|
26
|
+
]
|
|
27
|
+
for (const base of bases) {
|
|
28
|
+
if (!base) continue
|
|
29
|
+
let dir = resolve(base)
|
|
30
|
+
for (let depth = 0; depth < 8; depth += 1) {
|
|
31
|
+
const pkgDir = join(dir, 'node_modules', '@deepseek-ai', 'schemastery')
|
|
32
|
+
if (existsSync(join(pkgDir, 'package.json'))) return pkgDir
|
|
33
|
+
const parent = dirname(dir)
|
|
34
|
+
if (parent === dir) break
|
|
35
|
+
dir = parent
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return null
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function loadSchemastery() {
|
|
42
|
+
const found = resolveSchemastery()
|
|
43
|
+
if (!found) return null
|
|
44
|
+
try {
|
|
45
|
+
const mod = require(found)
|
|
46
|
+
return mod && typeof mod.object === 'function' ? mod : mod?.default ?? null
|
|
47
|
+
} catch {
|
|
48
|
+
return null
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The plugin Config shown in Settings. Every key mirrors runtime DEFAULTS so an
|
|
54
|
+
* existing profile patch validates unchanged; descriptions are the field labels.
|
|
55
|
+
*/
|
|
56
|
+
export function buildConfigSchema() {
|
|
57
|
+
const z = loadSchemastery()
|
|
58
|
+
if (!z) return undefined
|
|
59
|
+
const dict = (description) => z.dict(z.string()).default({}).description(description)
|
|
60
|
+
return z.object({
|
|
61
|
+
foamRoot: z.string().default('').description('Legacy single OpenFOAM root (prefer foamRoots).'),
|
|
62
|
+
openfoamBash: z.string().default('').description('Legacy single bashrc path (prefer foamRoots).'),
|
|
63
|
+
foamRoots: dict('OpenFOAM installations: { org: /opt/openfoam14, com: /usr/lib/openfoam/openfoam2606 }. Empty = discover automatically.'),
|
|
64
|
+
foamBashs: dict('bashrc override per distribution key; normally derived from foamRoots.'),
|
|
65
|
+
defaultDistribution: z.string().default('').description('Which distribution a tool uses when called without distribution=. Empty = org when present.'),
|
|
66
|
+
paraviewExe: z.string().default('').description('ParaView executable for -help checks. Empty = discover.'),
|
|
67
|
+
paraviewPython: z.string().default('').description('pvpython for off-screen renders. Empty = discover in /opt and PATH.'),
|
|
68
|
+
pythonPath: z.string().default('').description('Python 3 interpreter for the PDF-text fallback. Empty = discover.'),
|
|
69
|
+
caseRoots: z.array(z.string()).default([]).description('Directories that resolve relative case paths. Empty = the working directory.'),
|
|
70
|
+
extraCommands: z.array(z.string()).default([]).description('Extra whitelisted OpenFOAM commands for openfoam_run.'),
|
|
71
|
+
corePath: z.string().default('').description('Alternative CORE.md. Empty = the bundled one.'),
|
|
72
|
+
logTailBytes: z.number().min(0).default(4 * 1024 * 1024).description('How much of a solver log the verifiers read (bytes). 0 = whole file.'),
|
|
73
|
+
escalationAuthority: z.string().default('auto').description(
|
|
74
|
+
'Who issues an escalation token when a direct write is unavoidable: auto = the plugin issues it from the verified evidence (recorded in openfoam_usage_report), ask = the DSH approval answerer decides'
|
|
75
|
+
),
|
|
76
|
+
enforceToolRouting: z.string().default('warn').description(
|
|
77
|
+
'Watch tools/pre-execute for direct edits of case dictionaries: off = ignore, warn = allow and record the bypass, deny = refuse and point at the plugin tool, strict = refuse unless a live openfoam_escalate token covers the target'
|
|
78
|
+
),
|
|
79
|
+
writeMode: z.string().default('impact').description('How dictionary writes are applied: impact (output keys apply, physics keys preview), apply (always write) or preview (never write without apply:true).'),
|
|
80
|
+
runsDir: z.string().default('').description('Where run records and logs go. Empty = <case>/.openfoam-runs (next to the case).'),
|
|
81
|
+
scaleAskAbove: z.number().min(0).default(0.1).description('Geometry-scale gate in metres: ask the human when the bounding box is larger. 0 = off.'),
|
|
82
|
+
language: z.string().default('').description('Reply language: empty = OS locale, or a code/name such as ru, en, Russian.'),
|
|
83
|
+
})
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export const Config = buildConfigSchema()
|
package/lib/skills.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { existsSync, readFileSync, readdirSync } from 'node:fs'
|
|
2
|
+
import { join } from 'node:path'
|
|
3
|
+
import { HERE } from './runtime.js'
|
|
4
|
+
|
|
5
|
+
export const SKILLS_DIR = join(HERE, '..', 'skills')
|
|
6
|
+
|
|
7
|
+
/** Parse `--- frontmatter --- body` from a SKILL.md; null when the shape is wrong. */
|
|
8
|
+
export function parseSkillMd(text) {
|
|
9
|
+
const m = text.match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n([\s\S]*)$/)
|
|
10
|
+
if (!m) return null
|
|
11
|
+
const name = (m[1].match(/^name:\s*(.+)$/m) || [])[1]
|
|
12
|
+
const description = (m[1].match(/^description:\s*(.+)$/m) || [])[1]
|
|
13
|
+
if (!name || !description) return null
|
|
14
|
+
return {
|
|
15
|
+
name: name.trim().replace(/^["']|["']$/g, ''),
|
|
16
|
+
description: description.trim().replace(/^["']|["']$/g, ''),
|
|
17
|
+
content: m[2].trim(),
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Register the bundled skills so the `skill` tool can discover them. A broken
|
|
22
|
+
// SKILL.md is reported with its path instead of silently disappearing from the
|
|
23
|
+
// catalog; test/skills.test.mjs keeps the shipped ones valid.
|
|
24
|
+
export function mountSkills(ctx) {
|
|
25
|
+
let count = 0
|
|
26
|
+
let entries = []
|
|
27
|
+
try { entries = readdirSync(SKILLS_DIR, { withFileTypes: true }) } catch (e) {
|
|
28
|
+
console.error('[openfoam-workbench] cannot read skills dir:', SKILLS_DIR, (e && e.message) || e)
|
|
29
|
+
return 0
|
|
30
|
+
}
|
|
31
|
+
for (const d of entries) {
|
|
32
|
+
if (!d.isDirectory()) continue
|
|
33
|
+
const p = join(SKILLS_DIR, d.name, 'SKILL.md')
|
|
34
|
+
if (!existsSync(p)) continue
|
|
35
|
+
const s = parseSkillMd(readFileSync(p, 'utf8'))
|
|
36
|
+
if (!s) {
|
|
37
|
+
console.error('[openfoam-workbench] malformed SKILL.md (name/description frontmatter required):', p)
|
|
38
|
+
continue
|
|
39
|
+
}
|
|
40
|
+
if (!/^openfoam-[a-z0-9-]+$/.test(s.name)) {
|
|
41
|
+
console.error('[openfoam-workbench] suspicious skill name (expected openfoam-kebab-case):', s.name, 'in', p)
|
|
42
|
+
}
|
|
43
|
+
ctx.skills.register({
|
|
44
|
+
name: s.name,
|
|
45
|
+
description: s.description,
|
|
46
|
+
content: s.content,
|
|
47
|
+
source: 'bundled',
|
|
48
|
+
invocation: { modelInvocable: true, userInvocable: true },
|
|
49
|
+
})
|
|
50
|
+
count += 1
|
|
51
|
+
}
|
|
52
|
+
return count
|
|
53
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs'
|
|
2
|
+
import { basename, join } from 'node:path'
|
|
3
|
+
import { bashrcFor, resolveCase, runFoam, textOut } from '../runtime.js'
|
|
4
|
+
import { firstError, readMakeFiles } from '../buildlib.js'
|
|
5
|
+
|
|
6
|
+
export default function buildTools({ cfg }) {
|
|
7
|
+
return [
|
|
8
|
+
// --- tool: build a solver module ---
|
|
9
|
+
{
|
|
10
|
+
name: 'openfoam_solver_build',
|
|
11
|
+
description: 'Build an OpenFOAM solver or library module from the workspace: sources the bashrc, optionally wclean, then wmake -jN (EXE) or wmake libso -jN (LIB). Returns the first error and the log tail.',
|
|
12
|
+
parameters: {
|
|
13
|
+
type: 'object',
|
|
14
|
+
properties: {
|
|
15
|
+
modulePath: { type: 'string' },
|
|
16
|
+
clean: { type: 'boolean' },
|
|
17
|
+
jobs: { type: 'number' },
|
|
18
|
+
distribution: { type: 'string', description: 'org | com' },
|
|
19
|
+
},
|
|
20
|
+
required: ['modulePath'],
|
|
21
|
+
},
|
|
22
|
+
output: { schema: { type: 'object' }, render: (_a, v) => textOut(v) },
|
|
23
|
+
timeoutMs: 600000,
|
|
24
|
+
isConcurrencySafe: () => false,
|
|
25
|
+
execute: async (args, exec) => {
|
|
26
|
+
const p = resolveCase(cfg, args.modulePath)
|
|
27
|
+
if (!existsSync(join(p, 'Make/files'))) return { ok: false, error: 'not a module: ' + p }
|
|
28
|
+
const bash = bashrcFor(cfg, args.distribution)
|
|
29
|
+
if (!bash || !existsSync(bash)) return { ok: false, error: 'bashrc/foamRoot not configured' }
|
|
30
|
+
const make = readMakeFiles(p)
|
|
31
|
+
const jobs = Math.max(1, Math.min(Number(args.jobs) || 4, 32))
|
|
32
|
+
const buildArgv = make.isLib ? ['wmake', 'libso', `-j${jobs}`] : ['wmake', `-j${jobs}`]
|
|
33
|
+
const t0 = Date.now()
|
|
34
|
+
if (args.clean) await runFoam(['wclean'], { bashrc: bash, dir: p, signal: exec && exec.signal, timeoutMs: 300000 })
|
|
35
|
+
const r = await runFoam(buildArgv, { bashrc: bash, dir: p, signal: exec && exec.signal, timeoutMs: 600000 })
|
|
36
|
+
const log = (r.stdout || '') + (r.stderr ? '\n[stderr]\n' + r.stderr : '')
|
|
37
|
+
return { ok: r.ok, modulePath: p, target: make.target, isLib: make.isLib, exitCode: r.code, durationMs: Date.now() - t0, firstError: r.ok ? null : firstError(log), logTail: log.slice(-4000) }
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
// --- tool: dry compile (first error) ---
|
|
41
|
+
{
|
|
42
|
+
name: 'openfoam_dry_compile',
|
|
43
|
+
description: 'Quick compile of a solver module to catch the first error (no wclean). Sources the bashrc, runs wmake/wmake libso, returns the first compile/link error with context.',
|
|
44
|
+
parameters: {
|
|
45
|
+
type: 'object',
|
|
46
|
+
properties: { modulePath: { type: 'string' }, distribution: { type: 'string', description: 'org | com' } },
|
|
47
|
+
required: ['modulePath'],
|
|
48
|
+
},
|
|
49
|
+
output: { schema: { type: 'object' }, render: (_a, v) => textOut(v) },
|
|
50
|
+
timeoutMs: 600000,
|
|
51
|
+
isConcurrencySafe: () => false,
|
|
52
|
+
execute: async (args, exec) => {
|
|
53
|
+
const p = resolveCase(cfg, args.modulePath)
|
|
54
|
+
if (!existsSync(join(p, 'Make/files'))) return { ok: false, error: 'not a module: ' + p }
|
|
55
|
+
const bash = bashrcFor(cfg, args.distribution)
|
|
56
|
+
if (!bash || !existsSync(bash)) return { ok: false, error: 'bashrc/foamRoot not configured' }
|
|
57
|
+
const make = readMakeFiles(p)
|
|
58
|
+
const buildArgv = make.isLib ? ['wmake', 'libso'] : ['wmake']
|
|
59
|
+
const r = await runFoam(buildArgv, { bashrc: bash, dir: p, signal: exec && exec.signal, timeoutMs: 600000 })
|
|
60
|
+
const log = (r.stdout || '') + (r.stderr ? '\n[stderr]\n' + r.stderr : '')
|
|
61
|
+
return { ok: r.ok, exitCode: r.code, firstError: r.ok ? null : firstError(log), logTail: log.slice(-4000) }
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
// --- tool: solver smoke test ---
|
|
65
|
+
{
|
|
66
|
+
name: 'openfoam_solver_smoke',
|
|
67
|
+
description: 'Smoke-test a built solver: run `<solver> -help` with the OpenFOAM environment sourced and report the exit code. Use after a successful build.',
|
|
68
|
+
parameters: {
|
|
69
|
+
type: 'object',
|
|
70
|
+
properties: { solver: { type: 'string' }, modulePath: { type: 'string' }, distribution: { type: 'string', description: 'org | com' } },
|
|
71
|
+
},
|
|
72
|
+
output: { schema: { type: 'object' }, render: (_a, v) => textOut(v) },
|
|
73
|
+
timeoutMs: 120000,
|
|
74
|
+
isConcurrencySafe: () => true,
|
|
75
|
+
execute: async (args) => {
|
|
76
|
+
let solver = args.solver
|
|
77
|
+
if (!solver && args.modulePath) {
|
|
78
|
+
const make = readMakeFiles(resolveCase(cfg, args.modulePath))
|
|
79
|
+
solver = make.target ? basename(make.target) : null
|
|
80
|
+
}
|
|
81
|
+
if (!solver) return { ok: false, error: 'provide solver or modulePath with a Make/files target' }
|
|
82
|
+
const bash = bashrcFor(cfg, args.distribution)
|
|
83
|
+
if (!bash || !existsSync(bash)) return { ok: false, error: 'bashrc/foamRoot not configured' }
|
|
84
|
+
const r = await runFoam([solver, '-help'], { bashrc: bash, dir: process.cwd(), timeoutMs: 90000 })
|
|
85
|
+
const log = (r.stdout || '') + (r.stderr ? '\n[stderr]\n' + r.stderr : '')
|
|
86
|
+
return { ok: r.ok, solver, exitCode: r.code, logTail: log.slice(-2000) }
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
]
|
|
90
|
+
}
|