Skip to content

Commit 932f0bf

Browse files
committed
feat(debug): add Debug Overrides dialog under Diagnostic Tools
Dev-only command (debug.debugOverrides) that surfaces local-service override toggles without rebuilding. Values are persisted as a single JSON blob in localStorage under LOCAL_OVERIDES_FOR_PHOIENXI_DEBUG so any consumer can read flags with one getItem. First flag: AI_PANEL_LOCAL_OVERRIDE — when set, AIChatPanel switches the onboarding iframe from production to localhost:5555. Dialog shows one row per toggle with a checkbox, label, and a small fa-circle-info icon whose `title` carries the full explanation, so extra overrides can be added later without growing the dialog body.
1 parent ca841f8 commit 932f0bf

4 files changed

Lines changed: 119 additions & 0 deletions

File tree

src/brackets.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ define(function (require, exports, module) {
143143
require("thirdparty/tinycolor");
144144
require("utils/LocalizationUtils");
145145
require("phoenix-builder/main");
146+
require("phoenix-builder/debug-overrides");
146147

147148
// DEPRECATED: In future we want to remove the global CodeMirror, but for now we
148149
// expose our required CodeMirror globally so as to avoid breaking extensions in the

src/extensions/default/DebugCommands/main.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,7 @@ define(function (require, exports, module) {
830830
diagnosticsSubmenu.addMenuItem(DEBUG_BUILD_TESTS);
831831
if (AppConfig.config.environment === "dev") {
832832
diagnosticsSubmenu.addMenuItem("debug.phoenixBuilderConnect");
833+
diagnosticsSubmenu.addMenuItem("debug.debugOverrides");
833834
}
834835
diagnosticsSubmenu.addMenuDivider();
835836
diagnosticsSubmenu.addMenuItem(DEBUG_ENABLE_LOGGING);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<div class="phoenix-debug-overrides modal">
2+
<div class="modal-header">
3+
<h1 class="dialog-title">Debug Overrides</h1>
4+
</div>
5+
<div class="modal-body">
6+
<div style="margin-bottom: 6px;">
7+
<label style="display: flex; align-items: center; gap: 8px;">
8+
<input type="checkbox" class="ai-panel-local-override" {{#aiPanelLocalOverride}}checked{{/aiPanelLocalOverride}}>
9+
<span>AI panel onboarding — local server</span>
10+
<i class="fa-solid fa-circle-info"
11+
style="opacity: 0.5; cursor: help; font-size: 12px;"
12+
title="Load http://localhost:5555/onbaording_v5/ instead of the production https://ai-panel-onboarding.phcode.dev/onbaording_v5/. Reload Phoenix after toggling."></i>
13+
</label>
14+
</div>
15+
</div>
16+
<div class="modal-footer">
17+
<button class="dialog-button btn" data-button-id="cancel">Cancel</button>
18+
<button class="dialog-button btn primary" data-button-id="ok">Save</button>
19+
</div>
20+
</div>
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
* GNU AGPL-3.0 License
3+
*
4+
* Copyright (c) 2021 - present core.ai . All rights reserved.
5+
*
6+
* This program is free software: you can redistribute it and/or modify it
7+
* under the terms of the GNU Affero General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
14+
* for more details.
15+
*
16+
* You should have received a copy of the GNU Affero General Public License
17+
* along with this program. If not, see https://opensource.org/licenses/AGPL-3.0.
18+
*
19+
*/
20+
21+
/*globals AppConfig*/
22+
23+
/**
24+
* Debug → Diagnostic Tools → Debug Overrides
25+
*
26+
* A small dev-only dialog for toggling local-service overrides
27+
* without rebuilding. Values are persisted as a single JSON blob in
28+
* localStorage under LOCAL_OVERIDES_FOR_PHOIENXI_DEBUG so consumers
29+
* can read overrides at startup with a single getItem.
30+
*
31+
* Read flags from anywhere via:
32+
* const overrides = (function () {
33+
* try { return JSON.parse(localStorage.getItem(
34+
* "LOCAL_OVERIDES_FOR_PHOIENXI_DEBUG")) || {}; }
35+
* catch (e) { return {}; }
36+
* })();
37+
* if (overrides.AI_PANEL_LOCAL_OVERRIDE) { ... }
38+
*/
39+
define(function (require, exports, module) {
40+
41+
if (!window.AppConfig || AppConfig.config.environment !== "dev") {
42+
return;
43+
}
44+
45+
const CommandManager = require("command/CommandManager"),
46+
Dialogs = require("widgets/Dialogs"),
47+
Mustache = require("thirdparty/mustache/mustache"),
48+
OverridesTpl = require("text!./debug-overrides-dialog.html");
49+
50+
const COMMAND_ID = "debug.debugOverrides";
51+
const STORAGE_KEY = "LOCAL_OVERIDES_FOR_PHOIENXI_DEBUG";
52+
53+
function _readOverrides() {
54+
try {
55+
const raw = localStorage.getItem(STORAGE_KEY);
56+
if (!raw) { return {}; }
57+
const parsed = JSON.parse(raw);
58+
return (parsed && typeof parsed === "object") ? parsed : {};
59+
} catch (e) {
60+
return {};
61+
}
62+
}
63+
64+
function _writeOverrides(obj) {
65+
try {
66+
localStorage.setItem(STORAGE_KEY, JSON.stringify(obj || {}));
67+
} catch (e) {
68+
console.warn("[Debug Overrides] Failed to persist:", e);
69+
}
70+
}
71+
72+
function _handleDebugOverrides() {
73+
const overrides = _readOverrides();
74+
let aiPanelLocalOverride = !!overrides.AI_PANEL_LOCAL_OVERRIDE;
75+
76+
const html = Mustache.render(OverridesTpl, {
77+
aiPanelLocalOverride: aiPanelLocalOverride
78+
});
79+
80+
Dialogs.showModalDialogUsingTemplate(html).done(function (id) {
81+
if (id !== Dialogs.DIALOG_BTN_OK) { return; }
82+
const next = _readOverrides();
83+
next.AI_PANEL_LOCAL_OVERRIDE = aiPanelLocalOverride;
84+
_writeOverrides(next);
85+
});
86+
87+
const $dialog = $(".phoenix-debug-overrides.instance");
88+
$dialog.find(".ai-panel-local-override").on("change", function () {
89+
aiPanelLocalOverride = $(this).is(":checked");
90+
});
91+
}
92+
93+
CommandManager.register("Debug Overrides…", COMMAND_ID, _handleDebugOverrides);
94+
95+
exports.COMMAND_ID = COMMAND_ID;
96+
exports.STORAGE_KEY = STORAGE_KEY;
97+
});

0 commit comments

Comments
 (0)