Skip to content

Agent Zero AI framework

Fix Editor manual open behavior

Alessandro16f724226a10
diff --git a/plugins/_editor/webui/editor-store.js b/plugins/_editor/webui/editor-store.js
index e0e3c3682..c4293320a 100644
--- a/plugins/_editor/webui/editor-store.js
+++ b/plugins/_editor/webui/editor-store.js
@@ -225,7 +225,6 @@ const model = {
_previewEnhanceTimer: null,
_staticHighlightPromise: null,
_pendingPreviewFragment: "",
- _initialCreatePromise: null,
async init() {
if (this._initialized) return;
@@ -244,7 +243,6 @@ const model = {
this._mode = options?.mode === "canvas" ? "canvas" : "modal";
if (this._mode === "modal") {
this.setupMarkdownModal(element);
- await this.ensureInitialMarkdownFile();
}
this.scheduleSourceEditorInit();
},
@@ -261,7 +259,6 @@ const model = {
});
return;
}
- await this.ensureInitialMarkdownFile();
},
beforeHostHidden() {
@@ -848,24 +845,20 @@ const model = {
});
},
- async ensureInitialMarkdownFile() {
- if (this.session || this.visibleTabs().length > 0 || this.loading) return null;
- if (!this._root || this._initialCreatePromise) return this._initialCreatePromise;
- this._initialCreatePromise = this.create("document", "md").finally(() => {
- this._initialCreatePromise = null;
- });
- return await this._initialCreatePromise;
- },
-
async openFileBrowser() {
let workdirPath = "/a0/usr/workdir";
try {
- const response = await callJsonApi("settings_get", null);
- workdirPath = response?.settings?.workdir_path || workdirPath;
+ const home = await callEditor("home");
+ if (home?.path) {
+ workdirPath = home.path;
+ } else {
+ const response = await callJsonApi("settings_get", null);
+ workdirPath = response?.settings?.workdir_path || workdirPath;
+ }
} catch {
try {
- const home = await callEditor("home");
- workdirPath = home?.path || workdirPath;
+ const response = await callJsonApi("settings_get", null);
+ workdirPath = response?.settings?.workdir_path || workdirPath;
} catch {
// The file browser can still open with the static fallback.
}
diff --git a/tests/test_office_canvas_setup.py b/tests/test_office_canvas_setup.py
index 28935ba67..b4c398a80 100644
--- a/tests/test_office_canvas_setup.py
+++ b/tests/test_office_canvas_setup.py
@@ -140,10 +140,13 @@ def test_right_canvas_uses_desktop_surface_id_and_migrates_legacy_office_state()
assert "editor-preview-title" in editor_web_panel
assert "editor-preview-page-editor" in editor_web_panel
assert "editor-table-wrap" in editor_web_panel
+ assert "editor-empty" in editor_web_panel
+ assert "runNewMenuAction('open')" in editor_web_panel
+ assert "runNewMenuAction('markdown')" in editor_web_panel
assert "closeAllFiles" in editor_store
assert "confirmPendingClose" in editor_store
- assert "ensureInitialMarkdownFile" in editor_store
- assert "await this.ensureInitialMarkdownFile();" in editor_store
+ assert "ensureInitialMarkdownFile" not in editor_store
+ assert "_initialCreatePromise" not in editor_store
assert "startPreviewEdit" in editor_store
assert "applyPreviewEdit" in editor_store
assert "previewEditDirty" in editor_store
@@ -502,6 +505,20 @@ def test_editor_plugin_owns_markdown_sessions_and_active_context_extras():
assert "syncTextEditorResultsIntoOpenEditor" in editor_result_sync
+def test_editor_open_file_browser_prefers_context_home_before_workdir_fallback():
+ editor_store = read("plugins", "_editor", "webui", "editor-store.js")
+ start = editor_store.index("async openFileBrowser()")
+ end = editor_store.index("\n async openPath", start)
+ open_file_browser = editor_store[start:end]
+
+ home_lookup = open_file_browser.index('const home = await callEditor("home");')
+ settings_fallback = open_file_browser.index('const response = await callJsonApi("settings_get", null);')
+
+ assert home_lookup < settings_fallback
+ assert "workdirPath = home.path;" in open_file_browser
+ assert "workdirPath = response?.settings?.workdir_path || workdirPath;" in open_file_browser
+
+
def test_office_and_desktop_skills_are_rehomed_and_renamed():
office_skills = PROJECT_ROOT / "plugins" / "_office" / "skills"
desktop_skills = PROJECT_ROOT / "plugins" / "_desktop" / "skills"