@opute/host-agent 0.4.0 → 0.5.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.
Files changed (3) hide show
  1. package/README.md +12 -3
  2. package/index.js +41 -7
  3. package/package.json +3 -3
package/README.md CHANGED
@@ -38,8 +38,17 @@ Point your MCP client at the printed URL (default port **3014**). When
38
38
  stdio MCP transport is not supported.
39
39
 
40
40
  Safe first-run sequence once the client is connected: `tools/list` → read-only
41
- host/VM inspection tools (for example `get_host_info`, `list_vms`). Mutating
42
- tools stay denied until `OPUTE_HOST_ALLOW_MUTATIONS=true` (0.3.x read `OPUTE_STANDALONE_ALLOW_MUTATIONS`).
41
+ host/VM inspection tools (for example `get_host_info`, `list_vms`). The
42
+ `MCP_AUTH_TOKEN` bearer stays read-only unless the agent starts with
43
+ `--allow-mutations`; an OAuth client mutates only with the `mutate` scope.
44
+
45
+ Changes run inside the systemd user slice `opute-workload.slice`, and the
46
+ agent refuses them until that slice has resource limits. With
47
+ `--allow-mutations`, the launcher creates
48
+ `~/.config/systemd/user/opute-workload.slice` with the agent's default limits,
49
+ unless systemd already has one. You can edit it to lower the limits; the agent
50
+ refuses higher ones. Without a systemd user session the start is refused, and
51
+ the message shows the slice to create by hand.
43
52
 
44
53
  ## Commands
45
54
 
@@ -47,6 +56,7 @@ tools stay denied until `OPUTE_HOST_ALLOW_MUTATIONS=true` (0.3.x read `OPUTE_STA
47
56
  |---------|-------------|
48
57
  | `start` | Start standalone Streamable HTTP (foreground by default) |
49
58
  | `start --background` / `-d` | Daemonize, write pid state, print MCP URL |
59
+ | `start --allow-mutations` | Let the `MCP_AUTH_TOKEN` bearer run tools that change the host; creates the workload slice if it is missing |
50
60
  | `stop` | Stop a background daemon started by this launcher |
51
61
  | `status` | JSON status (`running`, `healthy`, `url`) |
52
62
  | `url` | Print the MCP URL |
@@ -60,7 +70,6 @@ tools stay denied until `OPUTE_HOST_ALLOW_MUTATIONS=true` (0.3.x read `OPUTE_STA
60
70
  | `OPUTE_REMOTE_AGENT_ID` | Required explicit opaque canonical agent identity |
61
71
  | `MCP_AUTH_TOKEN` | Bearer bootstrap token for `/mcp` |
62
72
  | `OPUTE_HOST_AGENT_BINARY` | Use a local binary instead of downloading a release |
63
- | `OPUTE_HOST_ALLOW_MUTATIONS=true` | Enable mutating infrastructure tools (0.4.0 and later) |
64
73
  | `OPUTE_STANDALONE_STATE_DIR` | Local SQLite / operation journal directory |
65
74
 
66
75
  The launcher deliberately strips most other `OPUTE_*` variables so a
package/index.js CHANGED
@@ -8,7 +8,7 @@ const http = require('node:http')
8
8
  const https = require('node:https')
9
9
  const net = require('node:net')
10
10
  const zlib = require('node:zlib')
11
- const { spawn } = require('node:child_process')
11
+ const { spawn, spawnSync } = require('node:child_process')
12
12
 
13
13
  const packageVersion = require('./package.json').version
14
14
  const MAX_ARCHIVE_BYTES = 128 * 1024 * 1024
@@ -17,6 +17,39 @@ const REQUEST_TIMEOUT_MS = 15_000
17
17
  const LOCK_TIMEOUT_MS = 30_000
18
18
  const HEALTH_WAIT_MS = 15_000
19
19
 
20
+ // D56: the agent runs changes in this user slice and, under its default
21
+ // fail-closed enforcement, refuses them until the slice has limits. This is
22
+ // the text the agent's reconcile_host_resource_policy renders for it
23
+ // (opute-host-resource-policy.v2).
24
+ const WORKLOAD_SLICE = 'opute-workload.slice'
25
+ const WORKLOAD_SLICE_UNIT = '[Unit]\nDescription=Opute killable workload slice (opute-host-resource-policy.v2)\n\n[Slice]\nMemoryHigh=10G\nMemoryMax=11G\nMemorySwapMax=1G\nCPUQuota=600%\nCPUWeight=100\nTasksMax=4096\n'
26
+
27
+ function systemctlUser(...args) {
28
+ const result = spawnSync('systemctl', ['--user', ...args], { stdio: 'ignore', timeout: 15_000 })
29
+ return result.status === 0
30
+ }
31
+
32
+ // Before a start with --allow-mutations: keep any slice systemd already
33
+ // loads, otherwise write the agent's own and reload the user manager.
34
+ function ensureWorkloadSlice() {
35
+ if (systemctlUser('cat', WORKLOAD_SLICE)) return
36
+ const dir = path.join(process.env.XDG_CONFIG_HOME || path.join(os.homedir(), '.config'), 'systemd', 'user')
37
+ const file = path.join(dir, WORKLOAD_SLICE)
38
+ if (!systemctlUser('show-environment')) {
39
+ throw new Error(`--allow-mutations needs a systemd user session: the agent runs changes in ${WORKLOAD_SLICE} and refuses them until it exists. Start from a login session, or create ${file} with:\n\n${WORKLOAD_SLICE_UNIT}\nthen run: systemctl --user daemon-reload`)
40
+ }
41
+ fs.mkdirSync(dir, { recursive: true })
42
+ try {
43
+ fs.writeFileSync(file, WORKLOAD_SLICE_UNIT, { mode: 0o644, flag: 'wx' })
44
+ } catch (error) {
45
+ if (error.code !== 'EEXIST') throw error
46
+ }
47
+ if (!systemctlUser('daemon-reload') || !systemctlUser('cat', WORKLOAD_SLICE)) {
48
+ throw new Error(`systemd did not load ${file}; check it with: systemctl --user cat ${WORKLOAD_SLICE}`)
49
+ }
50
+ console.error(`created ${file}: resource limits for the agent's changes (edit it to lower them)`)
51
+ }
52
+
20
53
  function targetName() {
21
54
  const platform = process.platform
22
55
  const arch = process.arch
@@ -305,8 +338,6 @@ function buildAgentEnv(instanceId = '') {
305
338
  || key === 'OPUTE_HOST_AGENT_SHA256'
306
339
  || key === 'OPUTE_LOCAL_HOST_AGENT_RUNTIME_DIR'
307
340
  || key === 'OPUTE_STANDALONE_STATE_DIR'
308
- || key === 'OPUTE_STANDALONE_ALLOW_MUTATIONS'
309
- || key === 'OPUTE_HOST_ALLOW_MUTATIONS'
310
341
  || key === 'OPUTE_STANDALONE_ALLOW_INSECURE_DOWNLOADS'
311
342
  || key === 'OPUTE_INFRA_PROVIDER_ID'
312
343
  ) {
@@ -315,7 +346,6 @@ function buildAgentEnv(instanceId = '') {
315
346
  delete env[key]
316
347
  }
317
348
  }
318
- env.OPUTE_AGENT_MODE = 'standalone'
319
349
  if (instanceId) env.OPUTE_LOCAL_HOST_AGENT_INSTANCE_ID = instanceId
320
350
  env.HOST_MCP_BIND_HOST = bindHost()
321
351
  env.HOST_MCP_PORT = String(mcpPort())
@@ -334,7 +364,12 @@ function printUsage() {
334
364
  console.log(`Usage: opute-host-agent <command>
335
365
 
336
366
  Commands:
337
- start [--background|-d] Start standalone Streamable HTTP MCP (default: foreground)
367
+ start [--background|-d] [--allow-mutations]
368
+ Start standalone Streamable HTTP MCP (default: foreground).
369
+ --allow-mutations lets MCP_AUTH_TOKEN run tools that change
370
+ the host; without it the agent is read-only. It also
371
+ creates ~/.config/systemd/user/opute-workload.slice
372
+ (the limits changes run under) unless one exists.
338
373
  stop Stop a background daemon started by this launcher
339
374
  status Show daemon/listener status and MCP URL
340
375
  url Print the MCP URL (http://127.0.0.1:3014/mcp by default)
@@ -345,8 +380,6 @@ Environment:
345
380
  OPUTE_REMOTE_AGENT_ID Required explicit opaque canonical agent id
346
381
  MCP_AUTH_TOKEN Bearer token required by /mcp when set
347
382
  OPUTE_HOST_AGENT_BINARY Use a local binary instead of downloading a release
348
- OPUTE_HOST_ALLOW_MUTATIONS=true Enable mutating tools (0.4.0 and later)
349
- OPUTE_STANDALONE_ALLOW_MUTATIONS=true Enable mutating tools (0.3.x; ignored from 0.4.0)
350
383
 
351
384
  MCP client config (include Authorization when MCP_AUTH_TOKEN is set):
352
385
  {
@@ -512,6 +545,7 @@ async function main() {
512
545
  requireCanonicalAgentID()
513
546
  const background = rest.includes('--background') || rest.includes('-d')
514
547
  const passthroughArgs = rest.filter(arg => arg !== '--background' && arg !== '-d')
548
+ if (passthroughArgs.includes('--allow-mutations')) ensureWorkloadSlice()
515
549
  const binary = await resolveBinary()
516
550
  if (background) return startBackground(binary, passthroughArgs)
517
551
  return startForeground(binary, passthroughArgs)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opute/host-agent",
3
- "version": "0.4.0",
3
+ "version": "0.5.1",
4
4
  "description": "Local Streamable HTTP launcher for the Opute host agent",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -8,9 +8,9 @@
8
8
  "url": "https://github.com/wunderous/host-agents.git",
9
9
  "directory": "npm/local-host-agent"
10
10
  },
11
- "homepage": "https://github.com/wunderous/host-agents#readme",
11
+ "homepage": "https://github.com/wunderous/opute-host-agent#readme",
12
12
  "bugs": {
13
- "url": "https://github.com/wunderous/host-agents/issues"
13
+ "url": "https://github.com/wunderous/opute-host-agent/issues"
14
14
  },
15
15
  "keywords": [
16
16
  "mcp",