@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.
Files changed (69) hide show
  1. package/index.d.ts +5 -0
  2. package/index.js +1 -1
  3. package/lib/ai-cache-facts.js +1 -1
  4. package/lib/ai-cache-verdict.d.ts +1 -1
  5. package/lib/ai-cache-verdict.js +1 -1
  6. package/lib/ai-cache.js +3 -3
  7. package/lib/ai-call-groups.js +2 -2
  8. package/lib/ai-call-row.d.ts +11 -0
  9. package/lib/ai-call-row.js +3 -3
  10. package/lib/ai-call.js +9 -9
  11. package/lib/ai-compare.js +3 -3
  12. package/lib/ai-context.js +6 -6
  13. package/lib/ai-origins.js +9 -9
  14. package/lib/ai-together.js +5 -5
  15. package/lib/bounded-clone.js +1 -1
  16. package/lib/bounded-map.js +1 -1
  17. package/lib/bounded-writer.js +1 -1
  18. package/lib/canvas-attachments.d.ts +80 -0
  19. package/lib/canvas-attachments.js +1 -0
  20. package/lib/canvas-catalog.js +5 -4
  21. package/lib/canvas-editing.d.ts +107 -0
  22. package/lib/canvas-editing.js +4 -0
  23. package/lib/canvas-frame-policy.d.ts +20 -0
  24. package/lib/canvas-frame-policy.js +1 -0
  25. package/lib/canvas-hub.d.ts +231 -0
  26. package/lib/canvas-hub.js +1 -0
  27. package/lib/canvas.d.ts +149 -8
  28. package/lib/canvas.js +1 -1
  29. package/lib/capture-demand.js +1 -1
  30. package/lib/dashboard-path.js +1 -1
  31. package/lib/docker-errors.js +1 -1
  32. package/lib/docker-jobs.d.ts +9 -2
  33. package/lib/docker-jobs.js +1 -1
  34. package/lib/docker-report.d.ts +2 -1
  35. package/lib/docker-report.js +2 -2
  36. package/lib/docker-runs.js +3 -3
  37. package/lib/error-cause.js +6 -6
  38. package/lib/error-dismissal.js +1 -1
  39. package/lib/error-verdict.js +3 -3
  40. package/lib/event-loop.js +1 -1
  41. package/lib/expected-failure.js +2 -2
  42. package/lib/finding-proof.js +1 -1
  43. package/lib/flood-guard.js +1 -1
  44. package/lib/goal-design.js +1 -1
  45. package/lib/host-agents.js +1 -1
  46. package/lib/http-exchange.d.ts +10 -0
  47. package/lib/lens-hosts.d.ts +40 -0
  48. package/lib/lens-hosts.js +1 -0
  49. package/lib/lint-coverage.d.ts +8 -0
  50. package/lib/lint-coverage.js +1 -1
  51. package/lib/lint-ignores.d.ts +20 -0
  52. package/lib/lint-ignores.js +2 -2
  53. package/lib/log-query.js +1 -1
  54. package/lib/metrics-reset.js +1 -1
  55. package/lib/overseer-findings.d.ts +21 -4
  56. package/lib/overseer-findings.js +1 -1
  57. package/lib/peers.d.ts +123 -1
  58. package/lib/peers.js +1 -1
  59. package/lib/perf-rules.js +1 -1
  60. package/lib/pod-memory.js +1 -1
  61. package/lib/producer-health.js +1 -1
  62. package/lib/remote-instances.js +1 -1
  63. package/lib/sources.js +1 -1
  64. package/lib/static-checks.d.ts +14 -0
  65. package/lib/static-checks.js +1 -1
  66. package/lib/system-report.js +1 -1
  67. package/lib/team.d.ts +35 -0
  68. package/lib/team.js +1 -1
  69. package/package.json +1 -1
@@ -0,0 +1,231 @@
1
+ import type { CanvasActor, CanvasAnswer, CanvasComment, CanvasDataOp, CanvasGrant, CanvasHealth, CanvasKept, CanvasLedgerRow, CanvasRecord, CanvasVersion } from './canvas.js';
2
+ import type { CanvasAsset } from './canvas-attachments.js';
3
+ /**
4
+ * THE CANVAS HUB — canvases shared by teammates on different machines (planning/canvas/00-plan.md § 6 «Teammates»,
5
+ * phase 16; issues canvas-14). A self-hosted server (`lensmcp hub serve`) keeps the canvases a team shares in a canvas
6
+ * store of its own, and is their HOME: the one writer, the one that assigns `seq` (§6: one writer per canvas). Each
7
+ * teammate's LensMCP keeps a READ CACHE of them in its own `canvases.db` and FORWARDS every write — a version, a data
8
+ * patch, an answer, a comment — to the hub, signed in as the person (OAuth, an identity provider the hub names).
9
+ *
10
+ * - Projects match by normalised remote (`normaliseRemote`): `github.com/acme/shop` is one hub project, whatever each
11
+ * teammate's checkout is called or wherever it is.
12
+ * - People have OAuth identities, recorded in `by.person`; per-project ROLES say who reads, answers, writes, administers.
13
+ * - The hub serves canvas frames from its own user-content origin (`frameOrigin`), never `*.localhost`.
14
+ *
15
+ * This file is the wire contract between a LensMCP (its dashboard, its MCP server, its CLI) and a hub.
16
+ */
17
+ /** Where every hub route lives: `<hub>/hub/v1/…`. */
18
+ export declare const CANVAS_HUB_API = "/hub/v1";
19
+ /** A person's roles on a hub project, lowest first: each holds the ones before it. */
20
+ export declare const CANVAS_HUB_ROLES: readonly ["read", "answer", "write", "admin"];
21
+ export type CanvasHubRole = (typeof CANVAS_HUB_ROLES)[number];
22
+ /** Whether `have` includes `need` (read < answer < write < admin). */
23
+ export declare function canvasHubRoleAtLeast(have: CanvasHubRole | undefined, need: CanvasHubRole): boolean;
24
+ export declare const isCanvasHubRole: (value: unknown) => value is CanvasHubRole;
25
+ /** `GET /hub/v1/info` — public: what a LensMCP needs to sign a person in and to frame the hub's canvases. */
26
+ export interface CanvasHubInfo {
27
+ /** The hub's name, as teammates read it («Acme canvases»). */
28
+ name: string;
29
+ /** Its public URL — what every link and every forwarded write names. */
30
+ url: string;
31
+ /** The LensMCP that serves it. */
32
+ version: string;
33
+ /** The identity provider people sign in with: authorization code + PKCE, a loopback redirect (RFC 8252). */
34
+ auth: {
35
+ issuer: string;
36
+ authorizationEndpoint: string;
37
+ tokenEndpoint: string;
38
+ /** A public client registered at the identity provider for LensMCP (no secret: a native app). */
39
+ clientId: string;
40
+ scopes: string[];
41
+ /** The audience the hub's tokens must carry (`aud`), asked for as `audience` and as `resource` (RFC 8707). */
42
+ audience: string;
43
+ };
44
+ /** The hub's own user-content origin, where its canvases' frames are served (planning/canvas § 2.2, § 6). */
45
+ frameOrigin: string;
46
+ /** The hub's session rules. */
47
+ rules: {
48
+ /** An answer counts as the person's own (confirmed) only within this long of their sign-in (`auth_time`). */
49
+ confirmMaxAgeSec: number;
50
+ };
51
+ }
52
+ /** A hub project: one normalised remote. */
53
+ export interface CanvasHubProject {
54
+ id: string;
55
+ remote: string;
56
+ name: string;
57
+ }
58
+ export interface CanvasHubProjectRole extends CanvasHubProject {
59
+ role: CanvasHubRole;
60
+ }
61
+ /** `GET /hub/v1/me` — who the token is, and their roles. */
62
+ export interface CanvasHubMe {
63
+ /** The identity the hub records in `by.person` (the email, else the subject). */
64
+ person: string;
65
+ name?: string;
66
+ email?: string;
67
+ /** A hub administrator (the hub's config): may make projects and give any role. */
68
+ admin: boolean;
69
+ projects: CanvasHubProjectRole[];
70
+ }
71
+ /** A canvas of a hub project, as listed for a cache to compare: its ledger head. */
72
+ export interface CanvasHubHead {
73
+ id: string;
74
+ title: string;
75
+ seq: number;
76
+ updatedAt: number;
77
+ deleted?: boolean;
78
+ }
79
+ /**
80
+ * What a forwarded write says made it, besides the person its token names: an agent's session and client, or the
81
+ * person's own browser (`kind: person` — a confirmed answer still needs the hub's session rules, {@link CanvasHubInfo}).
82
+ */
83
+ export interface CanvasHubOn {
84
+ kind: 'person' | 'agent';
85
+ client?: string;
86
+ session?: string;
87
+ name?: string;
88
+ machine: string;
89
+ }
90
+ /** A version as a home keeps it, with what a candidate's promotion needs. */
91
+ export interface CanvasHubVersion extends CanvasVersion {
92
+ intent: {
93
+ mode: 'keep' | 'whole';
94
+ } | {
95
+ mode: 'migrate';
96
+ ops: CanvasDataOp[];
97
+ };
98
+ shown: boolean;
99
+ questions: number;
100
+ }
101
+ export interface CanvasHubRevision {
102
+ rev: number;
103
+ version: number;
104
+ kind: string;
105
+ ops?: CanvasDataOp[];
106
+ merge?: unknown;
107
+ by: CanvasActor;
108
+ note?: string;
109
+ at: number;
110
+ compacted: boolean;
111
+ }
112
+ export interface CanvasHubCheckpoint {
113
+ rev: number;
114
+ version: number;
115
+ data?: unknown;
116
+ versionRef?: number;
117
+ at: number;
118
+ }
119
+ /**
120
+ * One canvas, as its home hands it on: whole (`since: 0, have: 0, rev: 0` — what «Share with the team» sends the hub)
121
+ * or what changed after what a cache has — ledger rows after `since`, versions after `have` (a version never changes
122
+ * but its health), revisions and checkpoints after `rev`. The mutable rest — the record, every version's health, the
123
+ * working data, answers, comments, grants — always whole.
124
+ */
125
+ export interface CanvasHubSnapshot {
126
+ format: 1;
127
+ canvas: CanvasRecord;
128
+ /** Bytes its versions take (the record's caps). */
129
+ bytes: number;
130
+ versions: CanvasHubVersion[];
131
+ health: Array<{
132
+ n: number;
133
+ health: CanvasHealth;
134
+ shown: boolean;
135
+ dataRev: number;
136
+ }>;
137
+ working: {
138
+ data: unknown;
139
+ dataRev: number;
140
+ version: number;
141
+ at: number;
142
+ };
143
+ answers: CanvasAnswer[];
144
+ comments: CanvasComment[];
145
+ grants: CanvasGrant[];
146
+ ledger: CanvasLedgerRow[];
147
+ revisions: CanvasHubRevision[];
148
+ checkpoints: CanvasHubCheckpoint[];
149
+ /**
150
+ * The files attached to its answers (canvas-11), every row whole — their bytes travel on their own
151
+ * (`GET|POST /hub/v1/canvases/:id/assets/:asset`). `stored`: the side that made the snapshot has the file.
152
+ */
153
+ assets?: CanvasHubAsset[];
154
+ /**
155
+ * Kept snapshots of outside sites (§2.5), in a SHARE: the sharer's own — they read them, so they stay theirs at the
156
+ * hub. A hub's snapshot for a teammate carries `outside` instead.
157
+ */
158
+ got?: CanvasKept[];
159
+ /**
160
+ * The asking teammate's OWN approvals of outside sites and the snapshots their dashboard kept (§2.5: each person
161
+ * approves for themselves; a kept snapshot belongs to the one who read it) — present when they differ from the
162
+ * `outside` mark the request named. A cache keeps these as its `grants` and `got`, and never another's.
163
+ */
164
+ outside?: CanvasHubOutside;
165
+ /** What it was made after. */
166
+ since: number;
167
+ have: number;
168
+ rev: number;
169
+ }
170
+ /** An attachment as a snapshot carries it: its row, and whether the side that made the snapshot holds its bytes. */
171
+ export type CanvasHubAsset = CanvasAsset & {
172
+ stored: boolean;
173
+ };
174
+ /** One person's approvals of outside sites for one hub canvas, and the snapshots their dashboard kept of them. */
175
+ export interface CanvasHubOutside {
176
+ grants: CanvasGrant[];
177
+ got: CanvasKept[];
178
+ /** What both sides compare (`canvasOutsideMark`): the same mark, nothing to send. */
179
+ mark: string;
180
+ }
181
+ /** Where a canvas's home is, as a LensMCP store keeps a canvas it caches from a hub. */
182
+ export interface CanvasHubHome {
183
+ canvas: string;
184
+ /** The hub's URL. */
185
+ hub: string;
186
+ /** The hub's project id. */
187
+ hubProject: string;
188
+ /** The normalised remote both sides match by. */
189
+ remote: string;
190
+ /** The hub's ledger head this cache holds. */
191
+ seq: number;
192
+ syncedAt: number;
193
+ movedAt: number;
194
+ }
195
+ /** A refusal from the hub: `{ error, code }` with its HTTP status. */
196
+ export interface CanvasHubError {
197
+ error: string;
198
+ code: string;
199
+ }
200
+ /** The dashboard's view of the team hub for the project it serves (`GET /api/canvases/hub`). */
201
+ export interface DashCanvasHub {
202
+ /** A hub is set for this machine or this project (`lensmcp hub add <url>`). */
203
+ configured: boolean;
204
+ url?: string;
205
+ name?: string;
206
+ /** The person is signed in to it on this machine. */
207
+ signedIn: boolean;
208
+ person?: string;
209
+ personName?: string;
210
+ /** A sign-in started here and not finished yet: its authorize URL. */
211
+ signingIn?: string;
212
+ /** This project's normalised remote: what the hub matches it by. None: it has no git remote. */
213
+ remote?: string;
214
+ /** The hub's project for it, and the person's role there. */
215
+ project?: CanvasHubProjectRole;
216
+ frameOrigin?: string;
217
+ /** When this machine last read the hub. */
218
+ syncedAt?: number;
219
+ /** Why the hub could not be read (offline, signed out, no role). */
220
+ error?: string;
221
+ }
222
+ /** A hub canvas on a list or a detail: where it lives, and what the person may do there. */
223
+ export interface DashCanvasHubOf {
224
+ url: string;
225
+ name: string;
226
+ role?: CanvasHubRole;
227
+ signedIn: boolean;
228
+ person?: string;
229
+ syncedAt: number;
230
+ error?: string;
231
+ }
@@ -0,0 +1 @@
1
+ "use strict";var s=Object.defineProperty;var n=(e,a)=>s(e,"name",{value:a,configurable:!0});var o=Object.defineProperty,t=n((e,a)=>o(e,"name",{value:a,configurable:!0}),"a"),i=Object.defineProperty,r=t((e,a)=>i(e,"name",{value:a,configurable:!0}),"t");export const CANVAS_HUB_API="/hub/v1",CANVAS_HUB_ROLES=["read","answer","write","admin"];export function canvasHubRoleAtLeast(e,a){return e?CANVAS_HUB_ROLES.indexOf(e)>=CANVAS_HUB_ROLES.indexOf(a):!1}n(canvasHubRoleAtLeast,"canvasHubRoleAtLeast"),t(canvasHubRoleAtLeast,"canvasHubRoleAtLeast"),r(canvasHubRoleAtLeast,"canvasHubRoleAtLeast");export const isCanvasHubRole=r(e=>typeof e=="string"&&CANVAS_HUB_ROLES.includes(e),"isCanvasHubRole");
package/lib/canvas.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  import { z } from 'zod';
2
+ import { type CanvasAsset } from './canvas-attachments.js';
3
+ import type { DashCanvasHubOf } from './canvas-hub.js';
2
4
  /**
3
5
  * Canvases (planning/canvas/00-plan.md): what any agent — Claude Code, Codex, a team agent — shows the person, and what
4
6
  * the person answers, kept by LensMCP rather than by one client's artifacts.
@@ -44,6 +46,7 @@ export declare const CANVAS_LIMITS: {
44
46
  /** One answer's value and note. */
45
47
  readonly answerBytes: number;
46
48
  readonly questions: 500;
49
+ /** Attachments (canvas-11): TaskArtifact's caps — 50 files, 100 MB together, 10 MB each. */
47
50
  readonly assets: 50;
48
51
  readonly assetBytes: number;
49
52
  readonly assetFileBytes: number;
@@ -81,8 +84,14 @@ export interface CanvasActor {
81
84
  kind: 'agent' | 'person' | 'system';
82
85
  /** `claude`, `codex`, `mcp`, `dashboard`, `cli`, `host:<name>`. */
83
86
  client?: string;
84
- /** The MCP session, the coordination session, or the dashboard's per-sign-in session id. */
87
+ /** The MCP session, the coordination session, or the dashboard's per-sign-in session id (`sid-<id>`, D8). */
85
88
  session?: string;
89
+ /**
90
+ * A person on the dashboard: how the request was signed in (D8). `session` — a per-sign-in cookie, the only one a
91
+ * confirmed answer is given with; `machine` — the machine-wide cookie from before it (`session` is then `ck-<digest>`):
92
+ * signed in, but its answers are reported until the browser signs in again; `none` — a Bearer, a token, no cookie.
93
+ */
94
+ signIn?: 'session' | 'machine' | 'none';
86
95
  /** A team agent's role or name, as the person reads it. */
87
96
  name?: string;
88
97
  /** An `ac-…` account. */
@@ -127,9 +136,9 @@ export interface CanvasAsk {
127
136
  items?: CanvasOption[];
128
137
  /** An option id. */
129
138
  recommended?: string;
130
- /** Sets the linked task's `waitingOn`; lands in the Inbox (§7). */
139
+ /** Holds the linked task — no one claims it until it is answered (`waitingOn`) — and lands in the Inbox (§7). */
131
140
  blocking?: boolean;
132
- /** Lands in Team › Inbox (§7). */
141
+ /** Lands in Team › Inbox, routed to the goal's manager first, then the person (§7). */
133
142
  inbox?: boolean;
134
143
  required?: boolean;
135
144
  min?: number;
@@ -381,7 +390,7 @@ export interface CanvasAnswer {
381
390
  /** For stale: the version that changed the question. */
382
391
  changedIn?: number;
383
392
  }
384
- export declare const CANVAS_LEDGER_PARTS: readonly ["version", "data", "answer", "got", "grant", "share", "archive", "delete", "comment", "health", "meta"];
393
+ export declare const CANVAS_LEDGER_PARTS: readonly ["version", "data", "answer", "got", "grant", "share", "archive", "delete", "comment", "health", "meta", "asset"];
385
394
  export type CanvasLedgerPart = (typeof CANVAS_LEDGER_PARTS)[number];
386
395
  /** One row per change (§3.4). `seq` is assigned by the home store only. */
387
396
  export interface CanvasLedgerRow {
@@ -440,6 +449,10 @@ export interface CanvasComment {
440
449
  note?: string;
441
450
  };
442
451
  }
452
+ /**
453
+ * The person's approval of one outside origin for one canvas (§2.5): exact (`https://api.github.com`), revocable, made
454
+ * only from the person's own browser — never by an agent, never by a reported answer.
455
+ */
443
456
  export interface CanvasGrant {
444
457
  canvas: string;
445
458
  origin: string;
@@ -450,6 +463,43 @@ export interface CanvasGrant {
450
463
  by: CanvasActor;
451
464
  };
452
465
  }
466
+ /**
467
+ * An `https:` get's result kept as a snapshot in the canvas's own `got` part (§2.5) — never in the agent's data. What
468
+ * the person's view read from the site, so a render and a health re-check draw what the person saw, never live.
469
+ */
470
+ export interface CanvasKept {
471
+ canvas: string;
472
+ uri: string;
473
+ origin: string;
474
+ value: unknown;
475
+ /** When the dashboard last read this value from the site. */
476
+ at: number;
477
+ /** When it was first kept as it is: an answer that changed is a new snapshot, and a ledger row. */
478
+ since: number;
479
+ bytes: number;
480
+ }
481
+ /** What the dashboard's own fetch of an outside site holds to (§2.5). */
482
+ export declare const CANVAS_OUTSIDE: {
483
+ /** The whole fetch, every redirect hop included. */
484
+ readonly timeoutMs: 10000;
485
+ /** The answer, after decompression. */
486
+ readonly maxBytes: number;
487
+ readonly redirects: 5;
488
+ /** Fetches in a minute, per canvas and per origin (across canvases). */
489
+ readonly perCanvasPerMinute: 30;
490
+ readonly perOriginPerMinute: 60;
491
+ /** Snapshots kept per canvas, and their bytes in all. */
492
+ readonly keptPerCanvas: 20;
493
+ readonly keptBytesPerCanvas: number;
494
+ };
495
+ /** The approval prompt's first line (§2.5): a granted origin is also a way out, so it says so. */
496
+ export declare function canvasGrantWords(origin: string): string;
497
+ /** The whole approval prompt the rail shows for `origin`. */
498
+ export declare function canvasGrantPrompt(origin: string): {
499
+ title: string;
500
+ lines: string[];
501
+ act: string;
502
+ };
453
503
  export interface CanvasDataChange {
454
504
  path: string;
455
505
  change: 'added' | 'removed' | 'changed';
@@ -542,7 +592,7 @@ export type CanvasSafeBlock = {
542
592
  /** Which tier the person sees (§4.3). */
543
593
  export type CanvasTier = 1 | 2 | 3;
544
594
  /** Every method the port carries; anything else is method-not-found. Names follow MCP Apps (SEP-1865). */
545
- export declare const CANVAS_BROKER_METHODS: readonly ["ui/initialize", "ui/notifications/size-changed", "ui/open-link", "canvas/heartbeat", "canvas/slots", "canvas/focus", "canvas/get", "canvas/rendered", "canvas/problem", "canvas/health", "canvas/data-changed", "canvas/answers-changed", "canvas/selection", "canvas/copy", "canvas/download", "canvas/open-ref", "canvas/slot-sizes", "canvas/theme"];
595
+ export declare const CANVAS_BROKER_METHODS: readonly ["ui/initialize", "ui/notifications/size-changed", "ui/open-link", "canvas/heartbeat", "canvas/slots", "canvas/focus", "canvas/get", "canvas/rendered", "canvas/problem", "canvas/health", "canvas/data-changed", "canvas/answers-changed", "canvas/selection", "canvas/copy", "canvas/download", "canvas/open-ref", "canvas/slot-sizes", "canvas/theme", "canvas/escape"];
546
596
  export type CanvasBrokerMethod = (typeof CANVAS_BROKER_METHODS)[number];
547
597
  /** A JSON-RPC 2.0 message on the port: a request has an `id`, a notification none. */
548
598
  export interface CanvasRpc<P = unknown> {
@@ -585,6 +635,7 @@ export interface CanvasFrameInit {
585
635
  fallback?: boolean;
586
636
  dir?: 'ltr' | 'rtl' | 'auto';
587
637
  }
638
+ /** A get's result. `kept`: read from the canvas's kept snapshot (a render's only `https:` source), `at` when it was read from the site. */
588
639
  export type CanvasGotResult = {
589
640
  ok: true;
590
641
  value: unknown;
@@ -594,6 +645,46 @@ export type CanvasGotResult = {
594
645
  ok: false;
595
646
  reason: string;
596
647
  };
648
+ /** The MIME type of an MCP Apps UI resource (SEP-1865): an HTML page a host renders in its sandbox. */
649
+ export declare const CANVAS_APP_MIME = "text/html;profile=mcp-app";
650
+ /** One canvas as an MCP Apps page: the runtime with the canvas written in. */
651
+ export declare const CANVAS_APP_URI_TEMPLATE = "ui://canvas/{id}";
652
+ export declare const canvasAppUri: (id: string) => string;
653
+ /**
654
+ * The page `canvas_get` and `canvas_write` name as their UI (`_meta.ui.resourceUri`): the same runtime with no canvas
655
+ * in it — a host renders it beside the call, and it reads the canvas the call answered about (`ui://canvas/<id>`).
656
+ */
657
+ export declare const CANVAS_APP_VIEW_URI = "ui://canvas/view";
658
+ /** The tool a hosted page answers through: app-only (`_meta.ui.visibility: ["app"]`), recorded REPORTED. */
659
+ export declare const CANVAS_ANSWER_TOOL = "canvas_answer";
660
+ /** The page's own protocol, in its payload. */
661
+ export declare const CANVAS_APP_PROTOCOL = 1;
662
+ /**
663
+ * What an MCP Apps page carries (`<script type="application/json" id="lensmcp-canvas">`): the frame init, as the
664
+ * dashboard builds it (confirmed answers only), and what the page shows around it. The host has no dashboard session,
665
+ * so an answer given in the page is REPORTED (`via: host:<name>`) until the person confirms it in the dashboard.
666
+ */
667
+ export interface CanvasAppPayload {
668
+ app: number;
669
+ canvas: {
670
+ id: string;
671
+ title: string;
672
+ version: number;
673
+ project: string;
674
+ url?: string;
675
+ };
676
+ init: CanvasFrameInit;
677
+ /** Reported answers newer than the key's confirmed one: shown under their question, never acted on. */
678
+ reported: Array<{
679
+ key: string;
680
+ value: unknown;
681
+ via: string;
682
+ at: number;
683
+ }>;
684
+ /** Whether the page has mermaid written in (`<script id="lensmcp-mermaid">`): only a canvas with a diagram does. */
685
+ mermaid: boolean;
686
+ answerTool: string;
687
+ }
597
688
  /**
598
689
  * The confirmed answers that stand (state `current`), the newest per key — what the frame's `props.answers` is, what
599
690
  * `When` reads, and the only answers agents act on (§2.4).
@@ -691,11 +782,11 @@ export declare const CANVAS_FRAME_PARAMS: {
691
782
  readonly 'canvas/download': z.ZodObject<{
692
783
  name: z.ZodString;
693
784
  type: z.ZodEnum<{
694
- csv: "csv";
695
- json: "json";
696
785
  png: "png";
786
+ json: "json";
697
787
  txt: "txt";
698
788
  md: "md";
789
+ csv: "csv";
699
790
  }>;
700
791
  text: z.ZodString;
701
792
  }, z.core.$strip>;
@@ -709,6 +800,8 @@ export declare const CANVAS_FRAME_PARAMS: {
709
800
  id: z.ZodString;
710
801
  line: z.ZodOptional<z.ZodNumber>;
711
802
  }, z.core.$strip>;
803
+ /** Escape pressed in the document: the page around it acts on it as its own (issues/closed/canvas-20). */
804
+ readonly 'canvas/escape': z.ZodObject<{}, z.core.$strip>;
712
805
  };
713
806
  /**
714
807
  * The height a question's slot starts at, before the parent measured its control (`canvas/slot-sizes` then tells the
@@ -744,6 +837,8 @@ export interface DashCanvasRow {
744
837
  shared: boolean;
745
838
  /** Homed by another project, shared to this one. */
746
839
  foreign: boolean;
840
+ /** Its home is a team hub (§6 teammates): this list shows the read cache. */
841
+ hub?: DashCanvasHubOf;
747
842
  updatedAt: number;
748
843
  createdAt: number;
749
844
  }
@@ -765,6 +860,26 @@ export interface DashCanvasInboxQuestion {
765
860
  askedAt: number;
766
861
  /** Homed by another project, shared to this one. */
767
862
  foreign: boolean;
863
+ /** Where it is in the team (§7): with its goal's manager first, or with the person. */
864
+ route?: CanvasQuestionRoute;
865
+ }
866
+ /**
867
+ * Where a canvas question asked with `inbox` or `blocking` is in the team (§7, planning/team/09): the coordination store
868
+ * derives a team question from it and routes it as an agent's — its goal's manager first, the person when no manager
869
+ * takes it or the manager's session ends or 30 minutes pass. `task-done`: every task it links ended — the Inbox row is
870
+ * withdrawn, and the question stays open on the canvas, «its task is done».
871
+ */
872
+ export interface CanvasQuestionRoute {
873
+ qid: string;
874
+ /** The derived team question (`q-…`). */
875
+ question?: string;
876
+ state: 'manager' | 'person' | 'task-done';
877
+ /** The manager it is with. */
878
+ toName?: string;
879
+ /** Why it is the person's: no manager on the team, escalated by its manager, its manager's session ended, … */
880
+ why?: string;
881
+ /** While with a manager: when it goes to the person by itself (Q-D4). */
882
+ escalatesAt?: number;
768
883
  }
769
884
  export interface DashCanvasInbox {
770
885
  questions: DashCanvasInboxQuestion[];
@@ -810,14 +925,30 @@ export interface DashCanvasDetail {
810
925
  frameOrigin: string;
811
926
  /** May the person answer here (a worker Mac's read-only board: «answer on the organizer»). */
812
927
  canAnswer: boolean;
813
- /** Gets the version uses, and what each resolves to now. */
928
+ /** May the person edit it here (canvas-12): this view may answer, and this project may write the canvas (its home or share.write). */
929
+ canEdit?: boolean;
930
+ /** Gets the version uses, and what each resolves to now. An `https:` one names its origin and its kept snapshot. */
814
931
  gets: Array<CanvasGetDecl & {
815
932
  allowed: boolean;
816
933
  why?: string;
934
+ origin?: string;
935
+ kept?: {
936
+ at: number;
937
+ since: number;
938
+ bytes: number;
939
+ };
817
940
  }>;
941
+ /** The person's approvals of outside origins (§2.5), standing and revoked. */
942
+ grants: CanvasGrant[];
818
943
  comments: CanvasComment[];
819
944
  /** The ledger's head. */
820
945
  seq: number;
946
+ /** Where its open questions asked with `inbox` or `blocking` are in the team (§7) — «its task is done» among them. */
947
+ routes?: CanvasQuestionRoute[];
948
+ /** The files the person attached to answers (canvas-11): what a file or image answer's `asset` names. */
949
+ assets?: CanvasAsset[];
950
+ /** Its home is a team hub (§6 teammates): writes go there, this is the read cache. */
951
+ hub?: DashCanvasHubOf;
821
952
  }
822
953
  export interface DashCanvasCompiled {
823
954
  canvas: string;
@@ -843,6 +974,16 @@ export interface DashCanvasAnswerResult {
843
974
  answer?: CanvasAnswer;
844
975
  answers: CanvasAnswer[];
845
976
  seq: number;
977
+ /** The person's own browser answered, and it was recorded reported: why, in words to show them (D8: sign in again). */
978
+ reported?: string;
979
+ }
980
+ /** `POST /api/canvases/<id>/grants`: approve (the person's browser only) or revoke one outside origin (§2.5). */
981
+ export interface DashCanvasGrantInput {
982
+ origin: string;
983
+ grant: boolean;
984
+ }
985
+ export interface DashCanvasGrantResult {
986
+ grants: CanvasGrant[];
846
987
  }
847
988
  export interface DashCanvasHealthInput {
848
989
  version: number;
package/lib/canvas.js CHANGED
@@ -1 +1 @@
1
- "use strict";var l=Object.defineProperty;var i=(a,n)=>l(a,"name",{value:n,configurable:!0});var d=Object.defineProperty,r=i((a,n)=>d(a,"name",{value:n,configurable:!0}),"i");import{z as e}from"zod";export const CANVAS_FORMAT=1,CANVAS_FRAME_PROTOCOL=1,CANVAS_FRAME_RUNTIME="frame-v1",CANVAS_FRAME_PATH="/v1",CANVAS_FRAME_HOST="lensmcp.canvas.localhost",CANVAS_ID_PATTERN=/^cv-[0-9a-f]{16}$/,CANVAS_PROJECT_ID_PATTERN=/^pr-[0-9a-f]{16}$/,CANVAS_QID_PATTERN=/^[a-z][a-z0-9_-]{0,63}$/i,isCanvasId=r(a=>typeof a=="string"&&CANVAS_ID_PATTERN.test(a),"isCanvasId"),CANVAS_LIMITS={mdxBytes:256*1024,mdxWholeBytes:64*1024,dataBytes:2*1024*1024,answerBytes:16*1024,questions:500,assets:50,assetBytes:100*1024*1024,assetFileBytes:10*1024*1024,canvasBytes:256*1024*1024,projectBytes:2*1024*1024*1024,titleChars:200,noteChars:2e3,commentChars:8e3,frameMessageBytes:256*1024,depth:64,ops:1e3,checkpointEvery:50,checkpointsKept:20,waitDefaultMs:45e3,waitMaxMs:9e5},CANVAS_KINDS=["doc","decision","plan","review","report","dashboard","qa","template"],CANVAS_TEMPLATE_NAMES=["decision-record","plan-review","weekly-report","goal-dashboard","qa-report"],CANVAS_QUESTION_KINDS=["choice","multi","text","number","confirm","approve"],CANVAS_FIELD_KINDS=["text","number","date","file","image"],CANVAS_INTERACTIVE=["Question","Checklist","Field","Options"];export function canvasAnswerKeys(a){return a.kind==="checklist"?(a.items??[]).map(n=>`${a.qid}/${n.id}`):a.kind==="multi"?(a.options??[]).map(n=>`${a.qid}/${n.id}`):[a.qid]}i(canvasAnswerKeys,"canvasAnswerKeys"),r(canvasAnswerKeys,"canvasAnswerKeys");export const canvasQidOf=r(a=>a.split("/")[0]??a,"canvasQidOf"),CANVAS_SHAPE_KEYS=["type","properties","required","items","enum","minimum","maximum","minItems","maxItems","format","additionalProperties","description","derived","$schema","title"],CANVAS_DATA_OPS=["set","remove","move","copy","append"],CANVAS_HEALTH_STATES=["checked","good","broken","unverified"],CANVAS_ANSWER_VIAS=["document","rail","inbox","cli","api","host"],CANVAS_LEDGER_PARTS=["version","data","answer","got","grant","share","archive","delete","comment","health","meta"],CANVAS_BROKER_METHODS=["ui/initialize","ui/notifications/size-changed","ui/open-link","canvas/heartbeat","canvas/slots","canvas/focus","canvas/get","canvas/rendered","canvas/problem","canvas/health","canvas/data-changed","canvas/answers-changed","canvas/selection","canvas/copy","canvas/download","canvas/open-ref","canvas/slot-sizes","canvas/theme"];export function canvasConfirmedAnswers(a){const n=new Map;for(const o of a){if(!o.confirmed)continue;const c=n.get(o.key);(!c||o.seq>c.seq)&&n.set(o.key,o)}const t={};for(const[o,c]of n)c.state==="current"&&(t[o]=c.value);return t}i(canvasConfirmedAnswers,"canvasConfirmedAnswers"),r(canvasConfirmedAnswers,"canvasConfirmedAnswers");export function canvasFrameInit(a){const n=a.detail;return{protocol:CANVAS_FRAME_PROTOCOL,theme:a.theme,tokens:a.tokens,canvas:n.canvas.id,version:n.shown,code:a.code,compiler:a.compiler,contract:n.version.contract,bindings:n.version.bindings,data:n.data,marks:n.marks,answers:canvasConfirmedAnswers(n.answers),got:{},...a.anchor?{anchor:a.anchor}:{},fallback:a.fallback,dir:"auto"}}i(canvasFrameInit,"canvasFrameInit"),r(canvasFrameInit,"canvasFrameInit");const s=e.number(),p=e.object({qid:e.string().max(64),x:s,y:s,width:s.min(0).max(1e4),height:s.min(0).max(1e4),visible:e.boolean()}),m=e.object({message:e.string().max(4e3),block:e.string().max(200).optional(),line:e.number().int().min(0).max(1e6).optional(),column:e.number().int().min(0).max(1e5).optional(),component:e.string().max(100).optional()});export const CANVAS_FRAME_PARAMS={"ui/initialize":e.looseObject({protocol:e.number().int()}),"ui/notifications/size-changed":e.object({height:s.min(0).max(1e6),width:s.min(0).max(1e5).optional()}),"ui/open-link":e.object({url:e.string().max(4e3)}),"canvas/heartbeat":e.object({t:s}),"canvas/slots":e.object({slots:e.array(p).max(CANVAS_LIMITS.questions)}),"canvas/focus":e.object({qid:e.string().max(64)}),"canvas/get":e.object({uri:e.string().max(2e3)}),"canvas/rendered":e.object({ms:s.min(0),blocks:e.number().int().min(0),errors:e.number().int().min(0)}),"canvas/problem":e.object({errors:e.array(m).max(200)}),"canvas/health":e.object({ok:e.boolean(),errors:e.array(m).max(200)}),"canvas/selection":e.object({text:e.string().max(8e3),block:e.string().max(200).optional(),lines:e.tuple([e.number().int(),e.number().int()]).optional()}),"canvas/copy":e.object({text:e.string().max(1024*1024)}),"canvas/download":e.object({name:e.string().max(200),type:e.enum(["csv","json","png","txt","md"]),text:e.string().max(4*1024*1024)}),"canvas/open-ref":e.object({kind:e.enum(["task","goal","file","canvas"]),id:e.string().max(2e3),line:e.number().int().optional()})};export function canvasSlotHeight(a){const n=40+(a.detail?20:0),t=44;switch(a.kind){case"choice":case"multi":return n+36*Math.max(1,a.options?.length??0)+t;case"checklist":return n+32*Math.max(1,a.items?.length??0);case"confirm":return n+t;case"approve":return n+72+t;case"text":return n+84+t;default:return n+40+t}}i(canvasSlotHeight,"canvasSlotHeight"),r(canvasSlotHeight,"canvasSlotHeight");
1
+ "use strict";var l=Object.defineProperty;var o=(a,t)=>l(a,"name",{value:t,configurable:!0});var v=Object.defineProperty,c=o((a,t)=>v(a,"name",{value:t,configurable:!0}),"o"),d=Object.defineProperty,n=c((a,t)=>d(a,"name",{value:t,configurable:!0}),"a");import{z as e}from"zod";import{TASK_ARTIFACT_MAX_BYTES as p,TASK_ARTIFACTS_MAX as u,TASK_ARTIFACTS_MAX_BYTES as h}from"./canvas-attachments.js";export const CANVAS_FORMAT=1,CANVAS_FRAME_PROTOCOL=1,CANVAS_FRAME_RUNTIME="frame-v1",CANVAS_FRAME_PATH="/v1",CANVAS_FRAME_HOST="lensmcp.canvas.localhost",CANVAS_ID_PATTERN=/^cv-[0-9a-f]{16}$/,CANVAS_PROJECT_ID_PATTERN=/^pr-[0-9a-f]{16}$/,CANVAS_QID_PATTERN=/^[a-z][a-z0-9_-]{0,63}$/i,isCanvasId=n(a=>typeof a=="string"&&CANVAS_ID_PATTERN.test(a),"isCanvasId"),CANVAS_LIMITS={mdxBytes:256*1024,mdxWholeBytes:64*1024,dataBytes:2*1024*1024,answerBytes:16*1024,questions:500,assets:u,assetBytes:h,assetFileBytes:p,canvasBytes:256*1024*1024,projectBytes:2*1024*1024*1024,titleChars:200,noteChars:2e3,commentChars:8e3,frameMessageBytes:256*1024,depth:64,ops:1e3,checkpointEvery:50,checkpointsKept:20,waitDefaultMs:45e3,waitMaxMs:9e5},CANVAS_KINDS=["doc","decision","plan","review","report","dashboard","qa","template"],CANVAS_TEMPLATE_NAMES=["decision-record","plan-review","weekly-report","goal-dashboard","qa-report"],CANVAS_QUESTION_KINDS=["choice","multi","text","number","confirm","approve"],CANVAS_FIELD_KINDS=["text","number","date","file","image"],CANVAS_INTERACTIVE=["Question","Checklist","Field","Options"];export function canvasAnswerKeys(a){return a.kind==="checklist"?(a.items??[]).map(t=>`${a.qid}/${t.id}`):a.kind==="multi"?(a.options??[]).map(t=>`${a.qid}/${t.id}`):[a.qid]}o(canvasAnswerKeys,"canvasAnswerKeys"),c(canvasAnswerKeys,"canvasAnswerKeys"),n(canvasAnswerKeys,"canvasAnswerKeys");export const canvasQidOf=n(a=>a.split("/")[0]??a,"canvasQidOf"),CANVAS_SHAPE_KEYS=["type","properties","required","items","enum","minimum","maximum","minItems","maxItems","format","additionalProperties","description","derived","$schema","title"],CANVAS_DATA_OPS=["set","remove","move","copy","append"],CANVAS_HEALTH_STATES=["checked","good","broken","unverified"],CANVAS_ANSWER_VIAS=["document","rail","inbox","cli","api","host"],CANVAS_LEDGER_PARTS=["version","data","answer","got","grant","share","archive","delete","comment","health","meta","asset"],CANVAS_OUTSIDE={timeoutMs:1e4,maxBytes:2*1024*1024,redirects:5,perCanvasPerMinute:30,perOriginPerMinute:60,keptPerCanvas:20,keptBytesPerCanvas:8*1024*1024};export function canvasGrantWords(a){return`This canvas could send what it reads to ${a}, or anywhere.`}o(canvasGrantWords,"canvasGrantWords"),c(canvasGrantWords,"canvasGrantWords"),n(canvasGrantWords,"canvasGrantWords");export function canvasGrantPrompt(a){return{title:`Let this canvas read ${a}?`,lines:[canvasGrantWords(a),"A site a canvas may read is also a way out: the addresses its versions ask for can carry what its author knows, each read tells the site you opened the canvas, and the site can pass any of it on.","The dashboard fetches it, never the canvas: only the exact URLs a version declares, public addresses only, GET, no cookies, 10 s and 2 MB at most. Revoke it here at any time; the ledger records both."],act:`Approve ${a}`}}o(canvasGrantPrompt,"canvasGrantPrompt"),c(canvasGrantPrompt,"canvasGrantPrompt"),n(canvasGrantPrompt,"canvasGrantPrompt");export const CANVAS_BROKER_METHODS=["ui/initialize","ui/notifications/size-changed","ui/open-link","canvas/heartbeat","canvas/slots","canvas/focus","canvas/get","canvas/rendered","canvas/problem","canvas/health","canvas/data-changed","canvas/answers-changed","canvas/selection","canvas/copy","canvas/download","canvas/open-ref","canvas/slot-sizes","canvas/theme","canvas/escape"],CANVAS_APP_MIME="text/html;profile=mcp-app",CANVAS_APP_URI_TEMPLATE="ui://canvas/{id}",canvasAppUri=n(a=>`ui://canvas/${a}`,"canvasAppUri"),CANVAS_APP_VIEW_URI="ui://canvas/view",CANVAS_ANSWER_TOOL="canvas_answer",CANVAS_APP_PROTOCOL=1;export function canvasConfirmedAnswers(a){const t=new Map;for(const i of a){if(!i.confirmed)continue;const m=t.get(i.key);(!m||i.seq>m.seq)&&t.set(i.key,i)}const s={};for(const[i,m]of t)m.state==="current"&&(s[i]=m.value);return s}o(canvasConfirmedAnswers,"canvasConfirmedAnswers"),c(canvasConfirmedAnswers,"canvasConfirmedAnswers"),n(canvasConfirmedAnswers,"canvasConfirmedAnswers");export function canvasFrameInit(a){const t=a.detail;return{protocol:CANVAS_FRAME_PROTOCOL,theme:a.theme,tokens:a.tokens,canvas:t.canvas.id,version:t.shown,code:a.code,compiler:a.compiler,contract:t.version.contract,bindings:t.version.bindings,data:t.data,marks:t.marks,answers:canvasConfirmedAnswers(t.answers),got:{},...a.anchor?{anchor:a.anchor}:{},fallback:a.fallback,dir:"auto"}}o(canvasFrameInit,"canvasFrameInit"),c(canvasFrameInit,"canvasFrameInit"),n(canvasFrameInit,"canvasFrameInit");const r=e.number(),_=e.object({qid:e.string().max(64),x:r,y:r,width:r.min(0).max(1e4),height:r.min(0).max(1e4),visible:e.boolean()}),A=e.object({message:e.string().max(4e3),block:e.string().max(200).optional(),line:e.number().int().min(0).max(1e6).optional(),column:e.number().int().min(0).max(1e5).optional(),component:e.string().max(100).optional()});export const CANVAS_FRAME_PARAMS={"ui/initialize":e.looseObject({protocol:e.number().int()}),"ui/notifications/size-changed":e.object({height:r.min(0).max(1e6),width:r.min(0).max(1e5).optional()}),"ui/open-link":e.object({url:e.string().max(4e3)}),"canvas/heartbeat":e.object({t:r}),"canvas/slots":e.object({slots:e.array(_).max(CANVAS_LIMITS.questions)}),"canvas/focus":e.object({qid:e.string().max(64)}),"canvas/get":e.object({uri:e.string().max(2e3)}),"canvas/rendered":e.object({ms:r.min(0),blocks:e.number().int().min(0),errors:e.number().int().min(0)}),"canvas/problem":e.object({errors:e.array(A).max(200)}),"canvas/health":e.object({ok:e.boolean(),errors:e.array(A).max(200)}),"canvas/selection":e.object({text:e.string().max(8e3),block:e.string().max(200).optional(),lines:e.tuple([e.number().int(),e.number().int()]).optional()}),"canvas/copy":e.object({text:e.string().max(1024*1024)}),"canvas/download":e.object({name:e.string().max(200),type:e.enum(["csv","json","png","txt","md"]),text:e.string().max(4*1024*1024)}),"canvas/open-ref":e.object({kind:e.enum(["task","goal","file","canvas"]),id:e.string().max(2e3),line:e.number().int().optional()}),"canvas/escape":e.object({})};export function canvasSlotHeight(a){const t=40+(a.detail?20:0),s=44;switch(a.kind){case"choice":case"multi":return t+36*Math.max(1,a.options?.length??0)+s;case"checklist":return t+32*Math.max(1,a.items?.length??0);case"confirm":return t+s;case"approve":return t+72+s;case"text":return t+84+s;default:return t+40+s}}o(canvasSlotHeight,"canvasSlotHeight"),c(canvasSlotHeight,"canvasSlotHeight"),n(canvasSlotHeight,"canvasSlotHeight");
@@ -1 +1 @@
1
- "use strict";var c=Object.defineProperty;var o=(t,e)=>c(t,"name",{value:e,configurable:!0});var s=Object.defineProperty,u=o((t,e)=>s(t,"name",{value:e,configurable:!0}),"s");export const CAPTURE_REQUEST_FILENAME="capture-request.json",CAPTURE_PRESENCE_FILENAME="capture-runner.json";export function appMatchesPage(t,e){const r=t.trim().toLowerCase();if(!r)return!1;if(e.project&&e.project.toLowerCase()===r)return!0;const n=e.url.toLowerCase();if(n===r||n.replace(/\/+$/,"")===r.replace(/\/+$/,""))return!0;try{const a=new URL(e.url);return/^\d+$/.test(r)?a.port===r:a.origin.toLowerCase()===r.replace(/\/+$/,"")}catch{return!1}}o(appMatchesPage,"appMatchesPage"),u(appMatchesPage,"appMatchesPage");export const CAPTURE_RULES_FILENAME="capture-rules.json";
1
+ "use strict";var s=Object.defineProperty;var a=(r,e)=>s(r,"name",{value:e,configurable:!0});var p=Object.defineProperty,c=a((r,e)=>p(r,"name",{value:e,configurable:!0}),"o"),u=Object.defineProperty,E=c((r,e)=>u(r,"name",{value:e,configurable:!0}),"s");export const CAPTURE_REQUEST_FILENAME="capture-request.json",CAPTURE_PRESENCE_FILENAME="capture-runner.json";export function appMatchesPage(r,e){const t=r.trim().toLowerCase();if(!t)return!1;if(e.project&&e.project.toLowerCase()===t)return!0;const o=e.url.toLowerCase();if(o===t||o.replace(/\/+$/,"")===t.replace(/\/+$/,""))return!0;try{const n=new URL(e.url);return/^\d+$/.test(t)?n.port===t:n.origin.toLowerCase()===t.replace(/\/+$/,"")}catch{return!1}}a(appMatchesPage,"appMatchesPage"),c(appMatchesPage,"appMatchesPage"),E(appMatchesPage,"appMatchesPage");export const CAPTURE_RULES_FILENAME="capture-rules.json";
@@ -1 +1 @@
1
- "use strict";var o=Object.defineProperty;var c=(e,t)=>o(e,"name",{value:t,configurable:!0});var d=Object.defineProperty,n=c((e,t)=>d(e,"name",{value:t,configurable:!0}),"t");const a={"~":"~~","/":"~s","\\":"~b","\0":"~0"},p={"~":"~",s:"/",b:"\\",0:"\0",d:"."},g=/%2f|%5c|%2e|%00/i;export function encodeSegment(e){return e==="."||e===".."?e.replace(/\./g,"~d"):encodeURIComponent(e.replace(/[~/\\\0]/g,t=>a[t])).replace(/%3A/g,":").replace(/%40/g,"@")}c(encodeSegment,"encodeSegment"),n(encodeSegment,"encodeSegment");export function decodeSegment(e){let t;try{t=decodeURIComponent(e)}catch{t=e}return g.test(e)?t:t.replace(/~([~sb0d])/g,(l,r)=>p[r])}c(decodeSegment,"decodeSegment"),n(decodeSegment,"decodeSegment");
1
+ "use strict";var d=Object.defineProperty;var t=(e,n)=>d(e,"name",{value:n,configurable:!0});var a=Object.defineProperty,c=t((e,n)=>a(e,"name",{value:n,configurable:!0}),"c"),g=Object.defineProperty,o=c((e,n)=>g(e,"name",{value:n,configurable:!0}),"t");const p={"~":"~~","/":"~s","\\":"~b","\0":"~0"},l={"~":"~",s:"/",b:"\\",0:"\0",d:"."},m=/%2f|%5c|%2e|%00/i;export function encodeSegment(e){return e==="."||e===".."?e.replace(/\./g,"~d"):encodeURIComponent(e.replace(/[~/\\\0]/g,n=>p[n])).replace(/%3A/g,":").replace(/%40/g,"@")}t(encodeSegment,"encodeSegment"),c(encodeSegment,"encodeSegment"),o(encodeSegment,"encodeSegment");export function decodeSegment(e){let n;try{n=decodeURIComponent(e)}catch{n=e}return m.test(e)?n:n.replace(/~([~sb0d])/g,(u,r)=>l[r])}t(decodeSegment,"decodeSegment"),c(decodeSegment,"decodeSegment"),o(decodeSegment,"decodeSegment");
@@ -1 +1 @@
1
- "use strict";var R=Object.defineProperty;var m=(t,e)=>R(t,"name",{value:e,configurable:!0});var O=Object.defineProperty,c=m((t,e)=>O(t,"name",{value:e,configurable:!0}),"c");import{CONTAINER_OOM as v,DOCKER_ENGINE_LOST as j,DOCKER_RUN_FIELD as B}from"./docker-jobs.js";import{joinId as x}from"./error-cause.js";const I=200,$=50,k=c(t=>typeof t=="object"&&t!==null&&!Array.isArray(t),"isObj"),h=c(t=>{if(typeof t!="string")return;const e=t.trim();return e?e.slice(0,I):void 0},"name"),p=c(t=>typeof t=="number"&&Number.isFinite(t)&&t>0?t:void 0,"someMb"),N=c(t=>typeof t=="number"&&Number.isFinite(t)&&t>=0?t:void 0,"anyMb"),w=c(t=>Object.fromEntries(Object.entries(t).filter(([,e])=>e!==void 0)),"defined"),g=c(t=>{if(!k(t))return;const e=h(t.peer);if(!e)return;const s=h(t.name);return s?{peer:e,name:s}:{peer:e}},"hostOf"),f=c(t=>t.name??t.peer,"hostWord");export function readDockerError(t){if(k(t)){if(t.kind===v)return w({kind:v,run:h(t.run),job:h(t.job),service:h(t.service),container:h(t.container),seen:t.seen==="event"||t.seen==="inspect"?t.seen:void 0,limitMb:p(t.limitMb),peakMb:p(t.peakMb),budgetMb:p(t.budgetMb),context:h(t.context),host:g(t.host)});if(t.kind===j){const e=new Map;for(const o of Array.isArray(t.runs)?t.runs:[]){const i=k(o)?h(o.run):h(o),r=k(o)?h(o.job):void 0;i&&!e.has(i)&&e.size<$&&e.set(i,{run:i,...r?{job:r}:{}})}const s=Array.isArray(t.killed)?[...new Set(t.killed.map(h).filter(o=>!!o))].slice(0,$):[];return w({kind:j,context:h(t.context),runs:[...e.values()],why:h(t.why),vmTotalMb:p(t.vmTotalMb),vmAvailableMb:N(t.vmAvailableMb),killed:s.length?s:void 0,host:g(t.host)})}}}m(readDockerError,"readDockerError"),c(readDockerError,"readDockerError");export function dockerErrorRuns(t){return t.kind===v?t.run?[t.run]:[]:t.runs.map(e=>e.run)}m(dockerErrorRuns,"dockerErrorRuns"),c(dockerErrorRuns,"dockerErrorRuns");export function dockerRunOfEvent(t){return k(t)?h(t[B]):void 0}m(dockerRunOfEvent,"dockerRunOfEvent"),c(dockerRunOfEvent,"dockerRunOfEvent");export const CONTAINER_OOM_ERROR="ContainerOOMKilled",DOCKER_ENGINE_LOST_ERROR="DockerEngineLost";const _=256,a=c(t=>`${Math.round(t)} MiB`,"mib");function y(t){const e=`${t.service??"a container"} ran out of memory in ${t.job??"a Docker job"}`,s=`${t.service?`\xAB${t.service}\xBB`:"A container"} ran out of memory and was killed, in ${t.job?`the Docker job \xAB${t.job}\xBB`:"a Docker job"}${t.host?` on the worker \xAB${f(t.host)}\xBB`:""}`,o=t.job?`\`${t.budgetMb!==void 0&&t.service?`jobs.${t.job}.budget.services.${t.service}`:`jobs.${t.job}.budget`}\` in lensmcp.json`:"its job's budget in lensmcp.json \u2192 jobs",{limitMb:i,peakMb:r,budgetMb:n}=t;let l;if(i!==void 0&&n!==void 0){const d=Math.round(i)-Math.round(n);l=d>0?`It was killed at its ${a(i)} limit \u2014 ${a(d)} over the ${a(n)} it declares. Raise ${o} to what it takes (more than ${a(i)}), and the container's memory limit with it.`:d===0?`It was killed at its ${a(i)} limit, which is all it declares. Raise ${o} to what it takes, and the container's memory limit with it.`:`It was killed at its ${a(i)} limit, ${a(-d)} under the ${a(n)} it declares. Raise the container's memory limit to its budget (${o}) \u2014 and both, if it takes more.`}else if(i!==void 0)l=`It was killed at its ${a(i)} limit. Raise the limit, and ${o}, to what it takes.`;else if(r!==void 0&&n!==void 0){const d=Math.round(r)-Math.round(n);l=d>0?`It held ${a(r)} at its peak \u2014 ${a(d)} over the ${a(n)} it declares. Raise ${o} to what it takes, so the queue lets the job in only when Docker's VM has that much.`:`It held ${a(r)} at its peak, within the ${a(n)} it declares (${o}): it was killed at a lower limit of its own, or when Docker's VM ran out. Check its memory limit in the compose file, and what else the VM held.`}else r!==void 0?l=`It held ${a(r)} at its peak. Check ${o} against that, and the container's memory limit.`:n!==void 0?l=`Its peak was not sampled. It declares ${a(n)}: raise ${o} to what it takes, and the container's memory limit with it.`:l=`Raise ${o} to what the service takes, and the container's memory limit with it.`;const u=[i!==void 0?`killed at its ${a(i)} limit`:"killed for memory",r!==void 0?`peak ${a(r)}`:void 0,n!==void 0?`budget ${a(n)}`:void 0,t.run?`run ${t.run}`:void 0,t.seen==="inspect"?"found by the inspect at the run's end":void 0,t.host?`on the worker ${f(t.host)}`:void 0,t.context?`Docker context ${t.context}`:void 0];return{cause:{id:x("cause",[CONTAINER_OOM_ERROR,t.job,t.service]),errorName:CONTAINER_OOM_ERROR,message:e},title:`${CONTAINER_OOM_ERROR}: ${e}`,headline:s,hint:l,facts:u.filter(Boolean).join(" \xB7 "),where:t.job?`Docker job ${t.job}`:"Docker"}}m(y,"A"),c(y,"oomWords");function E(t){const e=t.host?` on the worker ${f(t.host)}`:"",s=`Docker stopped answering${t.context?` (context ${t.context})`:""}${e}`,o=[...new Set(t.runs.map(b=>b.job).filter(b=>!!b))],i=t.runs.length,r=t.host?`Docker on the worker \xAB${f(t.host)}\xBB`:"Docker",n=i===0?`${r} stopped answering while LensMCP ran work in it`:i===1?`${r} stopped answering while ${o[0]?`the job \xAB${o[0]}\xBB`:"a job"} ran: its containers went with it`:`${r} stopped answering while ${i} runs were in it${o.length?` (${o.map(b=>`\xAB${b}\xBB`).join(", ")})`:""}: their containers went with it`,{vmTotalMb:l,vmAvailableMb:u}=t,d=u===void 0?void 0:`${a(u)} free${l!==void 0?` of ${a(l)}`:""}`,M=u===void 0?"If nobody stopped it, its VM most likely ran out of memory: compare the jobs' budgets in lensmcp.json with what Docker's VM has.":u<=_?`Its VM had ${d} when it was last read: it most likely ran out of memory. Let less in at once (the jobs' budgets in lensmcp.json decide), or give Docker's VM more.`:`Its VM had ${d} when it was last read, so memory is not the likely reason: was Docker stopped or restarted?`,A=[i?`${i} run${i===1?"":"s"} lost: ${t.runs.map(b=>`${b.job??"a job"} (run ${b.run})`).join(", ")}`:void 0,t.why,d?`VM ${d}`:void 0,t.killed?.length?`killed for memory before it went: ${t.killed.join(", ")}`:void 0];return{cause:{id:x("cause",t.host?[DOCKER_ENGINE_LOST_ERROR,t.context,t.host.peer]:[DOCKER_ENGINE_LOST_ERROR,t.context]),errorName:DOCKER_ENGINE_LOST_ERROR,message:s},title:`${DOCKER_ENGINE_LOST_ERROR}: ${s}`,headline:n,hint:`Start Docker again${e} and run ${i>1?"the jobs":"the job"} again: a run lost with the engine has no result. ${M}`,facts:A.filter(Boolean).join(" \xB7 "),where:`${t.context?`Docker context ${t.context}`:"Docker"}${e}`}}m(E,"I"),c(E,"engineWords");export function dockerErrorWords(t){return t.kind===v?y(t):E(t)}m(dockerErrorWords,"dockerErrorWords"),c(dockerErrorWords,"dockerErrorWords");export function mergeDockerError(t,e){if(t.kind===v){if(e.kind!==v)return t;const r=Math.max(t.peakMb??0,e.peakMb??0);return w({...e,...t,seen:t.seen==="event"||e.seen==="event"?"event":t.seen??e.seen,peakMb:r>0?r:void 0})}const s=t;if(e.kind===v)return e.service&&!s.killed?.includes(e.service)?{...s,killed:[...s.killed??[],e.service].slice(0,$)}:t;const o=new Map(s.runs.map(r=>[r.run,r]));for(const r of e.runs)(!o.has(r.run)||!o.get(r.run).job&&r.job)&&o.set(r.run,r);const i=[...new Set([...s.killed??[],...e.killed??[]])];return w({...e,...s,runs:[...o.values()].slice(0,$),vmAvailableMb:s.vmAvailableMb!==void 0&&e.vmAvailableMb!==void 0?Math.min(s.vmAvailableMb,e.vmAvailableMb):s.vmAvailableMb??e.vmAvailableMb,killed:i.length?i:void 0})}m(mergeDockerError,"mergeDockerError"),c(mergeDockerError,"mergeDockerError");export const DOCKER_ENGINE_LOSS_SAME_MS=6e4;const D=2e3,C=200;export class DockerErrorLedger{static{m(this,"DockerErrorLedger")}static{c(this,"DockerErrorLedger")}constructor(){this.kills=new Map,this.losses=new Map,this.lostRuns=new Map}account(e,s,o){if(e.kind===j){const l=e.host?`${e.host.peer}\0${e.context??""}`:e.context??"",u=this.losses.get(l),d=u&&Math.abs(o-u.at)<=DOCKER_ENGINE_LOSS_SAME_MS?u.told:void 0;d||this.remember(this.losses,l,{told:s,at:o},C);for(const M of e.runs)this.remember(this.lostRuns,M.run,d??s,D);return d}const i=e.seen!=="inspect",r=e.run&&e.container?`${e.run}\0${e.container}`:e.run&&e.service?`${e.run}\0\0${e.service}`:void 0,n=r?this.kills.get(r):void 0;if(!n){const l=!i&&e.run?this.lostRuns.get(e.run):void 0;if(l)return l;r&&this.remember(this.kills,r,{told:s,live:i?1:0},D);return}if(!i)return n.told;if(n.live===0)return n.live=1,n.told;n.live+=1,n.told=s}remember(e,s,o,i){e.delete(s),e.set(s,o),e.size>i&&e.delete(e.keys().next().value)}}
1
+ "use strict";var O=Object.defineProperty;var m=(e,o)=>O(e,"name",{value:o,configurable:!0});var B=Object.defineProperty,b=m((e,o)=>B(e,"name",{value:o,configurable:!0}),"m"),I=Object.defineProperty,c=b((e,o)=>I(e,"name",{value:o,configurable:!0}),"c");import{CONTAINER_OOM as k,DOCKER_ENGINE_LOST as g,DOCKER_RUN_FIELD as N}from"./docker-jobs.js";import{joinId as E}from"./error-cause.js";const _=200,f=50,$=c(e=>typeof e=="object"&&e!==null&&!Array.isArray(e),"isObj"),h=c(e=>{if(typeof e!="string")return;const o=e.trim();return o?o.slice(0,_):void 0},"name"),p=c(e=>typeof e=="number"&&Number.isFinite(e)&&e>0?e:void 0,"someMb"),C=c(e=>typeof e=="number"&&Number.isFinite(e)&&e>=0?e:void 0,"anyMb"),w=c(e=>Object.fromEntries(Object.entries(e).filter(([,o])=>o!==void 0)),"defined"),D=c(e=>{if(!$(e))return;const o=h(e.peer);if(!o)return;const n=h(e.name);return n?{peer:o,name:n}:{peer:o}},"hostOf"),M=c(e=>e.name??e.peer,"hostWord");export function readDockerError(e){if($(e)){if(e.kind===k)return w({kind:k,run:h(e.run),job:h(e.job),service:h(e.service),container:h(e.container),seen:e.seen==="event"||e.seen==="inspect"?e.seen:void 0,limitMb:p(e.limitMb),peakMb:p(e.peakMb),budgetMb:p(e.budgetMb),context:h(e.context),host:D(e.host)});if(e.kind===g){const o=new Map;for(const r of Array.isArray(e.runs)?e.runs:[]){const i=$(r)?h(r.run):h(r),t=$(r)?h(r.job):void 0;i&&!o.has(i)&&o.size<f&&o.set(i,{run:i,...t?{job:t}:{}})}const n=Array.isArray(e.killed)?[...new Set(e.killed.map(h).filter(r=>!!r))].slice(0,f):[];return w({kind:g,context:h(e.context),runs:[...o.values()],why:h(e.why),vmTotalMb:p(e.vmTotalMb),vmAvailableMb:C(e.vmAvailableMb),killed:n.length?n:void 0,host:D(e.host)})}}}m(readDockerError,"readDockerError"),b(readDockerError,"readDockerError"),c(readDockerError,"readDockerError");export function dockerErrorRuns(e){return e.kind===k?e.run?[e.run]:[]:e.runs.map(o=>o.run)}m(dockerErrorRuns,"dockerErrorRuns"),b(dockerErrorRuns,"dockerErrorRuns"),c(dockerErrorRuns,"dockerErrorRuns");export function dockerRunOfEvent(e){return $(e)?h(e[N]):void 0}m(dockerRunOfEvent,"dockerRunOfEvent"),b(dockerRunOfEvent,"dockerRunOfEvent"),c(dockerRunOfEvent,"dockerRunOfEvent");export const CONTAINER_OOM_ERROR="ContainerOOMKilled",DOCKER_ENGINE_LOST_ERROR="DockerEngineLost";const L=256,a=c(e=>`${Math.round(e)} MiB`,"mib");function x(e){const o=`${e.service??"a container"} ran out of memory in ${e.job??"a Docker job"}`,n=`${e.service?`\xAB${e.service}\xBB`:"A container"} ran out of memory and was killed, in ${e.job?`the Docker job \xAB${e.job}\xBB`:"a Docker job"}${e.host?` on the worker \xAB${M(e.host)}\xBB`:""}`,r=e.job?`\`${e.budgetMb!==void 0&&e.service?`jobs.${e.job}.budget.services.${e.service}`:`jobs.${e.job}.budget`}\` in lensmcp.json`:"its job's budget in lensmcp.json \u2192 jobs",{limitMb:i,peakMb:t,budgetMb:s}=e;let l;if(i!==void 0&&s!==void 0){const d=Math.round(i)-Math.round(s);l=d>0?`It was killed at its ${a(i)} limit \u2014 ${a(d)} over the ${a(s)} it declares. Raise ${r} to what it takes (more than ${a(i)}), and the container's memory limit with it.`:d===0?`It was killed at its ${a(i)} limit, which is all it declares. Raise ${r} to what it takes, and the container's memory limit with it.`:`It was killed at its ${a(i)} limit, ${a(-d)} under the ${a(s)} it declares. Raise the container's memory limit to its budget (${r}) \u2014 and both, if it takes more.`}else if(i!==void 0)l=`It was killed at its ${a(i)} limit. Raise the limit, and ${r}, to what it takes.`;else if(t!==void 0&&s!==void 0){const d=Math.round(t)-Math.round(s);l=d>0?`It held ${a(t)} at its peak \u2014 ${a(d)} over the ${a(s)} it declares. Raise ${r} to what it takes, so the queue lets the job in only when Docker's VM has that much.`:`It held ${a(t)} at its peak, within the ${a(s)} it declares (${r}): it was killed at a lower limit of its own, or when Docker's VM ran out. Check its memory limit in the compose file, and what else the VM held.`}else t!==void 0?l=`It held ${a(t)} at its peak. Check ${r} against that, and the container's memory limit.`:s!==void 0?l=`Its peak was not sampled. It declares ${a(s)}: raise ${r} to what it takes, and the container's memory limit with it.`:l=`Raise ${r} to what the service takes, and the container's memory limit with it.`;const u=[i!==void 0?`killed at its ${a(i)} limit`:"killed for memory",t!==void 0?`peak ${a(t)}`:void 0,s!==void 0?`budget ${a(s)}`:void 0,e.run?`run ${e.run}`:void 0,e.seen==="inspect"?"found by the inspect at the run's end":void 0,e.host?`on the worker ${M(e.host)}`:void 0,e.context?`Docker context ${e.context}`:void 0];return{cause:{id:E("cause",[CONTAINER_OOM_ERROR,e.job,e.service]),errorName:CONTAINER_OOM_ERROR,message:o},title:`${CONTAINER_OOM_ERROR}: ${o}`,headline:n,hint:l,facts:u.filter(Boolean).join(" \xB7 "),where:e.job?`Docker job ${e.job}`:"Docker"}}m(x,"y"),b(x,"A"),c(x,"oomWords");function y(e){const o=e.host?` on the worker ${M(e.host)}`:"",n=`Docker stopped answering${e.context?` (context ${e.context})`:""}${o}`,r=[...new Set(e.runs.map(v=>v.job).filter(v=>!!v))],i=e.runs.length,t=e.host?`Docker on the worker \xAB${M(e.host)}\xBB`:"Docker",s=i===0?`${t} stopped answering while LensMCP ran work in it`:i===1?`${t} stopped answering while ${r[0]?`the job \xAB${r[0]}\xBB`:"a job"} ran: its containers went with it`:`${t} stopped answering while ${i} runs were in it${r.length?` (${r.map(v=>`\xAB${v}\xBB`).join(", ")})`:""}: their containers went with it`,{vmTotalMb:l,vmAvailableMb:u}=e,d=u===void 0?void 0:`${a(u)} free${l!==void 0?` of ${a(l)}`:""}`,j=u===void 0?"If nobody stopped it, its VM most likely ran out of memory: compare the jobs' budgets in lensmcp.json with what Docker's VM has.":u<=L?`Its VM had ${d} when it was last read: it most likely ran out of memory. Let less in at once (the jobs' budgets in lensmcp.json decide), or give Docker's VM more.`:`Its VM had ${d} when it was last read, so memory is not the likely reason: was Docker stopped or restarted?`,A=[i?`${i} run${i===1?"":"s"} lost: ${e.runs.map(v=>`${v.job??"a job"} (run ${v.run})`).join(", ")}`:void 0,e.why,d?`VM ${d}`:void 0,e.killed?.length?`killed for memory before it went: ${e.killed.join(", ")}`:void 0];return{cause:{id:E("cause",e.host?[DOCKER_ENGINE_LOST_ERROR,e.context,e.host.peer]:[DOCKER_ENGINE_LOST_ERROR,e.context]),errorName:DOCKER_ENGINE_LOST_ERROR,message:n},title:`${DOCKER_ENGINE_LOST_ERROR}: ${n}`,headline:s,hint:`Start Docker again${o} and run ${i>1?"the jobs":"the job"} again: a run lost with the engine has no result. ${j}`,facts:A.filter(Boolean).join(" \xB7 "),where:`${e.context?`Docker context ${e.context}`:"Docker"}${o}`}}m(y,"E"),b(y,"I"),c(y,"engineWords");export function dockerErrorWords(e){return e.kind===k?x(e):y(e)}m(dockerErrorWords,"dockerErrorWords"),b(dockerErrorWords,"dockerErrorWords"),c(dockerErrorWords,"dockerErrorWords");export function mergeDockerError(e,o){if(e.kind===k){if(o.kind!==k)return e;const t=Math.max(e.peakMb??0,o.peakMb??0);return w({...o,...e,seen:e.seen==="event"||o.seen==="event"?"event":e.seen??o.seen,peakMb:t>0?t:void 0})}const n=e;if(o.kind===k)return o.service&&!n.killed?.includes(o.service)?{...n,killed:[...n.killed??[],o.service].slice(0,f)}:e;const r=new Map(n.runs.map(t=>[t.run,t]));for(const t of o.runs)(!r.has(t.run)||!r.get(t.run).job&&t.job)&&r.set(t.run,t);const i=[...new Set([...n.killed??[],...o.killed??[]])];return w({...o,...n,runs:[...r.values()].slice(0,f),vmAvailableMb:n.vmAvailableMb!==void 0&&o.vmAvailableMb!==void 0?Math.min(n.vmAvailableMb,o.vmAvailableMb):n.vmAvailableMb??o.vmAvailableMb,killed:i.length?i:void 0})}m(mergeDockerError,"mergeDockerError"),b(mergeDockerError,"mergeDockerError"),c(mergeDockerError,"mergeDockerError");export const DOCKER_ENGINE_LOSS_SAME_MS=6e4;const R=2e3,S=200;export class DockerErrorLedger{static{m(this,"DockerErrorLedger")}static{b(this,"DockerErrorLedger")}static{c(this,"DockerErrorLedger")}constructor(){this.kills=new Map,this.losses=new Map,this.lostRuns=new Map}account(o,n,r){if(o.kind===g){const l=o.host?`${o.host.peer}\0${o.context??""}`:o.context??"",u=this.losses.get(l),d=u&&Math.abs(r-u.at)<=DOCKER_ENGINE_LOSS_SAME_MS?u.told:void 0;d||this.remember(this.losses,l,{told:n,at:r},S);for(const j of o.runs)this.remember(this.lostRuns,j.run,d??n,R);return d}const i=o.seen!=="inspect",t=o.run&&o.container?`${o.run}\0${o.container}`:o.run&&o.service?`${o.run}\0\0${o.service}`:void 0,s=t?this.kills.get(t):void 0;if(!s){const l=!i&&o.run?this.lostRuns.get(o.run):void 0;if(l)return l;t&&this.remember(this.kills,t,{told:n,live:i?1:0},R);return}if(!i)return s.told;if(s.live===0)return s.live=1,s.told;s.live+=1,s.told=n}remember(o,n,r,i){o.delete(n),o.set(n,r),o.size>i&&o.delete(o.keys().next().value)}}