fix: import reported agent outputs and authorize workbuddy writes

This commit is contained in:
Ryder Sun committed 2026-09-15 18:38:50 +08:00
1 parent d47bff5433
commit 28127b3706
3 files changed
+28 -1

No files matched your search

+20 -1
View File
@@ -426,7 +426,7 @@ function importAgentOutputs(input, attachmentStore) {
&& !Array.isArray(input.baseline.files)
? input.baseline.files
: {}
const candidates = outputFiles(safeOutputDirectory(workdirRealPath))
const controlledCandidates = outputFiles(safeOutputDirectory(workdirRealPath))
.filter(file => !sameFileState(baselineFiles[file.name], file))
.filter(file => Math.max(file.mtimeMs, file.ctimeMs) >= startedAt - 2000)
.sort((left, right) => (
@@ -434,6 +434,25 @@ function importAgentOutputs(input, attachmentStore) {
|| left.name.localeCompare(right.name)
))
const reportedCandidates = []
const reportedPaths = Array.isArray(input.reportedPaths) ? input.reportedPaths : []
for (const reportedPath of reportedPaths.slice(0, MAX_SCANNED_ENTRIES)) {
if (typeof reportedPath !== 'string' || !path.isAbsolute(reportedPath)) continue
try {
const realPath = fs.realpathSync(reportedPath)
const stat = fs.statSync(realPath)
const extension = path.extname(realPath).toLowerCase()
if (!stat.isFile() || !SUPPORTED_EXTENSIONS.has(extension)
|| stat.size > 64 * 1024 * 1024 || !isInside(workdirRealPath, realPath)) continue
reportedCandidates.push({
name: path.basename(realPath), path: realPath, size: stat.size,
mtimeMs: stat.mtimeMs, ctimeMs: stat.ctimeMs,
})
} catch { /* reported paths are best effort */ }
}
const candidates = [...controlledCandidates, ...reportedCandidates]
.filter((file, index, all) => all.findIndex(candidate => candidate.path === file.path) === index)
const imported = []
if (input.signal?.aborted) return imported
for (const file of candidates) {
@@ -145,6 +145,7 @@ function invocation(kind, executable, workdir, sessionRef = '', options = {}) {
'--output-format', 'stream-json',
'--include-partial-messages',
'--permission-mode', options.sandbox === 'workspace-write' ? 'acceptEdits' : 'plan',
...(options.sandbox === 'workspace-write' ? ['--dangerously-skip-permissions'] : []),
...(maxTurns ? ['--max-turns', String(maxTurns)] : []),
...(sessionRef ? ['--resume', sessionRef] : []),
],
@@ -49,6 +49,12 @@ const OUTCOME_REF_FIELDS = Object.freeze([
'workflowOutcomeRefs',
])
function extractReportedOutputPaths(text) {
if (typeof text !== 'string') return []
const matches = text.match(/(?:\/(?:Users|home|tmp|private\/tmp)\/[^\s"'<>`\]\[)]+)/g) || []
return [...new Set(matches.map(value => value.replace(/[.,;:!?]+$/, '')))]
}
function mergeOutcomeRefs(sources, options = {}) {
const merged = {}
const seen = new Map(OUTCOME_REF_FIELDS.map(field => [field, new Set()]))
@@ -1788,6 +1794,7 @@ class LocalWorkspaceAgentInvocation {
baseline: outputBaseline,
startedAt,
agentKind: kind,
reportedPaths: extractReportedOutputPaths(reply.text),
signal: agentController.signal,
}))
importPromise.catch(() => {})