@opute/host-agent 0.5.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.
- package/README.md +9 -1
- package/index.js +38 -2
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -42,13 +42,21 @@ host/VM inspection tools (for example `get_host_info`, `list_vms`). The
|
|
|
42
42
|
`MCP_AUTH_TOKEN` bearer stays read-only unless the agent starts with
|
|
43
43
|
`--allow-mutations`; an OAuth client mutates only with the `mutate` scope.
|
|
44
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.
|
|
52
|
+
|
|
45
53
|
## Commands
|
|
46
54
|
|
|
47
55
|
| Command | Description |
|
|
48
56
|
|---------|-------------|
|
|
49
57
|
| `start` | Start standalone Streamable HTTP (foreground by default) |
|
|
50
58
|
| `start --background` / `-d` | Daemonize, write pid state, print MCP URL |
|
|
51
|
-
| `start --allow-mutations` | Let the `MCP_AUTH_TOKEN` bearer run tools that change the host |
|
|
59
|
+
| `start --allow-mutations` | Let the `MCP_AUTH_TOKEN` bearer run tools that change the host; creates the workload slice if it is missing |
|
|
52
60
|
| `stop` | Stop a background daemon started by this launcher |
|
|
53
61
|
| `status` | JSON status (`running`, `healthy`, `url`) |
|
|
54
62
|
| `url` | Print the MCP URL |
|
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
|
|
@@ -334,7 +367,9 @@ Commands:
|
|
|
334
367
|
start [--background|-d] [--allow-mutations]
|
|
335
368
|
Start standalone Streamable HTTP MCP (default: foreground).
|
|
336
369
|
--allow-mutations lets MCP_AUTH_TOKEN run tools that change
|
|
337
|
-
the host; without it the agent is read-only.
|
|
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)
|
|
@@ -510,6 +545,7 @@ async function main() {
|
|
|
510
545
|
requireCanonicalAgentID()
|
|
511
546
|
const background = rest.includes('--background') || rest.includes('-d')
|
|
512
547
|
const passthroughArgs = rest.filter(arg => arg !== '--background' && arg !== '-d')
|
|
548
|
+
if (passthroughArgs.includes('--allow-mutations')) ensureWorkloadSlice()
|
|
513
549
|
const binary = await resolveBinary()
|
|
514
550
|
if (background) return startBackground(binary, passthroughArgs)
|
|
515
551
|
return startForeground(binary, passthroughArgs)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opute/host-agent",
|
|
3
|
-
"version": "0.5.
|
|
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-
|
|
11
|
+
"homepage": "https://github.com/wunderous/opute-host-agent#readme",
|
|
12
12
|
"bugs": {
|
|
13
|
-
"url": "https://github.com/wunderous/host-
|
|
13
|
+
"url": "https://github.com/wunderous/opute-host-agent/issues"
|
|
14
14
|
},
|
|
15
15
|
"keywords": [
|
|
16
16
|
"mcp",
|