|
|
|
@ -61,7 +61,7 @@ |
|
|
|
if (pid.length === 0) return; |
|
|
|
if (pid.length === 0) return; |
|
|
|
if (pid === lastSsePid) { __uiLog('sse dup skipped ' + pid); return; } |
|
|
|
if (pid === lastSsePid) { __uiLog('sse dup skipped ' + pid); return; } |
|
|
|
lastSsePid = pid; |
|
|
|
lastSsePid = pid; |
|
|
|
var parsed = extractCalls(d.text, 10); |
|
|
|
var parsed = extractCalls(d.text, 0); |
|
|
|
try { var __callSum = []; if (parsed ? (parsed.calls ? true : false) : false) { for (var __ci = 0; __ci < parsed.calls.length; __ci++) { var __c = parsed.calls[__ci]; __callSum.push({ i: __ci, tool: (__c ? String(__c.tool) : 'null'), hasArgs: (__c ? (__c.args ? true : false) : false), argsPreview: (__c ? String(JSON.stringify(__c.args || {})).slice(0, 400) : '') }) } } __debugReport({ ev: 'sse-parse', ts: Date.now(), pid: pid, execSource: execMode, consumed: (parsed ? parsed.consumed : -1), textLen: d.text.length, calls: __callSum, parsedCount: (parsed ? parsed.calls.length : 0), text: String(d.text).slice(0, 2000) }) } catch (e7) { } |
|
|
|
try { var __callSum = []; if (parsed ? (parsed.calls ? true : false) : false) { for (var __ci = 0; __ci < parsed.calls.length; __ci++) { var __c = parsed.calls[__ci]; __callSum.push({ i: __ci, tool: (__c ? String(__c.tool) : 'null'), hasArgs: (__c ? (__c.args ? true : false) : false), argsPreview: (__c ? String(JSON.stringify(__c.args || {})).slice(0, 400) : '') }) } } __debugReport({ ev: 'sse-parse', ts: Date.now(), pid: pid, execSource: execMode, consumed: (parsed ? parsed.consumed : -1), textLen: d.text.length, calls: __callSum, parsedCount: (parsed ? parsed.calls.length : 0), text: String(d.text).slice(0, 2000) }) } catch (e7) { } |
|
|
|
if (parsed ? (parsed.calls ? (parsed.calls.length > 0) : false) : false) { |
|
|
|
if (parsed ? (parsed.calls ? (parsed.calls.length > 0) : false) : false) { |
|
|
|
var validCount = 0; |
|
|
|
var validCount = 0; |
|
|
|
@ -77,8 +77,8 @@ |
|
|
|
} |
|
|
|
} |
|
|
|
if (validCount === 0) { if (UI) UI.setPhase('idle'); return; } |
|
|
|
if (validCount === 0) { if (UI) UI.setPhase('idle'); return; } |
|
|
|
if (UI) { if (UI.setDot) UI.setDot('ok-busy'); UI.setPhase('executing'); } |
|
|
|
if (UI) { if (UI.setDot) UI.setDot('ok-busy'); UI.setPhase('executing'); } |
|
|
|
__uiLog('sse exec ' + parsed.calls.length + ' pid ' + pid); |
|
|
|
__uiLog('sse exec ' + parsed.calls.length + ' pid ' + pid + ' on_error ' + ((parsed.policy && parsed.policy.on_error) || 'continue')); |
|
|
|
pump(); |
|
|
|
pump(parsed.policy); |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (e) { console.warn('[dsh-memory] sse-answer error', String(e)); } |
|
|
|
} catch (e) { console.warn('[dsh-memory] sse-answer error', String(e)); } |
|
|
|
}); |
|
|
|
}); |
|
|
|
@ -241,7 +241,7 @@ |
|
|
|
processed.add(m); |
|
|
|
processed.add(m); |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
var hasMarker = text.indexOf(String.fromCharCode(10214)) !== -1 || text.indexOf('[DSH') !== -1; if (hasMarker && UI && UI.setDot) UI.setDot('busy'); var parsed = extractCalls(text, 10); |
|
|
|
var hasMarker = text.indexOf(String.fromCharCode(10214)) !== -1 || text.indexOf('[DSH') !== -1; if (hasMarker && UI && UI.setDot) UI.setDot('busy'); var parsed = extractCalls(text, 0); |
|
|
|
if (!parsed) continue; |
|
|
|
if (!parsed) continue; |
|
|
|
if (!parsed.calls) continue; |
|
|
|
if (!parsed.calls) continue; |
|
|
|
if (parsed.calls.length === 0) { if (hasMarker) { try { var __dh = hashText(text); if (!domDebugSeen.has(__dh) && domDebugCount < 3) { domDebugSeen.add(__dh); domDebugCount = domDebugCount + 1; __debugReport({ ev: 'dom-parse-fail', ts: Date.now(), execSource: execMode, textLen: text.length, msgText: String(text).slice(0, 2000) }) } } catch (e9) { } } continue; } |
|
|
|
if (parsed.calls.length === 0) { if (hasMarker) { try { var __dh = hashText(text); if (!domDebugSeen.has(__dh) && domDebugCount < 3) { domDebugSeen.add(__dh); domDebugCount = domDebugCount + 1; __debugReport({ ev: 'dom-parse-fail', ts: Date.now(), execSource: execMode, textLen: text.length, msgText: String(text).slice(0, 2000) }) } } catch (e9) { } } continue; } |
|
|
|
@ -253,7 +253,7 @@ if (parsed.calls.length === 0) { if (hasMarker) { try { var __dh = hashText(text |
|
|
|
for (k = 0; k < parsed.calls.length; k++) { var __dc = parsed.calls[k]; if (__dc && __dc.tool === 'invalid') { try { __debugReport({ ev: 'sse-exec-result', ts: Date.now(), pid: lastSsePid, execSource: execMode, tool: 'invalid', ok: false, errorCode: 'E_PARSE_INVALID', errorMsg: String((__dc.args && __dc.args._reason) || '') }) } catch (e) { } continue; } queue.push(__dc); } if (UI && UI.setDot) UI.setDot('ok-busy'); |
|
|
|
for (k = 0; k < parsed.calls.length; k++) { var __dc = parsed.calls[k]; if (__dc && __dc.tool === 'invalid') { try { __debugReport({ ev: 'sse-exec-result', ts: Date.now(), pid: lastSsePid, execSource: execMode, tool: 'invalid', ok: false, errorCode: 'E_PARSE_INVALID', errorMsg: String((__dc.args && __dc.args._reason) || '') }) } catch (e) { } continue; } queue.push(__dc); } if (UI && UI.setDot) UI.setDot('ok-busy'); |
|
|
|
if (UI) UI.setPhase('executing'); |
|
|
|
if (UI) UI.setPhase('executing'); |
|
|
|
} |
|
|
|
} |
|
|
|
pump(); |
|
|
|
pump(parsed.policy); |
|
|
|
} |
|
|
|
} |
|
|
|
function executeOne(call) { |
|
|
|
function executeOne(call) { |
|
|
|
return BRIDGE.sendCall(call).then(function (res) { |
|
|
|
return BRIDGE.sendCall(call).then(function (res) { |
|
|
|
@ -266,11 +266,19 @@ if (parsed.calls.length === 0) { if (hasMarker) { try { var __dh = hashText(text |
|
|
|
return res; |
|
|
|
return res; |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
function pump() { |
|
|
|
var MUTATING_TOOLS = { dsh_write: 1, dsh_edit: 1, dsh_script: 1, dsh_bash: 1 }; |
|
|
|
|
|
|
|
function pump(policy) { |
|
|
|
if (pumping) return; |
|
|
|
if (pumping) return; |
|
|
|
if (queue.length === 0) return; |
|
|
|
if (queue.length === 0) return; |
|
|
|
pumping = true; |
|
|
|
pumping = true; |
|
|
|
|
|
|
|
var onError = (policy && policy.on_error) ? String(policy.on_error) : 'continue'; |
|
|
|
|
|
|
|
var stopAll = false; |
|
|
|
|
|
|
|
var failedTools = {}; |
|
|
|
|
|
|
|
var failedMutating = false; |
|
|
|
var results = []; |
|
|
|
var results = []; |
|
|
|
|
|
|
|
var skipResult = function (call, reason) { |
|
|
|
|
|
|
|
return { ok: false, skipped: true, error: { code: 'E_SKIPPED', message: reason }, tool: call.tool }; |
|
|
|
|
|
|
|
}; |
|
|
|
var step = function () { |
|
|
|
var step = function () { |
|
|
|
if (queue.length === 0) { |
|
|
|
if (queue.length === 0) { |
|
|
|
pumping = false; |
|
|
|
pumping = false; |
|
|
|
@ -282,6 +290,9 @@ if (parsed.calls.length === 0) { if (hasMarker) { try { var __dh = hashText(text |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
var call = queue.shift(); |
|
|
|
var call = queue.shift(); |
|
|
|
|
|
|
|
if (stopAll) { results.push(skipResult(call, 'on_error=stop: previous call failed')); return step(); } |
|
|
|
|
|
|
|
if (onError === 'skip_same_tool' && failedTools[call.tool]) { results.push(skipResult(call, 'on_error=skip_same_tool')); return step(); } |
|
|
|
|
|
|
|
if (onError === 'skip_mutating' && failedMutating && MUTATING_TOOLS[call.tool]) { results.push(skipResult(call, 'on_error=skip_mutating')); return step(); } |
|
|
|
executeOne(call).then(function (res) { |
|
|
|
executeOne(call).then(function (res) { |
|
|
|
try { __debugReport({ ev: 'sse-exec-result', ts: Date.now(), pid: lastSsePid, execSource: execMode, tool: (call ? String(call.tool) : 'null'), ok: (res ? (res.ok ? true : false) : false), errorCode: (res ? (res.error ? String(res.error.code || '') : '') : 'nores'), errorMsg: (res ? (res.error ? String(res.error.message || '').slice(0, 300) : '') : '') }) } catch (e8) { } |
|
|
|
try { __debugReport({ ev: 'sse-exec-result', ts: Date.now(), pid: lastSsePid, execSource: execMode, tool: (call ? String(call.tool) : 'null'), ok: (res ? (res.ok ? true : false) : false), errorCode: (res ? (res.error ? String(res.error.code || '') : '') : 'nores'), errorMsg: (res ? (res.error ? String(res.error.message || '').slice(0, 300) : '') : '') }) } catch (e8) { } |
|
|
|
if (res) { |
|
|
|
if (res) { |
|
|
|
@ -297,6 +308,7 @@ if (parsed.calls.length === 0) { if (hasMarker) { try { var __dh = hashText(text |
|
|
|
console.warn('[dsh-memory] call failed (no res)', call.tool); |
|
|
|
console.warn('[dsh-memory] call failed (no res)', call.tool); |
|
|
|
if (UI) UI.log('fail ' + call.tool + ' ' + JSON.stringify((res && res.error) || 'nores')); |
|
|
|
if (UI) UI.log('fail ' + call.tool + ' ' + JSON.stringify((res && res.error) || 'nores')); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (!res || !res.ok) { if (onError === 'stop') stopAll = true; if (onError === 'skip_same_tool') failedTools[call.tool] = true; if (onError === 'skip_mutating' && MUTATING_TOOLS[call.tool]) failedMutating = true; } |
|
|
|
}).catch(function (err) { console.warn('[dsh-memory] call throw', call.tool, String(err)); }).then(step); |
|
|
|
}).catch(function (err) { console.warn('[dsh-memory] call throw', call.tool, String(err)); }).then(step); |
|
|
|
}; |
|
|
|
}; |
|
|
|
step(); |
|
|
|
step(); |
|
|
|
|