@oked/sdk 0.6.1 → 0.6.3

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
@@ -51,6 +51,69 @@ const SAFE_TOOL_ALIASES = new Set([
51
51
  "search_files",
52
52
  "find",
53
53
  ]);
54
+ // Claude Code built-ins that only steer the session itself (its background
55
+ // tasks, todo list, plan mode, tool loading, questions to the user) or show
56
+ // something to the user. They touch no files, network or other process, so a
57
+ // prompt is pure approval fatigue.
58
+ const SAFE_SESSION_TOOLS = new Set([
59
+ "TaskStop",
60
+ "KillShell",
61
+ "TaskOutput",
62
+ "BashOutput",
63
+ "TaskCreate",
64
+ "TaskUpdate",
65
+ "TodoWrite",
66
+ "ToolSearch",
67
+ "Skill",
68
+ "AskUserQuestion",
69
+ "EnterPlanMode",
70
+ "ExitPlanMode",
71
+ "ListAgents",
72
+ "CronList",
73
+ "ScheduleWakeup",
74
+ "LSP",
75
+ "ReportFindings",
76
+ "SendUserFile",
77
+ "PushNotification",
78
+ ]);
79
+ // Claude Code built-ins with a small effect: a new worktree, a session-only
80
+ // scheduled prompt, a message to another agent, a web page fetch. Logged, not
81
+ // prompted; whatever they lead to (the scheduled prompt's tool calls, the other
82
+ // agent's actions) is gated on its own.
83
+ const WARNING_SESSION_TOOLS = new Set([
84
+ "EnterWorktree",
85
+ "CronCreate",
86
+ "CronDelete",
87
+ "SendMessage",
88
+ "WebFetch",
89
+ ]);
90
+ /** Built-ins whose tier depends on their input. Returns null for other tools. */
91
+ function classifySessionTool(toolName, toolInput) {
92
+ switch (toolName) {
93
+ // "keep" leaves everything on disk. "remove" refuses when there is
94
+ // unsaved work, unless discard_changes deletes it for good.
95
+ case "ExitWorktree":
96
+ if (toolInput.action !== "remove")
97
+ return "safe";
98
+ return toolInput.discard_changes === true ? "high_stakes" : "warning";
99
+ // Monitor runs a shell command (classified like Bash) or reads a WebSocket.
100
+ case "Monitor":
101
+ if (typeof toolInput.command === "string")
102
+ return classifyBashCommand(toolInput.command);
103
+ return "warning";
104
+ // Artifact: publishing puts content on claude.ai; delete is permanent;
105
+ // read / list / open / quickstart / pin only look or arrange.
106
+ case "Artifact": {
107
+ const action = typeof toolInput.action === "string" ? toolInput.action : "publish";
108
+ if (action === "delete")
109
+ return "high_stakes";
110
+ if (action === "publish")
111
+ return "review";
112
+ return "safe";
113
+ }
114
+ }
115
+ return null;
116
+ }
54
117
  // Tools that are always review-tier risk (modify local files)
55
118
  const REVIEW_TOOLS = new Set([]);
56
119
  // Tools that are always high stakes
@@ -317,6 +380,13 @@ export function classify(toolName, toolInput) {
317
380
  return "high_stakes";
318
381
  if (REVIEW_TOOLS.has(toolName))
319
382
  return "review";
383
+ if (SAFE_SESSION_TOOLS.has(toolName))
384
+ return "safe";
385
+ if (WARNING_SESSION_TOOLS.has(toolName))
386
+ return "warning";
387
+ const sessionTier = classifySessionTool(toolName, toolInput);
388
+ if (sessionTier !== null)
389
+ return sessionTier;
320
390
  // File-editing tools: a write/edit can't act on its own — whatever later
321
391
  // executes it is classified separately — so it's `warning` (logged, no
322
392
  // prompt) everywhere EXCEPT sensitive targets (system dirs, secret stores,
package/dist/describe.js CHANGED
@@ -62,6 +62,9 @@ function summarize(toolName, toolInput, ctx) {
62
62
  case "Agent":
63
63
  return summarizeAgent(toolInput);
64
64
  }
65
+ const session = summarizeSessionTool(toolName, toolInput);
66
+ if (session)
67
+ return session;
65
68
  if (toolName.startsWith("mcp__")) {
66
69
  return summarizeMcp(toolName, toolInput);
67
70
  }
@@ -492,16 +495,31 @@ function extractSqlFromScriptBody(body) {
492
495
  // to gate SQL extraction so SQL words appearing in *argument data* (a `gh pr
493
496
  // create --body` mentioning "TRUNCATE", a path like `better-sqlite3`) don't get
494
497
  // misread as a statement to run.
495
- 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
+ }
496
514
  export function findSqlInCommand(cmd) {
497
515
  // Inline interpreter flags: node -e, python -c, ruby -e, perl -e. Anchored to
498
516
  // a command position so a SQL-looking string elsewhere doesn't match.
499
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*$/);
500
518
  if (inline) {
501
519
  const body = inline[1] ?? inline[2];
502
- if (body && SQL_KEYWORDS_RE.test(body)) {
503
- return extractSqlFromScriptBody(body) ?? body;
504
- }
520
+ const sql = body ? sqlFromInterpreterBody(body) : null;
521
+ if (sql)
522
+ return sql;
505
523
  }
506
524
  // psql -c "..." / mysql -e "..." / sqlite3 db "..." — outer-quoted statement.
507
525
  // Anchored to the start of the command so "psql"/"mysql" appearing inside an
@@ -520,9 +538,14 @@ export function findSqlInCommand(cmd) {
520
538
  if (hd) {
521
539
  const body = hd[2];
522
540
  const context = cmd.slice(0, hd.index) + cmd.slice((hd.index ?? 0) + hd[0].length);
523
- 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)) {
524
542
  return extractSqlFromScriptBody(body) ?? body;
525
543
  }
544
+ if (body && INTERPRETER_CONSUMER_RE.test(context)) {
545
+ const sql = sqlFromInterpreterBody(body);
546
+ if (sql)
547
+ return sql;
548
+ }
526
549
  }
527
550
  // Direct SQL keywords at top of command
528
551
  if (/^\s*(DROP|DELETE\s+FROM|TRUNCATE|UPDATE|INSERT\s+INTO|CREATE\s+TABLE|ALTER\s+TABLE)\b/i.test(cmd)) {
@@ -1070,6 +1093,82 @@ function prettyServer(server) {
1070
1093
  // ───────────────────────────────────────────────────────────────────────
1071
1094
  // Fallback
1072
1095
  // ───────────────────────────────────────────────────────────────────────
1096
+ /**
1097
+ * Claude Code built-ins. Their names (`TaskStop`, `CronCreate`, …) and raw
1098
+ * fields (`task_id: bkm34a6nc`) mean nothing on an approval card, so say what
1099
+ * the step does. Returns null for other tools.
1100
+ */
1101
+ function summarizeSessionTool(toolName, input) {
1102
+ const str = (v) => (typeof v === "string" && v.trim() ? v.trim() : undefined);
1103
+ switch (toolName) {
1104
+ case "TaskStop":
1105
+ case "KillShell":
1106
+ return {
1107
+ title: "Stop background task",
1108
+ target: str(input.task_id) ?? str(input.shell_id),
1109
+ footnote: "Only a task this session started",
1110
+ kind: "session_control",
1111
+ };
1112
+ case "EnterWorktree":
1113
+ return { title: "Create a git worktree for this session", target: str(input.name), kind: "worktree" };
1114
+ case "ExitWorktree":
1115
+ if (input.action !== "remove")
1116
+ return { title: "Leave worktree (keep it on disk)", kind: "worktree" };
1117
+ return input.discard_changes === true
1118
+ ? { title: "Delete worktree and discard its changes", footnote: "Uncommitted files and unmerged commits are lost", kind: "worktree" }
1119
+ : { title: "Delete worktree", footnote: "Refused if it has unsaved changes", kind: "worktree" };
1120
+ case "CronCreate": {
1121
+ const prompt = str(input.prompt);
1122
+ return {
1123
+ title: input.recurring === false ? "Schedule a one-time prompt" : "Schedule a recurring prompt",
1124
+ target: str(input.cron),
1125
+ body: prompt ? truncateBody(prompt) : undefined,
1126
+ kind: "schedule",
1127
+ };
1128
+ }
1129
+ case "CronDelete":
1130
+ return { title: "Delete scheduled prompt", target: str(input.id) ?? str(input.job_id), kind: "schedule" };
1131
+ case "SendMessage": {
1132
+ const message = str(input.message);
1133
+ return {
1134
+ title: str(input.to) ? `Send message to agent "${truncate(str(input.to), 40)}"` : "Send message to agent",
1135
+ body: message ? truncateBody(message) : undefined,
1136
+ kind: "agent_message",
1137
+ };
1138
+ }
1139
+ case "WebFetch": {
1140
+ const url = str(input.url);
1141
+ return { title: "Fetch web page", target: url ? truncate(url, 80) : undefined, kind: "web_fetch" };
1142
+ }
1143
+ case "Monitor": {
1144
+ const cmd = str(input.command);
1145
+ const ws = str(input.ws?.url);
1146
+ return {
1147
+ title: str(input.description) ? `Watch: ${truncate(str(input.description), 60)}` : "Start background watcher",
1148
+ target: ws ? truncate(ws, 80) : undefined,
1149
+ body: cmd ? truncateBody(cmd) : undefined,
1150
+ kind: "monitor",
1151
+ };
1152
+ }
1153
+ case "Artifact": {
1154
+ const action = str(input.action) ?? "publish";
1155
+ const target = str(input.url) ?? (str(input.file_path) ? shortenPath(str(input.file_path)) : undefined);
1156
+ if (action === "delete") {
1157
+ return { title: "Delete page from claude.ai", target, footnote: "The link stops working for everyone", kind: "artifact" };
1158
+ }
1159
+ if (action === "publish") {
1160
+ return {
1161
+ title: str(input.url) ? "Update page on claude.ai" : "Publish page to claude.ai",
1162
+ target,
1163
+ footnote: "Private to you until you share it",
1164
+ kind: "artifact",
1165
+ };
1166
+ }
1167
+ return { title: `${action.replace(/_/g, " ")} page on claude.ai`.replace(/^./, (c) => c.toUpperCase()), target, kind: "artifact" };
1168
+ }
1169
+ }
1170
+ return null;
1171
+ }
1073
1172
  function summarizeFallback(toolName, toolInput) {
1074
1173
  const keys = Object.keys(toolInput);
1075
1174
  if (!keys.length)
package/dist/kinds.d.ts CHANGED
@@ -7,4 +7,4 @@
7
7
  * classifier that produced them.
8
8
  */
9
9
  export declare const CLASSIFIER_VERSION = "v2";
10
- export type OperationKind = "file_create" | "file_append" | "file_edit" | "file_touch" | "file_copy" | "file_move" | "file_delete" | "sql_drop" | "sql_truncate" | "sql_alter" | "sql_create" | "sql_delete_rows" | "sql_delete_all_rows" | "sql_update_rows" | "sql_update_every_row" | "sql_insert" | "sql_query" | "git_push" | "git_force_push" | "git_reset_hard" | "git_clean" | "git_checkout" | "git_restore" | "git_commit" | "git_pr_create" | "ssh_remote" | "http_get" | "http_post" | "http_put" | "http_delete" | "http_pipe_to_shell" | "docker_up" | "docker_down" | "docker_rm" | "docker_rmi" | "docker_prune" | "npm_install" | "npm_run" | "npm_test" | "npm_publish" | "npm_unpublish" | "npx_deploy" | "kill_process" | "sudo" | "chmod_777" | "email_send" | "email_delete" | "email_purge" | "payment_charge" | "payment_create" | "chat_message" | "mcp_delete" | "mcp_update" | "mcp_create" | "mcp_post" | "mcp_publish" | "mcp_send" | "mcp_submit_form" | "mcp_fill" | "mcp_submit" | "mcp_query" | "browser_navigate" | "browser_interact" | "browser_script" | "browser_dev_server" | "folder_access" | "agent_launch" | "shell_pipeline" | "unknown_bash" | "unknown_tool";
10
+ export type OperationKind = "file_create" | "file_append" | "file_edit" | "file_touch" | "file_copy" | "file_move" | "file_delete" | "sql_drop" | "sql_truncate" | "sql_alter" | "sql_create" | "sql_delete_rows" | "sql_delete_all_rows" | "sql_update_rows" | "sql_update_every_row" | "sql_insert" | "sql_query" | "git_push" | "git_force_push" | "git_reset_hard" | "git_clean" | "git_checkout" | "git_restore" | "git_commit" | "git_pr_create" | "ssh_remote" | "http_get" | "http_post" | "http_put" | "http_delete" | "http_pipe_to_shell" | "docker_up" | "docker_down" | "docker_rm" | "docker_rmi" | "docker_prune" | "npm_install" | "npm_run" | "npm_test" | "npm_publish" | "npm_unpublish" | "npx_deploy" | "kill_process" | "sudo" | "chmod_777" | "email_send" | "email_delete" | "email_purge" | "payment_charge" | "payment_create" | "chat_message" | "mcp_delete" | "mcp_update" | "mcp_create" | "mcp_post" | "mcp_publish" | "mcp_send" | "mcp_submit_form" | "mcp_fill" | "mcp_submit" | "mcp_query" | "browser_navigate" | "browser_interact" | "browser_script" | "browser_dev_server" | "folder_access" | "session_control" | "worktree" | "schedule" | "agent_message" | "web_fetch" | "monitor" | "artifact" | "agent_launch" | "shell_pipeline" | "unknown_bash" | "unknown_tool";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oked/sdk",
3
- "version": "0.6.1",
3
+ "version": "0.6.3",
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.1"
48
+ "@oked/receipt-core": "0.6.3"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@types/node": "^22.13.10",