@lensmcp/protocol-types 1.26.2 → 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 +13 -1
- package/index.js +1 -1
- package/lib/ai-call-groups.js +2 -2
- package/lib/ai-call-row.js +3 -3
- package/lib/ai-call.js +9 -9
- package/lib/ai-context.js +6 -6
- package/lib/ai-origins.js +9 -9
- package/lib/bounded-clone.js +1 -1
- package/lib/bounded-map.js +1 -1
- package/lib/bounded-writer.js +1 -1
- package/lib/capture-demand.js +1 -1
- package/lib/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-path.js +1 -1
- package/lib/dashboard-updates.d.ts +80 -0
- package/lib/dashboard-updates.js +1 -0
- package/lib/dashboard.d.ts +8 -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/error-cause.js +5 -5
- package/lib/error-dismissal.js +1 -1
- package/lib/event-loop.js +1 -1
- package/lib/expected-failure.js +2 -2
- package/lib/flood-guard.js +1 -1
- package/lib/goal-design.js +1 -1
- 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/lint-coverage.js +1 -1
- package/lib/log-query.js +1 -1
- package/lib/main-mirror.d.ts +117 -0
- package/lib/main-mirror.js +1 -0
- package/lib/metrics-reset.js +1 -1
- package/lib/overseer-findings.js +1 -1
- package/lib/peers.d.ts +1881 -0
- package/lib/peers.js +1 -0
- package/lib/perf-rules.js +1 -1
- package/lib/pod-memory.js +1 -1
- package/lib/producer-health.js +1 -1
- 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/sources.js +1 -1
- package/lib/static-checks.d.ts +290 -0
- package/lib/static-checks.js +1 -0
- package/lib/system-report.js +1 -1
- package/lib/team-delivery.d.ts +13 -0
- package/lib/team.d.ts +60 -2
- package/lib/team.js +1 -1
- package/lib/workspace-actions.d.ts +104 -1
- package/lib/workspace-actions.js +1 -1
- package/package.json +1 -1
package/lib/peers.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var G=Object.defineProperty;var w=(t,a)=>G(t,"name",{value:a,configurable:!0});var K=Object.defineProperty,v=w((t,a)=>K(t,"name",{value:a,configurable:!0}),"w"),U=Object.defineProperty,s=v((t,a)=>U(t,"name",{value:a,configurable:!0}),"r");import{z as e}from"zod";import{RUN_ID_PATTERN as I}from"./docker-jobs.js";import{REMOTE_DASHBOARD_BASE_PATTERN as F,REMOTE_INSTANCE_ID_PATTERN as z,REMOTE_INSTANCE_NAME_PREFIX as Y}from"./remote-instances.js";export const PEER_PROTOCOL="peer/v1",PEER_PORT=7466,PEER_TIMING={pingMs:5e3,lostMs:45e3,windowMs:10*6e4,approveMs:10*6e4,capacityMs:3e4},PAIRING_CODE={length:10,tries:5},CROCKFORD_ALPHABET="0123456789ABCDEFGHJKMNPQRSTVWXYZ",PEER_PATHS={pair:"/peer/v1/pair",control:"/peer/v1/control",runs:"/peer/v1/runs/",bundles:"/peer/v1/bundles/",sent:"/peer/v1/sent/",tunnel:"/peer/v1/tunnel/"},RUN_UPLOAD_KINDS=["log","samples","events","artifacts"],PEER_FILES={dir:"peers",key:"identity.key",cert:"identity.crt",window:"window.json",workers:"workers.json",organizer:"organizer.json",hub:"hub.json",hubLock:"hub.lock",hubLog:"hub.log",runs:"runs",instances:"instances"},FINGERPRINT_PATTERN=/^[0-9a-f]{64}$/,REMOTE_RUN_LOST="lost",PEER_MESSAGE_ID=/^[A-Za-z0-9_-]{1,64}$/,TO_WORKER=["job.offer","job.cancel","bundle.ready","tunnel.open","tunnel.close","launch.start","launch.stop","store.reply","version.install","main.moved","instance.tunnel.open","goal.place","goal.changes","goal.update"],TO_ORGANIZER=["hello","capacity","job.state","job.stage","job.done","bundle.sent","launch.state","launch.tail","store.call","version.state","forget","main.state","instance.state","store.read","goal.sent"],EITHER_WAY=["ping"],PEER_REPLIES=["ack","error","pong"],PEER_MESSAGE_SLICE={hello:"D12 (versions: D13, capacity: D14)",ping:"D12",pong:"D12",ack:"D12",error:"D12",forget:"D11",capacity:"D14","job.offer":"D14","job.cancel":"D14/D18","job.state":"D14/D16","job.stage":"D16","job.done":"D16","bundle.ready":"D15","bundle.sent":"D34 (goal branches: D30)","tunnel.open":"D17","tunnel.close":"D17","launch.start":"D29","launch.stop":"D29","launch.state":"D29","launch.tail":"D29","store.call":"D27/D28","store.reply":"D27/D28","version.install":"D13","version.state":"D13","main.moved":"D34","main.state":"D34","instance.tunnel.open":"D35","instance.state":"D35 (sent by D30)","store.read":"D32","goal.place":"D30","goal.sent":"D30","goal.changes":"D30","goal.update":"D30"};const h=s((t,a)=>t.includes(a),"has");export const isPeerMessageType=s(t=>Object.prototype.hasOwnProperty.call(PEER_MESSAGE_SLICE,t),"isPeerMessageType");export function peerMaySend(t,a){return h(EITHER_WAY,a)||h(PEER_REPLIES,a)?!0:h(t==="organizer"?TO_WORKER:TO_ORGANIZER,a)}w(peerMaySend,"peerMaySend"),v(peerMaySend,"peerMaySend"),s(peerMaySend,"peerMaySend");export const isPeerReply=s(t=>h(PEER_REPLIES,t),"isPeerReply");const l=/^[^\p{Cc}\p{Cf}\p{Zl}\p{Zp}]*$/u,m=s(t=>e.string().min(1).max(t).regex(l),"shownText"),D=e.string().regex(/^[A-Za-z0-9_-]{43}$/),$=e.string().regex(/^[0-9a-f]{64}$/),r=e.string().min(1).max(64).regex(/^[0-9A-Za-z.+_-]+$/),q=e.tuple([e.string().regex(/^[a-z]{3,8}$/),e.string().regex(/^[a-z]{3,8}$/),e.string().regex(/^[a-z]{3,8}$/),e.string().regex(/^[a-z]{3,8}$/)]),n=e.number().int().nonnegative();export const PeerEnvelopeSchema=e.strictObject({v:e.literal(1),id:e.string().regex(PEER_MESSAGE_ID),replyTo:e.string().regex(PEER_MESSAGE_ID).optional(),type:e.string().min(1).max(40),body:e.record(e.string(),e.unknown())});const X=["unknown-type","wrong-direction","bad-message","hello-first","not-handled","too-large","busy","refused","timeout","lost","internal","no-window","window-used","window-closed","wrong-code","protocol"];export const PeerErrorBodySchema=e.strictObject({code:e.enum(X),message:e.string().max(500),triesLeft:e.number().int().min(0).max(PAIRING_CODE.tries).optional(),retryAfterMs:e.number().int().min(0).max(36e5).optional()});const c=e.string().regex(I);export const WorkerAdvertSchema=e.record(e.string(),e.unknown()).superRefine((t,a)=>{const x=t.runs;x!==void 0&&(!Array.isArray(x)||x.length>256||!x.every(S=>typeof S=="string"&&I.test(S)))&&a.addIssue({code:"custom",message:"runs: at most 256 run ids"})}),PEER_BODY_SCHEMAS={hello:e.strictObject({protocol:e.literal(PEER_PROTOCOL),lensmcp:r,follow:e.boolean().optional(),store:e.array(r).max(64).optional(),capacity:WorkerAdvertSchema.optional()}),ping:e.strictObject({at:n}),pong:e.strictObject({at:n}),ack:e.strictObject({result:e.unknown().optional()}),error:PeerErrorBodySchema,forget:e.strictObject({why:e.string().max(200).regex(l).optional()})},PeerWelcomeSchema=e.strictObject({protocol:e.literal(PEER_PROTOCOL),lensmcp:r,name:m(64),inStep:e.boolean().optional(),why:e.string().max(500).optional()}),PAIR_BODY_SCHEMAS={"pair.hello":e.strictObject({protocol:e.literal(PEER_PROTOCOL),nonce:D,name:m(64),model:m(40),lensmcp:r}),"pair.resume":e.strictObject({protocol:e.literal(PEER_PROTOCOL)}),"pair.challenge":e.strictObject({nonce:D}),"pair.proof":e.strictObject({proof:$}),"pair.accepted":e.strictObject({proof:$,name:m(64),model:m(40),words:q,approveBy:n}),"pair.approved":e.strictObject({at:n}),"pair.declined":e.strictObject({why:e.string().max(500)}),error:PeerErrorBodySchema},MAIN_MIRROR={branch:"main",quietMs:10*6e4,snapshotEveryMs:60*6e4,maxSendBytes:512*1024*1024,maxWipBytes:256*1024*1024,maxHaves:16},MAIN_BRING_IN=["in-main","brought-in","waiting","not-ff","refused"],MAIN_FOLLOW_STATES=["in-step","fast-forward","ahead","waiting","to-update","not-following","off-branch"];const o=e.string().regex(/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/),f=e.string().regex(/^[0-9a-f]{16,64}$/),M=e.string().regex(/^[0-9a-f]{64}$/),k=e.string().regex(/^[0-9a-f]{16}$/),d=e.number().int().min(0).max(1e7),O=e.string().min(1).max(250).regex(/^[A-Za-z0-9._/-]+$/),y=e.string().max(1e3),P=e.strictObject({state:e.enum(["in-main","brought-in","waiting","not-ff","refused"]),count:d,sha:o.optional(),main:o.optional(),why:y,at:n}),J=e.strictObject({outcome:e.enum(["merged","fast-forward","current","conflicts","waiting","refused"]),at:n,why:y,sha:o.optional(),conflicts:e.array(e.string().min(1).max(4096)).max(200).optional(),asked:e.array(e.strictObject({who:e.enum(["person","manager"]),goal:e.string().max(64).optional(),to:e.string().max(200).optional()})).max(20).optional()}),T=e.enum(["in-step","fast-forward","ahead","waiting","to-update","not-following","off-branch"]);export const MAIN_MIRROR_SCHEMAS={"bundle.sent":e.strictObject({bundleId:k,repository:f,refs:e.array(O).length(1),size:e.number().int().positive().max(MAIN_MIRROR.maxSendBytes),sha256:M}),"main.moved":e.strictObject({repository:f,branch:O,sha:o,bundle:e.strictObject({id:k,size:e.number().int().positive(),sha256:M}),verdict:P.optional(),at:n}),"main.state":e.strictObject({repository:f,branch:O,head:o.optional(),organizerHead:o.optional(),haves:e.array(o).max(MAIN_MIRROR.maxHaves),notSent:d,toPull:d,uncommitted:e.strictObject({files:d,changedAt:n.optional()}),snapshot:e.strictObject({sha:o,at:n,files:d,sent:e.boolean()}).optional(),follow:T,update:J.optional(),at:n})},MAIN_MIRROR_ANSWER_SCHEMAS={"bundle.sent":e.strictObject({took:e.boolean(),ref:O,sha:o.optional(),code:e.string().max(40).optional(),why:y.optional(),verdict:P.optional()}),"main.moved":e.strictObject({took:e.boolean(),needWhole:e.boolean().optional(),why:y.optional(),follow:T.optional(),head:o.optional()})};const Q=e.string().regex(/^[A-Za-z0-9][A-Za-z0-9._-]{0,62}$/),_=e.string().regex(/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/),C=e.string().regex(/^[0-9a-f]{16,64}$/),u=e.string().regex(/^[A-Za-z0-9][A-Za-z0-9_-]{7,79}$/),N=s(t=>e.string().min(1).max(t).regex(l),"sentence"),p=e.record(e.string(),e.unknown()),V=e.string().regex(/^[A-Za-z_][A-Za-z0-9_]{0,99}$/),i=e.strictObject({lensmcp:r,protocol:e.string().regex(/^peer\/v[1-9]\d{0,3}$/)});export const PEER_WORK_SCHEMAS={capacity:WorkerAdvertSchema,"job.offer":e.strictObject({runId:c,job:Q,candidate:_,repository:C,lane:e.enum(["light","heavy"]).optional(),kind:e.enum(["compose","testcontainers","playwright"]).optional(),hostMb:e.number().int().min(0).max(1024*1024).optional(),vmMb:e.number().int().min(0).max(1024*1024).optional(),proof:e.boolean().optional(),timeoutMinutes:e.number().positive().max(360).optional(),secrets:e.record(V,e.string().min(1).max(8192)).refine(t=>Object.keys(t).length<=16,"at most 16 secrets").optional(),origin:e.string().max(300).regex(/^https?:\/\/[A-Za-z0-9.-]+(?::\d{1,5})?$/).optional()}),"job.cancel":e.strictObject({runId:c,why:N(300)}),"job.state":e.strictObject({runId:c,at:n,started:e.literal(!0).optional(),state:e.enum(["queued","running"]).optional(),note:e.string().max(1e3).optional(),queue:p.optional(),docker:p.optional(),edgePort:e.number().int().min(1024).max(65535).optional()}),"job.stage":e.strictObject({runId:c,stage:N(120),at:n}),"job.done":e.strictObject({runId:c,at:n,state:e.enum(["passed","failed","errored","cancelled","timeout"]),note:e.string().max(1e3).optional(),step:p.optional(),docker:p.optional(),givenBack:e.strictObject({why:e.string().min(1).max(1e3)}).optional(),refused:e.strictObject({why:e.string().min(1).max(1e3)}).optional(),proof:p.optional()}),"bundle.ready":e.strictObject({runId:c.optional(),bundleId:u,repository:C,heads:e.array(_).min(1).max(16),basis:e.array(_).max(256).optional(),size:e.number().int().positive().max(64*1024*1024*1024),sha256:e.string().regex(/^[0-9a-f]{64}$/),shipment:p.optional(),blobs:e.record(e.string().regex(/^[0-9a-f]{64}$/),u).refine(t=>Object.keys(t).length<=101,"at most 101 blobs").optional()}),"tunnel.open":e.strictObject({tunnelId:u,runId:c,port:e.number().int().min(1).max(65535).optional()}),"tunnel.close":e.strictObject({tunnelId:u,why:e.string().max(300).optional()}),"version.install":e.strictObject({version:r,from:e.enum(["registry","organizer"]),tarball:e.strictObject({bundleId:u,sha256:e.string().regex(/^[0-9a-f]{64}$/),size:e.number().int().positive().max(8*1024*1024*1024)}).optional()}),"version.state":e.discriminatedUnion("state",[e.strictObject({state:e.literal("in-step"),worker:i,organizer:i}),e.strictObject({state:e.literal("installing"),worker:i,organizer:i,from:e.enum(["registry","organizer"]),since:n}),e.strictObject({state:e.literal("waiting-for-person"),worker:i,organizer:i,stored:e.boolean()}),e.strictObject({state:e.literal("out-of-step"),worker:i,organizer:i,why:e.object({kind:e.enum(["protocol","version","installed","restarting","install-failed","restart-failed","no-store"])}).catchall(e.union([e.string().max(600),e.number(),e.boolean()]))})])},STORE_CALL_LIMITS={args:16,argsBytes:256*1024,answerBytes:480*1024},PEER_LAUNCH_KEY_PATTERN=/^[A-Za-z0-9_-]{43}$/;const L=e.strictObject({added:e.number().int().nonnegative().nullable(),removed:e.number().int().nonnegative().nullable()});export const StoreCallSchema=e.strictObject({v:e.literal(1),kind:e.literal("store.call"),id:e.string().regex(/^[A-Za-z0-9._:-]{1,100}$/),method:e.string().regex(/^[A-Za-z][A-Za-z0-9]{0,79}$/),args:e.array(e.unknown()).max(STORE_CALL_LIMITS.args),launchKey:e.string().min(16).max(512),observe:e.strictObject({intervalMs:e.number().int().min(0).max(864e5).optional(),snapshot:e.strictObject({branch:e.string().max(300).nullable(),head:e.string().regex(/^[0-9a-f]{40}(?:[0-9a-f]{24})?$/).nullable(),files:e.array(e.strictObject({path:e.string().min(1).max(4096),from:e.string().max(4096).optional(),status:e.string().max(2),staged:L.optional(),unstaged:L.optional()})).max(1e3),truncated:e.boolean()}).optional(),failed:e.literal(!0).optional()}).optional()}),StoreReplySchema=e.strictObject({v:e.literal(1),kind:e.literal("store.reply"),id:e.string().max(100),wrote:e.boolean(),result:e.unknown().optional(),error:e.strictObject({name:e.enum(["CoordinationError","CapacityRefusal","CoordinationBusyError","StoreCallRefused","Error"]),message:e.string().max(4e3),room:e.record(e.string(),e.unknown()).optional(),step:e.enum(["open","write","commit","read"]).optional(),waitedMs:e.number().nonnegative().optional(),tries:e.number().int().nonnegative().optional(),wrote:e.boolean().optional(),where:e.string().max(300).optional(),wal:e.boolean().optional()}).optional()}),REMOTE_INSTANCE_BODY_SCHEMAS={"instance.tunnel.open":e.strictObject({tunnelId:e.string().regex(/^[A-Za-z0-9][A-Za-z0-9_-]{7,79}$/),instanceId:e.string().regex(z)}),"instance.state":e.strictObject({instanceId:e.string().regex(z),state:e.enum(["up","gone"]),apex:e.string().max(253).regex(/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*\.localhost$/).startsWith(Y).optional(),dashboardBase:e.string().regex(F).optional(),at:n,why:e.string().max(500).regex(l).optional()})},PEER_LAUNCH_LIMITS={promptChars:64*1024,roleTextChars:64*1024,maxMinutes:720,tailLines:40,tailLineChars:400},PEER_LAUNCH_ID=/^ln-[a-z0-9]{1,12}-[a-f0-9]{6}$/;const b=e.string().regex(PEER_LAUNCH_ID),ee=e.string().regex(PEER_LAUNCH_KEY_PATTERN),Z=e.string().regex(/^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i),te=e.string().regex(/^[a-z][a-z0-9-]{0,39}$/),B=s(t=>e.string().min(1).max(t).regex(/^[A-Za-z0-9][A-Za-z0-9._:/@[\]-]*$/),"clientWord"),A=e.string().min(2).max(1024).regex(/^\/[^\0\r\n]*$/).refine(t=>!t.split("/").includes(".."),"no .. part"),R=e.string().min(1).max(100).regex(/^[A-Za-z0-9._:-]+$/);export const PEER_LAUNCH_SCHEMAS={"launch.start":e.strictObject({launchId:b,repository:f,goal:R,task:Z.optional(),role:te,by:R,client:e.enum(["claude","codex"]),model:B(80).optional(),effort:B(40).optional(),worktree:A.optional(),placedGoal:e.literal(!0).optional(),prompt:e.string().min(1).max(PEER_LAUNCH_LIMITS.promptChars),roleText:e.string().max(PEER_LAUNCH_LIMITS.roleTextChars).optional(),name:e.string().min(1).max(80).regex(l).optional(),maxMinutes:e.number().int().min(1).max(PEER_LAUNCH_LIMITS.maxMinutes),account:e.string().regex(/^ac-[a-z0-9]{1,12}-[a-f0-9]{6}$/).optional(),launchKey:ee,lensmcp:r,resume:e.strictObject({launchId:b,threadId:Z,from:A.optional()}).optional(),capKind:e.enum(["writers","checkers"]).optional()}).refine(t=>t.worktree===void 0!=(t.placedGoal===void 0),"a launch names its worktree, or that its goal is placed there \u2014 exactly one"),"launch.stop":e.strictObject({launchId:b,why:e.string().max(300).regex(l).optional()}),"launch.state":e.strictObject({launchId:b,state:e.enum(["running","exited","stopped","failed"]),at:n,pid:e.number().int().min(0).max(99999999).optional(),exitCode:e.number().int().min(-1).max(1024).optional(),endedAt:n.optional(),threadId:R.optional(),ended:e.strictObject({quota:e.strictObject({client:e.enum(["claude","codex"]),why:e.string().min(1).max(300),until:n,firstTurn:e.boolean(),account:e.string().max(40).optional()}).optional(),context:e.string().min(1).max(600).optional()}).optional()}),"launch.tail":e.strictObject({launchId:b,lines:e.array(e.string().max(PEER_LAUNCH_LIMITS.tailLineChars+8)).max(PEER_LAUNCH_LIMITS.tailLines),at:n})},LaunchStartedSchema=e.strictObject({started:e.literal(!0),pid:e.number().int().min(2).max(99999999),worktree:A,branch:e.string().max(250).optional(),startedAt:n,deadline:n,threadId:e.string().max(200).optional(),lensmcp:r}),STORE_READ_LIMITS={calls:24,argsBytes:64*1024,answerBytes:STORE_CALL_LIMITS.answerBytes},StoreReadSchema=e.strictObject({v:e.literal(1),kind:e.literal("store.read"),id:e.string().regex(/^[A-Za-z0-9._:-]{1,100}$/),repoId:e.string().regex(/^[0-9a-f]{16,64}$/),calls:e.array(e.strictObject({method:e.string().regex(/^[A-Za-z][A-Za-z0-9]{0,79}$/),args:e.array(e.unknown()).max(STORE_CALL_LIMITS.args)})).min(1).max(STORE_READ_LIMITS.calls)}),GOAL_ON_WORKER={maxSendBytes:512*1024*1024,maxChangesBytes:400*1024,branchPrefix:"lensmcp/g-"};const j=e.string().regex(/^[A-Za-z0-9._:-]{1,100}$/),H=e.strictObject({id:e.string().regex(/^[0-9a-f]{16}$/),size:e.number().int().positive().max(64*1024*1024*1024),sha256:e.string().regex(/^[0-9a-f]{64}$/)}),ne=e.string().min(1).max(200).regex(/^lensmcp\/g-[a-z0-9-]{1,30}$/),g=e.string().regex(/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/),W=e.string().regex(/^[0-9a-f]{16,64}$/),E=e.string().max(1e3);export const GOAL_PEER_SCHEMAS={"goal.place":e.strictObject({goal:j,title:e.string().min(1).max(300).regex(l),repository:W,worktreeId:e.string().regex(/^[0-9a-f]{24}$/),name:e.string().regex(/^g-[a-z0-9](?:[a-z0-9-]{0,17}[a-z0-9])?$/),branch:ne,base:g,bundle:H,services:e.enum(["on-demand","none","always"]).optional(),at:n}),"goal.sent":e.strictObject({bundleId:e.string().regex(/^[0-9a-f]{16}$/),repository:W,goal:j,ref:e.string().min(1).max(250).regex(/^heads\/lensmcp\/g-[a-z0-9-]{1,30}$/),size:e.number().int().positive().max(GOAL_ON_WORKER.maxSendBytes),sha256:e.string().regex(/^[0-9a-f]{64}$/)}),"goal.changes":e.strictObject({goal:j,what:e.enum(["row","files","diff","commits","commit","against"]),path:e.string().min(1).max(4096).optional(),sha:g.optional(),full:e.boolean().optional(),againstMain:e.boolean().optional()}),"goal.update":e.strictObject({goal:j,main:e.strictObject({branch:e.string().min(1).max(200).regex(/^[A-Za-z0-9._/-]+$/),sha:g,bundle:H}),at:n})},GOAL_PEER_ANSWER_SCHEMAS={"goal.place":e.strictObject({state:e.enum(["ready","creating","failed"]),head:g.optional(),onDemand:e.boolean().optional(),needWhole:e.boolean().optional(),why:E.optional()}),"goal.sent":e.strictObject({took:e.boolean(),ref:e.string().max(250),sha:g.optional(),mirror:e.enum(["created","fast-forward","current","not-ff","checked-out"]).optional(),told:e.string().max(200).optional(),code:e.string().max(40).optional(),why:E.optional()}),"goal.changes":e.strictObject({ok:e.boolean(),value:e.unknown().optional(),status:e.number().int().min(100).max(599).optional(),why:E.optional(),shortened:e.boolean().optional()}),"goal.update":e.strictObject({outcome:e.enum(["current","merged","asked","conflicts","refused"]),why:E,sha:g.optional(),behind:e.number().int().min(0).max(1e7).optional(),dirty:e.number().int().min(0).max(1e7).optional(),conflicts:e.array(e.string().min(1).max(4096)).max(200).optional(),needWhole:e.boolean().optional()})};
|
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");
|
package/lib/proof.d.ts
CHANGED
|
@@ -19,6 +19,25 @@ export interface RuntimeProofIdentity {
|
|
|
19
19
|
ran: string;
|
|
20
20
|
}>;
|
|
21
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Where a proof ran (planning/docker/00-plan.md § 12, slice D25): evidence, as `runtime` and `runnerHash` are — never a
|
|
24
|
+
* candidate input. A job run on a worker Mac and the same run on the organizer stand for the same candidate; this says
|
|
25
|
+
* which Mac it was. (`peers.ts` may name the same shape for the channel: this is the proof's own.)
|
|
26
|
+
*/
|
|
27
|
+
export interface ProofHost {
|
|
28
|
+
/** The peer that ran it, as the organizer knows it: `local` for the organizer's own Mac, else the worker's peer id. */
|
|
29
|
+
peer: string;
|
|
30
|
+
/** The Mac's name, as it calls itself (its host name). */
|
|
31
|
+
name: string;
|
|
32
|
+
/** Its processor, as Node names it: `arm64`, `x64`. */
|
|
33
|
+
arch: string;
|
|
34
|
+
/** Its system and release: `darwin 25.5.0`. */
|
|
35
|
+
os: string;
|
|
36
|
+
/** The Docker engine's version where the host said it (a worker's capacity) — absent where nothing asked Docker. */
|
|
37
|
+
docker?: string;
|
|
38
|
+
/** The LensMCP version that ran it. */
|
|
39
|
+
lensmcp: string;
|
|
40
|
+
}
|
|
22
41
|
/** Identity of a proof's source and declared execution inputs. Secret values are never retained. */
|
|
23
42
|
export interface ProofFingerprint {
|
|
24
43
|
version: 1;
|
|
@@ -42,10 +61,23 @@ export interface ProofFingerprint {
|
|
|
42
61
|
committed: string;
|
|
43
62
|
ran: string;
|
|
44
63
|
}>;
|
|
64
|
+
/**
|
|
65
|
+
* The Mac the proof ran on (slice D25). In the key, as `runtime` is — taken once per run, so before and after agree —
|
|
66
|
+
* and not a candidate input: a worker's proof and the organizer's of the same job, candidate and inputs differ here
|
|
67
|
+
* and nowhere else. Absent on proofs that do not say (every proof but a job's, for now).
|
|
68
|
+
*/
|
|
69
|
+
host?: ProofHost;
|
|
45
70
|
}
|
|
46
71
|
export interface ProofEvidence {
|
|
47
72
|
fingerprint?: ProofFingerprint;
|
|
48
73
|
eligible: boolean;
|
|
49
74
|
reason?: string;
|
|
50
75
|
verifiedAt?: number;
|
|
76
|
+
/**
|
|
77
|
+
* What a `lensmcp queue run` proof of a static check stands on (planning/checks § 8; CK-Q3): `exit-code` — the
|
|
78
|
+
* command's exit code alone, which cannot say what was checked (a `--work typecheck | lint | build | verify` run with
|
|
79
|
+
* no report); `coverage` — a `--report static-check` report that binds the result to the candidate and says what it
|
|
80
|
+
* covered. Absent on every other proof: a test run stands on its test report.
|
|
81
|
+
*/
|
|
82
|
+
basis?: 'exit-code' | 'coverage';
|
|
51
83
|
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* REMOTE INSTANCES — a goal's runtime on a worker Mac, opened from the organizer's URLs (planning/docker/00-plan.md § 13
|
|
3
|
+
* «The lens for a remote goal's runtime», slice D35; issues/open/overseer-74). What the peer hub (`apps/agent`
|
|
4
|
+
* `peers/remote-instance.ts`) and the dev gateway (`@lensmcp/cluster` `runtime/remote-instances.ts`) share:
|
|
5
|
+
*
|
|
6
|
+
* - the route the hub asks of the organizer's gateway on its control socket (`POST/GET/DELETE /remote-instance`) — the
|
|
7
|
+
* request, the answer, the refusals. The gateway's copy is written beside its code (cluster does not depend on this
|
|
8
|
+
* package); `remote-instances.contract.spec.ts` (cluster) fails when the two differ;
|
|
9
|
+
* - the worker's record of the instances it runs for its organizer (`~/.lensmcp/peer/instances.json`) — what its side of
|
|
10
|
+
* the tunnel reads before it lets a request through: the instance's apex, and its lens dashboard's host and base;
|
|
11
|
+
* - the lens's own host, `lensmcp.<apex>`, which both sides derive the same way.
|
|
12
|
+
*
|
|
13
|
+
* The channel's messages for it (`instance.tunnel.open`, `instance.state`) are in `peers.ts`, with the rest of the union.
|
|
14
|
+
* Pure, as the rest of this package.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* A remote instance's id: letters, digits, `_` and `-`, 8 to 40 characters — safe in a log line and a path, and short
|
|
18
|
+
* enough that `<home>/.lensmcp/peers/instances/<id>.sock` fits a unix socket's 103 bytes under a usual home.
|
|
19
|
+
*/
|
|
20
|
+
export declare const REMOTE_INSTANCE_ID_PATTERN: RegExp;
|
|
21
|
+
/**
|
|
22
|
+
* What a remote instance's name — its apex's first label — begins with: it is a goal's worktree on a worker, named as
|
|
23
|
+
* LensMCP names one (`g-<slug>-<id6>`). The organizer's gateway refuses any other name (a tenant's under the main
|
|
24
|
+
* checkout's wildcard would be taken from it), and the worker records no other.
|
|
25
|
+
*/
|
|
26
|
+
export declare const REMOTE_INSTANCE_NAME_PREFIX = "g-";
|
|
27
|
+
/** The longest lease of a remote instance's route (s): a hub that died leaves no route for longer. */
|
|
28
|
+
export declare const MAX_REMOTE_INSTANCE_SEC: number;
|
|
29
|
+
/**
|
|
30
|
+
* The label of a remote instance's lens host: `lensmcp.<apex>`. The worker's lens dashboard is served there, on an
|
|
31
|
+
* origin of its own — never under the organizer's dashboard host, whose session cookie and same-origin writes it would
|
|
32
|
+
* otherwise share.
|
|
33
|
+
*/
|
|
34
|
+
export declare const REMOTE_LENS_LABEL = "lensmcp";
|
|
35
|
+
/** The lens dashboard's base path as the worker's gateway serves it: ONE path segment (`/<instance key>`). */
|
|
36
|
+
export declare const REMOTE_DASHBOARD_BASE_PATTERN: RegExp;
|
|
37
|
+
/** `lensmcp.<apex>`: the remote instance's lens, on an origin of its own. */
|
|
38
|
+
export declare function remoteLensHost(apex: string): string;
|
|
39
|
+
/** `POST /remote-instance`. */
|
|
40
|
+
export interface RemoteInstanceRouteRequest {
|
|
41
|
+
/** The instance, as the hub names it ({@link REMOTE_INSTANCE_ID_PATTERN}): its socket is named for it. */
|
|
42
|
+
instanceId: string;
|
|
43
|
+
/** A workspace registered with this gateway — the main checkout of the instance's project: its apex is under that one's. */
|
|
44
|
+
wsKey: string;
|
|
45
|
+
/** The instance's apex as the worker's gateway serves it: `g-<goal>.<the workspace's apex>`. */
|
|
46
|
+
apex: string;
|
|
47
|
+
/** Its tunnel's socket: `<home>/.lensmcp/peers/instances/<instanceId>.sock`, and nothing else. */
|
|
48
|
+
socket: string;
|
|
49
|
+
/** How long the route lives unless asked again (s): more than 0, at most {@link MAX_REMOTE_INSTANCE_SEC}. */
|
|
50
|
+
forSec: number;
|
|
51
|
+
/** The instance's lens dashboard base path on the worker (`/<instance key>`): asked, its lens host is routed too. */
|
|
52
|
+
dashboardBase?: string;
|
|
53
|
+
}
|
|
54
|
+
/** A remote instance's routes as `/remote-instance` answers them. */
|
|
55
|
+
export interface RemoteInstanceRouteView {
|
|
56
|
+
instanceId: string;
|
|
57
|
+
wsKey: string;
|
|
58
|
+
apex: string;
|
|
59
|
+
/** Every host routed to its tunnel: the apex, `*.<apex>`, the workspace's hosts named under it, its lens host. */
|
|
60
|
+
hosts: string[];
|
|
61
|
+
/** Where a browser opens its app: `https://<apex>`, with the front door's port when it is not the scheme's own. */
|
|
62
|
+
origin: string;
|
|
63
|
+
socket: string;
|
|
64
|
+
/** Its lens: `lensmcp.<apex>` and the dashboard's base on the worker — `url` is what a browser opens. */
|
|
65
|
+
lens?: {
|
|
66
|
+
host: string;
|
|
67
|
+
base: string;
|
|
68
|
+
url: string;
|
|
69
|
+
};
|
|
70
|
+
registeredAt: number;
|
|
71
|
+
/** When it goes unless renewed (ms). */
|
|
72
|
+
expiresAt: number;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Why the gateway refused. `not-its-apex`: the apex is not one name in front of the workspace's. `instance-in-use`: the
|
|
76
|
+
* id is routed with another apex, workspace or lens — removed first. `no-socket`: nothing of this user's serves the
|
|
77
|
+
* socket (none there, not a socket, a link, another user's, open to others). `no-instance-route`: a GET of an id that
|
|
78
|
+
* is not routed.
|
|
79
|
+
*/
|
|
80
|
+
export type RemoteInstanceRouteRefusalCode = 'bad-request' | 'no-workspace' | 'no-apex' | 'apex-not-loopback' | 'not-its-apex' | 'instance-in-use' | 'host-conflict' | 'no-socket' | 'too-many-instances' | 'no-instance-route';
|
|
81
|
+
/** Why a request was refused: a code, and one sentence a person or the hub's log can act on. */
|
|
82
|
+
export interface RemoteInstanceRouteRefusal {
|
|
83
|
+
error: RemoteInstanceRouteRefusalCode;
|
|
84
|
+
message: string;
|
|
85
|
+
/** `bad-request`: the field that is wrong. */
|
|
86
|
+
field?: string;
|
|
87
|
+
/** The host that is held. */
|
|
88
|
+
host?: string;
|
|
89
|
+
/** Who holds it: `workspace '<key>' (<project>)`, `run '<id>'`, `remote instance '<id>'`, the dashboard, a parked worktree. */
|
|
90
|
+
heldBy?: string;
|
|
91
|
+
/** `no-workspace`: the keys that are registered. */
|
|
92
|
+
workspaces?: string[];
|
|
93
|
+
/** `too-many-instances`: the cap. */
|
|
94
|
+
max?: number;
|
|
95
|
+
}
|
|
96
|
+
/** `~/.lensmcp/peer/instances.json`, under `LENSMCP_HOME` when it is set: the worker's record (0600, in its 0700 folder). */
|
|
97
|
+
export declare const REMOTE_INSTANCES_FILE = "instances.json";
|
|
98
|
+
/**
|
|
99
|
+
* An instance a worker runs for its organizer, as the worker recorded it when the instance came up (slice D30 writes
|
|
100
|
+
* it; D35's tunnel reads it). Nothing here comes from a message at the time of a request: what a tunnel stream may reach
|
|
101
|
+
* is decided by this record and the worker's own gateway alone.
|
|
102
|
+
*/
|
|
103
|
+
export interface RemoteInstanceRecord {
|
|
104
|
+
/** {@link REMOTE_INSTANCE_ID_PATTERN}. */
|
|
105
|
+
instanceId: string;
|
|
106
|
+
/** The organizer it runs for: its pinned certificate's fingerprint. An instance recorded for another organizer is never reached. */
|
|
107
|
+
organizer: string;
|
|
108
|
+
/** Its apex as the worker's gateway serves it: a `.localhost` name. A request reaches the instance only on it or a host beneath it. */
|
|
109
|
+
apex: string;
|
|
110
|
+
/**
|
|
111
|
+
* Its lens dashboard as the worker's gateway serves it: the dashboard host (`lensmcp.local`) and the instance's base
|
|
112
|
+
* path (`/<instance key>`). A request on `lensmcp.<apex>` reaches it under that base only — never the dashboard host's
|
|
113
|
+
* chooser, never another workspace's dashboard.
|
|
114
|
+
*/
|
|
115
|
+
dashboard?: {
|
|
116
|
+
host: string;
|
|
117
|
+
base: string;
|
|
118
|
+
};
|
|
119
|
+
/** The instance's checkout on the worker: evidence, never routed on. */
|
|
120
|
+
root?: string;
|
|
121
|
+
/** When it was recorded (ms). */
|
|
122
|
+
recordedAt: number;
|
|
123
|
+
}
|
|
124
|
+
/** Where the worker's own gateway serves browsers, as it says on its control socket (`GET /status` → `daemon.frontDoor`). */
|
|
125
|
+
export interface GatewayFrontDoor {
|
|
126
|
+
port: number;
|
|
127
|
+
/** It speaks TLS: dialled over TLS, as a browser does. */
|
|
128
|
+
tls: boolean;
|
|
129
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var r=Object.defineProperty;var t=(e,E)=>r(e,"name",{value:E,configurable:!0});var _=Object.defineProperty,o=t((e,E)=>_(e,"name",{value:E,configurable:!0}),"_"),n=Object.defineProperty,A=o((e,E)=>n(e,"name",{value:E,configurable:!0}),"o");export const REMOTE_INSTANCE_ID_PATTERN=/^[A-Za-z0-9][A-Za-z0-9_-]{7,39}$/,REMOTE_INSTANCE_NAME_PREFIX="g-",MAX_REMOTE_INSTANCE_SEC=14400,REMOTE_LENS_LABEL="lensmcp",REMOTE_DASHBOARD_BASE_PATTERN=/^\/[A-Za-z0-9][A-Za-z0-9._-]{0,99}$/;export function remoteLensHost(e){return`${REMOTE_LENS_LABEL}.${e.toLowerCase()}`}t(remoteLensHost,"remoteLensHost"),o(remoteLensHost,"remoteLensHost"),A(remoteLensHost,"remoteLensHost");export const REMOTE_INSTANCES_FILE="instances.json";
|
package/lib/resources.d.ts
CHANGED
|
@@ -337,6 +337,7 @@ declare const CheckEntrySchema: z.ZodObject<{
|
|
|
337
337
|
line: z.ZodOptional<z.ZodNumber>;
|
|
338
338
|
column: z.ZodOptional<z.ZodNumber>;
|
|
339
339
|
project: z.ZodOptional<z.ZodString>;
|
|
340
|
+
programs: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
340
341
|
}, z.core.$strip>;
|
|
341
342
|
export type CheckEntry = z.infer<typeof CheckEntrySchema>;
|
|
342
343
|
export declare const TypecheckCurrentSchema: z.ZodObject<{
|
|
@@ -426,6 +427,7 @@ export declare const TypecheckErrorsSchema: z.ZodObject<{
|
|
|
426
427
|
line: z.ZodOptional<z.ZodNumber>;
|
|
427
428
|
column: z.ZodOptional<z.ZodNumber>;
|
|
428
429
|
project: z.ZodOptional<z.ZodString>;
|
|
430
|
+
programs: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
429
431
|
}, z.core.$strip>>;
|
|
430
432
|
}, z.core.$strip>;
|
|
431
433
|
export type TypecheckErrors = z.infer<typeof TypecheckErrorsSchema>;
|
package/lib/resources.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{z as n}from"zod";import{SCHEMA_VERSION as i}from"./schema-version.js";import{SourceLocationSchema as
|
|
1
|
+
"use strict";import{z as n}from"zod";import{SCHEMA_VERSION as i}from"./schema-version.js";import{SourceLocationSchema as r}from"./source-location.js";import{SeveritySchema as t}from"./event.js";import{ProducerHealthSchema as e}from"./producer-health.js";export const URI_SCHEMES=["agent","events","build","lint","typecheck","test","runtime","render","visual","flow","story","trace","graph","bundle","security","perf","deps","memory","browser","react","valtio","nest","next","process"],ResourceEnvelopeSchema=n.object({$schema:n.string().optional(),schemaVersion:n.literal(i),revision:n.number().int().nonnegative(),updatedAt:n.string().datetime().optional()}),AgentStatusKindSchema=n.enum(["starting","clean","warning","failing"]),AgentBlockingItemSchema=n.object({source:n.string(),severity:t,title:n.string(),fingerprint:n.string(),resource:n.string(),pageId:n.string().optional(),flowId:n.string().optional(),location:r.optional(),rule:n.string().optional(),fix:n.string().optional(),verify:n.string().optional(),docs:n.string().optional()}),AgentChecksSchema=n.object({typecheck:n.enum(["passed","failed","unknown"]).optional(),lint:n.enum(["passed","failed","unknown"]).optional(),build:n.enum(["passed","failed","unknown"]).optional(),runtime:n.enum(["passed","failed","warning","unknown"]).optional(),visual:n.enum(["passed","failed","warning","unknown"]).optional(),memory:n.enum(["passed","failed","warning","unknown"]).optional()}),AgentServerModeSchema=n.enum(["embedded","shared"]),AgentServerInfoSchema=n.object({mode:AgentServerModeSchema,pid:n.number(),startedAt:n.string(),url:n.string().optional()}),AgentCurrentStatusSchema=ResourceEnvelopeSchema.extend({sessionId:n.string(),status:AgentStatusKindSchema,activeTab:n.string().optional(),tabsWithIssues:n.array(n.string()).optional(),blocking:n.array(AgentBlockingItemSchema),warnings:n.array(AgentBlockingItemSchema).default([]),suggestedReads:n.array(n.string()),checks:AgentChecksSchema.optional(),server:AgentServerInfoSchema.optional()}),AgentStorageStatsSchema=n.object({eventsResident:n.number().int().nonnegative(),eventsResidentBytes:n.number().int().nonnegative(),eventsIngested:n.number().int().nonnegative(),eventsDropped:n.number().int().nonnegative(),eventsDroppedForBytes:n.number().int().nonnegative().optional(),eventCap:n.number().int().nonnegative().optional(),eventByteCap:n.number().int().nonnegative().optional(),artifactsResident:n.number().int().nonnegative().optional(),artifactsResidentBytes:n.number().int().nonnegative().optional(),artifactsDropped:n.number().int().nonnegative().optional(),artifactByteCap:n.number().int().nonnegative().optional(),truncatedEvents:n.number().int().nonnegative().optional(),truncatedBytesReclaimed:n.number().int().nonnegative().optional(),rawByteLimit:n.number().int().nonnegative().optional(),reducers:n.record(n.string(),n.object({residentEvents:n.number().int().nonnegative(),residentBytes:n.number().int().nonnegative(),evictedEvents:n.number().int().nonnegative(),evictedForBytes:n.number().int().nonnegative(),eventCap:n.number().int().nonnegative(),byteCap:n.number().int().nonnegative()})).optional()}),AgentSessionSchema=ResourceEnvelopeSchema.extend({sessionId:n.string(),supportedResources:n.array(n.string()),supportedTools:n.array(n.string()),supportedJobs:n.array(n.string()),supportedChannels:n.array(n.string()),subscribedByDefault:n.array(n.string()),transports:n.array(n.enum(["stdio","http","socket"])),host:n.object({platform:n.string(),node:n.string()}),project:n.object({name:n.string(),nxVersion:n.string().optional()}),storage:AgentStorageStatsSchema.optional()});const o=n.object({id:n.string(),timestamp:n.number().int().nonnegative(),message:n.string(),fingerprint:n.string(),code:n.string().optional(),rule:n.string().optional(),severity:t.optional(),file:n.string().optional(),line:n.number().int().nonnegative().optional(),column:n.number().int().nonnegative().optional(),project:n.string().optional(),programs:n.array(n.string()).optional()});export const TypecheckCurrentSchema=ResourceEnvelopeSchema.merge(e).extend({status:n.enum(["unknown","clean","failing"]),errorCount:n.number().int().nonnegative(),lastRunAt:n.number().int().nonnegative().optional()}),TypecheckErrorsSchema=ResourceEnvelopeSchema.merge(e).extend({errors:n.array(o)}),LintCurrentSchema=ResourceEnvelopeSchema.merge(e).extend({status:n.enum(["unknown","clean","warning","failing"]),errorCount:n.number().int().nonnegative(),warningCount:n.number().int().nonnegative(),lastRunAt:n.number().int().nonnegative().optional()}),BuildCurrentSchema=ResourceEnvelopeSchema.merge(e).extend({status:n.enum(["unknown","clean","warning","failing"]),hmrUpdates:n.number().int().nonnegative(),lastRunAt:n.number().int().nonnegative().optional()});
|
package/lib/sources.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var U=Object.defineProperty;var u=(e,r)=>U(e,"name",{value:r,configurable:!0});var v=Object.defineProperty,c=u((e,r)=>v(e,"name",{value:r,configurable:!0}),"a"),I=Object.defineProperty,n=c((e,r)=>I(e,"name",{value:r,configurable:!0}),"r");export const SOURCE_KINDS=["queue","loop","store","traffic"],SOURCE_KINDS_READ=["queue","loop","store","traffic"],sourceWireSchema=n(e=>`lensmcp.${e}/v1`,"sourceWireSchema"),QUEUE_WIRE_SCHEMA="lensmcp.queue/v1",LOOP_WIRE_SCHEMA="lensmcp.loop/v1",STORE_WIRE_SCHEMA="lensmcp.store/v1",TRAFFIC_WIRE_SCHEMA="lensmcp.traffic/v1",SOURCE_SNAPSHOT_FIELD={queue:"snapshot",loop:"loop",store:"store",traffic:"traffic"},URI_SOURCES="process://sources",SOURCE_PROVENANCE="reported",QUEUE_OLDEST_WAIT_RULE="queue/oldest-wait",QUEUE_STALLED_RULE="queue/stalled",LOOP_OVERDUE_RULE="loop/overdue",LOOP_FAILING_RULE="loop/failing",LOOP_IDLE_RULE="loop/idle-while-fed",STORE_QUOTA_RULE="store/near-quota",STORE_ERRORS_RULE="store/errors",STORE_ORPHANS_RULE="store/orphans",TRAFFIC_FAILURES_RULE="traffic/failures",TRAFFIC_LATENCY_RULE="traffic/latency",TRAFFIC_RATE_LIMITED_RULE="traffic/rate-limited",SOURCE_RULES=[QUEUE_OLDEST_WAIT_RULE,QUEUE_STALLED_RULE,LOOP_OVERDUE_RULE,LOOP_FAILING_RULE,LOOP_IDLE_RULE,STORE_QUOTA_RULE,STORE_ERRORS_RULE,STORE_ORPHANS_RULE,TRAFFIC_FAILURES_RULE,TRAFFIC_LATENCY_RULE,TRAFFIC_RATE_LIMITED_RULE],SOURCE_EVENT_KINDS=["source-poll","source-declaration","source-event"],CUSTOM_EVENT_SOURCE="custom",QUEUE_EVENTS=["enqueued","admitted","completed","failed","parked"],LOOP_EVENTS=["run-start","run-end"],LOOP_OUTCOMES=["ok","failed","skipped"],STORE_EVENTS=["write","delete","error"],TRAFFIC_EVENTS=["inbound","outbound"],TRAFFIC_OUTCOMES=["ok","failed","rate-limited"],SOURCE_PUSH_EVENTS={queue:QUEUE_EVENTS,loop:LOOP_EVENTS,store:STORE_EVENTS,traffic:TRAFFIC_EVENTS},SOURCE_PUSH_OUTCOMES={queue:[],loop:LOOP_OUTCOMES,store:[],traffic:TRAFFIC_OUTCOMES},SOURCE_POLL_STATES=["current","unreachable","refused","malformed","not-running"],SOURCE_STATES=[...SOURCE_POLL_STATES,"stale","never-polled"],SOURCE_DEFAULT_INTERVAL_SEC=10,SOURCE_MIN_INTERVAL_SEC=2,QUEUE_DEFAULT_OLDEST_WAIT_MIN=10,QUEUE_DEFAULT_STALLED_MIN=15,LOOP_DEFAULT_IDLE_MIN=10,LOOP_OVERDUE_INTERVALS=2,LOOP_FAILING_RUNS=3,SOURCE_FULL_REPORT_MS=6e4,SOURCE_HISTORY_POINTS=60,SOURCE_RUNS_KEPT=30,SOURCE_PUSHED_KEPT=20,STORE_DEFAULT_QUOTA_PCT=90,STORE_DEFAULT_ERROR_RATE_PCT=5,STORE_DEFAULT_ORPHAN_MIN=60,TRAFFIC_DEFAULT_FAILURE_PCT=5,TRAFFIC_DEFAULT_P95_MS=2e3,TRAFFIC_DEFAULT_RATE_LIMITED=1,TRAFFIC_MIN_MESSAGES=10,TRAFFIC_PUSH_WINDOW_MS=10*6e4,TRAFFIC_PUSH_CHANNELS=50,TRAFFIC_PUSH_EVENTS_PER_CHANNEL=1e3,SOURCE_MAX_GROUPS=500,SOURCE_MAX_BYTES=256*1024,SOURCE_STALE_PERIODS=3,SOURCE_STALE_MIN_MS=3e4;export function sourceStaleAfterMs(e){return Math.max(SOURCE_STALE_MIN_MS,SOURCE_STALE_PERIODS*Math.max(0,e))}u(sourceStaleAfterMs,"sourceStaleAfterMs"),c(sourceStaleAfterMs,"sourceStaleAfterMs"),n(sourceStaleAfterMs,"sourceStaleAfterMs");const i=n(e=>typeof e=="object"&&e!==null&&!Array.isArray(e),"isObj"),t=n(e=>typeof e=="number"&&Number.isInteger(e)&&e>=0,"isCount"),E=n(e=>typeof e=="number"&&Number.isFinite(e)&&e>0,"isTime"),a=n((e,r)=>typeof e=="string"&&e.length>0&&e.length<=r,"isStr"),L=n(e=>e===void 0||typeof e=="number"&&e>0,"isMin");function _(e){if(!SOURCE_KINDS_READ.includes(e.sourceKind)||typeof e.path!="string"&&!(e.path===void 0&&(e.sourceKind==="traffic"||e.sourceKind==="loop"))||!a(e.name,200)||typeof e.intervalSec!="number"||e.feeds!==void 0&&!a(e.feeds,200))return!1;const r=e.thresholds;if(!i(r))return!1;for(const o of["stalledMin","idleMin","oldestWaitMin","quotaPct","errorRatePct","orphanMin","failurePct","p95Ms","rateLimited"])if(!L(r[o]))return!1;return e.sourceKind!=="queue"||typeof r.oldestWaitMin=="number"}u(_,"_"),c(_,"l"),n(_,"asDecl");const d=n(e=>e===null||typeof e=="string","isIsoOrNull"),l=n(e=>e===void 0||t(e),"isOptCount");function f(e){if(!i(e)||typeof e.at!="string"||!E(e.receivedAt)||!E(e.intervalSec)||!d(e.lastRunAt)||e.nextRunAt!==void 0&&!d(e.nextRunAt))return!1;for(const r of["lastDurationMs","lastItems","runsInWindow","itemsInWindow","failuresInWindow","windowSec"])if(!l(e[r]))return!1;return e.lastOutcome!==void 0&&!LOOP_OUTCOMES.includes(e.lastOutcome)?!1:e.lastError===void 0||typeof e.lastError=="string"}u(f,"d"),c(f,"_"),n(f,"asLoopSnapshot");const T=n(e=>e===void 0||i(e)&&Object.values(e).every(r=>typeof r=="string"),"isLabels");function S(e){if(!i(e)||typeof e.at!="string"||!E(e.receivedAt)||!t(e.objects)||!t(e.bytes)||e.quotaBytes!==void 0&&e.quotaBytes!==null&&!t(e.quotaBytes))return!1;for(const s of["opsInWindow","writesInWindow","deletesInWindow","errorsInWindow","windowSec"])if(!l(e[s]))return!1;if(e.lastWriteAt!==void 0&&!d(e.lastWriteAt)||e.lastError!==void 0&&typeof e.lastError!="string")return!1;const r=e.truncated;if(r!==void 0&&!(i(r)&&t(r.groups)))return!1;const o=e.groups;return o===void 0?!0:Array.isArray(o)&&o.length<=SOURCE_MAX_GROUPS&&o.every(s=>i(s)&&a(s.group,1e3)&&t(s.objects)&&t(s.bytes)&&T(s.labels))}u(S,"S"),c(S,"S"),n(S,"asStoreSnapshot");function R(e){if(!i(e)||typeof e.at!="string"||!E(e.receivedAt)||!Array.isArray(e.channels)||!l(e.windowSec))return!1;const r=e.truncated;return r!==void 0&&!(i(r)&&t(r.channels))?!1:e.channels.length<=SOURCE_MAX_GROUPS&&e.channels.every(o=>{if(!i(o)||!a(o.channel,1e3)||!T(o.labels)||o.direction!==void 0&&o.direction!=="inbound"&&o.direction!=="outbound"||o.counterpart!==void 0&&!a(o.counterpart,200))return!1;for(const s of["messagesInWindow","failuresInWindow","rateLimitedInWindow"])if(!l(o[s]))return!1;return o.p95Ms!==void 0&&!(typeof o.p95Ms=="number"&&Number.isFinite(o.p95Ms)&&o.p95Ms>=0)||o.lastAt!==void 0&&!d(o.lastAt)?!1:o.lastError===void 0||typeof o.lastError=="string"})}u(R,"p"),c(R,"R"),n(R,"asTrafficSnapshot");function p(e){return i(e)&&a(e.digest,100)&&typeof e.at=="string"&&E(e.receivedAt)}u(p,"R"),c(p,"A"),n(p,"asSame");function A(e){if(!i(e)||!a(e.group,1e3)||!t(e.pending))return!1;for(const s of["inFlight","failed","completedInWindow"])if(e[s]!==void 0&&!t(e[s]))return!1;const r=e.oldestPendingAt;if(r!=null&&typeof r!="string")return!1;const o=e.labels;return o===void 0||i(o)&&Object.values(o).every(s=>typeof s=="string")}u(A,"A"),c(A,"O"),n(A,"asGroup");function O(e){if(!i(e)||typeof e.at!="string"||!E(e.receivedAt)||!Array.isArray(e.groups))return!1;const r=e.totals;if(!i(r)||!t(r.groups)||!t(r.pending)||!t(r.inFlight)||!t(r.failed))return!1;const o=e.truncated;return o!==void 0&&!(i(o)&&t(o.groups))?!1:e.groups.length<=SOURCE_MAX_GROUPS&&e.groups.every(A)}u(O,"O"),c(O,"T"),n(O,"asSnapshot");export function asSourcePollRaw(e){if(!i(e)||e.kind!=="source-poll"||!a(e.project,200)||!_(e)||!SOURCE_POLL_STATES.includes(e.state)||!E(e.polledAt)||!E(e.reportEveryMs)||e.path===void 0)return;const r=SOURCE_SNAPSHOT_FIELD[e.sourceKind];for(const s of Object.values(SOURCE_SNAPSHOT_FIELD))if(s!==r&&e[s]!==void 0)return;const o={snapshot:O,loop:f,store:S,traffic:R}[r];if(!(e[r]!==void 0&&!o(e[r]))&&!(e.same!==void 0&&(!p(e.same)||e[r]!==void 0))&&!(e.state==="current"&&e[r]===void 0&&e.same===void 0))return e}u(asSourcePollRaw,"asSourcePollRaw"),c(asSourcePollRaw,"asSourcePollRaw"),n(asSourcePollRaw,"asSourcePollRaw");export function asSourceEventRaw(e){if(!i(e)||e.kind!=="source-event"||!a(e.project,200)||!a(e.name,200))return;const r=e.sourceKind;if(SOURCE_KINDS_READ.includes(r)&&SOURCE_PUSH_EVENTS[r].includes(e.event)&&!(e.item!==void 0&&!a(e.item,200)||e.group!==void 0&&!a(e.group,200))&&!(!l(e.items)||!l(e.durationMs)||!l(e.bytes))&&!(e.outcome!==void 0&&!SOURCE_PUSH_OUTCOMES[r].includes(e.outcome))){for(const o of["object","channel","counterpart","correlation"])if(e[o]!==void 0&&!a(e[o],200))return;if(!(e.error!==void 0&&typeof e.error!="string"))return e}}u(asSourceEventRaw,"asSourceEventRaw"),c(asSourceEventRaw,"asSourceEventRaw"),n(asSourceEventRaw,"asSourceEventRaw");export function asSourceDeclarationRaw(e){if(!(!i(e)||e.kind!=="source-declaration"||!a(e.project,200))&&!(!Array.isArray(e.sources)||!e.sources.every(r=>i(r)&&_(r)))&&!(!Array.isArray(e.problems)||!e.problems.every(r=>typeof r=="string")))return e}u(asSourceDeclarationRaw,"asSourceDeclarationRaw"),c(asSourceDeclarationRaw,"asSourceDeclarationRaw"),n(asSourceDeclarationRaw,"asSourceDeclarationRaw");
|