chore(telemetry): fix agent loops, name mangling, dev server leaks, CWD alignment, and add daily session auditor
This commit is contained in:
@@ -557,7 +557,7 @@ export async function POST(request: Request) {
|
||||
.replace(/<tool_calls>[\s\S]*?<\/tool_calls>/g, "")
|
||||
.replace(/<think>[\s\S]*?<\/think>/g, "")
|
||||
// Completely strip any legacy leaked "[tools executed this turn]" strings in case they exist in older messages
|
||||
.replace(/\n\n\[tools executed this turn:[\s\S]*?\]/g, "")
|
||||
.replace(/(?:\r?\n)*\[tools executed this turn:[\s\S]*?\]/g, "")
|
||||
.trim();
|
||||
}
|
||||
|
||||
@@ -1156,7 +1156,7 @@ export async function POST(request: Request) {
|
||||
|
||||
// Ensure we strip the `[tools executed this turn...]` block if the AI accidentally hallucinated it
|
||||
assistantText = assistantText.replace(
|
||||
/\n\n\[tools executed this turn:[\s\S]*?\]/g,
|
||||
/(?:\r?\n)*\[tools executed this turn:[\s\S]*?\]/g,
|
||||
"",
|
||||
);
|
||||
|
||||
@@ -1173,7 +1173,10 @@ export async function POST(request: Request) {
|
||||
toolCalls: assistantToolCalls.length ? assistantToolCalls : undefined,
|
||||
textSegments: assistantTextSegments.length
|
||||
? assistantTextSegments.map((seg) =>
|
||||
seg.replace(/\n\n\[tools executed this turn:[\s\S]*?\]/g, ""),
|
||||
seg.replace(
|
||||
/(?:\r?\n)*\[tools executed this turn:[\s\S]*?\]/g,
|
||||
"",
|
||||
),
|
||||
)
|
||||
: undefined,
|
||||
_rawToolResults: assistantToolCalls.length ? [] : undefined,
|
||||
|
||||
@@ -432,6 +432,7 @@ export async function POST(request: Request) {
|
||||
case "fs_read":
|
||||
return await toolFsRead(principal, params);
|
||||
case "request_visual_qa":
|
||||
case "request.visual.qa":
|
||||
return await toolRequestVisualQA(principal, params);
|
||||
case "fs.write":
|
||||
case "fs_write":
|
||||
@@ -440,10 +441,12 @@ export async function POST(request: Request) {
|
||||
case "fs_edit":
|
||||
return await toolFsEdit(principal, params);
|
||||
case "get_design_template":
|
||||
case "get.design.template":
|
||||
return await toolGetDesignTemplate(params);
|
||||
case "apps.templates.scaffold":
|
||||
return await toolAppsTemplatesScaffold(principal, params);
|
||||
case "generate_media":
|
||||
case "generate.media":
|
||||
return await toolGenerateMedia(principal, params);
|
||||
case "fs.list":
|
||||
case "fs_list":
|
||||
@@ -4505,7 +4508,10 @@ async function toolShellExec(
|
||||
const result = await execInDevContainer({
|
||||
projectId: project.id,
|
||||
command,
|
||||
cwd: typeof params.cwd === "string" ? params.cwd : undefined,
|
||||
cwd:
|
||||
typeof params.cwd === "string"
|
||||
? params.cwd
|
||||
: `/workspace/${project.slug}`,
|
||||
timeoutMs: Number.isFinite(Number(params.timeoutMs))
|
||||
? Number(params.timeoutMs)
|
||||
: Number.isFinite(Number(params.timeout_ms))
|
||||
@@ -5044,38 +5050,41 @@ except FileNotFoundError:
|
||||
sys.exit(2)
|
||||
|
||||
new_str = spec['newString']
|
||||
old = spec.get('oldString', '')
|
||||
|
||||
if spec.get('hasLineNumbers'):
|
||||
lines = src.splitlines(keepends=True)
|
||||
start = max(0, spec['startLine'] - 1)
|
||||
end = min(len(lines), spec['endLine'])
|
||||
if start > len(lines):
|
||||
sys.stderr.write('startLine is past end of file\\n')
|
||||
sys.exit(2)
|
||||
|
||||
# Ensure the new replacement lines have proper line endings
|
||||
new_lines = new_str.splitlines(keepends=True)
|
||||
if new_lines and not new_lines[-1].endswith('\\n'):
|
||||
new_lines[-1] += '\\n'
|
||||
|
||||
lines[start:end] = new_lines
|
||||
out = "".join(lines)
|
||||
n = 1
|
||||
else:
|
||||
old = spec['oldString']
|
||||
ra = spec.get('replaceAll', False)
|
||||
if old:
|
||||
n = src.count(old)
|
||||
if n == 0:
|
||||
sys.stderr.write('oldString not found\\n')
|
||||
sys.exit(2)
|
||||
if n > 1 and not ra:
|
||||
sys.stderr.write(f'oldString found {n}x; pass replaceAll=true or include more context\\n')
|
||||
sys.stderr.write("Anchor string (oldString) not found in file. Stale context or incorrect file? Code was NOT edited.\\n")
|
||||
sys.exit(3)
|
||||
out = src.replace(old, new_str) if ra else src.replace(old, new_str, 1)
|
||||
if n > 1 and not spec.get('replaceAll', False):
|
||||
sys.stderr.write(f"Anchor string (oldString) found {n}x (non-unique). Please include more lines of surrounding context to uniquely identify the target code block.\\n")
|
||||
sys.exit(3)
|
||||
out = src.replace(old, new_str) if spec.get('replaceAll', False) else src.replace(old, new_str, 1)
|
||||
n_replaced = n if spec.get('replaceAll', False) else 1
|
||||
else:
|
||||
if spec.get('hasLineNumbers'):
|
||||
lines = src.splitlines(keepends=True)
|
||||
start = max(0, spec['startLine'] - 1)
|
||||
end = min(len(lines), spec['endLine'])
|
||||
if start > len(lines):
|
||||
sys.stderr.write('startLine is past end of file\\n')
|
||||
sys.exit(2)
|
||||
|
||||
new_lines = new_str.splitlines(keepends=True)
|
||||
if new_lines and not new_lines[-1].endswith('\\n'):
|
||||
new_lines[-1] += '\\n'
|
||||
|
||||
lines[start:end] = new_lines
|
||||
out = "".join(lines)
|
||||
n_replaced = 1
|
||||
else:
|
||||
sys.stderr.write('Provide either oldString or startLine/endLine\\n')
|
||||
sys.exit(2)
|
||||
|
||||
with open(spec['path'], 'w', encoding='utf-8') as f:
|
||||
f.write(out)
|
||||
print(n)`;
|
||||
print(n_replaced)`;
|
||||
|
||||
const b64 = Buffer.from(JSON.stringify(payload), "utf8").toString("base64");
|
||||
const pyB64 = Buffer.from(py, "utf8").toString("base64");
|
||||
|
||||
Reference in New Issue
Block a user