@lensmcp/protocol-types 1.26.13 → 1.26.15
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/index.d.ts +2 -0
- package/index.js +1 -1
- package/lib/accounts.d.ts +35 -6
- package/lib/ai-cache-facts.js +1 -1
- package/lib/ai-cache-verdict.js +1 -1
- package/lib/ai-cache.js +3 -3
- package/lib/ai-call-groups.js +2 -2
- package/lib/ai-call-row.js +3 -3
- package/lib/ai-call.js +9 -9
- package/lib/ai-compare.js +3 -3
- package/lib/ai-context.js +6 -6
- package/lib/ai-origins.js +9 -9
- package/lib/ai-together.js +5 -5
- package/lib/bounded-clone.js +1 -1
- package/lib/bounded-map.js +1 -1
- package/lib/bounded-writer.js +1 -1
- package/lib/capture-demand.js +1 -1
- package/lib/cluster-hosts.d.ts +1 -1
- package/lib/conversations.d.ts +286 -0
- package/lib/conversations.js +1 -0
- package/lib/dashboard-lint.d.ts +31 -0
- package/lib/dashboard-path.js +1 -1
- package/lib/docker-errors.js +1 -1
- package/lib/docker-jobs.d.ts +1 -1
- package/lib/docker-jobs.js +1 -1
- package/lib/docker-report.js +2 -2
- package/lib/docker-runs.d.ts +1 -1
- package/lib/docker-runs.js +3 -3
- package/lib/error-cause.js +6 -6
- package/lib/error-dismissal.js +1 -1
- package/lib/error-verdict.js +3 -3
- package/lib/event-loop.js +1 -1
- package/lib/expected-failure.js +2 -2
- package/lib/finding-proof.js +1 -1
- package/lib/flood-guard.js +1 -1
- package/lib/goal-design.js +1 -1
- package/lib/host-agents.d.ts +1 -1
- package/lib/host-agents.js +1 -1
- package/lib/hosts.d.ts +1 -1
- package/lib/lint-coverage.js +1 -1
- package/lib/lint-ignores.d.ts +154 -0
- package/lib/lint-ignores.js +2 -0
- package/lib/log-query.js +1 -1
- package/lib/metrics-reset.js +1 -1
- package/lib/overseer-findings.js +1 -1
- package/lib/peers.d.ts +275 -23
- package/lib/peers.js +1 -1
- package/lib/perf-rules.js +1 -1
- package/lib/pod-memory.js +1 -1
- package/lib/producer-health.js +1 -1
- package/lib/remote-instances.d.ts +1 -1
- package/lib/remote-instances.js +1 -1
- package/lib/sources.js +1 -1
- package/lib/static-checks.d.ts +6 -0
- package/lib/static-checks.js +1 -1
- package/lib/system-report.js +1 -1
- package/lib/team.d.ts +21 -0
- package/lib/team.js +1 -1
- package/package.json +1 -1
package/lib/peers.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { type DockerRunState, type DockerVmRead, type LensJobLinkLoss } from './docker-jobs.js';
|
|
3
|
+
import { type ConversationGetPart, type ConversationHandoff, type ConversationListQuery, type ConversationTurnsPage, type DashConversationState, type DashConversationTurn, type DashConversationsAnswer } from './conversations.js';
|
|
3
4
|
import type { HostAgentsAdvert } from './host-agents.js';
|
|
5
|
+
import type { DashClientSessionClient, DashClientSessionKind } from './sessions.js';
|
|
4
6
|
import type { WorkspaceActionLane, WorkspaceActionState } from './workspace-actions.js';
|
|
5
7
|
/**
|
|
6
|
-
* WORKER MACS — the peer contract (planning/docker/00-plan.md §§ 7–10 and «The contract»; issues/
|
|
8
|
+
* WORKER MACS — the peer contract (planning/docker/00-plan.md §§ 7–10 and «The contract»; issues/closed/overseer-74).
|
|
7
9
|
* The organizer is this Mac's LensMCP; a worker is the same LensMCP on another Mac, that runs the organizer's work.
|
|
8
10
|
* What the slices of Phase 2 share is here: who a peer is, what each side pins, the pairing exchange, and the control
|
|
9
11
|
* messages of the channel — one discriminated union, each message an envelope with `v: 1`, an id and, for a reply,
|
|
@@ -771,6 +773,8 @@ export interface PeerBodies {
|
|
|
771
773
|
'goal.sent': GoalSent;
|
|
772
774
|
'goal.changes': GoalChanges;
|
|
773
775
|
'goal.update': GoalUpdate;
|
|
776
|
+
'conversation.sync': ConversationSync;
|
|
777
|
+
'conversation.read': ConversationRead;
|
|
774
778
|
}
|
|
775
779
|
export type PeerMessageType = keyof PeerBodies;
|
|
776
780
|
/** One control message: the discriminated union, by `type`. */
|
|
@@ -780,7 +784,7 @@ export type PeerMessage = {
|
|
|
780
784
|
/** What the organizer sends (§ 8, left column). */
|
|
781
785
|
export declare const TO_WORKER: readonly ["job.offer", "job.cancel", "bundle.ready", "tunnel.open", "tunnel.close", "launch.start", "launch.stop", "store.reply", "version.install", "main.moved", "instance.tunnel.open", "goal.place", "goal.changes", "goal.update"];
|
|
782
786
|
/** What the worker sends (§ 8, right column), and `forget`. */
|
|
783
|
-
export declare const TO_ORGANIZER: readonly ["hello", "capacity", "job.state", "job.stage", "job.done", "bundle.sent", "launch.state", "launch.tail", "store.call", "version.state", "forget", "main.state", "instance.state", "store.read", "goal.sent"];
|
|
787
|
+
export declare const TO_ORGANIZER: readonly ["hello", "capacity", "job.state", "job.stage", "job.done", "bundle.sent", "launch.state", "launch.tail", "store.call", "version.state", "forget", "main.state", "instance.state", "store.read", "goal.sent", "conversation.sync", "conversation.read"];
|
|
784
788
|
/** Either side sends a ping. */
|
|
785
789
|
export declare const EITHER_WAY: readonly ["ping"];
|
|
786
790
|
/** The replies: each names the message it answers, and is answered by nothing. */
|
|
@@ -861,7 +865,6 @@ export declare const PeerErrorBodySchema: z.ZodObject<{
|
|
|
861
865
|
code: z.ZodEnum<{
|
|
862
866
|
timeout: "timeout";
|
|
863
867
|
lost: "lost";
|
|
864
|
-
refused: "refused";
|
|
865
868
|
"unknown-type": "unknown-type";
|
|
866
869
|
"wrong-direction": "wrong-direction";
|
|
867
870
|
"bad-message": "bad-message";
|
|
@@ -869,6 +872,7 @@ export declare const PeerErrorBodySchema: z.ZodObject<{
|
|
|
869
872
|
"not-handled": "not-handled";
|
|
870
873
|
"too-large": "too-large";
|
|
871
874
|
busy: "busy";
|
|
875
|
+
refused: "refused";
|
|
872
876
|
internal: "internal";
|
|
873
877
|
"no-window": "no-window";
|
|
874
878
|
"window-used": "window-used";
|
|
@@ -910,7 +914,6 @@ export declare const PEER_BODY_SCHEMAS: {
|
|
|
910
914
|
code: z.ZodEnum<{
|
|
911
915
|
timeout: "timeout";
|
|
912
916
|
lost: "lost";
|
|
913
|
-
refused: "refused";
|
|
914
917
|
"unknown-type": "unknown-type";
|
|
915
918
|
"wrong-direction": "wrong-direction";
|
|
916
919
|
"bad-message": "bad-message";
|
|
@@ -918,6 +921,7 @@ export declare const PEER_BODY_SCHEMAS: {
|
|
|
918
921
|
"not-handled": "not-handled";
|
|
919
922
|
"too-large": "too-large";
|
|
920
923
|
busy: "busy";
|
|
924
|
+
refused: "refused";
|
|
921
925
|
internal: "internal";
|
|
922
926
|
"no-window": "no-window";
|
|
923
927
|
"window-used": "window-used";
|
|
@@ -976,7 +980,6 @@ export declare const PAIR_BODY_SCHEMAS: {
|
|
|
976
980
|
code: z.ZodEnum<{
|
|
977
981
|
timeout: "timeout";
|
|
978
982
|
lost: "lost";
|
|
979
|
-
refused: "refused";
|
|
980
983
|
"unknown-type": "unknown-type";
|
|
981
984
|
"wrong-direction": "wrong-direction";
|
|
982
985
|
"bad-message": "bad-message";
|
|
@@ -984,6 +987,7 @@ export declare const PAIR_BODY_SCHEMAS: {
|
|
|
984
987
|
"not-handled": "not-handled";
|
|
985
988
|
"too-large": "too-large";
|
|
986
989
|
busy: "busy";
|
|
990
|
+
refused: "refused";
|
|
987
991
|
internal: "internal";
|
|
988
992
|
"no-window": "no-window";
|
|
989
993
|
"window-used": "window-used";
|
|
@@ -1167,10 +1171,10 @@ export declare const MAIN_MIRROR_SCHEMAS: {
|
|
|
1167
1171
|
}, z.core.$strict>;
|
|
1168
1172
|
verdict: z.ZodOptional<z.ZodObject<{
|
|
1169
1173
|
state: z.ZodEnum<{
|
|
1170
|
-
waiting: "waiting";
|
|
1171
1174
|
refused: "refused";
|
|
1172
1175
|
"in-main": "in-main";
|
|
1173
1176
|
"brought-in": "brought-in";
|
|
1177
|
+
waiting: "waiting";
|
|
1174
1178
|
"not-ff": "not-ff";
|
|
1175
1179
|
}>;
|
|
1176
1180
|
count: z.ZodNumber;
|
|
@@ -1210,11 +1214,11 @@ export declare const MAIN_MIRROR_SCHEMAS: {
|
|
|
1210
1214
|
}>;
|
|
1211
1215
|
update: z.ZodOptional<z.ZodObject<{
|
|
1212
1216
|
outcome: z.ZodEnum<{
|
|
1213
|
-
waiting: "waiting";
|
|
1214
1217
|
refused: "refused";
|
|
1215
|
-
|
|
1218
|
+
waiting: "waiting";
|
|
1216
1219
|
"fast-forward": "fast-forward";
|
|
1217
1220
|
merged: "merged";
|
|
1221
|
+
current: "current";
|
|
1218
1222
|
conflicts: "conflicts";
|
|
1219
1223
|
}>;
|
|
1220
1224
|
at: z.ZodNumber;
|
|
@@ -1243,10 +1247,10 @@ export declare const MAIN_MIRROR_ANSWER_SCHEMAS: {
|
|
|
1243
1247
|
why: z.ZodOptional<z.ZodString>;
|
|
1244
1248
|
verdict: z.ZodOptional<z.ZodObject<{
|
|
1245
1249
|
state: z.ZodEnum<{
|
|
1246
|
-
waiting: "waiting";
|
|
1247
1250
|
refused: "refused";
|
|
1248
1251
|
"in-main": "in-main";
|
|
1249
1252
|
"brought-in": "brought-in";
|
|
1253
|
+
waiting: "waiting";
|
|
1250
1254
|
"not-ff": "not-ff";
|
|
1251
1255
|
}>;
|
|
1252
1256
|
count: z.ZodNumber;
|
|
@@ -1312,8 +1316,8 @@ export declare const PEER_WORK_SCHEMAS: {
|
|
|
1312
1316
|
at: z.ZodNumber;
|
|
1313
1317
|
started: z.ZodOptional<z.ZodLiteral<true>>;
|
|
1314
1318
|
state: z.ZodOptional<z.ZodEnum<{
|
|
1315
|
-
running: "running";
|
|
1316
1319
|
queued: "queued";
|
|
1320
|
+
running: "running";
|
|
1317
1321
|
}>>;
|
|
1318
1322
|
note: z.ZodOptional<z.ZodString>;
|
|
1319
1323
|
queue: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
@@ -1329,9 +1333,9 @@ export declare const PEER_WORK_SCHEMAS: {
|
|
|
1329
1333
|
runId: z.ZodString;
|
|
1330
1334
|
at: z.ZodNumber;
|
|
1331
1335
|
state: z.ZodEnum<{
|
|
1332
|
-
errored: "errored";
|
|
1333
1336
|
passed: "passed";
|
|
1334
1337
|
failed: "failed";
|
|
1338
|
+
errored: "errored";
|
|
1335
1339
|
cancelled: "cancelled";
|
|
1336
1340
|
timeout: "timeout";
|
|
1337
1341
|
}>;
|
|
@@ -1426,10 +1430,10 @@ export declare const PEER_WORK_SCHEMAS: {
|
|
|
1426
1430
|
}, z.core.$strict>;
|
|
1427
1431
|
why: z.ZodObject<{
|
|
1428
1432
|
kind: z.ZodEnum<{
|
|
1429
|
-
restarting: "restarting";
|
|
1430
1433
|
protocol: "protocol";
|
|
1431
1434
|
version: "version";
|
|
1432
1435
|
installed: "installed";
|
|
1436
|
+
restarting: "restarting";
|
|
1433
1437
|
"install-failed": "install-failed";
|
|
1434
1438
|
"restart-failed": "restart-failed";
|
|
1435
1439
|
"no-store": "no-store";
|
|
@@ -1491,18 +1495,18 @@ export declare const StoreReplySchema: z.ZodObject<{
|
|
|
1491
1495
|
result: z.ZodOptional<z.ZodUnknown>;
|
|
1492
1496
|
error: z.ZodOptional<z.ZodObject<{
|
|
1493
1497
|
name: z.ZodEnum<{
|
|
1494
|
-
Error: "Error";
|
|
1495
1498
|
CoordinationError: "CoordinationError";
|
|
1496
1499
|
CapacityRefusal: "CapacityRefusal";
|
|
1497
1500
|
CoordinationBusyError: "CoordinationBusyError";
|
|
1498
1501
|
StoreCallRefused: "StoreCallRefused";
|
|
1502
|
+
Error: "Error";
|
|
1499
1503
|
}>;
|
|
1500
1504
|
message: z.ZodString;
|
|
1501
1505
|
room: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
1502
1506
|
step: z.ZodOptional<z.ZodEnum<{
|
|
1503
1507
|
open: "open";
|
|
1504
|
-
commit: "commit";
|
|
1505
1508
|
write: "write";
|
|
1509
|
+
commit: "commit";
|
|
1506
1510
|
read: "read";
|
|
1507
1511
|
}>>;
|
|
1508
1512
|
waitedMs: z.ZodOptional<z.ZodNumber>;
|
|
@@ -1592,8 +1596,8 @@ export declare const PEER_LAUNCH_SCHEMAS: {
|
|
|
1592
1596
|
state: z.ZodEnum<{
|
|
1593
1597
|
running: "running";
|
|
1594
1598
|
failed: "failed";
|
|
1595
|
-
stopped: "stopped";
|
|
1596
1599
|
exited: "exited";
|
|
1600
|
+
stopped: "stopped";
|
|
1597
1601
|
}>;
|
|
1598
1602
|
at: z.ZodNumber;
|
|
1599
1603
|
pid: z.ZodOptional<z.ZodNumber>;
|
|
@@ -1798,9 +1802,9 @@ export declare const GOAL_PEER_SCHEMAS: {
|
|
|
1798
1802
|
sha256: z.ZodString;
|
|
1799
1803
|
}, z.core.$strict>;
|
|
1800
1804
|
services: z.ZodOptional<z.ZodEnum<{
|
|
1801
|
-
always: "always";
|
|
1802
|
-
none: "none";
|
|
1803
1805
|
"on-demand": "on-demand";
|
|
1806
|
+
none: "none";
|
|
1807
|
+
always: "always";
|
|
1804
1808
|
}>>;
|
|
1805
1809
|
at: z.ZodNumber;
|
|
1806
1810
|
}, z.core.$strict>;
|
|
@@ -1817,10 +1821,10 @@ export declare const GOAL_PEER_SCHEMAS: {
|
|
|
1817
1821
|
what: z.ZodEnum<{
|
|
1818
1822
|
files: "files";
|
|
1819
1823
|
commit: "commit";
|
|
1820
|
-
diff: "diff";
|
|
1821
|
-
against: "against";
|
|
1822
1824
|
row: "row";
|
|
1825
|
+
diff: "diff";
|
|
1823
1826
|
commits: "commits";
|
|
1827
|
+
against: "against";
|
|
1824
1828
|
}>;
|
|
1825
1829
|
path: z.ZodOptional<z.ZodString>;
|
|
1826
1830
|
sha: z.ZodOptional<z.ZodString>;
|
|
@@ -1859,10 +1863,10 @@ export declare const GOAL_PEER_ANSWER_SCHEMAS: {
|
|
|
1859
1863
|
ref: z.ZodString;
|
|
1860
1864
|
sha: z.ZodOptional<z.ZodString>;
|
|
1861
1865
|
mirror: z.ZodOptional<z.ZodEnum<{
|
|
1862
|
-
created: "created";
|
|
1863
|
-
current: "current";
|
|
1864
1866
|
"not-ff": "not-ff";
|
|
1865
1867
|
"fast-forward": "fast-forward";
|
|
1868
|
+
current: "current";
|
|
1869
|
+
created: "created";
|
|
1866
1870
|
"checked-out": "checked-out";
|
|
1867
1871
|
}>>;
|
|
1868
1872
|
told: z.ZodOptional<z.ZodString>;
|
|
@@ -1879,10 +1883,10 @@ export declare const GOAL_PEER_ANSWER_SCHEMAS: {
|
|
|
1879
1883
|
readonly 'goal.update': z.ZodObject<{
|
|
1880
1884
|
outcome: z.ZodEnum<{
|
|
1881
1885
|
refused: "refused";
|
|
1882
|
-
current: "current";
|
|
1883
|
-
asked: "asked";
|
|
1884
1886
|
merged: "merged";
|
|
1887
|
+
current: "current";
|
|
1885
1888
|
conflicts: "conflicts";
|
|
1889
|
+
asked: "asked";
|
|
1886
1890
|
}>;
|
|
1887
1891
|
why: z.ZodString;
|
|
1888
1892
|
sha: z.ZodOptional<z.ZodString>;
|
|
@@ -1892,3 +1896,251 @@ export declare const GOAL_PEER_ANSWER_SCHEMAS: {
|
|
|
1892
1896
|
needWhole: z.ZodOptional<z.ZodBoolean>;
|
|
1893
1897
|
}, z.core.$strict>;
|
|
1894
1898
|
};
|
|
1899
|
+
/**
|
|
1900
|
+
* CONVERSATIONS ON TWO MACS (planning/sessions/01-conversations.md § 6, CV-D2; slice CV5). Each Mac's lens keeps its own
|
|
1901
|
+
* conversations (libs/storage conversations/store.ts). A worker sends the organizer the conversations of the
|
|
1902
|
+
* organizer's repositories it holds — the checkouts of the goals placed on it and of the main it follows — on a beat of
|
|
1903
|
+
* their own (`conversation.sync`): per conversation, its row and the turns after the seq the organizer last said it
|
|
1904
|
+
* holds, and the tool calls it sent open that settled since — bounded per message and per beat. The organizer keeps them
|
|
1905
|
+
* with the worker's Mac in the row, under the WORKER's ids (a hash of the worker's Mac basis: checked, never recomputed),
|
|
1906
|
+
* and answers the seq it holds of each: the worker's cursor. A worker asks the organizer for a conversation it does not
|
|
1907
|
+
* hold (`conversation.read`): a list, a handoff or a page of turns, bounded to one line of the stream.
|
|
1908
|
+
*
|
|
1909
|
+
* Both bodies carry their own `v: 1` and `kind`, as `store.call` does. An organizer of an older LensMCP refuses them —
|
|
1910
|
+
* `unknown-type` (it knows no such message), `not-handled` (it knows the type, its slice is not built) — and the worker
|
|
1911
|
+
* stops sending them until its next connection: never more than once a connection, so the channel's strikes (twenty
|
|
1912
|
+
* refusals in a minute close it) are never reached. Nothing here names a folder the other side acts on: a row's checkout
|
|
1913
|
+
* and cwd are the words the worker's store holds, shown, never opened.
|
|
1914
|
+
*/
|
|
1915
|
+
export declare const CONVERSATION_PEER_LIMITS: {
|
|
1916
|
+
/** One `conversation.sync`, or one `conversation.read`'s answer, encoded: a line of the control stream with room for its envelope. */
|
|
1917
|
+
readonly messageBytes: number;
|
|
1918
|
+
/** Conversations one sync carries, and turns of one conversation in it. */
|
|
1919
|
+
readonly conversations: 32;
|
|
1920
|
+
readonly turns: 500;
|
|
1921
|
+
/** Tool calls sent with no outcome yet, settled by a later sync: per conversation. */
|
|
1922
|
+
readonly settles: 64;
|
|
1923
|
+
/** One turn, encoded, at most: a longer one is cut to it (`cut`). */
|
|
1924
|
+
readonly turnBytes: number;
|
|
1925
|
+
/** A tool call's target as it is sent (a store keeps whole commands). */
|
|
1926
|
+
readonly targetChars: 4096;
|
|
1927
|
+
/** What one beat sends at most: bytes over its syncs, and conversations. */
|
|
1928
|
+
readonly beatBytes: number;
|
|
1929
|
+
readonly beatConversations: 64;
|
|
1930
|
+
/** A forwarded read's budget at most, in tokens: a 100,000-token handoff is no line of the stream. */
|
|
1931
|
+
readonly readTokens: 60000;
|
|
1932
|
+
};
|
|
1933
|
+
/** A conversation as the worker's store holds it: everything but its turns — no transcript path, no Mac (the organizer writes its own word for the Mac). */
|
|
1934
|
+
export interface ConversationSyncRow {
|
|
1935
|
+
id: string;
|
|
1936
|
+
client: DashClientSessionClient;
|
|
1937
|
+
nativeId: string;
|
|
1938
|
+
account: string;
|
|
1939
|
+
accountNick?: string;
|
|
1940
|
+
checkout: {
|
|
1941
|
+
root: string;
|
|
1942
|
+
branch?: string;
|
|
1943
|
+
key?: string;
|
|
1944
|
+
};
|
|
1945
|
+
cwd?: string;
|
|
1946
|
+
model?: string;
|
|
1947
|
+
startedAt: number;
|
|
1948
|
+
lastAt: number;
|
|
1949
|
+
state: DashConversationState;
|
|
1950
|
+
kind?: DashClientSessionKind;
|
|
1951
|
+
sessionId?: string;
|
|
1952
|
+
launchId?: string;
|
|
1953
|
+
role?: string;
|
|
1954
|
+
goalId?: string;
|
|
1955
|
+
goalTitle?: string;
|
|
1956
|
+
taskId?: string;
|
|
1957
|
+
/** The conversation it continues (it started from that one's handoff) — an organizer's conversation, often. */
|
|
1958
|
+
continues?: string;
|
|
1959
|
+
}
|
|
1960
|
+
/** A tool call sent with no outcome, as it ended: settled by its seq. */
|
|
1961
|
+
export interface ConversationSyncSettle {
|
|
1962
|
+
seq: number;
|
|
1963
|
+
outcome: 'ok' | 'error';
|
|
1964
|
+
output?: string;
|
|
1965
|
+
}
|
|
1966
|
+
/** One conversation of a sync: its row, its turns from `turns[0].seq` (consecutive), the calls it settled. */
|
|
1967
|
+
export interface ConversationSyncEntry {
|
|
1968
|
+
row: ConversationSyncRow;
|
|
1969
|
+
turns: DashConversationTurn[];
|
|
1970
|
+
settles?: ConversationSyncSettle[];
|
|
1971
|
+
/** The worker read it again from its first turn (its transcript was rewritten shorter): the organizer drops what it held first. */
|
|
1972
|
+
rewound?: true;
|
|
1973
|
+
}
|
|
1974
|
+
/** `conversation.sync` (worker → organizer) — slice CV5. Answered by a {@link ConversationSyncAnswer}. */
|
|
1975
|
+
export interface ConversationSync {
|
|
1976
|
+
v: 1;
|
|
1977
|
+
kind: 'conversation.sync';
|
|
1978
|
+
/** The organizer's repository, as its stores name it (`repoId`): one the organizer placed a goal of, or sends main of, on this worker. */
|
|
1979
|
+
repository: string;
|
|
1980
|
+
/** The basis the worker's store names its conversation ids by (`conversationIdOf`): kept in each row's Mac, never recomputed. */
|
|
1981
|
+
macBasis: string;
|
|
1982
|
+
conversations: ConversationSyncEntry[];
|
|
1983
|
+
}
|
|
1984
|
+
/** What the organizer holds of each conversation now — the newest seq, the worker's cursor — or why it took none of it. */
|
|
1985
|
+
export interface ConversationSyncAnswer {
|
|
1986
|
+
v: 1;
|
|
1987
|
+
held: Array<{
|
|
1988
|
+
id: string;
|
|
1989
|
+
seq: number;
|
|
1990
|
+
refused?: string;
|
|
1991
|
+
}>;
|
|
1992
|
+
}
|
|
1993
|
+
/** What a worker asks of the organizer's conversations: a list (`conversation_list`), or one (`conversation_get`). */
|
|
1994
|
+
export type ConversationReadAsk = {
|
|
1995
|
+
what: 'list';
|
|
1996
|
+
query: ConversationListQuery;
|
|
1997
|
+
} | {
|
|
1998
|
+
what: 'get';
|
|
1999
|
+
id: string;
|
|
2000
|
+
part: ConversationGetPart;
|
|
2001
|
+
maxTokens?: number;
|
|
2002
|
+
before?: number;
|
|
2003
|
+
};
|
|
2004
|
+
/** `conversation.read` (worker → organizer) — slice CV5: a read of the organizer's store for the repository. */
|
|
2005
|
+
export interface ConversationRead {
|
|
2006
|
+
v: 1;
|
|
2007
|
+
kind: 'conversation.read';
|
|
2008
|
+
repository: string;
|
|
2009
|
+
ask: ConversationReadAsk;
|
|
2010
|
+
}
|
|
2011
|
+
/**
|
|
2012
|
+
* The organizer's answer: who answered, whether it holds what was asked, and the answer — `list`, `handoff` or `page`,
|
|
2013
|
+
* each as the store answers it, a conversation's `mac.here` said for the WORKER (true: one of the worker's own).
|
|
2014
|
+
*/
|
|
2015
|
+
export interface ConversationReadAnswer {
|
|
2016
|
+
v: 1;
|
|
2017
|
+
from: {
|
|
2018
|
+
name: string;
|
|
2019
|
+
fingerprint?: string;
|
|
2020
|
+
};
|
|
2021
|
+
found: boolean;
|
|
2022
|
+
why?: string;
|
|
2023
|
+
list?: DashConversationsAnswer;
|
|
2024
|
+
handoff?: ConversationHandoff;
|
|
2025
|
+
page?: ConversationTurnsPage;
|
|
2026
|
+
}
|
|
2027
|
+
/** The schemas of slice CV5's messages, strict: what the hub's handlers are registered with, and what the worker checks before it sends. */
|
|
2028
|
+
export declare const CONVERSATION_PEER_SCHEMAS: {
|
|
2029
|
+
readonly 'conversation.sync': z.ZodObject<{
|
|
2030
|
+
v: z.ZodLiteral<1>;
|
|
2031
|
+
kind: z.ZodLiteral<"conversation.sync">;
|
|
2032
|
+
repository: z.ZodString;
|
|
2033
|
+
macBasis: z.ZodString;
|
|
2034
|
+
conversations: z.ZodArray<z.ZodObject<{
|
|
2035
|
+
row: z.ZodObject<{
|
|
2036
|
+
id: z.ZodString;
|
|
2037
|
+
client: z.ZodEnum<{
|
|
2038
|
+
claude: "claude";
|
|
2039
|
+
codex: "codex";
|
|
2040
|
+
}>;
|
|
2041
|
+
nativeId: z.ZodString;
|
|
2042
|
+
account: z.ZodString;
|
|
2043
|
+
accountNick: z.ZodOptional<z.ZodString>;
|
|
2044
|
+
checkout: z.ZodObject<{
|
|
2045
|
+
root: z.ZodString;
|
|
2046
|
+
branch: z.ZodOptional<z.ZodString>;
|
|
2047
|
+
key: z.ZodOptional<z.ZodString>;
|
|
2048
|
+
}, z.core.$strict>;
|
|
2049
|
+
cwd: z.ZodOptional<z.ZodString>;
|
|
2050
|
+
model: z.ZodOptional<z.ZodString>;
|
|
2051
|
+
startedAt: z.ZodNumber;
|
|
2052
|
+
lastAt: z.ZodNumber;
|
|
2053
|
+
state: z.ZodEnum<{
|
|
2054
|
+
running: "running";
|
|
2055
|
+
ended: "ended";
|
|
2056
|
+
kept: "kept";
|
|
2057
|
+
}>;
|
|
2058
|
+
kind: z.ZodOptional<z.ZodEnum<{
|
|
2059
|
+
person: "person";
|
|
2060
|
+
team: "team";
|
|
2061
|
+
outside: "outside";
|
|
2062
|
+
}>>;
|
|
2063
|
+
sessionId: z.ZodOptional<z.ZodString>;
|
|
2064
|
+
launchId: z.ZodOptional<z.ZodString>;
|
|
2065
|
+
role: z.ZodOptional<z.ZodString>;
|
|
2066
|
+
goalId: z.ZodOptional<z.ZodString>;
|
|
2067
|
+
goalTitle: z.ZodOptional<z.ZodString>;
|
|
2068
|
+
taskId: z.ZodOptional<z.ZodString>;
|
|
2069
|
+
continues: z.ZodOptional<z.ZodString>;
|
|
2070
|
+
}, z.core.$strict>;
|
|
2071
|
+
turns: z.ZodArray<z.ZodObject<{
|
|
2072
|
+
seq: z.ZodNumber;
|
|
2073
|
+
at: z.ZodOptional<z.ZodNumber>;
|
|
2074
|
+
kind: z.ZodEnum<{
|
|
2075
|
+
prompt: "prompt";
|
|
2076
|
+
reply: "reply";
|
|
2077
|
+
tool: "tool";
|
|
2078
|
+
compaction: "compaction";
|
|
2079
|
+
subagent: "subagent";
|
|
2080
|
+
}>;
|
|
2081
|
+
text: z.ZodString;
|
|
2082
|
+
cut: z.ZodOptional<z.ZodLiteral<true>>;
|
|
2083
|
+
tool: z.ZodOptional<z.ZodObject<{
|
|
2084
|
+
name: z.ZodString;
|
|
2085
|
+
target: z.ZodOptional<z.ZodString>;
|
|
2086
|
+
outcome: z.ZodOptional<z.ZodEnum<{
|
|
2087
|
+
error: "error";
|
|
2088
|
+
ok: "ok";
|
|
2089
|
+
}>>;
|
|
2090
|
+
output: z.ZodOptional<z.ZodString>;
|
|
2091
|
+
}, z.core.$strict>>;
|
|
2092
|
+
files: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
2093
|
+
}, z.core.$strict>>;
|
|
2094
|
+
settles: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
2095
|
+
seq: z.ZodNumber;
|
|
2096
|
+
outcome: z.ZodEnum<{
|
|
2097
|
+
error: "error";
|
|
2098
|
+
ok: "ok";
|
|
2099
|
+
}>;
|
|
2100
|
+
output: z.ZodOptional<z.ZodString>;
|
|
2101
|
+
}, z.core.$strict>>>;
|
|
2102
|
+
rewound: z.ZodOptional<z.ZodLiteral<true>>;
|
|
2103
|
+
}, z.core.$strict>>;
|
|
2104
|
+
}, z.core.$strict>;
|
|
2105
|
+
readonly 'conversation.read': z.ZodObject<{
|
|
2106
|
+
v: z.ZodLiteral<1>;
|
|
2107
|
+
kind: z.ZodLiteral<"conversation.read">;
|
|
2108
|
+
repository: z.ZodString;
|
|
2109
|
+
ask: z.ZodType<ConversationReadAsk, unknown, z.core.$ZodTypeInternals<ConversationReadAsk, unknown>>;
|
|
2110
|
+
}, z.core.$strict>;
|
|
2111
|
+
};
|
|
2112
|
+
/** The answers, as the worker reads its `ack`'s result. A read's answer is checked here for its frame; the tool's own output schema reads the rest. */
|
|
2113
|
+
export declare const CONVERSATION_PEER_ANSWER_SCHEMAS: {
|
|
2114
|
+
readonly 'conversation.sync': z.ZodObject<{
|
|
2115
|
+
v: z.ZodLiteral<1>;
|
|
2116
|
+
held: z.ZodArray<z.ZodObject<{
|
|
2117
|
+
id: z.ZodString;
|
|
2118
|
+
seq: z.ZodNumber;
|
|
2119
|
+
refused: z.ZodOptional<z.ZodString>;
|
|
2120
|
+
}, z.core.$strict>>;
|
|
2121
|
+
}, z.core.$strict>;
|
|
2122
|
+
readonly 'conversation.read': z.ZodObject<{
|
|
2123
|
+
v: z.ZodLiteral<1>;
|
|
2124
|
+
from: z.ZodObject<{
|
|
2125
|
+
name: z.ZodString;
|
|
2126
|
+
fingerprint: z.ZodOptional<z.ZodString>;
|
|
2127
|
+
}, z.core.$strict>;
|
|
2128
|
+
found: z.ZodBoolean;
|
|
2129
|
+
why: z.ZodOptional<z.ZodString>;
|
|
2130
|
+
list: z.ZodOptional<z.ZodObject<{
|
|
2131
|
+
conversations: z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
2132
|
+
more: z.ZodBoolean;
|
|
2133
|
+
}, z.core.$loose>>;
|
|
2134
|
+
handoff: z.ZodOptional<z.ZodObject<{
|
|
2135
|
+
conversation: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
2136
|
+
turns: z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
2137
|
+
more: z.ZodBoolean;
|
|
2138
|
+
next: z.ZodString;
|
|
2139
|
+
}, z.core.$loose>>;
|
|
2140
|
+
page: z.ZodOptional<z.ZodObject<{
|
|
2141
|
+
conversation: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
2142
|
+
turns: z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
2143
|
+
more: z.ZodBoolean;
|
|
2144
|
+
}, z.core.$loose>>;
|
|
2145
|
+
}, z.core.$strict>;
|
|
2146
|
+
};
|
package/lib/peers.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var G=Object.defineProperty;var _=(t,a)=>G(t,"name",{value:a,configurable:!0});var U=Object.defineProperty,v=_((t,a)=>U(t,"name",{value:a,configurable:!0}),"_"),K=Object.defineProperty,s=v((t,a)=>K(t,"name",{value:a,configurable:!0}),"r");import{z as e}from"zod";import{RUN_ID_PATTERN as I}from"./docker-jobs.js";import{REMOTE_DASHBOARD_BASE_PATTERN as F,REMOTE_INSTANCE_ID_PATTERN as z,REMOTE_INSTANCE_NAME_PREFIX as Y}from"./remote-instances.js";export const PEER_PROTOCOL="peer/v1",PEER_PORT=7466,PEER_TIMING={pingMs:5e3,lostMs:45e3,windowMs:10*6e4,approveMs:10*6e4,capacityMs:3e4},PAIRING_CODE={length:10,tries:5},CROCKFORD_ALPHABET="0123456789ABCDEFGHJKMNPQRSTVWXYZ",PEER_PATHS={pair:"/peer/v1/pair",control:"/peer/v1/control",runs:"/peer/v1/runs/",bundles:"/peer/v1/bundles/",sent:"/peer/v1/sent/",tunnel:"/peer/v1/tunnel/"},RUN_UPLOAD_KINDS=["log","samples","events","artifacts"],RUN_UPLOAD_RANGE={from:"x-lensmcp-from",to:"x-lensmcp-to"},PEER_FILES={dir:"peers",key:"identity.key",cert:"identity.crt",window:"window.json",workers:"workers.json",organizer:"organizer.json",hub:"hub.json",hubLock:"hub.lock",hubLog:"hub.log",runs:"runs",instances:"instances"},FINGERPRINT_PATTERN=/^[0-9a-f]{64}$/,REMOTE_RUN_LOST="lost",PEER_MESSAGE_ID=/^[A-Za-z0-9_-]{1,64}$/,TO_WORKER=["job.offer","job.cancel","bundle.ready","tunnel.open","tunnel.close","launch.start","launch.stop","store.reply","version.install","main.moved","instance.tunnel.open","goal.place","goal.changes","goal.update"],TO_ORGANIZER=["hello","capacity","job.state","job.stage","job.done","bundle.sent","launch.state","launch.tail","store.call","version.state","forget","main.state","instance.state","store.read","goal.sent"],EITHER_WAY=["ping"],PEER_REPLIES=["ack","error","pong"],PEER_MESSAGE_SLICE={hello:"D12 (versions: D13, capacity: D14)",ping:"D12",pong:"D12",ack:"D12",error:"D12",forget:"D11",capacity:"D14","job.offer":"D14","job.cancel":"D14/D18","job.state":"D14/D16","job.stage":"D16","job.done":"D16","bundle.ready":"D15","bundle.sent":"D34 (goal branches: D30)","tunnel.open":"D17","tunnel.close":"D17","launch.start":"D29","launch.stop":"D29","launch.state":"D29","launch.tail":"D29","store.call":"D27/D28","store.reply":"D27/D28","version.install":"D13","version.state":"D13","main.moved":"D34","main.state":"D34","instance.tunnel.open":"D35","instance.state":"D35 (sent by D30)","store.read":"D32","goal.place":"D30","goal.sent":"D30","goal.changes":"D30","goal.update":"D30"};const h=s((t,a)=>t.includes(a),"has");export const isPeerMessageType=s(t=>Object.prototype.hasOwnProperty.call(PEER_MESSAGE_SLICE,t),"isPeerMessageType");export function peerMaySend(t,a){return h(EITHER_WAY,a)||h(PEER_REPLIES,a)?!0:h(t==="organizer"?TO_WORKER:TO_ORGANIZER,a)}_(peerMaySend,"peerMaySend"),v(peerMaySend,"peerMaySend"),s(peerMaySend,"peerMaySend");export const isPeerReply=s(t=>h(PEER_REPLIES,t),"isPeerReply");const l=/^[^\p{Cc}\p{Cf}\p{Zl}\p{Zp}]*$/u,g=s(t=>e.string().min(1).max(t).regex(l),"shownText"),D=e.string().regex(/^[A-Za-z0-9_-]{43}$/),M=e.string().regex(/^[0-9a-f]{64}$/),r=e.string().min(1).max(64).regex(/^[0-9A-Za-z.+_-]+$/),q=e.tuple([e.string().regex(/^[a-z]{3,8}$/),e.string().regex(/^[a-z]{3,8}$/),e.string().regex(/^[a-z]{3,8}$/),e.string().regex(/^[a-z]{3,8}$/)]),n=e.number().int().nonnegative();export const PeerEnvelopeSchema=e.strictObject({v:e.literal(1),id:e.string().regex(PEER_MESSAGE_ID),replyTo:e.string().regex(PEER_MESSAGE_ID).optional(),type:e.string().min(1).max(40),body:e.record(e.string(),e.unknown())});const X=["unknown-type","wrong-direction","bad-message","hello-first","not-handled","too-large","busy","refused","timeout","lost","internal","no-window","window-used","window-closed","wrong-code","protocol"];export const PeerErrorBodySchema=e.strictObject({code:e.enum(X),message:e.string().max(500),triesLeft:e.number().int().min(0).max(PAIRING_CODE.tries).optional(),retryAfterMs:e.number().int().min(0).max(36e5).optional()});const c=e.string().regex(I);export const WorkerAdvertSchema=e.record(e.string(),e.unknown()).superRefine((t,a)=>{const x=t.runs;x!==void 0&&(!Array.isArray(x)||x.length>256||!x.every(S=>typeof S=="string"&&I.test(S)))&&a.addIssue({code:"custom",message:"runs: at most 256 run ids"})}),PEER_BODY_SCHEMAS={hello:e.strictObject({protocol:e.literal(PEER_PROTOCOL),lensmcp:r,follow:e.boolean().optional(),store:e.array(r).max(64).optional(),capacity:WorkerAdvertSchema.optional()}),ping:e.strictObject({at:n}),pong:e.strictObject({at:n}),ack:e.strictObject({result:e.unknown().optional()}),error:PeerErrorBodySchema,forget:e.strictObject({why:e.string().max(200).regex(l).optional()})},PeerWelcomeSchema=e.strictObject({protocol:e.literal(PEER_PROTOCOL),lensmcp:r,name:g(64),inStep:e.boolean().optional(),why:e.string().max(500).optional()}),PAIR_BODY_SCHEMAS={"pair.hello":e.strictObject({protocol:e.literal(PEER_PROTOCOL),nonce:D,name:g(64),model:g(40),lensmcp:r}),"pair.resume":e.strictObject({protocol:e.literal(PEER_PROTOCOL)}),"pair.challenge":e.strictObject({nonce:D}),"pair.proof":e.strictObject({proof:M}),"pair.accepted":e.strictObject({proof:M,name:g(64),model:g(40),words:q,approveBy:n}),"pair.approved":e.strictObject({at:n}),"pair.declined":e.strictObject({why:e.string().max(500)}),error:PeerErrorBodySchema},MAIN_MIRROR={branch:"main",quietMs:10*6e4,snapshotEveryMs:60*6e4,maxSendBytes:512*1024*1024,maxWipBytes:256*1024*1024,maxHaves:16},MAIN_BRING_IN=["in-main","brought-in","waiting","not-ff","refused"],MAIN_FOLLOW_STATES=["in-step","fast-forward","ahead","waiting","to-update","not-following","off-branch"];const o=e.string().regex(/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/),f=e.string().regex(/^[0-9a-f]{16,64}$/),$=e.string().regex(/^[0-9a-f]{64}$/),k=e.string().regex(/^[0-9a-f]{16}$/),d=e.number().int().min(0).max(1e7),O=e.string().min(1).max(250).regex(/^[A-Za-z0-9._/-]+$/),y=e.string().max(1e3),P=e.strictObject({state:e.enum(["in-main","brought-in","waiting","not-ff","refused"]),count:d,sha:o.optional(),main:o.optional(),why:y,at:n}),J=e.strictObject({outcome:e.enum(["merged","fast-forward","current","conflicts","waiting","refused"]),at:n,why:y,sha:o.optional(),conflicts:e.array(e.string().min(1).max(4096)).max(200).optional(),asked:e.array(e.strictObject({who:e.enum(["person","manager"]),goal:e.string().max(64).optional(),to:e.string().max(200).optional()})).max(20).optional()}),T=e.enum(["in-step","fast-forward","ahead","waiting","to-update","not-following","off-branch"]);export const MAIN_MIRROR_SCHEMAS={"bundle.sent":e.strictObject({bundleId:k,repository:f,refs:e.array(O).length(1),size:e.number().int().positive().max(MAIN_MIRROR.maxSendBytes),sha256:$}),"main.moved":e.strictObject({repository:f,branch:O,sha:o,bundle:e.strictObject({id:k,size:e.number().int().positive(),sha256:$}),verdict:P.optional(),at:n}),"main.state":e.strictObject({repository:f,branch:O,head:o.optional(),organizerHead:o.optional(),haves:e.array(o).max(MAIN_MIRROR.maxHaves),notSent:d,toPull:d,uncommitted:e.strictObject({files:d,changedAt:n.optional()}),snapshot:e.strictObject({sha:o,at:n,files:d,sent:e.boolean()}).optional(),follow:T,update:J.optional(),at:n})},MAIN_MIRROR_ANSWER_SCHEMAS={"bundle.sent":e.strictObject({took:e.boolean(),ref:O,sha:o.optional(),code:e.string().max(40).optional(),why:y.optional(),verdict:P.optional()}),"main.moved":e.strictObject({took:e.boolean(),needWhole:e.boolean().optional(),why:y.optional(),follow:T.optional(),head:o.optional()})};const Q=e.string().regex(/^[A-Za-z0-9][A-Za-z0-9._-]{0,62}$/),w=e.string().regex(/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/),C=e.string().regex(/^[0-9a-f]{16,64}$/),u=e.string().regex(/^[A-Za-z0-9][A-Za-z0-9_-]{7,79}$/),N=s(t=>e.string().min(1).max(t).regex(l),"sentence"),p=e.record(e.string(),e.unknown()),V=e.string().regex(/^[A-Za-z_][A-Za-z0-9_]{0,99}$/),i=e.strictObject({lensmcp:r,protocol:e.string().regex(/^peer\/v[1-9]\d{0,3}$/)});export const PEER_WORK_SCHEMAS={capacity:WorkerAdvertSchema,"job.offer":e.strictObject({runId:c,job:Q,candidate:w,repository:C,lane:e.enum(["light","heavy"]).optional(),kind:e.enum(["compose","testcontainers","playwright"]).optional(),hostMb:e.number().int().min(0).max(1024*1024).optional(),vmMb:e.number().int().min(0).max(1024*1024).optional(),proof:e.boolean().optional(),timeoutMinutes:e.number().positive().max(360).optional(),onLinkLoss:e.union([e.literal("cancel"),e.strictObject({continueMinutes:e.number().int().min(1).max(360)})]).optional(),secrets:e.record(V,e.string().min(1).max(8192)).refine(t=>Object.keys(t).length<=16,"at most 16 secrets").optional(),origin:e.string().max(300).regex(/^https?:\/\/[A-Za-z0-9.-]+(?::\d{1,5})?$/).optional()}),"job.cancel":e.strictObject({runId:c,why:N(300)}),"job.state":e.strictObject({runId:c,at:n,started:e.literal(!0).optional(),state:e.enum(["queued","running"]).optional(),note:e.string().max(1e3).optional(),queue:p.optional(),docker:p.optional(),edgePort:e.number().int().min(1024).max(65535).optional()}),"job.stage":e.strictObject({runId:c,stage:N(120),at:n}),"job.done":e.strictObject({runId:c,at:n,state:e.enum(["passed","failed","errored","cancelled","timeout"]),note:e.string().max(1e3).optional(),step:p.optional(),docker:p.optional(),givenBack:e.strictObject({why:e.string().min(1).max(1e3)}).optional(),refused:e.strictObject({why:e.string().min(1).max(1e3)}).optional(),proof:p.optional()}),"bundle.ready":e.strictObject({runId:c.optional(),bundleId:u,repository:C,heads:e.array(w).min(1).max(16),basis:e.array(w).max(256).optional(),size:e.number().int().positive().max(64*1024*1024*1024),sha256:e.string().regex(/^[0-9a-f]{64}$/),shipment:p.optional(),blobs:e.record(e.string().regex(/^[0-9a-f]{64}$/),u).refine(t=>Object.keys(t).length<=101,"at most 101 blobs").optional()}),"tunnel.open":e.strictObject({tunnelId:u,runId:c,port:e.number().int().min(1).max(65535).optional()}),"tunnel.close":e.strictObject({tunnelId:u,why:e.string().max(300).optional()}),"version.install":e.strictObject({version:r,from:e.enum(["registry","organizer"]),tarball:e.strictObject({bundleId:u,sha256:e.string().regex(/^[0-9a-f]{64}$/),size:e.number().int().positive().max(8*1024*1024*1024)}).optional()}),"version.state":e.discriminatedUnion("state",[e.strictObject({state:e.literal("in-step"),worker:i,organizer:i}),e.strictObject({state:e.literal("installing"),worker:i,organizer:i,from:e.enum(["registry","organizer"]),since:n}),e.strictObject({state:e.literal("waiting-for-person"),worker:i,organizer:i,stored:e.boolean()}),e.strictObject({state:e.literal("out-of-step"),worker:i,organizer:i,why:e.object({kind:e.enum(["protocol","version","installed","restarting","install-failed","restart-failed","no-store"])}).catchall(e.union([e.string().max(600),e.number(),e.boolean()]))})])},STORE_CALL_LIMITS={args:16,argsBytes:256*1024,answerBytes:480*1024},PEER_LAUNCH_KEY_PATTERN=/^[A-Za-z0-9_-]{43}$/;const L=e.strictObject({added:e.number().int().nonnegative().nullable(),removed:e.number().int().nonnegative().nullable()});export const StoreCallSchema=e.strictObject({v:e.literal(1),kind:e.literal("store.call"),id:e.string().regex(/^[A-Za-z0-9._:-]{1,100}$/),method:e.string().regex(/^[A-Za-z][A-Za-z0-9]{0,79}$/),args:e.array(e.unknown()).max(STORE_CALL_LIMITS.args),launchKey:e.string().min(16).max(512),observe:e.strictObject({intervalMs:e.number().int().min(0).max(864e5).optional(),snapshot:e.strictObject({branch:e.string().max(300).nullable(),head:e.string().regex(/^[0-9a-f]{40}(?:[0-9a-f]{24})?$/).nullable(),files:e.array(e.strictObject({path:e.string().min(1).max(4096),from:e.string().max(4096).optional(),status:e.string().max(2),staged:L.optional(),unstaged:L.optional()})).max(1e3),truncated:e.boolean()}).optional(),failed:e.literal(!0).optional()}).optional()}),StoreReplySchema=e.strictObject({v:e.literal(1),kind:e.literal("store.reply"),id:e.string().max(100),wrote:e.boolean(),result:e.unknown().optional(),error:e.strictObject({name:e.enum(["CoordinationError","CapacityRefusal","CoordinationBusyError","StoreCallRefused","Error"]),message:e.string().max(4e3),room:e.record(e.string(),e.unknown()).optional(),step:e.enum(["open","write","commit","read"]).optional(),waitedMs:e.number().nonnegative().optional(),tries:e.number().int().nonnegative().optional(),wrote:e.boolean().optional(),where:e.string().max(300).optional(),wal:e.boolean().optional()}).optional()}),REMOTE_INSTANCE_BODY_SCHEMAS={"instance.tunnel.open":e.strictObject({tunnelId:e.string().regex(/^[A-Za-z0-9][A-Za-z0-9_-]{7,79}$/),instanceId:e.string().regex(z)}),"instance.state":e.strictObject({instanceId:e.string().regex(z),state:e.enum(["up","gone"]),apex:e.string().max(253).regex(/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*\.localhost$/).startsWith(Y).optional(),dashboardBase:e.string().regex(F).optional(),at:n,why:e.string().max(500).regex(l).optional()})},PEER_LAUNCH_LIMITS={promptChars:64*1024,roleTextChars:64*1024,maxMinutes:720,tailLines:40,tailLineChars:400},PEER_LAUNCH_ID=/^ln-[a-z0-9]{1,12}-[a-f0-9]{6}$/;const b=e.string().regex(PEER_LAUNCH_ID),ee=e.string().regex(PEER_LAUNCH_KEY_PATTERN),Z=e.string().regex(/^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i),te=e.string().regex(/^[a-z][a-z0-9-]{0,39}$/),B=s(t=>e.string().min(1).max(t).regex(/^[A-Za-z0-9][A-Za-z0-9._:/@[\]-]*$/),"clientWord"),A=e.string().min(2).max(1024).regex(/^\/[^\0\r\n]*$/).refine(t=>!t.split("/").includes(".."),"no .. part"),R=e.string().min(1).max(100).regex(/^[A-Za-z0-9._:-]+$/);export const PEER_LAUNCH_SCHEMAS={"launch.start":e.strictObject({launchId:b,repository:f,goal:R,task:Z.optional(),role:te,by:R,client:e.enum(["claude","codex"]),model:B(80).optional(),effort:B(40).optional(),worktree:A.optional(),placedGoal:e.literal(!0).optional(),prompt:e.string().min(1).max(PEER_LAUNCH_LIMITS.promptChars),roleText:e.string().max(PEER_LAUNCH_LIMITS.roleTextChars).optional(),name:e.string().min(1).max(80).regex(l).optional(),maxMinutes:e.number().int().min(1).max(PEER_LAUNCH_LIMITS.maxMinutes),account:e.string().regex(/^ac-[a-z0-9]{1,12}-[a-f0-9]{6}$/).optional(),launchKey:ee,lensmcp:r,resume:e.strictObject({launchId:b,threadId:Z,from:A.optional()}).optional(),capKind:e.enum(["writers","checkers"]).optional()}).refine(t=>t.worktree===void 0!=(t.placedGoal===void 0),"a launch names its worktree, or that its goal is placed there \u2014 exactly one"),"launch.stop":e.strictObject({launchId:b,why:e.string().max(300).regex(l).optional()}),"launch.state":e.strictObject({launchId:b,state:e.enum(["running","exited","stopped","failed"]),at:n,pid:e.number().int().min(0).max(99999999).optional(),exitCode:e.number().int().min(-1).max(1024).optional(),endedAt:n.optional(),threadId:R.optional(),ended:e.strictObject({quota:e.strictObject({client:e.enum(["claude","codex"]),why:e.string().min(1).max(300),until:n,firstTurn:e.boolean(),account:e.string().max(40).optional()}).optional(),context:e.string().min(1).max(600).optional()}).optional()}),"launch.tail":e.strictObject({launchId:b,lines:e.array(e.string().max(PEER_LAUNCH_LIMITS.tailLineChars+8)).max(PEER_LAUNCH_LIMITS.tailLines),at:n})},LaunchStartedSchema=e.strictObject({started:e.literal(!0),pid:e.number().int().min(2).max(99999999),worktree:A,branch:e.string().max(250).optional(),startedAt:n,deadline:n,threadId:e.string().max(200).optional(),lensmcp:r}),STORE_READ_LIMITS={calls:24,argsBytes:64*1024,answerBytes:STORE_CALL_LIMITS.answerBytes},StoreReadSchema=e.strictObject({v:e.literal(1),kind:e.literal("store.read"),id:e.string().regex(/^[A-Za-z0-9._:-]{1,100}$/),repoId:e.string().regex(/^[0-9a-f]{16,64}$/),calls:e.array(e.strictObject({method:e.string().regex(/^[A-Za-z][A-Za-z0-9]{0,79}$/),args:e.array(e.unknown()).max(STORE_CALL_LIMITS.args)})).min(1).max(STORE_READ_LIMITS.calls)}),GOAL_ON_WORKER={maxSendBytes:512*1024*1024,maxChangesBytes:400*1024,branchPrefix:"lensmcp/g-"};const j=e.string().regex(/^[A-Za-z0-9._:-]{1,100}$/),H=e.strictObject({id:e.string().regex(/^[0-9a-f]{16}$/),size:e.number().int().positive().max(64*1024*1024*1024),sha256:e.string().regex(/^[0-9a-f]{64}$/)}),ne=e.string().min(1).max(200).regex(/^lensmcp\/g-[a-z0-9-]{1,30}$/),m=e.string().regex(/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/),W=e.string().regex(/^[0-9a-f]{16,64}$/),E=e.string().max(1e3);export const GOAL_PEER_SCHEMAS={"goal.place":e.strictObject({goal:j,title:e.string().min(1).max(300).regex(l),repository:W,worktreeId:e.string().regex(/^[0-9a-f]{24}$/),name:e.string().regex(/^g-[a-z0-9](?:[a-z0-9-]{0,17}[a-z0-9])?$/),branch:ne,base:m,bundle:H,services:e.enum(["on-demand","none","always"]).optional(),at:n}),"goal.sent":e.strictObject({bundleId:e.string().regex(/^[0-9a-f]{16}$/),repository:W,goal:j,ref:e.string().min(1).max(250).regex(/^heads\/lensmcp\/g-[a-z0-9-]{1,30}$/),size:e.number().int().positive().max(GOAL_ON_WORKER.maxSendBytes),sha256:e.string().regex(/^[0-9a-f]{64}$/)}),"goal.changes":e.strictObject({goal:j,what:e.enum(["row","files","diff","commits","commit","against"]),path:e.string().min(1).max(4096).optional(),sha:m.optional(),full:e.boolean().optional(),againstMain:e.boolean().optional()}),"goal.update":e.strictObject({goal:j,main:e.strictObject({branch:e.string().min(1).max(200).regex(/^[A-Za-z0-9._/-]+$/),sha:m,bundle:H}),at:n})},GOAL_PEER_ANSWER_SCHEMAS={"goal.place":e.strictObject({state:e.enum(["ready","creating","failed"]),head:m.optional(),onDemand:e.boolean().optional(),needWhole:e.boolean().optional(),why:E.optional()}),"goal.sent":e.strictObject({took:e.boolean(),ref:e.string().max(250),sha:m.optional(),mirror:e.enum(["created","fast-forward","current","not-ff","checked-out"]).optional(),told:e.string().max(200).optional(),code:e.string().max(40).optional(),why:E.optional()}),"goal.changes":e.strictObject({ok:e.boolean(),value:e.unknown().optional(),status:e.number().int().min(100).max(599).optional(),why:E.optional(),shortened:e.boolean().optional()}),"goal.update":e.strictObject({outcome:e.enum(["current","merged","asked","conflicts","refused"]),why:E,sha:m.optional(),behind:e.number().int().min(0).max(1e7).optional(),dirty:e.number().int().min(0).max(1e7).optional(),conflicts:e.array(e.string().min(1).max(4096)).max(200).optional(),needWhole:e.boolean().optional()})};
|
|
1
|
+
"use strict";var Y=Object.defineProperty;var w=(e,o)=>Y(e,"name",{value:o,configurable:!0});var X=Object.defineProperty,i=w((e,o)=>X(e,"name",{value:o,configurable:!0}),"i");import{z as t}from"zod";import{RUN_ID_PATTERN as T}from"./docker-jobs.js";import{CONVERSATION_ID as J,CONVERSATION_LIST_MAX as D,CONVERSATION_TOOL_OUTPUT_CHARS as M,CONVERSATION_TURN_CHARS as Q}from"./conversations.js";import{REMOTE_DASHBOARD_BASE_PATTERN as tt,REMOTE_INSTANCE_ID_PATTERN as N,REMOTE_INSTANCE_NAME_PREFIX as et}from"./remote-instances.js";export const PEER_PROTOCOL="peer/v1",PEER_PORT=7466,PEER_TIMING={pingMs:5e3,lostMs:45e3,windowMs:10*6e4,approveMs:10*6e4,capacityMs:3e4},PAIRING_CODE={length:10,tries:5},CROCKFORD_ALPHABET="0123456789ABCDEFGHJKMNPQRSTVWXYZ",PEER_PATHS={pair:"/peer/v1/pair",control:"/peer/v1/control",runs:"/peer/v1/runs/",bundles:"/peer/v1/bundles/",sent:"/peer/v1/sent/",tunnel:"/peer/v1/tunnel/"},RUN_UPLOAD_KINDS=["log","samples","events","artifacts"],RUN_UPLOAD_RANGE={from:"x-lensmcp-from",to:"x-lensmcp-to"},PEER_FILES={dir:"peers",key:"identity.key",cert:"identity.crt",window:"window.json",workers:"workers.json",organizer:"organizer.json",hub:"hub.json",hubLock:"hub.lock",hubLog:"hub.log",runs:"runs",instances:"instances"},FINGERPRINT_PATTERN=/^[0-9a-f]{64}$/,REMOTE_RUN_LOST="lost",PEER_MESSAGE_ID=/^[A-Za-z0-9_-]{1,64}$/,TO_WORKER=["job.offer","job.cancel","bundle.ready","tunnel.open","tunnel.close","launch.start","launch.stop","store.reply","version.install","main.moved","instance.tunnel.open","goal.place","goal.changes","goal.update"],TO_ORGANIZER=["hello","capacity","job.state","job.stage","job.done","bundle.sent","launch.state","launch.tail","store.call","version.state","forget","main.state","instance.state","store.read","goal.sent","conversation.sync","conversation.read"],EITHER_WAY=["ping"],PEER_REPLIES=["ack","error","pong"],PEER_MESSAGE_SLICE={hello:"D12 (versions: D13, capacity: D14)",ping:"D12",pong:"D12",ack:"D12",error:"D12",forget:"D11",capacity:"D14","job.offer":"D14","job.cancel":"D14/D18","job.state":"D14/D16","job.stage":"D16","job.done":"D16","bundle.ready":"D15","bundle.sent":"D34 (goal branches: D30)","tunnel.open":"D17","tunnel.close":"D17","launch.start":"D29","launch.stop":"D29","launch.state":"D29","launch.tail":"D29","store.call":"D27/D28","store.reply":"D27/D28","version.install":"D13","version.state":"D13","main.moved":"D34","main.state":"D34","instance.tunnel.open":"D35","instance.state":"D35 (sent by D30)","store.read":"D32","goal.place":"D30","goal.sent":"D30","goal.changes":"D30","goal.update":"D30","conversation.sync":"CV5","conversation.read":"CV5"};const f=i((e,o)=>e.includes(o),"has");export const isPeerMessageType=i(e=>Object.prototype.hasOwnProperty.call(PEER_MESSAGE_SLICE,e),"isPeerMessageType");export function peerMaySend(e,o){return f(EITHER_WAY,o)||f(PEER_REPLIES,o)?!0:f(e==="organizer"?TO_WORKER:TO_ORGANIZER,o)}w(peerMaySend,"peerMaySend"),i(peerMaySend,"peerMaySend");export const isPeerReply=i(e=>f(PEER_REPLIES,e),"isPeerReply");const s=/^[^\p{Cc}\p{Cf}\p{Zl}\p{Zp}]*$/u,d=i(e=>t.string().min(1).max(e).regex(s),"shownText"),$=t.string().regex(/^[A-Za-z0-9_-]{43}$/),C=t.string().regex(/^[0-9a-f]{64}$/),l=t.string().min(1).max(64).regex(/^[0-9A-Za-z.+_-]+$/),nt=t.tuple([t.string().regex(/^[a-z]{3,8}$/),t.string().regex(/^[a-z]{3,8}$/),t.string().regex(/^[a-z]{3,8}$/),t.string().regex(/^[a-z]{3,8}$/)]),n=t.number().int().nonnegative();export const PeerEnvelopeSchema=t.strictObject({v:t.literal(1),id:t.string().regex(PEER_MESSAGE_ID),replyTo:t.string().regex(PEER_MESSAGE_ID).optional(),type:t.string().min(1).max(40),body:t.record(t.string(),t.unknown())});const at=["unknown-type","wrong-direction","bad-message","hello-first","not-handled","too-large","busy","refused","timeout","lost","internal","no-window","window-used","window-closed","wrong-code","protocol"];export const PeerErrorBodySchema=t.strictObject({code:t.enum(at),message:t.string().max(500),triesLeft:t.number().int().min(0).max(PAIRING_CODE.tries).optional(),retryAfterMs:t.number().int().min(0).max(36e5).optional()});const p=t.string().regex(T);export const WorkerAdvertSchema=t.record(t.string(),t.unknown()).superRefine((e,o)=>{const O=e.runs;O!==void 0&&(!Array.isArray(O)||O.length>256||!O.every(z=>typeof z=="string"&&T.test(z)))&&o.addIssue({code:"custom",message:"runs: at most 256 run ids"})}),PEER_BODY_SCHEMAS={hello:t.strictObject({protocol:t.literal(PEER_PROTOCOL),lensmcp:l,follow:t.boolean().optional(),store:t.array(l).max(64).optional(),capacity:WorkerAdvertSchema.optional()}),ping:t.strictObject({at:n}),pong:t.strictObject({at:n}),ack:t.strictObject({result:t.unknown().optional()}),error:PeerErrorBodySchema,forget:t.strictObject({why:t.string().max(200).regex(s).optional()})},PeerWelcomeSchema=t.strictObject({protocol:t.literal(PEER_PROTOCOL),lensmcp:l,name:d(64),inStep:t.boolean().optional(),why:t.string().max(500).optional()}),PAIR_BODY_SCHEMAS={"pair.hello":t.strictObject({protocol:t.literal(PEER_PROTOCOL),nonce:$,name:d(64),model:d(40),lensmcp:l}),"pair.resume":t.strictObject({protocol:t.literal(PEER_PROTOCOL)}),"pair.challenge":t.strictObject({nonce:$}),"pair.proof":t.strictObject({proof:C}),"pair.accepted":t.strictObject({proof:C,name:d(64),model:d(40),words:nt,approveBy:n}),"pair.approved":t.strictObject({at:n}),"pair.declined":t.strictObject({why:t.string().max(500)}),error:PeerErrorBodySchema},MAIN_MIRROR={branch:"main",quietMs:10*6e4,snapshotEveryMs:60*6e4,maxSendBytes:512*1024*1024,maxWipBytes:256*1024*1024,maxHaves:16},MAIN_BRING_IN=["in-main","brought-in","waiting","not-ff","refused"],MAIN_FOLLOW_STATES=["in-step","fast-forward","ahead","waiting","to-update","not-following","off-branch"];const r=t.string().regex(/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/),y=t.string().regex(/^[0-9a-f]{16,64}$/),P=t.string().regex(/^[0-9a-f]{64}$/),L=t.string().regex(/^[0-9a-f]{16}$/),u=t.number().int().min(0).max(1e7),j=t.string().min(1).max(250).regex(/^[A-Za-z0-9._/-]+$/),E=t.string().max(1e3),Z=t.strictObject({state:t.enum(["in-main","brought-in","waiting","not-ff","refused"]),count:u,sha:r.optional(),main:r.optional(),why:E,at:n}),ot=t.strictObject({outcome:t.enum(["merged","fast-forward","current","conflicts","waiting","refused"]),at:n,why:E,sha:r.optional(),conflicts:t.array(t.string().min(1).max(4096)).max(200).optional(),asked:t.array(t.strictObject({who:t.enum(["person","manager"]),goal:t.string().max(64).optional(),to:t.string().max(200).optional()})).max(20).optional()}),B=t.enum(["in-step","fast-forward","ahead","waiting","to-update","not-following","off-branch"]);export const MAIN_MIRROR_SCHEMAS={"bundle.sent":t.strictObject({bundleId:L,repository:y,refs:t.array(j).length(1),size:t.number().int().positive().max(MAIN_MIRROR.maxSendBytes),sha256:P}),"main.moved":t.strictObject({repository:y,branch:j,sha:r,bundle:t.strictObject({id:L,size:t.number().int().positive(),sha256:P}),verdict:Z.optional(),at:n}),"main.state":t.strictObject({repository:y,branch:j,head:r.optional(),organizerHead:r.optional(),haves:t.array(r).max(MAIN_MIRROR.maxHaves),notSent:u,toPull:u,uncommitted:t.strictObject({files:u,changedAt:n.optional()}),snapshot:t.strictObject({sha:r,at:n,files:u,sent:t.boolean()}).optional(),follow:B,update:ot.optional(),at:n})},MAIN_MIRROR_ANSWER_SCHEMAS={"bundle.sent":t.strictObject({took:t.boolean(),ref:j,sha:r.optional(),code:t.string().max(40).optional(),why:E.optional(),verdict:Z.optional()}),"main.moved":t.strictObject({took:t.boolean(),needWhole:t.boolean().optional(),why:E.optional(),follow:B.optional(),head:r.optional()})};const rt=t.string().regex(/^[A-Za-z0-9][A-Za-z0-9._-]{0,62}$/),v=t.string().regex(/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/),H=t.string().regex(/^[0-9a-f]{16,64}$/),b=t.string().regex(/^[A-Za-z0-9][A-Za-z0-9_-]{7,79}$/),W=i(e=>t.string().min(1).max(e).regex(s),"sentence"),m=t.record(t.string(),t.unknown()),it=t.string().regex(/^[A-Za-z_][A-Za-z0-9_]{0,99}$/),c=t.strictObject({lensmcp:l,protocol:t.string().regex(/^peer\/v[1-9]\d{0,3}$/)});export const PEER_WORK_SCHEMAS={capacity:WorkerAdvertSchema,"job.offer":t.strictObject({runId:p,job:rt,candidate:v,repository:H,lane:t.enum(["light","heavy"]).optional(),kind:t.enum(["compose","testcontainers","playwright"]).optional(),hostMb:t.number().int().min(0).max(1024*1024).optional(),vmMb:t.number().int().min(0).max(1024*1024).optional(),proof:t.boolean().optional(),timeoutMinutes:t.number().positive().max(360).optional(),onLinkLoss:t.union([t.literal("cancel"),t.strictObject({continueMinutes:t.number().int().min(1).max(360)})]).optional(),secrets:t.record(it,t.string().min(1).max(8192)).refine(e=>Object.keys(e).length<=16,"at most 16 secrets").optional(),origin:t.string().max(300).regex(/^https?:\/\/[A-Za-z0-9.-]+(?::\d{1,5})?$/).optional()}),"job.cancel":t.strictObject({runId:p,why:W(300)}),"job.state":t.strictObject({runId:p,at:n,started:t.literal(!0).optional(),state:t.enum(["queued","running"]).optional(),note:t.string().max(1e3).optional(),queue:m.optional(),docker:m.optional(),edgePort:t.number().int().min(1024).max(65535).optional()}),"job.stage":t.strictObject({runId:p,stage:W(120),at:n}),"job.done":t.strictObject({runId:p,at:n,state:t.enum(["passed","failed","errored","cancelled","timeout"]),note:t.string().max(1e3).optional(),step:m.optional(),docker:m.optional(),givenBack:t.strictObject({why:t.string().min(1).max(1e3)}).optional(),refused:t.strictObject({why:t.string().min(1).max(1e3)}).optional(),proof:m.optional()}),"bundle.ready":t.strictObject({runId:p.optional(),bundleId:b,repository:H,heads:t.array(v).min(1).max(16),basis:t.array(v).max(256).optional(),size:t.number().int().positive().max(64*1024*1024*1024),sha256:t.string().regex(/^[0-9a-f]{64}$/),shipment:m.optional(),blobs:t.record(t.string().regex(/^[0-9a-f]{64}$/),b).refine(e=>Object.keys(e).length<=101,"at most 101 blobs").optional()}),"tunnel.open":t.strictObject({tunnelId:b,runId:p,port:t.number().int().min(1).max(65535).optional()}),"tunnel.close":t.strictObject({tunnelId:b,why:t.string().max(300).optional()}),"version.install":t.strictObject({version:l,from:t.enum(["registry","organizer"]),tarball:t.strictObject({bundleId:b,sha256:t.string().regex(/^[0-9a-f]{64}$/),size:t.number().int().positive().max(8*1024*1024*1024)}).optional()}),"version.state":t.discriminatedUnion("state",[t.strictObject({state:t.literal("in-step"),worker:c,organizer:c}),t.strictObject({state:t.literal("installing"),worker:c,organizer:c,from:t.enum(["registry","organizer"]),since:n}),t.strictObject({state:t.literal("waiting-for-person"),worker:c,organizer:c,stored:t.boolean()}),t.strictObject({state:t.literal("out-of-step"),worker:c,organizer:c,why:t.object({kind:t.enum(["protocol","version","installed","restarting","install-failed","restart-failed","no-store"])}).catchall(t.union([t.string().max(600),t.number(),t.boolean()]))})])},STORE_CALL_LIMITS={args:16,argsBytes:256*1024,answerBytes:480*1024},PEER_LAUNCH_KEY_PATTERN=/^[A-Za-z0-9_-]{43}$/;const G=t.strictObject({added:t.number().int().nonnegative().nullable(),removed:t.number().int().nonnegative().nullable()});export const StoreCallSchema=t.strictObject({v:t.literal(1),kind:t.literal("store.call"),id:t.string().regex(/^[A-Za-z0-9._:-]{1,100}$/),method:t.string().regex(/^[A-Za-z][A-Za-z0-9]{0,79}$/),args:t.array(t.unknown()).max(STORE_CALL_LIMITS.args),launchKey:t.string().min(16).max(512),observe:t.strictObject({intervalMs:t.number().int().min(0).max(864e5).optional(),snapshot:t.strictObject({branch:t.string().max(300).nullable(),head:t.string().regex(/^[0-9a-f]{40}(?:[0-9a-f]{24})?$/).nullable(),files:t.array(t.strictObject({path:t.string().min(1).max(4096),from:t.string().max(4096).optional(),status:t.string().max(2),staged:G.optional(),unstaged:G.optional()})).max(1e3),truncated:t.boolean()}).optional(),failed:t.literal(!0).optional()}).optional()}),StoreReplySchema=t.strictObject({v:t.literal(1),kind:t.literal("store.reply"),id:t.string().max(100),wrote:t.boolean(),result:t.unknown().optional(),error:t.strictObject({name:t.enum(["CoordinationError","CapacityRefusal","CoordinationBusyError","StoreCallRefused","Error"]),message:t.string().max(4e3),room:t.record(t.string(),t.unknown()).optional(),step:t.enum(["open","write","commit","read"]).optional(),waitedMs:t.number().nonnegative().optional(),tries:t.number().int().nonnegative().optional(),wrote:t.boolean().optional(),where:t.string().max(300).optional(),wal:t.boolean().optional()}).optional()}),REMOTE_INSTANCE_BODY_SCHEMAS={"instance.tunnel.open":t.strictObject({tunnelId:t.string().regex(/^[A-Za-z0-9][A-Za-z0-9_-]{7,79}$/),instanceId:t.string().regex(N)}),"instance.state":t.strictObject({instanceId:t.string().regex(N),state:t.enum(["up","gone"]),apex:t.string().max(253).regex(/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*\.localhost$/).startsWith(et).optional(),dashboardBase:t.string().regex(tt).optional(),at:n,why:t.string().max(500).regex(s).optional()})},PEER_LAUNCH_LIMITS={promptChars:64*1024,roleTextChars:64*1024,maxMinutes:720,tailLines:40,tailLineChars:400},PEER_LAUNCH_ID=/^ln-[a-z0-9]{1,12}-[a-f0-9]{6}$/;const x=t.string().regex(PEER_LAUNCH_ID),st=t.string().regex(PEER_LAUNCH_KEY_PATTERN),U=t.string().regex(/^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i),lt=t.string().regex(/^[a-z][a-z0-9-]{0,39}$/),K=i(e=>t.string().min(1).max(e).regex(/^[A-Za-z0-9][A-Za-z0-9._:/@[\]-]*$/),"clientWord"),R=t.string().min(2).max(1024).regex(/^\/[^\0\r\n]*$/).refine(e=>!e.split("/").includes(".."),"no .. part"),I=t.string().min(1).max(100).regex(/^[A-Za-z0-9._:-]+$/);export const PEER_LAUNCH_SCHEMAS={"launch.start":t.strictObject({launchId:x,repository:y,goal:I,task:U.optional(),role:lt,by:I,client:t.enum(["claude","codex"]),model:K(80).optional(),effort:K(40).optional(),worktree:R.optional(),placedGoal:t.literal(!0).optional(),prompt:t.string().min(1).max(PEER_LAUNCH_LIMITS.promptChars),roleText:t.string().max(PEER_LAUNCH_LIMITS.roleTextChars).optional(),name:t.string().min(1).max(80).regex(s).optional(),maxMinutes:t.number().int().min(1).max(PEER_LAUNCH_LIMITS.maxMinutes),account:t.string().regex(/^ac-[a-z0-9]{1,12}-[a-f0-9]{6}$/).optional(),launchKey:st,lensmcp:l,resume:t.strictObject({launchId:x,threadId:U,from:R.optional()}).optional(),capKind:t.enum(["writers","checkers"]).optional()}).refine(e=>e.worktree===void 0!=(e.placedGoal===void 0),"a launch names its worktree, or that its goal is placed there \u2014 exactly one"),"launch.stop":t.strictObject({launchId:x,why:t.string().max(300).regex(s).optional()}),"launch.state":t.strictObject({launchId:x,state:t.enum(["running","exited","stopped","failed"]),at:n,pid:t.number().int().min(0).max(99999999).optional(),exitCode:t.number().int().min(-1).max(1024).optional(),endedAt:n.optional(),threadId:I.optional(),ended:t.strictObject({quota:t.strictObject({client:t.enum(["claude","codex"]),why:t.string().min(1).max(300),until:n,firstTurn:t.boolean(),account:t.string().max(40).optional()}).optional(),context:t.string().min(1).max(600).optional()}).optional()}),"launch.tail":t.strictObject({launchId:x,lines:t.array(t.string().max(PEER_LAUNCH_LIMITS.tailLineChars+8)).max(PEER_LAUNCH_LIMITS.tailLines),at:n})},LaunchStartedSchema=t.strictObject({started:t.literal(!0),pid:t.number().int().min(2).max(99999999),worktree:R,branch:t.string().max(250).optional(),startedAt:n,deadline:n,threadId:t.string().max(200).optional(),lensmcp:l}),STORE_READ_LIMITS={calls:24,argsBytes:64*1024,answerBytes:STORE_CALL_LIMITS.answerBytes},StoreReadSchema=t.strictObject({v:t.literal(1),kind:t.literal("store.read"),id:t.string().regex(/^[A-Za-z0-9._:-]{1,100}$/),repoId:t.string().regex(/^[0-9a-f]{16,64}$/),calls:t.array(t.strictObject({method:t.string().regex(/^[A-Za-z][A-Za-z0-9]{0,79}$/),args:t.array(t.unknown()).max(STORE_CALL_LIMITS.args)})).min(1).max(STORE_READ_LIMITS.calls)}),GOAL_ON_WORKER={maxSendBytes:512*1024*1024,maxChangesBytes:400*1024,branchPrefix:"lensmcp/g-"};const _=t.string().regex(/^[A-Za-z0-9._:-]{1,100}$/),V=t.strictObject({id:t.string().regex(/^[0-9a-f]{16}$/),size:t.number().int().positive().max(64*1024*1024*1024),sha256:t.string().regex(/^[0-9a-f]{64}$/)}),ct=t.string().min(1).max(200).regex(/^lensmcp\/g-[a-z0-9-]{1,30}$/),g=t.string().regex(/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/),q=t.string().regex(/^[0-9a-f]{16,64}$/),A=t.string().max(1e3);export const GOAL_PEER_SCHEMAS={"goal.place":t.strictObject({goal:_,title:t.string().min(1).max(300).regex(s),repository:q,worktreeId:t.string().regex(/^[0-9a-f]{24}$/),name:t.string().regex(/^g-[a-z0-9](?:[a-z0-9-]{0,17}[a-z0-9])?$/),branch:ct,base:g,bundle:V,services:t.enum(["on-demand","none","always"]).optional(),at:n}),"goal.sent":t.strictObject({bundleId:t.string().regex(/^[0-9a-f]{16}$/),repository:q,goal:_,ref:t.string().min(1).max(250).regex(/^heads\/lensmcp\/g-[a-z0-9-]{1,30}$/),size:t.number().int().positive().max(GOAL_ON_WORKER.maxSendBytes),sha256:t.string().regex(/^[0-9a-f]{64}$/)}),"goal.changes":t.strictObject({goal:_,what:t.enum(["row","files","diff","commits","commit","against"]),path:t.string().min(1).max(4096).optional(),sha:g.optional(),full:t.boolean().optional(),againstMain:t.boolean().optional()}),"goal.update":t.strictObject({goal:_,main:t.strictObject({branch:t.string().min(1).max(200).regex(/^[A-Za-z0-9._/-]+$/),sha:g,bundle:V}),at:n})},GOAL_PEER_ANSWER_SCHEMAS={"goal.place":t.strictObject({state:t.enum(["ready","creating","failed"]),head:g.optional(),onDemand:t.boolean().optional(),needWhole:t.boolean().optional(),why:A.optional()}),"goal.sent":t.strictObject({took:t.boolean(),ref:t.string().max(250),sha:g.optional(),mirror:t.enum(["created","fast-forward","current","not-ff","checked-out"]).optional(),told:t.string().max(200).optional(),code:t.string().max(40).optional(),why:A.optional()}),"goal.changes":t.strictObject({ok:t.boolean(),value:t.unknown().optional(),status:t.number().int().min(100).max(599).optional(),why:A.optional(),shortened:t.boolean().optional()}),"goal.update":t.strictObject({outcome:t.enum(["current","merged","asked","conflicts","refused"]),why:A,sha:g.optional(),behind:t.number().int().min(0).max(1e7).optional(),dirty:t.number().int().min(0).max(1e7).optional(),conflicts:t.array(t.string().min(1).max(4096)).max(200).optional(),needWhole:t.boolean().optional()})},CONVERSATION_PEER_LIMITS={messageBytes:384*1024,conversations:32,turns:500,settles:64,turnBytes:64*1024,targetChars:4096,beatBytes:1024*1024,beatConversations:64,readTokens:6e4};const S=t.string().regex(J),F=t.string().regex(/^[0-9a-f]{16,64}$/),a=i(e=>t.string().max(e),"cvWords"),k=t.number().int().min(1).max(Number.MAX_SAFE_INTEGER),pt=t.strictObject({id:S,client:t.enum(["claude","codex"]),nativeId:t.string().regex(/^[\w.-]{8,128}$/),account:t.string().min(1).max(4200),accountNick:a(200).optional(),checkout:t.strictObject({root:t.string().min(1).max(4096),branch:a(300).optional(),key:a(300).optional()}),cwd:a(4096).optional(),model:a(200).optional(),startedAt:n,lastAt:n,state:t.enum(["running","ended","kept"]),kind:t.enum(["person","team","outside"]).optional(),sessionId:a(200).optional(),launchId:a(200).optional(),role:a(80).optional(),goalId:a(120).optional(),goalTitle:a(300).optional(),taskId:a(120).optional(),continues:S.optional()}),mt=t.strictObject({seq:k,at:n.optional(),kind:t.enum(["prompt","reply","tool","compaction","subagent"]),text:a(Q),cut:t.literal(!0).optional(),tool:t.strictObject({name:t.string().min(1).max(200),target:a(CONVERSATION_PEER_LIMITS.targetChars).optional(),outcome:t.enum(["ok","error"]).optional(),output:a(M).optional()}).optional(),files:t.array(t.string().min(1).max(4096)).max(50).optional()}),gt=t.strictObject({checkout:a(400).min(1).optional(),goalId:a(120).min(1).optional(),taskId:a(120).min(1).optional(),role:a(80).min(1).optional(),client:t.enum(["claude","codex"]).optional(),account:a(4200).min(1).optional(),mac:a(128).min(1).optional(),state:t.enum(["running","ended","kept"]).optional(),since:n.optional(),text:a(400).min(1).optional(),limit:t.number().int().min(1).max(D).optional()}),h=t.record(t.string(),t.unknown()),dt=t.discriminatedUnion("what",[t.strictObject({what:t.literal("list"),query:gt}),t.strictObject({what:t.literal("get"),id:t.string().min(1).max(200),part:t.enum(["handoff","turns"]),maxTokens:t.number().int().min(500).max(1e5).optional(),before:k.optional()})]);export const CONVERSATION_PEER_SCHEMAS={"conversation.sync":t.strictObject({v:t.literal(1),kind:t.literal("conversation.sync"),repository:F,macBasis:t.string().regex(/^[\w-]{8,128}$/),conversations:t.array(t.strictObject({row:pt,turns:t.array(mt).max(CONVERSATION_PEER_LIMITS.turns),settles:t.array(t.strictObject({seq:k,outcome:t.enum(["ok","error"]),output:a(M).optional()})).max(CONVERSATION_PEER_LIMITS.settles).optional(),rewound:t.literal(!0).optional()})).min(1).max(CONVERSATION_PEER_LIMITS.conversations)}),"conversation.read":t.strictObject({v:t.literal(1),kind:t.literal("conversation.read"),repository:F,ask:dt})},CONVERSATION_PEER_ANSWER_SCHEMAS={"conversation.sync":t.strictObject({v:t.literal(1),held:t.array(t.strictObject({id:S,seq:t.number().int().min(0),refused:a(500).optional()})).max(CONVERSATION_PEER_LIMITS.conversations)}),"conversation.read":t.strictObject({v:t.literal(1),from:t.strictObject({name:t.string().min(1).max(64).regex(s),fingerprint:t.string().regex(FINGERPRINT_PATTERN).optional()}),found:t.boolean(),why:a(1e3).optional(),list:t.object({conversations:t.array(h).max(D),more:t.boolean()}).passthrough().optional(),handoff:t.object({conversation:h,turns:t.array(h),more:t.boolean(),next:t.string()}).passthrough().optional(),page:t.object({conversation:h,turns:t.array(h),more:t.boolean()}).passthrough().optional()})};
|
package/lib/perf-rules.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var u=Object.defineProperty;var o=(r,e)=>u(r,"name",{value:e,configurable:!0});var c=Object.defineProperty,a=o((r,e)=>c(r,"name",{value:e,configurable:!0}),"o");export const PERF_RULE_IDS=["bundle/heavy-barrel-import","pod/heap-budget","pod/retained-generation"],PERF_RULE_EVENT_KINDS=["perf-rule-finding","perf-rule-retracted","perf-rule-scan"],PERF_RULES_DOC="https://github.com/kiwiapps-ltd/lensmcp/blob/main/docs/lensmcp/concepts/memory-and-build-cost.mdx",PERF_RULE_DOCS={"bundle/heavy-barrel-import":`${PERF_RULES_DOC}#bundleheavy-barrel-import`,"pod/heap-budget":`${PERF_RULES_DOC}#podheap-budget`,"pod/retained-generation":`${PERF_RULES_DOC}#podretained-generation`};export function perfRuleFingerprint(r,e,n){return`perf-rule:${r}:${e}:${n}`}o(perfRuleFingerprint,"perfRuleFingerprint"),a(perfRuleFingerprint,"perfRuleFingerprint");export function perfRuleScanFingerprint(r,e){return`perf-rule-scan:${r}:${e}`}o(perfRuleScanFingerprint,"perfRuleScanFingerprint"),a(perfRuleScanFingerprint,"perfRuleScanFingerprint");const s=/^[a-z][a-z0-9-]*\/[a-z0-9][a-z0-9-]*$/,l=12,f=4e3,t=a((r,e=f)=>typeof r=="string"&&r.length>0&&r.length<=e,"isText");export function asPerfRuleRaw(r){if(!r||typeof r!="object")return;const e=r;if(!PERF_RULE_EVENT_KINDS.includes(e.kind)||typeof e.rule!="string"||!s.test(e.rule)||!t(e.project,512))return;if(e.kind==="perf-rule-scan"){const i=e.open;return!Array.isArray(i)||i.length>256||!i.every(p=>t(p,512))?void 0:r}if(!t(e.subject,512))return;if(e.kind==="perf-rule-retracted")return r;if(e.severity!=="warning"&&e.severity!=="error"||!t(e.title)||!t(e.summary)||!t(e.verify)||!t(e.docs,1024))return;const n=e.fix;if(!(!Array.isArray(n)||n.length===0||n.length>l||!n.every(i=>t(i)))&&!(!e.evidence||typeof e.evidence!="object"||Array.isArray(e.evidence))&&!(!e.cost||typeof e.cost!="object"||Array.isArray(e.cost)))return r}o(asPerfRuleRaw,"asPerfRuleRaw"),a(asPerfRuleRaw,"asPerfRuleRaw");
|
package/lib/pod-memory.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var t=Object.defineProperty;var r=(o,e)=>t(o,"name",{value:e,configurable:!0});var d=Object.defineProperty,m=r((o,e)=>d(o,"name",{value:e,configurable:!0}),"r");export const POD_MEMORY_KINDS=["pod-memory","pod-memory-retained","pod-memory-released","pod-memory-exited"];export function asPodMemoryRaw(o){if(!o||typeof o!="object")return;const e=o;if(POD_MEMORY_KINDS.includes(e.kind)&&!(typeof e.project!="string"||!e.project)&&!(typeof e.pod!="number"||typeof e.pid!="number")&&!(e.kind==="pod-memory"&&(typeof e.live!="number"||!Number.isFinite(e.live)))&&!((e.kind==="pod-memory-retained"||e.kind==="pod-memory-released")&&typeof e.gen!="number"))return o}r(asPodMemoryRaw,"asPodMemoryRaw"),m(asPodMemoryRaw,"asPodMemoryRaw");
|
package/lib/producer-health.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var m=Object.defineProperty;var i=(t,o)=>m(t,"name",{value:o,configurable:!0});var R=Object.defineProperty,p=i((t,o)=>R(t,"name",{value:o,configurable:!0}),"u");import{z as e}from"zod";export const ProducerStateSchema=e.enum(["none","connected"]),ProducerRunStatusSchema=e.enum(["running","clean","failing","error"]),ProducerReportSchema=e.object({id:e.string(),tool:e.string(),project:e.string().optional(),firstReportedAt:e.number().int().nonnegative(),lastReportedAt:e.number().int().nonnegative(),lastRunStatus:ProducerRunStatusSchema,lastRunDurationMs:e.number().int().nonnegative().optional(),errorCount:e.number().int().nonnegative(),warningCount:e.number().int().nonnegative().optional(),error:e.string().optional()}),ProducerHealthSchema=e.object({producer:ProducerStateSchema,producers:e.array(ProducerReportSchema),lastReportedAt:e.number().int().nonnegative().optional(),ageMs:e.number().int().nonnegative().optional(),stale:e.boolean(),detail:e.string()}),PRODUCER_STALE_AFTER_MS=10*6e4;export function summariseProducers(t){const o=t.now??Date.now(),n=[...t.producers].sort((r,h)=>h.lastReportedAt-r.lastReportedAt);if(n.length===0)return{producer:"none",producers:[],stale:!1,detail:`No ${t.domain} producer has ever reported into this session \u2014 this is NOT a clean result, nothing is watching. ${t.noProducerHint}`};const d=n[0].lastReportedAt,u=Math.max(0,o-d),l=u>PRODUCER_STALE_AFTER_MS,c=n.filter(r=>r.lastRunStatus==="failing"),s=n.filter(r=>r.lastRunStatus==="error"),a=[`${n.length} ${t.domain} producer${n.length===1?"":"s"} reporting (${n.map(r=>r.id).join(", ")}); newest report ${g(u)}.`];return s.length>0&&a.push(`${s.length} produced NO verdict (the tool itself failed): ${s.map(r=>`${r.id} \u2014 ${r.error??"unknown error"}`).join("; ")}.`),c.length>0&&a.push(`${c.length} reporting errors.`),l&&a.push(`Older than ${Math.round(PRODUCER_STALE_AFTER_MS/6e4)}m \u2014 the verdict may predate the current source.`),{producer:"connected",producers:n,lastReportedAt:d,ageMs:u,stale:l,detail:a.join(" ")}}i(summariseProducers,"summariseProducers"),p(summariseProducers,"summariseProducers");function g(t){return t<1e3?"just now":t<6e4?`${Math.round(t/1e3)}s ago`:t<36e5?`${Math.round(t/6e4)}m ago`:`${Math.round(t/36e5)}h ago`}i(g,"g"),p(g,"describeAge");
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* REMOTE INSTANCES — a goal's runtime on a worker Mac, opened from the organizer's URLs (planning/docker/00-plan.md § 13
|
|
3
|
-
* «The lens for a remote goal's runtime», slice D35; issues/
|
|
3
|
+
* «The lens for a remote goal's runtime», slice D35; issues/closed/overseer-74). What the peer hub (`apps/agent`
|
|
4
4
|
* `peers/remote-instance.ts`) and the dev gateway (`@lensmcp/cluster` `runtime/remote-instances.ts`) share:
|
|
5
5
|
*
|
|
6
6
|
* - the route the hub asks of the organizer's gateway on its control socket (`POST/GET/DELETE /remote-instance`) — the
|
package/lib/remote-instances.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var t=Object.defineProperty;var _=(E,e)=>t(E,"name",{value:e,configurable:!0});var n=Object.defineProperty,A=_((E,e)=>n(E,"name",{value:e,configurable:!0}),"t");export const REMOTE_INSTANCE_ID_PATTERN=/^[A-Za-z0-9][A-Za-z0-9_-]{7,39}$/,REMOTE_INSTANCE_NAME_PREFIX="g-",MAX_REMOTE_INSTANCE_SEC=14400,REMOTE_LENS_LABEL="lensmcp",REMOTE_DASHBOARD_BASE_PATTERN=/^\/[A-Za-z0-9][A-Za-z0-9._-]{0,99}$/,PEER_TUNNEL_HEADER="x-lensmcp-peer-tunnel";export function remoteLensHost(E){return`${REMOTE_LENS_LABEL}.${E.toLowerCase()}`}_(remoteLensHost,"remoteLensHost"),A(remoteLensHost,"remoteLensHost");export const REMOTE_INSTANCES_FILE="instances.json";
|