@wji.ai/cli 0.7.0 → 0.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/dist/core/zip.js DELETED
@@ -1,87 +0,0 @@
1
- /**
2
- * Minimal ZIP writer — "stored" (no compression) entries only.
3
- *
4
- * The backend's skill importer keeps just the `.md` files and re-parses them, so
5
- * compression buys nothing here; storing avoids pulling a zip dependency into an
6
- * otherwise dependency-light CLI. Enough of the spec is implemented to produce a
7
- * archive JSZip (what the backend uses) reads back correctly.
8
- */
9
- const CRC_TABLE = (() => {
10
- const table = new Uint32Array(256);
11
- for (let n = 0; n < 256; n++) {
12
- let c = n;
13
- for (let k = 0; k < 8; k++)
14
- c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1;
15
- table[n] = c >>> 0;
16
- }
17
- return table;
18
- })();
19
- function crc32(buf) {
20
- let crc = 0xffffffff;
21
- for (let i = 0; i < buf.length; i++)
22
- crc = CRC_TABLE[(crc ^ buf[i]) & 0xff] ^ (crc >>> 8);
23
- return (crc ^ 0xffffffff) >>> 0;
24
- }
25
- /** DOS date/time — a fixed, valid timestamp is fine; the backend ignores it. */
26
- function dosDateTime(date = new Date()) {
27
- const time = (date.getHours() << 11) | (date.getMinutes() << 5) | (Math.floor(date.getSeconds() / 2));
28
- const day = (((date.getFullYear() - 1980) & 0x7f) << 9) | ((date.getMonth() + 1) << 5) | date.getDate();
29
- return { time: time & 0xffff, day: day & 0xffff };
30
- }
31
- export function createZip(entries) {
32
- const { time, day } = dosDateTime();
33
- const locals = [];
34
- const centrals = [];
35
- let offset = 0;
36
- for (const entry of entries) {
37
- const nameBuf = Buffer.from(entry.path.replace(/\\/g, '/'), 'utf8');
38
- const data = Buffer.isBuffer(entry.content) ? entry.content : Buffer.from(entry.content, 'utf8');
39
- const crc = crc32(data);
40
- const local = Buffer.alloc(30 + nameBuf.length);
41
- local.writeUInt32LE(0x04034b50, 0); // local file header signature
42
- local.writeUInt16LE(20, 4); // version needed
43
- local.writeUInt16LE(0, 6); // flags
44
- local.writeUInt16LE(0, 8); // method: store
45
- local.writeUInt16LE(time, 10);
46
- local.writeUInt16LE(day, 12);
47
- local.writeUInt32LE(crc, 14);
48
- local.writeUInt32LE(data.length, 18); // compressed size
49
- local.writeUInt32LE(data.length, 22); // uncompressed size
50
- local.writeUInt16LE(nameBuf.length, 26);
51
- local.writeUInt16LE(0, 28); // extra length
52
- nameBuf.copy(local, 30);
53
- locals.push(local, data);
54
- const central = Buffer.alloc(46 + nameBuf.length);
55
- central.writeUInt32LE(0x02014b50, 0); // central directory header signature
56
- central.writeUInt16LE(20, 4); // version made by
57
- central.writeUInt16LE(20, 6); // version needed
58
- central.writeUInt16LE(0, 8); // flags
59
- central.writeUInt16LE(0, 10); // method
60
- central.writeUInt16LE(time, 12);
61
- central.writeUInt16LE(day, 14);
62
- central.writeUInt32LE(crc, 16);
63
- central.writeUInt32LE(data.length, 20);
64
- central.writeUInt32LE(data.length, 24);
65
- central.writeUInt16LE(nameBuf.length, 28);
66
- central.writeUInt16LE(0, 30); // extra length
67
- central.writeUInt16LE(0, 32); // comment length
68
- central.writeUInt16LE(0, 34); // disk number
69
- central.writeUInt16LE(0, 36); // internal attrs
70
- central.writeUInt32LE(0, 38); // external attrs
71
- central.writeUInt32LE(offset, 42); // local header offset
72
- nameBuf.copy(central, 46);
73
- centrals.push(central);
74
- offset += local.length + data.length;
75
- }
76
- const centralDir = Buffer.concat(centrals);
77
- const end = Buffer.alloc(22);
78
- end.writeUInt32LE(0x06054b50, 0); // end of central directory signature
79
- end.writeUInt16LE(0, 4); // disk number
80
- end.writeUInt16LE(0, 6); // central dir start disk
81
- end.writeUInt16LE(entries.length, 8); // entries on this disk
82
- end.writeUInt16LE(entries.length, 10); // total entries
83
- end.writeUInt32LE(centralDir.length, 12);
84
- end.writeUInt32LE(offset, 16); // central dir offset
85
- end.writeUInt16LE(0, 20); // comment length
86
- return Buffer.concat([...locals, centralDir, end]);
87
- }