codex-plus-patcher 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/package.json +4 -2
- package/src/patches/lib/common-patches.js +46 -66
- package/src/patches/lib/hooks/about.js +7 -0
- package/src/patches/lib/hooks/diagnostics.js +7 -0
- package/src/patches/lib/hooks/mermaid.js +7 -0
- package/src/patches/lib/hooks/message-composer.js +7 -0
- package/src/patches/lib/hooks/native-main.js +7 -0
- package/src/patches/lib/hooks/project-selector.js +12 -0
- package/src/patches/lib/hooks/review.js +7 -0
- package/src/patches/lib/hooks/settings-commands.js +12 -0
- package/src/patches/lib/hooks/sidebar.js +12 -0
- package/src/patches/lib/hooks/thread-header.js +7 -0
- package/src/patches/lib/hooks/worker.js +7 -0
- package/src/patches/lib/project-selector-shortcut-patch.js +7 -6
- package/src/runtime/api/about.js +16 -0
- package/src/runtime/api/commands.js +85 -0
- package/src/runtime/api/composer.js +14 -0
- package/src/runtime/api/diagnostics.js +38 -0
- package/src/runtime/api/errors.js +20 -0
- package/src/runtime/api/index.js +79 -0
- package/src/runtime/api/mermaid.js +14 -0
- package/src/runtime/api/message.js +14 -0
- package/src/runtime/api/modules.js +57 -0
- package/src/runtime/api/native.js +14 -0
- package/src/runtime/api/patches.js +31 -0
- package/src/runtime/api/review.js +20 -0
- package/src/runtime/api/settings.js +76 -0
- package/src/runtime/api/sidebar.js +24 -0
- package/src/runtime/api/styles.js +28 -0
- package/src/runtime/api/threadHeader.js +41 -0
- package/src/runtime/assets.js +58 -17
- package/src/runtime/host/messageComposer.js +16 -0
- package/src/runtime/host/nativeMain.js +159 -0
- package/src/runtime/host/projectSelector.js +58 -0
- package/src/runtime/host/review.js +62 -0
- package/src/runtime/host/sidebar.js +21 -0
- package/src/runtime/host/threadHeader.js +9 -0
- package/src/runtime/{worker.js → host/worker.js} +7 -0
- package/src/runtime/runtime.js +23 -441
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
(function () {
|
|
2
|
+
const globalObject = typeof window !== "undefined" ? window : globalThis;
|
|
3
|
+
const { applyDecorators } = globalObject.__CodexPlusRuntime;
|
|
4
|
+
globalObject.CodexPlus.ui.composer = {
|
|
5
|
+
surfaceDecorators: [],
|
|
6
|
+
decorateSurface(fn) {
|
|
7
|
+
this.surfaceDecorators.push(fn);
|
|
8
|
+
return fn;
|
|
9
|
+
},
|
|
10
|
+
surfaceProps(props) {
|
|
11
|
+
return applyDecorators(props, this.surfaceDecorators);
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
(function () {
|
|
2
|
+
const globalObject = typeof window !== "undefined" ? window : globalThis;
|
|
3
|
+
const { core } = globalObject.__CodexPlusRuntime;
|
|
4
|
+
|
|
5
|
+
function diagnosticsEnabled() {
|
|
6
|
+
try {
|
|
7
|
+
return globalObject.localStorage?.getItem("codex-plus:diagnostics") === "1";
|
|
8
|
+
} catch {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function log(event, details = {}) {
|
|
14
|
+
const entry = { event, details, time: new Date().toISOString() };
|
|
15
|
+
core.diagnosticEvents.push(entry);
|
|
16
|
+
if (core.diagnosticEvents.length > 200) core.diagnosticEvents.shift();
|
|
17
|
+
if (diagnosticsEnabled()) {
|
|
18
|
+
try {
|
|
19
|
+
console.info("[Codex Plus]", event, details);
|
|
20
|
+
} catch {}
|
|
21
|
+
}
|
|
22
|
+
return entry;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const diagnostics = {
|
|
26
|
+
log,
|
|
27
|
+
snapshot() {
|
|
28
|
+
return core.diagnosticEvents.slice();
|
|
29
|
+
},
|
|
30
|
+
clear() {
|
|
31
|
+
core.diagnosticEvents.splice(0, core.diagnosticEvents.length);
|
|
32
|
+
},
|
|
33
|
+
enabled: diagnosticsEnabled,
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
globalObject.CodexPlus.diagnostics = diagnostics;
|
|
37
|
+
globalObject.CodexPlusDiagnostics = diagnostics;
|
|
38
|
+
})();
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
(function () {
|
|
2
|
+
const globalObject = typeof window !== "undefined" ? window : globalThis;
|
|
3
|
+
|
|
4
|
+
function renderDetails({ jsx, error, componentStack } = {}) {
|
|
5
|
+
for (const decorator of globalObject.CodexPlus.ui.errors.boundaryDecorators) {
|
|
6
|
+
const detail = decorator({ jsx, error, componentStack });
|
|
7
|
+
if (detail != null) return detail;
|
|
8
|
+
}
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
globalObject.CodexPlus.ui.errors = {
|
|
13
|
+
boundaryDecorators: [],
|
|
14
|
+
decorateBoundary(fn) {
|
|
15
|
+
this.boundaryDecorators.push(fn);
|
|
16
|
+
return fn;
|
|
17
|
+
},
|
|
18
|
+
renderDetails,
|
|
19
|
+
};
|
|
20
|
+
})();
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
(function () {
|
|
2
|
+
const globalObject = typeof window !== "undefined" ? window : globalThis;
|
|
3
|
+
const core = {
|
|
4
|
+
commands: new Map(),
|
|
5
|
+
diagnosticEvents: [],
|
|
6
|
+
hostModules: new Map(),
|
|
7
|
+
patchDescriptors: [],
|
|
8
|
+
plugins: new Map(),
|
|
9
|
+
settingsListeners: new Map(),
|
|
10
|
+
startedPlugins: new Set(),
|
|
11
|
+
storagePrefix: "codex-plus:plugin:",
|
|
12
|
+
styleElements: new Map(),
|
|
13
|
+
waiters: [],
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
function safeId(id) {
|
|
17
|
+
if (typeof id !== "string" || id.trim() === "") throw new Error("Codex Plus plugin ids must be non-empty strings");
|
|
18
|
+
return id.trim();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function definePlugin(definition) {
|
|
22
|
+
const id = safeId(definition.id || definition.name);
|
|
23
|
+
return { ...definition, id };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function registerPlugin(definition) {
|
|
27
|
+
const plugin = definePlugin(definition);
|
|
28
|
+
core.plugins.set(plugin.id, plugin);
|
|
29
|
+
if (plugin.settings) plugin.settingsStore = CodexPlus.settings.define(plugin.id, plugin.settings);
|
|
30
|
+
for (const descriptor of plugin.patches || []) CodexPlus.patches.register({ ...descriptor, plugin: plugin.id });
|
|
31
|
+
for (const command of plugin.commands || []) CodexPlus.commands.register({ ...command, plugin: plugin.id });
|
|
32
|
+
if (plugin.styles) CodexPlus.styles.register(plugin.id, plugin.styles);
|
|
33
|
+
if (plugin.required || plugin.enabledByDefault) startPlugin(plugin.id);
|
|
34
|
+
CodexPlus.diagnostics.log("plugin.register", { id: plugin.id, started: core.startedPlugins.has(plugin.id) });
|
|
35
|
+
return plugin;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function startPlugin(id) {
|
|
39
|
+
const plugin = core.plugins.get(id);
|
|
40
|
+
if (!plugin || core.startedPlugins.has(id)) return;
|
|
41
|
+
plugin.start?.(CodexPlus);
|
|
42
|
+
core.startedPlugins.add(id);
|
|
43
|
+
CodexPlus.diagnostics.log("plugin.start", { id });
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function stopPlugin(id) {
|
|
47
|
+
const plugin = core.plugins.get(id);
|
|
48
|
+
if (!plugin || !core.startedPlugins.has(id)) return;
|
|
49
|
+
plugin.stop?.(CodexPlus);
|
|
50
|
+
core.startedPlugins.delete(id);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function mergeDataAttributes(base, extra) {
|
|
54
|
+
if (extra == null) return base;
|
|
55
|
+
if (base == null) return extra;
|
|
56
|
+
return { ...base, ...extra, style: { ...base.style, ...extra.style } };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function applyDecorators(props, decorators) {
|
|
60
|
+
let result;
|
|
61
|
+
for (const decorator of decorators) result = mergeDataAttributes(result, decorator(props));
|
|
62
|
+
return result;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const CodexPlus = {
|
|
66
|
+
definePlugin,
|
|
67
|
+
registerPlugin,
|
|
68
|
+
startPlugin,
|
|
69
|
+
stopPlugin,
|
|
70
|
+
plugins: core.plugins,
|
|
71
|
+
ui: {},
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
globalObject.CodexPlus = CodexPlus;
|
|
75
|
+
globalObject.CodexPlusDiagnostics = null;
|
|
76
|
+
globalObject.CodexPlusHost ||= {};
|
|
77
|
+
globalObject.CodexPlusHost.adapters ||= {};
|
|
78
|
+
globalObject.__CodexPlusRuntime = { core, safeId, mergeDataAttributes, applyDecorators };
|
|
79
|
+
})();
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
(function () {
|
|
2
|
+
const globalObject = typeof window !== "undefined" ? window : globalThis;
|
|
3
|
+
const { applyDecorators } = globalObject.__CodexPlusRuntime;
|
|
4
|
+
globalObject.CodexPlus.ui.mermaid = {
|
|
5
|
+
diagramDecorators: [],
|
|
6
|
+
decorateDiagram(fn) {
|
|
7
|
+
this.diagramDecorators.push(fn);
|
|
8
|
+
return fn;
|
|
9
|
+
},
|
|
10
|
+
diagramProps(props) {
|
|
11
|
+
return applyDecorators(props, this.diagramDecorators);
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
(function () {
|
|
2
|
+
const globalObject = typeof window !== "undefined" ? window : globalThis;
|
|
3
|
+
const { applyDecorators } = globalObject.__CodexPlusRuntime;
|
|
4
|
+
globalObject.CodexPlus.ui.message = {
|
|
5
|
+
userBubbleDecorators: [],
|
|
6
|
+
decorateUserBubble(fn) {
|
|
7
|
+
this.userBubbleDecorators.push(fn);
|
|
8
|
+
return fn;
|
|
9
|
+
},
|
|
10
|
+
userBubbleProps(props) {
|
|
11
|
+
return applyDecorators(props, this.userBubbleDecorators);
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
(function () {
|
|
2
|
+
const globalObject = typeof window !== "undefined" ? window : globalThis;
|
|
3
|
+
const { core } = globalObject.__CodexPlusRuntime;
|
|
4
|
+
|
|
5
|
+
function notifyWaiters(name, value) {
|
|
6
|
+
for (let index = core.waiters.length - 1; index >= 0; index -= 1) {
|
|
7
|
+
const waiter = core.waiters[index];
|
|
8
|
+
if (!waiter.filter(value, name)) continue;
|
|
9
|
+
core.waiters.splice(index, 1);
|
|
10
|
+
waiter.resolve(value);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function registerHostModule(name, value) {
|
|
15
|
+
core.hostModules.set(name, value);
|
|
16
|
+
notifyWaiters(name, value);
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function moduleValues() {
|
|
21
|
+
return Array.from(core.hostModules.values());
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function findByProps(...props) {
|
|
25
|
+
return moduleValues().find((value) => value && props.every((prop) => prop in value));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function findByCode(text) {
|
|
29
|
+
return moduleValues().find((value) => {
|
|
30
|
+
try {
|
|
31
|
+
return String(value).includes(text);
|
|
32
|
+
} catch {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function findComponentByCode(text) {
|
|
39
|
+
return moduleValues().find((value) => {
|
|
40
|
+
try {
|
|
41
|
+
return typeof value === "function" && String(value).includes(text);
|
|
42
|
+
} catch {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function waitFor(filter) {
|
|
49
|
+
for (const [name, value] of core.hostModules) {
|
|
50
|
+
if (filter(value, name)) return Promise.resolve(value);
|
|
51
|
+
}
|
|
52
|
+
return new Promise((resolve) => core.waiters.push({ filter, resolve }));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
globalObject.CodexPlus.modules = { registerHostModule, findByCode, findByProps, findComponentByCode, waitFor };
|
|
56
|
+
globalObject.CodexPlusHost.register = registerHostModule;
|
|
57
|
+
})();
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
(function () {
|
|
2
|
+
const globalObject = typeof window !== "undefined" ? window : globalThis;
|
|
3
|
+
|
|
4
|
+
async function request(method, params) {
|
|
5
|
+
return globalObject.codexPlusNative?.request?.(method, params) ?? globalObject.CodexPlusHost?.nativeRequest?.(method, params);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function registerNativeMenuItem(item) {
|
|
9
|
+
return globalObject.CodexPlus.native.request("native-menu/register-item", item).catch(() => ({ ok: false }));
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
globalObject.CodexPlus.native = { request };
|
|
13
|
+
globalObject.CodexPlus.nativeMenus = { registerItem: registerNativeMenuItem };
|
|
14
|
+
})();
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
(function () {
|
|
2
|
+
const globalObject = typeof window !== "undefined" ? window : globalThis;
|
|
3
|
+
const { core } = globalObject.__CodexPlusRuntime;
|
|
4
|
+
|
|
5
|
+
function register(descriptor) {
|
|
6
|
+
core.patchDescriptors.push(descriptor);
|
|
7
|
+
return descriptor;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function apply(source, descriptors = core.patchDescriptors) {
|
|
11
|
+
let output = source;
|
|
12
|
+
for (const descriptor of descriptors) {
|
|
13
|
+
const moduleMatches =
|
|
14
|
+
typeof descriptor.find === "string" ? output.includes(descriptor.find) : descriptor.find.test(output);
|
|
15
|
+
if (!moduleMatches) continue;
|
|
16
|
+
const replacements = Array.isArray(descriptor.replacement) ? descriptor.replacement : [descriptor.replacement];
|
|
17
|
+
const beforeGroup = output;
|
|
18
|
+
let appliedGroup = true;
|
|
19
|
+
for (const replacement of replacements) {
|
|
20
|
+
const before = output;
|
|
21
|
+
output = output.replace(replacement.match, replacement.replace);
|
|
22
|
+
if (before === output) appliedGroup = false;
|
|
23
|
+
}
|
|
24
|
+
if (descriptor.group && !appliedGroup) output = beforeGroup;
|
|
25
|
+
if (!descriptor.all) break;
|
|
26
|
+
}
|
|
27
|
+
return output;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
globalObject.CodexPlus.patches = { register, apply, all: core.patchDescriptors };
|
|
31
|
+
})();
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
(function () {
|
|
2
|
+
const globalObject = typeof window !== "undefined" ? window : globalThis;
|
|
3
|
+
|
|
4
|
+
function renderBody({ props, deps, defaultBody } = {}) {
|
|
5
|
+
let body = defaultBody;
|
|
6
|
+
for (const wrapper of globalObject.CodexPlus.ui.review.wrappers) {
|
|
7
|
+
body = wrapper({ ...props, mainReviewContent: body }, deps);
|
|
8
|
+
}
|
|
9
|
+
return body;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
globalObject.CodexPlus.ui.review = {
|
|
13
|
+
wrappers: [],
|
|
14
|
+
wrapBody(wrapper) {
|
|
15
|
+
this.wrappers.push(wrapper);
|
|
16
|
+
return wrapper;
|
|
17
|
+
},
|
|
18
|
+
renderBody,
|
|
19
|
+
};
|
|
20
|
+
})();
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
(function () {
|
|
2
|
+
const globalObject = typeof window !== "undefined" ? window : globalThis;
|
|
3
|
+
const { core, safeId } = globalObject.__CodexPlusRuntime;
|
|
4
|
+
|
|
5
|
+
function getPluginStore(pluginId) {
|
|
6
|
+
const key = `${core.storagePrefix}${pluginId}`;
|
|
7
|
+
try {
|
|
8
|
+
return JSON.parse(globalObject.localStorage?.getItem(key) || "{}") || {};
|
|
9
|
+
} catch {
|
|
10
|
+
return {};
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function writePluginStore(pluginId, store) {
|
|
15
|
+
const key = `${core.storagePrefix}${pluginId}`;
|
|
16
|
+
globalObject.localStorage?.setItem(key, JSON.stringify(store));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function emitSetting(pluginId, key, value) {
|
|
20
|
+
const listenerKey = `${pluginId}:${key}`;
|
|
21
|
+
for (const listener of core.settingsListeners.get(listenerKey) || []) listener(value);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function define(pluginId, definitions) {
|
|
25
|
+
const id = safeId(pluginId);
|
|
26
|
+
const store = getPluginStore(id);
|
|
27
|
+
for (const [key, definition] of Object.entries(definitions || {})) {
|
|
28
|
+
if (!(key in store) && "default" in definition) store[key] = definition.default;
|
|
29
|
+
}
|
|
30
|
+
writePluginStore(id, store);
|
|
31
|
+
return {
|
|
32
|
+
definitions,
|
|
33
|
+
get(key) {
|
|
34
|
+
return getPluginStore(id)[key];
|
|
35
|
+
},
|
|
36
|
+
set(key, value) {
|
|
37
|
+
const next = getPluginStore(id);
|
|
38
|
+
next[key] = value;
|
|
39
|
+
writePluginStore(id, next);
|
|
40
|
+
emitSetting(id, key, value);
|
|
41
|
+
},
|
|
42
|
+
use(key, listener) {
|
|
43
|
+
const listenerKey = `${id}:${key}`;
|
|
44
|
+
const listeners = core.settingsListeners.get(listenerKey) || new Set();
|
|
45
|
+
listeners.add(listener);
|
|
46
|
+
core.settingsListeners.set(listenerKey, listeners);
|
|
47
|
+
listener(getPluginStore(id)[key]);
|
|
48
|
+
return () => listeners.delete(listener);
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function AppearanceRowHost({ row, deps, variant }) {
|
|
54
|
+
return row.render?.({ ...deps, variant, row }) ?? null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const appearance = {
|
|
58
|
+
rows: [],
|
|
59
|
+
addRow(row) {
|
|
60
|
+
this.rows.push(row);
|
|
61
|
+
return row;
|
|
62
|
+
},
|
|
63
|
+
renderRows({ deps, variant, section = "appearance" } = {}) {
|
|
64
|
+
const jsx = deps?.jsx;
|
|
65
|
+
if (typeof jsx !== "function") return [];
|
|
66
|
+
return this.rows
|
|
67
|
+
.filter((row) => (row.section || "appearance") === section)
|
|
68
|
+
.slice()
|
|
69
|
+
.sort((left, right) => (left.order || 0) - (right.order || 0))
|
|
70
|
+
.map((row) => jsx(AppearanceRowHost, { row, deps, variant }, row.id));
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
globalObject.CodexPlus.ui.settings = { appearance };
|
|
75
|
+
globalObject.CodexPlus.settings = { define };
|
|
76
|
+
})();
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
(function () {
|
|
2
|
+
const globalObject = typeof window !== "undefined" ? window : globalThis;
|
|
3
|
+
const { applyDecorators, mergeDataAttributes } = globalObject.__CodexPlusRuntime;
|
|
4
|
+
const sidebar = {
|
|
5
|
+
projectDecorators: [],
|
|
6
|
+
threadDecorators: [],
|
|
7
|
+
decorateProjectRow(fn) {
|
|
8
|
+
this.projectDecorators.push(fn);
|
|
9
|
+
return fn;
|
|
10
|
+
},
|
|
11
|
+
decorateThreadRow(fn) {
|
|
12
|
+
this.threadDecorators.push(fn);
|
|
13
|
+
return fn;
|
|
14
|
+
},
|
|
15
|
+
mergeDataAttributes,
|
|
16
|
+
projectRowProps(props) {
|
|
17
|
+
return applyDecorators(props, this.projectDecorators);
|
|
18
|
+
},
|
|
19
|
+
threadRowProps(props) {
|
|
20
|
+
return applyDecorators(props, this.threadDecorators);
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
globalObject.CodexPlus.ui.sidebar = sidebar;
|
|
24
|
+
})();
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
(function () {
|
|
2
|
+
const globalObject = typeof window !== "undefined" ? window : globalThis;
|
|
3
|
+
const { core, safeId } = globalObject.__CodexPlusRuntime;
|
|
4
|
+
|
|
5
|
+
function register(pluginId, cssText) {
|
|
6
|
+
if (typeof document === "undefined") return null;
|
|
7
|
+
const id = `codex-plus-style-${safeId(pluginId)}`;
|
|
8
|
+
let element = core.styleElements.get(id) || document.getElementById(id);
|
|
9
|
+
if (!element) {
|
|
10
|
+
element = document.createElement("style");
|
|
11
|
+
element.id = id;
|
|
12
|
+
document.head?.appendChild(element);
|
|
13
|
+
}
|
|
14
|
+
element.textContent = cssText;
|
|
15
|
+
core.styleElements.set(id, element);
|
|
16
|
+
return element;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function setRootVars(vars) {
|
|
20
|
+
if (typeof document === "undefined") return;
|
|
21
|
+
for (const [key, value] of Object.entries(vars || {})) {
|
|
22
|
+
if (value == null) document.documentElement.style.removeProperty(key);
|
|
23
|
+
else document.documentElement.style.setProperty(key, value);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
globalObject.CodexPlus.styles = { register, setRootVars };
|
|
28
|
+
})();
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
(function () {
|
|
2
|
+
const globalObject = typeof window !== "undefined" ? window : globalThis;
|
|
3
|
+
|
|
4
|
+
function ThreadHeaderAccessoryHost({ accessory, context, deps }) {
|
|
5
|
+
const rendered = accessory?.({ context, ...deps }) ?? null;
|
|
6
|
+
globalObject.CodexPlus.diagnostics.log("threadHeader.accessoryHost.render", {
|
|
7
|
+
accessoryName: accessory?.name || null,
|
|
8
|
+
cwd: typeof context?.cwd === "string" ? context.cwd : null,
|
|
9
|
+
rendered: rendered != null,
|
|
10
|
+
});
|
|
11
|
+
return rendered;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function renderAccessories({ context, deps } = {}) {
|
|
15
|
+
const jsx = deps?.jsx;
|
|
16
|
+
if (typeof jsx !== "function") {
|
|
17
|
+
globalObject.CodexPlus.diagnostics.log("threadHeader.render.skip", { reason: "missing-jsx" });
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
globalObject.CodexPlus.diagnostics.log("threadHeader.render", {
|
|
21
|
+
accessoryCount: globalObject.CodexPlus.ui.threadHeader.accessories.length,
|
|
22
|
+
cwd: typeof context?.cwd === "string" ? context.cwd : null,
|
|
23
|
+
hostId: context?.hostId ?? null,
|
|
24
|
+
header: context?.header ?? null,
|
|
25
|
+
});
|
|
26
|
+
const rendered = globalObject.CodexPlus.ui.threadHeader.accessories.map((accessory, index) =>
|
|
27
|
+
jsx(ThreadHeaderAccessoryHost, { accessory, context, deps }, `thread-header-accessory:${index}`),
|
|
28
|
+
);
|
|
29
|
+
return rendered.length === 0 ? null : rendered;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
globalObject.CodexPlus.ui.threadHeader = {
|
|
33
|
+
accessories: [],
|
|
34
|
+
addAccessory(fn) {
|
|
35
|
+
this.accessories.push(fn);
|
|
36
|
+
globalObject.CodexPlus.diagnostics.log("threadHeader.addAccessory", { accessoryName: fn?.name || null, accessoryCount: this.accessories.length });
|
|
37
|
+
return fn;
|
|
38
|
+
},
|
|
39
|
+
renderAccessories,
|
|
40
|
+
};
|
|
41
|
+
})();
|
package/src/runtime/assets.js
CHANGED
|
@@ -2,31 +2,72 @@ const fs = require("node:fs");
|
|
|
2
2
|
const path = require("node:path");
|
|
3
3
|
|
|
4
4
|
const runtimeRoot = __dirname;
|
|
5
|
-
const
|
|
5
|
+
const browserRuntimeFiles = [
|
|
6
|
+
"api/index.js",
|
|
7
|
+
"api/diagnostics.js",
|
|
8
|
+
"api/modules.js",
|
|
9
|
+
"api/settings.js",
|
|
10
|
+
"api/patches.js",
|
|
11
|
+
"api/commands.js",
|
|
12
|
+
"api/styles.js",
|
|
13
|
+
"api/sidebar.js",
|
|
14
|
+
"api/message.js",
|
|
15
|
+
"api/composer.js",
|
|
16
|
+
"api/about.js",
|
|
17
|
+
"api/review.js",
|
|
18
|
+
"api/native.js",
|
|
19
|
+
"api/errors.js",
|
|
20
|
+
"api/threadHeader.js",
|
|
21
|
+
"api/mermaid.js",
|
|
22
|
+
"host/review.js",
|
|
23
|
+
"host/sidebar.js",
|
|
24
|
+
"host/messageComposer.js",
|
|
25
|
+
"host/projectSelector.js",
|
|
26
|
+
"host/threadHeader.js",
|
|
27
|
+
"vendor/fzf.umd.js",
|
|
28
|
+
"plugins/aboutMetadata.js",
|
|
29
|
+
"plugins/nestedRepositories.js",
|
|
30
|
+
"plugins/diagnosticErrors.js",
|
|
31
|
+
"plugins/userBubbleColors.js",
|
|
32
|
+
"plugins/projectColors.js",
|
|
33
|
+
"plugins/projectPathHeader.js",
|
|
34
|
+
"plugins/sidebarNameBlur.js",
|
|
35
|
+
"plugins/devTools.js",
|
|
36
|
+
"plugins/projectSelectorShortcut.js",
|
|
37
|
+
"plugins/mermaidFullscreen.js",
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
const nodeRuntimeFiles = [
|
|
6
41
|
[".vite/build/codex-plus-aboutMetadata.js", "plugins/aboutMetadata.js"],
|
|
7
|
-
[".vite/build/codex-plus-
|
|
42
|
+
[".vite/build/codex-plus-native-main.js", "host/nativeMain.js"],
|
|
43
|
+
[".vite/build/codex-plus-worker.js", "host/worker.js"],
|
|
8
44
|
["webview/assets/codex-plus/runtime.js", "runtime.js"],
|
|
9
|
-
["webview/assets/codex-plus/plugins/aboutMetadata.js", "plugins/aboutMetadata.js"],
|
|
10
|
-
["webview/assets/codex-plus/plugins/nestedRepositories.js", "plugins/nestedRepositories.js"],
|
|
11
|
-
["webview/assets/codex-plus/plugins/diagnosticErrors.js", "plugins/diagnosticErrors.js"],
|
|
12
|
-
["webview/assets/codex-plus/plugins/userBubbleColors.js", "plugins/userBubbleColors.js"],
|
|
13
|
-
["webview/assets/codex-plus/plugins/projectColors.js", "plugins/projectColors.js"],
|
|
14
|
-
["webview/assets/codex-plus/plugins/projectPathHeader.js", "plugins/projectPathHeader.js"],
|
|
15
|
-
["webview/assets/codex-plus/plugins/sidebarNameBlur.js", "plugins/sidebarNameBlur.js"],
|
|
16
|
-
["webview/assets/codex-plus/plugins/devTools.js", "plugins/devTools.js"],
|
|
17
|
-
["webview/assets/codex-plus/vendor/fzf.umd.js", "../../node_modules/fzf/dist/fzf.umd.js"],
|
|
18
|
-
["webview/assets/codex-plus/plugins/projectSelectorShortcut.js", "plugins/projectSelectorShortcut.js"],
|
|
19
|
-
["webview/assets/codex-plus/plugins/mermaidFullscreen.js", "plugins/mermaidFullscreen.js"],
|
|
20
45
|
];
|
|
21
46
|
|
|
47
|
+
const browserRuntimeAssets = browserRuntimeFiles.map((filePath) => [
|
|
48
|
+
`webview/assets/codex-plus/${filePath}`,
|
|
49
|
+
filePath.startsWith("vendor/") ? "../../node_modules/fzf/dist/fzf.umd.js" : filePath,
|
|
50
|
+
]);
|
|
51
|
+
|
|
52
|
+
const runtimeFiles = [
|
|
53
|
+
...nodeRuntimeFiles,
|
|
54
|
+
["webview/assets/codex-plus/runtime-manifest.js", null],
|
|
55
|
+
...browserRuntimeAssets,
|
|
56
|
+
];
|
|
57
|
+
|
|
58
|
+
function browserRuntimeManifest() {
|
|
59
|
+
return `window.__CodexPlusRuntimeFiles=${JSON.stringify(browserRuntimeFiles)};window.__CodexPlusLoadRuntimeFiles?.(window.__CodexPlusRuntimeFiles);\n`;
|
|
60
|
+
}
|
|
61
|
+
|
|
22
62
|
function codexPlusRuntimeAssets() {
|
|
23
|
-
return runtimeFiles.map(([asarPath, localPath]) =>
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
63
|
+
return runtimeFiles.map(([asarPath, localPath]) => {
|
|
64
|
+
const content = localPath == null ? browserRuntimeManifest() : fs.readFileSync(path.join(runtimeRoot, localPath), "utf8");
|
|
65
|
+
return [asarPath, content];
|
|
66
|
+
});
|
|
27
67
|
}
|
|
28
68
|
|
|
29
69
|
module.exports = {
|
|
70
|
+
browserRuntimeFiles,
|
|
30
71
|
codexPlusRuntimeAssets,
|
|
31
72
|
runtimeFiles,
|
|
32
73
|
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
(function () {
|
|
2
|
+
const globalObject = typeof window !== "undefined" ? window : globalThis;
|
|
3
|
+
|
|
4
|
+
function userBubbleProps(props) {
|
|
5
|
+
return globalObject.CodexPlus?.ui?.message?.userBubbleProps?.(props);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function composerSurfaceProps(props) {
|
|
9
|
+
return globalObject.CodexPlus?.ui?.composer?.surfaceProps?.(props);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
globalObject.CodexPlusHost.adapters.messageComposer = {
|
|
13
|
+
composerSurfaceProps,
|
|
14
|
+
userBubbleProps,
|
|
15
|
+
};
|
|
16
|
+
})();
|