@open-cr-agent/core 0.11.0 → 0.12.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.
Files changed (57) hide show
  1. package/dist/agent/settings.d.ts +1 -1
  2. package/dist/agent/settings.js +2 -1
  3. package/dist/{rereview → anchor}/quote.js +1 -1
  4. package/dist/contracts.d.ts +3 -0
  5. package/dist/fix/check.d.ts +13 -0
  6. package/dist/fix/check.js +62 -0
  7. package/dist/fix/prompt.d.ts +11 -0
  8. package/dist/fix/prompt.js +42 -0
  9. package/dist/fix/propose.d.ts +31 -0
  10. package/dist/fix/propose.js +96 -0
  11. package/dist/fix/select.d.ts +7 -0
  12. package/dist/fix/select.js +22 -0
  13. package/dist/index.d.ts +4 -1
  14. package/dist/index.js +2 -0
  15. package/dist/internal.d.ts +3 -1
  16. package/dist/internal.js +3 -1
  17. package/dist/pipeline/assemble-report.d.ts +2 -0
  18. package/dist/pipeline/assemble-report.js +6 -2
  19. package/dist/pipeline/check-stage.js +1 -2
  20. package/dist/pipeline/context-footprint.d.ts +10 -0
  21. package/dist/pipeline/context-footprint.js +36 -0
  22. package/dist/pipeline/execute-stage.d.ts +1 -1
  23. package/dist/pipeline/execute-stage.js +3 -1
  24. package/dist/pipeline/execute.d.ts +2 -0
  25. package/dist/pipeline/execute.js +5 -1
  26. package/dist/pipeline/findings.js +1 -1
  27. package/dist/pipeline/fix-stage.d.ts +12 -0
  28. package/dist/pipeline/fix-stage.js +34 -0
  29. package/dist/pipeline/options.d.ts +8 -1
  30. package/dist/pipeline/options.js +14 -0
  31. package/dist/pipeline/plan-output.d.ts +21 -0
  32. package/dist/pipeline/plan-output.js +11 -0
  33. package/dist/pipeline/preview.d.ts +2 -0
  34. package/dist/pipeline/preview.js +11 -4
  35. package/dist/pipeline/run.js +4 -1
  36. package/dist/pipeline/task-prompt.d.ts +3 -1
  37. package/dist/pipeline/task-prompt.js +5 -3
  38. package/dist/report/output-schema.d.ts +17 -0
  39. package/dist/report/output-schema.js +8 -0
  40. package/dist/report/output.js +8 -0
  41. package/dist/report/report.d.ts +3 -1
  42. package/dist/report/report.js +1 -0
  43. package/dist/report/serialize.d.ts +0 -1
  44. package/dist/report/serialize.js +1 -15
  45. package/dist/rereview/presence.js +1 -1
  46. package/dist/review/context-sources.d.ts +5 -0
  47. package/dist/review/context-sources.js +37 -0
  48. package/dist/review/prompt-text.d.ts +1 -1
  49. package/dist/review/prompt-text.js +1 -0
  50. package/dist/review/prompt.d.ts +9 -1
  51. package/dist/review/prompt.js +87 -43
  52. package/dist/task/linked-task.d.ts +2 -0
  53. package/dist/task/linked-task.js +2 -0
  54. package/dist/unsafe-text.d.ts +1 -0
  55. package/dist/unsafe-text.js +15 -0
  56. package/package.json +1 -1
  57. /package/dist/{rereview → anchor}/quote.d.ts +0 -0
@@ -8,56 +8,82 @@ export const MAX_GUIDELINES_CHARS = 20_000;
8
8
  // review tasks on Vertex ended at the cap (2026-09-28).
9
9
  const TURN_BUDGET = `## Turn budget
10
10
  Your turns are limited, and the last one allows no tool calls, so a finding you have not reported by then is lost. Report each issue with ${REVIEW_TOOLS.reportFinding} as soon as you have confirmed it, before you investigate the next one; never keep findings for the end. Spread your turns over every file in <ocra_review_files>.`;
11
- // Sections shared by every bundle of a run come first so providers can reuse
12
- // the cached prefix; bundle-specific sections follow.
13
11
  export function buildReviewPrompt(input) {
14
- const sections = [
15
- renderChangeRequest(input.changeRequest),
16
- renderChangedFiles(input.changedFiles),
17
- ];
18
- if (input.linkedTasks && input.linkedTasks.length > 0) {
19
- sections.push(renderLinkedTasks(input.linkedTasks));
12
+ const [system, ...user] = reviewPromptParts(input);
13
+ return {
14
+ system: system?.text ?? "",
15
+ user: join(user.map((p) => p.text), "\n\n"),
16
+ };
17
+ }
18
+ // The system prompt first, then the user prompt's parts in order. Parts
19
+ // shared by every bundle of a run come first so providers can reuse the
20
+ // cached prefix; bundle-specific parts follow.
21
+ export function reviewPromptParts(input) {
22
+ const without = input.without ?? new Set();
23
+ const parts = [];
24
+ const add = (source, text) => parts.push({ source, text });
25
+ add("system", ocraText(`${input.reviewer.systemPrompt}\n\n${TURN_BUDGET}`));
26
+ add("change_request", renderChangeRequest(input.changeRequest, MAX_DESCRIPTION_CHARS, !without.has("description")));
27
+ if (!without.has("changed_files"))
28
+ add("changed_files", renderChangedFiles(input.changedFiles));
29
+ if (input.linkedTasks && input.linkedTasks.length > 0 && !without.has("linked_tasks")) {
30
+ add("linked_tasks", renderLinkedTasks(input.linkedTasks));
20
31
  }
21
- if (input.guidelines?.trim()) {
22
- sections.push(section("repository_guidelines", truncated(input.guidelines, MAX_GUIDELINES_CHARS)));
32
+ if (input.guidelines?.trim() && !without.has("guidelines")) {
33
+ add("guidelines", section("repository_guidelines", truncated(input.guidelines, MAX_GUIDELINES_CHARS)));
34
+ }
35
+ const rules = renderRules(input.rules, without.has("rules") ? "" : (input.repoRules ?? ""));
36
+ if (rules)
37
+ add("rules", rules);
38
+ if (input.accepted && input.accepted.length > 0 && !without.has("accepted")) {
39
+ add("accepted", renderAccepted(input.accepted));
23
40
  }
24
- if (input.rules.trim())
25
- sections.push(section("review_rules", data(input.rules)));
26
- if (input.accepted && input.accepted.length > 0)
27
- sections.push(renderAccepted(input.accepted));
28
41
  const given = input.learnings ?? [];
29
42
  const more = input.moreLearnings ?? [];
30
- if (given.length > 0 || more.length > 0)
31
- sections.push(renderLearnings(given, more));
32
- if (input.projectDocs)
33
- sections.push(renderProjectDocs(input.projectDocs));
34
- sections.push(section("review_files", input.bundle.map(renderFile)), ...(input.callers && input.callers.length > 0 ? [renderCallers(input.callers)] : []), ...(input.analyzerResults && input.analyzerResults.length > 0
35
- ? [renderAnalyzerResults(input.analyzerResults)]
36
- : []), ...(input.plan
37
- ? [
38
- section("review_plan", [
39
- ocraText("A planning pass suggests checking these first; it may be wrong, so verify before you report."),
40
- data(input.plan),
41
- ]),
42
- ]
43
- : []));
43
+ if ((given.length > 0 || more.length > 0) && !without.has("learnings")) {
44
+ add("learnings", renderLearnings(given, more));
45
+ }
46
+ if (input.projectDocs && !without.has("project_docs")) {
47
+ add("project_docs", renderProjectDocs(input.projectDocs));
48
+ }
49
+ add("diff", section("review_files", input.bundle.map(renderFile)));
50
+ if (input.callers && input.callers.length > 0 && !without.has("callers")) {
51
+ add("callers", renderCallers(input.callers));
52
+ }
53
+ if (input.analyzerResults && input.analyzerResults.length > 0 && !without.has("analyzer")) {
54
+ add("analyzer", renderAnalyzerResults(input.analyzerResults));
55
+ }
56
+ if (input.plan) {
57
+ add("plan", section("review_plan", [
58
+ ocraText("A planning pass suggests checking these first; it may be wrong, so verify before you report."),
59
+ data(input.plan),
60
+ ]));
61
+ }
44
62
  if (!input.forPlanning) {
45
- sections.push(ocraText(`Review every file in <ocra_review_files>. Report each issue with ${REVIEW_TOOLS.reportFinding} as soon as you confirm it, then call ${REVIEW_TOOLS.taskDone}. Where a file shows "‹ocra_", the file itself has "<ocra_"; quote it that way.`));
63
+ add("instructions", ocraText(`Review every file in <ocra_review_files>. Report each issue with ${REVIEW_TOOLS.reportFinding} as soon as you confirm it, then call ${REVIEW_TOOLS.taskDone}. Where a file shows "‹ocra_", the file itself has "<ocra_"; quote it that way.`));
46
64
  }
47
- return {
48
- system: `${input.reviewer.systemPrompt}\n\n${TURN_BUDGET}`,
49
- user: join(sections, "\n\n"),
50
- };
65
+ return parts;
51
66
  }
52
67
  const MAX_TITLE_CHARS = 300;
53
68
  const MAX_DESCRIPTION_CHARS = 8_000;
69
+ const MAX_REPO_RULES_CHARS = 12_000;
54
70
  // Also used by the judge, which sees the same change request.
55
- export function renderChangeRequest(cr, maxDescription = MAX_DESCRIPTION_CHARS) {
71
+ export function renderChangeRequest(cr, maxDescription = MAX_DESCRIPTION_CHARS, withDescription = true) {
56
72
  return section("change_request", [
57
73
  section("title", truncated(cr.title, MAX_TITLE_CHARS)),
58
- section("description", truncated(cr.description, maxDescription)),
74
+ ...(withDescription ? [section("description", truncated(cr.description, maxDescription))] : []),
59
75
  ]);
60
76
  }
77
+ // The reviewer's rules are ocra's and short; the repository's are held to a
78
+ // limit, as the guidelines are.
79
+ function renderRules(builtin, repo) {
80
+ const parts = [];
81
+ if (builtin.trim())
82
+ parts.push(data(builtin));
83
+ if (repo.trim())
84
+ parts.push(truncated(repo, MAX_REPO_RULES_CHARS));
85
+ return parts.length > 0 ? section("review_rules", join(parts, "\n\n")) : undefined;
86
+ }
61
87
  // Every task of a run shares the list: rendered once per run.
62
88
  const changedFilesText = new WeakMap();
63
89
  function renderChangedFiles(files) {
@@ -68,12 +94,20 @@ function renderChangedFiles(files) {
68
94
  }
69
95
  return text;
70
96
  }
97
+ // Every task carries the list, so a change of thousands of files would
98
+ // repeat it in each; the bundle's own files are in its review_files anyway.
99
+ const MAX_LISTED_CHANGED_FILES = 150;
71
100
  function renderChangedFilesOnce(files) {
72
- const lines = files.map((f) => {
101
+ const listed = files.slice(0, MAX_LISTED_CHANGED_FILES);
102
+ const lines = listed.map((f) => {
73
103
  const path = f.kind === "renamed" ? `${f.oldPath} -> ${f.newPath}` : f.newPath;
74
104
  return join([ocraText(`${f.kind} `), data(oneLine(path)), ocraText(` (+${f.additions} -${f.deletions})`)], "");
75
105
  });
76
- return section("changed_files", lines);
106
+ const unlisted = files.length - listed.length;
107
+ return section("changed_files", [
108
+ ...lines,
109
+ ...(unlisted > 0 ? [ocraText(`and ${unlisted} more changed files.`)] : []),
110
+ ]);
77
111
  }
78
112
  // Every task of a run shares the tasks: rendered once per run.
79
113
  const linkedTasksText = new WeakMap();
@@ -90,17 +124,17 @@ function renderLinkedTasks(tasks) {
90
124
  }
91
125
  function renderLinkedTask(task) {
92
126
  const parts = [
93
- section("title", data(oneLine(task.title))),
127
+ section("title", data(oneLine(clip(task.title, LINKED_TASK_LIMITS.title)))),
94
128
  section("body", truncated(task.body, LINKED_TASK_LIMITS.body)),
95
129
  ];
96
130
  if (task.parent) {
97
131
  parts.push(section("parent", [
98
- data(oneLine(task.parent.title)),
132
+ data(oneLine(clip(task.parent.title, LINKED_TASK_LIMITS.title))),
99
133
  truncated(task.parent.body, LINKED_TASK_LIMITS.parentBody),
100
134
  ], { key: task.parent.key }));
101
135
  }
102
136
  if (task.subtasks.length > 0) {
103
- parts.push(section("subtasks", task.subtasks.map((t) => data(oneLine(`- ${t.key} ${t.title}${t.state ? ` (${t.state})` : ""}`)))));
137
+ parts.push(section("subtasks", task.subtasks.map((t) => data(oneLine(`- ${t.key} ${clip(t.title, LINKED_TASK_LIMITS.subtaskTitle)}${t.state ? ` (${t.state})` : ""}`)))));
104
138
  }
105
139
  return section("task", parts, {
106
140
  tracker: task.tracker,
@@ -109,18 +143,25 @@ function renderLinkedTask(task) {
109
143
  ...(task.labels.length > 0 ? { labels: task.labels.join(", ") } : {}),
110
144
  });
111
145
  }
146
+ // Memory only grows, and every entry on a bundle's files would otherwise
147
+ // reach its prompt: the last listed are shown, each on one short line.
148
+ // applyMemory still drops every remembered finding by its fingerprint.
149
+ const ACCEPTED_LIMITS = { entries: 20, title: 160, reason: 240 };
112
150
  function renderAccepted(entries) {
113
- const lines = entries.map((e) => data(oneLine(`- ${e.file}: ${e.title} (accepted: ${e.reason})`)));
151
+ const kept = entries.slice(-ACCEPTED_LIMITS.entries);
152
+ const lines = kept.map((e) => data(oneLine(`- ${e.file}: ${clip(e.title, ACCEPTED_LIMITS.title)} (accepted: ${clip(e.reason, ACCEPTED_LIMITS.reason)})`)));
153
+ const earlier = entries.length - kept.length;
114
154
  return section("accepted_findings", [
115
155
  ocraText("The team has accepted these; do not report them again."),
116
156
  ...lines,
157
+ ...(earlier > 0 ? [ocraText(`and ${earlier} more accepted earlier.`)] : []),
117
158
  ]);
118
159
  }
119
160
  export const MAX_LISTED_LEARNINGS = 10;
120
161
  function renderLearnings(given, more) {
121
162
  return section("team_learnings", [
122
163
  ocraText("What the team learned from earlier changes to this code. Check whether this change repeats a mistake one describes; report only what the change itself gets wrong, never a learning alone."),
123
- ...given.map((l) => section("learning", [data(oneLine(l.title)), data(l.body)], {
164
+ ...given.map((l) => section("learning", [data(oneLine(clip(l.title, MAX_TITLE_CHARS))), data(l.body)], {
124
165
  id: l.id,
125
166
  paths: l.paths.join(", "),
126
167
  ...(l.critical ? { critical: "true" } : {}),
@@ -135,7 +176,7 @@ function renderLearningIndex(more) {
135
176
  const unlisted = more.length - listed.length;
136
177
  return section("learning_index", [
137
178
  ocraText(`More learnings that match this change, by id and title; read one that may apply with ${REVIEW_TOOLS.readLearning}:`),
138
- ...listed.map((l) => data(`- ${l.id}: ${oneLine(l.title)}`)),
179
+ ...listed.map((l) => data(`- ${l.id}: ${oneLine(clip(l.title, MAX_TITLE_CHARS))}`)),
139
180
  ...(unlisted > 0 ? [ocraText(`and ${unlisted} more.`)] : []),
140
181
  ]);
141
182
  }
@@ -197,3 +238,6 @@ function renderHunk(hunk) {
197
238
  });
198
239
  return [hunk.header, ...lines].join("\n");
199
240
  }
241
+ function clip(text, max) {
242
+ return text.length > max ? `${text.slice(0, max)}…` : text;
243
+ }
@@ -36,6 +36,8 @@ export interface LinkedTaskUse {
36
36
  }
37
37
  export declare const LINKED_TASK_LIMITS: {
38
38
  readonly tasks: 3;
39
+ readonly title: 300;
40
+ readonly subtaskTitle: 120;
39
41
  readonly body: 4000;
40
42
  readonly parentBody: 1500;
41
43
  readonly subtasks: 10;
@@ -1,6 +1,8 @@
1
1
  export const TASK_TRACKERS = ["github", "gitlab", "jira", "tapd"];
2
2
  export const LINKED_TASK_LIMITS = {
3
3
  tasks: 3,
4
+ title: 300,
5
+ subtaskTitle: 120,
4
6
  body: 4_000,
5
7
  parentBody: 1_500,
6
8
  subtasks: 10,
@@ -0,0 +1 @@
1
+ export declare function isUnsafeCodePoint(code: number): boolean;
@@ -0,0 +1,15 @@
1
+ // Characters a terminal or an editor acts on: C0 controls but tab and
2
+ // newline, DEL and C1 controls (ANSI and OSC escapes), line and paragraph
3
+ // separators, and bidirectional marks and overrides ("Trojan Source"). One
4
+ // definition for every output: terminal text replaces them, JSON escapes them.
5
+ export function isUnsafeCodePoint(code) {
6
+ return ((code <= 0x1f && code !== 0x09 && code !== 0x0a) ||
7
+ (code >= 0x7f && code <= 0x9f) ||
8
+ code === 0x061c ||
9
+ code === 0x200e ||
10
+ code === 0x200f ||
11
+ code === 0x2028 ||
12
+ code === 0x2029 ||
13
+ (code >= 0x202a && code <= 0x202e) ||
14
+ (code >= 0x2066 && code <= 0x2069));
15
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-cr-agent/core",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "description": "Domain types, review pipeline stages and plugin contracts for Open-CR-Agent",
5
5
  "keywords": [
6
6
  "code-review",
File without changes