cliclaw 1.0.35 → 1.0.36

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 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: '🔁 Sessão' },
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cliclaw",
3
- "version": "1.0.35",
3
+ "version": "1.0.36",
4
4
  "description": "Telegram bot bridging AI CLIs (Claude Code, Codex) to Forum Topics",
5
5
  "main": "index.ts",
6
6
  "scripts": {
@@ -26,12 +26,13 @@ interface PendingReq {
26
26
  }
27
27
 
28
28
  interface ProtoSession {
29
- proc: ChildProcess
30
- sessionId: string
31
- lastUsed: number
32
- pending: Map<string, PendingReq>
33
- buf: string // incomplete stdout line buffer
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) => {
@@ -129,11 +131,18 @@ function handleProtoEvent(ps: ProtoSession, obj: any) {
129
131
  const subId = msg.sub_id ?? msg.call_id ?? msgId
130
132
  const commandStr = formatApprovalCommand(msg.command ?? msg.cmd)
131
133
  console.log(`[Codex approval] request recebido sub_id=${subId} cmd="${commandStr.slice(0, 80)}"`)
134
+
135
+ // Respond using the original message id so Codex can correlate the reply
132
136
  const respond = (decision: string) => {
137
+ // Handle app-level session approval — Codex only understands 'approved'/'denied'/'abort'
138
+ if (decision === 'approved_for_session') {
139
+ ps.sessionApproved = true
140
+ decision = 'approved'
141
+ }
133
142
  console.log(`[Codex approval] enviando exec_approval sub_id=${subId} decision=${decision}`)
134
143
  try {
135
144
  ps.proc.stdin!.write(JSON.stringify({
136
- id: randomUUID(),
145
+ id: msgId, // use original event id, not a new UUID
137
146
  op: { type: 'exec_approval', sub_id: subId, decision },
138
147
  }) + '\n')
139
148
  console.log(`[Codex approval] enviado ok`)
@@ -141,6 +150,14 @@ function handleProtoEvent(ps: ProtoSession, obj: any) {
141
150
  console.error(`[Codex approval] erro ao enviar: ${e.message}`)
142
151
  }
143
152
  }
153
+
154
+ // If the user already approved the whole session, skip the prompt
155
+ if (ps.sessionApproved) {
156
+ console.log(`[Codex approval] sessão aprovada — auto-aprovando`)
157
+ respond('approved')
158
+ return
159
+ }
160
+
144
161
  if (ps.approvalHandler) {
145
162
  console.log(`[Codex approval] aguardando usuário via Telegram...`)
146
163
  ps.approvalHandler(subId, commandStr)
@@ -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', callback_data: `capprove:${approvalId}` },
119
- { text: '🔁 Sessão', callback_data: `csession:${approvalId}` },
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}` },