@lensmcp/protocol-types 1.26.1 → 1.26.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/index.d.ts +14 -1
- package/index.js +1 -1
- package/lib/changes.d.ts +15 -3
- package/lib/cluster-hosts.d.ts +272 -0
- package/lib/cluster-hosts.js +1 -0
- package/lib/dashboard-lint.d.ts +22 -0
- package/lib/dashboard-updates.d.ts +80 -0
- package/lib/dashboard-updates.js +1 -0
- package/lib/dashboard.d.ts +54 -1
- package/lib/docker-errors.d.ts +123 -0
- package/lib/docker-errors.js +1 -0
- package/lib/docker-jobs.d.ts +673 -0
- package/lib/docker-jobs.js +1 -0
- package/lib/docker-report.d.ts +99 -0
- package/lib/docker-report.js +2 -0
- package/lib/docker-runs.d.ts +300 -0
- package/lib/docker-runs.js +3 -0
- package/lib/expected-failure.d.ts +251 -0
- package/lib/expected-failure.js +2 -0
- package/lib/host-agents.d.ts +139 -0
- package/lib/host-agents.js +1 -0
- package/lib/hosts.d.ts +206 -0
- package/lib/hosts.js +1 -0
- package/lib/main-mirror.d.ts +117 -0
- package/lib/main-mirror.js +1 -0
- package/lib/peers.d.ts +1881 -0
- package/lib/peers.js +1 -0
- package/lib/proof.d.ts +32 -0
- package/lib/remote-instances.d.ts +129 -0
- package/lib/remote-instances.js +1 -0
- package/lib/resources.d.ts +2 -0
- package/lib/resources.js +1 -1
- package/lib/static-checks.d.ts +290 -0
- package/lib/static-checks.js +1 -0
- package/lib/team-delivery.d.ts +13 -0
- package/lib/team.d.ts +60 -2
- package/lib/workspace-actions.d.ts +104 -1
- package/lib/workspace-actions.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import type { BaseEvent } from './event.js';
|
|
2
|
+
/**
|
|
3
|
+
* A standing rule that says «in these flows, this failure is expected» (issues/open/overseer-86).
|
|
4
|
+
*
|
|
5
|
+
* A dismissal (error-dismissal.ts) covers the past: «I have seen this one». Some failures are expected every time —
|
|
6
|
+
* a signed-out browser asking for a session token, a budget gate refusing a model call, one stranded test business
|
|
7
|
+
* retrying until its deadline — and a person or an agent had to recognise each occurrence again. A rule holds the
|
|
8
|
+
* occurrences it matches back from the error lists and from «is anything broken», and counts them.
|
|
9
|
+
*
|
|
10
|
+
* Where a rule comes from:
|
|
11
|
+
* - RUN TIME — a person in the dashboard, a person at the CLI, an agent through `observe_expect_errors`. An EVENT ON THE
|
|
12
|
+
* BUS, for the reason a dismissal is one: every lens process folds the same file in the same order, and a restart
|
|
13
|
+
* replays it. Undone the same way (`expected-rule-removed`). It needs a reason, and it ends: 7 days unless said,
|
|
14
|
+
* never more than 30.
|
|
15
|
+
* - THE REPOSITORY — `lensmcp.json` → `config.expectedFailures`, committed: the failures expected in this product for
|
|
16
|
+
* good. Every checkout and every agent starts with them; undone by editing the file.
|
|
17
|
+
*
|
|
18
|
+
* What keeps it from becoming a way to stop seeing failures:
|
|
19
|
+
* - **Never broad.** A rule needs a flow scope (`route`, `span` or `flow`) AND an outcome (`status`, `error` or
|
|
20
|
+
* `message`). «Everything in engine» is refused (`checkExpectedMatch`).
|
|
21
|
+
* - **Never silent.** Whatever list held something back says how many occurrences and how many rules
|
|
22
|
+
* (`heldBackLine`); the rules are listed with reason, author, last hit and hit count; held occurrences stay readable.
|
|
23
|
+
* - **It ends.** A run-time rule past its expiry holds nothing back.
|
|
24
|
+
* - **A change in rate is said.** A rule that suddenly matches far more than it usually does is reported
|
|
25
|
+
* (`ExpectedRuleBook.surging`).
|
|
26
|
+
*/
|
|
27
|
+
export declare const EXPECTED_RULE_SET = "expected-rule-set";
|
|
28
|
+
export declare const EXPECTED_RULE_REMOVED = "expected-rule-removed";
|
|
29
|
+
/** Who wrote a rule: a person in the dashboard, a person at the CLI, an agent, or the repository's `lensmcp.json`. */
|
|
30
|
+
export type ExpectedRuleAuthor = 'dashboard' | 'cli' | 'agent' | 'repository';
|
|
31
|
+
/** A run-time rule's life when its writer names none. */
|
|
32
|
+
export declare const EXPECTED_RULE_DEFAULT_TTL_MS: number;
|
|
33
|
+
/** The longest a run-time rule may live: past it, a rule belongs in the repository. */
|
|
34
|
+
export declare const EXPECTED_RULE_MAX_TTL_MS: number;
|
|
35
|
+
export declare const EXPECTED_RULE_MIN_REASON_CHARS = 8;
|
|
36
|
+
export declare const MAX_EXPECTED_REASON_CHARS = 500;
|
|
37
|
+
/**
|
|
38
|
+
* What a rule matches on. Patterns are case-insensitive globs (`*` any run, `?` one character), whole-text except
|
|
39
|
+
* `message`, which may occur anywhere in the message. A `flow` ending in `:` is a kind (`api:`, `job:`).
|
|
40
|
+
*/
|
|
41
|
+
export interface ExpectedFailureMatch {
|
|
42
|
+
/** The service (Nx project) — narrows; not a scope by itself. */
|
|
43
|
+
service?: string;
|
|
44
|
+
/** `GET /session/token`, or a path alone (`/session/token`). */
|
|
45
|
+
route?: string;
|
|
46
|
+
/** A traced call's name: `SessionTokenService.tokenForSession`. */
|
|
47
|
+
span?: string;
|
|
48
|
+
/** The flow's id or kind: `job:product-analysis-*`, `api:`. A job also answers to `job:<queue>` and `job:<job id>`. */
|
|
49
|
+
flow?: string;
|
|
50
|
+
/** The HTTP status the request answered. */
|
|
51
|
+
status?: number;
|
|
52
|
+
/** An error key or class: `supervisor.preparationBudgetUnavailable`, `DelayedError`. */
|
|
53
|
+
error?: string;
|
|
54
|
+
/** A pattern the message contains. */
|
|
55
|
+
message?: string;
|
|
56
|
+
/** One attribute of the flow — a tenant id. Looked up on the failure and on the other events of its flow. */
|
|
57
|
+
attribute?: {
|
|
58
|
+
name: string;
|
|
59
|
+
value: string;
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
export interface ExpectedFailureRule {
|
|
63
|
+
id: string;
|
|
64
|
+
match: ExpectedFailureMatch;
|
|
65
|
+
/** Why it is expected here, in the writer's words. */
|
|
66
|
+
reason: string;
|
|
67
|
+
by: ExpectedRuleAuthor;
|
|
68
|
+
createdAt: number;
|
|
69
|
+
/** Absent only on a repository rule, which lasts while the file says it. */
|
|
70
|
+
expiresAt?: number;
|
|
71
|
+
/** What it was made from, for a list that no longer holds the failure. */
|
|
72
|
+
title?: string;
|
|
73
|
+
}
|
|
74
|
+
export interface ExpectedRuleRemoval {
|
|
75
|
+
kind: typeof EXPECTED_RULE_REMOVED;
|
|
76
|
+
id: string;
|
|
77
|
+
by?: Exclude<ExpectedRuleAuthor, 'repository'>;
|
|
78
|
+
}
|
|
79
|
+
export type ExpectedRuleChange = ({
|
|
80
|
+
kind: typeof EXPECTED_RULE_SET;
|
|
81
|
+
} & ExpectedFailureRule) | ExpectedRuleRemoval;
|
|
82
|
+
/** The fields that make a flow scope, and those that make an outcome. */
|
|
83
|
+
export declare const EXPECTED_SCOPE_FIELDS: readonly ["route", "span", "flow"];
|
|
84
|
+
export declare const EXPECTED_OUTCOME_FIELDS: readonly ["status", "error", "message"];
|
|
85
|
+
/**
|
|
86
|
+
* A match as written by anyone — a tool's input, a bus event, a line of `lensmcp.json` — checked and normalised, or why
|
|
87
|
+
* it is refused. Refused when it is not narrow: no flow scope, or no outcome.
|
|
88
|
+
*/
|
|
89
|
+
export declare function checkExpectedMatch(input: unknown): {
|
|
90
|
+
match: ExpectedFailureMatch;
|
|
91
|
+
} | {
|
|
92
|
+
error: string;
|
|
93
|
+
};
|
|
94
|
+
/** A rule's match in a line: `auth · GET /session/token · 401`. */
|
|
95
|
+
export declare function describeExpectedMatch(m: ExpectedFailureMatch): string;
|
|
96
|
+
/**
|
|
97
|
+
* Read a rule or its removal out of a bus event, or nothing. Total: the bus is a file any local process appends to.
|
|
98
|
+
* Its `createdAt` is the event's timestamp at the latest, and its life at most `EXPECTED_RULE_MAX_TTL_MS` from then: no
|
|
99
|
+
* event can make a rule ahead, or one that never ends. A rule that is not narrow is not one.
|
|
100
|
+
*/
|
|
101
|
+
export declare function readExpectedRule(event: Pick<BaseEvent, 'source' | 'timestamp' | 'raw'>): ExpectedRuleChange | undefined;
|
|
102
|
+
/** A rule's life in ms from the hours a writer asked for: the default when none, never past the maximum. */
|
|
103
|
+
export declare function expectedRuleTtlMs(hours: number | undefined): number;
|
|
104
|
+
/**
|
|
105
|
+
* `lensmcp.json` → `config.expectedFailures`: each entry the match's fields (or a `match` object), a `reason`, and an
|
|
106
|
+
* optional `id`. A wrong entry is dropped by itself and named; the rest still count.
|
|
107
|
+
*/
|
|
108
|
+
export declare function readRepositoryExpectedRules(raw: unknown, createdAt: number): {
|
|
109
|
+
rules: ExpectedFailureRule[];
|
|
110
|
+
problems: string[];
|
|
111
|
+
};
|
|
112
|
+
/** What a rule can be matched against, read off a failure and what the lens knows of its request and its flow. */
|
|
113
|
+
export interface FailureFacts {
|
|
114
|
+
service?: string;
|
|
115
|
+
method?: string;
|
|
116
|
+
/** The route pattern and the path it was called on, as far as known. */
|
|
117
|
+
routes?: string[];
|
|
118
|
+
span?: string;
|
|
119
|
+
flowId?: string;
|
|
120
|
+
/** Other names its flow answers to: a job's `job:<queue>`, `job:<job id>`. */
|
|
121
|
+
flowNames?: string[];
|
|
122
|
+
status?: number;
|
|
123
|
+
errorName?: string;
|
|
124
|
+
/** An error's own key fields (`errorKey`, `reason`), when it carries them. */
|
|
125
|
+
errorKeys?: string[];
|
|
126
|
+
message?: string;
|
|
127
|
+
attributes?: Record<string, string>;
|
|
128
|
+
requestId?: string;
|
|
129
|
+
}
|
|
130
|
+
/** The attributes an event states: string context fields, and `attributes` / a span's `attributes` and captured arguments / a job's `data`, one level deep. */
|
|
131
|
+
export declare function eventAttributes(e: Pick<BaseEvent, 'context' | 'raw'>): Record<string, string> | undefined;
|
|
132
|
+
/** What a failure event says of itself. `enrich` adds its request's and its flow's. */
|
|
133
|
+
export declare function failureFacts(e: Pick<BaseEvent, 'context' | 'raw' | 'message' | 'title'>): FailureFacts;
|
|
134
|
+
/** What the lens learned of one request from its own reports: the service's answer, the gateway's hop. */
|
|
135
|
+
export interface RequestFacts {
|
|
136
|
+
service?: string;
|
|
137
|
+
method?: string;
|
|
138
|
+
route?: string;
|
|
139
|
+
path?: string;
|
|
140
|
+
status?: number;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* What a failure's request and flow said elsewhere, kept so a rule can be matched against them: a span that threw does
|
|
144
|
+
* not say the route or the status its request answered (the request's own report does, a moment later), and a tenant
|
|
145
|
+
* id is stated on one event of a flow, not every one. Bounded; cheap per event.
|
|
146
|
+
*/
|
|
147
|
+
export declare class FailureContextIndex {
|
|
148
|
+
private readonly maxRequests;
|
|
149
|
+
private readonly maxFlows;
|
|
150
|
+
private readonly requests;
|
|
151
|
+
private readonly flows;
|
|
152
|
+
constructor(maxRequests?: number, maxFlows?: number);
|
|
153
|
+
/** Learn from one bus event. Returns the request id whose answer it reported, if it did. */
|
|
154
|
+
observe(e: Pick<BaseEvent, 'source' | 'context' | 'raw'>): string | undefined;
|
|
155
|
+
request(requestId: string | undefined): RequestFacts | undefined;
|
|
156
|
+
/** The facts with what the request and the flow said added where the failure itself was silent. */
|
|
157
|
+
enrich(f: FailureFacts): FailureFacts;
|
|
158
|
+
}
|
|
159
|
+
/** Does this failure match the rule's every field? */
|
|
160
|
+
export declare function expectedMatches(m: ExpectedFailureMatch, f: FailureFacts): boolean;
|
|
161
|
+
/**
|
|
162
|
+
* Does the rule's verdict on an occurrence depend on more than what every occurrence of one error group shares? A flow,
|
|
163
|
+
* an attribute — and a message pattern with a number in it, since a group's messages differ in their numbers.
|
|
164
|
+
*/
|
|
165
|
+
export declare function expectedMatchIsPerOccurrence(m: ExpectedFailureMatch): boolean;
|
|
166
|
+
/**
|
|
167
|
+
* A narrow match for «always expect this here», from one occurrence's facts: its service, its route (else its span,
|
|
168
|
+
* else its flow's kind) and its status (else its error's class, else its message with the numbers left open).
|
|
169
|
+
*/
|
|
170
|
+
export declare function suggestExpectedMatch(f: FailureFacts): ExpectedFailureMatch | undefined;
|
|
171
|
+
/** A rule that ended: removed by someone, or past its date. */
|
|
172
|
+
export interface EndedExpectedRule extends ExpectedFailureRule {
|
|
173
|
+
endedAt: number;
|
|
174
|
+
why: 'removed' | 'expired' | 'dropped from lensmcp.json';
|
|
175
|
+
removedBy?: ExpectedRuleRemoval['by'];
|
|
176
|
+
}
|
|
177
|
+
/** A rule as a list shows it: what it is, and what it has done. */
|
|
178
|
+
export interface ExpectedRuleView extends ExpectedFailureRule {
|
|
179
|
+
/** Occurrences it held back since this process started. */
|
|
180
|
+
hits: number;
|
|
181
|
+
lastHitAt?: number;
|
|
182
|
+
/** Of them, in the hour before the reading. */
|
|
183
|
+
lastHour: number;
|
|
184
|
+
/** Set while it matches far more than its usual rate — said once, as a warning. */
|
|
185
|
+
surge?: ExpectedSurge;
|
|
186
|
+
}
|
|
187
|
+
export interface ExpectedSurge {
|
|
188
|
+
since: number;
|
|
189
|
+
lastHour: number;
|
|
190
|
+
/** Its usual hourly rate over the day before the last hour. */
|
|
191
|
+
usualPerHour: number;
|
|
192
|
+
}
|
|
193
|
+
/** How much more than usual is a surge, from how many an hour, after how much history. */
|
|
194
|
+
export declare const EXPECTED_SURGE_FACTOR = 10;
|
|
195
|
+
export declare const EXPECTED_SURGE_MIN_PER_HOUR = 20;
|
|
196
|
+
/**
|
|
197
|
+
* The rules one process holds — the repository's and the bus's — and what each has held back. Pure; the clock is
|
|
198
|
+
* passed in. A reader (the runtime reducer, the dashboard's error log) asks it which rule holds a failure, tells it
|
|
199
|
+
* what was held, and lists it.
|
|
200
|
+
*/
|
|
201
|
+
export declare class ExpectedRuleBook {
|
|
202
|
+
private readonly startedAt;
|
|
203
|
+
private readonly runtime;
|
|
204
|
+
private repository;
|
|
205
|
+
private repositoryKey;
|
|
206
|
+
private readonly stats;
|
|
207
|
+
private readonly ended;
|
|
208
|
+
/** Bumped whenever the rules in effect change — what a holder re-reads its held occurrences on. */
|
|
209
|
+
version: number;
|
|
210
|
+
constructor(startedAt?: number);
|
|
211
|
+
/** Fold a bus event. True when it was a rule or a removal. */
|
|
212
|
+
apply(e: Pick<BaseEvent, 'source' | 'timestamp' | 'raw'>, now: number): boolean;
|
|
213
|
+
/** Replace the repository's rules. True when they changed. */
|
|
214
|
+
setRepository(rules: readonly ExpectedFailureRule[], now: number): boolean;
|
|
215
|
+
/** End the run-time rules past their date. True when one ended. */
|
|
216
|
+
expire(now: number): boolean;
|
|
217
|
+
private end;
|
|
218
|
+
/** The rules in effect at `now`: the repository's first, then the run-time ones oldest first. */
|
|
219
|
+
active(now: number): ExpectedFailureRule[];
|
|
220
|
+
get(id: string): ExpectedFailureRule | undefined;
|
|
221
|
+
isActive(id: string, now: number): boolean;
|
|
222
|
+
get size(): number;
|
|
223
|
+
/** The first rule in effect that holds this failure. */
|
|
224
|
+
holderOf(f: FailureFacts, now: number): ExpectedFailureRule | undefined;
|
|
225
|
+
/** Count `n` occurrences held by a rule, at `at` (undefined: their times are not known, the total only). */
|
|
226
|
+
count(id: string, at: number | undefined, n?: number): void;
|
|
227
|
+
/** Occurrences in the minutes that start in [from, to). */
|
|
228
|
+
private windowCount;
|
|
229
|
+
/** Re-judge a rule's rate: a surge starts at 10× its usual hourly rate (and 20 at least), ends below a third of that. */
|
|
230
|
+
private judge;
|
|
231
|
+
/** The rules in effect, each with what it has held — newest first, the repository's last. */
|
|
232
|
+
list(now: number): ExpectedRuleView[];
|
|
233
|
+
/** The rules that ended lately, newest first. */
|
|
234
|
+
endedRules(): EndedExpectedRule[];
|
|
235
|
+
}
|
|
236
|
+
/** «2 rules held back 61 occurrences in the last hour» — what every list and status that held something back says. */
|
|
237
|
+
export declare function heldBackLine(rules: number, occurrences: number, window?: string): string;
|
|
238
|
+
/** «this expected failure is now happening much more often» — said once per surge. */
|
|
239
|
+
export declare function surgeLine(r: Pick<ExpectedRuleView, 'match' | 'reason' | 'surge'>): string;
|
|
240
|
+
/** `POST /api/errors/expect` — a rule from a row («always expect this here»), or a match written out. */
|
|
241
|
+
export interface DashExpectBody {
|
|
242
|
+
groupId?: string;
|
|
243
|
+
causeId?: string;
|
|
244
|
+
match?: ExpectedFailureMatch;
|
|
245
|
+
reason: string;
|
|
246
|
+
hours?: number;
|
|
247
|
+
}
|
|
248
|
+
/** `POST /api/errors/unexpect` — the run-time rules to remove, by id. */
|
|
249
|
+
export interface DashUnexpectBody {
|
|
250
|
+
ids: string[];
|
|
251
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var K=Object.defineProperty;var h=(t,e)=>K(t,"name",{value:e,configurable:!0});var W=Object.defineProperty,l=h((t,e)=>W(t,"name",{value:e,configurable:!0}),"h"),G=Object.defineProperty,c=l((t,e)=>G(t,"name",{value:e,configurable:!0}),"d");import{LENS_EVENT_SOURCE as J}from"./error-dismissal.js";export const EXPECTED_RULE_SET="expected-rule-set",EXPECTED_RULE_REMOVED="expected-rule-removed";const L=new Set(["dashboard","cli","agent"]),f=60*6e4;export const EXPECTED_RULE_DEFAULT_TTL_MS=168*f,EXPECTED_RULE_MAX_TTL_MS=720*f,EXPECTED_RULE_MIN_REASON_CHARS=8,MAX_EXPECTED_REASON_CHARS=500;const $=300,V=300,D=120,Z=200,U=20,p=c(t=>!!t&&typeof t=="object"&&!Array.isArray(t),"isObj"),x=c((t,e)=>typeof t=="string"&&t.trim()?t.trim().slice(0,e):void 0,"text"),_=c(t=>!!t&&t.replace(/[*?\s/:.#_-]/g,"").length>=2,"meaningful");export const EXPECTED_SCOPE_FIELDS=["route","span","flow"],EXPECTED_OUTCOME_FIELDS=["status","error","message"];export function checkExpectedMatch(t){if(!p(t))return{error:"a rule needs a match: a flow scope (route, span or flow) and an outcome (status, error or message)"};const e={};for(const r of["service","route","span","flow","error","message"]){const o=t[r];if(o==null||o==="")continue;if(typeof o!="string")return{error:`\`${r}\` must be text`};const i=o.trim();if(i.length>$)return{error:`\`${r}\` is longer than ${$} characters`};i&&(e[r]=i)}if(t.status!==void 0&&t.status!==null&&t.status!==""){const r=typeof t.status=="string"?Number(t.status):t.status;if(typeof r!="number"||!Number.isInteger(r)||r<100||r>599)return{error:"`status` must be an HTTP status (100\u2013599)"};e.status=r}const s=t.attribute;if(s!=null){const r=p(s)?x(s.name,100):void 0,o=p(s)?typeof s.value=="number"?String(s.value):x(s.value,$):void 0;if(!r||!o)return{error:"`attribute` needs a `name` and a `value` (one attribute of the flow, such as a tenant id)"};e.attribute={name:r,value:o}}return EXPECTED_SCOPE_FIELDS.some(r=>_(e[r]))?e.status===void 0&&!_(e.error)&&!_(e.message)?{error:"a rule needs an outcome \u2014 a `status`, an `error` key or a `message` pattern \u2014 saying WHICH failure is expected in that flow"}:{match:e}:{error:`a rule needs a flow scope \u2014 a \`route\`, a \`span\` or a \`flow\` \u2014 not only ${e.service?`the service \xAB${e.service}\xBB`:"an outcome"}: \xABeverything in a service\xBB is not expected, it is unwatched`}}h(checkExpectedMatch,"checkExpectedMatch"),l(checkExpectedMatch,"checkExpectedMatch"),c(checkExpectedMatch,"checkExpectedMatch");export function describeExpectedMatch(t){return[t.service,t.route,t.span,t.flow?`flow ${t.flow}`:void 0,t.status!==void 0?String(t.status):void 0,t.error,t.message?`\xAB${t.message}\xBB`:void 0,t.attribute?`${t.attribute.name}=${t.attribute.value}`:void 0].filter(Boolean).join(" \xB7 ")}h(describeExpectedMatch,"describeExpectedMatch"),l(describeExpectedMatch,"describeExpectedMatch"),c(describeExpectedMatch,"describeExpectedMatch");export function readExpectedRule(t){if(t.source!==J||!p(t.raw))return;const e=t.raw,s=x(e.id,D);if(!s)return;if(e.kind===EXPECTED_RULE_REMOVED)return{kind:EXPECTED_RULE_REMOVED,id:s,...L.has(e.by)?{by:e.by}:{}};if(e.kind!==EXPECTED_RULE_SET||!L.has(e.by))return;const r=x(e.reason,MAX_EXPECTED_REASON_CHARS);if(!r)return;const o=checkExpectedMatch(e.match);if("error"in o)return;const i=Math.min(typeof e.createdAt=="number"&&Number.isFinite(e.createdAt)?e.createdAt:t.timestamp,t.timestamp),u=typeof e.expiresAt=="number"&&Number.isFinite(e.expiresAt)?e.expiresAt:i+EXPECTED_RULE_DEFAULT_TTL_MS,a=x(e.title,V);return{kind:EXPECTED_RULE_SET,id:s,match:o.match,reason:r,by:e.by,createdAt:i,expiresAt:Math.min(u,i+EXPECTED_RULE_MAX_TTL_MS),...a?{title:a}:{}}}h(readExpectedRule,"readExpectedRule"),l(readExpectedRule,"readExpectedRule"),c(readExpectedRule,"readExpectedRule");export function expectedRuleTtlMs(t){return t===void 0||!Number.isFinite(t)||t<=0?EXPECTED_RULE_DEFAULT_TTL_MS:Math.min(Math.round(t*f),EXPECTED_RULE_MAX_TTL_MS)}h(expectedRuleTtlMs,"expectedRuleTtlMs"),l(expectedRuleTtlMs,"expectedRuleTtlMs"),c(expectedRuleTtlMs,"expectedRuleTtlMs");function j(t){let e=2166136261;for(let s=0;s<t.length;s++)e=Math.imul(e^t.charCodeAt(s),16777619);return(e>>>0).toString(36)}h(j,"F"),l(j,"z"),c(j,"hashOf");export function readRepositoryExpectedRules(t,e){const s=[],r=[];return t==null?{rules:s,problems:r}:Array.isArray(t)?(t.forEach((o,i)=>{if(!p(o))return void r.push(`expectedFailures[${i}] is not an object`);const u=checkExpectedMatch(p(o.match)?o.match:o);if("error"in u)return void r.push(`expectedFailures[${i}]: ${u.error}`);const a=x(o.reason,MAX_EXPECTED_REASON_CHARS);if(!a)return void r.push(`expectedFailures[${i}] has no reason \u2014 say why it is expected`);const d=`repository:${x(o.id,D)??j(JSON.stringify(u.match))}`;if(s.some(m=>m.id===d))return void r.push(`expectedFailures[${i}] repeats the id ${d}`);s.push({id:d,match:u.match,reason:a,by:"repository",createdAt:e})}),{rules:s,problems:r}):{rules:s,problems:["expectedFailures is not a list \u2014 no repository rule is read"]}}h(readRepositoryExpectedRules,"readRepositoryExpectedRules"),l(readRepositoryExpectedRules,"readRepositoryExpectedRules"),c(readRepositoryExpectedRules,"readRepositoryExpectedRules");const n=c(t=>typeof t=="string"&&t?t:void 0,"str"),I=c(t=>typeof t=="number"&&Number.isFinite(t)?t:void 0,"num"),z=c(t=>{const e=t.split(/[?#]/)[0]??t,s=/^[a-z][a-z0-9+.-]*:\/\/[^/]+(\/.*)?$/i.exec(e);return s?s[1]??"/":e},"pathOf"),Q=new Set(["sessionId","flowId","requestId","parentRequestId","runId","traceparent","originNodeId","causedByNodeId","userActionId","browserContextId","frameId","tabId","url","route","projectName"]),S=24;export function eventAttributes(t){let e;const s=c((a,d)=>{if(e&&Object.keys(e).length>=S)return;const m=typeof d=="string"?d:typeof d=="number"||typeof d=="boolean"?String(d):void 0;m===void 0||m.length>$||((e??={})[a]=m)},"put"),r=t.context??{};for(const a of Object.keys(r))Q.has(a)||s(a,r[a]);const o=p(t.raw)?t.raw:void 0;if(!o)return e;const i=p(o.span)?o.span:void 0,u=p(o.request)?o.request:void 0;for(const a of[o.attributes,i?.attributes,u?.attributes,o.data,Array.isArray(i?.args)?i?.args[0]:i?.args])if(p(a))for(const d of Object.keys(a))s(d,a[d]);return e}h(eventAttributes,"eventAttributes"),l(eventAttributes,"eventAttributes"),c(eventAttributes,"eventAttributes");export function failureFacts(t){const e=p(t.raw)?t.raw:{},s=t.context??{},r=p(e.request)?e.request:{},o=p(e.span)?e.span:{},i=p(r.error)?r.error:{},u=p(o.error)?o.error:{},a=p(e.error)?e.error:{},d=n(e.kind),m=[],A=n(r.route)??(d==="egress"?n(e.path):void 0);A&&m.push(A);const y=n(e.url)??n(r.url);y&&m.push(z(y)),d!=="server-request"&&n(s.route)&&m.push(n(s.route));const v=[];if(d==="queue-failed"||d==="queue-enqueued"){const w=n(e.queue),M=e.jobId===void 0||e.jobId===null?void 0:String(e.jobId);w&&v.push(`job:${w}`),M&&v.push(`job:${M}`),w&&M&&v.push(`job:${w}#${M}`),n(e.name)&&v.push(`job:${n(e.name)}`)}const b=[i.errorKey,u.errorKey,a.errorKey,e.errorKey,i.reason,u.reason].map(n).filter(w=>!!w),k=n(i.message)??n(t.message)??n(u.message)??n(a.message)??n(e.failedReason)??n(e.error)??n(e.message)??n(t.title),P=I(r.status)??I(e.status),B=n(s.flowId)??n(o.flowId)??n(r.flowId),F=n(s.requestId)??n(r.requestId)??n(o.requestId),H=eventAttributes(t);return{...n(e.project)??n(s.projectName)?{service:n(e.project)??n(s.projectName)}:{},...n(r.method)??n(e.method)?{method:n(r.method)??n(e.method)}:{},...m.length?{routes:m}:{},...n(o.name)?{span:n(o.name)}:{},...B?{flowId:B}:{},...v.length?{flowNames:v}:{},...P!==void 0?{status:P}:{},...n(i.name)??n(u.name)??n(a.name)?{errorName:n(i.name)??n(u.name)??n(a.name)}:{},...b.length?{errorKeys:b}:{},...k?{message:k}:{},...H?{attributes:H}:{},...F?{requestId:F}:{}}}h(failureFacts,"failureFacts"),l(failureFacts,"failureFacts"),c(failureFacts,"failureFacts");export class FailureContextIndex{static{h(this,"FailureContextIndex")}static{l(this,"FailureContextIndex")}static{c(this,"FailureContextIndex")}constructor(e=5e3,s=2e3){this.maxRequests=e,this.maxFlows=s,this.requests=new Map,this.flows=new Map}observe(e){const s=p(e.raw)?e.raw:void 0,r=e.context??{},o=n(r.flowId);if(o&&(s?.attributes!==void 0||p(s?.span)||r.tenantIdHash!==void 0||r.userIdHash!==void 0||s?.data!==void 0)){const y=eventAttributes(e);if(y){const v=this.flows.get(o);this.flows.delete(o);const b={...v??{},...y};this.flows.set(o,Object.keys(b).length>S?Object.fromEntries(Object.entries(b).slice(-S)):b),this.flows.size>this.maxFlows&&this.flows.delete(this.flows.keys().next().value)}}const i=n(s?.kind);if(!s||i!=="server-request"&&i!=="gateway-request")return;const u=p(s.request)?s.request:s,a=n(r.requestId)??n(u.requestId);if(!a)return;const d=this.requests.get(a)??{},m=n(u.url),A={...d,...n(s.project)&&(i==="server-request"||!d.service)?{service:n(s.project)}:{},...n(u.method)?{method:n(u.method)}:{},...i==="server-request"&&n(u.route)?{route:n(u.route)}:{},...m?{path:z(m)}:{},...I(u.status)!==void 0&&(i==="server-request"||d.status===void 0)?{status:I(u.status)}:{}};return this.requests.delete(a),this.requests.set(a,A),this.requests.size>this.maxRequests&&this.requests.delete(this.requests.keys().next().value),i==="server-request"?a:void 0}request(e){return e?this.requests.get(e):void 0}enrich(e){const s=this.request(e.requestId),r=e.flowId?this.flows.get(e.flowId):void 0;if(!s&&!r)return e;const o=[...e.routes??[],...s?.route?[s.route]:[],...s?.path?[s.path]:[]];return{...e,...e.service??s?.service?{service:e.service??s?.service}:{},...e.method??s?.method?{method:e.method??s?.method}:{},...o.length?{routes:[...new Set(o)]}:{},...e.status??s?.status!==void 0?{status:e.status??s?.status}:{},...r||e.attributes?{attributes:{...r??{},...e.attributes??{}}}:{}}}}const R=new Map,C=c((t,e)=>t.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,e).replace(/\?/g,"."),"globBody");function E(t,e="whole"){const s=`${e}\0${t}`;let r=R.get(s);return r||(r=e==="whole"?new RegExp(`^${C(t,"[\\s\\S]*")}$`,"i"):e==="anywhere"?new RegExp(C(t,"[\\s\\S]*"),"i"):new RegExp(`(?:^|[^\\w.])${C(t,"[\\w.]*")}(?:$|[^\\w.])`,"i"),R.size>1e3&&R.clear(),R.set(s,r)),r}h(E,"M"),l(E,"S"),c(E,"globRe");const g=c((t,e)=>e!==void 0&&E(t).test(e),"glob");function T(t,e){const s=e.routes??[],r=/^([A-Za-z]+)\s+(\S.*)$/.exec(t);return r&&/^(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS|\*)$/i.test(r[1])?r[1]!=="*"&&(e.method??"").toUpperCase()!==r[1].toUpperCase()?!1:s.some(o=>g(r[2],o)):s.some(o=>g(t,o))}h(T,"D"),l(T,"B"),c(T,"routeMatches");function O(t,e){const s=[e.flowId,...e.flowNames??[]].filter(o=>!!o),r=t.endsWith(":")?`${t}*`:t;return s.some(o=>g(r,o))}h(O,"L"),l(O,"G"),c(O,"flowMatches");function N(t,e){return g(t,e.errorName)||(e.errorKeys??[]).some(s=>g(t,s))?!0:e.message!==void 0&&E(t,"word").test(e.message)}h(N,"U"),l(N,"W"),c(N,"errorMatches");export function expectedMatches(t,e){return!(t.service!==void 0&&!g(t.service,e.service)||t.route!==void 0&&!T(t.route,e)||t.span!==void 0&&!g(t.span,e.span)||t.flow!==void 0&&!O(t.flow,e)||t.status!==void 0&&e.status!==t.status||t.error!==void 0&&!N(t.error,e)||t.message!==void 0&&!(e.message!==void 0&&E(t.message,"anywhere").test(e.message))||t.attribute!==void 0&&!g(t.attribute.value,e.attributes?.[t.attribute.name]))}h(expectedMatches,"expectedMatches"),l(expectedMatches,"expectedMatches"),c(expectedMatches,"expectedMatches");export function expectedMatchIsPerOccurrence(t){return t.flow!==void 0||t.attribute!==void 0||t.message!==void 0&&/\d/.test(t.message)}h(expectedMatchIsPerOccurrence,"expectedMatchIsPerOccurrence"),l(expectedMatchIsPerOccurrence,"expectedMatchIsPerOccurrence"),c(expectedMatchIsPerOccurrence,"expectedMatchIsPerOccurrence");export function suggestExpectedMatch(t){const e=t.routes?.find(a=>a.startsWith("/")),s=t.flowNames?.find(a=>a.startsWith("job:")&&!a.includes("#"))??(t.flowId?`${t.flowId.split(":")[0]}:`:void 0),r=e?{route:t.method?`${t.method.toUpperCase()} ${e}`:e}:t.span?{span:t.span}:s?{flow:s}:{},o=t.message?.split(`
|
|
2
|
+
`)[0]?.replace(/\d+/g,"*").replace(/\*+/g,"*").slice(0,120).trim(),i=t.status!==void 0?{status:t.status}:t.errorName&&t.errorName!=="Error"?{error:t.errorName}:o?{message:o}:{},u=checkExpectedMatch({...t.service?{service:t.service}:{},...r,...i});return"match"in u?u.match:void 0}h(suggestExpectedMatch,"suggestExpectedMatch"),l(suggestExpectedMatch,"suggestExpectedMatch"),c(suggestExpectedMatch,"suggestExpectedMatch");export const EXPECTED_SURGE_FACTOR=10,EXPECTED_SURGE_MIN_PER_HOUR=20;const Y=2*f,X=24*f,q=6e4;export class ExpectedRuleBook{static{h(this,"ExpectedRuleBook")}static{l(this,"ExpectedRuleBook")}static{c(this,"ExpectedRuleBook")}constructor(e=Date.now()){this.startedAt=e,this.runtime=new Map,this.repository=[],this.repositoryKey="",this.stats=new Map,this.ended=[],this.version=0}apply(e,s){const r=readExpectedRule(e);if(!r)return!1;const o=this.runtime.get(r.id);if(this.runtime.delete(r.id),r.kind===EXPECTED_RULE_REMOVED)o&&this.end(o,s,"removed",r.by);else{const{kind:i,...u}=r;if(this.runtime.set(u.id,u),this.stats.has(u.id)||this.stats.set(u.id,{hits:0,minutes:new Map,since:Math.max(u.createdAt,this.startedAt)}),this.runtime.size>Z){const a=this.runtime.keys().next().value,d=this.runtime.get(a);this.runtime.delete(a),this.end(d,s,"expired")}}return this.version++,!0}setRepository(e,s){const r=JSON.stringify(e.map(i=>[i.id,i.match,i.reason]));if(r===this.repositoryKey)return!1;const o=new Set(e.map(i=>i.id));for(const i of this.repository)o.has(i.id)||this.end(i,s,"dropped from lensmcp.json");this.repository=e.slice(),this.repositoryKey=r;for(const i of e)this.stats.has(i.id)||this.stats.set(i.id,{hits:0,minutes:new Map,since:Math.max(this.startedAt,Math.min(i.createdAt,s))});return this.version++,!0}expire(e){let s=!1;for(const[r,o]of this.runtime)o.expiresAt===void 0||o.expiresAt>e||(this.runtime.delete(r),this.end(o,o.expiresAt,"expired"),s=!0);return s&&this.version++,s}end(e,s,r,o){this.ended.unshift({...e,endedAt:s,why:r,...o?{removedBy:o}:{}}),this.ended.length>U&&(this.ended.length=U)}active(e){return[...this.repository,...[...this.runtime.values()].filter(s=>s.expiresAt===void 0||s.expiresAt>e)]}get(e){return this.runtime.get(e)??this.repository.find(s=>s.id===e)}isActive(e,s){const r=this.get(e);return!!r&&(r.expiresAt===void 0||r.expiresAt>s)}get size(){return this.runtime.size+this.repository.length}holderOf(e,s){if(this.size!==0)return this.active(s).find(r=>expectedMatches(r.match,e))}count(e,s,r=1){const o=this.stats.get(e);if(!o||r<=0||(o.hits+=r,s===void 0))return;o.lastHitAt=Math.max(o.lastHitAt??0,s);const i=Math.floor(s/q);if(o.minutes.set(i,(o.minutes.get(i)??0)+r),o.minutes.size>1600){const u=i-(X+f)/q;for(const a of o.minutes.keys())a<u&&o.minutes.delete(a)}}windowCount(e,s,r){let o=0;for(const[i,u]of e.minutes)i*q>=s&&i*q<r&&(o+=u);return o}judge(e,s){const r=this.windowCount(e,s-f,s+1),o=Math.max(e.since,s-f-X),i=s-f-o;if(i<Y)return e.surge=void 0;const u=this.windowCount(e,o,s-f)/(i/f),a=Math.max(EXPECTED_SURGE_MIN_PER_HOUR,EXPECTED_SURGE_FACTOR*u);return e.surge?r<a/3?e.surge=void 0:e.surge={...e.surge,lastHour:r}:r>=a&&(e.surge={since:s,lastHour:r,usualPerHour:Math.round(u*10)/10}),e.surge}list(e){return this.active(e).map(s=>{const r=this.stats.get(s.id),o=r?this.judge(r,e):void 0;return{...s,hits:r?.hits??0,...r?.lastHitAt!==void 0?{lastHitAt:r.lastHitAt}:{},lastHour:r?this.windowCount(r,e-f,e+1):0,...o?{surge:o}:{}}}).sort((s,r)=>+(s.by==="repository")-+(r.by==="repository")||r.createdAt-s.createdAt)}endedRules(){return this.ended.slice()}}export function heldBackLine(t,e,s=""){return`${t} rule${t===1?"":"s"} held back ${e} occurrence${e===1?"":"s"}${s?` ${s}`:""}`}h(heldBackLine,"heldBackLine"),l(heldBackLine,"heldBackLine"),c(heldBackLine,"heldBackLine");export function surgeLine(t){const e=t.surge;return`this expected failure is now happening much more often: ${describeExpectedMatch(t.match)} \u2014 ${e?`${e.lastHour} in the last hour, usually ${e.usualPerHour} an hour`:"its rate jumped"} (expected because: ${t.reason})`}h(surgeLine,"surgeLine"),l(surgeLine,"surgeLine"),c(surgeLine,"surgeLine");
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ACCOUNTS AND LIMITS PER HOST (planning/docker/00-plan.md § 13 «Accounts and goal power», slice D31;
|
|
3
|
+
* issues/open/overseer-74). Each Mac has its own sign-ins: a worker reports its accounts — id, client, label, whether it
|
|
4
|
+
* is standalone, which one is selected per client, its quota stop and its usage — in its capacity advert (`agents`),
|
|
5
|
+
* and the organizer reads that part field by field before it keeps it, per host. NEVER a token, never the path of a
|
|
6
|
+
* sign-in's folder: the advert names an account by its id and label only, and a part that carries anything shaped like
|
|
7
|
+
* a credential is refused whole.
|
|
8
|
+
*
|
|
9
|
+
* Goal power stays team-wide (planning/team/22): capacity counts agents wherever they run. A host adds its own ceiling —
|
|
10
|
+
* `agents` at once, the person's number, else one from its memory — and the clients it has a sign-in for.
|
|
11
|
+
*
|
|
12
|
+
* ~/.lensmcp/peers/host-agents.json 0600 the organizer's: each worker's agents part as last read, by its peer id
|
|
13
|
+
* ~/.lensmcp/peers/host-ceilings.json 0600 the person's ceilings, by host (`local` or a worker's peer id)
|
|
14
|
+
*
|
|
15
|
+
* Pure, as the rest of this package: the dashboard reads these too.
|
|
16
|
+
*/
|
|
17
|
+
export type HostAgentClient = 'claude' | 'codex';
|
|
18
|
+
export declare const HOST_AGENT_CLIENTS: readonly HostAgentClient[];
|
|
19
|
+
/** The organizer's files for the hosts' accounts and ceilings, under `~/.lensmcp/peers/`. */
|
|
20
|
+
export declare const HOST_AGENTS_FILES: {
|
|
21
|
+
readonly agents: "host-agents.json";
|
|
22
|
+
readonly ceilings: "host-ceilings.json";
|
|
23
|
+
};
|
|
24
|
+
/** What an agents part may hold: more is refused whole, never cut — a Mac with more sign-ins than this is not one the organizer reads. */
|
|
25
|
+
export declare const HOST_AGENTS_LIMITS: {
|
|
26
|
+
readonly accounts: 32;
|
|
27
|
+
readonly windows: 6;
|
|
28
|
+
readonly label: 60;
|
|
29
|
+
readonly why: 300;
|
|
30
|
+
readonly plan: 40;
|
|
31
|
+
readonly name: 40;
|
|
32
|
+
/** The most agents a host's ceiling may say at once. */
|
|
33
|
+
readonly agents: 64;
|
|
34
|
+
};
|
|
35
|
+
/** An account's id (`lensmcp agent accounts`): the storage's `ACCOUNT_ID`. */
|
|
36
|
+
export declare const HOST_ACCOUNT_ID: RegExp;
|
|
37
|
+
/** A quota stop in force on a sign-in (storage client-quota.ts `ClientQuotaStop`, without the launch and repository). */
|
|
38
|
+
export interface HostQuotaStop {
|
|
39
|
+
/** When it was read, and until when no launch runs on it — by the HOST's clock. */
|
|
40
|
+
at: number;
|
|
41
|
+
until: number;
|
|
42
|
+
reset: 'given' | 'assumed' | 'held';
|
|
43
|
+
/** The client's own words. */
|
|
44
|
+
why: string;
|
|
45
|
+
}
|
|
46
|
+
/** What a sign-in has used of its plan (storage account-usage.ts `AccountUsage`), as its host last read it. */
|
|
47
|
+
export interface HostUsage {
|
|
48
|
+
at: number;
|
|
49
|
+
plan?: string;
|
|
50
|
+
windows: Array<{
|
|
51
|
+
name: string;
|
|
52
|
+
usedPercent: number;
|
|
53
|
+
resetsAt?: number;
|
|
54
|
+
minutes?: number;
|
|
55
|
+
}>;
|
|
56
|
+
/** Codex: the limit it says was reached, and whether credits carry work past a full window. */
|
|
57
|
+
reached?: string;
|
|
58
|
+
carried?: true;
|
|
59
|
+
}
|
|
60
|
+
/** One account on a host — what the person and placement need, and nothing that signs in. */
|
|
61
|
+
export interface HostAccount {
|
|
62
|
+
id: string;
|
|
63
|
+
client: HostAgentClient;
|
|
64
|
+
label: string;
|
|
65
|
+
/** Kept for the person's own sessions: no team agent runs on it, on any host. */
|
|
66
|
+
standalone?: true;
|
|
67
|
+
/** The account new launches of its client use on that host. */
|
|
68
|
+
selected?: true;
|
|
69
|
+
quota?: HostQuotaStop;
|
|
70
|
+
usage?: HostUsage;
|
|
71
|
+
}
|
|
72
|
+
/** A client's own sign-in on a host (`~/.claude`, `~/.codex` there): what a launch runs under when no account of the client is selected. */
|
|
73
|
+
export interface HostOwnSignIn {
|
|
74
|
+
client: HostAgentClient;
|
|
75
|
+
quota?: HostQuotaStop;
|
|
76
|
+
usage?: HostUsage;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* The `agents` part of a worker's capacity advert (in `hello` and `capacity`). `at` is the host's clock; `running`: the
|
|
80
|
+
* launched agents running there now (its launch registry, every repository's).
|
|
81
|
+
*/
|
|
82
|
+
export interface HostAgentsAdvert {
|
|
83
|
+
at: number;
|
|
84
|
+
running: number;
|
|
85
|
+
accounts: HostAccount[];
|
|
86
|
+
/** The clients whose own sign-in folder exists there — none: no client is set up there outside its accounts. */
|
|
87
|
+
own: HostOwnSignIn[];
|
|
88
|
+
}
|
|
89
|
+
/** A host's ceiling: the person's number, or one from its memory. */
|
|
90
|
+
export interface HostCeiling {
|
|
91
|
+
agents: number;
|
|
92
|
+
from: 'person' | 'memory';
|
|
93
|
+
/** The whole memory the default was worked out from, MiB — none: not known yet. */
|
|
94
|
+
memoryMb?: number;
|
|
95
|
+
/** When the person set it. */
|
|
96
|
+
setAt?: number;
|
|
97
|
+
}
|
|
98
|
+
/** A host's account as the page shows it: `stopped` — its quota stop holds now. */
|
|
99
|
+
export type HostAccountView = HostAccount & {
|
|
100
|
+
stopped?: true;
|
|
101
|
+
};
|
|
102
|
+
export type HostOwnView = HostOwnSignIn & {
|
|
103
|
+
stopped?: true;
|
|
104
|
+
};
|
|
105
|
+
/** One host's agents, accounts and ceiling, as `GET /api/team/hosts` answers it. */
|
|
106
|
+
export interface HostAgentsView {
|
|
107
|
+
/** `local` — this Mac — or the worker's peer id. */
|
|
108
|
+
id: string;
|
|
109
|
+
name: string;
|
|
110
|
+
local: boolean;
|
|
111
|
+
/** When its accounts were said, by THIS Mac's clock — a worker's: its last advert's. */
|
|
112
|
+
at?: number;
|
|
113
|
+
/** The launched agents running there now, as it last said. */
|
|
114
|
+
running?: number;
|
|
115
|
+
ceiling: HostCeiling;
|
|
116
|
+
/** The clients a goal can run on there: a usable sign-in (the selected account, else the client's own) that is not quota-stopped now. */
|
|
117
|
+
clients: HostAgentClient[];
|
|
118
|
+
accounts: HostAccountView[];
|
|
119
|
+
own: HostOwnView[];
|
|
120
|
+
/** Why its accounts are not known: a worker that has not said them, or said them in a form this Mac does not read. */
|
|
121
|
+
unread?: string;
|
|
122
|
+
}
|
|
123
|
+
/** `GET /api/team/hosts` (and the answer of a ceiling's write). */
|
|
124
|
+
export interface HostAccountsAnswer {
|
|
125
|
+
at: number;
|
|
126
|
+
/** This Mac first, then the paired workers by name. */
|
|
127
|
+
hosts: HostAgentsView[];
|
|
128
|
+
/** The ceiling writes are taken from a dashboard bound to loopback only (Settings › Hosts' rule): false — read only here. */
|
|
129
|
+
writable: boolean;
|
|
130
|
+
}
|
|
131
|
+
/** `POST /api/team/hosts/ceiling`: the person's ceiling for a host — `null`: back to the one from its memory. */
|
|
132
|
+
export interface HostCeilingWrite {
|
|
133
|
+
host: string;
|
|
134
|
+
agents: number | null;
|
|
135
|
+
}
|
|
136
|
+
/** Whether `text` carries something shaped like a credential. */
|
|
137
|
+
export declare function tokenShaped(text: string): boolean;
|
|
138
|
+
/** `text` with every credential-shaped piece replaced by `…` — what a worker says of a client's own words before it sends them. */
|
|
139
|
+
export declare function withoutTokens(text: string): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var c=Object.defineProperty;var o=(t,e)=>c(t,"name",{value:e,configurable:!0});var u=Object.defineProperty,n=o((t,e)=>u(t,"name",{value:e,configurable:!0}),"s"),i=Object.defineProperty,s=n((t,e)=>i(t,"name",{value:e,configurable:!0}),"o");export const HOST_AGENT_CLIENTS=["claude","codex"],HOST_AGENTS_FILES={agents:"host-agents.json",ceilings:"host-ceilings.json"},HOST_AGENTS_LIMITS={accounts:32,windows:6,label:60,why:300,plan:40,name:40,agents:64},HOST_ACCOUNT_ID=/^ac-[a-z0-9]{1,12}-[a-f0-9]{6}$/;const r=[/\bsk-[A-Za-z0-9_-]{16,}/,/\b[rs]k_(?:live|test)_[A-Za-z0-9]{12,}/,/\bgh[pousr]_[A-Za-z0-9]{20,}|\bgithub_pat_[A-Za-z0-9_]{20,}/,/\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/,/\bxox[abposr]-[A-Za-z0-9-]{10,}/,/\bAIza[0-9A-Za-z_-]{30,}/,/\beyJ[A-Za-z0-9_-]{6,}\.[A-Za-z0-9_-]{4,}/,/-----BEGIN [A-Z ]*(?:PRIVATE KEY|CERTIFICATE)-----/,/\bbearer\s+[A-Za-z0-9._~+/=-]{12,}/i],A=/[A-Za-z0-9+/_=-]{32,}/g;export function tokenShaped(t){if(r.some(e=>e.test(t)))return!0;for(const e of t.match(A)??[])if(/\d/.test(e)&&/[A-Za-z]/.test(e))return!0;return!1}o(tokenShaped,"tokenShaped"),n(tokenShaped,"tokenShaped"),s(tokenShaped,"tokenShaped");export function withoutTokens(t){let e=t;for(const a of r)e=e.replace(new RegExp(a.source,a.flags.includes("g")?a.flags:`${a.flags}g`),"\u2026");return e.replace(A,a=>/\d/.test(a)&&/[A-Za-z]/.test(a)?"\u2026":a)}o(withoutTokens,"withoutTokens"),n(withoutTokens,"withoutTokens"),s(withoutTokens,"withoutTokens");
|
package/lib/hosts.d.ts
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import type { PairingWindowView, PeerPinState, PeerWords } from './peers.js';
|
|
2
|
+
/**
|
|
3
|
+
* SETTINGS › HOSTS — what the dashboard's `GET /api/hosts` answers, and its actions' answers (planning/docker/00-plan.md
|
|
4
|
+
* §§ 7, 9 and 11 «The dashboard», slice D19; issues/open/overseer-74).
|
|
5
|
+
*
|
|
6
|
+
* On the organizer: this Mac's identity, the peer hub (listening where and why, or not and why), the pairing window
|
|
7
|
+
* (never its code), the workers — waiting for the person's approval with their four words, or paired with their link
|
|
8
|
+
* and their version. On a worker (a home that pins an organizer): the organizer it serves, its link, its version and
|
|
9
|
+
* the person's choice to follow the organizer's version.
|
|
10
|
+
*
|
|
11
|
+
* The code of a pairing window is in ONE answer only: the one that opened it ({@link DashHostsPairOpened}). No other
|
|
12
|
+
* answer, listing or log carries it.
|
|
13
|
+
*
|
|
14
|
+
* Every action here is the person's: the dashboard takes it as it takes every other write of the person's — a
|
|
15
|
+
* same-origin JSON POST behind the dashboard's sign-in — and only on a dashboard bound to loopback, as the Changes
|
|
16
|
+
* page's writes. Pure types: the dashboard reads them.
|
|
17
|
+
*/
|
|
18
|
+
/** A version state as both dashboards show it: D13's `PeerVersionState` (apps/agent peers/versions.ts) in words. */
|
|
19
|
+
export type HostVersionState = 'in-step' | 'installing' | 'waiting-for-person' | 'out-of-step';
|
|
20
|
+
export interface HostVersionView {
|
|
21
|
+
state: HostVersionState;
|
|
22
|
+
/** What each side runs: its LensMCP version and the peer protocol it speaks. */
|
|
23
|
+
worker: {
|
|
24
|
+
lensmcp: string;
|
|
25
|
+
protocol: string;
|
|
26
|
+
};
|
|
27
|
+
organizer: {
|
|
28
|
+
lensmcp: string;
|
|
29
|
+
protocol: string;
|
|
30
|
+
};
|
|
31
|
+
/** D13's words (`versionStateWords`): a headline, and what it means for the work. */
|
|
32
|
+
headline: string;
|
|
33
|
+
detail: string;
|
|
34
|
+
/** Only a worker in step takes work (§ 9 rule 4). */
|
|
35
|
+
takesWork: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Where it was read: `hello` — the organizer's view from the worker's hello alone (in step, or out of step and on
|
|
38
|
+
* which side); `worker` — what the worker itself said of its store, its install and its restart.
|
|
39
|
+
*/
|
|
40
|
+
from: 'hello' | 'worker';
|
|
41
|
+
/** When it was read, by this Mac's clock. */
|
|
42
|
+
at: number;
|
|
43
|
+
/** The waiting-for-person state's: the organizer's version is in the worker's store already. */
|
|
44
|
+
stored?: boolean;
|
|
45
|
+
}
|
|
46
|
+
/** A link between two Macs, as one side last saw it. */
|
|
47
|
+
export interface HostLinkView {
|
|
48
|
+
/**
|
|
49
|
+
* `connected`: its control stream is up and said hello. `not-connected`: it was, and went (`why`). `lost`: 45 s
|
|
50
|
+
* without a word — its runs read lost. `never`: not since this Mac began keeping the link's account.
|
|
51
|
+
*/
|
|
52
|
+
state: 'connected' | 'not-connected' | 'lost' | 'never';
|
|
53
|
+
/** Connected since. */
|
|
54
|
+
since?: number;
|
|
55
|
+
/** The address it came from (the organizer's view), or the one it dials (the worker's). */
|
|
56
|
+
remote?: string;
|
|
57
|
+
/** The last word from the other side, by this Mac's clock — none: not known. */
|
|
58
|
+
lastHeardAt?: number;
|
|
59
|
+
/** When it went: disconnected, or found lost. */
|
|
60
|
+
wentAt?: number;
|
|
61
|
+
why?: string;
|
|
62
|
+
}
|
|
63
|
+
/** A worker as the organizer's Settings › Hosts shows it — its pin, and what the peer hub knows of its link. */
|
|
64
|
+
export interface HostsWorker {
|
|
65
|
+
name: string;
|
|
66
|
+
model: string;
|
|
67
|
+
fingerprint: string;
|
|
68
|
+
/** Its certificate's fingerprint as a person reads it: the first sixteen characters, in fours. */
|
|
69
|
+
short: string;
|
|
70
|
+
/** The four words the person compares with the worker's terminal before approving. */
|
|
71
|
+
words: PeerWords;
|
|
72
|
+
state: PeerPinState;
|
|
73
|
+
answeredAt: number;
|
|
74
|
+
/** A pending worker is dropped at this time unless the person approved it. */
|
|
75
|
+
approveBy?: number;
|
|
76
|
+
approvedAt?: number;
|
|
77
|
+
/** The address it paired from: evidence only — a worker is its certificate. */
|
|
78
|
+
from?: string;
|
|
79
|
+
link: HostLinkView;
|
|
80
|
+
/** Its versions, as last read — none: not heard since it was paired. */
|
|
81
|
+
version?: HostVersionView;
|
|
82
|
+
/** Whether it follows the organizer's version by itself, as it last said — none: it has not said. Its person sets it, on the worker. */
|
|
83
|
+
follow?: boolean;
|
|
84
|
+
}
|
|
85
|
+
/** The organizer's peer hub: listening where and why, or not and why. */
|
|
86
|
+
export interface HostsHub {
|
|
87
|
+
/** As `hub.json` says it — `never`: no hub has run in this home. A `listening` whose process is gone reads `stopped`. */
|
|
88
|
+
state: 'listening' | 'idle' | 'stopped' | 'never';
|
|
89
|
+
why: string;
|
|
90
|
+
address?: string;
|
|
91
|
+
port?: number;
|
|
92
|
+
pid?: number;
|
|
93
|
+
/** When the hub last wrote its status. */
|
|
94
|
+
at?: number;
|
|
95
|
+
/** What the files say it should do now (pairing.ts `hubWanted`) — the page says when the two disagree. */
|
|
96
|
+
wanted: {
|
|
97
|
+
wanted: boolean;
|
|
98
|
+
why: string;
|
|
99
|
+
address?: string;
|
|
100
|
+
port?: number;
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
/** This Mac, as the other side sees it. */
|
|
104
|
+
export interface HostsSelf {
|
|
105
|
+
/** The name it goes by as a peer (`LENSMCP_PEER_NAME`, else its Computer Name). */
|
|
106
|
+
name: string;
|
|
107
|
+
/** Its model identifier («Mac14,13»). */
|
|
108
|
+
model: string;
|
|
109
|
+
/** Its certificate's fingerprint — none: no identity was made yet (the first pairing makes it). */
|
|
110
|
+
fingerprint?: string;
|
|
111
|
+
short?: string;
|
|
112
|
+
}
|
|
113
|
+
/** Where a new pairing window would listen, and what else this Mac could listen on (DW-Q6: ONE address the person picks). */
|
|
114
|
+
export interface HostsListen {
|
|
115
|
+
address?: string;
|
|
116
|
+
port: number;
|
|
117
|
+
/** `env`: LENSMCP_PEER_ADDRESS; `kept`: the address the paired workers dial; `primary`: the primary interface's. */
|
|
118
|
+
from?: 'env' | 'kept' | 'primary';
|
|
119
|
+
/** This Mac's own addresses a window may listen on — never every interface, multicast or broadcast. */
|
|
120
|
+
choices: string[];
|
|
121
|
+
/** Why there is no address to listen on. */
|
|
122
|
+
none?: string;
|
|
123
|
+
}
|
|
124
|
+
export interface HostsOrganizerSide {
|
|
125
|
+
hub: HostsHub;
|
|
126
|
+
/** The pairing window, never with its code — none: none is open or used now. */
|
|
127
|
+
window?: PairingWindowView;
|
|
128
|
+
listen: HostsListen;
|
|
129
|
+
/** The pending ones first, then the paired, by name. */
|
|
130
|
+
workers: HostsWorker[];
|
|
131
|
+
}
|
|
132
|
+
/** This Mac as a worker: the organizer it serves. */
|
|
133
|
+
export interface HostsWorkerSide {
|
|
134
|
+
organizer: {
|
|
135
|
+
name: string;
|
|
136
|
+
model: string;
|
|
137
|
+
fingerprint: string;
|
|
138
|
+
short: string;
|
|
139
|
+
words: PeerWords;
|
|
140
|
+
/** `pending`: it gave the right code and waits for the organizer's person. */
|
|
141
|
+
state: PeerPinState;
|
|
142
|
+
/** Where it dials. */
|
|
143
|
+
address: string;
|
|
144
|
+
port: number;
|
|
145
|
+
answeredAt: number;
|
|
146
|
+
approvedAt?: number;
|
|
147
|
+
};
|
|
148
|
+
/** The link the worker daemon keeps — `never` when no daemon has run here since the pairing. */
|
|
149
|
+
link: HostLinkView & {
|
|
150
|
+
/** The daemon that keeps it, while it runs. */
|
|
151
|
+
daemon?: {
|
|
152
|
+
pid: number;
|
|
153
|
+
};
|
|
154
|
+
/** The organizer's own LensMCP version, as its welcome said. */
|
|
155
|
+
organizerVersion?: string;
|
|
156
|
+
};
|
|
157
|
+
/** Its versions, as its daemon last said them — none: no daemon has said. */
|
|
158
|
+
version?: HostVersionView;
|
|
159
|
+
/** The person's choice on this Mac (D13 `versions.json`, per pairing): follow the organizer's version by itself (yes by default), and the version they approved. */
|
|
160
|
+
follow: {
|
|
161
|
+
follow: boolean;
|
|
162
|
+
approved?: string;
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
/** `GET /api/hosts`: Settings › Hosts. */
|
|
166
|
+
export interface DashHostsView {
|
|
167
|
+
at: number;
|
|
168
|
+
self: HostsSelf;
|
|
169
|
+
organizer: HostsOrganizerSide;
|
|
170
|
+
/** Present on a Mac that pins an organizer. */
|
|
171
|
+
worker?: HostsWorkerSide;
|
|
172
|
+
/**
|
|
173
|
+
* Whether this dashboard takes the person's actions on this page: a dashboard bound to loopback only — refused (and
|
|
174
|
+
* said why) on one bound wider, as the Changes page's writes are.
|
|
175
|
+
*/
|
|
176
|
+
writes: {
|
|
177
|
+
ok: true;
|
|
178
|
+
} | {
|
|
179
|
+
ok: false;
|
|
180
|
+
why: string;
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* `POST /api/hosts/pair`'s answer — the ONE answer that carries a window's code. The page keeps it in memory only, for
|
|
185
|
+
* the person to copy: reloaded, the page no longer has it (open another window).
|
|
186
|
+
*/
|
|
187
|
+
export interface DashHostsPairOpened {
|
|
188
|
+
window: PairingWindowView;
|
|
189
|
+
/** The code as it is shown: two groups of five, `7K3MQ-XW2PD`. */
|
|
190
|
+
code: string;
|
|
191
|
+
/** What the person types on the other Mac. */
|
|
192
|
+
line: string;
|
|
193
|
+
/** The hub listens for this window now. */
|
|
194
|
+
listening: boolean;
|
|
195
|
+
/** Why it does not listen yet, and what changes for workers already paired. */
|
|
196
|
+
notes: string[];
|
|
197
|
+
hosts: DashHostsView;
|
|
198
|
+
}
|
|
199
|
+
/** Every other action's answer: what was done, in a sentence, and the page as it is after it. */
|
|
200
|
+
export interface DashHostsDone {
|
|
201
|
+
said: string;
|
|
202
|
+
hosts: DashHostsView;
|
|
203
|
+
}
|
|
204
|
+
/** The actions of Settings › Hosts, each `POST /api/hosts/<action>` — the person's, every one. */
|
|
205
|
+
export declare const HOSTS_ACTIONS: readonly ["pair", "close", "approve", "decline", "revoke", "forget", "follow", "approve-version"];
|
|
206
|
+
export type HostsAction = (typeof HOSTS_ACTIONS)[number];
|
package/lib/hosts.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";export const HOSTS_ACTIONS=["pair","close","approve","decline","revoke","forget","follow","approve-version"];
|