by adom
Let an AI (Claude, ChatGPT, Codex or any agent) run Altium Designer for you: create symbols and footprints, place parts (also from Altium 365), wire and annotate schematics, Update PCB, set the stack-up and rules, route, pour copper, add mounting holes and stitching vias, run ERC and DRC, and make Gerbers, BOMs and STEP. Free in Hydrogen; bring your own AI and Altium licence.
← Commit history
0.2.98: keep the agent's script project out of the user's Altium workspace (#32)
11 files changed
+346−7
CHANGELOG.md+8@@ -1,5 +1,13 @@ # Changelog +## 0.2.98++- **The agent no longer leaves its script project in your Altium workspace** (#32). Each agent start opens the agent's `AdomAgent_<gen>.PrjScr`, and Altium adds it to the open workspace. In a workspace you saved, that marked the workspace changed, so closing Altium asked "Save changes? <workspace>.DsnWrk", and saving wrote the agent's project into your file. A project from an earlier run could also stay there and reopen at every launch.+ - After each start the bridge compares the open workspace with its `.DsnWrk`. When the agent's project is the only difference, it takes any agent entries out of the file and clears Altium's change flag. The agent clears the flag again when its loop ends, because Altium sets it a moment after a project opens or closes. `altium_agent_start` reports this in `userWorkspace`.+ - If you opened or closed a project yourself in the meantime, the workspace is left exactly as it is.+ - Before it starts Altium, `altium_launch` removes the agent's projects from Altium's automatic last-workspace file (`agentProjectsRemovedFromLastWorkspace`), so Altium no longer reopens them.+- Tested on Altium Designer 26.11.1. A saved workspace with a board project and an earlier agent generation lost the agent entry, and after the agent ran and stopped, closing Altium listed only the board project: the same prompt Altium shows when no agent ran at all. 13 lifecycle and board verbs passed.+ ## 0.2.97 - **The agent starts when the Windows user name has accented or non-Latin letters** (#30). The agent's script carries its workspace folder, and the bridge wrote it as UTF-8 without a byte-order mark. Altium's script engine reads such a file as ANSI, so `C:\Users\Iván…` became `C:\Users\Iván…`, a folder that does not exist. The first heartbeat write failed, the script stopped in Altium's debugger, and `altium_agent_start` ended with `no_heartbeat`. The path is now written with Pascal character codes (`'Iv'#225'n'`), so the script file is plain ASCII and reads the same in any code page.
bridge-rs/src/dsnwrk.rsadded+183@@ -0,0 +1,183 @@+//! The user's Altium workspace file (`.DsnWrk`) and the agent's script project (altium-bridge#32).+//!+//! Every agent start opens `AdomAgent_<gen>.PrjScr`, and Altium adds it to the open workspace. In a workspace the user+//! saved, that marks the workspace changed: closing Altium asked "Save changes? <workspace>.DsnWrk", and a Save wrote+//! the agent's project into the user's own file, where it was reopened on every launch. Altium's automatic+//! `LastWorkspace` file keeps it the same way.+//!+//! Altium writes the file as INI text: `[ProjectGroup]`, then `[Project1]`, `[Project2]`, ... each with a+//! `ProjectPath=` that may be relative to the file. Lines are handled as bytes so a path in any code page survives.++/// Whether a project path is one of the agent's own script projects.+pub fn is_agent_project(path: &str) -> bool {+ let p = path.replace('/', "\\").to_ascii_lowercase();+ p.contains("\\adomagent_") && p.ends_with(".prjscr")+}++fn decode(bytes: &[u8]) -> String {+ let b = bytes.strip_prefix(&[0xEF, 0xBB, 0xBF][..]).unwrap_or(bytes);+ match std::str::from_utf8(b) {+ Ok(s) => s.to_string(),+ // Altium's own files are ANSI on most machines: Latin-1 keeps every byte as one character+ Err(_) => b.iter().map(|&c| c as char).collect(),+ }+}++/// A path written in the file, made absolute against the file's folder and normalised for comparison+/// (`\`, no `.`/`..`, lower case: Windows paths ignore case).+pub fn resolve(dir: &str, path: &str) -> String {+ let p = path.trim().replace('/', "\\");+ let abs = if p.len() >= 2 && p.as_bytes()[1] == b':' || p.starts_with("\\\\") { p } else { format!("{}\\{}", dir.trim_end_matches('\\'), p) };+ let unc = abs.starts_with("\\\\");+ let mut parts: Vec<&str> = Vec::new();+ for c in abs.split('\\') {+ match c {+ "" | "." => {}+ ".." => { if parts.len() > 1 { parts.pop(); } }+ _ => parts.push(c),+ }+ }+ let joined = parts.join("\\");+ (if unc { format!("\\\\{joined}") } else { joined }).to_lowercase()+}++/// Every `ProjectPath=` in the file, as written.+pub fn project_paths(bytes: &[u8]) -> Vec<String> {+ decode(bytes).lines().filter_map(|l| {+ let t = l.trim();+ t.get(..12).filter(|k| k.eq_ignore_ascii_case("projectpath=")).map(|_| t[12..].to_string())+ }).collect()+}++/// The file without the agent's `[ProjectN]` sections, the rest renumbered from 1. `None` when there is none to remove.+pub fn without_agent_projects(bytes: &[u8]) -> Option<Vec<u8>> {+ let crlf = bytes.windows(2).any(|w| w == b"\r\n");+ let lines: Vec<&[u8]> = bytes.split(|&b| b == b'\n').map(|l| l.strip_suffix(b"\r").unwrap_or(l)).collect();+ // sections: (header line index, end exclusive)+ let is_project_header = |l: &[u8]| {+ let t = String::from_utf8_lossy(l).trim().to_ascii_lowercase();+ t.starts_with("[project") && t.ends_with(']') && t[8..t.len() - 1].chars().all(|c| c.is_ascii_digit()) && t.len() > 9+ };+ let is_header = |l: &[u8]| { let t = String::from_utf8_lossy(l); let t = t.trim(); t.starts_with('[') && t.ends_with(']') };+ let mut out: Vec<Vec<u8>> = Vec::new();+ let mut removed = 0;+ let mut n = 0;+ let mut i = 0;+ while i < lines.len() {+ if is_project_header(lines[i]) {+ let mut j = i + 1;+ while j < lines.len() && !is_header(lines[j]) { j += 1; }+ let agent = lines[i + 1..j].iter().any(|l| {+ let s = decode(l);+ let t = s.trim();+ t.get(..12).map(|k| k.eq_ignore_ascii_case("projectpath=")).unwrap_or(false) && is_agent_project(&t[12..])+ });+ if agent {+ removed += 1;+ } else {+ n += 1;+ out.push(format!("[Project{n}]").into_bytes());+ out.extend(lines[i + 1..j].iter().map(|l| l.to_vec()));+ }+ i = j;+ } else {+ out.push(lines[i].to_vec());+ i += 1;+ }+ }+ if removed == 0 {+ return None;+ }+ // a removed section leaves its blank separator behind: no two blank lines in a row+ let mut tidy: Vec<Vec<u8>> = Vec::new();+ for l in out {+ let blank = l.iter().all(|b| b.is_ascii_whitespace());+ if blank && tidy.last().map(|p: &Vec<u8>| p.iter().all(|b| b.is_ascii_whitespace())).unwrap_or(false) { continue; }+ tidy.push(l);+ }+ Some(tidy.join(if crlf { &b"\r\n"[..] } else { &b"\n"[..] }))+}++/// Whether the open workspace differs from its file only by the agent's projects: the projects Altium has open+/// (`open`, absolute, from the agent) against the file's, both without the agent's and without Free Documents.+pub fn differs_only_by_agent(file_bytes: &[u8], file_dir: &str, open: &[String]) -> bool {+ let mut disk: Vec<String> = project_paths(file_bytes).iter().filter(|p| !is_agent_project(p)).map(|p| resolve(file_dir, p)).collect();+ let mut mem: Vec<String> = open.iter().filter(|p| p.contains('\\') && !is_agent_project(p)).map(|p| resolve(file_dir, p)).collect();+ disk.sort();+ disk.dedup();+ mem.sort();+ mem.dedup();+ disk == mem+}++/// Altium's automatic last-workspace files (`%APPDATA%\Altium\<install>\LastWorkspace\*.DsnWrk`).+pub fn last_workspace_files() -> Vec<std::path::PathBuf> {+ let Ok(appdata) = std::env::var("APPDATA") else { return Vec::new() };+ let mut out = Vec::new();+ if let Ok(rd) = std::fs::read_dir(std::path::Path::new(&appdata).join("Altium")) {+ for inst in rd.flatten() {+ if let Ok(files) = std::fs::read_dir(inst.path().join("LastWorkspace")) {+ out.extend(files.flatten().map(|f| f.path()).filter(|p| p.extension().map(|e| e.eq_ignore_ascii_case("dsnwrk")).unwrap_or(false)));+ }+ }+ }+ out+}++/// Remove the agent's projects from a workspace file on disk. Answers whether it changed the file.+pub fn scrub_file(path: &std::path::Path) -> bool {+ let Ok(bytes) = std::fs::read(path) else { return false };+ match without_agent_projects(&bytes) {+ Some(clean) => std::fs::write(path, clean).is_ok(),+ None => false,+ }+}++#[cfg(test)]+mod tests {+ use super::*;++ const IVAN: &str = "[ProjectGroup]\r\nVersion=1.0\r\n\r\n[Project1]\r\nProjectPath=Board\\Board.PrjPcb\r\n\r\n[Project2]\r\nProjectPath=..\\..\\..\\Users\\u\\AppData\\Local\\Adom Bridge\\bridges-cache\\altium\\agent\\AD24\\AdomAgent_4005dc0085.PrjScr\r\n\r\n[Project3]\r\nProjectPath=Lib\\Lib.LibPkg\r\n";++ #[test]+ fn removes_only_the_agent_projects_and_renumbers() {+ let out = String::from_utf8(without_agent_projects(IVAN.as_bytes()).unwrap()).unwrap();+ assert_eq!(out, "[ProjectGroup]\r\nVersion=1.0\r\n\r\n[Project1]\r\nProjectPath=Board\\Board.PrjPcb\r\n\r\n[Project2]\r\nProjectPath=Lib\\Lib.LibPkg\r\n");+ // nothing of ours: the file is left alone+ assert!(without_agent_projects(out.as_bytes()).is_none());+ // a user's own script project is not ours+ assert!(!is_agent_project(r"C:\Scripts\MyTools.PrjScr"));+ assert!(is_agent_project(r"C:/x/agent/AD26/AdomAgent_a086cfbf3f.PrjScr"));+ }++ #[test]+ fn paths_compare_resolved_and_without_case() {+ assert_eq!(resolve(r"C:\Users\u\Documents\ws", r"..\Boards\B.PrjPcb"), r"c:\users\u\documents\boards\b.prjpcb");+ assert_eq!(resolve(r"C:\ws", r"D:\X\Y.PrjPcb"), r"d:\x\y.prjpcb");+ }++ #[test]+ fn only_the_agent_difference_counts_as_ours() {+ let dir = r"C:\Users\u\Documents\ws";+ let open = vec!["Free Documents".to_string(), r"C:\Users\u\Documents\ws\Board\Board.PrjPcb".to_string(),+ r"C:\Users\u\Documents\ws\Lib\Lib.LibPkg".to_string(),+ r"C:\Users\u\AppData\Local\Adom Bridge\bridges-cache\altium\agent\AD24\AdomAgent_a086cfbf3f.PrjScr".to_string()];+ assert!(differs_only_by_agent(IVAN.as_bytes(), dir, &open));+ // the user opened another project: their change, the workspace stays changed+ let mut more = open.clone();+ more.push(r"C:\Other\Other.PrjPcb".to_string());+ assert!(!differs_only_by_agent(IVAN.as_bytes(), dir, &more));+ // or closed one+ assert!(!differs_only_by_agent(IVAN.as_bytes(), dir, &open[..2]));+ }++ #[test]+ fn an_ansi_file_keeps_its_bytes() {+ let mut f = b"[ProjectGroup]\r\nVersion=1.0\r\n\r\n[Project1]\r\nProjectPath=C:\\Users\\Iv".to_vec();+ f.push(0xE1); // á in Windows-1252+ f.extend_from_slice(b"n\\B.PrjPcb\r\n\r\n[Project2]\r\nProjectPath=C:\\x\\AdomAgent_1.PrjScr\r\n");+ let out = without_agent_projects(&f).unwrap();+ assert!(out.windows(3).any(|w| w == [b'v', 0xE1, b'n']));+ assert!(!String::from_utf8_lossy(&out).contains("AdomAgent"));+ }+}
bridge-rs/src/lifecycle.rs+36@@ -101,6 +101,41 @@ pub fn install() -> Value { "pas": pas.to_string_lossy(), "digest": &base[base.len() - 10..]}) } +/// After a start: the agent's script project joined the open workspace. When it is the only difference from the+/// workspace file, take the agent's entries out of the file and clear Altium's change flag, so closing Altium does+/// not ask to save the workspace and the agent never lands in the user's file (#32). A workspace with changes of the+/// user's own is left exactly as it is.+fn leave_workspace_unchanged() -> Value {+ let keep = agent::workspace_dir().join("keep_ws.txt");+ let _ = std::fs::remove_file(&keep);+ let info = agent::call("workspace_info", &[], None, Duration::from_secs(10));+ let d = info.get("data").cloned().unwrap_or(Value::Null);+ let path = d.get("path").and_then(|p| p.as_str()).unwrap_or("").to_string();+ let modified = d.get("modified").and_then(|m| m.as_bool());+ let projects: Vec<String> = d.get("projects").and_then(|a| a.as_array())+ .map(|a| a.iter().filter_map(|p| p.as_str().map(str::to_string)).collect()).unwrap_or_default();+ // Altium's unsaved default group has no folder in its path and never asks; it is cleaned at the next launch+ if !path.contains('\\') {+ return json!({"workspace": path, "action": "none", "why": "Altium's default workspace, not a file of the user's"});+ }+ let file = std::path::Path::new(&path);+ let dir = file.parent().map(|p| p.to_string_lossy().to_string()).unwrap_or_default();+ let Ok(bytes) = std::fs::read(file) else {+ return json!({"workspace": path, "action": "none", "why": "the workspace file could not be read"});+ };+ if !crate::dsnwrk::differs_only_by_agent(&bytes, &dir, &projects) {+ return json!({"workspace": path, "action": "none", "modified": modified, "why": "the open workspace has changes of the user's own; it is left as it is"});+ }+ let removed = crate::dsnwrk::scrub_file(file);+ // Altium sets the flag a moment after a project opens or closes, so the agent clears it again when its loop ends+ let mine: Vec<&String> = projects.iter().filter(|p| p.contains('\\') && !crate::dsnwrk::is_agent_project(p)).collect();+ let note = std::iter::once(&path).chain(mine.into_iter()).cloned().collect::<Vec<_>>().join("\r\n") + "\r\n";+ let noted = std::fs::write(&keep, agent::agent_text(¬e)).is_ok();+ let flag = agent::call("workspace_set_unmodified", &[], None, Duration::from_secs(10));+ json!({"workspace": path, "action": "kept_unchanged", "agentEntriesRemovedFromFile": removed,+ "changeFlagClearedNow": flag.get("success").and_then(|b| b.as_bool()) == Some(true), "clearedAgainWhenTheAgentStops": noted})+}+ /// Keep the newest `keep` generations so an open editor tab never dangles. fn prune_generations(keep: usize) { let ws = agent::workspace_dir();@@ -606,6 +641,7 @@ fn start_impl(mut wait: Duration) -> Value { "dialogs": crate::dialogs::scan(), "install": inst, "_hint": "The agent script started in Altium and stopped on its first command. READ errorShot when it is present: it is Altium's own error box, naming the line. The bridge has sent the stop, so Altium is not left on a breakpoint (if Altium still refuses to close a document, press Stop on its Debug toolbar). Please report it on adom/altium-bridge with this reply, the Altium version and errorShot: it is a bug in the agent on this Altium build."}); }+ out["userWorkspace"] = leave_workspace_unchanged(); if retried { out["resentBootstrap"] = json!(true); out["_hint"] = json!("The first RunScript hand-off was swallowed (Altium was busy); the bridge sent it again and the agent came up. Nothing for the caller to do.");
bridge-rs/src/main.rs+2−1@@ -4,6 +4,7 @@ mod a365; mod ab; mod agent;+mod dsnwrk; mod assembly; mod autoclass; mod board;@@ -80,7 +81,7 @@ use tiny_http::{Header, Method, Response, Server}; /// Attached to every failed reply (see the /command handler). const REPORT_ISSUES: &str = "If this looks like an altium-bridge BUG (not a refusal you expected), report it: check for a duplicate with `adom-wiki issue list adom/altium-bridge`, then `adom-wiki issue create adom/altium-bridge --title \"<verb>: <one-line symptom>\" --category bug-report --body \"<what you ran, what you expected, what happened, the VERBATIM response JSON (and errorShot if present), bridgeVersion, the Altium version from altium_status, the OS>\"`. A relay, routing, toast or lifecycle problem belongs on adom/adom-bridge instead. Reports from real machines are how this bridge gets correct: three different Altium builds behaved three different ways in one weekend."; -pub const BRIDGE_VERSION: &str = "0.2.97";+pub const BRIDGE_VERSION: &str = "0.2.98"; fn json_response(status: u16, body: &serde_json::Value) -> Response<std::io::Cursor<Vec<u8>>> { let data = serde_json::to_vec(body).unwrap_or_else(|_| b"{}".to_vec());
bridge-rs/src/misc.rs+5−1@@ -391,6 +391,10 @@ pub fn launch(args: &Value) -> Value { let hand_back = args.get("background").and_then(|b| b.as_bool()).unwrap_or(true); let user_fg = if hand_back { lifecycle::foreground_hwnd_pub() } else { None }; let exe = inst.get("exe").and_then(|e| e.as_str()).unwrap_or("").to_string();+ // Altium reopens its last workspace at start, and that kept the agent's script project from earlier runs (#32)+ let scrubbed: Vec<String> = if lic.get("running").and_then(|b| b.as_bool()) != Some(true) {+ crate::dsnwrk::last_workspace_files().into_iter().filter(|f| crate::dsnwrk::scrub_file(f)).map(|f| f.to_string_lossy().to_string()).collect()+ } else { Vec::new() }; if let Err(e) = lifecycle::spawn_helper_pub(&exe, "") { progress::end("cold_start", "bridge"); return json!({"success": false, "error": format!("launch failed: {e}")});@@ -412,7 +416,7 @@ pub fn launch(args: &Value) -> Value { } return json!({"success": true, "startedInSec": support::elapsed_round(t0), "licence": lic, "windowEtiquette": if returned.is_null() { "foreground" } else { "background" },- "foregroundReturnedTo": returned,+ "foregroundReturnedTo": returned, "agentProjectsRemovedFromLastWorkspace": scrubbed, "_hint": if returned.is_null() { "Altium's own launch foregrounds itself. Next: altium_readiness; if unlicensed, altium_license." } else { "Altium is up and the user's own window was handed back (it launches in front of everything and cannot be told not to). Pass background:false if the user asked to SEE Altium come up. Next: altium_readiness; if unlicensed, altium_license." }}); }
bridge-rs/src/verbs.rs+1−1@@ -263,7 +263,7 @@ fn describe() -> Value { // ---- agent / REPL ---- verb_doc("agent_start", "Bootstrap the resident DelphiScript agent inside Altium (renders the script, runs it through the -R lane, waits for the heartbeat). Optional: every agent-backed verb does this on demand.", json!({"waitSec": "int, default 45 - how long to wait for the first heartbeat"}),- json!({"startedInSec": "float", "alreadyRunning": "bool", "generation": "string - AdomAgent_<digest>", "install": "object - the rendered script", "strayHelpersKilled": "[pid]", "parkedLoopStopped": "[step] - an earlier loop was parked in the debugger and was stopped first"}), 120,+ json!({"startedInSec": "float", "alreadyRunning": "bool", "generation": "string - AdomAgent_<digest>", "install": "object - the rendered script", "strayHelpersKilled": "[pid]", "parkedLoopStopped": "[step] - an earlier loop was parked in the debugger and was stopped first", "userWorkspace": "{workspace, action: kept_unchanged|none, agentEntriesRemovedFromFile, changeFlagClearedNow, clearedAgainWhenTheAgentStops, why} - the agent's script project joins the open workspace; when it is the only change, it is kept out of the user's .DsnWrk and Altium will not ask to save the workspace"}), 120, "After success altium_eval / altium_run_command / altium_state go through the agent in milliseconds. Do NOT use altium_run_script while it is up.", &["agent_status", "agent_stop", "agent_recover", "eval"], &["The bootstrap ACTIVATES Altium for a moment (it opens the .PrjScr in the script editor); the bridge hands the user's foreground window back.",
package.json+1−1@@ -1,6 +1,6 @@ { "slug": "altium-bridge",- "version": "0.2.97",+ "version": "0.2.98", "type": "app", "description": "Let an AI (Claude, ChatGPT, Codex or any agent) run Altium Designer for you: create symbols and footprints, place parts (also from Altium 365), wire and annotate schematics, Update PCB, set the stack-up and rules, route, pour copper, add mounting holes and stitching vias, run ERC and DRC, and make Gerbers, BOMs and STEP. Free in Hydrogen; bring your own AI and Altium licence.", "tags": [
page.json+1−1@@ -4,7 +4,7 @@ "type": "app", "title": "Altium Bridge: AI for Altium Designer", "brief": "Let an AI (Claude, ChatGPT, Codex or any agent) run Altium Designer for you: create symbols and footprints, place parts (also from Altium 365), wire and annotate schematics, Update PCB, set the stack-up and rules, route, pour copper, add mounting holes and stitching vias, run ERC and DRC, and make Gerbers, BOMs and STEP. Free in Hydrogen; bring your own AI and Altium licence.",- "version": "0.2.97",+ "version": "0.2.98", "hero": { "type": "image", "path": "screenshots/hero.png"
src/BRIDGE_VERSION+1−1@@ -1 +1 @@-0.2.97+0.2.98
src/agent/AdomAgent.pas.tmpl+107@@ -9651,6 +9651,110 @@ Begin Result := '{' + JRaw('ok','true') + ',' + JRaw('closed', IntToStr(CloseOldAgents)) + '}'; End; +{ workspace_info / workspace_set_unmodified (altium-bridge#32): every start opens this agent's script project, and+ Altium adds it to the open workspace, which marks a workspace the user saved as changed ("Save changes?+ <workspace>.DsnWrk" on close, and a Save writes the agent into their file). The bridge compares the open projects+ with the file and, when the agent's project is the only difference, has the change flag cleared. }+Function CmdWorkspaceInfo(Lines : TStringList) : String;+Var+ WS : IWorkspace;+ D : IServerDocument;+ Prj : IProject;+ I : Integer;+ P, L, M : String;+Begin+ WS := GetWorkspace;+ If WS = Nil Then+ Begin+ Result := '{' + JRaw('ok','true') + ',' + JStr('path','') + ',' + JRaw('projects','[]') + '}';+ Exit;+ End;+ P := WS.DM_WorkspaceFullPath;+ M := 'null';+ D := Client.GetDocumentByPath(P);+ If D <> Nil Then+ Begin+ If D.Modified Then M := 'true' Else M := 'false';+ End;+ L := '';+ For I := 0 To WS.DM_ProjectCount - 1 Do+ Begin+ Prj := WS.DM_Projects(I);+ If Prj <> Nil Then+ Begin+ If L <> '' Then L := L + ',';+ L := L + '"' + JsonEsc(Prj.DM_ProjectFullPath) + '"';+ End;+ End;+ Result := '{' + JRaw('ok','true') + ',' + JStr('path', P) + ',' + JRaw('modified', M) + ',' + JRaw('projects', '[' + L + ']') + '}';+End;++{ On the way out of the loop: the bridge wrote keep_ws.txt at start when the agent's own project was the only change+ to the open workspace (line 1 the workspace, then the user's projects as they were). Altium marks the workspace+ changed a moment after a project opens or closes, so the flag is cleared here, once more, if the workspace still+ holds exactly those projects. Anything the user opened or closed since leaves it alone. }+Procedure KeepWorkspaceUnchanged;+Var+ WS : IWorkspace;+ D : IServerDocument;+ Prj : IProject;+ Want, Have : TStringList;+ I : Integer;+ P : String;+ Same : Boolean;+Begin+ If Not FileExists(WORKSPACE + 'keep_ws.txt') Then Exit;+ Want := TStringList.Create;+ Have := TStringList.Create;+ Try+ Want.Text := ReadAll(WORKSPACE + 'keep_ws.txt');+ WS := GetWorkspace;+ If (WS <> Nil) And (Want.Count > 0) Then+ Begin+ If UpperCase(WS.DM_WorkspaceFullPath) = UpperCase(Want[0]) Then+ Begin+ For I := 0 To WS.DM_ProjectCount - 1 Do+ Begin+ Prj := WS.DM_Projects(I);+ If Prj <> Nil Then+ Begin+ P := UpperCase(Prj.DM_ProjectFullPath);+ If (Pos('\', P) > 0) And (Pos('\ADOMAGENT_', P) = 0) Then Have.Add(P);+ End;+ End;+ Same := Have.Count = Want.Count - 1;+ For I := 1 To Want.Count - 1 Do+ Begin+ If Have.IndexOf(UpperCase(Want[I])) < 0 Then Same := False;+ End;+ If Same Then+ Begin+ D := Client.GetDocumentByPath(WS.DM_WorkspaceFullPath);+ If D <> Nil Then D.Modified := False;+ End;+ End;+ End;+ Finally+ Want.Free;+ Have.Free;+ End;+End;++Function CmdWorkspaceSetUnmodified(Lines : TStringList) : String;+Var+ WS : IWorkspace;+ D : IServerDocument;+Begin+ Result := '{' + JRaw('ok','false') + ',' + JStr('error','no open workspace') + '}';+ WS := GetWorkspace;+ If WS = Nil Then Exit;+ D := Client.GetDocumentByPath(WS.DM_WorkspaceFullPath);+ If D = Nil Then Exit;+ D.Modified := False;+ If D.Modified Then Result := '{' + JRaw('ok','false') + ',' + JStr('error','Altium kept the workspace marked changed') + '}'+ Else Result := '{' + JRaw('ok','true') + '}';+End;+ { --------------------------------------------------------------------------------------------------------------- Schematic wiring as data (the EDA Bridge Standard's sch_* verbs). The bridge does the planning in Rust; the agent only dumps a sheet's wiring and applies a list of primitive steps as one undo step.@@ -10693,6 +10797,8 @@ Begin Else If Cmd = 'place_parts' Then Result := CmdPlaceParts(Lines, Payload) Else If Cmd = 'model_check' Then Result := CmdModelCheck(Lines) Else If Cmd = 'close_old_agents' Then Result := CmdCloseOldAgents(Lines)+ Else If Cmd = 'workspace_info' Then Result := CmdWorkspaceInfo(Lines)+ Else If Cmd = 'workspace_set_unmodified' Then Result := CmdWorkspaceSetUnmodified(Lines) Else If Cmd = 'silk_state' Then Result := CmdSilkState(Lines) Else If Cmd = 'apply_silk' Then Result := CmdApplySilk(Lines, Payload) Else If Cmd = 'build_footprint' Then Result := CmdBuildFootprint(Lines)@@ -10854,6 +10960,7 @@ Begin Sleep(SleepMs); End; Try+ KeepWorkspaceUnchanged; WriteAtomic(WORKSPACE + 'agent.json', '{' + JStr('version', AGENT_VERSION) + ',' + JRaw('stoppedTick', IntToStr(GetTickCount)) + ',' + JRaw('requests', IntToStr(gRequests)) + '}'); If FileExists(WORKSPACE + 'hb.txt') Then DeleteFile(WORKSPACE + 'hb.txt'); Except
src/bridge.json+1−1@@ -2,7 +2,7 @@ "manifest_version": 1, "name": "altium", "displayName": "Altium Designer",- "version": "0.2.97",+ "version": "0.2.98", "description": "Drive Altium Designer from Adom: a resident DelphiScript agent (eval + the 1,100-command process launcher), the X2 -R command line, UIA over the VCL shell, dialogs by PID, screenshots of every Altium window, and Altium 365.", "homepage": "https://wiki.adom.inc/adom/altium-bridge", "docs": "https://wiki.adom.inc/adom/altium-bridge",