Skip to content

Commit a405171

Browse files
Add scaffolding for Codex & Antigravity platforms
- adds --codex and --antigravity init flags - adds inject_instructions_into helper and platform init paths
1 parent ba04c51 commit a405171

2 files changed

Lines changed: 57 additions & 10 deletions

File tree

src/commands/init.rs

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::path::Path;
1+
use std::path::{Path, PathBuf};
22

33
use crate::{
44
config::Config,
@@ -49,10 +49,8 @@ fn load_config_from(base: &str) -> Config {
4949
.unwrap_or_default()
5050
}
5151

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]) {
5654
let existing = std::fs::read_to_string(&path).unwrap_or_default();
5755

5856
let mut block = String::from("<!-- squeez:start -->\n");
@@ -87,6 +85,54 @@ fn inject_copilot_instructions(home: &str, cfg: &Config, summaries: &[memory::Su
8785
let _ = std::fs::write(&path, contents);
8886
}
8987

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+
90136
/// Testable version with explicit directories.
91137
pub fn run_with_dirs(sessions_dir: &Path, memory_dir: &Path, config: &Config) -> i32 {
92138
// 1. Finalise previous session → memory (best-effort)

src/main.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ fn main() {
2525
std::process::exit(exit_code);
2626
}
2727
Some("init") => {
28-
let copilot = args.get(2).map(String::as_str) == Some("--copilot");
29-
let exit_code = if copilot {
30-
squeez::commands::init::run_copilot()
31-
} else {
32-
squeez::commands::init::run()
28+
let opt = args.get(2).map(String::as_str);
29+
let exit_code = match opt {
30+
Some("--copilot") => squeez::commands::init::run_copilot(),
31+
Some("--codex") => squeez::commands::init::run_codex(),
32+
Some("--antigravity") => squeez::commands::init::run_antigravity(),
33+
_ => squeez::commands::init::run(),
3334
};
3435
std::process::exit(exit_code);
3536
}

0 commit comments

Comments
 (0)