@hasna/hooks 0.13.1 → 0.13.2

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/bin/serve.js CHANGED
@@ -731,7 +731,7 @@ function getHook(name) {
731
731
  import { existsSync as existsSync2, mkdirSync, readFileSync, readdirSync, realpathSync, writeFileSync } from "fs";
732
732
  import { basename, dirname, isAbsolute, join as join3, normalize, resolve as resolve2, sep } from "path";
733
733
 
734
- // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/external.js
734
+ // ../../../../../../home/hasna/.hasna/scratchpad/scratch/baf4a176-62b7-49a5-aab3-8dcbe08e5fc2/apps-copy/node_modules/.bun/zod@3.25.76/node_modules/zod/v3/external.js
735
735
  var exports_external = {};
736
736
  __export(exports_external, {
737
737
  void: () => voidType,
@@ -843,7 +843,7 @@ __export(exports_external, {
843
843
  BRAND: () => BRAND
844
844
  });
845
845
 
846
- // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/helpers/util.js
846
+ // ../../../../../../home/hasna/.hasna/scratchpad/scratch/baf4a176-62b7-49a5-aab3-8dcbe08e5fc2/apps-copy/node_modules/.bun/zod@3.25.76/node_modules/zod/v3/helpers/util.js
847
847
  var util;
848
848
  (function(util2) {
849
849
  util2.assertEqual = (_) => {};
@@ -974,7 +974,7 @@ var getParsedType = (data) => {
974
974
  }
975
975
  };
976
976
 
977
- // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/ZodError.js
977
+ // ../../../../../../home/hasna/.hasna/scratchpad/scratch/baf4a176-62b7-49a5-aab3-8dcbe08e5fc2/apps-copy/node_modules/.bun/zod@3.25.76/node_modules/zod/v3/ZodError.js
978
978
  var ZodIssueCode = util.arrayToEnum([
979
979
  "invalid_type",
980
980
  "invalid_literal",
@@ -1093,7 +1093,7 @@ ZodError.create = (issues) => {
1093
1093
  return error;
1094
1094
  };
1095
1095
 
1096
- // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/locales/en.js
1096
+ // ../../../../../../home/hasna/.hasna/scratchpad/scratch/baf4a176-62b7-49a5-aab3-8dcbe08e5fc2/apps-copy/node_modules/.bun/zod@3.25.76/node_modules/zod/v3/locales/en.js
1097
1097
  var errorMap = (issue, _ctx) => {
1098
1098
  let message;
1099
1099
  switch (issue.code) {
@@ -1196,7 +1196,7 @@ var errorMap = (issue, _ctx) => {
1196
1196
  };
1197
1197
  var en_default = errorMap;
1198
1198
 
1199
- // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/errors.js
1199
+ // ../../../../../../home/hasna/.hasna/scratchpad/scratch/baf4a176-62b7-49a5-aab3-8dcbe08e5fc2/apps-copy/node_modules/.bun/zod@3.25.76/node_modules/zod/v3/errors.js
1200
1200
  var overrideErrorMap = en_default;
1201
1201
  function setErrorMap(map) {
1202
1202
  overrideErrorMap = map;
@@ -1204,7 +1204,7 @@ function setErrorMap(map) {
1204
1204
  function getErrorMap() {
1205
1205
  return overrideErrorMap;
1206
1206
  }
1207
- // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/helpers/parseUtil.js
1207
+ // ../../../../../../home/hasna/.hasna/scratchpad/scratch/baf4a176-62b7-49a5-aab3-8dcbe08e5fc2/apps-copy/node_modules/.bun/zod@3.25.76/node_modules/zod/v3/helpers/parseUtil.js
1208
1208
  var makeIssue = (params) => {
1209
1209
  const { data, path, errorMaps, issueData } = params;
1210
1210
  const fullPath = [...path, ...issueData.path || []];
@@ -1310,14 +1310,14 @@ var isAborted = (x) => x.status === "aborted";
1310
1310
  var isDirty = (x) => x.status === "dirty";
1311
1311
  var isValid = (x) => x.status === "valid";
1312
1312
  var isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
1313
- // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/helpers/errorUtil.js
1313
+ // ../../../../../../home/hasna/.hasna/scratchpad/scratch/baf4a176-62b7-49a5-aab3-8dcbe08e5fc2/apps-copy/node_modules/.bun/zod@3.25.76/node_modules/zod/v3/helpers/errorUtil.js
1314
1314
  var errorUtil;
1315
1315
  (function(errorUtil2) {
1316
1316
  errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
1317
1317
  errorUtil2.toString = (message) => typeof message === "string" ? message : message?.message;
1318
1318
  })(errorUtil || (errorUtil = {}));
1319
1319
 
1320
- // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/types.js
1320
+ // ../../../../../../home/hasna/.hasna/scratchpad/scratch/baf4a176-62b7-49a5-aab3-8dcbe08e5fc2/apps-copy/node_modules/.bun/zod@3.25.76/node_modules/zod/v3/types.js
1321
1321
  class ParseInputLazyPath {
1322
1322
  constructor(parent, value, path, key) {
1323
1323
  this._cachedPath = [];
package/dist/index.js CHANGED
@@ -581,7 +581,7 @@ var init_redact = __esm(() => {
581
581
  ];
582
582
  });
583
583
 
584
- // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/helpers/util.js
584
+ // ../../../../../../home/hasna/.hasna/scratchpad/scratch/baf4a176-62b7-49a5-aab3-8dcbe08e5fc2/apps-copy/node_modules/.bun/zod@3.25.76/node_modules/zod/v3/helpers/util.js
585
585
  var util, objectUtil, ZodParsedType, getParsedType = (data) => {
586
586
  const t = typeof data;
587
587
  switch (t) {
@@ -712,7 +712,7 @@ var init_util = __esm(() => {
712
712
  ]);
713
713
  });
714
714
 
715
- // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/ZodError.js
715
+ // ../../../../../../home/hasna/.hasna/scratchpad/scratch/baf4a176-62b7-49a5-aab3-8dcbe08e5fc2/apps-copy/node_modules/.bun/zod@3.25.76/node_modules/zod/v3/ZodError.js
716
716
  var ZodIssueCode, quotelessJson = (obj) => {
717
717
  const json = JSON.stringify(obj, null, 2);
718
718
  return json.replace(/"([^"]+)":/g, "$1:");
@@ -833,7 +833,7 @@ var init_ZodError = __esm(() => {
833
833
  };
834
834
  });
835
835
 
836
- // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/locales/en.js
836
+ // ../../../../../../home/hasna/.hasna/scratchpad/scratch/baf4a176-62b7-49a5-aab3-8dcbe08e5fc2/apps-copy/node_modules/.bun/zod@3.25.76/node_modules/zod/v3/locales/en.js
837
837
  var errorMap = (issue, _ctx) => {
838
838
  let message;
839
839
  switch (issue.code) {
@@ -940,7 +940,7 @@ var init_en = __esm(() => {
940
940
  en_default = errorMap;
941
941
  });
942
942
 
943
- // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/errors.js
943
+ // ../../../../../../home/hasna/.hasna/scratchpad/scratch/baf4a176-62b7-49a5-aab3-8dcbe08e5fc2/apps-copy/node_modules/.bun/zod@3.25.76/node_modules/zod/v3/errors.js
944
944
  function setErrorMap(map) {
945
945
  overrideErrorMap = map;
946
946
  }
@@ -953,7 +953,7 @@ var init_errors = __esm(() => {
953
953
  overrideErrorMap = en_default;
954
954
  });
955
955
 
956
- // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/helpers/parseUtil.js
956
+ // ../../../../../../home/hasna/.hasna/scratchpad/scratch/baf4a176-62b7-49a5-aab3-8dcbe08e5fc2/apps-copy/node_modules/.bun/zod@3.25.76/node_modules/zod/v3/helpers/parseUtil.js
957
957
  function addIssueToContext(ctx, issueData) {
958
958
  const overrideMap = getErrorMap();
959
959
  const issue = makeIssue({
@@ -1058,10 +1058,10 @@ var init_parseUtil = __esm(() => {
1058
1058
  });
1059
1059
  });
1060
1060
 
1061
- // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/helpers/typeAliases.js
1061
+ // ../../../../../../home/hasna/.hasna/scratchpad/scratch/baf4a176-62b7-49a5-aab3-8dcbe08e5fc2/apps-copy/node_modules/.bun/zod@3.25.76/node_modules/zod/v3/helpers/typeAliases.js
1062
1062
  var init_typeAliases = () => {};
1063
1063
 
1064
- // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/helpers/errorUtil.js
1064
+ // ../../../../../../home/hasna/.hasna/scratchpad/scratch/baf4a176-62b7-49a5-aab3-8dcbe08e5fc2/apps-copy/node_modules/.bun/zod@3.25.76/node_modules/zod/v3/helpers/errorUtil.js
1065
1065
  var errorUtil;
1066
1066
  var init_errorUtil = __esm(() => {
1067
1067
  (function(errorUtil2) {
@@ -1070,7 +1070,7 @@ var init_errorUtil = __esm(() => {
1070
1070
  })(errorUtil || (errorUtil = {}));
1071
1071
  });
1072
1072
 
1073
- // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/types.js
1073
+ // ../../../../../../home/hasna/.hasna/scratchpad/scratch/baf4a176-62b7-49a5-aab3-8dcbe08e5fc2/apps-copy/node_modules/.bun/zod@3.25.76/node_modules/zod/v3/types.js
1074
1074
  class ParseInputLazyPath {
1075
1075
  constructor(parent, value, path, key) {
1076
1076
  this._cachedPath = [];
@@ -4421,7 +4421,7 @@ var init_types = __esm(() => {
4421
4421
  NEVER = INVALID;
4422
4422
  });
4423
4423
 
4424
- // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/external.js
4424
+ // ../../../../../../home/hasna/.hasna/scratchpad/scratch/baf4a176-62b7-49a5-aab3-8dcbe08e5fc2/apps-copy/node_modules/.bun/zod@3.25.76/node_modules/zod/v3/external.js
4425
4425
  var exports_external = {};
4426
4426
  __export(exports_external, {
4427
4427
  void: () => voidType,
@@ -4541,7 +4541,7 @@ var init_external = __esm(() => {
4541
4541
  init_ZodError();
4542
4542
  });
4543
4543
 
4544
- // ../../node_modules/.bun/zod@3.25.76/node_modules/zod/index.js
4544
+ // ../../../../../../home/hasna/.hasna/scratchpad/scratch/baf4a176-62b7-49a5-aab3-8dcbe08e5fc2/apps-copy/node_modules/.bun/zod@3.25.76/node_modules/zod/index.js
4545
4545
  var init_zod = __esm(() => {
4546
4546
  init_external();
4547
4547
  init_external();
@@ -8891,7 +8891,7 @@ import { existsSync as existsSync11, lstatSync as lstatSync9 } from "fs";
8891
8891
  import { homedir as homedir7 } from "os";
8892
8892
  import { join as join17, resolve as resolve9 } from "path";
8893
8893
 
8894
- // ../../node_modules/.bun/@hasna+skills@0.10.78+a00d3064559565bb/node_modules/@hasna/skills/dist/index.js
8894
+ // ../../../../../../home/hasna/.hasna/scratchpad/scratch/baf4a176-62b7-49a5-aab3-8dcbe08e5fc2/apps-copy/node_modules/.bun/@hasna+skills@0.10.78+a00d3064559565bb/node_modules/@hasna/skills/dist/index.js
8895
8895
  import { existsSync as existsSync10 } from "fs";
8896
8896
  import { homedir as homedir6 } from "os";
8897
8897
  import { join as join11, resolve as resolve4 } from "path";
@@ -78,6 +78,8 @@ export type ProgramKind = "c-interp" | "awk" | "shell";
78
78
  export interface EmbeddedProgram {
79
79
  text: string;
80
80
  kind: ProgramKind;
81
+ /** The language of a `c-interp` program that has a reader of its own. */
82
+ language?: "python";
81
83
  }
82
84
 
83
85
  export interface ExecutorFinding {
@@ -152,23 +154,105 @@ const SSH_LOCAL_EXEC_OPTS = new Set(["proxycommand", "localcommand", "knownhosts
152
154
  const C_INTERP_DANGER = /(?:`|\$\()|\b(?:system|exec|execve|execvp|popen|spawn|posix_spawn|fork|subprocess|Popen|check_output|check_call|shell_exec|passthru|proc_open|pcntl_exec|qx|open|fopen|sysopen|unlink|remove|delete|rmtree|rmdir|mkdir|rename|truncate|ftruncate|chmod|chown|symlink|writeFile|createWriteStream|appendFile|child_process|FileUtils|shutil|Kernel|require|import|load|eval|os|sys|io|fs|File|IO|Dir|Path|pathlib|Deno|Bun)|%x\W/;
153
155
 
154
156
  /**
155
- * awk danger: `system()` or a pipe/redirect (`| "cmd"`, `print > "file"`), a
156
- * `getline` from a command or file, `close`/`fflush` on a stream, or a delete
157
- * verb. `>`/`|` are awk redirection/pipe operators, so a program using them is
158
- * not provably read-only (a bare comparison `$1 > 5` reads only, but is refused
159
- * here under a protected root — fail closed, in class).
157
+ * awk danger: `system`, `getline`, `close` and `fflush` in any use, matched
158
+ * anywhere, since awk reads `1system("x")` as a call; and
159
+ * a gawk `@` before anything but `@` or `/`: an indirect call (`@f()`, `@ f()`)
160
+ * can reach `system` by a name built from strings, and `@load` or `@include`
161
+ * brings in other code. `/^@@/` stays text.
160
162
  */
161
- const AWK_DANGER = /[|>]|\b(?:system|getline|close|fflush|print\w*\s*>>?)/;
163
+ const AWK_DANGER = /system|getline|close|fflush|@(?![@/])/;
164
+
165
+ /**
166
+ * Whether an awk program can only read. Output leaves it only through a `print`
167
+ * or `printf`, and a redirection follows its statement, so a `>` or `|` before
168
+ * the first print is an operator or a pattern. Past it, even a `>` in a string
169
+ * fails, because telling a string from a regexp or a comment takes a parser. A
170
+ * line continuation (awks differ on it) anywhere fails once a `>` or `|` is
171
+ * present.
172
+ */
173
+ function awkProgramIsReadOnly(program: string): boolean {
174
+ if (AWK_DANGER.test(program)) return false;
175
+ if (!/[|>]/.test(program)) return true;
176
+ if (/\\\r?\n/.test(program)) return false;
177
+ const print = program.search(/print/);
178
+ return print < 0 || !/[|>]/.test(program.slice(print));
179
+ }
180
+
181
+ /**
182
+ * A `.` followed by anything but reading in `json` and `sys`, or a method of a
183
+ * string, a container or a file. `write` fails on any file `open` may produce
184
+ * here. Nothing listed reaches a module, a code object or a buffer; what isn't
185
+ * listed is refused, which is why this can't go stale the way a list of dangers
186
+ * does. A `case` class pattern reads attributes with no `.`, so PYTHON_UNSAFE
187
+ * refuses `case`, and a string can't hide it (see pythonCode).
188
+ */
189
+ const PYTHON_UNLISTED_ATTRIBUTE = /\.\s*(?!(?:argv|std(?:in|out|err)|exit|write|loads?|dumps?|strip|split(?:lines)?|join|replace|(?:start|end)swith|lower|find|count|get|items|keys|values|append|sort|read)\b)[a-zA-Z_]/;
190
+
191
+ /**
192
+ * Only a builtin gives a bare name power: the only modules let in are `json`
193
+ * and `sys`, and their attributes are reached through a `.`, which
194
+ * PYTHON_UNLISTED_ATTRIBUTE checks. Refused here: the builtins that run code or
195
+ * return live objects (any name ending in `attr` among them), `case`, whose
196
+ * class pattern reads attributes with no `.`, and every name that starts with
197
+ * `_`, a lone `_` included. A name is refused even when assigned to, since
198
+ * `exec=exec` keeps the function.
199
+ */
200
+ const PYTHON_UNSAFE = /(?<![\w.])(?:breakpoint|case|compile|\w*attr|eval|exec|globals|help|locals|type|vars)\b|(?<!\w)_/;
201
+
202
+ /**
203
+ * A python program as python reads it, with comments gone and every string out
204
+ * of the way. A string made only of `r`, `b` and `t` may be a read mode, so it
205
+ * stays visible as `~`; every other string becomes `%`. Three quotes always open
206
+ * a triple-quoted string, as in python: `''''` is never read as two empty
207
+ * strings, so one left open stays a bare quote. A word is a token of its own, so
208
+ * only up to two of python's prefix letters (`r`, `b`, `u`, `f`, `t`) can be a
209
+ * string prefix and the end of a name can't: `case'x'` reads as `case%` and
210
+ * `if'x'` as `if%`, as python reads them. An `f` or `t` string holds code, so
211
+ * its fields stay. If a field holds a brace (it may hide a nested string) or a
212
+ * `#` (python 3.12 reads a comment there, and a `}` in it doesn't close the
213
+ * field), the whole string comes back as a bare quote. A backslash outside a string is a token of its
214
+ * own, so that an escaped quote can't open a string and scan to the end of the
215
+ * program each time; it stays in the result, and a backslash there is refused.
216
+ */
217
+ function pythonCode(source: string): string {
218
+ return source.replace(/#.*|\\[^]|([rRbBuUfFtT]{0,2})("""|'''|(["'])(?!\3\3))((?:\\[^]|(?!\2)[^\\])*)\2|\w+/g, (whole, prefix: string, fence, _, text: string) => {
219
+ if (!fence) return whole[0] === "#" ? "" : whole;
220
+ if (!/[ft]/i.test(prefix)) return /^[rbt]+$/.test(text) ? "~" : "%";
221
+ let fields = "";
222
+ const rest = text.replace(/\{\{|\}\}|\{([^{}#]*)\}/g, (_, field = "") => ((fields += `${pythonCode(field)},`), ""));
223
+ return /[{}]/.test(rest) ? "'" : `(${fields})`;
224
+ });
225
+ }
226
+
227
+ /**
228
+ * Whether an inline python program is provably read-only: a backtick or `$(`
229
+ * is refused, as is what can't be read as code (a leftover quote or backslash,
230
+ * or any non-ASCII character), nothing unsafe may be named, a statement may import only
231
+ * `json` and `sys`, `open` must read one plain path, and nothing unlisted may be
232
+ * reached through a `.`. A program over 8,192 characters is refused unread:
233
+ * past about 16,000 the scanner's regex slows sharply on an unclosed string.
234
+ */
235
+ function pythonProgramIsReadOnly(program: string): boolean {
236
+ if (program.length > 8192 || /`|\$\(/.test(program)) return false;
237
+ const code = pythonCode(program);
238
+ if (/['"\\]|[^\0-\x7f]/.test(code) || PYTHON_UNSAFE.test(code)) return false;
239
+ if (/\b(?:import|from)\b/.test(code.replace(/\bimport\s+(?:json|sys)(?:\s*,\s*(?:json|sys))*(?=\s*(?:;|$))/gm, ""))) return false;
240
+ if (/\bopen\b/.test(code.replace(/\bopen\([\w.[\]%]+(?:,\s*(?:mode=)?~)?(?:,\s*encoding=%)?\)/g, ""))) return false;
241
+ return !PYTHON_UNLISTED_ATTRIBUTE.test(code);
242
+ }
162
243
 
163
244
  /**
164
245
  * Whether an embedded program is provably read-only for its grammar. A `shell`
165
246
  * value is judged by the caller with its own command classifier (it is a shell
166
- * command); only `c-interp` and `awk` are judged here.
247
+ * command); only `c-interp` and `awk` are judged here. After the delete-verb
248
+ * check, Python 3 is judged by its allow-list in place of the danger words,
249
+ * since a program naming no danger word can still reach a debugger or a dunder
250
+ * chain.
167
251
  */
168
252
  export function embeddedProgramIsReadOnly(program: EmbeddedProgram): boolean {
169
253
  if (mentionsDeleteVerb(program.text)) return false;
170
- if (program.kind === "awk") return !AWK_DANGER.test(program.text);
171
- if (program.kind === "c-interp") return !C_INTERP_DANGER.test(program.text);
254
+ if (program.kind === "awk") return awkProgramIsReadOnly(program.text);
255
+ if (program.kind === "c-interp") return program.language === "python" ? pythonProgramIsReadOnly(program.text) : !C_INTERP_DANGER.test(program.text);
172
256
  // shell: never decided here.
173
257
  return false;
174
258
  }
@@ -177,11 +261,12 @@ export function embeddedProgramIsReadOnly(program: EmbeddedProgram): boolean {
177
261
  function interpPrograms(name: string, words: string[], index: number, opaque: (at: number) => boolean): ExecutorFinding | null {
178
262
  const spec = INTERP_PROGRAM_FLAGS[name] ?? (VERSIONED_INTERP.test(name) ? INTERP_PROGRAM_FLAGS[name.replace(/[0-9.]+$/, "")] : undefined);
179
263
  if (!spec) return null;
264
+ const inline = (text: string): EmbeddedProgram => (name.startsWith("python3") ? { text, kind: "c-interp", language: "python" } : { text, kind: "c-interp" });
180
265
  const programs: EmbeddedProgram[] = [];
181
266
  let unresolved = false;
182
267
  const takeNext = (at: number): number => {
183
268
  if (at + 1 >= words.length || opaque(at + 1)) { unresolved = true; return at; }
184
- programs.push({ text: words[at + 1], kind: "c-interp" });
269
+ programs.push(inline(words[at + 1]));
185
270
  return at + 1;
186
271
  };
187
272
  for (let at = index + 1; at < words.length; at++) {
@@ -193,7 +278,7 @@ function interpPrograms(name: string, words: string[], index: number, opaque: (a
193
278
  const eq = word.indexOf("=");
194
279
  const longName = eq < 0 ? word : word.slice(0, eq);
195
280
  if (spec.long.has(longName)) {
196
- if (eq >= 0) programs.push({ text: word.slice(eq + 1), kind: "c-interp" });
281
+ if (eq >= 0) programs.push(inline(word.slice(eq + 1)));
197
282
  else at = takeNext(at);
198
283
  }
199
284
  continue;
@@ -203,7 +288,7 @@ function interpPrograms(name: string, words: string[], index: number, opaque: (a
203
288
  const cluster = word.slice(1);
204
289
  for (let i = 0; i < cluster.length; i++) {
205
290
  if (!spec.letters.has(cluster[i])) continue;
206
- if (i < cluster.length - 1) programs.push({ text: cluster.slice(i + 1), kind: "c-interp" });
291
+ if (i < cluster.length - 1) programs.push(inline(cluster.slice(i + 1)));
207
292
  else at = takeNext(at);
208
293
  break;
209
294
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hasna/hooks",
3
- "version": "0.13.1",
3
+ "version": "0.13.2",
4
4
  "description": "Open source hooks library for AI coding agents - Install safety, quality, and automation hooks with a single command",
5
5
  "type": "module",
6
6
  "bin": {