@steerable/agent-protocol 0.14.3 → 0.14.4
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/index.d.ts +1 -0
- package/dist/index.js +2 -1
- package/dist/proposed-plan-parser.d.ts +49 -0
- package/dist/proposed-plan-parser.js +236 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export * from "./runtime-target.js";
|
|
|
9
9
|
export * from "./turn-failure-kind.js";
|
|
10
10
|
export * from "./shell-command-classifier.js";
|
|
11
11
|
export * from "./tool-transcript-model.js";
|
|
12
|
+
export * from "./proposed-plan-parser.js";
|
|
12
13
|
export * from "./generated/AgentSession.js";
|
|
13
14
|
export * from "./generated/HarnessTrace.js";
|
|
14
15
|
export * from "./generated/TraceSpan.js";
|
package/dist/index.js
CHANGED
|
@@ -9,9 +9,10 @@ export * from "./generated/CommandSafetyPattern.js";
|
|
|
9
9
|
export * from "./runtime-target.js";
|
|
10
10
|
// Failure vocabulary shared by the host shell and the command line
|
|
11
11
|
export * from "./turn-failure-kind.js";
|
|
12
|
-
// Read-only shell intent classifier
|
|
12
|
+
// Read-only shell intent classifier, tool transcript unwrapping, and proposed-plan parser shared by Web and TUI
|
|
13
13
|
export * from "./shell-command-classifier.js";
|
|
14
14
|
export * from "./tool-transcript-model.js";
|
|
15
|
+
export * from "./proposed-plan-parser.js";
|
|
15
16
|
// Tier 3 runtime models
|
|
16
17
|
export * from "./generated/AgentSession.js";
|
|
17
18
|
export * from "./generated/HarnessTrace.js";
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export interface ProposedPlanStep {
|
|
2
|
+
text: string;
|
|
3
|
+
done: boolean;
|
|
4
|
+
}
|
|
5
|
+
export interface ParsedProposedPlan {
|
|
6
|
+
/** Wire syntax that produced this plan: `<proposed_plan>` tag or legacy ```` ```plan ```` fence. */
|
|
7
|
+
syntax: 'tag' | 'fence';
|
|
8
|
+
/** Leading `# Title` extracted from the plan body, or null if absent. */
|
|
9
|
+
title: string | null;
|
|
10
|
+
/** Complete trimmed markdown inside the plan block (including any leading `# Title`). */
|
|
11
|
+
markdown: string;
|
|
12
|
+
/** Plan body with the leading `# Title` stripped so card headers do not repeat it. */
|
|
13
|
+
bodyMarkdown: string;
|
|
14
|
+
/** Extracted checklist / bullet / numbered steps (ignoring lines inside nested code fences). */
|
|
15
|
+
steps: ProposedPlanStep[];
|
|
16
|
+
/** Non-step plain lines (kept for legacy simple-list compatibility). */
|
|
17
|
+
notes: string[];
|
|
18
|
+
/** True when the body uses rich Markdown constructs (subheadings, nested code fences, tables, etc.). */
|
|
19
|
+
hasRichMarkdown: boolean;
|
|
20
|
+
/** True when the closing `</proposed_plan>` tag or closing ```` ``` ```` fence has arrived. */
|
|
21
|
+
complete: boolean;
|
|
22
|
+
}
|
|
23
|
+
export type MessagePlanSegment = {
|
|
24
|
+
kind: 'markdown';
|
|
25
|
+
content: string;
|
|
26
|
+
} | {
|
|
27
|
+
kind: 'plan';
|
|
28
|
+
plan: ParsedProposedPlan;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Parse the inner markdown of a `<proposed_plan>` or ```` ```plan ```` block.
|
|
32
|
+
*/
|
|
33
|
+
export declare function parseProposedPlanBody(raw: string): Omit<ParsedProposedPlan, 'syntax' | 'complete'>;
|
|
34
|
+
/**
|
|
35
|
+
* Split an assistant message into ordinary Markdown segments and structured
|
|
36
|
+
* proposed-plan segments (`<proposed_plan>...</proposed_plan>` or legacy ```` ```plan ````).
|
|
37
|
+
*
|
|
38
|
+
* Literal `<proposed_plan>` examples inside outer code fences are ignored so
|
|
39
|
+
* discussions about the tag syntax never trigger false plan cards.
|
|
40
|
+
*/
|
|
41
|
+
export declare function splitMessageWithProposedPlans(text: string): MessagePlanSegment[];
|
|
42
|
+
/**
|
|
43
|
+
* Extract all structured plans emitted in an assistant message.
|
|
44
|
+
*/
|
|
45
|
+
export declare function extractProposedPlans(text: string): ParsedProposedPlan[];
|
|
46
|
+
/**
|
|
47
|
+
* Return the latest non-empty proposed plan in an assistant message, or null if none.
|
|
48
|
+
*/
|
|
49
|
+
export declare function extractLatestProposedPlan(text: string): ParsedProposedPlan | null;
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
const CHECKBOX_RE = /^(?:[-*+]\s+|\d+[.、)]\s+)?\[([ xX])\]\s+(.*)$/;
|
|
2
|
+
const BULLET_RE = /^[-*+]\s+(.*)$/;
|
|
3
|
+
const NUMBERED_RE = /^\d+[.、)]\s+(.*)$/;
|
|
4
|
+
const OPEN_FENCE_RE = /^(\s*)(`{3,}|~{3,})([^\n]*)$/;
|
|
5
|
+
const OPEN_PROPOSED_TAG_RE = /^\s*<proposed_plan>\s*$/i;
|
|
6
|
+
const CLOSE_PROPOSED_TAG_RE = /^\s*<\/proposed_plan>\s*$/i;
|
|
7
|
+
/**
|
|
8
|
+
* Parse the inner markdown of a `<proposed_plan>` or ```` ```plan ```` block.
|
|
9
|
+
*/
|
|
10
|
+
export function parseProposedPlanBody(raw) {
|
|
11
|
+
const normalized = raw.replace(/\r\n/g, '\n');
|
|
12
|
+
const lines = normalized.split('\n');
|
|
13
|
+
let title = null;
|
|
14
|
+
let titleLineIndex = -1;
|
|
15
|
+
const steps = [];
|
|
16
|
+
const notes = [];
|
|
17
|
+
let hasNestedFence = false;
|
|
18
|
+
let hasSubheading = false;
|
|
19
|
+
let hasTable = false;
|
|
20
|
+
let innerFenceChar = null;
|
|
21
|
+
let innerFenceLen = 0;
|
|
22
|
+
for (let i = 0; i < lines.length; i++) {
|
|
23
|
+
const line = lines[i];
|
|
24
|
+
const trimmed = line.trim();
|
|
25
|
+
if (innerFenceChar !== null) {
|
|
26
|
+
const closeRe = new RegExp(`^\\s*${innerFenceChar}{${innerFenceLen},}\\s*$`);
|
|
27
|
+
if (closeRe.test(line)) {
|
|
28
|
+
innerFenceChar = null;
|
|
29
|
+
innerFenceLen = 0;
|
|
30
|
+
}
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
const fenceMatch = line.match(OPEN_FENCE_RE);
|
|
34
|
+
if (fenceMatch) {
|
|
35
|
+
hasNestedFence = true;
|
|
36
|
+
innerFenceChar = fenceMatch[2][0];
|
|
37
|
+
innerFenceLen = fenceMatch[2].length;
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
if (!trimmed)
|
|
41
|
+
continue;
|
|
42
|
+
if (/^#\s+/.test(trimmed) && title === null && steps.length === 0 && notes.length === 0) {
|
|
43
|
+
const candidate = trimmed.replace(/^#\s+/, '').trim();
|
|
44
|
+
if (candidate) {
|
|
45
|
+
title = candidate;
|
|
46
|
+
titleLineIndex = i;
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (/^#{2,6}\s+/.test(trimmed)) {
|
|
51
|
+
hasSubheading = true;
|
|
52
|
+
notes.push(trimmed);
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
if (/^\|.+\|$/.test(trimmed)) {
|
|
56
|
+
hasTable = true;
|
|
57
|
+
notes.push(trimmed);
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
const checkbox = trimmed.match(CHECKBOX_RE);
|
|
61
|
+
if (checkbox) {
|
|
62
|
+
const text = checkbox[2].trim();
|
|
63
|
+
if (text)
|
|
64
|
+
steps.push({ text, done: checkbox[1] !== ' ' });
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
const bullet = trimmed.match(BULLET_RE) ?? trimmed.match(NUMBERED_RE);
|
|
68
|
+
if (bullet) {
|
|
69
|
+
const text = bullet[1].trim();
|
|
70
|
+
if (text)
|
|
71
|
+
steps.push({ text, done: false });
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
notes.push(trimmed);
|
|
75
|
+
}
|
|
76
|
+
const markdown = normalized.trim();
|
|
77
|
+
const bodyLines = titleLineIndex >= 0
|
|
78
|
+
? [...lines.slice(0, titleLineIndex), ...lines.slice(titleLineIndex + 1)]
|
|
79
|
+
: lines;
|
|
80
|
+
const bodyMarkdown = bodyLines.join('\n').trim();
|
|
81
|
+
const hasRichMarkdown = hasNestedFence ||
|
|
82
|
+
hasSubheading ||
|
|
83
|
+
hasTable ||
|
|
84
|
+
(notes.length > 0 && steps.length === 0) ||
|
|
85
|
+
notes.some((n) => n.length > 100 || /`[^`]+`|\*\*[^*]+\*\*/.test(n));
|
|
86
|
+
return {
|
|
87
|
+
title,
|
|
88
|
+
markdown,
|
|
89
|
+
bodyMarkdown,
|
|
90
|
+
steps,
|
|
91
|
+
notes,
|
|
92
|
+
hasRichMarkdown,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Split an assistant message into ordinary Markdown segments and structured
|
|
97
|
+
* proposed-plan segments (`<proposed_plan>...</proposed_plan>` or legacy ```` ```plan ````).
|
|
98
|
+
*
|
|
99
|
+
* Literal `<proposed_plan>` examples inside outer code fences are ignored so
|
|
100
|
+
* discussions about the tag syntax never trigger false plan cards.
|
|
101
|
+
*/
|
|
102
|
+
export function splitMessageWithProposedPlans(text) {
|
|
103
|
+
if (!text)
|
|
104
|
+
return [];
|
|
105
|
+
const normalized = text.replace(/\r\n/g, '\n');
|
|
106
|
+
const lines = normalized.split('\n');
|
|
107
|
+
const segments = [];
|
|
108
|
+
let markdownBuf = [];
|
|
109
|
+
let outerFenceChar = null;
|
|
110
|
+
let outerFenceLen = 0;
|
|
111
|
+
let activePlanMode = null;
|
|
112
|
+
let planFenceChar = '`';
|
|
113
|
+
let planFenceLen = 3;
|
|
114
|
+
let planInnerFenceChar = null;
|
|
115
|
+
let planInnerFenceLen = 0;
|
|
116
|
+
let planBuf = [];
|
|
117
|
+
const flushMarkdown = () => {
|
|
118
|
+
if (markdownBuf.length === 0)
|
|
119
|
+
return;
|
|
120
|
+
const joined = markdownBuf.join('\n');
|
|
121
|
+
if (joined.trim().length > 0) {
|
|
122
|
+
segments.push({ kind: 'markdown', content: joined });
|
|
123
|
+
}
|
|
124
|
+
markdownBuf = [];
|
|
125
|
+
};
|
|
126
|
+
const emitPlan = (syntax, complete) => {
|
|
127
|
+
const rawPlan = planBuf.join('\n');
|
|
128
|
+
planBuf = [];
|
|
129
|
+
const parsed = parseProposedPlanBody(rawPlan);
|
|
130
|
+
if (!parsed.markdown && parsed.steps.length === 0 && complete) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
segments.push({
|
|
134
|
+
kind: 'plan',
|
|
135
|
+
plan: {
|
|
136
|
+
syntax,
|
|
137
|
+
complete,
|
|
138
|
+
...parsed,
|
|
139
|
+
},
|
|
140
|
+
});
|
|
141
|
+
};
|
|
142
|
+
for (const line of lines) {
|
|
143
|
+
if (activePlanMode === 'tag') {
|
|
144
|
+
if (planInnerFenceChar !== null) {
|
|
145
|
+
const closeInner = new RegExp(`^\\s*${planInnerFenceChar}{${planInnerFenceLen},}\\s*$`);
|
|
146
|
+
if (closeInner.test(line)) {
|
|
147
|
+
planInnerFenceChar = null;
|
|
148
|
+
planInnerFenceLen = 0;
|
|
149
|
+
}
|
|
150
|
+
planBuf.push(line);
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
const openInner = line.match(OPEN_FENCE_RE);
|
|
154
|
+
if (openInner) {
|
|
155
|
+
planInnerFenceChar = openInner[2][0];
|
|
156
|
+
planInnerFenceLen = openInner[2].length;
|
|
157
|
+
planBuf.push(line);
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
if (CLOSE_PROPOSED_TAG_RE.test(line)) {
|
|
161
|
+
emitPlan('tag', true);
|
|
162
|
+
activePlanMode = null;
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
planBuf.push(line);
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
if (activePlanMode === 'fence') {
|
|
169
|
+
const closePlanFence = new RegExp(`^\\s*${planFenceChar}{${planFenceLen},}\\s*$`);
|
|
170
|
+
if (closePlanFence.test(line)) {
|
|
171
|
+
emitPlan('fence', true);
|
|
172
|
+
activePlanMode = null;
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
planBuf.push(line);
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
// Outside any plan block: track ordinary code fences so `<proposed_plan>` inside
|
|
179
|
+
// an example code block is treated as literal code, not a plan card.
|
|
180
|
+
if (outerFenceChar !== null) {
|
|
181
|
+
const closeOuter = new RegExp(`^\\s*${outerFenceChar}{${outerFenceLen},}\\s*$`);
|
|
182
|
+
if (closeOuter.test(line)) {
|
|
183
|
+
outerFenceChar = null;
|
|
184
|
+
outerFenceLen = 0;
|
|
185
|
+
}
|
|
186
|
+
markdownBuf.push(line);
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
if (OPEN_PROPOSED_TAG_RE.test(line)) {
|
|
190
|
+
flushMarkdown();
|
|
191
|
+
activePlanMode = 'tag';
|
|
192
|
+
planInnerFenceChar = null;
|
|
193
|
+
planInnerFenceLen = 0;
|
|
194
|
+
planBuf = [];
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
const fenceMatch = line.match(OPEN_FENCE_RE);
|
|
198
|
+
if (fenceMatch) {
|
|
199
|
+
const marker = fenceMatch[2];
|
|
200
|
+
const info = fenceMatch[3].trim().toLowerCase();
|
|
201
|
+
if (info === 'plan') {
|
|
202
|
+
flushMarkdown();
|
|
203
|
+
activePlanMode = 'fence';
|
|
204
|
+
planFenceChar = marker[0];
|
|
205
|
+
planFenceLen = marker.length;
|
|
206
|
+
planBuf = [];
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
outerFenceChar = marker[0];
|
|
210
|
+
outerFenceLen = marker.length;
|
|
211
|
+
markdownBuf.push(line);
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
markdownBuf.push(line);
|
|
215
|
+
}
|
|
216
|
+
if (activePlanMode !== null) {
|
|
217
|
+
emitPlan(activePlanMode, false);
|
|
218
|
+
}
|
|
219
|
+
flushMarkdown();
|
|
220
|
+
return segments;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Extract all structured plans emitted in an assistant message.
|
|
224
|
+
*/
|
|
225
|
+
export function extractProposedPlans(text) {
|
|
226
|
+
return splitMessageWithProposedPlans(text)
|
|
227
|
+
.filter((seg) => seg.kind === 'plan')
|
|
228
|
+
.map((seg) => seg.plan);
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Return the latest non-empty proposed plan in an assistant message, or null if none.
|
|
232
|
+
*/
|
|
233
|
+
export function extractLatestProposedPlan(text) {
|
|
234
|
+
const plans = extractProposedPlans(text).filter((plan) => plan.markdown.length > 0 || plan.steps.length > 0);
|
|
235
|
+
return plans.length > 0 ? plans[plans.length - 1] : null;
|
|
236
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@steerable/agent-protocol",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.4",
|
|
4
4
|
"description": "Steerable framework Tier 1 — wire-format types (SSEEvent, ChatMessage, ToolCall, ToolResult, AgentSession, HarnessTrace, sidecar JSON-RPC) shared by every Steerable client and server.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://steerableframework.com/",
|