>
diff --git a/gui/src/pages/gui/ToolCallDiv/CreateFile.tsx b/gui/src/pages/gui/ToolCallDiv/CreateFile.tsx
index a3e81355b..d0a843104 100644
--- a/gui/src/pages/gui/ToolCallDiv/CreateFile.tsx
+++ b/gui/src/pages/gui/ToolCallDiv/CreateFile.tsx
@@ -8,6 +8,10 @@ interface CreateFileToolCallProps {
}
export function CreateFile(props: CreateFileToolCallProps) {
+ if (!props.fileContents) {
+ return null;
+ }
+
const src = `\`\`\`${getMarkdownLanguageTagForFile(props.relativeFilepath ?? "output.txt")} ${props.relativeFilepath}\n${props.fileContents ?? ""}\n\`\`\``;
return props.relativeFilepath ? (
diff --git a/gui/src/pages/gui/ToolCallDiv/EditFile.tsx b/gui/src/pages/gui/ToolCallDiv/EditFile.tsx
index 0c27ecee8..a4a487d42 100644
--- a/gui/src/pages/gui/ToolCallDiv/EditFile.tsx
+++ b/gui/src/pages/gui/ToolCallDiv/EditFile.tsx
@@ -16,13 +16,12 @@ type EditToolCallProps = {
};
export function EditFile(props: EditToolCallProps) {
- const src = `\`\`\`${getMarkdownLanguageTagForFile(props.relativeFilePath ?? "test.txt")} ${props.relativeFilePath}\n${props.changes ?? ""}\n\`\`\``;
-
const dispatch = useAppDispatch();
- const isStreaming = useAppSelector((state) => state.session.isStreaming);
+
const applyState = useAppSelector((state) =>
selectApplyStateByToolCallId(state, props.toolCallId),
);
+
useEffect(() => {
if (!applyState) {
dispatch(
@@ -35,10 +34,12 @@ export function EditFile(props: EditToolCallProps) {
}
}, [applyState, props.toolCallId]);
- if (!props.relativeFilePath) {
+ if (!props.relativeFilePath || !props.changes) {
return null;
}
+ const src = `\`\`\`${getMarkdownLanguageTagForFile(props.relativeFilePath ?? "test.txt")} ${props.relativeFilePath}\n${props.changes}\n\`\`\``;
+
return (
diff --git a/gui/src/pages/gui/ToolCallDiv/ToolCallStatusMessage.tsx b/gui/src/pages/gui/ToolCallDiv/ToolCallStatusMessage.tsx
index e4e4c6e42..7a25a7605 100644
--- a/gui/src/pages/gui/ToolCallDiv/ToolCallStatusMessage.tsx
+++ b/gui/src/pages/gui/ToolCallDiv/ToolCallStatusMessage.tsx
@@ -1,6 +1,8 @@
import { Tool, ToolCallState } from "core";
import Mustache from "mustache";
import { ReactNode } from "react";
+import { getFontSize } from "../../../util";
+import { useFontSize } from "../../../components/ui/font";
interface ToolCallStatusMessageProps {
tool: Tool | undefined;
@@ -11,6 +13,7 @@ export function ToolCallStatusMessage({
tool,
toolCallState,
}: ToolCallStatusMessageProps) {
+ const fontSize = useFontSize();
if (!tool) return "Agent tool use";
const defaultToolDescription = (
@@ -65,7 +68,7 @@ export function ToolCallStatusMessage({
message = futureMessage;
}
return (
-
+
Continue {intro} {message}
);
diff --git a/gui/src/pages/gui/useAutoScroll.ts b/gui/src/pages/gui/useAutoScroll.ts
index a787e7ec9..236ca9f76 100644
--- a/gui/src/pages/gui/useAutoScroll.ts
+++ b/gui/src/pages/gui/useAutoScroll.ts
@@ -1,16 +1,24 @@
-import { useEffect, useState } from "react";
+import { useEffect, useMemo, useState } from "react";
+import { ChatHistoryItemWithMessageId } from "../../redux/slices/sessionSlice";
+
+/**
+ * Only reset scroll state when a new user message is added to the chat.
+ * We don't want to auto-scroll on new tool response messages.
+ */
+function getNumUserMsgs(history: ChatHistoryItemWithMessageId[]) {
+ return history.filter((msg) => msg.message.role === "user").length;
+}
export const useAutoScroll = (
ref: React.RefObject
,
- history: unknown[],
+ history: ChatHistoryItemWithMessageId[],
) => {
const [userHasScrolled, setUserHasScrolled] = useState(false);
+ const numUserMsgs = useMemo(() => getNumUserMsgs(history), [history.length]);
useEffect(() => {
- if (history.length) {
- setUserHasScrolled(false);
- }
- }, [history.length]);
+ setUserHasScrolled(false);
+ }, [numUserMsgs]);
useEffect(() => {
if (!ref.current || history.length === 0) return;
diff --git a/gui/src/redux/slices/editModeState.ts b/gui/src/redux/slices/editModeState.ts
index 061514566..05b41a15b 100644
--- a/gui/src/redux/slices/editModeState.ts
+++ b/gui/src/redux/slices/editModeState.ts
@@ -1,21 +1,17 @@
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
-import {
- UpdateApplyStatePayload,
- SetCodeToEditPayload,
- MessageModes,
-} from "core";
+import { ApplyState, SetCodeToEditPayload, MessageModes } from "core";
import { EDIT_MODE_STREAM_ID } from "core/edit/constants";
export interface EditModeState {
// Array because of previous multi-file edit functionality
// Keeping array to not break persisted redux for now
codeToEdit: SetCodeToEditPayload[];
- applyState: UpdateApplyStatePayload;
+ applyState: ApplyState;
returnToMode: MessageModes;
lastNonEditSessionWasEmpty: boolean;
}
-export const INITIAL_EDIT_APPLY_STATE: UpdateApplyStatePayload = {
+export const INITIAL_EDIT_APPLY_STATE: ApplyState = {
streamId: EDIT_MODE_STREAM_ID,
status: "not-started",
};
@@ -39,7 +35,7 @@ export const editModeStateSlice = createSlice({
},
updateEditStateApplyState: (
state,
- { payload }: PayloadAction,
+ { payload }: PayloadAction,
) => {
state.applyState = {
...state.applyState,
diff --git a/gui/src/redux/slices/sessionSlice.ts b/gui/src/redux/slices/sessionSlice.ts
index 75d8acdda..627829da4 100644
--- a/gui/src/redux/slices/sessionSlice.ts
+++ b/gui/src/redux/slices/sessionSlice.ts
@@ -7,7 +7,7 @@ import {
} from "@reduxjs/toolkit";
import { JSONContent } from "@tiptap/react";
import {
- UpdateApplyStatePayload,
+ ApplyState,
ChatHistoryItem,
ChatMessage,
ContextItem,
@@ -15,6 +15,7 @@ import {
FileSymbolMap,
MessageModes,
PromptLog,
+ RuleWithSource,
Session,
SessionMetadata,
ToolCallDelta,
@@ -31,7 +32,7 @@ import { findCurrentToolCall, findToolCall } from "../util";
// We need this to handle reorderings (e.g. a mid-array deletion) of the messages array.
// The proper fix is adding a UUID to all chat messages, but this is the temp workaround.
-type ChatHistoryItemWithMessageId = ChatHistoryItem & {
+export type ChatHistoryItemWithMessageId = ChatHistoryItem & {
message: ChatMessage & { id: string };
};
@@ -47,7 +48,7 @@ type SessionState = {
symbols: FileSymbolMap;
mode: MessageModes;
codeBlockApplyStates: {
- states: UpdateApplyStatePayload[];
+ states: ApplyState[];
curIndex: number;
};
newestToolbarPreviewForInput: Record;
@@ -247,6 +248,19 @@ export const sessionSlice = createSlice({
...payload.contextItems,
];
},
+ setAppliedRulesAtIndex: (
+ state,
+ {
+ payload,
+ }: PayloadAction<{
+ index: number;
+ appliedRules: RuleWithSource[];
+ }>,
+ ) => {
+ if (state.history[payload.index]) {
+ state.history[payload.index].appliedRules = payload.appliedRules;
+ }
+ },
setInactive: (state) => {
const curMessage = state.history.at(-1);
@@ -521,10 +535,7 @@ export const sessionSlice = createSlice({
state.history[state.history.length - 1].contextItems = contextItems;
},
- updateApplyState: (
- state,
- { payload }: PayloadAction,
- ) => {
+ updateApplyState: (state, { payload }: PayloadAction) => {
const applyState = state.codeBlockApplyStates.states.find(
(state) => state.streamId === payload.streamId,
);
@@ -701,6 +712,7 @@ export const {
updateFileSymbols,
setContextItemsAtIndex,
addContextItemsAtIndex,
+ setAppliedRulesAtIndex,
setInactive,
streamUpdate,
newSession,
diff --git a/gui/src/redux/thunks/streamResponse.ts b/gui/src/redux/thunks/streamResponse.ts
index 5ab6f036e..c9a21a30c 100644
--- a/gui/src/redux/thunks/streamResponse.ts
+++ b/gui/src/redux/thunks/streamResponse.ts
@@ -1,12 +1,14 @@
import { createAsyncThunk, unwrapResult } from "@reduxjs/toolkit";
import { JSONContent } from "@tiptap/core";
-import { InputModifiers } from "core";
+import { InputModifiers, ToolResultChatMessage, UserChatMessage } from "core";
import { constructMessages } from "core/llm/constructMessages";
+import { getApplicableRules } from "core/llm/rules/getSystemMessageWithRules";
import posthog from "posthog-js";
import { v4 as uuidv4 } from "uuid";
import { getBaseSystemMessage } from "../../util";
import { selectSelectedChatModel } from "../slices/configSlice";
import {
+ setAppliedRulesAtIndex,
submitEditorAndInitAtIndex,
updateHistoryItemAtIndex,
} from "../slices/sessionSlice";
@@ -84,17 +86,41 @@ export const streamResponseThunk = createAsyncThunk<
}),
);
- // Construct messages from updated history
+ // Get updated history after the update
const updatedHistory = getState().session.history;
- const messageMode = getState().session.mode
- const baseChatOrAgentSystemMessage = getBaseSystemMessage(selectedChatModel, messageMode)
+ // Determine which rules apply to this message
+ const userMsg = updatedHistory[inputIndex].message;
+ const rules = getState().config.config.rules;
+
+ // Calculate applicable rules once
+ // We need to check the message type to match what getApplicableRules expects
+ const applicableRules = getApplicableRules(
+ userMsg.role === "user" || userMsg.role === "tool"
+ ? (userMsg as UserChatMessage | ToolResultChatMessage)
+ : undefined,
+ rules,
+ );
+
+ // Store in history for UI display
+ dispatch(
+ setAppliedRulesAtIndex({
+ index: inputIndex,
+ appliedRules: applicableRules,
+ }),
+ );
+
+ const messageMode = getState().session.mode;
+ const baseChatOrAgentSystemMessage = getBaseSystemMessage(
+ selectedChatModel,
+ messageMode,
+ );
const messages = constructMessages(
messageMode,
[...updatedHistory],
baseChatOrAgentSystemMessage,
- state.config.config.rules,
+ applicableRules,
);
posthog.capture("step run", {
diff --git a/packages/config-yaml/src/registryClient.test.ts b/packages/config-yaml/src/registryClient.test.ts
index d820579ab..bff0b9e84 100644
--- a/packages/config-yaml/src/registryClient.test.ts
+++ b/packages/config-yaml/src/registryClient.test.ts
@@ -3,6 +3,7 @@ import * as http from "node:http";
import { AddressInfo } from "node:net";
import * as os from "node:os";
import * as path from "node:path";
+import { pathToFileURL } from "url";
import { PackageIdentifier } from "./interfaces/slugs.js";
import { RegistryClient } from "./registryClient.js";
@@ -134,6 +135,7 @@ describe("RegistryClient", () => {
describe("getContentFromFilePath", () => {
let absoluteFilePath: string;
+ let fileUrl: string;
let relativeFilePath: string;
beforeEach(() => {
@@ -141,6 +143,11 @@ describe("RegistryClient", () => {
absoluteFilePath = path.join(tempDir, "absolute-path.yaml");
fs.writeFileSync(absoluteFilePath, "absolute file content", "utf8");
+ const urlFilePath = path.join(tempDir, "file-url-path.yaml");
+ fs.writeFileSync(urlFilePath, "file:// file content", "utf8");
+ const url = pathToFileURL(urlFilePath);
+ fileUrl = url.toString();
+
// Create a subdirectory and file in the temp directory
const subDir = path.join(tempDir, "sub");
fs.mkdirSync(subDir, { recursive: true });
@@ -160,6 +167,14 @@ describe("RegistryClient", () => {
expect(result).toBe("absolute file content");
});
+ it("should read from local file url directly", () => {
+ const client = new RegistryClient();
+
+ const result = (client as any).getContentFromFilePath(fileUrl);
+
+ expect(result).toBe("file:// file content");
+ });
+
it("should use rootPath for relative paths when provided", () => {
const client = new RegistryClient({ rootPath: tempDir });
diff --git a/packages/config-yaml/src/registryClient.ts b/packages/config-yaml/src/registryClient.ts
index 73ca9fefd..3dab5e062 100644
--- a/packages/config-yaml/src/registryClient.ts
+++ b/packages/config-yaml/src/registryClient.ts
@@ -38,11 +38,9 @@ export class RegistryClient implements Registry {
private getContentFromFilePath(filepath: string): string {
if (filepath.startsWith("file://")) {
- const pathWithoutProtocol = filepath.slice(7);
-
// For Windows file:///C:/path/to/file, we need to handle it properly
// On other systems, we might have file:///path/to/file
- return fs.readFileSync(decodeURIComponent(pathWithoutProtocol), "utf8");
+ return fs.readFileSync(new URL(filepath), "utf8");
} else if (path.isAbsolute(filepath)) {
return fs.readFileSync(filepath, "utf8");
} else if (this.rootPath) {