@rubytech/create-maxy 0.4.7 → 0.4.9

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": "@rubytech/create-maxy",
3
- "version": "0.4.7",
3
+ "version": "0.4.9",
4
4
  "description": "Install Maxy — your personal AI assistant",
5
5
  "bin": {
6
6
  "create-maxy": "./dist/index.js"
@@ -1,6 +1,8 @@
1
1
  import { NextResponse } from 'next/server'
2
2
  import { execFileSync } from 'node:child_process'
3
- import { loginAnthropic, type OAuthCredentials } from '@mariozechner/pi-ai/dist/utils/oauth/anthropic.js'
3
+ import { loginAnthropic } from '@mariozechner/pi-ai/dist/utils/oauth/anthropic.js'
4
+
5
+ type OAuthCredentials = { access: string; refresh: string; expires: number; email?: string }
4
6
  import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'node:fs'
5
7
  import { resolve } from 'node:path'
6
8
  import { homedir } from 'node:os'
@@ -27,6 +29,9 @@ function resetSession(): void {
27
29
  const CLAUDE_CREDS_PATH = resolve(homedir(), '.claude/.credentials.json')
28
30
 
29
31
  function writeClaudeCredentials(creds: OAuthCredentials): void {
32
+ // Store the OAuth credentials in two places:
33
+
34
+ // 1. ~/.claude/.credentials.json (Claude Code's credential file)
30
35
  const claudeDir = resolve(homedir(), '.claude')
31
36
  mkdirSync(claudeDir, { recursive: true })
32
37
 
@@ -45,6 +50,24 @@ function writeClaudeCredentials(creds: OAuthCredentials): void {
45
50
  }
46
51
 
47
52
  writeFileSync(CLAUDE_CREDS_PATH, JSON.stringify(data, null, 2), { mode: 0o600 })
53
+
54
+ // 2. ~/.maxy/.claude-oauth.json (persistent, for refresh + service restart)
55
+ const maxyDir = resolve(homedir(), '.maxy')
56
+ mkdirSync(maxyDir, { recursive: true })
57
+ writeFileSync(
58
+ resolve(maxyDir, '.claude-oauth.json'),
59
+ JSON.stringify({
60
+ accessToken: creds.access,
61
+ refreshToken: creds.refresh,
62
+ expiresAt: creds.expires,
63
+ email: creds.email,
64
+ }, null, 2),
65
+ { mode: 0o600 },
66
+ )
67
+
68
+ // 3. Set the access token as ANTHROPIC_API_KEY in the process environment
69
+ // so the Agent SDK can use it immediately without restarting
70
+ process.env.ANTHROPIC_API_KEY = creds.access
48
71
  }
49
72
 
50
73
  // --- Endpoints ---
@@ -1,10 +1,24 @@
1
1
  import { query, type HookCallback } from "@anthropic-ai/claude-agent-sdk";
2
2
  import { resolve } from "node:path";
3
3
  import { readFileSync, readdirSync, existsSync } from "node:fs";
4
+ import { homedir } from "node:os";
4
5
 
5
6
  const PLATFORM_ROOT = resolve(process.cwd(), "../platform");
6
7
  const ACCOUNTS_DIR = resolve(PLATFORM_ROOT, "config/accounts");
7
8
 
9
+ // Load OAuth token from persistent storage if not already in env
10
+ if (!process.env.ANTHROPIC_API_KEY) {
11
+ const oauthFile = resolve(homedir(), ".maxy/.claude-oauth.json");
12
+ if (existsSync(oauthFile)) {
13
+ try {
14
+ const creds = JSON.parse(readFileSync(oauthFile, "utf-8"));
15
+ if (creds.accessToken) {
16
+ process.env.ANTHROPIC_API_KEY = creds.accessToken;
17
+ }
18
+ } catch { /* ignore */ }
19
+ }
20
+ }
21
+
8
22
  // ---------------------------------------------------------------------------
9
23
  // Account resolution
10
24
  // ---------------------------------------------------------------------------