@laraveladmin/dsh-stay-awake 0.0.0-stage → 0.1.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/CHANGELOG.md +37 -0
- package/LICENSE +21 -0
- package/README.en.md +223 -0
- package/README.md +225 -2
- package/client.js +650 -0
- package/cordis.patch.yml +3 -0
- package/docs/REQUIREMENTS.md +516 -0
- package/docs/VERIFICATION.md +125 -0
- package/docs/images/indicator.svg +19 -0
- package/docs/images/panel.svg +65 -0
- package/icon.svg +7 -0
- package/index.js +270 -0
- package/lib/activity.js +74 -0
- package/lib/config.js +81 -0
- package/lib/controller.js +305 -0
- package/lib/log.js +21 -0
- package/lib/platform.js +105 -0
- package/lib/power.js +121 -0
- package/lib/server.js +91 -0
- package/lib/state.js +70 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +60 -4
package/lib/state.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* UI-owned state persistence.
|
|
3
|
+
*
|
|
4
|
+
* The popover can change two settings that must survive a reload; everything
|
|
5
|
+
* else (debounce, hold cap, reconciliation) stays in `cordis.patch.yml`.
|
|
6
|
+
*
|
|
7
|
+
* Deliberately a plain JSON file under the DSH plugin-data directory instead of
|
|
8
|
+
* the Host `storage` service: two booleans do not justify an async storage
|
|
9
|
+
* handshake, and a deterministic file can be verified end to end.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs'
|
|
13
|
+
import { homedir } from 'node:os'
|
|
14
|
+
import { dirname, join } from 'node:path'
|
|
15
|
+
|
|
16
|
+
const STATE_VERSION = 1
|
|
17
|
+
const SCOPES = new Set(['system', 'display'])
|
|
18
|
+
|
|
19
|
+
export function defaultStatePath() {
|
|
20
|
+
return join(homedir(), '.dsh', 'plugin-data', 'dsh-stay-awake', 'state.json')
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Keep only fields this version understands and that pass their own validation. */
|
|
24
|
+
export function sanitizeState(raw) {
|
|
25
|
+
const result = {}
|
|
26
|
+
if (raw === null || typeof raw !== 'object') return result
|
|
27
|
+
if (typeof raw.enabled === 'boolean') result.enabled = raw.enabled
|
|
28
|
+
if (SCOPES.has(raw.scope)) result.scope = raw.scope
|
|
29
|
+
return result
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @returns {{ state: { enabled?: boolean, scope?: 'system'|'display' }, warning: string | null }}
|
|
34
|
+
*/
|
|
35
|
+
export function loadState(path) {
|
|
36
|
+
let text
|
|
37
|
+
try {
|
|
38
|
+
text = readFileSync(path, 'utf8')
|
|
39
|
+
} catch (error) {
|
|
40
|
+
if (error?.code === 'ENOENT') return { state: {}, warning: null }
|
|
41
|
+
return { state: {}, warning: `state file unreadable (${error?.code ?? 'error'}); using defaults` }
|
|
42
|
+
}
|
|
43
|
+
let parsed
|
|
44
|
+
try {
|
|
45
|
+
parsed = JSON.parse(text)
|
|
46
|
+
} catch {
|
|
47
|
+
return { state: {}, warning: 'state file is not valid JSON; using defaults' }
|
|
48
|
+
}
|
|
49
|
+
if (parsed === null || typeof parsed !== 'object') {
|
|
50
|
+
return { state: {}, warning: 'state file has no object root; using defaults' }
|
|
51
|
+
}
|
|
52
|
+
return { state: sanitizeState(parsed), warning: null }
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Atomic write: a crash mid-write leaves the previous file intact.
|
|
57
|
+
* @returns {{ ok: true } | { ok: false, error: string }}
|
|
58
|
+
*/
|
|
59
|
+
export function saveState(path, state) {
|
|
60
|
+
try {
|
|
61
|
+
mkdirSync(dirname(path), { recursive: true })
|
|
62
|
+
const temporary = `${path}.${process.pid}.tmp`
|
|
63
|
+
const body = JSON.stringify({ version: STATE_VERSION, ...sanitizeState(state) }, null, 2)
|
|
64
|
+
writeFileSync(temporary, `${body}\n`, 'utf8')
|
|
65
|
+
renameSync(temporary, path)
|
|
66
|
+
return { ok: true }
|
|
67
|
+
} catch (error) {
|
|
68
|
+
return { ok: false, error: error instanceof Error ? error.message : String(error) }
|
|
69
|
+
}
|
|
70
|
+
}
|
package/locale/en.json
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"meta": {
|
|
3
|
+
"title": "Stay awake",
|
|
4
|
+
"description": "Keeps this machine awake only while unattended work is still running — agent turns, background jobs and manual compaction — then releases automatically. The composer status bar shows whether it is holding; hover for active sources and hold duration."
|
|
5
|
+
}
|
|
6
|
+
}
|
package/locale/zh.json
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,62 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@laraveladmin/dsh-stay-awake",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "DeepSeek Harness plugin that keeps the machine awake only while unattended work runs.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"dsh-plugin",
|
|
7
|
+
"deepseek-harness",
|
|
8
|
+
"keep-awake",
|
|
9
|
+
"prevent-sleep",
|
|
10
|
+
"caffeinate"
|
|
11
|
+
],
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"author": "laraveladmin",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://gitee.com/laravel-admin/dsh-stay-awake.git"
|
|
17
|
+
},
|
|
18
|
+
"homepage": "https://gitee.com/laravel-admin/dsh-stay-awake",
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://gitee.com/laravel-admin/dsh-stay-awake/issues"
|
|
21
|
+
},
|
|
22
|
+
"type": "module",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": "./index.js",
|
|
25
|
+
"./client": "./client.js",
|
|
26
|
+
"./locale/*.json": "./locale/*.json",
|
|
27
|
+
"./icon": "./icon.svg"
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"index.js",
|
|
31
|
+
"client.js",
|
|
32
|
+
"lib",
|
|
33
|
+
"cordis.patch.yml",
|
|
34
|
+
"locale/*.json",
|
|
35
|
+
"docs",
|
|
36
|
+
"icon.svg",
|
|
37
|
+
"README.md",
|
|
38
|
+
"README.en.md",
|
|
39
|
+
"LICENSE",
|
|
40
|
+
"CHANGELOG.md"
|
|
41
|
+
],
|
|
42
|
+
"scripts": {
|
|
43
|
+
"test": "node --test test/*.test.js",
|
|
44
|
+
"test:integration": "node --test test/integration/*.test.js"
|
|
45
|
+
},
|
|
46
|
+
"dsh": {
|
|
47
|
+
"bundle": {
|
|
48
|
+
"patch": "./cordis.patch.yml"
|
|
49
|
+
},
|
|
50
|
+
"client": {
|
|
51
|
+
"platform": "web",
|
|
52
|
+
"immediately": true,
|
|
53
|
+
"inject": [
|
|
54
|
+
"@deepseek-ai/dsh-client-ui-conversation"
|
|
55
|
+
]
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
"publishConfig": {
|
|
59
|
+
"access": "public",
|
|
60
|
+
"registry": "https://registry.npmjs.org/"
|
|
61
|
+
}
|
|
62
|
+
}
|