Skip to content

Commit 2882984

Browse files
committed
feat: implement Custom GPT gizmo_id routing and conversation_mode bypass (injected.js, content.js, extension_bridge.py, prompt_builder.py)
1 parent f24f216 commit 2882984

9 files changed

Lines changed: 76 additions & 36 deletions

File tree

‎Oops.rej‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@@ -1,7 +1,7 @@
2+
export function healthCheck() {
3+
return {
4+
- status: 'ok' as const,
5+
+ status: 'ok_zip_verified' as const,
6+
timestamp: new Date().toISOString(),
7+
};
8+
}
9+
export function formatTimestamp(ts: string | number | Date): string {

‎chrome_extension/content.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
messages: msg.messages,
8585
attachments: msg.attachments,
8686
model: msg.model,
87+
gizmoId: msg.gizmoId,
8788
conversationId: msg.conversationId,
8889
parentMessageId: msg.parentMessageId,
8990
}, '*');

‎chrome_extension/injected.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@
916916
};
917917

918918
try {
919-
var response = await sendConversation(messages, model, requestId, conversationId, parentMessageId, event.data.attachments);
919+
var response = await sendConversation(messages, model, requestId, conversationId, parentMessageId, event.data.attachments, event.data.gizmoId);
920920
activeStreams.set(requestId, streamState);
921921

922922
await parseSSEStream(response,

‎codex_engine/engine.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,12 @@ async def _handle_responses_locked(self, request):
480480
first_user_text = _find_first_user_text(_turn_items)
481481
if first_user_text:
482482
self._current_user_goal = first_user_text
483+
try:
484+
from codex_engine.router import classify_task_mode
485+
task_mode = classify_task_mode(first_user_text)
486+
logger.info("Hybrid Router: Task classified as %s mode", task_mode)
487+
except Exception as e:
488+
logger.warning("Failed to classify task mode: %s", e)
483489

484490
is_first_relay = self._last_sent_count == 0 or compacted
485491

‎codex_engine/patch_engine.py‎

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -66,39 +66,48 @@ def apply_git_patch(repo_path: str, patch_text: str) -> dict:
6666
with open(patch_file, "w", encoding="utf-8") as f:
6767
f.write(clean_patch)
6868

69-
try:
70-
# Try `git apply` first
71-
res = subprocess.run(
72-
["git", "apply", "--check", patch_file],
73-
cwd=repo_path,
74-
capture_output=True,
75-
text=True
76-
)
77-
if res.returncode == 0:
78-
apply_res = subprocess.run(
79-
["git", "apply", patch_file],
80-
cwd=repo_path,
81-
capture_output=True,
82-
text=True
83-
)
84-
if apply_res.returncode == 0:
85-
logger.info("Git patch applied cleanly via git apply!")
86-
return {"success": True, "method": "git apply", "patch_file": patch_file}
87-
else:
88-
return {"success": False, "error": apply_res.stderr}
89-
else:
90-
# Fallback to patch -p1
91-
patch_res = subprocess.run(
92-
["patch", "-p1", "-i", patch_file],
93-
cwd=repo_path,
69+
candidate_repos = [os.path.abspath(repo_path), "/Users/adammaged/computer-science-learning-platform"]
70+
last_error = ""
71+
72+
for target_repo in candidate_repos:
73+
if not os.path.exists(target_repo):
74+
continue
75+
try:
76+
# Try `git apply` first
77+
res = subprocess.run(
78+
["git", "apply", "--check", patch_file],
79+
cwd=target_repo,
9480
capture_output=True,
9581
text=True
9682
)
97-
if patch_res.returncode == 0:
98-
logger.info("Patch applied cleanly via patch -p1!")
99-
return {"success": True, "method": "patch -p1", "patch_file": patch_file}
83+
if res.returncode == 0:
84+
apply_res = subprocess.run(
85+
["git", "apply", patch_file],
86+
cwd=target_repo,
87+
capture_output=True,
88+
text=True
89+
)
90+
if apply_res.returncode == 0:
91+
logger.info("Git patch applied cleanly via git apply in %s!", target_repo)
92+
return {"success": True, "method": "git apply", "patch_file": patch_file, "repo": target_repo}
93+
else:
94+
last_error = apply_res.stderr
10095
else:
101-
return {"success": False, "error": f"git apply: {res.stderr}; patch: {patch_res.stderr}"}
102-
except Exception as e:
103-
logger.error("Failed to apply patch: %s", e)
104-
return {"success": False, "error": str(e)}
96+
# Fallback to patch -p1
97+
patch_res = subprocess.run(
98+
["patch", "-p1", "-i", patch_file],
99+
cwd=target_repo,
100+
capture_output=True,
101+
text=True
102+
)
103+
if patch_res.returncode == 0:
104+
logger.info("Patch applied cleanly via patch -p1 in %s!", target_repo)
105+
return {"success": True, "method": "patch -p1", "patch_file": patch_file, "repo": target_repo}
106+
else:
107+
last_error = f"git apply: {res.stderr}; patch: {patch_res.stderr}"
108+
except Exception as e:
109+
last_error = str(e)
110+
logger.error("Failed to apply patch in %s: %s", target_repo, e)
111+
112+
return {"success": False, "error": last_error or "Failed to apply patch to any candidate repo"}
113+

‎codex_engine/responses_passthrough.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,13 @@ async def handle_responses_passthrough(proxy: "_CodexProxy", body: dict, input_i
237237

238238
if contains_new_user_turn(input_items[proxy._last_sent_count:]):
239239
proxy._relay_count = 0
240+
try:
241+
from codex_engine.router import classify_task_mode
242+
prompt_str = str(body.get("input", ""))
243+
task_mode = classify_task_mode(prompt_str)
244+
logger.info("Hybrid Router: Task classified as %s mode", task_mode)
245+
except Exception:
246+
pass
240247
proxy._last_sent_count = len(input_items)
241248

242249
proxy._relay_count += 1

‎codex_engine/router.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@ def classify_task_mode(prompt: str) -> str:
4040

4141
low_prompt = prompt.lower().strip()
4242

43-
# Check for strong Local OS indicators
43+
# Check for strong Local OS indicators using word boundaries for short keywords
4444
for kw in LOCAL_OS_KEYWORDS:
45-
if kw in low_prompt:
45+
pattern = r'\b' + re.escape(kw) + r'\b' if len(kw) <= 3 else re.escape(kw)
46+
if re.search(pattern, low_prompt):
4647
logger.info("Hybrid Router: Classified '%s' -> LOCAL (matched '%s')", prompt[:50], kw)
4748
return "LOCAL"
4849

‎orchestrator/providers/browser/extension_bridge.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,12 +289,17 @@ async def _send_completion_locked(
289289
loop = asyncio.get_running_loop()
290290
fut: asyncio.Future = loop.create_future()
291291

292+
gizmo_id = os.getenv("KIM_GIZMO_ID") or None
293+
292294
payload = {
293295
"type": "request",
294296
"requestId": req_id,
295297
"messages": [{"role": "user", "content": prompt}],
296298
"model": "auto",
297299
}
300+
if gizmo_id:
301+
payload["gizmoId"] = gizmo_id
302+
logger.info("[Kim Bridge] Custom GPT Gizmo mode: forwarding gizmoId=%s", gizmo_id)
298303
if attachments:
299304
payload["attachments"] = attachments
300305
if conversation_id:

‎orchestrator/providers/browser/prompt_builder.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,9 @@ def _parse_header_image_path(match):
489489
# it under the same ChatGPT-only condition) is provably initialized.
490490
direct_contract = ""
491491
is_terminal = bool(system and "codex bridge terminal" in str(system).lower())
492-
if (preferred_site or "").lower() == "chatgpt":
492+
gizmo_id = os.getenv("KIM_GIZMO_ID") or None
493+
494+
if (preferred_site or "").lower() == "chatgpt" and not gizmo_id:
493495
if is_terminal:
494496
direct_contract = (
495497
"DIRECT RESPONSE FORMAT REQUEST FOR THIS MESSAGE:\n"

0 commit comments

Comments
 (0)