Command: python -c "from pathlib import Path;ls=Path(r'C:\Users\ash\ChatGPTMasterBridge\Code.gs').read_text(encoding='utf-8',errors='replace').splitlines();print('\n'.join(f'{i+1}:{ls[i]}' for i in range(285,min(365,len(ls)))))"
Directory: projects
Status: SUCCESS
Exit code: 0
Cancel Job Rerun Command Refresh
286: ok: true,
287: target: target,
288: status: 'deleted',
289: recoverable: true,
290: note: 'Spreadsheet moved to Google Drive Trash; not permanently erased.'
291: });
292:}
293:
294:function verifyManagedBridge_(bridge, target) {
295: if (!bridge || !bridge.managed) throw new Error('bridge_not_master_managed');
296: const ss = SpreadsheetApp.openById(bridge.spreadsheet_id);
297: const marker = getStateValueInSs_(ss, 'master_bridge_id');
298: const storedTarget = getStateValueInSs_(ss, 'target');
299: if (marker !== MASTER_ID) throw new Error('ownership_marker_mismatch');
300: if (storedTarget !== target) throw new Error('target_marker_mismatch');
301: return true;
302:}
303:
304:function poll_(bridge, target) {
305: const sheet = sheetById_(bridge.spreadsheet_id, COMMANDS_SHEET);
306: const values = sheet.getDataRange().getValues();
307: const headers = values[0] || [];
308: const col = headerMap_(headers);
309: for (let r = 1; r < values.length; r++) {
310: const row = values[r];
311: const status = String(row[col.status] || '').toLowerCase();
312: const confirm = String(row[col.confirm] || '').toLowerCase();
313: if (status === 'pending' && confirm === 'yes') {
314: const attempts = Number(row[col.attempts] || 0) + 1;
315: sheet.getRange(r + 1, col.status + 1).setValue('running');
316: sheet.getRange(r + 1, col.claimed_at + 1).setValue(nowIso_());
317: sheet.getRange(r + 1, col.attempts + 1).setValue(attempts);
318: return json_({
319: ok: true,
320: target: target,
321: command: {
322: row: r + 1,
323: id: String(row[col.id] || ''),
324: action: String(row[col.action] || ''),
325: payload_json: String(row[col.payload_json] || '{}'),
326: attempts: attempts
327: }
328: });
329: }
330: }
331: return json_({ ok: true, target: target, command: null });
332:}
333:
334:function result_(bridge, target, body) {
335: const commandId = String(body.command_id || '');
336: if (!commandId) return json_({ ok: false, error: 'command_id_required' }, 400);
337:
338: const status = String(body.status || 'done');
339: const completedAt = nowIso_();
340: const resultText = truncate_(String(body.result_text || ''));
341: const errorText = truncate_(String(body.error || ''));
342: const httpStatus = body.http_status === undefined ? '' : String(body.http_status);
343: const durationMs = body.duration_ms === undefined ? '' : String(body.duration_ms);
344: const sha = String(body.result_sha256 || '');
345: const truncated = body.truncated ? 'yes' : 'no';
346:
347: const resultSheet = sheetById_(bridge.spreadsheet_id, RESULTS_SHEET);
348: const resultId = Utilities.getUuid();
349: resultSheet.appendRow([resultId, commandId, completedAt, status, httpStatus, resultText, errorText, durationMs, sha, truncated]);
350:
351: const commandSheet = sheetById_(bridge.spreadsheet_id, COMMANDS_SHEET);
352: const rows = commandSheet.getDataRange().getValues();
353: const col = headerMap_(rows[0] || []);
354: for (let r = 1; r < rows.length; r++) {
355: if (String(rows[r][col.id] || '') === commandId) {
356: commandSheet.getRange(r + 1, col.status + 1).setValue(status);
357: commandSheet.getRange(r + 1, col.completed_at + 1).setValue(completedAt);
358: commandSheet.getRange(r + 1, col.result_ref + 1).setValue(resultId);
359: commandSheet.getRange(r + 1, col.error + 1).setValue(errorText);
360: break;
361: }
362: }
363: setStateValueById_(bridge.spreadsheet_id, 'last_command_id', commandId, 'Updated by relay result');
364: return json_({ ok: true, target: target, result_id: resultId });
365:}