@zelari/core 2.33.1 → 2.34.1
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 +1 -1
- package/dist/agents/council/cancel.d.ts +14 -0
- package/dist/agents/council/cancel.d.ts.map +1 -0
- package/dist/agents/council/cancel.js +29 -0
- package/dist/agents/council/cancel.js.map +1 -0
- package/dist/agents/council/chairmanDelivery.d.ts +92 -0
- package/dist/agents/council/chairmanDelivery.d.ts.map +1 -0
- package/dist/agents/council/chairmanDelivery.js +236 -0
- package/dist/agents/council/chairmanDelivery.js.map +1 -0
- package/dist/agents/council/chairmanFixLoop.d.ts +47 -0
- package/dist/agents/council/chairmanFixLoop.d.ts.map +1 -0
- package/dist/agents/council/chairmanFixLoop.js +131 -0
- package/dist/agents/council/chairmanFixLoop.js.map +1 -0
- package/dist/agents/council/memberMessages.d.ts +32 -0
- package/dist/agents/council/memberMessages.d.ts.map +1 -0
- package/dist/agents/council/memberMessages.js +95 -0
- package/dist/agents/council/memberMessages.js.map +1 -0
- package/dist/agents/council/outputCleaning.d.ts +49 -0
- package/dist/agents/council/outputCleaning.d.ts.map +1 -0
- package/dist/agents/council/outputCleaning.js +190 -0
- package/dist/agents/council/outputCleaning.js.map +1 -0
- package/dist/agents/council/retryTurn.d.ts +130 -0
- package/dist/agents/council/retryTurn.d.ts.map +1 -0
- package/dist/agents/council/retryTurn.js +206 -0
- package/dist/agents/council/retryTurn.js.map +1 -0
- package/dist/agents/council/toolEmission.d.ts +61 -0
- package/dist/agents/council/toolEmission.d.ts.map +1 -0
- package/dist/agents/council/toolEmission.js +110 -0
- package/dist/agents/council/toolEmission.js.map +1 -0
- package/dist/agents/council/types.d.ts +190 -0
- package/dist/agents/council/types.d.ts.map +1 -0
- package/dist/agents/council/types.js +15 -0
- package/dist/agents/council/types.js.map +1 -0
- package/dist/agents/councilApi.d.ts +11 -526
- package/dist/agents/councilApi.d.ts.map +1 -1
- package/dist/agents/councilApi.js +46 -903
- package/dist/agents/councilApi.js.map +1 -1
- package/dist/core/AgentHarness.d.ts.map +1 -1
- package/dist/core/AgentHarness.js +5 -5
- package/dist/core/AgentHarness.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { resolveRoleSystemPrompt } from '../roles.js';
|
|
2
|
+
import { buildSystemPromptSplit, computeAgentTools } from '../systemPromptBuilder.js';
|
|
3
|
+
import { getAllTools } from '../tools.js';
|
|
4
|
+
import { councilModeBanner } from '../../council/modeBanners.js';
|
|
5
|
+
/**
|
|
6
|
+
* Tools that mutate project files. In implementation-mode council runs only the
|
|
7
|
+
* chairman (Lucifero) implements; specialists + Minosse analyze and hand off.
|
|
8
|
+
* We strip these from every non-implementer so multiple agents never edit the
|
|
9
|
+
* same files (multi-writer chaos) and "who implemented" stays unambiguous.
|
|
10
|
+
* Note: specialists inherit write tools via skill `requiredTools`, so this must
|
|
11
|
+
* filter the RESULT of computeAgentTools, not just the declared role tools.
|
|
12
|
+
*/
|
|
13
|
+
export const MUTATING_PROJECT_TOOLS = ['write_file', 'edit_file'];
|
|
14
|
+
/**
|
|
15
|
+
* Remove file-mutating tools for non-implementer members in implementation mode.
|
|
16
|
+
* Design-phase and the implementer (chairman) keep the full set unchanged.
|
|
17
|
+
*/
|
|
18
|
+
export function restrictImplementationWrites(toolNames, opts) {
|
|
19
|
+
if (opts.runMode !== 'implementation' || opts.isImplementer)
|
|
20
|
+
return toolNames;
|
|
21
|
+
return toolNames.filter((t) => !MUTATING_PROJECT_TOOLS.includes(t));
|
|
22
|
+
}
|
|
23
|
+
/** @internal */
|
|
24
|
+
export function buildAgentMessages(agent, userMessage, ragContext, workspaceContext, priorOutputs, aiConfig, executableTools, runMode = 'implementation', languageModule) {
|
|
25
|
+
// v0.7.5: the AVAILABLE TOOLS prompt block must match the schemas the
|
|
26
|
+
// harness actually advertises. The v0.7.3 fix filtered the schemas
|
|
27
|
+
// (filterExecutable) but NOT this prompt text, so members still read
|
|
28
|
+
// "searchRAG: search the knowledge base…" in their system prompt and
|
|
29
|
+
// called it — every call a guaranteed "Tool not found" (live test
|
|
30
|
+
// 2026-07-03, /council in Z:\EasyPeasy\test).
|
|
31
|
+
const allToolNames = computeAgentTools(agent, aiConfig);
|
|
32
|
+
const toolNames = executableTools
|
|
33
|
+
? allToolNames.filter((n) => executableTools.has(n))
|
|
34
|
+
: allToolNames;
|
|
35
|
+
// Merge language policy into custom modules so every primary council turn
|
|
36
|
+
// gets it (retries previously received the arg but never used it).
|
|
37
|
+
const mergedAiConfig = languageModule
|
|
38
|
+
? {
|
|
39
|
+
enabledSkills: aiConfig?.enabledSkills ?? [],
|
|
40
|
+
enabledTools: aiConfig?.enabledTools ?? [],
|
|
41
|
+
agentSkillConfigs: aiConfig?.agentSkillConfigs ?? [],
|
|
42
|
+
customSkills: aiConfig?.customSkills,
|
|
43
|
+
customPromptModules: [
|
|
44
|
+
...(aiConfig?.customPromptModules ?? []),
|
|
45
|
+
languageModule,
|
|
46
|
+
],
|
|
47
|
+
}
|
|
48
|
+
: aiConfig;
|
|
49
|
+
// Mode-split: design mandatories only when runMode is design-phase.
|
|
50
|
+
const modeAwareAgent = {
|
|
51
|
+
...agent,
|
|
52
|
+
systemPrompt: resolveRoleSystemPrompt(agent, runMode),
|
|
53
|
+
};
|
|
54
|
+
// Cache-efficient split (Cache Wars): stable = identity/tools/role;
|
|
55
|
+
// volatile = workspace/RAG; banners stay trailing system msgs (volatile).
|
|
56
|
+
const split = buildSystemPromptSplit(modeAwareAgent, {
|
|
57
|
+
tools: getAllTools(),
|
|
58
|
+
toolNames,
|
|
59
|
+
aiConfig: mergedAiConfig,
|
|
60
|
+
workspaceContext,
|
|
61
|
+
ragContext,
|
|
62
|
+
mode: 'council',
|
|
63
|
+
includeWorkspaceInPrompt: true,
|
|
64
|
+
});
|
|
65
|
+
const messages = [
|
|
66
|
+
{ role: 'system', content: split.stable },
|
|
67
|
+
];
|
|
68
|
+
if (split.volatile.trim()) {
|
|
69
|
+
messages.push({ role: 'system', content: split.volatile });
|
|
70
|
+
}
|
|
71
|
+
messages.push({ role: 'system', content: councilModeBanner(runMode, { isImplementer: agent.id === 'lucifer' }) }, { role: 'system', content: 'IMPORTANT: Before making any tool calls or expensive operations, check if the information already exists in the shared context from previous agents. Avoid redundant work.' });
|
|
72
|
+
if (priorOutputs.length > 0) {
|
|
73
|
+
// Cap each prior member blob so one verbose specialist cannot saturate
|
|
74
|
+
// downstream members (chairman especially). Full text is not product law.
|
|
75
|
+
const MAX_PRIOR_CHARS = 2800;
|
|
76
|
+
const summary = priorOutputs
|
|
77
|
+
.map((o) => {
|
|
78
|
+
const body = o.content.length > MAX_PRIOR_CHARS
|
|
79
|
+
? `${o.content.slice(0, MAX_PRIOR_CHARS)}\n… [truncated ${o.content.length}→${MAX_PRIOR_CHARS} chars; treat as hypothesis]`
|
|
80
|
+
: o.content;
|
|
81
|
+
return `[${o.name} - ${o.role}]: ${body}`;
|
|
82
|
+
})
|
|
83
|
+
.join('\n\n');
|
|
84
|
+
messages.push({
|
|
85
|
+
role: 'user',
|
|
86
|
+
content: `Previous council members have said (hypotheses — prefer product files on disk if they conflict):\n${summary}\n\n` +
|
|
87
|
+
`Original user request: ${userMessage}`,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
messages.push({ role: 'user', content: userMessage });
|
|
92
|
+
}
|
|
93
|
+
return messages;
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=memberMessages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memberMessages.js","sourceRoot":"","sources":["../../../src/agents/council/memberMessages.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AACtF,OAAO,EAAE,WAAW,EAA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AC,EAAE,EAAE;YACT,MAAM,IAAI,GACR,CAAC,CAAC,OAAO,CAAC,MAAM,GAAG,eAAe;gBAChC,CAAC,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,eAAe,CAAC,kBAAkB,CAAC,CAAC,OAAO,CAAC,MAAM,IAAI,eAAe,8BAA8B;gBAC3H,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;YAChB,OAAO,IAAI,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,IAAI,MAAM,IAAI,EAAE,CAAC;QAC5C,CAAC,CAAC;aACD,IAAI,CAAC,MAAM,CAAC,CAAC;QAChB,QAAQ,CAAC,IAAI,CAAC;YACZ,IAAI,EAAE,MAAM;YACZ,OAAO,EACL,qGAAqG,OAAO,MAAM;gBAClH,0BAA0B,WAAW,EAAE;SAC1C,CAAC,CAAC;IACL,CAAC;SAAM,CAAC;QACN,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC,CAAC;IACxD,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export interface ClarificationRequest {
|
|
2
|
+
question: string;
|
|
3
|
+
choices?: string[];
|
|
4
|
+
context?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function parseClarificationRequest(text: string): ClarificationRequest | null;
|
|
7
|
+
/** True when text contains a structured question with ≥2 choices (pause UI). */
|
|
8
|
+
export declare function hasInteractiveClarification(text: string): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Strip real clarification blocks from display prose.
|
|
11
|
+
*
|
|
12
|
+
* A block is real only when `---QUESTION---` is followed (after whitespace)
|
|
13
|
+
* by `{`. Mentions of the marker in prose or backticks are left intact —
|
|
14
|
+
* the old marker→EOF regex ate the rest of any reply that *talked about*
|
|
15
|
+
* the protocol (Desktop/headless streamScrub then stopped emitting).
|
|
16
|
+
*
|
|
17
|
+
* Incomplete `{` (streaming, no balanced JSON, no ---END---) still hides
|
|
18
|
+
* from the marker through EOF so JSON scaffolding does not flash.
|
|
19
|
+
*/
|
|
20
|
+
export declare function stripQuestionBlocks(text: string): string;
|
|
21
|
+
export declare function parseThinking(text: string): string;
|
|
22
|
+
export interface CleanAgentContentOptions {
|
|
23
|
+
/**
|
|
24
|
+
* When true (default), strip `---QUESTION---` blocks from display text.
|
|
25
|
+
* Set false when cleaning text for rolling PROVIDER history — the model
|
|
26
|
+
* still needs to see its own clarifying question on the next turn.
|
|
27
|
+
*/
|
|
28
|
+
stripQuestion?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* When true (default), strip `<think>` / `<thinking>` blocks (UI display).
|
|
31
|
+
* Set **false** for multi-turn **provider** history: MiniMax-M3 (and M2.x)
|
|
32
|
+
* require the full assistant `content` including think tags so interleaved
|
|
33
|
+
* tool-use reasoning continues. Stripping them for the API degrades tool
|
|
34
|
+
* loops ("announces intent then stops"). Display paths keep the default.
|
|
35
|
+
*/
|
|
36
|
+
stripThink?: boolean;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Strip model "private" channels from text shown to the user / re-fed as
|
|
40
|
+
* history. Covers:
|
|
41
|
+
* - complete + unclosed `<think>` / `<thinking>` (GLM/MiniMax style) — optional
|
|
42
|
+
* - MiniMax XML tool-call wrappers
|
|
43
|
+
* - clarifying-question JSON blocks (display only; keep in provider history)
|
|
44
|
+
*
|
|
45
|
+
* Without unclosed-tag stripping, streamed thinking that never got a closing
|
|
46
|
+
* tag leaked into the TUI as visible assistant prose (v1.8.1).
|
|
47
|
+
*/
|
|
48
|
+
export declare function cleanAgentContent(text: string, opts?: CleanAgentContentOptions): string;
|
|
49
|
+
//# sourceMappingURL=outputCleaning.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"outputCleaning.d.ts","sourceRoot":"","sources":["../../../src/agents/council/outputCleaning.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAwCD,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,MAAM,GAAG,oBAAoB,GAAG,IAAI,CA6BnF;AAED,gFAAgF;AAChF,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAGjE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CA+BxD;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAMlD;AAED,MAAM,WAAW,wBAAwB;IACvC;;;;OAIG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,IAAI,GAAE,wBAA6B,GAClC,MAAM,CAgDR"}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* outputCleaning — clarifying-question parsing and model output cleaning,
|
|
3
|
+
* extracted verbatim from agents/councilApi.ts.
|
|
4
|
+
*/
|
|
5
|
+
import { scrubProprietaryLeak } from '../secrecyPolicy.js';
|
|
6
|
+
const QUESTION_MARKER = '---QUESTION---';
|
|
7
|
+
const QUESTION_END_MARKER = '---END---';
|
|
8
|
+
/**
|
|
9
|
+
* Extract the first top-level JSON object from `s` using brace depth so trailing
|
|
10
|
+
* MiniMax/tool garbage after `}` does not break JSON.parse (common failure mode:
|
|
11
|
+
* `---QUESTION--- {…}]<]minimax…` without ---END---).
|
|
12
|
+
*/
|
|
13
|
+
function extractBalancedJsonObject(s) {
|
|
14
|
+
const start = s.indexOf('{');
|
|
15
|
+
if (start < 0)
|
|
16
|
+
return null;
|
|
17
|
+
let depth = 0;
|
|
18
|
+
let inString = false;
|
|
19
|
+
let escape = false;
|
|
20
|
+
for (let i = start; i < s.length; i++) {
|
|
21
|
+
const ch = s[i];
|
|
22
|
+
if (inString) {
|
|
23
|
+
if (escape) {
|
|
24
|
+
escape = false;
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
if (ch === '\\') {
|
|
28
|
+
escape = true;
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (ch === '"')
|
|
32
|
+
inString = false;
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
if (ch === '"') {
|
|
36
|
+
inString = true;
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
if (ch === '{')
|
|
40
|
+
depth++;
|
|
41
|
+
else if (ch === '}') {
|
|
42
|
+
depth--;
|
|
43
|
+
if (depth === 0)
|
|
44
|
+
return s.slice(start, i + 1);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
export function parseClarificationRequest(text) {
|
|
50
|
+
const start = text.indexOf(QUESTION_MARKER);
|
|
51
|
+
if (start < 0)
|
|
52
|
+
return null;
|
|
53
|
+
const rest = text.slice(start + QUESTION_MARKER.length);
|
|
54
|
+
const end = rest.indexOf(QUESTION_END_MARKER);
|
|
55
|
+
const block = end >= 0 ? rest.slice(0, end) : rest;
|
|
56
|
+
const cleaned = block.replace(/```json\n?/g, '').replace(/```\n?/g, '').trim();
|
|
57
|
+
const jsonText = extractBalancedJsonObject(cleaned) ??
|
|
58
|
+
(() => {
|
|
59
|
+
const objStart = cleaned.indexOf('{');
|
|
60
|
+
const objEnd = cleaned.lastIndexOf('}');
|
|
61
|
+
return objStart >= 0 && objEnd > objStart
|
|
62
|
+
? cleaned.slice(objStart, objEnd + 1)
|
|
63
|
+
: cleaned;
|
|
64
|
+
})();
|
|
65
|
+
try {
|
|
66
|
+
const parsed = JSON.parse(jsonText);
|
|
67
|
+
if (typeof parsed.question !== 'string' || !parsed.question.trim())
|
|
68
|
+
return null;
|
|
69
|
+
return {
|
|
70
|
+
question: parsed.question.trim(),
|
|
71
|
+
choices: Array.isArray(parsed.choices)
|
|
72
|
+
? parsed.choices.filter((c) => typeof c === 'string' && c.trim().length > 0).map((c) => c.trim())
|
|
73
|
+
: undefined,
|
|
74
|
+
context: typeof parsed.context === 'string' ? parsed.context.trim() : undefined,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/** True when text contains a structured question with ≥2 choices (pause UI). */
|
|
82
|
+
export function hasInteractiveClarification(text) {
|
|
83
|
+
const c = parseClarificationRequest(text);
|
|
84
|
+
return !!(c && c.choices && c.choices.length >= 2);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Strip real clarification blocks from display prose.
|
|
88
|
+
*
|
|
89
|
+
* A block is real only when `---QUESTION---` is followed (after whitespace)
|
|
90
|
+
* by `{`. Mentions of the marker in prose or backticks are left intact —
|
|
91
|
+
* the old marker→EOF regex ate the rest of any reply that *talked about*
|
|
92
|
+
* the protocol (Desktop/headless streamScrub then stopped emitting).
|
|
93
|
+
*
|
|
94
|
+
* Incomplete `{` (streaming, no balanced JSON, no ---END---) still hides
|
|
95
|
+
* from the marker through EOF so JSON scaffolding does not flash.
|
|
96
|
+
*/
|
|
97
|
+
export function stripQuestionBlocks(text) {
|
|
98
|
+
let out = '';
|
|
99
|
+
let rest = text;
|
|
100
|
+
while (true) {
|
|
101
|
+
const start = rest.indexOf(QUESTION_MARKER);
|
|
102
|
+
if (start < 0) {
|
|
103
|
+
out += rest;
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
out += rest.slice(0, start);
|
|
107
|
+
const afterMarker = rest.slice(start + QUESTION_MARKER.length);
|
|
108
|
+
const trimmed = afterMarker.replace(/^\s+/, '');
|
|
109
|
+
if (!trimmed.startsWith('{')) {
|
|
110
|
+
out += QUESTION_MARKER;
|
|
111
|
+
rest = afterMarker;
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
const endIdx = afterMarker.indexOf(QUESTION_END_MARKER);
|
|
115
|
+
if (endIdx >= 0) {
|
|
116
|
+
rest = afterMarker.slice(endIdx + QUESTION_END_MARKER.length);
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
const json = extractBalancedJsonObject(trimmed);
|
|
120
|
+
if (json) {
|
|
121
|
+
const jsonAt = afterMarker.indexOf(json);
|
|
122
|
+
rest = afterMarker.slice(jsonAt + json.length);
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
return out.replace(/\n{3,}/g, '\n\n').trim();
|
|
128
|
+
}
|
|
129
|
+
export function parseThinking(text) {
|
|
130
|
+
// Prefer complete blocks; fall back to unclosed trailing block (common mid-stream).
|
|
131
|
+
const complete = text.match(/<think(?:ing)?>([\s\S]*?)<\/think(?:ing)?>/i);
|
|
132
|
+
if (complete)
|
|
133
|
+
return complete[1].trim();
|
|
134
|
+
const open = text.match(/<think(?:ing)?>([\s\S]*)$/i);
|
|
135
|
+
return open ? open[1].trim() : '';
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Strip model "private" channels from text shown to the user / re-fed as
|
|
139
|
+
* history. Covers:
|
|
140
|
+
* - complete + unclosed `<think>` / `<thinking>` (GLM/MiniMax style) — optional
|
|
141
|
+
* - MiniMax XML tool-call wrappers
|
|
142
|
+
* - clarifying-question JSON blocks (display only; keep in provider history)
|
|
143
|
+
*
|
|
144
|
+
* Without unclosed-tag stripping, streamed thinking that never got a closing
|
|
145
|
+
* tag leaked into the TUI as visible assistant prose (v1.8.1).
|
|
146
|
+
*/
|
|
147
|
+
export function cleanAgentContent(text, opts = {}) {
|
|
148
|
+
const stripQuestion = opts.stripQuestion !== false;
|
|
149
|
+
const stripThink = opts.stripThink !== false;
|
|
150
|
+
let out = text;
|
|
151
|
+
if (stripThink) {
|
|
152
|
+
out = out
|
|
153
|
+
.replace(/<think(?:ing)?>[\s\S]*?<\/think(?:ing)?>/gi, '')
|
|
154
|
+
.replace(/<think(?:ing)?>[\s\S]*$/gi, '')
|
|
155
|
+
.replace(/<\/think(?:ing)?>/gi, '');
|
|
156
|
+
}
|
|
157
|
+
// Tool-call markup that models sometimes dump into prose (MiniMax / GLM / generic).
|
|
158
|
+
// Prefer closed-block removal first; only then strip *trailing* unclosed
|
|
159
|
+
// open tags. Never use a mid-string open-tag → EOF wipe for tool tags when
|
|
160
|
+
// there may still be real prose after a broken unclosed tag sequence —
|
|
161
|
+
// headless streamScrub re-cleans the full buffer each push, so closed pairs
|
|
162
|
+
// are enough mid-stream; trailing open is for end-of-turn.
|
|
163
|
+
out = out
|
|
164
|
+
.replace(/<minimax:tool_call>[\s\S]*?<\/minimax:tool_call>/gi, '')
|
|
165
|
+
.replace(/<\/?minimax:tool_call>/gi, '')
|
|
166
|
+
.replace(/<tool_call>[\s\S]*?<\/tool_call>/gi, '')
|
|
167
|
+
.replace(/<\/?tool_call>/gi, '')
|
|
168
|
+
.replace(/<function_call>[\s\S]*?<\/function_call>/gi, '')
|
|
169
|
+
.replace(/<\/?function_call>/gi, '')
|
|
170
|
+
.replace(/<invoke\b[^>]*>[\s\S]*?<\/invoke>/gi, '')
|
|
171
|
+
.replace(/<\/invoke>/gi, '')
|
|
172
|
+
.replace(/<parameter\b[^>]*>[\s\S]*?<\/parameter>/gi, '')
|
|
173
|
+
.replace(/<\/parameter>/gi, '')
|
|
174
|
+
.replace(/\]\s*<\]\s*minimax\s*\[>\s*\[?<invoke\b[^>]*>[\s\S]*?<\/invoke>/gi, '')
|
|
175
|
+
// Trailing unclosed tool channels only (end of buffer)
|
|
176
|
+
.replace(/<minimax:tool_call>[\s\S]*$/gi, '')
|
|
177
|
+
.replace(/<tool_call>[\s\S]*$/gi, '')
|
|
178
|
+
.replace(/<function_call>[\s\S]*$/gi, '')
|
|
179
|
+
.replace(/<invoke\b[^>]*>[\s\S]*$/gi, '')
|
|
180
|
+
.replace(/\]\s*<\]\s*minimax\s*\[>[\s\S]*$/gi, '')
|
|
181
|
+
.replace(/^\s*\]\s*<\]\s*minimax\s*\[>.*$/gim, '')
|
|
182
|
+
.replace(/^\s*<\/?(?:tool_call|function_call|invoke|parameter|minimax:tool_call)\b[^>]*>\s*$/gim, '');
|
|
183
|
+
if (stripQuestion) {
|
|
184
|
+
out = stripQuestionBlocks(out);
|
|
185
|
+
}
|
|
186
|
+
out = out.replace(/\n{3,}/g, '\n\n').trim();
|
|
187
|
+
// Defense-in-depth: strip proprietary prompt dumps that escaped model policy.
|
|
188
|
+
return scrubProprietaryLeak(out);
|
|
189
|
+
}
|
|
190
|
+
//# sourceMappingURL=outputCleaning.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"outputCleaning.js","sourceRoot":"","sources":["../../../src/agents/council/outputCleaning.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAE3D,MAAM,eAAe,GAAG,gBAAgB,CAAC;AACzC,MAAM,mBAAmB,GAAG,WAAW,CAAC;AAQxC;;;;GAIG;AACH,SAAS,yBAAyB,CAAC,CAAS;IAC1C,MAAM,KAAK,GAAG,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC7B,IAAI,KAAK,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IAC3B,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,IAAI,QAAQ,GAAG,KAAK,CAAC;IACrB,IAAI,MAAM,GAAG,KAAK,CAAC;IACnB,KAAK,IAAI,CAAC,GAAG,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACtC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,CAAE,CAAC;QACjB,IAAI,QAAQ,EAAE,CAAC;YAC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batim from agents/councilApi.ts.
|
|
4
|
+
*/
|
|
5
|
+
import type { BrainEvent } from '../../shared/events.js';
|
|
6
|
+
import type { ProviderStreamFn } from '../../core/AgentHarness.js';
|
|
7
|
+
import type { AgentRole } from '../../types/index.js';
|
|
8
|
+
import type { SystemPromptConfig, SystemPromptModule } from '../../types/systemTypes.js';
|
|
9
|
+
import type { CouncilRunMode } from '../../council/runMode.js';
|
|
10
|
+
import type { ToolEmissionCheckResult, ToolEmissionRequirement } from './toolEmission.js';
|
|
11
|
+
import type { PureCouncilConfig } from './types.js';
|
|
12
|
+
/**
|
|
13
|
+
* Maximum number of forced retry turns per council member. Cap of 1
|
|
14
|
+
* keeps the worst-case council latency bounded (a single extra turn per
|
|
15
|
+
* member × 4 design-phase members ≈ 30-60 s on top of the base run).
|
|
16
|
+
* Going above 1 tends to produce hallucinated tool arguments because
|
|
17
|
+
* the model has already spent its "tool budget" on exploration.
|
|
18
|
+
*/
|
|
19
|
+
export declare const MAX_RETRY_PER_MEMBER = 1;
|
|
20
|
+
/**
|
|
21
|
+
* Pure helper: should the council loop spin up one more forced turn for
|
|
22
|
+
* this member to recover the missing tool emissions?
|
|
23
|
+
*
|
|
24
|
+
* Returns true when:
|
|
25
|
+
* - at least one tool is still missing after the post-condition check, AND
|
|
26
|
+
* - the retry budget for this member has not been exhausted.
|
|
27
|
+
*
|
|
28
|
+
* Returns false otherwise. Tested as a pure function so the council
|
|
29
|
+
* loop can branch on the answer without coupling to AgentHarness.
|
|
30
|
+
*/
|
|
31
|
+
export declare function shouldRetryMember(missingToolNames: string[], attemptsSoFar: number): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Build the one-line prompt that the retry turn sends to the model.
|
|
34
|
+
* The shape matters: the model is primed by its role prompt to produce
|
|
35
|
+
* prose, so the retry prompt must be unambiguous, imperative, and
|
|
36
|
+
* scoped to ONLY the missing tools.
|
|
37
|
+
*
|
|
38
|
+
* Format: "You did not emit: <names>. Call <names> NOW with concrete
|
|
39
|
+
* arguments. No prose."
|
|
40
|
+
*
|
|
41
|
+
* Multiple tools are listed comma-separated in the same call so the
|
|
42
|
+
* model can satisfy them in a single tool_calls turn (which is the
|
|
43
|
+
* cheapest path through AgentHarness).
|
|
44
|
+
*/
|
|
45
|
+
export declare function buildRetryPrompt(missingToolNames: string[]): string;
|
|
46
|
+
export declare function runRetryTurnForMember(args: {
|
|
47
|
+
agent: AgentRole;
|
|
48
|
+
missingToolNames: string[];
|
|
49
|
+
/**
|
|
50
|
+
* Per-tool minimum emission count. The retry budget is the SUM of these
|
|
51
|
+
* values (not just the number of distinct missing tools), because
|
|
52
|
+
* requirements like `createTask min: 12` need 12 separate calls even
|
|
53
|
+
* though only 1 distinct tool is missing. If omitted, the budget
|
|
54
|
+
* defaults to `missingToolNames.length` (suitable for tools like
|
|
55
|
+
* createDocument that need only one call).
|
|
56
|
+
*/
|
|
57
|
+
minPerTool?: Record<string, number>;
|
|
58
|
+
executableTools: ReadonlySet<string> | null;
|
|
59
|
+
userMessage: string;
|
|
60
|
+
ragContext: string;
|
|
61
|
+
workspaceContext: string;
|
|
62
|
+
priorOutputs: {
|
|
63
|
+
name: string;
|
|
64
|
+
role: string;
|
|
65
|
+
content: string;
|
|
66
|
+
}[];
|
|
67
|
+
aiConfig?: SystemPromptConfig;
|
|
68
|
+
sessionId: string;
|
|
69
|
+
effectiveModel: string;
|
|
70
|
+
effectiveProvider: string;
|
|
71
|
+
eventBus?: BrainEvent['sessionId'] extends string ? unknown : never;
|
|
72
|
+
toolRegistry?: unknown;
|
|
73
|
+
providerStream: ProviderStreamFn;
|
|
74
|
+
runMode?: CouncilRunMode;
|
|
75
|
+
/** Override the default buildRetryPrompt message. */
|
|
76
|
+
retryPrompt?: string;
|
|
77
|
+
/**
|
|
78
|
+
* v1.7.0 (agy audit M2): pre-built language module. Optional — when
|
|
79
|
+
* omitted, no language-policy system message is added (preserves the
|
|
80
|
+
* pre-1.7 retry behavior for tests and callers that don't track it).
|
|
81
|
+
* `runCouncilPure` threads the module it built once per run.
|
|
82
|
+
*/
|
|
83
|
+
languageModule?: SystemPromptModule;
|
|
84
|
+
/** Cooperative cancel — skip the retry turn when already aborted. */
|
|
85
|
+
signal?: AbortSignal;
|
|
86
|
+
}): AsyncGenerator<BrainEvent, string[], void>;
|
|
87
|
+
/**
|
|
88
|
+
* Shared retry orchestrator used by specialist, oracle, and chairman
|
|
89
|
+
* loops. Given the post-condition check result, decides whether to
|
|
90
|
+
* spin up a forced retry turn, and if so yields the events from that
|
|
91
|
+
* turn back to the caller (so the UI sees them) while mutating the
|
|
92
|
+
* shared `emittedToolNames` array (so the next post-condition check
|
|
93
|
+
* sees the union of original + retry emissions).
|
|
94
|
+
*
|
|
95
|
+
* The retry turn is skipped when:
|
|
96
|
+
* - the check passed (no missing tools), OR
|
|
97
|
+
* - the retry budget for this member is exhausted (shouldRetryMember).
|
|
98
|
+
*
|
|
99
|
+
* On retry failure (network error, model error, etc.) the function logs
|
|
100
|
+
* the error and continues — it never throws. The next post-condition
|
|
101
|
+
* check will simply re-warn.
|
|
102
|
+
*/
|
|
103
|
+
export declare function applyRetryIfMissing(args: {
|
|
104
|
+
agent: AgentRole;
|
|
105
|
+
check: ToolEmissionCheckResult;
|
|
106
|
+
/**
|
|
107
|
+
* Original per-member requirements. Used to compute the retry budget
|
|
108
|
+
* (sum of `min` for each missing tool) so the model can satisfy all
|
|
109
|
+
* minimums in one tool_calls turn. If omitted, defaults to 1 per
|
|
110
|
+
* distinct missing tool.
|
|
111
|
+
*/
|
|
112
|
+
requirements?: ToolEmissionRequirement[];
|
|
113
|
+
emittedToolNames: string[];
|
|
114
|
+
executableNames: ReadonlySet<string> | null;
|
|
115
|
+
sessionId: string;
|
|
116
|
+
userMessage: string;
|
|
117
|
+
agentOutputs: {
|
|
118
|
+
name: string;
|
|
119
|
+
role: string;
|
|
120
|
+
content: string;
|
|
121
|
+
}[];
|
|
122
|
+
config: PureCouncilConfig;
|
|
123
|
+
effectiveProvider: string;
|
|
124
|
+
effectiveModel: string;
|
|
125
|
+
/** Callback to bump the per-member tool-call counter on each retry emission. */
|
|
126
|
+
onToolCall: () => void;
|
|
127
|
+
/** v1.7.0 (Pass-2 agy finding): see applyCompletionRetry. */
|
|
128
|
+
languageModule?: SystemPromptModule;
|
|
129
|
+
}): AsyncGenerator<BrainEvent, void, void>;
|
|
130
|
+
//# sourceMappingURL=retryTurn.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retryTurn.d.ts","sourceRoot":"","sources":["../../../src/agents/council/retryTurn.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEzD,OAAO,KAAK,EAAiB,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAElF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,KAAK,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AACzF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAI/D,OAAO,KAAK,EAAE,uBAAuB,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAC1F,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,IAAI,CAAC;AAEtC;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAC/B,gBAAgB,EAAE,MAAM,EAAE,EAC1B,aAAa,EAAE,MAAM,GACpB,OAAO,CAIT;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,CAAC,gBAAgB,EAAE,MAAM,EAAE,GAAG,MAAM,CAGnE;AAuBD,wBAAuB,qBAAqB,CAAC,IAAI,EAAE;IACjD,KAAK,EAAE,SAAS,CAAC;IACjB,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B;;;;;;;OAOG;IACH,UAAU,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