Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions scripts/clone-auth.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
import { homedir } from 'node:os'
import { join } from 'node:path'

export const DEMO_TOKEN = 'clone_yc-reviewer-public-demo-2026'
export const AUTH_FILE_NAME = 'auth.local.json'

export function defaultPluginDataDir() {
return join(homedir(), '.claude', 'plugins', 'data', 'clone-clone-labs')
}

export function pluginDataDir(env = process.env) {
const value = String(env.CLAUDE_PLUGIN_DATA || '').trim()
return value || ''
return value || defaultPluginDataDir()
}

export function isPluginDataDirInjected(env = process.env) {
return Boolean(String(env.CLAUDE_PLUGIN_DATA || '').trim())
}

export function authFilePath(env = process.env) {
Expand Down Expand Up @@ -39,10 +48,6 @@ export function writePluginConfigToken(token, env = process.env) {
if (!value) throw new Error('Clone API key must not be empty.')

const dir = pluginDataDir(env)
if (!dir) {
throw new Error('CLAUDE_PLUGIN_DATA is not set, so the plugin config token cannot be stored.')
}

mkdirSync(dir, { recursive: true })
writeFileSync(
authFilePath(env),
Expand Down
7 changes: 4 additions & 3 deletions scripts/manage-api-key.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import {
authFilePath,
clearPluginConfigToken,
isPluginDataDirInjected,
maskToken,
pluginDataDir,
resolveCloneToken,
Expand Down Expand Up @@ -38,11 +39,11 @@ function printResolvedToken(prefix = '') {
console.log(`Source: ${resolved.source}`)
console.log(`Token: ${resolved.masked}`)

const dataDir = pluginDataDir()
if (dataDir) {
const injected = isPluginDataDirInjected()
if (injected) {
console.log(`Plugin config: ${authFilePath()}`)
} else {
console.log('Plugin config: unavailable because CLAUDE_PLUGIN_DATA is not set')
console.log(`Plugin config: ${authFilePath()} (fallback path — CLAUDE_PLUGIN_DATA not injected)`)
}

if (resolved.isDemo) {
Expand Down
8 changes: 3 additions & 5 deletions tests/stop-hook-v2.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,9 @@ function runHook(workdir, endpoint, options = {}) {
delete env.CLONE_API_TOKEN
}
}
if (options.pluginDataDir) {
env.CLAUDE_PLUGIN_DATA = options.pluginDataDir
} else {
delete env.CLAUDE_PLUGIN_DATA
}
// Always set CLAUDE_PLUGIN_DATA to an isolated dir so the fallback path
// doesn't accidentally read tokens stored in the developer's real config.
env.CLAUDE_PLUGIN_DATA = options.pluginDataDir || join(workdir, '.clone-plugin-data')

const child = spawn(process.execPath, [hookPath], {
cwd: workdir,
Expand Down
Loading