@animalabs/agent-framework 0.8.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/agent.d.ts +11 -1
- package/dist/src/agent.d.ts.map +1 -1
- package/dist/src/agent.js +33 -3
- package/dist/src/agent.js.map +1 -1
- package/dist/src/framework.d.ts +184 -18
- package/dist/src/framework.d.ts.map +1 -1
- package/dist/src/framework.js +1323 -246
- package/dist/src/framework.js.map +1 -1
- package/dist/src/gate/event-gate.d.ts +73 -7
- package/dist/src/gate/event-gate.d.ts.map +1 -1
- package/dist/src/gate/event-gate.js +399 -22
- package/dist/src/gate/event-gate.js.map +1 -1
- package/dist/src/gate/types.d.ts +56 -0
- package/dist/src/gate/types.d.ts.map +1 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/mcpl/capability-grant.d.ts +115 -0
- package/dist/src/mcpl/capability-grant.d.ts.map +1 -0
- package/dist/src/mcpl/capability-grant.js +291 -0
- package/dist/src/mcpl/capability-grant.js.map +1 -0
- package/dist/src/mcpl/capability-mask.d.ts +51 -0
- package/dist/src/mcpl/capability-mask.d.ts.map +1 -0
- package/dist/src/mcpl/capability-mask.js +190 -0
- package/dist/src/mcpl/capability-mask.js.map +1 -0
- package/dist/src/mcpl/channel-registry.d.ts +3 -1
- package/dist/src/mcpl/channel-registry.d.ts.map +1 -1
- package/dist/src/mcpl/channel-registry.js +163 -36
- package/dist/src/mcpl/channel-registry.js.map +1 -1
- package/dist/src/mcpl/checkpoint-manager.d.ts +8 -3
- package/dist/src/mcpl/checkpoint-manager.d.ts.map +1 -1
- package/dist/src/mcpl/checkpoint-manager.js +28 -8
- package/dist/src/mcpl/checkpoint-manager.js.map +1 -1
- package/dist/src/mcpl/errors.d.ts +6 -0
- package/dist/src/mcpl/errors.d.ts.map +1 -1
- package/dist/src/mcpl/errors.js +6 -0
- package/dist/src/mcpl/errors.js.map +1 -1
- package/dist/src/mcpl/feature-set-manager.d.ts +10 -1
- package/dist/src/mcpl/feature-set-manager.d.ts.map +1 -1
- package/dist/src/mcpl/feature-set-manager.js +45 -4
- package/dist/src/mcpl/feature-set-manager.js.map +1 -1
- package/dist/src/mcpl/hook-orchestrator.d.ts +10 -14
- package/dist/src/mcpl/hook-orchestrator.d.ts.map +1 -1
- package/dist/src/mcpl/hook-orchestrator.js +58 -67
- package/dist/src/mcpl/hook-orchestrator.js.map +1 -1
- package/dist/src/mcpl/index.d.ts +1 -1
- package/dist/src/mcpl/index.d.ts.map +1 -1
- package/dist/src/mcpl/index.js.map +1 -1
- package/dist/src/mcpl/prose-grammar.d.ts +11 -0
- package/dist/src/mcpl/prose-grammar.d.ts.map +1 -1
- package/dist/src/mcpl/prose-grammar.js +21 -0
- package/dist/src/mcpl/prose-grammar.js.map +1 -1
- package/dist/src/mcpl/prose-stream-router.d.ts +11 -2
- package/dist/src/mcpl/prose-stream-router.d.ts.map +1 -1
- package/dist/src/mcpl/prose-stream-router.js +73 -13
- package/dist/src/mcpl/prose-stream-router.js.map +1 -1
- package/dist/src/mcpl/push-handler.d.ts.map +1 -1
- package/dist/src/mcpl/push-handler.js +20 -2
- package/dist/src/mcpl/push-handler.js.map +1 -1
- package/dist/src/mcpl/server-connection.d.ts +93 -9
- package/dist/src/mcpl/server-connection.d.ts.map +1 -1
- package/dist/src/mcpl/server-connection.js +231 -32
- package/dist/src/mcpl/server-connection.js.map +1 -1
- package/dist/src/mcpl/server-registry.d.ts.map +1 -1
- package/dist/src/mcpl/server-registry.js +4 -3
- package/dist/src/mcpl/server-registry.js.map +1 -1
- package/dist/src/mcpl/tags.d.ts +24 -0
- package/dist/src/mcpl/tags.d.ts.map +1 -0
- package/dist/src/mcpl/tags.js +52 -0
- package/dist/src/mcpl/tags.js.map +1 -0
- package/dist/src/mcpl/transport.d.ts.map +1 -1
- package/dist/src/mcpl/transport.js +10 -0
- package/dist/src/mcpl/transport.js.map +1 -1
- package/dist/src/mcpl/types.d.ts +159 -64
- package/dist/src/mcpl/types.d.ts.map +1 -1
- package/dist/src/mcpl/types.js +16 -2
- package/dist/src/mcpl/types.js.map +1 -1
- package/dist/src/modules/workspace/index.d.ts +23 -0
- package/dist/src/modules/workspace/index.d.ts.map +1 -1
- package/dist/src/modules/workspace/index.js +48 -0
- package/dist/src/modules/workspace/index.js.map +1 -1
- package/dist/src/modules/workspace/sync.d.ts +11 -2
- package/dist/src/modules/workspace/sync.d.ts.map +1 -1
- package/dist/src/modules/workspace/sync.js +18 -8
- package/dist/src/modules/workspace/sync.js.map +1 -1
- package/dist/src/refusal-reactions.d.ts +27 -0
- package/dist/src/refusal-reactions.d.ts.map +1 -0
- package/dist/src/refusal-reactions.js +35 -0
- package/dist/src/refusal-reactions.js.map +1 -0
- package/dist/src/tool-result-history.d.ts +20 -0
- package/dist/src/tool-result-history.d.ts.map +1 -1
- package/dist/src/tool-result-history.js +26 -5
- package/dist/src/tool-result-history.js.map +1 -1
- package/dist/src/types/agent.d.ts +39 -1
- package/dist/src/types/agent.d.ts.map +1 -1
- package/dist/src/types/framework.d.ts +16 -0
- package/dist/src/types/framework.d.ts.map +1 -1
- package/dist/src/types/trace.d.ts +24 -0
- package/dist/src/types/trace.d.ts.map +1 -1
- package/dist/test/channel-registry-routing.test.js +38 -10
- package/dist/test/channel-registry-routing.test.js.map +1 -1
- package/dist/test/channel-registry-typing.test.js +10 -1
- package/dist/test/channel-registry-typing.test.js.map +1 -1
- package/dist/test/checkpoint-attribution.test.js +168 -8
- package/dist/test/checkpoint-attribution.test.js.map +1 -1
- package/dist/test/conversation-fork-injection-scoping.test.js +8 -3
- package/dist/test/conversation-fork-injection-scoping.test.js.map +1 -1
- package/dist/test/event-gate-passthrough.test.d.ts +15 -0
- package/dist/test/event-gate-passthrough.test.d.ts.map +1 -0
- package/dist/test/event-gate-passthrough.test.js +289 -0
- package/dist/test/event-gate-passthrough.test.js.map +1 -0
- package/dist/test/event-gate-selfwake.test.d.ts +15 -0
- package/dist/test/event-gate-selfwake.test.d.ts.map +1 -0
- package/dist/test/event-gate-selfwake.test.js +125 -0
- package/dist/test/event-gate-selfwake.test.js.map +1 -0
- package/dist/test/explicit-prose-routing.test.js +137 -7
- package/dist/test/explicit-prose-routing.test.js.map +1 -1
- package/dist/test/fixtures/awareness-barrier-mcpl-server.mjs +276 -0
- package/dist/test/fixtures/flaky-mcpl-server.mjs +41 -0
- package/dist/test/machine-close-provenance.test.js +6 -0
- package/dist/test/machine-close-provenance.test.js.map +1 -1
- package/dist/test/mcpl-awareness-barrier.test.js +10 -0
- package/dist/test/mcpl-awareness-barrier.test.js.map +1 -1
- package/dist/test/mcpl-capability-grant.test.d.ts +10 -0
- package/dist/test/mcpl-capability-grant.test.d.ts.map +1 -0
- package/dist/test/mcpl-capability-grant.test.js +109 -0
- package/dist/test/mcpl-capability-grant.test.js.map +1 -0
- package/dist/test/mcpl-capability-scoping.test.d.ts +2 -0
- package/dist/test/mcpl-capability-scoping.test.d.ts.map +1 -0
- package/dist/test/mcpl-capability-scoping.test.js +266 -0
- package/dist/test/mcpl-capability-scoping.test.js.map +1 -0
- package/dist/test/mcpl-gate-roundtrip.test.js +13 -0
- package/dist/test/mcpl-gate-roundtrip.test.js.map +1 -1
- package/dist/test/mcpl-list-status.test.d.ts +2 -0
- package/dist/test/mcpl-list-status.test.d.ts.map +1 -0
- package/dist/test/mcpl-list-status.test.js +78 -0
- package/dist/test/mcpl-list-status.test.js.map +1 -0
- package/dist/test/mcpl-manifest-changed.test.d.ts +2 -0
- package/dist/test/mcpl-manifest-changed.test.d.ts.map +1 -0
- package/dist/test/mcpl-manifest-changed.test.js +177 -0
- package/dist/test/mcpl-manifest-changed.test.js.map +1 -0
- package/dist/test/mcpl-reconnect-events.test.js +27 -2
- package/dist/test/mcpl-reconnect-events.test.js.map +1 -1
- package/dist/test/mcpl-reconnect-reregistration.test.js +53 -17
- package/dist/test/mcpl-reconnect-reregistration.test.js.map +1 -1
- package/dist/test/mcpl-request-timeout.test.js +1 -1
- package/dist/test/mcpl-request-timeout.test.js.map +1 -1
- package/dist/test/physical-window-restart.test.d.ts +14 -0
- package/dist/test/physical-window-restart.test.d.ts.map +1 -0
- package/dist/test/physical-window-restart.test.js +222 -0
- package/dist/test/physical-window-restart.test.js.map +1 -0
- package/dist/test/present-while-acting.test.js +199 -1
- package/dist/test/present-while-acting.test.js.map +1 -1
- package/dist/test/prose-stream-router.test.js +43 -0
- package/dist/test/prose-stream-router.test.js.map +1 -1
- package/dist/test/refusal-reaction-baseline.test.d.ts +2 -0
- package/dist/test/refusal-reaction-baseline.test.d.ts.map +1 -0
- package/dist/test/refusal-reaction-baseline.test.js +74 -0
- package/dist/test/refusal-reaction-baseline.test.js.map +1 -0
- package/dist/test/state-scaling-e2e.test.js +7 -1
- package/dist/test/state-scaling-e2e.test.js.map +1 -1
- package/dist/test/state-scaling.test.js +9 -1
- package/dist/test/state-scaling.test.js.map +1 -1
- package/dist/test/tool-result-spill.test.d.ts +13 -0
- package/dist/test/tool-result-spill.test.d.ts.map +1 -0
- package/dist/test/tool-result-spill.test.js +472 -0
- package/dist/test/tool-result-spill.test.js.map +1 -0
- package/dist/test/trunk-channel-routing.test.js +45 -0
- package/dist/test/trunk-channel-routing.test.js.map +1 -1
- package/dist/test/xml-round-persist.test.d.ts +19 -0
- package/dist/test/xml-round-persist.test.d.ts.map +1 -0
- package/dist/test/xml-round-persist.test.js +235 -0
- package/dist/test/xml-round-persist.test.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -4
- package/src/agent.ts +38 -4
- package/src/framework.ts +1488 -272
- package/src/gate/event-gate.ts +427 -24
- package/src/gate/types.ts +58 -0
- package/src/index.ts +1 -0
- package/src/mcpl/capability-grant.ts +319 -0
- package/src/mcpl/capability-mask.ts +228 -0
- package/src/mcpl/channel-registry.ts +167 -39
- package/src/mcpl/checkpoint-manager.ts +28 -8
- package/src/mcpl/errors.ts +7 -0
- package/src/mcpl/feature-set-manager.ts +50 -5
- package/src/mcpl/hook-orchestrator.ts +64 -86
- package/src/mcpl/index.ts +0 -2
- package/src/mcpl/prose-grammar.ts +21 -0
- package/src/mcpl/prose-stream-router.ts +65 -14
- package/src/mcpl/push-handler.ts +18 -2
- package/src/mcpl/server-connection.ts +262 -34
- package/src/mcpl/server-registry.ts +4 -3
- package/src/mcpl/tags.ts +50 -0
- package/src/mcpl/transport.ts +11 -0
- package/src/mcpl/types.ts +176 -78
- package/src/modules/workspace/index.ts +48 -0
- package/src/modules/workspace/sync.ts +30 -7
- package/src/refusal-reactions.ts +37 -0
- package/src/tool-result-history.ts +27 -5
- package/src/types/agent.ts +40 -1
- package/src/types/framework.ts +17 -0
- package/src/types/trace.ts +22 -0
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* XML-mode per-round persist: the framework must store each round's text
|
|
3
|
+
* exactly once.
|
|
4
|
+
*
|
|
5
|
+
* Regression for the Evander 2026-08-08 scaffold-leak pyramid: membrane's
|
|
6
|
+
* `ToolContext.preamble` is CUMULATIVE in XML mode (whole turn so far,
|
|
7
|
+
* including harness-injected <function_results> XML). The per-round persist
|
|
8
|
+
* fallback stored it per round, so a 3-call turn wrote round-1's text 3×,
|
|
9
|
+
* round-2's 2×, and re-persisted injected results as the agent's own words —
|
|
10
|
+
* which the anthropic-xml formatter then replayed to the model as
|
|
11
|
+
* scaffold-in-its-own-voice.
|
|
12
|
+
*
|
|
13
|
+
* With membrane ≥0.5.79 the context carries `roundPreamble` (this round's
|
|
14
|
+
* delta only) and the framework must prefer it. With an older membrane
|
|
15
|
+
* (no `roundPreamble`) the cumulative fallback remains — pinned here so the
|
|
16
|
+
* compat shape stays visible and deliberate.
|
|
17
|
+
*/
|
|
18
|
+
import { describe, it } from 'node:test';
|
|
19
|
+
import assert from 'node:assert';
|
|
20
|
+
import { tmpdir } from 'node:os';
|
|
21
|
+
import { mkdtempSync, rmSync } from 'node:fs';
|
|
22
|
+
import { join } from 'node:path';
|
|
23
|
+
import { AgentFramework } from '../src/index.js';
|
|
24
|
+
const R1 = 'ROUND_ONE_TEXT_alpha';
|
|
25
|
+
const R2 = 'ROUND_TWO_TEXT_beta';
|
|
26
|
+
const FINAL = 'FINAL_TEXT_gamma';
|
|
27
|
+
const INJECTED = 'INJECTED_RESULTS_XML_delta';
|
|
28
|
+
const RAW1 = '<function_calls><invoke name="test--echo"><parameter name="message">round1</parameter></invoke></function_calls>';
|
|
29
|
+
const RAW2 = '<function_calls><invoke name="test--echo"><parameter name="message">round2</parameter></invoke></function_calls>';
|
|
30
|
+
/**
|
|
31
|
+
* Mock yielding stream simulating membrane's XML tool mode: tool-calls
|
|
32
|
+
* events carry NO roundContent; `preamble` is cumulative (with injected
|
|
33
|
+
* results XML between rounds), `roundPreamble` optionally carries the
|
|
34
|
+
* per-round delta.
|
|
35
|
+
*/
|
|
36
|
+
class XmlMockStream {
|
|
37
|
+
rounds;
|
|
38
|
+
finalText;
|
|
39
|
+
withRoundPreamble;
|
|
40
|
+
events = [];
|
|
41
|
+
_done = false;
|
|
42
|
+
_isWaitingForTools = false;
|
|
43
|
+
_round = 0;
|
|
44
|
+
pendingResolve = null;
|
|
45
|
+
constructor(rounds, finalText, withRoundPreamble) {
|
|
46
|
+
this.rounds = rounds;
|
|
47
|
+
this.finalText = finalText;
|
|
48
|
+
this.withRoundPreamble = withRoundPreamble;
|
|
49
|
+
this.emitRound();
|
|
50
|
+
}
|
|
51
|
+
cumulativePreamble(uptoRound) {
|
|
52
|
+
// preamble before round N's call = r0 text + raw0 + injected results +
|
|
53
|
+
// r1 text + ... + rN text (matches membrane: beforeText minus prefill).
|
|
54
|
+
let out = '';
|
|
55
|
+
for (let i = 0; i < uptoRound; i++) {
|
|
56
|
+
out += this.rounds[i].text + '\n' + this.rounds[i].rawText +
|
|
57
|
+
`\n<function_results>${INJECTED}</function_results>\n`;
|
|
58
|
+
}
|
|
59
|
+
out += this.rounds[uptoRound].text + '\n';
|
|
60
|
+
return out;
|
|
61
|
+
}
|
|
62
|
+
emitRound() {
|
|
63
|
+
const round = this.rounds[this._round];
|
|
64
|
+
if (!round) {
|
|
65
|
+
const response = {
|
|
66
|
+
content: [{ type: 'text', text: this.finalText }],
|
|
67
|
+
stopReason: 'end_turn',
|
|
68
|
+
rawAssistantText: this.finalText,
|
|
69
|
+
toolCalls: [],
|
|
70
|
+
toolResults: [],
|
|
71
|
+
usage: { inputTokens: 10, outputTokens: 5 },
|
|
72
|
+
details: { raw: {} },
|
|
73
|
+
};
|
|
74
|
+
this.events.push({ type: 'complete', response });
|
|
75
|
+
this._done = true;
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
this._isWaitingForTools = true;
|
|
79
|
+
this.events.push({
|
|
80
|
+
type: 'tool-calls',
|
|
81
|
+
calls: [{ id: round.callId, name: 'test--echo', input: round.callInput }],
|
|
82
|
+
context: {
|
|
83
|
+
rawText: round.rawText,
|
|
84
|
+
preamble: this.cumulativePreamble(this._round),
|
|
85
|
+
depth: this._round,
|
|
86
|
+
previousResults: [],
|
|
87
|
+
accumulated: this.cumulativePreamble(this._round) + round.rawText,
|
|
88
|
+
...(this.withRoundPreamble ? { roundPreamble: round.text + '\n' } : {}),
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
provideToolResults(_results) {
|
|
93
|
+
if (!this._isWaitingForTools)
|
|
94
|
+
throw new Error('Not waiting for tools');
|
|
95
|
+
this._isWaitingForTools = false;
|
|
96
|
+
this._round++;
|
|
97
|
+
this.emitRound();
|
|
98
|
+
if (this.pendingResolve) {
|
|
99
|
+
const resolve = this.pendingResolve;
|
|
100
|
+
this.pendingResolve = null;
|
|
101
|
+
resolve();
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
cancel() {
|
|
105
|
+
this._done = true;
|
|
106
|
+
this.events.push({ type: 'aborted', reason: 'user' });
|
|
107
|
+
if (this.pendingResolve) {
|
|
108
|
+
const r = this.pendingResolve;
|
|
109
|
+
this.pendingResolve = null;
|
|
110
|
+
r();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
get isWaitingForTools() { return this._isWaitingForTools; }
|
|
114
|
+
get pendingToolCallIds() {
|
|
115
|
+
const round = this.rounds[this._round];
|
|
116
|
+
return this._isWaitingForTools && round ? [round.callId] : [];
|
|
117
|
+
}
|
|
118
|
+
get toolDepth() { return this._round; }
|
|
119
|
+
async *[Symbol.asyncIterator]() {
|
|
120
|
+
while (true) {
|
|
121
|
+
while (this.events.length > 0) {
|
|
122
|
+
const event = this.events.shift();
|
|
123
|
+
yield event;
|
|
124
|
+
if (event.type === 'complete' || event.type === 'error' || event.type === 'aborted') {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (this._done)
|
|
129
|
+
return;
|
|
130
|
+
await new Promise((resolve) => { this.pendingResolve = resolve; });
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
class XmlMockMembrane {
|
|
135
|
+
withRoundPreamble;
|
|
136
|
+
constructor(withRoundPreamble) {
|
|
137
|
+
this.withRoundPreamble = withRoundPreamble;
|
|
138
|
+
}
|
|
139
|
+
calls = [];
|
|
140
|
+
async complete(request) {
|
|
141
|
+
this.calls.push(request);
|
|
142
|
+
throw new Error('not used');
|
|
143
|
+
}
|
|
144
|
+
streamYielding(request) {
|
|
145
|
+
this.calls.push(request);
|
|
146
|
+
return new XmlMockStream([
|
|
147
|
+
{ text: R1, rawText: RAW1, callId: 'call_1', callInput: { message: 'round1' } },
|
|
148
|
+
{ text: R2, rawText: RAW2, callId: 'call_2', callInput: { message: 'round2' } },
|
|
149
|
+
], FINAL, this.withRoundPreamble);
|
|
150
|
+
}
|
|
151
|
+
asMembrane() {
|
|
152
|
+
return this;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
class EchoModule {
|
|
156
|
+
name = 'test';
|
|
157
|
+
async start(_ctx) { }
|
|
158
|
+
async stop() { }
|
|
159
|
+
getTools() {
|
|
160
|
+
return [{
|
|
161
|
+
name: 'echo',
|
|
162
|
+
description: 'Echoes the input',
|
|
163
|
+
inputSchema: {
|
|
164
|
+
type: 'object',
|
|
165
|
+
properties: { message: { type: 'string', description: 'Message to echo' } },
|
|
166
|
+
required: ['message'],
|
|
167
|
+
},
|
|
168
|
+
}];
|
|
169
|
+
}
|
|
170
|
+
async handleToolCall(call) {
|
|
171
|
+
const input = call.input;
|
|
172
|
+
return { success: true, data: { echoed: input.message } };
|
|
173
|
+
}
|
|
174
|
+
async onProcess(event, _state) {
|
|
175
|
+
if (event.type === 'external-message') {
|
|
176
|
+
return {
|
|
177
|
+
addMessages: [{ participant: 'User', content: [{ type: 'text', text: String(event.content) }] }],
|
|
178
|
+
requestInference: true,
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
return {};
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
async function runTurn(withRoundPreamble) {
|
|
185
|
+
const tempDir = mkdtempSync(join(tmpdir(), 'xml-round-persist-'));
|
|
186
|
+
const membrane = new XmlMockMembrane(withRoundPreamble);
|
|
187
|
+
const framework = await AgentFramework.create({
|
|
188
|
+
storePath: join(tempDir, 'test.chronicle'),
|
|
189
|
+
membrane: membrane.asMembrane(),
|
|
190
|
+
agents: [{ name: 'assistant', model: 'test-model', systemPrompt: 'Test' }],
|
|
191
|
+
modules: [new EchoModule()],
|
|
192
|
+
});
|
|
193
|
+
try {
|
|
194
|
+
framework.pushEvent({
|
|
195
|
+
type: 'external-message',
|
|
196
|
+
source: 'test',
|
|
197
|
+
content: 'Do two echoes',
|
|
198
|
+
metadata: {},
|
|
199
|
+
});
|
|
200
|
+
await framework.runUntilIdle();
|
|
201
|
+
const cm = framework.getAgent('assistant').getContextManager();
|
|
202
|
+
const msgs = (cm.queryMessages({}).messages ?? []);
|
|
203
|
+
return msgs
|
|
204
|
+
.flatMap((m) => m.content)
|
|
205
|
+
.filter((b) => b.type === 'text')
|
|
206
|
+
.map((b) => b.text ?? '')
|
|
207
|
+
.join('\n---\n');
|
|
208
|
+
}
|
|
209
|
+
finally {
|
|
210
|
+
await framework.stop();
|
|
211
|
+
rmSync(tempDir, { recursive: true, force: true });
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
function count(haystack, needle) {
|
|
215
|
+
return haystack.split(needle).length - 1;
|
|
216
|
+
}
|
|
217
|
+
describe('XML-mode per-round persist (scaffold-leak pyramid regression)', () => {
|
|
218
|
+
it('stores each round exactly once when membrane provides roundPreamble', async () => {
|
|
219
|
+
const storedText = await runTurn(true);
|
|
220
|
+
assert.strictEqual(count(storedText, R1), 1, `round-1 text stored once, got: ${count(storedText, R1)}`);
|
|
221
|
+
assert.strictEqual(count(storedText, R2), 1, 'round-2 text stored once');
|
|
222
|
+
assert.strictEqual(count(storedText, FINAL), 1, 'final text stored once');
|
|
223
|
+
assert.strictEqual(count(storedText, INJECTED), 0, 'injected <function_results> XML must never persist as agent text');
|
|
224
|
+
});
|
|
225
|
+
it('legacy membrane without roundPreamble keeps the cumulative fallback (pinned)', async () => {
|
|
226
|
+
const storedText = await runTurn(false);
|
|
227
|
+
// The old shape, deliberately pinned: round-1 in rounds 1+2 = 2 copies,
|
|
228
|
+
// injected results re-persisted once. When the fleet's membrane floor
|
|
229
|
+
// reaches 0.5.79 this contract can be dropped along with the fallback.
|
|
230
|
+
assert.strictEqual(count(storedText, R1), 2, 'cumulative fallback: round-1 text twice');
|
|
231
|
+
assert.strictEqual(count(storedText, R2), 1, 'round-2 text once');
|
|
232
|
+
assert.strictEqual(count(storedText, INJECTED), 1, 'injected XML persisted once by fallback');
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
//# sourceMappingURL=xml-round-persist.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xml-round-persist.test.js","sourceRoot":"","sources":["../../test/xml-round-persist.test.ts"],"names":[],"mappings":"AAAA;;;;;;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