Skip to content

Use Garry Tan's exact Claude Code setup: 23 opinionated tools that serve as CEO, Designer, Eng Manager, Release Manager, Doc Engineer, and QA

TypeScript

Label /autoplan approval choices past Z as AA, AB and so on (#4769) (#4798)

Garry Tanafb68ac2b187
diff --git a/changelog.d/gate-choice-labels-past-z.md b/changelog.d/gate-choice-labels-past-z.md
new file mode 100644
index 000000000..35126d16d
--- /dev/null
+++ b/changelog.d/gate-choice-labels-past-z.md
@@ -0,0 +1,3 @@
+### Fixed
+
+- **/autoplan approval asks with more than 26 choices now label them AA, AB and so on instead of punctuation.** The ask lettered its choices one character at a time, so choice 27 became `[`, choice 33 became `a` (the same answer as choice 1, since answers are read in any case), choices 63 to 95 were control characters that don't print, and later ones were stray symbols. Labels now run A to Z and then on like spreadsheet columns (AA, AB, … ZZ, AAA), every one capital letters and none repeated, so a reply like "AA1" names exactly one choice next to "A1". (#4769)
diff --git a/crew/docs/captain.md b/crew/docs/captain.md
index 34dfec79d..ae4db3ed6 100644
--- a/crew/docs/captain.md
+++ b/crew/docs/captain.md
@@ -824,7 +824,8 @@ letters unique across the list.
```
The recommendation is always option 1. "do it" takes every recommendation in the last
-list; a named option ("A2") takes that option instead. `<code>` is the issue, PR or thread
+list; a named option ("A2") takes that option instead. Past Z the letters go on AA, AB
+and so on, like spreadsheet columns, and are read in any case. `<code>` is the issue, PR or thread
the decision is about. An ask that cannot be put this way is not ready to send.
**When the owner has to do something** (create a token, approve a deployment, accept an
diff --git a/lib/captain-brief.ts b/lib/captain-brief.ts
index f030ec223..a4b619eff 100644
--- a/lib/captain-brief.ts
+++ b/lib/captain-brief.ts
@@ -75,6 +75,13 @@ export function buildEli5(planText: string, planFile: string): GateEli5 {
return { summary: body(ELI5_SECTION.aliases), before_after: before!, why: why!, cause: cause!, decisions: decisions!, plan_file_sha256: createHash('sha256').update(planText).digest('hex') };
}
+/** Choice n's label, counting from 0: A to Z, then AA, AB and on like spreadsheet columns, so every label is capital letters and none repeats. */
+export function choiceLabel(n: number): string {
+ let label = '';
+ for (let k = n + 1; k > 0; k = Math.floor((k - 1) / 26)) label = String.fromCharCode(65 + ((k - 1) % 26)) + label;
+ return label;
+}
+
export interface CaptainBrief { text: string; missing: string[]; pending: boolean; recHash: string }
export function renderCaptainBrief(inputs: BriefInputs, o: { outDir: string; captainName?: string }): CaptainBrief {
@@ -119,7 +126,7 @@ export function renderCaptainBrief(inputs: BriefInputs, o: { outDir: string; cap
const summary = eli5?.summary.trim() ? [`### ${ELI5_SECTION.title}`, '', eli5.summary.trim(), ''] : [];
const body = [...summary, ...sections.flatMap(s => [`### ${s.title}`, '', s.found?.body.trim() ? (eli5 ? s.found.body.trim() : capped(s.found.body.trim(), plan.file ?? 'plan.md')) : '_Not written for this plan yet._', ''])];
const need: string[] = ['### What we need from you', ''];
- const letter = (n: number) => String.fromCharCode(65 + n);
+ const letter = choiceLabel;
const ordered = (i: GateItem) => [...i.options.filter(x => x.key === recKey(i)), ...i.options.filter(x => x.key !== recKey(i))];
const example = asked.findIndex(i => i.options.length > 1);
if (!pending) need.push('Nothing. This gate is answered.', '');
diff --git a/test/captain-brief.test.ts b/test/captain-brief.test.ts
index e7f247160..37f3fa15e 100644
--- a/test/captain-brief.test.ts
+++ b/test/captain-brief.test.ts
@@ -9,7 +9,7 @@ import { spawnSync } from 'node:child_process';
import * as fs from 'node:fs';
import * as os from 'node:os';
import * as path from 'node:path';
-import { capyRelayLine, renderCaptainBrief } from '../lib/captain-brief';
+import { capyRelayLine, choiceLabel, renderCaptainBrief } from '../lib/captain-brief';
import { parseReply, recHash, type GateList } from '../lib/gate-list';
import { findSection, headings } from '../lib/markdown-sections';
import { loadBriefInputs } from '../lib/owner-brief';
@@ -248,3 +248,47 @@ describe('carried decisions at a cap gate (#3546)', () => {
expect(briefText).toContain('do it takes the recommendation for each.');
});
});
+
+describe('choice labels past Z (#4769)', () => {
+ function wide(n: number): string {
+ const dir = tmp('cb-wide-');
+ const items = [
+ ...Array.from({ length: n - 1 }, (_, k) => ({ id: `d${k + 1}`, title: `Choice ${k + 1}`, kind: 'auto', recommended: 'a', options: [{ key: 'a', text: 'keep your direction' }, { key: 'b', text: 'accept the change', changes_plan: true }] })),
+ { id: 'p1', title: 'Plan approval', kind: 'approval', recommended: 'a', options: [{ key: 'a', text: 'approve as-is' }, { key: 'e', text: 'reject' }] },
+ ];
+ fs.writeFileSync(path.join(dir, 'gate.json'), JSON.stringify({ schema_version: 1, run: 'run-1', gate_rev: 1, rec_rev: 0, items }));
+ fs.writeFileSync(path.join(dir, 'decisions.jsonl'), items.map(i => JSON.stringify({ schema_version: 1, run: 'run-1', id: `run-1-${i.id}`, label: i.id.toUpperCase(), title: i.title, options: i.options.map(x => x.key), recommended: i.recommended, kind: i.kind, gate_rev: 1, status: 'pending' })).join('\n') + '\n');
+ fs.writeFileSync(path.join(dir, 'findings.jsonl'), '');
+ fs.writeFileSync(path.join(dir, 'plan-active.md'), FULL_PLAN);
+ fs.writeFileSync(path.join(dir, 'run.json'), JSON.stringify({ run: 'run-1', status: 'gate_pending', active_plan: path.join(dir, 'plan-active.md') }));
+ return dir;
+ }
+
+ for (const n of [85, 703]) {
+ test(`${n} choices get ${n} distinct printable labels, A to Z then AA, AB…, and each answer token maps back to one choice in any case`, () => {
+ const { text } = brief(wide(n));
+ const asks = text.split('\n').filter(l => l.startsWith('- ') && l.endsWith('1 to take recommendation.'));
+ const labels = asks.map(l => l.slice(2, l.indexOf(':')));
+ expect(labels.length).toBe(n);
+ expect(labels.every(l => /^[A-Z]+$/.test(l))).toBe(true);
+ expect(new Set(labels.map(l => l.toLowerCase())).size).toBe(n);
+ expect(asks.every((l, k) => l.endsWith(`. ${labels[k]}1 to take recommendation.`))).toBe(true);
+ expect([labels[0], labels[25], labels[26], labels[27], labels[51], labels[52], labels[84]]).toEqual(['A', 'Z', 'AA', 'AB', 'AZ', 'BA', 'CG']);
+ if (n === 703) expect([labels[701], labels[702]]).toEqual(['ZZ', 'AAA']);
+ const map = /letters: ([^;]+);/.exec(text.split('\n---\n')[1]!)![1]!.split(' ').map(p => p.split('='));
+ expect(map.length).toBe(2 * n);
+ expect(new Set(map.map(([k]) => k!.toLowerCase())).size).toBe(2 * n);
+ const answer = (reply: string) => map.filter(([key]) => key!.toLowerCase() === reply.toLowerCase()).map(([, v]) => v);
+ labels.forEach((l, k) => {
+ const id = k === n - 1 ? 'p1' : `d${k + 1}`;
+ const second = k === n - 1 ? 'p1e' : `${id}b`;
+ for (const reply of [`${l}1`, `${l.toLowerCase()}1`]) expect(answer(reply)).toEqual([`${id}a`]);
+ for (const reply of [`${l}2`, `${l.toLowerCase()}2`]) expect(answer(reply)).toEqual([second]);
+ expect(choiceLabel(k)).toBe(l);
+ });
+ expect([answer('A1'), answer('AA1'), answer('aa2'), answer('a1')]).toEqual([['d1a'], ['d27a'], ['d27b'], ['d1a']]);
+ expect(parseReply(`rec except ${answer('AA2')[0]}`, brief(wide(n)).gate).choices.find(c => c.id === 'd27')?.chosen).toBe('b');
+ expect(parseReply('do it', brief(wide(n)).gate).mode).toBe('rec');
+ });
+ }
+});