@adhdev/daemon-core 0.5.38 → 0.5.40

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.
@@ -1,138 +0,0 @@
1
- /**
2
- * Codex Extension — list_modes
3
- *
4
- * Finds the mode / autonomy dropdown next to the model chip in the composer footer,
5
- * opens it (Radix), reads options, closes. UI expects `modes` + `current` (see ModelModeBar).
6
- */
7
- (() => {
8
- try {
9
- function resolveDoc() {
10
- let doc = document;
11
- let root = doc.getElementById('root');
12
- if (!root) {
13
- const iframes = doc.querySelectorAll('iframe');
14
- for (const iframe of iframes) {
15
- try {
16
- const innerDoc = iframe.contentDocument || iframe.contentWindow?.document;
17
- if (innerDoc?.getElementById('root')) {
18
- doc = innerDoc;
19
- root = innerDoc.getElementById('root');
20
- break;
21
- }
22
- } catch (e) { /* cross-origin */ }
23
- }
24
- }
25
- return { doc, root };
26
- }
27
-
28
- function isModelMenuButton(b) {
29
- const text = (b.textContent || '').trim();
30
- if (b.getAttribute('aria-haspopup') !== 'menu') return false;
31
- return /^(GPT-|gpt-|o\d|claude-|sonnet|opus)/i.test(text);
32
- }
33
-
34
- /** Mode chip: menu trigger in composer that is not the model selector. */
35
- function findModeMenuButton(doc) {
36
- const composer =
37
- doc.querySelector('[class*="thread-composer-max-width"]') ||
38
- doc.querySelector('[class*="thread-composer"]') ||
39
- doc.getElementById('root') ||
40
- doc.body;
41
-
42
- const buttons = Array.from(composer.querySelectorAll('button')).filter(
43
- (b) => b.offsetWidth > 0 && b.offsetHeight > 0,
44
- );
45
-
46
- const menuTriggers = buttons.filter(
47
- (b) => b.getAttribute('aria-haspopup') === 'menu' && !isModelMenuButton(b),
48
- );
49
-
50
- if (menuTriggers.length === 0) return null;
51
-
52
- const byAria = menuTriggers.find((b) => {
53
- const al = (b.getAttribute('aria-label') || '').toLowerCase();
54
- return /mode|agent|ask|plan|autonomy|codex|모드|에이전트|플랜/i.test(al);
55
- });
56
- if (byAria) return byAria;
57
-
58
- return menuTriggers[0];
59
- }
60
-
61
- function openMenu(btn) {
62
- const rect = btn.getBoundingClientRect();
63
- const cx = rect.left + rect.width / 2;
64
- const cy = rect.top + rect.height / 2;
65
- btn.dispatchEvent(
66
- new PointerEvent('pointerdown', { bubbles: true, clientX: cx, clientY: cy, pointerId: 1 }),
67
- );
68
- btn.dispatchEvent(new MouseEvent('mousedown', { bubbles: true, clientX: cx, clientY: cy }));
69
- btn.dispatchEvent(
70
- new PointerEvent('pointerup', { bubbles: true, clientX: cx, clientY: cy, pointerId: 1 }),
71
- );
72
- btn.dispatchEvent(new MouseEvent('mouseup', { bubbles: true, clientX: cx, clientY: cy }));
73
- btn.dispatchEvent(new MouseEvent('click', { bubbles: true, clientX: cx, clientY: cy }));
74
- }
75
-
76
- const { doc, root } = resolveDoc();
77
- if (!root) return JSON.stringify({ modes: [], current: '', currentMode: '', error: 'no root' });
78
-
79
- const modeBtn = findModeMenuButton(doc);
80
- if (!modeBtn) {
81
- return JSON.stringify({
82
- modes: [],
83
- current: '',
84
- currentMode: '',
85
- error: 'mode menu button not found',
86
- });
87
- }
88
-
89
- const currentLabel = (modeBtn.textContent || '').trim();
90
- openMenu(modeBtn);
91
-
92
- return new Promise((resolve) => {
93
- setTimeout(() => {
94
- let menu = doc.querySelector('[role="menu"][data-state="open"]');
95
- if (!menu) {
96
- menu = doc.querySelector('[role="menu"]');
97
- }
98
-
99
- const collected = [];
100
- if (menu) {
101
- const items = menu.querySelectorAll(
102
- '[role="menuitem"], [role="menuitemradio"], [role="option"], div[class*="cursor-interaction"]',
103
- );
104
- for (const item of items) {
105
- const text = (item.textContent || '').trim();
106
- if (
107
- text &&
108
- text.length > 0 &&
109
- text.length < 80 &&
110
- !/^모델|^model\b|^select\b/i.test(text)
111
- ) {
112
- collected.push(text);
113
- }
114
- }
115
- }
116
-
117
- doc.dispatchEvent(
118
- new KeyboardEvent('keydown', {
119
- key: 'Escape',
120
- code: 'Escape',
121
- keyCode: 27,
122
- bubbles: true,
123
- }),
124
- );
125
-
126
- const modes = [...new Set(collected)];
127
- const out = {
128
- modes: modes.length > 0 ? modes : currentLabel ? [currentLabel] : [],
129
- current: currentLabel,
130
- currentMode: currentLabel,
131
- };
132
- resolve(JSON.stringify(out));
133
- }, 550);
134
- });
135
- } catch (e) {
136
- return JSON.stringify({ error: e.message || String(e), modes: [], current: '', currentMode: '' });
137
- }
138
- })();
@@ -1,165 +0,0 @@
1
- /**
2
- * Codex Extension — set_mode
3
- *
4
- * Opens the mode dropdown (same discovery as list_modes), selects an item matching ${MODE}.
5
- *
6
- * Placeholder: ${MODE}
7
- */
8
- (() => {
9
- try {
10
- const targetMode = ${MODE};
11
-
12
- function resolveDoc() {
13
- let doc = document;
14
- let root = doc.getElementById('root');
15
- if (!root) {
16
- const iframes = doc.querySelectorAll('iframe');
17
- for (const iframe of iframes) {
18
- try {
19
- const innerDoc = iframe.contentDocument || iframe.contentWindow?.document;
20
- if (innerDoc?.getElementById('root')) {
21
- doc = innerDoc;
22
- root = innerDoc.getElementById('root');
23
- break;
24
- }
25
- } catch (e) { /* cross-origin */ }
26
- }
27
- }
28
- return { doc, root };
29
- }
30
-
31
- function isModelMenuButton(b) {
32
- const text = (b.textContent || '').trim();
33
- if (b.getAttribute('aria-haspopup') !== 'menu') return false;
34
- return /^(GPT-|gpt-|o\d|claude-|sonnet|opus)/i.test(text);
35
- }
36
-
37
- function findModeMenuButton(doc) {
38
- const composer =
39
- doc.querySelector('[class*="thread-composer-max-width"]') ||
40
- doc.querySelector('[class*="thread-composer"]') ||
41
- doc.getElementById('root') ||
42
- doc.body;
43
-
44
- const buttons = Array.from(composer.querySelectorAll('button')).filter(
45
- (b) => b.offsetWidth > 0 && b.offsetHeight > 0,
46
- );
47
-
48
- const menuTriggers = buttons.filter(
49
- (b) => b.getAttribute('aria-haspopup') === 'menu' && !isModelMenuButton(b),
50
- );
51
-
52
- if (menuTriggers.length === 0) return null;
53
-
54
- const byAria = menuTriggers.find((b) => {
55
- const al = (b.getAttribute('aria-label') || '').toLowerCase();
56
- return /mode|agent|ask|plan|autonomy|codex|모드|에이전트|플랜/i.test(al);
57
- });
58
- if (byAria) return byAria;
59
-
60
- return menuTriggers[0];
61
- }
62
-
63
- function openMenu(btn) {
64
- const rect = btn.getBoundingClientRect();
65
- const cx = rect.left + rect.width / 2;
66
- const cy = rect.top + rect.height / 2;
67
- btn.dispatchEvent(
68
- new PointerEvent('pointerdown', { bubbles: true, clientX: cx, clientY: cy, pointerId: 1 }),
69
- );
70
- btn.dispatchEvent(new MouseEvent('mousedown', { bubbles: true, clientX: cx, clientY: cy }));
71
- btn.dispatchEvent(
72
- new PointerEvent('pointerup', { bubbles: true, clientX: cx, clientY: cy, pointerId: 1 }),
73
- );
74
- btn.dispatchEvent(new MouseEvent('mouseup', { bubbles: true, clientX: cx, clientY: cy }));
75
- btn.dispatchEvent(new MouseEvent('click', { bubbles: true, clientX: cx, clientY: cy }));
76
- }
77
-
78
- function clickItem(el) {
79
- const ir = el.getBoundingClientRect();
80
- const ix = ir.left + ir.width / 2;
81
- const iy = ir.top + ir.height / 2;
82
- el.dispatchEvent(
83
- new PointerEvent('pointerdown', { bubbles: true, clientX: ix, clientY: iy }),
84
- );
85
- el.dispatchEvent(new MouseEvent('mousedown', { bubbles: true, clientX: ix, clientY: iy }));
86
- el.dispatchEvent(new PointerEvent('pointerup', { bubbles: true, clientX: ix, clientY: iy }));
87
- el.dispatchEvent(new MouseEvent('mouseup', { bubbles: true, clientX: ix, clientY: iy }));
88
- el.dispatchEvent(new MouseEvent('click', { bubbles: true, clientX: ix, clientY: iy }));
89
- }
90
-
91
- const { doc, root } = resolveDoc();
92
- if (!root) return JSON.stringify({ success: false, error: 'no root' });
93
-
94
- const want =
95
- typeof targetMode === 'string'
96
- ? targetMode.trim()
97
- : targetMode != null
98
- ? String(targetMode).trim()
99
- : '';
100
- if (!want) return JSON.stringify({ success: false, error: 'empty mode' });
101
-
102
- const modeBtn = findModeMenuButton(doc);
103
- if (!modeBtn) return JSON.stringify({ success: false, error: 'mode menu button not found' });
104
-
105
- const currentLabel = (modeBtn.textContent || '').trim();
106
- if (currentLabel.toLowerCase() === want.toLowerCase()) {
107
- return JSON.stringify({ success: true, mode: currentLabel, changed: false });
108
- }
109
-
110
- openMenu(modeBtn);
111
-
112
- return new Promise((resolve) => {
113
- setTimeout(() => {
114
- let menu = doc.querySelector('[role="menu"][data-state="open"]');
115
- if (!menu) menu = doc.querySelector('[role="menu"]');
116
-
117
- if (!menu) {
118
- doc.dispatchEvent(
119
- new KeyboardEvent('keydown', { key: 'Escape', code: 'Escape', keyCode: 27, bubbles: true }),
120
- );
121
- return resolve(JSON.stringify({ success: false, error: 'mode menu did not open' }));
122
- }
123
-
124
- const items = Array.from(
125
- menu.querySelectorAll(
126
- '[role="menuitem"], [role="menuitemradio"], [role="option"], div[class*="cursor-interaction"]',
127
- ),
128
- );
129
-
130
- const norm = (s) => (s || '').trim().toLowerCase();
131
- const wantN = norm(want);
132
-
133
- let match = items.find((el) => norm(el.textContent) === wantN);
134
- if (!match) {
135
- match = items.find((el) => norm(el.textContent).includes(wantN) || wantN.includes(norm(el.textContent)));
136
- }
137
-
138
- if (!match) {
139
- doc.dispatchEvent(
140
- new KeyboardEvent('keydown', { key: 'Escape', code: 'Escape', keyCode: 27, bubbles: true }),
141
- );
142
- const available = items
143
- .map((el) => (el.textContent || '').trim())
144
- .filter((t) => t.length > 0 && t.length < 80);
145
- return resolve(
146
- JSON.stringify({
147
- success: false,
148
- error: `mode "${want}" not found`,
149
- available,
150
- }),
151
- );
152
- }
153
-
154
- const picked = (match.textContent || '').trim();
155
- clickItem(match);
156
-
157
- setTimeout(() => {
158
- resolve(JSON.stringify({ success: true, mode: picked, changed: true }));
159
- }, 350);
160
- }, 550);
161
- });
162
- } catch (e) {
163
- return JSON.stringify({ success: false, error: e.message || String(e) });
164
- }
165
- })();