@oked/sdk 0.6.2 → 0.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/classify.js CHANGED
@@ -1376,16 +1376,76 @@ function classifyDirectoryGrant(tool, toolInput) {
1376
1376
  return "review";
1377
1377
  return "warning";
1378
1378
  }
1379
+ /**
1380
+ * Desktop app (`ccd_*`) tools that only change what the app shows or how it
1381
+ * tracks this session: panes, split view, the sidebar, the PR bar, archiving.
1382
+ * sync_with_base_branch merges the base branch into the session's worktree on
1383
+ * the host, the same as a Bash `git merge` or `git pull` (both safe); a push
1384
+ * after it is gated on its own. The app's tools with a real effect stay out
1385
+ * of this table: set_auto_merge (GitHub merges the PR), set_setting,
1386
+ * permission or model changes, worktree clean-up and discards.
1387
+ */
1388
+ const CCD_SAFE_TOOLS = new Map([
1389
+ ["ccd_pr", new Set(["bind_pr", "unbind_pr"])],
1390
+ ["ccd_view", new Set(["show_pane", "close_pane", "set_transcript_view"])],
1391
+ ["ccd_session", new Set(["spawn_task"])],
1392
+ ["ccd_window", new Set(["open_session_in", "close_split", "set_sidebar_collapsed"])],
1393
+ ["ccd_sidebar", new Set([
1394
+ "create_group", "create_section", "rename_group", "rename_section",
1395
+ "move_sessions", "set_pinned", "set_unread", "set_view",
1396
+ ])],
1397
+ ["ccd_host", new Set(["open_in_editor", "reveal_path", "request_keep_awake", "sync_with_base_branch"])],
1398
+ ["ccd_session_mgmt", new Set(["set_session_title", "archive_session", "unarchive_session"])],
1399
+ ]);
1400
+ // claude.ai connectors reach Claude Code as mcp__<uuid>__<tool>, so the server
1401
+ // name does not say which connector it is.
1402
+ const CONNECTOR_SERVER_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
1403
+ // Tool names that are a read verb alone (the prefix rules below need "read_").
1404
+ const SAFE_BARE_TOOLS = new Set(["read", "get", "list", "search", "find", "view", "guide", "help"]);
1405
+ function isRecord(v) {
1406
+ return typeof v === "object" && v !== null && !Array.isArray(v);
1407
+ }
1408
+ /**
1409
+ * Claude Docs connector writes: `batch` (create a doc or apply edits to one)
1410
+ * and `update` (edit a tab, rename, change a stored value). They change the
1411
+ * user's own docs on claude.ai, which are private until the user shares them.
1412
+ * Log them (`warning`), no prompt. The input shape identifies the connector,
1413
+ * because its server name is a UUID and the tool names are generic. Sharing
1414
+ * and deletes are not in this rule.
1415
+ */
1416
+ function isClaudeDocsWrite(server, tool, input) {
1417
+ if (!CONNECTOR_SERVER_RE.test(server))
1418
+ return false;
1419
+ if (tool === "batch") {
1420
+ return isRecord(input.container) && typeof input.container.kind === "string" &&
1421
+ (input.batch === undefined || Array.isArray(input.batch));
1422
+ }
1423
+ if (tool === "update") {
1424
+ return isRecord(input.ref) && typeof input.ref.object === "string" && typeof input.ref.id === "string" &&
1425
+ input.payload !== undefined;
1426
+ }
1427
+ return false;
1428
+ }
1379
1429
  function classifyMcpTool(toolName, toolInput = {}) {
1380
1430
  const parts = toolName.split("__");
1381
1431
  const tool = parts[parts.length - 1] || "";
1382
1432
  if (parts.includes("ccd_directory") && (tool === "change_directory" || tool === "request_directory")) {
1383
1433
  return classifyDirectoryGrant(tool, toolInput);
1384
1434
  }
1435
+ if (parts.slice(1, -1).some((p) => CCD_SAFE_TOOLS.get(p)?.has(tool)))
1436
+ return "safe";
1437
+ // The PR bar's CI monitor switches. auto_fix lets the session push fixes,
1438
+ // but each push is gated on its own. Log it, no prompt.
1439
+ if (parts.includes("ccd_pr") && tool === "set_monitor")
1440
+ return "warning";
1441
+ if (parts.length === 3 && isClaudeDocsWrite(parts[1] || "", tool, toolInput))
1442
+ return "warning";
1385
1443
  const browserServer = parts.slice(1, -1).find((p) => BROWSER_MCP_SERVERS.has(p));
1386
1444
  if (browserServer)
1387
1445
  return classifyBrowserTool(tool, toolInput, browserServer);
1388
1446
  // Read-only retrieval verbs.
1447
+ if (SAFE_BARE_TOOLS.has(tool))
1448
+ return "safe";
1389
1449
  if (tool.startsWith("list_") || tool.startsWith("get_") || tool.startsWith("search_") ||
1390
1450
  tool.startsWith("read_") || tool.startsWith("fetch_") || tool.startsWith("query_") ||
1391
1451
  tool.startsWith("find_") || tool.startsWith("view_") || tool.startsWith("show_") ||
package/dist/describe.js CHANGED
@@ -495,16 +495,31 @@ function extractSqlFromScriptBody(body) {
495
495
  // to gate SQL extraction so SQL words appearing in *argument data* (a `gh pr
496
496
  // create --body` mentioning "TRUNCATE", a path like `better-sqlite3`) don't get
497
497
  // misread as a statement to run.
498
- const SQL_CONSUMER_RE = /(?:^|\||&&|;|\$\(|`)\s*(?:\w+=\S+\s+)*(?:sudo\s+)?(?:psql|mysql|mariadb|sqlite3?|node|python\d?|ruby|perl|deno|bun)\b/;
498
+ const SQL_CLI_CONSUMER_RE = /(?:^|\||&&|;|\$\(|`)\s*(?:\w+=\S+\s+)*(?:sudo\s+)?(?:psql|mysql|mariadb|sqlite3?)\b/;
499
+ const INTERPRETER_CONSUMER_RE = /(?:^|\||&&|;|\$\(|`)\s*(?:\w+=\S+\s+)*(?:sudo\s+)?(?:node|python\d?|ruby|perl|deno|bun)\b/;
500
+ // A database client library named in a script body. A script that has SQL
501
+ // words but no .execute()-style call and no DB library cannot run SQL: it is
502
+ // text processing (a Python script that edits a source file whose comments
503
+ // say "DELETE FROM", for example), so it must not be shown as a SQL statement.
504
+ const DB_LIBRARY_RE = /\b(?:sqlite3|better-sqlite3|psycopg2?|pymysql|MySQLdb|mysql2?|sqlalchemy|duckdb|knex|prisma|pg|sequel|DBI)\b/;
505
+ // SQL to run from an interpreter body (node -e, python -c, `python - <<EOF`).
506
+ function sqlFromInterpreterBody(body) {
507
+ if (!SQL_KEYWORDS_RE.test(body))
508
+ return null;
509
+ const extracted = extractSqlFromScriptBody(body);
510
+ if (extracted)
511
+ return extracted;
512
+ return DB_LIBRARY_RE.test(body) ? body : null;
513
+ }
499
514
  export function findSqlInCommand(cmd) {
500
515
  // Inline interpreter flags: node -e, python -c, ruby -e, perl -e. Anchored to
501
516
  // a command position so a SQL-looking string elsewhere doesn't match.
502
517
  const inline = cmd.match(/(?:^|\||&&|;|\$\()\s*(?:\w+=\S+\s+)*(?:sudo\s+)?(?:node|python\d?|ruby|perl|deno|bun)\s+-[ec]\s+(?:"([\s\S]+?)"|'([\s\S]+?)')\s*$/);
503
518
  if (inline) {
504
519
  const body = inline[1] ?? inline[2];
505
- if (body && SQL_KEYWORDS_RE.test(body)) {
506
- return extractSqlFromScriptBody(body) ?? body;
507
- }
520
+ const sql = body ? sqlFromInterpreterBody(body) : null;
521
+ if (sql)
522
+ return sql;
508
523
  }
509
524
  // psql -c "..." / mysql -e "..." / sqlite3 db "..." — outer-quoted statement.
510
525
  // Anchored to the start of the command so "psql"/"mysql" appearing inside an
@@ -523,9 +538,14 @@ export function findSqlInCommand(cmd) {
523
538
  if (hd) {
524
539
  const body = hd[2];
525
540
  const context = cmd.slice(0, hd.index) + cmd.slice((hd.index ?? 0) + hd[0].length);
526
- if (body && SQL_CONSUMER_RE.test(context) && SQL_KEYWORDS_RE.test(body)) {
541
+ if (body && SQL_CLI_CONSUMER_RE.test(context) && SQL_KEYWORDS_RE.test(body)) {
527
542
  return extractSqlFromScriptBody(body) ?? body;
528
543
  }
544
+ if (body && INTERPRETER_CONSUMER_RE.test(context)) {
545
+ const sql = sqlFromInterpreterBody(body);
546
+ if (sql)
547
+ return sql;
548
+ }
529
549
  }
530
550
  // Direct SQL keywords at top of command
531
551
  if (/^\s*(DROP|DELETE\s+FROM|TRUNCATE|UPDATE|INSERT\s+INTO|CREATE\s+TABLE|ALTER\s+TABLE)\b/i.test(cmd)) {
@@ -859,7 +879,13 @@ function summarizeBrowser(tool, input, server) {
859
879
  }
860
880
  function summarizeMcp(toolName, input) {
861
881
  const parts = toolName.split("__");
862
- const server = parts[1] || "unknown";
882
+ // claude.ai connectors have a UUID as the server name. The UUID means nothing to the approver.
883
+ // Desktop app tools have internal server names (ccd_host, ccd_pr).
884
+ const server = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(parts[1] || "")
885
+ ? "claude.ai connector"
886
+ : /^ccd_/.test(parts[1] || "")
887
+ ? "Claude desktop app"
888
+ : parts[1] || "unknown";
863
889
  const tool = parts[2] || "";
864
890
  if (parts.includes("ccd_directory") && (tool === "change_directory" || tool === "request_directory")) {
865
891
  const dir = typeof input.path === "string" && input.path.trim() ? shortenPath(input.path.trim()) : undefined;
@@ -939,7 +965,7 @@ function summarizeMcp(toolName, input) {
939
965
  if (tool.startsWith("list_") || tool.startsWith("get_") || tool.startsWith("search_")) {
940
966
  return { title: `${toWords(tool)} via ${server}`, kind: "unknown_tool" };
941
967
  }
942
- return { title: `${toWords(tool)} via ${server}`, kind: "unknown_tool" };
968
+ return { title: `${toSentence(tool)} via ${server}`, kind: "unknown_tool" };
943
969
  }
944
970
  function identifyTarget(input) {
945
971
  const id = input.id ?? input.name ?? input.path ?? input.target ?? input.repo ?? input.repository ?? null;
@@ -1187,6 +1213,13 @@ function formatByteCount(bytes) {
1187
1213
  function toWords(snake) {
1188
1214
  return snake.replace(/_/g, " ").split(" ").map((w) => (w.length <= 3 ? w.toUpperCase() : w)).join(" ");
1189
1215
  }
1216
+ // "set_auto_merge" -> "Set auto merge", "bind_pr" -> "Bind PR": the first word
1217
+ // is a verb, so it is not read as an acronym.
1218
+ function toSentence(snake) {
1219
+ const [first = "", ...rest] = snake.split("_");
1220
+ const head = first.charAt(0).toUpperCase() + first.slice(1).toLowerCase();
1221
+ return rest.length ? `${head} ${toWords(rest.join("_"))}` : head;
1222
+ }
1190
1223
  function shortenPath(filePath) {
1191
1224
  return filePath
1192
1225
  .replace(/^\/home\/[^/]+\//, "~/")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oked/sdk",
3
- "version": "0.6.2",
3
+ "version": "0.6.4",
4
4
  "description": "OKed SDK - human approval layer for AI agents",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -45,7 +45,7 @@
45
45
  "access": "public"
46
46
  },
47
47
  "dependencies": {
48
- "@oked/receipt-core": "0.6.2"
48
+ "@oked/receipt-core": "0.6.4"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@types/node": "^22.13.10",