@synth1s/cloak 1.7.0 → 1.9.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 +1 -1
- package/src/cli.js +6 -0
- package/src/commands/banner.js +18 -0
- package/src/commands/init.js +1 -5
- package/src/commands/list.js +4 -3
- package/src/lib/messages.js +3 -2
- package/src/lib/paths.js +12 -1
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -12,6 +12,7 @@ import { listAccounts } from './commands/list.js'
|
|
|
12
12
|
import { deleteAccount } from './commands/delete.js'
|
|
13
13
|
import { whoami } from './commands/whoami.js'
|
|
14
14
|
import { renameAccount } from './commands/rename.js'
|
|
15
|
+
import { showBanner } from './commands/banner.js'
|
|
15
16
|
import { initShell } from './commands/init.js'
|
|
16
17
|
|
|
17
18
|
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
@@ -58,6 +59,11 @@ program
|
|
|
58
59
|
.description('Rename a cloak')
|
|
59
60
|
.action((oldName, newName) => renameAccount(oldName, newName))
|
|
60
61
|
|
|
62
|
+
program
|
|
63
|
+
.command('banner', { hidden: true })
|
|
64
|
+
.description('Show active cloak banner')
|
|
65
|
+
.action(() => showBanner())
|
|
66
|
+
|
|
61
67
|
program
|
|
62
68
|
.command('init')
|
|
63
69
|
.description('Output shell integration code (use with eval)')
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { getActiveProfile } from '../lib/paths.js'
|
|
2
|
+
|
|
3
|
+
export function showBanner(columns) {
|
|
4
|
+
const name = getActiveProfile()
|
|
5
|
+
if (!name) return
|
|
6
|
+
|
|
7
|
+
const cols = columns || process.stderr.columns || process.stdout.columns || 80
|
|
8
|
+
const msg = `🔹 Wearing cloak "${name}"`
|
|
9
|
+
const inner = cols - 2
|
|
10
|
+
const contentLen = msg.length + 2 // space before and after
|
|
11
|
+
const pad = Math.max(0, inner - contentLen)
|
|
12
|
+
|
|
13
|
+
const top = '╭' + '─'.repeat(inner) + '╮'
|
|
14
|
+
const mid = '│ ' + msg + ' '.repeat(pad) + ' │'
|
|
15
|
+
const bot = '╰' + '─'.repeat(inner) + '╯'
|
|
16
|
+
|
|
17
|
+
process.stdout.write(top + '\n' + mid + '\n' + bot + '\n')
|
|
18
|
+
}
|
package/src/commands/init.js
CHANGED
|
@@ -43,11 +43,7 @@ export function getInitScript() {
|
|
|
43
43
|
' fi',
|
|
44
44
|
' else',
|
|
45
45
|
' if [ -n "$CLAUDE_CONFIG_DIR" ]; then',
|
|
46
|
-
'
|
|
47
|
-
' _cloak_name=$(command cloak whoami 2>/dev/null)',
|
|
48
|
-
' if [ -n "$_cloak_name" ]; then',
|
|
49
|
-
' echo "🔹 Wearing cloak \\"$_cloak_name\\"" >&2',
|
|
50
|
-
' fi',
|
|
46
|
+
' command cloak banner 2>/dev/null >&2',
|
|
51
47
|
' fi',
|
|
52
48
|
' command claude "$@"',
|
|
53
49
|
' fi',
|
package/src/commands/list.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { listProfileNames, getActiveProfile } from '../lib/paths.js'
|
|
1
|
+
import { listProfileNames, getActiveProfile, getAccountEmail } from '../lib/paths.js'
|
|
2
2
|
import * as msg from '../lib/messages.js'
|
|
3
3
|
|
|
4
4
|
export function listAccounts() {
|
|
@@ -8,6 +8,7 @@ export function listAccounts() {
|
|
|
8
8
|
const accounts = names.map(name => ({
|
|
9
9
|
name,
|
|
10
10
|
active: name === active,
|
|
11
|
+
email: getAccountEmail(name),
|
|
11
12
|
}))
|
|
12
13
|
|
|
13
14
|
if (accounts.length === 0) {
|
|
@@ -17,8 +18,8 @@ export function listAccounts() {
|
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
console.log(msg.accountListHeader())
|
|
20
|
-
accounts.forEach(({ name, active: isActive }) => {
|
|
21
|
-
console.log(msg.accountListItem(name, isActive))
|
|
21
|
+
accounts.forEach(({ name, active: isActive, email }) => {
|
|
22
|
+
console.log(msg.accountListItem(name, isActive, email))
|
|
22
23
|
})
|
|
23
24
|
console.log()
|
|
24
25
|
|
package/src/lib/messages.js
CHANGED
|
@@ -98,11 +98,12 @@ export function accountListHeader() {
|
|
|
98
98
|
return chalk.bold('\nYour Cloaks\n')
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
export function accountListItem(name, isActive) {
|
|
101
|
+
export function accountListItem(name, isActive, email) {
|
|
102
102
|
const marker = isActive ? icon.active : icon.inactive
|
|
103
103
|
const label = isActive ? chalk.green.bold(name) : chalk.white(name)
|
|
104
104
|
const tag = isActive ? chalk.green(' (active)') : ''
|
|
105
|
-
|
|
105
|
+
const emailTag = email ? chalk.dim(` — ${email}`) : ''
|
|
106
|
+
return ` ${marker} ${label}${tag}${emailTag}`
|
|
106
107
|
}
|
|
107
108
|
|
|
108
109
|
export function alreadyInstalled(rcFile) {
|
package/src/lib/paths.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { homedir } from 'os'
|
|
2
2
|
import { join, resolve, sep } from 'path'
|
|
3
|
-
import { existsSync, mkdirSync, readdirSync } from 'fs'
|
|
3
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync } from 'fs'
|
|
4
4
|
|
|
5
5
|
function getHome() {
|
|
6
6
|
return process.env.HOME || homedir()
|
|
@@ -67,3 +67,14 @@ export function getActiveProfile() {
|
|
|
67
67
|
const name = resolved.slice(profilesResolved.length + 1).split(sep)[0]
|
|
68
68
|
return name || null
|
|
69
69
|
}
|
|
70
|
+
|
|
71
|
+
export function getAccountEmail(name) {
|
|
72
|
+
try {
|
|
73
|
+
const authFile = profileAuthPath(name)
|
|
74
|
+
if (!existsSync(authFile)) return null
|
|
75
|
+
const data = JSON.parse(readFileSync(authFile, 'utf8'))
|
|
76
|
+
return data?.oauthAccount?.emailAddress || null
|
|
77
|
+
} catch {
|
|
78
|
+
return null
|
|
79
|
+
}
|
|
80
|
+
}
|