|
1 | | -use std::path::Path; |
| 1 | +use std::path::{Path, PathBuf}; |
2 | 2 |
|
3 | 3 | use crate::{ |
4 | 4 | config::Config, |
@@ -49,10 +49,8 @@ fn load_config_from(base: &str) -> Config { |
49 | 49 | .unwrap_or_default() |
50 | 50 | } |
51 | 51 |
|
52 | | -/// Replaces the squeez block (<!-- squeez:start --> … <!-- squeez:end -->) |
53 | | -/// in ~/.copilot/copilot-instructions.md, creating the file if absent. |
54 | | -fn inject_copilot_instructions(home: &str, cfg: &Config, summaries: &[memory::Summary]) { |
55 | | - let path = format!("{}/.copilot/copilot-instructions.md", home); |
| 52 | +/// Generic injector: writes/replaces the squeez block in the given file path. |
| 53 | +fn inject_instructions_into(path: &str, cfg: &Config, summaries: &[memory::Summary]) { |
56 | 54 | let existing = std::fs::read_to_string(&path).unwrap_or_default(); |
57 | 55 |
|
58 | 56 | let mut block = String::from("<!-- squeez:start -->\n"); |
@@ -87,6 +85,54 @@ fn inject_copilot_instructions(home: &str, cfg: &Config, summaries: &[memory::Su |
87 | 85 | let _ = std::fs::write(&path, contents); |
88 | 86 | } |
89 | 87 |
|
| 88 | +/// Backwards-compatible wrapper for Copilot injection |
| 89 | +fn inject_copilot_instructions(home: &str, cfg: &Config, summaries: &[memory::Summary]) { |
| 90 | + let path = format!("{}/.copilot/copilot-instructions.md", home); |
| 91 | + inject_instructions_into(&path, cfg, summaries); |
| 92 | +} |
| 93 | + |
| 94 | +/// Entry point called from main.rs: `squeez init --codex` |
| 95 | +/// Creates ~/.codex/squeez and injects a squeez block into ~/.codex/codex-instructions.md |
| 96 | +pub fn run_codex() -> i32 { |
| 97 | + let home = std::env::var("HOME").unwrap_or_default(); |
| 98 | + // Honour SQUEEZ_DIR override, default to ~/.codex/squeez |
| 99 | + let base = std::env::var("SQUEEZ_DIR") |
| 100 | + .unwrap_or_else(|_| format!("{}/.codex/squeez", home)); |
| 101 | + let sessions = PathBuf::from(&base).join("sessions"); |
| 102 | + let mem = PathBuf::from(&base).join("memory"); |
| 103 | + let _ = std::fs::create_dir_all(&sessions); |
| 104 | + let _ = std::fs::create_dir_all(&mem); |
| 105 | + |
| 106 | + let cfg = load_config_from(&base); |
| 107 | + let code = run_with_dirs(&sessions, &mem, &cfg); |
| 108 | + |
| 109 | + let summaries = memory::read_last_n(&mem, 3); |
| 110 | + inject_instructions_into(&format!("{}/.codex/codex-instructions.md", home), &cfg, &summaries); |
| 111 | + |
| 112 | + code |
| 113 | +} |
| 114 | + |
| 115 | +/// Entry point called from main.rs: `squeez init --antigravity` |
| 116 | +/// Creates ~/.antigravity/squeez and injects a squeez block into ~/.antigravity/antigravity-instructions.md |
| 117 | +pub fn run_antigravity() -> i32 { |
| 118 | + let home = std::env::var("HOME").unwrap_or_default(); |
| 119 | + // Honour SQUEEZ_DIR override, default to ~/.antigravity/squeez |
| 120 | + let base = std::env::var("SQUEEZ_DIR") |
| 121 | + .unwrap_or_else(|_| format!("{}/.antigravity/squeez", home)); |
| 122 | + let sessions = PathBuf::from(&base).join("sessions"); |
| 123 | + let mem = PathBuf::from(&base).join("memory"); |
| 124 | + let _ = std::fs::create_dir_all(&sessions); |
| 125 | + let _ = std::fs::create_dir_all(&mem); |
| 126 | + |
| 127 | + let cfg = load_config_from(&base); |
| 128 | + let code = run_with_dirs(&sessions, &mem, &cfg); |
| 129 | + |
| 130 | + let summaries = memory::read_last_n(&mem, 3); |
| 131 | + inject_instructions_into(&format!("{}/.antigravity/antigravity-instructions.md", home), &cfg, &summaries); |
| 132 | + |
| 133 | + code |
| 134 | +} |
| 135 | + |
90 | 136 | /// Testable version with explicit directories. |
91 | 137 | pub fn run_with_dirs(sessions_dir: &Path, memory_dir: &Path, config: &Config) -> i32 { |
92 | 138 | // 1. Finalise previous session → memory (best-effort) |
|
0 commit comments