@twinsearth/w2m-dsh-plugin 1.0.4 → 1.0.5
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 +61 -0
- package/lib/gpw.js +10 -0
- package/package.json +3 -2
- package/plugin.json +1 -1
- package/src/plugin/gpw.mjs +205 -0
- package/src/plugin/tools.mjs +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,67 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project are documented here.
|
|
4
4
|
|
|
5
|
+
## [1.0.5] — 2026-10-17
|
|
6
|
+
|
|
7
|
+
**DSH-GPW ships as an optional sub-plugin, and the reason it never activated is fixed.**
|
|
8
|
+
|
|
9
|
+
### What DSH-GPW is
|
|
10
|
+
|
|
11
|
+
**Global Permission Watchdog.** It answers permission requests on the `approval/request` waterfall with a hard global
|
|
12
|
+
budget: **at most 10 auto-approvals per rolling 60 s, at least 3000 ms apart.** Past either limit it returns
|
|
13
|
+
`next()` -- *"no opinion"* -- so the request falls through to the human prompt **and waits**. It never refuses, and
|
|
14
|
+
it never changes what is being asked.
|
|
15
|
+
|
|
16
|
+
### Optional means optional, which decides where it lives
|
|
17
|
+
|
|
18
|
+
The package declares **one** `dsh.bundle.patch`, and that is what makes the w2m plugin mount itself on install. **A
|
|
19
|
+
second plugin in the same patch would mount for everyone**, and this one changes how permissions are answered -- that
|
|
20
|
+
is an operator's decision, not a default.
|
|
21
|
+
|
|
22
|
+
So it is exposed as `@twinsearth/w2m-dsh-plugin/gpw` and mounted by one explicit row:
|
|
23
|
+
|
|
24
|
+
- insert:
|
|
25
|
+
- id: dsh-gpw
|
|
26
|
+
name: '@twinsearth/w2m-dsh-plugin/gpw'
|
|
27
|
+
|
|
28
|
+
**`insert:` is required and the reason is recorded in this package's own patch file**: no earlier layer creates a
|
|
29
|
+
`dsh-gpw` row, and a bare `- id:` patch aimed at a nonexistent row is **skipped silently**. Removing the row
|
|
30
|
+
disables it again.
|
|
31
|
+
|
|
32
|
+
**It is deliberately not re-exported from `lib/index.js`.** A permission-answering plugin must not arrive because
|
|
33
|
+
someone installed a fleet tool.
|
|
34
|
+
|
|
35
|
+
### The defect that kept it from ever activating
|
|
36
|
+
|
|
37
|
+
The standalone copy declared:
|
|
38
|
+
|
|
39
|
+
export const inject = { required: ['approval'] };
|
|
40
|
+
|
|
41
|
+
**The host reads `inject` as an array of service names.** Measured across the shipped tree: **283 array-shaped
|
|
42
|
+
declarations, 0 object-shaped.** So the host took the object's *key* and waited for a service literally named
|
|
43
|
+
`required`:
|
|
44
|
+
|
|
45
|
+
pending (waiting for service: required)
|
|
46
|
+
|
|
47
|
+
-- indefinitely, and the client reported the component as `等待依赖`. It is now `['approval']`, and `approval`
|
|
48
|
+
does exist: `@deepseek-ai/dsh-base`'s patch mounts `@deepseek-ai/dsh-user-approval` as id `approval`.
|
|
49
|
+
|
|
50
|
+
**The error message named its own cause**, which is why this took one measurement instead of an investigation: it
|
|
51
|
+
said `required`, and `required` is the key.
|
|
52
|
+
|
|
53
|
+
### What is verified, and what is not
|
|
54
|
+
|
|
55
|
+
**Verified:** `lib/gpw.js` loads; `name` is `dsh-gpw`; `inject` is an array; `apply` is a function;
|
|
56
|
+
`approval/request` and `allowed-once` both exist in the host (9 and 22 files respectively).
|
|
57
|
+
|
|
58
|
+
**Not verified: that it mounts and intercepts.** That needs a live host with the row added. The observable evidence
|
|
59
|
+
after a restart is its own startup line --
|
|
60
|
+
|
|
61
|
+
approval-ratelimit: active -- at most 10 auto-approvals per 60 s, at least 3000 ms apart, process-wide
|
|
62
|
+
|
|
63
|
+
-- **and then the periodic counted line, without which "mounted and working" and "mounted and doing nothing" look
|
|
64
|
+
identical.** That distinction is the reason those counters exist.
|
|
65
|
+
|
|
5
66
|
## [1.0.4] — 2026-10-17
|
|
6
67
|
|
|
7
68
|
**The description described a different package, and it is the only thing many readers see.**
|
package/lib/gpw.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Package-facing entry for DSH-GPW: `@twinsearth/w2m-dsh-plugin/gpw`.
|
|
3
|
+
*
|
|
4
|
+
* The documented subpath a profile row names to enable the watchdog. A seam, not a second implementation -- the code
|
|
5
|
+
* lives in `src/plugin/gpw.mjs`, which is where it is readable.
|
|
6
|
+
*
|
|
7
|
+
* **It is deliberately not re-exported from `lib/index.js`.** The package root is what installs by default, and a
|
|
8
|
+
* permission-answering plugin must not arrive because someone installed a fleet tool.
|
|
9
|
+
*/
|
|
10
|
+
export { apply, inject, name } from '../src/plugin/gpw.mjs';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twinsearth/w2m-dsh-plugin",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "Run one project across your own Windows and macOS machines from a single DeepSeek account, through 11 w2m_* tools. Four coordination modes (replicate, split, broadcast, pipeline) and six aggregate verdicts (consistent, divergent, divergent-platform, failed, partial, unverifiable). P2P hole punching by default, with a bundled relay, STUN responder and ledger fallback, so the fleet needs no third-party service. Joining needs a pairing code plus autoStartAgent: true; installing alone does not join.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
"./rabbit": "./bin/w2m-rabbit.mjs",
|
|
17
17
|
"./localside": "./bin/w2m-localside.mjs",
|
|
18
18
|
"./stun": "./bin/w2m-stun.mjs",
|
|
19
|
-
"./package.json": "./package.json"
|
|
19
|
+
"./package.json": "./package.json",
|
|
20
|
+
"./gpw": "./lib/gpw.js"
|
|
20
21
|
},
|
|
21
22
|
"files": [
|
|
22
23
|
"mcp.json",
|
package/plugin.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json",
|
|
3
3
|
"name": "twinsearth-w2m-dsh",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.5",
|
|
5
5
|
"description": "Run one project across your own Windows and macOS machines from a single DeepSeek account, through 11 w2m_* tools. Four coordination modes (replicate, split, broadcast, pipeline) and six aggregate verdicts (consistent, divergent, divergent-platform, failed, partial, unverifiable). P2P hole punching by default, with a bundled relay, STUN responder and ledger fallback, so the fleet needs no third-party service. Joining needs a pairing code plus autoStartAgent: true; installing alone does not join.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"keywords": [
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DSH-GPW -- Global Permission Watchdog (v1.0.5), shipped as an OPTIONAL sub-plugin of @twinsearth/w2m-dsh-plugin.
|
|
3
|
+
*
|
|
4
|
+
* ## What it does, in one paragraph
|
|
5
|
+
*
|
|
6
|
+
* It answers permission requests on the `approval/request` waterfall with a hard global budget: **at most 10
|
|
7
|
+
* auto-approvals per rolling 60 s, at least 3000 ms apart.** Anything past either limit returns `next()`, which is
|
|
8
|
+
* *"no opinion"* -- the request falls through to the human prompt and **waits**. It never refuses, and it never
|
|
9
|
+
* changes what is being asked; it only decides who answers and how fast.
|
|
10
|
+
*
|
|
11
|
+
* ## Why the budget exists
|
|
12
|
+
*
|
|
13
|
+
* Every auto-approval is a permission decision made without a human reading it. A watchdog with no ceiling is a
|
|
14
|
+
* plugin that grants everything and is indistinguishable from one that is working correctly -- the failure mode this
|
|
15
|
+
* repository has recorded seven times. The two counters it logs (`allowedTotal`, `deferredTotal`) exist so that
|
|
16
|
+
* "mounted and doing nothing" and "mounted and working" look different.
|
|
17
|
+
*
|
|
18
|
+
* ## How it is enabled -- it is NOT on by default
|
|
19
|
+
*
|
|
20
|
+
* Installing this package does **not** mount the watchdog: its own `dsh.bundle.patch` mounts only the w2m plugin.
|
|
21
|
+
* To enable it, add ONE `insert:` to the profile's `cordis.patch.yml`:
|
|
22
|
+
*
|
|
23
|
+
* - insert:
|
|
24
|
+
* - id: dsh-gpw
|
|
25
|
+
* name: '@twinsearth/w2m-dsh-plugin/gpw'
|
|
26
|
+
* config:
|
|
27
|
+
* maxPerWindow: 10 # optional; these are the defaults
|
|
28
|
+
* windowMs: 60000
|
|
29
|
+
* minGapMs: 3000
|
|
30
|
+
*
|
|
31
|
+
* `insert:` is required: no earlier layer creates a `dsh-gpw` row, and a bare `- id:` patch aimed at a
|
|
32
|
+
* non-existent row is skipped **silently**. Remove the row to disable it again -- no other change is needed.
|
|
33
|
+
*
|
|
34
|
+
* ## Its dependency, and the bug that shipped in the standalone copy
|
|
35
|
+
*
|
|
36
|
+
* `inject = ['approval']`. The first version of this module declared `{ required: ['approval'] }`; the host reads
|
|
37
|
+
* `inject` as an array (**283 array-shaped declarations across the shipped tree, 0 object-shaped**), so it waited
|
|
38
|
+
* for a service named `required` and stayed `pending (waiting for service: required)` forever. `approval` itself
|
|
39
|
+
* exists: `@deepseek-ai/dsh-base`'s patch mounts `@deepseek-ai/dsh-user-approval` as id `approval`.
|
|
40
|
+
*
|
|
41
|
+
* ## Provenance
|
|
42
|
+
*
|
|
43
|
+
* Written as a standalone package `dsh-approval-ratelimit@1.0.0`, then folded in here so a fleet operator installs
|
|
44
|
+
* one thing. The logic is unchanged apart from the name and the `inject` fix; every comment explaining a decision is
|
|
45
|
+
* the original.
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
/** @type {import('node:timers').Timeout | null} */
|
|
49
|
+
let logTimer = null;
|
|
50
|
+
|
|
51
|
+
export const name = 'dsh-gpw';
|
|
52
|
+
|
|
53
|
+
export const inject = ['approval'];
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @param {object} ctx Cordis context.
|
|
57
|
+
* @param {object} [config]
|
|
58
|
+
* @param {number} [config.maxPerWindow] Auto-approvals allowed per rolling window. Default 10.
|
|
59
|
+
* @param {number} [config.windowMs] Window length in ms. Default 60000.
|
|
60
|
+
* @param {number} [config.minGapMs] Minimum gap between two auto-approvals, in ms. Default 3000.
|
|
61
|
+
*/
|
|
62
|
+
export function apply(ctx, config = {}) {
|
|
63
|
+
const maxPerWindow = positiveInt(config.maxPerWindow, 10);
|
|
64
|
+
const windowMs = positiveInt(config.windowMs, 60_000);
|
|
65
|
+
const minGapMs = positiveInt(config.minGapMs, 3_000);
|
|
66
|
+
|
|
67
|
+
/** Timestamps of the auto-approvals inside the current window, oldest first. */
|
|
68
|
+
const approvals = [];
|
|
69
|
+
/** Timestamp of the most recent auto-approval, or null. */
|
|
70
|
+
let lastApprovalAt = null;
|
|
71
|
+
/** Counters for the periodic line, so the operator can see this thing working. */
|
|
72
|
+
let deferredTotal = 0;
|
|
73
|
+
let allowedTotal = 0;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Drop approvals that have aged out of the window.
|
|
77
|
+
*
|
|
78
|
+
* A rolling window is the requirement; a fixed one would allow a burst of `2 * maxPerWindow`
|
|
79
|
+
* straddling a boundary (ten at the end of one minute, ten at the start of the next).
|
|
80
|
+
*
|
|
81
|
+
* @param {number} now
|
|
82
|
+
*/
|
|
83
|
+
function prune(now) {
|
|
84
|
+
const cutoff = now - windowMs;
|
|
85
|
+
while (approvals.length > 0 && approvals[0] <= cutoff) approvals.shift();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Decide one request, without ever rejecting.
|
|
90
|
+
*
|
|
91
|
+
* @param {number} now
|
|
92
|
+
* @returns {{ allow: boolean, reason: string, inWindow: number }}
|
|
93
|
+
*/
|
|
94
|
+
function decide(now) {
|
|
95
|
+
prune(now);
|
|
96
|
+
if (lastApprovalAt !== null && now - lastApprovalAt < minGapMs) {
|
|
97
|
+
return {
|
|
98
|
+
allow: false,
|
|
99
|
+
reason: `only ${now - lastApprovalAt} ms since the last auto-approval (needs ${minGapMs} ms)`,
|
|
100
|
+
inWindow: approvals.length,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
if (approvals.length >= maxPerWindow) {
|
|
104
|
+
return {
|
|
105
|
+
allow: false,
|
|
106
|
+
reason: `${approvals.length} auto-approvals already in the last ${Math.round(windowMs / 1000)} s (limit ${maxPerWindow})`,
|
|
107
|
+
inWindow: approvals.length,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
return { allow: true, reason: 'within both limits', inWindow: approvals.length };
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* One line per window of real activity, so a silent plugin and a broken plugin look different.
|
|
115
|
+
*
|
|
116
|
+
* The failure mode this guards against is the one this whole session keeps meeting: a component
|
|
117
|
+
* that is mounted, doing nothing, and indistinguishable from a healthy one. `allowedTotal` and
|
|
118
|
+
* `deferredTotal` are the two numbers that tell them apart.
|
|
119
|
+
*/
|
|
120
|
+
function startReporter() {
|
|
121
|
+
if (logTimer !== null) return () => {};
|
|
122
|
+
logTimer = setInterval(() => {
|
|
123
|
+
if (allowedTotal === 0 && deferredTotal === 0) return;
|
|
124
|
+
ctx.logger?.info?.(
|
|
125
|
+
`approval-ratelimit: ${allowedTotal} auto-approved, ${deferredTotal} deferred to the human `
|
|
126
|
+
+ `(limit ${maxPerWindow}/${Math.round(windowMs / 1000)}s, gap ${minGapMs}ms, ${approvals.length} in the current window)`,
|
|
127
|
+
);
|
|
128
|
+
}, windowMs);
|
|
129
|
+
logTimer.unref?.();
|
|
130
|
+
return () => {
|
|
131
|
+
if (logTimer !== null) {
|
|
132
|
+
clearInterval(logTimer);
|
|
133
|
+
logTimer = null;
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* The answerer.
|
|
140
|
+
*
|
|
141
|
+
* Registered on the `approval/request` waterfall. Returning `'allowed-once'` grants this one
|
|
142
|
+
* request; returning `next()` is "no opinion" and hands the decision to whoever answers next --
|
|
143
|
+
* which is the human prompt, and it *waits* there rather than being refused.
|
|
144
|
+
*/
|
|
145
|
+
const disposeListener = ctx.on('approval/request', (request, next) => {
|
|
146
|
+
const now = Date.now();
|
|
147
|
+
const verdict = decide(now);
|
|
148
|
+
if (!verdict.allow) {
|
|
149
|
+
deferredTotal += 1;
|
|
150
|
+
// Debug, not warn: deferring is the designed behaviour of this plugin, and warning about the
|
|
151
|
+
// normal path trains an operator to ignore the line that would matter.
|
|
152
|
+
ctx.logger?.debug?.(
|
|
153
|
+
`approval-ratelimit: deferring to the human -- ${verdict.reason}`
|
|
154
|
+
+ (request?.toolName ? ` (tool ${request.toolName})` : ''),
|
|
155
|
+
);
|
|
156
|
+
return next();
|
|
157
|
+
}
|
|
158
|
+
approvals.push(now);
|
|
159
|
+
lastApprovalAt = now;
|
|
160
|
+
allowedTotal += 1;
|
|
161
|
+
ctx.logger?.info?.(
|
|
162
|
+
`approval-ratelimit: auto-approved (${approvals.length}/${maxPerWindow} in the current window)`
|
|
163
|
+
+ (request?.toolName ? ` tool ${request.toolName}` : '')
|
|
164
|
+
+ (request?.reason ? ` -- ${request.reason}` : ''),
|
|
165
|
+
);
|
|
166
|
+
return 'allowed-once';
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
const stopReporter = startReporter();
|
|
170
|
+
|
|
171
|
+
// Reversible: the host owns this effect, so an unload removes the answerer and the timer with it.
|
|
172
|
+
// A listener that outlived its plugin would keep approving requests with nobody watching.
|
|
173
|
+
if (typeof ctx.effect === 'function') {
|
|
174
|
+
ctx.effect(() => () => {
|
|
175
|
+
disposeListener?.();
|
|
176
|
+
stopReporter();
|
|
177
|
+
});
|
|
178
|
+
} else {
|
|
179
|
+
// No effect seam: say so rather than pretending the cleanup is guaranteed.
|
|
180
|
+
ctx.logger?.warn?.(
|
|
181
|
+
'approval-ratelimit: the context provides no ctx.effect, so the answerer and its reporter '
|
|
182
|
+
+ 'cannot be released on unload',
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
ctx.logger?.info?.(
|
|
187
|
+
`approval-ratelimit: active -- at most ${maxPerWindow} auto-approvals per ${Math.round(windowMs / 1000)} s, `
|
|
188
|
+
+ `at least ${minGapMs} ms apart, process-wide; everything else waits for the human`,
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Coerce a config value to a positive integer, falling back to the default.
|
|
194
|
+
*
|
|
195
|
+
* A misconfigured limit must not silently become "0", which would disable the plugin while looking
|
|
196
|
+
* like it was on -- and must not become a non-finite number, which would break the comparison.
|
|
197
|
+
*
|
|
198
|
+
* @param {unknown} value
|
|
199
|
+
* @param {number} fallback
|
|
200
|
+
* @returns {number}
|
|
201
|
+
*/
|
|
202
|
+
function positiveInt(value, fallback) {
|
|
203
|
+
if (typeof value !== 'number' || !Number.isFinite(value) || value <= 0) return fallback;
|
|
204
|
+
return Math.floor(value);
|
|
205
|
+
}
|
package/src/plugin/tools.mjs
CHANGED
|
@@ -208,7 +208,7 @@ const MAX_STAGES = 16;
|
|
|
208
208
|
* `package.json` during `scripts/pack.mjs` rather than hand-maintained, and `W2M_PLUGIN_VERSION`
|
|
209
209
|
* overrides it at runtime for tests and packagers.
|
|
210
210
|
*/
|
|
211
|
-
const PLUGIN_VERSION = '1.0.
|
|
211
|
+
const PLUGIN_VERSION = '1.0.5';
|
|
212
212
|
|
|
213
213
|
/** How long any single HTTP call may take before it is aborted, in milliseconds. */
|
|
214
214
|
const DEFAULT_REQUEST_TIMEOUT_MS = 15_000;
|