@haus-tech/haus-workflow 6.7.0 → 6.7.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## [6.7.1](https://github.com/WeAreHausTech/haus-workflow/compare/v6.7.0...v6.7.1) (2026-10-22)
4
+
5
+ ### Bug Fixes
6
+
7
+ - **guard:** let an agent drop a throwaway database on a local target ([#907](https://github.com/WeAreHausTech/haus-workflow/issues/907)) ([bb9a7f8](https://github.com/WeAreHausTech/haus-workflow/commit/bb9a7f8784e4743a5a13553af59b5ce1fd722a81)), closes [#905](https://github.com/WeAreHausTech/haus-workflow/issues/905)
8
+
3
9
  ## [6.7.0](https://github.com/WeAreHausTech/haus-workflow/compare/v6.6.0...v6.7.0) (2026-10-22)
4
10
 
5
11
  ### Features
package/dist/cli.js CHANGED
@@ -23760,12 +23760,153 @@ var PRIVILEGE_ESCALATORS = /* @__PURE__ */ new Set(["sudo", "doas", "pkexec"]);
23760
23760
  function isPrivilegeEscalation(words) {
23761
23761
  return PRIVILEGE_ESCALATORS.has(commandName(words));
23762
23762
  }
23763
- function isDestructiveSql(segment) {
23763
+ var DROP_DATABASE = "drop database";
23764
+ var THROWAWAY_DATABASE = /_tmp_|_verify$/;
23765
+ var DROP_STATEMENT = /^drop database (?:if exists )?(?:`([a-z0-9_]+)`|"([a-z0-9_]+)"|\[([a-z0-9_]+)\]|([a-z0-9_]+))(?: ?(?:with ?)?\( ?force ?\))?$/;
23766
+ var ATTACHED_OPTION = /^(?:--[a-z][a-z-]*=|-[a-z])/;
23767
+ var CONNINFO = /^(?:[a-z_]+ ?= ?\S+ ?)+$/;
23768
+ function sqlText(value) {
23769
+ return value.toLowerCase().replace(/\s+/g, " ").trim();
23770
+ }
23771
+ function countOf(text, phrase) {
23772
+ return text.split(phrase).length - 1;
23773
+ }
23774
+ function throwawayDrops(sql) {
23775
+ let drops = 0;
23776
+ for (const statement of sql.split(";")) {
23777
+ const text = statement.trim();
23778
+ if (text === "") continue;
23779
+ const name = DROP_STATEMENT.exec(text)?.slice(1).find((group) => group !== void 0);
23780
+ if (name === void 0 || !THROWAWAY_DATABASE.test(name)) return void 0;
23781
+ drops += 1;
23782
+ }
23783
+ return drops;
23784
+ }
23785
+ function dropsOnlyThrowawayDatabases(segment, text) {
23786
+ if (DESTRUCTIVE_SQL_PHRASES.some((phrase) => phrase !== DROP_DATABASE && text.includes(phrase))) {
23787
+ return false;
23788
+ }
23789
+ let drops = 0;
23790
+ for (const token of segment) {
23791
+ const value = sqlText(token.value);
23792
+ const holdsDrop = value.includes(DROP_DATABASE);
23793
+ if (!holdsDrop && !value.includes(" ")) continue;
23794
+ const sql = value.replace(ATTACHED_OPTION, "").trim();
23795
+ if (!holdsDrop && CONNINFO.test(sql)) continue;
23796
+ const count = throwawayDrops(sql);
23797
+ if (count === void 0) return false;
23798
+ drops += count;
23799
+ }
23800
+ return drops === countOf(text, DROP_DATABASE);
23801
+ }
23802
+ var TARGET_VARIABLE = /(?:^|[^a-z0-9_]|-e)(?:pghost|pghostaddr|pgservice|pgservicefile|mysql_host|mysql_home|mysql_test_login_file|docker_host|docker_context|docker_config|container_host|container_connection|cockroach_host|cockroach_url|clickhouse_host|database_url)=/i;
23803
+ var CONNINFO_TARGET = /(host|hostaddr|service)\s*=\s*([^\s&]*)/gi;
23804
+ var HIDDEN_TARGET_OPTIONS = [
23805
+ "--defaults-file",
23806
+ "--defaults-extra-file",
23807
+ "--defaults-group-suffix",
23808
+ "--login-path"
23809
+ ];
23810
+ var UNREAD_SQL_OPTIONS = ["--file", "--queries-file", "--init-command"];
23811
+ var UNTARGETED_VALUE_OPTIONS = /* @__PURE__ */ new Set(["-u", "-U", "-p", "-P", "--user", "--username", "--port"]);
23812
+ var UNTARGETED_LONG_OPTIONS = /* @__PURE__ */ new Set(["--user", "--username", "--password", "--port"]);
23813
+ var REMOTE_ENGINE_OPTIONS = ["--host", "--context", "--connection", "--url"];
23814
+ var REMOTE_ENGINE_SHORT = /^-[A-Za-z]*[Hc]/;
23815
+ var CONTAINER_RUNNERS = /* @__PURE__ */ new Set(["docker", "podman", "docker-compose"]);
23816
+ var EXEC_VALUE_OPTIONS = /* @__PURE__ */ new Set([
23817
+ "-e",
23818
+ "--env",
23819
+ "-u",
23820
+ "--user",
23821
+ "-w",
23822
+ "--workdir",
23823
+ "--detach-keys",
23824
+ "--index",
23825
+ "--preserve-fds"
23826
+ ]);
23827
+ function isLocalHost(host) {
23828
+ const bare = host.replace(/^\[|\]$/g, "").toLowerCase();
23829
+ return bare === "localhost" || bare === "127.0.0.1" || bare === "::1" || bare.startsWith("/");
23830
+ }
23831
+ function isLocalUri(word) {
23832
+ try {
23833
+ return isLocalHost(new URL(word).hostname);
23834
+ } catch {
23835
+ return false;
23836
+ }
23837
+ }
23838
+ function isFlag(word, flag) {
23839
+ return word === flag || word.startsWith(`${flag}=`);
23840
+ }
23841
+ function isComputed(word) {
23842
+ return word.includes("$");
23843
+ }
23844
+ function longOptionName(word) {
23845
+ if (!word.startsWith("--") || word.length < 3) return void 0;
23846
+ return word.split("=", 1)[0].replace(/_/g, "-");
23847
+ }
23848
+ function abbreviates(name, option, shortest = 5) {
23849
+ return name !== void 0 && name.length >= shortest && option.startsWith(name);
23850
+ }
23851
+ function localClientArguments(words) {
23852
+ const first = commandBaseName(words[0] ?? "");
23853
+ if (SQL_CLIENTS.has(first)) return words.slice(1);
23854
+ if (!CONTAINER_RUNNERS.has(first)) return void 0;
23855
+ const execAt = words.indexOf("exec");
23856
+ if (execAt === -1) return void 0;
23857
+ const engine = words.slice(1, execAt);
23858
+ const remote = (word) => isComputed(word) || REMOTE_ENGINE_SHORT.test(word) || REMOTE_ENGINE_OPTIONS.some((option) => isFlag(word, option));
23859
+ if (engine.some(remote)) return void 0;
23860
+ let at = execAt + 1;
23861
+ while (at < words.length && words[at].startsWith("-")) {
23862
+ if (isFlag(words[at], "--env-file")) return void 0;
23863
+ at += EXEC_VALUE_OPTIONS.has(words[at]) ? 2 : 1;
23864
+ }
23865
+ const client = words[at + 1];
23866
+ if (client === void 0 || !SQL_CLIENTS.has(commandBaseName(client))) return void 0;
23867
+ return words.slice(at + 2);
23868
+ }
23869
+ function namesOnlyLocalHosts(segment, args) {
23870
+ for (const { value } of segment) {
23871
+ if (value.includes("://") && !isLocalUri(value)) return false;
23872
+ for (const [, key, host] of value.matchAll(CONNINFO_TARGET)) {
23873
+ if (key.toLowerCase() === "service" || !isLocalHost(host)) return false;
23874
+ }
23875
+ }
23876
+ for (let i = 0; i < args.length; i += 1) {
23877
+ const word = args[i];
23878
+ const long = longOptionName(word);
23879
+ if (HIDDEN_TARGET_OPTIONS.some((option) => abbreviates(long, option))) return false;
23880
+ if (UNREAD_SQL_OPTIONS.some((option) => abbreviates(long, option, 4))) return false;
23881
+ if (word === "-f" || /^-f./.test(word)) return false;
23882
+ if (isComputed(word) && !/^-[uUpP]./.test(word) && !(long !== void 0 && UNTARGETED_LONG_OPTIONS.has(long) && word.includes("=")) && !UNTARGETED_VALUE_OPTIONS.has(args[i - 1] ?? "")) {
23883
+ return false;
23884
+ }
23885
+ if (abbreviates(long, "--host", 4)) {
23886
+ const eq = word.indexOf("=");
23887
+ const host = eq === -1 ? args[i += 1] : word.slice(eq + 1);
23888
+ if (!isLocalHost(host ?? "")) return false;
23889
+ } else if (word === "-h") {
23890
+ if (!isLocalHost(args[i += 1] ?? "")) return false;
23891
+ } else if (/^-h./.test(word)) {
23892
+ if (!isLocalHost(word.slice(2))) return false;
23893
+ }
23894
+ }
23895
+ return true;
23896
+ }
23897
+ function isThrowawayLocalDrop(segment, text, whole) {
23898
+ if (TARGET_VARIABLE.test(whole)) return false;
23899
+ if (!dropsOnlyThrowawayDatabases(segment, text)) return false;
23900
+ const args = localClientArguments(commandWords(segment));
23901
+ return args !== void 0 && namesOnlyLocalHosts(segment, args);
23902
+ }
23903
+ function isDestructiveSql(segment, whole) {
23764
23904
  const words = commandWords(segment);
23765
23905
  if (words.length === 0) return false;
23766
23906
  if (words.some((word) => SQL_CLIENTS.has(commandBaseName(word)))) {
23767
- const text = segment.map((token) => token.value).join(" ").toLowerCase().replace(/\s+/g, " ");
23768
- return DESTRUCTIVE_SQL_PHRASES.some((phrase) => text.includes(phrase));
23907
+ const text = sqlText(segment.map((token) => token.value).join(" "));
23908
+ if (!DESTRUCTIVE_SQL_PHRASES.some((phrase) => text.includes(phrase))) return false;
23909
+ return !isThrowawayLocalDrop(segment, text, whole);
23769
23910
  }
23770
23911
  const spoken = words.join(" ").toLowerCase();
23771
23912
  return DESTRUCTIVE_SQL_PHRASES.some((phrase) => spoken.startsWith(phrase));
@@ -23877,7 +24018,7 @@ function isUngatedMergeChainIn(commands, depth2) {
23877
24018
  }
23878
24019
  var NESTING_TOO_DEEP = "a command that nests shells deeper than the guard reads";
23879
24020
  var NESTING_CAP = 3;
23880
- function matchDangerousCommandShape(command, depth2 = 0) {
24021
+ function matchDangerousCommandShape(command, depth2 = 0, whole = command) {
23881
24022
  if (isUngatedMergeChain(command)) return UNGATED_MERGE_CHAIN;
23882
24023
  const commands = parseShellCommandReadings(stripHarmlessRedirects(command)).flatMap(
23883
24024
  (reading) => joinSubstitutions(reading)
@@ -23888,14 +24029,14 @@ function matchDangerousCommandShape(command, depth2 = 0) {
23888
24029
  const nested = nestedCommandString(rawCommandWords(reading));
23889
24030
  if (nested !== void 0) {
23890
24031
  if (depth2 >= NESTING_CAP) return NESTING_TOO_DEEP;
23891
- const verdict = matchDangerousCommandShape(nested, depth2 + 1);
24032
+ const verdict = matchDangerousCommandShape(nested, depth2 + 1, whole);
23892
24033
  if (verdict) return verdict;
23893
24034
  }
23894
24035
  const words = commandWords(reading);
23895
24036
  if (words.length === 0) continue;
23896
24037
  const matched = SEGMENT_MATCHERS.find((matcher) => matcher.matches(words));
23897
24038
  if (matched) return matched.name;
23898
- if (isDestructiveSql(reading)) return "a destructive database statement";
24039
+ if (isDestructiveSql(reading, whole)) return "a destructive database statement";
23899
24040
  }
23900
24041
  }
23901
24042
  return void 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haus-tech/haus-workflow",
3
- "version": "6.7.0",
3
+ "version": "6.7.1",
4
4
  "description": "Haus AI workflow CLI for Claude Code.",
5
5
  "type": "module",
6
6
  "bin": {