dsh-workflow-execute 0.0.0-stage → 1.0.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.
@@ -0,0 +1,43 @@
1
+ import { readFileSync, writeFileSync } from 'node:fs'
2
+ let s = readFileSync('client/index.js', 'utf8')
3
+
4
+ const ZH_ADD = ` sessionUnavailable: '当前页面拿不到会话服务,无法跳转',
5
+ viewLib: '工艺库', viewExec: '执行',
6
+ runCreate: '▶ 按工艺执行', runWorkspace: '工作区(可选)', runStarted: '运行已发起',
7
+ workspaceDefault: '默认(不绑定)',
8
+ statusQueued: '排队中', statusRunning: '运行中', statusPaused: '已暂停', statusAwaiting: '等待裁决',
9
+ statusDone: '已完成', statusStopped: '已停止', statusFailed: '失败',
10
+ pause: '暂停', resume: '继续', stopRun: '停止运行', stopConfirm: '停止后当前环节结果作废,确定停止?',
11
+ noRuns: '还没有运行记录', noRunsHint: '到「工艺库」打开一个工艺,点「▶ 按工艺执行」发起一次运行',
12
+ emptyRun: '左侧选择一次运行查看看板',
13
+ progress: '{done}/{total} 环节', attemptN: '第 {n} 次尝试', reworkN: '返工 ×{n}',
14
+ gateLabel: '门禁', gateScore: '{score} 分(线 {min})',
15
+ openSession: '打开会话', outputLabel: '实时输出', retryLink: '重跑本环节', skipLink: '跳过本环节',
16
+ breakTitle: '门禁未过,等待你的裁决', decisionRetry: '重试本环节', decisionSkip: '跳过本环节', decisionStop: '中止运行',
17
+ linkPending: '待跑', linkDone: '完成', linkRunning: '进行中', linkGateFailed: '门禁未过', linkSkipped: '跳过', linkFailed: '失败', linkAbandoned: '中断',
18
+ currentStep: '当前', runError: '运行异常',
19
+ }`
20
+ const EN_ADD = ` sessionUnavailable: 'Session service unavailable on this page',
21
+ viewLib: 'Library', viewExec: 'Runs',
22
+ runCreate: '▶ Run process', runWorkspace: 'Workspace (optional)', runStarted: 'Run started',
23
+ workspaceDefault: 'Default (unbound)',
24
+ statusQueued: 'Queued', statusRunning: 'Running', statusPaused: 'Paused', statusAwaiting: 'Awaiting decision',
25
+ statusDone: 'Done', statusStopped: 'Stopped', statusFailed: 'Failed',
26
+ pause: 'Pause', resume: 'Resume', stopRun: 'Stop run', stopConfirm: 'The running link result will be discarded. Stop?',
27
+ noRuns: 'No runs yet', noRunsHint: 'Open a process in "Library" and click "▶ Run process"',
28
+ emptyRun: 'Pick a run on the left to see its board',
29
+ progress: '{done}/{total} links', attemptN: 'attempt {n}', reworkN: 'rework ×{n}',
30
+ gateLabel: 'Gate', gateScore: '{score} (min {min})',
31
+ openSession: 'Open chat', outputLabel: 'Live output', retryLink: 'Retry link', skipLink: 'Skip link',
32
+ breakTitle: 'Gate failed — awaiting your decision', decisionRetry: 'Retry this link', decisionSkip: 'Skip this link', decisionStop: 'Stop run',
33
+ linkPending: 'pending', linkDone: 'done', linkRunning: 'running', linkGateFailed: 'gate failed', linkSkipped: 'skipped', linkFailed: 'failed', linkAbandoned: 'abandoned',
34
+ currentStep: 'current', runError: 'run error',
35
+ }`
36
+
37
+ s = s.replace(` sessionUnavailable: '当前页面拿不到会话服务,无法跳转',
38
+ }`, ZH_ADD)
39
+ s = s.replace(` sessionUnavailable: 'Session service unavailable on this page',
40
+ }`, EN_ADD)
41
+
42
+ writeFileSync('client/index.js', s)
43
+ console.log('i18n added:', s.includes('viewExec') && s.includes("viewExec: 'Runs'"))
@@ -0,0 +1,205 @@
1
+ import { readFileSync, writeFileSync } from 'node:fs'
2
+ let s = readFileSync('client/index.js', 'utf8')
3
+ const must = (c, m) => { if (!c) { console.error('ANCHOR FAIL: ' + m); process.exit(1) } }
4
+
5
+ // ── i18n ──
6
+ must(s.includes(` currentStep: '当前', runError: '运行异常',
7
+ }`), 'zh i18n anchor')
8
+ s = s.replace(` currentStep: '当前', runError: '运行异常',
9
+ }`, ` currentStep: '当前', runError: '运行异常',
10
+ tabFlow: '流程图',
11
+ flowGate: '门禁 ≥{min}', flowRework: '返工≤{n}', flowNoGate: '无门禁',
12
+ flowLegendForward: '正常流转', flowLegendJump: '跳转', flowLegendFail: '门禁未过回跳', flowLegendBreak: '中止(不连线)',
13
+ flowRunCurrent: '当前环节', flowRunDone: '已完成', flowRunGateFailed: '门禁未过', flowRunSkipped: '跳过', flowRunFailed: '失败',
14
+ flowNoParsed: '工艺无法解析,无法绘制流程图',
15
+ }`)
16
+ must(s.includes(` currentStep: 'current', runError: 'run error',
17
+ }`), 'en i18n anchor')
18
+ s = s.replace(` currentStep: 'current', runError: 'run error',
19
+ }`, ` currentStep: 'current', runError: 'run error',
20
+ tabFlow: 'Flow',
21
+ flowGate: 'gate ≥{min}', flowRework: 'rework≤{n}', flowNoGate: 'no gate',
22
+ flowLegendForward: 'forward', flowLegendJump: 'jump', flowLegendFail: 'gate-fail back', flowLegendBreak: 'break (no edge)',
23
+ flowRunCurrent: 'current', flowRunDone: 'done', flowRunGateFailed: 'gate failed', flowRunSkipped: 'skipped', flowRunFailed: 'failed',
24
+ flowNoParsed: 'Process cannot be parsed — cannot draw flow',
25
+ }`)
26
+
27
+ // ── CSS ──
28
+ must(s.includes(`.dsh-prc-tail { max-height:180px; overflow:auto; margin:0; }`), 'css anchor')
29
+ s = s.replace(`.dsh-prc-tail { max-height:180px; overflow:auto; margin:0; }`, `.dsh-prc-tail { max-height:180px; overflow:auto; margin:0; }
30
+ .dsh-prc-flowwrap { border:1px solid var(--dsw-alias-border-l2, rgba(128,128,128,.3)); border-radius:10px; background:var(--dsw-alias-bg-layer-2, rgba(128,128,128,.05)); overflow:auto; max-height:460px; }
31
+ .dsh-prc-flowlegend { display:flex; gap:14px; flex-wrap:wrap; font-size:11px; color:var(--dsw-text-secondary, gray); margin:6px 2px 10px; align-items:center; }
32
+ .dsh-prc-flowlegend .sw { display:inline-block; width:18px; height:0; border-top:2px solid; margin-right:4px; vertical-align:middle; }
33
+ .dsh-prc-flowlegend .sw.fwd { border-color:var(--dsw-text-secondary, #94a3b8); }
34
+ .dsh-prc-flowlegend .sw.jump { border-color:#22c55e; }
35
+ .dsh-prc-flowlegend .sw.fail { border-color:var(--dsw-alias-state-error, #ef4444); border-top-style:dashed; }`)
36
+
37
+ // ── FlowGraph SVG 组件(替换占位)──
38
+ must(s.includes(`// FLOW_COMPONENTS_PLACEHOLDER`), 'flow components placeholder')
39
+ s = s.replace(`// FLOW_COMPONENTS_PLACEHOLDER`, `function flowPhaseColor(phaseId) {
40
+ let h = 0
41
+ for (let i = 0; i < String(phaseId || '').length; i++) h = (h * 31 + String(phaseId).charCodeAt(i)) >>> 0
42
+ return 'hsl(' + (h % 360) + ' 45% 55%)'
43
+ }
44
+
45
+ function escXml(text) {
46
+ return String(text).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;')
47
+ }
48
+
49
+ /**
50
+ * 流程图 SVG。model/layout 来自 flow-model;runState 可选(运行态高亮):
51
+ * { latestByLink: Map<linkId, attempt>, currentLinkId, pendingLinkId }
52
+ */
53
+ function FlowGraph({ t, parsed, run }) {
54
+ const [zoom, setZoom] = useState(1)
55
+ const model = useMemo(() => buildFlowModel(parsed), [parsed])
56
+ const layout = useMemo(() => (model ? layoutFlowGraph(model) : null), [model])
57
+ const latest = useMemo(() => (run ? latestAttempts(run) : null), [run])
58
+ if (!model || !layout) return h('div', { className: 'dsh-prc-empty' }, t('flowNoParsed'))
59
+
60
+ const pos = layout.positions
61
+ const nodeById = new Map([[START_ID, { id: START_ID, name: 'START', phaseName: '' }], [END_ID, { id: END_ID, name: 'END', phaseName: '' }], ...model.nodes.map((n) => [n.id, n])])
62
+ const currentLinkId = run && run.current && run.current.linkId
63
+ const stateOf = (linkId) => {
64
+ if (!run) return null
65
+ if (run.pendingBreak && run.pendingBreak.linkId === linkId) return 'awaiting'
66
+ if (currentLinkId === linkId && ['running', 'queued', 'awaiting'].includes(run.status)) return 'current'
67
+ const a = latest && latest.get(linkId)
68
+ return a ? a.status : null
69
+ }
70
+ const STROKE = { forward: 'var(--dsw-text-secondary, #94a3b8)', jump: '#22c55e', fail: 'var(--dsw-alias-state-error, #ef4444)' }
71
+ const edgePath = (e) => {
72
+ const from = pos.get(e.from)
73
+ const to = pos.get(e.to)
74
+ if (!from || !to) return null
75
+ const isBack = layout.backEdges.has(e.from + '→' + e.to)
76
+ const isLoop = layout.loops.has(e.from + '→' + e.to)
77
+ if (e.from === START_ID) return { d: 'M' + (from.x + FLOW_NODE_W / 2) + ' ' + (from.y + 14) + ' L' + (to.x) + ' ' + (to.y + FLOW_NODE_H / 2), label: null }
78
+ if (e.to === END_ID) return { d: 'M' + (from.x + FLOW_NODE_W) + ' ' + (from.y + FLOW_NODE_H / 2) + ' L' + (to.x) + ' ' + (to.y + 16), label: null }
79
+ if (isLoop) {
80
+ const sx = from.x + FLOW_NODE_W, sy = from.y + 18
81
+ return { d: 'M' + sx + ' ' + sy + ' C' + (sx + 46) + ' ' + sy + ' ' + (sx + 46) + ' ' + (sy + 30) + ' ' + sx + ' ' + (sy + 34), label: null }
82
+ }
83
+ if (isBack) {
84
+ const sx = from.x + FLOW_NODE_W / 2, sy = from.y
85
+ const tx = to.x + FLOW_NODE_W / 2, ty = to.y
86
+ const lift = Math.min(LOOP_BACK_PAD - 6, 12 + (sy - ty) * 0.18)
87
+ return { d: 'M' + sx + ' ' + sy + ' C' + sx + ' ' + (sy - lift) + ' ' + tx + ' ' + (ty - lift) + ' ' + tx + ' ' + ty, label: e.kind === 'fail' ? e.label : (e.label || '') }
88
+ }
89
+ const sx = from.x + FLOW_NODE_W, sy = from.y + FLOW_NODE_H / 2
90
+ const tx = to.x, ty = to.y + FLOW_NODE_H / 2
91
+ const dx = Math.max(28, (tx - sx) / 2)
92
+ return { d: 'M' + sx + ' ' + sy + ' C' + (sx + dx) + ' ' + sy + ' ' + (tx - dx) + ' ' + ty + ' ' + tx + ' ' + ty, label: e.label || null }
93
+ }
94
+
95
+ const nodeSvg = (id) => {
96
+ const p = pos.get(id)
97
+ if (!p) return null
98
+ if (id === START_ID || id === END_ID) {
99
+ const isStart = id === START_ID
100
+ return h('g', { key: id },
101
+ h('rect', { x: p.x, y: p.y, width: FLOW_NODE_W, height: 30, rx: 15, fill: 'var(--dsw-alias-bg-layer-1, transparent)', stroke: 'var(--dsw-alias-border-l2, rgba(128,128,128,.4))' }),
102
+ h('text', { x: p.x + FLOW_NODE_W / 2, y: p.y + 20, textAnchor: 'middle', fontSize: 12, fontWeight: 700, fill: 'var(--dsw-text-secondary, gray)', style: { fontFamily: 'monospace', letterSpacing: 2 } }, isStart ? '▶ START' : '■ END'))
103
+ }
104
+ const node = nodeById.get(id)
105
+ const st = stateOf(id)
106
+ const att = run && latest && latest.get(id)
107
+ const border = st === 'current' ? '#d9822b'
108
+ : st === 'done' || st === 'skipped' ? '#2e9e5b'
109
+ : st === 'gate_failed' || st === 'awaiting' ? 'var(--dsw-alias-state-error, #ef4444)'
110
+ : st === 'failed' ? 'var(--dsw-alias-state-error, #ef4444)' : 'var(--dsw-alias-border-l2, rgba(128,128,128,.35))'
111
+ const badge = []
112
+ if (node.gateCount > 0) badge.push(t('flowGate', { min: node.gateMin === null ? '?' : node.gateMin }))
113
+ else badge.push(t('flowNoGate'))
114
+ if (node.maxRework !== null) badge.push(t('flowRework', { n: node.maxRework }))
115
+ let runBadge = null
116
+ if (att && att.gate && att.gate.score !== null && att.gate.score !== undefined) {
117
+ runBadge = att.gate.score + '/' + (att.gate.minScore || 0)
118
+ }
119
+ const meta = [node.executor, node.expert].filter(Boolean).join(' · ')
120
+ const w = FLOW_NODE_W, hgt = FLOW_NODE_H
121
+ return h('g', { key: id },
122
+ h('rect', { x: p.x + 3, y: p.y + 6, width: 6, height: hgt - 12, rx: 3, fill: flowPhaseColor(node.phaseId) }),
123
+ h('rect', { x: p.x, y: p.y, width: w, height: hgt, rx: 10, fill: 'var(--dsw-alias-bg-layer-1, #fff)', stroke: border, strokeWidth: st === 'current' ? 2.5 : 1.2 }),
124
+ h('rect', { x: p.x - 9, y: p.y - 9, width: 22, height: 18, rx: 9, fill: 'var(--dsw-alias-bg-layer-2, #f1f5f9)', stroke: 'var(--dsw-alias-border-l1, rgba(128,128,128,.2))' }),
125
+ h('text', { x: p.x + 2, y: p.y + 4, textAnchor: 'middle', fontSize: 10, fontWeight: 700, fill: 'var(--dsw-text-secondary, gray)', style: { fontFamily: 'monospace' } }, String(node.no).padStart(2, '0')),
126
+ h('text', { x: p.x + 14, y: p.y + 24, fontSize: 13, fontWeight: 600, fill: 'var(--dsw-alias-label-primary, currentColor)' }, escXml(node.name.slice(0, 16))),
127
+ h('text', { x: p.x + 14, y: p.y + 41, fontSize: 10, fill: 'var(--dsw-text-secondary, gray)' }, escXml((meta || node.phaseName || '').slice(0, 26))),
128
+ h('text', { x: p.x + 14, y: p.y + hgt - 10, fontSize: 10, fill: node.gateCount > 0 ? '#b8860b' : 'var(--dsw-text-secondary, gray)' }, escXml(badge.join(' · ')).slice(0, 34)),
129
+ runBadge ? h('rect', { x: p.x + w - 66, y: p.y + hgt + 6, width: 64, height: 18, rx: 9, fill: 'var(--dsw-alias-bg-layer-1, #fff)', stroke: '#2e9e5b' }),
130
+ runBadge ? h('text', { x: p.x + w - 34, y: p.y + hgt + 19, textAnchor: 'middle', fontSize: 10, fontWeight: 700, fill: '#2e9e5b' }, runBadge) : null,
131
+ st === 'current' ? h('circle', { cx: p.x + w - 12, cy: p.y + 12, r: 5, fill: '#d9822b' }) : null,
132
+ st === 'done' ? h('circle', { cx: p.x + w - 12, cy: p.y + 12, r: 5, fill: '#2e9e5b' }) : null,
133
+ (st === 'gate_failed' || st === 'awaiting' || st === 'failed') ? h('circle', { cx: p.x + w - 12, cy: p.y + 12, r: 5, fill: 'var(--dsw-alias-state-error, #ef4444)' }) : null)
134
+ }
135
+
136
+ const edgeSvgs = []
137
+ for (const e of model.edges) {
138
+ const path = edgePath(e)
139
+ if (!path) continue
140
+ const color = e.kind === 'fail' ? STROKE.fail : e.kind === 'jump' ? STROKE.jump : STROKE.forward
141
+ const dashed = e.kind === 'fail' ? '6,4' : undefined
142
+ edgeSvgs.push(h('path', { key: e.from + '→' + e.to + e.kind, d: path.d, fill: 'none', stroke: color, strokeWidth: e.kind === 'fail' ? 1.8 : 1.4, strokeDasharray: dashed, markerEnd: 'url(#dsh-prc-arrow-' + (e.kind === 'fail' ? 'f' : e.kind === 'jump' ? 'j' : 'n') + ')' }))
143
+ if (path.label) {
144
+ const from = pos.get(e.from), to = pos.get(e.to)
145
+ const mx = (from.x + to.x + FLOW_NODE_W) / 2, my = Math.min(from.y, to.y) - 6
146
+ edgeSvgs.push(h('text', { key: e.from + '→' + e.to + e.kind + 'lbl', x: mx, y: my, textAnchor: 'middle', fontSize: 10, fill: e.kind === 'fail' ? 'var(--dsw-alias-state-error, #ef4444)' : '#16a34a', fontWeight: 600 }, escXml(path.label).slice(0, 30)))
147
+ }
148
+ }
149
+
150
+ return h('div', null,
151
+ h('div', { className: 'dsh-prc-flowlegend' },
152
+ h('span', null, h('span', { className: 'sw fwd' }), t('flowLegendForward')),
153
+ h('span', null, h('span', { className: 'sw jump' }), t('flowLegendJump')),
154
+ h('span', null, h('span', { className: 'sw fail' }), t('flowLegendFail')),
155
+ h('span', null, t('flowLegendBreak')),
156
+ h('span', { style: { marginLeft: 'auto' } },
157
+ h('button', { className: 'dsh-prc-mini', onClick: () => setZoom(Math.max(0.5, zoom - 0.2)) }, '−'),
158
+ h('span', { style: { margin: '0 6px' } }, Math.round(zoom * 100) + '%'),
159
+ h('button', { className: 'dsh-prc-mini', onClick: () => setZoom(Math.min(2, zoom + 0.2)) }, '+'))),
160
+ h('div', { className: 'dsh-prc-flowwrap' },
161
+ h('svg', { width: layout.width * zoom, height: layout.height * zoom, viewBox: '0 0 ' + layout.width + ' ' + layout.height },
162
+ h('defs', null,
163
+ h('marker', { id: 'dsh-prc-arrow-n', viewBox: '0 0 10 10', refX: 9, refY: 5, markerWidth: 7, markerHeight: 7, orient: 'auto-start-reverse' }, h('path', { d: 'M0 0L10 5L0 10z', fill: 'var(--dsw-text-secondary, #94a3b8)' })),
164
+ h('marker', { id: 'dsh-prc-arrow-j', viewBox: '0 0 10 10', refX: 9, refY: 5, markerWidth: 7, markerHeight: 7, orient: 'auto-start-reverse' }, h('path', { d: 'M0 0L10 5L0 10z', fill: '#22c55e' })),
165
+ h('marker', { id: 'dsh-prc-arrow-f', viewBox: '0 0 10 10', refX: 9, refY: 5, markerWidth: 7, markerHeight: 7, orient: 'auto-start-reverse' }, h('path', { d: 'M0 0L10 5L0 10z', fill: 'var(--dsw-alias-state-error, #ef4444)' }))),
166
+ edgeSvgs,
167
+ [START_ID, ...model.nodes.map((n) => n.id), END_ID].map((id) => nodeSvg(id)))))
168
+ }
169
+
170
+ function FlowTab({ t, parsed }) {
171
+ return h('div', null, h(FlowGraph, { t, parsed }))
172
+ }
173
+
174
+ `)
175
+
176
+ // ── tab 接线:'flow' 加入 tab 列表 + DetailPane 渲染 ──
177
+ must(s.includes(` ['overview', 'structure', 'yaml'].map((tab) => h('button', { key: tab, className: 'dsh-prc-tab', 'data-on': state.tab === tab ? 'true' : undefined, onClick: () => controller.setTab(tab) },`), 'tab list')
178
+ s = s.replace(` ['overview', 'structure', 'yaml'].map((tab) => h('button', { key: tab, className: 'dsh-prc-tab', 'data-on': state.tab === tab ? 'true' : undefined, onClick: () => controller.setTab(tab) },`,
179
+ ` ['overview', 'flow', 'structure', 'yaml'].map((tab) => h('button', { key: tab, className: 'dsh-prc-tab', 'data-on': state.tab === tab ? 'true' : undefined, onClick: () => controller.setTab(tab) },`)
180
+
181
+ must(s.includes(` t('tab' + tab[0].toUpperCase() + tab.slice(1))))),`), 'tab label')
182
+ // tabFlow 标签特殊化(Flow → 流程图 已由 i18n key 处理:tab[0].toUpperCase()+slice(1) = 'Flow' ✓)
183
+
184
+ s = s.replace(` state.tab === 'overview' ? h(OverviewTab, { t, meta, parsed: item.parsed, diagnostics: item.diagnostics, onJump: jump })
185
+ : state.tab === 'structure' ? h(StructureTab, { t, parsed: item.parsed })`,
186
+ ` state.tab === 'overview' ? h(OverviewTab, { t, meta, parsed: item.parsed, diagnostics: item.diagnostics, onJump: jump })
187
+ : state.tab === 'flow' ? h(FlowGraph, { t, parsed: item.parsed })
188
+ : state.tab === 'structure' ? h(StructureTab, { t, parsed: item.parsed })`)
189
+
190
+ // ── RunBoard:看板顶部嵌运行态流程图 ──
191
+ must(s.includes(` if (run.pendingBreak) {
192
+ children.push(h('div', { className: 'dsh-prc-break' },`), 'runboard break anchor')
193
+ s = s.replace(` if (run.pendingBreak) {
194
+ children.push(h('div', { className: 'dsh-prc-break' },`,
195
+ ` children.push(h('div', { className: 'dsh-prc-sec' }, h(FlowGraph, { t, parsed: run.snapshot, run })))
196
+ if (run.pendingBreak) {
197
+ children.push(h('div', { className: 'dsh-prc-break' },`)
198
+
199
+ // ── __internals 导出布局纯函数(plain Node 单测)──
200
+ must(s.includes(` __internals: { Controller, filterProcesses, ZH, EN, AI_PROMPT, colorizeLine },`), 'internals anchor')
201
+ s = s.replace(` __internals: { Controller, filterProcesses, ZH, EN, AI_PROMPT, colorizeLine },`,
202
+ ` __internals: { Controller, filterProcesses, ZH, EN, AI_PROMPT, colorizeLine, buildFlowModel, layoutFlowGraph, clientFlowTarget },`)
203
+
204
+ writeFileSync('client/index.js', s)
205
+ console.log('flow view wired')