cliclaw 1.0.35 → 1.0.37
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/index.ts +1 -1
- package/package.json +1 -1
- package/src/agents/codex.ts +32 -9
- package/src/handlers/messages.ts +2 -2
package/index.ts
CHANGED
|
@@ -27,7 +27,7 @@ registerMessageHandler(bot, storage, config)
|
|
|
27
27
|
// ── Codex exec approval callbacks ──────────────────────────────────────────
|
|
28
28
|
const APPROVAL_PREFIXES: Record<string, { decision: string; label: string }> = {
|
|
29
29
|
capprove: { decision: 'approved', label: '✅ Aprovado' },
|
|
30
|
-
csession: { decision: 'approved_for_session', label: '
|
|
30
|
+
csession: { decision: 'approved_for_session', label: '🔓 Sessão aprovada!' },
|
|
31
31
|
cdeny: { decision: 'denied', label: '❌ Negado' },
|
|
32
32
|
cabort: { decision: 'abort', label: '🛑 Abortado' },
|
|
33
33
|
}
|
package/package.json
CHANGED
package/src/agents/codex.ts
CHANGED
|
@@ -26,12 +26,13 @@ interface PendingReq {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
interface ProtoSession {
|
|
29
|
-
proc:
|
|
30
|
-
sessionId:
|
|
31
|
-
lastUsed:
|
|
32
|
-
pending:
|
|
33
|
-
buf:
|
|
29
|
+
proc: ChildProcess
|
|
30
|
+
sessionId: string
|
|
31
|
+
lastUsed: number
|
|
32
|
+
pending: Map<string, PendingReq>
|
|
33
|
+
buf: string // incomplete stdout line buffer
|
|
34
34
|
approvalHandler?: (callId: string, commandStr: string) => Promise<string>
|
|
35
|
+
sessionApproved: boolean // true after user clicks "Aprovar Sessão"
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
// Map from cliclaw session.id → ProtoSession
|
|
@@ -74,6 +75,7 @@ function startProto(appSessionId: string): ProtoSession {
|
|
|
74
75
|
lastUsed: Date.now(),
|
|
75
76
|
pending: new Map(),
|
|
76
77
|
buf: '',
|
|
78
|
+
sessionApproved: false,
|
|
77
79
|
}
|
|
78
80
|
|
|
79
81
|
proc.stdout!.on('data', (d: Buffer) => {
|
|
@@ -84,7 +86,9 @@ function startProto(appSessionId: string): ProtoSession {
|
|
|
84
86
|
try {
|
|
85
87
|
const obj = JSON.parse(line)
|
|
86
88
|
handleProtoEvent(ps, obj)
|
|
87
|
-
} catch {
|
|
89
|
+
} catch (e: any) {
|
|
90
|
+
console.error('[Codex proto] parse error:', e?.message, '| line:', line.slice(0, 120))
|
|
91
|
+
}
|
|
88
92
|
}
|
|
89
93
|
})
|
|
90
94
|
|
|
@@ -129,18 +133,37 @@ function handleProtoEvent(ps: ProtoSession, obj: any) {
|
|
|
129
133
|
const subId = msg.sub_id ?? msg.call_id ?? msgId
|
|
130
134
|
const commandStr = formatApprovalCommand(msg.command ?? msg.cmd)
|
|
131
135
|
console.log(`[Codex approval] request recebido sub_id=${subId} cmd="${commandStr.slice(0, 80)}"`)
|
|
136
|
+
|
|
137
|
+
// Codex uses JSON-RPC 2.0 with its own decision strings
|
|
138
|
+
const DECISION_MAP: Record<string, string> = {
|
|
139
|
+
approved: 'accept',
|
|
140
|
+
approved_for_session: 'acceptForSession',
|
|
141
|
+
denied: 'decline',
|
|
142
|
+
abort: 'cancel',
|
|
143
|
+
}
|
|
132
144
|
const respond = (decision: string) => {
|
|
133
|
-
|
|
145
|
+
if (decision === 'approved_for_session') ps.sessionApproved = true
|
|
146
|
+
const codexDecision = DECISION_MAP[decision] ?? 'decline'
|
|
147
|
+
console.log(`[Codex approval] enviando exec_approval id=${msgId} decision=${codexDecision}`)
|
|
134
148
|
try {
|
|
135
149
|
ps.proc.stdin!.write(JSON.stringify({
|
|
136
|
-
|
|
137
|
-
|
|
150
|
+
jsonrpc: '2.0',
|
|
151
|
+
id: msgId,
|
|
152
|
+
result: { decision: codexDecision },
|
|
138
153
|
}) + '\n')
|
|
139
154
|
console.log(`[Codex approval] enviado ok`)
|
|
140
155
|
} catch (e: any) {
|
|
141
156
|
console.error(`[Codex approval] erro ao enviar: ${e.message}`)
|
|
142
157
|
}
|
|
143
158
|
}
|
|
159
|
+
|
|
160
|
+
// If the user already approved the whole session, skip the prompt
|
|
161
|
+
if (ps.sessionApproved) {
|
|
162
|
+
console.log(`[Codex approval] sessão aprovada — auto-aprovando`)
|
|
163
|
+
respond('approved')
|
|
164
|
+
return
|
|
165
|
+
}
|
|
166
|
+
|
|
144
167
|
if (ps.approvalHandler) {
|
|
145
168
|
console.log(`[Codex approval] aguardando usuário via Telegram...`)
|
|
146
169
|
ps.approvalHandler(subId, commandStr)
|
package/src/handlers/messages.ts
CHANGED
|
@@ -115,8 +115,8 @@ async function processMessage(ctx: Context, storage: Storage, config: Config) {
|
|
|
115
115
|
parse_mode: 'HTML',
|
|
116
116
|
reply_markup: { inline_keyboard: [
|
|
117
117
|
[
|
|
118
|
-
{ text: '✅ Aprovar',
|
|
119
|
-
{ text: '
|
|
118
|
+
{ text: '✅ Aprovar', callback_data: `capprove:${approvalId}` },
|
|
119
|
+
{ text: '🔓 Aprovar Sessão', callback_data: `csession:${approvalId}` },
|
|
120
120
|
],
|
|
121
121
|
[
|
|
122
122
|
{ text: '❌ Negar', callback_data: `cdeny:${approvalId}` },
|