Skip to content

Commit 3ecace2

Browse files
committed
style: format external context policy integration
1 parent 436aadd commit 3ecace2

9 files changed

Lines changed: 62 additions & 16 deletions

File tree

src/context-registry/usage-ledger.ts

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,13 @@ function contextAdvice(result: ContextFetchResult): ContextAdviceDecision[] {
8181
const decisions: ContextAdviceDecision[] = [];
8282
if (result.selectedFiles.length) {
8383
decisions.push(
84-
decision(result, "file-location", "adopted", `Use ${result.selectedFiles.length} Context file(s) to locate relevant implementation details.`, "Files were explicitly selected for inspection.")
84+
decision(
85+
result,
86+
"file-location",
87+
"adopted",
88+
`Use ${result.selectedFiles.length} Context file(s) to locate relevant implementation details.`,
89+
"Files were explicitly selected for inspection."
90+
)
8591
);
8692
}
8793
if (result.entry.apiVersion || result.entry.packageVersion) {
@@ -97,7 +103,16 @@ function contextAdvice(result: ContextFetchResult): ContextAdviceDecision[] {
97103
}
98104
for (const file of result.files ?? []) {
99105
if (file.role === "error" || /(^|\/)(errors?|troubleshooting)(\.|\/)/i.test(file.path)) {
100-
decisions.push(decision(result, "error-handling", "available", `Error-handling guidance is available from ${file.path}.`, "Guidance may inform a repair but cannot prove it worked.", file.path));
106+
decisions.push(
107+
decision(
108+
result,
109+
"error-handling",
110+
"available",
111+
`Error-handling guidance is available from ${file.path}.`,
112+
"Guidance may inform a repair but cannot prove it worked.",
113+
file.path
114+
)
115+
);
101116
}
102117
for (const line of file.content.split(/\r?\n/)) {
103118
const command = suggestedCommand(line);
@@ -163,7 +178,10 @@ function decision(
163178
}
164179

165180
function suggestedCommand(line: string): string | undefined {
166-
const trimmed = line.trim().replace(/^[-*]\s+/, "").replace(/^\$\s*/, "");
181+
const trimmed = line
182+
.trim()
183+
.replace(/^[-*]\s+/, "")
184+
.replace(/^\$\s*/, "");
167185
if (!/^(npm|pnpm|yarn|bun|npx|node|deno|python|python3|pytest|cargo|go|git|opencode-plusplus)\b/i.test(trimmed)) return undefined;
168186
return trimmed.slice(0, 500);
169187
}
@@ -188,7 +206,11 @@ function contextVersionCompatibility(root: string, entry: ContextEntry): Context
188206
reason: matches ? "Context and repository package versions match." : "Context package version does not match the repository dependency version."
189207
};
190208
} catch (error) {
191-
return { status: "unknown", contextVersion: entry.packageVersion, reason: `Unable to inspect repository package version: ${error instanceof Error ? error.message : String(error)}` };
209+
return {
210+
status: "unknown",
211+
contextVersion: entry.packageVersion,
212+
reason: `Unable to inspect repository package version: ${error instanceof Error ? error.message : String(error)}`
213+
};
192214
}
193215
}
194216

@@ -203,7 +225,12 @@ function dependencyVersion(manifest: Record<string, unknown>, name: string): str
203225
}
204226

205227
function normalizedVersion(value: string): string {
206-
return value.trim().replace(/^[~^=v\s]+/, "").split(/[\s|]/)[0] ?? value;
228+
return (
229+
value
230+
.trim()
231+
.replace(/^[~^=v\s]+/, "")
232+
.split(/[\s|]/)[0] ?? value
233+
);
207234
}
208235

209236
function validateStore(store: ContextUsageStore, repository: string, taskId: string): void {

src/harness/control-plane/orchestrator-report.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ export function renderOrchestratorReport(report: HarnessOrchestratorReport): str
179179
heading(2, "External Context Provenance"),
180180
bullet(
181181
(report.contextPolicy?.provenance ?? []).map(
182-
(item) => `${item.entryId} from ${item.sourceName} (${item.sourceTrustLevel}), revision ${item.contentRevision}, verified=${item.verified ? "yes" : "no"}`
182+
(item) =>
183+
`${item.entryId} from ${item.sourceName} (${item.sourceTrustLevel}), revision ${item.contentRevision}, verified=${item.verified ? "yes" : "no"}`
183184
)
184185
),
185186
"",

src/harness/observability/intervention-mapper.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@ export function recordIterationInterventions(input: RecordIterationInterventions
7272
findingId: suggestion.id,
7373
category: "context",
7474
problem: suggestion.summary,
75-
action: rejected ? "do not execute or treat as verification" : suggestion.disposition === "adopted" ? "use as contextual guidance" : "keep available for review",
75+
action: rejected
76+
? "do not execute or treat as verification"
77+
: suggestion.disposition === "adopted"
78+
? "use as contextual guidance"
79+
: "keep available for review",
7680
targetFiles: suggestion.sourceFile ? [suggestion.sourceFile] : input.changedFiles,
7781
evidenceRefs: [suggestion.reason, ...(input.policy.contextPolicy?.provenance.map((item) => `${item.sourceName}:${item.contentHash}`) ?? [])],
7882
status: rejected ? "prevented" : "observed",

src/harness/verification-plane/policy-engine.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,8 @@ export function renderPolicyReport(report: PolicyEngineReport): string {
344344
heading(2, "External Context Provenance"),
345345
bullet(
346346
(report.contextPolicy?.provenance ?? []).map(
347-
(item) => `${item.entryId} from ${item.sourceName} (${item.sourceTrustLevel}), revision ${item.contentRevision}, verified=${item.verified ? "yes" : "no"}`
347+
(item) =>
348+
`${item.entryId} from ${item.sourceName} (${item.sourceTrustLevel}), revision ${item.contentRevision}, verified=${item.verified ? "yes" : "no"}`
348349
)
349350
),
350351
"",

src/integrations/opencode/plugin-runtime/harness/retrieve.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,7 @@ async function fetchPluginContext(root: string, args: PluginRetrieveArgs): Promi
135135
blocking: false,
136136
nextAction: session ? "evaluate" : "prepare",
137137
mustInspect: selected,
138-
artifacts: [
139-
".agent-context/manifest.json",
140-
path.relative(root, contextUsageStorePath(root, contextTaskId)).replaceAll("\\", "/")
141-
],
138+
artifacts: [".agent-context/manifest.json", path.relative(root, contextUsageStorePath(root, contextTaskId)).replaceAll("\\", "/")],
142139
context,
143140
interventions: pluginInterventionSnapshot(root, session?.taskId ?? context.entry.id, selected, excludedFiles),
144141
performance: {

src/outputs/guard-gates.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ function contextGates(policy: PolicyEngineReport, loop: LoopControllerReport): G
102102
});
103103
}
104104

105-
const versionWarnings = policy.contextPolicy?.findings.filter((finding) => finding.id.startsWith("context.version-mismatch") && finding.status === "warning") ?? [];
105+
const versionWarnings =
106+
policy.contextPolicy?.findings.filter((finding) => finding.id.startsWith("context.version-mismatch") && finding.status === "warning") ?? [];
106107
if (versionWarnings.length) {
107108
gates.push({
108109
id: "context.version-mismatch",

test/context-policy.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ test("latest fresh Context usage supersedes stale usage for the same entry", ()
99
const assessment = assessExternalContextPolicy(".", { records: [stale, fresh], currentWorkingTreeHash: "tree-current" });
1010
assert.equal(assessment.records.length, 1);
1111
assert.equal(assessment.records[0]?.usageId, "new");
12-
assert.equal(assessment.findings.some((finding) => finding.status === "blocked"), false);
12+
assert.equal(
13+
assessment.findings.some((finding) => finding.status === "blocked"),
14+
false
15+
);
1316
});
1417

1518
test("stale Context blocks while trust remains non-authoritative", () => {

test/guard-gates.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,10 @@ test("Guard reports version mismatch without turning Context commands into actio
119119
const gate = report.gates.find((item) => item.id === "context.version-mismatch");
120120
assert.equal(gate?.status, "warning");
121121
assert.equal(gate?.action, "human-review");
122-
assert.equal(report.gates.some((item) => item.evidence.includes("npm run malicious")), false);
122+
assert.equal(
123+
report.gates.some((item) => item.evidence.includes("npm run malicious")),
124+
false
125+
);
123126
});
124127

125128
function buildEvidenceGateReport(trace: ExecutionTrace) {

test/intervention-mapper.test.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,16 @@ test("Context advice records adopted guidance and prevents untrusted commands",
137137
providedHelp: ["located src/sdk.ts"],
138138
adoptedSuggestions: [{ id: "file", kind: "file-location", disposition: "adopted", summary: "Use src/sdk.ts", reason: "selected file" }],
139139
availableSuggestions: [],
140-
rejectedSuggestions: [{ id: "cmd", kind: "command", disposition: "rejected", summary: "Run npm test", reason: "Context commands are suggestions only.", suggestedCommand: "npm test" }]
140+
rejectedSuggestions: [
141+
{
142+
id: "cmd",
143+
kind: "command",
144+
disposition: "rejected",
145+
summary: "Run npm test",
146+
reason: "Context commands are suggestions only.",
147+
suggestedCommand: "npm test"
148+
}
149+
]
141150
}
142151
};
143152
const result = recordIterationInterventions({

0 commit comments

Comments
 (0)