@memnexus-ai/mx-agent-cli 0.1.1
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/dist/commands/create.d.ts +12 -0
- package/dist/commands/create.d.ts.map +1 -0
- package/dist/commands/create.js +169 -0
- package/dist/commands/create.js.map +1 -0
- package/dist/commands/list.d.ts +7 -0
- package/dist/commands/list.d.ts.map +1 -0
- package/dist/commands/list.js +58 -0
- package/dist/commands/list.js.map +1 -0
- package/dist/commands/start.d.ts +10 -0
- package/dist/commands/start.d.ts.map +1 -0
- package/dist/commands/start.js +93 -0
- package/dist/commands/start.js.map +1 -0
- package/dist/commands/status.d.ts +10 -0
- package/dist/commands/status.d.ts.map +1 -0
- package/dist/commands/status.js +32 -0
- package/dist/commands/status.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +66 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/catalog.d.ts +49 -0
- package/dist/lib/catalog.d.ts.map +1 -0
- package/dist/lib/catalog.js +112 -0
- package/dist/lib/catalog.js.map +1 -0
- package/dist/lib/claude.d.ts +46 -0
- package/dist/lib/claude.d.ts.map +1 -0
- package/dist/lib/claude.js +187 -0
- package/dist/lib/claude.js.map +1 -0
- package/dist/lib/memory.d.ts +52 -0
- package/dist/lib/memory.d.ts.map +1 -0
- package/dist/lib/memory.js +99 -0
- package/dist/lib/memory.js.map +1 -0
- package/dist/lib/worktree.d.ts +36 -0
- package/dist/lib/worktree.d.ts.map +1 -0
- package/dist/lib/worktree.js +209 -0
- package/dist/lib/worktree.js.map +1 -0
- package/package.json +46 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads and writes team catalog entries from mx-agent-system/teams/*.md.
|
|
3
|
+
*/
|
|
4
|
+
import { existsSync, readdirSync, readFileSync, writeFileSync, mkdirSync } from 'fs';
|
|
5
|
+
import { join, basename } from 'path';
|
|
6
|
+
/**
|
|
7
|
+
* Capitalise the first letter of each word.
|
|
8
|
+
*/
|
|
9
|
+
function toTitleCase(str) {
|
|
10
|
+
return str.replace(/\b\w/g, (c) => c.toUpperCase());
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Derive a display name from the slug.
|
|
14
|
+
* e.g. "retrieval" → "Retrieval"
|
|
15
|
+
*/
|
|
16
|
+
export function slugToDisplayName(slug) {
|
|
17
|
+
return toTitleCase(slug.replace(/-/g, ' '));
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Serialise a TeamEntry to markdown (matches the format of pipeline.md).
|
|
21
|
+
*/
|
|
22
|
+
export function serializeTeamEntry(entry) {
|
|
23
|
+
const memoriesList = entry.namedMemories.map((m) => `- \`${m}\``).join('\n');
|
|
24
|
+
return `# Team: ${entry.slug}
|
|
25
|
+
|
|
26
|
+
Display name: ${entry.displayName}
|
|
27
|
+
Roleguide: \`${entry.roleguide}\`
|
|
28
|
+
|
|
29
|
+
## Named Memories (Source of Truth)
|
|
30
|
+
|
|
31
|
+
${memoriesList}
|
|
32
|
+
`;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Parse a team catalog file into a TeamEntry.
|
|
36
|
+
* Returns null if the file cannot be parsed.
|
|
37
|
+
*/
|
|
38
|
+
export function parseTeamEntry(filePath) {
|
|
39
|
+
try {
|
|
40
|
+
const content = readFileSync(filePath, 'utf-8');
|
|
41
|
+
const lines = content.split('\n');
|
|
42
|
+
// slug from filename
|
|
43
|
+
const slug = basename(filePath, '.md');
|
|
44
|
+
// Display name
|
|
45
|
+
const displayNameLine = lines.find((l) => l.startsWith('Display name:'));
|
|
46
|
+
const displayName = displayNameLine ? displayNameLine.replace('Display name:', '').trim() : slugToDisplayName(slug);
|
|
47
|
+
// Roleguide
|
|
48
|
+
const roleguideLineRaw = lines.find((l) => l.startsWith('Roleguide:'));
|
|
49
|
+
let roleguide = `mx-agent-system/roleguides/${slug}-leader.md`;
|
|
50
|
+
if (roleguideLineRaw) {
|
|
51
|
+
const match = roleguideLineRaw.match(/`([^`]+)`/);
|
|
52
|
+
if (match)
|
|
53
|
+
roleguide = match[1];
|
|
54
|
+
}
|
|
55
|
+
// Named memories — lines that look like: - `some-memory-name`
|
|
56
|
+
const namedMemories = [];
|
|
57
|
+
for (const line of lines) {
|
|
58
|
+
const m = line.match(/^-\s+`([^`]+)`\s*$/);
|
|
59
|
+
if (m)
|
|
60
|
+
namedMemories.push(m[1]);
|
|
61
|
+
}
|
|
62
|
+
return { slug, displayName, roleguide, namedMemories };
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Return the path to the teams catalog directory.
|
|
70
|
+
*/
|
|
71
|
+
export function getTeamsCatalogDir(projectRoot) {
|
|
72
|
+
return join(projectRoot, 'mx-agent-system', 'teams');
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Return the path to a specific team's catalog file.
|
|
76
|
+
*/
|
|
77
|
+
export function getTeamCatalogPath(projectRoot, slug) {
|
|
78
|
+
return join(getTeamsCatalogDir(projectRoot), `${slug}.md`);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* List all teams from the catalog directory.
|
|
82
|
+
* Skips README.md.
|
|
83
|
+
*/
|
|
84
|
+
export function listTeams(projectRoot) {
|
|
85
|
+
const dir = getTeamsCatalogDir(projectRoot);
|
|
86
|
+
if (!existsSync(dir))
|
|
87
|
+
return [];
|
|
88
|
+
const files = readdirSync(dir).filter((f) => f.endsWith('.md') && f.toLowerCase() !== 'readme.md');
|
|
89
|
+
return files
|
|
90
|
+
.map((f) => parseTeamEntry(join(dir, f)))
|
|
91
|
+
.filter((e) => e !== null);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Look up a single team entry by slug.
|
|
95
|
+
*/
|
|
96
|
+
export function getTeam(projectRoot, slug) {
|
|
97
|
+
const path = getTeamCatalogPath(projectRoot, slug);
|
|
98
|
+
if (!existsSync(path))
|
|
99
|
+
return null;
|
|
100
|
+
return parseTeamEntry(path);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Write a team catalog entry (creates the file).
|
|
104
|
+
*/
|
|
105
|
+
export function writeTeamCatalog(projectRoot, entry) {
|
|
106
|
+
const dir = getTeamsCatalogDir(projectRoot);
|
|
107
|
+
if (!existsSync(dir))
|
|
108
|
+
mkdirSync(dir, { recursive: true });
|
|
109
|
+
const path = getTeamCatalogPath(projectRoot, entry.slug);
|
|
110
|
+
writeFileSync(path, serializeTeamEntry(entry));
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=catalog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"catalog.js","sourceRoot":"","sources":["../../src/lib/catalog.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AACrF,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAatC;;GAEG;AACH,SAAS,WAAW,CAAC,GAAW;IAC9B,OAAO,GAAG,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;AACtD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC5C,OAAO,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC;AAC9C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAgB;IACjD,MAAM,YAAY,GAAG,KAAK,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CA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BAAkB,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;IACnD,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IACnC,OAAO,cAAc,CAAC,IAAI,CAAC,CAAC;AAC9B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,WAAmB,EAAE,KAAgB;IACpE,MAAM,GAAG,GAAG,kBAAkB,CAAC,WAAW,CAAC,CAAC;IAC5C,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;QAAE,SAAS,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC1D,MAAM,IAAI,GAAG,kBAAkB,CAAC,WAAW,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;IACzD,aAAa,CAAC,IAAI,EAAE,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC;AACjD,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLAUDE.md deployment, CLAUDE.local.md generation, and session start.
|
|
3
|
+
* Mirrors the patterns in dev-tools/worktree-cli/src/operations.ts.
|
|
4
|
+
*/
|
|
5
|
+
export declare function logSuccess(msg: string): void;
|
|
6
|
+
export declare function logWarning(msg: string): void;
|
|
7
|
+
export declare function logDim(msg: string): void;
|
|
8
|
+
/**
|
|
9
|
+
* Deploy CLAUDE.md into the worktree from the template.
|
|
10
|
+
*
|
|
11
|
+
* Template resolution order:
|
|
12
|
+
* 1. dev-tools/worktree-cli/templates/CLAUDE.md.template (synced from origin/main)
|
|
13
|
+
* 2. CLAUDE.md at the project root
|
|
14
|
+
*/
|
|
15
|
+
export declare function deployClaudeMd(projectRoot: string, worktreePath: string): void;
|
|
16
|
+
/**
|
|
17
|
+
* Write CLAUDE.local.md into the worktree with isolation context.
|
|
18
|
+
* Matches the format produced by writeWorktreeClaudeLocal in operations.ts.
|
|
19
|
+
*
|
|
20
|
+
* If the project root has a CLAUDE.local.md, its content is prepended above
|
|
21
|
+
* the worktree isolation rules (same merge behaviour as worktree-cli).
|
|
22
|
+
*/
|
|
23
|
+
export declare function writeClaudeLocal(opts: {
|
|
24
|
+
projectRoot: string;
|
|
25
|
+
worktreePath: string;
|
|
26
|
+
worktreeName: string;
|
|
27
|
+
branch: string | null;
|
|
28
|
+
slot: number;
|
|
29
|
+
}): void;
|
|
30
|
+
/**
|
|
31
|
+
* Sync .claude/settings.json, .claude/hooks/, and the CLAUDE.md template
|
|
32
|
+
* from origin/main into the worktree.
|
|
33
|
+
*/
|
|
34
|
+
export declare function syncClaudeConfig(worktreePath: string): void;
|
|
35
|
+
/**
|
|
36
|
+
* Exec into a Claude session in the worktree with the given initial prompt.
|
|
37
|
+
* Uses spawnSync so Claude replaces the current process cleanly.
|
|
38
|
+
*/
|
|
39
|
+
export declare function launchClaudeSession(opts: {
|
|
40
|
+
worktreePath: string;
|
|
41
|
+
worktreeName: string;
|
|
42
|
+
branch: string | null;
|
|
43
|
+
slot: number;
|
|
44
|
+
initialPrompt: string;
|
|
45
|
+
}): void;
|
|
46
|
+
//# sourceMappingURL=claude.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claude.d.ts","sourceRoot":"","sources":["../../src/lib/claude.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAUH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAE5C;AAED,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAE5C;AAED,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAExC;AAID;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,IAAI,CAqD9E;AAID;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE;IACrC,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;CACd,GAAG,IAAI,CAmDP;AAID;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAgB3D;AAID;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE;IACxC,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,EAAE,MAAM,CAAC;CACvB,GAAG,IAAI,CAgCP"}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLAUDE.md deployment, CLAUDE.local.md generation, and session start.
|
|
3
|
+
* Mirrors the patterns in dev-tools/worktree-cli/src/operations.ts.
|
|
4
|
+
*/
|
|
5
|
+
import { existsSync, readFileSync, writeFileSync } from 'fs';
|
|
6
|
+
import { join } from 'path';
|
|
7
|
+
import { execSync, spawnSync } from 'child_process';
|
|
8
|
+
import chalk from 'chalk';
|
|
9
|
+
// ── Logging helpers ───────────────────────────────────────────────────
|
|
10
|
+
export function logSuccess(msg) {
|
|
11
|
+
console.log(chalk.green(' ✓ ' + msg));
|
|
12
|
+
}
|
|
13
|
+
export function logWarning(msg) {
|
|
14
|
+
console.log(chalk.yellow(' ⚠ ' + msg));
|
|
15
|
+
}
|
|
16
|
+
export function logDim(msg) {
|
|
17
|
+
console.log(chalk.dim(' ' + msg));
|
|
18
|
+
}
|
|
19
|
+
// ── CLAUDE.md deployment ──────────────────────────────────────────────
|
|
20
|
+
/**
|
|
21
|
+
* Deploy CLAUDE.md into the worktree from the template.
|
|
22
|
+
*
|
|
23
|
+
* Template resolution order:
|
|
24
|
+
* 1. dev-tools/worktree-cli/templates/CLAUDE.md.template (synced from origin/main)
|
|
25
|
+
* 2. CLAUDE.md at the project root
|
|
26
|
+
*/
|
|
27
|
+
export function deployClaudeMd(projectRoot, worktreePath) {
|
|
28
|
+
const claudeMdPath = join(worktreePath, 'CLAUDE.md');
|
|
29
|
+
// Handle transition: untrack from git index if still tracked
|
|
30
|
+
try {
|
|
31
|
+
const tracked = execSync('git ls-files CLAUDE.md', {
|
|
32
|
+
cwd: worktreePath,
|
|
33
|
+
encoding: 'utf-8',
|
|
34
|
+
stdio: 'pipe',
|
|
35
|
+
}).trim();
|
|
36
|
+
if (tracked === 'CLAUDE.md') {
|
|
37
|
+
execSync('git rm --cached CLAUDE.md', { cwd: worktreePath, stdio: 'pipe' });
|
|
38
|
+
logDim('Removed CLAUDE.md from git tracking (now template-managed)');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
// Not tracked or error — fine
|
|
43
|
+
}
|
|
44
|
+
// Try synced template path first
|
|
45
|
+
const templatePath = join(projectRoot, 'dev-tools/worktree-cli/templates/CLAUDE.md.template');
|
|
46
|
+
let content = null;
|
|
47
|
+
if (existsSync(templatePath)) {
|
|
48
|
+
try {
|
|
49
|
+
content = readFileSync(templatePath, 'utf-8');
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
// fall through
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
// Fall back to root CLAUDE.md
|
|
56
|
+
if (!content) {
|
|
57
|
+
const rootClaudeMd = join(projectRoot, 'CLAUDE.md');
|
|
58
|
+
if (existsSync(rootClaudeMd)) {
|
|
59
|
+
try {
|
|
60
|
+
content = readFileSync(rootClaudeMd, 'utf-8');
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
// fall through
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (!content) {
|
|
68
|
+
logWarning('Could not find CLAUDE.md template — skipping deployment');
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
try {
|
|
72
|
+
writeFileSync(claudeMdPath, content);
|
|
73
|
+
logSuccess('Deployed CLAUDE.md from template');
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
logWarning('Could not write CLAUDE.md');
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
// ── CLAUDE.local.md generation ────────────────────────────────────────
|
|
80
|
+
/**
|
|
81
|
+
* Write CLAUDE.local.md into the worktree with isolation context.
|
|
82
|
+
* Matches the format produced by writeWorktreeClaudeLocal in operations.ts.
|
|
83
|
+
*
|
|
84
|
+
* If the project root has a CLAUDE.local.md, its content is prepended above
|
|
85
|
+
* the worktree isolation rules (same merge behaviour as worktree-cli).
|
|
86
|
+
*/
|
|
87
|
+
export function writeClaudeLocal(opts) {
|
|
88
|
+
const { projectRoot, worktreePath, worktreeName, branch, slot } = opts;
|
|
89
|
+
const localMdPath = join(worktreePath, 'CLAUDE.local.md');
|
|
90
|
+
// Check if main workspace has a CLAUDE.local.md to merge
|
|
91
|
+
let mainLocalContent = '';
|
|
92
|
+
const mainLocalMdPath = join(projectRoot, 'CLAUDE.local.md');
|
|
93
|
+
if (existsSync(mainLocalMdPath)) {
|
|
94
|
+
try {
|
|
95
|
+
mainLocalContent = readFileSync(mainLocalMdPath, 'utf-8').trim();
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
// ignore
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
const isolationContent = `# Worktree Isolation Context
|
|
102
|
+
|
|
103
|
+
You are working in an isolated worktree. Follow these rules strictly.
|
|
104
|
+
|
|
105
|
+
## Your Environment
|
|
106
|
+
|
|
107
|
+
- **Worktree name:** ${worktreeName}
|
|
108
|
+
- **Worktree path:** ${worktreePath}
|
|
109
|
+
- **Branch:** ${branch || 'unknown'}
|
|
110
|
+
- **Slot:** ${slot}
|
|
111
|
+
|
|
112
|
+
## Critical Rules
|
|
113
|
+
|
|
114
|
+
1. **Stay in your worktree.** Your working directory is \`${worktreePath}\`. All file paths must be relative to or within this directory.
|
|
115
|
+
2. **Never reference \`/workspace\` directly.** That is the main repo. Use your worktree path instead. For example:
|
|
116
|
+
- Wrong: \`cd /workspace/cli\` or \`npm install --prefix /workspace/cli\`
|
|
117
|
+
- Right: \`cd ${worktreePath}/cli\` or \`npm install --prefix ${worktreePath}/cli\`
|
|
118
|
+
3. **Use environment variables** when available: \`$CLAUDE_WORKTREE_PATH\` points to your worktree root.
|
|
119
|
+
4. **Do not switch branches.** Stay on \`${branch || 'your current branch'}\`. Branch switching is blocked.
|
|
120
|
+
5. **Do not merge or push to main.** Create a PR instead using \`gh pr create\`.
|
|
121
|
+
6. **Push to your branch** with \`git push -u origin ${branch || '<your-branch>'}\`.
|
|
122
|
+
|
|
123
|
+
# currentDate
|
|
124
|
+
Today's date is ${new Date().toISOString().slice(0, 10)}.
|
|
125
|
+
`;
|
|
126
|
+
const content = mainLocalContent
|
|
127
|
+
? `${mainLocalContent}\n\n---\n\n${isolationContent}`
|
|
128
|
+
: isolationContent;
|
|
129
|
+
try {
|
|
130
|
+
writeFileSync(localMdPath, content);
|
|
131
|
+
logSuccess('Generated CLAUDE.local.md with worktree context');
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
logWarning('Could not write CLAUDE.local.md');
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
// ── Claude config sync ────────────────────────────────────────────────
|
|
138
|
+
/**
|
|
139
|
+
* Sync .claude/settings.json, .claude/hooks/, and the CLAUDE.md template
|
|
140
|
+
* from origin/main into the worktree.
|
|
141
|
+
*/
|
|
142
|
+
export function syncClaudeConfig(worktreePath) {
|
|
143
|
+
logDim('Syncing Claude config from origin/main...');
|
|
144
|
+
try {
|
|
145
|
+
execSync('git fetch origin main --quiet', { cwd: worktreePath, stdio: 'pipe' });
|
|
146
|
+
execSync('git checkout origin/main -- .claude/settings.json .claude/hooks/ dev-tools/worktree-cli/templates/CLAUDE.md.template', { cwd: worktreePath, stdio: 'pipe' });
|
|
147
|
+
execSync('git reset HEAD -- .claude/settings.json .claude/hooks/ dev-tools/worktree-cli/templates/CLAUDE.md.template', { cwd: worktreePath, stdio: 'pipe' });
|
|
148
|
+
logSuccess('Claude config synced from origin/main');
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
logWarning('Could not sync Claude config from origin/main (continuing with existing config)');
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
// ── Session launch ────────────────────────────────────────────────────
|
|
155
|
+
/**
|
|
156
|
+
* Exec into a Claude session in the worktree with the given initial prompt.
|
|
157
|
+
* Uses spawnSync so Claude replaces the current process cleanly.
|
|
158
|
+
*/
|
|
159
|
+
export function launchClaudeSession(opts) {
|
|
160
|
+
const { worktreePath, worktreeName, branch, slot, initialPrompt } = opts;
|
|
161
|
+
const env = {
|
|
162
|
+
...process.env,
|
|
163
|
+
CLAUDE_WORKTREE_PATH: worktreePath,
|
|
164
|
+
CLAUDE_WORKTREE_NAME: worktreeName,
|
|
165
|
+
CLAUDE_WORKTREE_SLOT: String(slot),
|
|
166
|
+
CLAUDE_WORKTREE_BRANCH: branch || '',
|
|
167
|
+
};
|
|
168
|
+
console.log();
|
|
169
|
+
console.log(chalk.bold(' Starting Claude Code...'));
|
|
170
|
+
console.log(chalk.dim(' Press Ctrl+C to exit'));
|
|
171
|
+
console.log();
|
|
172
|
+
const result = spawnSync('claude', [initialPrompt], {
|
|
173
|
+
cwd: worktreePath,
|
|
174
|
+
env,
|
|
175
|
+
stdio: 'inherit',
|
|
176
|
+
});
|
|
177
|
+
if (result.error) {
|
|
178
|
+
console.error(chalk.red(`Failed to launch claude: ${result.error.message}`));
|
|
179
|
+
process.exit(1);
|
|
180
|
+
}
|
|
181
|
+
// Propagate exit code
|
|
182
|
+
const code = result.status ?? 0;
|
|
183
|
+
if (code !== 0) {
|
|
184
|
+
process.exit(code);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
//# sourceMappingURL=claude.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claude.js","sourceRoot":"","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MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,IAAI,CAAC,CAAC;IAChC,IAAI,IAAI,KAAK,CAAC,EAAE,CAAC;QACf,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACrB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thin wrappers around the mx CLI for team memory initialisation.
|
|
3
|
+
*/
|
|
4
|
+
export declare function isMxAvailable(): boolean;
|
|
5
|
+
export interface CreateNamedMemoryOptions {
|
|
6
|
+
name: string;
|
|
7
|
+
content: string;
|
|
8
|
+
conversationId?: string;
|
|
9
|
+
topics?: string[];
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Create a named memory via the mx CLI.
|
|
13
|
+
* Returns the raw stdout string (may contain the memory ID or error).
|
|
14
|
+
*/
|
|
15
|
+
export declare function createNamedMemory(opts: CreateNamedMemoryOptions): {
|
|
16
|
+
ok: boolean;
|
|
17
|
+
output: string;
|
|
18
|
+
};
|
|
19
|
+
export interface TeamMemoryBootstrapResult {
|
|
20
|
+
leaderState: {
|
|
21
|
+
ok: boolean;
|
|
22
|
+
output: string;
|
|
23
|
+
};
|
|
24
|
+
iterationLog: {
|
|
25
|
+
ok: boolean;
|
|
26
|
+
output: string;
|
|
27
|
+
};
|
|
28
|
+
knownIssues: {
|
|
29
|
+
ok: boolean;
|
|
30
|
+
output: string;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Initialise the three standard named memories for a new team.
|
|
35
|
+
*/
|
|
36
|
+
export declare function bootstrapTeamMemories(teamSlug: string, teamDisplayName: string, roleguide: string): TeamMemoryBootstrapResult;
|
|
37
|
+
/**
|
|
38
|
+
* Log the result of a memory creation step.
|
|
39
|
+
*/
|
|
40
|
+
export declare function logMemoryResult(label: string, result: {
|
|
41
|
+
ok: boolean;
|
|
42
|
+
output: string;
|
|
43
|
+
}): void;
|
|
44
|
+
/**
|
|
45
|
+
* Retrieve a named memory's content via `mx memories get --name <name>`.
|
|
46
|
+
* Returns the raw output string.
|
|
47
|
+
*/
|
|
48
|
+
export declare function getNamedMemory(name: string): {
|
|
49
|
+
ok: boolean;
|
|
50
|
+
output: string;
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=memory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../src/lib/memory.ts"],"names":[],"mappings":"AAAA;;GAEG;AAOH,wBAAgB,aAAa,IAAI,OAAO,CAGvC;AAID,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,wBAAwB,GAAG;IAAE,EAAE,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAsCjG;AAID,MAAM,WAAW,yBAAyB;IACxC,WAAW,EAAE;QAAE,EAAE,EAAE,OAAO,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IAC7C,YAAY,EAAE;QAAE,EAAE,EAAE,OAAO,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IAC9C,WAAW,EAAE;QAAE,EAAE,EAAE,OAAO,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;CAC9C;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,MAAM,EAChB,eAAe,EAAE,MAAM,EACvB,SAAS,EAAE,MAAM,GAChB,yBAAyB,CAiB3B;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE;IAAE,EAAE,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAY5F;AAID;;;GAGG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG;IAAE,EAAE,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAY5E"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thin wrappers around the mx CLI for team memory initialisation.
|
|
3
|
+
*/
|
|
4
|
+
import { spawnSync } from 'child_process';
|
|
5
|
+
import chalk from 'chalk';
|
|
6
|
+
// ── mx availability ───────────────────────────────────────────────────
|
|
7
|
+
export function isMxAvailable() {
|
|
8
|
+
const result = spawnSync('mx', ['--version'], { stdio: 'pipe' });
|
|
9
|
+
return result.status === 0 && !result.error;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Create a named memory via the mx CLI.
|
|
13
|
+
* Returns the raw stdout string (may contain the memory ID or error).
|
|
14
|
+
*/
|
|
15
|
+
export function createNamedMemory(opts) {
|
|
16
|
+
const { name, content, conversationId = 'NEW', topics } = opts;
|
|
17
|
+
const args = [
|
|
18
|
+
'memories',
|
|
19
|
+
'create',
|
|
20
|
+
'--name', name,
|
|
21
|
+
'--conversation-id', conversationId,
|
|
22
|
+
'--content', content,
|
|
23
|
+
];
|
|
24
|
+
if (topics && topics.length > 0) {
|
|
25
|
+
args.push('--topics', topics.join(','));
|
|
26
|
+
}
|
|
27
|
+
const result = spawnSync('mx', args, {
|
|
28
|
+
stdio: 'pipe',
|
|
29
|
+
encoding: 'utf-8',
|
|
30
|
+
});
|
|
31
|
+
const stdout = result.stdout || '';
|
|
32
|
+
const stderr = result.stderr || '';
|
|
33
|
+
const output = stdout + stderr;
|
|
34
|
+
let ok = result.status === 0 && !result.error;
|
|
35
|
+
// mx memories create --name exits non-zero even on success in some versions.
|
|
36
|
+
// Fall back to verifying the memory exists if the command appeared to fail.
|
|
37
|
+
if (!ok) {
|
|
38
|
+
const verify = spawnSync('mx', ['memories', 'get', '--name', name], {
|
|
39
|
+
stdio: 'pipe',
|
|
40
|
+
encoding: 'utf-8',
|
|
41
|
+
});
|
|
42
|
+
if (verify.status === 0 && !verify.error) {
|
|
43
|
+
ok = true;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return { ok, output: output.trim() };
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Initialise the three standard named memories for a new team.
|
|
50
|
+
*/
|
|
51
|
+
export function bootstrapTeamMemories(teamSlug, teamDisplayName, roleguide) {
|
|
52
|
+
const leaderState = createNamedMemory({
|
|
53
|
+
name: `${teamSlug}-leader-state`,
|
|
54
|
+
content: `${teamDisplayName} team leader state — initialized. Roleguide: ${roleguide}. First session: read roleguide, check memories, begin iteration 1.`,
|
|
55
|
+
});
|
|
56
|
+
const iterationLog = createNamedMemory({
|
|
57
|
+
name: `${teamSlug}-iteration-log`,
|
|
58
|
+
content: `${teamDisplayName} iteration log — initialized. No iterations completed yet.`,
|
|
59
|
+
});
|
|
60
|
+
const knownIssues = createNamedMemory({
|
|
61
|
+
name: `${teamSlug}-known-issues`,
|
|
62
|
+
content: `${teamDisplayName} known issues — initialized. No known issues.`,
|
|
63
|
+
});
|
|
64
|
+
return { leaderState, iterationLog, knownIssues };
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Log the result of a memory creation step.
|
|
68
|
+
*/
|
|
69
|
+
export function logMemoryResult(label, result) {
|
|
70
|
+
if (result.ok) {
|
|
71
|
+
console.log(chalk.green(` ✓ ${label}`));
|
|
72
|
+
if (result.output) {
|
|
73
|
+
console.log(chalk.dim(` ${result.output.split('\n')[0]}`));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
console.log(chalk.yellow(` ⚠ ${label} (failed — run manually)`));
|
|
78
|
+
if (result.output) {
|
|
79
|
+
console.log(chalk.dim(` ${result.output.split('\n')[0]}`));
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
// ── Status memory read ────────────────────────────────────────────────
|
|
84
|
+
/**
|
|
85
|
+
* Retrieve a named memory's content via `mx memories get --name <name>`.
|
|
86
|
+
* Returns the raw output string.
|
|
87
|
+
*/
|
|
88
|
+
export function getNamedMemory(name) {
|
|
89
|
+
const result = spawnSync('mx', ['memories', 'get', '--name', name], {
|
|
90
|
+
stdio: 'pipe',
|
|
91
|
+
encoding: 'utf-8',
|
|
92
|
+
});
|
|
93
|
+
const stdout = result.stdout || '';
|
|
94
|
+
const stderr = result.stderr || '';
|
|
95
|
+
const output = stdout + stderr;
|
|
96
|
+
const ok = result.status === 0 && !result.error;
|
|
97
|
+
return { ok, output: output.trim() };
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=memory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.js","sourceRoot":"","sources":["../../src/lib/memory.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,yEAAyE;AAEzE,MAAM,UAAU,aAAa;IAC3B,MAAM,MAAM,GAAG,SAAS,CAAC,IAAI,EAAE,CAAC,WAAW,CAAC,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;IACjE,OAAO,MAAM,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;AAC9C,CAAC;AAWD;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAA8B;IAC9D,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,cAAc,GAAG,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IAE/D,MAAM,IAAI,GAAa;QACrB,UAAU;QACV,QAAQ;QACR,QAAQ,EAAE,IAAI;QACd,mBAAmB,EAAE,cAAc;QACnC,WAAW,EAAE,OAAO;KACrB,CAAC;IAEF,IAAI,MAAM,IAAI,MAAM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CAAC,EAAE;QAClE,KAAK,EAAE,MAAM;QACb,QAAQ,EAAE,OAAO;KAClB,CAAC,CAAC;IAEH,MAAM,MAAM,GAAI,MAAM,CAAC,MAAiB,IAAI,EAAE,CAAC;IAC/C,MAAM,MAAM,GAAI,MAAM,CAAC,MAAiB,IAAI,EAAE,CAAC;IAC/C,MAAM,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;IAC/B,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;IAEhD,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC;AACvC,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Git worktree operations for the agent CLI.
|
|
3
|
+
* Borrowed and simplified from dev-tools/worktree-cli/src/git.ts and config.ts.
|
|
4
|
+
*/
|
|
5
|
+
export declare function findProjectRoot(): string;
|
|
6
|
+
type SlotMap = Record<string, number>;
|
|
7
|
+
export declare function loadSlots(projectRoot: string): SlotMap;
|
|
8
|
+
export declare function assignSlot(projectRoot: string, worktreeName: string, maxWorktrees?: number): number;
|
|
9
|
+
export declare function getSlot(projectRoot: string, worktreeName: string): number | null;
|
|
10
|
+
export declare function getCurrentBranch(cwd: string): string | null;
|
|
11
|
+
export declare function fetchOrigin(cwd: string): void;
|
|
12
|
+
/**
|
|
13
|
+
* Create a git worktree at `worktreePath` on `branch` (branched from `baseBranch`).
|
|
14
|
+
*/
|
|
15
|
+
export declare function createGitWorktree(worktreePath: string, branch: string, baseBranch: string, cwd: string): void;
|
|
16
|
+
/**
|
|
17
|
+
* Add the worktree path to git safe.directory (so git works inside it).
|
|
18
|
+
*/
|
|
19
|
+
export declare function addToGitSafeDirectory(worktreePath: string): void;
|
|
20
|
+
/**
|
|
21
|
+
* Generate a datestamped branch name for a team worktree.
|
|
22
|
+
* e.g. "retrieval" → "worktree/retrieval-20260222"
|
|
23
|
+
*/
|
|
24
|
+
export declare function generateBranchName(teamSlug: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* Generate the worktree directory name.
|
|
27
|
+
* e.g. "retrieval" + "20260222" → "retrieval-20260222"
|
|
28
|
+
*/
|
|
29
|
+
export declare function generateWorktreeDirName(teamSlug: string): string;
|
|
30
|
+
/**
|
|
31
|
+
* Find the worktree directory for a team.
|
|
32
|
+
* Looks for an exact match `<name>` or a prefix match `<name>-*` under .worktrees/.
|
|
33
|
+
*/
|
|
34
|
+
export declare function findWorktreePath(projectRoot: string, teamName: string): string | null;
|
|
35
|
+
export {};
|
|
36
|
+
//# sourceMappingURL=worktree.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worktree.d.ts","sourceRoot":"","sources":["../../src/lib/worktree.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA+BH,wBAAgB,eAAe,IAAI,MAAM,CAuBxC;AAMD,KAAK,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAMtC,wBAAgB,SAAS,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAQtD;AAQD,wBAAgB,UAAU,CAAC,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,YAAY,GAAE,MAAW,GAAG,MAAM,CAavG;AAED,wBAAgB,OAAO,CAAC,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAGhF;AAID,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAU3D;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAM7C;AAeD;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,EAClB,GAAG,EAAE,MAAM,GACV,IAAI,CAWN;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAWhE;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAG3D;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAGhE;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CA4BrF"}
|