安全性提升:TID动态生成+Streamlit页面排除+工作记忆修复

This commit is contained in:
Liang Jiaqing
2026-03-06 18:54:09 +08:00
parent c6af92e612
commit 524944dfc8
7 changed files with 22 additions and 15 deletions

2
.gitignore vendored
View File

@@ -67,3 +67,5 @@ restore_commit.txt
sche_tasks/ sche_tasks/
QUICK_START.md QUICK_START.md
# CDP Bridge 密钥配置(首次运行自动生成)
assets/tmwd_cdp_bridge/config.js

View File

@@ -13,13 +13,17 @@ with open('assets/tools_schema.json', 'r', encoding='utf-8') as f:
TS = f.read() TS = f.read()
TOOLS_SCHEMA = json.loads(TS if os.name == 'nt' else TS.replace('powershell', 'bash')) TOOLS_SCHEMA = json.loads(TS if os.name == 'nt' else TS.replace('powershell', 'bash'))
if not os.path.exists('memory'): os.makedirs('memory')
if not os.path.exists('memory/global_mem.txt'):
with open('memory/global_mem.txt', 'w', encoding='utf-8') as f: f.write('')
if not os.path.exists('memory/global_mem_insight.txt'):
t = 'assets/global_mem_insight_template.txt'
open('memory/global_mem_insight.txt', 'w', encoding='utf-8').write(open(t, encoding='utf-8').read() if os.path.exists(t) else '')
if not os.path.exists('assets/tmwd_cdp_bridge/config.js'):
with open('assets/tmwd_cdp_bridge/config.js', 'w', encoding='utf-8') as f:
f.write(f"const TID = '__ljq_{hex(random.randint(0, 99999999))[2:8]}';")
def get_system_prompt(): def get_system_prompt():
if not os.path.exists('memory'): os.makedirs('memory')
if not os.path.exists('memory/global_mem.txt'):
with open('memory/global_mem.txt', 'w', encoding='utf-8') as f: f.write('')
if not os.path.exists('memory/global_mem_insight.txt'):
t = 'assets/global_mem_insight_template.txt'
open('memory/global_mem_insight.txt', 'w', encoding='utf-8').write(open(t, encoding='utf-8').read() if os.path.exists(t) else '')
with open('assets/sys_prompt.txt', 'r', encoding='utf-8') as f: prompt = f.read() with open('assets/sys_prompt.txt', 'r', encoding='utf-8') as f: prompt = f.read()
prompt += f"\nToday: {time.strftime('%Y-%m-%d %a')}\n" prompt += f"\nToday: {time.strftime('%Y-%m-%d %a')}\n"
prompt += get_global_memory() prompt += get_global_memory()

View File

@@ -19,6 +19,7 @@
(function() { (function() {
'use strict'; 'use strict';
const log_prefix = "ljq_driver: "; const log_prefix = "ljq_driver: ";
if (document.querySelector('[data-testid="stApp"],.stApp')) return;
if (window.self !== window.top) { if (window.self !== window.top) {
window.addEventListener('message',e=>{if(e.data?.type==='ljq_exec'){try{let r=eval(e.data.code);parent.postMessage({type:'ljq_result',id:e.data.id,result:String(r)},'*')}catch(err){parent.postMessage({type:'ljq_result',id:e.data.id,error:err.message},'*')}}}); window.addEventListener('message',e=>{if(e.data?.type==='ljq_exec'){try{let r=eval(e.data.code);parent.postMessage({type:'ljq_result',id:e.data.id,result:String(r)},'*')}catch(err){parent.postMessage({type:'ljq_result',id:e.data.id,error:err.message},'*')}}});

View File

@@ -1,5 +1,3 @@
// content.js - DOM trigger bridge
const TID = '__ljq_ctrl';
new MutationObserver(muts => { new MutationObserver(muts => {
for (const m of muts) for (const n of m.addedNodes) { for (const m of muts) for (const n of m.addedNodes) {

View File

@@ -16,7 +16,7 @@
"content_scripts": [ "content_scripts": [
{ {
"matches": ["<all_urls>"], "matches": ["<all_urls>"],
"js": ["content.js"], "js": ["config.js", "content.js"],
"run_at": "document_idle", "run_at": "document_idle",
"all_frames": true "all_frames": true
} }

4
ga.py
View File

@@ -407,8 +407,8 @@ class GenericAgentHandler(BaseHandler):
''' '''
key_info = args.get("key_info", "") key_info = args.get("key_info", "")
related_sop = args.get("related_sop", "") related_sop = args.get("related_sop", "")
if key_info: self.key_info = key_info if "key_info" in args: self.key_info = key_info
if related_sop: self.related_sop = related_sop if "related_sop" in args: self.related_sop = related_sop
yield f"[Info] Updated key_info and related_sop.\n" yield f"[Info] Updated key_info and related_sop.\n"
yield f"key_info:\n{self.key_info}\n\n" yield f"key_info:\n{self.key_info}\n\n"
yield f"related_sop:\n{self.related_sop}\n\n" yield f"related_sop:\n{self.related_sop}\n\n"

View File

@@ -46,12 +46,14 @@ fetch('PDF_URL').then(r=>r.blob()).then(b=>{
## CDP桥(tmwd_cdp_bridge扩展) ⭐首选 ## CDP桥(tmwd_cdp_bridge扩展) ⭐首选
扩展路径:`assets/tmwd_cdp_bridge/`(需安装含debugger权限) 扩展路径:`assets/tmwd_cdp_bridge/`(需安装含debugger权限)
调用MutationObserver监听addedNodes(id=`__ljq_ctrl`)⚠每次必须remove旧→createElement新→设textContent JSON→appendChild ⚠TID密钥首次运行自动生成到`assets/tmwd_cdp_bridge/config.js`(已gitignore)扩展通过manifest引用
调用MutationObserver监听addedNodes(id=TID)⚠每次必须remove旧→createElement新→设textContent JSON→appendChild
```js ```js
const old = document.getElementById('__ljq_ctrl'); // TID从assets/tmwd_cdp_bridge/config.js读取示例用'__ljq_ctrl'占位
const old = document.getElementById(TID);
if (old) old.remove(); if (old) old.remove();
const el = document.createElement('div'); const el = document.createElement('div');
el.id = '__ljq_ctrl'; el.style.display = 'none'; el.id = TID; el.style.display = 'none';
el.textContent = JSON.stringify({cmd:'...', ...}); el.textContent = JSON.stringify({cmd:'...', ...});
document.body.appendChild(el); // 响应写回el.textContent document.body.appendChild(el); // 响应写回el.textContent
``` ```