@olegkoval/agent-skills 1.79.0 → 1.81.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/adapters/claude/olko-github-pr/skills/lekker-review/SKILL.md +35 -0
- package/adapters/claude/olko-github-pr/skills/lekker-review/references/codex-workflow.md +46 -2
- package/adapters/claude/olko-github-pr/skills/lekker-review/scripts/codex-usage.mjs +32 -11
- package/adapters/claude/olko-github-pr/skills/lekker-review/scripts/native-results.mjs +49 -0
- package/docs/lekker-prompt-experiments.md +161 -0
- package/package.json +1 -1
- package/plugins/olko-apple-kit/.claude-plugin/plugin.json +1 -1
- package/plugins/olko-creative/.claude-plugin/plugin.json +1 -1
- package/plugins/olko-garmin-kit/.claude-plugin/plugin.json +1 -1
- package/plugins/olko-git-tools/.claude-plugin/plugin.json +1 -1
- package/plugins/olko-github-pr/.claude-plugin/plugin.json +1 -1
- package/plugins/olko-github-pr/skills/lekker-review/SKILL.md +35 -0
- package/plugins/olko-github-pr/skills/lekker-review/references/codex-workflow.md +46 -2
- package/plugins/olko-github-pr/skills/lekker-review/scripts/codex-usage.mjs +32 -11
- package/plugins/olko-github-pr/skills/lekker-review/scripts/native-results.mjs +49 -0
- package/plugins/olko-obsidian/.claude-plugin/plugin.json +1 -1
- package/plugins/olko-product/.claude-plugin/plugin.json +1 -1
- package/plugins/olko-reflection/.claude-plugin/plugin.json +1 -1
- package/plugins/olko-release/.claude-plugin/plugin.json +1 -1
- package/plugins/olko-skill-meta/.claude-plugin/plugin.json +1 -1
- package/plugins/olko-web-ops/.claude-plugin/plugin.json +1 -1
|
@@ -366,6 +366,12 @@ scripts reject `scan` (see Depth gate). If depth resolves to `scan` or `deps`
|
|
|
366
366
|
the flag and note `engine forced to <workflow|codex> - revmux needs
|
|
367
367
|
medium/deep` in the review header.
|
|
368
368
|
|
|
369
|
+
**`--deterministic-dedup` flag:** after resolving ENGINE, opt in to the trusted
|
|
370
|
+
native dedup helper for the initial Review -> Dedup stage only. Record it as
|
|
371
|
+
`deterministicDedup` in CONTEXT_FILE. Accept it only with `ENGINE=codex`;
|
|
372
|
+
otherwise report unsupported and stop. Without the flag, preserve the existing
|
|
373
|
+
manual native merge.
|
|
374
|
+
|
|
369
375
|
**Re-review detection:** run
|
|
370
376
|
`ls ~/code-reviews/*-<TARGET_SLUG>-<repo-short-name>.md 2>/dev/null | sort | tail -1`
|
|
371
377
|
(`TARGET_SLUG` = `pr-<PR_NUMBER>` in pr mode, `branch-<LOCAL_BRANCH sanitized to
|
|
@@ -682,6 +688,32 @@ git -C <worktreePath> log --format='%s%n%b' <mergeBase>..HEAD
|
|
|
682
688
|
- (medium/deep only, optional) Prior-review-memory recall, if you maintain
|
|
683
689
|
such a system: patterns and false positives specific to this repo.
|
|
684
690
|
|
|
691
|
+
### Collect shared deterministic evidence
|
|
692
|
+
|
|
693
|
+
For a run with `worktree.json`, collect once through the trusted installed
|
|
694
|
+
helper before assembling context. Never run a copy from the reviewed worktree:
|
|
695
|
+
|
|
696
|
+
```sh
|
|
697
|
+
node "<SKILL_ROOT>/scripts/evidence-bundle.mjs" \
|
|
698
|
+
--worktree "<scratchpad>/worktree.json" > "<scratchpad>/evidence-bundle.json"
|
|
699
|
+
jq 'del(.git.diff.text, .lint.report)' "<scratchpad>/evidence-bundle.json" \
|
|
700
|
+
> "<scratchpad>/static-evidence.json"
|
|
701
|
+
```
|
|
702
|
+
|
|
703
|
+
Check each exit status and re-read the JSON. Missing tools, nonzero exits or
|
|
704
|
+
malformed output make this collection unavailable: preserve diagnostics and
|
|
705
|
+
set both context paths below to null. Do not silently pass an empty file.
|
|
706
|
+
When Git evidence is available, its provenance base/head must match the
|
|
707
|
+
review's selected commit pair; a mismatch invalidates the collection, never
|
|
708
|
+
changes the review target. Unavailable Git or lint stays explicitly unknown.
|
|
709
|
+
|
|
710
|
+
The compact view removes only duplicate raw diff text and lint report data.
|
|
711
|
+
Keep the full bundle for provenance and detail; semantic review still reads
|
|
712
|
+
DIFF_FILE and existing lint/preflight inputs. Do not replace changedPaths,
|
|
713
|
+
project rules or the mandatory risk check with a different Git diff. Reuse
|
|
714
|
+
available pinned inventory instead of recollecting it in every review agent.
|
|
715
|
+
In scan/no-worktree mode, set both paths to null; do not fabricate a bundle.
|
|
716
|
+
|
|
685
717
|
### Assemble CONTEXT_FILE
|
|
686
718
|
|
|
687
719
|
Write `<scratchpad>/context.json` with keys:
|
|
@@ -701,8 +733,11 @@ Write `<scratchpad>/context.json` with keys:
|
|
|
701
733
|
"prePush": "<true in MODE=branch, false in MODE=pr>",
|
|
702
734
|
"preflightFile": "<PREFLIGHT_FILE, or null>",
|
|
703
735
|
"botPatternsFile": "<BOT_PATTERNS_FILE, or null>",
|
|
736
|
+
"evidenceBundleFile": "<full evidence-bundle.json path; null on collection failure or no worktree>",
|
|
737
|
+
"staticEvidenceFile": "<compact static-evidence.json path; null on collection failure or no worktree>",
|
|
704
738
|
"depsReport": "<deps-report.json contents at depth deps, else null>",
|
|
705
739
|
"depsInstall": "<worktree.json depsInstall>",
|
|
740
|
+
"deterministicDedup": "<boolean: true only for explicit --deterministic-dedup with ENGINE=codex>",
|
|
706
741
|
"prBody": "<full PR body at every depth; empty string in branch mode>"
|
|
707
742
|
}
|
|
708
743
|
```
|
|
@@ -57,7 +57,10 @@ repository-relative `file:line` (empty array when there is none).
|
|
|
57
57
|
Implementation additionally returns `acCoverage`. Test-quality additionally
|
|
58
58
|
returns `coverageVerdict`, `mutationSlip`, and `mockSmells`.
|
|
59
59
|
|
|
60
|
-
Use `apply_patch` for every file
|
|
60
|
+
Use `apply_patch` for every file authored by Codex. The only exception is
|
|
61
|
+
capturing JSON stdout from trusted installed mechanical helpers verbatim to
|
|
62
|
+
their assigned scratchpad file; never rewrite that output through the model.
|
|
63
|
+
Re-read each JSON file before
|
|
61
64
|
trusting it. Invalid JSON or a missing required field makes that agent result
|
|
62
65
|
unavailable; do not infer what it meant from prose.
|
|
63
66
|
|
|
@@ -76,7 +79,11 @@ bounded task:
|
|
|
76
79
|
1. Read its exact prompt under
|
|
77
80
|
`<SKILL_ROOT>/references/agents/<dimension>.md`.
|
|
78
81
|
2. Read `DIFF_FILE` and `CONTEXT_FILE` by path. Read the worktree only when one
|
|
79
|
-
exists. Never paste the whole diff into the task message.
|
|
82
|
+
exists. Never paste the whole diff into the task message. When context supplies
|
|
83
|
+
a non-null `staticEvidenceFile`, reuse its available commit-bound inventory; report
|
|
84
|
+
stale/unavailable facts to the coordinator rather than silently retargeting
|
|
85
|
+
or recollecting them per agent. It does not replace semantic investigation,
|
|
86
|
+
the authoritative diff, or required schema/completion/verification gates.
|
|
80
87
|
3. Review only the target diff. Do not edit files, run git writes, post to
|
|
81
88
|
GitHub, or communicate externally.
|
|
82
89
|
4. Write the shared result contract to
|
|
@@ -103,6 +110,43 @@ unavailable; never loop blindly.
|
|
|
103
110
|
|
|
104
111
|
## Dedup stage
|
|
105
112
|
|
|
113
|
+
When `deterministicDedup` in CONTEXT_FILE is exactly boolean `true`, replace
|
|
114
|
+
only this initial merge with the trusted installed helper. First finish the
|
|
115
|
+
Review barrier and validate each selected dimension against the shared result
|
|
116
|
+
contract. The helper checks record shape, not the complete finding schema or
|
|
117
|
+
required-dimension completion; those checks remain mandatory here.
|
|
118
|
+
|
|
119
|
+
Use `apply_patch` to write `<scratchpad>/codex-dedup-manifest.json`:
|
|
120
|
+
|
|
121
|
+
```json
|
|
122
|
+
{"dimensions":[{"name":"quality","path":"<assigned quality result JSON>"}]}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Use absolute result paths. Include every valid selected dimension, even one
|
|
126
|
+
with empty findings, in the original selected-dimension order. Use
|
|
127
|
+
coordinator-assigned names and paths, never finding-supplied attribution.
|
|
128
|
+
Keep unavailable dimensions explicitly
|
|
129
|
+
unavailable in completion accounting; omitting them from this manifest cannot
|
|
130
|
+
make the review complete. If none is valid, record Dedup unavailable.
|
|
131
|
+
|
|
132
|
+
Run only the trusted installed script, never code from the reviewed worktree:
|
|
133
|
+
|
|
134
|
+
```sh
|
|
135
|
+
node "<SKILL_ROOT>/scripts/native-dedup.mjs" \
|
|
136
|
+
--manifest "<scratchpad>/codex-dedup-manifest.json" \
|
|
137
|
+
> "<scratchpad>/codex-deduped-findings.json"
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Check exit status and re-read the output. Nonzero exit, unreadable output or
|
|
141
|
+
invalid JSON means Dedup unavailable, never an empty successful finding set;
|
|
142
|
+
do not proceed to Verify with that output. Preserve raw dimension documents.
|
|
143
|
+
Use the helper output without manually repeating its merge. Its canonical
|
|
144
|
+
Workflow policy includes PROJECT quote exceptions and arrival-order evidence
|
|
145
|
+
ownership; this is explicit policy alignment, not exact old-prose parity.
|
|
146
|
+
Critic-stage incremental merging and all later gates remain unchanged.
|
|
147
|
+
|
|
148
|
+
Without that explicit opt-in, retain the existing manual merge below.
|
|
149
|
+
|
|
106
150
|
The coordinator reads every valid reviewer JSON file and merges duplicate
|
|
107
151
|
findings before spending verifier agents:
|
|
108
152
|
|
|
@@ -7,14 +7,17 @@ const FIELDS = ['input_tokens', 'cached_input_tokens', 'cache_write_input_tokens
|
|
|
7
7
|
const record = v => v && typeof v === 'object' && !Array.isArray(v);
|
|
8
8
|
const unavailable = (agentPath, reason) => ({ agentPath, status: 'unavailable', reason });
|
|
9
9
|
|
|
10
|
-
async function inspectSession(sessionFile, parentThreadId, agentPath) {
|
|
11
|
-
let sessionId = null, usage = null, complete = false, models = [];
|
|
10
|
+
async function inspectSession(sessionFile, parentThreadId, agentPath, requireUsage) {
|
|
11
|
+
let sessionId = null, usage = null, complete = false, models = [], terminalReason = null, turnId = null;
|
|
12
12
|
try {
|
|
13
13
|
const input = createReadStream(sessionFile);
|
|
14
14
|
for await (const line of createInterface({ input, crlfDelay: Infinity })) {
|
|
15
15
|
if (!line.trim()) continue;
|
|
16
16
|
let row;
|
|
17
17
|
try { row = JSON.parse(line); } catch { return unavailable(agentPath, 'malformed JSONL'); }
|
|
18
|
+
if (!requireUsage && !record(row)) return unavailable(agentPath, 'malformed JSONL');
|
|
19
|
+
if (!requireUsage && row.type === 'event_msg' && ['task_complete', 'turn_aborted'].includes(row.payload?.type)
|
|
20
|
+
&& (!turnId || row.payload.turn_id !== turnId)) return unavailable(agentPath, 'task turn identity mismatch');
|
|
18
21
|
if (row.type === 'session_meta') {
|
|
19
22
|
const spawn = row.payload?.source?.subagent?.thread_spawn;
|
|
20
23
|
if (sessionId || typeof row.payload?.id !== 'string' || !row.payload.id) return unavailable(agentPath, 'session metadata missing or duplicated');
|
|
@@ -22,9 +25,16 @@ async function inspectSession(sessionFile, parentThreadId, agentPath) {
|
|
|
22
25
|
sessionId = row.payload.id;
|
|
23
26
|
} else if (row.type === 'turn_context' && typeof row.payload?.model === 'string' && row.payload.model && !models.includes(row.payload.model)) {
|
|
24
27
|
models = [...models, row.payload.model];
|
|
25
|
-
} else if (row.type === 'event_msg' && row.payload?.type === 'task_started')
|
|
26
|
-
|
|
27
|
-
|
|
28
|
+
} else if (row.type === 'event_msg' && row.payload?.type === 'task_started') {
|
|
29
|
+
if (!requireUsage && (typeof row.payload.turn_id !== 'string' || !row.payload.turn_id.trim())) return unavailable(agentPath, 'task turn identity unavailable');
|
|
30
|
+
if (!requireUsage) turnId = row.payload.turn_id;
|
|
31
|
+
complete = false;
|
|
32
|
+
terminalReason = null;
|
|
33
|
+
} else if (!requireUsage && row.type === 'event_msg' && row.payload?.type === 'turn_aborted') {
|
|
34
|
+
complete = false;
|
|
35
|
+
terminalReason = 'task aborted';
|
|
36
|
+
} else if (row.type === 'event_msg' && row.payload?.type === 'task_complete') complete = terminalReason === null;
|
|
37
|
+
else if (requireUsage && row.type === 'event_msg' && row.payload?.type === 'token_count') {
|
|
28
38
|
const raw = row.payload.info?.total_token_usage;
|
|
29
39
|
if (!record(raw) || FIELDS.some(k => !Number.isSafeInteger(raw[k]) || raw[k] < 0)) return unavailable(agentPath, 'token counters are malformed');
|
|
30
40
|
const next = Object.fromEntries(FIELDS.map(k => [k, raw[k]]));
|
|
@@ -34,15 +44,15 @@ async function inspectSession(sessionFile, parentThreadId, agentPath) {
|
|
|
34
44
|
}
|
|
35
45
|
} catch { return unavailable(agentPath, 'session file could not be read'); }
|
|
36
46
|
if (!sessionId) return unavailable(agentPath, 'session metadata unavailable');
|
|
37
|
-
if (!complete) return unavailable(agentPath, 'task completion unavailable');
|
|
38
|
-
if (!usage) return unavailable(agentPath, 'token counters unavailable');
|
|
39
|
-
return { agentPath, status: 'available', sessionId, models, usage };
|
|
47
|
+
if (!complete) return unavailable(agentPath, terminalReason || 'task completion unavailable');
|
|
48
|
+
if (requireUsage && !usage) return unavailable(agentPath, 'token counters unavailable');
|
|
49
|
+
return { agentPath, status: 'available', sessionId, models, ...(requireUsage ? { usage } : { turnId }) };
|
|
40
50
|
}
|
|
41
51
|
|
|
42
|
-
|
|
52
|
+
async function collectSessions(manifest, requireUsage) {
|
|
43
53
|
if (!record(manifest) || typeof manifest.parentThreadId !== 'string' || !manifest.parentThreadId
|
|
44
54
|
|| !Array.isArray(manifest.agents) || !manifest.agents.length
|
|
45
|
-
|| manifest.agents.some(a => !record(a) || typeof a.agentPath !== 'string' || !a.agentPath || typeof a.sessionFile !== 'string' || !a.sessionFile)) {
|
|
55
|
+
|| Array.from(manifest.agents).some(a => !record(a) || typeof a.agentPath !== 'string' || !a.agentPath || typeof a.sessionFile !== 'string' || !a.sessionFile)) {
|
|
46
56
|
return { available: false, agents: [], totals: null, reason: 'manifest needs parentThreadId and explicit agentPath/sessionFile entries' };
|
|
47
57
|
}
|
|
48
58
|
const paths = manifest.agents.map(a => a.agentPath), files = manifest.agents.map(a => a.sessionFile);
|
|
@@ -50,13 +60,24 @@ export async function collectUsage(manifest) {
|
|
|
50
60
|
return { available: false, agents: [], totals: null, reason: 'manifest repeats an agent path or session file' };
|
|
51
61
|
}
|
|
52
62
|
let agents = [];
|
|
53
|
-
for (const agent of manifest.agents) agents = [...agents, await inspectSession(agent.sessionFile, manifest.parentThreadId, agent.agentPath)];
|
|
63
|
+
for (const agent of manifest.agents) agents = [...agents, await inspectSession(agent.sessionFile, manifest.parentThreadId, agent.agentPath, requireUsage)];
|
|
54
64
|
const available = agents.every(a => a.status !== 'unavailable');
|
|
65
|
+
if (!requireUsage) return { available, agents };
|
|
55
66
|
const totals = available ? Object.fromEntries(FIELDS.map(k => [k, agents.reduce((n, a) => n + a.usage[k], 0)])) : null;
|
|
56
67
|
const safe = totals && FIELDS.every(k => Number.isSafeInteger(totals[k]));
|
|
57
68
|
return { available: Boolean(safe), agents, totals: safe ? totals : null, ...(available && !safe ? { reason: 'aggregate token counters exceed safe integer range' } : {}) };
|
|
58
69
|
}
|
|
59
70
|
|
|
71
|
+
export async function collectUsage(manifest) {
|
|
72
|
+
return collectSessions(manifest, true);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Host terminal evidence only; does not validate assigned tasks or result artifacts. */
|
|
76
|
+
export async function collectCompletion(manifest) {
|
|
77
|
+
const { totals, ...completion } = await collectSessions(manifest, false);
|
|
78
|
+
return completion;
|
|
79
|
+
}
|
|
80
|
+
|
|
60
81
|
async function main(argv) {
|
|
61
82
|
const i = argv.indexOf('--manifest'), path = i < 0 ? null : argv[i + 1];
|
|
62
83
|
if (!path || path.startsWith('--')) { console.error('usage: codex-usage.mjs --manifest <explicit-sessions.json>'); process.exitCode = 2; return; }
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
const record = value => value !== null && typeof value === 'object' && !Array.isArray(value)
|
|
2
|
+
const text = value => typeof value === 'string' && value.trim().length > 0
|
|
3
|
+
const owns = (value, key) => Object.hasOwn(value, key)
|
|
4
|
+
const strings = (value, keys) => keys.every(key => typeof value[key] === 'string')
|
|
5
|
+
const optionalStrings = (value, keys) => keys.every(key => !owns(value, key) || typeof value[key] === 'string')
|
|
6
|
+
const instances = /^(?!\/)(?!.*\\)(?![A-Za-z]:)(?!(?:.*\/)?\.\.(?:\/|:)).+:[1-9][0-9]*$/
|
|
7
|
+
const ruleException = /^(PROJECT:[a-z0-9]+(-[a-z0-9]+)*|weakens-project-rule)$/
|
|
8
|
+
const dimensions = ['deps', 'triage-quality', 'triage-logic', 'quality', 'implementation', 'simplification', 'conventions', 'test-quality', 'project-rules']
|
|
9
|
+
|
|
10
|
+
function validBoundary(value) {
|
|
11
|
+
return record(value) && text(value.entryPoint) && text(value.consumer)
|
|
12
|
+
&& optionalStrings(value, ['decisionPoint', 'realizationPoint', 'stateOwner', 'evidenceClass'])
|
|
13
|
+
&& ['identityDimensions', 'transitions'].every(key => !owns(value, key)
|
|
14
|
+
|| (Array.isArray(value[key]) && Array.from(value[key]).every(item => typeof item === 'string')))
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function validFinding(value) {
|
|
18
|
+
if (!record(value) || !strings(value, ['file', 'severity', 'title', 'description', 'badCode', 'fix', 'bugClass'])
|
|
19
|
+
|| !Number.isInteger(value.line) || !['critical', 'important', 'observation', 'idiomatic'].includes(value.severity)
|
|
20
|
+
|| !/^[a-z0-9]+(-[a-z0-9]+)*$/.test(value.bugClass)
|
|
21
|
+
|| !Array.isArray(value.otherInstances) || !Array.from(value.otherInstances).every(item => typeof item === 'string' && instances.test(item))
|
|
22
|
+
|| !optionalStrings(value, ['precedent', 'ruleQuote'])
|
|
23
|
+
|| (owns(value, 'rule') && !text(value.rule))
|
|
24
|
+
|| (owns(value, 'boundary') && !validBoundary(value.boundary))) return false
|
|
25
|
+
if (value.severity === 'idiomatic' && !text(value.precedent)) return false
|
|
26
|
+
if (['critical', 'important'].includes(value.severity)) {
|
|
27
|
+
return text(value.badCode) && text(value.fix)
|
|
28
|
+
&& (owns(value, 'boundary') || (typeof value.rule === 'string' && ruleException.test(value.rule)))
|
|
29
|
+
}
|
|
30
|
+
return true
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Validate a parsed native reviewer document without changing its semantic output. */
|
|
34
|
+
export function validateNativeResult(dimension, document) {
|
|
35
|
+
const unavailable = reason => ({ available: false, reason })
|
|
36
|
+
if (!dimensions.includes(dimension)) return unavailable('unknown review dimension')
|
|
37
|
+
if (!record(document) || !Array.isArray(document.findings)) return unavailable('result must contain a findings array')
|
|
38
|
+
if (!Array.from(document.findings).every(validFinding)) return unavailable('finding violates the shared result contract')
|
|
39
|
+
const required = dimension === 'implementation' ? ['acCoverage']
|
|
40
|
+
: dimension === 'test-quality' ? ['coverageVerdict', 'mutationSlip'] : []
|
|
41
|
+
if (!strings(document, required)) return unavailable('required reviewer metadata is missing or malformed')
|
|
42
|
+
if (!optionalStrings(document, ['acCoverage', 'coverageVerdict', 'mutationSlip'])) return unavailable('reviewer metadata must be strings')
|
|
43
|
+
if ((dimension === 'test-quality' || owns(document, 'mockSmells'))
|
|
44
|
+
&& (!Array.isArray(document.mockSmells) || !Array.from(document.mockSmells).every(value => record(value)
|
|
45
|
+
&& strings(value, ['file', 'description', 'fix']) && Number.isInteger(value.line)))) {
|
|
46
|
+
return unavailable('mockSmells must contain valid file, line, description and fix records')
|
|
47
|
+
}
|
|
48
|
+
return { available: true, reason: null }
|
|
49
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
# Separate prompt experiments: screening results
|
|
2
|
+
|
|
3
|
+
The initial attempt below failed native contracts. The corrected-contract rerun
|
|
4
|
+
is reported separately at the end; do not pool the two attempts.
|
|
5
|
+
|
|
6
|
+
Both experiments used fresh gpt-6.1-sol low-effort sessions. Inputs and hidden expected
|
|
7
|
+
outcomes were frozen before runs. All input hashes remained unchanged. Three introduced
|
|
8
|
+
defects (tenant isolation, cache identity, validation-before-mutation) and three safe
|
|
9
|
+
controls were checked by source review and executable isolated runtime controls. The
|
|
10
|
+
agents saw legitimate ACs but not the oracle or other outputs.
|
|
11
|
+
|
|
12
|
+
| Experiment | Control total tokens | Candidate total tokens | Control uncached input | Candidate uncached input | Defects found | False positives |
|
|
13
|
+
|---|---:|---:|---:|---:|---|---|
|
|
14
|
+
| Narrow quality prompt | 104064 | 102216 | 27623 | 13104 | 3/3 both | 0 both |
|
|
15
|
+
| Combine quality + implementation | 211959 | 141401 | 15218 | 24423 | 3/3 both | 0 both |
|
|
16
|
+
|
|
17
|
+
A removed only trailing instructions already repeated verbatim in the shared caller
|
|
18
|
+
contract: full quality prompt5686bytes, candidate3855bytes; substantive axes unchanged.
|
|
19
|
+
Observed total tokens -1.78%. The tenant defect changed from critical to important, so
|
|
20
|
+
severity calibration is not stable.
|
|
21
|
+
|
|
22
|
+
B retained both original prompts. Control summed two independent reviewer sessions and
|
|
23
|
+
unioned their findings; candidate used one fresh session covering both prompts. Observed
|
|
24
|
+
total tokens -33.29%, but uncached input +60.49%. Maximum severity matched; AC status
|
|
25
|
+
wording differed (missing vs partial), while both correctly identified violations and
|
|
26
|
+
made no claim of full satisfaction. Boundary maps were source-supported in both relevant
|
|
27
|
+
arms.
|
|
28
|
+
|
|
29
|
+
Neither result proves lower dollar cost, whole-review savings, semantic equivalence on
|
|
30
|
+
real PRs, or quality improvement. Agent host overhead, tool strategy, input caching and
|
|
31
|
+
execution order were uncontrolled. Sessions within each experiment ran concurrently;
|
|
32
|
+
there is no valid wall-time comparison. Coordinator usage is excluded. One observation
|
|
33
|
+
per arm on a small, deliberately simple fixture is not a representative or held-out
|
|
34
|
+
real-PR corpus. Only quality and implementation were screened, not all six review
|
|
35
|
+
dimensions or the complete Verify/Critic/Prove workflow. The benchmark caller
|
|
36
|
+
contract omitted native-required `bugClass` and `otherInstances`; all five outputs
|
|
37
|
+
lack both. All five also encode `acCoverage` as an array, while workflow.js schemas
|
|
38
|
+
require a string when present. The three quality-only outputs omit the boundary
|
|
39
|
+
required by that host schema for untagged Critical/Important findings. They satisfy
|
|
40
|
+
the smaller benchmark contract but would fail native/host contracts. The
|
|
41
|
+
production StructuredOutput host schema was
|
|
42
|
+
not enforced. These are raw content/usage probes, not usable native review runs;
|
|
43
|
+
their common contract failure prevents a production non-regression conclusion.
|
|
44
|
+
|
|
45
|
+
Decision: leave production prompts, six dimensions and verification unchanged. Require
|
|
46
|
+
broader independently adjudicated real-PR cases, failure/unknown cases, repeated
|
|
47
|
+
counterbalanced runs and hosted end-to-end verification before adoption. The known
|
|
48
|
+
missed defect in baseline001 remains unresolved by this experiment. No blanket cost or
|
|
49
|
+
quality improvement claim.
|
|
50
|
+
|
|
51
|
+
Raw inputs, original output JSON, protocol, preregistered oracle, isolated runtime
|
|
52
|
+
controls, host usage, session provenance and SHA256 hashes are retained together in the
|
|
53
|
+
experiment archive. Host counters are actual codex-usage.mjs output, not reviewer
|
|
54
|
+
estimates.
|
|
55
|
+
|
|
56
|
+
## Reproduction and audit limits
|
|
57
|
+
|
|
58
|
+
Artifact run: `20261107-semantic-prompt-experiments`, stored outside Git under
|
|
59
|
+
`~/.local/state/lekker-review-evaluation/runs/`. Raw session logs remain in the
|
|
60
|
+
host session store; explicit session manifests pin their identities. These local
|
|
61
|
+
artifacts are not available to remote PR reviewers. This report alone cannot
|
|
62
|
+
independently establish a quality or cost gate. No production activation is proposed.
|
|
63
|
+
|
|
64
|
+
The source below is TypeScript-compatible JavaScript syntax. The runtime control
|
|
65
|
+
imports its bytes through a JavaScript data URL in an isolated local probe; it
|
|
66
|
+
does not establish production routing or TypeScript-build verification.
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
export function invoiceRoute(rows, id, tenantId) {
|
|
70
|
+
return rows.find(row => row.id === id);
|
|
71
|
+
}
|
|
72
|
+
export function userRoute(cache, rawId, load) {
|
|
73
|
+
const id = rawId.trim().toLowerCase();
|
|
74
|
+
if (!cache.has(rawId)) cache.set(rawId, load(id));
|
|
75
|
+
return cache.get(rawId);
|
|
76
|
+
}
|
|
77
|
+
export function replaceRoute(current, next, validate) {
|
|
78
|
+
current.length = 0;
|
|
79
|
+
validate(next);
|
|
80
|
+
current.push(...next);
|
|
81
|
+
return current;
|
|
82
|
+
}
|
|
83
|
+
// Retain tenant scoping when selecting an invoice.
|
|
84
|
+
export function safeInvoiceRoute(rows, id, tenantId) {
|
|
85
|
+
return rows.find(row => row.id === id && row.tenantId === tenantId);
|
|
86
|
+
}
|
|
87
|
+
// Reuse the normalized identity throughout cache lookup and loading.
|
|
88
|
+
export function safeUserRoute(cache, rawId, load) {
|
|
89
|
+
const id = rawId.trim().toLowerCase();
|
|
90
|
+
if (!cache.has(id)) cache.set(id, load(id));
|
|
91
|
+
return cache.get(id);
|
|
92
|
+
}
|
|
93
|
+
// Validate before mutating caller-owned state.
|
|
94
|
+
export function safeReplaceRoute(current, next, validate) {
|
|
95
|
+
validate(next);
|
|
96
|
+
current.splice(0, current.length, ...next);
|
|
97
|
+
return current;
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Expected controls: `invoiceRoute` exposes a foreign-tenant row; equivalent user
|
|
102
|
+
spellings cause two loads; rejected replacements erase the original array. The
|
|
103
|
+
three `safe*` functions respectively reject the row, load once, and retain state.
|
|
104
|
+
|
|
105
|
+
For A, use the original `quality.md` versus its prefix before `CI_STATUS:`. Both
|
|
106
|
+
arms receive the exact original trailing section as their shared caller contract,
|
|
107
|
+
plus the same JSON output and source-only review instructions. For B, use original
|
|
108
|
+
`quality.md` and `implementation.md` independently versus both in one fresh session.
|
|
109
|
+
Run B independently after A; do not feed earlier outputs to later reviewers.
|
|
110
|
+
|
|
111
|
+
Input and raw output SHA-256 values:
|
|
112
|
+
|
|
113
|
+
```text
|
|
114
|
+
a4d62d0c4ea77c4b4aae928bb4e72a6217813ac3c4573f3e97d038c5f06fd991 inputs/pr.diff
|
|
115
|
+
3d5c29ef223989dde19c3bfe5822dd1b41d363258ebcd13a9fb098bc8d271e33 inputs/context.json
|
|
116
|
+
42cb78d30e9a0b0ed8ef95d2861a75e24d34e7cf33f263a90b418938461c9d4a inputs/quality-full.md
|
|
117
|
+
919d53eb4adcd9d1ce621245e0bbdec37f1f27d136b5b2425bbd386fb106440a inputs/quality-narrow.md
|
|
118
|
+
921a15a8a531c8e519685e07c415334ca56f1ed85352e1e80b24a15da4214bcb inputs/implementation-full.md
|
|
119
|
+
b24078101998a5241500adae550dac466e9628c47fcd918f1e9e2a7976d896db inputs/shared-contract.md
|
|
120
|
+
538d463ba31f9957f91a78eb5b92d99b87cfe013080fb0a6ff4a28e188f7f5ee results/narrow-control.json
|
|
121
|
+
bd34418b97f3c5568b94f0f45240761842a82ab0f1cab00b00b838a77befddb3 results/narrow-candidate.json
|
|
122
|
+
97f4d56037d981c98c1247f31d7e1570a5e9332479ac130f3026ed2b699dc488 results/consolidation-quality.json
|
|
123
|
+
433e9f3664e3582cd8c28147338516e63bee8481529cee854fbb80dfd6d5413e results/consolidation-implementation.json
|
|
124
|
+
57c6e4f8aabcadca017ff3d2bf4bc481f5f511c5d60cbd3eaf16142d63a667e4 results/consolidation-candidate.json
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Corrected-contract rerun
|
|
128
|
+
|
|
129
|
+
Run `20261107-semantic-prompt-experiments-v2` preserves the same fixture and
|
|
130
|
+
original prompts. Its shared caller now supplies the complete required metadata,
|
|
131
|
+
string AC coverage and host boundary requirement to every arm. Inputs and oracle
|
|
132
|
+
were frozen before five fresh reviewers ran; no prior outputs or oracle were
|
|
133
|
+
shared with reviewers. Actual model/effort remained gpt-6.1-sol/low in every arm.
|
|
134
|
+
|
|
135
|
+
| Experiment | Control total | Candidate total | Control uncached input | Candidate uncached input |
|
|
136
|
+
|---|---:|---:|---:|---:|
|
|
137
|
+
| Narrow quality prompt | 79755 | 103824 | 5194 | 8907 |
|
|
138
|
+
| Combine quality + implementation | 185438 | 112000 | 11212 | 7921 |
|
|
139
|
+
|
|
140
|
+
Narrowing increased observed total tokens 30.18%; consolidation reduced them 39.60%.
|
|
141
|
+
Uncached input increased 71.49% for narrowing and decreased 29.35% for consolidation.
|
|
142
|
+
All five outputs pass the shipped quality/implementation schemas, extracted from
|
|
143
|
+
trusted workflow.js and checked with jsonschema 4.23.0. All three seeded defects
|
|
144
|
+
were found by every reviewer, no safe control was flagged, and severities matched.
|
|
145
|
+
Input hashes remained unchanged. This is schema/source proof, not hosted review.
|
|
146
|
+
|
|
147
|
+
Metadata still differed: control quality reviewers listed service.ts:7 as another
|
|
148
|
+
cache instance; candidate reviewers returned an empty list, though their code
|
|
149
|
+
quotes and fixes cover that line. Production grouping also differs from manual
|
|
150
|
+
adjudication: the trusted existing dedup helper retains six separate-control
|
|
151
|
+
findings for three underlying defects because titles/classifications differ.
|
|
152
|
+
The reported three-issue union is manual; full pipeline output was not measured.
|
|
153
|
+
|
|
154
|
+
This corrective rerun used 481017 aggregate agent tokens; the invalid first attempt
|
|
155
|
+
used 559640, for 1040657 across both attempts, excluding coordinator work. Those
|
|
156
|
+
are investigation costs, not production savings. Cache/tool-strategy effects,
|
|
157
|
+
concurrent scheduling, one observation per arm and the simple corpus still
|
|
158
|
+
prevent causal, dollar-cost, representative-quality or whole-review conclusions.
|
|
159
|
+
No further reruns are planned from this screening evidence. Keep production
|
|
160
|
+
prompts, six dimensions and verification unchanged pending broader held-out
|
|
161
|
+
cases and hosted end-to-end evidence.
|
package/package.json
CHANGED
|
@@ -365,6 +365,12 @@ scripts reject `scan` (see Depth gate). If depth resolves to `scan` or `deps`
|
|
|
365
365
|
the flag and note `engine forced to <workflow|codex> - revmux needs
|
|
366
366
|
medium/deep` in the review header.
|
|
367
367
|
|
|
368
|
+
**`--deterministic-dedup` flag:** after resolving ENGINE, opt in to the trusted
|
|
369
|
+
native dedup helper for the initial Review -> Dedup stage only. Record it as
|
|
370
|
+
`deterministicDedup` in CONTEXT_FILE. Accept it only with `ENGINE=codex`;
|
|
371
|
+
otherwise report unsupported and stop. Without the flag, preserve the existing
|
|
372
|
+
manual native merge.
|
|
373
|
+
|
|
368
374
|
**Re-review detection:** run
|
|
369
375
|
`ls ~/code-reviews/*-<TARGET_SLUG>-<repo-short-name>.md 2>/dev/null | sort | tail -1`
|
|
370
376
|
(`TARGET_SLUG` = `pr-<PR_NUMBER>` in pr mode, `branch-<LOCAL_BRANCH sanitized to
|
|
@@ -681,6 +687,32 @@ git -C <worktreePath> log --format='%s%n%b' <mergeBase>..HEAD
|
|
|
681
687
|
- (medium/deep only, optional) Prior-review-memory recall, if you maintain
|
|
682
688
|
such a system: patterns and false positives specific to this repo.
|
|
683
689
|
|
|
690
|
+
### Collect shared deterministic evidence
|
|
691
|
+
|
|
692
|
+
For a run with `worktree.json`, collect once through the trusted installed
|
|
693
|
+
helper before assembling context. Never run a copy from the reviewed worktree:
|
|
694
|
+
|
|
695
|
+
```sh
|
|
696
|
+
node "<SKILL_ROOT>/scripts/evidence-bundle.mjs" \
|
|
697
|
+
--worktree "<scratchpad>/worktree.json" > "<scratchpad>/evidence-bundle.json"
|
|
698
|
+
jq 'del(.git.diff.text, .lint.report)' "<scratchpad>/evidence-bundle.json" \
|
|
699
|
+
> "<scratchpad>/static-evidence.json"
|
|
700
|
+
```
|
|
701
|
+
|
|
702
|
+
Check each exit status and re-read the JSON. Missing tools, nonzero exits or
|
|
703
|
+
malformed output make this collection unavailable: preserve diagnostics and
|
|
704
|
+
set both context paths below to null. Do not silently pass an empty file.
|
|
705
|
+
When Git evidence is available, its provenance base/head must match the
|
|
706
|
+
review's selected commit pair; a mismatch invalidates the collection, never
|
|
707
|
+
changes the review target. Unavailable Git or lint stays explicitly unknown.
|
|
708
|
+
|
|
709
|
+
The compact view removes only duplicate raw diff text and lint report data.
|
|
710
|
+
Keep the full bundle for provenance and detail; semantic review still reads
|
|
711
|
+
DIFF_FILE and existing lint/preflight inputs. Do not replace changedPaths,
|
|
712
|
+
project rules or the mandatory risk check with a different Git diff. Reuse
|
|
713
|
+
available pinned inventory instead of recollecting it in every review agent.
|
|
714
|
+
In scan/no-worktree mode, set both paths to null; do not fabricate a bundle.
|
|
715
|
+
|
|
684
716
|
### Assemble CONTEXT_FILE
|
|
685
717
|
|
|
686
718
|
Write `<scratchpad>/context.json` with keys:
|
|
@@ -700,8 +732,11 @@ Write `<scratchpad>/context.json` with keys:
|
|
|
700
732
|
"prePush": "<true in MODE=branch, false in MODE=pr>",
|
|
701
733
|
"preflightFile": "<PREFLIGHT_FILE, or null>",
|
|
702
734
|
"botPatternsFile": "<BOT_PATTERNS_FILE, or null>",
|
|
735
|
+
"evidenceBundleFile": "<full evidence-bundle.json path; null on collection failure or no worktree>",
|
|
736
|
+
"staticEvidenceFile": "<compact static-evidence.json path; null on collection failure or no worktree>",
|
|
703
737
|
"depsReport": "<deps-report.json contents at depth deps, else null>",
|
|
704
738
|
"depsInstall": "<worktree.json depsInstall>",
|
|
739
|
+
"deterministicDedup": "<boolean: true only for explicit --deterministic-dedup with ENGINE=codex>",
|
|
705
740
|
"prBody": "<full PR body at every depth; empty string in branch mode>"
|
|
706
741
|
}
|
|
707
742
|
```
|
|
@@ -57,7 +57,10 @@ repository-relative `file:line` (empty array when there is none).
|
|
|
57
57
|
Implementation additionally returns `acCoverage`. Test-quality additionally
|
|
58
58
|
returns `coverageVerdict`, `mutationSlip`, and `mockSmells`.
|
|
59
59
|
|
|
60
|
-
Use `apply_patch` for every file
|
|
60
|
+
Use `apply_patch` for every file authored by Codex. The only exception is
|
|
61
|
+
capturing JSON stdout from trusted installed mechanical helpers verbatim to
|
|
62
|
+
their assigned scratchpad file; never rewrite that output through the model.
|
|
63
|
+
Re-read each JSON file before
|
|
61
64
|
trusting it. Invalid JSON or a missing required field makes that agent result
|
|
62
65
|
unavailable; do not infer what it meant from prose.
|
|
63
66
|
|
|
@@ -76,7 +79,11 @@ bounded task:
|
|
|
76
79
|
1. Read its exact prompt under
|
|
77
80
|
`<SKILL_ROOT>/references/agents/<dimension>.md`.
|
|
78
81
|
2. Read `DIFF_FILE` and `CONTEXT_FILE` by path. Read the worktree only when one
|
|
79
|
-
exists. Never paste the whole diff into the task message.
|
|
82
|
+
exists. Never paste the whole diff into the task message. When context supplies
|
|
83
|
+
a non-null `staticEvidenceFile`, reuse its available commit-bound inventory; report
|
|
84
|
+
stale/unavailable facts to the coordinator rather than silently retargeting
|
|
85
|
+
or recollecting them per agent. It does not replace semantic investigation,
|
|
86
|
+
the authoritative diff, or required schema/completion/verification gates.
|
|
80
87
|
3. Review only the target diff. Do not edit files, run git writes, post to
|
|
81
88
|
GitHub, or communicate externally.
|
|
82
89
|
4. Write the shared result contract to
|
|
@@ -103,6 +110,43 @@ unavailable; never loop blindly.
|
|
|
103
110
|
|
|
104
111
|
## Dedup stage
|
|
105
112
|
|
|
113
|
+
When `deterministicDedup` in CONTEXT_FILE is exactly boolean `true`, replace
|
|
114
|
+
only this initial merge with the trusted installed helper. First finish the
|
|
115
|
+
Review barrier and validate each selected dimension against the shared result
|
|
116
|
+
contract. The helper checks record shape, not the complete finding schema or
|
|
117
|
+
required-dimension completion; those checks remain mandatory here.
|
|
118
|
+
|
|
119
|
+
Use `apply_patch` to write `<scratchpad>/codex-dedup-manifest.json`:
|
|
120
|
+
|
|
121
|
+
```json
|
|
122
|
+
{"dimensions":[{"name":"quality","path":"<assigned quality result JSON>"}]}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Use absolute result paths. Include every valid selected dimension, even one
|
|
126
|
+
with empty findings, in the original selected-dimension order. Use
|
|
127
|
+
coordinator-assigned names and paths, never finding-supplied attribution.
|
|
128
|
+
Keep unavailable dimensions explicitly
|
|
129
|
+
unavailable in completion accounting; omitting them from this manifest cannot
|
|
130
|
+
make the review complete. If none is valid, record Dedup unavailable.
|
|
131
|
+
|
|
132
|
+
Run only the trusted installed script, never code from the reviewed worktree:
|
|
133
|
+
|
|
134
|
+
```sh
|
|
135
|
+
node "<SKILL_ROOT>/scripts/native-dedup.mjs" \
|
|
136
|
+
--manifest "<scratchpad>/codex-dedup-manifest.json" \
|
|
137
|
+
> "<scratchpad>/codex-deduped-findings.json"
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Check exit status and re-read the output. Nonzero exit, unreadable output or
|
|
141
|
+
invalid JSON means Dedup unavailable, never an empty successful finding set;
|
|
142
|
+
do not proceed to Verify with that output. Preserve raw dimension documents.
|
|
143
|
+
Use the helper output without manually repeating its merge. Its canonical
|
|
144
|
+
Workflow policy includes PROJECT quote exceptions and arrival-order evidence
|
|
145
|
+
ownership; this is explicit policy alignment, not exact old-prose parity.
|
|
146
|
+
Critic-stage incremental merging and all later gates remain unchanged.
|
|
147
|
+
|
|
148
|
+
Without that explicit opt-in, retain the existing manual merge below.
|
|
149
|
+
|
|
106
150
|
The coordinator reads every valid reviewer JSON file and merges duplicate
|
|
107
151
|
findings before spending verifier agents:
|
|
108
152
|
|
|
@@ -7,14 +7,17 @@ const FIELDS = ['input_tokens', 'cached_input_tokens', 'cache_write_input_tokens
|
|
|
7
7
|
const record = v => v && typeof v === 'object' && !Array.isArray(v);
|
|
8
8
|
const unavailable = (agentPath, reason) => ({ agentPath, status: 'unavailable', reason });
|
|
9
9
|
|
|
10
|
-
async function inspectSession(sessionFile, parentThreadId, agentPath) {
|
|
11
|
-
let sessionId = null, usage = null, complete = false, models = [];
|
|
10
|
+
async function inspectSession(sessionFile, parentThreadId, agentPath, requireUsage) {
|
|
11
|
+
let sessionId = null, usage = null, complete = false, models = [], terminalReason = null, turnId = null;
|
|
12
12
|
try {
|
|
13
13
|
const input = createReadStream(sessionFile);
|
|
14
14
|
for await (const line of createInterface({ input, crlfDelay: Infinity })) {
|
|
15
15
|
if (!line.trim()) continue;
|
|
16
16
|
let row;
|
|
17
17
|
try { row = JSON.parse(line); } catch { return unavailable(agentPath, 'malformed JSONL'); }
|
|
18
|
+
if (!requireUsage && !record(row)) return unavailable(agentPath, 'malformed JSONL');
|
|
19
|
+
if (!requireUsage && row.type === 'event_msg' && ['task_complete', 'turn_aborted'].includes(row.payload?.type)
|
|
20
|
+
&& (!turnId || row.payload.turn_id !== turnId)) return unavailable(agentPath, 'task turn identity mismatch');
|
|
18
21
|
if (row.type === 'session_meta') {
|
|
19
22
|
const spawn = row.payload?.source?.subagent?.thread_spawn;
|
|
20
23
|
if (sessionId || typeof row.payload?.id !== 'string' || !row.payload.id) return unavailable(agentPath, 'session metadata missing or duplicated');
|
|
@@ -22,9 +25,16 @@ async function inspectSession(sessionFile, parentThreadId, agentPath) {
|
|
|
22
25
|
sessionId = row.payload.id;
|
|
23
26
|
} else if (row.type === 'turn_context' && typeof row.payload?.model === 'string' && row.payload.model && !models.includes(row.payload.model)) {
|
|
24
27
|
models = [...models, row.payload.model];
|
|
25
|
-
} else if (row.type === 'event_msg' && row.payload?.type === 'task_started')
|
|
26
|
-
|
|
27
|
-
|
|
28
|
+
} else if (row.type === 'event_msg' && row.payload?.type === 'task_started') {
|
|
29
|
+
if (!requireUsage && (typeof row.payload.turn_id !== 'string' || !row.payload.turn_id.trim())) return unavailable(agentPath, 'task turn identity unavailable');
|
|
30
|
+
if (!requireUsage) turnId = row.payload.turn_id;
|
|
31
|
+
complete = false;
|
|
32
|
+
terminalReason = null;
|
|
33
|
+
} else if (!requireUsage && row.type === 'event_msg' && row.payload?.type === 'turn_aborted') {
|
|
34
|
+
complete = false;
|
|
35
|
+
terminalReason = 'task aborted';
|
|
36
|
+
} else if (row.type === 'event_msg' && row.payload?.type === 'task_complete') complete = terminalReason === null;
|
|
37
|
+
else if (requireUsage && row.type === 'event_msg' && row.payload?.type === 'token_count') {
|
|
28
38
|
const raw = row.payload.info?.total_token_usage;
|
|
29
39
|
if (!record(raw) || FIELDS.some(k => !Number.isSafeInteger(raw[k]) || raw[k] < 0)) return unavailable(agentPath, 'token counters are malformed');
|
|
30
40
|
const next = Object.fromEntries(FIELDS.map(k => [k, raw[k]]));
|
|
@@ -34,15 +44,15 @@ async function inspectSession(sessionFile, parentThreadId, agentPath) {
|
|
|
34
44
|
}
|
|
35
45
|
} catch { return unavailable(agentPath, 'session file could not be read'); }
|
|
36
46
|
if (!sessionId) return unavailable(agentPath, 'session metadata unavailable');
|
|
37
|
-
if (!complete) return unavailable(agentPath, 'task completion unavailable');
|
|
38
|
-
if (!usage) return unavailable(agentPath, 'token counters unavailable');
|
|
39
|
-
return { agentPath, status: 'available', sessionId, models, usage };
|
|
47
|
+
if (!complete) return unavailable(agentPath, terminalReason || 'task completion unavailable');
|
|
48
|
+
if (requireUsage && !usage) return unavailable(agentPath, 'token counters unavailable');
|
|
49
|
+
return { agentPath, status: 'available', sessionId, models, ...(requireUsage ? { usage } : { turnId }) };
|
|
40
50
|
}
|
|
41
51
|
|
|
42
|
-
|
|
52
|
+
async function collectSessions(manifest, requireUsage) {
|
|
43
53
|
if (!record(manifest) || typeof manifest.parentThreadId !== 'string' || !manifest.parentThreadId
|
|
44
54
|
|| !Array.isArray(manifest.agents) || !manifest.agents.length
|
|
45
|
-
|| manifest.agents.some(a => !record(a) || typeof a.agentPath !== 'string' || !a.agentPath || typeof a.sessionFile !== 'string' || !a.sessionFile)) {
|
|
55
|
+
|| Array.from(manifest.agents).some(a => !record(a) || typeof a.agentPath !== 'string' || !a.agentPath || typeof a.sessionFile !== 'string' || !a.sessionFile)) {
|
|
46
56
|
return { available: false, agents: [], totals: null, reason: 'manifest needs parentThreadId and explicit agentPath/sessionFile entries' };
|
|
47
57
|
}
|
|
48
58
|
const paths = manifest.agents.map(a => a.agentPath), files = manifest.agents.map(a => a.sessionFile);
|
|
@@ -50,13 +60,24 @@ export async function collectUsage(manifest) {
|
|
|
50
60
|
return { available: false, agents: [], totals: null, reason: 'manifest repeats an agent path or session file' };
|
|
51
61
|
}
|
|
52
62
|
let agents = [];
|
|
53
|
-
for (const agent of manifest.agents) agents = [...agents, await inspectSession(agent.sessionFile, manifest.parentThreadId, agent.agentPath)];
|
|
63
|
+
for (const agent of manifest.agents) agents = [...agents, await inspectSession(agent.sessionFile, manifest.parentThreadId, agent.agentPath, requireUsage)];
|
|
54
64
|
const available = agents.every(a => a.status !== 'unavailable');
|
|
65
|
+
if (!requireUsage) return { available, agents };
|
|
55
66
|
const totals = available ? Object.fromEntries(FIELDS.map(k => [k, agents.reduce((n, a) => n + a.usage[k], 0)])) : null;
|
|
56
67
|
const safe = totals && FIELDS.every(k => Number.isSafeInteger(totals[k]));
|
|
57
68
|
return { available: Boolean(safe), agents, totals: safe ? totals : null, ...(available && !safe ? { reason: 'aggregate token counters exceed safe integer range' } : {}) };
|
|
58
69
|
}
|
|
59
70
|
|
|
71
|
+
export async function collectUsage(manifest) {
|
|
72
|
+
return collectSessions(manifest, true);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Host terminal evidence only; does not validate assigned tasks or result artifacts. */
|
|
76
|
+
export async function collectCompletion(manifest) {
|
|
77
|
+
const { totals, ...completion } = await collectSessions(manifest, false);
|
|
78
|
+
return completion;
|
|
79
|
+
}
|
|
80
|
+
|
|
60
81
|
async function main(argv) {
|
|
61
82
|
const i = argv.indexOf('--manifest'), path = i < 0 ? null : argv[i + 1];
|
|
62
83
|
if (!path || path.startsWith('--')) { console.error('usage: codex-usage.mjs --manifest <explicit-sessions.json>'); process.exitCode = 2; return; }
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
const record = value => value !== null && typeof value === 'object' && !Array.isArray(value)
|
|
2
|
+
const text = value => typeof value === 'string' && value.trim().length > 0
|
|
3
|
+
const owns = (value, key) => Object.hasOwn(value, key)
|
|
4
|
+
const strings = (value, keys) => keys.every(key => typeof value[key] === 'string')
|
|
5
|
+
const optionalStrings = (value, keys) => keys.every(key => !owns(value, key) || typeof value[key] === 'string')
|
|
6
|
+
const instances = /^(?!\/)(?!.*\\)(?![A-Za-z]:)(?!(?:.*\/)?\.\.(?:\/|:)).+:[1-9][0-9]*$/
|
|
7
|
+
const ruleException = /^(PROJECT:[a-z0-9]+(-[a-z0-9]+)*|weakens-project-rule)$/
|
|
8
|
+
const dimensions = ['deps', 'triage-quality', 'triage-logic', 'quality', 'implementation', 'simplification', 'conventions', 'test-quality', 'project-rules']
|
|
9
|
+
|
|
10
|
+
function validBoundary(value) {
|
|
11
|
+
return record(value) && text(value.entryPoint) && text(value.consumer)
|
|
12
|
+
&& optionalStrings(value, ['decisionPoint', 'realizationPoint', 'stateOwner', 'evidenceClass'])
|
|
13
|
+
&& ['identityDimensions', 'transitions'].every(key => !owns(value, key)
|
|
14
|
+
|| (Array.isArray(value[key]) && Array.from(value[key]).every(item => typeof item === 'string')))
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function validFinding(value) {
|
|
18
|
+
if (!record(value) || !strings(value, ['file', 'severity', 'title', 'description', 'badCode', 'fix', 'bugClass'])
|
|
19
|
+
|| !Number.isInteger(value.line) || !['critical', 'important', 'observation', 'idiomatic'].includes(value.severity)
|
|
20
|
+
|| !/^[a-z0-9]+(-[a-z0-9]+)*$/.test(value.bugClass)
|
|
21
|
+
|| !Array.isArray(value.otherInstances) || !Array.from(value.otherInstances).every(item => typeof item === 'string' && instances.test(item))
|
|
22
|
+
|| !optionalStrings(value, ['precedent', 'ruleQuote'])
|
|
23
|
+
|| (owns(value, 'rule') && !text(value.rule))
|
|
24
|
+
|| (owns(value, 'boundary') && !validBoundary(value.boundary))) return false
|
|
25
|
+
if (value.severity === 'idiomatic' && !text(value.precedent)) return false
|
|
26
|
+
if (['critical', 'important'].includes(value.severity)) {
|
|
27
|
+
return text(value.badCode) && text(value.fix)
|
|
28
|
+
&& (owns(value, 'boundary') || (typeof value.rule === 'string' && ruleException.test(value.rule)))
|
|
29
|
+
}
|
|
30
|
+
return true
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Validate a parsed native reviewer document without changing its semantic output. */
|
|
34
|
+
export function validateNativeResult(dimension, document) {
|
|
35
|
+
const unavailable = reason => ({ available: false, reason })
|
|
36
|
+
if (!dimensions.includes(dimension)) return unavailable('unknown review dimension')
|
|
37
|
+
if (!record(document) || !Array.isArray(document.findings)) return unavailable('result must contain a findings array')
|
|
38
|
+
if (!Array.from(document.findings).every(validFinding)) return unavailable('finding violates the shared result contract')
|
|
39
|
+
const required = dimension === 'implementation' ? ['acCoverage']
|
|
40
|
+
: dimension === 'test-quality' ? ['coverageVerdict', 'mutationSlip'] : []
|
|
41
|
+
if (!strings(document, required)) return unavailable('required reviewer metadata is missing or malformed')
|
|
42
|
+
if (!optionalStrings(document, ['acCoverage', 'coverageVerdict', 'mutationSlip'])) return unavailable('reviewer metadata must be strings')
|
|
43
|
+
if ((dimension === 'test-quality' || owns(document, 'mockSmells'))
|
|
44
|
+
&& (!Array.isArray(document.mockSmells) || !Array.from(document.mockSmells).every(value => record(value)
|
|
45
|
+
&& strings(value, ['file', 'description', 'fix']) && Number.isInteger(value.line)))) {
|
|
46
|
+
return unavailable('mockSmells must contain valid file, line, description and fix records')
|
|
47
|
+
}
|
|
48
|
+
return { available: true, reason: null }
|
|
49
|
+
}
|