@twinsearth/w2m-dsh-plugin 0.25.0 → 0.26.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.
package/CHANGELOG.md CHANGED
@@ -4,6 +4,54 @@ All notable changes to this project are documented here. The format follows
4
4
  [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project
5
5
  adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [0.26.0] — 2026-10-15
8
+
9
+ **`w2m_approvals`: the approval chain is reachable by an operator, not only by the suite.**
10
+
11
+ The tenth tool. `action: "list"` reads the queue, `approve` and `reject` settle one request by `approval_id`.
12
+ Until now the chain from 0.25.0 was **closed in code and testable end to end while no operator could reach
13
+ it**; this is the tool that opens it.
14
+
15
+ ### Every row says whether *you* may act, and why not when you may not
16
+
17
+ A list filtered to what the caller may answer would be shorter and would **make the fleet look idle at the
18
+ moment it is most blocked.** `listFor` already returns each row with `may_act` and `why_not`; the tool passes
19
+ them through instead of hiding work above the caller's authority.
20
+
21
+ ### `actor_level` is a parameter, and that is deliberate
22
+
23
+ The machine's own `actorAuthorityLevel` says what it may **dispatch as**. An approver's level is a fact about
24
+ the person answering, and a decision made on the dispatcher's level would let a machine approve its own
25
+ escalations. Passing it explicitly is what keeps `APPROVAL_SELF_APPROVAL` meaningful rather than incidental.
26
+
27
+ **Settling without a level is refused** (`W2M_APPROVAL_LEVEL`) rather than defaulted, so a decision is never
28
+ attributed to a level nobody supplied. Listing **without** a level still works and says so: `level_known:
29
+ false`, with a note explaining that the queue is visible but whether any of it is answerable is not known —
30
+ **knowing what is waiting does not require the authority to answer it, and a queue only its supervisors can
31
+ see is a queue that stays full.**
32
+
33
+ ### The note on every settle, because a reader will assume otherwise
34
+
35
+ > *"the request is settled; the dispatch did not run and must be attempted again"*
36
+
37
+ Approval means the next attempt is allowed, not that anything already happened. A tool that settled quietly
38
+ would leave its caller waiting for a result that is never coming.
39
+
40
+ ### Three defects of mine, all caught by the suite or by checking
41
+
42
+ * I called a `json(...)` helper **that does not exist in this file** — every tool returns `JSON.stringify(...)`.
43
+ `node --check` passed, so only reading the surrounding code found it.
44
+ * I referenced `AUTHORITY_MAX` without importing it.
45
+ * I omitted `presentCall`, which `ALLOWED_DEF_KEYS` requires and which the registration-shape test pins. It now
46
+ labels a list as a `read` and a settle as a `write`, because **calling a queue inspection a write would
47
+ misrepresent the common case.**
48
+
49
+ Four tool-count assertions said "exactly nine" and named the nine; they now say ten and name the ten. The
50
+ comment beside one of them already recorded the lesson from a previous version — that a **count** was once the
51
+ wrong property and the **message** was the right one. This time the count *was* the property.
52
+
53
+ **7 new tests, 0 failures.**
54
+
7
55
  ## [0.25.0] — 2026-10-15
8
56
 
9
57
  **The chain is closed: dispatch → gate → queue → decision. The plugin builds a queue, and an escalation is a real entry an approver can find.**
package/README.md CHANGED
@@ -39,7 +39,7 @@ So the cross-machine capability has to be built. This is that build.
39
39
  ▼
40
40
  ┌──────────────────────────────────┐ ┌──────────────────────────┐
41
41
  │ Windows · DSH session │ │ macOS · DSH session │
42
- │ w2m plugin (9 tools) │ │ w2m plugin (9 tools) │
42
+ │ w2m plugin (10 tools) │ │ w2m plugin (10 tools) │
43
43
  │ │ │ │ │ │
44
44
  │ Localside agent │ │ Localside agent │
45
45
  │ · three anchors │ │ · three anchors │
@@ -293,15 +293,16 @@ Then give it the relay URL in that profile's `cordis.patch.yml` — or leave
293
293
  > got "@twinsearth/w2m-dsh-plugin/tools"), skipping
294
294
  > ```
295
295
  >
296
- > That is a silent failure by construction — the install looks right, nine tools appear, and
296
+ > That is a silent failure by construction — the install looks right, ten tools appear, and
297
297
  > `w2m_status` reports `paired: false` and a null `rabbitUrl` because none of your values were ever
298
298
  > applied. It is not hypothetical: this row's expected name moved from the `/tools` subpath to the
299
299
  > package root in v0.5.4 (see `cordis.patch.yml`'s header for why), and every override that still
300
300
  > asserted the old subpath stopped being applied on upgrade. `id` already identifies the row, so the
301
301
  > safest `name:` is no `name:` at all.
302
302
 
303
- Restart DSH. You should see nine tools: `w2m_devices`, `w2m_run`, `w2m_wait`,
304
- `w2m_report`, `w2m_status`, `w2m_update`, `w2m_history`, `w2m_stats`, `w2m_memory`.
303
+ Restart DSH. You should see ten tools: `w2m_devices`, `w2m_run`, `w2m_wait`,
304
+ `w2m_report`, `w2m_status`, `w2m_update`, `w2m_history`, `w2m_stats`, `w2m_memory`,
305
+ `w2m_approvals`.
305
306
 
306
307
  > `dsh` may not be on your `PATH`. On a packaged install it lives under
307
308
  > `resources/runtime/cli/bin/`. If `dsh` is not found, call it by path.
@@ -584,7 +585,7 @@ a product.
584
585
  |---|---|---|
585
586
  | relay | 142 | pairing, auth, SSE with `ready`-first and `seq` replay, leases with heartbeat renewal and expiry, dedupe, all **nine** aggregation states plus `pending`/`refused`, report generation, operator token, rate limiting, persistence and restart recovery, TLS, and the lost-offer recovery path |
586
587
  | agent | 129 | allow-list allow/deny, timeout, output truncation, exit codes, anchors on clean and dirty trees, four concurrent fingerprint computations, spool, a 40-case URL join matrix, cursor lifecycle across relay restarts, and the bundled-runtime resolver |
587
- | tools | 89 | nine tools registered, schemas, typed errors, polling, operator-token enforcement (no request is sent without it), sub-path endpoints, and the credential canaries |
588
+ | tools | 89 | ten tools registered, schemas, typed errors, polling, operator-token enforcement (no request is sent without it), sub-path endpoints, and the credential canaries |
588
589
  | broadcast | 19 | exactly one executor, the rest `observing`; observers excluded from every aggregation step so a machine that did not run is never counted as agreeing |
589
590
  | claims | 19 | the document claims themselves: the version, the bundle patch, the tool list, every documented tarball URL, and the CHANGELOG's shape |
590
591
  | fleet-target | 37 | the composer's target selection, and the `executor_machine_id` narrowing that overrides it |
@@ -712,7 +713,7 @@ the plugin:
712
713
 
713
714
  ```bash
714
715
  node scripts/check-entrypoints.mjs # imports lib/tools.js, the exact specifier cordis.patch.yml mounts
715
- node scripts/verify-installed.mjs <path-to-installed-package> # asserts the installed copy registers 9 tools
716
+ node scripts/verify-installed.mjs <path-to-installed-package> # asserts the installed copy registers 10 tools
716
717
  ```
717
718
 
718
719
  **Not verified:**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twinsearth/w2m-dsh-plugin",
3
- "version": "0.25.0",
3
+ "version": "0.26.0",
4
4
  "description": "DSH: Windows2MacOS — drive the same project on online Windows and macOS machines from one DeepSeek account, across networks and regions. P2P hole punching is the default path (relay + shared server as rendezvous, ledger and fallback), with a bundled STUN responder, Tailscale/public-VPS/tunnel shapes, Rabbit relay + per-machine Localside + eight DSH tools (replicate / split), nine aggregate verdicts and signed requests.",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -129,7 +129,7 @@ import { gateDispatch, approvalRequestFor, raiseApproval } from '../agent/permis
129
129
  // v0.24.0: the queue an escalation is raised into. Imported from `src/`, never from `scripts/` -- a
130
130
  // `src/` module reaching above itself breaks the published package (see CHANGELOG 0.23.0).
131
131
  import { createApprovalIndex } from '../agent/approval-index.mjs';
132
- import { isAuthorityLevel } from '../agent/authority.mjs';
132
+ import { AUTHORITY_MAX, isAuthorityLevel } from '../agent/authority.mjs';
133
133
  // v0.6.0: the device keypair and the offer's key distribution (`docs/P2P-CRYPTO.md` §4). Imported
134
134
  // rather than reimplemented: the dispatcher and the executor have to derive the *same* keys, and two
135
135
  // implementations of a handshake are two chances to disagree about it.
@@ -193,7 +193,7 @@ const MAX_STAGES = 16;
193
193
  * `package.json` during `scripts/pack.mjs` rather than hand-maintained, and `W2M_PLUGIN_VERSION`
194
194
  * overrides it at runtime for tests and packagers.
195
195
  */
196
- const PLUGIN_VERSION = '0.25.0';
196
+ const PLUGIN_VERSION = '0.26.0';
197
197
 
198
198
  /** How long any single HTTP call may take before it is aborted, in milliseconds. */
199
199
  const DEFAULT_REQUEST_TIMEOUT_MS = 15_000;
@@ -5088,6 +5088,131 @@ export async function apply(ctx, config = {}) {
5088
5088
  rawInput: {},
5089
5089
  }),
5090
5090
  }));
5091
+
5092
+ /**
5093
+ * v0.25.0: the tool that makes the approval chain reachable by an operator.
5094
+ *
5095
+ * ## Why it reports refusals instead of hiding them
5096
+ *
5097
+ * Every row carries `may_act` and, when false, `why_not`. A list filtered down to what the caller may
5098
+ * answer would be shorter and **would make the fleet look idle at the moment it is most blocked** — the
5099
+ * work above their authority is exactly the work they most need to know exists.
5100
+ *
5101
+ * ## Why `actor_level` is a parameter and not read from config
5102
+ *
5103
+ * This machine's own `actorAuthorityLevel` says what it may *dispatch as*. An approver's level is a fact
5104
+ * about the person answering, and a decision made on the dispatcher's level would let a machine approve its
5105
+ * own escalations — which the index already refuses by name (`APPROVAL_SELF_APPROVAL`) when the ids match.
5106
+ * Making it explicit keeps that refusal meaningful rather than incidental.
5107
+ */
5108
+ ctx.tools.register(defineTool({
5109
+ name: 'w2m_approvals',
5110
+ description:
5111
+ 'List and settle the dispatches that are waiting for an approver. A dispatch whose actor level is ' +
5112
+ 'exactly one band below what it needs is QUEUED rather than refused, and this is where that queue is ' +
5113
+ 'read and answered. Every row reports whether YOU may act on it and why not if you may not, so work ' +
5114
+ 'above your authority is visible rather than filtered away. Settling a request does not run the ' +
5115
+ 'dispatch: approval means the next attempt is allowed, not that anything already happened.',
5116
+ parameters: {
5117
+ action: {
5118
+ type: 'string',
5119
+ enum: ['list', 'approve', 'reject'],
5120
+ description: 'list (default) shows the queue; approve and reject settle one request by approval_id.',
5121
+ default: 'list',
5122
+ },
5123
+ approval_id: {
5124
+ type: 'string',
5125
+ description: 'Which request to settle. Required for approve and reject.',
5126
+ },
5127
+ actor_id: {
5128
+ type: 'string',
5129
+ description: 'Who is answering. Defaults to this machine\'s name; it is recorded on the decision, and it is what makes a self-approval refusable.',
5130
+ },
5131
+ actor_level: {
5132
+ type: 'number',
5133
+ description: 'The authority level of the person answering, 0..100. Required to approve or reject: an approver with no level cannot be placed relative to the request, and the index refuses rather than guessing one.',
5134
+ },
5135
+ include_settled: {
5136
+ type: 'boolean',
5137
+ description: 'Also show recently settled requests. They are kept briefly as receipts, so a supervisor returning to a busy queue can tell "already dealt with" from "never seen".',
5138
+ default: false,
5139
+ },
5140
+ },
5141
+ output: jsonOutput,
5142
+ presentCall: (args) => ({
5143
+ card: 'generic',
5144
+ title: `w2m approvals ${typeof args?.action === 'string' ? args.action : 'list'}`,
5145
+ // Only `approve` and `reject` change anything; a list is a read. Labelling the whole tool 'write' would
5146
+ // make the common case -- looking at the queue -- read as an action.
5147
+ kind: args?.action === 'approve' || args?.action === 'reject' ? 'write' : 'read',
5148
+ rawInput: {},
5149
+ }),
5150
+ async execute(args, exec) {
5151
+ throwIfAborted(exec?.signal);
5152
+ const action = typeof args?.action === 'string' ? args.action : 'list';
5153
+ const queue = approvalQueue();
5154
+
5155
+ if (action === 'approve' || action === 'reject') {
5156
+ const approvalId = typeof args?.approval_id === 'string' ? args.approval_id.trim() : '';
5157
+ if (approvalId === '') {
5158
+ throw new W2MError('W2M_APPROVAL_ID', 'W2M_APPROVAL_ID: settling a request needs `approval_id`', {
5159
+ hint: 'call w2m_approvals with action="list" to see the pending ids',
5160
+ });
5161
+ }
5162
+ if (!isAuthorityLevel(args?.actor_level)) {
5163
+ // Refused rather than defaulted, and refused HERE rather than left to the index, so the message can
5164
+ // say what to do about it. A decision attributed to a level nobody supplied is a decision nobody
5165
+ // can audit.
5166
+ throw new W2MError(
5167
+ 'W2M_APPROVAL_LEVEL',
5168
+ 'W2M_APPROVAL_LEVEL: `actor_level` must be an integer 0..' + AUTHORITY_MAX + ' to settle a request',
5169
+ { hint: 'an approver with no level cannot be placed relative to the request it is answering' },
5170
+ );
5171
+ }
5172
+ const actor = { id: typeof args?.actor_id === 'string' && args.actor_id.trim() !== '' ? args.actor_id.trim() : cfg.machineName, level: args.actor_level };
5173
+ const outcome = action === 'approve' ? 'approved' : 'rejected';
5174
+ const result = queue.decide(approvalId, actor, outcome);
5175
+ return JSON.stringify({
5176
+ ok: result.ok === true,
5177
+ action,
5178
+ approval_id: approvalId,
5179
+ settled: result.ok === true ? outcome : null,
5180
+ reason_code: result.reason_code ?? null,
5181
+ detail: result.detail ?? null,
5182
+ acted_by: actor,
5183
+ // Said every time, because a reader who assumes approval ran the dispatch will wait for a result
5184
+ // that is never coming.
5185
+ note: result.ok === true
5186
+ ? 'the request is settled; the dispatch did not run and must be attempted again'
5187
+ : 'the decision was refused; the request is unchanged and still waiting',
5188
+ });
5189
+ }
5190
+
5191
+ const actor = {
5192
+ id: typeof args?.actor_id === 'string' && args.actor_id.trim() !== '' ? args.actor_id.trim() : cfg.machineName,
5193
+ level: isAuthorityLevel(args?.actor_level) ? args.actor_level : null,
5194
+ };
5195
+ // An actor with no level still gets the list: knowing what is waiting does not require the authority to
5196
+ // answer it, and a queue only its supervisors can see is a queue that stays full.
5197
+ const rows = queue.listFor(
5198
+ actor.level === null ? { id: actor.id, level: 0 } : actor,
5199
+ { includeSettled: args?.include_settled === true },
5200
+ );
5201
+ const summary = queue.summary(actor.level === null ? { id: actor.id, level: 0 } : actor);
5202
+ return JSON.stringify({
5203
+ ok: true,
5204
+ action: 'list',
5205
+ as: actor,
5206
+ level_known: actor.level !== null,
5207
+ summary,
5208
+ count: rows.length,
5209
+ rows,
5210
+ note: actor.level === null
5211
+ ? 'no actor_level was supplied, so may_act is reported as if the level were 0: the queue is visible, but whether you may answer any of it is not known'
5212
+ : 'may_act reflects the actor_level supplied',
5213
+ });
5214
+ },
5215
+ }));
5091
5216
  }
5092
5217
 
5093
5218
  /**