fix: guard hwlab product routing from issue 20
This commit is contained in:
+98
-8
@@ -993,16 +993,102 @@ function commanderBriefUpdateHeadings(body: string): string[] {
|
||||
.filter((line) => isCommanderBriefUpdateHeading(line));
|
||||
}
|
||||
|
||||
function codeQueueBoardHwlabProductRoutingFindings(body: string | undefined): Array<Record<string, unknown>> {
|
||||
if (body === undefined) return [];
|
||||
const findings: Array<Record<string, unknown>> = [];
|
||||
const directIssuePatterns = [
|
||||
{ kind: "hwlab-repo-issue-url", pattern: /(?:https?:\/\/github\.com\/)?pikasTech\/HWLAB\/issues\/\d+/iu },
|
||||
{ kind: "hwlab-repo-issue-short-ref", pattern: /\bpikasTech\/HWLAB#\d+\b/iu },
|
||||
{ kind: "hwlab-short-issue-ref", pattern: /\bHWLAB#\d+\b/iu },
|
||||
];
|
||||
const hwlabContextPattern = /\bHWLAB\b|pikasTech\/HWLAB|hwlab-/iu;
|
||||
const strongProductPattern = /hwlab-cloud-web|Cloud Workbench|DEV-LIVE|res_boxsimu|hwlab-patch-panel|patch panel|M3\s*(?:虚拟硬件|可信闭环)/iu;
|
||||
const genericProductPattern = /用户反馈|user feedback/iu;
|
||||
const governanceContextPattern = /\b(?:commander|Code Queue|CLI|infra|governance|guard|guardrail|routing|misfile|board)\b|治理|调度|基础设施|守卫|边界|分流|看板/iu;
|
||||
const lines = normalizeNewlines(body).split("\n");
|
||||
for (let index = 0; index < lines.length; index += 1) {
|
||||
const line = lines[index];
|
||||
const isTableRow = line.trim().startsWith("|") && !isMarkdownTableSeparator(line);
|
||||
const strongProductSignal = strongProductPattern.test(line);
|
||||
const genericProductSignal = genericProductPattern.test(line);
|
||||
const governanceContext = governanceContextPattern.test(line);
|
||||
for (const definition of directIssuePatterns) {
|
||||
const match = definition.pattern.exec(line);
|
||||
if (match !== null && !governanceContext && (isTableRow || strongProductSignal || (genericProductSignal && hwlabContextPattern.test(line)))) {
|
||||
findings.push({
|
||||
kind: definition.kind,
|
||||
lineNumber: index + 1,
|
||||
match: match[0],
|
||||
snippet: preview(line.trim()),
|
||||
});
|
||||
}
|
||||
}
|
||||
if (isTableRow && !governanceContext && (strongProductSignal || (genericProductSignal && hwlabContextPattern.test(line)))) {
|
||||
const match = strongProductSignal ? strongProductPattern.exec(line) : genericProductPattern.exec(line);
|
||||
findings.push({
|
||||
kind: "hwlab-product-signal",
|
||||
lineNumber: index + 1,
|
||||
match: match?.[0] ?? "HWLAB product signal",
|
||||
snippet: preview(line.trim()),
|
||||
});
|
||||
}
|
||||
if (findings.length >= 12) break;
|
||||
}
|
||||
return findings;
|
||||
}
|
||||
|
||||
function codeQueueBoardHwlabProductRoutingHint(boardIssueNumber: number, body?: string): Record<string, unknown> | null {
|
||||
if (boardIssueNumber !== CODE_QUEUE_BOARD_TARGET_ISSUE) return null;
|
||||
const findings = codeQueueBoardHwlabProductRoutingFindings(body);
|
||||
return {
|
||||
warning: "#20 is only for UniDesk commander/Code Queue/CLI/infra governance; HWLAB user/product issues belong in pikasTech/HWLAB.",
|
||||
route: "Create or update the corresponding issue in pikasTech/HWLAB; keep #20 rows limited to UniDesk governance or infrastructure support work.",
|
||||
forbiddenPatterns: [
|
||||
"pikasTech/HWLAB#<N>",
|
||||
"github.com/pikasTech/HWLAB/issues/<N>",
|
||||
"HWLAB#<N>",
|
||||
"HWLAB product/live validation rows",
|
||||
],
|
||||
allowedScope: ["commander governance", "Code Queue supervision", "UniDesk CLI guardrails", "UniDesk infrastructure"],
|
||||
detected: findings.length > 0,
|
||||
findings,
|
||||
};
|
||||
}
|
||||
|
||||
function codeQueueBoardHintHasHwlabProductRouting(hint: Record<string, unknown> | null): boolean {
|
||||
if (hint === null) return false;
|
||||
const routing = hint.hwlabProductRouting;
|
||||
return typeof routing === "object" && routing !== null && (routing as { detected?: unknown }).detected === true;
|
||||
}
|
||||
|
||||
function codeQueueBoardHintHasCommanderBriefUpdates(hint: Record<string, unknown> | null): boolean {
|
||||
if (hint === null) return false;
|
||||
const commanderBrief = hint.commanderBrief;
|
||||
return typeof commanderBrief === "object" && commanderBrief !== null && (commanderBrief as { detected?: unknown }).detected === true;
|
||||
}
|
||||
|
||||
function codeQueueBoardCommanderBriefHint(boardIssueNumber: number, body?: string): Record<string, unknown> | null {
|
||||
if (boardIssueNumber !== CODE_QUEUE_BOARD_TARGET_ISSUE) return null;
|
||||
const headings = body === undefined ? [] : commanderBriefUpdateHeadings(body);
|
||||
const hwlabProductRouting = codeQueueBoardHwlabProductRoutingHint(boardIssueNumber, body);
|
||||
const commanderBriefDetected = headings.length > 0;
|
||||
const hwlabProductDetected = codeQueueBoardHintHasHwlabProductRouting({ hwlabProductRouting });
|
||||
return {
|
||||
warning: "#20 is the long-term board only; do not write daily commander brief update sections into #20.",
|
||||
route: "Move daily progress notes to the daily rolling commander brief issue referenced in #20's 指挥简报索引, using --body-profile commander-brief.",
|
||||
warning: "#20 is the long-term UniDesk commander/Code Queue/CLI/infra governance board only; do not write daily commander brief updates or HWLAB product/user issue tracking into #20.",
|
||||
route: commanderBriefDetected
|
||||
? "Move daily progress notes to the daily rolling commander brief issue referenced in #20's 指挥简报索引, using --body-profile commander-brief."
|
||||
: hwlabProductDetected
|
||||
? "Move HWLAB product/user issue tracking to pikasTech/HWLAB; keep #20 limited to UniDesk commander/Code Queue/CLI/infra governance."
|
||||
: "Use #20 only for UniDesk commander/Code Queue/CLI/infra governance rows.",
|
||||
forbiddenHeadings: ["## 更新 YYYY-MM-DD HH:mm 北京时间", "## YYYY-MM-DD HH:mm 北京时间指挥更新", "### YYYY-MM-DD HH:mm CST:..."],
|
||||
suggestedCommand: "bun scripts/cli.ts gh issue update <daily-brief-issue> --mode replace --body-file <file> --body-profile commander-brief --expect-body-sha <sha>",
|
||||
detected: headings.length > 0,
|
||||
detected: commanderBriefDetected || hwlabProductDetected,
|
||||
detectedHeadings: headings,
|
||||
commanderBrief: {
|
||||
detected: commanderBriefDetected,
|
||||
detectedHeadings: headings,
|
||||
},
|
||||
hwlabProductRouting,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -3561,13 +3647,15 @@ function validateIssueBodyGuard(repo: string, issueNumber: number, body: string,
|
||||
const isShort = trimmed.length > 0 && trimmed.length < MIN_SAFE_ISSUE_BODY_CHARS;
|
||||
const profileValidation = issueProfileValidation(issueNumber, body, options.bodyProfile, profileContext);
|
||||
const boardBriefHint = codeQueueBoardCommanderBriefHint(issueNumber, body);
|
||||
const boardContainsCommanderBriefUpdates = boardBriefHint?.detected === true;
|
||||
const boardContainsCommanderBriefUpdates = codeQueueBoardHintHasCommanderBriefUpdates(boardBriefHint);
|
||||
const boardContainsHwlabProductWork = codeQueueBoardHintHasHwlabProductRouting(boardBriefHint);
|
||||
const profileOk = validationBoolean(profileValidation, "ok");
|
||||
const failures: string[] = [];
|
||||
if (isLiteralNull) failures.push("literal-null-body");
|
||||
if (isBlank) failures.push("blank-body");
|
||||
if (isShort && !options.allowShortBody) failures.push("short-body");
|
||||
if (boardContainsCommanderBriefUpdates) failures.push("code-queue-board-contains-commander-brief-updates");
|
||||
if (boardContainsHwlabProductWork) failures.push("code-queue-board-contains-hwlab-product-work");
|
||||
if (!profileOk) {
|
||||
if (profileValidation.issueMatchesProfile === false) failures.push("profile-issue-mismatch");
|
||||
const missingHeadings = validationStringArray(profileValidation, "missingHeadings");
|
||||
@@ -3609,7 +3697,8 @@ function issueEditGuardSummary(issueNumber: number, body: string, options: GitHu
|
||||
}
|
||||
if (options.allowShortBody) warnings.push("allow-short-body enabled; caller accepted short-body corruption risk");
|
||||
if (profile.ok === false) warnings.push("profile guard would fail");
|
||||
if (boardBriefHint?.detected === true) warnings.push("code-queue-board-contains-commander-brief-updates");
|
||||
if (codeQueueBoardHintHasCommanderBriefUpdates(boardBriefHint)) warnings.push("code-queue-board-contains-commander-brief-updates");
|
||||
if (codeQueueBoardHintHasHwlabProductRouting(boardBriefHint)) warnings.push("code-queue-board-contains-hwlab-product-work");
|
||||
const signals = bodySafetySignals(body);
|
||||
const shellPollution = signals.shellPollution as Record<string, unknown>;
|
||||
if (shellPollution.suspected === true) warnings.push("shell-pollution-suspected");
|
||||
@@ -3618,7 +3707,8 @@ function issueEditGuardSummary(issueNumber: number, body: string, options: GitHu
|
||||
&& trimmed.toLowerCase() !== "null"
|
||||
&& (trimmed.length >= MIN_SAFE_ISSUE_BODY_CHARS || options.allowShortBody)
|
||||
&& profile.ok === true
|
||||
&& boardBriefHint?.detected !== true,
|
||||
&& !codeQueueBoardHintHasCommanderBriefUpdates(boardBriefHint)
|
||||
&& !codeQueueBoardHintHasHwlabProductRouting(boardBriefHint),
|
||||
minSafeBodyChars: MIN_SAFE_ISSUE_BODY_CHARS,
|
||||
allowShortBody: options.allowShortBody,
|
||||
warnings,
|
||||
@@ -5173,7 +5263,7 @@ export function ghHelp(): unknown {
|
||||
"--body-file is the recommended source for Markdown bodies so real newlines, backticks, and tables are read as file bytes instead of shell arguments.",
|
||||
"update defaults to --mode replace; --mode append reads the current body and appends file bytes so real newlines, backticks, and Markdown tables are preserved.",
|
||||
"issue edit is a compatibility alias for issue update --mode replace.",
|
||||
"issue update --body-file refuses literal null, blank, and too-short bodies by default. Use --allow-short-body only for intentional short writes; #20 requires its board heading, and commander-brief requires its stable heading on legacy #24 plus daily rolling brief issues titled YYYY-MM-DD 指挥简报(北京时间).",
|
||||
"issue update --body-file refuses literal null, blank, and too-short bodies by default. Use --allow-short-body only for intentional short writes; #20 requires its board heading and rejects HWLAB product/user issue rows in favor of pikasTech/HWLAB, while commander-brief requires its stable heading on legacy #24 plus daily rolling brief issues titled YYYY-MM-DD 指挥简报(北京时间).",
|
||||
"issue update dry-run reports old/new body length slots, body SHA, required heading checks, literal \\n detection, and shell-pollution signals. Non-dry-run can use --expect-updated-at or --expect-body-sha for stale-cache protection.",
|
||||
"Issue body stdin is intentionally unsupported in this CLI; write generated Markdown to a file and pass --body-file.",
|
||||
"When staging a body file from a shell, use a quoted heredoc such as cat <<'EOF' > /tmp/body.md so backticks and backslashes are not expanded before --body-file reads the file.",
|
||||
@@ -5182,7 +5272,7 @@ export function ghHelp(): unknown {
|
||||
"issue board-audit is read-only and defaults to repo pikasTech/unidesk plus board issue #20. It reads only the board issue body, returns body size/SHA and parsed Markdown board sections, and no longer validates GitHub open/closed issue coverage against OPEN/CLOSED tables. The legacy coverage fields remain present as empty arrays/zero counts for compatibility.",
|
||||
"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 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, and the shared #20 guard rejects HWLAB product/user issue rows in favor of pikasTech/HWLAB.",
|
||||
"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.",
|
||||
"comment delete is supported because GitHub supports deleting issue comments; issue/pr hard delete is unsupported and close is the lifecycle alternative.",
|
||||
|
||||
Reference in New Issue
Block a user