lazyclaw 6.6.0 → 6.7.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/cli.mjs +5 -0
- package/commands/login.mjs +108 -0
- package/lib/args.mjs +1 -1
- package/mas/index_db.mjs +32 -10
- package/package.json +1 -1
- package/providers/claude_keychain.mjs +40 -0
- package/providers/model_catalogue.mjs +5 -2
package/cli.mjs
CHANGED
|
@@ -403,6 +403,11 @@ async function main() {
|
|
|
403
403
|
await (await import('./commands/config.mjs')).cmdDoctor();
|
|
404
404
|
break;
|
|
405
405
|
}
|
|
406
|
+
case 'login': {
|
|
407
|
+
const code = await (await import('./commands/login.mjs')).cmdLogin(rest.positional, rest.flags);
|
|
408
|
+
if (code) process.exitCode = code;
|
|
409
|
+
break;
|
|
410
|
+
}
|
|
406
411
|
case 'status': {
|
|
407
412
|
await (await import('./commands/config.mjs')).cmdStatus();
|
|
408
413
|
break;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// commands/login.mjs — `lazyclaw login [claude]`.
|
|
2
|
+
//
|
|
3
|
+
// lazyclaw is keyless: chatting via the claude-cli provider spawns the `claude`
|
|
4
|
+
// binary, which carries its own login. But the model-LISTING path makes a
|
|
5
|
+
// direct api.anthropic.com call that needs a bearer, and on macOS the `claude`
|
|
6
|
+
// login lives in the Keychain (no credential file), so listing failed with
|
|
7
|
+
// "set ANTHROPIC_API_KEY or CLAUDE_CODE_OAUTH_TOKEN". This command resolves the
|
|
8
|
+
// credential across env / file / Keychain and, when none is present, mints a
|
|
9
|
+
// long-lived token via `claude setup-token`. The minted token is stored in
|
|
10
|
+
// <config>/.env (0600, gitignored) — the same env path model listing reads.
|
|
11
|
+
|
|
12
|
+
import path from 'node:path';
|
|
13
|
+
import { execFileSync, spawn } from 'node:child_process';
|
|
14
|
+
import { _claudeCodeOAuthToken } from '../providers/model_catalogue.mjs';
|
|
15
|
+
import { readClaudeKeychainToken } from '../providers/claude_keychain.mjs';
|
|
16
|
+
import { writeDotenvMerge } from '../dotenv_min.mjs';
|
|
17
|
+
import { configPath } from '../lib/config.mjs';
|
|
18
|
+
|
|
19
|
+
// Where the claude-cli bearer comes from, in priority order. Pure + injectable.
|
|
20
|
+
export function resolveClaudeAuth({ env = process.env, home, readFileSync, keychainReader } = {}) {
|
|
21
|
+
if (env.CLAUDE_CODE_OAUTH_TOKEN) return { authenticated: true, source: 'env' };
|
|
22
|
+
if (env.ANTHROPIC_API_KEY) return { authenticated: true, source: 'apiKey' };
|
|
23
|
+
// Credential file (Linux / non-keychain) — keychain disabled here so we can
|
|
24
|
+
// distinguish the two sources for the status message.
|
|
25
|
+
const fileTok = _claudeCodeOAuthToken({ home, readFileSync, keychainReader: () => null });
|
|
26
|
+
if (fileTok) return { authenticated: true, source: 'file' };
|
|
27
|
+
const kcTok = (keychainReader || readClaudeKeychainToken)();
|
|
28
|
+
if (kcTok) return { authenticated: true, source: 'keychain' };
|
|
29
|
+
return { authenticated: false, source: 'none' };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function _hasClaudeBinary() {
|
|
33
|
+
try { execFileSync('claude', ['--version'], { stdio: 'ignore', timeout: 4000 }); return true; }
|
|
34
|
+
catch { return false; }
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function _runSetupToken() {
|
|
38
|
+
return new Promise((resolve) => {
|
|
39
|
+
try {
|
|
40
|
+
const p = spawn('claude', ['setup-token'], { stdio: 'inherit' });
|
|
41
|
+
p.on('exit', (code) => resolve(code ?? 1));
|
|
42
|
+
p.on('error', () => resolve(1));
|
|
43
|
+
} catch { resolve(1); }
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const SOURCE_LABEL = {
|
|
48
|
+
env: 'CLAUDE_CODE_OAUTH_TOKEN env var',
|
|
49
|
+
apiKey: 'ANTHROPIC_API_KEY env var',
|
|
50
|
+
file: 'claude credential file (~/.claude)',
|
|
51
|
+
keychain: 'macOS Keychain (your `claude login`)',
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export async function cmdLogin(positional = [], flags = {}, deps = {}) {
|
|
55
|
+
const log = deps.log || ((s) => process.stdout.write(s + '\n'));
|
|
56
|
+
const err = deps.err || ((s) => process.stderr.write(s + '\n'));
|
|
57
|
+
const provider = String(positional[0] || 'claude').toLowerCase();
|
|
58
|
+
if (provider !== 'claude' && provider !== 'claude-cli') {
|
|
59
|
+
err(`login: only 'claude' is supported right now (got "${provider}"). Other providers use their own CLI login.`);
|
|
60
|
+
return 2;
|
|
61
|
+
}
|
|
62
|
+
const cfgDir = deps.cfgDir || path.dirname(configPath());
|
|
63
|
+
const resolve = deps.resolve || resolveClaudeAuth;
|
|
64
|
+
const writeEnv = deps.writeEnv || ((vars) => writeDotenvMerge(cfgDir, vars));
|
|
65
|
+
|
|
66
|
+
// Save a token the user already minted (e.g. via `claude setup-token`).
|
|
67
|
+
if (flags.token) {
|
|
68
|
+
const tok = String(flags.token).trim();
|
|
69
|
+
if (!tok) { err('login: --token was empty'); return 2; }
|
|
70
|
+
writeEnv({ CLAUDE_CODE_OAUTH_TOKEN: tok });
|
|
71
|
+
log('✓ saved CLAUDE_CODE_OAUTH_TOKEN to <config>/.env (0600). claude-cli model listing + recall will use it.');
|
|
72
|
+
return 0;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const status = resolve();
|
|
76
|
+
if (status.authenticated) {
|
|
77
|
+
log(`✓ claude-cli is already authenticated — via ${SOURCE_LABEL[status.source] || status.source}.`);
|
|
78
|
+
log(' Model listing, recall, and the keyless trainer will work. Nothing to do.');
|
|
79
|
+
return 0;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (flags.check) {
|
|
83
|
+
err('✗ no claude-cli credential found (no env token, ~/.claude credential file, or macOS Keychain login).');
|
|
84
|
+
return 1;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const hasClaude = deps.hasClaudeBinary ? deps.hasClaudeBinary() : _hasClaudeBinary();
|
|
88
|
+
if (!hasClaude) {
|
|
89
|
+
err('No claude-cli credential found, and no `claude` binary on PATH.');
|
|
90
|
+
log('Install the Claude CLI and log in:');
|
|
91
|
+
log(' npm i -g @anthropic-ai/claude-code');
|
|
92
|
+
log(' claude login');
|
|
93
|
+
log('Then re-run `lazyclaw login`. (Headless/CI: set CLAUDE_CODE_OAUTH_TOKEN, or `lazyclaw login --token <token>`.)');
|
|
94
|
+
return 1;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
log('No usable credential found. Launching `claude setup-token` to mint a long-lived token…');
|
|
98
|
+
log('(A browser opens for OAuth; the token is printed when it finishes.)\n');
|
|
99
|
+
const code = deps.runSetupToken ? await deps.runSetupToken() : await _runSetupToken();
|
|
100
|
+
if (code !== 0) {
|
|
101
|
+
err('\n`claude setup-token` did not complete. Alternatively run `claude login`, then re-run `lazyclaw login`.');
|
|
102
|
+
return 1;
|
|
103
|
+
}
|
|
104
|
+
log('\nDone. Copy the token printed above, then save it with EITHER:');
|
|
105
|
+
log(' lazyclaw login --token <paste-token> # writes <config>/.env (recommended)');
|
|
106
|
+
log(' export CLAUDE_CODE_OAUTH_TOKEN=<paste-token>');
|
|
107
|
+
return 0;
|
|
108
|
+
}
|
package/lib/args.mjs
CHANGED
|
@@ -10,7 +10,7 @@ export const SUBCOMMANDS = [
|
|
|
10
10
|
'run', 'resume', 'inspect', 'clear', 'validate', 'graph',
|
|
11
11
|
'workflow',
|
|
12
12
|
'config', 'chat', 'agent',
|
|
13
|
-
'doctor', 'status', 'onboard',
|
|
13
|
+
'doctor', 'status', 'onboard', 'login',
|
|
14
14
|
'sessions', 'skills', 'providers',
|
|
15
15
|
'daemon', 'version', 'completion', 'help',
|
|
16
16
|
'export', 'import',
|
package/mas/index_db.mjs
CHANGED
|
@@ -42,6 +42,33 @@ function _logIndexFailure(configDir, scope, err) {
|
|
|
42
42
|
} catch { /* swallow — surface only via console.warn below */ }
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
// The native better-sqlite3 addon fails to load when node_modules was built
|
|
46
|
+
// against a different Node.js ABI than the one running lazyclaw (a Node switch
|
|
47
|
+
// via nvm/brew, or copied node_modules). Every index op then throws the same
|
|
48
|
+
// thing — so instead of dumping the raw stack on each write, recognise it and
|
|
49
|
+
// print ONE actionable hint, then stay quiet. Chat is unaffected; only recall /
|
|
50
|
+
// skill search degrade until the addon is rebuilt.
|
|
51
|
+
let _nativeHintShown = false;
|
|
52
|
+
export function _resetNativeHint() { _nativeHintShown = false; } // test seam
|
|
53
|
+
export function _isNativeAbiError(e) {
|
|
54
|
+
return /NODE_MODULE_VERSION|was compiled against a different Node|better_sqlite3\.node|invalid ELF header|dlopen\(/i
|
|
55
|
+
.test(String(e?.message || e || ''));
|
|
56
|
+
}
|
|
57
|
+
export function _warnIndexFailure(label, e) {
|
|
58
|
+
if (_isNativeAbiError(e)) {
|
|
59
|
+
if (_nativeHintShown) return;
|
|
60
|
+
_nativeHintShown = true;
|
|
61
|
+
// eslint-disable-next-line no-console
|
|
62
|
+
console.warn(
|
|
63
|
+
'[index_db] recall index disabled — better-sqlite3 was built for a different Node.js version.\n' +
|
|
64
|
+
' Re-enable it once with: npm rebuild better-sqlite3 (in the lazyclaw install dir),\n' +
|
|
65
|
+
' or reinstall deps with the Node you run lazyclaw with. Chat is unaffected.');
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
// eslint-disable-next-line no-console
|
|
69
|
+
console.warn(`[index_db] ${label}:`, e.message);
|
|
70
|
+
}
|
|
71
|
+
|
|
45
72
|
function dbPath(configDir) {
|
|
46
73
|
return path.join(configDir, 'index.db');
|
|
47
74
|
}
|
|
@@ -180,8 +207,7 @@ export function indexSessionTurn(row, configDir = defaultConfigDir()) {
|
|
|
180
207
|
);
|
|
181
208
|
} catch (e) {
|
|
182
209
|
_logIndexFailure(configDir, 'sessions', e);
|
|
183
|
-
|
|
184
|
-
console.warn('[index_db] indexSessionTurn failed:', e.message);
|
|
210
|
+
_warnIndexFailure('indexSessionTurn failed', e);
|
|
185
211
|
}
|
|
186
212
|
}
|
|
187
213
|
|
|
@@ -196,8 +222,7 @@ export function indexSkill(row, configDir = defaultConfigDir()) {
|
|
|
196
222
|
);
|
|
197
223
|
} catch (e) {
|
|
198
224
|
_logIndexFailure(configDir, 'skills', e);
|
|
199
|
-
|
|
200
|
-
console.warn('[index_db] indexSkill failed:', e.message);
|
|
225
|
+
_warnIndexFailure('indexSkill failed', e);
|
|
201
226
|
}
|
|
202
227
|
}
|
|
203
228
|
|
|
@@ -212,8 +237,7 @@ export function deleteSkill(skillName, configDir = defaultConfigDir()) {
|
|
|
212
237
|
s.deleteSkill.run(String(skillName || ''));
|
|
213
238
|
} catch (e) {
|
|
214
239
|
_logIndexFailure(configDir, 'skills', e);
|
|
215
|
-
|
|
216
|
-
console.warn('[index_db] deleteSkill failed:', e.message);
|
|
240
|
+
_warnIndexFailure('deleteSkill failed', e);
|
|
217
241
|
}
|
|
218
242
|
}
|
|
219
243
|
|
|
@@ -228,8 +252,7 @@ export function indexTrajectory(row, configDir = defaultConfigDir()) {
|
|
|
228
252
|
);
|
|
229
253
|
} catch (e) {
|
|
230
254
|
_logIndexFailure(configDir, 'trajectories', e);
|
|
231
|
-
|
|
232
|
-
console.warn('[index_db] indexTrajectory failed:', e.message);
|
|
255
|
+
_warnIndexFailure('indexTrajectory failed', e);
|
|
233
256
|
}
|
|
234
257
|
}
|
|
235
258
|
|
|
@@ -243,8 +266,7 @@ export function indexMemory(row, configDir = defaultConfigDir()) {
|
|
|
243
266
|
);
|
|
244
267
|
} catch (e) {
|
|
245
268
|
_logIndexFailure(configDir, 'memories', e);
|
|
246
|
-
|
|
247
|
-
console.warn('[index_db] indexMemory failed:', e.message);
|
|
269
|
+
_warnIndexFailure('indexMemory failed', e);
|
|
248
270
|
}
|
|
249
271
|
}
|
|
250
272
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lazyclaw",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.7.0",
|
|
4
4
|
"description": "Lazy, elegant terminal CLI for chatting with Claude / OpenAI / Gemini / Ollama, orchestrating multi-step LLM workflows, and running multi-agent Slack teams with cross-task memory. Banner-on-launch, slash-command ghost autocomplete, persistent sessions, local HTTP gateway.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"claude",
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// claude_keychain.mjs — read the Claude Code OAuth token from the macOS login
|
|
2
|
+
// Keychain.
|
|
3
|
+
//
|
|
4
|
+
// `claude login` on macOS stores its credential in the OS Keychain (there is no
|
|
5
|
+
// ~/.claude/.credentials.json file like on Linux), so lazyclaw's keyless paths
|
|
6
|
+
// (model listing, trainer detection) couldn't see an existing, working login
|
|
7
|
+
// and fell back to an "authenticate first" error. This reads that Keychain item
|
|
8
|
+
// — the same JSON blob the Linux file holds — and returns its accessToken.
|
|
9
|
+
//
|
|
10
|
+
// Read-only and macOS-only. The token is only ever sent to api.anthropic.com,
|
|
11
|
+
// never logged. The first read may surface a one-time Keychain access prompt;
|
|
12
|
+
// granting it ("Always Allow") makes subsequent reads silent.
|
|
13
|
+
|
|
14
|
+
import { execFileSync } from 'node:child_process';
|
|
15
|
+
|
|
16
|
+
// macOS stores the Claude Code credential under this generic-password service.
|
|
17
|
+
const KEYCHAIN_SERVICE = 'Claude Code-credentials';
|
|
18
|
+
|
|
19
|
+
// Pull the accessToken out of the credential blob (same shape as the Linux
|
|
20
|
+
// ~/.claude/.credentials.json file). Returns a non-empty string or null.
|
|
21
|
+
export function _extractAccessToken(raw) {
|
|
22
|
+
if (!raw || !String(raw).trim()) return null;
|
|
23
|
+
let j;
|
|
24
|
+
try { j = JSON.parse(raw); } catch { return null; }
|
|
25
|
+
const o = (j && j.claudeAiOauth) || j || {};
|
|
26
|
+
const tok = o.accessToken || o.access_token || (j && j.accessToken);
|
|
27
|
+
return (typeof tok === 'string' && tok) ? tok : null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Read the Claude Code OAuth access token from the macOS Keychain. Returns the
|
|
31
|
+
// token string, or null on non-macOS, a missing item, denied access, or an
|
|
32
|
+
// unparseable blob. `exec`/`platform` are injectable for tests.
|
|
33
|
+
export function readClaudeKeychainToken({ platform = process.platform, exec } = {}) {
|
|
34
|
+
if (platform !== 'darwin') return null;
|
|
35
|
+
const run = exec || ((args) => execFileSync('security', args, { encoding: 'utf8', timeout: 8000 }));
|
|
36
|
+
let raw;
|
|
37
|
+
try { raw = run(['find-generic-password', '-s', KEYCHAIN_SERVICE, '-w']); }
|
|
38
|
+
catch { return null; }
|
|
39
|
+
return _extractAccessToken(raw);
|
|
40
|
+
}
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
import fs from 'node:fs';
|
|
15
15
|
import os from 'node:os';
|
|
16
16
|
import path from 'node:path';
|
|
17
|
+
import { readClaudeKeychainToken } from './claude_keychain.mjs';
|
|
17
18
|
|
|
18
19
|
/**
|
|
19
20
|
* Whether a provider exposes a model catalogue we can live-fetch. True for
|
|
@@ -146,7 +147,7 @@ export function modelCatalogueFor({ cfg, registryMod, resolveAuthKey, providerId
|
|
|
146
147
|
// (no file), so this returns null there — the caller falls through to its
|
|
147
148
|
// honest "set ANTHROPIC_API_KEY or CLAUDE_CODE_OAUTH_TOKEN" error. Read-only;
|
|
148
149
|
// the token is only ever sent to api.anthropic.com, never logged.
|
|
149
|
-
export function _claudeCodeOAuthToken({ home, readFileSync } = {}) {
|
|
150
|
+
export function _claudeCodeOAuthToken({ home, readFileSync, keychainReader } = {}) {
|
|
150
151
|
const h = home || os.homedir();
|
|
151
152
|
const read = readFileSync || fs.readFileSync;
|
|
152
153
|
for (const rel of ['.claude/.credentials.json', '.config/claude/.credentials.json']) {
|
|
@@ -156,7 +157,9 @@ export function _claudeCodeOAuthToken({ home, readFileSync } = {}) {
|
|
|
156
157
|
if (typeof tok === 'string' && tok) return tok;
|
|
157
158
|
} catch { /* missing / unreadable / not JSON — try the next location */ }
|
|
158
159
|
}
|
|
159
|
-
|
|
160
|
+
// macOS keeps the login in the Keychain (no file) — read it there.
|
|
161
|
+
const fromKeychain = (keychainReader || readClaudeKeychainToken)();
|
|
162
|
+
return fromKeychain || null;
|
|
160
163
|
}
|
|
161
164
|
|
|
162
165
|
// A plain API key stored by `codex login --api-key` in ~/.codex/auth.json.
|