@ai-workbench/connect 0.7.44 → 0.7.45
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 +4 -0
- package/helper/auth-status.cjs +18 -2
- package/lib/ssh.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -134,3 +134,7 @@ DSH 自带子代理(subagent/subagent_fork/workflow 等)创建的子会话
|
|
|
134
134
|
### 同品牌并行轮的登录就绪核对(0.7.44)
|
|
135
135
|
|
|
136
136
|
DSH workflow/subagent 并行派出的多个子会话(以及同一员工同时进行的多个会话)每一轮开始前都要经 `ensureReady` 核对主机登录状态。旧实现每次调用各发一条主机状态命令,并按“最新一次为准”作废同品牌较早的检查,于是 N 路并行只有最后发起的一路成功,其余报 `AUTH_STATUS_INVALID`(`STATUS_SUPERSEDED`),DSH workflow 把它们记为 null。现在同一连接代次内同品牌并发的 `ensureReady` 共用同一次进行中的核对,每个调用方拿到各自的结果副本;断线重连后到达的调用方不接旧代次的核对,自行重新核对;结束后下一次调用照常重新核对。(0.7.43 为未转正候选,断线后到达的调用方会接上旧核对,已由 0.7.44 取代。)不新增设置、限制或错误码,不改登录、登出与授权流程。
|
|
137
|
+
|
|
138
|
+
### 登出时结束该品牌仍在运行的主机会话(0.7.45)
|
|
139
|
+
|
|
140
|
+
在“远程主机连接”里登出主机 Claude 或 Codex 后,L 在同一次主机命令里经主机会话控制(`aw-session status` 识别品牌,`kill --if-instance` 结束)结束该员工在主机上仍活着的这一品牌的会话进程;另一品牌不动,已无回应的残留目录不动。这些进程沿用登出前的登录,不应在登出后继续运行。正在进行的那一轮会结束,员工在原对话发下一条消息即按原会话续接(主机未登录时提示需要登录)。结束未获确认时登出报 `LOGOUT_FAILED`,可再次登出。CLI 登出本身失败时不动任何会话。不新增设置、限制或错误码。
|
package/helper/auth-status.cjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// Claude 状态只复用主机只读判断器;Codex 与显式登出仍走原 CLI 路径。
|
|
2
2
|
const {spawn}=require('node:child_process');const {StringDecoder}=require('node:string_decoder');const decoder=new StringDecoder('utf8'),errorDecoder=new StringDecoder('utf8');
|
|
3
3
|
const [provider,budgetText,action='status',...extra]=process.argv.slice(1),budget=Number(budgetText);
|
|
4
|
-
|
|
4
|
+
// Logout also names this employee's host session command and root, so the brand's live agents end with its login.
|
|
5
|
+
const [sessionCommand,sessionRoot]=action==='logout'?extra:[];
|
|
6
|
+
if(!['codex','claude'].includes(provider)||!Number.isSafeInteger(budget)||budget<1||!['status','logout'].includes(action)||extra.length!==(action==='logout'?2:0)||action==='logout'&&!extra.every(value=>value.startsWith('/')))process.exit(2);
|
|
5
7
|
if(provider==='claude'&&action==='status'){
|
|
6
8
|
try{
|
|
7
9
|
const {readClaudeAuthState}=require('/usr/local/aw-host/lib/claude-auth-state.cjs');
|
|
@@ -21,11 +23,25 @@ for(const [stream,channel] of [[child.stdout,'out'],[child.stderr,'err']])stream
|
|
|
21
23
|
function finish(exitCode){
|
|
22
24
|
if(finished)return;finished=true;
|
|
23
25
|
stdout+=decoder.end();stderr+=errorDecoder.end();let loggedIn=null;
|
|
24
|
-
if(action==='logout'){process.exitCode=!invalid&&Number.isInteger(exitCode)&&exitCode>=0&&exitCode<=255?exitCode:1;return;}
|
|
26
|
+
if(action==='logout'){process.exitCode=!invalid&&Number.isInteger(exitCode)&&exitCode>=0&&exitCode<=255?exitCode:1;if(process.exitCode===0&&!endBrandSessions())process.exitCode=1;return;}
|
|
25
27
|
if(!invalid&&provider==='codex'){if(exitCode===0)loggedIn=true;else if(exitCode===1&&stdout.trim()===''&&stderr.trim()==='Not logged in')loggedIn=false;}
|
|
26
28
|
const code=Number.isInteger(exitCode)&&exitCode>=0&&exitCode<=255?exitCode:1;
|
|
27
29
|
process.stdout.write(JSON.stringify({protocolVersion:1,provider,exitCode,loggedIn})+'\n',()=>process.exit(code));
|
|
28
30
|
}
|
|
31
|
+
// A host agent of this brand keeps the login it started with. After logout every one of them ends through the public S control
|
|
32
|
+
// (status identifies the brand, kill --if-instance ends it); a directory whose broker no longer answers has no live agent.
|
|
33
|
+
function endBrandSessions(){
|
|
34
|
+
const {readdirSync,existsSync}=require('node:fs'),{join}=require('node:path'),{spawnSync}=require('node:child_process'),env={...process.env,AW_SESSION_ROOT:sessionRoot},run=args=>spawnSync(sessionCommand,args,{env,encoding:'utf8',stdio:['ignore','pipe','ignore']});
|
|
35
|
+
let ids,ended=true;try{ids=readdirSync(sessionRoot);}catch(error){return error?.code==='ENOENT';}
|
|
36
|
+
for(const id of ids){const status=run(['status',id]);let row;try{row=status.status===0?JSON.parse(status.stdout):undefined;}catch{row=undefined;}
|
|
37
|
+
if(row?.id!==id||row.ownership?.provider!==provider)continue;
|
|
38
|
+
const killed=run(['kill',id,'--if-instance',String(row.instanceId)]);let reply;try{reply=JSON.parse(killed.stdout);}catch{reply=undefined;}
|
|
39
|
+
if(killed.status===0&&reply?.type==='killed'&&reply.id===id)continue;
|
|
40
|
+
// Not confirmed by this kill: the host removed it meanwhile, or another kill of the same session is already stopping it.
|
|
41
|
+
const again=existsSync(join(sessionRoot,id))?run(['status',id]):undefined;let state;try{state=again?.status===0?JSON.parse(again.stdout).state:undefined;}catch{state=undefined;}
|
|
42
|
+
if(again?.status===0&&state!=='stopping')ended=false;}
|
|
43
|
+
return ended;
|
|
44
|
+
}
|
|
29
45
|
child.once('exit',code=>{if(invalid)finish(code);});child.once('close',finish);
|
|
30
46
|
|
|
31
47
|
}
|
package/lib/ssh.js
CHANGED
|
@@ -84,7 +84,7 @@ export function createSsh(runner, maxOutputBytes) {
|
|
|
84
84
|
if (!['codex', 'claude'].includes(p) || !Number.isSafeInteger(maxOutputBytes) || maxOutputBytes < 1)
|
|
85
85
|
return authFailure('ssh-status', 'STATUS_ARGUMENT_INVALID');
|
|
86
86
|
const source = await readFile(new URL('../helper/auth-status.cjs', import.meta.url), 'utf8');
|
|
87
|
-
const r = await runRemote(runner, t, 'node -e ' + "'" + source.replaceAll("'", "'\\''") + "' -- " + p + ' ' + maxOutputBytes + ' logout', signal);
|
|
87
|
+
const r = await runRemote(runner, t, 'node -e ' + "'" + source.replaceAll("'", "'\\''") + "' -- " + p + ' ' + maxOutputBytes + ' logout ' + shellQuote(t.session.command) + ' ' + shellQuote(t.session.root), signal);
|
|
88
88
|
return r.exitCode === 0 ? ok(undefined) : authFailure('ssh-status', 'STATUS_EXIT_INVALID', { exitCode: r.exitCode }, undefined, 'LOGOUT_FAILED');
|
|
89
89
|
}
|
|
90
90
|
catch (error) {
|