MCPcopy
hub / github.com/openai/plugins / latest_workspace

Function latest_workspace

plugins/codex-security/scripts/workbench_db.py:1219–1265  ·  view source on GitHub ↗
(connection: sqlite3.Connection, thread_id: str)

Source from the content-addressed store, hash-verified

1217
1218
1219def latest_workspace(connection: sqlite3.Connection, thread_id: str) -> dict[str, Any]:
1220 thread_id = optional_text(thread_id, maximum=512)
1221 if thread_id is None:
1222 raise SystemExit("thread-id is required.")
1223 row = connection.execute(
1224 """
1225 SELECT workspaces.id
1226 FROM workspaces
1227 LEFT JOIN scans ON scans.id = workspaces.active_scan_id
1228 WHERE workspaces.thread_id = ?
1229 ORDER BY
1230 CASE WHEN scans.status = 'running' THEN 0 ELSE 1 END,
1231 CASE WHEN scans.status = 'running' THEN
1232 MAX(
1233 workspaces.updated_at,
1234 scans.updated_at,
1235 COALESCE((
1236 SELECT MAX(progress.updated_at)
1237 FROM scan_progress AS progress
1238 WHERE progress.scan_id = scans.id
1239 ), '')
1240 )
1241 ELSE
1242 MAX(
1243 workspaces.updated_at,
1244 COALESCE((
1245 SELECT MAX(triage.updated_at)
1246 FROM finding_triage AS triage
1247 JOIN finding_occurrences AS occurrences
1248 ON occurrences.id = triage.occurrence_id
1249 WHERE occurrences.scan_id = scans.id
1250 ), ''),
1251 COALESCE((
1252 SELECT MAX(remediation.updated_at)
1253 FROM finding_remediation_attempts AS remediation
1254 JOIN finding_occurrences AS occurrences
1255 ON occurrences.id = remediation.occurrence_id
1256 WHERE occurrences.scan_id = scans.id
1257 ), '')
1258 )
1259 END DESC,
1260 workspaces.created_at DESC
1261 LIMIT 1
1262 """,
1263 (thread_id,),
1264 ).fetchone()
1265 return {"workspace": workspace_state(connection, row["id"]) if row is not None else None}
1266
1267
1268def save_workspace(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:

Callers 1

mainFunction · 0.85

Calls 2

optional_textFunction · 0.90
workspace_stateFunction · 0.85

Tested by

no test coverage detected