Skip to content

Commit 64bc1a3

Browse files
koki-developclaude
andcommitted
feat: Integrate file editing with cat responses
- Update Cat class to use new Action type system - Add 20% random probability for file editing on any message - Integrate FileEditor with cat response system - Update App.tsx to handle action-based messages 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 9bbc90f commit 64bc1a3

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

src/App.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ export const App: React.FC = () => {
3232
.then((response) => {
3333
const message: Message = {
3434
id: Date.now(),
35-
text: response,
35+
text: response.text,
3636
sender: "cat",
37+
action: response.action,
3738
};
3839
setMessages((prev) => [...prev, message]);
3940
})

src/lib/cat.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import type { Action } from "../components/types";
2+
import { FileEditor } from "./fileEditor";
3+
14
type CatVocabulary = {
25
[key: string]: string[];
36
};
@@ -6,7 +9,14 @@ type EmotionKeywords = {
69
[key: string]: string[];
710
};
811

12+
type CatResponse = {
13+
text: string;
14+
action?: Action;
15+
};
16+
917
export class Cat {
18+
private fileEditor = new FileEditor();
19+
1020
private vocabulary: CatVocabulary = {
1121
greeting: ["ニャッ", "ミャッ", "ニャ"],
1222
affection: ["ニャオ~ン", "ミャオ~", "ニャンニャン"],
@@ -92,11 +102,28 @@ export class Cat {
92102
return Math.floor(Math.random() * 1000) + 300; // 300-1300ms
93103
}
94104

95-
async response(message: string): Promise<string> {
105+
async response(message: string): Promise<CatResponse> {
96106
const thinkingTime = this.getRandomThinkingTime();
97107
await new Promise((resolve) => setTimeout(resolve, thinkingTime));
98108

99109
const emotion = this.detectEmotion(message);
100-
return this.getRandomResponse(emotion);
110+
const catText = this.getRandomResponse(emotion);
111+
112+
// Execute file editing with random probability (20% chance)
113+
const shouldEditFile = Math.random() < 0.2;
114+
115+
if (shouldEditFile) {
116+
const diff = await this.fileEditor.edit();
117+
if (diff) {
118+
return {
119+
text: catText,
120+
action: { type: "edit", diff },
121+
};
122+
}
123+
}
124+
125+
return {
126+
text: catText,
127+
};
101128
}
102129
}

0 commit comments

Comments
 (0)