devcontour-harness-ui 0.0.0-stage → 0.1.0-alpha.2

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 (58) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +143 -2
  3. package/dist/app/assets/index-Det9VYJC.css +1 -0
  4. package/dist/app/assets/index-veveke8K.js +9 -0
  5. package/dist/app/index.html +13 -0
  6. package/dist/demo/ru/view.sample.json +483 -0
  7. package/dist/demo/ru/work.accepted.sample.json +187 -0
  8. package/dist/demo/ru/work.sample.json +171 -0
  9. package/dist/demo/view.sample.json +483 -0
  10. package/dist/demo/work.accepted.sample.json +187 -0
  11. package/dist/demo/work.sample.json +171 -0
  12. package/dist/lib/cli.d.ts +2 -0
  13. package/dist/lib/cli.js +160 -0
  14. package/dist/lib/components/Activity.d.ts +13 -0
  15. package/dist/lib/components/Activity.js +19 -0
  16. package/dist/lib/components/Decisions.d.ts +6 -0
  17. package/dist/lib/components/Decisions.js +19 -0
  18. package/dist/lib/components/Health.d.ts +8 -0
  19. package/dist/lib/components/Health.js +24 -0
  20. package/dist/lib/components/History.d.ts +32 -0
  21. package/dist/lib/components/History.js +129 -0
  22. package/dist/lib/components/Overview.d.ts +19 -0
  23. package/dist/lib/components/Overview.js +54 -0
  24. package/dist/lib/components/Reviews.d.ts +23 -0
  25. package/dist/lib/components/Reviews.js +22 -0
  26. package/dist/lib/components/Settings.d.ts +21 -0
  27. package/dist/lib/components/Settings.js +77 -0
  28. package/dist/lib/components/WorkDetail.d.ts +18 -0
  29. package/dist/lib/components/WorkDetail.js +96 -0
  30. package/dist/lib/components/common.d.ts +71 -0
  31. package/dist/lib/components/common.js +85 -0
  32. package/dist/lib/index.d.ts +10 -0
  33. package/dist/lib/index.js +12 -0
  34. package/dist/lib/model/compat.d.ts +36 -0
  35. package/dist/lib/model/compat.js +365 -0
  36. package/dist/lib/model/dict.d.ts +387 -0
  37. package/dist/lib/model/dict.js +1119 -0
  38. package/dist/lib/model/format.d.ts +34 -0
  39. package/dist/lib/model/format.js +88 -0
  40. package/dist/lib/model/i18n.d.ts +44 -0
  41. package/dist/lib/model/i18n.js +109 -0
  42. package/dist/lib/model/index.d.ts +6 -0
  43. package/dist/lib/model/index.js +8 -0
  44. package/dist/lib/model/source.d.ts +16 -0
  45. package/dist/lib/model/source.js +57 -0
  46. package/dist/lib/model/view.d.ts +474 -0
  47. package/dist/lib/model/view.js +10 -0
  48. package/dist/lib/server/harness.d.ts +44 -0
  49. package/dist/lib/server/harness.js +172 -0
  50. package/dist/lib/server/serve.d.ts +62 -0
  51. package/dist/lib/server/serve.js +302 -0
  52. package/dist/lib/styles.css +485 -0
  53. package/docs/design.md +1689 -0
  54. package/docs/harness-proposals.md +560 -0
  55. package/docs/release-notes/0.1.0-alpha.1.md +96 -0
  56. package/docs/release-notes/0.1.0-alpha.2.md +218 -0
  57. package/package.json +75 -4
  58. package/skills/harness-ui/SKILL.md +246 -0
@@ -0,0 +1,85 @@
1
+ import { Fragment as _Fragment, jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
2
+ import { dict, label } from "../model/dict.js";
3
+ import { formatClock, targetSentence } from "../model/i18n.js";
4
+ /** «что это значит»: a `<details>` disclosure from the glossary (design §12). */
5
+ export function Term({ id, t, named }) {
6
+ const g = t.glossary[id];
7
+ return (_jsxs("details", { className: "hui-term", children: [_jsx("summary", { children: named ? (_jsxs(_Fragment, { children: [g.term, ": ", t.whatItMeans] })) : (_jsxs(_Fragment, { children: [t.whatItMeans, _jsxs("span", { className: "hui-sr", children: [" \u2014 ", g.term] })] })) }), _jsxs("p", { children: [_jsx("strong", { children: g.term }), ": ", g.meaning] })] }));
8
+ }
9
+ /** Section heading with an optional glossary disclosure beside it. */
10
+ export function Heading({ children, term, t, id, level = 3, }) {
11
+ const H = level === 2 ? 'h2' : 'h3';
12
+ return (_jsxs("div", { className: "hui-heading", children: [_jsx(H, { className: level === 2 ? 'hui-title' : 'hui-subtitle', id: id, children: children }), term ? _jsx(Term, { id: term, t: t }) : null] }));
13
+ }
14
+ export function WorkRef({ id, onOpenWork, workHref, suffix, children, }) {
15
+ const text = children ?? _jsx("code", { children: id });
16
+ if (workHref)
17
+ return (_jsx("a", { className: "hui-link", href: workHref(id) + (suffix ?? ''), children: text }));
18
+ if (onOpenWork)
19
+ return (_jsx("button", { type: "button", className: "hui-link", onClick: () => onOpenWork(id), children: text }));
20
+ return _jsx(_Fragment, { children: text });
21
+ }
22
+ /** Clock of an instant, or "unknown" — never a guess. */
23
+ export function clockOf(iso, t, timeZone, nowMs) {
24
+ if (iso === undefined)
25
+ return t.unknown;
26
+ return formatClock(iso, timeZone, nowMs) ?? t.unknown;
27
+ }
28
+ export const actorLabel = (t, actor) => actor === null || actor === undefined ? t.unknown : label(t.actor, String(actor));
29
+ /** One reason a work waits: the plain text or the code, and who acts. */
30
+ export function BlockerLine({ b, t }) {
31
+ return (_jsxs("li", { className: "hui-item", "data-status": "blocked", children: [_jsx("span", { children: b.plain && b.plain.trim() ? b.plain : t.blocker.noReason(b.code) }), ' — ', _jsx("span", { className: "hui-who", children: b.actor === null ? t.blocker.nobody : t.blocker.whoActs(actorLabel(t, b.actor)) }), ' ', _jsx("code", { className: "hui-muted hui-code", children: b.code })] }));
32
+ }
33
+ /**
34
+ * Where an accepted work is, with a link to its verification rows. Only for
35
+ * works the harness reports as accepted (`stage.name: done` or a target).
36
+ */
37
+ export function AcceptedLine({ w, lang, linkProps, verificationHref, }) {
38
+ const t = dict(lang);
39
+ const where = w.target
40
+ ? targetSentence(w.target, lang)
41
+ : w.resultSha
42
+ ? t.target.noTarget(w.resultSha)
43
+ : t.target.noLocation;
44
+ return (_jsxs("div", { "data-status": "accepted", className: "hui-accepted", children: [_jsx("span", { children: where }), ' ', verificationHref ? (_jsx("a", { className: "hui-link", href: verificationHref, children: t.target.seeChecks })) : (_jsx(WorkRef, { id: w.id, suffix: "#verification", ...linkProps, children: t.target.seeChecks }))] }));
45
+ }
46
+ /** A note that a list was clipped by the projection. */
47
+ export function Clipped({ n, t }) {
48
+ return n ? _jsx("p", { className: "hui-muted hui-clipped", children: t.listClipped(n) }) : null;
49
+ }
50
+ /**
51
+ * A stage badge that keeps the wording rules: an accepted stage says where
52
+ * the result is and links to its checks; a stopped or waiting-on-conditions
53
+ * stage says why and who acts. Other stages are a plain badge.
54
+ */
55
+ export function StageStatus({ w, lang, linkProps, verificationHref, }) {
56
+ const t = dict(lang);
57
+ const name = w.stage.name;
58
+ const text = label(t.stage, name);
59
+ if (name === 'done') {
60
+ const remote = w.target
61
+ ? Object.hasOwn(t.target.short, w.target.remote.state)
62
+ ? t.target.short[w.target.remote.state]
63
+ : t.target.shortUnknown
64
+ : t.target.shortUnknown;
65
+ return (_jsxs("span", { className: "hui-badge hui-status", "data-status": "accepted", children: [text, "; ", remote, ";", ' ', verificationHref ? (_jsx("a", { className: "hui-link", href: verificationHref, children: t.target.seeChecks })) : (_jsx(WorkRef, { id: w.id, suffix: "#verification", ...linkProps, children: t.target.seeChecks }))] }));
66
+ }
67
+ if (name === 'stopped' || name === 'blocked') {
68
+ const b = w.blockers[0];
69
+ const reason = b
70
+ ? b.plain && b.plain.trim()
71
+ ? b.plain
72
+ : t.blocker.noReason(b.code)
73
+ : w.stage.needs
74
+ ? w.stage.needs.action
75
+ : t.blocker.stoppedNoReason;
76
+ const actor = b ? b.actor : w.stage.needs ? w.stage.needs.actor : undefined;
77
+ const who = actor === null
78
+ ? t.blocker.nobody
79
+ : actor === undefined
80
+ ? t.blocker.whoActs(t.unknown)
81
+ : t.blocker.whoActs(actorLabel(t, actor));
82
+ return (_jsxs("span", { className: "hui-badge hui-status hui-warn", "data-status": "blocked", children: [text, ": ", reason, " \u2014 ", _jsx("span", { className: "hui-who", children: who })] }));
83
+ }
84
+ return _jsx("span", { className: "hui-badge", children: text });
85
+ }
@@ -0,0 +1,10 @@
1
+ export * from './model/index.ts';
2
+ export { Overview, type OverviewProps } from './components/Overview.tsx';
3
+ export { WorkDetail, verificationWords, type WorkDetailProps } from './components/WorkDetail.tsx';
4
+ export { Reviews, type ReviewsProps } from './components/Reviews.tsx';
5
+ export { Decisions, type DecisionsProps } from './components/Decisions.tsx';
6
+ export { Activity, type ActivityFilter, type ActivityProps } from './components/Activity.tsx';
7
+ export { Settings, effectiveCodeReview, type SettingsProps } from './components/Settings.tsx';
8
+ export { History, cumulativeSpend, perHour, type HistoryProps } from './components/History.tsx';
9
+ export { Health, type HealthProps } from './components/Health.tsx';
10
+ export { Term, type ScreenProps } from './components/common.tsx';
@@ -0,0 +1,12 @@
1
+ // devcontour-harness-ui — React components over the harness operator view.
2
+ // Styles: import 'devcontour-harness-ui/styles.css' once in the host.
3
+ export * from "./model/index.js";
4
+ export { Overview } from "./components/Overview.js";
5
+ export { WorkDetail, verificationWords } from "./components/WorkDetail.js";
6
+ export { Reviews } from "./components/Reviews.js";
7
+ export { Decisions } from "./components/Decisions.js";
8
+ export { Activity } from "./components/Activity.js";
9
+ export { Settings, effectiveCodeReview } from "./components/Settings.js";
10
+ export { History, cumulativeSpend, perHour } from "./components/History.js";
11
+ export { Health } from "./components/Health.js";
12
+ export { Term } from "./components/common.js";
@@ -0,0 +1,36 @@
1
+ import { type OperatorView, type WorkDetailView } from './view.ts';
2
+ export type ViewCheck = {
3
+ ok: true;
4
+ view: OperatorView;
5
+ newerRevision: boolean;
6
+ } | {
7
+ ok: false;
8
+ code: 'NOT_A_VIEW' | 'VIEW_VERSION_UNSUPPORTED' | 'VIEW_UNAVAILABLE';
9
+ message: string;
10
+ };
11
+ /** Highest `viewRevision` this build knows how to render in full. */
12
+ export declare const KNOWN_VIEW_REVISION = 0;
13
+ /**
14
+ * An ISO 8601 instant with an explicit zone (`Z` or `±HH:MM`) and a real
15
+ * calendar date: `2026-02-30T…` or a zone-less local time is refused, so the
16
+ * footer never shows a shifted or reader-dependent time. Every instant the
17
+ * harness schema accepts (any number of fraction digits, years 0000-9999)
18
+ * passes.
19
+ */
20
+ export declare function isInstant(v: unknown): boolean;
21
+ /**
22
+ * Epoch ms of an instant accepted by `isInstant`; NaN otherwise. Fractions
23
+ * longer than milliseconds are cut to three digits first, since `Date.parse`
24
+ * refuses them.
25
+ */
26
+ export declare function instantMs(v: string): number;
27
+ export type WorkDetailCheck = {
28
+ ok: true;
29
+ detail: WorkDetailView;
30
+ newerRevision: boolean;
31
+ } | Extract<ViewCheck, {
32
+ ok: false;
33
+ }>;
34
+ /** The same gate for the work detail document (`harness view --work <id>`). */
35
+ export declare function checkWorkDetail(value: unknown): WorkDetailCheck;
36
+ export declare function checkView(value: unknown): ViewCheck;
@@ -0,0 +1,365 @@
1
+ // Compatibility gate between a view document and this UI build. The rule
2
+ // (docs/design.md, "Versioning"): the same `viewVersion` major is accepted,
3
+ // any `viewRevision` is accepted (unknown fields are ignored), a different
4
+ // major is refused with a reason the panel shows instead of guessing.
5
+ //
6
+ // The gate checks every field the components read, with the type the harness
7
+ // schema gives it (devcontour-harness schemas/operator-view.schema.json), so
8
+ // that a malformed document is refused here instead of throwing during render.
9
+ // It is not a full schema validator: the harness owns the schema, and
10
+ // tests/contract.test.ts checks that every schema-valid fixture passes here.
11
+ import { VIEW_VERSION } from "./view.js";
12
+ /** Highest `viewRevision` this build knows how to render in full. */
13
+ export const KNOWN_VIEW_REVISION = 0;
14
+ const isObject = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
15
+ const INSTANT = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(?::(\d{2})(\.\d+)?)?(Z|[+-](\d{2}):(\d{2}))$/;
16
+ /**
17
+ * An ISO 8601 instant with an explicit zone (`Z` or `±HH:MM`) and a real
18
+ * calendar date: `2026-02-30T…` or a zone-less local time is refused, so the
19
+ * footer never shows a shifted or reader-dependent time. Every instant the
20
+ * harness schema accepts (any number of fraction digits, years 0000-9999)
21
+ * passes.
22
+ */
23
+ export function isInstant(v) {
24
+ if (typeof v !== 'string')
25
+ return false;
26
+ const m = INSTANT.exec(v);
27
+ if (!m)
28
+ return false;
29
+ const [y, mo, d, h, mi, s] = m.slice(1, 7).map((x) => Number(x ?? 0));
30
+ const day = new Date(0);
31
+ // setUTCFullYear keeps years 0-99 as they are (Date.UTC maps them to 19xx).
32
+ day.setUTCFullYear(y, mo - 1, d);
33
+ return (day.getUTCFullYear() === y &&
34
+ day.getUTCMonth() === mo - 1 &&
35
+ day.getUTCDate() === d &&
36
+ h < 24 &&
37
+ mi < 60 &&
38
+ s < 60 &&
39
+ (m[8] === 'Z' || (Number(m[9]) < 24 && Number(m[10]) < 60)) &&
40
+ !Number.isNaN(instantMs(v)));
41
+ }
42
+ /**
43
+ * Epoch ms of an instant accepted by `isInstant`; NaN otherwise. Fractions
44
+ * longer than milliseconds are cut to three digits first, since `Date.parse`
45
+ * refuses them.
46
+ */
47
+ export function instantMs(v) {
48
+ const m = INSTANT.exec(v);
49
+ if (!m)
50
+ return Number.NaN;
51
+ const frac = m[7] ? m[7].slice(0, 4) : '';
52
+ const [y, mo, d, h, mi, s] = m.slice(1, 7).map((x) => x ?? '00');
53
+ return Date.parse(`${y}-${mo}-${d}T${h}:${mi}:${s}${frac}${m[8]}`);
54
+ }
55
+ const leaf = (ok) => (v, path, out) => {
56
+ if (!ok(v))
57
+ out.push(path);
58
+ };
59
+ const S = leaf((v) => typeof v === 'string');
60
+ const N = leaf((v) => typeof v === 'number' && Number.isFinite(v));
61
+ const C = leaf((v) => Number.isSafeInteger(v) && v >= 0);
62
+ const B = leaf((v) => typeof v === 'boolean');
63
+ const I = leaf(isInstant);
64
+ const opt = (c) => (v, path, out) => {
65
+ if (v !== undefined)
66
+ c(v, path, out);
67
+ };
68
+ const nul = (c) => (v, path, out) => {
69
+ if (v !== null)
70
+ c(v, path, out);
71
+ };
72
+ /** An array of at most `max` entries (the harness schema limits, design §3.10). */
73
+ const arr = (c, max) => (v, path, out) => {
74
+ if (!Array.isArray(v) || v.length > max)
75
+ return void out.push(path);
76
+ v.forEach((x, i) => c(x, `${path}[${i}]`, out));
77
+ };
78
+ const rec = (c) => (v, path, out) => {
79
+ if (!isObject(v))
80
+ return void out.push(path);
81
+ for (const [k, x] of Object.entries(v))
82
+ c(x, `${path}.${k}`, out);
83
+ };
84
+ const obj = (shape) => (v, path, out) => {
85
+ if (!isObject(v))
86
+ return void out.push(path);
87
+ for (const [k, c] of Object.entries(shape))
88
+ c(Object.hasOwn(v, k) ? v[k] : undefined, path ? `${path}.${k}` : k, out);
89
+ };
90
+ const bounded = obj({ value: N, bound: S });
91
+ const binding = obj({ runtime: S, model: opt(S), effort: opt(S) });
92
+ const source = obj({ producer: S, producerVersion: S, stateVersion: N, token: S });
93
+ const settings = obj({
94
+ policyDigest: S,
95
+ approvalMode: S,
96
+ mode: S,
97
+ concurrency: C,
98
+ roles: arr(obj({ role: S, writer: binding, repositoryId: opt(S) }), 100),
99
+ reviews: arr(obj({
100
+ kind: S,
101
+ scope: S,
102
+ repositoryId: opt(S),
103
+ role: opt(S),
104
+ reviewer: binding,
105
+ alternates: arr(binding, 10),
106
+ vendor: S,
107
+ }), 100),
108
+ thresholds: obj({
109
+ inputSeverity: N,
110
+ leadAnswersMaxSeverity: opt(N),
111
+ leadAnswersTechnical: opt(B),
112
+ criticalPaths: N,
113
+ maxAttempts: N,
114
+ repairBudget: N,
115
+ maxNeutralFailures: N,
116
+ reviewRoundCap: N,
117
+ reviewEscalationRounds: N,
118
+ }),
119
+ budgets: arr(obj({ scope: S, usd: opt(N), timeMs: opt(N) }), 3),
120
+ budgetOnUnknown: opt(S),
121
+ timeouts: obj({
122
+ runTimeoutMs: N,
123
+ leaseMs: N,
124
+ gateTimeoutFloorMs: opt(N),
125
+ stall: obj({ intervalMs: N, quietMs: N, stalledMs: N, action: S }),
126
+ }),
127
+ lean: obj({ state: S }),
128
+ defaulted: arr(S, 50),
129
+ });
130
+ const work = obj({
131
+ id: S,
132
+ graphId: S,
133
+ title: opt(S),
134
+ status: S,
135
+ stage: obj({
136
+ name: S,
137
+ step: opt(S),
138
+ since: opt(I),
139
+ next: arr(S, 10),
140
+ needs: opt(obj({ actor: nul(S), action: S })),
141
+ typical: opt(obj({ p50Ms: N, p90Ms: N, samples: N })),
142
+ }),
143
+ attempts: obj({
144
+ used: C,
145
+ max: C,
146
+ left: C,
147
+ failed: C,
148
+ interrupted: C,
149
+ rechecks: C,
150
+ neutral: obj({ used: C, max: C }),
151
+ line: opt(S),
152
+ lastFailure: opt(obj({ attempt: C, bucket: S, plain: S, at: opt(I) })),
153
+ }),
154
+ liveness: opt(S),
155
+ runtime: opt(S),
156
+ model: opt(S),
157
+ blockers: arr(obj({ code: S, plain: opt(S), actor: nul(S) }), 10),
158
+ dependsOn: opt(arr(S, 50)),
159
+ target: opt(obj({
160
+ repositoryId: S,
161
+ ref: S,
162
+ acceptedSha: opt(S),
163
+ remote: obj({ state: S, trackingRef: opt(S), reason: opt(S) }),
164
+ })),
165
+ question: opt(obj({ requestId: S, state: S, severity: N })),
166
+ spend: obj({ calls: N, usd: bounded, durationMs: N }),
167
+ resultSha: opt(S),
168
+ });
169
+ const review = obj({
170
+ kind: S,
171
+ subject: S,
172
+ workId: opt(S),
173
+ approved: B,
174
+ rounds: obj({ used: N, max: nul(N) }),
175
+ open: obj({ blocking: N, notes: N }),
176
+ accepted: N,
177
+ reviewer: opt(binding),
178
+ sameVendor: opt(B),
179
+ spend: obj({ calls: N, usd: bounded }),
180
+ findings: arr(obj({
181
+ id: S,
182
+ severity: S,
183
+ status: S,
184
+ rounds: opt(N),
185
+ disposition: opt(obj({ decision: S, by: S, round: N })),
186
+ title: opt(S),
187
+ }), 50),
188
+ escalation: opt(obj({ requestId: S, findings: arr(S, 50), answered: B })),
189
+ line: opt(S),
190
+ });
191
+ const question = (v, path, out) => {
192
+ obj({
193
+ state: S,
194
+ answerableBy: S,
195
+ impact: opt(S),
196
+ plain: opt(S),
197
+ answeredBy: opt(S),
198
+ title: opt(S),
199
+ createdAt: I,
200
+ })(v, path, out);
201
+ if (!isObject(v))
202
+ return;
203
+ // Paths kept from the first gate: ids and counts are reported together.
204
+ if (typeof v.requestId !== 'string' || typeof v.workId !== 'string')
205
+ out.push(`${path}.requestId`);
206
+ if (!Number.isSafeInteger(v.severity) || !Number.isSafeInteger(v.version))
207
+ out.push(`${path}.severity`);
208
+ else if (v.severity < 0 || v.version < 0)
209
+ out.push(`${path}.severity`);
210
+ };
211
+ const drift = obj({
212
+ workId: S,
213
+ repositoryId: S,
214
+ ref: S,
215
+ acceptedSha: S,
216
+ head: opt(S),
217
+ commitsSinceAccepted: opt(N),
218
+ filesSinceAccepted: opt(N),
219
+ diverged: opt(B),
220
+ unavailable: opt(S),
221
+ });
222
+ const overview = obj({
223
+ viewRevision: C,
224
+ generatedAt: I,
225
+ source,
226
+ settings,
227
+ works: arr(work, 500),
228
+ reviews: arr(review, 50),
229
+ questions: arr(question, 50),
230
+ escalations: arr(obj({ workId: opt(S), subject: opt(S), code: S, actor: S, action: S, since: I }), 50),
231
+ drift: arr(drift, 50),
232
+ progress: obj({
233
+ total: C,
234
+ byStage: rec(C),
235
+ running: C,
236
+ done: C,
237
+ waitingOperator: C,
238
+ queue: obj({ paused: B, reason: opt(S), detail: opt(S), actor: opt(S), action: opt(S) }),
239
+ }),
240
+ history: obj({
241
+ from: I,
242
+ to: I,
243
+ bucketMs: N,
244
+ load: arr(N, 500),
245
+ attemptsStarted: arr(N, 500),
246
+ attemptsFailed: arr(N, 500),
247
+ gatesPassed: arr(N, 500),
248
+ gatesFailed: arr(N, 500),
249
+ gatesReused: arr(N, 500),
250
+ spendUsd: arr(N, 500),
251
+ spendBound: S,
252
+ spendOpeningUsd: bounded,
253
+ budgetUsd: opt(N),
254
+ }),
255
+ health: obj({
256
+ controller: obj({ present: B, leaseUntil: opt(I) }),
257
+ stalledAttempts: C,
258
+ quietAttempts: C,
259
+ environmentFailures: C,
260
+ budgeting: S,
261
+ budgets: arr(obj({
262
+ scope: S,
263
+ id: opt(S),
264
+ state: S,
265
+ spentUsd: bounded,
266
+ limitUsd: opt(N),
267
+ spentMs: opt(N),
268
+ limitMs: opt(N),
269
+ }), 50),
270
+ spentTotalUsd: bounded,
271
+ drift: obj({ checked: C, drifted: C, unavailable: C }),
272
+ warnings: arr(obj({ code: S, message: S }), 20),
273
+ }),
274
+ activity: opt(arr(obj({ at: I, actor: S, action: S, workId: opt(S), subject: opt(S), plain: S }), 50)),
275
+ decisions: opt(arr(obj({
276
+ id: S,
277
+ kind: S,
278
+ by: S,
279
+ at: I,
280
+ workId: opt(S),
281
+ subject: opt(S),
282
+ findingId: opt(S),
283
+ requestId: opt(S),
284
+ temporary: B,
285
+ revisit: opt(S),
286
+ title: opt(S),
287
+ reason: opt(S),
288
+ }), 50)),
289
+ truncated: opt(rec(C)),
290
+ });
291
+ const detail = obj({
292
+ viewRevision: C,
293
+ generatedAt: I,
294
+ source,
295
+ work,
296
+ attempts: arr(obj({
297
+ attempt: C,
298
+ status: S,
299
+ failureBucket: opt(S),
300
+ interrupted: opt(B),
301
+ runtime: S,
302
+ model: opt(S),
303
+ startedAt: I,
304
+ finishedAt: opt(I),
305
+ stages: arr(obj({ stage: S, durationMs: opt(N), outcome: opt(S) }), 50),
306
+ }), 20),
307
+ verification: opt(arr(obj({
308
+ gate: S,
309
+ kind: S,
310
+ phase: opt(S),
311
+ result: S,
312
+ how: S,
313
+ by: opt(S),
314
+ attempt: opt(N),
315
+ at: opt(I),
316
+ }), 50)),
317
+ reviews: arr(review, 50),
318
+ questions: arr(question, 50),
319
+ drift: opt(drift),
320
+ truncated: opt(rec(C)),
321
+ });
322
+ function versionRefusal(value) {
323
+ if (!isObject(value) || typeof value.viewVersion !== 'number')
324
+ return { ok: false, code: 'NOT_A_VIEW', message: 'The document has no numeric viewVersion.' };
325
+ if (value.viewVersion !== VIEW_VERSION)
326
+ return {
327
+ ok: false,
328
+ code: 'VIEW_VERSION_UNSUPPORTED',
329
+ message: `View version ${value.viewVersion} is not supported by this panel ` +
330
+ `(expects ${VIEW_VERSION}). Install a matching devcontour-harness-ui.`,
331
+ };
332
+ return undefined;
333
+ }
334
+ function shapeRefusal(shape, value, what) {
335
+ const bad = [];
336
+ shape(value, '', bad);
337
+ if (!bad.length)
338
+ return undefined;
339
+ return {
340
+ ok: false,
341
+ code: 'NOT_A_VIEW',
342
+ message: `The ${what} is malformed: ${bad.slice(0, 5).join(', ')}${bad.length > 5 ? ', …' : ''}.`,
343
+ };
344
+ }
345
+ /** The same gate for the work detail document (`harness view --work <id>`). */
346
+ export function checkWorkDetail(value) {
347
+ const refused = versionRefusal(value) ?? shapeRefusal(detail, value, 'work detail');
348
+ if (refused)
349
+ return refused;
350
+ return {
351
+ ok: true,
352
+ detail: value,
353
+ newerRevision: value.viewRevision > KNOWN_VIEW_REVISION,
354
+ };
355
+ }
356
+ export function checkView(value) {
357
+ const refused = versionRefusal(value) ?? shapeRefusal(overview, value, 'view');
358
+ if (refused)
359
+ return refused;
360
+ return {
361
+ ok: true,
362
+ view: value,
363
+ newerRevision: value.viewRevision > KNOWN_VIEW_REVISION,
364
+ };
365
+ }