chorus-cli 0.4.7 → 0.4.8

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/index.js CHANGED
@@ -6,7 +6,6 @@ const _configEnv = _path.join(_configDir, '.env');
6
6
  const _localEnv = _path.join(__dirname, '.env');
7
7
  // Prefer user config dir (works when installed globally), fall back to local .env for dev
8
8
  require('dotenv').config({ path: require('fs').existsSync(_configEnv) ? _configEnv : _localEnv });
9
- const { Octokit } = require('@octokit/rest');
10
9
 
11
10
  const { createProvider } = require('./providers');
12
11
  const OpenAI = require('openai');
@@ -29,16 +28,16 @@ async function getMachineId() {
29
28
  const { stdout } = await execPromise(
30
29
  "ioreg -rd1 -c IOPlatformExpertDevice | awk -F'\"' '/IOPlatformUUID/{print $4}'"
31
30
  );
32
- if (stdout.trim()) rawId = stdout.trim();
31
+ if (stdout.trim()) {rawId = stdout.trim();}
33
32
  } else if (process.platform === 'linux') {
34
33
  const id = (await fs.readFile('/etc/machine-id', 'utf8')).trim();
35
- if (id) rawId = id;
34
+ if (id) {rawId = id;}
36
35
  } else if (process.platform === 'win32') {
37
36
  const { stdout } = await execPromise('wmic csproduct get UUID');
38
37
  const lines = stdout.trim().split('\n');
39
38
  if (lines.length > 1) {
40
39
  const uuid = lines[1].trim();
41
- if (uuid && uuid !== 'FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF') rawId = uuid;
40
+ if (uuid && uuid !== 'FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF') {rawId = uuid;}
42
41
  }
43
42
  }
44
43
  } catch { /* fall through to persistent fallback */ }
@@ -49,7 +48,7 @@ async function getMachineId() {
49
48
  const idPath = path.join(configDir, 'machine-id');
50
49
  try {
51
50
  const existing = await fs.readFile(idPath, 'utf8');
52
- if (existing.trim()) rawId = existing.trim();
51
+ if (existing.trim()) {rawId = existing.trim();}
53
52
  } catch { /* no file yet */ }
54
53
 
55
54
  if (!rawId) {
@@ -77,7 +76,7 @@ function runCoder(prompt) {
77
76
  cwd: process.cwd(),
78
77
  env,
79
78
  stdio: ['ignore', 'pipe', 'pipe'],
80
- timeout: 600000,
79
+ timeout: 600000
81
80
  });
82
81
 
83
82
  let stdout = '';
@@ -110,14 +109,14 @@ function runQAChat(issue, enrichedDetails, qaName, useSuper = false) {
110
109
  issue_number: issue.number,
111
110
  issue_title: issue.title,
112
111
  issue_body: issue.body || '',
113
- enriched_questions: enrichedDetails,
112
+ enriched_questions: enrichedDetails
114
113
  });
115
114
 
116
- const args = ['--messenger', CONFIG.messenger, '--qa', qaName];
115
+ const args = ['--messenger', CONFIG.messenger, '--qa', qaName?.login];
117
116
  if (CONFIG.messenger === 'teams') {
118
117
  args.push('--auth', CONFIG.teams.authPath);
119
118
  }
120
- if (useSuper) args.push('--super');
119
+ if (useSuper) {args.push('--super');}
121
120
 
122
121
  const env = { ...process.env };
123
122
  if (CONFIG.ai.chorusApiKey) {
@@ -134,7 +133,7 @@ function runQAChat(issue, enrichedDetails, qaName, useSuper = false) {
134
133
  cwd: process.cwd(),
135
134
  env,
136
135
  stdio: ['pipe', 'pipe', 'pipe'],
137
- timeout: 1800000, // 30 min
136
+ timeout: 1800000 // 30 min
138
137
  });
139
138
 
140
139
  let stdout = '';
@@ -168,13 +167,13 @@ const CONFIG = {
168
167
  github: {
169
168
  owner: process.env.GITHUB_OWNER,
170
169
  repo: process.env.GITHUB_REPO,
171
- token: process.env.GITHUB_TOKEN,
170
+ token: process.env.GITHUB_TOKEN
172
171
  },
173
172
  azuredevops: {
174
173
  org: process.env.AZDO_ORG,
175
174
  project: process.env.AZDO_PROJECT,
176
175
  repo: process.env.AZDO_REPO,
177
- pat: process.env.AZDO_PAT,
176
+ pat: process.env.AZDO_PAT
178
177
  },
179
178
  messenger: process.env.MESSENGER || 'teams',
180
179
  teams: {
@@ -182,11 +181,11 @@ const CONFIG = {
182
181
  pollInterval: 60000 // Check for response every 60 seconds
183
182
  },
184
183
  slack: {
185
- botToken: process.env.SLACK_BOT_TOKEN || '',
184
+ botToken: process.env.SLACK_BOT_TOKEN || ''
186
185
  },
187
186
  ai: {
188
- enrichmentTool: 'claude', // 'claude' or 'kimi'
189
- codingTool: 'coder', // 'coder', 'claude', or 'kimi'
187
+ enrichmentTool: 'claude', // 'claude' or 'kimi'
188
+ codingTool: 'coder', // 'coder', 'claude', or 'kimi'
190
189
  coderPath: path.join(__dirname, 'tools', 'coder.py'),
191
190
  qaPath: path.join(__dirname, 'tools', 'qa.py'),
192
191
  mapperPath: path.join(__dirname, 'tools', 'mapper.py'),
@@ -194,7 +193,7 @@ const CONFIG = {
194
193
  ? path.join(os.homedir(), '.config', 'chorus', '.venv', 'Scripts', 'python.exe')
195
194
  : path.join(os.homedir(), '.config', 'chorus', '.venv', 'bin', 'python'),
196
195
  chorusApiKey: process.env.CHORUS_API_KEY,
197
- chorusApiUrl: process.env.CHORUS_API_URL || 'https://chorus-bad0f.web.app/v1',
196
+ chorusApiUrl: process.env.CHORUS_API_URL || 'https://chorus-bad0f.web.app/v1'
198
197
  }
199
198
  };
200
199
 
@@ -236,9 +235,9 @@ Thanks!
236
235
  IMPORTANT: Output ONLY the message above. Do not include any preamble, thinking process, or explanations. Start directly with "Hi! I need clarification..."`;
237
236
 
238
237
  console.log('🤖 Enriching issue with AI...');
239
-
238
+
240
239
  const tool = CONFIG.ai.enrichmentTool;
241
-
240
+
242
241
  if (tool === 'claude') {
243
242
  // Use Chorus proxy API
244
243
  if (!CONFIG.ai.chorusApiKey) {
@@ -246,13 +245,13 @@ IMPORTANT: Output ONLY the message above. Do not include any preamble, thinking
246
245
  }
247
246
  const openaiOpts = {
248
247
  apiKey: CONFIG.ai.chorusApiKey,
249
- baseURL: CONFIG.ai.chorusApiUrl,
248
+ baseURL: CONFIG.ai.chorusApiUrl
250
249
  };
251
250
  if (CONFIG.ai.machineId) {
252
251
  openaiOpts.defaultHeaders = { 'X-Machine-Id': CONFIG.ai.machineId };
253
252
  }
254
253
  const openai = new OpenAI(openaiOpts);
255
-
254
+
256
255
  const response = await openai.chat.completions.create({
257
256
  model: 'anthropic/claude-opus-4',
258
257
  max_tokens: 2000,
@@ -269,12 +268,12 @@ IMPORTANT: Output ONLY the message above. Do not include any preamble, thinking
269
268
  }
270
269
 
271
270
  return response.choices[0].message.content.trim();
272
- } else {
273
- // Use Kimi CLI
274
- const escapedPrompt = prompt.replace(/"/g, '\\"').replace(/\$/g, '\\$');
275
- const { stdout } = await execPromise(`kimi --prompt "${escapedPrompt}"`);
276
- return stdout.trim();
277
271
  }
272
+ // Use Kimi CLI
273
+ const escapedPrompt = prompt.replace(/"/g, '\\"').replace(/\$/g, '\\$');
274
+ const { stdout } = await execPromise(`kimi --prompt "${escapedPrompt}"`);
275
+ return stdout.trim();
276
+
278
277
  }
279
278
 
280
279
  // ===== CODE GENERATION =====
@@ -396,10 +395,10 @@ async function getCodeRabbitReview(solution, issue, provider) {
396
395
  );
397
396
 
398
397
  // 5. Clean up — undo the commit so changes stay in working tree, then go back to main
399
- await execPromise(`git reset --mixed HEAD~1`); // undo commit, keep changes in working tree
400
- await execPromise(`git stash`); // stash working tree changes
398
+ await execPromise(`git reset --mixed HEAD~1`); // undo commit, keep changes in working tree
399
+ await execPromise(`git stash`); // stash working tree changes
401
400
  await execPromise(`git checkout main`);
402
- await execPromise(`git stash pop`); // restore coder's changes on main
401
+ await execPromise(`git stash pop`); // restore coder's changes on main
403
402
  await execPromise(`git branch -D ${branchName}`).catch(() => {});
404
403
 
405
404
  return {
@@ -489,7 +488,7 @@ async function lintAndFix(solution, provider) {
489
488
  console.log(' Auto-fix applied');
490
489
  } catch (e) {
491
490
  // eslint exits non-zero when there are unfixable errors — that's expected
492
- if (e.stdout) console.log(e.stdout);
491
+ if (e.stdout) {console.log(e.stdout);}
493
492
  }
494
493
 
495
494
  // Second pass: check for remaining errors
@@ -525,7 +524,7 @@ ${lintOutput.slice(0, 5000)}`;
525
524
 
526
525
  // Update solution with any new files coder touched
527
526
  for (const f of (fixResult.files_modified || [])) {
528
- if (!solution.files_modified.includes(f)) solution.files_modified.push(f);
527
+ if (!solution.files_modified.includes(f)) {solution.files_modified.push(f);}
529
528
  }
530
529
 
531
530
  console.log(' Lint fix pass complete\n');
@@ -585,12 +584,12 @@ async function processTicket(issueArg, { useSuper = false, skipQA = false, qaNam
585
584
  if (gitStatus.trim()) {
586
585
  console.error('⚠️ Working directory has uncommitted changes. Commit or stash first:');
587
586
  console.error(gitStatus);
588
- //throw new Error('Dirty working directory');
587
+ // throw new Error('Dirty working directory');
589
588
  }
590
589
  const { stdout: currentBranch } = await execPromise('git rev-parse --abbrev-ref HEAD');
591
590
  if (currentBranch.trim() !== 'main') {
592
591
  console.warn(`⚠️ Not on main branch (currently on ${currentBranch.trim()}). Switch to main first.`);
593
- //throw new Error('Not on main branch');
592
+ // throw new Error('Not on main branch');
594
593
  }
595
594
 
596
595
  // 0b. Map the codebase so coder starts with full context
@@ -629,6 +628,7 @@ async function processTicket(issueArg, { useSuper = false, skipQA = false, qaNam
629
628
  console.log('⏭️ Skipping QA conversation (--skip-qa)\n');
630
629
  } else {
631
630
  const qaName = qaNameOverride || await provider.getUserDisplayName(issue.user.login);
631
+ console.log(JSON.stringify(qaName));
632
632
  console.log(`💬 Starting QA conversation with ${qaName?.login}...`);
633
633
  const qaResult = await runQAChat(issue, enrichedDetails, qaName, useSuper);
634
634
  qaResponse = qaResult.requirements;
@@ -642,8 +642,17 @@ async function processTicket(issueArg, { useSuper = false, skipQA = false, qaNam
642
642
  }
643
643
  console.log(`QA complete (${qaResult.conversation_rounds} rounds)\n`);
644
644
  }
645
-
645
+
646
646
  // 4. Generate code (with retry if coder doesn't actually write files)
647
+ // Snapshot current working-tree state so we can detect what the coder *actually* changed
648
+ let baselineDirty = new Set();
649
+ try {
650
+ const { stdout: bDiff } = await execPromise('git diff --name-only');
651
+ const { stdout: bNew } = await execPromise('git ls-files --others --exclude-standard');
652
+ bDiff.trim().split('\n').filter(Boolean).forEach(f => baselineDirty.add(f));
653
+ bNew.trim().split('\n').filter(Boolean).forEach(f => baselineDirty.add(f));
654
+ } catch { /* non-git or error — baseline stays empty */ }
655
+
647
656
  const maxCodeAttempts = 3;
648
657
  let solution;
649
658
 
@@ -683,7 +692,27 @@ CRITICAL: You MUST write code to actual files. Do not just describe changes —
683
692
  throw new Error('Code generation failed');
684
693
  }
685
694
 
686
- const filesChanged = (solution.files_modified || []).length + (solution.files_created || []).length;
695
+ let filesChanged = (solution.files_modified || []).length + (solution.files_created || []).length;
696
+
697
+ // If coder reports 0 files, check git for actual working-tree changes
698
+ // the coder may have written files without reporting them
699
+ if (filesChanged === 0) {
700
+ try {
701
+ const { stdout: gitDiff } = await execPromise('git diff --name-only');
702
+ const { stdout: gitUntracked } = await execPromise('git ls-files --others --exclude-standard');
703
+ const diffFiles = gitDiff.trim().split('\n').filter(Boolean).filter(f => !baselineDirty.has(f));
704
+ const untrackedFiles = gitUntracked.trim().split('\n').filter(Boolean).filter(f => !baselineDirty.has(f));
705
+ const gitChangedFiles = [...diffFiles, ...untrackedFiles];
706
+
707
+ if (gitChangedFiles.length > 0) {
708
+ console.log(` Coder didn't report files, but git detected ${gitChangedFiles.length} changed file(s)`);
709
+ // Backfill the solution so downstream steps (lint, review, PR) work
710
+ solution.files_modified = [...(solution.files_modified || []), ...diffFiles];
711
+ solution.files_created = [...(solution.files_created || []), ...untrackedFiles];
712
+ filesChanged = gitChangedFiles.length;
713
+ }
714
+ } catch { /* git check failed, fall through to existing logic */ }
715
+ }
687
716
 
688
717
  if (filesChanged > 0) {
689
718
  break; // Success — coder actually wrote files
@@ -698,7 +727,7 @@ CRITICAL: You MUST write code to actual files. Do not just describe changes —
698
727
  }
699
728
 
700
729
  console.log('Code generation complete\n');
701
- if (solution.summary) console.log(`Summary: ${solution.summary}\n`);
730
+ if (solution.summary) {console.log(`Summary: ${solution.summary}\n`);}
702
731
 
703
732
  // 5. Lint files the coder touched
704
733
  await lintAndFix(solution, provider);
@@ -754,11 +783,11 @@ CRITICAL: You MUST write code to actual files. Do not just describe changes —
754
783
  while (userIteration < maxUserIterations) {
755
784
  const allFiles = [...new Set([
756
785
  ...(solution.files_modified || []),
757
- ...(solution.files_created || []),
786
+ ...(solution.files_created || [])
758
787
  ])];
759
788
  console.log('FILES CHANGED:');
760
789
  allFiles.forEach(f => console.log(` ${f}`));
761
- if (solution.summary) console.log(`\nSUMMARY: ${solution.summary}`);
790
+ if (solution.summary) {console.log(`\nSUMMARY: ${solution.summary}`);}
762
791
  console.log();
763
792
 
764
793
  const answer = await prompt(rl, '✅ Happy with the changes? (y/n): ');
@@ -856,7 +885,7 @@ function prompt(rl, question, hidden = false) {
856
885
  } else if (ch === '\u0003') {
857
886
  process.exit();
858
887
  } else if (ch === '\u007F' || ch === '\b') {
859
- if (input.length > 0) input = input.slice(0, -1);
888
+ if (input.length > 0) {input = input.slice(0, -1);}
860
889
  } else {
861
890
  input += ch;
862
891
  }
@@ -888,7 +917,7 @@ async function setupGitHub() {
888
917
  } catch { /* no .env yet */ }
889
918
 
890
919
  const updates = { GITHUB_OWNER: owner, GITHUB_REPO: repo };
891
- if (token) updates.GITHUB_TOKEN = token;
920
+ if (token) {updates.GITHUB_TOKEN = token;}
892
921
 
893
922
  for (const [key, value] of Object.entries(updates)) {
894
923
  const regex = new RegExp(`^${key}=.*$`, 'm');
@@ -904,7 +933,7 @@ async function setupGitHub() {
904
933
  // Update in-memory config
905
934
  CONFIG.github.owner = owner;
906
935
  CONFIG.github.repo = repo;
907
- if (token) CONFIG.github.token = token;
936
+ if (token) {CONFIG.github.token = token;}
908
937
 
909
938
  console.log(`\n✅ GitHub config saved (${owner}/${repo})\n`);
910
939
  }
@@ -940,7 +969,7 @@ async function setupProxyAuth() {
940
969
  const mod = parsed.protocol === 'https:' ? https : http;
941
970
  const req = mod.request(parsed, { method: 'POST', headers: { 'Content-Type': 'application/json' } }, (res) => {
942
971
  let data = '';
943
- res.on('data', (chunk) => data += chunk);
972
+ res.on('data', (chunk) => { data += chunk; });
944
973
  res.on('end', () => {
945
974
  try {
946
975
  resolve({ status: res.statusCode, body: JSON.parse(data) });
@@ -1099,7 +1128,7 @@ async function setupAzureDevOps() {
1099
1128
  } catch { /* no .env yet */ }
1100
1129
 
1101
1130
  const updates = { AZDO_ORG: adoOrg, AZDO_PROJECT: adoProject, AZDO_REPO: adoRepo, PROVIDER: 'azuredevops' };
1102
- if (adoPat) updates.AZDO_PAT = adoPat;
1131
+ if (adoPat) {updates.AZDO_PAT = adoPat;}
1103
1132
 
1104
1133
  for (const [key, value] of Object.entries(updates)) {
1105
1134
  const regex = new RegExp(`^${key}=.*$`, 'm');
@@ -1115,7 +1144,7 @@ async function setupAzureDevOps() {
1115
1144
  CONFIG.azuredevops.org = adoOrg;
1116
1145
  CONFIG.azuredevops.project = adoProject;
1117
1146
  CONFIG.azuredevops.repo = adoRepo;
1118
- if (adoPat) CONFIG.azuredevops.pat = adoPat;
1147
+ if (adoPat) {CONFIG.azuredevops.pat = adoPat;}
1119
1148
 
1120
1149
  console.log(`\n✅ Azure DevOps config saved (${adoOrg}/${adoProject}/${adoRepo})\n`);
1121
1150
  }
@@ -1154,6 +1183,70 @@ async function setup() {
1154
1183
  console.log('\n✅ Setup complete. You can now run: chorus run\n');
1155
1184
  }
1156
1185
 
1186
+ // === EASTER EGG ====
1187
+
1188
+ function printZEP() {
1189
+ const w = 'zep';
1190
+ const size = 9;
1191
+ const thick = 2;
1192
+ const blank = ' '.repeat(w.length);
1193
+
1194
+ // Colors
1195
+ const red = '\x1b[31m';
1196
+ const yellow = '\x1b[33m';
1197
+ const cyan = '\x1b[36m';
1198
+ const bold = '\x1b[1m';
1199
+ const reset = '\x1b[0m';
1200
+
1201
+ // Z
1202
+ const Z = [];
1203
+ for (let i = 0; i < size; i++) {
1204
+ if (i < thick || i >= size - thick) {
1205
+ Z.push(w.repeat(size));
1206
+ } else {
1207
+ const pos = size - 1 - i;
1208
+ Z.push(blank.repeat(pos) + w.repeat(thick) + blank.repeat(Math.max(0, size - pos - thick)));
1209
+ }
1210
+ }
1211
+
1212
+ // E
1213
+ const E = [];
1214
+ for (let i = 0; i < size; i++) {
1215
+ if (i < thick || i >= size - thick || (i >= Math.floor(size / 2) - Math.floor(thick / 2) && i < Math.floor(size / 2) + thick - Math.floor(thick / 2))) {
1216
+ E.push(w.repeat(size));
1217
+ } else {
1218
+ E.push(w.repeat(thick) + blank.repeat(size - thick));
1219
+ }
1220
+ }
1221
+
1222
+ // P
1223
+ const P = [];
1224
+ for (let i = 0; i < size; i++) {
1225
+ if (i < thick || (i >= Math.floor(size / 2) - Math.floor(thick / 2) && i < Math.floor(size / 2) + thick - Math.floor(thick / 2))) {
1226
+ P.push(w.repeat(size));
1227
+ } else if (i < Math.floor(size / 2)) {
1228
+ P.push(w.repeat(thick) + blank.repeat(size - thick * 2) + w.repeat(thick));
1229
+ } else {
1230
+ P.push(w.repeat(thick) + blank.repeat(size - thick));
1231
+ }
1232
+ }
1233
+
1234
+ const gap = ' ';
1235
+
1236
+ console.log('\n\n');
1237
+ for (let i = 0; i < size; i++) {
1238
+ console.log(
1239
+ bold + red + Z[i] + reset +
1240
+ gap +
1241
+ bold + yellow + E[i] + reset +
1242
+ gap +
1243
+ bold + cyan + P[i] + reset
1244
+ );
1245
+ }
1246
+ console.log('\n\n');
1247
+ }
1248
+
1249
+
1157
1250
  // ===== CLI =====
1158
1251
  const command = process.argv[2];
1159
1252
  const _envExists = require('fs').existsSync(path.join(os.homedir(), '.config', 'chorus', '.env'));
@@ -1190,6 +1283,8 @@ if (command === 'setup') {
1190
1283
  const { issueArg, ...opts } = parseRunArgs();
1191
1284
  processTicket(issueArg, opts).catch(console.error);
1192
1285
  }
1286
+ } else if (command === 'zep') {
1287
+ printZEP()
1193
1288
  } else {
1194
1289
  if (!_envExists) {
1195
1290
  console.log(`
@@ -1210,12 +1305,12 @@ Usage:
1210
1305
  chorus run 4464 - Process specific issue by number
1211
1306
  chorus run <url> - Process issue from full URL (auto-detects provider)
1212
1307
  chorus run 4464 --super - Use Opus 4.6 for QA evaluation
1213
- chorus run 4464 --qa 'John Doe' - Specify QA contact name for chat
1308
+ chorus run 4464 --qa 'John Doe' - Specify QA contact name for chat
1214
1309
  chorus run 4464 --skip-qa - Skip QA conversation, go straight to coding
1215
1310
 
1216
1311
  GitHub examples:
1217
1312
  chorus run 4464
1218
- chorus run https://github.com/shesha-io/shesha-framework/issues/4464
1313
+ chorus run https://github.com/org/repository/issues/4464
1219
1314
 
1220
1315
  Azure DevOps examples:
1221
1316
  chorus run 456
@@ -1238,4 +1333,4 @@ Configuration is stored in ~/.config/chorus/.env
1238
1333
  Run "chorus setup" to configure credentials and messenger auth.
1239
1334
  `);
1240
1335
  }
1241
- }
1336
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chorus-cli",
3
- "version": "0.4.7",
3
+ "version": "0.4.8",
4
4
  "description": "Automated ticket resolution with AI, Teams, and Slack integration",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -15,7 +15,9 @@
15
15
  "scripts": {
16
16
  "postinstall": "node scripts/postinstall.js",
17
17
  "setup": "node index.js setup",
18
- "start": "node index.js run"
18
+ "start": "node index.js run",
19
+ "lint": "eslint .",
20
+ "lint:fix": "eslint . --fix"
19
21
  },
20
22
  "dependencies": {
21
23
  "@octokit/rest": "^20.0.2",
@@ -23,6 +25,9 @@
23
25
  "openai": "^4.0.0",
24
26
  "playwright": "^1.40.0"
25
27
  },
28
+ "devDependencies": {
29
+ "eslint": "^8.56.0"
30
+ },
26
31
  "engines": {
27
32
  "node": ">=18.0.0"
28
33
  }
@@ -22,8 +22,8 @@ function normalize(workItem) {
22
22
  user: {
23
23
  login: fields['System.CreatedBy']?.displayName
24
24
  || fields['System.CreatedBy']?.uniqueName
25
- || 'unknown',
26
- },
25
+ || 'unknown'
26
+ }
27
27
  };
28
28
  }
29
29
 
@@ -37,14 +37,14 @@ function createAzureDevOpsProvider(config) {
37
37
  const encoded = Buffer.from(`:${pat}`).toString('base64');
38
38
  return {
39
39
  Authorization: `Basic ${encoded}`,
40
- 'Content-Type': 'application/json',
40
+ 'Content-Type': 'application/json'
41
41
  };
42
42
  }
43
43
 
44
44
  async function adoFetch(url, options = {}) {
45
45
  const res = await fetch(url, {
46
46
  ...options,
47
- headers: { ...authHeaders(), ...options.headers },
47
+ headers: { ...authHeaders(), ...options.headers }
48
48
  });
49
49
  if (!res.ok) {
50
50
  const text = await res.text();
@@ -59,7 +59,7 @@ function createAzureDevOpsProvider(config) {
59
59
  WHERE [System.AssignedTo] = @me
60
60
  AND [System.State] <> 'Closed'
61
61
  AND [System.State] <> 'Removed'
62
- ORDER BY [System.CreatedDate] DESC`,
62
+ ORDER BY [System.CreatedDate] DESC`
63
63
  };
64
64
 
65
65
  const result = await adoFetch(
@@ -88,7 +88,7 @@ function createAzureDevOpsProvider(config) {
88
88
  }
89
89
 
90
90
  function parseIssueArg(arg) {
91
- if (!arg) return null;
91
+ if (!arg) {return null;}
92
92
 
93
93
  // Full ADO URL: https://dev.azure.com/{org}/{project}/_workitems/edit/{id}
94
94
  const urlMatch = arg.match(
@@ -98,7 +98,7 @@ function createAzureDevOpsProvider(config) {
98
98
  return {
99
99
  org: urlMatch[1],
100
100
  project: urlMatch[2],
101
- number: parseInt(urlMatch[3], 10),
101
+ number: parseInt(urlMatch[3], 10)
102
102
  };
103
103
  }
104
104
 
@@ -142,7 +142,7 @@ function createAzureDevOpsProvider(config) {
142
142
  const cleanPath = filepath.trim();
143
143
  if (cleanPath.includes('/') || cleanPath.includes('.')) {
144
144
  const dir = cleanPath.substring(0, cleanPath.lastIndexOf('/'));
145
- if (dir) await execPromise(`mkdir -p ${dir}`).catch(() => {});
145
+ if (dir) {await execPromise(`mkdir -p ${dir}`).catch(() => {});}
146
146
  await fs.writeFile(cleanPath, content.trim());
147
147
  }
148
148
  }
@@ -176,7 +176,7 @@ function createAzureDevOpsProvider(config) {
176
176
  sourceRefName: `refs/heads/${branchName}`,
177
177
  targetRefName: 'refs/heads/main',
178
178
  title: `Fix: ${issue.title}`,
179
- description: `Resolves AB#${issue.number}\n\n## Summary\n${summary}${filesChanged ? `\n\n## Files Changed\n${filesChanged}` : ''}`,
179
+ description: `Resolves AB#${issue.number}\n\n## Summary\n${summary}${filesChanged ? `\n\n## Files Changed\n${filesChanged}` : ''}`
180
180
  };
181
181
 
182
182
  const prResult = await adoFetch(
@@ -195,7 +195,7 @@ function createAzureDevOpsProvider(config) {
195
195
  parseIssueArg,
196
196
  createPR,
197
197
  getSolutionFiles,
198
- gitAddSolutionFiles,
198
+ gitAddSolutionFiles
199
199
  };
200
200
  }
201
201
 
@@ -22,7 +22,7 @@ function createGitHubProvider(config) {
22
22
  assignee: 'james-baloyi',
23
23
  sort: 'created',
24
24
  direction: 'desc',
25
- per_page: 10,
25
+ per_page: 10
26
26
  });
27
27
 
28
28
  if (issues.length === 0) {
@@ -37,7 +37,7 @@ function createGitHubProvider(config) {
37
37
  const { data: issue } = await octokit.issues.get({
38
38
  owner: issueOwner || owner,
39
39
  repo: issueRepo || repo,
40
- issue_number: number,
40
+ issue_number: number
41
41
  });
42
42
  return issue;
43
43
  }
@@ -49,7 +49,7 @@ function createGitHubProvider(config) {
49
49
  }
50
50
 
51
51
  function parseIssueArg(arg) {
52
- if (!arg) return null;
52
+ if (!arg) {return null;}
53
53
 
54
54
  // Full GitHub URL: https://github.com/owner/repo/issues/123
55
55
  const urlMatch = arg.match(/github\.com\/([^/]+)\/([^/]+)\/issues\/(\d+)/);
@@ -86,7 +86,19 @@ function createGitHubProvider(config) {
86
86
  console.log('🌿 Creating PR...');
87
87
 
88
88
  if (!isCoder) {
89
- await writeSolutionToFiles(solution._raw || solution);
89
+ // Legacy: parse code blocks and write files
90
+ const fileRegex = /```(.+?)\n([\s\S]+?)```/g;
91
+ const raw = solution._raw || solution;
92
+ let match;
93
+ while ((match = fileRegex.exec(raw)) !== null) {
94
+ const [, filepath, content] = match;
95
+ const cleanPath = filepath.trim();
96
+ if (cleanPath.includes('/') || cleanPath.includes('.')) {
97
+ const dir = cleanPath.substring(0, cleanPath.lastIndexOf('/'));
98
+ if (dir) {await execPromise(`mkdir -p ${dir}`).catch(() => {});}
99
+ await fs.writeFile(cleanPath, content.trim());
100
+ }
101
+ }
90
102
  }
91
103
 
92
104
  // Clean up stale branch from previous runs
@@ -137,7 +149,7 @@ ${filesChanged ? `\n## Files Changed\n${filesChanged}` : ''}`;
137
149
  parseIssueArg,
138
150
  createPR,
139
151
  getSolutionFiles,
140
- gitAddSolutionFiles,
152
+ gitAddSolutionFiles
141
153
  };
142
154
  }
143
155
 
@@ -8,9 +8,9 @@ const { createAzureDevOpsProvider } = require('./azuredevops');
8
8
  * Returns 'github', 'azuredevops', or null if undetectable.
9
9
  */
10
10
  function detectProviderFromArg(issueArg) {
11
- if (!issueArg || typeof issueArg !== 'string') return null;
12
- if (issueArg.includes('github.com')) return 'github';
13
- if (issueArg.includes('dev.azure.com')) return 'azuredevops';
11
+ if (!issueArg || typeof issueArg !== 'string') {return null;}
12
+ if (issueArg.includes('github.com')) {return 'github';}
13
+ if (issueArg.includes('dev.azure.com')) {return 'azuredevops';}
14
14
  return null;
15
15
  }
16
16
 
@@ -35,7 +35,7 @@ function createProvider(config, issueArg) {
35
35
  }
36
36
  return createAzureDevOpsProvider({
37
37
  ...config.azuredevops,
38
- codingTool: config.ai.codingTool,
38
+ codingTool: config.ai.codingTool
39
39
  });
40
40
  }
41
41
 
@@ -44,7 +44,7 @@ function createProvider(config, issueArg) {
44
44
  owner: config.github.owner,
45
45
  repo: config.github.repo,
46
46
  token: config.github.token,
47
- codingTool: config.ai.codingTool,
47
+ codingTool: config.ai.codingTool
48
48
  });
49
49
  }
50
50
 
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  'use strict';
3
3
 
4
- const { execFileSync, execSync } = require('child_process');
4
+ const { execFileSync } = require('child_process');
5
5
  const path = require('path');
6
6
  const fs = require('fs');
7
7
 
@@ -25,7 +25,7 @@ function run(cmd, args, opts) {
25
25
  return execFileSync(cmd, args, { stdio: 'inherit', ...opts });
26
26
  } catch (e) {
27
27
  console.error(` Command failed: ${cmd} ${args.join(' ')}`);
28
- if (e.message) console.error(` ${e.message}`);
28
+ if (e.message) {console.error(` ${e.message}`);}
29
29
  return null;
30
30
  }
31
31
  }
@@ -35,7 +35,7 @@ function findPython() {
35
35
  try {
36
36
  const version = execFileSync(candidate, ['--version'], {
37
37
  encoding: 'utf8',
38
- stdio: ['ignore', 'pipe', 'pipe'],
38
+ stdio: ['ignore', 'pipe', 'pipe']
39
39
  }).trim(); // e.g. "Python 3.11.4"
40
40
 
41
41
  const match = version.match(/Python (\d+)\.(\d+)/);
package/tools/coder.py CHANGED
@@ -50,183 +50,8 @@ def is_token_limit_error(err):
50
50
  return "token limit exceeded" in msg or "rate_limit_error" in msg
51
51
 
52
52
 
53
- # ── Shared formatting rules (included in all prompts) ─────────────────────
54
- _FORMAT_RULES = """\
55
- OUTPUT FORMAT
56
-
57
- Your output is displayed raw in a terminal. Never use markdown.
58
- No headings with #, no **bold**, no *italic*, no `backticks`, no [links](url),
59
- no bullet characters like - or *.
60
- Use blank lines and indentation for structure. Use CAPS for section labels.
61
- Use plain numbered lists (1. 2. 3.) when listing things.
62
- Refer to code identifiers by name directly (e.g. myFunction not `myFunction`).
63
- No greetings, preambles, encouragement, or sign-offs.
64
- No "Great question!", "Let me", "Sure!", "I'll now", or similar filler.
65
- State what you are doing, then do it. After completing work, state what changed."""
66
-
67
- # ── Phase 1: Planning prompt (used once at the start of headless mode) ────
68
- PLAN_PROMPT = """\
69
- You are a coding agent. You receive a GitHub/Azure DevOps issue, a codebase map, \
70
- and optionally a QA conversation with clarified requirements. Your job is to \
71
- plan the implementation.
72
-
73
- Working directory: {cwd}
74
-
75
- """ + _FORMAT_RULES + """
76
-
77
-
78
- TASK
79
-
80
- Read the issue, QA conversation (if provided), and codebase map. Then produce a
81
- written plan with exactly these sections:
82
-
83
- UNDERSTANDING:
84
- What the issue is asking for in one sentence.
85
-
86
- QUESTIONS STILL OPEN:
87
- Anything unresolved from QA. If --skip-qa was used, list assumptions you are making
88
- and flag them clearly. Prefer the conservative/conventional choice for each.
89
-
90
- FILES TO READ:
91
- The minimum set of existing files you need to examine to understand the patterns,
92
- interfaces, and conventions. Maximum 8 files. Justify each.
93
-
94
- FILES TO CREATE:
95
- New files with their paths and a one-line description of contents.
96
-
97
- FILES TO MODIFY:
98
- Existing files with a one-line description of what changes.
99
-
100
- APPROACH:
101
- How you will implement this in 2-4 sentences. Reference specific patterns
102
- from the codebase map.
103
-
104
- ON AMBIGUITY
105
-
106
- When requirements are unclear and no QA conversation was provided:
107
- 1. State your assumption explicitly.
108
- 2. Choose the most conventional/standard approach.
109
- 3. Flag it so the reviewer can catch disagreements early.
110
- Do not guess ambitiously. Guess conservatively. A correct simple implementation beats
111
- a broken ambitious one.
112
- """
113
-
114
- # ── Phase 2: Execution prompt (used on every turn of the tool loop) ───────
115
- EXEC_PROMPT = """\
116
- You are a coding agent executing a plan. Implement the changes described in the
117
- plan below. Do not re-plan or re-analyze. Execute.
118
-
119
- Working directory: {cwd}
120
-
121
- """ + _FORMAT_RULES + """
122
-
123
-
124
- TOOL USAGE
125
-
126
- Always use read_file before editing a file.
127
- If edit_file fails with "old_string not found", re-read the file with read_file to
128
- get the actual current content before retrying. Never guess at file contents.
129
- Use edit_file for targeted changes. Use write_file for new files or complete rewrites.
130
- Prefer editing existing files over creating new ones.
131
- Use read_file, list_files, and search_files instead of bash with cat, find, or grep.
132
-
133
- EXECUTION RULES
134
-
135
- Reading files:
136
- Only use read_file on files listed in the plan. If you discover you need another
137
- file, note why -- but if you have read more than 12 files total, stop and
138
- re-evaluate. You are exploring, not implementing.
139
- The one exception to reading a file again: if edit_file fails because old_string
140
- was not found, re-read that file to get its current content before retrying.
141
-
142
- Writing code:
143
- Follow existing patterns exactly. Match the conventions you observed for: naming,
144
- exports, file structure, import ordering, indentation, and comment style.
145
- Write complete files. Do not leave TODOs, placeholders, or "implement this" comments.
146
- If the issue asks for a tool/script, it must work non-interactively (accept arguments
147
- or config, not interactive prompts) unless the issue explicitly requires interactivity.
148
-
149
- Shell commands (bash tool):
150
- You may run bash for: installing dependencies, running the project's existing
151
- linter, running the project's existing tests, checking TypeScript compilation.
152
- You may not run bash for: exploratory searching beyond what was in the plan,
153
- reading files you did not plan to read, testing scripts with improvised piped input.
154
- Maximum 10 bash commands total. If you are approaching this limit, you are doing
155
- too much exploration or too much debugging. Ship what you have.
156
-
157
- BUDGET DISCIPLINE
158
-
159
- Front-load the high-value work. Write the actual implementation code early. File
160
- exploration is not progress -- committed code is progress.
161
-
162
- Do not retry the same failing approach. If something fails twice, choose a different
163
- approach or simplify. Do not iterate more than twice on the same problem.
164
-
165
- If something fundamental is broken, stop. Produce what you have, note what is
166
- incomplete, and let the human finish. A partial, clean implementation is more
167
- valuable than a complete, broken one.
168
-
169
- No yak-shaving. Deliver the core ask. Do not create demo scripts, markdown docs,
170
- bash wrappers, or sample outputs unless the issue asks for them.
171
-
172
- WHAT NOT TO DO
173
-
174
- Do not explore the filesystem to "understand the project." The codebase map and your
175
- plan already cover that. Read specific files for specific reasons.
176
-
177
- Do not overuse list_files, search_files, or bash for exploration. If you need more
178
- than 3 exploratory calls, your plan was insufficient.
179
-
180
- Do not create interactive scripts that require stdin.
181
- Do not create documentation or READMEs unless the issue asks for them.
182
- Do not modify package.json, CI configs, or project infrastructure unless the issue
183
- specifically requires it.
184
- Do not keep going when stuck. After 2 failed attempts at the same problem, note the
185
- issue, deliver what works, and move on.
186
-
187
- WHEN YOU ARE DONE
188
-
189
- End with a verify block:
190
-
191
- 1. List every file you created or modified.
192
- 2. For each, confirm it is syntactically valid (ran linter or compiler if available).
193
- 3. If tests exist for the area you changed, run them and confirm they pass.
194
- 4. If you wrote a script/CLI tool, show the --help output or a dry-run invocation.
195
- 5. Write a summary in this exact format:
196
-
197
- PR_TITLE: conventional commit format (feat:, fix:, chore:, etc.)
198
- PR_BODY: what changed, why, any assumptions made, anything the reviewer should
199
- look at carefully.
200
-
201
- Do not output anything after the summary.
202
- """
203
-
204
- # ── Interactive REPL prompt (conversational, no phased workflow) ──────────
205
- REPL_PROMPT = """\
206
- You are a coding agent running in an interactive terminal session.
207
- Working directory: {cwd}
208
-
209
- """ + _FORMAT_RULES + """
210
-
211
-
212
- TOOL USAGE
213
-
214
- Always use read_file before editing a file.
215
- If edit_file fails with "old_string not found", re-read the file with read_file to
216
- get the actual current content before retrying. Never guess at file contents.
217
- Use edit_file for targeted changes. Use write_file for new files or complete rewrites.
218
- Prefer editing existing files over creating new ones.
219
- Use read_file, list_files, and search_files instead of bash with cat, find, or grep.
220
-
221
- GUIDELINES
222
-
223
- Be direct and concise. State what you will do, then do it.
224
- Always use your tools. Never guess when you can look.
225
- Do not write new unit tests unless the project already has substantive test coverage.
226
- Do not attempt to build or compile the project unless asked.
227
- Do not add unnecessary comments, docstrings, or type annotations.
228
- For bash commands, prefer non-interactive commands.
229
- """
53
+ # System prompts are served by the Chorus proxy (chorus_mode field).
54
+ # The client sends mode + context; the server injects the full prompt.
230
55
 
231
56
  # ── Tool Definitions ────────────────────────────────────────────────────────
232
57
 
@@ -754,21 +579,22 @@ def prune_context(messages, token_budget=None):
754
579
 
755
580
  # ── Streaming Response Handler ──────────────────────────────────────────────
756
581
 
757
- def stream_response(client, messages, system):
582
+ def stream_response(client, messages, chorus_mode, chorus_context):
758
583
  """Stream LLM response via Chorus proxy, handling tool-use loops until done."""
759
- openai_messages = [{"role": "system", "content": system}]
760
- # Convert existing messages to OpenAI format
761
- for msg in messages:
762
- openai_messages.append(msg)
763
-
584
+ openai_messages = list(messages)
585
+
764
586
  while True:
765
587
  printed_text = False
766
-
588
+
767
589
  response = client.chat.completions.create(
768
590
  model=MODEL,
769
591
  max_tokens=MAX_TOKENS,
770
592
  messages=openai_messages,
771
593
  tools=TOOLS,
594
+ extra_body={
595
+ "chorus_mode": chorus_mode,
596
+ "chorus_context": chorus_context,
597
+ },
772
598
  )
773
599
 
774
600
  message = response.choices[0].message
@@ -824,7 +650,7 @@ def stream_response(client, messages, system):
824
650
 
825
651
  # ── Headless Prompt Mode ────────────────────────────────────────────────────
826
652
 
827
- def run_prompt(client, prompt, plan_system, exec_system):
653
+ def run_prompt(client, prompt, chorus_context):
828
654
  """Run a single prompt non-interactively. Returns a JSON-serializable dict."""
829
655
 
830
656
  # PHASE 1: Planning - separate API call with planning prompt
@@ -833,7 +659,6 @@ def run_prompt(client, prompt, plan_system, exec_system):
833
659
 
834
660
  plan_text = ""
835
661
  plan_messages = [
836
- {"role": "system", "content": plan_system},
837
662
  {"role": "user", "content": f"{prompt}\n\nProduce the plan using the exact sections: UNDERSTANDING, QUESTIONS STILL OPEN, FILES TO READ, FILES TO CREATE, FILES TO MODIFY, APPROACH. Do NOT write any code yet."}
838
663
  ]
839
664
 
@@ -842,6 +667,10 @@ def run_prompt(client, prompt, plan_system, exec_system):
842
667
  model=MODEL,
843
668
  max_tokens=MAX_TOKENS,
844
669
  messages=plan_messages,
670
+ extra_body={
671
+ "chorus_mode": "plan",
672
+ "chorus_context": chorus_context,
673
+ },
845
674
  )
846
675
  plan_text = plan_response.choices[0].message.content.strip()
847
676
 
@@ -862,7 +691,6 @@ def run_prompt(client, prompt, plan_system, exec_system):
862
691
  exec_user_content = f"{prompt}\n\nHere is your plan. Follow it.\n\n{plan_text}"
863
692
 
864
693
  messages = [
865
- {"role": "system", "content": exec_system},
866
694
  {"role": "user", "content": exec_user_content}
867
695
  ]
868
696
  files_modified = set()
@@ -886,6 +714,10 @@ def run_prompt(client, prompt, plan_system, exec_system):
886
714
  max_tokens=MAX_TOKENS,
887
715
  messages=messages,
888
716
  tools=TOOLS,
717
+ extra_body={
718
+ "chorus_mode": "exec",
719
+ "chorus_context": chorus_context,
720
+ },
889
721
  )
890
722
  except Exception as e:
891
723
  if is_token_limit_error(e):
@@ -1073,12 +905,15 @@ def main():
1073
905
  except OSError:
1074
906
  pass
1075
907
 
908
+ # Build context for server-side prompt injection
909
+ chorus_context = {"cwd": cwd}
910
+ if map_suffix:
911
+ chorus_context["map"] = map_suffix.strip()
912
+
1076
913
  # ── Headless prompt mode ────────────────────────────────────────────
1077
914
  if args.prompt:
1078
- plan_system = PLAN_PROMPT.format(cwd=cwd) + map_suffix
1079
- exec_system = EXEC_PROMPT.format(cwd=cwd) + map_suffix
1080
915
  try:
1081
- result = run_prompt(client, args.prompt, plan_system, exec_system)
916
+ result = run_prompt(client, args.prompt, chorus_context)
1082
917
  print(json.dumps(result, indent=2))
1083
918
  sys.exit(0 if result["completed"] else 1)
1084
919
  except Exception as e:
@@ -1103,7 +938,6 @@ def main():
1103
938
  sys.exit(130)
1104
939
 
1105
940
  # ── Interactive REPL mode ───────────────────────────────────────────
1106
- system = REPL_PROMPT.format(cwd=cwd) + map_suffix
1107
941
  messages = []
1108
942
 
1109
943
  mode_label = f" {C.YELLOW}(safe mode){C.RESET}" if SAFE_MODE else ""
@@ -1175,7 +1009,7 @@ def main():
1175
1009
 
1176
1010
  try:
1177
1011
  print()
1178
- stream_response(client, messages, system)
1012
+ stream_response(client, messages, "repl", chorus_context)
1179
1013
  print()
1180
1014
  except KeyboardInterrupt:
1181
1015
  del messages[snapshot:]