backup current stable ejclaw state
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
*
|
||||
* EJClaw is Discord-only, so registrations must target Discord channel IDs.
|
||||
*/
|
||||
import { execFileSync } from 'child_process';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
@@ -12,6 +13,45 @@ import { isValidGroupFolder } from '../src/group-folder.js';
|
||||
import { logger } from '../src/logger.js';
|
||||
import { emitStatus } from './status.js';
|
||||
|
||||
/**
|
||||
* Resolve a usable git-repo work_dir for a new tribunal room.
|
||||
* Order: <folder> if .git exists, else <folder>/repo if .git exists,
|
||||
* else `git init` <folder> (with an empty initial commit) and use it.
|
||||
* Returns the absolute work_dir path.
|
||||
*/
|
||||
function ensureWorkDirForFolder(folderName: string): string {
|
||||
const folderPath = path.join(GROUPS_DIR, folderName);
|
||||
fs.mkdirSync(folderPath, { recursive: true });
|
||||
|
||||
if (fs.existsSync(path.join(folderPath, '.git'))) {
|
||||
return folderPath;
|
||||
}
|
||||
const repoSub = path.join(folderPath, 'repo');
|
||||
if (fs.existsSync(path.join(repoSub, '.git'))) {
|
||||
return repoSub;
|
||||
}
|
||||
|
||||
// No git repo found anywhere — initialize at the folder root.
|
||||
const gitEnv = {
|
||||
...process.env,
|
||||
GIT_AUTHOR_NAME: 'ejclaw',
|
||||
GIT_AUTHOR_EMAIL: 'ejclaw@local',
|
||||
GIT_COMMITTER_NAME: 'ejclaw',
|
||||
GIT_COMMITTER_EMAIL: 'ejclaw@local',
|
||||
};
|
||||
execFileSync('git', ['init', '-q'], { cwd: folderPath, env: gitEnv });
|
||||
execFileSync(
|
||||
'git',
|
||||
['commit', '-q', '--allow-empty', '-m', `init ${folderName} workspace`],
|
||||
{ cwd: folderPath, env: gitEnv },
|
||||
);
|
||||
logger.info(
|
||||
{ folder: folderName, workDir: folderPath },
|
||||
'Initialized git repository for tribunal workspace',
|
||||
);
|
||||
return folderPath;
|
||||
}
|
||||
|
||||
interface RegisterArgs {
|
||||
jid: string;
|
||||
name: string;
|
||||
@@ -102,10 +142,20 @@ export async function run(args: string[]): Promise<void> {
|
||||
logger.info(parsed, 'Registering channel');
|
||||
|
||||
initDatabase();
|
||||
|
||||
// Defaults for newly registered rooms:
|
||||
// roomMode = tribunal, owner = claude-code, reviewer = codex
|
||||
// Tribunal rooms also require a git-backed work_dir; auto-init if missing.
|
||||
const workDir = ensureWorkDirForFolder(parsed.folder);
|
||||
|
||||
assignRoom(parsed.jid, {
|
||||
name: parsed.name,
|
||||
folder: parsed.folder,
|
||||
isMain: parsed.isMain,
|
||||
roomMode: 'tribunal',
|
||||
ownerAgentType: 'claude-code',
|
||||
reviewerAgentType: 'codex',
|
||||
workDir,
|
||||
});
|
||||
logger.info('Assigned room through canonical room service');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user