@xdxer/dingtalk-agent 0.1.4-beta.6 → 0.1.4-beta.8
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 +12 -2
- package/dist/bin/dingtalk-agent.js +60 -333
- package/dist/bin/dingtalk-agent.js.map +1 -1
- package/dist/src/init.js +1 -1
- package/dist/src/init.js.map +1 -1
- package/dist/src/upgrade.js +137 -0
- package/dist/src/upgrade.js.map +1 -0
- package/docs/INSTALLATION.md +24 -0
- package/package.json +10 -12
- package/dist/src/boot.js +0 -70
- package/dist/src/boot.js.map +0 -1
- package/dist/src/duty.js +0 -74
- package/dist/src/duty.js.map +0 -1
- package/dist/src/kb.js +0 -240
- package/dist/src/kb.js.map +0 -1
- package/dist/src/runs.js +0 -79
- package/dist/src/runs.js.map +0 -1
- package/docs/ARCHITECTURE.md +0 -219
- package/docs/MINIMAL-WORKSPACE-V1.md +0 -172
- package/docs/OPEN-SOURCE-REFERENCES.md +0 -107
- package/docs/SELF-TEST.md +0 -252
- package/docs//345/206/205/347/275/221/345/256/236/347/233/270.md +0 -77
- package/evals/baselines/2026-07-14/behavior-summary.json +0 -28
- package/evals/baselines/2026-07-14/contract-summary.json +0 -18
- package/evals/baselines/2026-07-14/live-canary-summary.json +0 -25
- package/evals/baselines/2026-07-15/dingtalk-basic-behavior-0.3.0/SKILL.md +0 -72
- package/evals/baselines/2026-07-15/dingtalk-basic-behavior-0.3.0/references/action-contract.md +0 -31
- package/evals/baselines/2026-07-15/dingtalk-basic-behavior-0.3.0/references/event-to-behavior.md +0 -22
- package/evals/baselines/2026-07-15/dingtalk-basic-behavior-0.3.0/references/memory-and-evolution.md +0 -25
- package/evals/baselines/2026-07-15/dingtalk-basic-behavior-0.3.0/references/runtime-modes.md +0 -34
- package/evals/baselines/2026-07-15/task-lifecycle-summary.json +0 -50
- package/evals/evals.json +0 -327
- package/evals/fixtures/dm-ambiguous-send.json +0 -4
- package/evals/fixtures/dm-blocked.json +0 -4
- package/evals/fixtures/dm-clear.json +0 -4
- package/evals/fixtures/dm-discussion.json +0 -4
- package/evals/fixtures/dm-doc-write-no-tool.json +0 -4
- package/evals/fixtures/dm-long-task-ack.json +0 -4
- package/evals/fixtures/dm-nonblocking-gap.json +0 -4
- package/evals/fixtures/dm-structured-task.json +0 -4
- package/evals/fixtures/group.json +0 -10
- package/evals/fixtures/mentioned.json +0 -3
- package/evals/run-contract-evals.mjs +0 -1125
- package/evals/run-shadow-evals.mjs +0 -267
- package/evals/runners/README.md +0 -66
- package/evals/runners/claude-shadow.mjs +0 -533
- package/evals/schemas/action-request.schema.json +0 -77
- package/evals/shadow-evals.json +0 -133
- package/skills/AGENTS.md +0 -104
- package/skills//344/273/273/345/212/241.md +0 -48
- package/skills//345/237/272/347/241/200/350/241/214/344/270/272.md +0 -44
- package/skills//345/277/203/350/267/263.md +0 -79
- package/skills//346/266/210/346/201/257.md +0 -50
- package/skills//347/237/245/350/257/206.md +0 -55
- package/skills//350/257/204/346/265/213.md +0 -62
- package/skills//351/222/211/351/222/211.md +0 -64
- package/templates/ontology/index.md +0 -24
- package/templates/ontology/self/access.md +0 -38
- package/templates/ontology/self/role-spec.md +0 -34
- package/templates/ontology/self/workspace.md +0 -41
|
@@ -1,1125 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
// 纯本地合同评测:不调用真实 DWS 写能力。
|
|
4
|
-
import {
|
|
5
|
-
mkdtempSync, readFileSync, writeFileSync, mkdirSync, rmSync, chmodSync,
|
|
6
|
-
readdirSync, cpSync, existsSync, lstatSync, readlinkSync,
|
|
7
|
-
} from 'node:fs'
|
|
8
|
-
import { tmpdir } from 'node:os'
|
|
9
|
-
import { join, dirname, resolve } from 'node:path'
|
|
10
|
-
import { fileURLToPath } from 'node:url'
|
|
11
|
-
import { spawnSync } from 'node:child_process'
|
|
12
|
-
import { init } from '../dist/src/init.js'
|
|
13
|
-
import * as config from '../dist/src/config.js'
|
|
14
|
-
import { ackDispatch, listPendingDispatches, prepareSession, readJson } from '../dist/src/sessions.js'
|
|
15
|
-
import { previewAction, executeAction } from '../dist/src/actions.js'
|
|
16
|
-
import { heartbeatEvent } from '../dist/src/driver.js'
|
|
17
|
-
import { digest, normalizeEvent } from '../dist/src/events.js'
|
|
18
|
-
import {
|
|
19
|
-
cancelWaitForEvent, claimWait, readWaitForEvent, waitRoot,
|
|
20
|
-
} from '../dist/src/waits.js'
|
|
21
|
-
|
|
22
|
-
const HERE = dirname(fileURLToPath(import.meta.url))
|
|
23
|
-
const ROOT = dirname(HERE)
|
|
24
|
-
// 合同结果只拥有自己的子目录,不能清掉同级 Claude/live 评测证据。
|
|
25
|
-
const RESULTS = join(HERE, 'results', 'contract')
|
|
26
|
-
const EVALS = readJson(join(HERE, 'evals.json')).evals
|
|
27
|
-
const CLI = join(ROOT, 'dist', 'bin', 'dingtalk-agent.js')
|
|
28
|
-
const WORKSPACES = []
|
|
29
|
-
process.on('exit', () => {
|
|
30
|
-
for (const root of WORKSPACES) rmSync(root, { recursive: true, force: true })
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
rmSync(RESULTS, { recursive: true, force: true })
|
|
34
|
-
mkdirSync(RESULTS, { recursive: true })
|
|
35
|
-
|
|
36
|
-
const cases = [
|
|
37
|
-
evalMentioned, evalAmbientGroup, evalDuplicate, evalTamper, evalInboxRecovery,
|
|
38
|
-
evalDwsStringData, evalSessionScope, evalSkillSnapshot, evalSingleEgress,
|
|
39
|
-
evalHeartbeatOccurrences, evalAskWaitResume, evalWaitScopeIsolation,
|
|
40
|
-
evalWaitConflict, evalWaitCancelFence, evalWaitReceiptRepair,
|
|
41
|
-
evalClaimSupersededByCancel, evalNegativeWaitRouting,
|
|
42
|
-
evalWorkspaceAuthority, evalSessionSkillBinding,
|
|
43
|
-
evalGlobalSkillInstall, evalBootstrapLocal, evalBootstrapRemote, evalOptionalInit,
|
|
44
|
-
evalManagedSkillLifecycle, evalRemoteStorageTypeGate, evalDirectActGate,
|
|
45
|
-
evalDoctorMissingDependencies, evalFirstRunSetup, evalCliErrorHints,
|
|
46
|
-
]
|
|
47
|
-
const benchmarkRuns = []
|
|
48
|
-
for (let i = 0; i < cases.length; i++) {
|
|
49
|
-
const started = Date.now()
|
|
50
|
-
const result = cases[i]()
|
|
51
|
-
const expectations = EVALS[i].expectations.map((text, n) => ({
|
|
52
|
-
text,
|
|
53
|
-
passed: Boolean(result.checks[n]?.passed),
|
|
54
|
-
evidence: result.checks[n]?.evidence || '没有证据',
|
|
55
|
-
}))
|
|
56
|
-
const passed = expectations.filter((x) => x.passed).length
|
|
57
|
-
const runDir = join(RESULTS, `eval-${i + 1}`, 'with_skill')
|
|
58
|
-
mkdirSync(join(runDir, 'outputs'), { recursive: true })
|
|
59
|
-
writeJson(join(runDir, 'eval_metadata.json'), {
|
|
60
|
-
eval_id: i + 1,
|
|
61
|
-
prompt: EVALS[i].prompt,
|
|
62
|
-
expected_output: EVALS[i].expected_output,
|
|
63
|
-
})
|
|
64
|
-
writeJson(join(runDir, 'outputs', 'result.json'), result.output)
|
|
65
|
-
writeFileSync(join(runDir, 'outputs', 'summary.md'),
|
|
66
|
-
`# Eval ${i + 1}\n\n${EVALS[i].expected_output}\n\n` +
|
|
67
|
-
expectations.map((x) => `- ${x.passed ? '✅' : '❌'} ${x.text}: ${x.evidence}`).join('\n') + '\n')
|
|
68
|
-
writeJson(join(runDir, 'grading.json'), {
|
|
69
|
-
expectations,
|
|
70
|
-
summary: { passed, failed: expectations.length - passed,
|
|
71
|
-
total: expectations.length, pass_rate: passed / expectations.length },
|
|
72
|
-
execution_metrics: { tool_calls: { cli: result.toolCalls }, total_tool_calls: result.toolCalls,
|
|
73
|
-
total_steps: result.steps, errors_encountered: expectations.length - passed,
|
|
74
|
-
output_chars: JSON.stringify(result.output).length, transcript_chars: 0 },
|
|
75
|
-
timing: { executor_duration_seconds: (Date.now() - started) / 1000,
|
|
76
|
-
grader_duration_seconds: 0, total_duration_seconds: (Date.now() - started) / 1000 },
|
|
77
|
-
})
|
|
78
|
-
benchmarkRuns.push({
|
|
79
|
-
eval_id: i + 1,
|
|
80
|
-
eval_name: `Contract ${i + 1}`,
|
|
81
|
-
configuration: 'with_skill',
|
|
82
|
-
run_number: 1,
|
|
83
|
-
result: { pass_rate: passed / expectations.length, passed,
|
|
84
|
-
failed: expectations.length - passed, total: expectations.length,
|
|
85
|
-
time_seconds: (Date.now() - started) / 1000, tokens: 0,
|
|
86
|
-
tool_calls: result.toolCalls, errors: expectations.length - passed },
|
|
87
|
-
expectations,
|
|
88
|
-
notes: ['Deterministic runtime contract; no live DingTalk write was executed.'],
|
|
89
|
-
})
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const mean = benchmarkRuns.reduce((sum, x) => sum + x.result.pass_rate, 0) / benchmarkRuns.length
|
|
93
|
-
writeJson(join(RESULTS, 'benchmark.json'), {
|
|
94
|
-
metadata: { skill_name: '基础行为', skill_path: ROOT,
|
|
95
|
-
executor_model: 'deterministic-cli', analyzer_model: 'deterministic-assertions',
|
|
96
|
-
timestamp: new Date().toISOString(), evals_run: EVALS.map((x) => x.id), runs_per_configuration: 1 },
|
|
97
|
-
runs: benchmarkRuns,
|
|
98
|
-
run_summary: {
|
|
99
|
-
with_skill: {
|
|
100
|
-
pass_rate: { mean, stddev: 0, min: mean, max: mean },
|
|
101
|
-
time_seconds: { mean: 0, stddev: 0, min: 0, max: 0 },
|
|
102
|
-
tokens: { mean: 0, stddev: 0, min: 0, max: 0 },
|
|
103
|
-
},
|
|
104
|
-
delta: { pass_rate: 'n/a', time_seconds: 'n/a', tokens: 'n/a' },
|
|
105
|
-
},
|
|
106
|
-
notes: ['这是可机器判定的运行时合同评测,不做无 Skill 的主观模型对照。',
|
|
107
|
-
'全部案例禁止真实 DWS 写操作。'],
|
|
108
|
-
})
|
|
109
|
-
|
|
110
|
-
if (process.argv.includes('--smoke')) {
|
|
111
|
-
const pass = mean === 1
|
|
112
|
-
const mark = pass ? 'PASS' : 'FAIL'
|
|
113
|
-
console.log(`${mark} 全局 Skill 可在无 Workspace 时安全安装`)
|
|
114
|
-
console.log(`${mark} 本地/钉钉文档 Storage 可在无 init 时水合`)
|
|
115
|
-
console.log(`${mark} init 可选、幂等且不污染项目级 Agent 文件`)
|
|
116
|
-
console.log(`${mark} Prepared Run 的 Session/Wait/目标/幂等闸门通过`)
|
|
117
|
-
if (!pass) process.exitCode = 1
|
|
118
|
-
} else {
|
|
119
|
-
console.log(JSON.stringify({ results: RESULTS, passRate: mean, evals: benchmarkRuns.length }, null, 2))
|
|
120
|
-
}
|
|
121
|
-
if (mean !== 1) process.exitCode = 1
|
|
122
|
-
|
|
123
|
-
function evalMentioned() {
|
|
124
|
-
const { root, cfg } = workspace()
|
|
125
|
-
const event = fixture('mentioned.json')
|
|
126
|
-
const dispatch = prepareSession(root, cfg, event)
|
|
127
|
-
const target = readJson(join(dispatch.cwd, 'context', 'reply-target.json'))
|
|
128
|
-
return {
|
|
129
|
-
output: { dispatch, target }, toolCalls: 1, steps: 3,
|
|
130
|
-
checks: [
|
|
131
|
-
check(dispatch.eventKind === 'im.message.mentioned', `eventKind=${dispatch.eventKind}`),
|
|
132
|
-
check(sameSet(dispatch.allowedActions, ['ack', 'reply', 'ask', 'silence']),
|
|
133
|
-
`allowed=${dispatch.allowedActions.join(',')}`),
|
|
134
|
-
check(target.conversationId === 'cid-project-a' && target.messageId === 'mid-mentioned-001' &&
|
|
135
|
-
target.senderOpenDingTalkId === '$:LWCP_v1:$alice', JSON.stringify(target)),
|
|
136
|
-
],
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
function evalAmbientGroup() {
|
|
141
|
-
const { root, cfg } = workspace()
|
|
142
|
-
const dispatch = prepareSession(root, cfg, fixture('group.json'))
|
|
143
|
-
let blocked = ''
|
|
144
|
-
try { previewAction(dispatch.cwd, 'reply', { text: '不应该发送' }) }
|
|
145
|
-
catch (e) { blocked = e.message }
|
|
146
|
-
const receipt = executeAction(dispatch.cwd, 'silence', { reason: 'unmentioned' })
|
|
147
|
-
return {
|
|
148
|
-
output: { dispatch, blocked, receipt }, toolCalls: 3, steps: 4,
|
|
149
|
-
checks: [
|
|
150
|
-
check(sameSet(dispatch.allowedActions, ['silence']), `allowed=${dispatch.allowedActions.join(',')}`),
|
|
151
|
-
check(blocked.includes('不允许 reply'), blocked),
|
|
152
|
-
check(receipt.kind === 'silence' && receipt.verified === true, JSON.stringify(receipt)),
|
|
153
|
-
],
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
function evalDuplicate() {
|
|
158
|
-
const { root, cfg } = workspace()
|
|
159
|
-
const event = fixture('mentioned.json')
|
|
160
|
-
const first = prepareSession(root, cfg, event)
|
|
161
|
-
const second = prepareSession(root, cfg, event)
|
|
162
|
-
const pending = listPendingDispatches(root, cfg)
|
|
163
|
-
const ack = ackDispatch(root, cfg, first.eventId, first.runId, 'eval-controller')
|
|
164
|
-
const third = prepareSession(root, cfg, event)
|
|
165
|
-
return {
|
|
166
|
-
output: { first, second, pending, ack, third }, toolCalls: 5, steps: 5,
|
|
167
|
-
checks: [
|
|
168
|
-
check(first.sessionId === second.sessionId && first.runId === second.runId &&
|
|
169
|
-
pending.length === 1 && pending[0].runId === first.runId,
|
|
170
|
-
`${first.sessionId}/${first.runId}; pending=${pending.length}`),
|
|
171
|
-
check(second.duplicate === true && second.launch === true,
|
|
172
|
-
`duplicate=${second.duplicate}, launch=${second.launch}`),
|
|
173
|
-
check(ack.duplicate === false && third.duplicate === true && third.launch === false,
|
|
174
|
-
`ack=${ack.duplicate}, duplicate=${third.duplicate}, launch=${third.launch}`),
|
|
175
|
-
],
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
function evalTamper() {
|
|
180
|
-
const { root, cfg } = workspace()
|
|
181
|
-
const dispatch = prepareSession(root, cfg, fixture('mentioned.json'))
|
|
182
|
-
const override = spawnSync(process.execPath, [CLI, 'act', 'reply', '--text', 'x',
|
|
183
|
-
'--conversation-id', 'evil'], { cwd: dispatch.cwd, encoding: 'utf8' })
|
|
184
|
-
|
|
185
|
-
const fake = join(root, 'fake-run')
|
|
186
|
-
mkdirSync(fake)
|
|
187
|
-
writeFileSync(join(fake, 'run.json'), readFileSync(join(dispatch.cwd, 'run.json')))
|
|
188
|
-
let forged = ''
|
|
189
|
-
try { previewAction(fake, 'silence') } catch (e) { forged = e.message }
|
|
190
|
-
|
|
191
|
-
const targetPath = join(dispatch.cwd, 'context', 'reply-target.json')
|
|
192
|
-
writeJson(targetPath, { conversationId: 'evil', messageId: 'evil', senderOpenDingTalkId: 'evil' })
|
|
193
|
-
let drift = ''
|
|
194
|
-
try { previewAction(dispatch.cwd, 'silence') } catch (e) { drift = e.message }
|
|
195
|
-
return {
|
|
196
|
-
output: { overrideStatus: override.status, overrideError: override.stderr.trim(), forged, drift },
|
|
197
|
-
toolCalls: 4, steps: 5,
|
|
198
|
-
checks: [
|
|
199
|
-
check(override.status !== 0 && override.stderr.includes('Unknown option'), override.stderr.trim()),
|
|
200
|
-
check(forged.includes('身份不一致'), forged),
|
|
201
|
-
check(drift.includes('投影被修改'), drift),
|
|
202
|
-
],
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
function evalInboxRecovery() {
|
|
207
|
-
const { root, cfg } = workspace()
|
|
208
|
-
const event = fixture('mentioned.json')
|
|
209
|
-
const fieldPath = join(root, 'fields', 'default', 'field.json')
|
|
210
|
-
const field = readJson(fieldPath)
|
|
211
|
-
field.behavior.packs = ['behaviors/missing.json']
|
|
212
|
-
writeJson(fieldPath, field)
|
|
213
|
-
let failure = ''
|
|
214
|
-
try { prepareSession(root, cfg, event) } catch (e) { failure = e.message }
|
|
215
|
-
const inboxRoot = join(root, cfg.runtime.eventIndexRoot, 'inbox')
|
|
216
|
-
const retained = readdirSync(inboxRoot).filter((x) => x.endsWith('.json')).length
|
|
217
|
-
|
|
218
|
-
field.behavior.packs = ['behaviors/basic.json']
|
|
219
|
-
writeJson(fieldPath, field)
|
|
220
|
-
const pending = listPendingDispatches(root, cfg)
|
|
221
|
-
const recovered = pending.find((x) => x.type === 'dingtalk-agent.run.redelivery')
|
|
222
|
-
const remaining = readdirSync(inboxRoot).filter((x) => x.endsWith('.json')).length
|
|
223
|
-
return {
|
|
224
|
-
output: { failure, retained, pending, remaining }, toolCalls: 3, steps: 5,
|
|
225
|
-
checks: [
|
|
226
|
-
check(failure.includes('不存在') && retained === 1,
|
|
227
|
-
`failure=${failure}; retained=${retained}`),
|
|
228
|
-
check(Boolean(recovered?.launch && recovered?.runId),
|
|
229
|
-
`type=${recovered?.type}; launch=${recovered?.launch}; run=${recovered?.runId}`),
|
|
230
|
-
check(remaining === 0, `remaining=${remaining}`),
|
|
231
|
-
],
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
function evalDwsStringData() {
|
|
236
|
-
const { root, cfg } = workspace()
|
|
237
|
-
const raw = {
|
|
238
|
-
type: 'event',
|
|
239
|
-
event_corp_id: 'tenant-a',
|
|
240
|
-
data: JSON.stringify({
|
|
241
|
-
type: 'user_im_message_receive_o2o', event_id: 'evt-dws-string-1',
|
|
242
|
-
conversation_id: 'cid-dws-dm', message_id: 'mid-dws-dm',
|
|
243
|
-
sender_open_dingtalk_id: '$:LWCP_v1:$peer', content: '你好',
|
|
244
|
-
}),
|
|
245
|
-
}
|
|
246
|
-
const dispatch = prepareSession(root, cfg, raw)
|
|
247
|
-
const normalized = readJson(join(dispatch.cwd, 'event.json'))
|
|
248
|
-
let failure = ''
|
|
249
|
-
try { prepareSession(root, cfg, { type: 'event', data: '{bad json' }) }
|
|
250
|
-
catch (e) { failure = e.message }
|
|
251
|
-
return {
|
|
252
|
-
output: { dispatch, normalized, failure }, toolCalls: 2, steps: 3,
|
|
253
|
-
checks: [
|
|
254
|
-
check(normalized.kind === 'im.message.dm' && normalized.message.text === '你好',
|
|
255
|
-
`${normalized.kind}/${normalized.message.text}`),
|
|
256
|
-
check(normalized.tenant.id === 'tenant-a' &&
|
|
257
|
-
normalized.replyTarget.conversationId === 'cid-dws-dm' &&
|
|
258
|
-
normalized.replyTarget.messageId === 'mid-dws-dm' &&
|
|
259
|
-
normalized.replyTarget.senderOpenDingTalkId === '$:LWCP_v1:$peer',
|
|
260
|
-
JSON.stringify(normalized.replyTarget)),
|
|
261
|
-
check(failure.includes('data 不是合法 JSON 字符串'), failure),
|
|
262
|
-
],
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
function evalSessionScope() {
|
|
267
|
-
const { root, cfg } = workspace()
|
|
268
|
-
const base = fixture('mentioned.json')
|
|
269
|
-
const body = JSON.parse(base.data)
|
|
270
|
-
const messageEvent = (eventId, tenantId, messageId, extra = {}) => ({
|
|
271
|
-
event_corp_id: tenantId,
|
|
272
|
-
data: JSON.stringify({ ...body, event_id: eventId, message_id: messageId, ...extra }),
|
|
273
|
-
})
|
|
274
|
-
const firstEvent = messageEvent('evt-topic-1', 'tenant-a', 'mid-topic-1')
|
|
275
|
-
const secondEvent = messageEvent('evt-topic-2', 'tenant-a', 'mid-topic-2')
|
|
276
|
-
const followupEvent = messageEvent('evt-topic-3', 'tenant-a', 'mid-topic-3',
|
|
277
|
-
{ root_message_id: 'mid-topic-1' })
|
|
278
|
-
const otherTenantEvent = messageEvent('evt-topic-4', 'tenant-b', 'mid-topic-1')
|
|
279
|
-
const first = prepareSession(root, cfg, firstEvent)
|
|
280
|
-
const second = prepareSession(root, cfg, secondEvent)
|
|
281
|
-
const followup = prepareSession(root, cfg, followupEvent)
|
|
282
|
-
const otherTenant = prepareSession(root, cfg, otherTenantEvent)
|
|
283
|
-
return {
|
|
284
|
-
output: { first, second, followup, otherTenant }, toolCalls: 4, steps: 4,
|
|
285
|
-
checks: [
|
|
286
|
-
check(first.sessionId !== second.sessionId, `${first.sessionId} != ${second.sessionId}`),
|
|
287
|
-
check(first.sessionId === followup.sessionId && first.runId !== followup.runId,
|
|
288
|
-
`${first.sessionId}/${first.runId} -> ${followup.sessionId}/${followup.runId}`),
|
|
289
|
-
check(first.sessionId !== otherTenant.sessionId,
|
|
290
|
-
`${first.sessionId} != ${otherTenant.sessionId}`),
|
|
291
|
-
],
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
function evalSkillSnapshot() {
|
|
296
|
-
const { root, cfg } = workspace()
|
|
297
|
-
installWorkspaceSkillOverride(root)
|
|
298
|
-
const event = fixture('mentioned.json')
|
|
299
|
-
const first = prepareSession(root, cfg, event)
|
|
300
|
-
const manifestPath = join(first.cwd, 'context', 'skills', 'manifest.json')
|
|
301
|
-
const skillPath = join(first.cwd, 'context', 'skills', 'dingtalk-basic-behavior', 'SKILL.md')
|
|
302
|
-
const manifest = readJson(manifestPath)
|
|
303
|
-
const before = readFileSync(skillPath, 'utf8')
|
|
304
|
-
const source = join(root, 'skills', 'dingtalk-basic-behavior', 'SKILL.md')
|
|
305
|
-
writeFileSync(source, readFileSync(source, 'utf8') + '\n<!-- candidate change -->\n')
|
|
306
|
-
const replay = prepareSession(root, cfg, event)
|
|
307
|
-
const after = readFileSync(skillPath, 'utf8')
|
|
308
|
-
const run = readJson(join(first.cwd, 'run.json'))
|
|
309
|
-
writeFileSync(skillPath, after + '\n<!-- tampered in sandbox -->\n')
|
|
310
|
-
let tamperBlocked = ''
|
|
311
|
-
try { previewAction(first.cwd, 'silence', { reason: 'no_value' }) }
|
|
312
|
-
catch (e) { tamperBlocked = e.message }
|
|
313
|
-
return {
|
|
314
|
-
output: { first, replay, manifest, run, tamperBlocked }, toolCalls: 5, steps: 6,
|
|
315
|
-
checks: [
|
|
316
|
-
check(manifest.entries?.[0]?.name === 'dingtalk-basic-behavior' &&
|
|
317
|
-
before.includes('name: dingtalk-basic-behavior'), JSON.stringify(manifest.entries?.[0])),
|
|
318
|
-
check(run.skills?.manifestHash === manifest.hash, `${run.skills?.manifestHash}/${manifest.hash}`),
|
|
319
|
-
check(before === after && replay.runId === first.runId &&
|
|
320
|
-
tamperBlocked.includes('Skill snapshot 内容漂移'),
|
|
321
|
-
`snapshotSame=${before === after}; run=${replay.runId}; tamper=${tamperBlocked}`),
|
|
322
|
-
],
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
function evalSingleEgress() {
|
|
327
|
-
const { root, cfg } = workspace()
|
|
328
|
-
const fieldPath = join(root, 'fields', 'default', 'field.json')
|
|
329
|
-
const field = readJson(fieldPath)
|
|
330
|
-
field.transport = { mode: 'robot-connect', egressOwner: 'connector' }
|
|
331
|
-
writeJson(fieldPath, field)
|
|
332
|
-
const dispatch = prepareSession(root, cfg, fixture('mentioned.json'))
|
|
333
|
-
const fieldSnapshot = readJson(join(dispatch.cwd, 'context', 'field.json'))
|
|
334
|
-
let blocked = ''
|
|
335
|
-
try { previewAction(dispatch.cwd, 'reply', { text: '不应由 act 发送' }) }
|
|
336
|
-
catch (e) { blocked = e.message }
|
|
337
|
-
const receipt = executeAction(dispatch.cwd, 'silence', { reason: 'policy_denied' })
|
|
338
|
-
return {
|
|
339
|
-
output: { dispatch, fieldSnapshot, blocked, receipt }, toolCalls: 3, steps: 4,
|
|
340
|
-
checks: [
|
|
341
|
-
check(fieldSnapshot.transport?.egressOwner === 'connector',
|
|
342
|
-
JSON.stringify(fieldSnapshot.transport)),
|
|
343
|
-
check(blocked.includes('出口属于 connector'), blocked),
|
|
344
|
-
check(receipt.kind === 'silence' && receipt.verified === true, JSON.stringify(receipt)),
|
|
345
|
-
],
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
function evalHeartbeatOccurrences() {
|
|
350
|
-
const { root, cfg } = workspace()
|
|
351
|
-
const firstEvent = heartbeatEvent('duty:daily-review', 'beat-001')
|
|
352
|
-
const secondEvent = heartbeatEvent('duty:daily-review', 'beat-002')
|
|
353
|
-
const first = prepareSession(root, cfg, firstEvent)
|
|
354
|
-
const retry = prepareSession(root, cfg, firstEvent)
|
|
355
|
-
ackDispatch(root, cfg, first.eventId, first.runId, 'eval-controller')
|
|
356
|
-
const second = prepareSession(root, cfg, secondEvent)
|
|
357
|
-
return {
|
|
358
|
-
output: { firstEvent, secondEvent, first, retry, second }, toolCalls: 4, steps: 5,
|
|
359
|
-
checks: [
|
|
360
|
-
check(first.sessionId === second.sessionId,
|
|
361
|
-
`${first.sessionId} == ${second.sessionId}`),
|
|
362
|
-
check(first.runId !== second.runId && second.launch === true,
|
|
363
|
-
`${first.runId} != ${second.runId}; launch=${second.launch}`),
|
|
364
|
-
check(retry.runId === first.runId && retry.duplicate === true,
|
|
365
|
-
`retry=${retry.runId}; duplicate=${retry.duplicate}`),
|
|
366
|
-
],
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
function evalAskWaitResume() {
|
|
371
|
-
const { root, cfg } = workspace()
|
|
372
|
-
enableFakeDws(root)
|
|
373
|
-
const firstEvent = dmEvent('evt-wait-ask-1', 'mid-wait-ask-1', 'alice', '请先给我一个草稿')
|
|
374
|
-
const first = prepareSession(root, cfg, firstEvent)
|
|
375
|
-
const receipt = withFakeDws(root, () =>
|
|
376
|
-
executeAction(first.cwd, 'ask', { text: '草稿需要偏正式还是偏口语?' }))
|
|
377
|
-
const active = readWaitForEvent(root, cfg, first.fieldId, readJson(join(first.cwd, 'event.json')))
|
|
378
|
-
|
|
379
|
-
const replyEvent = dmEvent('evt-wait-reply-1', 'mid-wait-reply-1', 'alice', '偏正式')
|
|
380
|
-
const resumed = prepareSession(root, cfg, replyEvent)
|
|
381
|
-
const resume = readJson(join(resumed.cwd, 'context', 'resume.json'))
|
|
382
|
-
const claimed = readWaitForEvent(root, cfg, resumed.fieldId, readJson(join(resumed.cwd, 'event.json')))
|
|
383
|
-
const secondReceipt = withFakeDws(root, () =>
|
|
384
|
-
executeAction(resumed.cwd, 'ask', { text: '是否还需要附上数据来源?' }))
|
|
385
|
-
const secondActive = readWaitForEvent(root, cfg, resumed.fieldId, readJson(join(resumed.cwd, 'event.json')))
|
|
386
|
-
const replay = withFakeDws(root, () =>
|
|
387
|
-
executeAction(first.cwd, 'ask', { text: '草稿需要偏正式还是偏口语?' }))
|
|
388
|
-
const afterReplay = readWaitForEvent(root, cfg, resumed.fieldId, readJson(join(resumed.cwd, 'event.json')))
|
|
389
|
-
return {
|
|
390
|
-
output: { first, receipt, active, resumed, resume, claimed,
|
|
391
|
-
secondReceipt, secondActive, replay, afterReplay }, toolCalls: 7, steps: 9,
|
|
392
|
-
checks: [
|
|
393
|
-
check(receipt.kind === 'ask' && active?.status === 'active' &&
|
|
394
|
-
active?.sourceRunId === first.runId,
|
|
395
|
-
`receipt=${receipt.outcome}; wait=${active?.id}/${active?.status}`),
|
|
396
|
-
check(resumed.sessionId === first.sessionId && resumed.runId !== first.runId &&
|
|
397
|
-
resumed.mode === 'resume',
|
|
398
|
-
`${first.sessionId}/${first.runId} -> ${resumed.sessionId}/${resumed.runId}`),
|
|
399
|
-
check(resume.waitId === active?.id && resume.sourceRunId === first.runId &&
|
|
400
|
-
resume.questionText === '草稿需要偏正式还是偏口语?' &&
|
|
401
|
-
claimed?.status === 'claimed' && claimed?.claim?.runId === resumed.runId,
|
|
402
|
-
JSON.stringify({ resume, status: claimed?.status, claim: claimed?.claim })),
|
|
403
|
-
check(replay.duplicate === true && secondActive?.id !== active?.id &&
|
|
404
|
-
afterReplay?.id === secondActive?.id && afterReplay?.status === 'active',
|
|
405
|
-
`old=${active?.id}; current=${secondActive?.id}; afterReplay=${afterReplay?.id}`),
|
|
406
|
-
],
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
function evalWaitScopeIsolation() {
|
|
411
|
-
const { root, cfg } = workspace()
|
|
412
|
-
enableFakeDws(root)
|
|
413
|
-
const firstEvent = dmEvent('evt-wait-scope-1', 'mid-wait-scope-1', 'alice', '帮我准备材料')
|
|
414
|
-
const first = prepareSession(root, cfg, firstEvent)
|
|
415
|
-
withFakeDws(root, () => executeAction(first.cwd, 'ask', { text: '材料用于哪个会议?' }))
|
|
416
|
-
|
|
417
|
-
const otherActor = prepareSession(root, cfg,
|
|
418
|
-
dmEvent('evt-wait-scope-2', 'mid-wait-scope-2', 'bob', '用于周会'))
|
|
419
|
-
const explicit = prepareSession(root, cfg,
|
|
420
|
-
dmEvent('evt-wait-scope-3', 'mid-wait-scope-3', 'alice', '另开一个事项'),
|
|
421
|
-
{ sessionKey: 'explicit-other-work' })
|
|
422
|
-
const resumed = prepareSession(root, cfg,
|
|
423
|
-
dmEvent('evt-wait-scope-4', 'mid-wait-scope-4', 'alice', '用于季度复盘会'))
|
|
424
|
-
return {
|
|
425
|
-
output: { first, otherActor, explicit, resumed }, toolCalls: 5, steps: 6,
|
|
426
|
-
checks: [
|
|
427
|
-
check(otherActor.sessionId !== first.sessionId && otherActor.mode === 'start',
|
|
428
|
-
`other=${otherActor.sessionId}/${otherActor.mode}`),
|
|
429
|
-
check(explicit.sessionId !== first.sessionId && explicit.mode === 'start',
|
|
430
|
-
`explicit=${explicit.sessionId}/${explicit.mode}`),
|
|
431
|
-
check(resumed.sessionId === first.sessionId && resumed.mode === 'resume',
|
|
432
|
-
`resumed=${resumed.sessionId}/${resumed.mode}`),
|
|
433
|
-
],
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
function evalWaitConflict() {
|
|
438
|
-
const { root, cfg } = workspace()
|
|
439
|
-
enableFakeDws(root)
|
|
440
|
-
const firstEvent = dmEvent('evt-wait-conflict-1', 'mid-wait-conflict-1', 'alice', '事项一')
|
|
441
|
-
const first = prepareSession(root, cfg, firstEvent)
|
|
442
|
-
withFakeDws(root, () => executeAction(first.cwd, 'ask', { text: '事项一缺哪个日期?' }))
|
|
443
|
-
const resumed = prepareSession(root, cfg,
|
|
444
|
-
dmEvent('evt-wait-conflict-2', 'mid-wait-conflict-2', 'alice', '下周一'))
|
|
445
|
-
const claimed = readWaitForEvent(
|
|
446
|
-
root, cfg, first.fieldId, readJson(join(resumed.cwd, 'event.json')))
|
|
447
|
-
const second = prepareSession(root, cfg,
|
|
448
|
-
dmEvent('evt-wait-conflict-3', 'mid-wait-conflict-3', 'alice', '事项二'),
|
|
449
|
-
{ sessionKey: 'parallel-work' })
|
|
450
|
-
let blocked = ''
|
|
451
|
-
try {
|
|
452
|
-
withFakeDws(root, () => executeAction(second.cwd, 'ask', { text: '事项二缺哪个负责人?' }))
|
|
453
|
-
} catch (e) { blocked = e.message }
|
|
454
|
-
const current = readWaitForEvent(root, cfg, first.fieldId, readJson(join(first.cwd, 'event.json')))
|
|
455
|
-
return {
|
|
456
|
-
output: { first, resumed, claimed, second, blocked, current }, toolCalls: 5, steps: 6,
|
|
457
|
-
checks: [
|
|
458
|
-
check(first.sessionId !== second.sessionId && resumed.sessionId === first.sessionId,
|
|
459
|
-
`${first.sessionId} != ${second.sessionId}; resumed=${resumed.sessionId}`),
|
|
460
|
-
check(blocked.includes('单链 v1 拒绝并行追问'), blocked),
|
|
461
|
-
check(claimed?.status === 'claimed' && current?.sessionId === first.sessionId &&
|
|
462
|
-
current?.status === 'claimed',
|
|
463
|
-
`${current?.sessionId}/${current?.status}`),
|
|
464
|
-
],
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
function evalWaitCancelFence() {
|
|
469
|
-
const { root, cfg } = workspace()
|
|
470
|
-
enableFakeDws(root)
|
|
471
|
-
const firstEvent = dmEvent('evt-wait-cancel-1', 'mid-wait-cancel-1', 'alice', '请准备发布稿')
|
|
472
|
-
const first = prepareSession(root, cfg, firstEvent)
|
|
473
|
-
withFakeDws(root, () => executeAction(first.cwd, 'ask', { text: '确认按当前版本发布吗?' }))
|
|
474
|
-
|
|
475
|
-
// 下一条消息已 claim 并物化成 resumed Run,但尚未执行;/stop 仍必须能截断它。
|
|
476
|
-
const resumed = prepareSession(root, cfg,
|
|
477
|
-
dmEvent('evt-wait-cancel-2', 'mid-wait-cancel-2', 'alice', '确认'))
|
|
478
|
-
const beforeStop = readWaitForEvent(
|
|
479
|
-
root, cfg, first.fieldId, readJson(join(resumed.cwd, 'event.json')))
|
|
480
|
-
|
|
481
|
-
// 故意破坏当前 Behavior 引用,证明取消闸门先于 Field/Behavior/Skill 物化执行。
|
|
482
|
-
const fieldPath = join(root, 'fields', 'default', 'field.json')
|
|
483
|
-
const field = readJson(fieldPath)
|
|
484
|
-
writeJson(fieldPath, {
|
|
485
|
-
...field,
|
|
486
|
-
behavior: { ...(field.behavior || {}), packs: ['behaviors/missing.json'] },
|
|
487
|
-
})
|
|
488
|
-
const stopEvent = dmEvent('evt-wait-cancel-3', 'mid-wait-cancel-3', 'alice', '/stop')
|
|
489
|
-
let interrupted = ''
|
|
490
|
-
try { prepareSession(root, cfg, stopEvent) }
|
|
491
|
-
catch (e) { interrupted = e.message }
|
|
492
|
-
const fencedBeforeMaterialize = readJson(join(first.sessionPath, 'session.json'))
|
|
493
|
-
writeJson(fieldPath, field)
|
|
494
|
-
|
|
495
|
-
// 旧 stop 尚未落 event-index 时,新事项已经在同一 scope 建立 Wait。
|
|
496
|
-
// 重放旧 stop 必须按 eventId ledger 找回旧 Wait,不能误取消这个新 head。
|
|
497
|
-
const newer = prepareSession(root, cfg,
|
|
498
|
-
dmEvent('evt-wait-cancel-4', 'mid-wait-cancel-4', 'alice', '另开一个发布事项'),
|
|
499
|
-
{ sessionKey: 'post-cancel-new-work' })
|
|
500
|
-
withFakeDws(root, () => executeAction(
|
|
501
|
-
newer.cwd, 'ask', { text: '新事项按哪个版本?' }))
|
|
502
|
-
const newActiveBeforeReplay = readWaitForEvent(
|
|
503
|
-
root, cfg, newer.fieldId, readJson(join(newer.cwd, 'event.json')))
|
|
504
|
-
const cancelled = prepareSession(root, cfg, stopEvent)
|
|
505
|
-
const duplicate = prepareSession(root, cfg, stopEvent)
|
|
506
|
-
const session = readJson(join(first.sessionPath, 'session.json'))
|
|
507
|
-
const waitAfterReplay = readWaitForEvent(
|
|
508
|
-
root, cfg, newer.fieldId, readJson(join(newer.cwd, 'event.json')))
|
|
509
|
-
let fenced = ''
|
|
510
|
-
try { previewAction(resumed.cwd, 'reply', { text: '已唤醒 Run 不应再发送' }) }
|
|
511
|
-
catch (e) { fenced = e.message }
|
|
512
|
-
return {
|
|
513
|
-
output: { first, resumed, beforeStop, interrupted, fencedBeforeMaterialize,
|
|
514
|
-
newer, newActiveBeforeReplay, cancelled, duplicate, session, waitAfterReplay,
|
|
515
|
-
fenced }, toolCalls: 10, steps: 13,
|
|
516
|
-
checks: [
|
|
517
|
-
check(beforeStop?.status === 'claimed' && cancelled.sessionId === first.sessionId &&
|
|
518
|
-
cancelled.mode === 'cancel' &&
|
|
519
|
-
newActiveBeforeReplay?.sessionId === newer.sessionId &&
|
|
520
|
-
waitAfterReplay?.id === newActiveBeforeReplay?.id &&
|
|
521
|
-
waitAfterReplay?.status === 'active' &&
|
|
522
|
-
sameSet(cancelled.allowedActions, ['reply', 'silence']),
|
|
523
|
-
`before=${beforeStop?.status}; cancel=${cancelled.sessionId}/${cancelled.mode}; ` +
|
|
524
|
-
`new=${waitAfterReplay?.id}/${waitAfterReplay?.status}`),
|
|
525
|
-
check(interrupted.includes('missing.json') && fencedBeforeMaterialize.generation === 2 &&
|
|
526
|
-
session.generation === 2 && duplicate.runId === cancelled.runId,
|
|
527
|
-
`interrupted=${interrupted}; generations=${fencedBeforeMaterialize.generation}/${session.generation}`),
|
|
528
|
-
check(fenced.includes('Session generation 已失效'), fenced),
|
|
529
|
-
],
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
function evalWaitReceiptRepair() {
|
|
534
|
-
const { root, cfg } = workspace()
|
|
535
|
-
enableFakeDws(root)
|
|
536
|
-
const firstEvent = dmEvent('evt-wait-repair-1', 'mid-wait-repair-1', 'alice', '帮我写总结')
|
|
537
|
-
const first = prepareSession(root, cfg, firstEvent)
|
|
538
|
-
withFakeDws(root, () => executeAction(first.cwd, 'ask', { text: '总结覆盖哪个时间段?' }))
|
|
539
|
-
const event = readJson(join(first.cwd, 'event.json'))
|
|
540
|
-
const active = readWaitForEvent(root, cfg, first.fieldId, event)
|
|
541
|
-
|
|
542
|
-
// 模拟进程在 Receipt 落盘后、Wait 状态更新前崩溃。
|
|
543
|
-
const crashed = {
|
|
544
|
-
...active,
|
|
545
|
-
status: 'arming',
|
|
546
|
-
delivery: null,
|
|
547
|
-
lastAppliedReceiptActionId: undefined,
|
|
548
|
-
}
|
|
549
|
-
const authorityRoot = waitRoot(root, cfg)
|
|
550
|
-
writeJson(join(authorityRoot, `${active.scopeHash}.json`), crashed)
|
|
551
|
-
writeJson(join(authorityRoot, 'history', `${active.id}.json`), crashed)
|
|
552
|
-
|
|
553
|
-
const resumed = prepareSession(root, cfg,
|
|
554
|
-
dmEvent('evt-wait-repair-2', 'mid-wait-repair-2', 'alice', '本周'))
|
|
555
|
-
const repaired = readWaitForEvent(
|
|
556
|
-
root, cfg, resumed.fieldId, readJson(join(resumed.cwd, 'event.json')))
|
|
557
|
-
const resume = readJson(join(resumed.cwd, 'context', 'resume.json'))
|
|
558
|
-
return {
|
|
559
|
-
output: { first, active, crashed, resumed, repaired, resume }, toolCalls: 4, steps: 6,
|
|
560
|
-
checks: [
|
|
561
|
-
check(active?.status === 'active' && crashed.status === 'arming',
|
|
562
|
-
`${active?.status} -> ${crashed.status}`),
|
|
563
|
-
check(resumed.sessionId === first.sessionId && resumed.mode === 'resume' &&
|
|
564
|
-
repaired?.status === 'claimed',
|
|
565
|
-
`${resumed.sessionId}/${resumed.mode}; wait=${repaired?.status}`),
|
|
566
|
-
check(resume.waitId === active.id && resume.questionText === '总结覆盖哪个时间段?' &&
|
|
567
|
-
repaired?.claim?.runId === resumed.runId,
|
|
568
|
-
JSON.stringify({ resume, claim: repaired?.claim })),
|
|
569
|
-
],
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
function evalClaimSupersededByCancel() {
|
|
574
|
-
const { root, cfg } = workspace()
|
|
575
|
-
enableFakeDws(root)
|
|
576
|
-
const firstEvent = dmEvent('evt-claim-race-1', 'mid-claim-race-1', 'alice', '帮我发布评价')
|
|
577
|
-
const first = prepareSession(root, cfg, firstEvent)
|
|
578
|
-
withFakeDws(root, () => executeAction(
|
|
579
|
-
first.cwd, 'ask', { text: '确认使用当前评价吗?' }))
|
|
580
|
-
|
|
581
|
-
// 精确构造:回复 E 已绑定并 claim Wait,但尚未来得及 materialize Run;/stop 抢先取消。
|
|
582
|
-
const replyRaw = dmEvent('evt-claim-race-2', 'mid-claim-race-2', 'alice', '确认')
|
|
583
|
-
const replyEvent = normalizeEvent(replyRaw)
|
|
584
|
-
const claimed = claimWait(root, cfg, first.fieldId, replyEvent)
|
|
585
|
-
// 模拟 claimed head 已落盘、event ledger 尚未落盘时 SIGKILL。
|
|
586
|
-
rmSync(join(waitRoot(root, cfg), 'events', `${digest(replyEvent.id)}.json`), { force: true })
|
|
587
|
-
const stopRaw = dmEvent('evt-claim-race-3', 'mid-claim-race-3', 'alice', '/stop')
|
|
588
|
-
const stopEvent = normalizeEvent(stopRaw)
|
|
589
|
-
const cancelled = cancelWaitForEvent(root, cfg, stopEvent)
|
|
590
|
-
|
|
591
|
-
// E 重放只能回到原 Session 的安全 no-op Run,绝不能 fallback 成新事项。
|
|
592
|
-
const suppressed = prepareSession(root, cfg, replyRaw)
|
|
593
|
-
const resume = readJson(join(suppressed.cwd, 'context', 'resume.json'))
|
|
594
|
-
let replyBlocked = ''
|
|
595
|
-
try { previewAction(suppressed.cwd, 'reply', { text: '不应发送' }) }
|
|
596
|
-
catch (e) { replyBlocked = e.message }
|
|
597
|
-
const receipt = executeAction(suppressed.cwd, 'silence', { reason: 'policy_denied' })
|
|
598
|
-
const session = readJson(join(first.sessionPath, 'session.json'))
|
|
599
|
-
return {
|
|
600
|
-
output: { first, claimed, cancelled, suppressed, resume, replyBlocked, receipt, session },
|
|
601
|
-
toolCalls: 7, steps: 9,
|
|
602
|
-
checks: [
|
|
603
|
-
check(claimed?.status === 'claimed' && cancelled?.status === 'cancelled' &&
|
|
604
|
-
session.generation === 2,
|
|
605
|
-
`claim=${claimed?.status}; cancel=${cancelled?.status}; generation=${session.generation}`),
|
|
606
|
-
check(suppressed.sessionId === first.sessionId && suppressed.mode === 'cancel' &&
|
|
607
|
-
resume.suppressedInput === true && resume.cancelEventId === stopEvent.id &&
|
|
608
|
-
sameSet(suppressed.allowedActions, ['silence']),
|
|
609
|
-
JSON.stringify({ sessionId: suppressed.sessionId, mode: suppressed.mode,
|
|
610
|
-
resume, allowed: suppressed.allowedActions })),
|
|
611
|
-
check(replyBlocked.includes('不允许 reply') && receipt.kind === 'silence' &&
|
|
612
|
-
receipt.verified === true,
|
|
613
|
-
`blocked=${replyBlocked}; receipt=${receipt.kind}/${receipt.verified}`),
|
|
614
|
-
],
|
|
615
|
-
}
|
|
616
|
-
}
|
|
617
|
-
|
|
618
|
-
function evalNegativeWaitRouting() {
|
|
619
|
-
const { root, cfg } = workspace()
|
|
620
|
-
enableFakeDws(root)
|
|
621
|
-
|
|
622
|
-
// Alice 的旧消息第一次 lookup 时没有 Wait:先固化 NO_MATCH,再创建一条新 Wait。
|
|
623
|
-
const oldReplyRaw = dmEvent('evt-negative-1', 'mid-negative-1', 'alice', '旧消息')
|
|
624
|
-
const oldReplyEvent = normalizeEvent(oldReplyRaw)
|
|
625
|
-
const noClaim = claimWait(root, cfg, 'default', oldReplyEvent)
|
|
626
|
-
const aliceWork = prepareSession(root, cfg,
|
|
627
|
-
dmEvent('evt-negative-2', 'mid-negative-2', 'alice', '后来事项'),
|
|
628
|
-
{ sessionKey: 'later-alice-work' })
|
|
629
|
-
withFakeDws(root, () => executeAction(
|
|
630
|
-
aliceWork.cwd, 'ask', { text: '后来事项需要哪个日期?' }))
|
|
631
|
-
const aliceBeforeReplay = readWaitForEvent(
|
|
632
|
-
root, cfg, aliceWork.fieldId, readJson(join(aliceWork.cwd, 'event.json')))
|
|
633
|
-
const oldReplyReplay = prepareSession(root, cfg, oldReplyRaw)
|
|
634
|
-
const aliceAfterReplay = readWaitForEvent(
|
|
635
|
-
root, cfg, aliceWork.fieldId, readJson(join(aliceWork.cwd, 'event.json')))
|
|
636
|
-
|
|
637
|
-
// Bob 的旧 stop 第一次没有目标;后来出现的 Wait 不能被旧 stop 重放误杀。
|
|
638
|
-
const oldStopRaw = dmEvent('evt-negative-3', 'mid-negative-3', 'bob', '/stop')
|
|
639
|
-
const noCancel = cancelWaitForEvent(root, cfg, normalizeEvent(oldStopRaw))
|
|
640
|
-
const bobWork = prepareSession(root, cfg,
|
|
641
|
-
dmEvent('evt-negative-4', 'mid-negative-4', 'bob', '后来事项'),
|
|
642
|
-
{ sessionKey: 'later-bob-work' })
|
|
643
|
-
withFakeDws(root, () => executeAction(
|
|
644
|
-
bobWork.cwd, 'ask', { text: '后来事项需要哪个负责人?' }))
|
|
645
|
-
const bobBeforeReplay = readWaitForEvent(
|
|
646
|
-
root, cfg, bobWork.fieldId, readJson(join(bobWork.cwd, 'event.json')))
|
|
647
|
-
const oldStopReplay = prepareSession(root, cfg, oldStopRaw)
|
|
648
|
-
const bobAfterReplay = readWaitForEvent(
|
|
649
|
-
root, cfg, bobWork.fieldId, readJson(join(bobWork.cwd, 'event.json')))
|
|
650
|
-
return {
|
|
651
|
-
output: { noClaim, aliceWork, aliceBeforeReplay, oldReplyReplay, aliceAfterReplay,
|
|
652
|
-
noCancel, bobWork, bobBeforeReplay, oldStopReplay, bobAfterReplay },
|
|
653
|
-
toolCalls: 10, steps: 12,
|
|
654
|
-
checks: [
|
|
655
|
-
check(noClaim === null && noCancel === null, `claim=${noClaim}; cancel=${noCancel}`),
|
|
656
|
-
check(oldReplyReplay.mode === 'start' &&
|
|
657
|
-
oldReplyReplay.sessionId !== aliceWork.sessionId &&
|
|
658
|
-
aliceAfterReplay?.id === aliceBeforeReplay?.id && aliceAfterReplay?.status === 'active',
|
|
659
|
-
`oldReply=${oldReplyReplay.mode}/${oldReplyReplay.sessionId}; ` +
|
|
660
|
-
`newWait=${aliceAfterReplay?.id}/${aliceAfterReplay?.status}`),
|
|
661
|
-
check(oldStopReplay.mode === 'start' && oldStopReplay.sessionId !== bobWork.sessionId &&
|
|
662
|
-
bobAfterReplay?.id === bobBeforeReplay?.id && bobAfterReplay?.status === 'active',
|
|
663
|
-
`oldStop=${oldStopReplay.mode}/${oldStopReplay.sessionId}; ` +
|
|
664
|
-
`newWait=${bobAfterReplay?.id}/${bobAfterReplay?.status}`),
|
|
665
|
-
],
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
function evalWorkspaceAuthority() {
|
|
670
|
-
const { root, cfg } = workspace()
|
|
671
|
-
enableFakeDws(root)
|
|
672
|
-
const workspacePath = join(root, '.dingtalk-agent', 'workspace.json')
|
|
673
|
-
const manifest = readJson(workspacePath)
|
|
674
|
-
manifest.dws = { profile: 'workspace-profile', expectedUserId: 'workspace-agent' }
|
|
675
|
-
manifest.mounts.memory = 'dingtalk-doc:node-memory'
|
|
676
|
-
writeJson(workspacePath, manifest)
|
|
677
|
-
|
|
678
|
-
const dispatch = withFakeDws(root, () =>
|
|
679
|
-
prepareSession(root, cfg, fixture('mentioned.json'), { contextId: manifest.contextId }))
|
|
680
|
-
const field = readJson(join(dispatch.cwd, 'context', 'field.json'))
|
|
681
|
-
const mounts = readJson(join(dispatch.cwd, 'context', 'mounts', 'manifest.json'))
|
|
682
|
-
const memory = readFileSync(join(dispatch.cwd, 'context', 'mounts', 'memory.md'), 'utf8')
|
|
683
|
-
const trigger = readJson(join(dispatch.cwd, 'trigger.json'))
|
|
684
|
-
let wrongContext = ''
|
|
685
|
-
try { prepareSession(root, cfg, fixture('mentioned.json'), { contextId: 'wrong-context' }) }
|
|
686
|
-
catch (e) { wrongContext = e.message }
|
|
687
|
-
return {
|
|
688
|
-
output: { dispatch, field: field.dws, mounts, memory, trigger, wrongContext },
|
|
689
|
-
toolCalls: 2, steps: 5,
|
|
690
|
-
checks: [
|
|
691
|
-
check(trigger.contextId === manifest.contextId && dispatch.contextId === manifest.contextId,
|
|
692
|
-
`${trigger.contextId}/${dispatch.contextId}`),
|
|
693
|
-
check(mounts.entries.some((x) => x.slot === 'memory' &&
|
|
694
|
-
x.provider === 'dingtalk-doc') && memory.includes('Remote Memory'),
|
|
695
|
-
`${JSON.stringify(mounts.entries)}; memory=${memory.trim()}`),
|
|
696
|
-
check(field.dws?.profile === 'workspace-profile' &&
|
|
697
|
-
field.dws?.expectedUserId === 'workspace-agent' &&
|
|
698
|
-
wrongContext.includes('不属于当前 Workspace'),
|
|
699
|
-
`${JSON.stringify(field.dws)}; wrong=${wrongContext}`),
|
|
700
|
-
],
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
|
|
704
|
-
function evalSessionSkillBinding() {
|
|
705
|
-
const { root, cfg } = workspace()
|
|
706
|
-
installWorkspaceSkillOverride(root)
|
|
707
|
-
const firstRaw = fixture('mentioned.json')
|
|
708
|
-
const first = prepareSession(root, cfg, firstRaw)
|
|
709
|
-
const firstSkill = join(first.cwd, 'context', 'skills', 'dingtalk-basic-behavior', 'SKILL.md')
|
|
710
|
-
const before = readFileSync(firstSkill, 'utf8')
|
|
711
|
-
const source = join(root, 'skills', 'dingtalk-basic-behavior', 'SKILL.md')
|
|
712
|
-
writeFileSync(source, readFileSync(source, 'utf8') + '\n<!-- next-session-only -->\n')
|
|
713
|
-
|
|
714
|
-
const followBody = JSON.parse(firstRaw.data)
|
|
715
|
-
followBody.event_id = 'evt-mentioned-followup-001'
|
|
716
|
-
followBody.message_id = 'mid-mentioned-followup-001'
|
|
717
|
-
followBody.root_message_id = 'mid-mentioned-001'
|
|
718
|
-
followBody.content = '确认,继续原事项'
|
|
719
|
-
const follow = prepareSession(root, cfg, { ...firstRaw, data: JSON.stringify(followBody) })
|
|
720
|
-
const followSkill = readFileSync(join(
|
|
721
|
-
follow.cwd, 'context', 'skills', 'dingtalk-basic-behavior', 'SKILL.md'), 'utf8')
|
|
722
|
-
|
|
723
|
-
const nextBody = { ...followBody,
|
|
724
|
-
event_id: 'evt-mentioned-new-session-001',
|
|
725
|
-
message_id: 'mid-mentioned-new-session-001',
|
|
726
|
-
root_message_id: '',
|
|
727
|
-
content: '这是另一件事',
|
|
728
|
-
}
|
|
729
|
-
const next = prepareSession(root, cfg, { ...firstRaw, data: JSON.stringify(nextBody) })
|
|
730
|
-
const nextSkill = readFileSync(join(
|
|
731
|
-
next.cwd, 'context', 'skills', 'dingtalk-basic-behavior', 'SKILL.md'), 'utf8')
|
|
732
|
-
const session = readJson(join(first.sessionPath, 'session.json'))
|
|
733
|
-
return {
|
|
734
|
-
output: { first, follow, next, sessionSkills: session.skills },
|
|
735
|
-
toolCalls: 3, steps: 6,
|
|
736
|
-
checks: [
|
|
737
|
-
check(follow.sessionId === first.sessionId && follow.runId !== first.runId,
|
|
738
|
-
`${first.sessionId}/${first.runId} -> ${follow.sessionId}/${follow.runId}`),
|
|
739
|
-
check(before === followSkill && !followSkill.includes('next-session-only') &&
|
|
740
|
-
Boolean(session.skills?.manifestHash),
|
|
741
|
-
`same=${before === followSkill}; manifest=${session.skills?.manifestHash}`),
|
|
742
|
-
check(next.sessionId !== first.sessionId && nextSkill.includes('next-session-only'),
|
|
743
|
-
`${next.sessionId}; updated=${nextSkill.includes('next-session-only')}`),
|
|
744
|
-
],
|
|
745
|
-
}
|
|
746
|
-
}
|
|
747
|
-
|
|
748
|
-
function evalGlobalSkillInstall() {
|
|
749
|
-
const home = mkdtempSync(join(tmpdir(), 'dta-skill-home-'))
|
|
750
|
-
const cwd = mkdtempSync(join(tmpdir(), 'dta-skill-cwd-'))
|
|
751
|
-
WORKSPACES.push(home, cwd)
|
|
752
|
-
const env = { ...process.env, HOME: home }
|
|
753
|
-
const first = spawnSync(process.execPath, [CLI, 'skill', 'install', '--json'], {
|
|
754
|
-
cwd, env, encoding: 'utf8',
|
|
755
|
-
})
|
|
756
|
-
const second = spawnSync(process.execPath, [CLI, 'skill', 'install', '--json'], {
|
|
757
|
-
cwd, env, encoding: 'utf8',
|
|
758
|
-
})
|
|
759
|
-
const status = JSON.parse(second.stdout)
|
|
760
|
-
const canonical = join(home, '.agents', 'skills', 'dingtalk-basic-behavior')
|
|
761
|
-
const claude = join(home, '.claude', 'skills', 'dingtalk-basic-behavior')
|
|
762
|
-
|
|
763
|
-
const marker = join(canonical, '.dingtalk-agent-install.json')
|
|
764
|
-
return {
|
|
765
|
-
output: {
|
|
766
|
-
firstStatus: first.status, secondStatus: second.status, status,
|
|
767
|
-
claudeTarget: readlinkSync(claude), markerExists: existsSync(marker),
|
|
768
|
-
},
|
|
769
|
-
toolCalls: 3, steps: 6,
|
|
770
|
-
checks: [
|
|
771
|
-
check(first.status === 0 && existsSync(join(canonical, 'SKILL.md')),
|
|
772
|
-
`status=${first.status}; canonical=${canonical}`),
|
|
773
|
-
check(second.status === 0 && status.manager === 'skills-cli' &&
|
|
774
|
-
status.canonical.current === true && status.operation?.command.includes('skills@latest -- skills add'),
|
|
775
|
-
`status=${second.status}; manager=${status.manager}; current=${status.canonical.current}`),
|
|
776
|
-
check(lstatSync(claude).isSymbolicLink() &&
|
|
777
|
-
resolve(dirname(claude), readlinkSync(claude)) === resolve(canonical),
|
|
778
|
-
`target=${readlinkSync(claude)}`),
|
|
779
|
-
check(!existsSync(marker), '上游 skills CLI 接管后不存在 dta 自定义 marker'),
|
|
780
|
-
],
|
|
781
|
-
}
|
|
782
|
-
}
|
|
783
|
-
|
|
784
|
-
function evalBootstrapLocal() {
|
|
785
|
-
const root = mkdtempSync(join(tmpdir(), 'dta-bootstrap-local-'))
|
|
786
|
-
WORKSPACES.push(root)
|
|
787
|
-
mkdirSync(join(root, 'knowledge'), { recursive: true })
|
|
788
|
-
writeFileSync(join(root, 'WORKSPACE.md'), '# Identity\n')
|
|
789
|
-
writeFileSync(join(root, 'MEMORY.md'), '# Memory\n')
|
|
790
|
-
writeFileSync(join(root, 'knowledge', 'INDEX.md'), '# Knowledge\n')
|
|
791
|
-
const run = spawnSync(process.execPath, [CLI, 'bootstrap', '--json'], {
|
|
792
|
-
cwd: root, encoding: 'utf8',
|
|
793
|
-
})
|
|
794
|
-
const out = JSON.parse(run.stdout)
|
|
795
|
-
return {
|
|
796
|
-
output: out, toolCalls: 1, steps: 3,
|
|
797
|
-
checks: [
|
|
798
|
-
check(run.status === 0 && out.mode === 'direct' && out.initialized === false,
|
|
799
|
-
`status=${run.status}; mode=${out.mode}; initialized=${out.initialized}`),
|
|
800
|
-
check(out.mounts.map((x) => x.slot).join(',') === 'profile,memory,knowledge',
|
|
801
|
-
JSON.stringify(out.mounts)),
|
|
802
|
-
check(!existsSync(join(root, '.dingtalk-agent')), 'bootstrap 未创建 .dingtalk-agent'),
|
|
803
|
-
],
|
|
804
|
-
}
|
|
805
|
-
}
|
|
806
|
-
|
|
807
|
-
function evalBootstrapRemote() {
|
|
808
|
-
const root = mkdtempSync(join(tmpdir(), 'dta-bootstrap-remote-'))
|
|
809
|
-
WORKSPACES.push(root)
|
|
810
|
-
const bin = enableFakeDws(root)
|
|
811
|
-
const state = join(root, '.state')
|
|
812
|
-
const run = spawnSync(process.execPath, [
|
|
813
|
-
CLI, 'bootstrap', '--storage', 'dingtalk-doc:node-memory',
|
|
814
|
-
'--state-dir', state, '--json',
|
|
815
|
-
], {
|
|
816
|
-
cwd: root,
|
|
817
|
-
env: { ...process.env, PATH: `${bin}:${process.env.PATH || ''}` },
|
|
818
|
-
encoding: 'utf8',
|
|
819
|
-
})
|
|
820
|
-
const out = JSON.parse(run.stdout)
|
|
821
|
-
const snapshot = out.mounts?.[0]?.path || ''
|
|
822
|
-
return {
|
|
823
|
-
output: { out, snapshot: snapshot ? readFileSync(snapshot, 'utf8') : '', stderr: run.stderr },
|
|
824
|
-
toolCalls: 1, steps: 4,
|
|
825
|
-
checks: [
|
|
826
|
-
check(run.status === 0 && out.mode === 'direct' && out.initialized === false,
|
|
827
|
-
`status=${run.status}; mode=${out.mode}; initialized=${out.initialized}`),
|
|
828
|
-
check(out.mounts.length === 1 && out.mounts[0].provider === 'dingtalk-doc' &&
|
|
829
|
-
readFileSync(snapshot, 'utf8').includes('Remote Memory'), JSON.stringify(out.mounts)),
|
|
830
|
-
check(existsSync(join(dirname(snapshot), 'manifest.json')) &&
|
|
831
|
-
!existsSync(join(root, '.dingtalk-agent', 'workspace.json')),
|
|
832
|
-
`manifest=${join(dirname(snapshot), 'manifest.json')}`),
|
|
833
|
-
],
|
|
834
|
-
}
|
|
835
|
-
}
|
|
836
|
-
|
|
837
|
-
function evalOptionalInit() {
|
|
838
|
-
const root = mkdtempSync(join(tmpdir(), 'dta-init-optional-'))
|
|
839
|
-
WORKSPACES.push(root)
|
|
840
|
-
const first = spawnSync(process.execPath, [CLI, 'init'], { cwd: root, encoding: 'utf8' })
|
|
841
|
-
const workspaceFile = join(root, '.dingtalk-agent', 'workspace.json')
|
|
842
|
-
const before = readFileSync(workspaceFile, 'utf8')
|
|
843
|
-
const second = spawnSync(process.execPath, [CLI, 'init'], { cwd: root, encoding: 'utf8' })
|
|
844
|
-
const after = readFileSync(workspaceFile, 'utf8')
|
|
845
|
-
const manifest = JSON.parse(after)
|
|
846
|
-
return {
|
|
847
|
-
output: { first: first.stdout, second: second.stdout, manifest },
|
|
848
|
-
toolCalls: 2, steps: 4,
|
|
849
|
-
checks: [
|
|
850
|
-
check(first.status === 0 && manifest.contextId === root.split('/').pop(),
|
|
851
|
-
`status=${first.status}; context=${manifest.contextId}`),
|
|
852
|
-
check(before === after && second.stdout.includes('Workspace 已存在'),
|
|
853
|
-
`same=${before === after}; second=${second.stdout.trim()}`),
|
|
854
|
-
check(!existsSync(join(root, 'AGENTS.md')) && !existsSync(join(root, 'CLAUDE.md')) &&
|
|
855
|
-
!existsSync(join(root, 'ontology')) && !existsSync(join(root, 'skills')),
|
|
856
|
-
'init 未写 AGENTS.md/CLAUDE.md/ontology/skills'),
|
|
857
|
-
check(manifest.skills[0] === 'dingtalk-basic-behavior', JSON.stringify(manifest.skills)),
|
|
858
|
-
],
|
|
859
|
-
}
|
|
860
|
-
}
|
|
861
|
-
|
|
862
|
-
function evalManagedSkillLifecycle() {
|
|
863
|
-
const home = mkdtempSync(join(tmpdir(), 'dta-skill-lifecycle-'))
|
|
864
|
-
const cwd = mkdtempSync(join(tmpdir(), 'dta-skill-lifecycle-cwd-'))
|
|
865
|
-
WORKSPACES.push(home, cwd)
|
|
866
|
-
const env = { ...process.env, HOME: home }
|
|
867
|
-
spawnSync(process.execPath, [CLI, 'skill', 'install'], { cwd, env, encoding: 'utf8' })
|
|
868
|
-
const canonical = join(home, '.agents', 'skills', 'dingtalk-basic-behavior')
|
|
869
|
-
const file = join(canonical, 'SKILL.md')
|
|
870
|
-
writeFileSync(file, readFileSync(file, 'utf8') + '\n<!-- local edit -->\n')
|
|
871
|
-
const statusRun = spawnSync(process.execPath, [CLI, 'skill', 'status', '--json'], {
|
|
872
|
-
cwd, env, encoding: 'utf8',
|
|
873
|
-
})
|
|
874
|
-
const modified = JSON.parse(statusRun.stdout)
|
|
875
|
-
const repaired = spawnSync(process.execPath, [CLI, 'skill', 'upgrade', '--json'], {
|
|
876
|
-
cwd, env, encoding: 'utf8',
|
|
877
|
-
})
|
|
878
|
-
const repairedStatus = JSON.parse(repaired.stdout)
|
|
879
|
-
const repairedBody = readFileSync(file, 'utf8')
|
|
880
|
-
const removed = spawnSync(process.execPath, [CLI, 'skill', 'uninstall', '--json'], {
|
|
881
|
-
cwd, env, encoding: 'utf8',
|
|
882
|
-
})
|
|
883
|
-
const removedStatus = JSON.parse(removed.stdout)
|
|
884
|
-
return {
|
|
885
|
-
output: {
|
|
886
|
-
modified, repairedStatus, removedStatus,
|
|
887
|
-
},
|
|
888
|
-
toolCalls: 4, steps: 6,
|
|
889
|
-
checks: [
|
|
890
|
-
check(modified.manager === 'skills-cli' && modified.canonical.exists === true,
|
|
891
|
-
JSON.stringify(modified.canonical)),
|
|
892
|
-
check(repaired.status === 0 && !repairedBody.includes('local edit') &&
|
|
893
|
-
repairedStatus.operation?.command.includes('skills@latest -- skills add'),
|
|
894
|
-
`status=${repaired.status}; command=${repairedStatus.operation?.command}`),
|
|
895
|
-
check(removed.status === 0 && removedStatus.operation?.command.includes('skills@latest -- skills remove'),
|
|
896
|
-
`status=${removed.status}; command=${removedStatus.operation?.command}`),
|
|
897
|
-
check(repairedStatus.canonical.current === true &&
|
|
898
|
-
removed.status === 0 && removedStatus.canonical.exists === false &&
|
|
899
|
-
removedStatus.claude.state === 'missing',
|
|
900
|
-
`repaired=${repairedStatus.canonical.current}; removed=${removedStatus.canonical.exists}; ` +
|
|
901
|
-
`claude=${removedStatus.claude.state}`),
|
|
902
|
-
],
|
|
903
|
-
}
|
|
904
|
-
}
|
|
905
|
-
|
|
906
|
-
function evalRemoteStorageTypeGate() {
|
|
907
|
-
const root = mkdtempSync(join(tmpdir(), 'dta-bootstrap-wrong-type-'))
|
|
908
|
-
WORKSPACES.push(root)
|
|
909
|
-
const bin = enableFakeDws(root)
|
|
910
|
-
const run = spawnSync(process.execPath, [
|
|
911
|
-
CLI, 'bootstrap', '--storage', 'dingtalk-doc:sheet-node',
|
|
912
|
-
'--state-dir', join(root, '.state'), '--json',
|
|
913
|
-
], {
|
|
914
|
-
cwd: root,
|
|
915
|
-
env: {
|
|
916
|
-
...process.env,
|
|
917
|
-
PATH: `${bin}:${process.env.PATH || ''}`,
|
|
918
|
-
DTA_FAKE_DOC_EXTENSION: 'axls',
|
|
919
|
-
},
|
|
920
|
-
encoding: 'utf8',
|
|
921
|
-
})
|
|
922
|
-
return {
|
|
923
|
-
output: { status: run.status, stderr: run.stderr.trim() }, toolCalls: 1, steps: 2,
|
|
924
|
-
checks: [
|
|
925
|
-
check(run.status !== 0 && run.stderr.includes('只接受在线文档 adoc'), run.stderr.trim()),
|
|
926
|
-
check(!existsSync(join(root, '.state')), '类型不符时没有创建远端快照目录'),
|
|
927
|
-
],
|
|
928
|
-
}
|
|
929
|
-
}
|
|
930
|
-
|
|
931
|
-
function evalDirectActGate() {
|
|
932
|
-
const root = mkdtempSync(join(tmpdir(), 'dta-direct-act-'))
|
|
933
|
-
WORKSPACES.push(root)
|
|
934
|
-
const run = spawnSync(process.execPath, [CLI, 'act', 'reply', '--text', '越权回复'], {
|
|
935
|
-
cwd: root, encoding: 'utf8',
|
|
936
|
-
})
|
|
937
|
-
return {
|
|
938
|
-
output: { status: run.status, stderr: run.stderr.trim() }, toolCalls: 1, steps: 2,
|
|
939
|
-
checks: [
|
|
940
|
-
check(run.status !== 0 && run.stderr.includes('找不到当前 Run'), run.stderr.trim()),
|
|
941
|
-
check(!existsSync(join(root, '.dingtalk-agent')), 'act fail closed 时不自动 init'),
|
|
942
|
-
],
|
|
943
|
-
}
|
|
944
|
-
}
|
|
945
|
-
|
|
946
|
-
function evalDoctorMissingDependencies() {
|
|
947
|
-
const home = mkdtempSync(join(tmpdir(), 'dta-doctor-missing-home-'))
|
|
948
|
-
const cwd = mkdtempSync(join(tmpdir(), 'dta-doctor-missing-cwd-'))
|
|
949
|
-
WORKSPACES.push(home, cwd)
|
|
950
|
-
const run = spawnSync(process.execPath, [CLI, 'doctor', '--json'], {
|
|
951
|
-
cwd,
|
|
952
|
-
env: { ...process.env, HOME: home, PATH: '' },
|
|
953
|
-
encoding: 'utf8',
|
|
954
|
-
})
|
|
955
|
-
const out = JSON.parse(run.stdout)
|
|
956
|
-
const byId = Object.fromEntries(out.checks.map((check) => [check.id, check]))
|
|
957
|
-
return {
|
|
958
|
-
output: { status: run.status, report: out }, toolCalls: 1, steps: 3,
|
|
959
|
-
checks: [
|
|
960
|
-
check(run.status === 2 && out.ready === false && byId.cli.level === 'fail',
|
|
961
|
-
`status=${run.status}; ready=${out.ready}; cli=${byId.cli.level}`),
|
|
962
|
-
check(byId.dws.level === 'fail' && byId['dws-auth'].level === 'fail',
|
|
963
|
-
`dws=${byId.dws.level}; auth=${byId['dws-auth'].level}`),
|
|
964
|
-
check(out.nextSteps.some((step) => step.includes('npx --yes')) &&
|
|
965
|
-
out.nextSteps.some((step) => step.includes('dws auth login')),
|
|
966
|
-
JSON.stringify(out.nextSteps)),
|
|
967
|
-
],
|
|
968
|
-
}
|
|
969
|
-
}
|
|
970
|
-
|
|
971
|
-
function evalFirstRunSetup() {
|
|
972
|
-
const home = mkdtempSync(join(tmpdir(), 'dta-setup-home-'))
|
|
973
|
-
const cwd = mkdtempSync(join(tmpdir(), 'dta-setup-cwd-'))
|
|
974
|
-
WORKSPACES.push(home, cwd)
|
|
975
|
-
const fakeBin = enableFakeDws(cwd)
|
|
976
|
-
const env = {
|
|
977
|
-
...process.env,
|
|
978
|
-
HOME: home,
|
|
979
|
-
SHELL: '/bin/zsh',
|
|
980
|
-
PATH: `${fakeBin}:${process.env.PATH || ''}`,
|
|
981
|
-
DTA_SETUP_PACKAGE_SOURCE: ROOT,
|
|
982
|
-
}
|
|
983
|
-
const run = spawnSync(process.execPath, [CLI, 'setup', '--json'], {
|
|
984
|
-
cwd, env, encoding: 'utf8', timeout: 120_000,
|
|
985
|
-
})
|
|
986
|
-
const out = run.stdout ? JSON.parse(run.stdout) : null
|
|
987
|
-
const executable = join(home, '.local', 'bin', 'dingtalk-agent')
|
|
988
|
-
const alias = join(home, '.local', 'bin', 'dta')
|
|
989
|
-
const version = existsSync(executable)
|
|
990
|
-
? spawnSync(executable, ['--version'], { env, encoding: 'utf8' })
|
|
991
|
-
: { status: -1, stdout: '' }
|
|
992
|
-
const aliasVersion = existsSync(alias)
|
|
993
|
-
? spawnSync(alias, ['--version'], { env, encoding: 'utf8' })
|
|
994
|
-
: { status: -1, stdout: '' }
|
|
995
|
-
const rc = existsSync(join(home, '.zshrc')) ? readFileSync(join(home, '.zshrc'), 'utf8') : ''
|
|
996
|
-
const canonical = join(home, '.agents', 'skills', 'dingtalk-basic-behavior')
|
|
997
|
-
const claude = join(home, '.claude', 'skills', 'dingtalk-basic-behavior')
|
|
998
|
-
return {
|
|
999
|
-
output: {
|
|
1000
|
-
status: run.status, stderr: run.stderr.trim(), report: out,
|
|
1001
|
-
executable, alias, version: String(version.stdout || '').trim(),
|
|
1002
|
-
aliasVersion: String(aliasVersion.stdout || '').trim(), rc,
|
|
1003
|
-
},
|
|
1004
|
-
toolCalls: 1, steps: 6,
|
|
1005
|
-
checks: [
|
|
1006
|
-
check(run.status === 0 && existsSync(executable) && version.status === 0 &&
|
|
1007
|
-
existsSync(alias) && aliasVersion.status === 0 &&
|
|
1008
|
-
aliasVersion.stdout === version.stdout,
|
|
1009
|
-
`status=${run.status}; executable=${existsSync(executable)}; alias=${existsSync(alias)}; ` +
|
|
1010
|
-
`version=${version.status}/${aliasVersion.status}`),
|
|
1011
|
-
check(out?.shell.updated === true && rc.includes('dingtalk-agent PATH') &&
|
|
1012
|
-
rc.includes('$HOME/.local/bin'),
|
|
1013
|
-
`updated=${out?.shell.updated}; rc=${JSON.stringify(rc)}`),
|
|
1014
|
-
check(existsSync(join(canonical, 'SKILL.md')) && lstatSync(claude).isSymbolicLink() &&
|
|
1015
|
-
out?.skill.clients.every((client) => client.state === 'ok'),
|
|
1016
|
-
`canonical=${existsSync(canonical)}; clients=${JSON.stringify(out?.skill.clients)}`),
|
|
1017
|
-
check(out?.doctor.ready === true &&
|
|
1018
|
-
out.doctor.checks.find((check) => check.id === 'dws')?.level === 'pass' &&
|
|
1019
|
-
out.doctor.checks.find((check) => check.id === 'dws-auth')?.level === 'pass',
|
|
1020
|
-
`ready=${out?.doctor.ready}; checks=${JSON.stringify(out?.doctor.checks)}`),
|
|
1021
|
-
],
|
|
1022
|
-
}
|
|
1023
|
-
}
|
|
1024
|
-
|
|
1025
|
-
function evalCliErrorHints() {
|
|
1026
|
-
const typo = spawnSync(process.execPath, [CLI, 'doctro'], { encoding: 'utf8' })
|
|
1027
|
-
const subcommand = spawnSync(process.execPath, [CLI, 'skill', 'instal'], { encoding: 'utf8' })
|
|
1028
|
-
const option = spawnSync(process.execPath, [CLI, 'doctor', '--bogus'], { encoding: 'utf8' })
|
|
1029
|
-
return {
|
|
1030
|
-
output: {
|
|
1031
|
-
typo: { status: typo.status, stderr: typo.stderr.trim() },
|
|
1032
|
-
subcommand: { status: subcommand.status, stderr: subcommand.stderr.trim() },
|
|
1033
|
-
option: { status: option.status, stderr: option.stderr.trim() },
|
|
1034
|
-
},
|
|
1035
|
-
toolCalls: 3, steps: 3,
|
|
1036
|
-
checks: [
|
|
1037
|
-
check(typo.status === 1 && typo.stderr.includes('错误:') &&
|
|
1038
|
-
typo.stderr.includes('提示:') && typo.stderr.includes('dta doctor'), typo.stderr.trim()),
|
|
1039
|
-
check(subcommand.status === 1 && subcommand.stderr.includes('dta skill install'),
|
|
1040
|
-
subcommand.stderr.trim()),
|
|
1041
|
-
check(option.status === 2 && option.stderr.includes('检查参数拼写') &&
|
|
1042
|
-
option.stderr.includes('dta --help'), option.stderr.trim()),
|
|
1043
|
-
],
|
|
1044
|
-
}
|
|
1045
|
-
}
|
|
1046
|
-
|
|
1047
|
-
function dmEvent(eventId, messageId, actor, text, extra = {}) {
|
|
1048
|
-
return {
|
|
1049
|
-
event_corp_id: extra.tenantId || 'tenant-wait-eval',
|
|
1050
|
-
data: JSON.stringify({
|
|
1051
|
-
type: 'user_im_message_receive_o2o',
|
|
1052
|
-
event_id: eventId,
|
|
1053
|
-
conversation_id: extra.conversationId || 'cid-wait-eval',
|
|
1054
|
-
message_id: messageId,
|
|
1055
|
-
sender: actor,
|
|
1056
|
-
sender_open_dingtalk_id: `$:LWCP_v1:$${actor}`,
|
|
1057
|
-
content: text,
|
|
1058
|
-
}),
|
|
1059
|
-
}
|
|
1060
|
-
}
|
|
1061
|
-
|
|
1062
|
-
function enableFakeDws(root) {
|
|
1063
|
-
const fieldPath = join(root, 'fields', 'default', 'field.json')
|
|
1064
|
-
if (existsSync(fieldPath)) {
|
|
1065
|
-
const field = readJson(fieldPath)
|
|
1066
|
-
field.dws = { profile: 'eval-profile', expectedUserId: 'agent-eval' }
|
|
1067
|
-
writeJson(fieldPath, field)
|
|
1068
|
-
}
|
|
1069
|
-
|
|
1070
|
-
const bin = join(root, '.fake-bin')
|
|
1071
|
-
mkdirSync(bin, { recursive: true })
|
|
1072
|
-
const script = join(bin, 'dws')
|
|
1073
|
-
writeFileSync(script, `#!/usr/bin/env node
|
|
1074
|
-
const a = process.argv.slice(2)
|
|
1075
|
-
let data = {}
|
|
1076
|
-
if (a[0] === 'version') { console.log(JSON.stringify({ version: 'v1.0.99-test' })); process.exit(0) }
|
|
1077
|
-
if (a[0] === 'auth' && a[1] === 'status') { console.log(JSON.stringify({ authenticated: true, token_valid: true, corp_name: 'Test Corp', user_name: 'Test User' })); process.exit(0) }
|
|
1078
|
-
if (a.includes('get-self')) data = { userId: 'agent-eval' }
|
|
1079
|
-
else if (a.includes('doc') && a.includes('read')) data = { markdown: '# Remote Memory\\n\\n来自钉钉文档。' }
|
|
1080
|
-
else if (a.includes('doc') && a.includes('info')) data = { contentType: 'ALIDOC', extension: process.env.DTA_FAKE_DOC_EXTENSION || 'adoc', nodeType: 'file' }
|
|
1081
|
-
else if (a.includes('reply')) data = { openMessageId: 'fake-sent-message' }
|
|
1082
|
-
else if (a.includes('list-by-ids')) data = { messages: [{ openMessageId: 'fake-sent-message' }] }
|
|
1083
|
-
console.log(JSON.stringify({ data }))
|
|
1084
|
-
`)
|
|
1085
|
-
chmodSync(script, 0o755)
|
|
1086
|
-
return bin
|
|
1087
|
-
}
|
|
1088
|
-
|
|
1089
|
-
function withFakeDws(root, fn) {
|
|
1090
|
-
const before = process.env.PATH || ''
|
|
1091
|
-
process.env.PATH = `${join(root, '.fake-bin')}:${before}`
|
|
1092
|
-
try { return fn() } finally { process.env.PATH = before }
|
|
1093
|
-
}
|
|
1094
|
-
|
|
1095
|
-
function installWorkspaceSkillOverride(root) {
|
|
1096
|
-
cpSync(
|
|
1097
|
-
join(ROOT, 'skills', 'dingtalk-basic-behavior'),
|
|
1098
|
-
join(root, 'skills', 'dingtalk-basic-behavior'),
|
|
1099
|
-
{ recursive: true },
|
|
1100
|
-
)
|
|
1101
|
-
}
|
|
1102
|
-
|
|
1103
|
-
function workspace() {
|
|
1104
|
-
const root = mkdtempSync(join(tmpdir(), 'dta-eval-'))
|
|
1105
|
-
WORKSPACES.push(root)
|
|
1106
|
-
const log = console.log
|
|
1107
|
-
console.log = () => {}
|
|
1108
|
-
try { init(root) } finally { console.log = log }
|
|
1109
|
-
return { root, cfg: config.must(root) }
|
|
1110
|
-
}
|
|
1111
|
-
|
|
1112
|
-
function fixture(name) {
|
|
1113
|
-
return JSON.parse(readFileSync(join(HERE, 'fixtures', name), 'utf8'))
|
|
1114
|
-
}
|
|
1115
|
-
|
|
1116
|
-
function sameSet(a, b) {
|
|
1117
|
-
return a.length === b.length && a.every((x) => b.includes(x))
|
|
1118
|
-
}
|
|
1119
|
-
|
|
1120
|
-
function check(passed, evidence) { return { passed, evidence } }
|
|
1121
|
-
|
|
1122
|
-
function writeJson(path, value) {
|
|
1123
|
-
mkdirSync(dirname(path), { recursive: true })
|
|
1124
|
-
writeFileSync(path, JSON.stringify(value, null, 2) + '\n')
|
|
1125
|
-
}
|