feat: add gh board-row upsert

This commit is contained in:
Codex
2026-05-21 10:25:40 +00:00
parent 2344bcef59
commit 27d0ddff51
3 changed files with 763 additions and 13 deletions
+544 -12
View File
@@ -16,6 +16,7 @@ const COMMANDER_BRIEF_TARGET_ISSUE = 24;
const DEFAULT_BOARD_KNOWN_META_ISSUES = [CODE_QUEUE_BOARD_TARGET_ISSUE, COMMANDER_BRIEF_TARGET_ISSUE] as const;
const BOARD_AUDIT_REQUIRED_COLUMNS = ["branch", "acceptance", "relatedTask", "progress"] as const;
const BOARD_ROW_FIELDS = ["progress", "status", "validation", "branch", "tasks", "focus"] as const;
const BOARD_ROW_UPSERT_TEXT_FIELDS = ["category", "branch", "tasks", "summary", "focus", "validation", "progress"] as const;
const ISSUE_VIEW_JSON_FIELDS = ["body", "title", "state", "comments", "number", "url", "author", "createdAt", "updatedAt"] as const;
const ISSUE_LIST_JSON_FIELDS = ["number", "title", "state", "url", "updatedAt", "createdAt", "author", "labels"] as const;
const PR_JSON_FIELDS = ["body", "title", "state", "number", "url", "author", "head", "base", "draft", "createdAt", "updatedAt"] as const;
@@ -56,8 +57,10 @@ type EscapeBodyKind = "issue-body" | "comment-body";
type CleanupSuggestionAction = "rewrite-issue-body-with-body-file" | "review-comment-manually" | "review-body-length" | "no-cleanup-needed";
type BoardSectionKind = "open" | "closed";
type BoardRequiredColumn = typeof BOARD_AUDIT_REQUIRED_COLUMNS[number];
type BoardColumnKind = BoardRequiredColumn | "focus" | "githubStatus";
type BoardColumnKind = BoardRequiredColumn | "focus" | "githubStatus" | "category" | "summary";
type BoardRowField = typeof BOARD_ROW_FIELDS[number];
type BoardRowUpsertTextField = typeof BOARD_ROW_UPSERT_TEXT_FIELDS[number];
type BoardRowUpsertField = BoardRowUpsertTextField | "status";
type BoardIgnoreReason = "known-meta" | "ignored" | "brief-index-managed";
type GitHubDegradedReason =
@@ -255,6 +258,17 @@ interface BoardRowMutationPlanResult {
newBody: string;
}
interface BoardRowUpsertValues {
category?: string;
branch?: string;
tasks?: string;
summary?: string;
focus?: string;
validation?: string;
progress?: string;
status?: BoardGithubStatus;
}
interface GitHubCommandResult {
ok: boolean;
repo: string;
@@ -305,6 +319,7 @@ interface GitHubOptions {
boardSection?: BoardMutationSection;
boardMoveTo?: BoardMutationSection;
boardGithubStatus?: BoardGithubStatus;
boardRowUpsertValues: BoardRowUpsertValues;
}
interface IssueProfileValidationContext {
@@ -548,8 +563,21 @@ function parseBoardRowField(args: string[]): BoardRowField | undefined {
return validateEnumValue("--field", raw, BOARD_ROW_FIELDS);
}
function parseBoardRowUpsertValues(args: string[]): BoardRowUpsertValues {
return {
category: optionValue(args, "--category"),
branch: optionValue(args, "--branch"),
tasks: optionValue(args, "--tasks"),
summary: optionValue(args, "--summary"),
focus: optionValue(args, "--focus"),
validation: optionValue(args, "--validation"),
progress: optionValue(args, "--progress"),
status: parseBoardGithubStatus(args),
};
}
function validateKnownOptions(args: string[]): void {
const valueOptions = new Set(["--repo", "--limit", "--board-issue", "--known-meta-issue", "--ignore-issue", "--title", "--body-file", "--body", "--base", "--head", "--json", "--state", "--mode", "--expect-updated-at", "--expect-body-sha", "--body-profile", "--label", "--field", "--value", "--section", "--to", "--status", "--row-file"]);
const valueOptions = new Set(["--repo", "--limit", "--board-issue", "--known-meta-issue", "--ignore-issue", "--title", "--body-file", "--body", "--base", "--head", "--json", "--state", "--mode", "--expect-updated-at", "--expect-body-sha", "--body-profile", "--label", "--field", "--value", "--section", "--to", "--status", "--row-file", "--category", "--branch", "--tasks", "--summary", "--focus", "--validation", "--progress"]);
const flagOptions = new Set(["--dry-run", "--draft", "--notify-claudeqq-brief-diff", "--allow-short-body"]);
for (let index = 0; index < args.length; index += 1) {
const arg = args[index];
@@ -597,6 +625,7 @@ function parseOptions(args: string[]): GitHubOptions {
boardSection: parseBoardMutationSection(args, "--section"),
boardMoveTo: parseBoardMutationSection(args, "--to"),
boardGithubStatus: parseBoardGithubStatus(args),
boardRowUpsertValues: parseBoardRowUpsertValues(args),
};
}
@@ -1312,10 +1341,12 @@ function normalizeBoardHeader(header: string): string {
function boardHeaderColumnKind(header: string): BoardColumnKind | null {
const normalized = normalizeBoardHeader(header);
if (["category", "", "", "", ""].includes(normalized)) return "category";
if (["branch", "", "", ""].includes(normalized)) return "branch";
if (["acceptance", "", "", "", ""].includes(normalized)) return "acceptance";
if (["relatedtask", "task", "codequeue", "codequeuetask", "", "", "codequeue任务", "cq任务", "codequeue任务", "codequeuetask"].includes(normalized)) return "relatedTask";
if (["githubstatus", "githubstate", "github状态", "githubissue状态", "issuestate", "issue状态", "issuegithub状态", "", "openclosed", "openclosed状态"].includes(normalized)) return "githubStatus";
if (["summary", "", "", "", "", ""].includes(normalized)) return "summary";
if (["focus", "currentfocus", "", "", "focus"].includes(normalized)) return "focus";
if (["progress", "", "", ""].includes(normalized)) return "progress";
return null;
@@ -1602,6 +1633,25 @@ function boardRowFieldValues(section: BoardTableSection, row: BoardTableRow): Re
};
}
function boardRowUpsertFieldValues(section: BoardTableSection, row: BoardTableRow): Record<BoardRowUpsertField, string | null> {
const columnMap = boardColumnIndexMap(section.headers);
const valueFor = (kind: BoardColumnKind): string | null => {
const index = columnMap.get(kind);
return index === undefined ? null : row.cells[index] ?? "";
};
const acceptance = valueFor("acceptance");
return {
category: valueFor("category"),
branch: valueFor("branch"),
tasks: valueFor("relatedTask"),
summary: valueFor("summary"),
focus: valueFor("focus"),
validation: acceptance,
progress: valueFor("progress"),
status: valueFor("githubStatus"),
};
}
function boardRowSummary(section: BoardTableSection, row: BoardTableRow): Record<string, unknown> {
return {
issueNumber: row.issueNumber,
@@ -1617,6 +1667,13 @@ function boardRowSummary(section: BoardTableSection, row: BoardTableRow): Record
};
}
function boardRowsExactMatch(
sections: BoardTableSection[],
issueNumber: number,
): Array<{ section: BoardTableSection; row: BoardTableRow }> {
return boardRowsForState(sections, "all").filter(({ row }) => row.issueNumber === issueNumber);
}
function boardRowsForState(sections: BoardTableSection[], state: IssueListState): Array<{ section: BoardTableSection; row: BoardTableRow }> {
return sections
.filter((section) => state === "all" || section.kind === state)
@@ -1922,6 +1979,456 @@ function boardRowStatusConsistency(
return { ok: true, githubStatusColumnIndex, actualStatus, expectedStatus };
}
function boardRowUpsertValueEntries(values: BoardRowUpsertValues): Array<{ field: BoardRowUpsertField; value: string }> {
const entries: Array<{ field: BoardRowUpsertField; value: string }> = [];
for (const field of BOARD_ROW_UPSERT_TEXT_FIELDS) {
const value = values[field];
if (value !== undefined) entries.push({ field, value });
}
if (values.status !== undefined) entries.push({ field: "status", value: values.status });
return entries;
}
function boardColumnKindForUpsertField(field: BoardRowUpsertField): BoardColumnKind {
if (field === "category") return "category";
if (field === "branch") return "branch";
if (field === "tasks") return "relatedTask";
if (field === "summary") return "summary";
if (field === "focus") return "focus";
if (field === "validation") return "acceptance";
if (field === "status") return "githubStatus";
return "progress";
}
function renderBoardIssueCell(repo: string, issueNumber: number, summary: string | undefined): string {
const trimmed = (summary ?? "").trim();
if (trimmed.length === 0) return `#${issueNumber}`;
const targetHref = `https://github.com/${repo}/issues/${issueNumber}`;
const firstMarkdownIssue = /^\s*\[[^\]]*\]\(([^)]*)\)/u.exec(trimmed)?.[1] ?? "";
if (new RegExp(`/issues/${issueNumber}(?:\\b|$)`, "u").test(firstMarkdownIssue)) return trimmed;
return `[#${issueNumber}](${targetHref}) ${trimmed}`;
}
function boardRowUpsertTargetColumn(
repo: string,
commandName: string,
section: BoardTableSection,
issueNumber: number,
field: BoardRowUpsertField,
): { ok: true; columnIndex: number; targetColumn: BoardColumnKind | "issue"; usesIssueCell: boolean } | GitHubCommandFailure {
const columnMap = boardColumnIndexMap(section.headers);
if (field === "summary") {
const summaryIndex = columnMap.get("summary");
if (summaryIndex !== undefined) return { ok: true, columnIndex: summaryIndex, targetColumn: "summary", usesIssueCell: false };
const issueColumnIndex = boardIssueColumnIndex(section.headers);
if (issueColumnIndex !== null) return { ok: true, columnIndex: issueColumnIndex, targetColumn: "issue", usesIssueCell: true };
}
const targetColumn = boardColumnKindForUpsertField(field);
const columnIndex = columnMap.get(targetColumn);
if (columnIndex === undefined) {
return validationError(commandName, repo, `board table does not contain a column for --${field}`, {
issueNumber,
field,
targetColumn,
section: section.kind,
headers: section.headers,
}) as GitHubCommandFailure;
}
return { ok: true, columnIndex, targetColumn, usesIssueCell: false };
}
function boardRowUpsertRenderedValue(
repo: string,
issueNumber: number,
field: BoardRowUpsertField,
value: string,
targetColumn: BoardColumnKind | "issue",
): string {
if (field === "summary" && targetColumn === "issue") return renderBoardIssueCell(repo, issueNumber, value);
return value;
}
function boardRowUpsertPollutionFailure(
repo: string,
commandName: string,
issueNumber: number,
values: BoardRowUpsertValues,
): GitHubCommandFailure | null {
const findings = BOARD_ROW_UPSERT_TEXT_FIELDS
.map((field) => {
const value = values[field];
if (value === undefined) return null;
const evidence = boardRowValuePollutionEvidence(value);
return evidence.length === 0 ? null : { field, valuePreview: preview(value), evidence };
})
.filter((item): item is { field: BoardRowUpsertTextField; valuePreview: string; evidence: string[] } => item !== null);
if (findings.length === 0) return null;
return validationError(commandName, repo, "issue board-row upsert field value contains literal shell escape text that would pollute a board cell; pass real newlines or plain text instead", {
issueNumber,
shellPollution: { suspected: true, findings },
}) as GitHubCommandFailure;
}
function boardRowUpsertUpdatePlan(
repo: string,
boardIssue: GitHubIssue,
issueNumber: number,
found: { section: BoardTableSection; row: BoardTableRow },
values: BoardRowUpsertValues,
requestedSection: BoardMutationSection | undefined,
parsed: { sections: BoardTableSection[]; warnings: BoardRowValidationWarning[] },
): BoardRowMutationPlanResult | GitHubCommandFailure {
const commandName = "issue board-row upsert";
const { section, row } = found;
if (requestedSection !== undefined && requestedSection !== section.kind) {
return validationError(commandName, repo, `--section ${requestedSection} conflicts with existing row in ${section.kind}; use gh issue board-row move for section migration`, {
issueNumber,
requestedSection,
existingSection: section.kind,
moveCommand: `bun scripts/cli.ts gh issue board-row move ${issueNumber} --board-issue ${boardIssue.number} --to ${requestedSection}`,
}) as GitHubCommandFailure;
}
if (values.status !== undefined) {
const expectedStatus = expectedBoardGithubStatus(section.kind);
if (values.status !== expectedStatus) {
return validationError(commandName, repo, `--status ${values.status} conflicts with existing ${section.kind.toUpperCase()} section; use gh issue board-row move for section migration`, {
issueNumber,
existingSection: section.kind,
requestedStatus: values.status,
expectedStatus,
moveCommand: `bun scripts/cli.ts gh issue board-row move ${issueNumber} --board-issue ${boardIssue.number} --to ${values.status === "OPEN" ? "open" : "closed"} --status ${values.status}`,
}) as GitHubCommandFailure;
}
}
const entries = boardRowUpsertValueEntries(values);
if (entries.length === 0) {
return validationError(commandName, repo, "issue board-row upsert found an existing row but no upsert fields were provided", {
issueNumber,
existingSection: section.kind,
supportedFields: ["--category", "--branch", "--tasks", "--summary", "--focus", "--validation", "--progress", "--status"],
}) as GitHubCommandFailure;
}
if (row.cells.length !== section.headers.length) {
return validationError(commandName, repo, "existing row column count does not match the board table header", {
issueNumber,
section: section.kind,
expectedColumns: section.headers.length,
actualColumns: row.cells.length,
headers: section.headers,
lineNumber: row.lineNumber,
rowPreview: preview(row.raw),
}) as GitHubCommandFailure;
}
const oldCells = row.cells.slice();
const newCells = oldCells.slice();
const changedFields: Record<string, unknown>[] = [];
for (const entry of entries) {
const target = boardRowUpsertTargetColumn(repo, commandName, section, issueNumber, entry.field);
if (target.ok === false) return target;
const newValue = boardRowUpsertRenderedValue(repo, issueNumber, entry.field, entry.value, target.targetColumn);
const oldValue = oldCells[target.columnIndex] ?? "";
newCells[target.columnIndex] = newValue;
changedFields.push({
field: entry.field,
targetColumn: target.targetColumn,
targetColumnIndex: target.columnIndex,
requestedValue: entry.value,
oldValue,
newValue,
changed: oldValue !== newValue,
});
}
const newRow = renderMarkdownTableRow(newCells);
const oldBody = boardIssue.body ?? "";
let newBody: string;
try {
newBody = replaceBoardBodyLine(oldBody, row.lineNumber, newRow);
} catch (error) {
return validationError(commandName, repo, error instanceof Error ? error.message : String(error), {
issueNumber,
lineNumber: row.lineNumber,
}) as GitHubCommandFailure;
}
return {
ok: true,
newBody,
plan: {
repo,
boardIssue: boardIssue.number,
issueNumber,
operation: "update",
action: "update",
section: section.kind,
lineNumber: row.lineNumber,
requestedSection: requestedSection ?? null,
providedFields: entries.map((entry) => entry.field),
changedFields,
oldRow: row.raw,
newRow,
oldCells,
newCells,
row: {
old: boardRowSummary(section, row),
new: {
...boardRowSummary(section, { ...row, raw: newRow, cells: newCells }),
upsertFields: boardRowUpsertFieldValues(section, { ...row, raw: newRow, cells: newCells }),
},
},
linePlan: {
action: "replace",
section: section.kind,
lineNumber: row.lineNumber,
},
sectionPlan: {
kind: section.kind,
heading: section.heading,
headerLine: section.headerLine,
rowCount: section.rows.length,
},
body: {
oldBodyChars: oldBody.length,
oldBodySha: bodySha(oldBody),
newBodyChars: newBody.length,
newBodySha: bodySha(newBody),
changed: oldBody !== newBody,
},
tableParser: {
reused: "parseBoardTables",
rowValidationWarnings: parsed.warnings.length,
},
request: {
method: "PATCH",
path: `/repos/{owner}/{repo}/issues/${boardIssue.number}`,
body: { bodyChars: newBody.length },
},
},
};
}
function boardRowUpsertAddPlan(
repo: string,
boardIssue: GitHubIssue,
issueNumber: number,
sectionKind: BoardMutationSection,
values: BoardRowUpsertValues,
parsed: { sections: BoardTableSection[]; warnings: BoardRowValidationWarning[] },
): BoardRowMutationPlanResult | GitHubCommandFailure {
const commandName = "issue board-row upsert";
const targetLookup = targetBoardSection(repo, parsed.sections, sectionKind, commandName);
if (targetLookup.ok === false) return targetLookup;
const target = targetLookup.section;
const issueColumnIndex = boardIssueColumnIndex(target.headers);
if (issueColumnIndex === null) {
return validationError(commandName, repo, "board table does not contain an Issue column required for generated upsert rows", {
boardIssue: boardIssue.number,
section: sectionKind,
headers: target.headers,
}) as GitHubCommandFailure;
}
const columnMap = boardColumnIndexMap(target.headers);
const githubStatusColumnIndex = columnMap.get("githubStatus");
if (githubStatusColumnIndex === undefined) {
return validationError(commandName, repo, "board table does not contain a GitHub column required for generated upsert rows", {
boardIssue: boardIssue.number,
section: sectionKind,
headers: target.headers,
}) as GitHubCommandFailure;
}
const expectedStatus = expectedBoardGithubStatus(sectionKind);
const requestedStatus = values.status ?? expectedStatus;
if (requestedStatus !== expectedStatus) {
return validationError(commandName, repo, `--status ${requestedStatus} conflicts with --section ${sectionKind}; expected ${expectedStatus}`, {
issueNumber,
section: sectionKind,
requestedStatus,
expectedStatus,
}) as GitHubCommandFailure;
}
const appliedFields = new Set<BoardRowUpsertField>();
const missingFields: BoardRowUpsertTextField[] = [];
const unsupportedColumns: Array<{ index: number; header: string }> = [];
const summaryColumnIndex = columnMap.get("summary");
const cells = target.headers.map((header, index) => {
if (index === issueColumnIndex) {
if (summaryColumnIndex === undefined && values.summary !== undefined) appliedFields.add("summary");
return summaryColumnIndex === undefined ? renderBoardIssueCell(repo, issueNumber, values.summary) : `#${issueNumber}`;
}
const kind = boardHeaderColumnKind(header);
if (kind === "githubStatus") {
if (values.status !== undefined) appliedFields.add("status");
return requestedStatus;
}
const valueFor = (field: BoardRowUpsertTextField, value: string | undefined): string => {
if (value === undefined) {
missingFields.push(field);
return "";
}
appliedFields.add(field);
return value;
};
if (kind === "category") return valueFor("category", values.category);
if (kind === "branch") return valueFor("branch", values.branch);
if (kind === "relatedTask") return valueFor("tasks", values.tasks);
if (kind === "summary") return valueFor("summary", values.summary);
if (kind === "focus") return valueFor("focus", values.focus);
if (kind === "acceptance") return valueFor("validation", values.validation);
if (kind === "progress") return valueFor("progress", values.progress);
unsupportedColumns.push({ index, header });
return "";
});
if (unsupportedColumns.length > 0) {
return validationError(commandName, repo, "target board table contains unsupported column(s) for generated upsert rows", {
issueNumber,
section: sectionKind,
unsupportedColumns,
headers: target.headers,
}) as GitHubCommandFailure;
}
const unappliedFields = boardRowUpsertValueEntries(values)
.map((entry) => entry.field)
.filter((field) => !appliedFields.has(field));
if (unappliedFields.length > 0) {
return validationError(commandName, repo, "target board table does not contain column(s) for supplied upsert field(s)", {
issueNumber,
section: sectionKind,
unappliedFields,
headers: target.headers,
}) as GitHubCommandFailure;
}
const uniqueMissingFields = Array.from(new Set(missingFields));
if (uniqueMissingFields.length > 0) {
return validationError(commandName, repo, "issue board-row upsert add requires values for every generated row column", {
issueNumber,
section: sectionKind,
missingFields: uniqueMissingFields,
requiredOptions: uniqueMissingFields.map((field) => `--${field}`),
headers: target.headers,
}) as GitHubCommandFailure;
}
const newRow = renderMarkdownTableRow(cells);
const row = boardRowFromCells(target, newRow, cells, 0);
if (row.issueNumber !== issueNumber) {
return validationError(commandName, repo, "generated Issue column does not match the requested issue number", {
issueNumber,
issueColumnIndex,
issueCell: cells[issueColumnIndex] ?? "",
detectedIssueNumber: row.issueNumber,
rowPreview: preview(newRow),
}) as GitHubCommandFailure;
}
const actualStatus = normalizeBoardGithubStatusCell(cells[githubStatusColumnIndex]);
if (actualStatus !== expectedStatus) {
return validationError(commandName, repo, "generated GitHub column does not match the target section", {
issueNumber,
section: sectionKind,
expectedStatus,
actualStatus,
statusColumnIndex: githubStatusColumnIndex,
statusCell: cells[githubStatusColumnIndex] ?? "",
rowPreview: preview(newRow),
}) as GitHubCommandFailure;
}
const oldBody = boardIssue.body ?? "";
const insertAfterLine = boardSectionInsertAfterLine(target);
let newBody: string;
try {
newBody = insertBoardBodyLineAfter(oldBody, insertAfterLine, newRow);
} catch (error) {
return validationError(commandName, repo, error instanceof Error ? error.message : String(error), {
issueNumber,
section: sectionKind,
insertAfterLine,
}) as GitHubCommandFailure;
}
return {
ok: true,
newBody,
plan: {
repo,
boardIssue: boardIssue.number,
issueNumber,
operation: "add",
action: "add",
section: sectionKind,
insertAfterLine,
providedFields: boardRowUpsertValueEntries(values).map((entry) => entry.field),
newRow,
newCells: cells,
row: {
old: null,
new: {
...boardRowSummary(target, { ...row, lineNumber: insertAfterLine + 1 }),
upsertFields: boardRowUpsertFieldValues(target, { ...row, lineNumber: insertAfterLine + 1 }),
},
},
linePlan: {
action: "insert",
section: sectionKind,
insertAfterLine,
newLineNumber: insertAfterLine + 1,
},
sectionPlan: {
kind: sectionKind,
heading: target.heading,
headerLine: target.headerLine,
rowCount: target.rows.length,
},
validation: {
issueColumnIndex,
githubStatusColumnIndex,
expectedStatus,
actualStatus,
columnCount: cells.length,
},
body: {
oldBodyChars: oldBody.length,
oldBodySha: bodySha(oldBody),
newBodyChars: newBody.length,
newBodySha: bodySha(newBody),
changed: oldBody !== newBody,
},
tableParser: {
reused: "parseBoardTables",
rowValidationWarnings: parsed.warnings.length,
},
request: {
method: "PATCH",
path: `/repos/{owner}/{repo}/issues/${boardIssue.number}`,
body: { bodyChars: newBody.length },
},
},
};
}
function boardRowUpsertPlan(
repo: string,
boardIssue: GitHubIssue,
issueNumber: number,
options: GitHubOptions,
parsed: { sections: BoardTableSection[]; warnings: BoardRowValidationWarning[] },
): BoardRowMutationPlanResult | GitHubCommandFailure {
const commandName = "issue board-row upsert";
const pollutionFailure = boardRowUpsertPollutionFailure(repo, commandName, issueNumber, options.boardRowUpsertValues);
if (pollutionFailure !== null) return pollutionFailure;
const matches = boardRowsExactMatch(parsed.sections, issueNumber);
if (matches.length > 1) {
return validationError(commandName, repo, `board row for issue #${issueNumber} is ambiguous; refusing upsert`, {
issueNumber,
matches: matches.map(({ section, row }) => ({ section: section.kind, lineNumber: row.lineNumber, rowPreview: preview(row.raw) })),
}) as GitHubCommandFailure;
}
if (matches.length === 1) {
return boardRowUpsertUpdatePlan(repo, boardIssue, issueNumber, matches[0], options.boardRowUpsertValues, options.boardSection, parsed);
}
if (options.boardSection === undefined) {
return validationError(commandName, repo, "issue board-row upsert add requires --section open|closed when the row does not already exist", {
issueNumber,
supportedSections: BOARD_MUTATION_SECTIONS.slice(),
}) as GitHubCommandFailure;
}
return boardRowUpsertAddPlan(repo, boardIssue, issueNumber, options.boardSection, options.boardRowUpsertValues, parsed);
}
function boardRowAddPlan(
repo: string,
boardIssue: GitHubIssue,
@@ -2260,8 +2767,8 @@ async function issueBoardRowMutation(
token: string,
issueNumber: number,
options: GitHubOptions,
commandName: "issue board-row add" | "issue board-row move" | "issue board-row delete",
mutationKey: "add" | "move" | "delete",
commandName: "issue board-row add" | "issue board-row move" | "issue board-row delete" | "issue board-row upsert",
mutationKey: "add" | "move" | "delete" | "upsert",
buildPlan: (boardIssue: GitHubIssue, parsed: { sections: BoardTableSection[]; warnings: BoardRowValidationWarning[] }) => BoardRowMutationPlanResult | GitHubCommandFailure,
): Promise<GitHubCommandResult> {
const concurrencyOptionError = assertConcurrencyOptions(options, commandName);
@@ -2289,6 +2796,7 @@ async function issueBoardRowMutation(
updatedAt: boardIssue.updated_at ?? null,
},
issueNumber,
operation: typeof planned.plan.operation === "string" ? planned.plan.operation : mutationKey,
dryRun: effectiveDryRun,
planned: true,
[mutationKey]: planned.plan,
@@ -2519,6 +3027,19 @@ async function issueBoardRowAdd(repo: string, token: string, issueNumber: number
);
}
async function issueBoardRowUpsert(repo: string, token: string, issueNumber: number, options: GitHubOptions): Promise<GitHubCommandResult> {
const commandName = "issue board-row upsert";
return issueBoardRowMutation(
repo,
token,
issueNumber,
options,
commandName,
"upsert",
(boardIssue, parsed) => boardRowUpsertPlan(repo, boardIssue, issueNumber, options, parsed),
);
}
async function issueBoardRowMove(repo: string, token: string, issueNumber: number, options: GitHubOptions): Promise<GitHubCommandResult> {
const commandName = "issue board-row move";
if (options.boardMoveTo === undefined) return validationError(commandName, repo, "issue board-row move requires --to open|closed", { issueNumber, supportedTargets: BOARD_MUTATION_SECTIONS.slice() });
@@ -4071,6 +4592,7 @@ export function ghHelp(): unknown {
"bun scripts/cli.ts gh issue board-row get <issueNumber> [--repo owner/name] --board-issue 20",
"bun scripts/cli.ts gh issue board-row update <issueNumber> [--repo owner/name] --board-issue 20 --field progress|status|validation|branch|tasks|focus --value <text> [--dry-run] [--expect-updated-at ts|--expect-body-sha sha256]",
"bun scripts/cli.ts gh issue board-row add <issueNumber> [--repo owner/name] --board-issue 20 --section open|closed --row-file <markdown-row-file> [--dry-run] [--expect-body-sha sha256]",
"bun scripts/cli.ts gh issue board-row upsert <issueNumber> [--repo owner/name] --board-issue 20 --section open|closed [--category text] --branch <branch> --tasks <task> --summary <text> --focus <text> --validation <text> --progress <text> [--status OPEN|CLOSED] [--dry-run] [--expect-updated-at ts|--expect-body-sha sha256]",
"bun scripts/cli.ts gh issue board-row move <issueNumber> [--repo owner/name] --board-issue 20 --to open|closed [--status OPEN|CLOSED] [--dry-run] [--expect-body-sha sha256]",
"bun scripts/cli.ts gh issue board-row delete <issueNumber> [--repo owner/name] --board-issue 20 [--dry-run] [--expect-body-sha sha256]",
"bun scripts/cli.ts gh pr list [--repo owner/name] [--limit N] [--json number,title,state,url,updatedAt,createdAt,author,head,base,draft]",
@@ -4101,6 +4623,7 @@ export function ghHelp(): unknown {
"issue scan-escape classifies literal \\n findings as suspected-pollution, explanatory-mention, or risk, and emits cleanupSuggestions with body/comment ids plus diff-like previews. cleanup-plan is an alias that remains dry-run/read-only.",
"issue board-audit is read-only and defaults to repo pikasTech/unidesk plus board issue #20. It compares GitHub open/closed issue lists with the board OPEN/CLOSED tables and reports missingOpenIssues, closedInOpenRows, missingClosedRows, rowValidationWarnings, ignoredIssues, and recommendedActions. When an Issue column exists, row.issueNumber is taken from that column; #20 and #24 are known meta issues by default. Daily rolling brief issues titled YYYY-MM-DD 指挥简报(北京时间) are managed by #20's brief index and appear in ignoredIssues with reason=brief-index-managed instead of missingOpenIssues.",
"issue board-row list/get reuse the board-audit table parser and are read-only. board-row update changes one table cell by issue number, returns old/new row, body SHA, body guard and request plan, and defaults to dry-run unless --expect-updated-at or --expect-body-sha is supplied for the guarded PATCH. Field aliases map status and validation to the column, tasks to Code Queue , and focus to .",
"issue board-row upsert updates an existing row when the issue is already present, or generates a complete row in --section open|closed when missing. It returns operation=update or operation=add, defaults to dry-run, requires --expect-body-sha or --expect-updated-at before PATCH, and refuses section migration; use board-row move for OPEN/CLOSED migration.",
"issue board-row add/move/delete are row-scoped #20 table mutations. add validates a one-line --row-file against the target table column count, Issue column, and GitHub column; move refuses duplicate/ambiguous rows and can update GitHub via --status; delete removes only the matched row. All three default to dry-run and require --expect-body-sha or --expect-updated-at before PATCH. add/move/delete return old/new row, body SHA, and line/section plan details for the parsed table mutation.",
"issue edit 24 --notify-claudeqq-brief-diff remains the legacy #24 notification helper: it reads the old issue body, PATCHes the new body, and sends only newly added '## 更新 ... 北京时间' sections to ClaudeQQ; ClaudeQQ failure does not roll back GitHub.",
"Commander brief ClaudeQQ defaults to private target 645275593 through backend-core /api/microservices/claudeqq/proxy; UNIDESK_COMMANDER_BRIEF_CLAUDEQQ_* env vars can override target, base URL, timeout, and enabled state.",
@@ -4142,9 +4665,9 @@ export async function runGhCommand(args: string[]): Promise<GitHubCommandResult
const command = [top, sub].filter((value): value is string => value !== undefined).join(" ") || "gh";
return validationError(command, options.repo, "--mode is only supported by gh issue update/edit and gh pr update");
}
if ((options.allowShortBody || options.expectUpdatedAt !== undefined || options.expectBodySha !== undefined || optionWasProvided(args, "--body-profile")) && !(top === "issue" && (sub === "edit" || sub === "update" || sub === "board-row" && ["update", "add", "move", "delete"].includes(third ?? "")))) {
if ((options.allowShortBody || options.expectUpdatedAt !== undefined || options.expectBodySha !== undefined || optionWasProvided(args, "--body-profile")) && !(top === "issue" && (sub === "edit" || sub === "update" || sub === "board-row" && ["update", "add", "move", "delete", "upsert"].includes(third ?? "")))) {
const command = [top, sub].filter((value): value is string => value !== undefined).join(" ") || "gh";
return validationError(command, options.repo, "--allow-short-body, --expect-updated-at, --expect-body-sha, and --body-profile are only supported by gh issue update/edit and gh issue board-row update/add/move/delete");
return validationError(command, options.repo, "--allow-short-body, --expect-updated-at, --expect-body-sha, and --body-profile are only supported by gh issue update/edit and gh issue board-row update/add/move/delete/upsert");
}
if ((optionWasProvided(args, "--board-issue") || optionWasProvided(args, "--known-meta-issue") || optionWasProvided(args, "--ignore-issue")) && !(top === "issue" && (sub === "board-audit" || sub === "board-row"))) {
const command = [top, sub].filter((value): value is string => value !== undefined).join(" ") || "gh";
@@ -4162,13 +4685,21 @@ export async function runGhCommand(args: string[]): Promise<GitHubCommandResult
const command = [top, sub, third].filter((value): value is string => value !== undefined).join(" ") || "gh";
return validationError(command, options.repo, "--row-file is only supported by gh issue board-row add");
}
if (optionWasProvided(args, "--section") && !(top === "issue" && sub === "board-row" && third === "add")) {
if (optionWasProvided(args, "--section") && !(top === "issue" && sub === "board-row" && (third === "add" || third === "upsert"))) {
const command = [top, sub, third].filter((value): value is string => value !== undefined).join(" ") || "gh";
return validationError(command, options.repo, "--section is only supported by gh issue board-row add");
return validationError(command, options.repo, "--section is only supported by gh issue board-row add/upsert");
}
if ((optionWasProvided(args, "--to") || optionWasProvided(args, "--status")) && !(top === "issue" && sub === "board-row" && third === "move")) {
if (optionWasProvided(args, "--to") && !(top === "issue" && sub === "board-row" && third === "move")) {
const command = [top, sub, third].filter((value): value is string => value !== undefined).join(" ") || "gh";
return validationError(command, options.repo, "--to and --status are only supported by gh issue board-row move");
return validationError(command, options.repo, "--to is only supported by gh issue board-row move");
}
if (optionWasProvided(args, "--status") && !(top === "issue" && sub === "board-row" && (third === "move" || third === "upsert"))) {
const command = [top, sub, third].filter((value): value is string => value !== undefined).join(" ") || "gh";
return validationError(command, options.repo, "--status is only supported by gh issue board-row move/upsert");
}
if ((optionWasProvided(args, "--category") || optionWasProvided(args, "--branch") || optionWasProvided(args, "--tasks") || optionWasProvided(args, "--summary") || optionWasProvided(args, "--focus") || optionWasProvided(args, "--validation") || optionWasProvided(args, "--progress")) && !(top === "issue" && sub === "board-row" && third === "upsert")) {
const command = [top, sub, third].filter((value): value is string => value !== undefined).join(" ") || "gh";
return validationError(command, options.repo, "--category, --branch, --tasks, --summary, --focus, --validation, and --progress are only supported by gh issue board-row upsert");
}
if (optionWasProvided(args, "--label") && !(top === "issue" && sub === "create")) {
const command = [top, sub].filter((value): value is string => value !== undefined).join(" ") || "gh";
@@ -4213,8 +4744,8 @@ export async function runGhCommand(args: string[]): Promise<GitHubCommandResult
if (sub === "board-row") {
const action = third;
const commandName = `issue board-row ${action ?? ""}`.trim();
if (action !== "list" && action !== "get" && action !== "update" && action !== "add" && action !== "move" && action !== "delete") {
return unsupportedCommand(commandName, options.repo, "board-row supported commands are list, get, update, add, move, and delete.");
if (action !== "list" && action !== "get" && action !== "update" && action !== "add" && action !== "move" && action !== "delete" && action !== "upsert") {
return unsupportedCommand(commandName, options.repo, "board-row supported commands are list, get, update, add, move, delete, and upsert.");
}
const { token, probe } = resolveToken(true);
const missing = authRequired(options.repo, commandName, probe);
@@ -4225,6 +4756,7 @@ export async function runGhCommand(args: string[]): Promise<GitHubCommandResult
if (action === "get") return issueBoardRowGet(options.repo, token, issueNumber, options);
if (action === "update") return issueBoardRowUpdate(options.repo, token, issueNumber, options);
if (action === "add") return issueBoardRowAdd(options.repo, token, issueNumber, options);
if (action === "upsert") return issueBoardRowUpsert(options.repo, token, issueNumber, options);
if (action === "move") return issueBoardRowMove(options.repo, token, issueNumber, options);
return issueBoardRowDelete(options.repo, token, issueNumber, options);
}