diff options
Diffstat (limited to 'src/session.rs')
| -rw-r--r-- | src/session.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/session.rs b/src/session.rs index f27a188..6e3c1c1 100644 --- a/src/session.rs +++ b/src/session.rs | |||
| @@ -51,6 +51,8 @@ fn restrict(path: &Path, mode: u32) { | |||
| 51 | pub struct Session { | 51 | pub struct Session { |
| 52 | pub id: String, | 52 | pub id: String, |
| 53 | pub model: String, | 53 | pub model: String, |
| 54 | /// Directory the session was started in; the system prompt is frozen with it. | ||
| 55 | pub cwd: String, | ||
| 54 | path: PathBuf, | 56 | path: PathBuf, |
| 55 | file: File, | 57 | file: File, |
| 56 | } | 58 | } |
| @@ -83,10 +85,14 @@ impl Session { | |||
| 83 | .map_err(|e| format!("{}: {e}", path.display()))?; | 85 | .map_err(|e| format!("{}: {e}", path.display()))?; |
| 84 | restrict(&path, 0o600); | 86 | restrict(&path, 0o600); |
| 85 | 87 | ||
| 88 | let cwd = std::env::current_dir() | ||
| 89 | .map(|path| path.display().to_string()) | ||
| 90 | .unwrap_or_default(); | ||
| 86 | let header = json!({ | 91 | let header = json!({ |
| 87 | "t": "header", | 92 | "t": "header", |
| 88 | "session": id, | 93 | "session": id, |
| 89 | "model": model, | 94 | "model": model, |
| 95 | "cwd": cwd, | ||
| 90 | "created": now_ms(), | 96 | "created": now_ms(), |
| 91 | "system": system, | 97 | "system": system, |
| 92 | }); | 98 | }); |
| @@ -96,6 +102,7 @@ impl Session { | |||
| 96 | Ok(Session { | 102 | Ok(Session { |
| 97 | id, | 103 | id, |
| 98 | model: model.to_string(), | 104 | model: model.to_string(), |
| 105 | cwd, | ||
| 99 | path, | 106 | path, |
| 100 | file, | 107 | file, |
| 101 | }) | 108 | }) |
| @@ -111,6 +118,7 @@ impl Session { | |||
| 111 | let mut model = String::new(); | 118 | let mut model = String::new(); |
| 112 | let mut system = Value::Null; | 119 | let mut system = Value::Null; |
| 113 | let mut session_id = id.to_string(); | 120 | let mut session_id = id.to_string(); |
| 121 | let mut cwd = String::new(); | ||
| 114 | let mut messages = Vec::new(); | 122 | let mut messages = Vec::new(); |
| 115 | 123 | ||
| 116 | for line in reader.lines() { | 124 | for line in reader.lines() { |
| @@ -134,6 +142,9 @@ impl Session { | |||
| 134 | if let Some(s) = value.get("session").and_then(|s| s.as_str()) { | 142 | if let Some(s) = value.get("session").and_then(|s| s.as_str()) { |
| 135 | session_id = s.to_string(); | 143 | session_id = s.to_string(); |
| 136 | } | 144 | } |
| 145 | if let Some(c) = value.get("cwd").and_then(|c| c.as_str()) { | ||
| 146 | cwd = c.to_string(); | ||
| 147 | } | ||
| 137 | } | 148 | } |
| 138 | Some("msg") => { | 149 | Some("msg") => { |
| 139 | let mut message = value.clone(); | 150 | let mut message = value.clone(); |
| @@ -158,6 +169,7 @@ impl Session { | |||
| 158 | Session { | 169 | Session { |
| 159 | id: session_id, | 170 | id: session_id, |
| 160 | model, | 171 | model, |
| 172 | cwd, | ||
| 161 | path, | 173 | path, |
| 162 | file, | 174 | file, |
| 163 | }, | 175 | }, |
