@lensmcp/protocol-types 1.26.23 → 1.26.25
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 +5 -0
- package/index.js +1 -1
- package/lib/ai-cache-facts.js +1 -1
- package/lib/ai-cache-verdict.d.ts +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.d.ts +11 -0
- 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/canvas-attachments.d.ts +80 -0
- package/lib/canvas-attachments.js +1 -0
- package/lib/canvas-catalog.js +5 -4
- package/lib/canvas-editing.d.ts +107 -0
- package/lib/canvas-editing.js +4 -0
- package/lib/canvas-frame-policy.d.ts +20 -0
- package/lib/canvas-frame-policy.js +1 -0
- package/lib/canvas-hub.d.ts +231 -0
- package/lib/canvas-hub.js +1 -0
- package/lib/canvas.d.ts +149 -8
- package/lib/canvas.js +1 -1
- package/lib/capture-demand.js +1 -1
- package/lib/dashboard-path.js +1 -1
- package/lib/docker-errors.js +1 -1
- package/lib/docker-jobs.d.ts +9 -2
- package/lib/docker-jobs.js +1 -1
- package/lib/docker-report.d.ts +2 -1
- package/lib/docker-report.js +2 -2
- 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.js +1 -1
- package/lib/http-exchange.d.ts +10 -0
- package/lib/lens-hosts.d.ts +40 -0
- package/lib/lens-hosts.js +1 -0
- package/lib/lint-coverage.d.ts +8 -0
- package/lib/lint-coverage.js +1 -1
- package/lib/lint-ignores.d.ts +20 -0
- package/lib/lint-ignores.js +2 -2
- package/lib/log-query.js +1 -1
- package/lib/metrics-reset.js +1 -1
- package/lib/overseer-findings.d.ts +21 -4
- package/lib/overseer-findings.js +1 -1
- package/lib/peers.d.ts +123 -1
- 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.js +1 -1
- package/lib/sources.js +1 -1
- package/lib/static-checks.d.ts +14 -0
- package/lib/static-checks.js +1 -1
- package/lib/system-report.js +1 -1
- package/lib/team.d.ts +35 -0
- package/lib/team.js +1 -1
- package/package.json +1 -1
package/lib/http-exchange.d.ts
CHANGED
|
@@ -23,7 +23,15 @@ export interface HttpExchangeBody {
|
|
|
23
23
|
* compressed answer too big to unpack).
|
|
24
24
|
*/
|
|
25
25
|
omitted?: 'binary' | 'form-data' | 'stream' | 'ai' | 'encoded';
|
|
26
|
+
/**
|
|
27
|
+
* The read stopped before the body ended — `size` is then only what arrived, and `truncated` is set: `time`, it ran
|
|
28
|
+
* past the read's bound (5 minutes from the answer's first byte, 30 for an AI call kept whole); `broken`, the caller
|
|
29
|
+
* or the network cut it. Absent from a capture before it said (foodguard-302).
|
|
30
|
+
*/
|
|
31
|
+
cut?: HttpExchangeCut;
|
|
26
32
|
}
|
|
33
|
+
/** Why a capture stopped reading an answer before its end. `size`: a bound of what is kept (a stream's events). */
|
|
34
|
+
export type HttpExchangeCut = 'time' | 'broken' | 'size';
|
|
27
35
|
export interface HttpExchangeStreamEvent {
|
|
28
36
|
/** Since the request started. */
|
|
29
37
|
atMs: number;
|
|
@@ -72,6 +80,7 @@ export interface HttpExchange {
|
|
|
72
80
|
decoded?: number;
|
|
73
81
|
};
|
|
74
82
|
body?: HttpExchangeBody;
|
|
83
|
+
/** `cut`: not every event was kept — `cutBy` says why, from a capture that says it. */
|
|
75
84
|
stream?: {
|
|
76
85
|
protocol: 'sse';
|
|
77
86
|
firstEventMs?: number;
|
|
@@ -79,6 +88,7 @@ export interface HttpExchange {
|
|
|
79
88
|
bytes: number;
|
|
80
89
|
total: number;
|
|
81
90
|
cut?: boolean;
|
|
91
|
+
cutBy?: HttpExchangeCut;
|
|
82
92
|
};
|
|
83
93
|
};
|
|
84
94
|
/** What the lens removed before storing: header names, and body fields (paths). */
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LensMCP's own host names (planning/canvas D7, D9, phase H) and the links built on them.
|
|
3
|
+
*
|
|
4
|
+
* The dashboard lives at `https://lensmcp.localhost/<key>/`, a canvas's frame at `https://lensmcp.canvas.localhost`
|
|
5
|
+
* (`CANVAS_FRAME_HOST`, canvas.ts). `.localhost` is loopback by standard (RFC 6761): no `/etc/hosts` line, no mDNS miss
|
|
6
|
+
* (`.local` waited about 5 s per AAAA lookup for Bonjour).
|
|
7
|
+
*
|
|
8
|
+
* `lensmcp.local`, the name before the move, stays answered for two releases — through 1.27.x: it stays a name on the
|
|
9
|
+
* gateway's certificate; a browser's page load there is sent on with a 308 to the same path on the new host; anything
|
|
10
|
+
* else (a script, an open tab's API call, a worker Mac's tunnel) is served as the new host would be, an alias. A record
|
|
11
|
+
* written before the move is read as the new host ({@link currentLensHost}).
|
|
12
|
+
*
|
|
13
|
+
* Two copies, held equal by their specs, because neither package depends on this one at runtime: the gateway's
|
|
14
|
+
* (`@lensmcp/cluster` `runtime/lens-hosts.ts`) and the CLI's (`libs/cli` `dashboard-link.ts`).
|
|
15
|
+
*/
|
|
16
|
+
/** The dashboard's host (D7). */
|
|
17
|
+
export declare const LENS_HOST = "lensmcp.localhost";
|
|
18
|
+
/** The dashboard's host before the move: an alias and a 308 through the compatibility window. */
|
|
19
|
+
export declare const LEGACY_LENS_HOST = "lensmcp.local";
|
|
20
|
+
/** The key-free path of a canvas, `https://lensmcp.localhost/canvas/<id>` (§8 Links): the workspace key `canvas` is reserved. */
|
|
21
|
+
export declare const CANVAS_LINK_PATH = "/canvas";
|
|
22
|
+
export interface LensLinkOptions {
|
|
23
|
+
/** The gateway's front door port. The scheme's own (443) is left out of the link. */
|
|
24
|
+
port?: number;
|
|
25
|
+
/** The dashboard host the running gateway serves (an operator's `lensHost`). Default {@link LENS_HOST}. */
|
|
26
|
+
host?: string;
|
|
27
|
+
}
|
|
28
|
+
/** `https://lensmcp.localhost`, with the front door's port when it is not 443. */
|
|
29
|
+
export declare function lensOrigin(opts?: LensLinkOptions): string;
|
|
30
|
+
/**
|
|
31
|
+
* A dashboard page through the gateway (§8 Links: what replaces every hard-coded dashboard link): `base` is the
|
|
32
|
+
* dashboard's mount (`/<key>`), `path` a page under it (`canvases/cv-…`), empty for its home.
|
|
33
|
+
*/
|
|
34
|
+
export declare function dashboardLink(base: string, path?: string, opts?: LensLinkOptions): string;
|
|
35
|
+
/** The canonical, key-free link to a canvas: the gateway looks the id up and sends the browser to the dashboard that serves it. */
|
|
36
|
+
export declare function canvasKeyFreeLink(id: string, opts?: LensLinkOptions): string;
|
|
37
|
+
/** The front door's port as the gateway tells its children (`LENSMCP_GATEWAY_PORTS`, the first one) — none when not told. */
|
|
38
|
+
export declare function gatewayPortFromEnv(env: Readonly<Record<string, string | undefined>>): number | undefined;
|
|
39
|
+
/** A host as written before the move, as it is now: `lensmcp.local` is `lensmcp.localhost`; any other name is itself. */
|
|
40
|
+
export declare function currentLensHost(host: string): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var c=Object.defineProperty;var r=(e,n)=>c(e,"name",{value:n,configurable:!0});var i=Object.defineProperty,t=r((e,n)=>i(e,"name",{value:n,configurable:!0}),"t"),u=Object.defineProperty,o=t((e,n)=>u(e,"name",{value:n,configurable:!0}),"r");export const LENS_HOST="lensmcp.localhost",LEGACY_LENS_HOST="lensmcp.local",CANVAS_LINK_PATH="/canvas";export function lensOrigin(e={}){const n=e.port!==void 0&&e.port!==443?`:${e.port}`:"";return`https://${e.host||LENS_HOST}${n}`}r(lensOrigin,"lensOrigin"),t(lensOrigin,"lensOrigin"),o(lensOrigin,"lensOrigin");export function dashboardLink(e,n="",a={}){const s=e.replace(/\/+$/,"");return`${lensOrigin(a)}${s}/${n.replace(/^\/+/,"")}`}r(dashboardLink,"dashboardLink"),t(dashboardLink,"dashboardLink"),o(dashboardLink,"dashboardLink");export function canvasKeyFreeLink(e,n={}){return`${lensOrigin(n)}${CANVAS_LINK_PATH}/${e}`}r(canvasKeyFreeLink,"canvasKeyFreeLink"),t(canvasKeyFreeLink,"canvasKeyFreeLink"),o(canvasKeyFreeLink,"canvasKeyFreeLink");export function gatewayPortFromEnv(e){const n=Number((e.LENSMCP_GATEWAY_PORTS??"").split(",")[0]);return Number.isInteger(n)&&n>0&&n<65536?n:void 0}r(gatewayPortFromEnv,"gatewayPortFromEnv"),t(gatewayPortFromEnv,"gatewayPortFromEnv"),o(gatewayPortFromEnv,"gatewayPortFromEnv");export function currentLensHost(e){return e.trim().toLowerCase()===LEGACY_LENS_HOST?LENS_HOST:e}r(currentLensHost,"currentLensHost"),t(currentLensHost,"currentLensHost"),o(currentLensHost,"currentLensHost");
|
package/lib/lint-coverage.d.ts
CHANGED
|
@@ -87,6 +87,14 @@ export interface LintBase {
|
|
|
87
87
|
moreFiles?: number;
|
|
88
88
|
errors: LintBaseError[];
|
|
89
89
|
moreErrors?: number;
|
|
90
|
+
/**
|
|
91
|
+
* What of the above the person's ignores hold (`.lensmcp/lint/ignores.json`, lint-ignores.ts) — by file, each rule in
|
|
92
|
+
* the project that owns the file, with how many errors and warnings: `[file, rule, project, errors, warnings]`, up to a
|
|
93
|
+
* cap (`moreHidden` past it). The counts above are of everything held; a run built on this leaves these out of its
|
|
94
|
+
* verdict. Absent from a lens from before it said (foodguard-305), and when nothing is ignored.
|
|
95
|
+
*/
|
|
96
|
+
hidden?: Array<[string, string, string, number, number]>;
|
|
97
|
+
moreHidden?: number;
|
|
90
98
|
}
|
|
91
99
|
export interface LintBaseAnswer {
|
|
92
100
|
schemaVersion: 1;
|
package/lib/lint-coverage.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var C=Object.defineProperty;var p=(e,r)=>C(e,"name",{value:r,configurable:!0});var k=Object.defineProperty,h=p((e,r)=>k(e,"name",{value:r,configurable:!0}),"g"),A=Object.defineProperty,d=h((e,r)=>A(e,"name",{value:r,configurable:!0}),"i");import{TRUNCATION_MARKER_KEY as j}from"./bounded-clone.js";export const LINT_COVER_KIND="lint-cover",MAX_LINT_UNCOMMITTED=500;const L=["tree","paths","changed","incremental"],m=d(e=>Array.isArray(e)?e.filter(r=>typeof r=="string"&&r.length>0):[],"strings"),i=d(e=>typeof e=="number"&&Number.isFinite(e)&&e>=0?Math.floor(e):void 0,"count"),l=d(e=>typeof e=="string"&&e?e:void 0,"text");export function readLintCoverage(e){if(!e||typeof e!="object"||e[j])return;const r=e.coverage;if(!r||typeof r!="object")return;const t=r,n=t.kind,a=t.root;if(!L.includes(n)||typeof a!="string"||!a)return;const u=m(t.dirs),o=m(t.files),g=m(t.gone),$=i(t.notLinted),y=i(t.untracked),s=t.base&&typeof t.base=="object"?t.base:void 0,v=s&&l(s.sha)&&l(s.run)?{from:s.from==="main"?"main":"own",sha:s.sha,run:s.run}:void 0,b=Array.isArray(t.inputs)?t.inputs.flatMap(f=>Array.isArray(f)&&typeof f[0]=="string"&&typeof f[1]=="string"?[[f[0],f[1]]]:[]):void 0;return{kind:n,root:a,dirs:u,files:o,gone:g,fileCount:i(t.fileCount)??o.length,goneCount:i(t.goneCount)??g.length,linted:i(t.linted)??0,...i(t.dirCount)!==void 0?{dirCount:i(t.dirCount)}:{},...$?{notLinted:$}:{},...y?{untracked:y}:{},...l(t.since)?{since:t.since}:{},...l(t.head)?{head:t.head}:{},...typeof t.dirty=="boolean"?{dirty:t.dirty}:{},...Array.isArray(t.uncommitted)?{uncommitted:m(t.uncommitted)}:{},...t.uncommittedMore===!0?{uncommittedMore:!0}:{},...b?{inputs:b}:{},...l(t.folder)?{folder:t.folder}:{},...t.projects===!0?{projects:!0}:{},...v?{base:v}:{},...t.fromZero===!0?{fromZero:!0}:{},...t.narrowed===!0?{narrowed:!0}:{}}}p(readLintCoverage,"readLintCoverage"),h(readLintCoverage,"readLintCoverage"),d(readLintCoverage,"readLintCoverage");const c=d((e,r)=>`${e} ${r}${e===1?"":"s"}`,"some");export function lintCoverageLabel(e,r={}){const t=e.files??0,n=e.gone??0;if(e.kind==="changed"){const o=`since ${e.since??"HEAD"}`;if(!t)return`${c(n,"deleted file")} ${o}`;const g=r.untracked&&e.untracked?` (${e.untracked} untracked)`:"";return`${c(t,"changed file")} ${o}${g}${n?`, ${n} deleted`:""}`}if(e.kind==="incremental"){const o=e.since?` since ${e.since.slice(0,7)}`:"";return!t&&!n?`nothing changed${o}`:t?`${c(t,"file")} changed${o}${n?`, ${n} deleted`:""}`:`${c(n,"file")} deleted${o}`}if(e.kind==="tree"&&e.projects)return`the workspace\u2019s ${c(e.projects,"project")}`;if(e.kind==="tree"&&e.paths[0]===".")return"whole checkout";if(e.narrowed)return`${c(t,"file")} ESLint linted with the caller\u2019s arguments`;const a=e.paths.slice(0,3).join(", "),u=(e.more??0)+Math.max(0,e.paths.length-3);return u?`${a} +${u} more`:a}p(lintCoverageLabel,"lintCoverageLabel"),h(lintCoverageLabel,"lintCoverageLabel"),d(lintCoverageLabel,"lintCoverageLabel");
|
package/lib/lint-ignores.d.ts
CHANGED
|
@@ -126,6 +126,26 @@ export declare function lintIgnoredSummary(read: LintIgnoresRead, hid: ReadonlyM
|
|
|
126
126
|
errors: number;
|
|
127
127
|
warnings: number;
|
|
128
128
|
}>): LintIgnoredSummary | undefined;
|
|
129
|
+
/**
|
|
130
|
+
* The split an answer makes, for a reader that counts findings one by one (`lensmcp lint`'s plain and cold runs): `hides`
|
|
131
|
+
* says whether an ignore holds a finding — and counts it under that ignore — and `summary` is the block the answer
|
|
132
|
+
* carries, as {@link lintIgnoredSummary} makes it. `n` counts a row of findings at once.
|
|
133
|
+
*/
|
|
134
|
+
export interface LintIgnoreTally {
|
|
135
|
+
hides(finding: {
|
|
136
|
+
rule: string | null | undefined;
|
|
137
|
+
project: string | undefined;
|
|
138
|
+
scope?: string | undefined;
|
|
139
|
+
}, severity: 'error' | 'warning', n?: number): LintIgnore | undefined;
|
|
140
|
+
summary(): LintIgnoredSummary | undefined;
|
|
141
|
+
}
|
|
142
|
+
export declare function lintIgnoreTally(read: LintIgnoresRead): LintIgnoreTally;
|
|
143
|
+
/**
|
|
144
|
+
* What the person ignored, as a text answer prints it — the `lint` tool's text, `lensmcp lint` plain, by unit and cold
|
|
145
|
+
* alike: how many it left out, then each rule in its project that hides something now, with why; then what in the file
|
|
146
|
+
* does not hold. Indented under the answer's verdict line.
|
|
147
|
+
*/
|
|
148
|
+
export declare function lintIgnoredLines(ignored: LintIgnoredSummary | undefined): string[];
|
|
129
149
|
/** What became of a proposal: open for the person, accepted (the ignore is written), or declined. */
|
|
130
150
|
export type LintIgnoreProposalState = 'open' | 'accepted' | 'declined';
|
|
131
151
|
/** An agent's proposal to ignore a rule in a project — data for the person, who accepts or declines it on the Lint page. */
|
package/lib/lint-ignores.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
`}
|
|
1
|
+
"use strict";var $=Object.defineProperty;var u=(e,r)=>$(e,"name",{value:r,configurable:!0});var w=Object.defineProperty,c=u((e,r)=>w(e,"name",{value:r,configurable:!0}),"u"),x=Object.defineProperty,l=c((e,r)=>x(e,"name",{value:r,configurable:!0}),"l");export const LINT_IGNORES_FILE=".lensmcp/lint/ignores.json",LINT_IGNORE_LIMITS={rule:200,project:200,reason:500,evidence:1e3,by:80,ignores:500},LINT_IGNORED_RULES_SAID=50,LINT_IGNORED_NOTE="The person ignored these lints in the repository (each a rule in a project, with why): they are left out of the counts, the verdict and the status \u2014 do not fix them, and do not edit the ESLint config or this file for them. ESLint itself (`nx lint`) still reports them. To ask for another, `lint_ignore_propose`; only the person accepts.";const j=l(e=>e&&typeof e=="object"&&!Array.isArray(e)?e:void 0,"obj"),h=l(e=>typeof e=="string"&&e.trim()?e.replace(/\s+/g," ").trim():void 0,"text");export function lintIgnoreKey(e,r){return`${r}\0${e}`}u(lintIgnoreKey,"lintIgnoreKey"),c(lintIgnoreKey,"lintIgnoreKey"),l(lintIgnoreKey,"lintIgnoreKey");export function checkLintIgnore(e){const r=h(e.rule),o=h(e.project),t=h(e.reason),n=LINT_IGNORE_LIMITS;return r?r==="fatal"?{problem:"a file ESLint could not parse is never ignored \u2014 fix it"}:r.length>n.rule?{problem:`the rule is at most ${n.rule} characters`}:o?o.length>n.project?{problem:`the project is at most ${n.project} characters`}:t?t.length>n.reason?{problem:`the reason is at most ${n.reason} characters`}:{rule:r,project:o,reason:t}:{problem:"say why it is not to be fixed \u2014 the reason is what a teammate and an agent read"}:{problem:"name the project that owns the files"}:{problem:"name the rule (ESLint\u2019s rule id, as the finding names it)"}}u(checkLintIgnore,"checkLintIgnore"),c(checkLintIgnore,"checkLintIgnore"),l(checkLintIgnore,"checkLintIgnore");export function parseLintIgnores(e){if(e===void 0||!e.trim())return{ignores:[],problems:[]};let r;try{r=JSON.parse(e)}catch(s){return{ignores:[],problems:[`${LINT_IGNORES_FILE} is not JSON (${s instanceof Error?s.message:String(s)}) \u2014 no lint is ignored until it is`]}}const o=j(r),t=o?o.ignores:void 0;if(!o||!Array.isArray(t))return{ignores:[],problems:[`${LINT_IGNORES_FILE} holds no "ignores" list \u2014 no lint is ignored until it does`]};const n=[],a=[],i=new Set;return t.forEach((s,p)=>{const f=j(s);if(!f){a.push(`ignores[${p}] is not an object`);return}const g=checkLintIgnore(f);if("problem"in g){a.push(`ignores[${p}]: ${g.problem}`);return}const d=lintIgnoreKey(g.rule,g.project);if(i.has(d)){a.push(`ignores[${p}]: ${g.rule} in ${g.project} is ignored above already \u2014 the first stands`);return}if(n.length>=LINT_IGNORE_LIMITS.ignores){a.push(`ignores[${p}]: past ${LINT_IGNORE_LIMITS.ignores} ignores \u2014 the rest are not read`);return}i.add(d);const b=h(f.by)?.slice(0,LINT_IGNORE_LIMITS.by),m=h(f.at),y=h(f.proposal);n.push({...g,...b?{by:b}:{},...m&&!Number.isNaN(Date.parse(m))?{at:m}:{},...y?{proposal:y.slice(0,40)}:{}})}),{ignores:n,problems:a}}u(parseLintIgnores,"parseLintIgnores"),c(parseLintIgnores,"parseLintIgnores"),l(parseLintIgnores,"parseLintIgnores");export function lintIgnoresText(e){const r=[...e].sort((t,n)=>t.project<n.project?-1:t.project>n.project?1:t.rule<n.rule?-1:t.rule>n.rule?1:0),o=l(t=>({rule:t.rule,project:t.project,reason:t.reason,...t.by?{by:t.by}:{},...t.at?{at:t.at}:{},...t.proposal?{proposal:t.proposal}:{}}),"entry");return`${JSON.stringify({version:1,ignores:r.map(o)},null,2)}
|
|
2
|
+
`}u(lintIgnoresText,"lintIgnoresText"),c(lintIgnoresText,"lintIgnoresText"),l(lintIgnoresText,"lintIgnoresText");export function withLintIgnore(e,r){const o=lintIgnoreKey(r.rule,r.project);return[...e.filter(t=>lintIgnoreKey(t.rule,t.project)!==o),r]}u(withLintIgnore,"withLintIgnore"),c(withLintIgnore,"withLintIgnore"),l(withLintIgnore,"withLintIgnore");export function withoutLintIgnore(e,r,o){const t=lintIgnoreKey(r,o);return e.filter(n=>lintIgnoreKey(n.rule,n.project)!==t)}u(withoutLintIgnore,"withoutLintIgnore"),c(withoutLintIgnore,"withoutLintIgnore"),l(withoutLintIgnore,"withoutLintIgnore");export function lintIgnoreMatcher(e){if(!e.length)return()=>{};const r=new Map(e.map(o=>[lintIgnoreKey(o.rule,o.project),o]));return({rule:o,project:t,scope:n})=>{if(!o||o==="fatal")return;const a=t??n;return a===void 0?void 0:r.get(lintIgnoreKey(o,a))}}u(lintIgnoreMatcher,"lintIgnoreMatcher"),c(lintIgnoreMatcher,"lintIgnoreMatcher"),l(lintIgnoreMatcher,"lintIgnoreMatcher");export function lintIgnoredSummary(e,r){if(!e.ignores.length&&!e.problems.length)return;let o=0,t=0;const n=e.ignores.map(i=>{const s=r.get(lintIgnoreKey(i.rule,i.project))??{errors:0,warnings:0};return o+=s.errors,t+=s.warnings,{rule:i.rule,project:i.project,reason:i.reason,...i.by?{by:i.by}:{},...i.at?{at:i.at}:{},errors:s.errors,warnings:s.warnings}}).map((i,s)=>({r:i,i:s})).sort((i,s)=>s.r.errors-i.r.errors||s.r.warnings-i.r.warnings||i.i-s.i).map(({r:i})=>i),a=n.length-LINT_IGNORED_RULES_SAID;return{file:LINT_IGNORES_FILE,errors:o,warnings:t,rules:n.slice(0,LINT_IGNORED_RULES_SAID),...a>0?{moreRules:a}:{},...e.problems.length?{problems:e.problems.slice(0,10)}:{},note:LINT_IGNORED_NOTE}}u(lintIgnoredSummary,"lintIgnoredSummary"),c(lintIgnoredSummary,"lintIgnoredSummary"),l(lintIgnoredSummary,"lintIgnoredSummary");export function lintIgnoreTally(e){const r=lintIgnoreMatcher(e.ignores),o=new Map;return{hides(t,n,a=1){const i=r(t);if(!i)return;const s=lintIgnoreKey(i.rule,i.project),p=o.get(s)??{errors:0,warnings:0};return n==="error"?p.errors+=a:p.warnings+=a,o.set(s,p),i},summary:l(()=>lintIgnoredSummary(e,o),"summary")}}u(lintIgnoreTally,"lintIgnoreTally"),c(lintIgnoreTally,"lintIgnoreTally"),l(lintIgnoreTally,"lintIgnoreTally");const I=10,L=l((e,r)=>`${e} ${r}${e===1?"":"s"}`,"counted");export function lintIgnoredLines(e){if(!e)return[];const r=[],o=e.rules.filter(n=>n.errors||n.warnings),t=[e.errors?L(e.errors,"error"):"",e.warnings?L(e.warnings,"warning"):""].filter(Boolean).join(", ");t&&r.push(` ignored (${e.file}): ${t} left out \u2014 not counted, not to be fixed`);for(const n of o.slice(0,I))r.push(` ${n.rule} in ${n.project} \u2014 ${n.reason}`);o.length>I&&r.push(` and ${o.length-I} more (--json lists them)`);for(const n of e.problems??[])r.push(` ${e.file}: ${n}`);return r}u(lintIgnoredLines,"lintIgnoredLines"),c(lintIgnoredLines,"lintIgnoredLines"),l(lintIgnoredLines,"lintIgnoredLines");export const LINT_IGNORE_PROPOSAL_LIMITS={open:30,kept:200,requestId:200};
|
package/lib/log-query.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var L=Object.defineProperty;var a=(e,t)=>L(e,"name",{value:t,configurable:!0});var d=Object.defineProperty,c=a((e,t)=>d(e,"name",{value:t,configurable:!0}),"a"),h=Object.defineProperty,u=c((e,t)=>h(e,"name",{value:t,configurable:!0}),"c");const p={level:"level",severity:"level",service:"service",svc:"service",src:"service",source:"service",flow:"flow",trace:"trace",request:"trace",category:"category",cat:"category",ms:"ms"},C={warn:"warning",err:"error"},k=/(-?)(?:([A-Za-z]+):)?(?:"([^"]*)"|(\S+))/g;export function parseLogQuery(e){const t=[],r=[];for(const s of e.matchAll(k)){const[o,n,g,y,w]=s,i=(y??w??"").trim(),l=g?p[g.toLowerCase()]:void 0;if(l&&i){const m=l==="level"?C[i.toLowerCase()]??i.toLowerCase():i;t.push({key:l,value:m,negate:n==="-"})}else o.trim()&&r.push(o.trim())}return{tokens:t,text:r.join(" ")}}a(parseLogQuery,"parseLogQuery"),c(parseLogQuery,"parseLogQuery"),u(parseLogQuery,"parseLogQuery");export function formatLogQuery(e){const t=u(r=>/\s/.test(r)?`"${r}"`:r,"quote");return[...e.tokens.map(r=>`${r.negate?"-":""}${r.key}:${t(r.value)}`),e.text].filter(Boolean).join(" ")}a(formatLogQuery,"formatLogQuery"),c(formatLogQuery,"formatLogQuery"),u(formatLogQuery,"formatLogQuery");function v(e,t){if(e===void 0)return!1;const r=/^(>=|<=|>|<|=)?\s*(\d+(?:\.\d+)?)$/.exec(t);if(!r)return!1;const s=Number(r[2]);switch(r[1]){case">":return e>s;case"<":return e<s;case"<=":return e<=s;case"=":return e===s;default:return e>=s}}a(v,"v"),c(v,"h"),u(v,"msMatches");function f(e,t){const r=t.value.toLowerCase();switch(t.key){case"level":return e.severity.toLowerCase()===r;case"service":return e.source.toLowerCase()===r;case"flow":return!!e.flowId&&e.flowId.toLowerCase().startsWith(r);case"trace":return!!e.requestId&&e.requestId.toLowerCase().startsWith(r);case"category":return e.category.toLowerCase()===r;case"ms":return v(e.durationMs,t.value)}}a(f,"l"),c(f,"i"),u(f,"tokenMatches");export function matchesLogQuery(e,t,r){const s=new Map;for(const o of t.tokens){if(o.negate){if(f(e,o))return!1;continue}const n=s.get(o.key);n?n.push(o):s.set(o.key,[o])}for(const o of s.values())if(!o.some(n=>f(e,n)))return!1;if(t.text){const o=`${e.title} ${e.message??""} ${e.source} ${e.flowId??""}`;return r?r(o):o.toLowerCase().includes(t.text.toLowerCase())}return!0}a(matchesLogQuery,"matchesLogQuery"),c(matchesLogQuery,"matchesLogQuery"),u(matchesLogQuery,"matchesLogQuery");
|
package/lib/metrics-reset.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var l=Object.defineProperty;var i=(e,t)=>l(e,"name",{value:t,configurable:!0});var f=Object.defineProperty,a=i((e,t)=>f(e,"name",{value:t,configurable:!0}),"i"),u=Object.defineProperty,c=a((e,t)=>u(e,"name",{value:t,configurable:!0}),"s");import{LENS_EVENT_SOURCE as S}from"./error-dismissal.js";export const METRICS_RESET="metrics-reset",METRICS_RESTORED="metrics-restored",METRICS_SCOPES=["sql","external"],MAX_METRICS_RESET_IDS=500,MAX_METRICS_RESET_ID_LENGTH=512,METRICS_RESET_IDS_PER_EVENT=64;const d=16*1024,p=c(e=>e==="sql"||e==="external","isScope"),E=c(e=>typeof e=="string"&&e.length>0&&e.length<=MAX_METRICS_RESET_ID_LENGTH,"isId");export function readMetricsReset(e){if(e.source!==S||!e.raw||typeof e.raw!="object")return;const t=e.raw,r=t.kind;if(r!==METRICS_RESET&&r!==METRICS_RESTORED)return;const n=t.scope;if(!p(n))return;let s;if(t.ids!==void 0&&(!Array.isArray(t.ids)||(s=[...new Set(t.ids.filter(E))].slice(0,METRICS_RESET_IDS_PER_EVENT),!s.length)))return;if(r===METRICS_RESTORED)return{kind:r,scope:n,...s?{ids:s}:{}};const o=t.at;if(!(typeof o!="number"||!Number.isFinite(o)))return{kind:r,scope:n,at:Math.min(o,e.timestamp),...s?{ids:s}:{}}}i(readMetricsReset,"readMetricsReset"),a(readMetricsReset,"readMetricsReset"),c(readMetricsReset,"readMetricsReset");export function metricsIdBatches(e){const t=[];let r=[],n=0;for(const s of new Set(e.filter(E)))r.length&&(r.length>=METRICS_RESET_IDS_PER_EVENT||n+s.length+3>d)&&(t.push(r),r=[],n=0),r.push(s),n+=s.length+3;return r.length&&t.push(r),t}i(metricsIdBatches,"metricsIdBatches"),a(metricsIdBatches,"metricsIdBatches"),c(metricsIdBatches,"metricsIdBatches");
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type DashSystemScope, type DashSystemUnit } from './system-report.js';
|
|
2
2
|
import type { DashTeamHealthStatus } from './team.js';
|
|
3
3
|
/**
|
|
4
4
|
* The overseer's findings (planning/team/15-the-overseer.md S3): one problem each, kept until it is fixed or dismissed —
|
|
@@ -17,11 +17,19 @@ export type DashFindingState = 'open' | 'proposed' | 'applied' | 'fixed' | 'dism
|
|
|
17
17
|
export type DashFindingVerdict = 'true' | 'false-alarm';
|
|
18
18
|
/** Whose the problem is: the project's (its team, its code), LensMCP's, the host's, or the person's to decide. */
|
|
19
19
|
export type DashFindingCause = 'project' | 'lensmcp' | 'host' | 'person';
|
|
20
|
-
/** One reading of a finding's checks that was not ok — written when the status or the
|
|
20
|
+
/** One reading of a finding's checks that was not ok — written when the status, the value or the check moved. */
|
|
21
21
|
export interface DashFindingSighting {
|
|
22
22
|
at: number;
|
|
23
23
|
status: DashTeamHealthStatus;
|
|
24
24
|
value: number;
|
|
25
|
+
/**
|
|
26
|
+
* The check it is the reading of — the worst of the finding's checks then (`machine/machine.memory`). A finding over
|
|
27
|
+
* several checks reads each in its own unit (issues/closed/overseer-113: machine-09 printed memory % free as «load
|
|
28
|
+
* 46.0»). Absent: a record from before, a retrospective's goal count, a grade's value — the finding's `unit` then.
|
|
29
|
+
*/
|
|
30
|
+
check?: string;
|
|
31
|
+
/** That check's unit; absent with a check: a count. */
|
|
32
|
+
unit?: DashSystemUnit;
|
|
25
33
|
}
|
|
26
34
|
/** A change to one task, as `POST /api/team/task/operate` makes it (store.operate). */
|
|
27
35
|
export interface DashFindingOperate {
|
|
@@ -274,8 +282,11 @@ export interface DashFinding {
|
|
|
274
282
|
/** How its applied proposal is judged on the goals after it, and the newest grade (planning/team/18 RT-D16). */
|
|
275
283
|
acceptance?: DashFindingAcceptance;
|
|
276
284
|
grade?: DashFindingGrade;
|
|
277
|
-
/**
|
|
278
|
-
|
|
285
|
+
/**
|
|
286
|
+
* A retrospective wrote it (planning/team/18 RT-D1), or the repository census raised it when its thresholds passed
|
|
287
|
+
* (`repo.hygiene`, issues/closed/foodguard-307) — the overseer's otherwise.
|
|
288
|
+
*/
|
|
289
|
+
source?: 'retrospective' | 'census';
|
|
279
290
|
/** `<repo>:<target>:<signal>` (RT-D8): a new sighting of the same cause merges into it as another goal (RT-D9). */
|
|
280
291
|
causeKey?: string;
|
|
281
292
|
/** The independent goals that showed its cause, oldest first. */
|
|
@@ -324,6 +335,12 @@ export interface DashFindingApplied {
|
|
|
324
335
|
finding: DashFinding;
|
|
325
336
|
results: DashFindingActionResult[];
|
|
326
337
|
}
|
|
338
|
+
/**
|
|
339
|
+
* A sighting's value as the terminal and the Inbox print it: in its own check's unit, and named by that check's id when
|
|
340
|
+
* the finding holds more than one («machine.memory 37 %»). A sighting from before it kept its check reads in the
|
|
341
|
+
* finding's unit, as it always did (issues/closed/overseer-113).
|
|
342
|
+
*/
|
|
343
|
+
export declare function findingSightingValue(s: DashFindingSighting, f: Pick<DashFinding, 'unit' | 'checks'>): string;
|
|
327
344
|
/** Still the overseer's or the person's to settle: open, proposed or applied (not yet fixed). */
|
|
328
345
|
export declare function findingLive(f: Pick<DashFinding, 'state'>): boolean;
|
|
329
346
|
/**
|
package/lib/overseer-findings.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var u=Object.defineProperty;var s=(n,e)=>u(n,"name",{value:e,configurable:!0});var l=Object.defineProperty,c=s((n,e)=>l(n,"name",{value:e,configurable:!0}),"s"),f=Object.defineProperty,r=c((n,e)=>f(n,"name",{value:e,configurable:!0}),"s");import{systemValue as a}from"./system-report.js";export const FINDING_RUN_KINDS=["operate","stop-launch","close-session","role","role-off","check","rule","flow","lesson"];export function findingSightingValue(n,e){const i=a(n.value,n.check?n.unit:e.unit);if(!n.check||e.checks.length<=1)return i;const t=n.check.slice(n.check.lastIndexOf("/")+1),o=t.slice(t.lastIndexOf(".")+1);return i.startsWith(`${o} `)?`${t}${i.slice(o.length)}`:`${t} ${i}`}s(findingSightingValue,"findingSightingValue"),c(findingSightingValue,"findingSightingValue"),r(findingSightingValue,"findingSightingValue");export function findingLive(n){return n.state==="open"||n.state==="proposed"||n.state==="applied"}s(findingLive,"findingLive"),c(findingLive,"findingLive"),r(findingLive,"findingLive");export function findingRunsActions(n,e={}){return n.actions.some(i=>FINDING_RUN_KINDS.includes(i.kind)||i.kind==="issue"&&e.issuesFolder===!0)}s(findingRunsActions,"findingRunsActions"),c(findingRunsActions,"findingRunsActions"),r(findingRunsActions,"findingRunsActions");export function findingsForCheck(n,e,i){const t=`repo:${e}/team.${i}`;return n.filter(o=>findingLive(o)&&o.checks.includes(t))}s(findingsForCheck,"findingsForCheck"),c(findingsForCheck,"findingsForCheck"),r(findingsForCheck,"findingsForCheck");
|
package/lib/peers.d.ts
CHANGED
|
@@ -648,6 +648,63 @@ export interface StoreReply {
|
|
|
648
648
|
result?: unknown;
|
|
649
649
|
error?: StoreCallError;
|
|
650
650
|
}
|
|
651
|
+
/**
|
|
652
|
+
* The canvas tools a launch on a worker runs at the organizer (planning/canvas/00-plan.md § 6 «Worker Macs», phase 14;
|
|
653
|
+
* issues canvas-03) — all of them: a canvas's home is the organizer's store, so its writes, reads, waits and renders go
|
|
654
|
+
* there. `canvas_resource` is `canvas://{id}`.
|
|
655
|
+
*/
|
|
656
|
+
export declare const CANVAS_CALL_TOOLS: readonly ["canvas_write", "canvas_data", "canvas_get", "canvas_render", "canvas_list", "canvas_wait", "canvas_comment", "canvas_resource"];
|
|
657
|
+
export type CanvasCallTool = (typeof CANVAS_CALL_TOOLS)[number];
|
|
658
|
+
/**
|
|
659
|
+
* `canvas.call` (worker → organizer) — canvas phase 14: one canvas tool, run at the organizer as one launch, over the
|
|
660
|
+
* channel the team's store calls take (the worker daemon's `store.sock`, then its link). The organizer's hub resolves
|
|
661
|
+
* the key as it does for a `store.call`: the launch's placement decides the project (its repository's, at the
|
|
662
|
+
* organizer) and its goal the links a write may carry. Its answer is a {@link CanvasReply}, carried back as the
|
|
663
|
+
* `result` of the envelope's `ack`. Schema: {@link CanvasCallSchema}.
|
|
664
|
+
*/
|
|
665
|
+
export interface CanvasCall {
|
|
666
|
+
v: 1;
|
|
667
|
+
kind: 'canvas.call';
|
|
668
|
+
/** The reply carries it back. */
|
|
669
|
+
id: string;
|
|
670
|
+
tool: CanvasCallTool;
|
|
671
|
+
/** The tool's input, as the worker's server took it — checked again against the tool's schema at the organizer. */
|
|
672
|
+
input: Record<string, unknown>;
|
|
673
|
+
/** The worker's MCP session and client, as its server knows them: the provenance of what the call writes. */
|
|
674
|
+
caller?: {
|
|
675
|
+
session?: string;
|
|
676
|
+
client?: string;
|
|
677
|
+
};
|
|
678
|
+
/** `LENSMCP_PEER_LAUNCH_KEY`. Never logged, listed or answered. */
|
|
679
|
+
launchKey: string;
|
|
680
|
+
}
|
|
681
|
+
/** A file an answer hands back to the worker, which saves it under its own workspace's `.lensmcp/`. */
|
|
682
|
+
export interface CanvasCallFile {
|
|
683
|
+
/**
|
|
684
|
+
* `render`: a picture or a page of a render (`.lensmcp/renders/`); `mirror`: a part too big to answer inline
|
|
685
|
+
* (`.lensmcp/canvases/`); `asset`: a file the person attached to an answer (`.lensmcp/canvases/assets/`, canvas-11).
|
|
686
|
+
*/
|
|
687
|
+
kind: 'render' | 'mirror' | 'asset';
|
|
688
|
+
/** Its file name, {@link CANVAS_CALL_FILE_NAME}: never a folder. */
|
|
689
|
+
name: string;
|
|
690
|
+
base64: string;
|
|
691
|
+
}
|
|
692
|
+
/** `canvas.reply` — the answer to one {@link CanvasCall}, as the `result` of its `ack`. */
|
|
693
|
+
export interface CanvasReply {
|
|
694
|
+
v: 1;
|
|
695
|
+
kind: 'canvas.reply';
|
|
696
|
+
id: string;
|
|
697
|
+
/** The tool's structured answer. A file it names is `lensmcp-worker:<kind>/<name>` ({@link CANVAS_WORKER_FILE}), the worker's copy once saved. */
|
|
698
|
+
result?: Record<string, unknown>;
|
|
699
|
+
/** The picture the answer shows inline (a render): one of `files`, by its `lensmcp-worker:` name. */
|
|
700
|
+
image?: string;
|
|
701
|
+
files?: CanvasCallFile[];
|
|
702
|
+
/** The tool did not answer: what an agent reads, as the tool's own refusal. */
|
|
703
|
+
error?: {
|
|
704
|
+
code: 'NOT_FOUND' | 'REFUSED' | 'UNAVAILABLE' | 'ERROR';
|
|
705
|
+
message: string;
|
|
706
|
+
};
|
|
707
|
+
}
|
|
651
708
|
/**
|
|
652
709
|
* `store.read` (worker → organizer) — slice D32 (planning/docker/00-plan.md § 13, DW-Q2: read-only): the WORKER's own
|
|
653
710
|
* read of the organizer's board, for the worker's dashboard. It carries no launch key — it acts as no launch: the hub
|
|
@@ -762,6 +819,7 @@ export interface PeerBodies {
|
|
|
762
819
|
'launch.tail': LaunchTail;
|
|
763
820
|
'store.call': StoreCall;
|
|
764
821
|
'store.reply': StoreReply;
|
|
822
|
+
'canvas.call': CanvasCall;
|
|
765
823
|
'store.read': StoreRead;
|
|
766
824
|
'version.install': VersionInstall;
|
|
767
825
|
'version.state': VersionState;
|
|
@@ -784,7 +842,7 @@ export type PeerMessage = {
|
|
|
784
842
|
/** What the organizer sends (§ 8, left column). */
|
|
785
843
|
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"];
|
|
786
844
|
/** What the worker sends (§ 8, right column), and `forget`. */
|
|
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"];
|
|
845
|
+
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", "canvas.call"];
|
|
788
846
|
/** Either side sends a ping. */
|
|
789
847
|
export declare const EITHER_WAY: readonly ["ping"];
|
|
790
848
|
/** The replies: each names the message it answers, and is answered by nothing. */
|
|
@@ -1516,6 +1574,70 @@ export declare const StoreReplySchema: z.ZodObject<{
|
|
|
1516
1574
|
wal: z.ZodOptional<z.ZodBoolean>;
|
|
1517
1575
|
}, z.core.$strict>>;
|
|
1518
1576
|
}, z.core.$strict>;
|
|
1577
|
+
/**
|
|
1578
|
+
* What one canvas call carries (canvas phase 14), inside one line of the control stream (512 KiB with its envelope):
|
|
1579
|
+
* its input, encoded; its answer, encoded — the tool's structured output and the files it hands back, base64; the
|
|
1580
|
+
* files' bytes before their encoding (a render's first screen first, the rest while they fit). A wait runs at most
|
|
1581
|
+
* `waitSliceMs` at the organizer per call: the worker's tool asks again until its own time is up.
|
|
1582
|
+
*/
|
|
1583
|
+
export declare const CANVAS_CALL_LIMITS: {
|
|
1584
|
+
readonly inputBytes: number;
|
|
1585
|
+
readonly answerBytes: number;
|
|
1586
|
+
readonly fileBytes: number;
|
|
1587
|
+
readonly waitSliceMs: 20000;
|
|
1588
|
+
};
|
|
1589
|
+
/** A file a canvas answer hands back is named so — a canvas's id, then letters, digits, `.`, `_`, `-` — never a folder. */
|
|
1590
|
+
export declare const CANVAS_CALL_FILE_NAME: RegExp;
|
|
1591
|
+
/** How an answer names a file it hands back: `lensmcp-worker:render/<name>`, `lensmcp-worker:mirror/<name>`, `lensmcp-worker:asset/<name>`. */
|
|
1592
|
+
export declare const CANVAS_WORKER_FILE = "lensmcp-worker:";
|
|
1593
|
+
/** A {@link CanvasCall}, as the forwarder checks it before it goes and the organizer's hub before it runs. */
|
|
1594
|
+
export declare const CanvasCallSchema: z.ZodObject<{
|
|
1595
|
+
v: z.ZodLiteral<1>;
|
|
1596
|
+
kind: z.ZodLiteral<"canvas.call">;
|
|
1597
|
+
id: z.ZodString;
|
|
1598
|
+
tool: z.ZodEnum<{
|
|
1599
|
+
canvas_write: "canvas_write";
|
|
1600
|
+
canvas_data: "canvas_data";
|
|
1601
|
+
canvas_get: "canvas_get";
|
|
1602
|
+
canvas_render: "canvas_render";
|
|
1603
|
+
canvas_list: "canvas_list";
|
|
1604
|
+
canvas_wait: "canvas_wait";
|
|
1605
|
+
canvas_comment: "canvas_comment";
|
|
1606
|
+
canvas_resource: "canvas_resource";
|
|
1607
|
+
}>;
|
|
1608
|
+
input: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
1609
|
+
caller: z.ZodOptional<z.ZodObject<{
|
|
1610
|
+
session: z.ZodOptional<z.ZodString>;
|
|
1611
|
+
client: z.ZodOptional<z.ZodString>;
|
|
1612
|
+
}, z.core.$strict>>;
|
|
1613
|
+
launchKey: z.ZodString;
|
|
1614
|
+
}, z.core.$strict>;
|
|
1615
|
+
/** A {@link CanvasReply}, as the worker reads the `ack`'s result. */
|
|
1616
|
+
export declare const CanvasReplySchema: z.ZodObject<{
|
|
1617
|
+
v: z.ZodLiteral<1>;
|
|
1618
|
+
kind: z.ZodLiteral<"canvas.reply">;
|
|
1619
|
+
id: z.ZodString;
|
|
1620
|
+
result: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
1621
|
+
image: z.ZodOptional<z.ZodString>;
|
|
1622
|
+
files: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
1623
|
+
kind: z.ZodEnum<{
|
|
1624
|
+
render: "render";
|
|
1625
|
+
mirror: "mirror";
|
|
1626
|
+
asset: "asset";
|
|
1627
|
+
}>;
|
|
1628
|
+
name: z.ZodString;
|
|
1629
|
+
base64: z.ZodString;
|
|
1630
|
+
}, z.core.$strict>>>;
|
|
1631
|
+
error: z.ZodOptional<z.ZodObject<{
|
|
1632
|
+
code: z.ZodEnum<{
|
|
1633
|
+
NOT_FOUND: "NOT_FOUND";
|
|
1634
|
+
REFUSED: "REFUSED";
|
|
1635
|
+
UNAVAILABLE: "UNAVAILABLE";
|
|
1636
|
+
ERROR: "ERROR";
|
|
1637
|
+
}>;
|
|
1638
|
+
message: z.ZodString;
|
|
1639
|
+
}, z.core.$strict>>;
|
|
1640
|
+
}, z.core.$strict>;
|
|
1519
1641
|
/**
|
|
1520
1642
|
* The remote instances' messages (slice D35), strict — what the hub's `handle('instance.state', …)` and the worker
|
|
1521
1643
|
* daemon's `handle('instance.tunnel.open', …)` are registered with. A tunnel's id follows the hub's rule for the bulk
|
package/lib/peers.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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()})};
|
|
1
|
+
"use strict";var X=Object.defineProperty;var v=(e,o)=>X(e,"name",{value:o,configurable:!0});var J=Object.defineProperty,C=v((e,o)=>J(e,"name",{value:o,configurable:!0}),"v"),Q=Object.defineProperty,i=C((e,o)=>Q(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 tt,CONVERSATION_LIST_MAX as N,CONVERSATION_TOOL_OUTPUT_CHARS as D,CONVERSATION_TURN_CHARS as et}from"./conversations.js";import{REMOTE_DASHBOARD_BASE_PATTERN as nt,REMOTE_INSTANCE_ID_PATTERN as M,REMOTE_INSTANCE_NAME_PREFIX as at}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}$/,CANVAS_CALL_TOOLS=["canvas_write","canvas_data","canvas_get","canvas_render","canvas_list","canvas_wait","canvas_comment","canvas_resource"],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","canvas.call"],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","canvas.call":"canvas phase 14"};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)}v(peerMaySend,"peerMaySend"),C(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}$/),P=t.string().regex(/^[0-9a-f]{64}$/),l=t.string().min(1).max(64).regex(/^[0-9A-Za-z.+_-]+$/),ot=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 rt=["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(rt),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 m=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:P}),"pair.accepted":t.strictObject({proof:P,name:d(64),model:d(40),words:ot,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}$/),L=t.string().regex(/^[0-9a-f]{64}$/),B=t.string().regex(/^[0-9a-f]{16}$/),u=t.number().int().min(0).max(1e7),_=t.string().min(1).max(250).regex(/^[A-Za-z0-9._/-]+$/),j=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:j,at:n}),it=t.strictObject({outcome:t.enum(["merged","fast-forward","current","conflicts","waiting","refused"]),at:n,why:j,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()}),H=t.enum(["in-step","fast-forward","ahead","waiting","to-update","not-following","off-branch"]);export const MAIN_MIRROR_SCHEMAS={"bundle.sent":t.strictObject({bundleId:B,repository:y,refs:t.array(_).length(1),size:t.number().int().positive().max(MAIN_MIRROR.maxSendBytes),sha256:L}),"main.moved":t.strictObject({repository:y,branch:_,sha:r,bundle:t.strictObject({id:B,size:t.number().int().positive(),sha256:L}),verdict:Z.optional(),at:n}),"main.state":t.strictObject({repository:y,branch:_,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:H,update:it.optional(),at:n})},MAIN_MIRROR_ANSWER_SCHEMAS={"bundle.sent":t.strictObject({took:t.boolean(),ref:_,sha:r.optional(),code:t.string().max(40).optional(),why:j.optional(),verdict:Z.optional()}),"main.moved":t.strictObject({took:t.boolean(),needWhole:t.boolean().optional(),why:j.optional(),follow:H.optional(),head:r.optional()})};const st=t.string().regex(/^[A-Za-z0-9][A-Za-z0-9._-]{0,62}$/),w=t.string().regex(/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/),W=t.string().regex(/^[0-9a-f]{16,64}$/),b=t.string().regex(/^[A-Za-z0-9][A-Za-z0-9_-]{7,79}$/),U=i(e=>t.string().min(1).max(e).regex(s),"sentence"),p=t.record(t.string(),t.unknown()),lt=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:m,job:st,candidate:w,repository:W,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(lt,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:m,why:U(300)}),"job.state":t.strictObject({runId:m,at:n,started:t.literal(!0).optional(),state:t.enum(["queued","running"]).optional(),note:t.string().max(1e3).optional(),queue:p.optional(),docker:p.optional(),edgePort:t.number().int().min(1024).max(65535).optional()}),"job.stage":t.strictObject({runId:m,stage:U(120),at:n}),"job.done":t.strictObject({runId:m,at:n,state:t.enum(["passed","failed","errored","cancelled","timeout"]),note:t.string().max(1e3).optional(),step:p.optional(),docker:p.optional(),givenBack:t.strictObject({why:t.string().min(1).max(1e3)}).optional(),refused:t.strictObject({why:t.string().min(1).max(1e3)}).optional(),proof:p.optional()}),"bundle.ready":t.strictObject({runId:m.optional(),bundleId:b,repository:W,heads:t.array(w).min(1).max(16),basis:t.array(w).max(256).optional(),size:t.number().int().positive().max(64*1024*1024*1024),sha256:t.string().regex(/^[0-9a-f]{64}$/),shipment:p.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:m,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()}),CANVAS_CALL_LIMITS={inputBytes:400*1024,answerBytes:480*1024,fileBytes:300*1024,waitSliceMs:2e4},CANVAS_CALL_FILE_NAME=/^cv-[0-9a-f]{16}[A-Za-z0-9._-]{0,80}\.(?:png|html|mdx|json|jpg|webp|gif|txt|md|csv)$/,CANVAS_WORKER_FILE="lensmcp-worker:",CanvasCallSchema=t.strictObject({v:t.literal(1),kind:t.literal("canvas.call"),id:t.string().regex(/^[A-Za-z0-9._:-]{1,100}$/),tool:t.enum(CANVAS_CALL_TOOLS),input:t.record(t.string(),t.unknown()),caller:t.strictObject({session:t.string().max(200).optional(),client:t.string().max(200).optional()}).optional(),launchKey:t.string().min(16).max(512)}),CanvasReplySchema=t.strictObject({v:t.literal(1),kind:t.literal("canvas.reply"),id:t.string().max(100),result:t.record(t.string(),t.unknown()).optional(),image:t.string().max(200).optional(),files:t.array(t.strictObject({kind:t.enum(["render","mirror","asset"]),name:t.string().regex(CANVAS_CALL_FILE_NAME),base64:t.string().regex(/^[A-Za-z0-9+/]*={0,2}$/)})).max(8).optional(),error:t.strictObject({code:t.enum(["NOT_FOUND","REFUSED","UNAVAILABLE","ERROR"]),message:t.string().max(4e3)}).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(M)}),"instance.state":t.strictObject({instanceId:t.string().regex(M),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(at).optional(),dashboardBase:t.string().regex(nt).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),ct=t.string().regex(PEER_LAUNCH_KEY_PATTERN),V=t.string().regex(/^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i),mt=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"),S=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:S,task:V.optional(),role:mt,by:S,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:ct,lensmcp:l,resume:t.strictObject({launchId:x,threadId:V,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:S.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 E=t.string().regex(/^[A-Za-z0-9._:-]{1,100}$/),F=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}$/)}),pt=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:E,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:pt,base:g,bundle:F,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:E,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:E,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:E,main:t.strictObject({branch:t.string().min(1).max(200).regex(/^[A-Za-z0-9._/-]+$/),sha:g,bundle:F}),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 I=t.string().regex(tt),Y=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),gt=t.strictObject({id:I,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:I.optional()}),dt=t.strictObject({seq:k,at:n.optional(),kind:t.enum(["prompt","reply","tool","compaction","subagent"]),text:a(et),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(D).optional()}).optional(),files:t.array(t.string().min(1).max(4096)).max(50).optional()}),ut=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(N).optional()}),h=t.record(t.string(),t.unknown()),bt=t.discriminatedUnion("what",[t.strictObject({what:t.literal("list"),query:ut}),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:Y,macBasis:t.string().regex(/^[\w-]{8,128}$/),conversations:t.array(t.strictObject({row:gt,turns:t.array(dt).max(CONVERSATION_PEER_LIMITS.turns),settles:t.array(t.strictObject({seq:k,outcome:t.enum(["ok","error"]),output:a(D).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:Y,ask:bt})},CONVERSATION_PEER_ANSWER_SCHEMAS={"conversation.sync":t.strictObject({v:t.literal(1),held:t.array(t.strictObject({id:I,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(N),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 c=Object.defineProperty;var a=(r,e)=>c(r,"name",{value:e,configurable:!0});var l=Object.defineProperty,o=a((r,e)=>l(r,"name",{value:e,configurable:!0}),"o"),f=Object.defineProperty,p=o((r,e)=>f(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}`}a(perfRuleFingerprint,"perfRuleFingerprint"),o(perfRuleFingerprint,"perfRuleFingerprint"),p(perfRuleFingerprint,"perfRuleFingerprint");export function perfRuleScanFingerprint(r,e){return`perf-rule-scan:${r}:${e}`}a(perfRuleScanFingerprint,"perfRuleScanFingerprint"),o(perfRuleScanFingerprint,"perfRuleScanFingerprint"),p(perfRuleScanFingerprint,"perfRuleScanFingerprint");const s=/^[a-z][a-z0-9-]*\/[a-z0-9][a-z0-9-]*$/,d=12,y=4e3,t=p((r,e=y)=>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(u=>t(u,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>d||!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}a(asPerfRuleRaw,"asPerfRuleRaw"),o(asPerfRuleRaw,"asPerfRuleRaw"),p(asPerfRuleRaw,"asPerfRuleRaw");
|
package/lib/pod-memory.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var n=Object.defineProperty;var o=(r,e)=>n(r,"name",{value:e,configurable:!0});var d=Object.defineProperty,t=o((r,e)=>d(r,"name",{value:e,configurable:!0}),"r"),m=Object.defineProperty,i=t((r,e)=>m(r,"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(r){if(!r||typeof r!="object")return;const e=r;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 r}o(asPodMemoryRaw,"asPodMemoryRaw"),t(asPodMemoryRaw,"asPodMemoryRaw"),i(asPodMemoryRaw,"asPodMemoryRaw");
|
package/lib/producer-health.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var R=Object.defineProperty;var i=(e,o)=>R(e,"name",{value:o,configurable:!0});var $=Object.defineProperty,d=i((e,o)=>$(e,"name",{value:o,configurable:!0}),"i"),b=Object.defineProperty,m=d((e,o)=>b(e,"name",{value:o,configurable:!0}),"u");import{z as r}from"zod";export const ProducerStateSchema=r.enum(["none","connected"]),ProducerRunStatusSchema=r.enum(["running","clean","failing","error"]),ProducerReportSchema=r.object({id:r.string(),tool:r.string(),project:r.string().optional(),firstReportedAt:r.number().int().nonnegative(),lastReportedAt:r.number().int().nonnegative(),lastRunStatus:ProducerRunStatusSchema,lastRunDurationMs:r.number().int().nonnegative().optional(),errorCount:r.number().int().nonnegative(),warningCount:r.number().int().nonnegative().optional(),error:r.string().optional()}),ProducerHealthSchema=r.object({producer:ProducerStateSchema,producers:r.array(ProducerReportSchema),lastReportedAt:r.number().int().nonnegative().optional(),ageMs:r.number().int().nonnegative().optional(),stale:r.boolean(),detail:r.string()}),PRODUCER_STALE_AFTER_MS=10*6e4;export function summariseProducers(e){const o=e.now??Date.now(),t=[...e.producers].sort((n,h)=>h.lastReportedAt-n.lastReportedAt);if(t.length===0)return{producer:"none",producers:[],stale:!1,detail:`No ${e.domain} producer has ever reported into this session \u2014 this is NOT a clean result, nothing is watching. ${e.noProducerHint}`};const l=t[0].lastReportedAt,u=Math.max(0,o-l),p=u>PRODUCER_STALE_AFTER_MS,g=t.filter(n=>n.lastRunStatus==="failing"),s=t.filter(n=>n.lastRunStatus==="error"),a=[`${t.length} ${e.domain} producer${t.length===1?"":"s"} reporting (${t.map(n=>n.id).join(", ")}); newest report ${c(u)}.`];return s.length>0&&a.push(`${s.length} produced NO verdict (the tool itself failed): ${s.map(n=>`${n.id} \u2014 ${n.error??"unknown error"}`).join("; ")}.`),g.length>0&&a.push(`${g.length} reporting errors.`),p&&a.push(`Older than ${Math.round(PRODUCER_STALE_AFTER_MS/6e4)}m \u2014 the verdict may predate the current source.`),{producer:"connected",producers:t,lastReportedAt:l,ageMs:u,stale:p,detail:a.join(" ")}}i(summariseProducers,"summariseProducers"),d(summariseProducers,"summariseProducers"),m(summariseProducers,"summariseProducers");function c(e){return e<1e3?"just now":e<6e4?`${Math.round(e/1e3)}s ago`:e<36e5?`${Math.round(e/6e4)}m ago`:`${Math.round(e/36e5)}h ago`}i(c,"g"),d(c,"g"),m(c,"describeAge");
|