+
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 52a05a97e..05b41a15b 100644
--- a/gui/src/redux/slices/editModeState.ts
+++ b/gui/src/redux/slices/editModeState.ts
@@ -1,10 +1,11 @@
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
-import { ApplyState, CodeToEdit, 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: CodeToEdit[];
+ codeToEdit: SetCodeToEditPayload[];
applyState: ApplyState;
returnToMode: MessageModes;
lastNonEditSessionWasEmpty: boolean;
@@ -46,7 +47,7 @@ export const editModeStateSlice = createSlice({
{
payload,
}: PayloadAction<{
- codeToEdit: CodeToEdit | CodeToEdit[];
+ codeToEdit: SetCodeToEditPayload | SetCodeToEditPayload[];
}>,
) => {
state.codeToEdit = Array.isArray(payload.codeToEdit)
diff --git a/gui/src/redux/slices/sessionSlice.ts b/gui/src/redux/slices/sessionSlice.ts
index e81545d8b..627829da4 100644
--- a/gui/src/redux/slices/sessionSlice.ts
+++ b/gui/src/redux/slices/sessionSlice.ts
@@ -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 };
};
@@ -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);
@@ -698,6 +712,7 @@ export const {
updateFileSymbols,
setContextItemsAtIndex,
addContextItemsAtIndex,
+ setAppliedRulesAtIndex,
setInactive,
streamUpdate,
newSession,
diff --git a/gui/src/redux/thunks/editMode.ts b/gui/src/redux/thunks/editMode.ts
index 4341b14a4..8a7771a24 100644
--- a/gui/src/redux/thunks/editMode.ts
+++ b/gui/src/redux/thunks/editMode.ts
@@ -1,6 +1,10 @@
import { createAsyncThunk } from "@reduxjs/toolkit";
import { JSONContent } from "@tiptap/core";
-import { CodeToEdit, MessageModes, RangeInFileWithContents } from "core";
+import {
+ SetCodeToEditPayload,
+ MessageModes,
+ RangeInFileWithContents,
+} from "core";
import { stripImages } from "core/util/messageContent";
import { resolveEditorContent } from "../../components/mainInput/TipTapEditor";
import {
@@ -18,7 +22,7 @@ export const streamEditThunk = createAsyncThunk<
void,
{
editorState: JSONContent;
- codeToEdit: CodeToEdit[];
+ codeToEdit: SetCodeToEditPayload[];
},
ThunkApiType
>(
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/manual-testing-sandbox/test.kt b/manual-testing-sandbox/test.kt
index bb13ae9ee..512c34c25 100644
--- a/manual-testing-sandbox/test.kt
+++ b/manual-testing-sandbox/test.kt
@@ -31,3 +31,6 @@ class Test {
}
}
+
+
+
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) {
diff --git a/packages/config-yaml/src/schemas/data/editInteraction/index.ts b/packages/config-yaml/src/schemas/data/editInteraction/index.ts
index 92edc1c06..fd1ba3657 100644
--- a/packages/config-yaml/src/schemas/data/editInteraction/index.ts
+++ b/packages/config-yaml/src/schemas/data/editInteraction/index.ts
@@ -1,6 +1,9 @@
import { z } from "zod";
import { baseDevDataAllSchema } from "../base.js";
+/**
+ * The "editInteraction" event is sent whenever the user submits an input in edit mode and the model's response is completed
+ */
export const editInteractionEventAllSchema = baseDevDataAllSchema.extend({
modelProvider: z.string(),
modelTitle: z.string(),
diff --git a/packages/config-yaml/src/schemas/data/index.ts b/packages/config-yaml/src/schemas/data/index.ts
index d1155f389..7251e12a7 100644
--- a/packages/config-yaml/src/schemas/data/index.ts
+++ b/packages/config-yaml/src/schemas/data/index.ts
@@ -23,6 +23,11 @@ import {
chatInteractionEventSchema_0_2_0,
chatInteractionEventSchema_0_2_0_noCode,
} from "./chatInteraction/v0.2.0.js";
+import { editInteractionEventAllSchema } from "./editInteraction/index.js";
+import {
+ editInteractionEventSchema_0_2_0,
+ editInteractionEventSchema_0_2_0_noCode,
+} from "./editInteraction/v0.2.0.js";
import { quickEditEventAllSchema } from "./quickEdit/index.js";
import {
quickEditEventSchema_0_1_0,
@@ -66,7 +71,7 @@ const devEventAllVersionDataSchemas = z.object({
chatFeedback: chatFeedbackEventAllSchema,
tokensGenerated: tokensGeneratedEventAllSchema,
chatInteraction: chatInteractionEventAllSchema,
- // editInteraction: editInteractionEventAllSchema,
+ editInteraction: editInteractionEventAllSchema,
});
// Version and level specific schemas are organized here
@@ -91,14 +96,14 @@ export const devDataVersionedSchemas = {
chatFeedback: chatFeedbackEventSchema_0_2_0,
tokensGenerated: tokensGeneratedEventSchema_0_2_0,
chatInteraction: chatInteractionEventSchema_0_2_0,
- // editInteraction: editInteractionEventSchema_0_2_0,
+ editInteraction: editInteractionEventSchema_0_2_0,
},
noCode: {
autocomplete: autocompleteEventSchema_0_2_0_noCode,
chatFeedback: chatFeedbackEventSchema_0_2_0_noCode,
tokensGenerated: tokensGeneratedEventSchema_0_2_0_noCode,
chatInteraction: chatInteractionEventSchema_0_2_0_noCode,
- // editInteraction: editInteractionEventSchema_0_2_0_noCode,
+ editInteraction: editInteractionEventSchema_0_2_0_noCode,
},
},
};