mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-04-13 05:03:28 +08:00
Compare commits
3 Commits
5fe40f4a63
...
v1.8.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1797e79129 | ||
|
|
1f8b3eaba7 | ||
|
|
d1f44e89e2 |
@@ -144,10 +144,11 @@ function searchSessions(query, dir) {
|
|||||||
const q = String(query || '').toLowerCase().trim();
|
const q = String(query || '').toLowerCase().trim();
|
||||||
if (!q) return [];
|
if (!q) return [];
|
||||||
|
|
||||||
const sessions = listSessions(dir);
|
const sessionDir = dir || getClawDir();
|
||||||
|
const sessions = listSessions(sessionDir);
|
||||||
const results = [];
|
const results = [];
|
||||||
for (const name of sessions) {
|
for (const name of sessions) {
|
||||||
const p = getSessionPath(name);
|
const p = path.join(sessionDir, `${name}.md`);
|
||||||
const content = loadHistory(p);
|
const content = loadHistory(p);
|
||||||
if (!content) continue;
|
if (!content) continue;
|
||||||
|
|
||||||
@@ -212,12 +213,12 @@ function exportSession(filePath, format, outputPath) {
|
|||||||
return { ok: false, message: `Unsupported export format: ${format}` };
|
return { ok: false, message: `Unsupported export format: ${format}` };
|
||||||
}
|
}
|
||||||
|
|
||||||
function branchSession(currentSessionPath, newSessionName) {
|
function branchSession(currentSessionPath, newSessionName, targetDir = getClawDir()) {
|
||||||
if (!isValidSessionName(newSessionName)) {
|
if (!isValidSessionName(newSessionName)) {
|
||||||
return { ok: false, message: `Invalid branch session name: ${newSessionName}` };
|
return { ok: false, message: `Invalid branch session name: ${newSessionName}` };
|
||||||
}
|
}
|
||||||
|
|
||||||
const target = getSessionPath(newSessionName);
|
const target = path.join(targetDir, `${newSessionName}.md`);
|
||||||
fs.mkdirSync(path.dirname(target), { recursive: true });
|
fs.mkdirSync(path.dirname(target), { recursive: true });
|
||||||
|
|
||||||
const content = loadHistory(currentSessionPath);
|
const content = loadHistory(currentSessionPath);
|
||||||
|
|||||||
@@ -100,13 +100,29 @@ function runHookWithInput(scriptPath, input = {}, env = {}, timeoutMs = 10000) {
|
|||||||
function runHookCommand(command, input = {}, env = {}, timeoutMs = 10000) {
|
function runHookCommand(command, input = {}, env = {}, timeoutMs = 10000) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const isWindows = process.platform === 'win32';
|
const isWindows = process.platform === 'win32';
|
||||||
const shell = isWindows ? 'cmd' : 'bash';
|
const mergedEnv = { ...process.env, CLAUDE_PLUGIN_ROOT: REPO_ROOT, ...env };
|
||||||
const shellArgs = isWindows ? ['/d', '/s', '/c', command] : ['-lc', command];
|
const resolvedCommand = command.replace(
|
||||||
|
/\$\{([A-Z_][A-Z0-9_]*)\}/g,
|
||||||
|
(_, name) => String(mergedEnv[name] || '')
|
||||||
|
);
|
||||||
|
|
||||||
const proc = spawn(shell, shellArgs, {
|
const nodeMatch = resolvedCommand.match(/^node\s+"([^"]+)"\s*(.*)$/);
|
||||||
env: { ...process.env, CLAUDE_PLUGIN_ROOT: REPO_ROOT, ...env },
|
const useDirectNodeSpawn = Boolean(nodeMatch);
|
||||||
stdio: ['pipe', 'pipe', 'pipe']
|
const shell = isWindows ? 'cmd' : 'bash';
|
||||||
});
|
const shellArgs = isWindows ? ['/d', '/s', '/c', resolvedCommand] : ['-lc', resolvedCommand];
|
||||||
|
const nodeArgs = nodeMatch
|
||||||
|
? [
|
||||||
|
nodeMatch[1],
|
||||||
|
...Array.from(
|
||||||
|
nodeMatch[2].matchAll(/"([^"]*)"|(\S+)/g),
|
||||||
|
m => m[1] !== undefined ? m[1] : m[2]
|
||||||
|
)
|
||||||
|
]
|
||||||
|
: [];
|
||||||
|
|
||||||
|
const proc = useDirectNodeSpawn
|
||||||
|
? spawn('node', nodeArgs, { env: mergedEnv, stdio: ['pipe', 'pipe', 'pipe'] })
|
||||||
|
: spawn(shell, shellArgs, { env: mergedEnv, stdio: ['pipe', 'pipe', 'pipe'] });
|
||||||
|
|
||||||
let stdout = '';
|
let stdout = '';
|
||||||
let stderr = '';
|
let stderr = '';
|
||||||
|
|||||||
@@ -252,35 +252,31 @@ function runTests() {
|
|||||||
|
|
||||||
if (test('searchSessions finds query in saved session', () => {
|
if (test('searchSessions finds query in saved session', () => {
|
||||||
const tmpDir = makeTmpDir();
|
const tmpDir = makeTmpDir();
|
||||||
const originalHome = process.env.HOME;
|
|
||||||
process.env.HOME = tmpDir;
|
|
||||||
try {
|
try {
|
||||||
const sessionPath = path.join(tmpDir, '.claude', 'claw', 'alpha.md');
|
const clawDir = path.join(tmpDir, '.claude', 'claw');
|
||||||
fs.mkdirSync(path.dirname(sessionPath), { recursive: true });
|
const sessionPath = path.join(clawDir, 'alpha.md');
|
||||||
|
fs.mkdirSync(clawDir, { recursive: true });
|
||||||
appendTurn(sessionPath, 'User', 'Need oauth migration');
|
appendTurn(sessionPath, 'User', 'Need oauth migration');
|
||||||
const results = searchSessions('oauth');
|
const results = searchSessions('oauth', clawDir);
|
||||||
assert.strictEqual(results.length, 1);
|
assert.strictEqual(results.length, 1);
|
||||||
assert.strictEqual(results[0].session, 'alpha');
|
assert.strictEqual(results[0].session, 'alpha');
|
||||||
} finally {
|
} finally {
|
||||||
process.env.HOME = originalHome;
|
|
||||||
fs.rmSync(tmpDir, { recursive: true, force: true });
|
fs.rmSync(tmpDir, { recursive: true, force: true });
|
||||||
}
|
}
|
||||||
})) passed++; else failed++;
|
})) passed++; else failed++;
|
||||||
|
|
||||||
if (test('branchSession copies history into new branch session', () => {
|
if (test('branchSession copies history into new branch session', () => {
|
||||||
const tmpDir = makeTmpDir();
|
const tmpDir = makeTmpDir();
|
||||||
const originalHome = process.env.HOME;
|
|
||||||
process.env.HOME = tmpDir;
|
|
||||||
try {
|
try {
|
||||||
const source = path.join(tmpDir, '.claude', 'claw', 'base.md');
|
const clawDir = path.join(tmpDir, '.claude', 'claw');
|
||||||
fs.mkdirSync(path.dirname(source), { recursive: true });
|
const source = path.join(clawDir, 'base.md');
|
||||||
|
fs.mkdirSync(clawDir, { recursive: true });
|
||||||
appendTurn(source, 'User', 'base content');
|
appendTurn(source, 'User', 'base content');
|
||||||
const result = branchSession(source, 'feature-branch');
|
const result = branchSession(source, 'feature-branch', clawDir);
|
||||||
assert.strictEqual(result.ok, true);
|
assert.strictEqual(result.ok, true);
|
||||||
const branched = fs.readFileSync(result.path, 'utf8');
|
const branched = fs.readFileSync(result.path, 'utf8');
|
||||||
assert.ok(branched.includes('base content'));
|
assert.ok(branched.includes('base content'));
|
||||||
} finally {
|
} finally {
|
||||||
process.env.HOME = originalHome;
|
|
||||||
fs.rmSync(tmpDir, { recursive: true, force: true });
|
fs.rmSync(tmpDir, { recursive: true, force: true });
|
||||||
}
|
}
|
||||||
})) passed++; else failed++;
|
})) passed++; else failed++;
|
||||||
|
|||||||
Reference in New Issue
Block a user