@hugesb/dsh-stream-agent 0.0.0-stage → 0.3.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/CHANGELOG.md +622 -0
- package/CONTRIBUTING.md +72 -0
- package/LICENSE +202 -0
- package/README.en.md +349 -0
- package/README.md +300 -3
- package/cordis.patch.yml +77 -0
- package/dist/entry/action-gate.js +206 -0
- package/dist/entry/adapter-kit.js +192 -0
- package/dist/entry/context-render.js +119 -0
- package/dist/entry/control-bar-cli.js +289 -0
- package/dist/entry/control-bar.js +123 -0
- package/dist/entry/control-session.js +115 -0
- package/dist/entry/control-state.js +125 -0
- package/dist/entry/cordis-compat.js +95 -0
- package/dist/entry/eval-probe.js +112 -0
- package/dist/entry/intent-log.js +121 -0
- package/dist/entry/json-persistence.js +306 -0
- package/dist/entry/loop.js +4163 -0
- package/dist/entry/mock-provider.js +549 -0
- package/dist/entry/obs-broker.js +178 -0
- package/dist/entry/ptc-bridge.js +405 -0
- package/dist/entry/state-handle.js +217 -0
- package/dist/entry/takeover-registry.js +60 -0
- package/dist/kernel/control-bar.js +559 -0
- package/dist/kernel/final.js +62 -0
- package/dist/kernel/gate.js +464 -0
- package/dist/kernel/modes.js +253 -0
- package/dist/kernel/obs.js +517 -0
- package/dist/kernel/parser.js +1081 -0
- package/dist/kernel/render.js +466 -0
- package/dist/kernel/state.js +416 -0
- package/dist/version.js +9 -0
- package/docs/TEST-PROPOSITIONS.md +139 -0
- package/docs/adr-001-segment-boundary.md +61 -0
- package/docs/architecture.md +104 -0
- package/docs/desktop-ui-feasibility.md +277 -0
- package/docs/disabled-lines-audit.md +53 -0
- package/docs/limitations.md +181 -0
- package/docs/protocol.md +99 -0
- package/docs/v0.4.0-plan.md +50 -0
- package/eval/METRICS.md +128 -0
- package/eval/RESULTS.md +246 -0
- package/eval/tasks/fixtures/big-report.md +298 -0
- package/eval/tasks/fixtures/build-manifest.txt +5 -0
- package/eval/tasks/fixtures/deploy.yaml +4 -0
- package/eval/tasks/fixtures/error.log +200 -0
- package/eval/tasks/fixtures/features.yaml +4 -0
- package/eval/tasks/fixtures/pipeline.yaml +4 -0
- package/eval/tasks/fixtures/sales-q1.csv +61 -0
- package/eval/tasks/fixtures/settings.yaml +4 -0
- package/eval/tasks/fixtures/users-roster.json +304 -0
- package/eval/tasks/fixtures/users-scores.json +20 -0
- package/eval/tasks/gen-fixtures.cjs +80 -0
- package/eval/tasks/tasks.json +150 -0
- package/eval/tools/f6-kill-drill.cjs +176 -0
- package/eval/tools/f6-kill-drill.worker.cjs +131 -0
- package/eval/tools/gen-results.cjs +191 -0
- package/eval/tools/machine-test.cjs +200 -0
- package/eval/tools/manual-code-scenarios.md +59 -0
- package/eval/tools/replay-check.cjs +311 -0
- package/eval/tools/runner.cjs +219 -0
- package/eval/tools/session-log.cjs +106 -0
- package/eval/tools/summarize.cjs +185 -0
- package/eval/tools/t3-cells.cjs +173 -0
- package/package.json +73 -6
- package/patches/adapters-smoke.yml +41 -0
- package/patches/eval-account.yml +36 -0
- package/patches/eval-baseline.yml +33 -0
- package/patches/eval-stream-code-off.yml +46 -0
- package/patches/eval-stream-code-on.yml +47 -0
- package/patches/eval-stream.yml +54 -0
- package/patches/takeover.yml +42 -0
- package/patches/test-preset.yml +23 -0
- package/preset/stream/cordis.patch.yml +39 -0
- package/preset/stream/package.json +13 -0
- package/preset.yml +56 -0
- package/profiles/stream/README.md +66 -0
- package/profiles/stream/cordis.patch.yml +12 -0
- package/profiles/stream/package.json +17 -0
- package/profiles/stream-headless/package.json +16 -0
- package/scripts/build.mjs +103 -0
- package/scripts/check-consistency.mjs +146 -0
- package/scripts/gate.mjs +138 -0
- package/scripts/install-check.mjs +116 -0
- package/scripts/install-cycle.mjs +88 -0
- package/scripts/release.mjs +428 -0
- package/scripts/repair-session-logs.mjs +498 -0
- package/src/entry/action-gate.ts +206 -0
- package/src/entry/adapter-kit.ts +192 -0
- package/src/entry/context-render.ts +119 -0
- package/src/entry/control-bar-cli.ts +289 -0
- package/src/entry/control-bar.ts +123 -0
- package/src/entry/control-session.ts +115 -0
- package/src/entry/control-state.ts +125 -0
- package/src/entry/cordis-compat.ts +95 -0
- package/src/entry/eval-probe.ts +112 -0
- package/src/entry/intent-log.ts +121 -0
- package/src/entry/json-persistence.ts +306 -0
- package/src/entry/loop.ts +4163 -0
- package/src/entry/mock-provider.ts +549 -0
- package/src/entry/obs-broker.ts +178 -0
- package/src/entry/ptc-bridge.ts +405 -0
- package/src/entry/state-handle.ts +217 -0
- package/src/entry/takeover-registry.ts +60 -0
- package/src/kernel/control-bar.ts +559 -0
- package/src/kernel/final.ts +62 -0
- package/src/kernel/gate.ts +464 -0
- package/src/kernel/modes.ts +253 -0
- package/src/kernel/obs.ts +517 -0
- package/src/kernel/parser.ts +1081 -0
- package/src/kernel/render.ts +466 -0
- package/src/kernel/state.ts +416 -0
- package/src/version.ts +9 -0
- package/test/activation.test.ts +187 -0
- package/test/adapters.test.ts +676 -0
- package/test/control-bar.test.ts +486 -0
- package/test/desktop-ui.test.ts +359 -0
- package/test/eval-probe.test.ts +139 -0
- package/test/f5-plan.test.ts +221 -0
- package/test/f6-intent.test.ts +168 -0
- package/test/f7-segment.test.ts +190 -0
- package/test/fix-limits.test.ts +599 -0
- package/test/gate.test.ts +380 -0
- package/test/helpers/stub-loop.ts +240 -0
- package/test/host-conformance.test.ts +418 -0
- package/test/kernel/obs.test.ts +329 -0
- package/test/kernel/parser.test.ts +451 -0
- package/test/loop.test.ts +1393 -0
- package/test/mock-provider.test.ts +386 -0
- package/test/ptc-bridge.test.ts +356 -0
- package/test/render.test.ts +418 -0
- package/test/s2-install-check.test.ts +46 -0
- package/test/scenarios/3-file-basic.json +13 -0
- package/test/scenarios/5-file-basic.json +22 -0
- package/test/scenarios/burn-more.json +9 -0
- package/test/scenarios/degraded-final.json +10 -0
- package/test/scenarios/fault-abort-xml.json +11 -0
- package/test/scenarios/fault-malformed-command.json +12 -0
- package/test/scenarios/fault-midstream-abort.json +11 -0
- package/test/scenarios/fault-saturating-output.json +9 -0
- package/test/scenarios/fault-timeout.json +9 -0
- package/test/scenarios/peek-first.json +11 -0
- package/test/scenarios/peek-second.json +11 -0
- package/test/scenarios/peek-third.json +10 -0
- package/test/scenarios/recover-final.json +10 -0
- package/test/scenarios/reroute-first.json +17 -0
- package/test/scenarios/reroute-second.json +16 -0
- package/test/scenarios/starvation-final.json +10 -0
- package/test/scenarios/starvation-promote.json +11 -0
- package/test/scenarios/wait-tools-continue.json +10 -0
- package/test/scenarios/wait-tools-xml.json +22 -0
- package/test/scenarios/wait-tools.json +15 -0
- package/test/session-format.test.ts +234 -0
- package/test/state.test.ts +335 -0
- package/test/stream-v02.test.ts +264 -0
- package/test/v031-display.test.ts +333 -0
- package/test/v032-conflict.test.ts +191 -0
- package/test/v032-truncation.test.ts +291 -0
- package/ui/client.js +576 -0
- package/ui/index.js +282 -0
- package/ui/package.json +26 -0
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* render.ts 单测:三段式装配 / O6 前缀校验 fail-closed / O4 动态冻结 / O3 目录差分注入 /
|
|
3
|
+
* 压缩历史拒绝+尾部截断降级 / 20 步 renderHash 单调断言。
|
|
4
|
+
* 全部离线,时钟注入。
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import test from 'node:test';
|
|
8
|
+
import assert from 'node:assert/strict';
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
ContextRenderer,
|
|
12
|
+
assertPrefixStable,
|
|
13
|
+
renderHash,
|
|
14
|
+
PrefixBrokenError,
|
|
15
|
+
DynamicInPrefixError,
|
|
16
|
+
type RenderMessage,
|
|
17
|
+
type HandleDirectoryDelta,
|
|
18
|
+
type PolicyViolationRecord,
|
|
19
|
+
type RenderClock,
|
|
20
|
+
} from '../src/kernel/render.ts';
|
|
21
|
+
|
|
22
|
+
function makeRenderer(opts?: {
|
|
23
|
+
clock?: RenderClock;
|
|
24
|
+
policySink?: (r: PolicyViolationRecord) => void;
|
|
25
|
+
}): ContextRenderer {
|
|
26
|
+
return new ContextRenderer({
|
|
27
|
+
system: '你是单流协议 agent。',
|
|
28
|
+
protocol: 'tf-write / tf-read / tf-bash / tf-peek / tf-final 协议说明。',
|
|
29
|
+
toolSchemas: '{"tf-write": {"path": "string", "content": "string"}}',
|
|
30
|
+
invariants: '不变量 I1:不无来源推断;I2:节点必须溯源。',
|
|
31
|
+
...(opts?.clock ? { clock: opts.clock } : {}),
|
|
32
|
+
...(opts?.policySink ? { policySink: opts.policySink } : {}),
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
class FakeClock implements RenderClock {
|
|
37
|
+
t: number;
|
|
38
|
+
constructor(t = 0) {
|
|
39
|
+
this.t = t;
|
|
40
|
+
}
|
|
41
|
+
now(): number {
|
|
42
|
+
return this.t;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const m = (role: RenderMessage['role'], content: string): RenderMessage => ({
|
|
47
|
+
role,
|
|
48
|
+
content,
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// ---------------------------------------------------------------------------
|
|
52
|
+
// assertPrefixStable / renderHash(独立校验器)
|
|
53
|
+
// ---------------------------------------------------------------------------
|
|
54
|
+
|
|
55
|
+
test('assertPrefixStable:逐字节相等通过;next 更长(追加)通过', () => {
|
|
56
|
+
const prev = [m('system', 'S'), m('user', 'U1')];
|
|
57
|
+
assert.deepEqual(assertPrefixStable(prev, prev), { prefixLength: 2 });
|
|
58
|
+
assert.deepEqual(
|
|
59
|
+
assertPrefixStable(prev, [m('system', 'S'), m('user', 'U1'), m('assistant', 'A1')]),
|
|
60
|
+
{ prefixLength: 3 },
|
|
61
|
+
);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test('assertPrefixStable:中间内容被改 → PrefixBrokenError(含 index),不静默修复', () => {
|
|
65
|
+
const prev = [m('system', 'S'), m('user', 'U1'), m('assistant', 'A1')];
|
|
66
|
+
const next = [m('system', 'S'), m('user', 'U1-EDITED'), m('assistant', 'A1')];
|
|
67
|
+
assert.throws(
|
|
68
|
+
() => assertPrefixStable(prev, next),
|
|
69
|
+
(err: unknown) => {
|
|
70
|
+
assert.ok(err instanceof PrefixBrokenError);
|
|
71
|
+
assert.equal(err.index, 1);
|
|
72
|
+
assert.match(err.message, /逐字节不一致/);
|
|
73
|
+
return true;
|
|
74
|
+
},
|
|
75
|
+
);
|
|
76
|
+
// role 变化同样抛
|
|
77
|
+
assert.throws(
|
|
78
|
+
() => assertPrefixStable(prev, [m('system', 'S'), m('tool', 'U1'), m('assistant', 'A1')]),
|
|
79
|
+
PrefixBrokenError,
|
|
80
|
+
);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test('assertPrefixStable:稳定段收缩默认抛错;显式 allowTailDrop 且确为严格前缀时通过', () => {
|
|
84
|
+
const prev = [m('system', 'S'), m('user', 'U1'), m('assistant', 'A1')];
|
|
85
|
+
const shorter = [m('system', 'S'), m('user', 'U1')];
|
|
86
|
+
assert.throws(() => assertPrefixStable(prev, shorter), /收缩/);
|
|
87
|
+
// 整块尾部丢弃:next 是 prev 的字节前缀 → allowTailDrop 下允许,prefixLength = next.length
|
|
88
|
+
assert.deepEqual(assertPrefixStable(prev, shorter, { allowTailDrop: true }), {
|
|
89
|
+
prefixLength: 2,
|
|
90
|
+
});
|
|
91
|
+
// allowTailDrop 但保留部分也被改 → 仍然抛(只放行尾部整块丢弃)
|
|
92
|
+
const edited = [m('system', 'S-EDITED'), m('user', 'U1')];
|
|
93
|
+
assert.throws(() => assertPrefixStable(edited, prev, { allowTailDrop: true }), PrefixBrokenError);
|
|
94
|
+
// next 比 prev 长(追加)本来就允许
|
|
95
|
+
assert.deepEqual(assertPrefixStable(shorter, prev), { prefixLength: 3 });
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test('renderHash:确定性(同输入同 hash);内容/角色/顺序差异都改变 hash', () => {
|
|
99
|
+
const a = [m('system', 'S'), m('user', 'U')];
|
|
100
|
+
const b = [m('system', 'S'), m('user', 'U')];
|
|
101
|
+
assert.equal(renderHash(a), renderHash(b));
|
|
102
|
+
assert.notEqual(renderHash(a), renderHash([m('system', 'S'), m('user', 'U2')]));
|
|
103
|
+
assert.notEqual(renderHash(a), renderHash([m('user', 'U'), m('system', 'S')]));
|
|
104
|
+
assert.notEqual(renderHash(a), renderHash([m('assistant', 'U'), m('user', 'S')]));
|
|
105
|
+
// hash 是 hex sha256
|
|
106
|
+
assert.match(renderHash(a), /^[0-9a-f]{64}$/);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
// ---------------------------------------------------------------------------
|
|
110
|
+
// 三段式装配
|
|
111
|
+
// ---------------------------------------------------------------------------
|
|
112
|
+
|
|
113
|
+
test('render:稳定前缀是单条 system 消息,构造期冻结,无写入路径', () => {
|
|
114
|
+
const r = makeRenderer();
|
|
115
|
+
const prefix = r.prefixMessages;
|
|
116
|
+
assert.equal(prefix.length, 1);
|
|
117
|
+
assert.equal(prefix[0].role, 'system');
|
|
118
|
+
assert.match(prefix[0].content, /单流协议/);
|
|
119
|
+
assert.match(prefix[0].content, /tf-write/);
|
|
120
|
+
assert.match(prefix[0].content, /I2/);
|
|
121
|
+
// 尝试改写前缀:对象被 Object.freeze,严格模式下赋值抛 TypeError,内容不变
|
|
122
|
+
const first = r.render();
|
|
123
|
+
assert.throws(() => {
|
|
124
|
+
(first[0] as { content: string }).content = 'HACKED';
|
|
125
|
+
}, TypeError);
|
|
126
|
+
assert.match(r.render()[0].content, /单流协议/);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
test('render:易变尾每请求整块重建,旧尾自动丢弃', () => {
|
|
130
|
+
const r = makeRenderer();
|
|
131
|
+
r.setTail([{ content: '高增益观测:第 1 步结果' }]);
|
|
132
|
+
const req1 = r.render();
|
|
133
|
+
assert.match(req1[req1.length - 1].content, /第 1 步/);
|
|
134
|
+
|
|
135
|
+
r.setTail([{ content: '高增益观测:第 2 步结果' }]);
|
|
136
|
+
const req2 = r.render();
|
|
137
|
+
assert.match(req2[req2.length - 1].content, /第 2 步/);
|
|
138
|
+
// 旧尾整块丢弃,不在新请求里
|
|
139
|
+
for (const msg of req2) assert.doesNotMatch(msg.content, /第 1 步/);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
test('render:clearTail 丢弃整个易变尾', () => {
|
|
143
|
+
const r = makeRenderer();
|
|
144
|
+
r.setTail([{ content: 'tail' }]);
|
|
145
|
+
assert.equal(r.render().length, 2);
|
|
146
|
+
r.clearTail();
|
|
147
|
+
assert.equal(r.render().length, 1);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
test('appendHistory:追加进追加区;system 消息被拒绝(system 属于稳定前缀)', () => {
|
|
151
|
+
const r = makeRenderer();
|
|
152
|
+
r.appendHistory(m('assistant', 'A1'));
|
|
153
|
+
r.appendHistory(m('user', 'U2'));
|
|
154
|
+
const msgs = r.render();
|
|
155
|
+
assert.equal(msgs.length, 3); // prefix + A1 + U2(易变尾为空)
|
|
156
|
+
assert.equal(msgs[1].content, 'A1');
|
|
157
|
+
assert.equal(msgs[2].content, 'U2');
|
|
158
|
+
assert.throws(() => r.appendHistory(m('system', 'X')), /稳定前缀/);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
// ---------------------------------------------------------------------------
|
|
162
|
+
// O3:directoryDelta 差分注入(只追加进追加区)
|
|
163
|
+
// ---------------------------------------------------------------------------
|
|
164
|
+
|
|
165
|
+
test('appendHandleDelta:非空增量追加进追加区;空增量不产生块(前缀字节不变)', () => {
|
|
166
|
+
const r = makeRenderer();
|
|
167
|
+
const stableBefore = r.stableHash();
|
|
168
|
+
|
|
169
|
+
const appended = r.appendHandleDelta({
|
|
170
|
+
added: [{ handle: 'file:src/app.ts@v1', note: '新建' }],
|
|
171
|
+
changed: [{ handle: 'file:src/lib.ts@v3' }],
|
|
172
|
+
stale: [{ handle: 'obs:tf-read:c12@v1' }],
|
|
173
|
+
});
|
|
174
|
+
assert.equal(appended, true);
|
|
175
|
+
const deltaMsg = r.stableMessages()[1];
|
|
176
|
+
assert.match(deltaMsg.content, /\+ file:src\/app\.ts@v1 — 新建/);
|
|
177
|
+
assert.match(deltaMsg.content, /~ file:src\/lib\.ts@v3/);
|
|
178
|
+
assert.match(deltaMsg.content, /- obs:tf-read:c12@v1(已失效,tf-peek 将拒绝)/);
|
|
179
|
+
|
|
180
|
+
// 空增量:不追加
|
|
181
|
+
assert.equal(
|
|
182
|
+
r.appendHandleDelta({ added: [], changed: [], stale: [] }),
|
|
183
|
+
false,
|
|
184
|
+
);
|
|
185
|
+
assert.equal(r.stableMessages().length, 2);
|
|
186
|
+
// 增量块进入稳定段后字节冻结
|
|
187
|
+
assert.notEqual(r.stableHash(), stableBefore);
|
|
188
|
+
const frozen = r.stableMessages()[1].content;
|
|
189
|
+
r.render();
|
|
190
|
+
r.render();
|
|
191
|
+
assert.equal(r.stableMessages()[1].content, frozen);
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
test('O3 集成形态:连续多回合 directoryDelta 只追加,历史增量块字节不变', () => {
|
|
195
|
+
const r = makeRenderer();
|
|
196
|
+
const stables: RenderMessage[][] = [];
|
|
197
|
+
const deltas: HandleDirectoryDelta[] = [
|
|
198
|
+
{ added: [{ handle: 'file:a.ts@v1' }], changed: [], stale: [] },
|
|
199
|
+
{ added: [{ handle: 'file:b.ts@v1' }], changed: [{ handle: 'file:a.ts@v2' }], stale: [] },
|
|
200
|
+
{ added: [], changed: [], stale: [{ handle: 'file:a.ts@v2' }] },
|
|
201
|
+
];
|
|
202
|
+
for (const d of deltas) {
|
|
203
|
+
r.appendHandleDelta(d);
|
|
204
|
+
r.setTail([{ content: `第 ${stables.length} 步观测` }]);
|
|
205
|
+
const stable = r.stableMessages();
|
|
206
|
+
if (stables.length > 0) {
|
|
207
|
+
// 前缀逐字节单调(O6 校验器直接断言)
|
|
208
|
+
assertPrefixStable(stables[stables.length - 1], stable);
|
|
209
|
+
}
|
|
210
|
+
stables.push(stable);
|
|
211
|
+
r.render();
|
|
212
|
+
}
|
|
213
|
+
// 全部三列内容都进了追加区,且前一次的增量块仍字节不变
|
|
214
|
+
const all = r.stableMessages().map((x) => x.content).join('\n');
|
|
215
|
+
assert.match(all, /file:a\.ts@v1/);
|
|
216
|
+
assert.match(all, /file:b\.ts@v1/);
|
|
217
|
+
assert.match(all, /file:a\.ts@v2/);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
// ---------------------------------------------------------------------------
|
|
221
|
+
// O4:freezeDynamics —— 动态内容归易变尾或回合冻结,稳定前缀禁入
|
|
222
|
+
// ---------------------------------------------------------------------------
|
|
223
|
+
|
|
224
|
+
test('O4 volatile-tail:时间戳逐请求变化只进易变尾;10 步内稳定前缀 hash 恒定(单调)', () => {
|
|
225
|
+
const r = makeRenderer();
|
|
226
|
+
const clock = new FakeClock();
|
|
227
|
+
const prefixHashes: string[] = [];
|
|
228
|
+
for (let step = 1; step <= 10; step++) {
|
|
229
|
+
clock.t = step * 1_000;
|
|
230
|
+
r.freezeDynamics({ now: new Date(clock.t).toISOString() }, 'volatile-tail');
|
|
231
|
+
r.setTail([{ content: `step ${step} 观测` }]);
|
|
232
|
+
const msgs = r.render();
|
|
233
|
+
// 稳定前缀(system)不含任何一步的时间戳值
|
|
234
|
+
assert.doesNotMatch(msgs[0].content, /T\d{2}:/);
|
|
235
|
+
// 动态值进了易变尾的动态上下文块(在 setTail 块之前)
|
|
236
|
+
const dyn = msgs.find((x) => x.content.includes('动态上下文(易变尾'));
|
|
237
|
+
assert.ok(dyn, '易变尾里应有动态上下文块');
|
|
238
|
+
assert.ok(dyn.content.includes(new Date(clock.t).toISOString()));
|
|
239
|
+
// setTail 块仍在最后
|
|
240
|
+
assert.match(msgs[msgs.length - 1].content, new RegExp(`step ${step}`));
|
|
241
|
+
prefixHashes.push(renderHash(r.prefixMessages));
|
|
242
|
+
}
|
|
243
|
+
// 10 步前缀 hash 恒定(比"单调不降"更强的断言)
|
|
244
|
+
assert.deepEqual(prefixHashes, prefixHashes.map(() => prefixHashes[0]));
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
test('O4 turn-freeze:动态值按回合冻结进追加区,此后字节不变', () => {
|
|
248
|
+
const r = makeRenderer();
|
|
249
|
+
const clock = new FakeClock();
|
|
250
|
+
clock.t = 42;
|
|
251
|
+
r.freezeDynamics({ snapshot: 'turn-42-cwd' }, 'turn-freeze');
|
|
252
|
+
const frozenBlock = r.stableMessages()[1].content;
|
|
253
|
+
assert.match(frozenBlock, /turn-42-cwd/);
|
|
254
|
+
// 后续回合动态值变了,冻结块字节不变
|
|
255
|
+
clock.t = 43;
|
|
256
|
+
r.freezeDynamics({ snapshot: 'turn-43-cwd' }, 'turn-freeze');
|
|
257
|
+
r.appendHistory(m('assistant', 'A'));
|
|
258
|
+
const msgs = r.render();
|
|
259
|
+
assert.equal(msgs[1].content, frozenBlock); // 字节相等
|
|
260
|
+
assert.match(msgs[2].content, /turn-43-cwd/);
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
test('O4:稳定前缀中已出现的动态值 → DynamicInPrefixError(稳定前缀禁入动态字段)', () => {
|
|
264
|
+
const r = new ContextRenderer({
|
|
265
|
+
system: 'cwd=/tmp/work',
|
|
266
|
+
protocol: 'p',
|
|
267
|
+
toolSchemas: 't',
|
|
268
|
+
invariants: 'i',
|
|
269
|
+
});
|
|
270
|
+
assert.throws(
|
|
271
|
+
() => r.freezeDynamics({ cwd: '/tmp/work' }, 'volatile-tail'),
|
|
272
|
+
DynamicInPrefixError,
|
|
273
|
+
);
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
// ---------------------------------------------------------------------------
|
|
277
|
+
// O6:preflight fail-closed + 20 步 renderHash 前缀单调
|
|
278
|
+
// ---------------------------------------------------------------------------
|
|
279
|
+
|
|
280
|
+
test('O6 preflight:稳定段被破坏时 render() 抛 PrefixBrokenError 拒绝发送(fail-closed)', () => {
|
|
281
|
+
const r = makeRenderer();
|
|
282
|
+
r.render();
|
|
283
|
+
// 直接篡改内部追加区是不可能的(私有);用校验器模拟被破坏的稳定段:
|
|
284
|
+
const prevStable = r.stableMessages();
|
|
285
|
+
const broken = [m('system', 'S-EDITED'), m('user', 'x')];
|
|
286
|
+
assert.throws(() => assertPrefixStable(prevStable, broken), PrefixBrokenError);
|
|
287
|
+
// 正常路径继续可用
|
|
288
|
+
r.appendHistory(m('assistant', 'A'));
|
|
289
|
+
const ok = r.render();
|
|
290
|
+
assert.match(ok[1].content, /^A$/);
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
test('O6/O4:20 步请求序列,renderHash 稳定段严格单调(逐字节追加链)', () => {
|
|
294
|
+
const r = makeRenderer();
|
|
295
|
+
const clock = new FakeClock();
|
|
296
|
+
const hashes: string[] = [];
|
|
297
|
+
const stables: RenderMessage[][] = [];
|
|
298
|
+
let prevTailMarker: string | null = null;
|
|
299
|
+
for (let step = 1; step <= 20; step++) {
|
|
300
|
+
// 每步:历史追加 + 每 3 步一次目录增量 + 动态时间戳进易变尾 + 高增益观测进易变尾
|
|
301
|
+
r.appendHistory(m('assistant', `step-${step} response`));
|
|
302
|
+
if (step % 3 === 0) {
|
|
303
|
+
r.appendHandleDelta({
|
|
304
|
+
added: [{ handle: `file:mod${step}.ts@v1` }],
|
|
305
|
+
changed: [],
|
|
306
|
+
stale: step > 3 ? [{ handle: `file:mod${step - 3}.ts@v1` }] : [],
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
clock.t = step * 500;
|
|
310
|
+
r.freezeDynamics({ now: new Date(clock.t).toISOString() }, 'volatile-tail');
|
|
311
|
+
r.setTail([
|
|
312
|
+
{ content: `高增益观测 step-${step}:tf-peek 结果(易变尾,整块丢弃)` },
|
|
313
|
+
]);
|
|
314
|
+
|
|
315
|
+
const stable = r.stableMessages();
|
|
316
|
+
if (stables.length > 0) {
|
|
317
|
+
// O6 校验器:上一请求稳定段必须是本请求稳定段的逐字节前缀
|
|
318
|
+
assertPrefixStable(stables[stables.length - 1], stable);
|
|
319
|
+
}
|
|
320
|
+
stables.push(stable);
|
|
321
|
+
hashes.push(renderHash(stable));
|
|
322
|
+
const full = r.render();
|
|
323
|
+
// 易变尾包含本步观测
|
|
324
|
+
assert.match(full[full.length - 1].content, new RegExp(`观测 step-${step}`));
|
|
325
|
+
// 上一请求的易变尾已整块丢弃,不在本请求任何位置
|
|
326
|
+
if (prevTailMarker !== null) {
|
|
327
|
+
for (const msg of full) assert.ok(!msg.content.includes(prevTailMarker));
|
|
328
|
+
}
|
|
329
|
+
prevTailMarker = `观测 step-${step}:tf-peek`;
|
|
330
|
+
}
|
|
331
|
+
// renderHash 序列:20 步严格递变(每步都有追加 → 单调增长,无一步停滞或回退)
|
|
332
|
+
assert.equal(hashes.length, 20);
|
|
333
|
+
for (let i = 1; i < hashes.length; i++) {
|
|
334
|
+
assert.notEqual(hashes[i], hashes[i - 1], `第 ${i + 1} 步稳定段没有增长`);
|
|
335
|
+
}
|
|
336
|
+
// 前缀(system 消息)20 步字节不变
|
|
337
|
+
const prefixContents = stables.map((s) => s[0].content);
|
|
338
|
+
assert.deepEqual(prefixContents, prefixContents.map(() => prefixContents[0]));
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
// ---------------------------------------------------------------------------
|
|
342
|
+
// 压缩历史:拒绝 + 降级尾部截断 + 记录
|
|
343
|
+
// ---------------------------------------------------------------------------
|
|
344
|
+
|
|
345
|
+
test('压缩历史请求:拒绝 + 降级为整块尾部截断 + policyLog/外部 sink 双记录', () => {
|
|
346
|
+
const sinkRecords: PolicyViolationRecord[] = [];
|
|
347
|
+
const clock = new FakeClock(777);
|
|
348
|
+
const r = makeRenderer({ clock, policySink: (x) => sinkRecords.push(x) });
|
|
349
|
+
for (let i = 1; i <= 5; i++) r.appendHistory(m('assistant', `A${i}`));
|
|
350
|
+
r.render();
|
|
351
|
+
const before = r.stableMessages();
|
|
352
|
+
|
|
353
|
+
const rec = r.requestHistoryCompression({
|
|
354
|
+
request: '请把前面的历史压缩成摘要',
|
|
355
|
+
fallbackTailDrop: 2,
|
|
356
|
+
});
|
|
357
|
+
assert.equal(rec.accepted, false);
|
|
358
|
+
assert.equal(rec.degradedTo, 'tail-truncation');
|
|
359
|
+
assert.equal(rec.droppedBlocks, 2);
|
|
360
|
+
assert.equal(rec.at, 777);
|
|
361
|
+
// 双记录:内部台账 + 外部 sink
|
|
362
|
+
assert.equal(r.policyLog.length, 1);
|
|
363
|
+
assert.equal(sinkRecords.length, 1);
|
|
364
|
+
assert.deepEqual(r.policyLog[0], rec);
|
|
365
|
+
// 保留部分逐字节不变,只有末尾整块被丢弃
|
|
366
|
+
const after = r.stableMessages();
|
|
367
|
+
assert.equal(after.length, before.length - 2);
|
|
368
|
+
assert.equal(after[after.length - 1].content, 'A3');
|
|
369
|
+
assert.deepEqual(assertPrefixStable(after, before, { allowTailDrop: true }), {
|
|
370
|
+
prefixLength: before.length,
|
|
371
|
+
});
|
|
372
|
+
// 截断后可以继续正常渲染(基线已显式推进,非静默)
|
|
373
|
+
r.appendHistory(m('assistant', 'A6'));
|
|
374
|
+
const msgs = r.render();
|
|
375
|
+
assert.equal(msgs[msgs.length - 1].content, 'A6'); // 易变尾为空,末条即新历史
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
test('压缩历史请求:不指定降级 → 只拒绝不丢弃;截断超过现有块数时按实际上限截断', () => {
|
|
379
|
+
const r = makeRenderer();
|
|
380
|
+
r.appendHistory(m('assistant', 'A1'));
|
|
381
|
+
r.render();
|
|
382
|
+
const rec1 = r.requestHistoryCompression({ request: '压缩一下' });
|
|
383
|
+
assert.equal(rec1.degradedTo, 'none');
|
|
384
|
+
assert.equal(rec1.droppedBlocks, 0);
|
|
385
|
+
assert.equal(r.stableMessages().length, 2);
|
|
386
|
+
|
|
387
|
+
const rec2 = r.requestHistoryCompression({ request: '再压缩', fallbackTailDrop: 99 });
|
|
388
|
+
assert.equal(rec2.droppedBlocks, 1); // 只有 1 块可丢
|
|
389
|
+
assert.equal(r.stableMessages().length, 1); // 只剩前缀
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
test('truncateAppendTail:0 与负数不丢弃;被保留部分逐字节验证', () => {
|
|
393
|
+
const r = makeRenderer();
|
|
394
|
+
r.appendHistory(m('assistant', 'A1'));
|
|
395
|
+
r.appendHistory(m('assistant', 'A2'));
|
|
396
|
+
r.render();
|
|
397
|
+
assert.equal(r.truncateAppendTail(0), 0);
|
|
398
|
+
assert.equal(r.truncateAppendTail(-3), 0);
|
|
399
|
+
assert.equal(r.stableMessages().length, 3);
|
|
400
|
+
assert.equal(r.truncateAppendTail(1), 1);
|
|
401
|
+
const stable = r.stableMessages();
|
|
402
|
+
assert.equal(stable.length, 2);
|
|
403
|
+
assert.equal(stable[1].content, 'A1'); // 只丢了末尾的 A2
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
test('合规替代路径:模型"需要旧信息"时只能整块丢弃尾部或 tf-peek,前缀始终单调', () => {
|
|
407
|
+
const r = makeRenderer();
|
|
408
|
+
for (let i = 1; i <= 6; i++) r.appendHistory(m('assistant', `A${i}`));
|
|
409
|
+
r.render();
|
|
410
|
+
const beforeHash = renderHash(r.prefixMessages);
|
|
411
|
+
r.requestHistoryCompression({ request: 'summarize please', fallbackTailDrop: 4 });
|
|
412
|
+
r.appendHistory(m('assistant', 'A-new'));
|
|
413
|
+
r.render();
|
|
414
|
+
// 前缀 hash 不变,历史没有任何中间改写
|
|
415
|
+
assert.equal(renderHash(r.prefixMessages), beforeHash);
|
|
416
|
+
const contents = r.stableMessages().map((x) => x.content);
|
|
417
|
+
assert.deepEqual(contents.slice(1), ['A1', 'A2', 'A-new']);
|
|
418
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// test/s2-install-check.test.ts —— S2 安装前置校验(误装 100% 被拒;dry-run 可读)
|
|
2
|
+
//
|
|
3
|
+
// 直接跑 scripts/install-check.mjs(子进程,退出码判定):
|
|
4
|
+
// - web / desktop / headless(既有 profile)一律拒绝(exit 2)
|
|
5
|
+
// - stream / stream-headless 允许(exit 0)且 dry-run 打印装配面
|
|
6
|
+
// - 无 --profile = 用法错误(exit 3)
|
|
7
|
+
// 只读检查:脚本本身不做任何写操作(S2 红线:校验发生在写入之前)。
|
|
8
|
+
|
|
9
|
+
import { describe, it } from 'node:test';
|
|
10
|
+
import assert from 'node:assert/strict';
|
|
11
|
+
import { spawnSync } from 'node:child_process';
|
|
12
|
+
import { join } from 'node:path';
|
|
13
|
+
|
|
14
|
+
const script = join(import.meta.dirname, '..', 'scripts', 'install-check.mjs');
|
|
15
|
+
|
|
16
|
+
function run(args: string[]): { code: number; out: string } {
|
|
17
|
+
const r = spawnSync(process.execPath, [script, ...args], { encoding: 'utf8' });
|
|
18
|
+
return { code: r.status ?? -1, out: `${r.stdout ?? ''}${r.stderr ?? ''}` };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
describe('S2:安装前置校验', () => {
|
|
22
|
+
it('V7. 既有 profile(web/desktop/headless)100% 被拒,拒绝信息含目标 profile 与允许列表', () => {
|
|
23
|
+
for (const profile of ['web', 'desktop', 'headless']) {
|
|
24
|
+
const r = run(['--profile', profile]);
|
|
25
|
+
assert.equal(r.code, 2, `profile=${profile} 必须拒绝`);
|
|
26
|
+
assert.ok(r.out.includes(`"${profile}"`), `拒绝信息应含目标 profile 名:${r.out.slice(0, 200)}`);
|
|
27
|
+
assert.ok(r.out.includes('stream'), '拒绝信息应给出允许列表');
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('V7b. 专用 profile 允许且 dry-run 可读(目标/patch/entry)', () => {
|
|
32
|
+
const r = run(['--profile', 'stream', '--dry-run']);
|
|
33
|
+
assert.equal(r.code, 0);
|
|
34
|
+
assert.ok(r.out.includes('stream'), '目标 profile 应打印');
|
|
35
|
+
assert.ok(r.out.includes('cordis.patch.yml'), '应列出将应用的 patch');
|
|
36
|
+
assert.ok(r.out.includes('stream-agent'), '应列出受影响 entry');
|
|
37
|
+
const r2 = run(['--profile', 'stream-headless', '--dry-run']);
|
|
38
|
+
assert.equal(r2.code, 0);
|
|
39
|
+
assert.ok(r2.out.includes('不引入 preset'), 'headless 变体应说明不引入 preset');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('V7c. 无 --profile = 用法错误(exit 3)', () => {
|
|
43
|
+
const r = run([]);
|
|
44
|
+
assert.equal(r.code, 3);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "3-file-basic",
|
|
3
|
+
"match": { "promptIncludes": "请写三个文件" },
|
|
4
|
+
"chunking": { "charsPerChunk": 0, "delayMs": 0 },
|
|
5
|
+
"steps": [
|
|
6
|
+
{ "type": "text", "text": "分析任务:需要写三个文件,逐个写完即可。\n" },
|
|
7
|
+
{ "type": "commands", "commands": ["tf-write a.txt \"A\"", "tf-write b.txt \"B\"", "tf-write c.txt \"C\""] },
|
|
8
|
+
{ "type": "waitTools", "count": 3, "timeoutMs": 5000 },
|
|
9
|
+
{ "type": "text", "text": "三个文件都已写入,任务完成。\n" },
|
|
10
|
+
{ "type": "commands", "commands": ["tf-final"] },
|
|
11
|
+
{ "type": "finish", "reason": "stop" }
|
|
12
|
+
]
|
|
13
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "5-file-basic",
|
|
3
|
+
"match": { "promptIncludes": "请写五个文件" },
|
|
4
|
+
"chunking": { "charsPerChunk": 0, "delayMs": 0 },
|
|
5
|
+
"steps": [
|
|
6
|
+
{ "type": "text", "text": "任务:写五个文件,逐个写完。\n" },
|
|
7
|
+
{
|
|
8
|
+
"type": "commands",
|
|
9
|
+
"commands": [
|
|
10
|
+
"<tf-write path=\"f1.txt\" id=\"w1\">内容一</tf-write>",
|
|
11
|
+
"<tf-write path=\"f2.txt\" id=\"w2\">内容二</tf-write>",
|
|
12
|
+
"<tf-write path=\"f3.txt\" id=\"w3\">内容三</tf-write>",
|
|
13
|
+
"<tf-write path=\"f4.txt\" id=\"w4\">内容四</tf-write>",
|
|
14
|
+
"<tf-write path=\"f5.txt\" id=\"w5\">内容五</tf-write>"
|
|
15
|
+
]
|
|
16
|
+
},
|
|
17
|
+
{ "type": "waitTools", "count": 5, "timeoutMs": 5000 },
|
|
18
|
+
{ "type": "text", "text": "五个文件全部写入完成。\n" },
|
|
19
|
+
{ "type": "commands", "commands": ["<tf-final id=\"f1\" summary=\"五个文件已写\"/>"] },
|
|
20
|
+
{ "type": "finish", "reason": "stop" }
|
|
21
|
+
]
|
|
22
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "degraded-final",
|
|
3
|
+
"match": { "promptIncludes": "tf-stream:degraded" },
|
|
4
|
+
"chunking": { "charsPerChunk": 0, "delayMs": 0 },
|
|
5
|
+
"steps": [
|
|
6
|
+
{ "type": "text", "text": "预算告急,按台账收尾。\n" },
|
|
7
|
+
{ "type": "commands", "commands": ["<tf-final id=\"fd\" summary=\"降级交付\"/>"] },
|
|
8
|
+
{ "type": "finish", "reason": "stop" }
|
|
9
|
+
]
|
|
10
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "fault-abort-xml",
|
|
3
|
+
"match": { "promptIncludes": "故障注入:流中断" },
|
|
4
|
+
"chunking": { "charsPerChunk": 0, "delayMs": 0 },
|
|
5
|
+
"steps": [
|
|
6
|
+
{ "type": "text", "text": "开始写文件,然后流会突然中断。\n" },
|
|
7
|
+
{ "type": "commands", "commands": ["<tf-write path=\"a.txt\" id=\"wa\">A</tf-write>"] },
|
|
8
|
+
{ "type": "waitTools", "count": 1, "timeoutMs": 5000 },
|
|
9
|
+
{ "type": "fail", "mode": "midstream_abort" }
|
|
10
|
+
]
|
|
11
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "fault-malformed-command",
|
|
3
|
+
"match": { "promptIncludes": "故障注入:畸形命令" },
|
|
4
|
+
"chunking": { "charsPerChunk": 0, "delayMs": 0 },
|
|
5
|
+
"steps": [
|
|
6
|
+
{ "type": "text", "text": "下面一行是故意写坏的协议命令。\n" },
|
|
7
|
+
{ "type": "fail", "mode": "malformed_command", "text": "tf-frobnicate x y z\ntf-write 没有引号的内容\n" },
|
|
8
|
+
{ "type": "text", "text": "继续正常收尾。\n" },
|
|
9
|
+
{ "type": "commands", "commands": ["tf-final"] },
|
|
10
|
+
{ "type": "finish", "reason": "stop" }
|
|
11
|
+
]
|
|
12
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "fault-midstream-abort",
|
|
3
|
+
"match": { "promptIncludes": "故障注入:流中断" },
|
|
4
|
+
"chunking": { "charsPerChunk": 0, "delayMs": 0 },
|
|
5
|
+
"steps": [
|
|
6
|
+
{ "type": "text", "text": "开始写文件,然后流会突然中断。\n" },
|
|
7
|
+
{ "type": "commands", "commands": ["tf-write a.txt \"A\""] },
|
|
8
|
+
{ "type": "waitTools", "count": 1, "timeoutMs": 5000 },
|
|
9
|
+
{ "type": "fail", "mode": "midstream_abort" }
|
|
10
|
+
]
|
|
11
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "fault-saturating-output",
|
|
3
|
+
"match": { "promptIncludes": "故障注入:饱和输出" },
|
|
4
|
+
"chunking": { "charsPerChunk": 512, "delayMs": 0 },
|
|
5
|
+
"steps": [
|
|
6
|
+
{ "type": "text", "text": "开始无限制输出,直到消费方按预算掐断。\n" },
|
|
7
|
+
{ "type": "fail", "mode": "saturating_output", "maxChars": 4000000 }
|
|
8
|
+
]
|
|
9
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "peek-first",
|
|
3
|
+
"match": { "promptIncludes": "句柄演练" },
|
|
4
|
+
"chunking": { "charsPerChunk": 0, "delayMs": 0 },
|
|
5
|
+
"steps": [
|
|
6
|
+
{ "type": "text", "text": "先读 big.txt,看骨架。\n" },
|
|
7
|
+
{ "type": "commands", "commands": ["<tf-read path=\"big.txt\" id=\"r1\"/>"] },
|
|
8
|
+
{ "type": "waitTools", "count": 1, "timeoutMs": 5000 },
|
|
9
|
+
{ "type": "finish", "reason": "stop" }
|
|
10
|
+
]
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "peek-second",
|
|
3
|
+
"match": { "promptIncludes": "tf-stream:observation" },
|
|
4
|
+
"chunking": { "charsPerChunk": 0, "delayMs": 0 },
|
|
5
|
+
"steps": [
|
|
6
|
+
{ "type": "text", "text": "看到骨架了,取回第 1-2 行细节。\n" },
|
|
7
|
+
{ "type": "commands", "commands": ["<tf-peek handle=\"obs:read:r1@v1\" from_line=\"1\" to_line=\"2\" id=\"p1\"/>"] },
|
|
8
|
+
{ "type": "waitTools", "count": 2, "timeoutMs": 5000 },
|
|
9
|
+
{ "type": "finish", "reason": "stop" }
|
|
10
|
+
]
|
|
11
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "peek-third",
|
|
3
|
+
"match": { "promptIncludes": "tf-stream:peek" },
|
|
4
|
+
"chunking": { "charsPerChunk": 0, "delayMs": 0 },
|
|
5
|
+
"steps": [
|
|
6
|
+
{ "type": "text", "text": "细节到手,收尾。\n" },
|
|
7
|
+
{ "type": "commands", "commands": ["<tf-final id=\"fp\" summary=\"句柄演练完成\"/>"] },
|
|
8
|
+
{ "type": "finish", "reason": "stop" }
|
|
9
|
+
]
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "recover-final",
|
|
3
|
+
"match": { "promptIncludes": "tf-stream:nudge" },
|
|
4
|
+
"chunking": { "charsPerChunk": 0, "delayMs": 0 },
|
|
5
|
+
"steps": [
|
|
6
|
+
{ "type": "text", "text": "收到提醒,任务已完成,收尾。\n" },
|
|
7
|
+
{ "type": "commands", "commands": ["<tf-final id=\"fr\" summary=\"收尾完成\"/>"] },
|
|
8
|
+
{ "type": "finish", "reason": "stop" }
|
|
9
|
+
]
|
|
10
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "reroute-first",
|
|
3
|
+
"match": { "promptIncludes": "改道演练" },
|
|
4
|
+
"chunking": { "charsPerChunk": 0, "delayMs": 0 },
|
|
5
|
+
"steps": [
|
|
6
|
+
{ "type": "text", "text": "开始写文件,其中一个目标会失败。\n" },
|
|
7
|
+
{
|
|
8
|
+
"type": "commands",
|
|
9
|
+
"commands": [
|
|
10
|
+
"<tf-write path=\"a.txt\" id=\"wa\">A</tf-write>",
|
|
11
|
+
"<tf-write path=\"fail.txt\" id=\"wf\">F</tf-write>"
|
|
12
|
+
]
|
|
13
|
+
},
|
|
14
|
+
{ "type": "waitTools", "count": 2, "timeoutMs": 5000 },
|
|
15
|
+
{ "type": "finish", "reason": "stop" }
|
|
16
|
+
]
|
|
17
|
+
}
|