Skip to content

Commit 2e8922e

Browse files
committed
Added option to edit instruction file
1 parent 0ce699e commit 2e8922e

2 files changed

Lines changed: 49 additions & 4 deletions

File tree

src/app.rs

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,33 @@ impl eframe::App for App {
108108
).show(ctx, |ui_panel| {
109109
if self.editor.is_open() {
110110
ui::editor_panel::show(ui_panel, &mut self.editor);
111-
} else if self.selected_provider.is_some() {
111+
} else if let Some(provider) = self.selected_provider {
112+
let root = self.scan_root();
113+
let dir = scanner::provider_dir(provider, &root, self.scope);
114+
ui_panel.horizontal(|ui| {
115+
ui.label(egui::RichText::new(provider.label()).font(ui::theme::heading_font()).color(ui::theme::TEXT_PRIMARY));
116+
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
117+
if ui.button("Open folder").clicked() { open_path(&dir); }
118+
for md in instruction_files(provider, &root, &dir, self.scope) {
119+
let label = md.file_name().unwrap_or_default().to_string_lossy().to_string();
120+
let exists = md.exists();
121+
let btn_text = if exists { label.clone() } else { format!("+ {}", label) };
122+
let color = if exists { ui::theme::TEXT_ACCENT } else { ui::theme::TEXT_DIM };
123+
if ui.button(egui::RichText::new(btn_text).color(color).font(ui::theme::small_font())).clicked() {
124+
if !exists {
125+
if let Some(p) = md.parent() { let _ = std::fs::create_dir_all(p); }
126+
let _ = std::fs::write(&md, format!("# {} instructions\n", provider.label()));
127+
}
128+
self.editor.open(md);
129+
}
130+
}
131+
});
132+
});
133+
ui_panel.add_space(4.0);
112134
let kinds = self.available_kinds();
113135
ui::item_list::filter_tabs(ui_panel, &mut self.filter, &kinds);
114136
ui_panel.add_space(8.0);
115137
let result = ui::item_list::show(ui_panel, &self.items, self.filter);
116-
// handle toggle
117138
if let Some(idx) = result.index {
118139
if idx < self.items.len() {
119140
match toggler::toggle_item(&mut self.items[idx]) {
@@ -122,7 +143,6 @@ impl eframe::App for App {
122143
}
123144
}
124145
}
125-
// handle edit
126146
if let Some(idx) = result.edit {
127147
if idx < self.items.len() && self.items[idx].editable {
128148
self.editor.open(self.items[idx].path.clone());
@@ -147,3 +167,28 @@ impl eframe::App for App {
147167
}
148168
}
149169
}
170+
171+
fn open_path(path: &std::path::Path) {
172+
let _ = if cfg!(windows) {
173+
std::process::Command::new("explorer").arg(path).spawn()
174+
} else if cfg!(target_os = "macos") {
175+
std::process::Command::new("open").arg(path).spawn()
176+
} else {
177+
std::process::Command::new("xdg-open").arg(path).spawn()
178+
};
179+
}
180+
181+
fn instruction_files(provider: ProviderId, root: &PathBuf, dir: &PathBuf, scope: Scope) -> Vec<PathBuf> {
182+
match (provider, scope) {
183+
(ProviderId::Claude, Scope::Project) => vec![root.join("CLAUDE.md")],
184+
(ProviderId::Claude, Scope::Global) => vec![dir.join("CLAUDE.md")],
185+
(ProviderId::Codex, Scope::Project) => vec![root.join("AGENTS.md")],
186+
(ProviderId::Codex, Scope::Global) => vec![dir.join("AGENTS.md")],
187+
(ProviderId::Gemini, Scope::Project) => vec![root.join("GEMINI.md"), root.join("AGENTS.md")],
188+
(ProviderId::Gemini, Scope::Global) => vec![dir.join("GEMINI.md")],
189+
(ProviderId::Kiro, Scope::Project) => vec![root.join(".kiro").join("steering").join("instructions.md")],
190+
(ProviderId::Kiro, Scope::Global) => vec![dir.join("steering").join("instructions.md")],
191+
(ProviderId::OpenCode, Scope::Project) => vec![root.join("AGENTS.md")],
192+
(ProviderId::OpenCode, Scope::Global) => vec![dir.join("AGENTS.md")],
193+
}
194+
}

src/scanner.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub fn provider_exists(id: ProviderId, root: &Path, scope: Scope) -> bool {
2222
}
2323
}
2424

25-
fn provider_dir(id: ProviderId, root: &Path, scope: Scope) -> PathBuf {
25+
pub fn provider_dir(id: ProviderId, root: &Path, scope: Scope) -> PathBuf {
2626
let home = dirs::home_dir().unwrap_or_else(|| PathBuf::from("."));
2727
match (id, scope) {
2828
(ProviderId::Claude, Scope::Project) => root.join(".claude"),

0 commit comments

Comments
 (0)