@akshar5/cohall 0.11.2 → 0.11.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/CHANGELOG.md +13 -0
- package/README.md +4 -4
- package/bin/cohall.js +184 -165
- package/bin/cohall.js.map +12 -12
- package/docs/grok-bot.md +4 -3
- package/docs/install.md +3 -3
- package/docs/integrations.md +4 -0
- package/docs/services.md +3 -2
- package/package.json +1 -1
package/bin/cohall.js
CHANGED
|
@@ -17,7 +17,7 @@ var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
|
17
17
|
|
|
18
18
|
// packages/protocol/src/index.ts
|
|
19
19
|
import { Effect, Schema } from "effect";
|
|
20
|
-
var version = "0.11.
|
|
20
|
+
var version = "0.11.3", maxSocketPayloadBytes, maxAttachmentBytes, maxTaskAttachments = 2, maxProgressNoteBytes = 1024, bounded = (maxLength) => Schema.String.check(Schema.isMinLength(1), Schema.isMaxLength(maxLength)), optionalText = (maxLength) => Schema.String.check(Schema.isMaxLength(maxLength)), boundedArray = (schema, maxLength) => Schema.Array(schema).check(Schema.isMaxLength(maxLength)), count, uuid = (name) => Schema.String.check(Schema.isUUID(4)).pipe(Schema.brand(name)), isoTimestamp = (name) => Schema.String.check(Schema.isPattern(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,9})?Z$/, {
|
|
21
21
|
expected: "an ISO-8601 UTC timestamp"
|
|
22
22
|
})).pipe(Schema.brand(name)), BotId, Bot, DeviceId, ThreadId, MessageId, TaskId, TaskRequestId, TaskRunId, ClarificationId, AuthSessionId, OperationId, Timestamp, TaskDeadline, taskDeadlineError = "Task deadline exceeded", taskDeadlinePassed = (task, time = Date.now()) => task.expiresAt !== undefined && Date.parse(task.expiresAt) <= time, Platform, Provider, DeviceStatus, TaskStatus, OperationStatus, TaskTraceEventKind, MessageRole, ConnectionRole, AuthSession, CreatePairingInput, PairingCredential, ExchangePairingInput, SessionCredential, PairingResult, Capability, Workspace, Device, maxDevicePageDevices = 16, maxDevicePageResponseBytes, DevicePage, minimumDeviceOperationVersion = "0.5.0", parsedVersion = (value) => {
|
|
23
23
|
const match = /^v?(\d+)\.(\d+)\.(\d+)(-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/.exec(value);
|
|
@@ -420,7 +420,7 @@ var init_src = __esm(() => {
|
|
|
420
420
|
});
|
|
421
421
|
|
|
422
422
|
// apps/relay/src/config.ts
|
|
423
|
-
import { Effect as Effect13, Schema as
|
|
423
|
+
import { Effect as Effect13, Schema as Schema16 } from "effect";
|
|
424
424
|
import { access as access5, chmod as chmod7, mkdir as mkdir9, readFile as readFile4, writeFile as writeFile10 } from "node:fs/promises";
|
|
425
425
|
import { homedir as homedir5, platform as platform5 } from "node:os";
|
|
426
426
|
import { isAbsolute as isAbsolute6, join as join10, resolve as resolve6 } from "node:path";
|
|
@@ -455,14 +455,14 @@ var RelayConfiguration, defaultDataDirectory = () => {
|
|
|
455
455
|
throw new Error(`${name} must be true or false`);
|
|
456
456
|
}, isLoopback2 = (host) => host === "127.0.0.1" || host === "localhost" || host === "::1", loadEnvironmentConfiguration;
|
|
457
457
|
var init_config = __esm(() => {
|
|
458
|
-
RelayConfiguration =
|
|
459
|
-
host:
|
|
460
|
-
port:
|
|
461
|
-
token:
|
|
462
|
-
dataDirectory:
|
|
463
|
-
databasePath:
|
|
464
|
-
allowRemote:
|
|
465
|
-
historyTaskLimit:
|
|
458
|
+
RelayConfiguration = Schema16.Struct({
|
|
459
|
+
host: Schema16.NonEmptyString,
|
|
460
|
+
port: Schema16.Int.check(Schema16.isBetween({ minimum: 1, maximum: 65535 })),
|
|
461
|
+
token: Schema16.String.check(Schema16.isMinLength(32)),
|
|
462
|
+
dataDirectory: Schema16.NonEmptyString,
|
|
463
|
+
databasePath: Schema16.NonEmptyString,
|
|
464
|
+
allowRemote: Schema16.Boolean,
|
|
465
|
+
historyTaskLimit: Schema16.Int.check(Schema16.isBetween({ minimum: 100, maximum: 1e5 }))
|
|
466
466
|
});
|
|
467
467
|
loadEnvironmentConfiguration = Effect13.tryPromise({
|
|
468
468
|
try: async () => {
|
|
@@ -482,7 +482,7 @@ var init_config = __esm(() => {
|
|
|
482
482
|
throw new Error("The Cohall relay owner token must be at least 32 characters");
|
|
483
483
|
}
|
|
484
484
|
const historyTaskLimit = Number(process.env.COHALL_HISTORY_TASK_LIMIT ?? "1000");
|
|
485
|
-
return
|
|
485
|
+
return Schema16.decodeUnknownSync(RelayConfiguration)({
|
|
486
486
|
host,
|
|
487
487
|
port,
|
|
488
488
|
token,
|
|
@@ -673,12 +673,12 @@ __export(exports_store, {
|
|
|
673
673
|
RelayStore: () => exports_store,
|
|
674
674
|
PersistenceError: () => PersistenceError
|
|
675
675
|
});
|
|
676
|
-
import { Context as Context2, Effect as Effect14, Layer as Layer2, Schema as
|
|
676
|
+
import { Context as Context2, Effect as Effect14, Layer as Layer2, Schema as Schema17 } from "effect";
|
|
677
677
|
import { createHash as createHash2, randomBytes } from "node:crypto";
|
|
678
678
|
var PersistenceError, TaskProgressError, TaskInputError, TaskDeadlineError, TaskRequestError, Service2, operationError = (operation) => (cause) => new PersistenceError({
|
|
679
679
|
operation,
|
|
680
680
|
message: cause instanceof Error ? cause.message : String(cause)
|
|
681
|
-
}), decode2 = (operation, schema, value) =>
|
|
681
|
+
}), decode2 = (operation, schema, value) => Schema17.decodeUnknownEffect(schema)(value).pipe(Effect14.mapError(operationError(operation))), threadFromRow = (row) => decode2("RelayStore.decodeThread", Thread, {
|
|
682
682
|
id: row.id,
|
|
683
683
|
title: row.title,
|
|
684
684
|
createdAt: row.created_at,
|
|
@@ -777,7 +777,7 @@ var PersistenceError, TaskProgressError, TaskInputError, TaskDeadlineError, Task
|
|
|
777
777
|
kind: row.kind,
|
|
778
778
|
at: row.created_at,
|
|
779
779
|
...row.detail === null ? {} : { detail: row.detail }
|
|
780
|
-
}), rolesFromRow = (row) =>
|
|
780
|
+
}), rolesFromRow = (row) => Schema17.decodeUnknownSync(Schema17.Array(ConnectionRole))(JSON.parse(row.roles_json)), authSessionFromRow = (row) => {
|
|
781
781
|
const roles = rolesFromRow(row);
|
|
782
782
|
const role = roles[0];
|
|
783
783
|
return role === undefined ? Effect14.fail(new PersistenceError({
|
|
@@ -841,7 +841,7 @@ var PersistenceError, TaskProgressError, TaskInputError, TaskDeadlineError, Task
|
|
|
841
841
|
}
|
|
842
842
|
return events;
|
|
843
843
|
}, interruptedTaskStatus = `CASE
|
|
844
|
-
WHEN json_array_length(clarifications_json) > 0
|
|
844
|
+
WHEN provider = 'grok-bot' AND json_array_length(clarifications_json) > 0
|
|
845
845
|
AND json_extract(clarifications_json, '$[#-1].answer') IS NULL THEN 'needs_input'
|
|
846
846
|
ELSE 'queued' END`, makeService = (db, retainedTerminalTasks = 1000) => {
|
|
847
847
|
const requestHash = (input) => {
|
|
@@ -1115,9 +1115,9 @@ var PersistenceError, TaskProgressError, TaskInputError, TaskDeadlineError, Task
|
|
|
1115
1115
|
const devices = new Map;
|
|
1116
1116
|
let retainedTasks = 0;
|
|
1117
1117
|
for (const row of rows) {
|
|
1118
|
-
const status =
|
|
1119
|
-
const provider =
|
|
1120
|
-
const deviceId =
|
|
1118
|
+
const status = Schema17.decodeUnknownSync(TaskStatus)(row.status);
|
|
1119
|
+
const provider = Schema17.decodeUnknownSync(Provider)(row.provider);
|
|
1120
|
+
const deviceId = Schema17.decodeUnknownSync(DeviceId)(row.device_id);
|
|
1121
1121
|
retainedTasks += row.tasks;
|
|
1122
1122
|
totalStatus[status] += row.tasks;
|
|
1123
1123
|
totalProviders.set(provider, (totalProviders.get(provider) ?? 0) + row.tasks);
|
|
@@ -1509,7 +1509,8 @@ var PersistenceError, TaskProgressError, TaskInputError, TaskDeadlineError, Task
|
|
|
1509
1509
|
const pendingTasksFor = Effect14.fn("RelayStore.pendingTasksFor")(function* (deviceId) {
|
|
1510
1510
|
const rows = yield* Effect14.try({
|
|
1511
1511
|
try: () => db.query(`SELECT * FROM tasks WHERE target_device_id = ?
|
|
1512
|
-
AND status IN ('queued', 'cancelling')
|
|
1512
|
+
AND status IN ('queued', 'cancelling')
|
|
1513
|
+
ORDER BY dispatched_at IS NULL, created_at, id LIMIT 100`).all(deviceId),
|
|
1513
1514
|
catch: operationError("RelayStore.pendingTasksFor")
|
|
1514
1515
|
});
|
|
1515
1516
|
return yield* Effect14.forEach(rows, (row) => taskFromRow(db, row));
|
|
@@ -1909,7 +1910,7 @@ var PersistenceError, TaskProgressError, TaskInputError, TaskDeadlineError, Task
|
|
|
1909
1910
|
if (pairing === null) {
|
|
1910
1911
|
throw new Error("Pairing credential is invalid, expired, or already used");
|
|
1911
1912
|
}
|
|
1912
|
-
const roles =
|
|
1913
|
+
const roles = Schema17.decodeUnknownSync(Schema17.Array(ConnectionRole))(JSON.parse(pairing.roles_json));
|
|
1913
1914
|
const deviceId = roles.includes("device") ? makeDeviceId() : undefined;
|
|
1914
1915
|
const consumed = db.query("UPDATE auth_pairings SET used_at = ? WHERE token_hash = ? AND used_at IS NULL").run(timestamp, pairing.token_hash);
|
|
1915
1916
|
if (consumed.changes !== 1) {
|
|
@@ -2183,19 +2184,19 @@ var init_store = __esm(() => {
|
|
|
2183
2184
|
init_src();
|
|
2184
2185
|
init_database();
|
|
2185
2186
|
init_store();
|
|
2186
|
-
PersistenceError = class PersistenceError extends
|
|
2187
|
-
operation:
|
|
2188
|
-
message:
|
|
2189
|
-
missingRecord:
|
|
2187
|
+
PersistenceError = class PersistenceError extends Schema17.TaggedErrorClass()("RelayStore.PersistenceError", {
|
|
2188
|
+
operation: Schema17.String,
|
|
2189
|
+
message: Schema17.String,
|
|
2190
|
+
missingRecord: Schema17.optionalKey(Schema17.Literals(["task", "operation"]))
|
|
2190
2191
|
}) {
|
|
2191
2192
|
};
|
|
2192
|
-
TaskProgressError = class TaskProgressError extends
|
|
2193
|
+
TaskProgressError = class TaskProgressError extends Schema17.TaggedErrorClass()("RelayStore.TaskProgressError", { status: Schema17.Literals([403, 409]), message: Schema17.String }) {
|
|
2193
2194
|
};
|
|
2194
|
-
TaskInputError = class TaskInputError extends
|
|
2195
|
+
TaskInputError = class TaskInputError extends Schema17.TaggedErrorClass()("RelayStore.TaskInputError", { status: Schema17.Literals([403, 409]), message: Schema17.String }) {
|
|
2195
2196
|
};
|
|
2196
|
-
TaskDeadlineError = class TaskDeadlineError extends
|
|
2197
|
+
TaskDeadlineError = class TaskDeadlineError extends Schema17.TaggedErrorClass()("RelayStore.TaskDeadlineError", { status: Schema17.Literals([400, 409]), message: Schema17.String }) {
|
|
2197
2198
|
};
|
|
2198
|
-
TaskRequestError = class TaskRequestError extends
|
|
2199
|
+
TaskRequestError = class TaskRequestError extends Schema17.TaggedErrorClass()("RelayStore.TaskRequestError", { status: Schema17.Literals([409, 410]), message: Schema17.String }) {
|
|
2199
2200
|
};
|
|
2200
2201
|
Service2 = class Service2 extends Context2.Service()("@cohall/RelayStore") {
|
|
2201
2202
|
};
|
|
@@ -2211,7 +2212,7 @@ __export(exports_main, {
|
|
|
2211
2212
|
canReadTaskAttachments: () => canReadTaskAttachments,
|
|
2212
2213
|
canDispatchTaskToDevice: () => canDispatchTaskToDevice
|
|
2213
2214
|
});
|
|
2214
|
-
import { Effect as Effect15, ManagedRuntime, Schema as
|
|
2215
|
+
import { Effect as Effect15, ManagedRuntime, Schema as Schema18, Schedule as Schedule4 } from "effect";
|
|
2215
2216
|
import { createHash as createHash3, timingSafeEqual } from "node:crypto";
|
|
2216
2217
|
import { access as access6, chmod as chmod8 } from "node:fs/promises";
|
|
2217
2218
|
import { createServer } from "node:http";
|
|
@@ -2314,7 +2315,7 @@ Content-Length: 0\r
|
|
|
2314
2315
|
}, body = (request, decode3) => Effect15.tryPromise({
|
|
2315
2316
|
try: () => request.json(),
|
|
2316
2317
|
catch: () => new RequestError({ status: 400, message: "Expected a JSON request body" })
|
|
2317
|
-
}).pipe(Effect15.flatMap(decode3), Effect15.mapError((cause) => cause instanceof RequestError ? cause : new RequestError({ status: 400, message: String(cause).slice(0, 2048) }))), pathId = (schema, value) =>
|
|
2318
|
+
}).pipe(Effect15.flatMap(decode3), Effect15.mapError((cause) => cause instanceof RequestError ? cause : new RequestError({ status: 400, message: String(cause).slice(0, 2048) }))), pathId = (schema, value) => Schema18.decodeUnknownEffect(schema)(value).pipe(Effect15.mapError(() => new RequestError({ status: 400, message: `Invalid identifier: ${value}` }))), scoreDevice = (device, input, sourceDeviceId) => {
|
|
2318
2319
|
const prompt = `${input.prompt} ${input.context ?? ""}`.toLowerCase();
|
|
2319
2320
|
const needsXcode = /\b(xcode|ios|macos|swiftui|app store)\b/.test(prompt);
|
|
2320
2321
|
const needsBrowser = /\b(browser|chrome|youtube|twitter|logged[- ]?in|signed[- ]?in|x\.com)\b/.test(prompt);
|
|
@@ -3056,9 +3057,9 @@ var init_main = __esm(async () => {
|
|
|
3056
3057
|
init_config();
|
|
3057
3058
|
init_hub();
|
|
3058
3059
|
init_store();
|
|
3059
|
-
RequestError = class RequestError extends
|
|
3060
|
-
status:
|
|
3061
|
-
message:
|
|
3060
|
+
RequestError = class RequestError extends Schema18.TaggedErrorClass()("Relay.RequestError", {
|
|
3061
|
+
status: Schema18.Int,
|
|
3062
|
+
message: Schema18.String
|
|
3062
3063
|
}) {
|
|
3063
3064
|
};
|
|
3064
3065
|
maxTaskRequestBodyBytes = 3 * 1024 * 1024;
|
|
@@ -3413,7 +3414,9 @@ var executableDirectories = () => {
|
|
|
3413
3414
|
"/opt/homebrew/bin",
|
|
3414
3415
|
"/usr/local/bin"
|
|
3415
3416
|
];
|
|
3416
|
-
return [
|
|
3417
|
+
return [
|
|
3418
|
+
...new Set([...configured, ...common.filter((path) => path !== undefined)].map((path) => resolve(path)))
|
|
3419
|
+
];
|
|
3417
3420
|
};
|
|
3418
3421
|
var findExecutable = (command) => {
|
|
3419
3422
|
const paths = isAbsolute(command) || command.includes("/") || command.includes("\\") ? [""] : executableDirectories();
|
|
@@ -3905,7 +3908,7 @@ var run = (options) => Effect3.callback((resume, signal) => {
|
|
|
3905
3908
|
});
|
|
3906
3909
|
|
|
3907
3910
|
// apps/device/src/cli.ts
|
|
3908
|
-
import { Effect as Effect10, Schema as
|
|
3911
|
+
import { Effect as Effect10, Schema as Schema13 } from "effect";
|
|
3909
3912
|
import { access as access4, mkdir as mkdir8, open as open5, stat as stat4, writeFile as writeFile8 } from "node:fs/promises";
|
|
3910
3913
|
import { homedir as homedir4 } from "node:os";
|
|
3911
3914
|
import { dirname as dirname6, join as join9, resolve as resolve5 } from "node:path";
|
|
@@ -4306,7 +4309,7 @@ var StoredConfiguration = Schema4.Struct({
|
|
|
4306
4309
|
version: Schema4.Literal(1),
|
|
4307
4310
|
relayUrl: Schema4.NonEmptyString,
|
|
4308
4311
|
deviceId: DeviceId,
|
|
4309
|
-
deviceName:
|
|
4312
|
+
deviceName: Device.fields.name,
|
|
4310
4313
|
workspaces: WorkspaceList,
|
|
4311
4314
|
clientToken: Schema4.optionalKey(Schema4.NonEmptyString),
|
|
4312
4315
|
deviceToken: Schema4.optionalKey(Schema4.NonEmptyString),
|
|
@@ -4315,6 +4318,10 @@ var StoredConfiguration = Schema4.Struct({
|
|
|
4315
4318
|
sandbox: Schema4.optionalKey(Sandbox),
|
|
4316
4319
|
grokGateway: Schema4.optionalKey(Schema4.NonEmptyString)
|
|
4317
4320
|
});
|
|
4321
|
+
var ReadableConfiguration = Schema4.Struct({
|
|
4322
|
+
...StoredConfiguration.fields,
|
|
4323
|
+
deviceName: Schema4.NonEmptyString
|
|
4324
|
+
});
|
|
4318
4325
|
var ClientConfiguration = Schema4.Struct({
|
|
4319
4326
|
relayUrl: Schema4.NonEmptyString,
|
|
4320
4327
|
token: Schema4.NonEmptyString,
|
|
@@ -4326,7 +4333,7 @@ var DeviceConfiguration = Schema4.Struct({
|
|
|
4326
4333
|
relayUrl: Schema4.NonEmptyString,
|
|
4327
4334
|
token: Schema4.NonEmptyString,
|
|
4328
4335
|
id: DeviceId,
|
|
4329
|
-
name:
|
|
4336
|
+
name: Device.fields.name,
|
|
4330
4337
|
workspaces: WorkspaceList,
|
|
4331
4338
|
providers: Schema4.optionalKey(ProviderList),
|
|
4332
4339
|
model: Schema4.optionalKey(Schema4.NonEmptyString),
|
|
@@ -4395,7 +4402,7 @@ var readStoredConfiguration = async () => {
|
|
|
4395
4402
|
await chmod2(path, 384);
|
|
4396
4403
|
}
|
|
4397
4404
|
try {
|
|
4398
|
-
return Schema4.decodeUnknownSync(
|
|
4405
|
+
return Schema4.decodeUnknownSync(ReadableConfiguration)(JSON.parse(await readFile(path, "utf8")));
|
|
4399
4406
|
} catch (cause) {
|
|
4400
4407
|
throw new Error(`Invalid Cohall configuration at ${path}: ${String(cause)}`);
|
|
4401
4408
|
}
|
|
@@ -4465,7 +4472,7 @@ var environmentProviders = (stored) => {
|
|
|
4465
4472
|
};
|
|
4466
4473
|
var storedOrDefaults = async () => {
|
|
4467
4474
|
const stored = await readStoredConfiguration();
|
|
4468
|
-
return stored ??
|
|
4475
|
+
return stored ?? ReadableConfiguration.make({
|
|
4469
4476
|
version: 1,
|
|
4470
4477
|
relayUrl: "http://127.0.0.1:8787",
|
|
4471
4478
|
deviceId: makeDeviceId(),
|
|
@@ -4820,6 +4827,7 @@ var allDeviceHealth = (devices, localVersion) => {
|
|
|
4820
4827
|
// apps/device/src/grok-bot.ts
|
|
4821
4828
|
init_src();
|
|
4822
4829
|
import { Effect as Effect6, Schedule as Schedule2, Schema as Schema7 } from "effect";
|
|
4830
|
+
import { constants as constants2 } from "node:fs";
|
|
4823
4831
|
import { open as open2 } from "node:fs/promises";
|
|
4824
4832
|
import { isIP } from "node:net";
|
|
4825
4833
|
|
|
@@ -5028,6 +5036,24 @@ var cleanupBotReply = async (taskId, runId) => {
|
|
|
5028
5036
|
}
|
|
5029
5037
|
};
|
|
5030
5038
|
|
|
5039
|
+
// apps/device/src/bounded-file.ts
|
|
5040
|
+
var readBoundedFile = async (handle, limit) => {
|
|
5041
|
+
const buffer = Buffer.allocUnsafe(limit + 1);
|
|
5042
|
+
let size = 0;
|
|
5043
|
+
while (size < buffer.length) {
|
|
5044
|
+
const { bytesRead } = await handle.read({
|
|
5045
|
+
buffer,
|
|
5046
|
+
offset: size,
|
|
5047
|
+
length: buffer.length - size,
|
|
5048
|
+
position: null
|
|
5049
|
+
});
|
|
5050
|
+
if (bytesRead === 0)
|
|
5051
|
+
break;
|
|
5052
|
+
size += bytesRead;
|
|
5053
|
+
}
|
|
5054
|
+
return buffer.subarray(0, size);
|
|
5055
|
+
};
|
|
5056
|
+
|
|
5031
5057
|
// apps/device/src/grok-bot.ts
|
|
5032
5058
|
var maxResponseBytes = 4 * 1024 * 1024;
|
|
5033
5059
|
var maxDiscoveryBytes = 64 * 1024;
|
|
@@ -5066,13 +5092,15 @@ var decode = (schema, value, label) => {
|
|
|
5066
5092
|
};
|
|
5067
5093
|
var readConnection = async (path) => {
|
|
5068
5094
|
const value = await (async () => {
|
|
5069
|
-
const file = await open2(path, "
|
|
5095
|
+
const file = await open2(path, constants2.O_RDONLY | (process.platform === "win32" ? 0 : constants2.O_NONBLOCK));
|
|
5070
5096
|
try {
|
|
5071
|
-
const
|
|
5072
|
-
|
|
5073
|
-
|
|
5097
|
+
const metadata = await file.stat();
|
|
5098
|
+
if (!metadata.isFile())
|
|
5099
|
+
throw new Error("Discovery must be a regular file");
|
|
5100
|
+
const buffer = await readBoundedFile(file, maxDiscoveryBytes);
|
|
5101
|
+
if (buffer.length > maxDiscoveryBytes)
|
|
5074
5102
|
throw new Error("Discovery file exceeds its size limit");
|
|
5075
|
-
return decode(Discovery, JSON.parse(buffer.
|
|
5103
|
+
return decode(Discovery, JSON.parse(buffer.toString("utf8")), "discovery file");
|
|
5076
5104
|
} finally {
|
|
5077
5105
|
await file.close();
|
|
5078
5106
|
}
|
|
@@ -5290,7 +5318,8 @@ var runGrokBot = async (path, task, signal, supportsClarification = false) => {
|
|
|
5290
5318
|
};
|
|
5291
5319
|
|
|
5292
5320
|
// apps/device/src/setup.ts
|
|
5293
|
-
|
|
5321
|
+
init_src();
|
|
5322
|
+
import { Effect as Effect7, Schema as Schema8 } from "effect";
|
|
5294
5323
|
import { hostname as hostname2 } from "node:os";
|
|
5295
5324
|
import { Writable } from "node:stream";
|
|
5296
5325
|
import { createInterface } from "node:readline/promises";
|
|
@@ -5376,7 +5405,7 @@ var guidedSetupInput = async (options, prompter) => {
|
|
|
5376
5405
|
const root = await prompter.answer("Workspace root", existing?.workspaces[0] ?? options.cwd);
|
|
5377
5406
|
workspaces = existing !== undefined && root === existing.workspaces[0] ? existing.workspaces : [root];
|
|
5378
5407
|
}
|
|
5379
|
-
const deviceName = options.clientOnly ? undefined : options.deviceName ?? await prompter.answer("Device name", existing?.deviceName ?? hostname2());
|
|
5408
|
+
const deviceName = options.clientOnly ? undefined : Schema8.decodeUnknownSync(Device.fields.name)(options.deviceName ?? await prompter.answer("Device name", existing?.deviceName ?? hostname2()));
|
|
5380
5409
|
const providerInput = options.providers ?? (options.clientOnly ? existing?.providers?.join(",") ?? "auto" : await prompter.answer("Providers", existing?.providers?.join(",") ?? "auto"));
|
|
5381
5410
|
const providers = providerInput === "auto" ? "auto" : parseProviders(providerInput);
|
|
5382
5411
|
const token = options.readToken === undefined ? hasRequiredCredentials ? undefined : await prompter.secret("Pairing token") : await options.readToken();
|
|
@@ -5398,7 +5427,7 @@ var guidedSetupInput = async (options, prompter) => {
|
|
|
5398
5427
|
|
|
5399
5428
|
// apps/device/src/relay-migration.ts
|
|
5400
5429
|
init_src();
|
|
5401
|
-
import { Effect as Effect8, Schema as
|
|
5430
|
+
import { Effect as Effect8, Schema as Schema10 } from "effect";
|
|
5402
5431
|
import { createHash } from "node:crypto";
|
|
5403
5432
|
import { createReadStream } from "node:fs";
|
|
5404
5433
|
import {
|
|
@@ -5417,6 +5446,7 @@ import {
|
|
|
5417
5446
|
} from "node:fs/promises";
|
|
5418
5447
|
import { basename, dirname as dirname5, join as join6, resolve as resolve4 } from "node:path";
|
|
5419
5448
|
import { backup as sqliteBackup, DatabaseSync } from "node:sqlite";
|
|
5449
|
+
import { isDeepStrictEqual } from "node:util";
|
|
5420
5450
|
import { WebSocket } from "ws";
|
|
5421
5451
|
|
|
5422
5452
|
// apps/device/src/service.ts
|
|
@@ -5426,9 +5456,9 @@ import { homedir as homedir3 } from "node:os";
|
|
|
5426
5456
|
import { dirname as dirname4, isAbsolute as isAbsolute4, join as join5 } from "node:path";
|
|
5427
5457
|
|
|
5428
5458
|
// apps/device/src/upgrade.ts
|
|
5429
|
-
import { Schema as
|
|
5459
|
+
import { Schema as Schema9 } from "effect";
|
|
5430
5460
|
import { execa as execa2 } from "execa";
|
|
5431
|
-
import { constants as
|
|
5461
|
+
import { constants as constants3 } from "node:fs";
|
|
5432
5462
|
import {
|
|
5433
5463
|
access as access2,
|
|
5434
5464
|
chmod as chmod4,
|
|
@@ -5489,14 +5519,14 @@ var compareVersions = (left, right) => {
|
|
|
5489
5519
|
}
|
|
5490
5520
|
return 0;
|
|
5491
5521
|
};
|
|
5492
|
-
var PackageManager =
|
|
5493
|
-
var RestartReceipt =
|
|
5494
|
-
version:
|
|
5495
|
-
fromVersion:
|
|
5522
|
+
var PackageManager = Schema9.Literals(["npm", "bun", "pnpm"]);
|
|
5523
|
+
var RestartReceipt = Schema9.Struct({
|
|
5524
|
+
version: Schema9.String,
|
|
5525
|
+
fromVersion: Schema9.String,
|
|
5496
5526
|
packageManager: PackageManager,
|
|
5497
|
-
pendingServices:
|
|
5498
|
-
restartedServices:
|
|
5499
|
-
restartingService:
|
|
5527
|
+
pendingServices: Schema9.Array(Schema9.String),
|
|
5528
|
+
restartedServices: Schema9.Array(Schema9.String),
|
|
5529
|
+
restartingService: Schema9.optionalKey(Schema9.String)
|
|
5500
5530
|
});
|
|
5501
5531
|
var pnpmEnvironment = () => Object.fromEntries([
|
|
5502
5532
|
["COREPACK_ENABLE_PROJECT_SPEC", "0"],
|
|
@@ -5732,7 +5762,7 @@ var trustedExecutable = async (command, options = {}) => {
|
|
|
5732
5762
|
const candidates = isAbsolute3(command) ? [command] : (process.env.PATH ?? "").split(delimiter2).filter(Boolean).flatMap((directory) => executableNames(command).map((name) => join4(directory, name)));
|
|
5733
5763
|
let failure;
|
|
5734
5764
|
for (const path of candidates) {
|
|
5735
|
-
const available2 = await access2(path, operatingSystem() === "win32" ?
|
|
5765
|
+
const available2 = await access2(path, operatingSystem() === "win32" ? constants3.F_OK : constants3.X_OK).then(() => true).catch(() => false);
|
|
5736
5766
|
if (!available2)
|
|
5737
5767
|
continue;
|
|
5738
5768
|
try {
|
|
@@ -5778,9 +5808,9 @@ var trustedServices = async (services, resolveExecutable) => {
|
|
|
5778
5808
|
}
|
|
5779
5809
|
return secured;
|
|
5780
5810
|
};
|
|
5781
|
-
var ScheduledTaskAction =
|
|
5782
|
-
Execute:
|
|
5783
|
-
Arguments:
|
|
5811
|
+
var ScheduledTaskAction = Schema9.Struct({
|
|
5812
|
+
Execute: Schema9.NonEmptyString,
|
|
5813
|
+
Arguments: Schema9.NonEmptyString
|
|
5784
5814
|
});
|
|
5785
5815
|
var powershellLiteral = "(?:[^'\\r\\n]|'')+";
|
|
5786
5816
|
var scheduledTaskBootstrap = new RegExp([
|
|
@@ -5797,7 +5827,7 @@ var scheduledTaskEntrypoint = (output) => {
|
|
|
5797
5827
|
} catch {
|
|
5798
5828
|
return;
|
|
5799
5829
|
}
|
|
5800
|
-
const decoded =
|
|
5830
|
+
const decoded = Schema9.decodeUnknownOption(ScheduledTaskAction)(value);
|
|
5801
5831
|
if (decoded._tag === "None")
|
|
5802
5832
|
return;
|
|
5803
5833
|
const action = decoded.value;
|
|
@@ -5962,7 +5992,7 @@ ${result.stderr}`);
|
|
|
5962
5992
|
throw new Error(`Active ${service.label} uses ${serviceEntrypoint}, but this Cohall CLI uses ${installation.entrypoint}. Run the service executable's upgrade command so its installation is updated before restart.`);
|
|
5963
5993
|
}
|
|
5964
5994
|
};
|
|
5965
|
-
var readReceipt = async (path) => readFile2(path, "utf8").then((content) =>
|
|
5995
|
+
var readReceipt = async (path) => readFile2(path, "utf8").then((content) => Schema9.decodeUnknownOption(RestartReceipt)(JSON.parse(content))).then((decoded) => decoded._tag === "Some" ? decoded.value : undefined).catch(() => {
|
|
5966
5996
|
return;
|
|
5967
5997
|
});
|
|
5968
5998
|
var writeReceipt = async (path, value) => {
|
|
@@ -6038,7 +6068,9 @@ var upgrade = async (options) => {
|
|
|
6038
6068
|
platform: runtimePlatform,
|
|
6039
6069
|
...options.resolveExecutable === undefined ? {} : { resolveExecutable }
|
|
6040
6070
|
});
|
|
6041
|
-
if (previous?.version === options.currentVersion && (target === previous.version || target === "latest" && options.restart)) {
|
|
6071
|
+
if (previous?.version === options.currentVersion && (target === previous.version || target === "latest" && options.restart) && await installedVersion(installation.entrypoint).catch(() => {
|
|
6072
|
+
return;
|
|
6073
|
+
}) === previous.version) {
|
|
6042
6074
|
const pending = candidates.filter((service) => previous.pendingServices.includes(service.id));
|
|
6043
6075
|
const active = await activeServices(runner, pending);
|
|
6044
6076
|
await assertServiceInstallations(runner, active, installation);
|
|
@@ -6437,10 +6469,10 @@ ${check.stderr}`)) {
|
|
|
6437
6469
|
};
|
|
6438
6470
|
|
|
6439
6471
|
// apps/device/src/relay-migration.ts
|
|
6440
|
-
var sha256 =
|
|
6441
|
-
var RelayBackupManifest =
|
|
6442
|
-
formatVersion:
|
|
6443
|
-
cohallVersion:
|
|
6472
|
+
var sha256 = Schema10.String.check(Schema10.isPattern(/^[a-f0-9]{64}$/, { expected: "a lowercase SHA-256 digest" }));
|
|
6473
|
+
var RelayBackupManifest = Schema10.Struct({
|
|
6474
|
+
formatVersion: Schema10.Literal(1),
|
|
6475
|
+
cohallVersion: Schema10.NonEmptyString,
|
|
6444
6476
|
createdAt: Timestamp,
|
|
6445
6477
|
databaseSha256: sha256,
|
|
6446
6478
|
ownerTokenSha256: sha256
|
|
@@ -6464,7 +6496,7 @@ var verifyBackupMember = async (path, maximumBytes) => {
|
|
|
6464
6496
|
};
|
|
6465
6497
|
var readManifest = async (path) => {
|
|
6466
6498
|
await verifyBackupMember(path, 16384);
|
|
6467
|
-
return
|
|
6499
|
+
return Schema10.decodeUnknownSync(RelayBackupManifest)(JSON.parse(await readFile3(path, "utf8")));
|
|
6468
6500
|
};
|
|
6469
6501
|
var verifyBackupDestinationParent = async (path) => {
|
|
6470
6502
|
if (process.platform === "win32") {
|
|
@@ -6656,7 +6688,7 @@ var verifyLegacyDeviceCredential = (relayUrl, token) => new Promise((resolveProm
|
|
|
6656
6688
|
});
|
|
6657
6689
|
socket.on("message", (data) => {
|
|
6658
6690
|
try {
|
|
6659
|
-
const event =
|
|
6691
|
+
const event = Schema10.decodeUnknownSync(SocketEvent)(JSON.parse(data.toString()));
|
|
6660
6692
|
if (event._tag === "Connected") {
|
|
6661
6693
|
finish();
|
|
6662
6694
|
} else if (event._tag === "Error") {
|
|
@@ -6706,6 +6738,9 @@ var switchRelay = async (options) => {
|
|
|
6706
6738
|
}
|
|
6707
6739
|
roles.push("device");
|
|
6708
6740
|
}
|
|
6741
|
+
if (!isDeepStrictEqual(await readStoredConfiguration(), configuration)) {
|
|
6742
|
+
throw new Error("Cohall configuration changed during relay verification. Retry the command.");
|
|
6743
|
+
}
|
|
6709
6744
|
const updated = configuration.relayUrl !== relayUrl;
|
|
6710
6745
|
if (updated) {
|
|
6711
6746
|
await writeStoredConfiguration(StoredConfiguration.make({ ...configuration, relayUrl }));
|
|
@@ -6729,38 +6764,18 @@ var switchRelay = async (options) => {
|
|
|
6729
6764
|
|
|
6730
6765
|
// apps/device/src/task-attachments.ts
|
|
6731
6766
|
init_src();
|
|
6732
|
-
import { Effect as Effect9, Schema as
|
|
6733
|
-
import { constants as
|
|
6767
|
+
import { Effect as Effect9, Schema as Schema11 } from "effect";
|
|
6768
|
+
import { constants as constants4 } from "node:fs";
|
|
6734
6769
|
import { lstat as lstat2, mkdtemp as mkdtemp3, mkdir as mkdir6, open as open3, readdir as readdir2, rm as rm4, writeFile as writeFile6 } from "node:fs/promises";
|
|
6735
6770
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
6736
6771
|
import { basename as basename2, join as join7 } from "node:path";
|
|
6737
|
-
|
|
6738
|
-
// apps/device/src/bounded-file.ts
|
|
6739
|
-
var readBoundedFile = async (handle, limit) => {
|
|
6740
|
-
const buffer = Buffer.allocUnsafe(limit + 1);
|
|
6741
|
-
let size = 0;
|
|
6742
|
-
while (size < buffer.length) {
|
|
6743
|
-
const { bytesRead } = await handle.read({
|
|
6744
|
-
buffer,
|
|
6745
|
-
offset: size,
|
|
6746
|
-
length: buffer.length - size,
|
|
6747
|
-
position: null
|
|
6748
|
-
});
|
|
6749
|
-
if (bytesRead === 0)
|
|
6750
|
-
break;
|
|
6751
|
-
size += bytesRead;
|
|
6752
|
-
}
|
|
6753
|
-
return buffer.subarray(0, size);
|
|
6754
|
-
};
|
|
6755
|
-
|
|
6756
|
-
// apps/device/src/task-attachments.ts
|
|
6757
6772
|
var readInputAttachments = async (paths2) => {
|
|
6758
6773
|
if (paths2.length > maxTaskAttachments) {
|
|
6759
6774
|
throw new Error(`A task supports at most ${maxTaskAttachments} input files`);
|
|
6760
6775
|
}
|
|
6761
6776
|
const names = new Set;
|
|
6762
6777
|
return Promise.all(paths2.map(async (path) => {
|
|
6763
|
-
const name =
|
|
6778
|
+
const name = Schema11.decodeUnknownSync(AttachmentName)(basename2(path));
|
|
6764
6779
|
const key = name.normalize("NFC").toLocaleLowerCase("en-US");
|
|
6765
6780
|
if (names.has(key)) {
|
|
6766
6781
|
throw new Error(`Attachment name ${name} is repeated`);
|
|
@@ -6770,7 +6785,7 @@ var readInputAttachments = async (paths2) => {
|
|
|
6770
6785
|
if (!source.isFile()) {
|
|
6771
6786
|
throw new Error(`Attachment ${name} must be a regular file`);
|
|
6772
6787
|
}
|
|
6773
|
-
const handle = await open3(path,
|
|
6788
|
+
const handle = await open3(path, constants4.O_RDONLY | (process.platform === "win32" ? 0 : constants4.O_NOFOLLOW | constants4.O_NONBLOCK));
|
|
6774
6789
|
try {
|
|
6775
6790
|
const metadata = await handle.stat();
|
|
6776
6791
|
if (!metadata.isFile() || metadata.dev !== source.dev || metadata.ino !== source.ino || metadata.size < 1 || metadata.size > maxAttachmentBytes) {
|
|
@@ -6818,7 +6833,7 @@ var collectOutputs = async (directory) => {
|
|
|
6818
6833
|
const files = [];
|
|
6819
6834
|
const names = new Set;
|
|
6820
6835
|
for (const entry of entries) {
|
|
6821
|
-
const name =
|
|
6836
|
+
const name = Schema11.decodeUnknownSync(AttachmentName)(entry.name);
|
|
6822
6837
|
if (!entry.isFile()) {
|
|
6823
6838
|
throw new Error(`Output ${name} must be a regular file`);
|
|
6824
6839
|
}
|
|
@@ -6827,7 +6842,7 @@ var collectOutputs = async (directory) => {
|
|
|
6827
6842
|
throw new Error(`Output ${name} repeats another file name`);
|
|
6828
6843
|
}
|
|
6829
6844
|
names.add(key);
|
|
6830
|
-
const handle = await open3(join7(directory, name),
|
|
6845
|
+
const handle = await open3(join7(directory, name), constants4.O_RDONLY | (process.platform === "win32" ? 0 : constants4.O_NOFOLLOW | constants4.O_NONBLOCK));
|
|
6831
6846
|
try {
|
|
6832
6847
|
const metadata = await handle.stat();
|
|
6833
6848
|
const pathMetadata = await lstat2(join7(directory, name));
|
|
@@ -6857,28 +6872,28 @@ import {
|
|
|
6857
6872
|
// apps/device/src/mcp-host-diagnostics.ts
|
|
6858
6873
|
init_src();
|
|
6859
6874
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
6860
|
-
import { Schema as
|
|
6875
|
+
import { Schema as Schema12 } from "effect";
|
|
6861
6876
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
6862
|
-
import { constants as
|
|
6877
|
+
import { constants as constants5 } from "node:fs";
|
|
6863
6878
|
import { lstat as lstat3, mkdir as mkdir7, open as open4, opendir, rename as rename4, rm as rm5, writeFile as writeFile7 } from "node:fs/promises";
|
|
6864
6879
|
import { join as join8 } from "node:path";
|
|
6865
6880
|
var maxRecords = 8;
|
|
6866
6881
|
var maxRecordBytes = 4096;
|
|
6867
6882
|
var retentionMs = 7 * 24 * 60 * 60 * 1000;
|
|
6868
6883
|
var recordName = /^[\da-f]{8}-[\da-f]{4}-4[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}\.json$/;
|
|
6869
|
-
var text3 =
|
|
6870
|
-
var count2 =
|
|
6871
|
-
var McpHostSession =
|
|
6872
|
-
schema_version:
|
|
6873
|
-
launch_id:
|
|
6884
|
+
var text3 = Schema12.String.check(Schema12.isMaxLength(128));
|
|
6885
|
+
var count2 = Schema12.Int.check(Schema12.isBetween({ minimum: 0, maximum: Number.MAX_SAFE_INTEGER }));
|
|
6886
|
+
var McpHostSession = Schema12.Struct({
|
|
6887
|
+
schema_version: Schema12.Literal(1),
|
|
6888
|
+
launch_id: Schema12.String.check(Schema12.isUUID(4)),
|
|
6874
6889
|
launched_at: Timestamp,
|
|
6875
6890
|
server_version: text3,
|
|
6876
|
-
initialized_at:
|
|
6877
|
-
client:
|
|
6878
|
-
tools_list:
|
|
6891
|
+
initialized_at: Schema12.optionalKey(Timestamp),
|
|
6892
|
+
client: Schema12.optionalKey(Schema12.Struct({ name: text3, version: text3 })),
|
|
6893
|
+
tools_list: Schema12.optionalKey(Schema12.Struct({ at: Timestamp, tool_count: count2 })),
|
|
6879
6894
|
tools_call_count: count2,
|
|
6880
|
-
last_tool_call_at:
|
|
6881
|
-
closed_at:
|
|
6895
|
+
last_tool_call_at: Schema12.optionalKey(Timestamp),
|
|
6896
|
+
closed_at: Schema12.optionalKey(Timestamp)
|
|
6882
6897
|
});
|
|
6883
6898
|
var storagePath = (configPath) => `${configPath}.mcp-hosts`;
|
|
6884
6899
|
var replaceRecord = async (source, target) => {
|
|
@@ -6935,7 +6950,7 @@ var readMcpHostDiagnostics = async (configPath = configurationPath()) => {
|
|
|
6935
6950
|
let invalid = 0;
|
|
6936
6951
|
for (const record2 of records.filter((record3) => record3.modified >= Date.now() - retentionMs).slice(0, maxRecords)) {
|
|
6937
6952
|
try {
|
|
6938
|
-
const handle = await open4(record2.path,
|
|
6953
|
+
const handle = await open4(record2.path, constants5.O_RDONLY | (process.platform === "win32" ? 0 : constants5.O_NOFOLLOW | constants5.O_NONBLOCK));
|
|
6939
6954
|
try {
|
|
6940
6955
|
const metadata = await handle.stat();
|
|
6941
6956
|
if (!metadata.isFile() || metadata.size > maxRecordBytes)
|
|
@@ -6943,7 +6958,7 @@ var readMcpHostDiagnostics = async (configPath = configurationPath()) => {
|
|
|
6943
6958
|
const data = await readBoundedFile(handle, maxRecordBytes);
|
|
6944
6959
|
if (data.length > maxRecordBytes)
|
|
6945
6960
|
throw new Error("Invalid record");
|
|
6946
|
-
sessions.push(
|
|
6961
|
+
sessions.push(Schema12.decodeUnknownSync(McpHostSession)(JSON.parse(data.toString("utf8"))));
|
|
6947
6962
|
} finally {
|
|
6948
6963
|
await handle.close();
|
|
6949
6964
|
}
|
|
@@ -7419,11 +7434,11 @@ var runCli = async (command, raw) => {
|
|
|
7419
7434
|
}
|
|
7420
7435
|
if (command === "reply") {
|
|
7421
7436
|
allowOptions(arguments_, ["message", "message-file", "error", "question", "run-id"]);
|
|
7422
|
-
const id =
|
|
7437
|
+
const id = Schema13.decodeUnknownSync(TaskId)(identifier(arguments_, "task id"));
|
|
7423
7438
|
const error = option(arguments_, "error");
|
|
7424
7439
|
const question = option(arguments_, "question");
|
|
7425
7440
|
const rawRunId = option(arguments_, "run-id");
|
|
7426
|
-
const runId = rawRunId === undefined ? undefined :
|
|
7441
|
+
const runId = rawRunId === undefined ? undefined : Schema13.decodeUnknownSync(TaskRunId)(rawRunId);
|
|
7427
7442
|
if ((error !== undefined || question !== undefined) && (option(arguments_, "message") !== undefined || option(arguments_, "message-file") !== undefined || error !== undefined && question !== undefined)) {
|
|
7428
7443
|
throw new Error("Use one of --question, --error, or --message/--message-file");
|
|
7429
7444
|
}
|
|
@@ -7431,7 +7446,7 @@ var runCli = async (command, raw) => {
|
|
|
7431
7446
|
if (error === undefined && question === undefined && message === undefined) {
|
|
7432
7447
|
throw new Error("A bot reply requires --message, --message-file, --error, or --question");
|
|
7433
7448
|
}
|
|
7434
|
-
const reply = question !== undefined ? { question:
|
|
7449
|
+
const reply = question !== undefined ? { question: Schema13.decodeUnknownSync(RequestTaskInput.fields.question)(question) } : error === undefined ? { result: message ?? "" } : { error };
|
|
7435
7450
|
await writeBotReply(id, reply, runId);
|
|
7436
7451
|
print({ submitted: true, task_id: id });
|
|
7437
7452
|
return;
|
|
@@ -7600,7 +7615,7 @@ var runCli = async (command, raw) => {
|
|
|
7600
7615
|
if (arguments_.positionals.length !== 2 || arguments_.positionals[0] !== "abandon") {
|
|
7601
7616
|
throw new Error("Usage: cohall upgrades [abandon <operation-id>]");
|
|
7602
7617
|
}
|
|
7603
|
-
print(await Effect10.runPromise(relay2.abandonOperation(
|
|
7618
|
+
print(await Effect10.runPromise(relay2.abandonOperation(Schema13.decodeUnknownSync(OperationId)(arguments_.positionals[1]))));
|
|
7604
7619
|
return;
|
|
7605
7620
|
}
|
|
7606
7621
|
print(await Effect10.runPromise(relay2.operations()));
|
|
@@ -7699,7 +7714,7 @@ var runCli = async (command, raw) => {
|
|
|
7699
7714
|
...model === undefined ? {} : { model },
|
|
7700
7715
|
...grokGateway === undefined ? {} : { grokGateway },
|
|
7701
7716
|
...(sandbox ?? existing?.sandbox) === undefined ? {} : {
|
|
7702
|
-
sandbox:
|
|
7717
|
+
sandbox: Schema13.decodeUnknownSync(Schema13.Literals(["read-only", "workspace-write", "danger-full-access"]))(sandbox ?? existing?.sandbox)
|
|
7703
7718
|
}
|
|
7704
7719
|
});
|
|
7705
7720
|
await writeStoredConfiguration(configuration2);
|
|
@@ -7864,11 +7879,11 @@ var runCli = async (command, raw) => {
|
|
|
7864
7879
|
}
|
|
7865
7880
|
if (command === "forget") {
|
|
7866
7881
|
allowOptions(arguments_, []);
|
|
7867
|
-
print(await Effect10.runPromise(relay2.forgetDevice(
|
|
7882
|
+
print(await Effect10.runPromise(relay2.forgetDevice(Schema13.decodeUnknownSync(DeviceId)(identifier(arguments_, "device id")))));
|
|
7868
7883
|
return;
|
|
7869
7884
|
}
|
|
7870
7885
|
allowOptions(arguments_, []);
|
|
7871
|
-
print(await Effect10.runPromise(relay2.revokeAuthSession(
|
|
7886
|
+
print(await Effect10.runPromise(relay2.revokeAuthSession(Schema13.decodeUnknownSync(AuthSessionId)(identifier(arguments_, "session id")))));
|
|
7872
7887
|
return;
|
|
7873
7888
|
}
|
|
7874
7889
|
const { configuration, relay } = await client();
|
|
@@ -7877,20 +7892,20 @@ var runCli = async (command, raw) => {
|
|
|
7877
7892
|
const rawQuestion = option(arguments_, "question");
|
|
7878
7893
|
if (rawQuestion === undefined)
|
|
7879
7894
|
throw new Error("--question is required");
|
|
7880
|
-
const question =
|
|
7881
|
-
const id = arguments_.positionals.length === 0 ? undefined :
|
|
7895
|
+
const question = Schema13.decodeUnknownSync(RequestTaskInput.fields.question)(rawQuestion);
|
|
7896
|
+
const id = arguments_.positionals.length === 0 ? undefined : Schema13.decodeUnknownSync(TaskId)(identifier(arguments_, "task id"));
|
|
7882
7897
|
const rawRunId = option(arguments_, "run-id");
|
|
7883
|
-
const runId = rawRunId === undefined ? undefined :
|
|
7898
|
+
const runId = rawRunId === undefined ? undefined : Schema13.decodeUnknownSync(TaskRunId)(rawRunId);
|
|
7884
7899
|
print(await Effect10.runPromise(requestInput(relay, configuration, question, id, runId)));
|
|
7885
7900
|
return;
|
|
7886
7901
|
}
|
|
7887
7902
|
if (command === "answer") {
|
|
7888
7903
|
allowOptions(arguments_, ["request-id", "message", "message-file"]);
|
|
7889
|
-
const id =
|
|
7904
|
+
const id = Schema13.decodeUnknownSync(TaskId)(identifier(arguments_, "task id"));
|
|
7890
7905
|
const requestId = option(arguments_, "request-id");
|
|
7891
7906
|
if (requestId === undefined)
|
|
7892
7907
|
throw new Error("--request-id is required; use the input request id from status or inbox");
|
|
7893
|
-
const input =
|
|
7908
|
+
const input = Schema13.decodeUnknownSync(AnswerTaskInput)({
|
|
7894
7909
|
requestId,
|
|
7895
7910
|
answer: await readInput(arguments_, "message")
|
|
7896
7911
|
});
|
|
@@ -7905,8 +7920,8 @@ var runCli = async (command, raw) => {
|
|
|
7905
7920
|
const note = option(arguments_, "message");
|
|
7906
7921
|
if (note === undefined)
|
|
7907
7922
|
throw new Error("--message is required");
|
|
7908
|
-
const input =
|
|
7909
|
-
print(await Effect10.runPromise(relay.reportTaskProgress(
|
|
7923
|
+
const input = Schema13.decodeUnknownSync(TaskProgressInput)({ note });
|
|
7924
|
+
print(await Effect10.runPromise(relay.reportTaskProgress(Schema13.decodeUnknownSync(TaskId)(rawId), input)));
|
|
7910
7925
|
return;
|
|
7911
7926
|
}
|
|
7912
7927
|
if (command === "devices") {
|
|
@@ -7966,15 +7981,15 @@ var runCli = async (command, raw) => {
|
|
|
7966
7981
|
const requestId = option(arguments_, "request-id");
|
|
7967
7982
|
const task = await Effect10.runPromise(createDelegation(relay, configuration, {
|
|
7968
7983
|
prompt,
|
|
7969
|
-
...requestId === undefined ? {} : { requestId:
|
|
7984
|
+
...requestId === undefined ? {} : { requestId: Schema13.decodeUnknownSync(TaskRequestId)(requestId) },
|
|
7970
7985
|
...target === undefined ? {} : { target },
|
|
7971
7986
|
...context === undefined ? {} : { context },
|
|
7972
|
-
...thread === undefined ? {} : { threadId:
|
|
7973
|
-
...parent === undefined ? {} : { parentTaskId:
|
|
7987
|
+
...thread === undefined ? {} : { threadId: Schema13.decodeUnknownSync(ThreadId)(thread) },
|
|
7988
|
+
...parent === undefined ? {} : { parentTaskId: Schema13.decodeUnknownSync(TaskId)(parent) },
|
|
7974
7989
|
...workspace === undefined ? {} : { workspace },
|
|
7975
|
-
...provider === undefined ? {} : { provider:
|
|
7990
|
+
...provider === undefined ? {} : { provider: Schema13.decodeUnknownSync(Provider)(provider) },
|
|
7976
7991
|
...attachments2.length === 0 ? {} : { attachments: attachments2 },
|
|
7977
|
-
...deadline === undefined ? {} : { expiresAt:
|
|
7992
|
+
...deadline === undefined ? {} : { expiresAt: Schema13.decodeUnknownSync(TaskDeadline)(deadline) }
|
|
7978
7993
|
}));
|
|
7979
7994
|
const completed = arguments_.options.has("no-wait") ? task : await Effect10.runPromise(waitForTask(relay, task, waitSeconds));
|
|
7980
7995
|
print(arguments_.options.has("no-wait") ? taskResult(completed) : await acknowledgedTaskResult(relay, completed));
|
|
@@ -7985,7 +8000,7 @@ var runCli = async (command, raw) => {
|
|
|
7985
8000
|
if (arguments_.positionals[0] === "ack") {
|
|
7986
8001
|
if (arguments_.positionals.length !== 2)
|
|
7987
8002
|
throw new Error("Usage: cohall inbox ack <task-id>");
|
|
7988
|
-
const id =
|
|
8003
|
+
const id = Schema13.decodeUnknownSync(TaskId)(arguments_.positionals[1]);
|
|
7989
8004
|
print(await Effect10.runPromise(relay.acknowledgeCompletion(id)));
|
|
7990
8005
|
return;
|
|
7991
8006
|
}
|
|
@@ -7995,13 +8010,13 @@ var runCli = async (command, raw) => {
|
|
|
7995
8010
|
}
|
|
7996
8011
|
if (command === "status") {
|
|
7997
8012
|
allowOptions(arguments_, []);
|
|
7998
|
-
const id =
|
|
8013
|
+
const id = Schema13.decodeUnknownSync(TaskId)(identifier(arguments_, "task id"));
|
|
7999
8014
|
print(taskResult(await Effect10.runPromise(relay.getTask(id))));
|
|
8000
8015
|
return;
|
|
8001
8016
|
}
|
|
8002
8017
|
if (command === "attachments") {
|
|
8003
8018
|
allowOptions(arguments_, []);
|
|
8004
|
-
const id =
|
|
8019
|
+
const id = Schema13.decodeUnknownSync(TaskId)(identifier(arguments_, "task id"));
|
|
8005
8020
|
print(await Effect10.runPromise(relay.listAttachments(id)));
|
|
8006
8021
|
return;
|
|
8007
8022
|
}
|
|
@@ -8014,10 +8029,10 @@ var runCli = async (command, raw) => {
|
|
|
8014
8029
|
if (destination === undefined) {
|
|
8015
8030
|
throw new Error("--output is required");
|
|
8016
8031
|
}
|
|
8017
|
-
const id =
|
|
8018
|
-
const name =
|
|
8032
|
+
const id = Schema13.decodeUnknownSync(TaskId)(arguments_.positionals[0]);
|
|
8033
|
+
const name = Schema13.decodeUnknownSync(AttachmentName)(arguments_.positionals[1]);
|
|
8019
8034
|
const directionInput = option(arguments_, "direction");
|
|
8020
|
-
const direction = directionInput === undefined ? undefined :
|
|
8035
|
+
const direction = directionInput === undefined ? undefined : Schema13.decodeUnknownSync(AttachmentDirection)(directionInput);
|
|
8021
8036
|
const data = await Effect10.runPromise(relay.readAttachment(id, name, direction));
|
|
8022
8037
|
await writeFile8(destination, data, { flag: "wx", mode: 384 });
|
|
8023
8038
|
print({ task_id: id, name, path: resolve5(destination), bytes: data.length });
|
|
@@ -8025,7 +8040,7 @@ var runCli = async (command, raw) => {
|
|
|
8025
8040
|
}
|
|
8026
8041
|
if (command === "trace") {
|
|
8027
8042
|
allowOptions(arguments_, ["follow"]);
|
|
8028
|
-
const id =
|
|
8043
|
+
const id = Schema13.decodeUnknownSync(TaskId)(identifier(arguments_, "task id"));
|
|
8029
8044
|
if (arguments_.options.has("follow")) {
|
|
8030
8045
|
await Effect10.runPromise(followTaskTrace(relay, id, printLine));
|
|
8031
8046
|
return;
|
|
@@ -8035,19 +8050,19 @@ var runCli = async (command, raw) => {
|
|
|
8035
8050
|
}
|
|
8036
8051
|
if (command === "wait") {
|
|
8037
8052
|
allowOptions(arguments_, ["timeout"]);
|
|
8038
|
-
const id =
|
|
8053
|
+
const id = Schema13.decodeUnknownSync(TaskId)(identifier(arguments_, "task id"));
|
|
8039
8054
|
print(taskResult(await Effect10.runPromise(waitForTask(relay, id, timeout(arguments_)))));
|
|
8040
8055
|
return;
|
|
8041
8056
|
}
|
|
8042
8057
|
if (command === "cancel") {
|
|
8043
8058
|
allowOptions(arguments_, []);
|
|
8044
|
-
const id =
|
|
8059
|
+
const id = Schema13.decodeUnknownSync(TaskId)(identifier(arguments_, "task id"));
|
|
8045
8060
|
print(taskResult(await Effect10.runPromise(relay.cancelTask(id))));
|
|
8046
8061
|
return;
|
|
8047
8062
|
}
|
|
8048
8063
|
if (command === "thread") {
|
|
8049
8064
|
allowOptions(arguments_, []);
|
|
8050
|
-
const id =
|
|
8065
|
+
const id = Schema13.decodeUnknownSync(ThreadId)(identifier(arguments_, "thread id"));
|
|
8051
8066
|
print(await Effect10.runPromise(threadContext(relay, id)));
|
|
8052
8067
|
return;
|
|
8053
8068
|
}
|
|
@@ -8056,15 +8071,15 @@ var runCli = async (command, raw) => {
|
|
|
8056
8071
|
|
|
8057
8072
|
// apps/device/src/daemon.ts
|
|
8058
8073
|
init_src();
|
|
8059
|
-
import { Effect as Effect11, Schedule as Schedule3, Schema as
|
|
8060
|
-
import { constants as
|
|
8074
|
+
import { Effect as Effect11, Schedule as Schedule3, Schema as Schema14 } from "effect";
|
|
8075
|
+
import { constants as constants6 } from "node:fs";
|
|
8061
8076
|
import { open as open6, realpath as realpath4, stat as stat5 } from "node:fs/promises";
|
|
8062
8077
|
import { arch, hostname as hostname3, platform as platform4 } from "node:os";
|
|
8063
8078
|
import { basename as basename3, isAbsolute as isAbsolute5, relative as relative2, sep } from "node:path";
|
|
8064
8079
|
import { WebSocket as WebSocket2 } from "ws";
|
|
8065
8080
|
var maxQueuedRelayMessages = 8;
|
|
8066
8081
|
|
|
8067
|
-
class DeviceConnectionError extends
|
|
8082
|
+
class DeviceConnectionError extends Schema14.TaggedErrorClass()("Device.ConnectionError", { message: Schema14.String }) {
|
|
8068
8083
|
}
|
|
8069
8084
|
var socketUrl = (configuration) => {
|
|
8070
8085
|
const url = new URL(configuration.relayUrl);
|
|
@@ -8151,31 +8166,35 @@ var allowedWorkspace = async (configuration, requested) => {
|
|
|
8151
8166
|
var openAllowedWorkspace = async (configuration, requested) => {
|
|
8152
8167
|
const path = await allowedWorkspace(configuration, requested);
|
|
8153
8168
|
const operatingSystem2 = platform4();
|
|
8154
|
-
const flags =
|
|
8169
|
+
const flags = constants6.O_RDONLY | (operatingSystem2 === "win32" ? 0 : constants6.O_DIRECTORY | constants6.O_NOFOLLOW);
|
|
8155
8170
|
const handle = await open6(path, flags);
|
|
8156
|
-
|
|
8157
|
-
|
|
8158
|
-
|
|
8159
|
-
|
|
8160
|
-
|
|
8161
|
-
|
|
8162
|
-
|
|
8163
|
-
cwd,
|
|
8164
|
-
validate: async () => {
|
|
8171
|
+
try {
|
|
8172
|
+
const identity = await handle.stat();
|
|
8173
|
+
if (!identity.isDirectory()) {
|
|
8174
|
+
throw new Error(`Workspace ${path} is not a directory`);
|
|
8175
|
+
}
|
|
8176
|
+
const cwd = operatingSystem2 === "linux" ? `/proc/self/fd/${handle.fd}` : path;
|
|
8177
|
+
const validate = async () => {
|
|
8165
8178
|
const current = await handle.stat();
|
|
8166
8179
|
if (!current.isDirectory() || current.dev !== identity.dev || current.ino !== identity.ino) {
|
|
8167
8180
|
throw new Error(`Workspace ${path} changed before provider startup`);
|
|
8168
8181
|
}
|
|
8182
|
+
const currentPath = await allowedWorkspace(configuration, cwd);
|
|
8169
8183
|
if (operatingSystem2 !== "linux") {
|
|
8170
|
-
const currentPath = await realpath4(path);
|
|
8171
8184
|
const currentPathIdentity = await stat5(currentPath);
|
|
8172
8185
|
if (currentPathIdentity.dev !== identity.dev || currentPathIdentity.ino !== identity.ino) {
|
|
8173
8186
|
throw new Error(`Workspace ${path} changed before provider startup`);
|
|
8174
8187
|
}
|
|
8175
8188
|
}
|
|
8176
|
-
}
|
|
8177
|
-
|
|
8178
|
-
|
|
8189
|
+
};
|
|
8190
|
+
await validate();
|
|
8191
|
+
return { cwd, validate, close: () => handle.close() };
|
|
8192
|
+
} catch (cause) {
|
|
8193
|
+
await handle.close().catch(() => {
|
|
8194
|
+
return;
|
|
8195
|
+
});
|
|
8196
|
+
throw cause;
|
|
8197
|
+
}
|
|
8179
8198
|
};
|
|
8180
8199
|
var promptFor = (task, deviceName, supportsClarification, files) => {
|
|
8181
8200
|
const context = task.context === undefined ? "" : `
|
|
@@ -8680,7 +8699,7 @@ var runDaemon = (configuration) => {
|
|
|
8680
8699
|
// apps/device/src/mcp.ts
|
|
8681
8700
|
init_src();
|
|
8682
8701
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
8683
|
-
import { Effect as Effect12, Schema as
|
|
8702
|
+
import { Effect as Effect12, Schema as Schema15 } from "effect";
|
|
8684
8703
|
import * as z from "zod/v4";
|
|
8685
8704
|
import { writeFile as writeFile9 } from "node:fs/promises";
|
|
8686
8705
|
|
|
@@ -8752,7 +8771,7 @@ var runMcp = async (configuration) => {
|
|
|
8752
8771
|
run_id: z.string().uuid().optional(),
|
|
8753
8772
|
question: z.string().min(1).max(maxClarificationBytes)
|
|
8754
8773
|
}
|
|
8755
|
-
}, async ({ task_id, run_id, question }) => output(await Effect12.runPromise(requestInput(client2, configuration,
|
|
8774
|
+
}, async ({ task_id, run_id, question }) => output(await Effect12.runPromise(requestInput(client2, configuration, Schema15.decodeUnknownSync(RequestTaskInput.fields.question)(question), task_id === undefined ? undefined : Schema15.decodeUnknownSync(TaskId)(task_id), run_id === undefined ? undefined : Schema15.decodeUnknownSync(TaskRunId)(run_id)))));
|
|
8756
8775
|
server.registerTool("task_answer", {
|
|
8757
8776
|
title: "Answer a worker's question",
|
|
8758
8777
|
description: "Answer the current clarification and resume the same task. Use input_request.id from task_status or delegate as request_id, or inputRequest.id from completion_inbox. Only the original requester or relay owner can answer. Use wait_task to collect the resumed result.",
|
|
@@ -8761,7 +8780,7 @@ var runMcp = async (configuration) => {
|
|
|
8761
8780
|
request_id: z.string().uuid(),
|
|
8762
8781
|
answer: z.string().min(1).max(maxClarificationBytes)
|
|
8763
8782
|
}
|
|
8764
|
-
}, async ({ task_id, request_id, answer }) => output(taskResult(await Effect12.runPromise(client2.answerTaskInput(
|
|
8783
|
+
}, async ({ task_id, request_id, answer }) => output(taskResult(await Effect12.runPromise(client2.answerTaskInput(Schema15.decodeUnknownSync(TaskId)(task_id), Schema15.decodeUnknownSync(AnswerTaskInput)({ requestId: request_id, answer }))))));
|
|
8765
8784
|
server.registerTool("task_progress", {
|
|
8766
8785
|
title: "Report task progress",
|
|
8767
8786
|
description: `Replace the latest progress note for a running task on this device. Use brief milestones, up to ${maxProgressNoteBytes} UTF-8 bytes. Inherits the delegated task ID when omitted.`,
|
|
@@ -8773,8 +8792,8 @@ var runMcp = async (configuration) => {
|
|
|
8773
8792
|
const id = task_id ?? configuration.mcpTaskId;
|
|
8774
8793
|
if (id === undefined)
|
|
8775
8794
|
throw new Error("Task id is required outside delegated work");
|
|
8776
|
-
const input =
|
|
8777
|
-
return output(await Effect12.runPromise(client2.reportTaskProgress(
|
|
8795
|
+
const input = Schema15.decodeUnknownSync(TaskProgressInput)({ note });
|
|
8796
|
+
return output(await Effect12.runPromise(client2.reportTaskProgress(Schema15.decodeUnknownSync(TaskId)(id), input)));
|
|
8778
8797
|
});
|
|
8779
8798
|
server.registerTool("list_devices", {
|
|
8780
8799
|
title: "List Cohall devices",
|
|
@@ -8820,7 +8839,7 @@ var runMcp = async (configuration) => {
|
|
|
8820
8839
|
const attachments2 = await readInputAttachments(attachment_paths ?? []);
|
|
8821
8840
|
const task = await Effect12.runPromise(createDelegation(client2, configuration, {
|
|
8822
8841
|
prompt,
|
|
8823
|
-
...request_id === undefined ? {} : { requestId:
|
|
8842
|
+
...request_id === undefined ? {} : { requestId: Schema15.decodeUnknownSync(TaskRequestId)(request_id) },
|
|
8824
8843
|
...provider === undefined ? {} : { provider },
|
|
8825
8844
|
...target === undefined ? {} : { target },
|
|
8826
8845
|
...context === undefined ? {} : { context },
|
|
@@ -8828,7 +8847,7 @@ var runMcp = async (configuration) => {
|
|
|
8828
8847
|
...parent_task_id === undefined ? {} : { parentTaskId: TaskId.make(parent_task_id) },
|
|
8829
8848
|
...workspace === undefined ? {} : { workspace },
|
|
8830
8849
|
...attachments2.length === 0 ? {} : { attachments: attachments2 },
|
|
8831
|
-
...deadline === undefined ? {} : { expiresAt:
|
|
8850
|
+
...deadline === undefined ? {} : { expiresAt: Schema15.decodeUnknownSync(TaskDeadline)(deadline) }
|
|
8832
8851
|
}), { signal });
|
|
8833
8852
|
const completed = wait ? await Effect12.runPromise(waitForTask(client2, task, timeout_seconds), { signal }) : task;
|
|
8834
8853
|
return output(wait ? await acknowledgedTaskResult(client2, completed, signal) : taskResult(completed));
|
|
@@ -8863,8 +8882,8 @@ var runMcp = async (configuration) => {
|
|
|
8863
8882
|
direction: z.enum(["input", "output"]).optional()
|
|
8864
8883
|
}
|
|
8865
8884
|
}, async ({ task_id, name, output_path, direction }, { signal }) => {
|
|
8866
|
-
const safeName =
|
|
8867
|
-
const safeDirection = direction === undefined ? undefined :
|
|
8885
|
+
const safeName = Schema15.decodeUnknownSync(AttachmentName)(name);
|
|
8886
|
+
const safeDirection = direction === undefined ? undefined : Schema15.decodeUnknownSync(AttachmentDirection)(direction);
|
|
8868
8887
|
const data = await Effect12.runPromise(client2.readAttachment(TaskId.make(task_id), safeName, safeDirection), { signal });
|
|
8869
8888
|
signal.throwIfAborted();
|
|
8870
8889
|
await writeFile9(output_path, data, { flag: "wx", mode: 384, signal });
|
|
@@ -8953,4 +8972,4 @@ await main().catch((cause) => {
|
|
|
8953
8972
|
process.exitCode = 1;
|
|
8954
8973
|
});
|
|
8955
8974
|
|
|
8956
|
-
//# debugId=
|
|
8975
|
+
//# debugId=83A2666BE91A2AA364756E2164756E21
|