kira-glasses-bridge 2.9.0 → 2.10.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kira-glasses-bridge",
3
- "version": "2.9.0",
3
+ "version": "2.10.0",
4
4
  "description": "Connects your Mac to Kira, the assistant for Even G2 glasses: Claude Code sessions, files, folders and apps, by voice.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -202,6 +202,9 @@ export async function run({ prompt, sessionId, cwd, policy, persona, abort }, io
202
202
  // A team member's soul, skills and conventions ride on top of Claude Code's own prompt; its preset says which tools it does without.
203
203
  ...(persona?.systemPrompt ? { systemPrompt: { type: 'preset', preset: 'claude_code', append: persona.systemPrompt } } : {}),
204
204
  ...(persona?.disallowedTools?.length ? { disallowedTools: persona.disallowedTools } : {}),
205
+ // Kira has its own Gmail/Calendar/Drive tools; keep the user's claude.ai connectors out of
206
+ // the sessions it runs, so there's one pathway for acting on their accounts (Kira's).
207
+ env: { ...process.env, ENABLE_CLAUDEAI_MCP_SERVERS: 'false' },
205
208
  canUseTool,
206
209
  hooks: { PreToolUse: [{ hooks: [preToolUse] }] },
207
210
  ...(process.env.KIRA_CLAUDE_BIN ? { pathToClaudeCodeExecutable: process.env.KIRA_CLAUDE_BIN } : {}),
package/src/index.mjs CHANGED
@@ -35,19 +35,50 @@ function sendLive(obj) {
35
35
  }
36
36
  const ANSWER_TIMEOUT_MS = 3 * 60 * 1000
37
37
 
38
- /** Start the bridge with resolved settings. Runs until the process exits. */
39
- export function startBridge(config) {
38
+ /**
39
+ * How the host hears from the bridge. The CLI passes nothing (logs to stdout, exits when the
40
+ * token is rejected); an app embedding it (the Kira desktop app) passes its own:
41
+ * log(line) every log line
42
+ * onStatus(status) 'connecting' | 'connected' | 'disconnected' | 'rejected'
43
+ */
44
+ let hooks = {}
45
+ let stopped = false
46
+ let reconnectTimer = null
47
+
48
+ /** Start the bridge with resolved settings. Runs until stopBridge() or the process exits. */
49
+ export function startBridge(config, hostHooks = {}) {
50
+ hooks = hostHooks
40
51
  URL_ = config.url
41
52
  TOKEN = config.token
42
53
  if (config.claudeBin) process.env.KIRA_CLAUDE_BIN = config.claudeBin
43
54
  if (!URL_ || !TOKEN) {
44
- console.error('No token. Run: npx kira-glasses-bridge --token <token> (from the Kira portal → Connections → Claude Code)')
45
- process.exit(1)
55
+ throw new Error('No token. Run: npx kira-glasses-bridge --token <token> (from the Kira portal → Connections → Claude Code)')
46
56
  }
57
+ stopped = false
47
58
  log(`kira-bridge ${BRIDGE_VERSION} · agents: ${Object.keys(AGENTS).join(', ')}`)
48
59
  connect()
49
60
  }
50
61
 
62
+ /** Disconnect and stop reconnecting (the app calls this on sign-out or a token change). */
63
+ export function stopBridge() {
64
+ stopped = true
65
+ clearTimeout(reconnectTimer)
66
+ const ws = live
67
+ live = null
68
+ try {
69
+ ws?.close(1000, 'stopped')
70
+ } catch {
71
+ /* already closed */
72
+ }
73
+ status('disconnected')
74
+ }
75
+
76
+ export const bridgeVersion = BRIDGE_VERSION
77
+
78
+ function status(s) {
79
+ hooks.onStatus?.(s)
80
+ }
81
+
51
82
  const tools = {
52
83
  async list_files(args) {
53
84
  return listFiles(args)
@@ -196,6 +227,22 @@ end tell`
196
227
  return { repo: await repoOfFolder(args.path) }
197
228
  },
198
229
 
230
+ /** Which Claude account Claude Code on this Mac is signed in to (`claude auth status --json`). */
231
+ async claude_account() {
232
+ const { execFile } = await import('node:child_process')
233
+ const bin = process.env.KIRA_CLAUDE_BIN || 'claude'
234
+ return new Promise(resolve =>
235
+ execFile(bin, ['auth', 'status', '--json'], { timeout: 10_000 }, (err, stdout) => {
236
+ try {
237
+ const s = JSON.parse(stdout)
238
+ resolve({ loggedIn: !!s.loggedIn, email: s.email ?? null, plan: s.subscriptionType ?? null, org: s.orgName ?? null, method: s.authMethod ?? null })
239
+ } catch {
240
+ resolve({ error: err?.code === 'ENOENT' ? 'Claude Code is not installed on this Mac' : 'Claude Code did not say which account it uses' })
241
+ }
242
+ }),
243
+ )
244
+ },
245
+
199
246
  /** Read-only git facts for a folder: repo, branch, head, dirty files. */
200
247
  async git_status(args) {
201
248
  const s = await snapshot(resolveCwd(args.path ?? args.cwd))
@@ -227,6 +274,8 @@ async function withChange(pathArg, fn) {
227
274
 
228
275
  let backoff = 1000
229
276
  function connect() {
277
+ if (stopped) return
278
+ status('connecting')
230
279
  const ws = new WebSocket(`${URL_}?token=${encodeURIComponent(TOKEN)}`)
231
280
  let ping
232
281
  ws.on('open', () => {
@@ -251,6 +300,7 @@ function connect() {
251
300
  log(`sending ${outbox.length} queued job messages`)
252
301
  for (const o of outbox.splice(0)) ws.send(JSON.stringify(o))
253
302
  }
303
+ status('connected')
254
304
  return log(`registered as bridge ${msg.bridgeId} (${Object.keys(tools).length} tools)`)
255
305
  }
256
306
  if (msg.type === 'job.answer') {
@@ -277,10 +327,14 @@ function connect() {
277
327
  if (live === ws) live = null
278
328
  if (code === 4001) {
279
329
  log('token rejected; create a new one in the portal')
280
- process.exit(1)
330
+ status('rejected')
331
+ if (!hooks.onStatus) process.exit(1) // the CLI's behavior; an app decides for itself
332
+ return
281
333
  }
334
+ if (stopped) return
335
+ status('disconnected')
282
336
  log(`disconnected (${code} ${reason}); retrying in ${backoff / 1000}s`)
283
- setTimeout(connect, backoff)
337
+ reconnectTimer = setTimeout(connect, backoff)
284
338
  backoff = Math.min(backoff * 2, 30_000)
285
339
  })
286
340
  ws.on('error', err => log(`socket error: ${err.message}`))
@@ -290,6 +344,8 @@ function send(ws, obj) {
290
344
  if (ws.readyState === WebSocket.OPEN) ws.send(JSON.stringify(obj))
291
345
  }
292
346
  function log(m) {
293
- console.log(`[kira-bridge ${new Date().toLocaleTimeString()}] ${m}`)
347
+ const line = `[kira-bridge ${new Date().toLocaleTimeString()}] ${m}`
348
+ if (hooks.log) hooks.log(line)
349
+ else console.log(line)
294
350
  }
295
351