shrinker-ai 0.3.3 → 0.7.0

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,129 @@
1
+ #!/usr/bin/env node
2
+ import { cp, mkdir, readFile, rm, writeFile } from "node:fs/promises";
3
+ import { existsSync } from "node:fs";
4
+ import { spawnSync } from "node:child_process";
5
+ import { fileURLToPath } from "node:url";
6
+ import path from "node:path";
7
+ import process from "node:process";
8
+
9
+ const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
10
+ const packageJson = JSON.parse(await readFile(path.join(repoRoot, "package.json"), "utf8"));
11
+
12
+ const targets = {
13
+ "win-x64": { pkg: "node22-win-x64", archive: "zip", binary: "shrinker.exe" },
14
+ "macos-arm64": { pkg: "node22-macos-arm64", archive: "tar.gz", binary: "shrinker" },
15
+ "macos-x64": { pkg: "node22-macos-x64", archive: "tar.gz", binary: "shrinker" },
16
+ "linux-x64": { pkg: "node22-linux-x64", archive: "tar.gz", binary: "shrinker" },
17
+ };
18
+
19
+ function currentTarget() {
20
+ if (process.platform === "win32" && process.arch === "x64") return "win-x64";
21
+ if (process.platform === "darwin" && process.arch === "arm64") return "macos-arm64";
22
+ if (process.platform === "darwin" && process.arch === "x64") return "macos-x64";
23
+ if (process.platform === "linux" && process.arch === "x64") return "linux-x64";
24
+ throw new Error(`No default release target for ${process.platform}-${process.arch}. Pass --target explicitly.`);
25
+ }
26
+
27
+ function readOption(name) {
28
+ const index = process.argv.indexOf(name);
29
+ if (index === -1) return undefined;
30
+ const value = process.argv[index + 1];
31
+ if (!value || value.startsWith("--")) throw new Error(`${name} requires a value`);
32
+ return value;
33
+ }
34
+
35
+ function readTarget() {
36
+ const explicit = readOption("--target");
37
+ if (explicit) return explicit;
38
+ const positional = process.argv.slice(2).find((arg) => !arg.startsWith("--"));
39
+ return positional ?? currentTarget();
40
+ }
41
+
42
+ function run(command, args, options = {}) {
43
+ const result = spawnSync(command, args, {
44
+ cwd: repoRoot,
45
+ stdio: "inherit",
46
+ shell: false,
47
+ ...options,
48
+ });
49
+ if (result.status !== 0) {
50
+ throw new Error(`${command} ${args.join(" ")} failed with exit code ${result.status ?? "unknown"}`);
51
+ }
52
+ }
53
+
54
+ async function copySupportFiles(stageDir) {
55
+ await cp(
56
+ path.join(repoRoot, "integrations", "windows", "shrinker-profile.ps1"),
57
+ path.join(stageDir, "integrations", "windows", "shrinker-profile.ps1"),
58
+ { recursive: true },
59
+ );
60
+ await cp(
61
+ path.join(repoRoot, "integrations", "macos", "shrinker-profile.zsh"),
62
+ path.join(stageDir, "integrations", "macos", "shrinker-profile.zsh"),
63
+ { recursive: true },
64
+ );
65
+ await cp(
66
+ path.join(repoRoot, "templates", "agent-rules.md"),
67
+ path.join(stageDir, "templates", "agent-rules.md"),
68
+ { recursive: true },
69
+ );
70
+ }
71
+
72
+ async function createArchive(stageDir, archivePath, archiveType) {
73
+ await rm(archivePath, { force: true });
74
+ if (archiveType === "zip") {
75
+ const expression = [
76
+ "$ErrorActionPreference = 'Stop'",
77
+ `$source = Join-Path '${stageDir.replaceAll("'", "''")}' '*'`,
78
+ `Compress-Archive -Path $source -DestinationPath '${archivePath.replaceAll("'", "''")}' -Force`,
79
+ ].join("; ");
80
+ run("pwsh", ["-NoProfile", "-Command", expression]);
81
+ return;
82
+ }
83
+
84
+ run("tar", ["-czf", archivePath, "-C", stageDir, "."]);
85
+ }
86
+
87
+ const targetName = readTarget();
88
+ const version = readOption("--version") ?? packageJson.version;
89
+ const target = targets[targetName];
90
+ if (!target) {
91
+ throw new Error(`Unsupported target '${targetName}'. Supported targets: ${Object.keys(targets).join(", ")}`);
92
+ }
93
+
94
+ const entrypoint = path.join(repoRoot, "dist", "src", "cli.js");
95
+ if (!existsSync(entrypoint)) {
96
+ throw new Error("Missing dist/src/cli.js. Run npm run build before packaging.");
97
+ }
98
+
99
+ const releaseDir = path.join(repoRoot, "release");
100
+ const stageDir = path.join(repoRoot, ".shrinker", "package", targetName);
101
+ const binaryPath = path.join(stageDir, "bin", target.binary);
102
+ const archiveName = `shrinker-${targetName}.${target.archive === "zip" ? "zip" : "tar.gz"}`;
103
+ const archivePath = path.join(releaseDir, archiveName);
104
+
105
+ await rm(stageDir, { recursive: true, force: true });
106
+ await mkdir(path.dirname(binaryPath), { recursive: true });
107
+ await mkdir(releaseDir, { recursive: true });
108
+
109
+ run(process.execPath, [
110
+ path.join(repoRoot, "node_modules", "@yao-pkg", "pkg", "lib-es5", "bin.js"),
111
+ entrypoint,
112
+ "--targets",
113
+ target.pkg,
114
+ "--output",
115
+ binaryPath,
116
+ "--no-bytecode",
117
+ "--public",
118
+ "--public-packages",
119
+ "*",
120
+ ]);
121
+ await copySupportFiles(stageDir);
122
+ await writeFile(
123
+ path.join(stageDir, "manifest.json"),
124
+ `${JSON.stringify({ name: packageJson.name, version, target: targetName, binary: `bin/${target.binary}` }, null, 2)}\n`,
125
+ "utf8",
126
+ );
127
+
128
+ await createArchive(stageDir, archivePath, target.archive);
129
+ console.log(`Created ${path.relative(repoRoot, archivePath)}`);
@@ -1,19 +1,19 @@
1
- Use `shrinker` for high-volume terminal outputs to reduce tokens.
2
-
3
- Routing policy:
4
- - `git status|diff|log|show|reflog|branch|tag|stash` -> `shrinker git ...`
5
- - `npm test|t|install|i|ci|ls|list` -> `shrinker npm ...`
6
- - `docker ps|logs|images|compose` -> `shrinker docker ...`
7
- - `kubectl get|describe|logs` -> `shrinker kubectl ...`
8
- - `gh pr|issue|run` -> `shrinker gh ...`
9
- - `rg`, `find`, `tail`, `cat`, `ls`, `dir` -> `shrinker <command> ...`
10
-
11
- Bypass shrinker when:
12
- - command modifies remote state and output volume is already tiny
13
- - command requires interactive stdin
14
- - command explicitly needs `shrinker --raw`
15
-
16
- Examples:
17
- - `shrinker git log -n 20`
18
- - `shrinker rg "pattern" src`
1
+ Use `shrinker` for high-volume terminal outputs to reduce tokens.
2
+
3
+ Routing policy:
4
+ - `git status|diff|log|show|reflog|branch|tag|stash` -> `shrinker git ...`
5
+ - `npm test|t|install|i|ci|ls|list` -> `shrinker npm ...`
6
+ - `docker ps|logs|images|compose` -> `shrinker docker ...`
7
+ - `kubectl get|describe|logs` -> `shrinker kubectl ...`
8
+ - `gh pr|issue|run` -> `shrinker gh ...`
9
+ - `rg`, `find`, `tail`, `cat`, `ls`, `dir` -> `shrinker <command> ...`
10
+
11
+ Bypass shrinker when:
12
+ - command modifies remote state and output volume is already tiny
13
+ - command requires interactive stdin
14
+ - command explicitly needs `shrinker --raw`
15
+
16
+ Examples:
17
+ - `shrinker git log -n 20`
18
+ - `shrinker rg "pattern" src`
19
19
  - `shrinker docker logs api --tail 500`
@@ -1,28 +0,0 @@
1
-
2
-
3
-
4
- <!-- shrinker agent rules start -->
5
- Use `shrinker` for high-volume terminal outputs to reduce tokens.
6
-
7
- Routing policy:
8
- - `git status|diff|log|show|reflog|branch|tag|stash` -> `shrinker git ...`
9
- - `npm test|t|install|i|ci|ls|list` -> `shrinker npm ...`
10
- - `docker ps|logs|images|compose` -> `shrinker docker ...`
11
- - `kubectl get|describe|logs` -> `shrinker kubectl ...`
12
- - `gh pr|issue|run` -> `shrinker gh ...`
13
- - `rg`, `find`, `tail`, `cat`, `ls`, `dir` -> `shrinker <command> ...`
14
-
15
- Bypass shrinker when:
16
- - command modifies remote state and output volume is already tiny
17
- - command requires interactive stdin
18
- - command explicitly needs `shrinker --raw`
19
-
20
- Examples:
21
- - `shrinker git log -n 20`
22
- - `shrinker rg "pattern" src`
23
- - `shrinker docker logs api --tail 500`
24
- <!-- shrinker agent rules end -->
25
-
26
-
27
-
28
-
package/CLAUDE.md DELETED
@@ -1,28 +0,0 @@
1
-
2
-
3
-
4
- <!-- shrinker agent rules start -->
5
- Use `shrinker` for high-volume terminal outputs to reduce tokens.
6
-
7
- Routing policy:
8
- - `git status|diff|log|show|reflog|branch|tag|stash` -> `shrinker git ...`
9
- - `npm test|t|install|i|ci|ls|list` -> `shrinker npm ...`
10
- - `docker ps|logs|images|compose` -> `shrinker docker ...`
11
- - `kubectl get|describe|logs` -> `shrinker kubectl ...`
12
- - `gh pr|issue|run` -> `shrinker gh ...`
13
- - `rg`, `find`, `tail`, `cat`, `ls`, `dir` -> `shrinker <command> ...`
14
-
15
- Bypass shrinker when:
16
- - command modifies remote state and output volume is already tiny
17
- - command requires interactive stdin
18
- - command explicitly needs `shrinker --raw`
19
-
20
- Examples:
21
- - `shrinker git log -n 20`
22
- - `shrinker rg "pattern" src`
23
- - `shrinker docker logs api --tail 500`
24
- <!-- shrinker agent rules end -->
25
-
26
-
27
-
28
-