mirror of
https://github.com/Heretek-AI/opencode-harness.git
synced 2026-11-07 10:56:02 -10:00
Scan for the reworded subagent bullet without a regex; pin setup-bun
CodeQL flagged the fallback line regex as polynomial on crafted prompt text. A plain line scan does the same match in linear time. setup-bun is pinned to the v2.2.0 commit. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_012AuVk4nEvBXaTjs4G6wdW4
This commit is contained in:
2 files changed
+24
-7
No files matched your search
@@ -13,7 +13,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: oven-sh/setup-bun@v2
|
||||
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
|
||||
with:
|
||||
bun-version: 1.4.2
|
||||
- run: bun install --frozen-lockfile
|
||||
@@ -26,7 +26,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: oven-sh/setup-bun@v2
|
||||
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
|
||||
with:
|
||||
bun-version: 1.4.2
|
||||
- run: bun install --frozen-lockfile
|
||||
|
||||
@@ -37,8 +37,22 @@ const META_SUBAGENT_OVERTRIGGER =
|
||||
* single bullet line telling the model to use `subagent` to save context
|
||||
* tokens. Deliberately one line (`[^\n]*`) so nothing else is touched.
|
||||
*/
|
||||
const META_SUBAGENT_OVERTRIGGER_LINE =
|
||||
/^- [^\n]*`subagent` tool[^\n]*context token usage[^\n]*$/m;
|
||||
/**
|
||||
* Fallback for a reworded upstream sentence: the bullet line that mentions both
|
||||
* the `subagent` tool and context token usage. A plain line scan (no regex) keeps
|
||||
* this linear on arbitrary prompt text.
|
||||
*/
|
||||
function replaceSubagentOvertriggerLine(text: string): string | undefined {
|
||||
const lines = text.split("\n");
|
||||
const index = lines.findIndex((line) => {
|
||||
if (!line.startsWith("- ")) return false;
|
||||
const toolAt = line.indexOf("`subagent` tool");
|
||||
return toolAt !== -1 && line.indexOf("context token usage", toolAt) !== -1;
|
||||
});
|
||||
if (index === -1) return undefined;
|
||||
lines[index] = CALIBRATED_SUBAGENT_RULE;
|
||||
return lines.join("\n");
|
||||
}
|
||||
|
||||
const CALIBRATED_SUBAGENT_RULE =
|
||||
"- Perform routine file reads (`read`, `file_hash_read`, `file_outline`), targeted searches (`grep`, `glob`, `ast_structural_search`, `symbol_references`), and dependency checks (`repo_map`, `blast_radius`) directly in the main context. Only spawn a `subagent` when broad exploration spans more than 8 files or when executing independent parallel workstreams.";
|
||||
@@ -64,11 +78,14 @@ export function calibrateSystemPromptInPlace(
|
||||
if (text.includes(META_SUBAGENT_OVERTRIGGER)) {
|
||||
text = text.replace(META_SUBAGENT_OVERTRIGGER, CALIBRATED_SUBAGENT_RULE);
|
||||
modified = true;
|
||||
} else if (META_SUBAGENT_OVERTRIGGER_LINE.test(text)) {
|
||||
} else {
|
||||
// Upstream reworded the sentence: still replace the whole bullet line so
|
||||
// the calibration does not silently become a no-op.
|
||||
text = text.replace(META_SUBAGENT_OVERTRIGGER_LINE, CALIBRATED_SUBAGENT_RULE);
|
||||
modified = true;
|
||||
const replaced = replaceSubagentOvertriggerLine(text);
|
||||
if (replaced !== undefined) {
|
||||
text = replaced;
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
const overlay = buildMuseSystemOverlay();
|
||||
if (!text.includes("<muse-1.3-harness-calibration>")) {
|
||||
|
||||
Reference in new issue
Block a user