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
28 changes: 28 additions & 0 deletions apps/gittensory-ui/public/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -4296,16 +4296,20 @@
},
"credibilityFloor": {
"type": "number"
},

Check notice on line 4299 in apps/gittensory-ui/public/openapi.json

View check run for this annotation

Deleted GitHub App / Gittensory Context

Issue discovery is disabled for this repo

This repo is configured for direct contribution review rather than issue-discovery flow.
"credibilityObserved": {
"type": "number"
},
"reviewCollateralMultiplier": {
"type": "number"
}
},
"required": [
"baseTokenGatePassed",
"openPrThreshold",
"openPrCount",
"collateralFraction",
"reviewCollateralMultiplier",
"credibilityFloor",
"credibilityObserved"
]
Expand Down Expand Up @@ -4551,13 +4555,17 @@
},
"credibilityObserved": {
"type": "number"
},
"reviewCollateralMultiplier": {
"type": "number"
}
},
"required": [
"baseTokenGatePassed",
"openPrThreshold",
"openPrCount",
"collateralFraction",
"reviewCollateralMultiplier",
"credibilityFloor",
"credibilityObserved"
]
Expand Down Expand Up @@ -4803,13 +4811,17 @@
},
"credibilityObserved": {
"type": "number"
},
"reviewCollateralMultiplier": {
"type": "number"
}
},
"required": [
"baseTokenGatePassed",
"openPrThreshold",
"openPrCount",
"collateralFraction",
"reviewCollateralMultiplier",
"credibilityFloor",
"credibilityObserved"
]
Expand Down Expand Up @@ -5055,13 +5067,17 @@
},
"credibilityObserved": {
"type": "number"
},
"reviewCollateralMultiplier": {
"type": "number"
}
},
"required": [
"baseTokenGatePassed",
"openPrThreshold",
"openPrCount",
"collateralFraction",
"reviewCollateralMultiplier",
"credibilityFloor",
"credibilityObserved"
]
Expand Down Expand Up @@ -5307,13 +5323,17 @@
},
"credibilityObserved": {
"type": "number"
},
"reviewCollateralMultiplier": {
"type": "number"
}
},
"required": [
"baseTokenGatePassed",
"openPrThreshold",
"openPrCount",
"collateralFraction",
"reviewCollateralMultiplier",
"credibilityFloor",
"credibilityObserved"
]
Expand Down Expand Up @@ -6207,13 +6227,17 @@
},
"credibilityObserved": {
"type": "number"
},
"reviewCollateralMultiplier": {
"type": "number"
}
},
"required": [
"baseTokenGatePassed",
"openPrThreshold",
"openPrCount",
"collateralFraction",
"reviewCollateralMultiplier",
"credibilityFloor",
"credibilityObserved"
]
Expand Down Expand Up @@ -6455,13 +6479,17 @@
},
"credibilityObserved": {
"type": "number"
},
"reviewCollateralMultiplier": {
"type": "number"
}
},
"required": [
"baseTokenGatePassed",
"openPrThreshold",
"openPrCount",
"collateralFraction",
"reviewCollateralMultiplier",
"credibilityFloor",
"credibilityObserved"
]
Expand Down
2 changes: 2 additions & 0 deletions src/api/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -464,9 +464,10 @@
activeModel: z.string().max(MAX_LOCAL_BRANCH_REF_CHARS).optional(),
sourceTokenScore: z.number().min(0).optional(),
totalTokenScore: z.number().min(0).optional(),
sourceLines: z.number().min(0).optional(),

Check notice on line 467 in src/api/routes.ts

View check run for this annotation

Deleted GitHub App / Gittensory Context

Issue discovery is disabled for this repo

This repo is configured for direct contribution review rather than issue-discovery flow.
testTokenScore: z.number().min(0).optional(),
nonCodeTokenScore: z.number().min(0).optional(),
nonCodeLines: z.number().min(0).optional(),
warnings: z.array(z.string().max(MAX_LOCAL_SCORER_WARNING_CHARS)).max(MAX_LOCAL_SCORER_WARNING_COUNT).optional(),
})
.strict();
Expand Down Expand Up @@ -544,6 +545,7 @@
sourceLines: z.number().min(0).optional(),
testTokenScore: z.number().min(0).optional(),
nonCodeTokenScore: z.number().min(0).optional(),
nonCodeLines: z.number().min(0).optional(),
existingContributorTokenScore: z.number().min(0).optional(),
prAgeHours: z.number().min(0).optional(),
openPrCount: z.number().int().min(0).optional(),
Expand Down
1 change: 1 addition & 0 deletions src/openapi/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1259,9 +1259,10 @@

const ScoreGatesSchema = z.object({
baseTokenGatePassed: z.boolean(),
openPrThreshold: z.number(),

Check notice on line 1262 in src/openapi/schemas.ts

View check run for this annotation

Deleted GitHub App / Gittensory Context

Issue discovery is disabled for this repo

This repo is configured for direct contribution review rather than issue-discovery flow.
openPrCount: z.number(),
collateralFraction: z.number(),
reviewCollateralMultiplier: z.number(),
credibilityFloor: z.number(),
credibilityObserved: z.number(),
});
Expand Down
3 changes: 1 addition & 2 deletions src/registry/normalize.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { DEFAULT_ISSUE_DISCOVERY_SHARE } from "../scoring/model";

Check notice on line 1 in src/registry/normalize.ts

View check run for this annotation

Deleted GitHub App / Gittensory Context

Issue discovery is disabled for this repo

This repo is configured for direct contribution review rather than issue-discovery flow.
import type { JsonValue, RegistryRepoConfig, RegistrySnapshot, RepoTimeDecayOverrides } from "../types";

type RawRepoConfig = Record<string, JsonValue>;

const DEFAULT_ISSUE_DISCOVERY_SHARE = 0.5;

export function normalizeRegistryPayload(payload: unknown, source: RegistrySnapshot["source"], fetchedAt: string): RegistrySnapshot {
const repos = extractRepoEntries(payload).map(([repo, config]) => normalizeRepo(repo, config));
const totalEmissionShare = repos.reduce((sum, repo) => sum + repo.emissionShare, 0);
Expand Down
5 changes: 5 additions & 0 deletions src/scoring/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
} from "../db/repositories";
import { getLatestRegistrySnapshot } from "../registry/sync";
import { syncUnmodeledScoringConstantDrift } from "../upstream/unmodeled-scoring-drift";
import type { JsonValue, ScoringModelSnapshotRecord } from "../types";

Check notice on line 7 in src/scoring/model.ts

View check run for this annotation

Deleted GitHub App / Gittensory Context

Issue discovery is disabled for this repo

This repo is configured for direct contribution review rather than issue-discovery flow.
import { errorMessage, nowIso } from "../utils/json";

export const DEFAULT_ISSUE_DISCOVERY_SHARE = 0.5;

export const DEFAULT_SCORING_CONSTANTS: Record<string, number> = {
OSS_EMISSION_SHARE: 0.9,
// Upstream name is ISSUES_TREASURY_EMISSION_SHARE (plural). The prior singular spelling never matched
Expand Down Expand Up @@ -34,6 +36,9 @@
OPEN_ISSUE_SPAM_TOKEN_SCORE_PER_SLOT: 300,
MAX_OPEN_ISSUE_THRESHOLD: 30,
OPEN_PR_COLLATERAL_PERCENT: 0.2,
MAX_OPEN_PR_REVIEW_COLLATERAL_MULTIPLIER: 2.0,
MAX_LINES_SCORED_FOR_NON_CODE_EXT: 300,
DEFAULT_ISSUE_DISCOVERY_SHARE,
REVIEW_PENALTY_RATE: 0.15,
STANDARD_ISSUE_MULTIPLIER: 1.33,
MAINTAINER_ISSUE_MULTIPLIER: 1.66,
Expand Down
29 changes: 26 additions & 3 deletions src/scoring/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
linkedIssueContext?: LinkedIssueMultiplierContext | undefined;
sourceTokenScore?: number | undefined;
totalTokenScore?: number | undefined;
sourceLines?: number | undefined;

Check notice on line 14 in src/scoring/preview.ts

View check run for this annotation

Deleted GitHub App / Gittensory Context

Issue discovery is disabled for this repo

This repo is configured for direct contribution review rather than issue-discovery flow.
testTokenScore?: number | undefined;
nonCodeTokenScore?: number | undefined;
/** Raw non-code line count before upstream's MAX_LINES_SCORED_FOR_NON_CODE_EXT cap. */
nonCodeLines?: number | undefined;
existingContributorTokenScore?: number | undefined;
openPrCount?: number | undefined;
/** Contributor's current open-issue count for the repo, used for the open-issue spam gate (#808). */
Expand Down Expand Up @@ -171,7 +173,10 @@
baseTokenGatePassed: boolean;
openPrThreshold: number;
openPrCount: number;
/** Effective open-PR collateral fraction (OPEN_PR_COLLATERAL_PERCENT × reviewCollateralMultiplier). */
collateralFraction: number;
/** Upstream open-PR review-collateral multiplier from CHANGES_REQUESTED reviews (≥ 1, capped). */
reviewCollateralMultiplier: number;
credibilityFloor: number;
credibilityObserved: number;
openIssueThreshold: number;
Expand Down Expand Up @@ -298,7 +303,10 @@
// TEST_FILE_CONTRIBUTION_WEIGHT (#808): upstream weights test-file tokens at 0.05× relative to source tokens.
// Applied only when totalTokenScore is not explicitly provided — an explicit caller total is honoured as-is.
const testFileWeight = constant(constants, "TEST_FILE_CONTRIBUTION_WEIGHT", 0.05);
const totalTokenScore = nonNegative(input.totalTokenScore ?? sourceTokenScore + testFileWeight * nonNegative(input.testTokenScore) + nonNegative(input.nonCodeTokenScore));
const cappedNonCodeTokenScore = applyNonCodeLineCap(input, constants);
const totalTokenScore = nonNegative(
input.totalTokenScore ?? sourceTokenScore + testFileWeight * nonNegative(input.testTokenScore) + cappedNonCodeTokenScore,
);
const sourceLines = Math.max(1, nonNegative(input.sourceLines ?? sourceTokenScore));
const fixedBaseScore = input.fixedBaseScore ?? config?.fixedBaseScore ?? undefined;
const rawDensity = sourceTokenScore / sourceLines;
Expand All @@ -325,7 +333,13 @@
const credibilityFloor = constant(constants, "MIN_CREDIBILITY", 0.8);
const credibilityMultiplier = credibilityObserved >= credibilityFloor ? 1 : credibilityObserved / credibilityFloor;
const changesRequestedCount = nonNegative(input.changesRequestedCount);
const reviewPenaltyMultiplier = clamp(1 - changesRequestedCount * constant(constants, "REVIEW_PENALTY_RATE", 0.15), 0, 1);
const reviewPenaltyRate = constant(constants, "REVIEW_PENALTY_RATE", 0.15);
const reviewPenaltyMultiplier = clamp(1 - changesRequestedCount * reviewPenaltyRate, 0, 1);
const reviewCollateralMultiplier = Math.min(
constant(constants, "MAX_OPEN_PR_REVIEW_COLLATERAL_MULTIPLIER", 2.0),
1 + changesRequestedCount * reviewPenaltyRate,
);
const openPrCollateralPercent = constant(constants, "OPEN_PR_COLLATERAL_PERCENT", 0.2);
const openPrCount = nonNegative(input.openPrCount);
// The concurrency allowance is earned from the contributor's established merged-history token
// score; the planned PR's own tokens (totalTokenScore) must not inflate its own open-PR threshold.
Expand Down Expand Up @@ -381,7 +395,8 @@
baseTokenGatePassed,
openPrThreshold,
openPrCount,
collateralFraction: constant(constants, "OPEN_PR_COLLATERAL_PERCENT", 0.2),
reviewCollateralMultiplier: roundScore(reviewCollateralMultiplier),
collateralFraction: roundScore(openPrCollateralPercent * reviewCollateralMultiplier),
credibilityFloor,
credibilityObserved,
openIssueThreshold,
Expand Down Expand Up @@ -955,6 +970,14 @@
return clamp(0.75 + merged * 0.04 - stale * 0.03 - unlinked * 0.02, 0.25, 1);
}

function applyNonCodeLineCap(input: Pick<ScorePreviewInput, "nonCodeTokenScore" | "nonCodeLines">, constants: Record<string, number>): number {
const score = nonNegative(input.nonCodeTokenScore);
const lines = nonNegative(input.nonCodeLines);
if (score <= 0 || lines <= 0) return score;
const maxLines = constant(constants, "MAX_LINES_SCORED_FOR_NON_CODE_EXT", 300);
return lines <= maxLines ? score : score * (maxLines / lines);
}

function constant(constants: Record<string, number>, key: string, fallback: number): number {
const value = constants[key];
return typeof value === "number" && Number.isFinite(value) ? value : fallback;
Expand Down
1 change: 1 addition & 0 deletions src/signals/local-branch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -468,9 +468,10 @@
linkedIssueContext: args.linkedIssueContext,
sourceTokenScore: scorer?.sourceTokenScore ?? Math.max(0, sourceLineCount),
totalTokenScore: scorer?.totalTokenScore ?? Math.max(0, args.changedLineCount),
sourceLines: scorer?.sourceLines ?? Math.max(1, sourceLineCount || args.changedLineCount || 1),

Check notice on line 471 in src/signals/local-branch.ts

View check run for this annotation

Deleted GitHub App / Gittensory Context

Issue discovery is disabled for this repo

This repo is configured for direct contribution review rather than issue-discovery flow.
testTokenScore: scorer?.testTokenScore ?? testLineCount,
nonCodeTokenScore: scorer?.nonCodeTokenScore ?? nonCodeLineCount,
nonCodeLines: nonCodeLineCount,
openPrCount: args.outcomeHistory.totals.openPullRequests,
openIssueCount: args.repoOutcome?.openIssues ?? args.outcomeHistory.totals.openIssues,
credibility: args.repoOutcome?.credibility ?? args.outcomeHistory.totals.credibility,
Expand Down
10 changes: 9 additions & 1 deletion test/unit/registry.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { afterEach, describe, expect, it, vi } from "vitest";

Check notice on line 1 in test/unit/registry.test.ts

View check run for this annotation

Deleted GitHub App / Gittensory Context

Issue discovery is disabled for this repo

This repo is configured for direct contribution review rather than issue-discovery flow.
import { getRepository, upsertRepositoryFromGitHub } from "../../src/db/repositories";
import { normalizeRegistryPayload } from "../../src/registry/normalize";
import { DEFAULT_ISSUE_DISCOVERY_SHARE } from "../../src/scoring/model";
import { getLatestRegistrySnapshot, persistRegistrySnapshot, refreshRegistry } from "../../src/registry/sync";
import { createTestEnv } from "../helpers/d1";

Expand Down Expand Up @@ -122,8 +123,15 @@
trustedLabelPipeline: true,
});
expect(fromObjectMap.repositories.map((repo) => repo.repo)).toEqual(["JSONbored/gittensory"]);
expect(fromObjectMap.repositories[0]).toMatchObject({
repo: "JSONbored/gittensory",
issueDiscoveryShare: DEFAULT_ISSUE_DISCOVERY_SHARE,
});
expect(fromArray.repositories.map((repo) => repo.repo)).toEqual(["JSONbored/gittensory", "bad/numbers"]);
expect(fromArray.repositories.find((repo) => repo.repo === "bad/numbers")).toMatchObject({ emissionShare: 0, issueDiscoveryShare: 0.5 });
expect(fromArray.repositories.find((repo) => repo.repo === "bad/numbers")).toMatchObject({
emissionShare: 0,
issueDiscoveryShare: DEFAULT_ISSUE_DISCOVERY_SHARE,
});
expect(empty.repoCount).toBe(0);
});

Expand Down
Loading
Loading