mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-07-15 20:40:35 -07:00
Merge branch 'main' into bot-prompt-improvements
This commit is contained in:
@@ -49,6 +49,10 @@ synchronize with previous sessions:
|
||||
than closure rates).
|
||||
- **Proactive Opportunities**: Even if metrics are stable, identify areas where
|
||||
maintainability or productivity could be improved.
|
||||
- **Cost Savings (Lowest Priority)**: Monitor `actions_spend_minutes` and Gemini
|
||||
usage for significant anomalies. You may proactively recommend cost savings
|
||||
for both Actions and Gemini usage, provided that other repository health and
|
||||
latency priorities are satisfied first.
|
||||
|
||||
### 2. Hypothesis Testing & Deep Dive
|
||||
|
||||
|
||||
@@ -133,7 +133,7 @@ async function run() {
|
||||
writeFileSync(OUTPUT_FILE, results.join('\n'));
|
||||
console.log(`Saved metrics to ${OUTPUT_FILE}`);
|
||||
|
||||
// Update timeseries with rolling window (keep last 100 lines)
|
||||
// Update timeseries with rolling window (keep last 5000 lines)
|
||||
const timestamp = new Date().toISOString();
|
||||
let timeseriesLines: string[] = [];
|
||||
if (existsSync(TIMESERIES_FILE)) {
|
||||
@@ -146,10 +146,10 @@ async function run() {
|
||||
if (newRows.length > 0) {
|
||||
timeseriesLines.push(...newRows);
|
||||
|
||||
// Keep header + last 100 data rows
|
||||
if (timeseriesLines.length > 101) {
|
||||
// Keep header + last 5000 data rows
|
||||
if (timeseriesLines.length > 5001) {
|
||||
const header = timeseriesLines[0];
|
||||
timeseriesLines = [header, ...timeseriesLines.slice(-100)];
|
||||
timeseriesLines = [header, ...timeseriesLines.slice(-5000)];
|
||||
}
|
||||
|
||||
writeFileSync(TIMESERIES_FILE, timeseriesLines.join('\n') + '\n');
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2026 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import { execFileSync } from 'node:child_process';
|
||||
|
||||
async function getWorkflowMinutes(): Promise<Record<string, number>> {
|
||||
const sevenDaysAgoDate = new Date(Date.now() - 7 * 24 * 60 * 60 * 1000)
|
||||
.toISOString()
|
||||
.split('T')[0];
|
||||
|
||||
const output = execFileSync(
|
||||
'gh',
|
||||
[
|
||||
'run',
|
||||
'list',
|
||||
'--limit',
|
||||
'1000',
|
||||
'--created',
|
||||
`>=${sevenDaysAgoDate}`,
|
||||
'--json',
|
||||
'databaseId,workflowName',
|
||||
],
|
||||
{ encoding: 'utf-8' },
|
||||
);
|
||||
|
||||
const runs = JSON.parse(output);
|
||||
const workflowMinutes: Record<string, number> = {};
|
||||
const token = execFileSync('gh', ['auth', 'token'], {
|
||||
encoding: 'utf-8',
|
||||
}).trim();
|
||||
const repoInfo = JSON.parse(
|
||||
execFileSync('gh', ['repo', 'view', '--json', 'nameWithOwner'], {
|
||||
encoding: 'utf-8',
|
||||
}),
|
||||
);
|
||||
const repoName = repoInfo.nameWithOwner;
|
||||
|
||||
const chunkSize = 20;
|
||||
for (let i = 0; i < runs.length; i += chunkSize) {
|
||||
const chunk = runs.slice(i, i + chunkSize);
|
||||
await Promise.all(
|
||||
chunk.map(async (r: { databaseId: number; workflowName?: string }) => {
|
||||
try {
|
||||
const res = await fetch(
|
||||
`https://api.github.com/repos/${repoName}/actions/runs/${r.databaseId}/jobs`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
Accept: 'application/vnd.github.v3+json',
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
if (!res.ok) return;
|
||||
|
||||
const { jobs } = await res.json();
|
||||
let runBillableMinutes = 0;
|
||||
|
||||
for (const job of jobs || []) {
|
||||
if (!job.started_at || !job.completed_at) continue;
|
||||
const start = new Date(job.started_at).getTime();
|
||||
const end = new Date(job.completed_at).getTime();
|
||||
const durationMs = end - start;
|
||||
|
||||
if (durationMs > 0) {
|
||||
runBillableMinutes += Math.ceil(durationMs / (1000 * 60));
|
||||
}
|
||||
}
|
||||
|
||||
if (runBillableMinutes > 0) {
|
||||
const name = r.workflowName || 'Unknown';
|
||||
workflowMinutes[name] =
|
||||
(workflowMinutes[name] || 0) + runBillableMinutes;
|
||||
}
|
||||
} catch {
|
||||
// Ignore failures for individual runs
|
||||
}
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
return workflowMinutes;
|
||||
}
|
||||
|
||||
async function run() {
|
||||
try {
|
||||
const workflowMinutes = await getWorkflowMinutes();
|
||||
let totalMinutes = 0;
|
||||
|
||||
for (const minutes of Object.values(workflowMinutes)) {
|
||||
totalMinutes += minutes;
|
||||
}
|
||||
|
||||
const now = new Date().toISOString();
|
||||
console.log(
|
||||
JSON.stringify({
|
||||
metric: 'actions_spend_minutes',
|
||||
value: totalMinutes,
|
||||
timestamp: now,
|
||||
details: workflowMinutes,
|
||||
}),
|
||||
);
|
||||
|
||||
for (const [name, minutes] of Object.entries(workflowMinutes)) {
|
||||
const safeName = name.replace(/[^a-zA-Z0-9]/g, '_').toLowerCase();
|
||||
console.log(
|
||||
JSON.stringify({
|
||||
metric: `actions_spend_minutes_workflow:${safeName}`,
|
||||
value: minutes,
|
||||
timestamp: now,
|
||||
}),
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
process.stderr.write(
|
||||
error instanceof Error ? error.message : String(error),
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
run();
|
||||
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2026 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import { GITHUB_OWNER, GITHUB_REPO } from '../types.js';
|
||||
import { execSync } from 'node:child_process';
|
||||
|
||||
/**
|
||||
* Calculates the average age of the oldest 100 open issues in days.
|
||||
*/
|
||||
function run() {
|
||||
try {
|
||||
const query = `
|
||||
query($owner: String!, $repo: String!) {
|
||||
repository(owner: $owner, name: $repo) {
|
||||
issues(first: 100, states: OPEN, orderBy: {field: CREATED_AT, direction: ASC}) {
|
||||
nodes {
|
||||
createdAt
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
const output = execSync(
|
||||
`gh api graphql -F owner=${GITHUB_OWNER} -F repo=${GITHUB_REPO} -f query='${query}'`,
|
||||
{ encoding: 'utf-8', stdio: ['ignore', 'pipe', 'ignore'] },
|
||||
).trim();
|
||||
const data = JSON.parse(output).data.repository;
|
||||
const issues = data.issues.nodes;
|
||||
|
||||
if (issues.length === 0) {
|
||||
process.stdout.write('backlog_age_days,0\n');
|
||||
return;
|
||||
}
|
||||
|
||||
const now = new Date().getTime();
|
||||
const totalAgeDays = issues.reduce(
|
||||
(acc: number, issue: { createdAt: string }) => {
|
||||
const created = new Date(issue.createdAt).getTime();
|
||||
return acc + (now - created) / (1000 * 60 * 60 * 24);
|
||||
},
|
||||
0,
|
||||
);
|
||||
|
||||
const avgAgeDays = totalAgeDays / issues.length;
|
||||
process.stdout.write(
|
||||
`backlog_age_days,${Math.round(avgAgeDays * 100) / 100}\n`,
|
||||
);
|
||||
} catch (error) {
|
||||
process.stderr.write(
|
||||
error instanceof Error ? error.message : String(error),
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
run();
|
||||
Reference in New Issue
Block a user