@claudexor/synthesis 1.0.0
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/LICENSE +21 -0
- package/README.md +7 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +88 -0
- package/dist/index.js.map +1 -0
- package/package.json +40 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 joi-lab
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# @claudexor/synthesis
|
|
2
|
+
|
|
3
|
+
Internal package of [Claudexor](https://github.com/razzant/claudexor) — Synthesis decision + plan: when to merge candidates into a new (re-checked) candidate.
|
|
4
|
+
|
|
5
|
+
Published as part of the Claudexor toolchain; it follows the monorepo's
|
|
6
|
+
lockstep version and has no separate semver contract. Use the `claudexor`
|
|
7
|
+
CLI (or `@claudexor/cli`) as the supported entry point.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { CandidateEvidence } from "@claudexor/arbitration";
|
|
2
|
+
export type SynthesisMode = "auto" | "always" | "never";
|
|
3
|
+
export interface SynthesisDecision {
|
|
4
|
+
synthesize: boolean;
|
|
5
|
+
reason: string;
|
|
6
|
+
sources: string[];
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Auto mode only synthesizes a 3rd candidate when there are at least this many
|
|
10
|
+
* candidates. best-of-2 just picks the winner: synthesizing on n=2 adds a 3rd
|
|
11
|
+
* paid harness run + a 3rd full review pass (~3x cost) for marginal benefit.
|
|
12
|
+
* `--synthesis always` overrides this; `never` disables.
|
|
13
|
+
*/
|
|
14
|
+
export declare const AUTO_SYNTHESIS_MIN_CANDIDATES = 3;
|
|
15
|
+
/**
|
|
16
|
+
* Decide whether synthesizing a new candidate is worthwhile. Auto mode
|
|
17
|
+
* synthesizes (when >= AUTO_SYNTHESIS_MIN_CANDIDATES) if there is no clear
|
|
18
|
+
* winner, the best candidate has fixable accepted findings, or candidates have
|
|
19
|
+
* complementary strengths. A single clearly-winning candidate — and any n<3
|
|
20
|
+
* auto race — is NOT synthesized.
|
|
21
|
+
*/
|
|
22
|
+
export declare function decideSynthesis(candidates: CandidateEvidence[], mode?: SynthesisMode): SynthesisDecision;
|
|
23
|
+
export interface SynthesisPlan {
|
|
24
|
+
baseFrom: string;
|
|
25
|
+
borrowTestsFrom: string | null;
|
|
26
|
+
fixFindings: string[];
|
|
27
|
+
instructions: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Build a plan for the synthesizer harness. The synthesized output MUST then be
|
|
31
|
+
* re-run through gates + review + revalidation + arbitration as a new candidate
|
|
32
|
+
* (never applied unchecked, never a blind diff concatenation).
|
|
33
|
+
*/
|
|
34
|
+
export declare function buildSynthesisPlan(candidates: CandidateEvidence[]): SynthesisPlan;
|
|
35
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAGhE,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAC;AAExD,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,OAAO,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAID;;;;;GAKG;AACH,eAAO,MAAM,6BAA6B,IAAI,CAAC;AAE/C;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,UAAU,EAAE,iBAAiB,EAAE,EAAE,IAAI,GAAE,aAAsB,GAAG,iBAAiB,CAiDhH;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,iBAAiB,EAAE,GAAG,aAAa,CA0BjF"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { candidateSummary, compareCandidates } from "@claudexor/arbitration";
|
|
2
|
+
const FIXABLE_STATUSES = new Set(["accepted", "accepted_risk"]);
|
|
3
|
+
/**
|
|
4
|
+
* Auto mode only synthesizes a 3rd candidate when there are at least this many
|
|
5
|
+
* candidates. best-of-2 just picks the winner: synthesizing on n=2 adds a 3rd
|
|
6
|
+
* paid harness run + a 3rd full review pass (~3x cost) for marginal benefit.
|
|
7
|
+
* `--synthesis always` overrides this; `never` disables.
|
|
8
|
+
*/
|
|
9
|
+
export const AUTO_SYNTHESIS_MIN_CANDIDATES = 3;
|
|
10
|
+
/**
|
|
11
|
+
* Decide whether synthesizing a new candidate is worthwhile. Auto mode
|
|
12
|
+
* synthesizes (when >= AUTO_SYNTHESIS_MIN_CANDIDATES) if there is no clear
|
|
13
|
+
* winner, the best candidate has fixable accepted findings, or candidates have
|
|
14
|
+
* complementary strengths. A single clearly-winning candidate — and any n<3
|
|
15
|
+
* auto race — is NOT synthesized.
|
|
16
|
+
*/
|
|
17
|
+
export function decideSynthesis(candidates, mode = "auto") {
|
|
18
|
+
if (mode === "never")
|
|
19
|
+
return { synthesize: false, reason: "synthesis disabled", sources: [] };
|
|
20
|
+
if (candidates.length < 2) {
|
|
21
|
+
return { synthesize: false, reason: "need >= 2 candidates to synthesize", sources: candidates.map((c) => c.attemptId) };
|
|
22
|
+
}
|
|
23
|
+
if (mode === "always") {
|
|
24
|
+
return { synthesize: true, reason: "synthesis forced (always)", sources: candidates.map((c) => c.attemptId) };
|
|
25
|
+
}
|
|
26
|
+
if (candidates.length < AUTO_SYNTHESIS_MIN_CANDIDATES) {
|
|
27
|
+
return {
|
|
28
|
+
synthesize: false,
|
|
29
|
+
reason: `auto synthesis needs >= ${AUTO_SYNTHESIS_MIN_CANDIDATES} candidates (best-of-${candidates.length} picks the winner)`,
|
|
30
|
+
sources: candidates.map((c) => c.attemptId),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
const ranked = [...candidates].sort(compareCandidates);
|
|
34
|
+
const top = ranked[0];
|
|
35
|
+
const second = ranked[1];
|
|
36
|
+
const ts = candidateSummary(top);
|
|
37
|
+
const ss = candidateSummary(second);
|
|
38
|
+
const strictlyBetter = compareCandidates(top, second) < 0;
|
|
39
|
+
const clearWinner = ts.gatesPassed && ts.clean && ts.blockers === 0 && strictlyBetter;
|
|
40
|
+
const topFixable = top.findings.some((f) => FIXABLE_STATUSES.has(f.status));
|
|
41
|
+
// Only a GREEN runner-up can contribute complementary strengths: a failed
|
|
42
|
+
// candidate with an empty diff is not "simpler", and synthesizing against it
|
|
43
|
+
// wastes a paid run plus a full review pass.
|
|
44
|
+
const complementary = ss.gatesPassed &&
|
|
45
|
+
(ss.testFraction > ts.testFraction ||
|
|
46
|
+
ss.acceptance > ts.acceptance ||
|
|
47
|
+
ss.blockers < ts.blockers ||
|
|
48
|
+
(second.diffSize ?? 0) < (top.diffSize ?? 0)); // second is simpler on a lower-priority axis
|
|
49
|
+
if (clearWinner && !topFixable && !complementary) {
|
|
50
|
+
return { synthesize: false, reason: "a single candidate clearly passes all gates and review", sources: [top.attemptId] };
|
|
51
|
+
}
|
|
52
|
+
const reasons = [];
|
|
53
|
+
if (!clearWinner)
|
|
54
|
+
reasons.push("no clear winner");
|
|
55
|
+
if (topFixable)
|
|
56
|
+
reasons.push("best candidate has fixable accepted findings");
|
|
57
|
+
if (complementary)
|
|
58
|
+
reasons.push("candidates have complementary strengths");
|
|
59
|
+
return {
|
|
60
|
+
synthesize: true,
|
|
61
|
+
reason: reasons.join("; "),
|
|
62
|
+
sources: ranked.slice(0, Math.min(3, ranked.length)).map((c) => c.attemptId),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Build a plan for the synthesizer harness. The synthesized output MUST then be
|
|
67
|
+
* re-run through gates + review + revalidation + arbitration as a new candidate
|
|
68
|
+
* (never applied unchecked, never a blind diff concatenation).
|
|
69
|
+
*/
|
|
70
|
+
export function buildSynthesisPlan(candidates) {
|
|
71
|
+
const ranked = [...candidates].sort(compareCandidates);
|
|
72
|
+
const base = ranked[0];
|
|
73
|
+
const bestTests = [...candidates].sort((a, b) => candidateSummary(b).testFraction - candidateSummary(a).testFraction)[0];
|
|
74
|
+
const fixFindings = [
|
|
75
|
+
...new Set(candidates.flatMap((c) => c.findings.filter((f) => FIXABLE_STATUSES.has(f.status)).map((f) => f.claim))),
|
|
76
|
+
];
|
|
77
|
+
const borrowTestsFrom = bestTests.attemptId !== base.attemptId ? bestTests.attemptId : null;
|
|
78
|
+
const instructions = [
|
|
79
|
+
`Start from ${base.label}.`,
|
|
80
|
+
borrowTestsFrom ? `Use the stronger gate/test results from ${bestTests.label} as evidence, but do not edit protected tests or gate configuration unless the user explicitly asked for test changes.` : "",
|
|
81
|
+
fixFindings.length > 0 ? `Fix the accepted findings (${fixFindings.length}).` : "",
|
|
82
|
+
"Produce a single coherent patch; do not blindly concatenate diffs. The result will be re-reviewed.",
|
|
83
|
+
]
|
|
84
|
+
.filter(Boolean)
|
|
85
|
+
.join(" ");
|
|
86
|
+
return { baseFrom: base.attemptId, borrowTestsFrom, fixFindings, instructions };
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAU7E,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC,CAAC,UAAU,EAAE,eAAe,CAAC,CAAC,CAAC;AAEhE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAAC,CAAC;AAE/C;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAAC,UAA+B,EAAE,OAAsB,MAAM;IAC3F,IAAI,IAAI,KAAK,OAAO;QAAE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,oBAAoB,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;IAC9F,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC1B,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,oCAAoC,EAAE,OAAO,EAAE,UAAU,CAAC,GAAG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AE,YAAY,EAAE,CAAC;AAClF,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@claudexor/synthesis",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"description": "Synthesis decision + plan: when to merge candidates into a new (re-checked) candidate.",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@claudexor/arbitration": "1.0.0"
|
|
20
|
+
},
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/razzant/claudexor.git",
|
|
24
|
+
"directory": "packages/synthesis"
|
|
25
|
+
},
|
|
26
|
+
"homepage": "https://github.com/razzant/claudexor#readme",
|
|
27
|
+
"bugs": {
|
|
28
|
+
"url": "https://github.com/razzant/claudexor/issues"
|
|
29
|
+
},
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=20.19"
|
|
32
|
+
},
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsc",
|
|
38
|
+
"typecheck": "tsc --noEmit"
|
|
39
|
+
}
|
|
40
|
+
}
|