Skip to content

Commit 0c7e230

Browse files
committed
frontend/get-help: include the latex error and the line in the prompt
1 parent 19481d5 commit 0c7e230

File tree

7 files changed

+43
-19
lines changed

7 files changed

+43
-19
lines changed

src/.claude/settings.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"Bash(../node_modules/.bin/tsc:*)",
55
"Bash(NODE_OPTIONS=--max-old-space-size=8192 ../node_modules/.bin/tsc --noEmit)",
66
"Bash(bash:*)",
7-
"Bash(curl:*)",
7+
"Bash(chmod:*)",
88
"Bash(curl:*)",
99
"Bash(docker run:*)",
1010
"Bash(find:*)",
@@ -24,9 +24,11 @@
2424
"Bash(pnpm list:*)",
2525
"Bash(pnpm ts-build:*)",
2626
"Bash(pnpm tsc:*)",
27+
"Bash(pnpm update:*)",
2728
"Bash(pnpm why:*)",
2829
"Bash(prettier -w:*)",
2930
"Bash(psql:*)",
31+
"Bash(python3:*)",
3032
"WebFetch(domain:cocalc.com)",
3133
"WebFetch(domain:doc.cocalc.com)",
3234
"WebFetch(domain:docs.anthropic.com)",
@@ -36,6 +38,7 @@
3638
"WebFetch(domain:www.anthropic.com)",
3739
"WebSearch",
3840
"mcp__cclsp__find_definition",
41+
"mcp__cclsp__find_references",
3942
"mcp__github__get_issue",
4043
"mcp__github__get_pull_request_comments",
4144
"mcp__github__get_pull_request",

src/packages/frontend/frame-editors/frame-tree/format-error.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// A dismissable error message that appears when formatting code.
1+
// A dismissible error message that appears when formatting code.
22

33
import { Alert, Button } from "antd";
44
import { useMemo } from "react";

src/packages/frontend/frame-editors/latex-editor/errors-and-warnings.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,8 @@ const Item: React.FC<ItemProps> = React.memo(
143143
style={{ float: "right", marginLeft: "10px" }}
144144
size="small"
145145
task={"ran latex"}
146-
error={
147-
(item.get("message") ?? "") + "\n" + (item.get("content") ?? "")
148-
}
146+
error={item.get("message") ?? ""}
147+
line={item.get("content") ?? ""}
149148
input={() => {
150149
const s = actions._syncstring.to_str();
151150
const v = s

src/packages/frontend/frame-editors/latex-editor/gutters.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ function Component({
8787
size="small"
8888
style={{ marginTop: "5px" }}
8989
task={"ran latex"}
90-
error={content}
90+
error={message}
91+
line={content}
9192
input={() => {
9293
const s = actions._syncstring.to_str();
9394
const v = s
@@ -100,7 +101,7 @@ function Component({
100101
language={"latex"}
101102
extraFileInfo={actions.languageModelExtraFileInfo()}
102103
tag={"latex-error-popover"}
103-
prioritize="end"
104+
prioritize="start-end"
104105
/>
105106
</>
106107
)}

src/packages/frontend/frame-editors/llm/help-me-fix-utils.ts

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export interface GetHelpOptions {
1212
error: string;
1313
input?: string;
1414
task?: string;
15+
line?: string;
1516
language?: string;
1617
extraFileInfo?: string;
1718
redux: any;
@@ -22,6 +23,7 @@ export interface GetHelpOptions {
2223
export interface CreateMessageOpts {
2324
tag?: string;
2425
error: string;
26+
line: string;
2527
input?: string;
2628
task?: string;
2729
language?: string;
@@ -38,6 +40,7 @@ export async function getHelp(options: GetHelpOptions) {
3840
project_id,
3941
path,
4042
tag,
43+
line = "",
4144
error,
4245
input,
4346
task,
@@ -51,6 +54,7 @@ export async function getHelp(options: GetHelpOptions) {
5154
const solutionText = createMessage({
5255
error,
5356
task,
57+
line,
5458
input,
5559
language,
5660
extraFileInfo,
@@ -77,6 +81,7 @@ export async function getHelp(options: GetHelpOptions) {
7781

7882
export function createMessage({
7983
error,
84+
line,
8085
language,
8186
input,
8287
model,
@@ -104,20 +109,19 @@ export function createMessage({
104109
message.push(`I ${task}.`);
105110
}
106111

107-
if (error.length > 3000) {
108-
// 3000 is about 500 tokens
109-
// This uses structure:
110-
error = shortenError(error, language);
111-
if (error.length > 3000) {
112-
// this just puts ... in the middle.
113-
error = trunc_middle(error, 3000);
114-
}
115-
}
112+
error = trimStr(error, language);
113+
line = trimStr(line, language);
116114

117115
message.push(`I received the following error:`);
118116
const delimE = backtickSequence(error);
119117
message.push(`${delimE}${language}\n${error}\n${delimE}`);
120118

119+
if (line) {
120+
message.push(`For the following line:`);
121+
const delimL = backtickSequence(line);
122+
message.push(`${delimL}${language}\n${line}\n${delimL}`);
123+
}
124+
121125
// We put the input last, since it could be huge and get truncated.
122126
// It's much more important to show the error, obviously.
123127
if (input) {
@@ -151,3 +155,16 @@ export function createMessage({
151155

152156
return message.join("\n\n");
153157
}
158+
159+
function trimStr(s: string, language): string {
160+
if (s.length > 3000) {
161+
// 3000 is about 500 tokens
162+
// This uses structure:
163+
s = shortenError(s, language);
164+
if (s.length > 3000) {
165+
// this just puts ... in the middle.
166+
s = trunc_middle(s, 3000);
167+
}
168+
}
169+
return s;
170+
}

src/packages/frontend/frame-editors/llm/help-me-fix.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export { getHelp } from "./help-me-fix-utils";
2121

2222
interface Props {
2323
error: string | (() => string); // the error it produced. This is viewed as code.
24+
line?: string | (() => string); // the line content where the error was produced, if available
2425
input?: string | (() => string); // the input, e.g., code you ran
2526
task?: string; // what you're doing, e.g., "ran a cell in a Jupyter notebook" or "ran a code formatter"
2627
tag?: string;
@@ -34,12 +35,13 @@ interface Props {
3435

3536
function get(f: undefined | string | (() => string)): string {
3637
if (f == null) return "";
37-
if (typeof f == "string") return f;
38+
if (typeof f === "string") return f;
3839
return f();
3940
}
4041

4142
export default function HelpMeFix({
4243
error,
44+
line,
4345
task,
4446
input,
4547
tag,
@@ -78,6 +80,7 @@ export default function HelpMeFix({
7880
): string {
7981
return createMessage({
8082
error: get(error),
83+
line: get(line),
8184
task,
8285
input: get(input),
8386
language,

src/packages/frontend/frame-editors/rmd-editor/build-log.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55

66
import Anser from "anser";
77
import React from "react";
8-
import Ansi from "@cocalc/frontend/components/ansi-to-react";
8+
99
import { Button } from "@cocalc/frontend/antd-bootstrap";
1010
import { Rendered, useRedux } from "@cocalc/frontend/app-framework";
1111
import { Loading } from "@cocalc/frontend/components";
12-
import HelpMeFix from "../llm/help-me-fix";
12+
import Ansi from "@cocalc/frontend/components/ansi-to-react";
13+
import HelpMeFix from "@cocalc/frontend/frame-editors/llm/help-me-fix";
1314
import { Actions } from "./actions";
1415
import {
1516
STYLE_ERR,

0 commit comments

Comments
 (0)