opencode-model-router 2.1.0 → 2.3.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/CHANGELOG.md +86 -0
- package/README.md +44 -5
- package/package.json +4 -1
- package/src/commands/output.ts +4 -1
- package/src/compat/child-session.ts +43 -0
- package/src/compat/v2-client.ts +107 -7
- package/src/compat/v2-hooks.ts +174 -47
- package/src/escalate/attempt-recorder.ts +263 -0
- package/src/escalate/ladder.ts +484 -10
- package/src/escalate/resume.ts +208 -0
- package/src/escalate/variants.ts +391 -0
- package/src/index.ts +557 -61
- package/src/router/build-info.ts +151 -0
- package/src/router/config.ts +1691 -67
- package/src/router/protocol.ts +47 -0
- package/src/router/sessions.ts +441 -9
- package/src/routing/advisor/findings.ts +706 -0
- package/src/routing/advisor/index.ts +606 -0
- package/src/routing/classify/backends/host.ts +163 -0
- package/src/routing/classify/backends/openai-compatible.ts +275 -0
- package/src/routing/classify/backends/shared.ts +741 -0
- package/src/routing/classify/backends/typesafe.ts +315 -0
- package/src/routing/classify/fences.ts +96 -0
- package/src/routing/classify/index.ts +576 -0
- package/src/routing/classify/route-line.ts +298 -0
- package/src/routing/classify/rules.ts +607 -0
- package/src/routing/classify/scrub.ts +214 -0
- package/src/routing/classify/state.ts +148 -0
- package/src/routing/classify/text.ts +20 -0
- package/src/routing/classify/types.ts +1280 -0
- package/src/routing/commands/annotate-plan.ts +652 -0
- package/src/routing/commands/stats.ts +131 -0
- package/src/routing/commands/v1-roles.ts +64 -0
- package/src/routing/engine/index.ts +32 -0
- package/src/routing/engine/kernel.ts +597 -0
- package/src/routing/engine/ladders.ts +561 -0
- package/src/routing/engine/plan.ts +404 -0
- package/src/routing/engine/protocol-line.ts +133 -0
- package/src/routing/engine/simulate.ts +167 -0
- package/src/routing/engine/types.ts +270 -0
- package/src/routing/file-lock.ts +53 -0
- package/src/routing/outcomes/beta.ts +141 -0
- package/src/routing/outcomes/cost.ts +313 -0
- package/src/routing/outcomes/index.ts +172 -0
- package/src/routing/outcomes/ingest.ts +812 -0
- package/src/routing/outcomes/persist.ts +1058 -0
- package/src/routing/outcomes/stats.ts +602 -0
- package/src/routing/outcomes/store.ts +653 -0
- package/src/routing/outcomes/types.ts +954 -0
- package/src/routing/wire/dispatch.ts +799 -0
- package/src/routing/wire/hint.ts +208 -0
- package/src/routing/wire/host-info.ts +256 -0
- package/src/routing/wire/runtime.ts +259 -0
- package/src/v2.ts +15 -1
- package/tiers.json +43 -0
|
@@ -0,0 +1,652 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `/annotate-plan` with route lines (M8, plan F3, Phase 2.4.4).
|
|
3
|
+
*
|
|
4
|
+
* The command itself stays what it was: a prompt template that tells the model to tag a plan's steps (`[tier:X]`) and add
|
|
5
|
+
* `[acceptance]` blocks, byte for byte. What this adds, when the engine is live on v2 (shadow, advise or enforce; static and v1 add
|
|
6
|
+
* nothing, §1.2), is the part a model should not guess: it reads the plan file, splits it into steps (fence-aware), classifies every step
|
|
7
|
+
* with ONE batched `classifyMany` call (rules per step, then the configured backend, rules again on any failure), runs 1.4's
|
|
8
|
+
* `annotateSteps` (class → start tier, pins, route lines) and hands the model the exact lines to insert as an extra message part.
|
|
9
|
+
*
|
|
10
|
+
* - Additive: no line is removed or reordered. An existing `[tier:X]` or `[route …]` is authoritative. The only edits to an existing line
|
|
11
|
+
* are `[tier:X]` inserted after the step's list marker (the template's "at the START of each step") and ` pin` appended to an existing
|
|
12
|
+
* route line when its step is `[tier:heavy]` or a QA step (A26); both are reported as such.
|
|
13
|
+
* - Safe with code: nothing inside a fenced block (``` or ~~~, nested or not) starts a step, is a tag, or receives a route line.
|
|
14
|
+
* - The hook does not write the plan file. `annotatePlanText` produces the whole annotated text (used by the tests and by anyone who wants
|
|
15
|
+
* to write it); the message part lists, step by step, the exact lines the model has to write, derived from the same additions.
|
|
16
|
+
*
|
|
17
|
+
* Pure apart from the injected `classifyMany`, and the file reads of `locatePlan`.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { readFile, readdir, stat } from "node:fs/promises";
|
|
21
|
+
import { isAbsolute, join, resolve } from "node:path";
|
|
22
|
+
import type { RouterConfig } from "../../router/config";
|
|
23
|
+
import { classifyMany as classifyManyWith, type ClassifyDeps } from "../classify";
|
|
24
|
+
import { parseRouteLine } from "../classify/route-line";
|
|
25
|
+
import type { ClassifyInput, ClassifyResult } from "../classify/types";
|
|
26
|
+
import { annotateSteps } from "../engine";
|
|
27
|
+
import type { AnnotateDeps, AnnotatedStep, PlanStep } from "../engine";
|
|
28
|
+
import type { HostAgentInfo } from "../engine";
|
|
29
|
+
import { agentModelRef, grantsOfRules, parseRules } from "../wire/host-info";
|
|
30
|
+
import type { EngineRuntime } from "../wire/runtime";
|
|
31
|
+
|
|
32
|
+
// ---------------------------------------------------------------------------
|
|
33
|
+
// Splitting a plan into steps
|
|
34
|
+
// ---------------------------------------------------------------------------
|
|
35
|
+
|
|
36
|
+
export interface PlacedStep extends PlanStep {
|
|
37
|
+
/** 1-based line of the step's first line. */
|
|
38
|
+
readonly line: number;
|
|
39
|
+
/** Character range of the step in the plan text (`to` exclusive; it includes the terminator of the step's last line when there is one). */
|
|
40
|
+
readonly from: number;
|
|
41
|
+
readonly to: number;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const LINE_SPLIT_RE = /(\r\n|\n|\r)/;
|
|
45
|
+
const LIST_ITEM_RE = /^( {0,3})([-*+]|\d{1,9}[.)])([ \t]+)\S/;
|
|
46
|
+
const HEADING_RE = /^ {0,3}#{1,6}(?:[ \t]|$)/;
|
|
47
|
+
const THEMATIC_RE = /^ {0,3}(?:(?:-[ \t]*){3,}|(?:\*[ \t]*){3,}|(?:_[ \t]*){3,})$/;
|
|
48
|
+
const ACCEPT_OPEN_RE = /^\s*\[acceptance\]\s*$/i;
|
|
49
|
+
const ACCEPT_CLOSE_RE = /^\s*\[\/acceptance\]\s*$/i;
|
|
50
|
+
const STEP_HEADING_RE = /^ {0,3}#{2,6}[ \t]+(?:step|task|phase|stage|milestone)\b/i;
|
|
51
|
+
|
|
52
|
+
/** Columns of leading whitespace (a tab counts as four, like the route-line parser). */
|
|
53
|
+
function indentOf(line: string): number {
|
|
54
|
+
let columns = 0;
|
|
55
|
+
for (const ch of line) {
|
|
56
|
+
if (ch === " ") columns += 1;
|
|
57
|
+
else if (ch === "\t") columns += 4;
|
|
58
|
+
else break;
|
|
59
|
+
}
|
|
60
|
+
return columns;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** A fence run at the start of `text` (indentation already measured): the character and length, or `null` (a backtick run's info string may not hold a backtick). */
|
|
64
|
+
function fenceRunOf(text: string): { readonly char: string; readonly length: number } | null {
|
|
65
|
+
const match = /^(`{3,}|~{3,})(.*)$/.exec(text);
|
|
66
|
+
const run = match?.[1];
|
|
67
|
+
if (match === null || run === undefined || (run[0] === "`" && (match[2] ?? "").includes("`"))) return null;
|
|
68
|
+
return { char: run[0] as string, length: run.length };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Which lines are code or comment, the way the step scanner needs it (QA-2.4-12, QA-2.4-R2-2, -R2-8, -R2-9). Like the shared `fenceMask`
|
|
73
|
+
* (an opener, a closer of the same character at least as long, nothing but whitespace after it) with differences that matter inside a plan:
|
|
74
|
+
* - a fence opened inside a list item ends where the item does: a non-blank line indented less than the item's content column closes it
|
|
75
|
+
* (CommonMark), so a closer that is not valid (`closerWithInfo`: ``` followed by an info string) can no longer swallow every later
|
|
76
|
+
* step to the end of the file;
|
|
77
|
+
* - indentation is measured from the container: a fence (and its closer, and a comment) inside an item may be indented up to 3 columns
|
|
78
|
+
* PAST the item's content column (`10. step` has its content at column 4), not 3 columns from the margin;
|
|
79
|
+
* - an item whose content STARTS with a fence opener (`1. ```bash`) opens the fence on its own line: the item line stays a step line (it
|
|
80
|
+
* is not masked), everything after it up to the closer is code;
|
|
81
|
+
* - an HTML comment block (`<!--` … `-->`, at most 3 columns from its container) is masked, so a list inside one is never a step.
|
|
82
|
+
* A fence at the top level (not inside an item) still runs to its closer, or to the end of the text.
|
|
83
|
+
*/
|
|
84
|
+
export function structureMask(lines: readonly string[]): boolean[] {
|
|
85
|
+
const mask: boolean[] = new Array<boolean>(lines.length).fill(false);
|
|
86
|
+
let fence: { readonly char: string; readonly length: number; readonly itemOffset: number | null } | null = null;
|
|
87
|
+
let comment = false;
|
|
88
|
+
let itemOffset: number | null = null; // content column of the list item we are in, if any
|
|
89
|
+
let gap = false;
|
|
90
|
+
/** The column a line is measured from: the item's content column when the line reaches it, else the margin. */
|
|
91
|
+
const baseOf = (line: string, offset: number | null): number => (offset !== null && indentOf(line) >= offset ? offset : 0);
|
|
92
|
+
for (let i = 0; i < lines.length; i += 1) {
|
|
93
|
+
const line = lines[i] as string;
|
|
94
|
+
if (fence !== null) {
|
|
95
|
+
const relative = indentOf(line) - (fence.itemOffset ?? 0);
|
|
96
|
+
const closer = relative >= 0 && relative <= 3 ? /^(`{3,}|~{3,})[ \t]*$/.exec(line.trimStart()) : null;
|
|
97
|
+
if (closer !== null && (closer[1] as string)[0] === fence.char && (closer[1] as string).length >= fence.length) {
|
|
98
|
+
mask[i] = true;
|
|
99
|
+
fence = null;
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
if (line.trim() === "" || fence.itemOffset === null || indentOf(line) >= fence.itemOffset) {
|
|
103
|
+
mask[i] = true;
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
fence = null; // the item ended: so did its code block; this line is an ordinary line
|
|
107
|
+
}
|
|
108
|
+
if (comment) {
|
|
109
|
+
mask[i] = true;
|
|
110
|
+
if (line.includes("-->")) comment = false;
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
if (line.trim() === "") {
|
|
114
|
+
gap = true;
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
if (HEADING_RE.test(line) || THEMATIC_RE.test(line)) {
|
|
118
|
+
itemOffset = null;
|
|
119
|
+
gap = false;
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
const relative = indentOf(line) - baseOf(line, itemOffset);
|
|
123
|
+
const run = relative <= 3 ? fenceRunOf(line.trimStart()) : null;
|
|
124
|
+
if (run !== null) {
|
|
125
|
+
if (itemOffset !== null && indentOf(line) < itemOffset) itemOffset = null; // not indented as the item's content: not part of it
|
|
126
|
+
mask[i] = true;
|
|
127
|
+
fence = { ...run, itemOffset };
|
|
128
|
+
gap = false;
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
if (relative <= 3 && line.trimStart().startsWith("<!--")) {
|
|
132
|
+
if (itemOffset !== null && indentOf(line) < itemOffset) itemOffset = null;
|
|
133
|
+
mask[i] = true;
|
|
134
|
+
comment = !line.slice(line.indexOf("<!--") + 4).includes("-->");
|
|
135
|
+
gap = false;
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
const item = LIST_ITEM_RE.exec(line);
|
|
139
|
+
if (item !== null) {
|
|
140
|
+
const indent = indentOf(line);
|
|
141
|
+
const spaces = indentOf(item[3] as string);
|
|
142
|
+
const own = indent + (item[2] as string).length + spaces; // this item's content column
|
|
143
|
+
if (itemOffset === null || indent < itemOffset) itemOffset = own;
|
|
144
|
+
// `1. ```bash`: the item's content opens a code block on the item line itself (QA-2.4-R2-2)
|
|
145
|
+
const opened = spaces <= 4 ? fenceRunOf(line.slice((item[1] as string).length + (item[2] as string).length + (item[3] as string).length)) : null;
|
|
146
|
+
if (opened !== null) fence = { ...opened, itemOffset: own };
|
|
147
|
+
gap = false;
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
if (itemOffset !== null && gap && indentOf(line) < itemOffset) itemOffset = null; // a paragraph after a blank line ends the item
|
|
151
|
+
gap = false;
|
|
152
|
+
}
|
|
153
|
+
return mask;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** The step's first line is a list item whose content opens a code block (`1. ```bash`): a tag or a route line cannot be added to it. */
|
|
157
|
+
export function opensCodeBlock(line: string): boolean {
|
|
158
|
+
const item = LIST_ITEM_RE.exec(line);
|
|
159
|
+
if (item === null || indentOf(item[3] as string) > 4) return false;
|
|
160
|
+
return fenceRunOf(line.slice((item[1] as string).length + (item[2] as string).length + (item[3] as string).length)) !== null;
|
|
161
|
+
}
|
|
162
|
+
interface Run {
|
|
163
|
+
start: number;
|
|
164
|
+
end: number;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** Top-level list items, with their continuation lines, nested items, fenced blocks and a following `[acceptance]` block. */
|
|
168
|
+
function listRuns(lines: readonly string[], fenced: readonly boolean[]): Run[] {
|
|
169
|
+
const runs: Run[] = [];
|
|
170
|
+
let current: (Run & { offset: number }) | null = null;
|
|
171
|
+
let gap = false; // a blank line since the last line included in the step
|
|
172
|
+
let acceptance = false;
|
|
173
|
+
let joinFence = false;
|
|
174
|
+
const close = (): void => {
|
|
175
|
+
if (current !== null) runs.push({ start: current.start, end: current.end });
|
|
176
|
+
current = null;
|
|
177
|
+
};
|
|
178
|
+
for (let i = 0; i < lines.length; i += 1) {
|
|
179
|
+
const line = lines[i] as string;
|
|
180
|
+
if (fenced[i] === true) {
|
|
181
|
+
if (i === 0 || fenced[i - 1] !== true) {
|
|
182
|
+
// A block joins the step when nothing separates them, or it is indented as the item's content (CommonMark).
|
|
183
|
+
joinFence = current !== null && (!gap || indentOf(line) >= current.offset);
|
|
184
|
+
if (!joinFence) close();
|
|
185
|
+
}
|
|
186
|
+
if (current !== null && joinFence) {
|
|
187
|
+
current.end = i + 1;
|
|
188
|
+
gap = false;
|
|
189
|
+
}
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
if (acceptance) {
|
|
193
|
+
if (ACCEPT_CLOSE_RE.test(line)) acceptance = false;
|
|
194
|
+
if (current !== null) {
|
|
195
|
+
current.end = i + 1;
|
|
196
|
+
gap = false;
|
|
197
|
+
}
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
if (line.trim() === "") {
|
|
201
|
+
gap = true;
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
if (HEADING_RE.test(line) || THEMATIC_RE.test(line)) {
|
|
205
|
+
close();
|
|
206
|
+
gap = false;
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
if (ACCEPT_OPEN_RE.test(line)) {
|
|
210
|
+
acceptance = true;
|
|
211
|
+
if (current !== null) {
|
|
212
|
+
current.end = i + 1;
|
|
213
|
+
gap = false;
|
|
214
|
+
}
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
const item = LIST_ITEM_RE.exec(line);
|
|
218
|
+
if (item !== null) {
|
|
219
|
+
const indent = indentOf(line);
|
|
220
|
+
if (current !== null && indent >= current.offset) {
|
|
221
|
+
current.end = i + 1; // a nested item belongs to its parent step
|
|
222
|
+
gap = false;
|
|
223
|
+
continue;
|
|
224
|
+
}
|
|
225
|
+
if (indent <= 3) {
|
|
226
|
+
close();
|
|
227
|
+
current = { start: i, end: i + 1, offset: indent + (item[2] as string).length + indentOf(item[3] as string) };
|
|
228
|
+
gap = false;
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
if (current !== null && (!gap || indentOf(line) >= current.offset)) {
|
|
233
|
+
current.end = i + 1;
|
|
234
|
+
gap = false;
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
close();
|
|
238
|
+
gap = false;
|
|
239
|
+
}
|
|
240
|
+
close();
|
|
241
|
+
return runs;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/** Fallback for a plan with no list at all: `## Step 1`, `### Task: …`, `## Phase 2` headings, each running to the next heading. */
|
|
245
|
+
function headingRuns(lines: readonly string[], fenced: readonly boolean[]): Run[] {
|
|
246
|
+
const runs: Run[] = [];
|
|
247
|
+
let current: Run | null = null;
|
|
248
|
+
for (let i = 0; i < lines.length; i += 1) {
|
|
249
|
+
const line = lines[i] as string;
|
|
250
|
+
if (fenced[i] !== true && HEADING_RE.test(line)) {
|
|
251
|
+
if (current !== null) runs.push(current);
|
|
252
|
+
current = STEP_HEADING_RE.test(line) ? { start: i, end: i + 1 } : null;
|
|
253
|
+
continue;
|
|
254
|
+
}
|
|
255
|
+
if (current !== null && (fenced[i] === true || line.trim() !== "")) current.end = i + 1;
|
|
256
|
+
}
|
|
257
|
+
if (current !== null) runs.push(current);
|
|
258
|
+
return runs;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* The steps of a markdown plan, in order. A step is a top-level list item (up to three spaces of indentation) with everything that
|
|
263
|
+
* belongs to it; headings, paragraphs and thematic breaks between steps are never steps. A fenced block (``` or ~~~, any nesting of
|
|
264
|
+
* the other kind inside) belongs to the step it sits in and hides its content from the step scanner. A plan without any list falls back to
|
|
265
|
+
* `Step`/`Task`/`Phase`/`Stage`/`Milestone` headings.
|
|
266
|
+
*/
|
|
267
|
+
export function splitPlan(text: string): PlacedStep[] {
|
|
268
|
+
const parts = text.split(LINE_SPLIT_RE);
|
|
269
|
+
const lines: string[] = [];
|
|
270
|
+
const offsets: number[] = [];
|
|
271
|
+
let at = 0;
|
|
272
|
+
parts.forEach((part, index) => {
|
|
273
|
+
if (index % 2 === 0) {
|
|
274
|
+
lines.push(part);
|
|
275
|
+
offsets.push(at);
|
|
276
|
+
}
|
|
277
|
+
at += part.length;
|
|
278
|
+
});
|
|
279
|
+
const fenced = structureMask(lines);
|
|
280
|
+
let runs = listRuns(lines, fenced);
|
|
281
|
+
if (runs.length === 0) runs = headingRuns(lines, fenced);
|
|
282
|
+
return runs.map((run) => {
|
|
283
|
+
const from = offsets[run.start] as number;
|
|
284
|
+
// The step includes the terminator of its last line (so `annotateSteps` inserts a route line with the file's own line ending); the
|
|
285
|
+
// last line of a text that has no final terminator simply ends at the end of the text.
|
|
286
|
+
const to = run.end < lines.length ? (offsets[run.end] as number) : text.length;
|
|
287
|
+
return { id: `L${run.start + 1}`, text: text.slice(from, to), line: run.start + 1, from, to };
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
// ---------------------------------------------------------------------------
|
|
291
|
+
// Annotating
|
|
292
|
+
// ---------------------------------------------------------------------------
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* One step's additions, in terms of lines of the ORIGINAL plan: the single definition of "what `/annotate-plan` adds". The annotated text
|
|
296
|
+
* ({@link applyAdditions}) and the message part ({@link renderDirectives}) are both made from it, so what the model is asked to write is
|
|
297
|
+
* exactly what the tests snapshot.
|
|
298
|
+
* - the tier tag goes at the START of the step, after its list marker or heading hashes (the command template's rule 1:
|
|
299
|
+
* `1. [tier:fast] Find all …`), and only when the step has none;
|
|
300
|
+
* - the route line goes on the line directly BELOW the step's first line (plan 2.4.4: `[route …]` after each `[tier:X]`), indented like
|
|
301
|
+
* that line (at most 3 spaces). The first line of a step is never inside a fenced block, so neither is the insertion point;
|
|
302
|
+
* - an existing route line is edited in place only to add ` pin` (A26).
|
|
303
|
+
*/
|
|
304
|
+
export interface PlanAddition {
|
|
305
|
+
/** 1-based line of the step's first line (the anchor), as it is in the file now. */
|
|
306
|
+
readonly line: number;
|
|
307
|
+
/** That line, verbatim. */
|
|
308
|
+
readonly anchor: string;
|
|
309
|
+
/** The anchor rewritten with `[tier:X]` after its marker; `null` when the step already carries a tier tag. */
|
|
310
|
+
readonly tag: { readonly tier: string; readonly line: string } | null;
|
|
311
|
+
/** A new route line to put directly below the anchor (`indent` + `text`); `null` when the step has a route line already. */
|
|
312
|
+
readonly insertRoute: { readonly indent: string; readonly text: string } | null;
|
|
313
|
+
/** An existing route line that only gains ` pin`: its 1-based line, what it is now and what it becomes. */
|
|
314
|
+
readonly replaceRoute: { readonly line: number; readonly before: string; readonly text: string } | null;
|
|
315
|
+
/** Where the step's facts came from (`rules`, `host`, `plan`, …). */
|
|
316
|
+
readonly source: string;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* A step that would have changed but cannot take an addition: its first line is a list item whose content opens a code block
|
|
321
|
+
* (`1. ```bash`), so a tag after the marker would corrupt the fence opener and a route line below it would be inside the code
|
|
322
|
+
* (QA-2.4-R2-2). Skipped, never guessed at, and reported so the user can annotate it by hand.
|
|
323
|
+
*/
|
|
324
|
+
export interface SkippedStep {
|
|
325
|
+
/** 1-based line of the step's first line. */
|
|
326
|
+
readonly line: number;
|
|
327
|
+
/** That line, verbatim. */
|
|
328
|
+
readonly anchor: string;
|
|
329
|
+
/** The tier the engine would have written, for the by-hand edit. */
|
|
330
|
+
readonly tier: string;
|
|
331
|
+
/** The route line the engine would have written, for the by-hand edit. */
|
|
332
|
+
readonly routeLine: string;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
export interface AnnotatedPlanText {
|
|
336
|
+
/** The whole plan with every step annotated; equal to the input when nothing had to change. */
|
|
337
|
+
readonly text: string;
|
|
338
|
+
readonly placed: readonly PlacedStep[];
|
|
339
|
+
readonly steps: readonly AnnotatedStep[];
|
|
340
|
+
/** Steps this annotation pinned (A26). */
|
|
341
|
+
readonly pinnedCount: number;
|
|
342
|
+
/** What was added, step by step (only steps that change). */
|
|
343
|
+
readonly additions: readonly PlanAddition[];
|
|
344
|
+
/** Steps that start with a code block: nothing was added to them (see {@link SkippedStep}). */
|
|
345
|
+
readonly skipped: readonly SkippedStep[];
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
const TAG_SLOT_RE = /^(?: {0,3}(?:[-*+]|\d{1,9}[.)])[ \t]+(?:\[[ xX]\][ \t]+)?| {0,3}#{1,6}[ \t]+)/;
|
|
349
|
+
|
|
350
|
+
/** `line` with `[tier:X]` after its list marker (and checkbox) or heading hashes; at the start of the text when there is neither. */
|
|
351
|
+
export function withTagAtStart(line: string, tier: string): string {
|
|
352
|
+
const prefix = TAG_SLOT_RE.exec(line)?.[0] ?? /^[ \t]*/.exec(line)?.[0] ?? "";
|
|
353
|
+
const rest = line.slice(prefix.length);
|
|
354
|
+
return rest === "" ? `${prefix}[tier:${tier}]` : `${prefix}[tier:${tier}] ${rest}`;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/** A matching run must close inline code on the anchor itself, never below the inserted route. */
|
|
358
|
+
function hasUnbalancedBackticks(line: string): boolean {
|
|
359
|
+
let open = 0;
|
|
360
|
+
for (const match of line.matchAll(/`+/g)) {
|
|
361
|
+
const run = match[0].length;
|
|
362
|
+
if (open === 0) {
|
|
363
|
+
const slashes = /\\*$/.exec(line.slice(0, match.index))?.[0].length ?? 0;
|
|
364
|
+
if (slashes % 2 === 1) continue;
|
|
365
|
+
open = run;
|
|
366
|
+
} else if (run === open) open = 0;
|
|
367
|
+
}
|
|
368
|
+
return open !== 0;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
function additionsOf(placed: readonly PlacedStep[], steps: readonly AnnotatedStep[]): { additions: PlanAddition[]; skipped: SkippedStep[]; pinned: number } {
|
|
372
|
+
const out: PlanAddition[] = [];
|
|
373
|
+
const skipped: SkippedStep[] = [];
|
|
374
|
+
let pinned = 0;
|
|
375
|
+
placed.forEach((where, index) => {
|
|
376
|
+
const step = steps[index] as AnnotatedStep;
|
|
377
|
+
if (!step.changed) return;
|
|
378
|
+
const original = where.text.split(LINE_SPLIT_RE).filter((_, i) => i % 2 === 0);
|
|
379
|
+
const annotated = step.text.split(LINE_SPLIT_RE).filter((_, i) => i % 2 === 0);
|
|
380
|
+
const anchor = original[0] ?? "";
|
|
381
|
+
if (opensCodeBlock(anchor) || hasUnbalancedBackticks(anchor)) {
|
|
382
|
+
skipped.push({ line: where.line, anchor, tier: step.tier, routeLine: step.routeLine });
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
if (step.pin && (step.routeEdited || step.routeSource === "engine")) pinned += 1;
|
|
386
|
+
let replaceRoute: PlanAddition["replaceRoute"] = null;
|
|
387
|
+
if (step.routeEdited) {
|
|
388
|
+
// The engine edited an existing, unfenced route line in place: the same line index in both texts. The mask is the scanner's own
|
|
389
|
+
// (indentation measured from the item's content column, QA-2.4-R2-8), so a route line inside a code block is never the one edited.
|
|
390
|
+
const mask = structureMask(original);
|
|
391
|
+
const at = original.findIndex((line, i) => mask[i] !== true && parseRouteLine(line, { positions: "any" }).count > 0);
|
|
392
|
+
if (at >= 0 && annotated[at] !== undefined && annotated[at] !== original[at]) {
|
|
393
|
+
replaceRoute = { line: where.line + at, before: original[at] as string, text: annotated[at] as string };
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
out.push({
|
|
397
|
+
line: where.line,
|
|
398
|
+
anchor,
|
|
399
|
+
tag: step.tierSource === "engine" ? { tier: step.tier, line: withTagAtStart(anchor, step.tier) } : null,
|
|
400
|
+
insertRoute: step.routeSource === "engine" ? { indent: (/^ */.exec(anchor)?.[0] ?? "").slice(0, 3), text: step.routeLine } : null,
|
|
401
|
+
replaceRoute,
|
|
402
|
+
source: step.facts.source,
|
|
403
|
+
});
|
|
404
|
+
});
|
|
405
|
+
return { additions: out, skipped, pinned };
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/** Apply additions to the plan they were computed for: the mechanical meaning of {@link PlanAddition}. Line endings are the file's own. */
|
|
409
|
+
export function applyAdditions(text: string, additions: readonly PlanAddition[]): string {
|
|
410
|
+
const parts = text.split(LINE_SPLIT_RE);
|
|
411
|
+
const lines: string[] = [];
|
|
412
|
+
const terminators: string[] = [];
|
|
413
|
+
parts.forEach((part, index) => {
|
|
414
|
+
if (index % 2 === 0) lines.push(part);
|
|
415
|
+
else terminators.push(part);
|
|
416
|
+
});
|
|
417
|
+
const docEol = terminators[0] ?? "\n";
|
|
418
|
+
const byLine = new Map(additions.map((addition) => [addition.line, addition]));
|
|
419
|
+
const replacements = new Map<number, string>();
|
|
420
|
+
for (const addition of additions) if (addition.replaceRoute !== null) replacements.set(addition.replaceRoute.line, addition.replaceRoute.text);
|
|
421
|
+
let out = "";
|
|
422
|
+
lines.forEach((line, index) => {
|
|
423
|
+
const addition = byLine.get(index + 1);
|
|
424
|
+
const current = addition?.tag != null ? addition.tag.line : (replacements.get(index + 1) ?? line);
|
|
425
|
+
const eol = terminators[index];
|
|
426
|
+
if (addition?.insertRoute != null) out += `${current}${eol ?? docEol}${addition.insertRoute.indent}${addition.insertRoute.text}${eol ?? ""}`;
|
|
427
|
+
else out += `${current}${eol ?? ""}`;
|
|
428
|
+
});
|
|
429
|
+
return out;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
/**
|
|
433
|
+
* `splitPlan` + one `annotateSteps` call (one batched classification). Idempotent: annotating the result again changes nothing.
|
|
434
|
+
* Never throws for well-typed input (a classifier failure leaves rules facts, see `annotateSteps`).
|
|
435
|
+
*/
|
|
436
|
+
export async function annotatePlanText(text: string, deps: AnnotateDeps): Promise<AnnotatedPlanText> {
|
|
437
|
+
const placed = splitPlan(text);
|
|
438
|
+
if (placed.length === 0) return { text, placed, steps: [], pinnedCount: 0, additions: [], skipped: [] };
|
|
439
|
+
// A step that ends the text has no terminator of its own: give it the file's, so the engine joins an inserted route line with the same
|
|
440
|
+
// line ending as everything else (only its tier, route and pin DECISIONS are used from the engine, not its text).
|
|
441
|
+
const eol = /\r\n|\n|\r/.exec(text)?.[0] ?? "\n";
|
|
442
|
+
const annotated = await annotateSteps(
|
|
443
|
+
placed.map((step) => ({ id: step.id, text: step.to === text.length && !/[\r\n]$/.test(step.text) ? `${step.text}${eol}` : step.text })),
|
|
444
|
+
deps,
|
|
445
|
+
);
|
|
446
|
+
const steps = [...annotated];
|
|
447
|
+
const { additions, skipped, pinned } = additionsOf(placed, steps);
|
|
448
|
+
// `pinned` is the engine's figure minus the steps that were skipped (nothing was written for them, so nothing was pinned)
|
|
449
|
+
return { text: applyAdditions(text, additions), placed, steps, pinnedCount: pinned, additions, skipped };
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
// ---------------------------------------------------------------------------
|
|
453
|
+
// The message part
|
|
454
|
+
// ---------------------------------------------------------------------------
|
|
455
|
+
|
|
456
|
+
export interface ClassificationReport {
|
|
457
|
+
/** `rules`, or the configured backend (`host`, `openai-compatible`, `typesafe`). */
|
|
458
|
+
readonly backend: string;
|
|
459
|
+
/** Count of backend outcomes by status (`ok`, `timeout`, …); empty when no backend was consulted. */
|
|
460
|
+
readonly statuses: Readonly<Record<string, number>>;
|
|
461
|
+
/** The slowest backend call of the batch, in ms; `null` when none was made. */
|
|
462
|
+
readonly latencyMs: number | null;
|
|
463
|
+
/** The first backend failure reason, verbatim, when there was one. */
|
|
464
|
+
readonly error: string | null;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
const MAX_LISTED_STEPS = 300;
|
|
468
|
+
const q = (value: string): string => JSON.stringify(value);
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* What the model is told to write, one line per step that changes, anchored on line numbers of the file as it is now and quoting the
|
|
472
|
+
* anchor line so it can be found even after earlier insertions moved the numbers. Each piece is a complete instruction with the exact
|
|
473
|
+
* line to write (JSON-quoted), so nothing is left to the model's judgement: `rewrite line N as "…"`, `insert directly below line N
|
|
474
|
+
* (outside any code fence) the line "…"`, `replace line M (was "…") with "…"`.
|
|
475
|
+
*/
|
|
476
|
+
export function renderDirectives(
|
|
477
|
+
result: AnnotatedPlanText,
|
|
478
|
+
info: { readonly path: string; readonly engine: string; readonly classification: ClassificationReport },
|
|
479
|
+
): string {
|
|
480
|
+
const { steps, additions, skipped } = result;
|
|
481
|
+
const sources = new Map<string, number>();
|
|
482
|
+
for (const step of steps) sources.set(step.facts.source, (sources.get(step.facts.source) ?? 0) + 1);
|
|
483
|
+
const statuses = Object.entries(info.classification.statuses).map(([status, count]) => `${status} ${count}`).join(", ");
|
|
484
|
+
const lines = [
|
|
485
|
+
`## Router route lines (model-router, engine=${info.engine})`,
|
|
486
|
+
`Computed by the router for ${info.path}: ${steps.length} step${steps.length === 1 ? "" : "s"} found, ${additions.length} need${additions.length === 1 ? "s" : ""} an addition${skipped.length === 0 ? "" : ` (${skipped.length} more start${skipped.length === 1 ? "s" : ""} with a code block${skipped.some((s) => !opensCodeBlock(s.anchor)) ? " or unbalanced backtick run" : ""} and ${skipped.length === 1 ? "is" : "are"} skipped)`}, ${result.pinnedCount} pinned by this annotation (a \`[tier:heavy]\` or QA step is never moved by the engine).`,
|
|
487
|
+
`Classification: backend=${info.classification.backend}; sources: ${[...sources].map(([source, count]) => `${source} ${count}`).join(", ") || "none"}${statuses === "" ? "" : `; backend outcomes: ${statuses}`}${info.classification.latencyMs === null ? "" : `; backend latency ${info.classification.latencyMs} ms`}${info.classification.error === null ? "" : `; first error: ${info.classification.error}`}.`,
|
|
488
|
+
];
|
|
489
|
+
// A step whose first line is a list item that opens a code block (`1. ```bash`) takes neither a tag (it would break the fence opener)
|
|
490
|
+
// nor a route line below (it would be inside the code): skipped, and said so (QA-2.4-R2-2).
|
|
491
|
+
const skippedLines = skipped.slice(0, MAX_LISTED_STEPS).map(
|
|
492
|
+
(step) => opensCodeBlock(step.anchor)
|
|
493
|
+
? `- line ${step.line} ${q(step.anchor)}: step at line ${step.line} starts with a code block: add nothing to it here; to annotate it by hand, put ${q(`[tier:${step.tier}]`)} and ${q(step.routeLine)} on their own lines directly above the list item, or after the closing fence.`
|
|
494
|
+
: `- line ${step.line} ${q(step.anchor)}: step at line ${step.line} has an unbalanced backtick run: add nothing here; close the inline code on that line before annotating it by hand with ${q(`[tier:${step.tier}]`)} and ${q(step.routeLine)}.`,
|
|
495
|
+
);
|
|
496
|
+
if (additions.length === 0) {
|
|
497
|
+
lines.push(skipped.length === 0 ? "Every step already carries its tier and route line: add nothing." : "No step can take an addition automatically. Make no change to the file for these steps:");
|
|
498
|
+
lines.push(...skippedLines);
|
|
499
|
+
return lines.join("\n");
|
|
500
|
+
}
|
|
501
|
+
lines.push(
|
|
502
|
+
"Make exactly these changes, keeping every other line as it is. Line numbers are those of the file now: apply the list from the last step to the first (or find each line by its quoted text) so earlier insertions do not move the later ones. Each quoted string is the complete line to write. Where a tier tag is listed it replaces the template's tag rule for that step (it is already at the start, as the template says); never write a `[route …]` line inside a fenced code block, and do not invent others.",
|
|
503
|
+
);
|
|
504
|
+
for (const addition of additions.slice(0, MAX_LISTED_STEPS)) {
|
|
505
|
+
const pieces: string[] = [];
|
|
506
|
+
if (addition.tag !== null) pieces.push(`rewrite line ${addition.line} as ${q(addition.tag.line)}`);
|
|
507
|
+
if (addition.insertRoute !== null) pieces.push(`insert directly below line ${addition.line} (outside any code fence) the line ${q(`${addition.insertRoute.indent}${addition.insertRoute.text}`)}`);
|
|
508
|
+
if (addition.replaceRoute !== null) pieces.push(`replace line ${addition.replaceRoute.line} (was ${q(addition.replaceRoute.before)}) with ${q(addition.replaceRoute.text)}`);
|
|
509
|
+
lines.push(`- line ${addition.line} ${q(addition.anchor)}: ${pieces.join("; ")} [facts source: ${addition.source}]`);
|
|
510
|
+
}
|
|
511
|
+
if (additions.length > MAX_LISTED_STEPS) lines.push(`- … ${additions.length - MAX_LISTED_STEPS} more steps: run /annotate-plan again after applying these.`);
|
|
512
|
+
if (skippedLines.length > 0) lines.push("Make no change to these steps (a code block or unbalanced backtick run makes the first line unsafe to annotate):", ...skippedLines);
|
|
513
|
+
return lines.join("\n");
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
// ---------------------------------------------------------------------------
|
|
517
|
+
// Locating the plan file
|
|
518
|
+
// ---------------------------------------------------------------------------
|
|
519
|
+
|
|
520
|
+
const MAX_PLAN_BYTES = 1_048_576;
|
|
521
|
+
|
|
522
|
+
async function readPlan(path: string): Promise<string | null> {
|
|
523
|
+
try {
|
|
524
|
+
const info = await stat(path);
|
|
525
|
+
if (!info.isFile() || info.size > MAX_PLAN_BYTES) return null;
|
|
526
|
+
return await readFile(path, "utf-8");
|
|
527
|
+
} catch {
|
|
528
|
+
return null; // not there (or not readable): the next candidate, or the plain template as before
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
/**
|
|
533
|
+
* The plan the command was pointed at: the path argument (quotes stripped; relative to the project directories), else, like the
|
|
534
|
+
* template says, `PLAN.md`, `plan.md` or the most recently changed `*plan*.md` of those directories. `null` when there is none.
|
|
535
|
+
*/
|
|
536
|
+
export async function locatePlan(args: string, dirs: readonly string[]): Promise<{ path: string; text: string } | null> {
|
|
537
|
+
const named = args.trim().replace(/^(["'])(.*)\1$/, "$2").trim();
|
|
538
|
+
const candidates: string[] = [];
|
|
539
|
+
if (named !== "") {
|
|
540
|
+
for (const dir of dirs) candidates.push(isAbsolute(named) ? named : resolve(dir, named));
|
|
541
|
+
} else {
|
|
542
|
+
for (const dir of dirs) {
|
|
543
|
+
candidates.push(join(dir, "PLAN.md"), join(dir, "plan.md"));
|
|
544
|
+
try {
|
|
545
|
+
const entries = (await readdir(dir)).filter((name) => /plan/i.test(name) && /\.md$/i.test(name));
|
|
546
|
+
const dated: Array<{ path: string; mtime: number }> = [];
|
|
547
|
+
for (const name of entries) {
|
|
548
|
+
try {
|
|
549
|
+
dated.push({ path: join(dir, name), mtime: (await stat(join(dir, name))).mtimeMs });
|
|
550
|
+
} catch {
|
|
551
|
+
continue; // vanished between readdir and stat
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
dated.sort((a, b) => b.mtime - a.mtime || (a.path < b.path ? -1 : 1));
|
|
555
|
+
candidates.push(...dated.map((entry) => entry.path));
|
|
556
|
+
} catch {
|
|
557
|
+
continue; // an unreadable directory has no plan
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
for (const path of [...new Set(candidates)]) {
|
|
562
|
+
const text = await readPlan(path);
|
|
563
|
+
if (text !== null) return { path, text };
|
|
564
|
+
}
|
|
565
|
+
return null;
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
// ---------------------------------------------------------------------------
|
|
569
|
+
// The command
|
|
570
|
+
// ---------------------------------------------------------------------------
|
|
571
|
+
|
|
572
|
+
/** Host agents as the plan annotation needs them: dispatchable by any caller (the command has no parent agent), grants from their own rules. */
|
|
573
|
+
export function agentInfosForPlan(raw: readonly unknown[]): HostAgentInfo[] {
|
|
574
|
+
const infos: HostAgentInfo[] = [];
|
|
575
|
+
for (const entry of raw) {
|
|
576
|
+
if (typeof entry !== "object" || entry === null) continue;
|
|
577
|
+
const agent = entry as Record<string, unknown>;
|
|
578
|
+
if (typeof agent.id !== "string" || agent.id === "") continue;
|
|
579
|
+
infos.push({
|
|
580
|
+
id: agent.id,
|
|
581
|
+
model: agentModelRef(agent.model),
|
|
582
|
+
mode: typeof agent.mode === "string" ? agent.mode : "primary",
|
|
583
|
+
hidden: agent.hidden === true,
|
|
584
|
+
permitted: true,
|
|
585
|
+
grants: grantsOfRules(parseRules(agent.permissions)),
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
return infos;
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
export interface AnnotateCommandDeps {
|
|
592
|
+
readonly cfg: RouterConfig;
|
|
593
|
+
readonly runtime: EngineRuntime;
|
|
594
|
+
/** `ctx.agent.list().data`. */
|
|
595
|
+
readonly listAgents: () => Promise<readonly unknown[]>;
|
|
596
|
+
/** The project directories searched for a plan, in order. */
|
|
597
|
+
readonly dirs: readonly string[];
|
|
598
|
+
readonly logger: { warn(message: string, extra?: Record<string, unknown>): void };
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
/**
|
|
602
|
+
* The text to add to `/annotate-plan`, or `null` when there is nothing to add: the engine is static (or the host is v1), no plan file can be
|
|
603
|
+
* found, or the plan has no steps. Never throws.
|
|
604
|
+
*/
|
|
605
|
+
export async function buildAnnotateDirectives(args: string, deps: AnnotateCommandDeps): Promise<string | null> {
|
|
606
|
+
try {
|
|
607
|
+
const prepared = await deps.runtime.prepare(deps.cfg);
|
|
608
|
+
if (prepared === null) return null; // static, or not v2: the command is exactly what it was
|
|
609
|
+
const plan = await locatePlan(args, deps.dirs);
|
|
610
|
+
if (plan === null) return null;
|
|
611
|
+
let agents: HostAgentInfo[] | null = null;
|
|
612
|
+
try {
|
|
613
|
+
agents = agentInfosForPlan(await deps.listAgents());
|
|
614
|
+
} catch (error) {
|
|
615
|
+
deps.logger.warn("[router] /annotate-plan: the agent list is unavailable; tiers are annotated without it", { error: error instanceof Error ? error.message : String(error) });
|
|
616
|
+
}
|
|
617
|
+
const classifyDeps: ClassifyDeps = { ...deps.runtime.classifyDeps(prepared), routeLinePositions: "any" };
|
|
618
|
+
let classified: readonly ClassifyResult[] = [];
|
|
619
|
+
const classifyMany = async (inputs: readonly ClassifyInput[]): Promise<ClassifyResult[]> => {
|
|
620
|
+
classified = await classifyManyWith(inputs, classifyDeps);
|
|
621
|
+
return [...classified];
|
|
622
|
+
};
|
|
623
|
+
const result = await annotatePlanText(plan.text, {
|
|
624
|
+
cfg: deps.cfg,
|
|
625
|
+
routing: prepared.routing,
|
|
626
|
+
agents,
|
|
627
|
+
store: prepared.store,
|
|
628
|
+
pricing: (model) => prepared.catalog.pricing(model),
|
|
629
|
+
session: prepared.session,
|
|
630
|
+
logger: deps.logger,
|
|
631
|
+
classifyMany,
|
|
632
|
+
});
|
|
633
|
+
if (result.steps.length === 0) return null;
|
|
634
|
+
const outcomes = classified.map((c) => c.trace.backend).filter((b): b is NonNullable<typeof b> => b !== null);
|
|
635
|
+
const statuses: Record<string, number> = {};
|
|
636
|
+
for (const outcome of outcomes) statuses[outcome.status] = (statuses[outcome.status] ?? 0) + 1;
|
|
637
|
+
const failure = outcomes.find((o) => o.status !== "ok" && o.reason !== undefined);
|
|
638
|
+
return renderDirectives(result, {
|
|
639
|
+
path: plan.path,
|
|
640
|
+
engine: prepared.routing.engine,
|
|
641
|
+
classification: {
|
|
642
|
+
backend: classifyDeps.settings.backend,
|
|
643
|
+
statuses,
|
|
644
|
+
latencyMs: outcomes.length === 0 ? null : Math.max(...outcomes.map((o) => o.latencyMs)),
|
|
645
|
+
error: failure?.reason ?? null,
|
|
646
|
+
},
|
|
647
|
+
});
|
|
648
|
+
} catch (error) {
|
|
649
|
+
deps.logger.warn("[router] /annotate-plan: route lines unavailable; the plan is annotated without them", { error: error instanceof Error ? error.message : String(error) });
|
|
650
|
+
return null;
|
|
651
|
+
}
|
|
652
|
+
}
|