@bbcsoftwarefactory/cli 0.1.0 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/audit-ledger.d.ts +2 -0
- package/dist/audit-ledger.js +71 -0
- package/dist/bbc-install.d.ts +2 -0
- package/dist/bbc-install.js +1250 -0
- package/dist/bbc.d.ts +2 -0
- package/dist/bbc.js +124 -0
- package/dist/bigo/complexity.d.ts +18 -0
- package/dist/bigo/complexity.js +139 -0
- package/dist/bigo/functions.d.ts +5 -0
- package/dist/bigo/functions.js +174 -0
- package/dist/bigo/keywords.d.ts +1 -0
- package/dist/bigo/keywords.js +43 -0
- package/dist/bigo/lexical.d.ts +14 -0
- package/dist/bigo/lexical.js +69 -0
- package/dist/bigo/source-files.d.ts +1 -0
- package/dist/bigo/source-files.js +80 -0
- package/dist/change-lane/classification.d.ts +41 -0
- package/dist/change-lane/classification.js +104 -0
- package/dist/change-lane/git.d.ts +8 -0
- package/dist/change-lane/git.js +105 -0
- package/dist/check-issue-claim.d.ts +2 -0
- package/dist/check-issue-claim.js +146 -0
- package/dist/check-worktree-guard.d.ts +2 -0
- package/dist/check-worktree-guard.js +114 -0
- package/dist/classify-change-lane.d.ts +2 -0
- package/dist/classify-change-lane.js +128 -0
- package/dist/diff-scope/git-diff.d.ts +25 -0
- package/dist/diff-scope/git-diff.js +146 -0
- package/dist/error-scan.d.ts +3 -0
- package/dist/error-scan.js +216 -0
- package/dist/export-public.d.ts +9 -0
- package/dist/export-public.js +274 -0
- package/dist/extract-diff-scope.d.ts +2 -0
- package/dist/extract-diff-scope.js +111 -0
- package/dist/fetch-issue-attachments.d.ts +22 -0
- package/dist/fetch-issue-attachments.js +325 -0
- package/dist/issue-claim/evaluation.d.ts +66 -0
- package/dist/issue-claim/evaluation.js +259 -0
- package/dist/issue-claim/loaders.d.ts +5 -0
- package/dist/issue-claim/loaders.js +116 -0
- package/dist/list-zed-commands.d.ts +7 -0
- package/dist/list-zed-commands.js +288 -0
- package/dist/measure-bigo.d.ts +2 -0
- package/dist/measure-bigo.js +84 -0
- package/dist/plan-issue-triage.d.ts +3 -0
- package/dist/plan-issue-triage.js +404 -0
- package/dist/question-gate/ledger.d.ts +5 -0
- package/dist/question-gate/ledger.js +115 -0
- package/dist/question-gate/rules.d.ts +40 -0
- package/dist/question-gate/rules.js +483 -0
- package/dist/recap/board.d.ts +5 -0
- package/dist/recap/board.js +384 -0
- package/dist/recap/git-and-github.d.ts +11 -0
- package/dist/recap/git-and-github.js +620 -0
- package/dist/recap/report-and-hud.d.ts +2 -0
- package/dist/recap/report-and-hud.js +294 -0
- package/dist/recap/time-and-refs.d.ts +27 -0
- package/dist/recap/time-and-refs.js +148 -0
- package/dist/recap.d.ts +2 -0
- package/dist/recap.js +217 -0
- package/dist/render-workflow.d.ts +2 -0
- package/dist/render-workflow.js +142 -0
- package/dist/resolve-containers.d.ts +2 -0
- package/dist/resolve-containers.js +96 -0
- package/dist/review-loop.d.ts +7 -0
- package/dist/review-loop.js +622 -0
- package/dist/save-counts.d.ts +2 -0
- package/dist/save-counts.js +191 -0
- package/dist/summarize-logs.d.ts +2 -0
- package/dist/summarize-logs.js +41 -0
- package/dist/sweep-github.d.ts +10 -0
- package/dist/sweep-github.js +453 -0
- package/dist/sweep-issues.d.ts +56 -0
- package/dist/sweep-issues.js +650 -0
- package/dist/sweep.d.ts +2 -0
- package/dist/sweep.js +301 -0
- package/dist/triage-question.d.ts +2 -0
- package/dist/triage-question.js +189 -0
- package/dist/validate-skills.d.ts +2 -0
- package/dist/validate-skills.js +48 -0
- package/dist/watch-live.d.ts +7 -0
- package/dist/watch-live.js +83 -0
- package/dist/watcher/config.d.ts +11 -0
- package/dist/watcher/config.js +265 -0
- package/dist/watcher/live-classifier.d.ts +52 -0
- package/dist/watcher/live-classifier.js +510 -0
- package/dist/watcher/safe-fs.d.ts +9 -0
- package/dist/watcher/safe-fs.js +159 -0
- package/dist/watcher/stream.d.ts +27 -0
- package/dist/watcher/stream.js +340 -0
- package/dist/watcher/summarizer.d.ts +19 -0
- package/dist/watcher/summarizer.js +121 -0
- package/dist/wave3/process.d.ts +14 -0
- package/dist/wave3/process.js +84 -0
- package/dist/wave4/process.d.ts +14 -0
- package/dist/wave4/process.js +128 -0
- package/dist/workflow/render.d.ts +13 -0
- package/dist/workflow/render.js +31 -0
- package/dist/workflow/schema.d.ts +25 -0
- package/dist/workflow/schema.js +99 -0
- package/dist/workflow-auditor/audit.d.ts +27 -0
- package/dist/workflow-auditor/audit.js +583 -0
- package/dist/workflow-auditor/ledger-io.d.ts +5 -0
- package/dist/workflow-auditor/ledger-io.js +99 -0
- package/dist/workflow-auditor/skills-validator.d.ts +10 -0
- package/dist/workflow-auditor/skills-validator.js +533 -0
- package/dist/worktree-guard/evaluation.d.ts +19 -0
- package/dist/worktree-guard/evaluation.js +84 -0
- package/dist/worktree-guard/git.d.ts +3 -0
- package/dist/worktree-guard/git.js +61 -0
- package/package.json +32 -33
- package/src/bbc.ts +0 -39
- package/src/bigo/complexity.ts +0 -138
- package/src/bigo/functions.ts +0 -183
- package/src/bigo/keywords.ts +0 -41
- package/src/bigo/lexical.ts +0 -68
- package/src/bigo/source-files.ts +0 -80
- package/src/change-lane/classification.ts +0 -128
- package/src/change-lane/git.ts +0 -110
- package/src/classify-change-lane.ts +0 -140
- package/src/diff-scope/git-diff.ts +0 -161
- package/src/extract-diff-scope.ts +0 -130
- package/src/measure-bigo.ts +0 -86
- package/src/render-workflow.ts +0 -144
- package/src/workflow/render.ts +0 -40
- package/src/workflow/schema.ts +0 -141
|
@@ -0,0 +1,483 @@
|
|
|
1
|
+
const CODE_FENCE_RE = /```[\s\S]*?```/g;
|
|
2
|
+
const SPLIT_CLAUSE_RE = /\s+(?:o\s+(?:prefieres|quieres|mejor|lo|bien)|or\s+(?:would\s+you\s+(?:rather|like|prefer)|do\s+you\s+want|should\s+(?:i|we)|prefer))\b/i;
|
|
3
|
+
const CHOICE_CUE_RE = /(?:^|\n)\s*(?:si\s+quieres|puedes\s+elegir|elige\s+(?:una\s+)?opci[oó]n|if\s+you(?:'d|\s+would)?\s+like|choose\s+(?:an?\s+)?option|pick\s+(?:an?\s+)?option|what\s+would\s+you\s+like|next\s+steps?)\s*:/i;
|
|
4
|
+
const CHOICE_FIRST_ITEM_RE = /^\s*1\.\s+\S/m;
|
|
5
|
+
const CHOICE_SECOND_ITEM_RE = /^\s*2\.\s+\S/m;
|
|
6
|
+
const BOSS_GATE_MARKER_RE = /BOSS\s+GATE/i;
|
|
7
|
+
const BOSS_GATE_ROLES = ['PM', 'Tech Lead', 'Commit & PR', 'Code Owner', 'Release Owner'];
|
|
8
|
+
const BOSS_GATE_ROLE_NAMES = {
|
|
9
|
+
PM: 'Product Manager',
|
|
10
|
+
'Commit & PR': 'Tech Lead / Commit & PR authorization',
|
|
11
|
+
};
|
|
12
|
+
const BOSS_GATE_ROLE_RE = /BOSS\s+GATE\s*[─—–-]+\s*(Product Manager|PM|Tech Lead|Commit & PR|Code Owner|Release Owner)(?![\w&])/;
|
|
13
|
+
const BOSS_GATE_RECOMMENDED_RE = /(?:Recomendado|Recommended)\s*:/i;
|
|
14
|
+
const BOSS_GATE_OPTIONS_RE = /\[A\][\s\S]*\[B\]/;
|
|
15
|
+
const AND_SPLIT_RE = /\s+(?:y|e|and)\s+/i;
|
|
16
|
+
const DELEGABLE_RULES = [
|
|
17
|
+
{
|
|
18
|
+
skill: 'regression-testing',
|
|
19
|
+
role: 'QA Engineer',
|
|
20
|
+
stage: 'verify',
|
|
21
|
+
reason: 'Local verification, test execution, and bug reproduction belong to QA (regression-testing), never to the user.',
|
|
22
|
+
patterns: [
|
|
23
|
+
/\bprobar(?:lo)?(?:\s+primero)?\s+en\s+local\b/,
|
|
24
|
+
/\bproban?do\s+en\s+local\b/,
|
|
25
|
+
/\b(?:lo\s+)?prueb[ae]s?(?:\s+tu)?\s+primero\b/,
|
|
26
|
+
/\btest(?:ing)?(?:\s+it)?\s+(?:locally|first)(?:\s+first)?\b/,
|
|
27
|
+
/\bverify\s+locally\b/,
|
|
28
|
+
/\b(?:run|ejecut(?:o|e|a|ar|amos|emos)|corr(?:o|e|a|er|emos|amos)|pas(?:o|e|a|ar)|lanz(?:o|a|ar|amos)|lance|lancemos)\s+(?:los\s+|las\s+|el\s+|la\s+|the\s+)?(?:tests?|pruebas?|specs?|vitest|jest|pytest|build|suites?)\b/,
|
|
29
|
+
/\b(?:reproduc(?:e|en|ir|imos)|reproduzc(?:o|a|amos))\b/,
|
|
30
|
+
/\bverifi(?:car|que|quemos|co|camos)\s+(?:si\s+funciona|el\s+build)\b/,
|
|
31
|
+
/\bcheck\s+if\s+it\s+works\b/,
|
|
32
|
+
/\bsmoke\s*test\b/,
|
|
33
|
+
],
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
skill: 'code-quality-gate',
|
|
37
|
+
role: 'Software Engineer self-check',
|
|
38
|
+
stage: 'quality',
|
|
39
|
+
reason: 'Typecheck, lint, BigO, EarlyReturn, and TypeSafe checks belong to code-quality-gate.',
|
|
40
|
+
patterns: [
|
|
41
|
+
/\b(?:typecheck|lint(?:er)?|prettier|eslint|tsc)\b/,
|
|
42
|
+
/\bquality\s+gate\b/,
|
|
43
|
+
/\b(?:revis(?:o|a|e|ar|amos|emos)|check)\s+(?:la\s+)?calidad\b/,
|
|
44
|
+
/\b(?:early\s*return|type\s*safe|big\s*o)\b/,
|
|
45
|
+
],
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
skill: 'skill-clean-architecture',
|
|
49
|
+
role: 'Software Engineer',
|
|
50
|
+
stage: 'implement',
|
|
51
|
+
reason: 'Layer boundaries, DDD placement, and source headers belong to skill-clean-architecture.',
|
|
52
|
+
patterns: [
|
|
53
|
+
/\bclean\s+architecture\b/,
|
|
54
|
+
/\b(?:layer|capas)\s+(?:rules|headers|boundaries)\b/,
|
|
55
|
+
/\bsource\s+headers?\b/,
|
|
56
|
+
],
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
skill: 'documentation-steward',
|
|
60
|
+
role: 'Documentation Steward',
|
|
61
|
+
stage: 'docs',
|
|
62
|
+
reason: 'Auditing affected docs or finding the canonical page belongs to documentation-steward.',
|
|
63
|
+
patterns: [
|
|
64
|
+
/\b(?:actuali(?:zar|ce|cemos|zo|za)|update|revis(?:o|a|e|ar|amos|emos)|check|audit(?:ar|e|emos|o|a)?)\s+(?:si\s+)?(?:la\s+|el\s+|the\s+)?(?:docs?|documentacion|documentation|readme|wiki)\b/,
|
|
65
|
+
/\b(?:docs?|documentacion|documentation)\s+(?:(?:fue|esta|este|ha\s+sido)\s+)?afectad/,
|
|
66
|
+
],
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
skill: 'risk-scout',
|
|
70
|
+
role: 'SRE / Staff Engineer',
|
|
71
|
+
stage: 'residual_risk',
|
|
72
|
+
reason: 'Failure modes, rollout risk, and edge-case premortems belong to risk-scout.',
|
|
73
|
+
patterns: [
|
|
74
|
+
/\b(?:que|what)\s+(?:puede|podria|could)\s+(?:fallar|break|fail)\b/,
|
|
75
|
+
/\b(?:riesgos?|risk\s+matrix|residual\s+risk|premortem)\b/,
|
|
76
|
+
],
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
skill: 'greptile-review-loop',
|
|
80
|
+
role: 'AI Code Reviewer',
|
|
81
|
+
stage: 'review',
|
|
82
|
+
reason: 'Triggering or reconciling Greptile review comments and 5/5 status belongs to greptile-review-loop.',
|
|
83
|
+
patterns: [
|
|
84
|
+
/\bgreptile\b/,
|
|
85
|
+
/\b5\/5\b/,
|
|
86
|
+
/\b(?:comentarios|comments|threads)\s+(?:del\s+|of\s+the\s+|en\s+el\s+)?pr\b/,
|
|
87
|
+
/\b(?:comentarios\s+de\s+(?:la\s+)?revision|review\s+comments)\b/,
|
|
88
|
+
],
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
skill: 'workflow-auditor',
|
|
92
|
+
role: 'Process Auditor',
|
|
93
|
+
stage: 'audit',
|
|
94
|
+
reason: 'Checking diagram order, delivery ledger, and Tool Depot compliance belongs to workflow-auditor.',
|
|
95
|
+
patterns: [
|
|
96
|
+
/\b(?:audit(?:ar|e|emos)?|audit)\s+(?:el\s+|the\s+|si\s+el\s+ledger\s+)?(?:workflow|flujo|ledger)\b/,
|
|
97
|
+
/\bcumple\s+(?:con\s+)?(?:el\s+)?(?:diagrama|workflow|flujo)\b/,
|
|
98
|
+
],
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
skill: 'watcher-observability',
|
|
102
|
+
role: 'SRE on call',
|
|
103
|
+
stage: 'observe',
|
|
104
|
+
reason: 'Reading sanitized logs or container telemetry belongs to watcher-observability (via tool-depot).',
|
|
105
|
+
patterns: [
|
|
106
|
+
/\b(?:ver|veo|revis(?:o|a|e|ar|amos|emos)|check|read)\s+(?:los\s+|the\s+)?(?:docker\s+)?logs\b/,
|
|
107
|
+
/\bsleuth\b/,
|
|
108
|
+
/\b(?:docker\s+ps|contenedores|containers)\b/,
|
|
109
|
+
],
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
skill: 'tool-depot',
|
|
113
|
+
role: 'Tool Depot',
|
|
114
|
+
stage: 'external_tool',
|
|
115
|
+
reason: 'Checking duplicate issues, reading existing GitHub artifacts, or verifying public docs routes through tool-depot.',
|
|
116
|
+
patterns: [
|
|
117
|
+
/\b(?:issues?\s+duplicad\w*|duplicate\s+issues?)\b/,
|
|
118
|
+
/\b(?:bus(?:car|que)|check|read|le[ae]r?)\s+(?:la\s+|el\s+|the\s+)?(?:issue|pr|wiki)\b/,
|
|
119
|
+
],
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
skill: 'delivery-coordinator',
|
|
123
|
+
role: 'Tech Lead',
|
|
124
|
+
stage: 'coordinate',
|
|
125
|
+
reason: 'Choosing the next workflow stage from handoff contracts belongs to delivery-coordinator.',
|
|
126
|
+
patterns: [
|
|
127
|
+
/\b(?:que|cual)\s+(?:sigue|hacemos\s+ahora|paso\s+sigue|skill\s+uso)\b/,
|
|
128
|
+
/\bcomo\s+(?:procedo|continuo|seguimos)\b/,
|
|
129
|
+
/\bwhat\s+(?:should\s+(?:i|we)\s+do\s+next|is\s+next|comes\s+next)\b/,
|
|
130
|
+
],
|
|
131
|
+
},
|
|
132
|
+
];
|
|
133
|
+
const COMMIT_PR_PATTERNS = [
|
|
134
|
+
/\b(?:hacer|haga|hago|hagamos|make|create|crear|cre[ae]|creo)\s+(?:el\s+|the\s+|un\s+)?commit\b/,
|
|
135
|
+
/\b(?:abrir|abra|abro|abramos|open|create|crear|cre[ae]|creo|subir|suba|subo|push)\s+(?:el\s+|the\s+|la\s+|un\s+|una\s+|an?\s+)?(?:pr|pull\s+request)\b/,
|
|
136
|
+
/\b(?:crear|cree|creo|creemos|create|abrir|abra|abro|open|publicar|publique|publico|publish)\s+(?:la\s+|el\s+|the\s+|an?\s+)?issue\b/,
|
|
137
|
+
/\bcommit(?:\s+and|\s+y|\s*,\s*)?\s*(?:push|pr|pull\s+request)\b/,
|
|
138
|
+
];
|
|
139
|
+
const ALWAYS_HUMAN_RULES = [
|
|
140
|
+
{
|
|
141
|
+
owner: 'Code Owner',
|
|
142
|
+
stage: 'code_owner',
|
|
143
|
+
reason: 'Merging or approving a PR as Code Owner always requires a person.',
|
|
144
|
+
patterns: [
|
|
145
|
+
/\b(?:hacer|hago|haga|hagamos|hacemos|make)\s+(?:el\s+)?merge\b/,
|
|
146
|
+
/\b(?:merge|mergeo|mergea|mergear|mergeamos|fusiono|fusiona|fusionar)\s+(?:el\s+|the\s+)?(?:pr|pull\s+request)\b/,
|
|
147
|
+
/\bapprove\s+and\s+merge\b/,
|
|
148
|
+
],
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
owner: 'Release Owner',
|
|
152
|
+
stage: 'release_owner',
|
|
153
|
+
reason: 'Production deployment decisions always belong to the human Release Owner.',
|
|
154
|
+
patterns: [
|
|
155
|
+
/\b(?:deploy|desplegar|despliego|despliegue|despliega|desplegamos|despleguemos|hacer\s+deploy|release\s+to\s+prod|subir\s+a\s+produccion)\b/,
|
|
156
|
+
],
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
owner: 'Product Manager',
|
|
160
|
+
stage: 'specify',
|
|
161
|
+
reason: 'Open product or UX decisions belong to the human Product Manager (via requirements-spec Open Decision Question Format).',
|
|
162
|
+
patterns: [
|
|
163
|
+
/\b(?:decision\s+de\s+producto|product\s+decision|comportamiento\s+esperado)\b/,
|
|
164
|
+
/\b(?:nueva\s+pestana|new\s+tab|misma\s+pestana|same\s+tab)\b/,
|
|
165
|
+
],
|
|
166
|
+
},
|
|
167
|
+
];
|
|
168
|
+
function stripAccents(text) {
|
|
169
|
+
return text.normalize('NFKD').replace(/\p{M}/gu, '');
|
|
170
|
+
}
|
|
171
|
+
function normalizeText(text) {
|
|
172
|
+
return stripAccents(text).toLowerCase().trim();
|
|
173
|
+
}
|
|
174
|
+
function matchesAny(text, patterns) {
|
|
175
|
+
return patterns.some((pattern) => pattern.test(text));
|
|
176
|
+
}
|
|
177
|
+
function extractQuestions(rawText) {
|
|
178
|
+
const cleaned = (rawText || '').replace(CODE_FENCE_RE, ' ').trim();
|
|
179
|
+
if (cleaned === '')
|
|
180
|
+
return [];
|
|
181
|
+
if (!cleaned.includes('?') && !cleaned.includes('¿'))
|
|
182
|
+
return [];
|
|
183
|
+
const parts = cleaned.split(/(?<=[?\n])\s+/);
|
|
184
|
+
const questions = parts.map((part) => part.trim()).filter((part) => part.includes('?') || part.includes('¿'));
|
|
185
|
+
return questions.length > 0 ? questions : [cleaned];
|
|
186
|
+
}
|
|
187
|
+
function splitClauses(question) {
|
|
188
|
+
const trimmed = question.trim().replace(/^¿+/, '').replace(/\?+$/, '').trim();
|
|
189
|
+
if (trimmed === '')
|
|
190
|
+
return [];
|
|
191
|
+
const rawClauses = trimmed.split(SPLIT_CLAUSE_RE);
|
|
192
|
+
const clauses = [];
|
|
193
|
+
for (const chunk of rawClauses) {
|
|
194
|
+
const piece = chunk.replace(/^[ ,;:.¿?]+|[ ,;:.¿?]+$/g, '');
|
|
195
|
+
if (piece !== '')
|
|
196
|
+
clauses.push(piece);
|
|
197
|
+
}
|
|
198
|
+
return clauses;
|
|
199
|
+
}
|
|
200
|
+
export function extractLedgerState(ledger) {
|
|
201
|
+
if (ledger === null) {
|
|
202
|
+
return { present: false, commit_authorized: false, missing_prereqs: [] };
|
|
203
|
+
}
|
|
204
|
+
let commitAuthorized = false;
|
|
205
|
+
if (Array.isArray(ledger.authorizations)) {
|
|
206
|
+
for (const auth of ledger.authorizations) {
|
|
207
|
+
if (typeof auth !== 'object' || auth === null || Array.isArray(auth))
|
|
208
|
+
continue;
|
|
209
|
+
const obj = auth;
|
|
210
|
+
if (obj.by === 'person' && Array.isArray(obj.covers) && obj.covers.includes('commit_pr')) {
|
|
211
|
+
commitAuthorized = true;
|
|
212
|
+
break;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
const names = [];
|
|
217
|
+
if (Array.isArray(ledger.stages)) {
|
|
218
|
+
for (const stage of ledger.stages) {
|
|
219
|
+
if (typeof stage === 'object' && stage !== null && !Array.isArray(stage)) {
|
|
220
|
+
names.push(stage.stage);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
const lastImplement = names.lastIndexOf('implement');
|
|
225
|
+
const afterImpl = lastImplement >= 0 ? names.slice(lastImplement + 1) : [];
|
|
226
|
+
const missingPrereqs = [];
|
|
227
|
+
if (!afterImpl.includes('verify'))
|
|
228
|
+
missingPrereqs.push('regression-testing');
|
|
229
|
+
if (!afterImpl.includes('quality'))
|
|
230
|
+
missingPrereqs.push('code-quality-gate');
|
|
231
|
+
return {
|
|
232
|
+
present: true,
|
|
233
|
+
commit_authorized: commitAuthorized,
|
|
234
|
+
missing_prereqs: missingPrereqs,
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
function classifyClause(clause, state) {
|
|
238
|
+
const norm = normalizeText(clause);
|
|
239
|
+
for (const rule of DELEGABLE_RULES) {
|
|
240
|
+
if (matchesAny(norm, rule.patterns)) {
|
|
241
|
+
return {
|
|
242
|
+
clause,
|
|
243
|
+
disposition: 'delegate_to_skill',
|
|
244
|
+
resolved_by: rule.skill,
|
|
245
|
+
role: rule.role,
|
|
246
|
+
stage: rule.stage,
|
|
247
|
+
reason: rule.reason,
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
if (matchesAny(norm, COMMIT_PR_PATTERNS)) {
|
|
252
|
+
if (state.present && state.missing_prereqs.length > 0) {
|
|
253
|
+
const firstSkill = state.missing_prereqs[0];
|
|
254
|
+
return {
|
|
255
|
+
clause,
|
|
256
|
+
disposition: 'delegate_to_skill',
|
|
257
|
+
resolved_by: firstSkill,
|
|
258
|
+
role: 'QA Engineer / Software Engineer',
|
|
259
|
+
stage: firstSkill === 'regression-testing' ? 'verify' : 'quality',
|
|
260
|
+
reason: `Do not ask to commit or open a PR before prerequisites pass: run ${state.missing_prereqs.join(', ')} first.`,
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
if (state.commit_authorized) {
|
|
264
|
+
return {
|
|
265
|
+
clause,
|
|
266
|
+
disposition: 'already_authorized',
|
|
267
|
+
resolved_by: 'delivery-coordinator',
|
|
268
|
+
role: 'Tech Lead',
|
|
269
|
+
stage: 'commit_pr',
|
|
270
|
+
reason: 'The delivery ledger already records a person authorization covering commit_pr; execute Commit & PR without asking again.',
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
return {
|
|
274
|
+
clause,
|
|
275
|
+
disposition: 'human_approval_required',
|
|
276
|
+
resolved_by: 'person',
|
|
277
|
+
role: 'Tech Lead / Commit & PR authorization',
|
|
278
|
+
stage: 'commit_pr',
|
|
279
|
+
reason: 'Commit, issue publication, and PR creation require explicit person authorization when not yet granted in the session or ledger.',
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
for (const rule of ALWAYS_HUMAN_RULES) {
|
|
283
|
+
if (matchesAny(norm, rule.patterns)) {
|
|
284
|
+
return {
|
|
285
|
+
clause,
|
|
286
|
+
disposition: 'human_approval_required',
|
|
287
|
+
resolved_by: 'person',
|
|
288
|
+
role: rule.owner,
|
|
289
|
+
stage: rule.stage,
|
|
290
|
+
reason: rule.reason,
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
return {
|
|
295
|
+
clause,
|
|
296
|
+
disposition: 'needs_classification',
|
|
297
|
+
resolved_by: 'person',
|
|
298
|
+
role: 'Unclassified',
|
|
299
|
+
stage: 'unknown',
|
|
300
|
+
reason: `No diagram skill or human rule matched. Route it to its owning skill, or declare the human owner with a 🟡 BOSS GATE ─ <Role> header (${BOSS_GATE_ROLES.join(', ')}).`,
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
function ownerOf(item) {
|
|
304
|
+
return item.resolved_by !== 'person' ? item.resolved_by : item.role;
|
|
305
|
+
}
|
|
306
|
+
function classifyCompound(clause, state) {
|
|
307
|
+
const whole = classifyClause(clause, state);
|
|
308
|
+
const parts = clause
|
|
309
|
+
.split(AND_SPLIT_RE)
|
|
310
|
+
.map((part) => part.replace(/^[ ,;:.]+|[ ,;:.]+$/g, ''))
|
|
311
|
+
.filter((part) => part !== '');
|
|
312
|
+
if (parts.length < 2)
|
|
313
|
+
return [whole];
|
|
314
|
+
const items = parts.map((part) => classifyClause(part, state));
|
|
315
|
+
if (items.some((item) => item.stage === 'unknown'))
|
|
316
|
+
return [whole];
|
|
317
|
+
if (new Set(items.map(ownerOf)).size < 2)
|
|
318
|
+
return [whole];
|
|
319
|
+
return items;
|
|
320
|
+
}
|
|
321
|
+
function hasChoiceOffer(rawText) {
|
|
322
|
+
const cleaned = (rawText || '').replace(CODE_FENCE_RE, ' ');
|
|
323
|
+
if (!CHOICE_CUE_RE.test(cleaned))
|
|
324
|
+
return false;
|
|
325
|
+
const hasNumbered = CHOICE_FIRST_ITEM_RE.test(cleaned) && CHOICE_SECOND_ITEM_RE.test(cleaned);
|
|
326
|
+
const hasLettered = cleaned.includes('[A]') && cleaned.includes('[B]');
|
|
327
|
+
return hasNumbered || hasLettered;
|
|
328
|
+
}
|
|
329
|
+
function hasBossGateFormat(rawText) {
|
|
330
|
+
const text = rawText || '';
|
|
331
|
+
return BOSS_GATE_MARKER_RE.test(text) && BOSS_GATE_RECOMMENDED_RE.test(text) && BOSS_GATE_OPTIONS_RE.test(text);
|
|
332
|
+
}
|
|
333
|
+
export function evaluateQuestionText(rawText, ledger = null, requireHud = false) {
|
|
334
|
+
const questions = extractQuestions(rawText);
|
|
335
|
+
if (questions.length === 0) {
|
|
336
|
+
if (requireHud && hasChoiceOffer(rawText) && !hasBossGateFormat(rawText)) {
|
|
337
|
+
return {
|
|
338
|
+
verdict: 'block_format',
|
|
339
|
+
ledger_checked: ledger !== null,
|
|
340
|
+
clauses: [],
|
|
341
|
+
resolved_by: [],
|
|
342
|
+
human_gates: [],
|
|
343
|
+
hud_format_ok: false,
|
|
344
|
+
rewrite_suggestion: 'Format this decision or choice prompt with the Quest-Tree HUD and a compact ' +
|
|
345
|
+
'🟡 BOSS GATE (🟡 BOSS GATE ─ <Role>, ❓ question, 👉 Recomendado: [A], ' +
|
|
346
|
+
'⚡ Opciones with [A]/[B]) before stopping.',
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
return {
|
|
350
|
+
verdict: 'no_question',
|
|
351
|
+
ledger_checked: ledger !== null,
|
|
352
|
+
clauses: [],
|
|
353
|
+
resolved_by: [],
|
|
354
|
+
human_gates: [],
|
|
355
|
+
hud_format_ok: true,
|
|
356
|
+
rewrite_suggestion: null,
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
const state = extractLedgerState(ledger);
|
|
360
|
+
const classified = [];
|
|
361
|
+
for (const question of questions) {
|
|
362
|
+
for (const clause of splitClauses(question)) {
|
|
363
|
+
classified.push(...classifyCompound(clause, state));
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
const declared = BOSS_GATE_ROLE_RE.exec(rawText || '');
|
|
367
|
+
if (declared !== null) {
|
|
368
|
+
const matchedRole = declared[1];
|
|
369
|
+
const role = BOSS_GATE_ROLE_NAMES[matchedRole] ?? matchedRole;
|
|
370
|
+
for (const item of classified) {
|
|
371
|
+
if (item.disposition === 'needs_classification') {
|
|
372
|
+
item.disposition = 'human_approval_required';
|
|
373
|
+
item.role = role;
|
|
374
|
+
item.stage = 'declared';
|
|
375
|
+
item.reason = 'Owner declared by the 🟡 BOSS GATE header.';
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
const unclassified = classified.filter((item) => item.disposition === 'needs_classification');
|
|
380
|
+
const blocked = classified.filter((item) => item.disposition === 'delegate_to_skill' || item.disposition === 'already_authorized');
|
|
381
|
+
const humanGates = classified.filter((item) => item.disposition === 'human_approval_required');
|
|
382
|
+
const resolvedBy = [];
|
|
383
|
+
const seenResolvedBy = new Set();
|
|
384
|
+
for (const item of blocked) {
|
|
385
|
+
if (!seenResolvedBy.has(item.resolved_by)) {
|
|
386
|
+
seenResolvedBy.add(item.resolved_by);
|
|
387
|
+
resolvedBy.push(item.resolved_by);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
const hudOk = hasBossGateFormat(rawText);
|
|
391
|
+
let verdict;
|
|
392
|
+
let rewriteSuggestion;
|
|
393
|
+
if (unclassified.length > 0 && blocked.length === 0) {
|
|
394
|
+
verdict = 'block_question';
|
|
395
|
+
rewriteSuggestion =
|
|
396
|
+
`Unclassified question: ${unclassified.map((c) => c.clause).join('; ')}. ` +
|
|
397
|
+
'Route it to the skill that owns it, or, if a person must decide, declare the owner with a ' +
|
|
398
|
+
`🟡 BOSS GATE ─ <Role> header (${BOSS_GATE_ROLES.join(', ')}).`;
|
|
399
|
+
}
|
|
400
|
+
else if (blocked.length > 0) {
|
|
401
|
+
verdict = 'block_question';
|
|
402
|
+
if (humanGates.length > 0) {
|
|
403
|
+
rewriteSuggestion =
|
|
404
|
+
`Do not ask the blocked clause(s) (${resolvedBy.join(', ')}). ` +
|
|
405
|
+
'Run/resolve those diagram stages first; only ask the remaining human approval: ' +
|
|
406
|
+
humanGates.map((g) => g.clause).join('; ');
|
|
407
|
+
}
|
|
408
|
+
else {
|
|
409
|
+
rewriteSuggestion = `Do not ask the user. Resolve directly with: ${resolvedBy.join(', ')}.`;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
else if (requireHud && !hudOk) {
|
|
413
|
+
verdict = 'block_format';
|
|
414
|
+
rewriteSuggestion =
|
|
415
|
+
'Format the human decision with the Quest-Tree HUD (`🎮 QUEST ACTUAL` when in a quest) ' +
|
|
416
|
+
'and a compact `🟡 BOSS GATE` (`🟡 BOSS GATE ─ <Role>`, `❓`, `👉 Recomendado: [A]`, ' +
|
|
417
|
+
'`⚡ Opciones` with `[A]`/`[B]`) before stopping.';
|
|
418
|
+
}
|
|
419
|
+
else {
|
|
420
|
+
verdict = 'allow_question';
|
|
421
|
+
rewriteSuggestion = null;
|
|
422
|
+
}
|
|
423
|
+
return {
|
|
424
|
+
verdict,
|
|
425
|
+
ledger_checked: ledger !== null,
|
|
426
|
+
clauses: classified,
|
|
427
|
+
resolved_by: resolvedBy,
|
|
428
|
+
human_gates: humanGates.map((g) => ({ clause: g.clause, role: g.role, stage: g.stage })),
|
|
429
|
+
hud_format_ok: hudOk,
|
|
430
|
+
rewrite_suggestion: rewriteSuggestion,
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
function escapeAscii(text) {
|
|
434
|
+
return text.replace(/[\u007f-\uffff]/g, (char) => `\\u${char.charCodeAt(0).toString(16).padStart(4, '0')}`);
|
|
435
|
+
}
|
|
436
|
+
export function pythonJsonCompact(value) {
|
|
437
|
+
if (value === null || typeof value !== 'object')
|
|
438
|
+
return escapeAscii(JSON.stringify(value));
|
|
439
|
+
if (Array.isArray(value))
|
|
440
|
+
return `[${value.map(pythonJsonCompact).join(', ')}]`;
|
|
441
|
+
const entries = Object.entries(value);
|
|
442
|
+
return `{${entries.map(([key, val]) => `${escapeAscii(JSON.stringify(key))}: ${pythonJsonCompact(val)}`).join(', ')}}`;
|
|
443
|
+
}
|
|
444
|
+
function blockReason(report) {
|
|
445
|
+
if (report.resolved_by.length === 0) {
|
|
446
|
+
return `Question Gate: ${report.rewrite_suggestion ?? ''}`.trim();
|
|
447
|
+
}
|
|
448
|
+
return `Question Gate: resolve via diagram skill(s) [${report.resolved_by.join(', ')}] before asking the user. ${report.rewrite_suggestion ?? ''}`.trim();
|
|
449
|
+
}
|
|
450
|
+
export function formatTriageOutput(report, format) {
|
|
451
|
+
if (format === 'cursor-hook') {
|
|
452
|
+
if (report.verdict === 'block_question') {
|
|
453
|
+
return pythonJsonCompact({
|
|
454
|
+
followup_message: `Question Gate blocked stopping to ask the user. ${report.rewrite_suggestion ?? ''}`.trim(),
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
if (report.verdict === 'block_format') {
|
|
458
|
+
return pythonJsonCompact({
|
|
459
|
+
followup_message: `Question Gate blocked stopping: missing Quest-Tree HUD / 🟡 BOSS GATE format. ${report.rewrite_suggestion ?? ''}`.trim(),
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
return '{}';
|
|
463
|
+
}
|
|
464
|
+
if (format === 'claude-hook' || format === 'codex-hook') {
|
|
465
|
+
if (report.verdict === 'block_question') {
|
|
466
|
+
return pythonJsonCompact({ decision: 'block', reason: blockReason(report) });
|
|
467
|
+
}
|
|
468
|
+
if (report.verdict === 'block_format') {
|
|
469
|
+
return pythonJsonCompact({ decision: 'block', reason: `Question Gate: ${report.rewrite_suggestion ?? ''}`.trim() });
|
|
470
|
+
}
|
|
471
|
+
return '{}';
|
|
472
|
+
}
|
|
473
|
+
if (format === 'gemini-hook') {
|
|
474
|
+
if (report.verdict === 'block_question') {
|
|
475
|
+
return pythonJsonCompact({ decision: 'deny', reason: blockReason(report) });
|
|
476
|
+
}
|
|
477
|
+
if (report.verdict === 'block_format') {
|
|
478
|
+
return pythonJsonCompact({ decision: 'deny', reason: `Question Gate: ${report.rewrite_suggestion ?? ''}`.trim() });
|
|
479
|
+
}
|
|
480
|
+
return '{}';
|
|
481
|
+
}
|
|
482
|
+
return JSON.stringify(report, null, 2);
|
|
483
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function inferBoardStatus(item: Record<string, unknown>, statusOptions: readonly Record<string, unknown>[]): Record<string, unknown> | null;
|
|
2
|
+
export declare function inferRepoLabel(title: string | null | undefined, existingLabels: readonly string[]): string | null;
|
|
3
|
+
export declare function summarizeProjectBoard(projectData: Record<string, unknown> | null | undefined, activityItems?: readonly Record<string, unknown>[], defaultRepo?: string | null): Record<string, unknown>;
|
|
4
|
+
export declare function planBoardSync(boardSummary: Record<string, unknown>, projectMeta: Record<string, unknown>, fixColors?: boolean): Record<string, unknown>;
|
|
5
|
+
export declare function applyBoardSync(plan: Record<string, unknown>, dryRun?: boolean, applyLabels?: boolean): Record<string, unknown>;
|