GeezerVison is showing github.com — fix(client): a subagent prompt that opens with comment dividers no lo… · HNRow/r3code@f70eb5c
File tree
Expand file treeCollapse file tree
Open diff view settings
packages/client-runtime/src/state
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: packages/client-runtime/src/state/subagentRuntime.test.ts +12Lines changed: 12 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -316,5 +316,17 @@ describe("resolveWorkflowOpening", () => { |
316 | 316 | false, |
317 | 317 | ); |
318 | 318 | expect(isWorkflowScriptMessage({ role: "assistant", text: SCRIPT })).toBe(false); |
| 319 | + expect( |
| 320 | + isWorkflowScriptMessage({ role: "user", text: `// a\r// b\u2028/* c\n * d */\r\n${SCRIPT}` }), |
| 321 | + ).toBe(true); |
| 322 | + expect(isWorkflowScriptMessage({ role: "user", text: "// export const meta = {}" })).toBe( |
| 323 | + false, |
| 324 | + ); |
| 325 | + // Divider comments ahead of ordinary code must reject without catastrophic backtracking. |
| 326 | + const dividers = `${"/".repeat(40)}\n`.repeat(40); |
| 327 | + expect(isWorkflowScriptMessage({ role: "user", text: `${dividers}const x = 1;` })).toBe(false); |
| 328 | + expect( |
| 329 | + isWorkflowScriptMessage({ role: "user", text: `${"/**/".repeat(200)}const x = 1;` }), |
| 330 | + ).toBe(false); |
319 | 331 | }); |
320 | 332 | }); |
Collapse file
Copy file name to clipboardExpand all lines: packages/client-runtime/src/state/subagentRuntime.ts +3-1Lines changed: 3 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -325,7 +325,9 @@ export function deriveWorkflowGroups( |
325 | 325 | } |
326 | 326 |
|
327 | 327 | // Workflow scripts open with their `meta` export, after any leading comments. |
328 | | -const WORKFLOW_SCRIPT_START = /^\s*(?:(?:\/\/[^\n]*|\/\*[\s\S]*?\*\/)\s*)*export\s+const\s+meta\b/; |
| 328 | +// Each comment has one way to match, so a prompt of `////` divider lines cannot backtrack. |
| 329 | +const WORKFLOW_SCRIPT_START = |
| 330 | + /^\s*(?:(?:\/\/[^\r\n\u2028\u2029]*(?:[\r\n\u2028\u2029]|$)|\/\*(?:[^*]|\*(?!\/))*\*\/)\s*)*export\s+const\s+meta\b/; |
329 | 331 |
|
330 | 332 | /** |
331 | 333 | * Whether a user message is the script a provider-native workflow runs. Servers mark every |
|