oxe-cc 1.22.0 → 1.22.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/.cursor/commands/oxe-discuss.md +45 -45
- package/.cursor/commands/oxe-execute.md +52 -52
- package/.cursor/commands/oxe-help.md +44 -44
- package/.cursor/commands/oxe-next.md +44 -44
- package/.cursor/commands/oxe-plan.md +49 -49
- package/.cursor/commands/oxe-quick.md +49 -49
- package/.cursor/commands/oxe-review-pr.md +47 -47
- package/.cursor/commands/oxe-scan.md +47 -47
- package/.cursor/commands/oxe-ship.md +47 -47
- package/.cursor/commands/oxe-spec.md +49 -49
- package/.cursor/commands/oxe-verify.md +50 -50
- package/.cursor/commands/oxe.md +51 -51
- package/.github/prompts/oxe-alm.prompt.md +47 -47
- package/.github/prompts/oxe-ask.prompt.md +47 -47
- package/.github/prompts/oxe-capabilities.prompt.md +47 -47
- package/.github/prompts/oxe-checkpoint.prompt.md +47 -47
- package/.github/prompts/oxe-compact.prompt.md +46 -46
- package/.github/prompts/oxe-dashboard.prompt.md +47 -47
- package/.github/prompts/oxe-debug.prompt.md +47 -47
- package/.github/prompts/oxe-discuss.prompt.md +47 -47
- package/.github/prompts/oxe-execute.prompt.md +52 -52
- package/.github/prompts/oxe-forensics.prompt.md +47 -47
- package/.github/prompts/oxe-help.prompt.md +46 -46
- package/.github/prompts/oxe-loop.prompt.md +47 -47
- package/.github/prompts/oxe-milestone.prompt.md +47 -47
- package/.github/prompts/oxe-next.prompt.md +46 -46
- package/.github/prompts/oxe-obs.prompt.md +47 -47
- package/.github/prompts/oxe-plan-agent.prompt.md +46 -46
- package/.github/prompts/oxe-plan.prompt.md +49 -49
- package/.github/prompts/oxe-project.prompt.md +47 -47
- package/.github/prompts/oxe-quick.prompt.md +49 -49
- package/.github/prompts/oxe-research.prompt.md +47 -47
- package/.github/prompts/oxe-retro.prompt.md +47 -47
- package/.github/prompts/oxe-review-pr.prompt.md +47 -47
- package/.github/prompts/oxe-route.prompt.md +47 -47
- package/.github/prompts/oxe-scan.prompt.md +47 -47
- package/.github/prompts/oxe-security.prompt.md +47 -47
- package/.github/prompts/oxe-session.prompt.md +47 -47
- package/.github/prompts/oxe-ship.prompt.md +47 -47
- package/.github/prompts/oxe-skill.prompt.md +47 -47
- package/.github/prompts/oxe-spec.prompt.md +49 -49
- package/.github/prompts/oxe-ui-review.prompt.md +47 -47
- package/.github/prompts/oxe-ui-spec.prompt.md +47 -47
- package/.github/prompts/oxe-update.prompt.md +46 -46
- package/.github/prompts/oxe-validate-gaps.prompt.md +47 -47
- package/.github/prompts/oxe-verify.prompt.md +50 -50
- package/.github/prompts/oxe-workstream.prompt.md +47 -47
- package/.github/prompts/oxe.prompt.md +51 -51
- package/.github/workflows/release.yml +31 -0
- package/CHANGELOG.md +88 -0
- package/README.md +1 -1
- package/bin/lib/commands/ops-commands.cjs +751 -0
- package/bin/lib/commands/spec-program-commands.cjs +337 -0
- package/bin/lib/operational/alm-refine-runtime.cjs +791 -0
- package/bin/lib/operational/child-env.cjs +52 -0
- package/bin/lib/operational/promote-runtime.cjs +1187 -0
- package/bin/lib/oxe-agent-coord.cjs +246 -0
- package/bin/lib/oxe-alm-refine.cjs +97 -1
- package/bin/lib/oxe-ci-adapter.cjs +304 -0
- package/bin/lib/oxe-complexity.cjs +1 -1
- package/bin/lib/oxe-decisions.cjs +9 -3
- package/bin/lib/oxe-dir-info.cjs +20 -1
- package/bin/lib/oxe-env-sanitize.cjs +6 -1
- package/bin/lib/oxe-git-root.cjs +97 -0
- package/bin/lib/oxe-grill.cjs +90 -1
- package/bin/lib/oxe-onboard.cjs +640 -0
- package/bin/lib/oxe-operational.cjs +14481 -15949
- package/bin/lib/oxe-origin.cjs +4 -1
- package/bin/lib/oxe-phase-gates.cjs +139 -2
- package/bin/lib/oxe-plan-build.cjs +62 -2
- package/bin/lib/oxe-plan-mutate.cjs +108 -2
- package/bin/lib/oxe-preflight.cjs +9 -3
- package/bin/lib/oxe-presets.cjs +216 -0
- package/bin/lib/oxe-project-env.cjs +79 -0
- package/bin/lib/oxe-project-health.cjs +2 -0
- package/bin/lib/oxe-reevaluate.cjs +198 -0
- package/bin/lib/oxe-release-ops.cjs +51 -15
- package/bin/lib/oxe-scorecard.cjs +394 -1
- package/bin/lib/oxe-ship-pr.cjs +72 -4
- package/bin/lib/oxe-spec-check.cjs +32 -0
- package/bin/lib/oxe-suite-impact.cjs +1160 -1145
- package/bin/lib/oxe-sync.cjs +99 -2
- package/bin/lib/oxe-verify-cache.cjs +132 -0
- package/bin/lib/oxe-vitest-batch.cjs +10 -3
- package/bin/lib/oxe-worktree-gc.cjs +655 -170
- package/bin/oxe-cc.js +10042 -10669
- package/commands/oxe/alm.md +54 -54
- package/commands/oxe/ask.md +55 -55
- package/commands/oxe/capabilities.md +50 -50
- package/commands/oxe/checkpoint.md +53 -53
- package/commands/oxe/compact.md +47 -47
- package/commands/oxe/dashboard.md +51 -51
- package/commands/oxe/debug.md +58 -58
- package/commands/oxe/discuss.md +58 -58
- package/commands/oxe/execute.md +63 -63
- package/commands/oxe/forensics.md +53 -53
- package/commands/oxe/help.md +48 -48
- package/commands/oxe/loop.md +54 -54
- package/commands/oxe/milestone.md +53 -53
- package/commands/oxe/next.md +49 -49
- package/commands/oxe/obs.md +53 -53
- package/commands/oxe/oxe.md +55 -55
- package/commands/oxe/plan-agent.md +57 -57
- package/commands/oxe/plan.md +59 -59
- package/commands/oxe/project.md +53 -53
- package/commands/oxe/quick.md +53 -53
- package/commands/oxe/research.md +53 -53
- package/commands/oxe/retro.md +53 -53
- package/commands/oxe/review-pr.md +53 -53
- package/commands/oxe/route.md +48 -48
- package/commands/oxe/scan.md +58 -58
- package/commands/oxe/security.md +53 -53
- package/commands/oxe/session.md +53 -53
- package/commands/oxe/ship.md +53 -53
- package/commands/oxe/skill.md +53 -53
- package/commands/oxe/spec.md +59 -59
- package/commands/oxe/ui-review.md +53 -53
- package/commands/oxe/ui-spec.md +53 -53
- package/commands/oxe/update.md +53 -53
- package/commands/oxe/validate-gaps.md +53 -53
- package/commands/oxe/verify-audit.md +50 -50
- package/commands/oxe/verify.md +60 -60
- package/commands/oxe/workflow-authoring.md +50 -50
- package/commands/oxe/workstream.md +53 -53
- package/docs/RELEASE-READINESS.md +7 -1
- package/docs/adr/D-1-isolamento-read-only-e-sanitizacao-centralizada-de-env-vars.md +29 -29
- package/docs/adr/D-2-junction-segura-de-node-modules-condicionada-a-sha-256-de-pa.md +29 -29
- package/docs/adr/D-3-preflight-local-5s-impacto-estatico-e2e-e-leitura-explicita.md +29 -29
- package/docs/adr/D-4-governanca-de-release-unificada-retomada-idempotente-pos-rei.md +29 -29
- package/docs/adr/D-5-core-agnostico-vs-presets-declarativos-de-dominio.md +29 -0
- package/docs/adr/D-6-decomposicao-strangler-fig-de-oxe-cc-e-oxe-operational.md +29 -0
- package/docs/adr/D-7-paridade-pre-push-com-phase-gates-path-aware-json-compacto-e.md +28 -0
- package/docs/adr/D-F1F4-1-paridade-pre-push-compactacao-json-sync-version-pins-e-quali.md +44 -0
- package/docs/adr/README.md +18 -14
- package/lib/runtime/verification/verification-compiler.d.ts +12 -1
- package/lib/runtime/verification/verification-compiler.js +235 -65
- package/oxe/templates/CONFIG.md +14 -1
- package/oxe/workflows/help.md +3 -0
- package/oxe/workflows/lean/execute.md +2 -1
- package/oxe/workflows/ship.md +4 -2
- package/package.json +4 -4
- package/packages/runtime/package.json +1 -1
- package/packages/runtime/src/verification/verification-compiler.ts +193 -25
- package/packages/runtime/tsconfig.json +1 -0
- package/vscode-extension/package.json +1 -1
|
@@ -218,6 +218,210 @@ function computeScorecard(input = {}) {
|
|
|
218
218
|
};
|
|
219
219
|
}
|
|
220
220
|
|
|
221
|
+
function readNdjsonQuiet(file) {
|
|
222
|
+
try {
|
|
223
|
+
return fs.readFileSync(file, 'utf8')
|
|
224
|
+
.split(/\r?\n/)
|
|
225
|
+
.filter(Boolean)
|
|
226
|
+
.map((l) => {
|
|
227
|
+
try { return JSON.parse(l); } catch { return null; }
|
|
228
|
+
})
|
|
229
|
+
.filter(Boolean);
|
|
230
|
+
} catch {
|
|
231
|
+
return [];
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* 1.22.2 (OXB-222-08): Offline CI rework & leadtime breakdown from local `.oxe/` records
|
|
237
|
+
* (`ci.ndjson` + `events.ndjson` / `OXE-EVENTS.ndjson`). Zero network or `gh` calls.
|
|
238
|
+
*
|
|
239
|
+
* @param {string} projectRoot
|
|
240
|
+
* @param {{ activeSession?: string|null, since?: string|null, events?: object[] }} [options]
|
|
241
|
+
*/
|
|
242
|
+
function computeLeadtimeAndCiMetrics(projectRoot, options = {}) {
|
|
243
|
+
let since = null;
|
|
244
|
+
if (options.since) {
|
|
245
|
+
const d = new Date(options.since);
|
|
246
|
+
if (Number.isNaN(d.getTime())) throw new Error(`scorecard: data --since inválida (${options.since})`);
|
|
247
|
+
since = d.toISOString();
|
|
248
|
+
}
|
|
249
|
+
const after = (ts) => !since || String(ts || '') >= since;
|
|
250
|
+
|
|
251
|
+
// 1. Collect CI records from session program dir (when set) and root `.oxe/program/ci.ndjson`
|
|
252
|
+
const ciCandidates = [];
|
|
253
|
+
if (options.activeSession) {
|
|
254
|
+
ciCandidates.push(path.join(projectRoot, '.oxe', options.activeSession, 'program', 'ci.ndjson'));
|
|
255
|
+
}
|
|
256
|
+
ciCandidates.push(path.join(projectRoot, '.oxe', 'program', 'ci.ndjson'));
|
|
257
|
+
const seenCiPaths = new Set();
|
|
258
|
+
const ciRuns = [];
|
|
259
|
+
for (const candidate of ciCandidates) {
|
|
260
|
+
const resolved = path.resolve(candidate);
|
|
261
|
+
if (seenCiPaths.has(resolved)) continue;
|
|
262
|
+
seenCiPaths.add(resolved);
|
|
263
|
+
for (const rec of readNdjsonQuiet(resolved)) {
|
|
264
|
+
if (rec && typeof rec === 'object' && (!rec.kind || rec.kind === 'ci') && after(rec.at || rec.timestamp)) {
|
|
265
|
+
ciRuns.push(rec);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// Group CI runs by phase
|
|
271
|
+
const ciByPhase = new Map();
|
|
272
|
+
for (const rec of ciRuns) {
|
|
273
|
+
const ph = String(rec.phase || 'unknown');
|
|
274
|
+
if (!ciByPhase.has(ph)) ciByPhase.set(ph, []);
|
|
275
|
+
ciByPhase.get(ph).push(rec);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
let firstPassGreenCount = 0;
|
|
279
|
+
let ciReworkCycles = 0;
|
|
280
|
+
const phaseCiSummary = new Map();
|
|
281
|
+
for (const [phase, runs] of ciByPhase.entries()) {
|
|
282
|
+
const sorted = [...runs].sort((a, b) => String(a.at || a.timestamp || '').localeCompare(String(b.at || b.timestamp || '')));
|
|
283
|
+
const first = sorted[0];
|
|
284
|
+
const concl = String((first && (first.conclusion || first.status)) || '').toLowerCase();
|
|
285
|
+
const firstPassGreen = first
|
|
286
|
+
? (first.ok === true
|
|
287
|
+
|| concl === 'success'
|
|
288
|
+
|| concl === 'passed'
|
|
289
|
+
|| concl === 'green'
|
|
290
|
+
|| (!concl && sorted.length === 1))
|
|
291
|
+
: false;
|
|
292
|
+
const rework = Math.max(0, sorted.length - 1);
|
|
293
|
+
if (firstPassGreen) firstPassGreenCount += 1;
|
|
294
|
+
ciReworkCycles += rework;
|
|
295
|
+
phaseCiSummary.set(phase, {
|
|
296
|
+
ci_runs: sorted.length,
|
|
297
|
+
first_pass_green: firstPassGreen,
|
|
298
|
+
rework_cycles: rework,
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
const phasesWithCi = ciByPhase.size;
|
|
303
|
+
const firstPassRate = phasesWithCi > 0 ? Math.round((firstPassGreenCount / phasesWithCi) * 100) / 100 : null;
|
|
304
|
+
|
|
305
|
+
// 2. Collect lifecycle events (passed-in + local ndjson files) and deduplicate
|
|
306
|
+
const rawEvents = [];
|
|
307
|
+
if (Array.isArray(options.events)) rawEvents.push(...options.events);
|
|
308
|
+
const eventCandidates = [];
|
|
309
|
+
if (options.activeSession) {
|
|
310
|
+
eventCandidates.push(path.join(projectRoot, '.oxe', options.activeSession, 'events', 'events.ndjson'));
|
|
311
|
+
eventCandidates.push(path.join(projectRoot, '.oxe', options.activeSession, 'OXE-EVENTS.ndjson'));
|
|
312
|
+
}
|
|
313
|
+
eventCandidates.push(path.join(projectRoot, '.oxe', 'events', 'events.ndjson'));
|
|
314
|
+
eventCandidates.push(path.join(projectRoot, '.oxe', 'OXE-EVENTS.ndjson'));
|
|
315
|
+
const seenEventPaths = new Set();
|
|
316
|
+
for (const candidate of eventCandidates) {
|
|
317
|
+
const resolved = path.resolve(candidate);
|
|
318
|
+
if (seenEventPaths.has(resolved)) continue;
|
|
319
|
+
seenEventPaths.add(resolved);
|
|
320
|
+
rawEvents.push(...readNdjsonQuiet(resolved));
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
const seenEventKey = new Set();
|
|
324
|
+
const events = [];
|
|
325
|
+
for (const e of rawEvents) {
|
|
326
|
+
if (!e || typeof e !== 'object' || !e.type) continue;
|
|
327
|
+
const ts = String(e.timestamp || e.at || '');
|
|
328
|
+
if (!after(ts)) continue;
|
|
329
|
+
const phase = (e.payload && e.payload.phase) || e.phase || '';
|
|
330
|
+
const status = (e.payload && e.payload.status) || '';
|
|
331
|
+
const dedupKey = `${e.type}|${ts}|${phase}|${status}|${e.run_id || ''}`;
|
|
332
|
+
if (seenEventKey.has(dedupKey)) continue;
|
|
333
|
+
seenEventKey.add(dedupKey);
|
|
334
|
+
events.push({ ...e, _ts: ts });
|
|
335
|
+
}
|
|
336
|
+
events.sort((a, b) => a._ts.localeCompare(b._ts));
|
|
337
|
+
|
|
338
|
+
// Build phase windows for inferring phase when events omit payload.phase
|
|
339
|
+
const phaseWindows = [];
|
|
340
|
+
for (const e of events) {
|
|
341
|
+
if (e.type === 'PhaseStarted' && e.payload && e.payload.phase) {
|
|
342
|
+
phaseWindows.push({ phase: String(e.payload.phase), at: e._ts });
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
const inferPhaseAt = (ts) => {
|
|
346
|
+
let ph = null;
|
|
347
|
+
for (const w of phaseWindows) {
|
|
348
|
+
if (w.at <= ts) ph = w.phase;
|
|
349
|
+
else break;
|
|
350
|
+
}
|
|
351
|
+
return ph;
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
const phaseTimes = new Map();
|
|
355
|
+
const ensurePhaseTime = (ph) => {
|
|
356
|
+
if (!phaseTimes.has(ph)) phaseTimes.set(ph, { started: null, verified: null, closed: null });
|
|
357
|
+
return phaseTimes.get(ph);
|
|
358
|
+
};
|
|
359
|
+
for (const e of events) {
|
|
360
|
+
const ms = Date.parse(e._ts);
|
|
361
|
+
if (Number.isNaN(ms)) continue;
|
|
362
|
+
const ph = (e.payload && e.payload.phase) ? String(e.payload.phase) : inferPhaseAt(e._ts);
|
|
363
|
+
if (!ph) continue;
|
|
364
|
+
const rec = ensurePhaseTime(ph);
|
|
365
|
+
if (e.type === 'PhaseStarted') {
|
|
366
|
+
if (rec.started == null || ms < rec.started) rec.started = ms;
|
|
367
|
+
} else if (e.type === 'VerificationCompleted' && e.payload && (e.payload.status === 'passed' || e.payload.ok === true)) {
|
|
368
|
+
if (rec.verified == null || ms < rec.verified) rec.verified = ms;
|
|
369
|
+
} else if (e.type === 'PhaseClosed') {
|
|
370
|
+
if (rec.closed == null || ms < rec.closed) rec.closed = ms;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
const planToVerifySamples = [];
|
|
375
|
+
const verifyToCloseSamples = [];
|
|
376
|
+
const totalSamples = [];
|
|
377
|
+
const allPhases = new Set([...phaseCiSummary.keys(), ...phaseTimes.keys()]);
|
|
378
|
+
const byPhase = [];
|
|
379
|
+
|
|
380
|
+
for (const ph of [...allPhases].sort()) {
|
|
381
|
+
const ci = phaseCiSummary.get(ph) || { ci_runs: 0, first_pass_green: null, rework_cycles: 0 };
|
|
382
|
+
const tm = phaseTimes.get(ph) || { started: null, verified: null, closed: null };
|
|
383
|
+
const p2v = tm.started != null && tm.verified != null && tm.verified >= tm.started ? tm.verified - tm.started : null;
|
|
384
|
+
const v2c = tm.verified != null && tm.closed != null && tm.closed >= tm.verified ? tm.closed - tm.verified : null;
|
|
385
|
+
const tot = tm.started != null && tm.closed != null && tm.closed >= tm.started ? tm.closed - tm.started : null;
|
|
386
|
+
if (p2v != null) planToVerifySamples.push(p2v);
|
|
387
|
+
if (v2c != null) verifyToCloseSamples.push(v2c);
|
|
388
|
+
if (tot != null) totalSamples.push(tot);
|
|
389
|
+
byPhase.push({
|
|
390
|
+
phase: ph,
|
|
391
|
+
ci_runs: ci.ci_runs,
|
|
392
|
+
first_pass_green: ci.first_pass_green,
|
|
393
|
+
rework_cycles: ci.rework_cycles,
|
|
394
|
+
plan_to_verify_ms: p2v,
|
|
395
|
+
verify_to_close_ms: v2c,
|
|
396
|
+
total_ms: tot,
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
const avg = (arr) => (arr.length ? Math.round(arr.reduce((a, b) => a + b, 0) / arr.length) : null);
|
|
401
|
+
const avgPlanToVerify = avg(planToVerifySamples);
|
|
402
|
+
const avgVerifyToClose = avg(verifyToCloseSamples);
|
|
403
|
+
const avgTotal = avg(totalSamples);
|
|
404
|
+
const postVerifySharePct = avgPlanToVerify != null && avgVerifyToClose != null && (avgPlanToVerify + avgVerifyToClose) > 0
|
|
405
|
+
? Math.round((avgVerifyToClose / (avgPlanToVerify + avgVerifyToClose)) * 1000) / 10
|
|
406
|
+
: null;
|
|
407
|
+
|
|
408
|
+
return {
|
|
409
|
+
offline: true,
|
|
410
|
+
total_ci_runs: ciRuns.length,
|
|
411
|
+
phases_with_ci: phasesWithCi,
|
|
412
|
+
first_pass_ci_green_rate: firstPassRate,
|
|
413
|
+
ci_rework_cycles: ciReworkCycles,
|
|
414
|
+
leadtime_breakdown: {
|
|
415
|
+
avg_plan_to_verify_ms: avgPlanToVerify,
|
|
416
|
+
avg_verify_to_close_ms: avgVerifyToClose,
|
|
417
|
+
avg_total_ms: avgTotal,
|
|
418
|
+
post_verify_share_pct: postVerifySharePct,
|
|
419
|
+
phases_measured: Math.max(planToVerifySamples.length, verifyToCloseSamples.length, totalSamples.length),
|
|
420
|
+
},
|
|
421
|
+
by_phase: byPhase,
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
|
|
221
425
|
function scorecardForProject(projectRoot, readEvents, options = {}) {
|
|
222
426
|
const events = typeof readEvents === 'function' ? readEvents() : [];
|
|
223
427
|
let changeLines = [];
|
|
@@ -231,4 +435,193 @@ function scorecardForProject(projectRoot, readEvents, options = {}) {
|
|
|
231
435
|
return computeScorecard({ events, changeLines, ledgers: readLedgers(projectRoot), since: options.since || null });
|
|
232
436
|
}
|
|
233
437
|
|
|
234
|
-
|
|
438
|
+
const DOC_CFG_FILE_RE = /\.(md|txt|json|ya?ml|toml|ini|cfg|conf)$|^(docs|\.oxe|\.github)\//i;
|
|
439
|
+
const TEST_ONLY_FILE_RE = /(^|\/)(tests?|__tests__|spec|e2e)\/|\.(test|spec)\.[cm]?[jt]sx?$/i;
|
|
440
|
+
const HEURISTIC_TIER_BY_CATEGORY = Object.freeze({
|
|
441
|
+
'docs-config': 'fast',
|
|
442
|
+
'test-only': 'fast',
|
|
443
|
+
'small-edit': 'balanced',
|
|
444
|
+
'multi-file-refactor': 'powerful',
|
|
445
|
+
architecture: 'powerful',
|
|
446
|
+
general: 'balanced',
|
|
447
|
+
});
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* 1.22.2 (OXB-222-21): Classifies a task into a coarse routing category from its kind, files and title.
|
|
451
|
+
*/
|
|
452
|
+
function classifyTaskCategory(task = {}) {
|
|
453
|
+
const kind = String(task.kind || '').toLowerCase();
|
|
454
|
+
const files = (Array.isArray(task.files) ? task.files : []).map((f) => String(f || '').replace(/\\/g, '/'));
|
|
455
|
+
const title = String(task.title || '');
|
|
456
|
+
if (kind === 'test-only' || (files.length > 0 && files.every((f) => TEST_ONLY_FILE_RE.test(f)))) return 'test-only';
|
|
457
|
+
if (kind === 'config-only' || (files.length > 0 && files.every((f) => DOC_CFG_FILE_RE.test(f)))) return 'docs-config';
|
|
458
|
+
if (files.length >= 4 || /\b(refactor|refator|migrat|modulariz|strangler|arquitetura|architecture)\b/i.test(title)) return 'multi-file-refactor';
|
|
459
|
+
return 'small-edit';
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* 1.22.2 (OXB-222-21): Offline empirical model-routing statistics per task category and tier.
|
|
464
|
+
* Reads historical `ExecutorUsage`, `RetryScheduled`, and `WorkItemCompleted` events (zero network calls).
|
|
465
|
+
*/
|
|
466
|
+
function computeModelRoutingStats(events = [], options = {}) {
|
|
467
|
+
let since = null;
|
|
468
|
+
if (options.since) {
|
|
469
|
+
const d = new Date(options.since);
|
|
470
|
+
if (!Number.isNaN(d.getTime())) since = d.toISOString();
|
|
471
|
+
}
|
|
472
|
+
const combined = Array.isArray(events) ? [...events] : [];
|
|
473
|
+
if (options.projectRoot) {
|
|
474
|
+
const evCandidates = [];
|
|
475
|
+
if (options.activeSession) {
|
|
476
|
+
evCandidates.push(path.join(options.projectRoot, '.oxe', options.activeSession, 'events', 'events.ndjson'));
|
|
477
|
+
evCandidates.push(path.join(options.projectRoot, '.oxe', options.activeSession, 'OXE-EVENTS.ndjson'));
|
|
478
|
+
}
|
|
479
|
+
evCandidates.push(path.join(options.projectRoot, '.oxe', 'events', 'events.ndjson'));
|
|
480
|
+
evCandidates.push(path.join(options.projectRoot, '.oxe', 'OXE-EVENTS.ndjson'));
|
|
481
|
+
const seenPaths = new Set();
|
|
482
|
+
for (const c of evCandidates) {
|
|
483
|
+
const abs = path.resolve(c);
|
|
484
|
+
if (seenPaths.has(abs)) continue;
|
|
485
|
+
seenPaths.add(abs);
|
|
486
|
+
combined.push(...readNdjsonQuiet(abs));
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
const seenKey = new Set();
|
|
490
|
+
const list = [];
|
|
491
|
+
for (const e of combined) {
|
|
492
|
+
if (!e || typeof e !== 'object') continue;
|
|
493
|
+
const ts = String(e.timestamp || e.at || '');
|
|
494
|
+
if (since && ts < since) continue;
|
|
495
|
+
const dk = `${e.type || ''}|${e.run_id || ''}|${e.work_item_id || ''}|${ts}|${JSON.stringify(e.payload || {})}`;
|
|
496
|
+
if (seenKey.has(dk)) continue;
|
|
497
|
+
seenKey.add(dk);
|
|
498
|
+
list.push(e);
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
const taskState = new Map();
|
|
502
|
+
const ensure = (key) => {
|
|
503
|
+
if (!taskState.has(key)) {
|
|
504
|
+
taskState.set(key, { category: 'general', firstTier: null, finalTier: null, turns: 0, costUsd: 0, retried: false, completed: false, attempt1: false, tierAttempts: [] });
|
|
505
|
+
}
|
|
506
|
+
return taskState.get(key);
|
|
507
|
+
};
|
|
508
|
+
|
|
509
|
+
for (const e of list) {
|
|
510
|
+
const wid = e.work_item_id || (e.payload && e.payload.task);
|
|
511
|
+
if (!wid) continue;
|
|
512
|
+
const key = `${e.run_id || 'default'}::${wid}`;
|
|
513
|
+
const p = e.payload || {};
|
|
514
|
+
const st = ensure(key);
|
|
515
|
+
const cat = p.category || p.task_category || null;
|
|
516
|
+
if (cat) st.category = String(cat);
|
|
517
|
+
const tier = p.tier || p.model_tier || p.model_hint || null;
|
|
518
|
+
if (e.type === 'ExecutorUsage') {
|
|
519
|
+
if (tier && !st.firstTier) st.firstTier = String(tier);
|
|
520
|
+
if (tier) st.finalTier = String(tier);
|
|
521
|
+
st.turns += Number(p.turns) || 0;
|
|
522
|
+
st.costUsd += Number(p.cost_usd) || 0;
|
|
523
|
+
if (p.success === false) st.retried = true;
|
|
524
|
+
st.tierAttempts.push({ tier: String(tier || 'balanced'), success: p.success !== false });
|
|
525
|
+
} else if (e.type === 'RetryScheduled') {
|
|
526
|
+
st.retried = true;
|
|
527
|
+
} else if (e.type === 'WorkItemCompleted') {
|
|
528
|
+
if (tier && !st.finalTier) st.finalTier = String(tier);
|
|
529
|
+
if (tier && !st.firstTier) st.firstTier = String(tier);
|
|
530
|
+
st.completed = true;
|
|
531
|
+
const attempt = Number(p.attempt_number ?? p.attempt ?? 1);
|
|
532
|
+
if (attempt === 1 && !st.retried) st.attempt1 = true;
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
const byCatRaw = new Map();
|
|
537
|
+
for (const st of taskState.values()) {
|
|
538
|
+
const cat = st.category || 'general';
|
|
539
|
+
if (!byCatRaw.has(cat)) byCatRaw.set(cat, []);
|
|
540
|
+
byCatRaw.get(cat).push(st);
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
const byCategory = {};
|
|
544
|
+
let totalSamples = 0;
|
|
545
|
+
for (const [cat, items] of byCatRaw.entries()) {
|
|
546
|
+
const samples = items.length;
|
|
547
|
+
totalSamples += samples;
|
|
548
|
+
const firstPass = items.filter((x) => x.attempt1).length;
|
|
549
|
+
const firstAttemptRate = samples ? Math.round((firstPass / samples) * 100) / 100 : null;
|
|
550
|
+
const avgTurns = samples ? Math.round((items.reduce((a, b) => a + b.turns, 0) / samples) * 100) / 100 : 0;
|
|
551
|
+
const avgCost = samples ? Math.round((items.reduce((a, b) => a + b.costUsd, 0) / samples) * 10000) / 10000 : 0;
|
|
552
|
+
|
|
553
|
+
const tierAgg = {};
|
|
554
|
+
for (const tierName of ['fast', 'balanced', 'powerful']) {
|
|
555
|
+
const attempts = items.flatMap((x) => x.tierAttempts.filter((a) => a.tier === tierName));
|
|
556
|
+
if (!attempts.length) continue;
|
|
557
|
+
const okCount = attempts.filter((a) => a.success).length;
|
|
558
|
+
tierAgg[tierName] = {
|
|
559
|
+
attempts: attempts.length,
|
|
560
|
+
successes: okCount,
|
|
561
|
+
success_rate: Math.round((okCount / attempts.length) * 100) / 100,
|
|
562
|
+
};
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
let recommended = HEURISTIC_TIER_BY_CATEGORY[cat] || 'balanced';
|
|
566
|
+
if (tierAgg.fast && tierAgg.fast.attempts >= 1 && tierAgg.fast.success_rate >= 0.8) {
|
|
567
|
+
recommended = 'fast';
|
|
568
|
+
} else if (tierAgg.balanced && tierAgg.balanced.attempts >= 1 && tierAgg.balanced.success_rate < 0.7) {
|
|
569
|
+
recommended = 'powerful';
|
|
570
|
+
} else if (tierAgg.balanced && tierAgg.balanced.attempts >= 1 && tierAgg.balanced.success_rate >= 0.8) {
|
|
571
|
+
recommended = 'balanced';
|
|
572
|
+
} else if (tierAgg.powerful && tierAgg.powerful.attempts >= 1 && tierAgg.powerful.success_rate >= 0.7) {
|
|
573
|
+
recommended = 'powerful';
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
byCategory[cat] = {
|
|
577
|
+
samples,
|
|
578
|
+
first_attempt_rate: firstAttemptRate,
|
|
579
|
+
avg_turns: avgTurns,
|
|
580
|
+
avg_cost_usd: avgCost,
|
|
581
|
+
tiers: tierAgg,
|
|
582
|
+
recommended_tier: recommended,
|
|
583
|
+
};
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
return {
|
|
587
|
+
offline: true,
|
|
588
|
+
total_samples: totalSamples,
|
|
589
|
+
by_category: byCategory,
|
|
590
|
+
};
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
/**
|
|
594
|
+
* Suggests a `model_hint` (`fast` | `balanced` | `powerful`) for a task using empirical stats when
|
|
595
|
+
* available, falling back deterministically to category heuristics. Never overrides an explicit `model_hint`.
|
|
596
|
+
*/
|
|
597
|
+
function suggestModelHint(task = {}, routingStats = null) {
|
|
598
|
+
const category = classifyTaskCategory(task);
|
|
599
|
+
const catStats = routingStats && routingStats.by_category && routingStats.by_category[category];
|
|
600
|
+
if (catStats && catStats.samples >= 1 && catStats.recommended_tier) {
|
|
601
|
+
const pct = catStats.first_attempt_rate != null ? `${Math.round(catStats.first_attempt_rate * 100)}%` : 'n/a';
|
|
602
|
+
return {
|
|
603
|
+
category,
|
|
604
|
+
suggested_model_hint: catStats.recommended_tier,
|
|
605
|
+
routing_reason: `empírico (${category}: ${catStats.samples} amostra(s), first-attempt ${pct})`,
|
|
606
|
+
source: 'empirical',
|
|
607
|
+
};
|
|
608
|
+
}
|
|
609
|
+
const fallback = HEURISTIC_TIER_BY_CATEGORY[category] || 'balanced';
|
|
610
|
+
return {
|
|
611
|
+
category,
|
|
612
|
+
suggested_model_hint: fallback,
|
|
613
|
+
routing_reason: `heurístico (${category}, sem amostras históricas suficientes)`,
|
|
614
|
+
source: 'heuristic',
|
|
615
|
+
};
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
module.exports = {
|
|
619
|
+
TARGETS,
|
|
620
|
+
computeScorecard,
|
|
621
|
+
scorecardForProject,
|
|
622
|
+
foldChanges,
|
|
623
|
+
computeLeadtimeAndCiMetrics,
|
|
624
|
+
classifyTaskCategory,
|
|
625
|
+
computeModelRoutingStats,
|
|
626
|
+
suggestModelHint,
|
|
627
|
+
};
|
package/bin/lib/oxe-ship-pr.cjs
CHANGED
|
@@ -11,12 +11,32 @@
|
|
|
11
11
|
* gh only (the user's login); `spawn` injectable for tests.
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
+
const fs = require('fs');
|
|
15
|
+
const path = require('path');
|
|
14
16
|
const { spawnSync } = require('child_process');
|
|
17
|
+
const presets = require('./oxe-presets.cjs');
|
|
15
18
|
|
|
16
19
|
const MARKER = '<!-- oxe-ci-verdict -->';
|
|
17
20
|
const DEFAULT_TRAIN = ['na-fila', 'no-batch', 'fix-main'];
|
|
18
21
|
const DEFAULT_REQUIRED_STATUSES = ['marca/conformidade'];
|
|
19
22
|
|
|
23
|
+
function resolveRequiredCommitStatuses(cwd, options = {}) {
|
|
24
|
+
if (Array.isArray(options.requiredStatuses)) {
|
|
25
|
+
return options.requiredStatuses.map((s) => String(s).toLowerCase()).filter(Boolean);
|
|
26
|
+
}
|
|
27
|
+
const hasConfigFile = Boolean(
|
|
28
|
+
cwd && (fs.existsSync(path.join(cwd, 'oxe.config.json')) || fs.existsSync(path.join(cwd, '.oxe', 'config.json')))
|
|
29
|
+
);
|
|
30
|
+
const presetCfg = cwd ? presets.resolvePresetConfig(cwd) : null;
|
|
31
|
+
if (presetCfg && Array.isArray(presetCfg.ship && presetCfg.ship.requiredCommitStatuses) && presetCfg.ship.requiredCommitStatuses.length) {
|
|
32
|
+
return presetCfg.ship.requiredCommitStatuses.map((s) => String(s).toLowerCase()).filter(Boolean);
|
|
33
|
+
}
|
|
34
|
+
if (presetCfg && presetCfg.hasExplicitPreset) return [];
|
|
35
|
+
if (cwd && fs.existsSync(path.join(cwd, 'src', 'design', 'targets'))) return DEFAULT_REQUIRED_STATUSES;
|
|
36
|
+
if (hasConfigFile) return [];
|
|
37
|
+
return Array.isArray(options.commitStatuses) ? DEFAULT_REQUIRED_STATUSES : [];
|
|
38
|
+
}
|
|
39
|
+
|
|
20
40
|
function gh(spawn, cwd, args, input) {
|
|
21
41
|
const r = spawn('gh', args, { cwd, encoding: 'utf8', windowsHide: true, timeout: 60_000, maxBuffer: 16 * 1024 * 1024, ...(input != null ? { input } : {}) });
|
|
22
42
|
if (!r || r.error || r.status !== 0) throw new Error(`gh ${args.slice(0, 3).join(' ')}: ${String((r && (r.stderr || (r.error && r.error.message))) || 'sem resposta').trim().split('\n')[0]}`);
|
|
@@ -30,10 +50,8 @@ const FIELDS = 'number,title,headRefName,headRefOid,url,labels,isDraft,state';
|
|
|
30
50
|
* so a green Actions job never masks an enforced brand-conformance divergence posted as a commit status.
|
|
31
51
|
*/
|
|
32
52
|
function inspectRequiredCommitStatuses(cwd, headSha, options = {}) {
|
|
33
|
-
const required =
|
|
34
|
-
|
|
35
|
-
: DEFAULT_REQUIRED_STATUSES;
|
|
36
|
-
if (!headSha) return { ok: true, checked: [], failures: [] };
|
|
53
|
+
const required = resolveRequiredCommitStatuses(cwd, options);
|
|
54
|
+
if (!headSha || !required.length) return { ok: true, checked: [], failures: [] };
|
|
37
55
|
const spawn = options.spawn || spawnSync;
|
|
38
56
|
let statuses = [];
|
|
39
57
|
if (Array.isArray(options.commitStatuses)) {
|
|
@@ -101,12 +119,62 @@ function selectPrs(spawn, cwd, sel) {
|
|
|
101
119
|
|
|
102
120
|
/**
|
|
103
121
|
* `{ pr | card | repo }` → the PRs with their CI verdict. `known`: the known failures in force (not expired).
|
|
122
|
+
* Supports provider-agnostic delegation via `bin/lib/oxe-ci-adapter.cjs` (`github`, `gitlab`, `azure-devops`, `local`).
|
|
104
123
|
*/
|
|
105
124
|
function status(cwd, sel, options = {}) {
|
|
106
125
|
const spawn = options.spawn || spawnSync;
|
|
107
126
|
const kf = require('./oxe-known-failures.cjs');
|
|
127
|
+
const ciAdapter = require('./oxe-ci-adapter.cjs');
|
|
108
128
|
const known = (options.known || []).filter((k) => !k.expired);
|
|
109
129
|
const trainLabels = options.trainLabels || DEFAULT_TRAIN;
|
|
130
|
+
const selector = sel.pr ? { pr: Number(String(sel.pr).replace(/^#/, '')) } : sel.card ? { card: String(sel.card).toUpperCase() } : { repo: true };
|
|
131
|
+
|
|
132
|
+
const explicitProvider = options.provider ? String(options.provider).toLowerCase() : null;
|
|
133
|
+
const detectedProvider = explicitProvider || ciAdapter.detectCiProvider(cwd);
|
|
134
|
+
// Preserve legacy GitHub behavior when caller supplies a mock `spawn` without explicit provider on a non-git temp dir
|
|
135
|
+
const effectiveProvider = explicitProvider || (['gitlab', 'azure-devops'].includes(detectedProvider) ? detectedProvider : (options.spawn ? 'github' : detectedProvider));
|
|
136
|
+
|
|
137
|
+
if (effectiveProvider === 'local') {
|
|
138
|
+
return { provider: 'local', offline: true, selector, prs: [], known: known.length, train_labels: trainLabels };
|
|
139
|
+
}
|
|
140
|
+
if (effectiveProvider !== 'github') {
|
|
141
|
+
const adapter = ciAdapter.resolveCiAdapter(cwd, { provider: effectiveProvider, spawn });
|
|
142
|
+
const listed = adapter.listPullRequests({ state: 'open', limit: sel.limit || 50 });
|
|
143
|
+
const ciRuns = adapter.inspectCiStatus({ limit: 20 });
|
|
144
|
+
const items = (listed.items || []).filter((it) => {
|
|
145
|
+
if (sel.pr) return Number(it.number) === Number(String(sel.pr).replace(/^#/, ''));
|
|
146
|
+
if (sel.card) {
|
|
147
|
+
const key = String(sel.card).trim().toUpperCase().replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
148
|
+
const re = new RegExp(`(^|[^A-Za-z0-9])${key.replace(/[-#]/g, '[-_#]?')}($|[^0-9])`, 'i');
|
|
149
|
+
return re.test(it.title || '') || re.test(it.branch || '');
|
|
150
|
+
}
|
|
151
|
+
return true;
|
|
152
|
+
});
|
|
153
|
+
const out = items.map((it) => {
|
|
154
|
+
const matchingRun = (ciRuns.runs || []).find((r) => !it.branch || !r.branch || r.branch === it.branch) || (ciRuns.runs || [])[0] || null;
|
|
155
|
+
let ciState = 'unknown';
|
|
156
|
+
if (matchingRun) {
|
|
157
|
+
if (matchingRun.conclusion === 'success') ciState = 'green';
|
|
158
|
+
else if (matchingRun.conclusion === 'failure' || matchingRun.conclusion === 'failed') ciState = 'regression';
|
|
159
|
+
else ciState = 'pending';
|
|
160
|
+
}
|
|
161
|
+
const labels = Array.isArray(it.labels) ? it.labels : [];
|
|
162
|
+
return {
|
|
163
|
+
pr: it.number,
|
|
164
|
+
title: it.title,
|
|
165
|
+
url: it.url,
|
|
166
|
+
branch: it.branch,
|
|
167
|
+
head_sha: it.head_sha || null,
|
|
168
|
+
draft: Boolean(it.draft),
|
|
169
|
+
state: it.state || 'OPEN',
|
|
170
|
+
labels,
|
|
171
|
+
train: labels.filter((l) => trainLabels.includes(l)),
|
|
172
|
+
ci: { state: ciState, failed: [] },
|
|
173
|
+
};
|
|
174
|
+
});
|
|
175
|
+
return { provider: effectiveProvider, offline: false, selector, prs: out, known: known.length, train_labels: trainLabels, ...(listed.ok ? {} : { error: listed.error }) };
|
|
176
|
+
}
|
|
177
|
+
|
|
110
178
|
const prs = selectPrs(spawn, cwd, sel);
|
|
111
179
|
const out = prs.map((p) => {
|
|
112
180
|
const labels = (p.labels || []).map((l) => l.name || l);
|
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
* covering every criterion. Pure: the caller reads the files.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
+
const fs = require('fs');
|
|
12
|
+
const path = require('path');
|
|
11
13
|
const criteriaIds = require('./oxe-criteria-ids.cjs');
|
|
12
14
|
|
|
13
15
|
const RISKS = ['P0', 'P1', 'P2', 'P3'];
|
|
@@ -206,6 +208,36 @@ function checkSpec(input) {
|
|
|
206
208
|
(mode === 'risk' || mode === 'always' ? errors : warnings).push(`critério(s) de risco ${risky.join(', ')} sem RFC — rascunhe a proposta técnica: oxe-cc rfc new --title "…"`);
|
|
207
209
|
}
|
|
208
210
|
|
|
211
|
+
// OXB-222-11: SPEC depth & real-path checks (Bordas/Proibições, overloaded criteria, doc paths on disk)
|
|
212
|
+
if (crit.list.length) {
|
|
213
|
+
const cleanSpec = stripMarkdownNoise(specText);
|
|
214
|
+
if (!/^#{2,3}\s*(?:bordas|proibi[cç][oõ]es|restri[cç][oõ]es|contratos\s+observ[aá]veis|invariantes)/im.test(cleanSpec)) {
|
|
215
|
+
warnings.push('SPEC sem seção de Bordas/Proibições (ex.: "## Bordas e proibições") — feche limites e casos de erro antes do /oxe-plan');
|
|
216
|
+
}
|
|
217
|
+
for (const c of crit.list) {
|
|
218
|
+
if (c.text && c.text.length > 320) {
|
|
219
|
+
warnings.push(`${c.id}: critério extenso/sobrecarregado (${c.text.length} chars) — considere dividir em critérios menores e independentes`);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
if (input.projectRoot) {
|
|
223
|
+
const rootAbs = path.resolve(input.projectRoot);
|
|
224
|
+
const DOC_PATH_RE = /`((?:docs\/adr|oxe\/workflows|oxe\/templates)\/[^`\r\n*<>]+\.(?:md|json))`/g;
|
|
225
|
+
const NEW_HINT_RE = /\b(?:novo|nova|criar|a\s+criar|new)\b/i;
|
|
226
|
+
const seenDocPaths = new Set();
|
|
227
|
+
let dm;
|
|
228
|
+
while ((dm = DOC_PATH_RE.exec(cleanSpec))) {
|
|
229
|
+
const rel = dm[1].trim().replace(/#.*$/, '');
|
|
230
|
+
if (!rel || seenDocPaths.has(rel) || rel.includes('..')) continue;
|
|
231
|
+
const after = cleanSpec.slice(dm.index + dm[0].length, dm.index + dm[0].length + 35);
|
|
232
|
+
if (NEW_HINT_RE.test(after)) continue;
|
|
233
|
+
seenDocPaths.add(rel);
|
|
234
|
+
if (!fs.existsSync(path.join(rootAbs, rel))) {
|
|
235
|
+
errors.push(`referência inexistente na SPEC: \`${rel}\` (verifique o caminho real no repositório)`);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
209
241
|
return {
|
|
210
242
|
ok: errors.length === 0,
|
|
211
243
|
errors,
|