@ours.network/install 1.2.1-nightly.1 → 1.2.1-nightly.3
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 +94 -126
- package/assets/Dockerfile +1 -0
- package/assets/docker-compose.yaml +20 -0
- package/assets/release-lock.json +6 -6
- package/assets/release.json +1 -1
- package/assets/scripts/runtime/legacy-import.mjs +103 -0
- package/assets/sources.json +1 -1
- package/install.mjs +2 -2
- package/lib/build-transition.mjs +13 -7
- package/lib/effects.mjs +99 -30
- package/lib/fleet-settings.mjs +43 -0
- package/lib/legacy-migration.mjs +202 -0
- package/lib/legacy-state.mjs +205 -0
- package/lib/managed-cli.mjs +164 -0
- package/lib/orchestrate.mjs +69 -24
- package/lib/prompt.mjs +113 -119
- package/lib/server-onboarding.mjs +114 -0
- package/lib/setup-options.mjs +253 -0
- package/lib/setup.mjs +155 -0
- package/lib/usage.mjs +49 -44
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,141 +1,98 @@
|
|
|
1
|
-
# @ours.network/install —
|
|
1
|
+
# @ours.network/install — one installer for the whole stack
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
configures the shared daemon, MCP adapter, cowork, Telegram connector, Fleet,
|
|
5
|
-
and plugins for every safely detected agent harness.
|
|
3
|
+
Requires Node.js 22+ and npm. Install the selected release channel:
|
|
6
4
|
|
|
7
5
|
```sh
|
|
8
|
-
npm install
|
|
6
|
+
npm install -g @ours.network/install@nightly
|
|
9
7
|
ours-install
|
|
10
8
|
```
|
|
11
9
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
do not. MCP and the Codex launcher are installed by exact version, and local
|
|
20
|
-
Claude Code and Codex marketplace manifests pin the corresponding plugin
|
|
21
|
-
packages to that same version.
|
|
22
|
-
|
|
23
|
-
`OURS_CHANNEL=latest|nightly` (or the legacy `OURS_INSTALL_CHANNEL`) remains an
|
|
24
|
-
explicit override. Without an override, the installed package's own version
|
|
25
|
-
selects the channel.
|
|
26
|
-
|
|
27
|
-
The normal flow uses one daemon at `~/.ours` on port 3050, shows an eight-stage
|
|
28
|
-
progress bar, and asks only for information it cannot safely infer (normally the
|
|
29
|
-
Human identity's display name). Existing daemon conflicts and moving a Telegram
|
|
30
|
-
connector from another daemon still require explicit confirmation.
|
|
31
|
-
|
|
32
|
-
## What the installer does
|
|
33
|
-
|
|
34
|
-
- Installs `@ours.network/cli`, `@ours.network/mcp`,
|
|
35
|
-
`@ours.network/tg-connector`, `@ours.network/cowork`, and
|
|
36
|
-
`@ours.network/fleet` on one release channel.
|
|
37
|
-
- Configures, starts, and enables the single shared daemon with a CLI-managed
|
|
38
|
-
user systemd service on Linux or LaunchAgent on macOS.
|
|
39
|
-
- Creates the daemon's Human identity (historically called the root identity),
|
|
40
|
-
or preserves the existing one on a re-run.
|
|
41
|
-
- Installs the ours plugin into safely detected Claude Code, Codex, and Hermes
|
|
42
|
-
installations.
|
|
43
|
-
- Configures and starts cowork as a durable shim over the shared daemon.
|
|
44
|
-
- Configures and starts Telegram as a durable shim over the same daemon.
|
|
45
|
-
- Runs Fleet's native initialization through prepared settings or its interactive wizard. Fleet owns and
|
|
46
|
-
publishes its v2 configuration, including subscriptions, models, roles,
|
|
47
|
-
templates, and permissions. The installer does not start Fleet roles.
|
|
48
|
-
|
|
49
|
-
The operator CLI owns daemon configuration, lifecycle, and boot persistence.
|
|
50
|
-
The MCP package is only the stdio adapter spawned by agent harnesses; the
|
|
51
|
-
installer never asks `ours-mcp` to start a daemon.
|
|
52
|
-
|
|
53
|
-
Daemon state is temporarily scoped to its package major version. On a same-major
|
|
54
|
-
update, the installer refreshes the packages and runs `ours daemon restart`; the
|
|
55
|
-
CLI streams structured startup phases until restore is complete instead of
|
|
56
|
-
appearing to hang. A different-major update is detected before package
|
|
57
|
-
replacement. The installer explains the incompatibility and, only in an
|
|
58
|
-
interactive run, offers to stop the CLI-managed daemon, copy the complete state
|
|
59
|
-
directory to a timestamped directory under `~/.ours-backups/`, remove the
|
|
60
|
-
managed service and old state, then initialize the new major. The default answer is no, and
|
|
61
|
-
`OURS_ASSUME_YES` never authorizes this purge.
|
|
62
|
-
|
|
63
|
-
## What remains stopped
|
|
64
|
-
|
|
65
|
-
Only Fleet is intentionally not started. Review and activate it when ready:
|
|
10
|
+
With no arguments, the wizard explains each step and offers keyboard choices.
|
|
11
|
+
Use arrow keys and Enter to choose, and Space to select integrations. Recommended
|
|
12
|
+
settings keep advanced ports and package overrides out of the usual flow. Text
|
|
13
|
+
input is used for your name and explicitly customized paths or ports. Linux x64
|
|
14
|
+
recommends native mode; macOS and Windows recommend Docker. On Windows run the
|
|
15
|
+
installer inside WSL with Docker Desktop integration. This recommendation concerns
|
|
16
|
+
packaging and isolation, not a guarantee that emulated x64 is faster on ARM Macs.
|
|
66
17
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
ours-fleet config
|
|
71
|
-
ours-fleet up
|
|
72
|
-
ours-fleet ls
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
The final installer screen repeats these commands and provides a copy-paste
|
|
76
|
-
prompt for Claude Code, Codex, or Hermes. The agent should guide local bot-token
|
|
77
|
-
entry without asking the user to paste the secret into chat.
|
|
78
|
-
|
|
79
|
-
## Preview and automation
|
|
18
|
+
The same installer accepts complete CLI presets. It reports missing answers before
|
|
19
|
+
changing the machine and never opens hidden prompts when arguments are supplied.
|
|
20
|
+
Both forms show the same preparation, identity, update and readiness progress.
|
|
80
21
|
|
|
81
22
|
```sh
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
23
|
+
# Whole stack, with prepared Fleet settings and no interactive prompts:
|
|
24
|
+
ours-install --mode docker --state-dir "$HOME/ours-docker" \
|
|
25
|
+
--identity-name "Your Name" --integrations codex,fleet \
|
|
26
|
+
--fleet-settings "$HOME/fleet-settings.json"
|
|
27
|
+
|
|
28
|
+
# Native server only; native and packages mean the same mode:
|
|
29
|
+
ours-install server --mode native --state-dir "$HOME/ours-native" \
|
|
30
|
+
--identity-name "Your Name"
|
|
31
|
+
|
|
32
|
+
# Clients connected to an existing server:
|
|
33
|
+
ours-install client --config /private/client/profile.json \
|
|
34
|
+
--integrations codex,fleet --fleet-settings /private/fleet-settings.json
|
|
35
|
+
|
|
36
|
+
# Update a retained complete installation and its clients:
|
|
37
|
+
ours-install all update --mode docker --state-dir "$HOME/ours-docker" \
|
|
38
|
+
--identity-name "Your Name" --integrations codex,fleet \
|
|
39
|
+
--fleet-settings "$HOME/fleet-settings.json" --compatible
|
|
85
40
|
```
|
|
86
41
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
A non-default daemon must be selected coherently with a config file or matching
|
|
93
|
-
port and state directory. Hermes and the generated Fleet role persist that
|
|
94
|
-
selection through `OURS_CONFIG`. Claude Code and Codex plugin registrations
|
|
95
|
-
cannot store an environment value; for those harnesses the installer prints the
|
|
96
|
-
exact `export OURS_CONFIG=...` line that must be added to the shell profile
|
|
97
|
-
before starting the harness. There is no per-application daemon.
|
|
98
|
-
|
|
99
|
-
`OURS_CONFIG` may also name a prepared private host profile containing the
|
|
100
|
-
complete `endpoint`, `expectedInstanceId`, and absolute `credentialPath` tuple.
|
|
101
|
-
The profile and credential must already be regular current-user files with
|
|
102
|
-
private permissions. In this mode the installer verifies `/selection` before
|
|
103
|
-
sending the credential to `/version`, installs only MCP, detected Claude/Codex
|
|
104
|
-
plugins, and Fleet client support, and never creates, starts, stops, or services
|
|
105
|
-
a host daemon. Telegram, cowork, messenger, daemon voice, and daemon state stay
|
|
106
|
-
Compose-owned. If `OURS_CONFIG` is unset, the same profile is discovered at
|
|
107
|
-
`~/.ours/config.json`; a legacy config there keeps the existing local behavior.
|
|
108
|
-
|
|
109
|
-
## Uninstall
|
|
42
|
+
`server` and `client` are presets of the same flow, not separate interactive
|
|
43
|
+
installers. `--integrations none` explicitly skips client integrations. Use
|
|
44
|
+
`--dry-run` with a complete preset to preview it, and `--help` for all options.
|
|
45
|
+
Fleet's own wizard is available only in interactive setup; CLI Fleet setup requires
|
|
46
|
+
its JSON settings file. Fleet stays stopped until you review and activate it.
|
|
110
47
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
state is retained by default. Purging requires the existing destructive gates and
|
|
118
|
-
targets only the explicit state directory.
|
|
48
|
+
The server installs the daemon/SDK/CLI, main MCP, Telegram, Cowork and Messenger.
|
|
49
|
+
It starts the daemon, preserves the existing Human identity (or creates it once),
|
|
50
|
+
then starts its applications. Full-stack setup issues a separate local client
|
|
51
|
+
credential and configures the selected Codex, Claude Code and Fleet integrations.
|
|
52
|
+
Existing identity keys and names are retained on update. An update's storage
|
|
53
|
+
compatibility must be reviewed before supplying `--compatible`.
|
|
119
54
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
55
|
+
The installer embeds exact component versions and SHA-512 values for its release.
|
|
56
|
+
An existing server's retained release selects matching local clients. Secrets are
|
|
57
|
+
read from protected files, and client setup never copies the daemon API master.
|
|
123
58
|
|
|
124
|
-
##
|
|
59
|
+
## Migrate an existing global installation
|
|
125
60
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
both channels.
|
|
61
|
+
The wizard detects the old `~/.ours/config.json` and offers to keep its identities,
|
|
62
|
+
messages, keys and settings in the new installation. It follows the configured
|
|
63
|
+
state directory, including a custom location. An equivalent unattended preset is:
|
|
130
64
|
|
|
131
|
-
|
|
65
|
+
```sh
|
|
66
|
+
ours-install all --mode docker --state-dir "$HOME/ours-docker" \
|
|
67
|
+
--migrate-from "$HOME/.ours/config.json" --compatible --integrations codex
|
|
68
|
+
```
|
|
132
69
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
70
|
+
Run the old daemon before the first migration so the installer can record and
|
|
71
|
+
verify its identities. The new runtime is downloaded/built first. Then the old
|
|
72
|
+
boot service and daemon stop, and the complete daemon state is copied while its
|
|
73
|
+
writer lock is held. Docker migration imports that copy into its named storage
|
|
74
|
+
volume. Existing Human/role names and CIDs must match before applications start;
|
|
75
|
+
migration never creates a replacement Human.
|
|
76
|
+
|
|
77
|
+
The original state/configuration remain unchanged. A private `legacy-backup`
|
|
78
|
+
directory stores the original config/service definition, and
|
|
79
|
+
`legacy-client/profile.json` is a prepared connection profile for the new server.
|
|
80
|
+
Selected integrations are configured by the usual client setup. The global `ours` command is switched to a launcher for the managed installation
|
|
81
|
+
only after verifying ownership of its existing npm entry; foreign or read-only
|
|
82
|
+
commands are refused before migration. Ordinary `ours identity list` is checked
|
|
83
|
+
after cutover. Lifecycle commands manage the new installation, and selection
|
|
84
|
+
overrides cannot accidentally return to the old daemon. The old configuration is
|
|
85
|
+
not reinterpreted as a client profile. Do not start the old state alongside the
|
|
86
|
+
migrated daemon. Reinstalling the global CLI with npm can replace the launcher;
|
|
87
|
+
repeat the same migration command to verify and repair that routing.
|
|
88
|
+
|
|
89
|
+
Repeat the same command after an interruption. Once the destination has started,
|
|
90
|
+
retries repair it in place instead of replacing it with an older source snapshot.
|
|
91
|
+
The source is kept stopped after an activation failure to avoid diverging identity
|
|
92
|
+
sessions. Migration requires local Linux/macOS (or WSL) with `node:sqlite` support,
|
|
93
|
+
a verifiable old CLI/service, and a separate target directory. External PostgreSQL
|
|
94
|
+
history or unsupported external MCP/token-delivery paths are refused before
|
|
95
|
+
shutdown. Unrelated application data outside the daemon tree is not copied.
|
|
139
96
|
|
|
140
97
|
## Selected network installations (2.0)
|
|
141
98
|
|
|
@@ -145,15 +102,15 @@ SHA-512 values. Acquisition validates the ours dependency graph before activatio
|
|
|
145
102
|
A development override without a release binding is not a qualified product release.
|
|
146
103
|
|
|
147
104
|
```sh
|
|
148
|
-
ours-install server install --mode docker --state-dir /private/ours-install
|
|
149
|
-
ours-install server install --mode packages --state-dir /private/ours-install
|
|
105
|
+
ours-install server install --mode docker --state-dir /private/ours-install --identity-name "Your Name"
|
|
106
|
+
ours-install server install --mode packages --state-dir /private/ours-install --identity-name "Your Name"
|
|
150
107
|
ours-install server status --state-dir /private/ours-install
|
|
151
108
|
ours-install server stop --state-dir /private/ours-install
|
|
152
109
|
ours-install server start --state-dir /private/ours-install
|
|
153
110
|
ours-install server restart --state-dir /private/ours-install
|
|
154
111
|
```
|
|
155
112
|
|
|
156
|
-
Choose one mode
|
|
113
|
+
Choose one mode and a folder for its programs and data. The private `installation.json`
|
|
157
114
|
records mode, instance selection, configuration/source paths and service selection;
|
|
158
115
|
it never records master bytes or an issued-token registry. The selected policy
|
|
159
116
|
is resolved to an exact, role-filtered `sources.json` before acquisition.
|
|
@@ -169,6 +126,17 @@ Linux/WSL or a launchd GUI user domain on macOS. Source builds also require Git,
|
|
|
169
126
|
Python 3, a C/C++ toolchain, make, and the selected repositories' own prerequisites.
|
|
170
127
|
Docker mode requires a working Docker engine and Compose 2.35+; its build image
|
|
171
128
|
contains the source-build prerequisites. No bind or Docker socket mounts are used.
|
|
129
|
+
Docker is recommended for macOS and Windows. Install and start Docker Desktop
|
|
130
|
+
on those hosts; on Linux, install Docker Engine and the Compose plugin. If Docker
|
|
131
|
+
is unavailable, the installer explains how to install/start it or use
|
|
132
|
+
`server install --mode packages --state-dir <new-empty-directory>` instead.
|
|
133
|
+
Native Windows installations require WSL with a working systemd user manager.
|
|
134
|
+
The installer never switches an existing installation's mode automatically.
|
|
135
|
+
Server installation shows each stage before it starts, streams Docker builds and
|
|
136
|
+
native package acquisition, and reports completion only after service readiness.
|
|
137
|
+
If a Docker service fails, the error includes its last 50 log lines (bounded in
|
|
138
|
+
size) and a command to inspect the logs. A failed daemon prevents consumers from
|
|
139
|
+
starting; a failed consumer does not prevent checks of unrelated consumers.
|
|
172
140
|
Server runtime installation selects SDK/CLI, main MCP, Telegram, Cowork and
|
|
173
141
|
Messenger. Main MCP is injected into the daemon, not started as a second daemon.
|
|
174
142
|
The daemon starts first; consumers are checked through their owning readiness
|
|
@@ -219,7 +187,7 @@ client-owned installer settings:
|
|
|
219
187
|
```
|
|
220
188
|
|
|
221
189
|
```sh
|
|
222
|
-
ours-install client install --config /private/client/profile.json
|
|
190
|
+
ours-install client install --config /private/client/profile.json --integrations codex,claude-code
|
|
223
191
|
```
|
|
224
192
|
|
|
225
193
|
Optional `sourcesPath` and `fleetSettingsPath` values are absolute or resolved
|
|
@@ -269,7 +237,7 @@ For a managed server, maintenance runs on the server machine through the install
|
|
|
269
237
|
ours-install server backup server snapshot --state-dir /path/to/installation
|
|
270
238
|
ours-install server restore server snapshot --state-dir /path/to/installation
|
|
271
239
|
ours-install server rebuild --state-dir /path/to/installation
|
|
272
|
-
ours-install server update --state-dir /path/to/installation --compatible
|
|
240
|
+
ours-install server update --mode docker --state-dir /path/to/installation --identity-name "Your Name" --compatible
|
|
273
241
|
```
|
|
274
242
|
|
|
275
243
|
Backup and restore support the full server or an individual `daemon`, `telegram`,
|
package/assets/Dockerfile
CHANGED
|
@@ -21,6 +21,7 @@ COPY scripts/runtime/runtime-common.mjs /opt/ours/docker/runtime-common.mjs
|
|
|
21
21
|
COPY scripts/runtime/check-client.mjs /opt/ours/docker/check-client.mjs
|
|
22
22
|
COPY scripts/runtime/check-start.mjs /opt/ours/docker/check-start.mjs
|
|
23
23
|
COPY scripts/runtime/client-setup.mjs /opt/ours/docker/client-setup.mjs
|
|
24
|
+
COPY scripts/runtime/legacy-import.mjs /opt/ours/docker/legacy-import.mjs
|
|
24
25
|
COPY scripts/runtime/entrypoint.sh /opt/ours/docker/entrypoint.sh
|
|
25
26
|
COPY scripts/runtime/healthcheck.mjs /opt/ours/docker/healthcheck.mjs
|
|
26
27
|
COPY scripts/runtime/start-telegram.sh scripts/runtime/health-telegram.sh scripts/runtime/start-cowork.sh scripts/runtime/health-cowork.sh scripts/runtime/start-messenger.sh scripts/runtime/health-messenger.mjs /opt/ours/docker/
|
|
@@ -177,6 +177,26 @@ services:
|
|
|
177
177
|
start_period: 30s
|
|
178
178
|
retries: 12
|
|
179
179
|
|
|
180
|
+
legacy-import:
|
|
181
|
+
profiles: [maintenance]
|
|
182
|
+
build:
|
|
183
|
+
<<: *source-build
|
|
184
|
+
target: maintenance
|
|
185
|
+
platform: linux/amd64
|
|
186
|
+
image: "${OURS_MAINTENANCE_IMAGE:-ours-compose-2-maintenance:local}"
|
|
187
|
+
user: "0:0"
|
|
188
|
+
network_mode: none
|
|
189
|
+
read_only: true
|
|
190
|
+
cap_drop: [ALL]
|
|
191
|
+
cap_add: [CHOWN, DAC_OVERRIDE]
|
|
192
|
+
security_opt: [no-new-privileges:true]
|
|
193
|
+
entrypoint: [node, /opt/ours/docker/legacy-import.mjs]
|
|
194
|
+
environment:
|
|
195
|
+
OURS_UID: "${OURS_UID:-1000}"
|
|
196
|
+
OURS_GID: "${OURS_GID:-1000}"
|
|
197
|
+
volumes:
|
|
198
|
+
- {type: volume, source: server-storage, target: /storage, volume: {nocopy: true}}
|
|
199
|
+
|
|
180
200
|
state-operation:
|
|
181
201
|
profiles: [maintenance]
|
|
182
202
|
build:
|
package/assets/release-lock.json
CHANGED
|
@@ -565,9 +565,9 @@
|
|
|
565
565
|
]
|
|
566
566
|
},
|
|
567
567
|
"node_modules/@anthropic-ai/sdk": {
|
|
568
|
-
"version": "0.
|
|
569
|
-
"resolved": "https://registry.npmjs.org/@anthropic-ai/sdk/-/sdk-0.
|
|
570
|
-
"integrity": "sha512-
|
|
568
|
+
"version": "0.127.0",
|
|
569
|
+
"resolved": "https://registry.npmjs.org/@anthropic-ai/sdk/-/sdk-0.127.0.tgz",
|
|
570
|
+
"integrity": "sha512-OKiVbG9LHCxjn4fBJZJFy/Bz3hqE1RYpwaeSEDNheQnvz0XNKmGT/Lhkz2Sf1a27Ldt3vVv+BkU81I0U/8EpoQ==",
|
|
571
571
|
"license": "MIT",
|
|
572
572
|
"optional": true,
|
|
573
573
|
"peer": true,
|
|
@@ -811,9 +811,9 @@
|
|
|
811
811
|
}
|
|
812
812
|
},
|
|
813
813
|
"node_modules/@fastify/websocket": {
|
|
814
|
-
"version": "11.3.
|
|
815
|
-
"resolved": "https://registry.npmjs.org/@fastify/websocket/-/websocket-11.3.
|
|
816
|
-
"integrity": "sha512-
|
|
814
|
+
"version": "11.3.1",
|
|
815
|
+
"resolved": "https://registry.npmjs.org/@fastify/websocket/-/websocket-11.3.1.tgz",
|
|
816
|
+
"integrity": "sha512-3117Fteg0MC9zRl0ilNAQelRb+PNDvNuWe0yJ+jnLthaPPZnlml+GraGpesNUEQvLl8+3C+W4aKZz10XmQ10Mg==",
|
|
817
817
|
"funding": [
|
|
818
818
|
{
|
|
819
819
|
"type": "github",
|
package/assets/release.json
CHANGED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/** Import a stopped, read-only host migration stage into the managed Docker volume. */
|
|
2
|
+
import * as fs from 'node:fs';
|
|
3
|
+
import { dirname, join, resolve, isAbsolute } from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { randomUUID } from 'node:crypto';
|
|
6
|
+
// Repository layout and the maintenance image intentionally place this binding differently.
|
|
7
|
+
const nativeModule = new URL('../maintenance/state-native.mjs', import.meta.url);
|
|
8
|
+
const { publishNoReplace } = await import(fs.existsSync(nativeModule) ? nativeModule.href : new URL('./state-native.mjs', import.meta.url).href);
|
|
9
|
+
|
|
10
|
+
const MARKER = '.ours-legacy-import.json';
|
|
11
|
+
const COMPONENTS = ['mcp', 'daemon'];
|
|
12
|
+
const fail = message => { throw Error(`Legacy volume import: ${message}`); };
|
|
13
|
+
function canonical(path) {
|
|
14
|
+
if (typeof path !== 'string' || !isAbsolute(path) || resolve(path) !== path) fail('paths must be normalized absolute paths');
|
|
15
|
+
if (fs.realpathSync(path) !== path) fail('symlink paths are not supported');
|
|
16
|
+
}
|
|
17
|
+
function privateEntry(path, uid, gid, directory) {
|
|
18
|
+
const stat = fs.lstatSync(path);
|
|
19
|
+
if (!(directory ? stat.isDirectory() : stat.isFile()) || stat.isSymbolicLink()
|
|
20
|
+
|| stat.uid !== uid || stat.gid !== gid
|
|
21
|
+
|| (directory ? (stat.mode & 0o7777) !== 0o700 : ((stat.mode & 0o7077) !== 0 || !(stat.mode & 0o400)))
|
|
22
|
+
|| (!directory && stat.nlink !== 1)) fail('unsafe ownership, permissions, or linked state entry');
|
|
23
|
+
return stat;
|
|
24
|
+
}
|
|
25
|
+
function scan(root, uid, gid) {
|
|
26
|
+
const entries = [];
|
|
27
|
+
function visit(path, relative) {
|
|
28
|
+
const stat = fs.lstatSync(path), directory = stat.isDirectory();
|
|
29
|
+
privateEntry(path, uid, gid, directory); entries.push({ relative, directory, mode: stat.mode & 0o700 });
|
|
30
|
+
if (directory) for (const name of fs.readdirSync(path).sort()) visit(join(path, name), relative ? join(relative, name) : name);
|
|
31
|
+
}
|
|
32
|
+
canonical(root); visit(root, ''); return entries;
|
|
33
|
+
}
|
|
34
|
+
function readReceipt(root, uid, gid, targetRoot) {
|
|
35
|
+
privateEntry(join(root, MARKER), uid, gid, false);
|
|
36
|
+
const value = JSON.parse(fs.readFileSync(join(root, MARKER), 'utf8'));
|
|
37
|
+
const keys = ['sourceStateDir', 'sourceConfigPath', 'targetRoot', 'rootName'];
|
|
38
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)
|
|
39
|
+
|| Object.keys(value).sort().join('\0') !== [...keys].sort().join('\0')
|
|
40
|
+
|| keys.some(key => typeof value[key] !== 'string' || !value[key])
|
|
41
|
+
|| value.targetRoot !== targetRoot
|
|
42
|
+
|| ['sourceStateDir', 'sourceConfigPath', 'targetRoot'].some(key => !isAbsolute(value[key]) || resolve(value[key]) !== value[key])) fail('invalid or mismatched migration receipt');
|
|
43
|
+
return Object.fromEntries(keys.map(key => [key, value[key]]));
|
|
44
|
+
}
|
|
45
|
+
const same = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
|
46
|
+
function existingDestination(path, expected, uid, gid, targetRoot) {
|
|
47
|
+
if (!fs.existsSync(path)) return false;
|
|
48
|
+
canonical(path); privateEntry(path, uid, gid, true);
|
|
49
|
+
if (!fs.readdirSync(path).length) return false;
|
|
50
|
+
if (!fs.existsSync(join(path, MARKER)) || !same(readReceipt(path, uid, gid, targetRoot), expected)) fail('nonmatching existing destination');
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
function makeDirectory(path, uid, gid) {
|
|
54
|
+
if (!fs.existsSync(path)) { fs.mkdirSync(path, { mode: 0o700 }); fs.chownSync(path, uid, gid); }
|
|
55
|
+
canonical(path); privateEntry(path, uid, gid, true);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Caller holds installation exclusion and has stopped all destination writers. */
|
|
59
|
+
export function importLegacyVolume({ sourceRoot = '/legacy-import', storageRoot = '/storage', targetRoot, uid, gid }) {
|
|
60
|
+
if (![uid, gid].every(value => Number.isSafeInteger(value) && value >= 0)) fail('numeric target UID/GID required');
|
|
61
|
+
if (typeof targetRoot !== 'string' || !isAbsolute(targetRoot) || resolve(targetRoot) !== targetRoot) fail('expected target root required');
|
|
62
|
+
canonical(sourceRoot); canonical(storageRoot);
|
|
63
|
+
const sourceOwner = fs.lstatSync(sourceRoot);
|
|
64
|
+
privateEntry(sourceRoot, sourceOwner.uid, sourceOwner.gid, true);
|
|
65
|
+
const sources = COMPONENTS.map(component => {
|
|
66
|
+
const path = join(sourceRoot, component);
|
|
67
|
+
const entries = scan(path, sourceOwner.uid, sourceOwner.gid);
|
|
68
|
+
return { component, path, entries, receipt: readReceipt(path, sourceOwner.uid, sourceOwner.gid, targetRoot) };
|
|
69
|
+
});
|
|
70
|
+
if (!same(sources[0].receipt, sources[1].receipt)) fail('source daemon and MCP receipts differ');
|
|
71
|
+
const rootStat = fs.lstatSync(storageRoot);
|
|
72
|
+
const freshRoot = rootStat.isDirectory() && rootStat.uid === 0 && rootStat.gid === 0 && fs.readdirSync(storageRoot).length === 0;
|
|
73
|
+
if (!freshRoot) privateEntry(storageRoot, uid, gid, true);
|
|
74
|
+
const state = join(storageRoot, 'state');
|
|
75
|
+
if (fs.existsSync(state)) { canonical(state); privateEntry(state, uid, gid, true); }
|
|
76
|
+
// Validate every existing destination before changing even an empty volume.
|
|
77
|
+
for (const source of sources) source.reused = existingDestination(join(state, source.component), source.receipt, uid, gid, targetRoot);
|
|
78
|
+
if (freshRoot) { fs.chmodSync(storageRoot, 0o700); fs.chownSync(storageRoot, uid, gid); }
|
|
79
|
+
makeDirectory(state, uid, gid);
|
|
80
|
+
for (const source of sources) {
|
|
81
|
+
if (source.reused) continue;
|
|
82
|
+
const destination = join(state, source.component), staging = join(state, `.legacy-import-${randomUUID()}`);
|
|
83
|
+
try {
|
|
84
|
+
fs.cpSync(source.path, staging, { recursive: true, errorOnExist: true, force: false });
|
|
85
|
+
for (const entry of [...source.entries].reverse()) {
|
|
86
|
+
const path = entry.relative ? join(staging, entry.relative) : staging;
|
|
87
|
+
fs.chmodSync(path, entry.mode); fs.chownSync(path, uid, gid);
|
|
88
|
+
}
|
|
89
|
+
scan(staging, uid, gid);
|
|
90
|
+
if (!same(readReceipt(staging, uid, gid, targetRoot), source.receipt)) fail('copied receipt changed');
|
|
91
|
+
if (fs.existsSync(destination)) fs.rmdirSync(destination); // empty skeleton only
|
|
92
|
+
publishNoReplace(staging, destination);
|
|
93
|
+
} finally { fs.rmSync(staging, { recursive: true, force: true }); }
|
|
94
|
+
}
|
|
95
|
+
return { imported: sources.filter(source => !source.reused).map(source => source.component), retained: sources.filter(source => source.reused).map(source => source.component) };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
99
|
+
try {
|
|
100
|
+
importLegacyVolume({ targetRoot: process.env.OURS_LEGACY_TARGET_ROOT, uid: Number(process.env.OURS_UID), gid: Number(process.env.OURS_GID) });
|
|
101
|
+
console.log('Legacy daemon and MCP state imported into the selected volume.');
|
|
102
|
+
} catch (error) { console.error(error.message); process.exitCode = 1; }
|
|
103
|
+
}
|
package/assets/sources.json
CHANGED
package/install.mjs
CHANGED
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
import { readFileSync } from 'node:fs';
|
|
4
4
|
|
|
5
5
|
import { realEffects } from './lib/effects.mjs';
|
|
6
|
-
import {
|
|
6
|
+
import { runSetup } from './lib/setup.mjs';
|
|
7
7
|
import { closeSync, makeWriter, openTty } from './lib/ui.mjs';
|
|
8
8
|
|
|
9
9
|
const version = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf8')).version;
|
|
10
10
|
const ttyFd = openTty();
|
|
11
11
|
|
|
12
12
|
try {
|
|
13
|
-
const code = await
|
|
13
|
+
const code = await runSetup(process.argv.slice(2), realEffects({
|
|
14
14
|
write: makeWriter(ttyFd),
|
|
15
15
|
ttyFd,
|
|
16
16
|
env: process.env,
|
package/lib/build-transition.mjs
CHANGED
|
@@ -2,10 +2,16 @@ import { readFileSync } from 'node:fs';
|
|
|
2
2
|
import { createHash } from 'node:crypto';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
4
|
import { validateInstallation } from './plan.mjs';
|
|
5
|
+
import { info, ok, warn } from './ui.mjs';
|
|
5
6
|
|
|
6
7
|
/** The caller holds the installation lock; installation.json owns retry state. */
|
|
7
8
|
export async function serverBuildTransition(record, args, effects) {
|
|
8
9
|
validateInstallation(record, record.root);
|
|
10
|
+
const stage = async (label, action) => {
|
|
11
|
+
effects.out?.(info(label));
|
|
12
|
+
try { const result = await action(); effects.out?.(ok(`${label} complete`)); return result; }
|
|
13
|
+
catch (error) { effects.out?.(warn(`Server ${args.operation} stopped during ${label.toLowerCase()}.`)); throw error; }
|
|
14
|
+
};
|
|
9
15
|
const path = join(record.root, 'installation.json');
|
|
10
16
|
const save = transition => {
|
|
11
17
|
record = { ...record, buildTransition: transition };
|
|
@@ -14,9 +20,9 @@ export async function serverBuildTransition(record, args, effects) {
|
|
|
14
20
|
};
|
|
15
21
|
let transition = record.buildTransition;
|
|
16
22
|
if (!transition) {
|
|
17
|
-
const candidate = await effects.prepareServerBuild(record, args);
|
|
23
|
+
const candidate = await stage('Prepare the updated runtime', () => effects.prepareServerBuild(record, args));
|
|
18
24
|
try {
|
|
19
|
-
await effects.checkServerBuild(record, candidate, !!args.compatible, args.operation);
|
|
25
|
+
await stage('Verify package and stored-state compatibility', () => effects.checkServerBuild(record, candidate, !!args.compatible, args.operation));
|
|
20
26
|
transition = { operation: args.operation, candidate, compatible: !!args.compatible,
|
|
21
27
|
...(args.sources ? { sourcePolicyHash: createHash('sha256').update(readFileSync(args.sources)).digest('hex') } : {}),
|
|
22
28
|
runningServices: await effects.serverLifecycle(record, 'status'), phase: 'prepared' };
|
|
@@ -34,19 +40,19 @@ export async function serverBuildTransition(record, args, effects) {
|
|
|
34
40
|
const { candidate, runningServices } = transition;
|
|
35
41
|
// A failed readiness check can leave some new services running. Every retry
|
|
36
42
|
// excludes those writers again and retains the original requested running set.
|
|
37
|
-
await effects.retireServerBuildRuntime(record);
|
|
43
|
+
await stage('Stop services before updating stored state', () => effects.retireServerBuildRuntime(record));
|
|
38
44
|
if (transition.phase === 'prepared') {
|
|
39
|
-
await effects.updateServerBuildState(record, candidate, transition.compatible, transition.operation);
|
|
45
|
+
await stage('Update stored state while retaining identities and credentials', () => effects.updateServerBuildState(record, candidate, transition.compatible, transition.operation));
|
|
40
46
|
transition = { ...transition, phase: 'state-updated' };
|
|
41
47
|
save(transition);
|
|
42
48
|
}
|
|
43
49
|
if (transition.phase === 'state-updated') {
|
|
44
|
-
await effects.publishServerBuild(record, candidate);
|
|
50
|
+
await stage('Activate the prepared runtime', () => effects.publishServerBuild(record, candidate));
|
|
45
51
|
transition = { ...transition, phase: 'runtime-activated' };
|
|
46
52
|
save(transition);
|
|
47
53
|
}
|
|
48
|
-
await effects.validateServerBuildState(record);
|
|
49
|
-
await effects.serverLifecycle(record, 'start', runningServices);
|
|
54
|
+
await stage('Verify retained state and identities', () => effects.validateServerBuildState(record));
|
|
55
|
+
await stage('Restore previously running services and check readiness', () => effects.serverLifecycle(record, 'start', runningServices));
|
|
50
56
|
const completed = { ...record, sourcePolicyHash: candidate.sourcePolicyHash };
|
|
51
57
|
delete completed.buildTransition;
|
|
52
58
|
effects.writeJson(path, JSON.stringify(completed, null, 2) + '\n');
|