@stigmer/zip-structure 0.3.0 → 0.3.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.
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Whether an archive entry is a script a command may run directly: the one
3
+ * rule every reader of a pushed archive applies to the executable bit.
4
+ *
5
+ * A ZIP's mode bits are not trusted (most writers leave them unset, and a
6
+ * pushed archive's entries are judged by name and bytes alone), so the bit
7
+ * is inferred: a script extension, or a file that opens with `#!`. Claude
8
+ * Code plugins run extensionless scripts directly (`hooks/check`,
9
+ * `bin/tool`), so the shebang is the signal that matters for them; skills
10
+ * gain it too.
11
+ *
12
+ * Shared because two processes must agree on it byte for byte: the
13
+ * runner, which writes a skill's or plugin's tree with these modes
14
+ * (`runner` `shared/archive-mount.ts`), and the server, whose table of an
15
+ * archive's files tells a reader which files are executable
16
+ * (`stigmer-server` `archive/file-index.ts`). A file listed one way and
17
+ * written another would change what a command can run.
18
+ *
19
+ * The one piece of policy in this otherwise structural library, kept here
20
+ * because both consumers already depend on it and nothing else does.
21
+ */
22
+ /** Whether the entry at `path` with these bytes is executable. */
23
+ export declare function isExecutableEntry(path: string, content: Uint8Array): boolean;
24
+ /** The mode an entry is written with: 0755 for an executable entry, 0644 otherwise. */
25
+ export declare function entryFileMode(path: string, content: Uint8Array): number;
26
+ //# sourceMappingURL=entry-mode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entry-mode.d.ts","sourceRoot":"","sources":["src/entry-mode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAUH,kEAAkE;AAClE,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,GAAG,OAAO,CAG5E;AAED,uFAAuF;AACvF,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,GAAG,MAAM,CAEvE"}
package/entry-mode.js ADDED
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Whether an archive entry is a script a command may run directly: the one
3
+ * rule every reader of a pushed archive applies to the executable bit.
4
+ *
5
+ * A ZIP's mode bits are not trusted (most writers leave them unset, and a
6
+ * pushed archive's entries are judged by name and bytes alone), so the bit
7
+ * is inferred: a script extension, or a file that opens with `#!`. Claude
8
+ * Code plugins run extensionless scripts directly (`hooks/check`,
9
+ * `bin/tool`), so the shebang is the signal that matters for them; skills
10
+ * gain it too.
11
+ *
12
+ * Shared because two processes must agree on it byte for byte: the
13
+ * runner, which writes a skill's or plugin's tree with these modes
14
+ * (`runner` `shared/archive-mount.ts`), and the server, whose table of an
15
+ * archive's files tells a reader which files are executable
16
+ * (`stigmer-server` `archive/file-index.ts`). A file listed one way and
17
+ * written another would change what a command can run.
18
+ *
19
+ * The one piece of policy in this otherwise structural library, kept here
20
+ * because both consumers already depend on it and nothing else does.
21
+ */
22
+ import { extname } from "node:path/posix";
23
+ /** Extensions read as executable whatever their first bytes say. */
24
+ const SCRIPT_EXTENSIONS = new Set([".sh", ".py", ".js", ".ts", ".rb", ".pl"]);
25
+ /** `#!`, the two bytes that make a file runnable as `./file`. */
26
+ const SHEBANG = [0x23, 0x21];
27
+ /** Whether the entry at `path` with these bytes is executable. */
28
+ export function isExecutableEntry(path, content) {
29
+ const shebang = content.length >= 2 && content[0] === SHEBANG[0] && content[1] === SHEBANG[1];
30
+ return shebang || SCRIPT_EXTENSIONS.has(extname(path));
31
+ }
32
+ /** The mode an entry is written with: 0755 for an executable entry, 0644 otherwise. */
33
+ export function entryFileMode(path, content) {
34
+ return isExecutableEntry(path, content) ? 0o755 : 0o644;
35
+ }
36
+ //# sourceMappingURL=entry-mode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entry-mode.js","sourceRoot":"","sources":["src/entry-mode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE1C,oEAAoE;AACpE,MAAM,iBAAiB,GAAwB,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;AAEnG,iEAAiE;AACjE,MAAM,OAAO,GAAG,CAAC,IAAI,EAAE,IAAI,CAAU,CAAC;AAEtC,kEAAkE;AAClE,MAAM,UAAU,iBAAiB,CAAC,IAAY,EAAE,OAAmB;IACjE,MAAM,OAAO,GAAG,OAAO,CAAC,MAAM,IAAI,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;IAC9F,OAAO,OAAO,IAAI,iBAAiB,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;AACzD,CAAC;AAED,uFAAuF;AACvF,MAAM,UAAU,aAAa,CAAC,IAAY,EAAE,OAAmB;IAC7D,OAAO,iBAAiB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;AAC1D,CAAC"}
package/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export { EOCD_MIN_SIZE, crc32, parseZipStructure, type ZipStructuralEntry, } from "./zip-structure.js";
2
+ export { entryFileMode, isExecutableEntry } from "./entry-mode.js";
2
3
  //# sourceMappingURL=index.d.ts.map
package/index.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,KAAK,EACL,iBAAiB,EACjB,KAAK,kBAAkB,GACxB,MAAM,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,KAAK,EACL,iBAAiB,EACjB,KAAK,kBAAkB,GACxB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC"}
package/index.js CHANGED
@@ -1,2 +1,3 @@
1
1
  export { EOCD_MIN_SIZE, crc32, parseZipStructure, } from "./zip-structure.js";
2
+ export { entryFileMode, isExecutableEntry } from "./entry-mode.js";
2
3
  //# sourceMappingURL=index.js.map
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,KAAK,EACL,iBAAiB,GAElB,MAAM,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,KAAK,EACL,iBAAiB,GAElB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stigmer/zip-structure",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "Policy-free structural ZIP parsing shared by Stigmer's TypeScript processes — central-directory-based entry enumeration (never local-header walks) plus the byte-level archive builder its consumers' tests craft fixtures with",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Whether an archive entry is a script a command may run directly: the one
3
+ * rule every reader of a pushed archive applies to the executable bit.
4
+ *
5
+ * A ZIP's mode bits are not trusted (most writers leave them unset, and a
6
+ * pushed archive's entries are judged by name and bytes alone), so the bit
7
+ * is inferred: a script extension, or a file that opens with `#!`. Claude
8
+ * Code plugins run extensionless scripts directly (`hooks/check`,
9
+ * `bin/tool`), so the shebang is the signal that matters for them; skills
10
+ * gain it too.
11
+ *
12
+ * Shared because two processes must agree on it byte for byte: the
13
+ * runner, which writes a skill's or plugin's tree with these modes
14
+ * (`runner` `shared/archive-mount.ts`), and the server, whose table of an
15
+ * archive's files tells a reader which files are executable
16
+ * (`stigmer-server` `archive/file-index.ts`). A file listed one way and
17
+ * written another would change what a command can run.
18
+ *
19
+ * The one piece of policy in this otherwise structural library, kept here
20
+ * because both consumers already depend on it and nothing else does.
21
+ */
22
+
23
+ import { extname } from "node:path/posix";
24
+
25
+ /** Extensions read as executable whatever their first bytes say. */
26
+ const SCRIPT_EXTENSIONS: ReadonlySet<string> = new Set([".sh", ".py", ".js", ".ts", ".rb", ".pl"]);
27
+
28
+ /** `#!`, the two bytes that make a file runnable as `./file`. */
29
+ const SHEBANG = [0x23, 0x21] as const;
30
+
31
+ /** Whether the entry at `path` with these bytes is executable. */
32
+ export function isExecutableEntry(path: string, content: Uint8Array): boolean {
33
+ const shebang = content.length >= 2 && content[0] === SHEBANG[0] && content[1] === SHEBANG[1];
34
+ return shebang || SCRIPT_EXTENSIONS.has(extname(path));
35
+ }
36
+
37
+ /** The mode an entry is written with: 0755 for an executable entry, 0644 otherwise. */
38
+ export function entryFileMode(path: string, content: Uint8Array): number {
39
+ return isExecutableEntry(path, content) ? 0o755 : 0o644;
40
+ }
package/src/index.ts CHANGED
@@ -4,3 +4,4 @@ export {
4
4
  parseZipStructure,
5
5
  type ZipStructuralEntry,
6
6
  } from "./zip-structure.js";
7
+ export { entryFileMode, isExecutableEntry } from "./entry-mode.js";