Go implementation of DeepSeek Harness and self-hosted personal agent.
Go
fix(plugins): skip X client secret for native apps
xyce45604cf186f
diff --git a/docs/plugin-account-setup.md b/docs/plugin-account-setup.mdindex ba21277..9561eca 100644--- a/docs/plugin-account-setup.md+++ b/docs/plugin-account-setup.md@@ -11,16 +11,20 @@ Go credentials. Do not put user credentials in chat, deployment `.env` or Git.1. Open the [X Developer Console](https://developer.x.com/), create an app andenable OAuth 2.0 user authentication. Select the app permissions you need.+ Use **Native App (public client)** for the default connection flow.2. Register `http://localhost:8080/callback` exactly as a callback URL. Obtain your- **Client ID** and, for a confidential client, **Client Secret**. A Native App- is a public client: leave the Secret empty, even if the console still shows a- secret value. Supplying one makes xurl use confidential-client authentication.+ **Client ID**. A Native App is a public client and does not need a Secret.+ If you use a **Web App / confidential client**, obtain its **Client Secret**+ as well; this application type requires it.**Website URL** is the application's homepage, for example`https://github.com/xyc999-ai/go-bot`. It introduces the app; it is not theController address or OAuth callback and does not need another deployed server.-3. Install and enable X in the plugin market. Open **Accounts and authorization →- Connect X account**. On first connection, enter the Client ID and Secret (leave- the latter empty only if you chose a public Native App).+3. Install and enable X in the plugin market. Open **Accounts and authorization** and+ use the authorization-method selector. Keep the default **Native App (no Client+ Secret)** and authorize: first connection asks only for the Client ID. For a+ confidential application, select **Web App / confidential client** instead;+ only that method asks for a Client Secret. Use the method matching your saved+ application when authorizing again.4. Open the authorization link in your own browser, sign in to X and approveaccess. Copy the **complete redirect URL** from the address bar into the panel,even if its localhost page cannot open. Submit it immediately: X documents a@@ -29,9 +33,10 @@ Go credentials. Do not put user credentials in chat, deployment `.env` or Git.5. Wait for the native authorization result. Subsequent connections reuse thenative application configuration, and xurl refreshes account tokens.-If an attempt fails or is cancelled, select **Connect X account** again. No Host-restart is needed. Open the new authorization link and submit that attempt's new-redirect URL; do not reuse an earlier URL or authorization code.+If an attempt fails or is cancelled, start authorization again with the same+application type. No Host restart is needed. Open the new authorization link and+submit that attempt's new redirect URL; do not reuse an earlier URL or+authorization code.X API usage is billed to the developer application/account. Connecting your ownX account does not make API calls free. Review your developer account's credits,diff --git a/extensions/catalog/plugins.json b/extensions/catalog/plugins.jsonindex 0816843..e0c33de 100644--- a/extensions/catalog/plugins.json+++ b/extensions/catalog/plugins.json@@ -26,7 +26,7 @@{"pluginId": "x","package": "@go-bot/plugin-x",- "version": "0.1.0",+ "version": "0.1.1","source": {"type": "bundled","spec": "x"diff --git a/extensions/cordis/test/native-account-plugins.test.mjs b/extensions/cordis/test/native-account-plugins.test.mjsindex 03cb2c6..1ed4102 100644--- a/extensions/cordis/test/native-account-plugins.test.mjs+++ b/extensions/cordis/test/native-account-plugins.test.mjs@@ -22,12 +22,12 @@ const fakeX=`const fs=require('node:fs'),path=require('node:path');const args=process.argv.slice(2),file=path.join(process.env.HOME,'.xurl','auth.yml');if(args[0]==='--version'){console.log('xurl test');process.exit(0)}if(args[1]==='oauth2'){- if(process.env.CLIENT_ID!=='project-x-client'||process.env.CLIENT_SECRET!=='')process.exit(3);+ if(process.env.CLIENT_ID!=='project-x-client'||process.env.CLIENT_SECRET!==(process.env.X_TEST_EXPECTED_SECRET||''))process.exit(3);const url='https://x.com/i/oauth2/authorize?client_id=project-x-client&redirect_uri='+encodeURIComponent('http://localhost:8080/callback')+'&state=attempt-state&code_challenge=test';process.stderr.write(url.slice(0,75));setTimeout(()=>process.stderr.write(url.slice(75)+'\\n'),10);let input='';process.stdin.on('data',v=>input+=v);process.stdin.on('end',()=>{const value=new URL(input.trim());if(value.searchParams.get('code')!=='accepted'||value.searchParams.get('state')!=='attempt-state')process.exit(4);- fs.writeFileSync(file,JSON.stringify({default_app:'default',apps:{default:{client_id:process.env.CLIENT_ID,default_user:'alice',oauth2_tokens:{alice:{oauth2:{access_token:'private-access',refresh_token:'private-refresh',expiration_time:1}}}}}}),{mode:0o600});+ fs.writeFileSync(file,JSON.stringify({default_app:'default',apps:{default:{client_id:process.env.CLIENT_ID,client_secret:process.env.CLIENT_SECRET,default_user:'alice',oauth2_tokens:{alice:{oauth2:{access_token:'private-access',refresh_token:'private-refresh',expiration_time:1}}}}}}),{mode:0o600});});}else if(args[1]==='clear'){if(args.at(-2)!=='--oauth2-username')process.exit(5);@@ -57,14 +57,14 @@ function context(){const ctx={host:{info:async()=>({instanceId:'x'}),authorization:{register:async row=>state.flows.push(row)},mcp:{register:async row=>{state.mcps.push(row);registration.resolve();return {dispose:async()=>state.removed++}}},skills:{registerDirectory:async dir=>state.skills.push(dir)},prompts:{register:async()=>{}}},on:(name,handler)=>state.events.set(name,handler),logger:{warn:()=>{}}}return {ctx,state}}-function session(provider){+function session(provider,method='oauth',secret=''){const notices=[],prompts=[],signal=new AbortController().signal- return {notices,prompts,method:'oauth',signal,notify:async value=>notices.push(value),prompt:async prompt=>{+ return {notices,prompts,method,signal,notify:async value=>notices.push(value),prompt:async prompt=>{prompts.push(prompt)if(prompt.kind==='select')return 'readonly'if(prompt.message.includes('Google Desktop OAuth client JSON'))return JSON.stringify({installed:{client_id:'project-google-client',client_secret:'desktop-public-value'}})if(prompt.message==='Enter your X app Client ID.')return 'project-x-client'- if(prompt.message.includes('Client Secret'))return ''+ if(prompt.message.includes('Client Secret'))return secretconst url=new URL(notices.at(-1).url),redirect=new URL(url.searchParams.get('redirect_uri'));redirect.searchParams.set('code','accepted');redirect.searchParams.set('state',url.searchParams.get('state'));return redirect.href}}}@@ -72,13 +72,14 @@ test('native X authorization uses child env, keeps tokens native and only startsconst f=await fixture(t);await f.binary('xurl',fakeX)const {ctx,state}=context();await applyX(ctx)assert.equal(state.mcps.length,0);assert.deepEqual(await state.flows[0].inspect(),{configured:false})+ assert.deepEqual(state.flows[0].methods.map(method=>method.id),['oauth','oauth-confidential'])const s=session('x'),root=path.join(process.env.DSH_HOME,'credentials','x')await authorizeX(s,root)- assert.equal(s.prompts.length,3,'first connection collects application ID, optional secret and callback')+ assert.equal(s.prompts.length,2,'a Native App only needs the application ID and callback')assert.equal(s.notices.filter(n=>n.url).length,1,'only the actual account login URL should be offered during authorization')- assert.match(s.prompts[2].message,/First open the authorization link/)- assert.match(s.prompts[2].placeholder,/localhost:8080\/callback/)- assert.equal(s.prompts[1].kind,'secret');assert.equal(s.prompts[2].kind,'text')+ assert.match(s.prompts[1].message,/First open the authorization link/)+ assert.match(s.prompts[1].placeholder,/localhost:8080\/callback/)+ assert.ok(s.prompts.every(prompt=>prompt.kind==='text'))assert.equal((await nativeAccount(root)).configured,true,'expired access tokens with refresh tokens remain configured')state.events.get('host/authorization-changed')({instanceId:'google-workspace',key:'account',phase:'authorized'})assert.equal(state.mcps.length,0,'another plugin authorization must not activate this bridge')@@ -91,6 +92,34 @@ test('native X authorization uses child env, keeps tokens native and only startsassert.equal(state.removed,1);assert.deepEqual(await state.flows[0].inspect(),{configured:false})assert.equal(process.env.CLIENT_ID,undefined)})+test('Native App login ignores inherited application secrets and reuses its saved Client ID',async t=>{+ const f=await fixture(t);await f.binary('xurl',fakeX)+ const {ctx}=context();await applyX(ctx)+ process.env.CLIENT_ID='another-application';process.env.CLIENT_SECRET='unrelated-host-secret'+ const root=path.join(process.env.DSH_HOME,'credentials','x')+ await authorizeX(session('x'),root)+ assert.equal((await nativeAccount(root)).app.client_secret,'')+ const again=session('x');await authorizeX(again,root)+ assert.equal(again.prompts.length,1,'saved Native Apps go straight to the callback question')+ assert.equal(process.env.CLIENT_SECRET,'unrelated-host-secret','child overrides must not modify Host environment')+})+test('confidential X login requires a secret, then reuses native credentials without another secret prompt',async t=>{+ const f=await fixture(t);await f.binary('xurl',fakeX)+ const {ctx}=context();await applyX(ctx)+ const root=path.join(process.env.DSH_HOME,'credentials','x')+ const empty=session('x','oauth-confidential')+ await assert.rejects(authorizeX(empty,root),/Client Secret is required/)+ assert.equal(empty.notices.filter(notice=>notice.url).length,0,'do not start OAuth with missing credentials')+ process.env.X_TEST_EXPECTED_SECRET='confidential-test-secret'+ const s=session('x','oauth-confidential','confidential-test-secret');await authorizeX(s,root)+ assert.deepEqual(s.prompts.map(prompt=>prompt.kind),['text','secret','text'])+ assert.equal((await nativeAccount(root)).app.client_secret,'confidential-test-secret')+ const again=session('x','oauth-confidential');await authorizeX(again,root)+ assert.equal(again.prompts.length,1)+ await assert.rejects(authorizeX(session('x'),root),/Select the confidential-client/)+ const reloaded=context();await applyX(reloaded.ctx)+ assert.equal(reloaded.state.flows[0].methods[0].id,'oauth-confidential','default to the saved application type after reload')+})test('native Google authorization relays only the current callback and stores an actual native grant',async t=>{const f=await fixture(t);await f.binary('gws',fakeGoogle)const {ctx,state}=context();await applyGoogle(ctx)diff --git a/extensions/plugins/x/package-lock.json b/extensions/plugins/x/package-lock.jsonindex ccb1825..e6cbca0 100644--- a/extensions/plugins/x/package-lock.json+++ b/extensions/plugins/x/package-lock.json@@ -1,12 +1,12 @@{"name": "@go-bot/plugin-x",- "version": "0.1.0",+ "version": "0.1.1","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "@go-bot/plugin-x",- "version": "0.1.0",+ "version": "0.1.1","hasInstallScript": true,"license": "MIT","dependencies": {diff --git a/extensions/plugins/x/package.json b/extensions/plugins/x/package.jsonindex d869133..4d4e207 100644--- a/extensions/plugins/x/package.json+++ b/extensions/plugins/x/package.json@@ -1,6 +1,6 @@{"name": "@go-bot/plugin-x",- "version": "0.1.0",+ "version": "0.1.1","type": "module","description": "Connect X with the official xurl MCP bridge and native account authorization.","license": "MIT",diff --git a/extensions/plugins/x/plugin.json b/extensions/plugins/x/plugin.jsonindex e58c524..240e785 100644--- a/extensions/plugins/x/plugin.json+++ b/extensions/plugins/x/plugin.json@@ -1,11 +1,11 @@{"name": "X","description": {- "en": "Connect X with the official xurl MCP bridge and native account authorization.\n\n1. Create an app at [X Developer Portal](https://developer.x.com/) and enable OAuth 2.0 user authentication. Choose the app permissions you need.\n2. Register `http://localhost:8080/callback` as the callback URL. Obtain your Client ID and Client Secret (for a public Native App, leave the secret empty even if the console shows a secret value).\n3. Install and enable X. Open Accounts and authorization → Connect X account. Enter your application credentials when prompted on first connection.\n4. Open the authorization link in your browser, sign in to X and approve access. Paste the complete redirect URL back into the panel, even if its localhost page cannot open. Submit it immediately: X authorization codes expire after 30 seconds.\n\nxurl saves the application settings and account tokens in your Host and refreshes tokens natively. Subsequent authorization reuses the application configuration. Disconnect removes only the active account token. X API usage is billed to your developer application/account; review its access, credits and spending limit.\n\nUpstream guide: [xurl authentication](https://github.com/xdevplatform/xurl#authentication)\n\nRetrieved content enters your Agent context and may be processed by your selected model provider.",- "zh-CN": "通过官方 xurl MCP 桥连接 X,使用原生账号授权。\n\n1. 在 [X Developer Portal](https://developer.x.com/) 创建应用,启用 OAuth 2.0 用户认证并选择需要的应用权限。\n2. 登记回调地址 `http://localhost:8080/callback`,获取 Client ID 和 Client Secret(公共 Native App 请将 Secret 留空,即使控制台仍显示 Secret 值)。\n3. 安装并启用 X,打开「账号与授权」→「连接 X 账号」,首次连接按提示填写应用凭证。\n4. 在自己的浏览器中打开授权链接,登录 X 并同意权限。将完整回跳地址粘贴回面板,即使 localhost 页面打不开。请立即提交,X 授权码只有 30 秒有效。\n\nxurl 在你的 Host 中原生保存应用配置与账号令牌,并刷新令牌;后续授权复用应用配置。退出授权只移除当前账号令牌。X API 调用由你自己的开发者应用/账户计费,请核对访问权限、额度与消费限额。\n\n上游指引:[xurl authentication](https://github.com/xdevplatform/xurl#authentication)\n\n检索内容会进入你的 Agent 上下文,并可能交给你选择的模型服务处理。"+ "en": "Connect X with the official xurl MCP bridge and native account authorization.\n\n1. Create an app at [X Developer Portal](https://developer.x.com/) and enable OAuth 2.0 user authentication. Choose the app permissions you need. Native App (public client) is the default connection type.\n2. Register `http://localhost:8080/callback` as the callback URL. Obtain your Client ID. A Native App does not need a Client Secret.\n3. Install and enable X. Open Accounts and authorization. Keep Native App (no Client Secret) selected and authorize; first connection asks only for the Client ID. If your developer app is a Web App / confidential client, select that authorization method instead; only this method asks for a Client Secret. Saved application credentials are reused on later connections.\n4. Open the authorization link in your browser, sign in to X and approve access. Paste the complete redirect URL back into the panel, even if its localhost page cannot open. Submit it immediately: X authorization codes expire after 30 seconds.\n\nxurl saves the application settings and account tokens in your Host and refreshes tokens natively. Subsequent authorization reuses the application configuration. Disconnect removes only the active account token. X API usage is billed to your developer application/account; review its access, credits and spending limit.\n\nUpstream guide: [xurl authentication](https://github.com/xdevplatform/xurl#authentication)\n\nRetrieved content enters your Agent context and may be processed by your selected model provider.",+ "zh-CN": "通过官方 xurl MCP 桥连接 X,使用原生账号授权。\n\n1. 在 [X Developer Portal](https://developer.x.com/) 创建应用,启用 OAuth 2.0 用户认证并选择需要的应用权限,默认采用 Native App(公共客户端)连接。\n2. 登记回调地址 `http://localhost:8080/callback`,获取 Client ID。Native App 无需 Client Secret。\n3. 安装并启用 X,打开「账号与授权」,保留默认的「Native App(无需 Client Secret)」并发起授权,首次连接只需填写 Client ID。如果开发者应用属于 Web App/机密客户端,改选对应授权方式,才会要求填写 Client Secret;后续连接复用已保存的应用凭证。\n4. 在自己的浏览器中打开授权链接,登录 X 并同意权限。将完整回跳地址粘贴回面板,即使 localhost 页面打不开。请立即提交,X 授权码只有 30 秒有效。\n\nxurl 在你的 Host 中原生保存应用配置与账号令牌,并刷新令牌;后续授权复用应用配置。退出授权只移除当前账号令牌。X API 调用由你自己的开发者应用/账户计费,请核对访问权限、额度与消费限额。\n\n上游指引:[xurl authentication](https://github.com/xdevplatform/xurl#authentication)\n\n检索内容会进入你的 Agent 上下文,并可能交给你选择的模型服务处理。"},"icon": "/assets/plugins/x/icon.png",- "version": "0.1.0",+ "version": "0.1.1","maintainer": "Go Bot","license": "MIT","tutorials": [diff --git a/extensions/plugins/x/src/index.mjs b/extensions/plugins/x/src/index.mjsindex 02bef51..2265bc3 100644--- a/extensions/plugins/x/src/index.mjs+++ b/extensions/plugins/x/src/index.mjs@@ -27,7 +27,10 @@ export async function apply(ctx) {if(bridge || !(await inspect()).configured)returnbridge=await ctx.host.mcp.register({name:'api',connection:{transport:'stdio',command:'xurl',args:['mcp','https://api.x.com/mcp']},toolLoading:'on-demand'})})- await ctx.host.authorization.register({key:'account',title:'X',methods:[{id:'oauth',label:'Connect X account'}],inspect,+ const account=await nativeAccount(directory)+ const methods=[{id:'oauth',label:'Native App (no Client Secret)'},{id:'oauth-confidential',label:'Web App / confidential client'}]+ if(account.app?.client_secret)methods.reverse()+ await ctx.host.authorization.register({key:'account',title:'X',methods,inspect,disconnect:async({signal})=>{await closeBridge()const row=await nativeAccount(directory)@@ -45,15 +48,23 @@ export async function apply(ctx) {export async function authorize(session,directory){const row=await nativeAccount(directory)const env={...process.env}+ const confidential=session.method==='oauth-confidential'+ // Do not inherit another application's credentials from the Host environment.+ env.CLIENT_ID=row.app?.client_id||''+ env.CLIENT_SECRET=''+ if(!confidential&&row.app?.client_secret)throw new Error('This saved X app uses a Client Secret. Select the confidential-client authorization method.')if(!row.app?.client_id){// The setup link already lives in the plugin detail. Keeping it as a// second "Continue in browser" notice obscures the real login link.await session.notify({message:'Create your X Developer App and enable OAuth 2.0. Register http://localhost:8080/callback as its callback URL. API usage is billed to your developer account.'})env.CLIENT_ID=(await session.prompt({kind:'text',message:'Enter your X app Client ID.'})).trim()if(!env.CLIENT_ID)throw new Error('X Client ID is required.')- env.CLIENT_SECRET=(await session.prompt({kind:'secret',message:'Enter the Client Secret only for a Web App / confidential client. For a Native App / public client, leave this empty.'})).trim()env.REDIRECT_URI='http://localhost:8080/callback'}+ if(confidential){+ env.CLIENT_SECRET=row.app?.client_secret||(await session.prompt({kind:'secret',message:'Enter your confidential X app Client Secret.'})).trim()+ if(!env.CLIENT_SECRET)throw new Error('X Client Secret is required for a confidential client.')+ }const cli=interactive('xurl',['auth','oauth2','--headless','--app',row.appName||'default'],{signal:session.signal,env,acceptURL:u=>u.protocol==='https:'&&['x.com','twitter.com'].includes(u.hostname)&&u.searchParams.has('redirect_uri')})try{const url=await cli.url, redirect=url.searchParams.get('redirect_uri'), state=url.searchParams.get('state')diff --git a/frontend/src/extensions/messages.ts b/frontend/src/extensions/messages.tsindex 80302b6..318fa9a 100644--- a/frontend/src/extensions/messages.ts+++ b/frontend/src/extensions/messages.ts@@ -111,8 +111,11 @@ export const extensionChinese: Readonly<Record<string, string>> = {"Could not load this video. Try again.": "无法加载视频,请重试。","Create your X Developer App and enable OAuth 2.0. Register http://localhost:8080/callback as its callback URL. API usage is billed to your developer account.": "创建自己的 X 开发者应用并启用 OAuth 2.0,登记回调地址 http://localhost:8080/callback。API 调用由你的开发者账户计费。","Enter your X app Client ID.": "填写你的 X 应用 Client ID。",- "Enter your X app Client Secret. Leave empty only for a public Native App.": "填写你的 X 应用 Client Secret;只有公共 Native App 可留空。",- 'Enter the Client Secret only for a Web App / confidential client. For a Native App / public client, leave this empty.': '只有 Web App/机密客户端才填写 Client Secret。Native App/公共客户端请留空。',+ 'Native App (no Client Secret)': 'Native App(无需 Client Secret)',+ 'Web App / confidential client': 'Web App/机密客户端',+ 'Enter your confidential X app Client Secret.': '填写你的 X 机密客户端 Client Secret。',+ 'X Client Secret is required for a confidential client.': '机密客户端必须填写 Client Secret。',+ 'This saved X app uses a Client Secret. Select the confidential-client authorization method.': '已保存的 X 应用使用 Client Secret,请选择机密客户端授权方式。','Sign in to X in your browser. After approval, immediately copy the complete redirect URL here, even if the local page cannot open. X authorization codes expire after 30 seconds.': '在浏览器中登录 X 并授权后,请立即将完整回跳地址复制到这里,即使本地页面打不开。X 授权码只有 30 秒有效。','Could not verify the imported Google authorization. Check the export and Host network. Your existing account has not been changed.': '无法验证导入的 Google 授权,请检查导出数据和 Host 网络。原有账号未被修改。','Select a JSON configuration file.': '选择 JSON 配置文件。',