@ours.network/codex 1.2.0-nightly.6 → 1.2.0-nightly.8
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/.codex-plugin/plugin.json +1 -1
- package/README.md +11 -28
- package/bin/codex-config-install.mjs +3 -3
- package/bin/ours-codex-install.mjs +4 -31
- package/dist/hooks-runner.mjs +49 -238
- package/dist/host-hooks.mjs +9 -48
- package/dist/monitor-mcp.mjs +20 -122
- package/dist/network-watch.mjs +17 -118
- package/dist/profile.mjs +14 -153
- package/install.sh +14 -33
- package/package.json +3 -3
- package/skills/ours/SKILL.md +6 -6
- package/skills/ours/references/configuration.md +20 -22
- package/src/hooks/runner.mjs +1 -48
- package/src/launcher.mjs +1 -9
- package/src/profile.mjs +1 -40
package/dist/host-hooks.mjs
CHANGED
|
@@ -127,52 +127,13 @@ var ApplicationIdentityStore = class {
|
|
|
127
127
|
};
|
|
128
128
|
|
|
129
129
|
// ../core/src/host-profile.ts
|
|
130
|
-
import {
|
|
131
|
-
var
|
|
132
|
-
var LEGACY_SELECTION_KEYS = ["port", "stateDir", "apiToken", "apiVisibility"];
|
|
133
|
-
var UUID2 = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
134
|
-
function profileError(reason) {
|
|
135
|
-
return new Error(`Invalid external host profile: ${reason}`);
|
|
136
|
-
}
|
|
137
|
-
function validateHostProfile(value) {
|
|
138
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
139
|
-
throw profileError("expected a complete host profile object.");
|
|
140
|
-
}
|
|
141
|
-
const record = value;
|
|
142
|
-
const present = PROFILE_KEYS.filter((key) => Object.hasOwn(record, key));
|
|
143
|
-
if (present.length !== PROFILE_KEYS.length) {
|
|
144
|
-
throw profileError("expected a complete host profile tuple: endpoint, expectedInstanceId, credentialPath.");
|
|
145
|
-
}
|
|
146
|
-
const mixed = LEGACY_SELECTION_KEYS.filter((key) => Object.hasOwn(record, key));
|
|
147
|
-
if (mixed.length) throw profileError(`legacy selection keys cannot be mixed with a host profile (${mixed.join(", ")}).`);
|
|
148
|
-
const endpoint = record.endpoint;
|
|
149
|
-
const expectedInstanceId = record.expectedInstanceId;
|
|
150
|
-
const credentialPath = record.credentialPath;
|
|
151
|
-
if (typeof endpoint !== "string" || endpoint.trim() !== endpoint || endpoint === "") {
|
|
152
|
-
throw profileError("endpoint must be a non-empty HTTP or HTTPS origin.");
|
|
153
|
-
}
|
|
154
|
-
if (typeof expectedInstanceId !== "string" || !UUID2.test(expectedInstanceId)) {
|
|
155
|
-
throw profileError("expectedInstanceId must be a lowercase UUID.");
|
|
156
|
-
}
|
|
157
|
-
if (typeof credentialPath !== "string" || credentialPath === "" || !credentialPath.startsWith("/") || resolve2(credentialPath) !== credentialPath) {
|
|
158
|
-
throw profileError("credentialPath must be a normalized absolute path.");
|
|
159
|
-
}
|
|
160
|
-
let url;
|
|
161
|
-
try {
|
|
162
|
-
url = new URL(endpoint);
|
|
163
|
-
} catch {
|
|
164
|
-
throw profileError("endpoint must be an HTTP or HTTPS origin.");
|
|
165
|
-
}
|
|
166
|
-
if (url.protocol !== "http:" && url.protocol !== "https:" || url.username || url.password || url.pathname !== "/" || url.search || url.hash) {
|
|
167
|
-
throw profileError("endpoint must be an HTTP or HTTPS origin without credentials, path, query, or fragment.");
|
|
168
|
-
}
|
|
169
|
-
return { endpoint: url.origin, expectedInstanceId, credentialPath };
|
|
170
|
-
}
|
|
130
|
+
import { readGatewayClientProfile, validateGatewayClientProfile } from "@ours.network/sdk/client";
|
|
131
|
+
var validateHostProfile = validateGatewayClientProfile;
|
|
171
132
|
|
|
172
133
|
// ../core/src/native-session.ts
|
|
173
134
|
import { createHash as createHash2, randomUUID as randomUUID2 } from "node:crypto";
|
|
174
135
|
import { chmod as chmod2, mkdir as mkdir2, readFile as readFile2, rename as rename2, unlink as unlink2, writeFile as writeFile2 } from "node:fs/promises";
|
|
175
|
-
import { dirname as dirname2, join as join2, resolve as
|
|
136
|
+
import { dirname as dirname2, join as join2, resolve as resolve2 } from "node:path";
|
|
176
137
|
import { attachOursClient } from "@ours.network/sdk";
|
|
177
138
|
|
|
178
139
|
// ../core/src/session-guard.ts
|
|
@@ -250,7 +211,7 @@ function acquireSessionGuard(recordPath) {
|
|
|
250
211
|
|
|
251
212
|
// ../core/src/native-session.ts
|
|
252
213
|
var RECORD_VERSION = 1;
|
|
253
|
-
var
|
|
214
|
+
var UUID2 = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
254
215
|
var clients = /* @__PURE__ */ new Map();
|
|
255
216
|
var operations = /* @__PURE__ */ new Map();
|
|
256
217
|
function selector(value) {
|
|
@@ -260,10 +221,10 @@ function selector(value) {
|
|
|
260
221
|
return value;
|
|
261
222
|
}
|
|
262
223
|
function nativeSessionRecordPath(hostRecordRoot, instanceId, nativeSessionId) {
|
|
263
|
-
if (!hostRecordRoot || !hostRecordRoot.startsWith("/") ||
|
|
224
|
+
if (!hostRecordRoot || !hostRecordRoot.startsWith("/") || resolve2(hostRecordRoot) !== hostRecordRoot) {
|
|
264
225
|
throw new Error("Native session host record root must be a normalized absolute path.");
|
|
265
226
|
}
|
|
266
|
-
if (!
|
|
227
|
+
if (!UUID2.test(instanceId)) throw new Error("Native session daemon instance must be a lowercase UUID.");
|
|
267
228
|
const hash = createHash2("sha256").update(selector(nativeSessionId), "utf8").digest("hex");
|
|
268
229
|
return join2(hostRecordRoot, "sessions", instanceId, `${hash}.json`);
|
|
269
230
|
}
|
|
@@ -279,7 +240,7 @@ function parseRecord(text, path) {
|
|
|
279
240
|
}
|
|
280
241
|
const record = value;
|
|
281
242
|
const keys = Object.keys(record).sort();
|
|
282
|
-
if (keys.join(",") !== "ownerInstanceId,state,version" || record.version !== RECORD_VERSION || typeof record.ownerInstanceId !== "string" || !
|
|
243
|
+
if (keys.join(",") !== "ownerInstanceId,state,version" || record.version !== RECORD_VERSION || typeof record.ownerInstanceId !== "string" || !UUID2.test(record.ownerInstanceId) || !["active", "pending", "ended"].includes(String(record.state))) {
|
|
283
244
|
throw new Error(`Invalid native session record at ${path}.`);
|
|
284
245
|
}
|
|
285
246
|
return record;
|
|
@@ -313,8 +274,8 @@ async function writeRecord(path, record) {
|
|
|
313
274
|
async function serialized(key, operation) {
|
|
314
275
|
const predecessor = operations.get(key) ?? Promise.resolve();
|
|
315
276
|
let release;
|
|
316
|
-
const gate = new Promise((
|
|
317
|
-
release =
|
|
277
|
+
const gate = new Promise((resolve3) => {
|
|
278
|
+
release = resolve3;
|
|
318
279
|
});
|
|
319
280
|
const tail = predecessor.catch(() => {
|
|
320
281
|
}).then(() => gate);
|
package/dist/monitor-mcp.mjs
CHANGED
|
@@ -2979,7 +2979,7 @@ var require_compile = __commonJS({
|
|
|
2979
2979
|
const schOrFunc = root.refs[ref];
|
|
2980
2980
|
if (schOrFunc)
|
|
2981
2981
|
return schOrFunc;
|
|
2982
|
-
let _sch =
|
|
2982
|
+
let _sch = resolve.call(this, root, ref);
|
|
2983
2983
|
if (_sch === void 0) {
|
|
2984
2984
|
const schema = (_a = root.localRefs) === null || _a === void 0 ? void 0 : _a[ref];
|
|
2985
2985
|
const { schemaId } = this.opts;
|
|
@@ -3006,7 +3006,7 @@ var require_compile = __commonJS({
|
|
|
3006
3006
|
function sameSchemaEnv(s1, s2) {
|
|
3007
3007
|
return s1.schema === s2.schema && s1.root === s2.root && s1.baseId === s2.baseId;
|
|
3008
3008
|
}
|
|
3009
|
-
function
|
|
3009
|
+
function resolve(root, ref) {
|
|
3010
3010
|
let sch;
|
|
3011
3011
|
while (typeof (sch = this.refs[ref]) == "string")
|
|
3012
3012
|
ref = sch;
|
|
@@ -3831,7 +3831,7 @@ var require_fast_uri = __commonJS({
|
|
|
3831
3831
|
}
|
|
3832
3832
|
return uri;
|
|
3833
3833
|
}
|
|
3834
|
-
function
|
|
3834
|
+
function resolve(baseURI, relativeURI, options) {
|
|
3835
3835
|
const schemelessOptions = options ? Object.assign({ scheme: "null" }, options) : { scheme: "null" };
|
|
3836
3836
|
const {
|
|
3837
3837
|
parsed: baseParsed,
|
|
@@ -4193,7 +4193,7 @@ var require_fast_uri = __commonJS({
|
|
|
4193
4193
|
var fastUri = {
|
|
4194
4194
|
SCHEMES,
|
|
4195
4195
|
normalize,
|
|
4196
|
-
resolve
|
|
4196
|
+
resolve,
|
|
4197
4197
|
resolveComponent,
|
|
4198
4198
|
equal,
|
|
4199
4199
|
serialize,
|
|
@@ -19274,7 +19274,7 @@ var Protocol = class {
|
|
|
19274
19274
|
return;
|
|
19275
19275
|
}
|
|
19276
19276
|
const pollInterval = task2.pollInterval ?? this._options?.defaultTaskPollInterval ?? 1e3;
|
|
19277
|
-
await new Promise((
|
|
19277
|
+
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
19278
19278
|
options?.signal?.throwIfAborted();
|
|
19279
19279
|
}
|
|
19280
19280
|
} catch (error2) {
|
|
@@ -19291,7 +19291,7 @@ var Protocol = class {
|
|
|
19291
19291
|
*/
|
|
19292
19292
|
request(request, resultSchema, options) {
|
|
19293
19293
|
const { relatedRequestId, resumptionToken, onresumptiontoken, task, relatedTask } = options ?? {};
|
|
19294
|
-
return new Promise((
|
|
19294
|
+
return new Promise((resolve, reject) => {
|
|
19295
19295
|
const earlyReject = (error2) => {
|
|
19296
19296
|
reject(error2);
|
|
19297
19297
|
};
|
|
@@ -19369,7 +19369,7 @@ var Protocol = class {
|
|
|
19369
19369
|
if (!parseResult.success) {
|
|
19370
19370
|
reject(parseResult.error);
|
|
19371
19371
|
} else {
|
|
19372
|
-
|
|
19372
|
+
resolve(parseResult.data);
|
|
19373
19373
|
}
|
|
19374
19374
|
} catch (error2) {
|
|
19375
19375
|
reject(error2);
|
|
@@ -19630,12 +19630,12 @@ var Protocol = class {
|
|
|
19630
19630
|
}
|
|
19631
19631
|
} catch {
|
|
19632
19632
|
}
|
|
19633
|
-
return new Promise((
|
|
19633
|
+
return new Promise((resolve, reject) => {
|
|
19634
19634
|
if (signal.aborted) {
|
|
19635
19635
|
reject(new McpError(ErrorCode.InvalidRequest, "Request cancelled"));
|
|
19636
19636
|
return;
|
|
19637
19637
|
}
|
|
19638
|
-
const timeoutId = setTimeout(
|
|
19638
|
+
const timeoutId = setTimeout(resolve, interval);
|
|
19639
19639
|
signal.addEventListener("abort", () => {
|
|
19640
19640
|
clearTimeout(timeoutId);
|
|
19641
19641
|
reject(new McpError(ErrorCode.InvalidRequest, "Request cancelled"));
|
|
@@ -20735,7 +20735,7 @@ var McpServer = class {
|
|
|
20735
20735
|
let task = createTaskResult.task;
|
|
20736
20736
|
const pollInterval = task.pollInterval ?? 5e3;
|
|
20737
20737
|
while (task.status !== "completed" && task.status !== "failed" && task.status !== "cancelled") {
|
|
20738
|
-
await new Promise((
|
|
20738
|
+
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
20739
20739
|
const updatedTask = await extra.taskStore.getTask(taskId);
|
|
20740
20740
|
if (!updatedTask) {
|
|
20741
20741
|
throw new McpError(ErrorCode.InternalError, `Task ${taskId} not found during polling`);
|
|
@@ -21384,12 +21384,12 @@ var StdioServerTransport = class {
|
|
|
21384
21384
|
this.onclose?.();
|
|
21385
21385
|
}
|
|
21386
21386
|
send(message) {
|
|
21387
|
-
return new Promise((
|
|
21387
|
+
return new Promise((resolve) => {
|
|
21388
21388
|
const json = serializeMessage(message);
|
|
21389
21389
|
if (this._stdout.write(json)) {
|
|
21390
|
-
|
|
21390
|
+
resolve();
|
|
21391
21391
|
} else {
|
|
21392
|
-
this._stdout.once("drain",
|
|
21392
|
+
this._stdout.once("drain", resolve);
|
|
21393
21393
|
}
|
|
21394
21394
|
});
|
|
21395
21395
|
}
|
|
@@ -21401,115 +21401,13 @@ import { createRequire } from "node:module";
|
|
|
21401
21401
|
import { fileURLToPath } from "node:url";
|
|
21402
21402
|
|
|
21403
21403
|
// ../core/src/host-profile.ts
|
|
21404
|
-
import {
|
|
21405
|
-
import { homedir } from "node:os";
|
|
21406
|
-
import { resolve } from "node:path";
|
|
21407
|
-
var PROFILE_KEYS = ["endpoint", "expectedInstanceId", "credentialPath"];
|
|
21408
|
-
var LEGACY_SELECTION_KEYS = ["port", "stateDir", "apiToken", "apiVisibility"];
|
|
21409
|
-
var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
21410
|
-
var CONFLICTING_ENV = ["OURS_API_TOKEN", "OURS_PORT", "OURS_STATE_DIR", "OURS_DAEMON_ID"];
|
|
21411
|
-
function profileError(reason) {
|
|
21412
|
-
return new Error(`Invalid external host profile: ${reason}`);
|
|
21413
|
-
}
|
|
21414
|
-
function validateHostProfile(value) {
|
|
21415
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
21416
|
-
throw profileError("expected a complete host profile object.");
|
|
21417
|
-
}
|
|
21418
|
-
const record2 = value;
|
|
21419
|
-
const present = PROFILE_KEYS.filter((key) => Object.hasOwn(record2, key));
|
|
21420
|
-
if (present.length !== PROFILE_KEYS.length) {
|
|
21421
|
-
throw profileError("expected a complete host profile tuple: endpoint, expectedInstanceId, credentialPath.");
|
|
21422
|
-
}
|
|
21423
|
-
const mixed = LEGACY_SELECTION_KEYS.filter((key) => Object.hasOwn(record2, key));
|
|
21424
|
-
if (mixed.length) throw profileError(`legacy selection keys cannot be mixed with a host profile (${mixed.join(", ")}).`);
|
|
21425
|
-
const endpoint = record2.endpoint;
|
|
21426
|
-
const expectedInstanceId = record2.expectedInstanceId;
|
|
21427
|
-
const credentialPath = record2.credentialPath;
|
|
21428
|
-
if (typeof endpoint !== "string" || endpoint.trim() !== endpoint || endpoint === "") {
|
|
21429
|
-
throw profileError("endpoint must be a non-empty HTTP or HTTPS origin.");
|
|
21430
|
-
}
|
|
21431
|
-
if (typeof expectedInstanceId !== "string" || !UUID.test(expectedInstanceId)) {
|
|
21432
|
-
throw profileError("expectedInstanceId must be a lowercase UUID.");
|
|
21433
|
-
}
|
|
21434
|
-
if (typeof credentialPath !== "string" || credentialPath === "" || !credentialPath.startsWith("/") || resolve(credentialPath) !== credentialPath) {
|
|
21435
|
-
throw profileError("credentialPath must be a normalized absolute path.");
|
|
21436
|
-
}
|
|
21437
|
-
let url;
|
|
21438
|
-
try {
|
|
21439
|
-
url = new URL(endpoint);
|
|
21440
|
-
} catch {
|
|
21441
|
-
throw profileError("endpoint must be an HTTP or HTTPS origin.");
|
|
21442
|
-
}
|
|
21443
|
-
if (url.protocol !== "http:" && url.protocol !== "https:" || url.username || url.password || url.pathname !== "/" || url.search || url.hash) {
|
|
21444
|
-
throw profileError("endpoint must be an HTTP or HTTPS origin without credentials, path, query, or fragment.");
|
|
21445
|
-
}
|
|
21446
|
-
return { endpoint: url.origin, expectedInstanceId, credentialPath };
|
|
21447
|
-
}
|
|
21448
|
-
function readProfileObject(configPath) {
|
|
21449
|
-
let text;
|
|
21450
|
-
try {
|
|
21451
|
-
text = readFileSync(configPath, "utf8");
|
|
21452
|
-
} catch {
|
|
21453
|
-
throw new Error(`Cannot read host profile ${JSON.stringify(configPath)}.`);
|
|
21454
|
-
}
|
|
21455
|
-
let value;
|
|
21456
|
-
try {
|
|
21457
|
-
value = JSON.parse(text);
|
|
21458
|
-
} catch {
|
|
21459
|
-
throw profileError(`config ${JSON.stringify(configPath)} is not valid JSON.`);
|
|
21460
|
-
}
|
|
21461
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) throw profileError(`config ${JSON.stringify(configPath)} must be an object.`);
|
|
21462
|
-
return value;
|
|
21463
|
-
}
|
|
21464
|
-
function assertPrivateRegularFile(configPath) {
|
|
21465
|
-
let stat;
|
|
21466
|
-
try {
|
|
21467
|
-
stat = lstatSync(configPath);
|
|
21468
|
-
} catch {
|
|
21469
|
-
throw new Error(`Cannot read host profile ${JSON.stringify(configPath)}.`);
|
|
21470
|
-
}
|
|
21471
|
-
if (!stat.isFile()) throw profileError(`config ${JSON.stringify(configPath)} must be a regular file.`);
|
|
21472
|
-
const currentUid = process.getuid?.();
|
|
21473
|
-
if (currentUid === void 0 || stat.uid !== currentUid) throw profileError(`config ${JSON.stringify(configPath)} must be owned by the current user.`);
|
|
21474
|
-
if ((stat.mode & 63) !== 0) throw profileError(`config ${JSON.stringify(configPath)} must have private permissions.`);
|
|
21475
|
-
}
|
|
21476
|
-
function readHostProfile(configPath) {
|
|
21477
|
-
const record2 = readProfileObject(configPath);
|
|
21478
|
-
const found = PROFILE_KEYS.filter((key) => Object.hasOwn(record2, key));
|
|
21479
|
-
if (found.length === 0) return null;
|
|
21480
|
-
assertPrivateRegularFile(configPath);
|
|
21481
|
-
return validateHostProfile(record2);
|
|
21482
|
-
}
|
|
21483
|
-
function nonempty(env, key) {
|
|
21484
|
-
return (env[key] ?? "").trim() !== "";
|
|
21485
|
-
}
|
|
21404
|
+
import { readGatewayClientProfile, validateGatewayClientProfile } from "@ours.network/sdk/client";
|
|
21486
21405
|
function hostProfileSelectionFromEnv(env = process.env) {
|
|
21487
|
-
const
|
|
21488
|
-
const managedPath = resolve(env.HOME || homedir(), ".ours-client", "profile.json");
|
|
21489
|
-
let configPath = explicit;
|
|
21490
|
-
if (!configPath) {
|
|
21491
|
-
try {
|
|
21492
|
-
lstatSync(managedPath);
|
|
21493
|
-
configPath = managedPath;
|
|
21494
|
-
} catch (error2) {
|
|
21495
|
-
if (error2.code !== "ENOENT") {
|
|
21496
|
-
throw new Error(`Cannot read host profile ${JSON.stringify(managedPath)}.`);
|
|
21497
|
-
}
|
|
21498
|
-
configPath = resolve(homedir(), ".ours", "config.json");
|
|
21499
|
-
if (!existsSync(configPath)) return null;
|
|
21500
|
-
}
|
|
21501
|
-
}
|
|
21502
|
-
const profile = readHostProfile(configPath);
|
|
21503
|
-
if (profile === null) {
|
|
21504
|
-
if (resolve(configPath) === managedPath) throw profileError("managed client config must contain a complete host profile tuple.");
|
|
21505
|
-
return null;
|
|
21506
|
-
}
|
|
21507
|
-
const conflicting = CONFLICTING_ENV.filter((key) => nonempty(env, key));
|
|
21508
|
-
if (conflicting.length) throw profileError(`${conflicting.join(", ")} conflicts with host-profile mode.`);
|
|
21406
|
+
const { configPath, ...profile } = readGatewayClientProfile(env);
|
|
21509
21407
|
return { profile, configPath };
|
|
21510
21408
|
}
|
|
21511
21409
|
function hostProfileFromEnv(env = process.env) {
|
|
21512
|
-
return hostProfileSelectionFromEnv(env)
|
|
21410
|
+
return hostProfileSelectionFromEnv(env).profile;
|
|
21513
21411
|
}
|
|
21514
21412
|
|
|
21515
21413
|
// ../core/src/native-session.ts
|
|
@@ -21527,7 +21425,7 @@ function encodeControlResponse(value) {
|
|
|
21527
21425
|
|
|
21528
21426
|
// src/control-server.mjs
|
|
21529
21427
|
function sendControlCommand(socketPath, capability, message, timeoutMs = 2e3) {
|
|
21530
|
-
return new Promise((
|
|
21428
|
+
return new Promise((resolve, reject) => {
|
|
21531
21429
|
const socket = createConnection(socketPath);
|
|
21532
21430
|
let buffer = "";
|
|
21533
21431
|
const timer = setTimeout(() => {
|
|
@@ -21548,7 +21446,7 @@ function sendControlCommand(socketPath, capability, message, timeoutMs = 2e3) {
|
|
|
21548
21446
|
try {
|
|
21549
21447
|
const response = JSON.parse(buffer);
|
|
21550
21448
|
if (!response.ok) reject(new Error(response.error || "monitor control failed"));
|
|
21551
|
-
else
|
|
21449
|
+
else resolve(response);
|
|
21552
21450
|
} catch (error2) {
|
|
21553
21451
|
reject(error2);
|
|
21554
21452
|
}
|
|
@@ -21601,7 +21499,7 @@ function waitForForegroundMail(identity, nativeSessionId, {
|
|
|
21601
21499
|
commandFor = foregroundWatchProcess
|
|
21602
21500
|
} = {}) {
|
|
21603
21501
|
if (typeof identity !== "string" || !identity.trim()) return Promise.reject(new Error("identity is required"));
|
|
21604
|
-
return new Promise((
|
|
21502
|
+
return new Promise((resolve, reject) => {
|
|
21605
21503
|
const invocation = commandFor(identity, nativeSessionId, env);
|
|
21606
21504
|
const child = spawnImpl(invocation.command, invocation.args, {
|
|
21607
21505
|
env: invocation.env ?? env,
|
|
@@ -21633,7 +21531,7 @@ function waitForForegroundMail(identity, nativeSessionId, {
|
|
|
21633
21531
|
const newline = stdout.indexOf("\n");
|
|
21634
21532
|
if (newline === -1) return;
|
|
21635
21533
|
const event = stdout.slice(0, newline).trim();
|
|
21636
|
-
if (event) finish(
|
|
21534
|
+
if (event) finish(resolve, event);
|
|
21637
21535
|
});
|
|
21638
21536
|
child.once("exit", (code, childSignal) => {
|
|
21639
21537
|
if (settled) return;
|
package/dist/network-watch.mjs
CHANGED
|
@@ -1,128 +1,27 @@
|
|
|
1
1
|
// src/network-watch.mjs
|
|
2
|
-
import { homedir
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
3
|
import { dirname as dirname2, join as join3 } from "node:path";
|
|
4
4
|
|
|
5
5
|
// ../core/src/host-profile.ts
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
import { resolve } from "node:path";
|
|
9
|
-
var PROFILE_KEYS = ["endpoint", "expectedInstanceId", "credentialPath"];
|
|
10
|
-
var LEGACY_SELECTION_KEYS = ["port", "stateDir", "apiToken", "apiVisibility"];
|
|
11
|
-
var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
12
|
-
var CONFLICTING_ENV = ["OURS_API_TOKEN", "OURS_PORT", "OURS_STATE_DIR", "OURS_DAEMON_ID"];
|
|
13
|
-
function profileError(reason) {
|
|
14
|
-
return new Error(`Invalid external host profile: ${reason}`);
|
|
15
|
-
}
|
|
16
|
-
function validateHostProfile(value) {
|
|
17
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
18
|
-
throw profileError("expected a complete host profile object.");
|
|
19
|
-
}
|
|
20
|
-
const record = value;
|
|
21
|
-
const present = PROFILE_KEYS.filter((key) => Object.hasOwn(record, key));
|
|
22
|
-
if (present.length !== PROFILE_KEYS.length) {
|
|
23
|
-
throw profileError("expected a complete host profile tuple: endpoint, expectedInstanceId, credentialPath.");
|
|
24
|
-
}
|
|
25
|
-
const mixed = LEGACY_SELECTION_KEYS.filter((key) => Object.hasOwn(record, key));
|
|
26
|
-
if (mixed.length) throw profileError(`legacy selection keys cannot be mixed with a host profile (${mixed.join(", ")}).`);
|
|
27
|
-
const endpoint = record.endpoint;
|
|
28
|
-
const expectedInstanceId = record.expectedInstanceId;
|
|
29
|
-
const credentialPath = record.credentialPath;
|
|
30
|
-
if (typeof endpoint !== "string" || endpoint.trim() !== endpoint || endpoint === "") {
|
|
31
|
-
throw profileError("endpoint must be a non-empty HTTP or HTTPS origin.");
|
|
32
|
-
}
|
|
33
|
-
if (typeof expectedInstanceId !== "string" || !UUID.test(expectedInstanceId)) {
|
|
34
|
-
throw profileError("expectedInstanceId must be a lowercase UUID.");
|
|
35
|
-
}
|
|
36
|
-
if (typeof credentialPath !== "string" || credentialPath === "" || !credentialPath.startsWith("/") || resolve(credentialPath) !== credentialPath) {
|
|
37
|
-
throw profileError("credentialPath must be a normalized absolute path.");
|
|
38
|
-
}
|
|
39
|
-
let url;
|
|
40
|
-
try {
|
|
41
|
-
url = new URL(endpoint);
|
|
42
|
-
} catch {
|
|
43
|
-
throw profileError("endpoint must be an HTTP or HTTPS origin.");
|
|
44
|
-
}
|
|
45
|
-
if (url.protocol !== "http:" && url.protocol !== "https:" || url.username || url.password || url.pathname !== "/" || url.search || url.hash) {
|
|
46
|
-
throw profileError("endpoint must be an HTTP or HTTPS origin without credentials, path, query, or fragment.");
|
|
47
|
-
}
|
|
48
|
-
return { endpoint: url.origin, expectedInstanceId, credentialPath };
|
|
49
|
-
}
|
|
50
|
-
function readProfileObject(configPath) {
|
|
51
|
-
let text;
|
|
52
|
-
try {
|
|
53
|
-
text = readFileSync(configPath, "utf8");
|
|
54
|
-
} catch {
|
|
55
|
-
throw new Error(`Cannot read host profile ${JSON.stringify(configPath)}.`);
|
|
56
|
-
}
|
|
57
|
-
let value;
|
|
58
|
-
try {
|
|
59
|
-
value = JSON.parse(text);
|
|
60
|
-
} catch {
|
|
61
|
-
throw profileError(`config ${JSON.stringify(configPath)} is not valid JSON.`);
|
|
62
|
-
}
|
|
63
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) throw profileError(`config ${JSON.stringify(configPath)} must be an object.`);
|
|
64
|
-
return value;
|
|
65
|
-
}
|
|
66
|
-
function assertPrivateRegularFile(configPath) {
|
|
67
|
-
let stat;
|
|
68
|
-
try {
|
|
69
|
-
stat = lstatSync(configPath);
|
|
70
|
-
} catch {
|
|
71
|
-
throw new Error(`Cannot read host profile ${JSON.stringify(configPath)}.`);
|
|
72
|
-
}
|
|
73
|
-
if (!stat.isFile()) throw profileError(`config ${JSON.stringify(configPath)} must be a regular file.`);
|
|
74
|
-
const currentUid = process.getuid?.();
|
|
75
|
-
if (currentUid === void 0 || stat.uid !== currentUid) throw profileError(`config ${JSON.stringify(configPath)} must be owned by the current user.`);
|
|
76
|
-
if ((stat.mode & 63) !== 0) throw profileError(`config ${JSON.stringify(configPath)} must have private permissions.`);
|
|
77
|
-
}
|
|
78
|
-
function readHostProfile(configPath) {
|
|
79
|
-
const record = readProfileObject(configPath);
|
|
80
|
-
const found = PROFILE_KEYS.filter((key) => Object.hasOwn(record, key));
|
|
81
|
-
if (found.length === 0) return null;
|
|
82
|
-
assertPrivateRegularFile(configPath);
|
|
83
|
-
return validateHostProfile(record);
|
|
84
|
-
}
|
|
85
|
-
function nonempty(env, key) {
|
|
86
|
-
return (env[key] ?? "").trim() !== "";
|
|
87
|
-
}
|
|
6
|
+
import { readGatewayClientProfile, validateGatewayClientProfile } from "@ours.network/sdk/client";
|
|
7
|
+
var validateHostProfile = validateGatewayClientProfile;
|
|
88
8
|
function hostProfileSelectionFromEnv(env = process.env) {
|
|
89
|
-
const
|
|
90
|
-
const managedPath = resolve(env.HOME || homedir(), ".ours-client", "profile.json");
|
|
91
|
-
let configPath = explicit;
|
|
92
|
-
if (!configPath) {
|
|
93
|
-
try {
|
|
94
|
-
lstatSync(managedPath);
|
|
95
|
-
configPath = managedPath;
|
|
96
|
-
} catch (error) {
|
|
97
|
-
if (error.code !== "ENOENT") {
|
|
98
|
-
throw new Error(`Cannot read host profile ${JSON.stringify(managedPath)}.`);
|
|
99
|
-
}
|
|
100
|
-
configPath = resolve(homedir(), ".ours", "config.json");
|
|
101
|
-
if (!existsSync(configPath)) return null;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
const profile = readHostProfile(configPath);
|
|
105
|
-
if (profile === null) {
|
|
106
|
-
if (resolve(configPath) === managedPath) throw profileError("managed client config must contain a complete host profile tuple.");
|
|
107
|
-
return null;
|
|
108
|
-
}
|
|
109
|
-
const conflicting = CONFLICTING_ENV.filter((key) => nonempty(env, key));
|
|
110
|
-
if (conflicting.length) throw profileError(`${conflicting.join(", ")} conflicts with host-profile mode.`);
|
|
9
|
+
const { configPath, ...profile } = readGatewayClientProfile(env);
|
|
111
10
|
return { profile, configPath };
|
|
112
11
|
}
|
|
113
12
|
function hostProfileFromEnv(env = process.env) {
|
|
114
|
-
return hostProfileSelectionFromEnv(env)
|
|
13
|
+
return hostProfileSelectionFromEnv(env).profile;
|
|
115
14
|
}
|
|
116
15
|
|
|
117
16
|
// ../core/src/native-session.ts
|
|
118
17
|
import { createHash as createHash2, randomUUID } from "node:crypto";
|
|
119
18
|
import { chmod, mkdir, readFile, rename, unlink, writeFile } from "node:fs/promises";
|
|
120
|
-
import { dirname, join as join2, resolve
|
|
19
|
+
import { dirname, join as join2, resolve } from "node:path";
|
|
121
20
|
import { attachOursClient } from "@ours.network/sdk";
|
|
122
21
|
|
|
123
22
|
// ../core/src/session-guard.ts
|
|
124
23
|
import { createHash } from "node:crypto";
|
|
125
|
-
import { openSync, closeSync, lstatSync
|
|
24
|
+
import { openSync, closeSync, lstatSync, mkdirSync, chmodSync, constants } from "node:fs";
|
|
126
25
|
import { join } from "node:path";
|
|
127
26
|
import { createRequire } from "node:module";
|
|
128
27
|
var BUSY_TIMEOUT_MS = 5e3;
|
|
@@ -153,7 +52,7 @@ function ensureGuardFile(guardPath) {
|
|
|
153
52
|
} catch (error) {
|
|
154
53
|
if (error.code !== "EEXIST") throw error;
|
|
155
54
|
}
|
|
156
|
-
const stat =
|
|
55
|
+
const stat = lstatSync(guardPath);
|
|
157
56
|
if (!stat.isFile() || stat.uid !== process.getuid() || (stat.mode & 63) !== 0 || stat.nlink !== 1) {
|
|
158
57
|
throw new Error("Native session guard file must be an owner-only regular file");
|
|
159
58
|
}
|
|
@@ -169,11 +68,11 @@ function acquireSessionGuard(recordPath) {
|
|
|
169
68
|
const hash = createHash("sha256").update(recordPath).digest("hex");
|
|
170
69
|
const guardPath = join(base, `${hash}.guard`);
|
|
171
70
|
ensureGuardFile(guardPath);
|
|
172
|
-
const before =
|
|
71
|
+
const before = lstatSync(guardPath);
|
|
173
72
|
const Database = resolveDatabase();
|
|
174
73
|
const db = new Database(guardPath);
|
|
175
74
|
try {
|
|
176
|
-
const after =
|
|
75
|
+
const after = lstatSync(guardPath);
|
|
177
76
|
if (before.dev !== after.dev || before.ino !== after.ino || before.mode !== after.mode || before.uid !== after.uid) {
|
|
178
77
|
throw new Error("Native session guard file changed during acquisition");
|
|
179
78
|
}
|
|
@@ -195,7 +94,7 @@ function acquireSessionGuard(recordPath) {
|
|
|
195
94
|
|
|
196
95
|
// ../core/src/native-session.ts
|
|
197
96
|
var RECORD_VERSION = 1;
|
|
198
|
-
var
|
|
97
|
+
var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
199
98
|
var clients = /* @__PURE__ */ new Map();
|
|
200
99
|
var operations = /* @__PURE__ */ new Map();
|
|
201
100
|
function selector(value) {
|
|
@@ -205,10 +104,10 @@ function selector(value) {
|
|
|
205
104
|
return value;
|
|
206
105
|
}
|
|
207
106
|
function nativeSessionRecordPath(hostRecordRoot, instanceId, nativeSessionId) {
|
|
208
|
-
if (!hostRecordRoot || !hostRecordRoot.startsWith("/") ||
|
|
107
|
+
if (!hostRecordRoot || !hostRecordRoot.startsWith("/") || resolve(hostRecordRoot) !== hostRecordRoot) {
|
|
209
108
|
throw new Error("Native session host record root must be a normalized absolute path.");
|
|
210
109
|
}
|
|
211
|
-
if (!
|
|
110
|
+
if (!UUID.test(instanceId)) throw new Error("Native session daemon instance must be a lowercase UUID.");
|
|
212
111
|
const hash = createHash2("sha256").update(selector(nativeSessionId), "utf8").digest("hex");
|
|
213
112
|
return join2(hostRecordRoot, "sessions", instanceId, `${hash}.json`);
|
|
214
113
|
}
|
|
@@ -224,7 +123,7 @@ function parseRecord(text, path) {
|
|
|
224
123
|
}
|
|
225
124
|
const record = value;
|
|
226
125
|
const keys = Object.keys(record).sort();
|
|
227
|
-
if (keys.join(",") !== "ownerInstanceId,state,version" || record.version !== RECORD_VERSION || typeof record.ownerInstanceId !== "string" || !
|
|
126
|
+
if (keys.join(",") !== "ownerInstanceId,state,version" || record.version !== RECORD_VERSION || typeof record.ownerInstanceId !== "string" || !UUID.test(record.ownerInstanceId) || !["active", "pending", "ended"].includes(String(record.state))) {
|
|
228
127
|
throw new Error(`Invalid native session record at ${path}.`);
|
|
229
128
|
}
|
|
230
129
|
return record;
|
|
@@ -258,8 +157,8 @@ async function writeRecord(path, record) {
|
|
|
258
157
|
async function serialized(key, operation) {
|
|
259
158
|
const predecessor = operations.get(key) ?? Promise.resolve();
|
|
260
159
|
let release;
|
|
261
|
-
const gate = new Promise((
|
|
262
|
-
release =
|
|
160
|
+
const gate = new Promise((resolve2) => {
|
|
161
|
+
release = resolve2;
|
|
263
162
|
});
|
|
264
163
|
const tail = predecessor.catch(() => {
|
|
265
164
|
}).then(() => gate);
|
|
@@ -358,7 +257,7 @@ async function runNetworkWatch({
|
|
|
358
257
|
if (typeof nativeSessionId !== "string" || !nativeSessionId.trim()) throw new Error("native session id is required");
|
|
359
258
|
const profile = profileValue ?? hostProfileFromEnv(env);
|
|
360
259
|
if (!profile) throw new Error("A selected host network profile is required.");
|
|
361
|
-
const appPath = env.OURS_MCP_CONFIG || join3(env.HOME ||
|
|
260
|
+
const appPath = env.OURS_MCP_CONFIG || join3(env.HOME || homedir(), ".ours-mcp", "config.json");
|
|
362
261
|
const hostRecordRoot = hostRecordRootValue ?? dirname2(appPath);
|
|
363
262
|
const controller = new AbortController();
|
|
364
263
|
const stop = () => controller.abort();
|