@kriya-ai/harness 0.0.0-stage → 0.2.0

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 (185) hide show
  1. package/README.md +379 -2
  2. package/SAFETY.md +162 -0
  3. package/THIRD_PARTY_NOTICES.md +7911 -0
  4. package/bin/kriya.js +577 -0
  5. package/bundle/cordis.patch.yml +397 -0
  6. package/contract/SOURCE.md +15 -0
  7. package/contract/contract.json +1355 -0
  8. package/package.json +57 -4
  9. package/plugins/anchor/index.js +56 -0
  10. package/plugins/anchor/package.json +13 -0
  11. package/plugins/approvals/index.js +183 -0
  12. package/plugins/approvals/package.json +13 -0
  13. package/plugins/brand/DESIGN.md +112 -0
  14. package/plugins/brand/client.js +826 -0
  15. package/plugins/brand/index.js +15 -0
  16. package/plugins/brand/package.json +25 -0
  17. package/plugins/brand/src/client.js +823 -0
  18. package/plugins/browser/index.js +218 -0
  19. package/plugins/browser/package.json +13 -0
  20. package/plugins/budget/index.js +108 -0
  21. package/plugins/budget/package.json +13 -0
  22. package/plugins/changes/client.js +245 -0
  23. package/plugins/changes/index.js +75 -0
  24. package/plugins/changes/package.json +22 -0
  25. package/plugins/edit/client.js +113 -0
  26. package/plugins/edit/index.js +58 -0
  27. package/plugins/edit/package.json +23 -0
  28. package/plugins/fs-freshness/index.js +28 -0
  29. package/plugins/fs-freshness/package.json +13 -0
  30. package/plugins/graph/client.js +178 -0
  31. package/plugins/graph/index.js +4 -0
  32. package/plugins/graph/package.json +22 -0
  33. package/plugins/kriya-handoff/index.js +194 -0
  34. package/plugins/kriya-handoff/package.json +13 -0
  35. package/plugins/kriya-tools/index.js +189 -0
  36. package/plugins/kriya-tools/package.json +13 -0
  37. package/plugins/loop/index.js +743 -0
  38. package/plugins/loop/package.json +13 -0
  39. package/plugins/mirror/index.js +235 -0
  40. package/plugins/mirror/package.json +13 -0
  41. package/plugins/overview/client.js +276 -0
  42. package/plugins/overview/index.js +95 -0
  43. package/plugins/overview/package.json +22 -0
  44. package/plugins/preview/client.js +337 -0
  45. package/plugins/preview/index.js +4 -0
  46. package/plugins/preview/package.json +22 -0
  47. package/plugins/progress/client.js +290 -0
  48. package/plugins/progress/index.js +100 -0
  49. package/plugins/progress/package.json +22 -0
  50. package/plugins/projects/client.js +249 -0
  51. package/plugins/projects/index.js +30 -0
  52. package/plugins/projects/package.json +24 -0
  53. package/plugins/rea/index.js +256 -0
  54. package/plugins/rea/package.json +10 -0
  55. package/plugins/rea/skill/LICENSE +21 -0
  56. package/plugins/rea/skill/SKILL.md +360 -0
  57. package/plugins/rea/skill/references/android-applications.md +36 -0
  58. package/plugins/rea/skill/references/connection-and-recovery.md +127 -0
  59. package/plugins/rea/skill/references/evidence-workflows.md +71 -0
  60. package/plugins/rea/skill/references/javascript-applications.md +218 -0
  61. package/plugins/rea/skill/references/native-and-artifacts.md +297 -0
  62. package/plugins/rea/skill/references/runtime-observation.md +78 -0
  63. package/plugins/remote/index.js +297 -0
  64. package/plugins/remote/package.json +10 -0
  65. package/plugins/router/index.js +84 -0
  66. package/plugins/router/package.json +13 -0
  67. package/plugins/sessions/client.js +68 -0
  68. package/plugins/sessions/index.js +79 -0
  69. package/plugins/sessions/package.json +20 -0
  70. package/plugins/skills/client.js +504 -0
  71. package/plugins/skills/index.js +166 -0
  72. package/plugins/skills/package.json +23 -0
  73. package/src/api.js +97 -0
  74. package/src/browser.js +286 -0
  75. package/src/changes.js +191 -0
  76. package/src/checkpoints.js +313 -0
  77. package/src/daemon.js +503 -0
  78. package/src/doctor.js +137 -0
  79. package/src/edit/core/anchors.js +102 -0
  80. package/src/edit/core/audio.js +158 -0
  81. package/src/edit/core/faces.js +99 -0
  82. package/src/edit/core/ffmpeg.js +258 -0
  83. package/src/edit/core/handoff.js +220 -0
  84. package/src/edit/core/history.js +90 -0
  85. package/src/edit/core/layout.js +92 -0
  86. package/src/edit/core/mix.js +115 -0
  87. package/src/edit/core/ops.js +602 -0
  88. package/src/edit/core/plan.js +266 -0
  89. package/src/edit/core/project.d.ts +134 -0
  90. package/src/edit/core/project.js +307 -0
  91. package/src/edit/core/reframe.js +125 -0
  92. package/src/edit/core/solver.js +416 -0
  93. package/src/edit/core/time.js +110 -0
  94. package/src/edit/core/tonemap.js +57 -0
  95. package/src/edit/director/ask.js +120 -0
  96. package/src/edit/director/gateway.js +16 -0
  97. package/src/edit/director/revise.js +186 -0
  98. package/src/edit/engine/capabilities.js +33 -0
  99. package/src/edit/engine/captions.js +154 -0
  100. package/src/edit/engine/color.js +269 -0
  101. package/src/edit/engine/confine.js +67 -0
  102. package/src/edit/engine/dna.js +148 -0
  103. package/src/edit/engine/index.js +473 -0
  104. package/src/edit/engine/loudness.js +43 -0
  105. package/src/edit/engine/media.js +57 -0
  106. package/src/edit/engine/motion.js +281 -0
  107. package/src/edit/engine/packs.js +87 -0
  108. package/src/edit/engine/probe.js +101 -0
  109. package/src/edit/engine/receipt.js +123 -0
  110. package/src/edit/engine/tool.js +101 -0
  111. package/src/edit/gates/copy.js +113 -0
  112. package/src/edit/gates/index.js +430 -0
  113. package/src/edit/gates/picture.js +130 -0
  114. package/src/edit/gates/sound.js +58 -0
  115. package/src/edit/gates/speech.js +127 -0
  116. package/src/edit/gates/text.js +196 -0
  117. package/src/edit/gates/text.swift +22 -0
  118. package/src/edit/graph/index.js +139 -0
  119. package/src/edit/graph/journal.js +69 -0
  120. package/src/edit/graph/scheduler.js +79 -0
  121. package/src/edit/host/client.js +58 -0
  122. package/src/edit/host/deliver.js +119 -0
  123. package/src/edit/host/jobs.js +84 -0
  124. package/src/edit/host/main.js +135 -0
  125. package/src/edit/host/paths.js +11 -0
  126. package/src/edit/host/projects.js +415 -0
  127. package/src/edit/host/server.js +391 -0
  128. package/src/edit/host/taste.js +135 -0
  129. package/src/edit/host/tavi.js +417 -0
  130. package/src/edit/host/watch.js +141 -0
  131. package/src/edit/index/db.js +109 -0
  132. package/src/edit/index/index.js +236 -0
  133. package/src/edit/index/layers/faces.js +78 -0
  134. package/src/edit/index/layers/faces.swift +18 -0
  135. package/src/edit/index/layers/meta.js +35 -0
  136. package/src/edit/index/layers/music.js +146 -0
  137. package/src/edit/index/layers/quality.js +120 -0
  138. package/src/edit/index/layers/retakes.js +132 -0
  139. package/src/edit/index/layers/screen.js +99 -0
  140. package/src/edit/index/layers/shots.js +29 -0
  141. package/src/edit/index/layers/sound.js +42 -0
  142. package/src/edit/index/layers/words.js +64 -0
  143. package/src/edit/index/story.js +248 -0
  144. package/src/edit/index/views.js +71 -0
  145. package/src/edit/loop/governor.js +112 -0
  146. package/src/edit/loop/loop.js +69 -0
  147. package/src/edit/loop/make.js +115 -0
  148. package/src/edit/loop/repair.js +97 -0
  149. package/src/edit/loop/replay.js +32 -0
  150. package/src/edit/recipes/multicam.js +461 -0
  151. package/src/edit/recipes/reel.js +202 -0
  152. package/src/edit/recipes/short-from-long.js +237 -0
  153. package/src/edit/recipes/tutorial.js +137 -0
  154. package/src/edit/recipes/youtube.js +155 -0
  155. package/src/edit/runtime/cli.js +126 -0
  156. package/src/edit/runtime/doctor.js +122 -0
  157. package/src/edit/runtime/fetch.js +15 -0
  158. package/src/edit/runtime/licences.js +88 -0
  159. package/src/edit/runtime/manifest.js +73 -0
  160. package/src/edit/runtime/setup.js +252 -0
  161. package/src/failure.js +69 -0
  162. package/src/gateway-proxy.js +213 -0
  163. package/src/intent.js +130 -0
  164. package/src/launch.js +315 -0
  165. package/src/live.js +81 -0
  166. package/src/local-skills.js +284 -0
  167. package/src/login.js +82 -0
  168. package/src/loop.js +428 -0
  169. package/src/modes.js +128 -0
  170. package/src/overview.js +71 -0
  171. package/src/paths.js +30 -0
  172. package/src/profiles.js +92 -0
  173. package/src/projects.js +104 -0
  174. package/src/recon.js +244 -0
  175. package/src/rules.js +139 -0
  176. package/src/runner.bundle.js +21172 -0
  177. package/src/sentinel.js +248 -0
  178. package/src/skill-switches.js +130 -0
  179. package/src/store.js +58 -0
  180. package/src/strict.js +124 -0
  181. package/src/verify.js +659 -0
  182. package/src/world.js +268 -0
  183. package/studio/dist/index.html +14 -0
  184. package/studio/dist/studio.css +163 -0
  185. package/studio/dist/studio.js +1 -0
@@ -0,0 +1,337 @@
1
+ // The Preview tab (browser stage 1): a right-sidebar page that shows an app
2
+ // running on this computer (a dev server on localhost) in a frame, with an
3
+ // address bar, reload and "open in your browser". Only loopback addresses
4
+ // (localhost, *.localhost, 127.0.0.1, [::1]) over http or https are framed,
5
+ // and never the Web UI's own port, so a framed page can't reach Kriya
6
+ // Harness itself. A site that refuses to be framed opens in the person's
7
+ // own browser instead. Plain React and DSH's theme tokens; no DSH file is
8
+ // edited (HD-02). Stage 2 (a real browser the agent can test with) shares
9
+ // this tab later.
10
+ window.__ModuleLoader__.load({
11
+ id: "@kriya-ai/harness-preview",
12
+ factory: (require) => {
13
+ const React = require("react")
14
+ const { useEffect, useRef, useState } = React
15
+ const h = React.createElement
16
+
17
+ const PLUGIN = "@kriya-ai/harness-preview"
18
+ const KIND = "kriya-preview"
19
+ const STORE = "kriya-preview:last"
20
+
21
+ /**
22
+ * The address to frame, or an error sentence. `self` is the Web UI's own
23
+ * location, so its port is refused.
24
+ */
25
+ function previewUrl(input, self) {
26
+ let text = String(input ?? "").trim()
27
+ if (!text) return { error: "Type a local address, e.g. localhost:3000." }
28
+ if (/^\d{2,5}(\/|$)/.test(text)) text = `localhost:${text}`
29
+ if (!/^[a-z][a-z0-9+.-]*:\/\//i.test(text)) text = `http://${text}`
30
+ let url
31
+ try {
32
+ url = new URL(text)
33
+ } catch {
34
+ return { error: "That isn't an address." }
35
+ }
36
+ if (url.protocol !== "http:" && url.protocol !== "https:") return { error: "Only http and https addresses." }
37
+ if (url.username || url.password) return { error: "Addresses with a user name or password aren't framed." }
38
+ const host = url.hostname.replace(/^\[|\]$/g, "")
39
+ const loopback = host === "localhost" || host.endsWith(".localhost") || host === "::1" || /^127(\.\d{1,3}){3}$/.test(host)
40
+ if (!loopback) return { error: "Preview shows apps on this computer only (localhost). Open other sites in your browser." }
41
+ const port = url.port || (url.protocol === "https:" ? "443" : "80")
42
+ const selfPort = self?.port || (self?.protocol === "https:" ? "443" : "80")
43
+ const selfLoopback = self && ["localhost", "127.0.0.1", "[::1]", "::1"].includes(self.hostname)
44
+ if (selfLoopback && port === selfPort) return { error: "That's Kriya Harness itself; preview your app's port instead." }
45
+ return { url: url.href }
46
+ }
47
+
48
+ const CSS = `
49
+ .kh-pv { display: flex; flex-direction: column; height: 100%; min-height: 0; color: var(--dsw-alias-label-primary); font-size: 13px; }
50
+ .kh-pv-bar { display: flex; align-items: center; gap: 4px; padding: 6px 8px; border-bottom: 1px solid var(--dsw-alias-border-l2); }
51
+ .kh-pv-form { flex: 1; min-width: 0; display: flex; }
52
+ .kh-pv-input { flex: 1; min-width: 0; min-height: 36px; padding: 0 10px; border-radius: 9px; border: 1px solid var(--dsw-alias-border-l2); background: var(--dsw-alias-bg-layer-1, transparent); color: inherit; font: inherit; font-family: var(--dsw-font-code, ui-monospace, monospace); font-size: 12px; }
53
+ .kh-pv-input:focus-visible { outline: 2px solid var(--dsw-alias-link); outline-offset: 0; }
54
+ .kh-pv-btn { min-width: 44px; min-height: 44px; border: 0; border-radius: 10px; background: transparent; color: inherit; cursor: pointer; display: grid; place-items: center; }
55
+ .kh-pv-btn:hover { background: var(--dsw-alias-interactive-bg-hover); }
56
+ .kh-pv-btn:disabled { opacity: 0.4; cursor: default; }
57
+ .kh-pv-btn:focus-visible { outline: 2px solid var(--dsw-alias-link); outline-offset: -2px; }
58
+ .kh-pv-frame { flex: 1; min-height: 0; width: 100%; border: 0; background: #fff; }
59
+ .kh-pv-note { padding: 16px 14px; color: var(--dsw-alias-label-tertiary); line-height: 1.55; }
60
+ .kh-pv-error { padding: 8px 12px; color: var(--dsw-alias-state-error-primary); border-bottom: 1px solid var(--dsw-alias-border-l2); }
61
+ .kh-pv-modes { display: flex; gap: 4px; padding: 6px 8px 0; }
62
+ .kh-pv-mode { min-height: 32px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--dsw-alias-border-l2); background: transparent; color: var(--dsw-alias-label-secondary); font: inherit; font-size: 12px; cursor: pointer; }
63
+ .kh-pv-mode[aria-pressed="true"] { color: var(--dsw-alias-label-primary); border-color: var(--dsw-alias-link); font-weight: 600; }
64
+ .kh-pv-mode:focus-visible { outline: 2px solid var(--dsw-alias-link); outline-offset: 1px; }
65
+ .kh-pv-live { flex: 1; min-height: 0; overflow: auto; background: var(--dsw-alias-bg-layer-1, #111); display: flex; align-items: flex-start; justify-content: center; }
66
+ .kh-pv-shot { width: 100%; height: auto; display: block; cursor: pointer; outline: none; }
67
+ .kh-pv-shot:focus-visible { box-shadow: inset 0 0 0 2px var(--dsw-alias-link); }
68
+ .kh-pv-url { padding: 4px 10px; font-family: var(--dsw-font-code, ui-monospace, monospace); font-size: 11.5px; color: var(--dsw-alias-label-tertiary); border-bottom: 1px solid var(--dsw-alias-border-l2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
69
+ `
70
+
71
+ function installStyles() {
72
+ const tag = document.createElement("style")
73
+ tag.dataset.plugin = PLUGIN
74
+ tag.textContent = CSS
75
+ document.head.appendChild(tag)
76
+ return () => tag.remove()
77
+ }
78
+
79
+ const svg = (paths, size = 16) =>
80
+ h(
81
+ "svg",
82
+ { width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 1.7, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": true },
83
+ ...paths.map((d, i) => h("path", { key: i, d }))
84
+ )
85
+ const TabIcon = ({ size = 20 }) => svg(["M3 5h18v14H3z", "M3 9h18", "M6 7h.01", "M9 7h.01"], size)
86
+ const RELOAD = ["M20 11a8 8 0 1 0-2.3 5.7", "M20 4v7h-7"]
87
+ const OPEN = ["M14 4h6v6", "M20 4l-9 9", "M18 14v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1h5"]
88
+
89
+ const remembered = () => {
90
+ try {
91
+ return localStorage.getItem(STORE) ?? ""
92
+ } catch {
93
+ return ""
94
+ }
95
+ }
96
+
97
+ function FrameView() {
98
+ const [input, setInput] = useState(remembered)
99
+ const [url, setUrl] = useState(null)
100
+ const [error, setError] = useState(null)
101
+ const [stamp, setStamp] = useState(0)
102
+ const frame = useRef(null)
103
+
104
+ const go = (value) => {
105
+ const out = previewUrl(value, window.location)
106
+ if (out.error) {
107
+ setError(out.error)
108
+ return
109
+ }
110
+ setError(null)
111
+ setUrl(out.url)
112
+ setInput(out.url)
113
+ setStamp((n) => n + 1)
114
+ try {
115
+ localStorage.setItem(STORE, out.url)
116
+ } catch {
117
+ // A remembered address is a convenience only
118
+ }
119
+ }
120
+
121
+ useEffect(() => {
122
+ const first = remembered()
123
+ if (first && !previewUrl(first, window.location).error) go(first)
124
+ // Only on first show
125
+ }, [])
126
+
127
+ return h(
128
+ React.Fragment,
129
+ null,
130
+ h(
131
+ "div",
132
+ { className: "kh-pv-bar" },
133
+ h(
134
+ "form",
135
+ {
136
+ className: "kh-pv-form",
137
+ onSubmit: (e) => {
138
+ e.preventDefault()
139
+ go(input)
140
+ },
141
+ },
142
+ h("input", {
143
+ className: "kh-pv-input",
144
+ value: input,
145
+ onChange: (e) => setInput(e.target.value),
146
+ placeholder: "localhost:3000",
147
+ "aria-label": "Local address to preview",
148
+ spellCheck: false,
149
+ autoCapitalize: "off",
150
+ autoCorrect: "off",
151
+ })
152
+ ),
153
+ h("button", { type: "button", className: "kh-pv-btn", onClick: () => url && setStamp((n) => n + 1), disabled: !url, "aria-label": "Reload the preview", title: "Reload" }, svg(RELOAD)),
154
+ h("button", { type: "button", className: "kh-pv-btn", onClick: () => url && window.open(url, "_blank", "noopener,noreferrer"), disabled: !url, "aria-label": "Open in your browser", title: "Open in your browser" }, svg(OPEN))
155
+ ),
156
+ error && h("div", { className: "kh-pv-error", role: "alert" }, error),
157
+ url
158
+ ? h("iframe", {
159
+ key: stamp,
160
+ ref: frame,
161
+ className: "kh-pv-frame",
162
+ src: url,
163
+ title: `Preview of ${url}`,
164
+ referrerPolicy: "no-referrer",
165
+ // The app's own origin (another port), never Kriya Harness's
166
+ sandbox: "allow-scripts allow-forms allow-same-origin allow-popups allow-modals allow-downloads",
167
+ })
168
+ : h(
169
+ "div",
170
+ { className: "kh-pv-note" },
171
+ "Preview an app running on this computer: type its local address (for example localhost:3000) and press Enter. If the page stays blank, the app refuses to be framed; open it in your browser with the arrow."
172
+ )
173
+ )
174
+ }
175
+
176
+ const API = { state: "api/kriya.browser.state", frame: "api/kriya.browser.frame", input: "api/kriya.browser.input" }
177
+ const VIEW = { width: 1280, height: 800 }
178
+ const FRAME_MS = 400
179
+
180
+ async function send(body) {
181
+ const response = await fetch(API.input, { method: "POST", credentials: "same-origin", headers: { "content-type": "application/json" }, body: JSON.stringify(body) })
182
+ const data = await response.json().catch(() => ({}))
183
+ if (!response.ok) throw new Error(data.error || `Kriya answered ${response.status}.`)
184
+ return data
185
+ }
186
+
187
+ // The agent's browser (stage 2): its live page as frames, and the
188
+ // person's address, clicks, scrolls and keys sent to the same page
189
+ function AgentView({ visible }) {
190
+ const [src, setSrc] = useState(null)
191
+ const [where, setWhere] = useState("")
192
+ const [input, setInput] = useState("")
193
+ const [error, setError] = useState(null)
194
+ const img = useRef(null)
195
+
196
+ useEffect(() => {
197
+ if (!visible) return
198
+ let alive = true
199
+ let last
200
+ const tick = async () => {
201
+ try {
202
+ const response = await fetch(API.frame, { credentials: "same-origin" })
203
+ if (response.status === 204) {
204
+ if (alive) setSrc(null)
205
+ } else if (response.ok) {
206
+ const url = URL.createObjectURL(await response.blob())
207
+ if (!alive) return URL.revokeObjectURL(url)
208
+ if (last) URL.revokeObjectURL(last)
209
+ last = url
210
+ setSrc(url)
211
+ setWhere(decodeURI(response.headers.get("x-kriya-url") || ""))
212
+ }
213
+ } catch {
214
+ // The next tick tries again
215
+ }
216
+ }
217
+ tick()
218
+ const timer = setInterval(tick, FRAME_MS)
219
+ return () => {
220
+ alive = false
221
+ clearInterval(timer)
222
+ if (last) URL.revokeObjectURL(last)
223
+ }
224
+ }, [visible])
225
+
226
+ const act = (body) => send(body).then(() => setError(null), (e) => setError(e.message))
227
+ const point = (e) => {
228
+ const r = img.current.getBoundingClientRect()
229
+ return { x: Math.round(((e.clientX - r.left) / r.width) * VIEW.width), y: Math.round(((e.clientY - r.top) / r.height) * VIEW.height) }
230
+ }
231
+ const KEYS = new Set(["Enter", "Tab", "Escape", "Backspace", "Delete", "ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight", "Home", "End", "PageUp", "PageDown"])
232
+ const onKey = (e) => {
233
+ if (e.metaKey || e.ctrlKey || e.altKey) return
234
+ if (KEYS.has(e.key)) {
235
+ e.preventDefault()
236
+ act({ kind: "key", key: e.key })
237
+ } else if (e.key.length === 1) {
238
+ e.preventDefault()
239
+ act({ kind: "text", text: e.key })
240
+ }
241
+ }
242
+
243
+ return h(
244
+ React.Fragment,
245
+ null,
246
+ h(
247
+ "div",
248
+ { className: "kh-pv-bar" },
249
+ h(
250
+ "form",
251
+ {
252
+ className: "kh-pv-form",
253
+ onSubmit: (e) => {
254
+ e.preventDefault()
255
+ const out = previewUrl(input, window.location)
256
+ if (out.error) return setError(out.error)
257
+ act({ kind: "open", url: out.url })
258
+ },
259
+ },
260
+ h("input", { className: "kh-pv-input", value: input, onChange: (e) => setInput(e.target.value), placeholder: "localhost:3000", "aria-label": "Local address for the agent's browser", spellCheck: false, autoCapitalize: "off", autoCorrect: "off" })
261
+ )
262
+ ),
263
+ error && h("div", { className: "kh-pv-error", role: "alert" }, error),
264
+ where && h("div", { className: "kh-pv-url", title: where }, where),
265
+ src
266
+ ? h(
267
+ "div",
268
+ { className: "kh-pv-live" },
269
+ h("img", {
270
+ ref: img,
271
+ className: "kh-pv-shot",
272
+ src,
273
+ alt: `The agent's browser: ${where}`,
274
+ tabIndex: 0,
275
+ onClick: (e) => (img.current.focus(), act({ kind: "click", ...point(e) })),
276
+ onWheel: (e) => act({ kind: "wheel", ...point(e), deltaY: e.deltaY }),
277
+ onKeyDown: onKey,
278
+ })
279
+ )
280
+ : h("div", { className: "kh-pv-note" }, "The agent's browser has no page open yet. Type a local address above, or ask the agent to open your app; you'll see and can click the same page here.")
281
+ )
282
+ }
283
+
284
+ function PreviewBody({ useTabInfo }) {
285
+ const visible = useTabInfo?.().tab?.visible !== false
286
+ const [agent, setAgent] = useState(false)
287
+ const [mode, setMode] = useState("frame")
288
+ useEffect(() => {
289
+ let alive = true
290
+ fetch(API.state, { credentials: "same-origin" })
291
+ .then((r) => (r.ok ? r.json() : null))
292
+ .then((s) => {
293
+ if (!alive || !s?.enabled) return
294
+ setAgent(true)
295
+ if (s.url) setMode("agent")
296
+ })
297
+ .catch(() => {})
298
+ return () => {
299
+ alive = false
300
+ }
301
+ }, [])
302
+ return h(
303
+ "div",
304
+ { className: "kh-pv" },
305
+ agent &&
306
+ h(
307
+ "div",
308
+ { className: "kh-pv-modes", role: "group", "aria-label": "What the preview shows" },
309
+ h("button", { type: "button", className: "kh-pv-mode", "aria-pressed": mode === "frame", onClick: () => setMode("frame") }, "Your app"),
310
+ h("button", { type: "button", className: "kh-pv-mode", "aria-pressed": mode === "agent", onClick: () => setMode("agent") }, "Agent's browser")
311
+ ),
312
+ mode === "agent" ? h(AgentView, { visible }) : h(FrameView)
313
+ )
314
+ }
315
+
316
+ const definition = {
317
+ id: PLUGIN,
318
+ kind: KIND,
319
+ priority: "extension",
320
+ title: () => "Preview",
321
+ guide: [{ id: "preview", order: 7, title: () => "Preview", description: () => "An app running on this computer (localhost)", icon: TabIcon }],
322
+ }
323
+
324
+ const inject = ["slots", "sidebarRightTabs"]
325
+
326
+ function apply(ctx) {
327
+ if (typeof document !== "undefined") ctx.effect(installStyles, "kriya-preview: styles")
328
+ ctx.effect(() => ctx.sidebarRightTabs.register(definition), "kriya-preview: type")
329
+ ctx.effect(
330
+ () => ctx.slots.inject("sidebar.right.pane.tab", () => ctx.slots.register({ name: "sidebar.right.pane.tab", key: PLUGIN }, PreviewBody)),
331
+ "kriya-preview: body"
332
+ )
333
+ }
334
+
335
+ return { apply, inject, PreviewBody, definition, previewUrl }
336
+ },
337
+ })
@@ -0,0 +1,4 @@
1
+ // The Preview tab, node half: an empty Loader seat. The browser half
2
+ // (client.js) is the tab; it frames loopback addresses only and calls no route.
3
+ export const name = "kriya-preview"
4
+ export function apply() {}
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "@kriya-ai/harness-preview",
3
+ "description": "The Preview tab of the Kriya Harness Web UI: an app running on this computer (localhost) in a frame",
4
+ "version": "0.1.0",
5
+ "private": true,
6
+ "type": "module",
7
+ "main": "index.js",
8
+ "exports": {
9
+ ".": "./index.js",
10
+ "./client": "./client.js",
11
+ "./package.json": "./package.json"
12
+ },
13
+ "dsh": {
14
+ "client": {
15
+ "inject": [
16
+ "@deepseek-ai/dsh-client-ui-sidebar-right"
17
+ ],
18
+ "platform": "web"
19
+ }
20
+ },
21
+ "license": "UNLICENSED"
22
+ }
@@ -0,0 +1,290 @@
1
+ // The Progress tab, browser half: a right-sidebar page showing what the
2
+ // Kriya loop did in this session, from its verified records (index.js):
3
+ // goal → plan → build → verify → verdict, each step with its status and
4
+ // attempts, and every check run with its exit code. Plain React and DSH's
5
+ // theme tokens; no DSH file is edited (HD-02).
6
+ window.__ModuleLoader__.load({
7
+ id: "@kriya-ai/harness-progress",
8
+ factory: (require) => {
9
+ const React = require("react")
10
+ const { useCallback, useEffect, useState } = React
11
+ const h = React.createElement
12
+
13
+ const PLUGIN = "@kriya-ai/harness-progress"
14
+ const KIND = "kriya-progress"
15
+ const API = "api/kriya.progress"
16
+ const CHECK_API = "api/kriya.progress.check"
17
+ const REFRESH_MS = 3000
18
+ const MAX_ATTEMPTS = 4
19
+
20
+ const CSS = `
21
+ .kh-pg { height: 100%; overflow: auto; color: var(--dsw-alias-label-primary); font-size: 13px; padding-bottom: 16px; }
22
+ .kh-pg-sec { padding: 10px 14px; border-bottom: 1px solid var(--dsw-alias-border-l2); }
23
+ .kh-pg-sec:last-child { border-bottom: 0; }
24
+ .kh-pg-h { display: flex; align-items: center; justify-content: space-between; margin: 0 0 8px; font-size: 12px; font-weight: 600; color: var(--dsw-alias-label-secondary); }
25
+ .kh-pg-flow { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; margin: 2px 0 10px; }
26
+ .kh-pg-stage { font-size: 11.5px; padding: 3px 8px; border-radius: 999px; border: 1px solid var(--dsw-alias-border-l2); color: var(--dsw-alias-label-tertiary); }
27
+ .kh-pg-stage.done { color: var(--dsw-alias-label-secondary); }
28
+ .kh-pg-stage.now { color: var(--dsw-alias-link); border-color: currentColor; font-weight: 600; }
29
+ .kh-pg-arrow { color: var(--dsw-alias-label-tertiary); font-size: 11px; }
30
+ .kh-pg-verdict { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; }
31
+ .kh-pg-verdict.verified { color: var(--dsw-alias-state-success-primary); }
32
+ .kh-pg-verdict.failed, .kh-pg-verdict.blocked { color: var(--dsw-alias-state-error-primary); }
33
+ .kh-pg-verdict.stale, .kh-pg-verdict.not-checked, .kh-pg-verdict.partial { color: var(--dsw-alias-state-warn-label); }
34
+ .kh-pg-goal { line-height: 1.45; margin: 6px 0 0; }
35
+ .kh-pg-check { margin-top: 6px; color: var(--dsw-alias-label-tertiary); }
36
+ .kh-pg-use { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
37
+ .kh-pg-usebtn { min-height: 44px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--dsw-alias-border-l2); background: transparent; color: var(--dsw-alias-label-primary); cursor: pointer; font: inherit; font-size: 12.5px; display: inline-flex; align-items: center; gap: 6px; max-width: 100%; }
38
+ .kh-pg-usebtn:hover { background: var(--dsw-alias-interactive-bg-hover); }
39
+ .kh-pg-usebtn:focus-visible { outline: 2px solid var(--dsw-alias-link); outline-offset: 1px; }
40
+ .kh-pg-usebtn:disabled { opacity: .6; cursor: default; }
41
+ .kh-pg-mono { font-family: var(--dsw-font-code, ui-monospace, monospace); font-size: 12px; }
42
+ .kh-pg-step { display: grid; grid-template-columns: 20px 1fr auto; gap: 8px; align-items: start; padding: 6px 0; }
43
+ .kh-pg-step + .kh-pg-step { border-top: 1px dashed var(--dsw-alias-border-l2); }
44
+ .kh-pg-ico { width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; font-weight: 700; margin-top: 1px; border: 1.5px solid var(--dsw-alias-label-tertiary); color: var(--dsw-alias-label-tertiary); }
45
+ .kh-pg-ico.pass { border-color: var(--dsw-alias-state-success-primary); background: var(--dsw-alias-state-success-primary); color: var(--dsw-alias-bg-layer-0, #fff); }
46
+ .kh-pg-ico.fail { border-color: var(--dsw-alias-state-warn-label); color: var(--dsw-alias-state-warn-label); }
47
+ .kh-pg-ico.blocked { border-color: var(--dsw-alias-state-error-primary); background: var(--dsw-alias-state-error-primary); color: var(--dsw-alias-bg-layer-0, #fff); }
48
+ .kh-pg-ico.skipped { border-style: dashed; }
49
+ .kh-pg-ico.next { border-color: var(--dsw-alias-link); color: var(--dsw-alias-link); }
50
+ .kh-pg-ico.building { border-color: var(--dsw-alias-link); color: var(--dsw-alias-link); border-style: dotted; }
51
+ .kh-pg-title { font-weight: 500; }
52
+ .kh-pg-sub { color: var(--dsw-alias-label-tertiary); font-size: 12px; margin-top: 2px; line-height: 1.4; }
53
+ .kh-pg-tag { font-size: 11px; color: var(--dsw-alias-label-secondary); white-space: nowrap; }
54
+ .kh-pg-run { display: grid; grid-template-columns: 14px 1fr auto; gap: 8px; align-items: center; min-height: 28px; }
55
+ .kh-pg-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--dsw-alias-state-error-primary); justify-self: center; }
56
+ .kh-pg-dot.pass { background: var(--dsw-alias-state-success-primary); }
57
+ .kh-pg-dim { color: var(--dsw-alias-label-tertiary); }
58
+ .kh-pg-val { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
59
+ .kh-pg-btn { min-width: 44px; min-height: 44px; margin: -12px -10px -12px 0; border: 0; border-radius: 10px; background: transparent; color: inherit; cursor: pointer; display: grid; place-items: center; }
60
+ .kh-pg-btn:hover { background: var(--dsw-alias-interactive-bg-hover); }
61
+ .kh-pg-btn:focus-visible { outline: 2px solid var(--dsw-alias-link); outline-offset: -2px; }
62
+ .kh-pg-note { padding: 14px; color: var(--dsw-alias-label-tertiary); line-height: 1.5; }
63
+ .kh-pg-error { padding: 10px 14px; color: var(--dsw-alias-state-error-primary); }
64
+ `
65
+
66
+ function installStyles() {
67
+ const tag = document.createElement("style")
68
+ tag.dataset.plugin = PLUGIN
69
+ tag.textContent = CSS
70
+ document.head.appendChild(tag)
71
+ return () => tag.remove()
72
+ }
73
+
74
+ const svg = (paths, size = 16) =>
75
+ h(
76
+ "svg",
77
+ { width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 1.7, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": true },
78
+ ...paths.map((d, i) => h("path", { key: i, d }))
79
+ )
80
+ const TabIcon = ({ size = 20 }) => svg(["M9 6h11", "M9 12h11", "M9 18h11", "M4 6l1 1 2-2", "M4 12l1 1 2-2", "M4 18h2"], size)
81
+ const REFRESH = ["M20 11a8 8 0 1 0-2.3 5.7", "M20 4v7h-7"]
82
+
83
+ const VERDICT = { verified: "Verified", partial: "Partly done", failed: "Failing", blocked: "Blocked", "not checked": "Not checked" }
84
+ const STEP_ICON = { pass: "✓", fail: "!", blocked: "×", skipped: "–", built: "○", "not started": "", next: "›", building: "…" }
85
+ // A builder at work: its run, steps so far, minutes and latest tool (live, from the loop)
86
+ const buildingTag = (b) => `building · run ${b.attempt}`
87
+ const buildingLine = (b) =>
88
+ [`Builder at work: ${b.steps} step${b.steps === 1 ? "" : "s"}`, `${Math.max(0, Math.floor((Date.now() - b.startedAt) / 60_000))} min`, b.last && `last: ${b.last}`].filter(Boolean).join(" · ")
89
+
90
+ /** Where the work stands: the stages a session moves through, and which one it is in */
91
+ function stages(data) {
92
+ const v = data.verdict
93
+ const plan = data.plan
94
+ const ran = data.runs.length > 0
95
+ const allDone = plan ? plan.steps.every((s) => ["pass", "blocked", "skipped", "built"].includes(s.status)) : v.status === "verified"
96
+ const building = plan?.steps.some((s) => s.building)
97
+ const now = building ? 2 : v.status === "verified" && !v.stale ? 4 : allDone && ran ? 3 : ran ? (plan ? 2 : 3) : plan ? 1 : 0
98
+ return { now, list: ["Goal", "Plan", "Build", "Verify", "Done"] }
99
+ }
100
+
101
+ function Flow({ data }) {
102
+ const { now, list } = stages(data)
103
+ return h(
104
+ "div",
105
+ { className: "kh-pg-flow", role: "list", "aria-label": "Where the work stands" },
106
+ ...list.flatMap((label, i) => [
107
+ i > 0 && h("span", { key: `a${i}`, className: "kh-pg-arrow", "aria-hidden": true }, "→"),
108
+ h("span", { key: label, role: "listitem", className: `kh-pg-stage${i < now ? " done" : i === now ? " now" : ""}`, "aria-current": i === now ? "step" : undefined }, label),
109
+ ])
110
+ )
111
+ }
112
+
113
+ function Verdict({ v }) {
114
+ const cls = v.stale ? "stale" : v.status.replace(" ", "-")
115
+ return h("span", { className: `kh-pg-verdict ${cls}` }, v.stale ? "Changed since the last pass" : VERDICT[v.status] ?? v.status)
116
+ }
117
+
118
+ function Steps({ plan }) {
119
+ const next = plan.steps.find((s) => s.status === "not started" && (s.after ?? []).every((d) => ["pass", "built"].includes(plan.steps[d - 1]?.status)))
120
+ return plan.steps.map((s) => {
121
+ const state = s.building ? "building" : s === next ? "next" : s.status
122
+ const tag = s.building
123
+ ? buildingTag(s.building)
124
+ : s.status === "fail"
125
+ ? `attempt ${s.attempts} of ${MAX_ATTEMPTS} failed`
126
+ : s.status === "pass"
127
+ ? `passed${s.attempts > 1 ? ` on run ${s.attempts}` : ""}`
128
+ : s.status === "blocked"
129
+ ? `blocked after ${s.attempts}`
130
+ : s.status === "skipped"
131
+ ? "skipped"
132
+ : s.status === "built"
133
+ ? "built, not checked"
134
+ : s === next
135
+ ? "next"
136
+ : ""
137
+ return h(
138
+ "div",
139
+ { key: s.n, className: "kh-pg-step" },
140
+ h("span", { className: `kh-pg-ico ${state}`, "aria-hidden": true }, STEP_ICON[state] ?? ""),
141
+ h(
142
+ "div",
143
+ null,
144
+ h("div", { className: "kh-pg-title" }, `${s.n}. ${s.title}`),
145
+ h("div", { className: "kh-pg-sub" }, `Done when ${s.doneWhen}`),
146
+ s.after?.length ? h("div", { className: "kh-pg-sub" }, `After step ${s.after.join(", ")}`) : null,
147
+ s.building ? h("div", { className: "kh-pg-sub", role: "status" }, buildingLine(s.building)) : null
148
+ ),
149
+ h("span", { className: "kh-pg-tag", "aria-label": `Step ${s.n}: ${s.status}` }, tag)
150
+ )
151
+ })
152
+ }
153
+
154
+ const time = (iso) => {
155
+ const d = new Date(iso)
156
+ return Number.isNaN(d.getTime()) ? "" : d.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit", second: "2-digit" })
157
+ }
158
+ const secs = (ms) => (typeof ms === "number" ? (ms < 1000 ? `${ms} ms` : `${(ms / 1000).toFixed(1)} s`) : "")
159
+
160
+ function Runs({ runs }) {
161
+ return runs.map((r, i) =>
162
+ h(
163
+ "div",
164
+ { key: `${r.at}-${i}`, className: "kh-pg-run", title: `${r.step}: ${r.status}, exit ${r.exitCode ?? "none"}` },
165
+ h("span", { className: `kh-pg-dot ${r.status}`, "aria-hidden": true }),
166
+ h("span", { className: "kh-pg-val" }, h("span", null, r.step), r.kind && h("span", { className: "kh-pg-dim" }, ` · ${r.kind}`), r.timedOut && h("span", { className: "kh-pg-dim" }, " · timed out")),
167
+ h("span", { className: "kh-pg-dim kh-pg-mono" }, `${r.status === "pass" ? "exit 0" : `exit ${r.exitCode ?? "–"}`} · ${secs(r.durationMs)} · ${time(r.at)}`)
168
+ )
169
+ )
170
+ }
171
+
172
+ function ProgressBody({ useTabInfo, sessionId }) {
173
+ const { tab } = useTabInfo()
174
+ const visible = tab?.visible !== false
175
+ const [data, setData] = useState(null)
176
+ const [error, setError] = useState(null)
177
+ const [busy, setBusy] = useState(false)
178
+
179
+ const load = useCallback(async () => {
180
+ if (!sessionId) return
181
+ try {
182
+ const response = await fetch(`${API}?${new URLSearchParams({ session: sessionId })}`, { credentials: "same-origin" })
183
+ const body = await response.json().catch(() => ({}))
184
+ if (!response.ok) throw new Error(body.error || `Kriya answered ${response.status}.`)
185
+ setData(body)
186
+ setError(null)
187
+ } catch (e) {
188
+ setError(e.message === "Failed to fetch" ? "Kriya Harness isn't answering; is it still running?" : e.message)
189
+ }
190
+ }, [sessionId])
191
+
192
+ // The person picks one of the checks the harness found: from now on every step is judged by it
193
+ const useCheck = useCallback(
194
+ async (command) => {
195
+ setBusy(true)
196
+ try {
197
+ const response = await fetch(CHECK_API, { method: "POST", credentials: "same-origin", headers: { "content-type": "application/json" }, body: JSON.stringify({ session: sessionId, command }) })
198
+ const body = await response.json().catch(() => ({}))
199
+ if (!response.ok) throw new Error(body.error || `Kriya answered ${response.status}.`)
200
+ await load()
201
+ } catch (e) {
202
+ setError(e.message)
203
+ } finally {
204
+ setBusy(false)
205
+ }
206
+ },
207
+ [sessionId, load]
208
+ )
209
+
210
+ useEffect(() => {
211
+ if (!visible) return
212
+ load()
213
+ const timer = setInterval(load, REFRESH_MS)
214
+ return () => clearInterval(timer)
215
+ }, [visible, load])
216
+
217
+ if (!sessionId) return h("div", { className: "kh-pg-note" }, "Start or open a session to see its progress.")
218
+ if (error && !data) return h("div", { className: "kh-pg-error", role: "alert" }, error)
219
+ if (!data) return h("div", { className: "kh-pg-note" }, "Loading…")
220
+ const refresh = h("button", { type: "button", className: "kh-pg-btn", onClick: load, "aria-label": "Refresh the progress", title: "Refresh" }, svg(REFRESH))
221
+ return h(
222
+ "div",
223
+ { className: "kh-pg" },
224
+ error && h("div", { className: "kh-pg-error", role: "alert" }, error),
225
+ h(
226
+ "section",
227
+ { className: "kh-pg-sec", "aria-label": "Verdict" },
228
+ h("h3", { className: "kh-pg-h" }, "Progress", refresh),
229
+ h(Flow, { data }),
230
+ h(Verdict, { v: data.verdict }),
231
+ data.plan && h("p", { className: "kh-pg-goal" }, data.plan.goal),
232
+ h(
233
+ "div",
234
+ { className: "kh-pg-check" },
235
+ data.check
236
+ ? h(React.Fragment, null, "Checked by ", h("span", { className: "kh-pg-mono" }, data.check.command))
237
+ : data.suggestions?.length
238
+ ? "No check confirmed, so no step can pass. Pick the command that proves the work, and every step is judged by it:"
239
+ : "No check confirmed for this project: run kriya verify use \"<command>\" in a terminal."
240
+ ),
241
+ !data.check &&
242
+ data.suggestions?.length > 0 &&
243
+ h(
244
+ "div",
245
+ { className: "kh-pg-use", role: "group", "aria-label": "Checks found for this project" },
246
+ ...data.suggestions.map((s) =>
247
+ h(
248
+ "button",
249
+ { key: s.command, type: "button", className: "kh-pg-usebtn", disabled: busy, onClick: () => useCheck(s.command), title: `Found in ${s.source}` },
250
+ "Use ",
251
+ h("span", { className: "kh-pg-mono" }, s.command)
252
+ )
253
+ )
254
+ ),
255
+ data.verdict.touched && h("div", { className: "kh-pg-check" }, `The passing work changed test or check files: ${data.verdict.touched.join(", ")}.`)
256
+ ),
257
+ data.plan
258
+ ? h("section", { className: "kh-pg-sec", "aria-label": "Plan" }, h("h3", { className: "kh-pg-h" }, `Plan · ${data.plan.steps.length} step${data.plan.steps.length === 1 ? "" : "s"}${data.earlierPlans ? ` · plan ${data.earlierPlans + 1}` : ""}`), h(Steps, { plan: data.plan }))
259
+ : h("section", { className: "kh-pg-sec" }, h("h3", { className: "kh-pg-h" }, "Plan"), h("div", { className: "kh-pg-dim" }, "No plan: the agent plans with kriya_plan when a task has several parts.")),
260
+ h(
261
+ "section",
262
+ { className: "kh-pg-sec", "aria-label": "Check runs" },
263
+ h("h3", { className: "kh-pg-h" }, `Check runs${data.runs.length ? ` · ${data.runs.length}` : ""}`),
264
+ data.runs.length ? h(Runs, { runs: data.runs }) : h("div", { className: "kh-pg-dim" }, "None yet. Only these runs decide whether the work passes.")
265
+ )
266
+ )
267
+ }
268
+
269
+ const definition = {
270
+ id: PLUGIN,
271
+ kind: KIND,
272
+ priority: "extension",
273
+ title: () => "Progress",
274
+ guide: [{ id: "progress", order: 6, title: () => "Progress", description: () => "Goal, plan, each step's check and the verdict", icon: TabIcon }],
275
+ }
276
+
277
+ const inject = ["slots", "sidebarRightTabs"]
278
+
279
+ function apply(ctx) {
280
+ if (typeof document !== "undefined") ctx.effect(installStyles, "kriya-progress: styles")
281
+ ctx.effect(() => ctx.sidebarRightTabs.register(definition), "kriya-progress: type")
282
+ ctx.effect(
283
+ () => ctx.slots.inject("sidebar.right.pane.tab", () => ctx.slots.register({ name: "sidebar.right.pane.tab", key: PLUGIN }, ProgressBody)),
284
+ "kriya-progress: body"
285
+ )
286
+ }
287
+
288
+ return { apply, inject, ProgressBody, definition, API, stages }
289
+ },
290
+ })