| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- // 251 langgraph dispatch via opencode SHELL channel (bypasses agent LLM, per B-94/R101)
- // Auth: opencode:IwinTrue@123
- const BASE = process.env.OPENCODE_251_BASE || 'http://192.168.16.251:4096';
- const AUTH = 'Basic ' + Buffer.from('opencode:' + (process.env.OPENCODE_SERVER_PASSWORD || 'IwinTrue@123')).toString('base64');
- const PROJECT_ID = '527b7036bd8d16188784528603a9b79a1d95c9fb';
- const capMs = parseInt(process.env.DISPATCH_CAP_MS || '420000', 10);
- const CMD = "cd /sc-data/cfc/cfc-langgraph && git pull --ff-only 2>&1 | tail -3 ; timeout 600 .venv/bin/python -m pytest tests --ignore=tests/qna --ignore=tests/test_chat.py -q ; echo EXIT=$?";
- async function j(url, opt) {
- const r = await fetch(url, Object.assign({ headers: { 'Authorization': AUTH, 'Content-Type': 'application/json' } }, opt));
- const t = await r.text();
- try { return { status: r.status, json: JSON.parse(t) }; } catch { return { status: r.status, text: t }; }
- }
- async function main() {
- const cr = await j(BASE + '/api/session', { method: 'POST', body: JSON.stringify({ title: 'lg-shell-' + Date.now(), model: { id: 'deepseek3.2', providerID: 'axon' }, projectID: PROJECT_ID }) });
- const sid = (cr.json.data && cr.json.data.id) || cr.json.id;
- if (!sid) throw new Error('no session: ' + JSON.stringify(cr.json).slice(0,200));
- console.log('SESSION_ID', sid);
- const sr = await j(BASE + '/api/session/' + sid + '/shell', { method: 'POST', body: JSON.stringify({ command: CMD }) });
- console.log('SHELL_CREATE', sr.status);
- // find shell id
- let shellId = null;
- for (let i = 0; i < 10 && !shellId; i++) {
- const gl = await j(BASE + '/api/shell');
- const arr = (gl.json && (gl.json.data || gl.json)) || [];
- if (Array.isArray(arr) && arr.length) { shellId = arr[arr.length - 1].id; break; }
- await new Promise(r => setTimeout(r, 1500));
- }
- if (!shellId) throw new Error('no shell id');
- console.log('SHELL_ID', shellId);
- const start = Date.now();
- let last = '';
- while (Date.now() - start < capMs) {
- await new Promise(r => setTimeout(r, 4000));
- const st = await j(BASE + '/api/shell/' + shellId);
- const status = (st.json && (st.json.data && st.json.data.status || st.json.status)) || '?';
- if (status !== last) { console.log('SHELL_STATUS', status); last = status; }
- if (status && status !== 'running') {
- const out = await j(BASE + '/api/shell/' + shellId + '/output');
- const o = (out.json && out.json.data && out.json.data.output) || '';
- console.log('OUTPUT_BEGIN');
- console.log(o.slice(-4000));
- console.log('OUTPUT_END');
- return;
- }
- }
- console.log('SHELL_TIMEOUT after ' + capMs + 'ms');
- }
- main().catch(e => { console.error('ERR', e.message); process.exit(1); });
|