rovloom 0.6.0 → 0.6.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 +2 -2
- package/dist/src/admin/index.js +1 -1
- package/dist/src/{chunk-g27b2gmx.js → chunk-0e9gg4sg.js} +2 -2
- package/dist/src/chunk-1xer1ent.js +102 -0
- package/dist/src/{chunk-863tk45b.js → chunk-41fny9qm.js} +5 -5
- package/dist/src/{chunk-zjzrcc59.js → chunk-59h200cr.js} +139 -7
- package/dist/src/chunk-5w5srj3b.js +93 -0
- package/dist/src/{chunk-d4ejrtjq.js → chunk-6n6b1xpy.js} +1 -1
- package/dist/src/{chunk-ez7d5dac.js → chunk-6w4g9fw8.js} +4 -1
- package/dist/src/{chunk-0dqx2mmz.js → chunk-73aq2qkz.js} +1 -1
- package/dist/src/{chunk-n6wtjyfb.js → chunk-8c9yc0ge.js} +5 -5
- package/dist/src/{chunk-57ayxqnb.js → chunk-8fy8w7ds.js} +2 -23
- package/dist/src/{chunk-2tn0r64b.js → chunk-9h9x79bx.js} +5 -5
- package/dist/src/{chunk-qjh9x872.js → chunk-av31bx1e.js} +1 -1
- package/dist/src/{chunk-0xgpxdgc.js → chunk-bbdtsg4b.js} +7 -5
- package/dist/src/{chunk-q5pgbwb3.js → chunk-e7jgpxkf.js} +2 -2
- package/dist/src/{chunk-zj48jvfe.js → chunk-efty77sb.js} +3 -40
- package/dist/src/{chunk-gyvqqnjb.js → chunk-enj7s8cv.js} +49 -29
- package/dist/src/{chunk-jka7v3wb.js → chunk-ftpy8xx3.js} +311 -23
- package/dist/src/{chunk-zdxww7ms.js → chunk-h3xyq7zk.js} +1 -1
- package/dist/src/{chunk-ttsrctxg.js → chunk-hxmq28pg.js} +9 -7
- package/dist/src/{chunk-s3ydr65k.js → chunk-j59ac0xs.js} +2 -2
- package/dist/src/{chunk-5s2emvww.js → chunk-j6svdqr8.js} +10 -302
- package/dist/src/{chunk-9zkq0kc8.js → chunk-jkzfck98.js} +3 -3
- package/dist/src/{chunk-ssp57p43.js → chunk-m76cmkfy.js} +7 -5
- package/dist/src/{chunk-d2kz25f2.js → chunk-m96mbzcw.js} +674 -308
- package/dist/src/{chunk-yv9px0f5.js → chunk-n3z3jaxy.js} +20 -14
- package/dist/src/{chunk-jf4r0r44.js → chunk-ndj0ay2p.js} +19 -18
- package/dist/src/{chunk-5b8g62kw.js → chunk-pgs9jp6t.js} +61 -179
- package/dist/src/chunk-pksaqt9a.js +25 -0
- package/dist/src/{chunk-wxqhscsw.js → chunk-pnep7yhj.js} +7 -99
- package/dist/src/chunk-qn5xae7g.js +66 -0
- package/dist/src/{chunk-0pewfj89.js → chunk-qp8tgms2.js} +1 -1
- package/dist/src/{chunk-mg0fd6ph.js → chunk-rmgw8h27.js} +10 -8
- package/dist/src/{chunk-gbsbwssz.js → chunk-sf4ztxba.js} +3 -3
- package/dist/src/{chunk-x0td5wn4.js → chunk-shez7hkc.js} +1 -1
- package/dist/src/chunk-sqz614bh.js +30 -0
- package/dist/src/{chunk-09f9q26d.js → chunk-vdwzb63d.js} +2 -2
- package/dist/src/chunk-xtvgm6kf.js +48 -0
- package/dist/src/chunk-y8zm75jt.js +157 -0
- package/dist/src/chunk-yasqw2vj.js +756 -0
- package/dist/src/{chunk-srfbjwtk.js → chunk-z0qmfqvd.js} +3 -3
- package/dist/src/chunk-zm705snh.js +53 -0
- package/dist/src/cli/index.js +29 -28
- package/dist/src/cli/main.js +5 -5
- package/dist/src/connector/herdr/installation.js +4 -4
- package/dist/src/connector/herdr/provider.js +9 -9
- package/dist/src/connector/herdr/runtime.js +7 -7
- package/dist/src/connector/luvus/index.js +7 -6
- package/dist/src/mcp/index.js +16 -15
- package/dist/src/runtime/index.js +16 -15
- package/dist/src/service/index.js +2 -2
- package/dist/src/store.js +4 -4
- package/dist/src/transport/index.js +9 -9
- package/dist/src/webui/index.js +141 -939
- package/package.json +1 -1
- package/dist/src/chunk-0qgk7mhz.js +0 -52
- package/dist/src/chunk-3dvn33c4.js +0 -1299
- package/dist/src/chunk-5j0gj6w2.js +0 -7
- package/dist/src/chunk-vwcntax3.js +0 -228
- package/dist/src/chunk-ytpfmcp1.js +0 -25
- package/dist/src/chunk-zjkjjm81.js +0 -1114
|
@@ -0,0 +1,756 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
parseNativeJson2
|
|
4
|
+
} from "./chunk-7crhmqn2.js";
|
|
5
|
+
import"./chunk-d71r315c.js";
|
|
6
|
+
import {
|
|
7
|
+
object2,
|
|
8
|
+
fields2,
|
|
9
|
+
id2,
|
|
10
|
+
boundedJson2,
|
|
11
|
+
hash2,
|
|
12
|
+
validatePolicies2
|
|
13
|
+
} from "./chunk-qt9m2kg2.js";
|
|
14
|
+
import {
|
|
15
|
+
observedHerdrSource
|
|
16
|
+
} from "./chunk-9tt13dm0.js";
|
|
17
|
+
import"./chunk-g7pnjzkk.js";
|
|
18
|
+
import {
|
|
19
|
+
cliMessages2,
|
|
20
|
+
formatMessage2
|
|
21
|
+
} from "./chunk-pgs9jp6t.js";
|
|
22
|
+
import"./chunk-mqyq5jh6.js";
|
|
23
|
+
import"./chunk-hz8pm6hz.js";
|
|
24
|
+
import"./chunk-8fy8w7ds.js";
|
|
25
|
+
import"./chunk-vdwzb63d.js";
|
|
26
|
+
import {
|
|
27
|
+
localLimits,
|
|
28
|
+
verifyInstallation,
|
|
29
|
+
runFixedProcess
|
|
30
|
+
} from "./chunk-bbdtsg4b.js";
|
|
31
|
+
import"./chunk-y4hksha9.js";
|
|
32
|
+
import {
|
|
33
|
+
initializeManagedLuvusRoot2,
|
|
34
|
+
discoverLuvusInstallation,
|
|
35
|
+
MANAGED_LUVUS_REVISION2,
|
|
36
|
+
MANAGED_LUVUS_CLASSIFICATION2
|
|
37
|
+
} from "./chunk-j6svdqr8.js";
|
|
38
|
+
import"./chunk-efty77sb.js";
|
|
39
|
+
import {
|
|
40
|
+
compileHerdrSchemas2
|
|
41
|
+
} from "./chunk-5h82060k.js";
|
|
42
|
+
import {
|
|
43
|
+
HerdrLocalError,
|
|
44
|
+
measureHerdrInstallation,
|
|
45
|
+
verifyHerdrInstallation
|
|
46
|
+
} from "./chunk-e7jgpxkf.js";
|
|
47
|
+
import {
|
|
48
|
+
isStoppedHerdrCommandCancellation,
|
|
49
|
+
herdrDeadline,
|
|
50
|
+
runHerdrCommand
|
|
51
|
+
} from "./chunk-41fny9qm.js";
|
|
52
|
+
import"./chunk-6n6b1xpy.js";
|
|
53
|
+
import"./chunk-zb641qa3.js";
|
|
54
|
+
import"./chunk-hxmq28pg.js";
|
|
55
|
+
import"./chunk-5svt6rwr.js";
|
|
56
|
+
import {
|
|
57
|
+
parseHerdrProviderRefConfig2
|
|
58
|
+
} from "./chunk-9h9x79bx.js";
|
|
59
|
+
import {
|
|
60
|
+
hasPairingState2,
|
|
61
|
+
retirePairingState2
|
|
62
|
+
} from "./chunk-y8zm75jt.js";
|
|
63
|
+
import {
|
|
64
|
+
setupTarget,
|
|
65
|
+
setupReference,
|
|
66
|
+
setupSessionsFor,
|
|
67
|
+
simpleSetupAuthorization
|
|
68
|
+
} from "./chunk-qn5xae7g.js";
|
|
69
|
+
import {
|
|
70
|
+
setupFileStamp,
|
|
71
|
+
writeSetupFile,
|
|
72
|
+
readSetupJson,
|
|
73
|
+
writeSetupJson
|
|
74
|
+
} from "./chunk-1xer1ent.js";
|
|
75
|
+
import {
|
|
76
|
+
readRuntimeConfig2
|
|
77
|
+
} from "./chunk-bspzg8er.js";
|
|
78
|
+
import {
|
|
79
|
+
privateDirectory
|
|
80
|
+
} from "./chunk-8ykrqhxh.js";
|
|
81
|
+
import"./chunk-1bf0wmgk.js";
|
|
82
|
+
import {
|
|
83
|
+
runtimeReference
|
|
84
|
+
} from "./chunk-z7kkfrgz.js";
|
|
85
|
+
import {
|
|
86
|
+
herdrMode,
|
|
87
|
+
luvusMode,
|
|
88
|
+
selectedNativeProviders,
|
|
89
|
+
CliError2,
|
|
90
|
+
CliCancelled,
|
|
91
|
+
parseConfig2,
|
|
92
|
+
configDocument2,
|
|
93
|
+
readConfig2
|
|
94
|
+
} from "./chunk-hpzr94hm.js";
|
|
95
|
+
import {
|
|
96
|
+
createFileCredentialSink2
|
|
97
|
+
} from "./chunk-5w5srj3b.js";
|
|
98
|
+
import {
|
|
99
|
+
LuvusDispatchClaims2
|
|
100
|
+
} from "./chunk-sf4ztxba.js";
|
|
101
|
+
import {
|
|
102
|
+
LuvusAdapterError2
|
|
103
|
+
} from "./chunk-pksaqt9a.js";
|
|
104
|
+
import {
|
|
105
|
+
effectiveBinDirectories
|
|
106
|
+
} from "./chunk-3nnahj0j.js";
|
|
107
|
+
import"./chunk-h3xyq7zk.js";
|
|
108
|
+
import"./chunk-qp8tgms2.js";
|
|
109
|
+
import"./chunk-0y5542k8.js";
|
|
110
|
+
|
|
111
|
+
// src/cli/join-connector.ts
|
|
112
|
+
import { existsSync as existsSync2 } from "fs";
|
|
113
|
+
import { join as join3 } from "path";
|
|
114
|
+
|
|
115
|
+
// src/cli/setup-native.ts
|
|
116
|
+
import { existsSync, mkdirSync } from "fs";
|
|
117
|
+
import { homedir } from "os";
|
|
118
|
+
import { isAbsolute, join } from "path";
|
|
119
|
+
function assertSetupNativePath(config, console) {
|
|
120
|
+
if (selectedNativeProviders(config).includes("luvus") && luvusMode(config) === "managed" && Buffer.byteLength(join(config.state_dir, "n")) > 52) {
|
|
121
|
+
console.show(cliMessages2(console.io.language)["setup.native.statePathTooLongLuvus"]);
|
|
122
|
+
throw new CliError2("configuration_required");
|
|
123
|
+
}
|
|
124
|
+
if (selectedNativeProviders(config).includes("herdr") && herdrMode(config) === "managed" && process.platform !== "win32" && Buffer.byteLength(join(config.state_dir, "hr/c/herdr/herdr-client.sock")) > 107) {
|
|
125
|
+
console.show(cliMessages2(console.io.language)["setup.native.statePathTooLongHerdr"]);
|
|
126
|
+
throw new CliError2("configuration_required");
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
function setupBinary(config, kind = "luvus") {
|
|
130
|
+
const fallback = process.platform === "win32" ? [] : ["/usr/bin", "/bin"];
|
|
131
|
+
const name = process.platform === "win32" ? kind + ".exe" : kind;
|
|
132
|
+
for (const directory of [...effectiveBinDirectories(config.native?.runtime_bin_dirs), ...fallback]) {
|
|
133
|
+
const path = join(directory, name);
|
|
134
|
+
if (existsSync(path)) {
|
|
135
|
+
return path;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
throw new CliError2("configuration_required");
|
|
139
|
+
}
|
|
140
|
+
function setupAgentDirectories(config) {
|
|
141
|
+
const directories = effectiveBinDirectories(config.native?.agent_bin_dirs);
|
|
142
|
+
return directories.length > 0 ? { agent_bin_dirs: directories } : {};
|
|
143
|
+
}
|
|
144
|
+
function userLuvusHome(config) {
|
|
145
|
+
const configured = config.native?.luvus?.state_root;
|
|
146
|
+
const environment = process.env.LUVUS_HOME;
|
|
147
|
+
const path = configured ?? (environment && isAbsolute(environment) ? environment : join(homedir(), ".luvus"));
|
|
148
|
+
mkdirSync(path, { recursive: true, mode: 448 });
|
|
149
|
+
return path;
|
|
150
|
+
}
|
|
151
|
+
function prepared(value, attempt, machine, config) {
|
|
152
|
+
const row = object2(value);
|
|
153
|
+
fields2(row, ["schema_version", "attempt_id", "machine_id", "phase", "settings", "reference", "local", "remote"]);
|
|
154
|
+
if (row.schema_version !== 1 || row.attempt_id !== attempt || row.machine_id !== machine || row.phase !== "prepared" || row.reference !== setupReference(attempt) || boundedJson2(row.settings) !== boundedJson2(config.native ?? {})) {
|
|
155
|
+
throw new CliError2("configuration_required");
|
|
156
|
+
}
|
|
157
|
+
return row;
|
|
158
|
+
}
|
|
159
|
+
async function prepareSetupNative(config, console, machine, attempt, authorization) {
|
|
160
|
+
console.assertOwner();
|
|
161
|
+
id2(attempt);
|
|
162
|
+
id2(machine);
|
|
163
|
+
id2(authorization.principal_id);
|
|
164
|
+
validatePolicies2(authorization.policies);
|
|
165
|
+
const path = runtimeReference(config.state_dir, "native-setup");
|
|
166
|
+
const existing = readSetupJson(path, 1048576);
|
|
167
|
+
if (existing !== undefined) {
|
|
168
|
+
return prepared(existing, attempt, machine, config);
|
|
169
|
+
}
|
|
170
|
+
const binary = setupBinary(config);
|
|
171
|
+
const attach = luvusMode(config) === "attach";
|
|
172
|
+
if (!attach && process.platform === "win32") {
|
|
173
|
+
console.show(formatMessage2(cliMessages2(console.io.language)["setup.native.managedUnsupportedWindows"], {
|
|
174
|
+
provider: "luvus",
|
|
175
|
+
configKey: "luvus"
|
|
176
|
+
}));
|
|
177
|
+
throw new CliError2("configuration_required");
|
|
178
|
+
}
|
|
179
|
+
if (!attach && process.platform === "darwin") {
|
|
180
|
+
console.show(formatMessage2(cliMessages2(console.io.language)["setup.native.managedUnsupportedMacos"], {
|
|
181
|
+
provider: "luvus",
|
|
182
|
+
configKey: "luvus"
|
|
183
|
+
}));
|
|
184
|
+
throw new CliError2("configuration_required");
|
|
185
|
+
}
|
|
186
|
+
const control = join(config.state_dir, "control");
|
|
187
|
+
const stateRoot = attach ? userLuvusHome(config) : join(config.state_dir, "n");
|
|
188
|
+
const home = join(config.state_dir, "h");
|
|
189
|
+
const work = join(config.state_dir, "w");
|
|
190
|
+
assertSetupNativePath(config, console);
|
|
191
|
+
for (const directory of [
|
|
192
|
+
control,
|
|
193
|
+
...attach ? [] : [stateRoot],
|
|
194
|
+
home,
|
|
195
|
+
work,
|
|
196
|
+
...["config", "data", "cache", "runtime"].map((name) => join(home, name))
|
|
197
|
+
]) {
|
|
198
|
+
privateDirectory(directory);
|
|
199
|
+
}
|
|
200
|
+
const reference = setupReference(attempt);
|
|
201
|
+
const target = setupTarget(machine, "luvus", setupSessionsFor(config));
|
|
202
|
+
const discovered = await discoverLuvusInstallation({
|
|
203
|
+
target,
|
|
204
|
+
config_ref: reference,
|
|
205
|
+
binding_revision: 1,
|
|
206
|
+
binary,
|
|
207
|
+
state_root: stateRoot,
|
|
208
|
+
home,
|
|
209
|
+
cwd: work,
|
|
210
|
+
transport: "ipc",
|
|
211
|
+
allow_terminal_execution: false,
|
|
212
|
+
...attach ? { attach: true, user_home: homedir() } : {},
|
|
213
|
+
...setupAgentDirectories(config)
|
|
214
|
+
}, { revision: MANAGED_LUVUS_REVISION2, signal: console.io.signal });
|
|
215
|
+
const schema = await runFixedProcess(discovered.config, localLimits(discovered.config.limits), "schema", console.io.signal);
|
|
216
|
+
if (schema.exit_code !== 0 || hash2(schema.stdout) !== discovered.compiled.identity.schema_sha256) {
|
|
217
|
+
throw new CliError2("configuration_required");
|
|
218
|
+
}
|
|
219
|
+
await verifyInstallation(discovered.config);
|
|
220
|
+
const remote = {
|
|
221
|
+
kind: "luvus",
|
|
222
|
+
authentication: "remote_connector",
|
|
223
|
+
binding: {
|
|
224
|
+
machine_id: target.machine_id,
|
|
225
|
+
provider_id: target.provider_id,
|
|
226
|
+
kind: "luvus",
|
|
227
|
+
config_ref: reference,
|
|
228
|
+
binding_revision: 1,
|
|
229
|
+
enabled: true
|
|
230
|
+
},
|
|
231
|
+
target,
|
|
232
|
+
contract: {
|
|
233
|
+
binary_version: discovered.binaryVersion,
|
|
234
|
+
binary_sha256: discovered.config.binary_sha256,
|
|
235
|
+
schema_sha256: discovered.compiled.identity.schema_sha256,
|
|
236
|
+
adapter_revision: MANAGED_LUVUS_REVISION2,
|
|
237
|
+
classification_revision: MANAGED_LUVUS_CLASSIFICATION2,
|
|
238
|
+
schema_bundle: schema.stdout.toString("utf8")
|
|
239
|
+
},
|
|
240
|
+
peer_policy_revision: authorization.policies.local.revision,
|
|
241
|
+
raw_grant: {
|
|
242
|
+
principal_id: authorization.principal_id,
|
|
243
|
+
methods: [...authorization.policies.caller.grants[0].methods]
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
boundedJson2(remote, 1048576);
|
|
247
|
+
console.assertOwner();
|
|
248
|
+
writeSetupJson(path, {
|
|
249
|
+
schema_version: 1,
|
|
250
|
+
attempt_id: attempt,
|
|
251
|
+
machine_id: machine,
|
|
252
|
+
phase: "initializing"
|
|
253
|
+
});
|
|
254
|
+
if (attach) {
|
|
255
|
+
const ledgerId = hash2(boundedJson2([reference, "user", target]));
|
|
256
|
+
new LuvusDispatchClaims2({
|
|
257
|
+
path: join(control, "luvus-claims.db"),
|
|
258
|
+
mode: "create",
|
|
259
|
+
ledger_id: ledgerId,
|
|
260
|
+
limits: { entries: 1024, bytes: 4194304 },
|
|
261
|
+
now: Date.now
|
|
262
|
+
}).close();
|
|
263
|
+
const result = {
|
|
264
|
+
schema_version: 1,
|
|
265
|
+
attempt_id: attempt,
|
|
266
|
+
machine_id: machine,
|
|
267
|
+
phase: "prepared",
|
|
268
|
+
settings: config.native ?? {},
|
|
269
|
+
reference,
|
|
270
|
+
local: {
|
|
271
|
+
kind: "luvus",
|
|
272
|
+
authentication: "local_owner",
|
|
273
|
+
native: { mode: "user", config: discovered.config },
|
|
274
|
+
peer_policy_revision: remote.peer_policy_revision,
|
|
275
|
+
principal_id: authorization.principal_id,
|
|
276
|
+
policies: authorization.policies,
|
|
277
|
+
storage_mode: "open"
|
|
278
|
+
},
|
|
279
|
+
remote
|
|
280
|
+
};
|
|
281
|
+
writeSetupJson(path, result, true, 1048576);
|
|
282
|
+
return result;
|
|
283
|
+
}
|
|
284
|
+
const rootRecord = join(control, "luvus-root.json");
|
|
285
|
+
const root = await initializeManagedLuvusRoot2({
|
|
286
|
+
record_path: rootRecord,
|
|
287
|
+
config: discovered.config
|
|
288
|
+
});
|
|
289
|
+
try {
|
|
290
|
+
const ledgerId = hash2(boundedJson2([reference, root.root_id, root.root_revision, root.config.target]));
|
|
291
|
+
const claims = new LuvusDispatchClaims2({
|
|
292
|
+
path: join(control, "luvus-claims.db"),
|
|
293
|
+
mode: "create",
|
|
294
|
+
ledger_id: ledgerId,
|
|
295
|
+
limits: { entries: 1024, bytes: 4194304 },
|
|
296
|
+
now: Date.now
|
|
297
|
+
});
|
|
298
|
+
claims.close();
|
|
299
|
+
const result = {
|
|
300
|
+
schema_version: 1,
|
|
301
|
+
attempt_id: attempt,
|
|
302
|
+
machine_id: machine,
|
|
303
|
+
phase: "prepared",
|
|
304
|
+
settings: config.native ?? {},
|
|
305
|
+
reference,
|
|
306
|
+
local: {
|
|
307
|
+
kind: "luvus",
|
|
308
|
+
authentication: "local_owner",
|
|
309
|
+
native: {
|
|
310
|
+
mode: "managed",
|
|
311
|
+
root_record: rootRecord,
|
|
312
|
+
expected_root_id: root.root_id,
|
|
313
|
+
expected_root_revision: root.root_revision
|
|
314
|
+
},
|
|
315
|
+
peer_policy_revision: remote.peer_policy_revision,
|
|
316
|
+
principal_id: authorization.principal_id,
|
|
317
|
+
policies: authorization.policies,
|
|
318
|
+
storage_mode: "open"
|
|
319
|
+
},
|
|
320
|
+
remote
|
|
321
|
+
};
|
|
322
|
+
writeSetupJson(path, result, true, 1048576);
|
|
323
|
+
return result;
|
|
324
|
+
} finally {
|
|
325
|
+
root.close();
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// src/cli/setup-herdr.ts
|
|
330
|
+
import { mkdirSync as mkdirSync2 } from "fs";
|
|
331
|
+
import { homedir as homedir2 } from "os";
|
|
332
|
+
import { isAbsolute as isAbsolute2, join as join2 } from "path";
|
|
333
|
+
function attachedDirectories(config) {
|
|
334
|
+
const home = homedir2();
|
|
335
|
+
if (process.platform === "win32") {
|
|
336
|
+
const roaming = config.native?.herdr?.config_home ?? process.env.APPDATA ?? join2(home, "AppData", "Roaming");
|
|
337
|
+
const local = process.env.LOCALAPPDATA ?? join2(home, "AppData", "Local");
|
|
338
|
+
for (const path of [roaming, local]) {
|
|
339
|
+
mkdirSync2(path, { recursive: true });
|
|
340
|
+
}
|
|
341
|
+
return { home, config_home: roaming, state_home: local, cache_home: local, cwd: home };
|
|
342
|
+
}
|
|
343
|
+
const xdg = (variable, fallback) => {
|
|
344
|
+
const value = process.env[variable];
|
|
345
|
+
return value && isAbsolute2(value) ? value : join2(home, fallback);
|
|
346
|
+
};
|
|
347
|
+
const directories = {
|
|
348
|
+
home,
|
|
349
|
+
config_home: config.native?.herdr?.config_home ?? xdg("XDG_CONFIG_HOME", ".config"),
|
|
350
|
+
state_home: xdg("XDG_STATE_HOME", ".local/state"),
|
|
351
|
+
cache_home: xdg("XDG_CACHE_HOME", ".cache"),
|
|
352
|
+
cwd: home
|
|
353
|
+
};
|
|
354
|
+
for (const path of [directories.config_home, directories.state_home, directories.cache_home]) {
|
|
355
|
+
mkdirSync2(path, { recursive: true, mode: 448 });
|
|
356
|
+
}
|
|
357
|
+
return directories;
|
|
358
|
+
}
|
|
359
|
+
async function version(config, signal) {
|
|
360
|
+
const scope = herdrDeadline(signal, 1000);
|
|
361
|
+
try {
|
|
362
|
+
const raw = await runHerdrCommand(config, "version", scope.signal);
|
|
363
|
+
const label = raw.toString("utf8").trim().replace(/^herdr\s+/i, "");
|
|
364
|
+
return label.length > 0 && label.length <= 128 && [...label].every((character) => character.charCodeAt(0) >= 32 && character.charCodeAt(0) !== 127) ? label : "unavailable";
|
|
365
|
+
} catch (error) {
|
|
366
|
+
if (error instanceof HerdrLocalError && (error.code === "herdr_cli_exit" || error.code === "herdr_timeout" && !signal.aborted)) {
|
|
367
|
+
return "unavailable";
|
|
368
|
+
}
|
|
369
|
+
throw error;
|
|
370
|
+
} finally {
|
|
371
|
+
scope.close();
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
function prepared2(value, config, attempt, machine) {
|
|
375
|
+
const row = object2(value);
|
|
376
|
+
fields2(row, ["schema_version", "attempt_id", "machine_id", "phase", "settings", "reference", "local", "remote"]);
|
|
377
|
+
if (row.schema_version !== 1 || row.attempt_id !== attempt || row.machine_id !== machine || row.phase !== "prepared" || row.reference !== setupReference(attempt, "herdr") || boundedJson2(row.settings) !== boundedJson2(config.native ?? {})) {
|
|
378
|
+
throw new CliError2("configuration_required");
|
|
379
|
+
}
|
|
380
|
+
return row;
|
|
381
|
+
}
|
|
382
|
+
async function prepareSetupHerdr(config, console, machine, attempt, authorization) {
|
|
383
|
+
console.assertOwner();
|
|
384
|
+
const path = runtimeReference(config.state_dir, "herdr-setup");
|
|
385
|
+
const existing = readSetupJson(path, 1048576);
|
|
386
|
+
if (existing !== undefined) {
|
|
387
|
+
return prepared2(existing, config, attempt, machine);
|
|
388
|
+
}
|
|
389
|
+
const binary = setupBinary(config, "herdr");
|
|
390
|
+
const attach = herdrMode(config) === "attach";
|
|
391
|
+
if (!attach && process.platform === "win32") {
|
|
392
|
+
console.show(formatMessage2(cliMessages2(console.io.language)["setup.native.managedUnsupportedWindows"], {
|
|
393
|
+
provider: "herdr",
|
|
394
|
+
configKey: "herdr"
|
|
395
|
+
}));
|
|
396
|
+
throw new CliError2("configuration_required");
|
|
397
|
+
}
|
|
398
|
+
if (!attach && process.platform === "darwin") {
|
|
399
|
+
console.show(formatMessage2(cliMessages2(console.io.language)["setup.native.managedUnsupportedMacos"], {
|
|
400
|
+
provider: "herdr",
|
|
401
|
+
configKey: "herdr"
|
|
402
|
+
}));
|
|
403
|
+
throw new CliError2("configuration_required");
|
|
404
|
+
}
|
|
405
|
+
assertSetupNativePath(config, console);
|
|
406
|
+
const root = join2(config.state_dir, "hr");
|
|
407
|
+
privateDirectory(root);
|
|
408
|
+
for (const name of ["h", "c", "s", "k", "t", "w", "control"]) {
|
|
409
|
+
privateDirectory(join2(root, name));
|
|
410
|
+
}
|
|
411
|
+
const target = setupTarget(machine, "herdr");
|
|
412
|
+
const reference = setupReference(attempt, "herdr");
|
|
413
|
+
const local = {
|
|
414
|
+
target,
|
|
415
|
+
binding_revision: 1,
|
|
416
|
+
config_ref: reference,
|
|
417
|
+
binary,
|
|
418
|
+
...attach ? attachedDirectories(config) : {
|
|
419
|
+
home: join2(root, "h"),
|
|
420
|
+
config_home: join2(root, "c"),
|
|
421
|
+
state_home: join2(root, "s"),
|
|
422
|
+
cache_home: join2(root, "k"),
|
|
423
|
+
cwd: join2(root, "w")
|
|
424
|
+
},
|
|
425
|
+
temporary_home: join2(root, "t"),
|
|
426
|
+
allow_terminal_execution: false,
|
|
427
|
+
...attach ? { attach: true } : {},
|
|
428
|
+
...setupAgentDirectories(config)
|
|
429
|
+
};
|
|
430
|
+
const measured = measureHerdrInstallation(local);
|
|
431
|
+
const scope = herdrDeadline(console.io.signal, 1e4);
|
|
432
|
+
let raw;
|
|
433
|
+
let source;
|
|
434
|
+
try {
|
|
435
|
+
const label = await version(local, scope.signal);
|
|
436
|
+
raw = await runHerdrCommand(local, "schema", scope.signal);
|
|
437
|
+
const compiled = await compileHerdrSchemas2(raw, scope.signal);
|
|
438
|
+
if (verifyHerdrInstallation(local, measured.sha256) !== measured.stamp || compiled.schema_sha256 !== hash2(raw)) {
|
|
439
|
+
throw new CliError2("configuration_required");
|
|
440
|
+
}
|
|
441
|
+
source = observedHerdrSource(label, measured.sha256, compiled.schema_sha256, compiled.protocol);
|
|
442
|
+
} catch (error) {
|
|
443
|
+
if (console.io.signal.aborted && isStoppedHerdrCommandCancellation(error)) {
|
|
444
|
+
throw new CliCancelled;
|
|
445
|
+
}
|
|
446
|
+
throw error;
|
|
447
|
+
} finally {
|
|
448
|
+
scope.close();
|
|
449
|
+
}
|
|
450
|
+
const shared = {
|
|
451
|
+
version: 1,
|
|
452
|
+
target,
|
|
453
|
+
binding_revision: 1,
|
|
454
|
+
config_ref: reference,
|
|
455
|
+
expected_source: source,
|
|
456
|
+
peer_policy_revision: authorization.policies.local.revision
|
|
457
|
+
};
|
|
458
|
+
const control = join2(root, "control");
|
|
459
|
+
const schemaPath = join2(control, "schema.json");
|
|
460
|
+
const limits = { entries: 1024, bytes: 4194304 };
|
|
461
|
+
const claimsRef = {
|
|
462
|
+
path: join2(control, "claims.db"),
|
|
463
|
+
mode: "open",
|
|
464
|
+
ledger_id: hash2(boundedJson2([reference, target, source, "claims"])),
|
|
465
|
+
limits
|
|
466
|
+
};
|
|
467
|
+
const provider = parseHerdrProviderRefConfig2({
|
|
468
|
+
...shared,
|
|
469
|
+
schema_path: schemaPath,
|
|
470
|
+
connector: {
|
|
471
|
+
local,
|
|
472
|
+
principal_id: authorization.principal_id,
|
|
473
|
+
claims: claimsRef
|
|
474
|
+
}
|
|
475
|
+
});
|
|
476
|
+
console.assertOwner();
|
|
477
|
+
writeSetupJson(path, {
|
|
478
|
+
schema_version: 1,
|
|
479
|
+
attempt_id: attempt,
|
|
480
|
+
machine_id: machine,
|
|
481
|
+
phase: "initializing"
|
|
482
|
+
});
|
|
483
|
+
writeSetupFile(schemaPath, raw);
|
|
484
|
+
const claims = new LuvusDispatchClaims2({ ...claimsRef, mode: "create", now: Date.now });
|
|
485
|
+
try {} finally {
|
|
486
|
+
claims.close();
|
|
487
|
+
}
|
|
488
|
+
const result = {
|
|
489
|
+
schema_version: 1,
|
|
490
|
+
attempt_id: attempt,
|
|
491
|
+
machine_id: machine,
|
|
492
|
+
phase: "prepared",
|
|
493
|
+
settings: config.native ?? {},
|
|
494
|
+
reference,
|
|
495
|
+
local: {
|
|
496
|
+
kind: "herdr",
|
|
497
|
+
config: provider,
|
|
498
|
+
native: { mode: attach ? "attach" : "managed" },
|
|
499
|
+
policies: authorization.policies
|
|
500
|
+
},
|
|
501
|
+
remote: { kind: "herdr", config: shared, schema_bundle: raw.toString("utf8") }
|
|
502
|
+
};
|
|
503
|
+
writeSetupJson(path, result, true, 1048576);
|
|
504
|
+
return result;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
// src/cli/setup-console.ts
|
|
508
|
+
function silentConsole(io) {
|
|
509
|
+
return {
|
|
510
|
+
io,
|
|
511
|
+
show: (text) => {
|
|
512
|
+
io.stderr.write(text);
|
|
513
|
+
},
|
|
514
|
+
confirm: async () => true,
|
|
515
|
+
assertOwner: () => {}
|
|
516
|
+
};
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
// src/cli/join-connector.ts
|
|
520
|
+
function parseJoinValue(value) {
|
|
521
|
+
const hash = value.indexOf("#");
|
|
522
|
+
if (typeof value !== "string" || hash <= 0 || hash === value.length - 1) {
|
|
523
|
+
throw new CliError2("invalid_arguments");
|
|
524
|
+
}
|
|
525
|
+
const url = value.slice(0, hash);
|
|
526
|
+
const parts = value.slice(hash + 1).split(".");
|
|
527
|
+
if (parts.length !== 3) {
|
|
528
|
+
throw new CliError2("invalid_arguments");
|
|
529
|
+
}
|
|
530
|
+
const [machine, attempt, secret] = parts;
|
|
531
|
+
id2(machine);
|
|
532
|
+
id2(attempt);
|
|
533
|
+
if (typeof secret !== "string" || !/^[A-Za-z0-9_-]{32,256}$/.test(secret)) {
|
|
534
|
+
throw new CliError2("invalid_arguments");
|
|
535
|
+
}
|
|
536
|
+
const parsed = new URL(url);
|
|
537
|
+
if (!["ws:", "wss:"].includes(parsed.protocol) || !parsed.hostname || parsed.username || parsed.password || parsed.search || parsed.hash || !["/", ""].includes(parsed.pathname)) {
|
|
538
|
+
throw new CliError2("invalid_arguments");
|
|
539
|
+
}
|
|
540
|
+
return { url: parsed.origin, machine, attempt, secret, value: machine + "." + attempt + "." + secret };
|
|
541
|
+
}
|
|
542
|
+
async function responseJson(response) {
|
|
543
|
+
if (!response.body || response.status !== 200) {
|
|
544
|
+
await response.body?.cancel().catch(() => {});
|
|
545
|
+
throw new CliError2("configuration_required");
|
|
546
|
+
}
|
|
547
|
+
const reader = response.body.getReader();
|
|
548
|
+
const chunks = [];
|
|
549
|
+
let bytes = 0;
|
|
550
|
+
try {
|
|
551
|
+
while (true) {
|
|
552
|
+
const value = await reader.read();
|
|
553
|
+
if (value.done) {
|
|
554
|
+
break;
|
|
555
|
+
}
|
|
556
|
+
bytes += value.value.length;
|
|
557
|
+
if (bytes > 262144) {
|
|
558
|
+
throw new CliError2("configuration_required");
|
|
559
|
+
}
|
|
560
|
+
chunks.push(value.value);
|
|
561
|
+
}
|
|
562
|
+
const parsed = parseNativeJson2(Buffer.concat(chunks, bytes), { object_bytes: 262144 });
|
|
563
|
+
if (!parsed.ok) {
|
|
564
|
+
throw new CliError2("configuration_required");
|
|
565
|
+
}
|
|
566
|
+
return object2(parsed.value);
|
|
567
|
+
} finally {
|
|
568
|
+
await reader.cancel().catch(() => {});
|
|
569
|
+
reader.releaseLock();
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
async function post(config, path, value, signal, timeout = 300000) {
|
|
573
|
+
const origin = new URL(config.gateway_url);
|
|
574
|
+
origin.protocol = origin.protocol === "wss:" ? "https:" : "http:";
|
|
575
|
+
return await responseJson(await fetch(new URL(path, origin), {
|
|
576
|
+
method: "POST",
|
|
577
|
+
redirect: "error",
|
|
578
|
+
headers: { "content-type": "application/json" },
|
|
579
|
+
body: boundedJson2(value, 1048576),
|
|
580
|
+
signal: AbortSignal.any([signal, AbortSignal.timeout(timeout)])
|
|
581
|
+
}));
|
|
582
|
+
}
|
|
583
|
+
async function joinConnector(config, path, io, value) {
|
|
584
|
+
const code = parseJoinValue(value);
|
|
585
|
+
const console = silentConsole(io);
|
|
586
|
+
const providers = readRuntimeConfig2(config).providers;
|
|
587
|
+
const hasCredential = existsSync2(runtimeReference(config.state_dir, "device"));
|
|
588
|
+
if (hasPairingState2(config.state_dir)) {
|
|
589
|
+
const paired = readSetupJson(runtimeReference(config.state_dir, "pairing"));
|
|
590
|
+
const current = paired === undefined ? undefined : object2(paired);
|
|
591
|
+
const machine = current && "machine_id" in current ? String(current.machine_id) : undefined;
|
|
592
|
+
if (hasCredential && existsSync2(runtimeReference(config.state_dir, "providers")) && machine === code.machine && config.gateway_url === code.url) {
|
|
593
|
+
return config;
|
|
594
|
+
}
|
|
595
|
+
const prepared = ["native-setup", "herdr-setup"].map((reference) => readSetupJson(runtimeReference(config.state_dir, reference), 1048576)).filter((entry) => entry !== undefined);
|
|
596
|
+
const resume = !hasCredential && providers.length === 0 && config.gateway_url === code.url && prepared.length > 0 && prepared.every((entry) => {
|
|
597
|
+
const row = object2(entry);
|
|
598
|
+
return row.phase === "prepared" && row.machine_id === code.machine && row.attempt_id === code.attempt;
|
|
599
|
+
});
|
|
600
|
+
if (!resume) {
|
|
601
|
+
const retired = retirePairingState2(config, console);
|
|
602
|
+
if (retired !== undefined) {
|
|
603
|
+
console.show(formatMessage2(cliMessages2(io.language)[config.gateway_url === code.url ? "setup.join.resettingState" : "setup.join.switchingGateway"], { retired }));
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
if (config.gateway_url !== code.url) {
|
|
608
|
+
if (boundedJson2(configDocument2(readConfig2(path))) !== boundedJson2(configDocument2(config))) {
|
|
609
|
+
throw new CliError2("config_changed");
|
|
610
|
+
}
|
|
611
|
+
config = parseConfig2({ ...configDocument2(config), gateway: { url: code.url } });
|
|
612
|
+
writeSetupFile(path, JSON.stringify(configDocument2(config), null, 2) + `
|
|
613
|
+
`, true, setupFileStamp(path));
|
|
614
|
+
}
|
|
615
|
+
privateDirectory(config.state_dir);
|
|
616
|
+
privateDirectory(join3(config.state_dir, "managed"));
|
|
617
|
+
assertSetupNativePath(config, console);
|
|
618
|
+
const authorization = simpleSetupAuthorization(code.machine, selectedNativeProviders(config), setupSessionsFor(config));
|
|
619
|
+
const prepared = [];
|
|
620
|
+
for (const kind of selectedNativeProviders(config)) {
|
|
621
|
+
prepared.push(await (kind === "luvus" ? prepareSetupNative : prepareSetupHerdr)(config, console, code.machine, code.attempt, authorization));
|
|
622
|
+
}
|
|
623
|
+
const installations = prepared.map((native) => ({
|
|
624
|
+
reference: native.reference,
|
|
625
|
+
value: native.remote
|
|
626
|
+
}));
|
|
627
|
+
const installation = installations.length === 1 && selectedNativeProviders(config)[0] === "luvus" ? installations[0] : { installations };
|
|
628
|
+
const applied = await post(config, "/pairing", { code: code.value, installation }, io.signal);
|
|
629
|
+
fields2(applied, ["state", "machine_id", "recovery_generation", "credential"], ["mcp", "replayed"]);
|
|
630
|
+
id2(applied.machine_id);
|
|
631
|
+
id2(applied.recovery_generation);
|
|
632
|
+
if (applied.state !== "paired" || applied.machine_id !== code.machine || typeof applied.credential !== "string" || !/^[A-Za-z0-9_-]{32,256}$/.test(applied.credential)) {
|
|
633
|
+
throw new CliError2("configuration_required");
|
|
634
|
+
}
|
|
635
|
+
const credential = {
|
|
636
|
+
machine_id: code.machine,
|
|
637
|
+
recovery_generation: applied.recovery_generation,
|
|
638
|
+
credential: applied.credential
|
|
639
|
+
};
|
|
640
|
+
const credentialPath = runtimeReference(config.state_dir, "device");
|
|
641
|
+
const sink = createFileCredentialSink2(credentialPath, credential, existsSync2(credentialPath));
|
|
642
|
+
try {
|
|
643
|
+
await sink.deliver(credential, io.signal, { delivery_id: "join_" + code.attempt, revision: 0 });
|
|
644
|
+
} finally {
|
|
645
|
+
sink.close();
|
|
646
|
+
}
|
|
647
|
+
writeSetupJson(runtimeReference(config.state_dir, "providers"), {
|
|
648
|
+
schema_version: 1,
|
|
649
|
+
role: "connector",
|
|
650
|
+
providers: prepared.map((native) => ({
|
|
651
|
+
reference: native.reference,
|
|
652
|
+
value: native.local
|
|
653
|
+
}))
|
|
654
|
+
}, false, 1048576);
|
|
655
|
+
writeSetupJson(runtimeReference(config.state_dir, "pairing"), {
|
|
656
|
+
schema_version: 1,
|
|
657
|
+
attempt_id: code.attempt,
|
|
658
|
+
machine_id: code.machine,
|
|
659
|
+
gateway_url: config.gateway_url,
|
|
660
|
+
phase: "configured"
|
|
661
|
+
}, false);
|
|
662
|
+
console.show(formatMessage2(cliMessages2(io.language)["setup.join.completed"], {
|
|
663
|
+
machine: code.machine,
|
|
664
|
+
url: config.gateway_url
|
|
665
|
+
}) + formatMessage2(cliMessages2(io.language)["setup.join.providers"], {
|
|
666
|
+
entries: prepared.map((native) => native.reference).join(", ")
|
|
667
|
+
}));
|
|
668
|
+
if (applied.mcp !== undefined) {
|
|
669
|
+
const mcp = object2(applied.mcp);
|
|
670
|
+
fields2(mcp, ["url", "token"]);
|
|
671
|
+
if (typeof mcp.url !== "string" || typeof mcp.token !== "string") {
|
|
672
|
+
throw new CliError2("configuration_required");
|
|
673
|
+
}
|
|
674
|
+
console.show(formatMessage2(cliMessages2(io.language)["setup.join.mcpBlock"], { url: mcp.url, token: mcp.token }));
|
|
675
|
+
}
|
|
676
|
+
return config;
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
// src/cli/setup-runtime.ts
|
|
680
|
+
class CliSetup {
|
|
681
|
+
#io;
|
|
682
|
+
#issueCode = false;
|
|
683
|
+
#issued = false;
|
|
684
|
+
#observation;
|
|
685
|
+
async prepare(config, path, io, options) {
|
|
686
|
+
this.#io = io;
|
|
687
|
+
if (config.role === "connector") {
|
|
688
|
+
if (options?.join !== undefined) {
|
|
689
|
+
const joined = await joinConnector(config, path, io, options.join);
|
|
690
|
+
io.stderr.write(`
|
|
691
|
+
`);
|
|
692
|
+
return joined;
|
|
693
|
+
}
|
|
694
|
+
return config;
|
|
695
|
+
}
|
|
696
|
+
this.#issueCode = options?.issueCode === true;
|
|
697
|
+
return config;
|
|
698
|
+
}
|
|
699
|
+
async gatewayListening(issue) {
|
|
700
|
+
const io = this.#io;
|
|
701
|
+
if (!io || !this.#issueCode || this.#issued || io.signal.aborted) {
|
|
702
|
+
return;
|
|
703
|
+
}
|
|
704
|
+
const value = await issue();
|
|
705
|
+
if (value !== undefined) {
|
|
706
|
+
this.#issued = true;
|
|
707
|
+
io.stderr.write(formatMessage2(cliMessages2(io.language)["setup.gateway.joinCommandBlock"], {
|
|
708
|
+
command: "rovloom connector --join " + value
|
|
709
|
+
}));
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
nativeFailed(error) {
|
|
713
|
+
if ((error instanceof LuvusAdapterError2 || error instanceof HerdrLocalError) && /^[a-z_]{1,80}$/.test(error.code)) {
|
|
714
|
+
this.#io?.stderr.write("native_unavailable " + error.code + `
|
|
715
|
+
`);
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
observe(running) {
|
|
719
|
+
if (!running.transport) {
|
|
720
|
+
return;
|
|
721
|
+
}
|
|
722
|
+
let previous = "";
|
|
723
|
+
this.#observation = setInterval(() => {
|
|
724
|
+
try {
|
|
725
|
+
const status = running.transport.status();
|
|
726
|
+
const ready = status.providers.some((provider) => provider.ready);
|
|
727
|
+
const current = status.phase + ":" + ready + ":" + (status.failure ?? "");
|
|
728
|
+
if (current !== previous) {
|
|
729
|
+
previous = current;
|
|
730
|
+
this.#io?.stderr.write("connector_transport " + status.phase + " provider_ready=" + String(ready) + (status.capacity ? " capacity=" + status.capacity.resource + " reclaim_at=" + String(status.capacity.reclaim_at) : "") + (status.failure ? " reason=" + status.failure : "") + `
|
|
731
|
+
`);
|
|
732
|
+
}
|
|
733
|
+
} catch {
|
|
734
|
+
clearInterval(this.#observation);
|
|
735
|
+
this.#observation = undefined;
|
|
736
|
+
}
|
|
737
|
+
}, 250);
|
|
738
|
+
running.closed.then(() => {
|
|
739
|
+
clearInterval(this.#observation);
|
|
740
|
+
this.#observation = undefined;
|
|
741
|
+
}, () => {
|
|
742
|
+
clearInterval(this.#observation);
|
|
743
|
+
this.#observation = undefined;
|
|
744
|
+
});
|
|
745
|
+
}
|
|
746
|
+
close() {
|
|
747
|
+
clearInterval(this.#observation);
|
|
748
|
+
this.#observation = undefined;
|
|
749
|
+
this.#io = undefined;
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
export {
|
|
753
|
+
CliSetup
|
|
754
|
+
};
|
|
755
|
+
|
|
756
|
+
//# debugId=859B7FAC09008D6B64756E2164756E21
|