Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 97 additions & 45 deletions apps/gittensory-ui/public/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -14536,63 +14536,115 @@
"get": {
"responses": {
"200": {
"description": "Maintainer-scoped agent audit feed (#784): executed actions + approval-queue decisions, newest first, public-safe action posture only. Supports ?since=ISO-8601&limit=1-200.",
"description": "Maintainer-scoped agent audit feed (#784): executed actions + approval-queue decisions, newest first, public-safe action posture only. Supports ?since=ISO-8601&limit=1-200. ?pull=N opts into the unfiltered sibling query: every audit_events row for that one PR's targetKey (no eventType restriction), still maintainer-gated and detail-sanitized the same way.",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"repoFullName": {
"type": "string"
},
"events": {
"type": "array",
"items": {
"type": "object",
"properties": {
"eventType": {
"type": "string"
},
"pullNumber": {
"type": "number",
"nullable": true
},
"outcome": {
"type": "string"
},
"actor": {
"type": "string",
"nullable": true
},
"detail": {
"type": "string",
"nullable": true
},
"createdAt": {
"type": "string"
"anyOf": [
{
"type": "object",
"properties": {
"repoFullName": {
"type": "string"
},
"events": {
"type": "array",
"items": {
"type": "object",
"properties": {
"eventType": {
"type": "string"
},
"pullNumber": {
"type": "number",
"nullable": true
},
"outcome": {
"type": "string"
},
"actor": {
"type": "string",
"nullable": true
},
"detail": {
"type": "string",
"nullable": true
},
"createdAt": {
"type": "string"
}
},
"required": [
"eventType",
"pullNumber",
"outcome",
"actor",
"detail",
"createdAt"
]
}
}
},
"required": [
"repoFullName",
"events"
]
},
{
"type": "object",
"properties": {
"repoFullName": {
"type": "string"
},
"required": [
"eventType",
"pullNumber",
"outcome",
"actor",
"detail",
"createdAt"
]
}
"pullNumber": {
"type": "number"
},
"events": {
"type": "array",
"items": {
"type": "object",
"properties": {
"eventType": {
"type": "string"
},
"outcome": {
"type": "string"
},
"actor": {
"type": "string",
"nullable": true
},
"detail": {
"type": "string",
"nullable": true
},
"createdAt": {
"type": "string"
}
},
"required": [
"eventType",
"outcome",
"actor",
"detail",
"createdAt"
]
}
}
},
"required": [
"repoFullName",
"pullNumber",
"events"
]
}
},
"required": [
"repoFullName",
"events"
]
}
}
}
},
"400": {
"description": "Malformed since (not ISO-8601) or limit (not an integer in 1-200)"
"description": "Malformed since (not ISO-8601), limit (not an integer in 1-200), or pull (not a positive integer)"
},
"403": {
"description": "Insufficient role"
Expand Down
20 changes: 20 additions & 0 deletions src/api/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import {
getRepositorySettings,
getPendingAgentAction,
listAgentAuditEvents,
listAuditEventsForTarget,
listPendingAgentActions,
recordAuditEvent,
getContributorEvidence,
Expand Down Expand Up @@ -2412,6 +2413,9 @@ export function createApp() {

// #784 audit feed: the agent's executed actions + approval-queue decisions for this repo. Maintainer-scoped,
// read-only, public-safe (action posture only — no trust/score metadata). `?since=ISO&limit=N` (max 200).
// `?pull=N` opts into the unfiltered sibling query (listAuditEventsForTarget): every audit_events row for
// that one PR's targetKey, not just the agent.action.%/agent.pending_action.% subset — still maintainer-gated
// by the same requireRepoMaintainer check above, just scoped to a single PR instead of the whole repo.
app.get("/v1/repos/:owner/:repo/agent/audit-feed", async (c) => {
const fullName = `${c.req.param("owner")}/${c.req.param("repo")}`;
const gate = await requireRepoMaintainer(c, fullName);
Expand All @@ -2426,6 +2430,22 @@ export function createApp() {
if (!Number.isInteger(parsed) || parsed < 1 || parsed > 200) return c.json({ error: "invalid_limit", detail: "limit must be an integer between 1 and 200" }, 400);
limit = parsed;
}
const pullParam = c.req.query("pull");
if (pullParam !== undefined) {
const pullNumber = Number(pullParam);
if (!Number.isInteger(pullNumber) || pullNumber <= 0) return c.json({ error: "invalid_pull", detail: "pull must be a positive integer" }, 400);
const targetEvents = await listAuditEventsForTarget(c.env, {
repoFullName: fullName,
pullNumber,
...(since !== undefined ? { sinceIso: since } : {}),
...(limit !== undefined ? { limit } : {}),
});
return c.json({
repoFullName: fullName,
pullNumber,
events: targetEvents.map((event) => ({ ...event, detail: event.detail === null ? null : sanitizePublicComment(event.detail) })),
});
}
const events = await listAgentAuditEvents(c.env, {
repoFullName: fullName,
...(since !== undefined ? { sinceIso: since } : {}),
Expand Down
36 changes: 36 additions & 0 deletions src/db/repositories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3035,6 +3035,42 @@ export async function listAgentAuditEvents(
}));
}

// Unfiltered sibling of `listAgentAuditEvents`: same `repo#pr` targetKey correlation (exact match, not just
// the repo-prefix range, since a single PR's full history is the whole point here), but with NO `eventType`
// restriction -- every one of the ~140 event types this table records is eligible, not just the
// `agent.action.%`/`agent.pending_action.%` subset the public audit-feed exposes. Maintainer-gated at the
// route layer; this function itself does no authorization, matching every other list* helper in this file.
export type AuditEventForTarget = {
eventType: string;
outcome: string;
actor: string | null;
detail: string | null;
createdAt: string;
};

export async function listAuditEventsForTarget(
env: Env,
options: { repoFullName: string; pullNumber: number; sinceIso?: string | undefined; limit?: number | undefined },
): Promise<AuditEventForTarget[]> {
const limit = clampInteger(options.limit ?? 50, 1, 200);
const targetKey = `${options.repoFullName}#${options.pullNumber}`;
const conditions: SQL[] = [eq(sql`lower(${auditEvents.targetKey})`, targetKey.toLowerCase())];
if (options.sinceIso) conditions.push(gte(auditEvents.createdAt, options.sinceIso));
const rows = await getDb(env.DB)
.select({ eventType: auditEvents.eventType, outcome: auditEvents.outcome, actor: auditEvents.actor, detail: auditEvents.detail, createdAt: auditEvents.createdAt })
.from(auditEvents)
.where(and(...conditions))
.orderBy(desc(auditEvents.createdAt), desc(auditEvents.id))
.limit(limit);
return rows.map((row) => ({
eventType: row.eventType,
outcome: row.outcome,
actor: row.actor,
detail: row.detail,
createdAt: row.createdAt,
}));
}

export async function getFreshOfficialMinerDetection(env: Env, login: string, now = nowIso()): Promise<OfficialGittensorMinerDetection | null> {
const [row] = await getDb(env.DB).select().from(officialMinerDetections).where(and(eq(officialMinerDetections.login, login.toLowerCase()), gte(officialMinerDetections.expiresAt, now))).limit(1);
return row ? toOfficialMinerDetection(row) : null;
Expand Down
47 changes: 32 additions & 15 deletions src/openapi/spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,26 +442,43 @@ export function buildOpenApiSpec() {
path: "/v1/repos/{owner}/{repo}/agent/audit-feed",
responses: {
200: {
description: "Maintainer-scoped agent audit feed (#784): executed actions + approval-queue decisions, newest first, public-safe action posture only. Supports ?since=ISO-8601&limit=1-200.",
description:
"Maintainer-scoped agent audit feed (#784): executed actions + approval-queue decisions, newest first, public-safe action posture only. Supports ?since=ISO-8601&limit=1-200. " +
"?pull=N opts into the unfiltered sibling query: every audit_events row for that one PR's targetKey (no eventType restriction), still maintainer-gated and detail-sanitized the same way.",
content: {
"application/json": {
schema: z.object({
repoFullName: z.string(),
events: z.array(
z.object({
eventType: z.string(),
pullNumber: z.number().nullable(),
outcome: z.string(),
actor: z.string().nullable(),
detail: z.string().nullable(),
createdAt: z.string(),
}),
),
}),
schema: z.union([
z.object({
repoFullName: z.string(),
events: z.array(
z.object({
eventType: z.string(),
pullNumber: z.number().nullable(),
outcome: z.string(),
actor: z.string().nullable(),
detail: z.string().nullable(),
createdAt: z.string(),
}),
),
}),
z.object({
repoFullName: z.string(),
pullNumber: z.number(),
events: z.array(
z.object({
eventType: z.string(),
outcome: z.string(),
actor: z.string().nullable(),
detail: z.string().nullable(),
createdAt: z.string(),
}),
),
}),
]),
},
},
},
400: { description: "Malformed since (not ISO-8601) or limit (not an integer in 1-200)" },
400: { description: "Malformed since (not ISO-8601), limit (not an integer in 1-200), or pull (not a positive integer)" },
403: { description: "Insufficient role" },
},
});
Expand Down
39 changes: 33 additions & 6 deletions src/queue/processors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8164,6 +8164,19 @@ async function maybePublishPrPublicSurface(
source: decisionResult.source,
}),
);
await recordAuditEvent(env, {
eventType: "github_app.type_label_decision",
targetKey: `${repoFullName}#${pr.number}`,
outcome: "completed",
// `|| "none"` is unreachable: resolvePrTypeLabel's "title" source always resolves a non-empty
// label (deriveKindFromTitle only ever returns "bug"/"feature", and parseTypeLabelSet always
// falls back a built-in category to its default rather than an empty string), and its
// propagation sources only ever use a mapping's `prLabel`, which normalizeMapping drops
// entirely when empty -- applyLabels can never be [] here.
/* v8 ignore next */
detail: `applied labels: ${decisionResult.applyLabels.join(", ") || "none"}`,
metadata: { labels: decisionResult.applyLabels, source: decisionResult.source },
}).catch(() => undefined);
} catch (error) {
console.log(
JSON.stringify({
Expand All @@ -8173,22 +8186,36 @@ async function maybePublishPrPublicSurface(
message: errorMessage(error).slice(0, 150),
}),
);
await recordAuditEvent(env, {
eventType: "github_app.type_label_decision",
targetKey: `${repoFullName}#${pr.number}`,
outcome: "error",
detail: errorMessage(error).slice(0, 150),
metadata: { labels: [], source: null },
}).catch(() => undefined);
}
} else {
const skipReason = settings.agentPaused
? "agent_paused"
: decision.skipReason === "miner_detection_unavailable" || decision.skipReason === "not_official_gittensor_miner"
? decision.skipReason
: "typeLabelsEnabled_false";
console.log(
JSON.stringify({
event: "type_label_decision",
repoFullName,
pull: pr.number,
applied: false,
reason: settings.agentPaused
? "agent_paused"
: decision.skipReason === "miner_detection_unavailable" ||
decision.skipReason === "not_official_gittensor_miner"
? decision.skipReason
: "typeLabelsEnabled_false",
reason: skipReason,
}),
);
await recordAuditEvent(env, {
eventType: "github_app.type_label_decision",
targetKey: `${repoFullName}#${pr.number}`,
outcome: "denied",
detail: skipReason,
metadata: { labels: [], source: null },
}).catch(() => undefined);
}

// Respect the per-repo agent pause: suppress all public surface mutations (label, comment, context
Expand Down
Loading
Loading