agentworkshop 0.9.0 → 0.9.2
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/.output/nitro.json +1 -1
- package/.output/public/_nuxt/builds/latest.json +1 -1
- package/.output/public/_nuxt/builds/meta/582a3c6f-cd1b-4e1c-b4ee-249fd3efd658.json +1 -0
- package/.output/server/chunks/_/nitro.mjs +1262 -991
- package/.output/server/chunks/_/nitro.mjs.map +1 -1
- package/.output/server/chunks/routes/api/workshop/process-model/experiments.mjs +110 -17
- package/.output/server/chunks/routes/api/workshop/process-model/experiments.mjs.map +1 -1
- package/.output/server/package.json +1 -1
- package/README-zh.md +3 -3
- package/README.md +3 -3
- package/config.yml +1 -1
- package/docs/cli.en.md +2 -2
- package/docs/cli.md +2 -2
- package/docs/plugins.en.md +1 -1
- package/docs/plugins.md +1 -1
- package/docs/sdk.en.md +1 -1
- package/docs/sdk.md +1 -1
- package/package.json +2 -1
- package/scripts/acceptance-scientific-fullchain.ts +391 -0
- package/scripts/acceptance-scientific-loop.ts +16 -0
- package/scripts/demo/build-provision-config.mjs +48 -0
- package/scripts/demo/create-demo-templates.mjs +84 -0
- package/scripts/demo/e2e-optimization-demo.mjs +259 -0
- package/scripts/e2e-model-loop-live.mjs +827 -821
- package/server/services/workshop/agents/industrial/optimization-tools.ts +16 -0
- package/server/services/workshop/aml/intervention-ledger.ts +12 -4
- package/server/services/workshop/aml/twin/cross-check-service.ts +114 -0
- package/server/services/workshop/aml/twin/cross-check.ts +1 -1
- package/server/services/workshop/dcw/dcw-controller/write.ts +4 -2
- package/server/services/workshop/dcw/dcw-node.ts +307 -295
- package/server/services/workshop/process-model/experiment-runner.ts +81 -5
- package/server/services/workshop/process-model/experiment.ts +6 -0
- package/server/services/workshop/process-model/plan-safety.ts +74 -0
- package/shared/dcw-protocol/line.ts +3 -1
- package/.output/public/_nuxt/builds/meta/f507c33b-4ecc-4e32-af88-2e3736b443e9.json +0 -1
|
@@ -20,6 +20,7 @@ import { resolveRefFaces } from './tool-verify'
|
|
|
20
20
|
// P1/P2(科学探索计划):可辨识性前置门 + 引擎判读 + 台账回填
|
|
21
21
|
import { assessIdentifiability } from '../../aml/identifiability'
|
|
22
22
|
import { attachExplorationVerdict, explorationIdentifiabilityPreflight, identGateEnabled, identifiabilityLearningText, periodHintFromSeries, readTargetWindow } from './identifiability-tools'
|
|
23
|
+
import { preDispatchCrossCheck } from '../../aml/twin/cross-check-service'
|
|
23
24
|
|
|
24
25
|
const sleep = (ms: number) => new Promise(r => setTimeout(r, ms))
|
|
25
26
|
|
|
@@ -87,6 +88,20 @@ export async function toolOptimizationExplore(agentId: string, args: {
|
|
|
87
88
|
const gate = await explorationIdentifiabilityPreflight(controlNodeId)
|
|
88
89
|
if (gate.blocked) return { text: gate.text, isError: true }
|
|
89
90
|
|
|
91
|
+
// P5 双通道互审(强制):模型通道(ARX 增益)vs 本体通道(耦合边)。
|
|
92
|
+
// 只有确证冲突才拒;未绑模型/无已发布本体 = unknown 不拦(缺证据不是反证)。
|
|
93
|
+
// manual 模式下冲突交审批卡(卡上带科学载荷),auto 模式下直接拒。
|
|
94
|
+
const channelAuto = (profile.executionMode ?? 'auto') !== 'manual' && profile.controlPolicy !== 'hitl_governed'
|
|
95
|
+
const crossCheck = preDispatchCrossCheck({
|
|
96
|
+
lineId: node.lineId ?? '',
|
|
97
|
+
controlNodeId,
|
|
98
|
+
targetNodeId,
|
|
99
|
+
proposedDelta: target - controlBefore,
|
|
100
|
+
channelId,
|
|
101
|
+
auto: channelAuto,
|
|
102
|
+
})
|
|
103
|
+
if (crossCheck.blocked) return { text: crossCheck.text, isError: true }
|
|
104
|
+
|
|
90
105
|
// 真实写入:复用 dcw_control 全治理链(手动绑定会挂 HITL,auto+bounded 走限界直写)
|
|
91
106
|
const settleSec = Math.min(300, Math.max(10, Number(args.settle_seconds ?? 45)))
|
|
92
107
|
const writeAtMs = Date.now()
|
|
@@ -165,6 +180,7 @@ export async function toolOptimizationExplore(agentId: string, args: {
|
|
|
165
180
|
`探索记录已归档,可在 AML 界面与训练数据回流中使用。`,
|
|
166
181
|
]
|
|
167
182
|
if (gate.hint) lines.push(` 提示: ${gate.hint}`)
|
|
183
|
+
for (const w of crossCheck.warnings) lines.push(` ⚠ ${w}`)
|
|
168
184
|
return { text: lines.join('\n') }
|
|
169
185
|
}
|
|
170
186
|
catch (err) {
|
|
@@ -24,6 +24,14 @@ export interface InterventionCriterion {
|
|
|
24
24
|
mde?: number
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
/** 台账判定态(DB 里是 TEXT;读取时收敛到该联合类型) */
|
|
28
|
+
export type InterventionVerdict = 'pending'
|
|
29
|
+
| 'unassessed'
|
|
30
|
+
| 'identifiable_effect'
|
|
31
|
+
| 'no_resolvable_effect'
|
|
32
|
+
| 'underpowered'
|
|
33
|
+
| 'confounded'
|
|
34
|
+
|
|
27
35
|
export interface InterventionRecordInput {
|
|
28
36
|
nodeId: string
|
|
29
37
|
nodeName?: string
|
|
@@ -69,7 +77,7 @@ export interface InterventionEventRow {
|
|
|
69
77
|
targetNodeId: string | null
|
|
70
78
|
criterion: InterventionCriterion | null
|
|
71
79
|
settleMs: number | null
|
|
72
|
-
verdict:
|
|
80
|
+
verdict: InterventionVerdict
|
|
73
81
|
effect: number | null
|
|
74
82
|
ciLow: number | null
|
|
75
83
|
ciHigh: number | null
|
|
@@ -111,7 +119,7 @@ function mapRow(r: Record<string, unknown>): InterventionEventRow {
|
|
|
111
119
|
targetNodeId: (r.target_node_id as string | null) ?? null,
|
|
112
120
|
criterion: (parse(r.criterion_json) as InterventionCriterion | null) ?? null,
|
|
113
121
|
settleMs: num(r.settle_ms),
|
|
114
|
-
verdict: String(r.verdict ?? 'pending'),
|
|
122
|
+
verdict: String(r.verdict ?? 'pending') as InterventionVerdict,
|
|
115
123
|
effect: num(r.effect),
|
|
116
124
|
ciLow: num(r.ci_low),
|
|
117
125
|
ciHigh: num(r.ci_high),
|
|
@@ -148,7 +156,7 @@ export function recordIntervention(input: InterventionRecordInput): string | nul
|
|
|
148
156
|
export function attachAssessment(
|
|
149
157
|
id: string,
|
|
150
158
|
assessment: {
|
|
151
|
-
verdict:
|
|
159
|
+
verdict: Exclude<InterventionVerdict, 'pending'>
|
|
152
160
|
effect?: number | null
|
|
153
161
|
ciLow?: number | null
|
|
154
162
|
ciHigh?: number | null
|
|
@@ -175,7 +183,7 @@ export function attachAssessment(
|
|
|
175
183
|
}
|
|
176
184
|
|
|
177
185
|
/** 引擎 verdict → 台账 verdict 映射(INSUFFICIENT_DATA 归 unassessed,如实"未判") */
|
|
178
|
-
export function verdictCodeOf(engine: IdentifiabilityVerdict):
|
|
186
|
+
export function verdictCodeOf(engine: IdentifiabilityVerdict): Exclude<InterventionVerdict, 'pending'> {
|
|
179
187
|
switch (engine.verdict) {
|
|
180
188
|
case 'IDENTIFIABLE':
|
|
181
189
|
return engine.significant ? 'identifiable_effect' : 'no_resolvable_effect'
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 下发前双通道互审的**服务态**(P5 补全,2026-11-02 上线前加固):
|
|
3
|
+
* 纯判定在 cross-check.ts;本模块负责取证据并接到探索下发路径上:
|
|
4
|
+
* - 模型通道:渠道绑定模型(aml_channel_profiles.bound_model_id)的 ARX 工件
|
|
5
|
+
* (model.json 的 A/B/C/D + io_spec 的 mvOrder/cvOrder/norm),阶跃仿真求稳态增益;
|
|
6
|
+
* 非 ARX 工件/OOD 无工件一律 unknown(**不拦**:缺证据不是反证);
|
|
7
|
+
* - 本体通道:已发布本体的 actuator→target 耦合边(含干预回灌的 support/refute 计数);
|
|
8
|
+
* - 逃生门 AW_CROSSCHECK_GATE=0 关闭强制(仅保留告警)。
|
|
9
|
+
* 只有"确证冲突"才拒(模型有效应 & 本体明确无路径,或反之);manual 模式交给 HITL 卡。
|
|
10
|
+
*/
|
|
11
|
+
import { readFileSync } from 'node:fs'
|
|
12
|
+
import { join } from 'node:path'
|
|
13
|
+
import { getAmlRuntime } from '../runtime'
|
|
14
|
+
import { parseIoSpec } from '../model-registry'
|
|
15
|
+
import { getChannelTwinProfile } from './channel-profile'
|
|
16
|
+
import { resolveCouplingFromOntology } from '../ontology-learning'
|
|
17
|
+
import { evaluateCrossCheck, scientificPayloadLines, type CrossCheckResult } from './cross-check'
|
|
18
|
+
import type { ArxArtifactLike } from '../action-coverage'
|
|
19
|
+
|
|
20
|
+
export function crossCheckGateEnabled(): boolean {
|
|
21
|
+
return process.env.AW_CROSSCHECK_GATE !== '0'
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface ModelChannelResolution {
|
|
25
|
+
artifact: ArxArtifactLike | null
|
|
26
|
+
modelId?: string
|
|
27
|
+
reason: string
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** 渠道绑定模型 → ARX 工件(含 norm 供物理单位换算);不可用时如实给 reason */
|
|
31
|
+
export function resolveModelChannel(channelId: string | undefined): ModelChannelResolution {
|
|
32
|
+
if (!channelId) return { artifact: null, reason: '无频道上下文,模型通道 unknown' }
|
|
33
|
+
let boundModelId: string | undefined
|
|
34
|
+
try {
|
|
35
|
+
boundModelId = getChannelTwinProfile(channelId).boundModelId
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return { artifact: null, reason: '频道 profile 不可读,模型通道 unknown' }
|
|
39
|
+
}
|
|
40
|
+
if (!boundModelId) return { artifact: null, reason: '频道未绑定 AML 模型,模型通道 unknown' }
|
|
41
|
+
try {
|
|
42
|
+
const row = getAmlRuntime().repo.model.get(boundModelId)
|
|
43
|
+
if (!row) return { artifact: null, modelId: boundModelId, reason: '绑定模型已不存在,模型通道 unknown' }
|
|
44
|
+
const artifact = JSON.parse(readFileSync(join(row.path, 'model.json'), 'utf8')) as Record<string, unknown>
|
|
45
|
+
if (artifact.kind !== 'linear_state_space@1') {
|
|
46
|
+
return { artifact: null, modelId: boundModelId, reason: `工件类型 ${String(artifact.kind)} 暂不支持动作敏感度(仅 ARX),模型通道 unknown` }
|
|
47
|
+
}
|
|
48
|
+
const io = parseIoSpec(row) as unknown as {
|
|
49
|
+
mvOrder?: string[]
|
|
50
|
+
cvOrder?: string[]
|
|
51
|
+
norm?: { u: { mean: number[], std: number[] }, y: { mean: number[], std: number[] } }
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
artifact: {
|
|
55
|
+
A: artifact.A as number[][],
|
|
56
|
+
B: artifact.B as number[][],
|
|
57
|
+
C: artifact.C as number[][],
|
|
58
|
+
D: artifact.D as number[][],
|
|
59
|
+
mvOrder: (artifact.mvOrder as string[]) ?? io.mvOrder ?? [],
|
|
60
|
+
cvOrder: (artifact.cvOrder as string[]) ?? io.cvOrder ?? [],
|
|
61
|
+
...(io.norm ? { norm: io.norm } : {}),
|
|
62
|
+
},
|
|
63
|
+
modelId: boundModelId,
|
|
64
|
+
reason: '模型通道就绪(ARX 阶跃仿真)',
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
68
|
+
return { artifact: null, modelId: boundModelId, reason: `工件读取失败(${err instanceof Error ? err.message : String(err)}),模型通道 unknown` }
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface DispatchCrossCheckInput {
|
|
73
|
+
lineId: string
|
|
74
|
+
controlNodeId: string
|
|
75
|
+
targetNodeId: string
|
|
76
|
+
/** 拟下发步长(物理单位,有正负) */
|
|
77
|
+
proposedDelta: number
|
|
78
|
+
channelId?: string
|
|
79
|
+
/** true=自动执行路径(冲突直接拒);false=需人工批准路径(冲突进审批卡) */
|
|
80
|
+
auto: boolean
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export interface DispatchCrossCheckOutcome {
|
|
84
|
+
blocked: boolean
|
|
85
|
+
text: string
|
|
86
|
+
warnings: string[]
|
|
87
|
+
result: CrossCheckResult
|
|
88
|
+
modelReason: string
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function preDispatchCrossCheck(input: DispatchCrossCheckInput): DispatchCrossCheckOutcome {
|
|
92
|
+
const model = resolveModelChannel(input.channelId)
|
|
93
|
+
const ontology = resolveCouplingFromOntology(input.lineId, input.controlNodeId, input.targetNodeId)
|
|
94
|
+
const result = evaluateCrossCheck({
|
|
95
|
+
controlNodeId: input.controlNodeId,
|
|
96
|
+
targetNodeId: input.targetNodeId,
|
|
97
|
+
proposedDelta: input.proposedDelta,
|
|
98
|
+
auto: input.auto,
|
|
99
|
+
model: { artifact: model.artifact, targetNodeId: input.targetNodeId },
|
|
100
|
+
ontology: { hasCouplingPath: ontology.hasCouplingPath, evidence: ontology.evidence },
|
|
101
|
+
})
|
|
102
|
+
const enabled = crossCheckGateEnabled()
|
|
103
|
+
const blocked = enabled && result.decision === 'reject'
|
|
104
|
+
const lines = scientificPayloadLines(result.payload)
|
|
105
|
+
const text = [
|
|
106
|
+
blocked ? '互审拒绝(双通道确证冲突),本次下发未执行:' : '互审通过(未发现确证冲突)',
|
|
107
|
+
...result.conflicts.map(c => ` ✗ ${c}`),
|
|
108
|
+
...result.warnings.map(w => ` ⚠ ${w}`),
|
|
109
|
+
` [模型通道] ${model.reason}`,
|
|
110
|
+
...lines.map(l => ` ${l}`),
|
|
111
|
+
blocked ? ' 处置:改用人工审批(manual)并由审批人写明理由;或先补数据集/重训模型/更新本体断言。' : '',
|
|
112
|
+
].filter(Boolean)
|
|
113
|
+
return { blocked, text: text.join('\n'), warnings: result.warnings, result, modelReason: model.reason }
|
|
114
|
+
}
|
|
@@ -155,7 +155,7 @@ export function evaluateCrossCheck(input: CrossCheckInput): CrossCheckResult {
|
|
|
155
155
|
export function buildFalsificationMethod(input: CrossCheckInput, modelHasEffect: boolean | null): string {
|
|
156
156
|
const delta = input.proposedDelta
|
|
157
157
|
const parts = [
|
|
158
|
-
|
|
158
|
+
`对 ${input.controlNodeId} 的干预若在响应窗(≥3 个主导扰动周期)内使 ${input.targetNodeId} 的变化量 95% CI 不含 0 且方向与模型预测(${modelHasEffect === true ? '有' : modelHasEffect === false ? '无' : '未知'}效应)不一致,则本次因果断言被否证`,
|
|
159
159
|
`比较基准 = 干预前同长窗口;置信区间用 bootstrap(种子固定可复现)`,
|
|
160
160
|
`Δ控制=${delta} 的效应若小于 MDE,结论只能记为"不可辨识",不得外推`,
|
|
161
161
|
]
|
|
@@ -135,8 +135,10 @@ export abstract class DcwControllerWrite extends DcwControllerBindings {
|
|
|
135
135
|
}
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
|
-
// 60s
|
|
139
|
-
|
|
138
|
+
// 60s 成功间隔:只认最近一次**改变设定值**的成功下发。
|
|
139
|
+
// 保写心跳按 holdIntervalMs 同值重发不推进基准,否则心跳与 Agent 写会互相饿死
|
|
140
|
+
// (2026-11-02 端到端演示实测活锁:每 60s 心跳刷新,Agent 永远"还需 60s")。
|
|
141
|
+
const previousAt = node.lastChangeAt ? Date.parse(node.lastChangeAt) : NaN
|
|
140
142
|
if (Number.isFinite(previousAt)) {
|
|
141
143
|
const elapsed = Date.now() - previousAt
|
|
142
144
|
if (elapsed < 60_000) {
|