@6starlong/dsh-disk-cleanup 0.0.0-stage → 0.4.4

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,90 @@
1
+ /**
2
+ * 往 pwsh / bash 的命令串前注入环境变量。
3
+ * @module dsh-disk-cleanup/shell-env
4
+ */
5
+
6
+ /**
7
+ * 单引号包裹并转义,供 pwsh 与 bash 共用。
8
+ * @param {string} value - 原始字符串。
9
+ * @param {'pwsh' | 'bash'} shell - 目标 shell。
10
+ * @returns {string} 已加引号的字面量。
11
+ */
12
+ export function quote(value, shell) {
13
+ if (shell === 'pwsh') return `'${String(value).replace(/'/g, "''")}'`
14
+ return `'${String(value).replace(/'/g, "'\\''")}'`
15
+ }
16
+
17
+ /**
18
+ * 判断命令串是否自己设置过某个环境变量(用户显式指定时不覆盖)。
19
+ * @param {'pwsh' | 'bash'} shell - 目标 shell。
20
+ * @param {string} command - 原始命令串。
21
+ * @param {string} name - 环境变量名。
22
+ * @returns {boolean} 是否已自行设置。
23
+ */
24
+ export function alreadySets(shell, command, name) {
25
+ if (typeof command !== 'string' || typeof name !== 'string' || name === '') return false
26
+ const escaped = name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
27
+ const pattern = shell === 'pwsh'
28
+ ? new RegExp(`\\$env:${escaped}\\s*=`, 'i')
29
+ : new RegExp(`(?:^|[;&|(\\s])(?:export\\s+)?${escaped}\\s*=`, 'i')
30
+ return pattern.test(command)
31
+ }
32
+
33
+ /**
34
+ * 判断命令串是否自己设置过临时目录。
35
+ * @param {'pwsh' | 'bash'} shell - 目标 shell。
36
+ * @param {string} command - 原始命令串。
37
+ * @returns {boolean} 是否已自行设置。
38
+ */
39
+ export function alreadySetsTemp(shell, command) {
40
+ return alreadySets(shell, command, 'TMP')
41
+ || alreadySets(shell, command, 'TEMP')
42
+ || (shell !== 'pwsh' && alreadySets(shell, command, 'TMPDIR'))
43
+ }
44
+
45
+ /**
46
+ * 生成环境变量赋值前缀。
47
+ * @param {'pwsh' | 'bash'} shell - 目标 shell。
48
+ * @param {Array<[string, string]>} entries - 变量名与值。
49
+ * @returns {string} 可直接拼在命令前的字符串。
50
+ */
51
+ export function envPrefix(shell, entries) {
52
+ const parts = entries.map(([name, value]) => (shell === 'pwsh'
53
+ ? `$env:${name}=${quote(value, 'pwsh')}; `
54
+ : `export ${name}=${quote(value, 'bash')}; `))
55
+ return parts.join('')
56
+ }
57
+
58
+ /**
59
+ * 给命令串注入环境变量前缀;命令自己设置过的变量跳过。
60
+ * @param {'pwsh' | 'bash'} shell - 目标 shell。
61
+ * @param {string} command - 原始命令串。
62
+ * @param {Array<[string, string]>} entries - 变量名与值。
63
+ * @returns {string} 注入后的命令串(无需注入时原样返回)。
64
+ */
65
+ export function injectShellEnv(shell, command, entries) {
66
+ if (typeof command !== 'string' || command === '') return command
67
+ const usable = []
68
+ for (const [name, value] of entries) {
69
+ if (typeof value !== 'string' || value === '') continue
70
+ if (alreadySets(shell, command, name)) continue
71
+ usable.push([name, value])
72
+ }
73
+ if (usable.length === 0) return command
74
+ return envPrefix(shell, usable) + command
75
+ }
76
+
77
+ /**
78
+ * 只注入临时目录(TMP / TEMP,bash 另有 TMPDIR)。
79
+ * @param {'pwsh' | 'bash'} shell - 目标 shell。
80
+ * @param {string} command - 原始命令串。
81
+ * @param {string | undefined} dir - 临时目录;为空表示本次不注入。
82
+ * @returns {string} 注入后的命令串。
83
+ */
84
+ export function injectShellTemp(shell, command, dir) {
85
+ if (typeof dir !== 'string' || dir === '') return command
86
+ const entries = shell !== 'pwsh'
87
+ ? [['TMPDIR', dir], ['TMP', dir], ['TEMP', dir]]
88
+ : [['TMP', dir], ['TEMP', dir]]
89
+ return injectShellEnv(shell, command, entries)
90
+ }
package/locale/en.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Disk Cleanup",
4
+ "description": "Moves Shell temporary files out of the workspace, grants write access to the temp directory, explains where temporary files go via the system prompt, and cleans up expired temporary files and orphaned attachments on a schedule."
5
+ }
6
+ }
package/locale/zh.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "磁盘清理",
4
+ "description": "将 Shell 临时文件移出工作区,并补齐对临时目录的写入权限,通过系统提示词说明临时文件落点,再按保留天数清理过期的临时文件和无主附件。"
5
+ }
6
+ }
package/package.json CHANGED
@@ -1,6 +1,88 @@
1
1
  {
2
2
  "name": "@6starlong/dsh-disk-cleanup",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.4.4",
4
+ "description": "为 shell 命令注入临时目录,给 scratch 目录补齐写权限,在系统提示里点明临时文件该写哪里,并清理过期的临时文件。",
5
+ "type": "module",
6
+ "main": "lib/index.js",
7
+ "types": "lib/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./lib/index.d.ts",
11
+ "default": "./lib/index.js"
12
+ },
13
+ "./client": {
14
+ "default": "./lib/client.js"
15
+ },
16
+ "./cordis.patch.yml": "./cordis.patch.yml",
17
+ "./package.json": "./package.json",
18
+ "./locale/*.json": "./locale/*.json",
19
+ "./icon": "./icon.svg"
20
+ },
21
+ "files": [
22
+ "lib",
23
+ "cordis.patch.yml",
24
+ "README.md",
25
+ "locale/*.json",
26
+ "icon.svg"
27
+ ],
28
+ "publishConfig": {
29
+ "registry": "https://registry.npmjs.org/",
30
+ "access": "public"
31
+ },
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "git+https://github.com/6starlong/dsh-plugins.git",
35
+ "directory": "packages/dsh-disk-cleanup"
36
+ },
37
+ "homepage": "https://github.com/6starlong/dsh-plugins/tree/main/packages/dsh-disk-cleanup#readme",
38
+ "bugs": {
39
+ "url": "https://github.com/6starlong/dsh-plugins/issues"
40
+ },
41
+ "icon": "./icon.svg",
42
+ "scripts": {
43
+ "build": "node scripts/build.mjs",
44
+ "test": "node --test \"test/*.test.mjs\"",
45
+ "test:e2e": "node test/e2e-shell.mjs"
46
+ },
47
+ "dependencies": {},
48
+ "peerDependencies": {
49
+ "@deepseek-ai/cordis": "^4.1.0",
50
+ "@deepseek-ai/dsh-client-ui-primitives": "^0.2.2-rc.3",
51
+ "@deepseek-ai/schemastery": "*"
52
+ },
53
+ "peerDependenciesMeta": {
54
+ "@deepseek-ai/cordis": {
55
+ "optional": true
56
+ },
57
+ "@deepseek-ai/dsh-client-ui-primitives": {
58
+ "optional": true
59
+ },
60
+ "@deepseek-ai/schemastery": {
61
+ "optional": true
62
+ }
63
+ },
64
+ "dsh": {
65
+ "bundle": {
66
+ "patch": "./cordis.patch.yml"
67
+ },
68
+ "client": {
69
+ "inject": [
70
+ "dsh-client-ui-primitives"
71
+ ],
72
+ "platform": "web"
73
+ }
74
+ },
75
+ "keywords": [
76
+ "dsh",
77
+ "deepseek-harness",
78
+ "plugin",
79
+ "scratch",
80
+ "temp",
81
+ "cleanup"
82
+ ],
83
+ "license": "MIT",
84
+ "engines": {
85
+ "node": "^22.19.0 || >=24.0.0",
86
+ "dsh": ">=0.2.1-rc.2"
87
+ }
88
+ }