@kriya-ai/harness 0.0.0-stage → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +379 -2
- package/SAFETY.md +162 -0
- package/THIRD_PARTY_NOTICES.md +7911 -0
- package/bin/kriya.js +577 -0
- package/bundle/cordis.patch.yml +397 -0
- package/contract/SOURCE.md +15 -0
- package/contract/contract.json +1355 -0
- package/package.json +57 -4
- package/plugins/anchor/index.js +56 -0
- package/plugins/anchor/package.json +13 -0
- package/plugins/approvals/index.js +183 -0
- package/plugins/approvals/package.json +13 -0
- package/plugins/brand/DESIGN.md +112 -0
- package/plugins/brand/client.js +826 -0
- package/plugins/brand/index.js +15 -0
- package/plugins/brand/package.json +25 -0
- package/plugins/brand/src/client.js +823 -0
- package/plugins/browser/index.js +218 -0
- package/plugins/browser/package.json +13 -0
- package/plugins/budget/index.js +108 -0
- package/plugins/budget/package.json +13 -0
- package/plugins/changes/client.js +245 -0
- package/plugins/changes/index.js +75 -0
- package/plugins/changes/package.json +22 -0
- package/plugins/edit/client.js +113 -0
- package/plugins/edit/index.js +58 -0
- package/plugins/edit/package.json +23 -0
- package/plugins/fs-freshness/index.js +28 -0
- package/plugins/fs-freshness/package.json +13 -0
- package/plugins/graph/client.js +178 -0
- package/plugins/graph/index.js +4 -0
- package/plugins/graph/package.json +22 -0
- package/plugins/kriya-handoff/index.js +194 -0
- package/plugins/kriya-handoff/package.json +13 -0
- package/plugins/kriya-tools/index.js +189 -0
- package/plugins/kriya-tools/package.json +13 -0
- package/plugins/loop/index.js +743 -0
- package/plugins/loop/package.json +13 -0
- package/plugins/mirror/index.js +235 -0
- package/plugins/mirror/package.json +13 -0
- package/plugins/overview/client.js +276 -0
- package/plugins/overview/index.js +95 -0
- package/plugins/overview/package.json +22 -0
- package/plugins/preview/client.js +337 -0
- package/plugins/preview/index.js +4 -0
- package/plugins/preview/package.json +22 -0
- package/plugins/progress/client.js +290 -0
- package/plugins/progress/index.js +100 -0
- package/plugins/progress/package.json +22 -0
- package/plugins/projects/client.js +249 -0
- package/plugins/projects/index.js +30 -0
- package/plugins/projects/package.json +24 -0
- package/plugins/rea/index.js +256 -0
- package/plugins/rea/package.json +10 -0
- package/plugins/rea/skill/LICENSE +21 -0
- package/plugins/rea/skill/SKILL.md +360 -0
- package/plugins/rea/skill/references/android-applications.md +36 -0
- package/plugins/rea/skill/references/connection-and-recovery.md +127 -0
- package/plugins/rea/skill/references/evidence-workflows.md +71 -0
- package/plugins/rea/skill/references/javascript-applications.md +218 -0
- package/plugins/rea/skill/references/native-and-artifacts.md +297 -0
- package/plugins/rea/skill/references/runtime-observation.md +78 -0
- package/plugins/remote/index.js +297 -0
- package/plugins/remote/package.json +10 -0
- package/plugins/router/index.js +84 -0
- package/plugins/router/package.json +13 -0
- package/plugins/sessions/client.js +68 -0
- package/plugins/sessions/index.js +79 -0
- package/plugins/sessions/package.json +20 -0
- package/plugins/skills/client.js +504 -0
- package/plugins/skills/index.js +166 -0
- package/plugins/skills/package.json +23 -0
- package/src/api.js +97 -0
- package/src/browser.js +286 -0
- package/src/changes.js +191 -0
- package/src/checkpoints.js +313 -0
- package/src/daemon.js +503 -0
- package/src/doctor.js +137 -0
- package/src/edit/core/anchors.js +102 -0
- package/src/edit/core/audio.js +158 -0
- package/src/edit/core/faces.js +99 -0
- package/src/edit/core/ffmpeg.js +258 -0
- package/src/edit/core/handoff.js +220 -0
- package/src/edit/core/history.js +90 -0
- package/src/edit/core/layout.js +92 -0
- package/src/edit/core/mix.js +115 -0
- package/src/edit/core/ops.js +602 -0
- package/src/edit/core/plan.js +266 -0
- package/src/edit/core/project.d.ts +134 -0
- package/src/edit/core/project.js +307 -0
- package/src/edit/core/reframe.js +125 -0
- package/src/edit/core/solver.js +416 -0
- package/src/edit/core/time.js +110 -0
- package/src/edit/core/tonemap.js +57 -0
- package/src/edit/director/ask.js +120 -0
- package/src/edit/director/gateway.js +16 -0
- package/src/edit/director/revise.js +186 -0
- package/src/edit/engine/capabilities.js +33 -0
- package/src/edit/engine/captions.js +154 -0
- package/src/edit/engine/color.js +269 -0
- package/src/edit/engine/confine.js +67 -0
- package/src/edit/engine/dna.js +148 -0
- package/src/edit/engine/index.js +473 -0
- package/src/edit/engine/loudness.js +43 -0
- package/src/edit/engine/media.js +57 -0
- package/src/edit/engine/motion.js +281 -0
- package/src/edit/engine/packs.js +87 -0
- package/src/edit/engine/probe.js +101 -0
- package/src/edit/engine/receipt.js +123 -0
- package/src/edit/engine/tool.js +101 -0
- package/src/edit/gates/copy.js +113 -0
- package/src/edit/gates/index.js +430 -0
- package/src/edit/gates/picture.js +130 -0
- package/src/edit/gates/sound.js +58 -0
- package/src/edit/gates/speech.js +127 -0
- package/src/edit/gates/text.js +196 -0
- package/src/edit/gates/text.swift +22 -0
- package/src/edit/graph/index.js +139 -0
- package/src/edit/graph/journal.js +69 -0
- package/src/edit/graph/scheduler.js +79 -0
- package/src/edit/host/client.js +58 -0
- package/src/edit/host/deliver.js +119 -0
- package/src/edit/host/jobs.js +84 -0
- package/src/edit/host/main.js +135 -0
- package/src/edit/host/paths.js +11 -0
- package/src/edit/host/projects.js +415 -0
- package/src/edit/host/server.js +391 -0
- package/src/edit/host/taste.js +135 -0
- package/src/edit/host/tavi.js +417 -0
- package/src/edit/host/watch.js +141 -0
- package/src/edit/index/db.js +109 -0
- package/src/edit/index/index.js +236 -0
- package/src/edit/index/layers/faces.js +78 -0
- package/src/edit/index/layers/faces.swift +18 -0
- package/src/edit/index/layers/meta.js +35 -0
- package/src/edit/index/layers/music.js +146 -0
- package/src/edit/index/layers/quality.js +120 -0
- package/src/edit/index/layers/retakes.js +132 -0
- package/src/edit/index/layers/screen.js +99 -0
- package/src/edit/index/layers/shots.js +29 -0
- package/src/edit/index/layers/sound.js +42 -0
- package/src/edit/index/layers/words.js +64 -0
- package/src/edit/index/story.js +248 -0
- package/src/edit/index/views.js +71 -0
- package/src/edit/loop/governor.js +112 -0
- package/src/edit/loop/loop.js +69 -0
- package/src/edit/loop/make.js +115 -0
- package/src/edit/loop/repair.js +97 -0
- package/src/edit/loop/replay.js +32 -0
- package/src/edit/recipes/multicam.js +461 -0
- package/src/edit/recipes/reel.js +202 -0
- package/src/edit/recipes/short-from-long.js +237 -0
- package/src/edit/recipes/tutorial.js +137 -0
- package/src/edit/recipes/youtube.js +155 -0
- package/src/edit/runtime/cli.js +126 -0
- package/src/edit/runtime/doctor.js +122 -0
- package/src/edit/runtime/fetch.js +15 -0
- package/src/edit/runtime/licences.js +88 -0
- package/src/edit/runtime/manifest.js +73 -0
- package/src/edit/runtime/setup.js +252 -0
- package/src/failure.js +69 -0
- package/src/gateway-proxy.js +213 -0
- package/src/intent.js +130 -0
- package/src/launch.js +315 -0
- package/src/live.js +81 -0
- package/src/local-skills.js +284 -0
- package/src/login.js +82 -0
- package/src/loop.js +428 -0
- package/src/modes.js +128 -0
- package/src/overview.js +71 -0
- package/src/paths.js +30 -0
- package/src/profiles.js +92 -0
- package/src/projects.js +104 -0
- package/src/recon.js +244 -0
- package/src/rules.js +139 -0
- package/src/runner.bundle.js +21172 -0
- package/src/sentinel.js +248 -0
- package/src/skill-switches.js +130 -0
- package/src/store.js +58 -0
- package/src/strict.js +124 -0
- package/src/verify.js +659 -0
- package/src/world.js +268 -0
- package/studio/dist/index.html +14 -0
- package/studio/dist/studio.css +163 -0
- package/studio/dist/studio.js +1 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kriya-ai/harness-loop",
|
|
3
|
+
"description": "The Kriya loop's verify step for Kriya Harness: kriya_verify runs the project's confirmed check and reports pass, fail or blocked from its exit code",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"private": true,
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "index.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./index.js",
|
|
10
|
+
"./package.json": "./package.json"
|
|
11
|
+
},
|
|
12
|
+
"license": "UNLICENSED"
|
|
13
|
+
}
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import { chmodSync, readFileSync, renameSync, writeFileSync } from "node:fs"
|
|
2
|
+
import { basename, join } from "node:path"
|
|
3
|
+
|
|
4
|
+
import { call, deviceFromEnv } from "../../src/api.js"
|
|
5
|
+
import { kriyaHome } from "../../src/paths.js"
|
|
6
|
+
import { hideSecrets } from "../approvals/index.js"
|
|
7
|
+
|
|
8
|
+
// Kriya mirror plugin (H6, HD-09, P-SYNC): a summary of each DeepSeek
|
|
9
|
+
// Harness turn goes to a thread in Kriya, so the phone shows progress.
|
|
10
|
+
// It only watches DSH's committed `session/event` feed: local history stays
|
|
11
|
+
// DSH's own and complete. A turn's summary is its answer text and each
|
|
12
|
+
// tool's name, status and time; tool arguments and output go only when the
|
|
13
|
+
// person chose "Full" for this device (arguments with secret-looking names
|
|
14
|
+
// are hidden first, as for phone approvals; output text is sent as it is) (Kriya says which when the session
|
|
15
|
+
// opens, and refuses `full` otherwise). Turns wait in a queue on disk (0600
|
|
16
|
+
// in the Kriya home) while Kriya is unreachable and are sent in order; a
|
|
17
|
+
// session Kriya doesn't mirror (404, mirror off) is dropped and not retried.
|
|
18
|
+
|
|
19
|
+
export const name = "kriya-mirror"
|
|
20
|
+
|
|
21
|
+
// The contract's limits (TurnRequest)
|
|
22
|
+
const MAX_TEXT = 64 * 1024
|
|
23
|
+
const MAX_FULL = 64 * 1024
|
|
24
|
+
const MAX_TOOLS = 100
|
|
25
|
+
// Each tool's output in a full turn
|
|
26
|
+
const MAX_OUTPUT = 4 * 1024
|
|
27
|
+
// Turns kept while Kriya is unreachable; the oldest go first
|
|
28
|
+
const MAX_QUEUE = 500
|
|
29
|
+
const MAX_BACKOFF = 60_000
|
|
30
|
+
|
|
31
|
+
const REJECTED = /the user rejected (tool|escalating)/
|
|
32
|
+
|
|
33
|
+
const textOf = (content) =>
|
|
34
|
+
(Array.isArray(content) ? content : [])
|
|
35
|
+
.filter((block) => block?.type === "text")
|
|
36
|
+
.map((block) => block.text)
|
|
37
|
+
.join("")
|
|
38
|
+
const cut = (text, max) => (text.length <= max ? text : `${text.slice(0, max - 1)}…`)
|
|
39
|
+
const parsed = (json) => {
|
|
40
|
+
try {
|
|
41
|
+
return JSON.parse(json)
|
|
42
|
+
} catch {
|
|
43
|
+
return json
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function fullOf(tools) {
|
|
48
|
+
const full = {
|
|
49
|
+
tools: tools.slice(0, MAX_TOOLS).map((tool) => ({
|
|
50
|
+
name: tool.name,
|
|
51
|
+
input: hideSecrets(parsed(tool.args ?? "{}")),
|
|
52
|
+
output: cut(tool.output, MAX_OUTPUT),
|
|
53
|
+
})),
|
|
54
|
+
}
|
|
55
|
+
while (full.tools.length && JSON.stringify(full).length > MAX_FULL) full.tools.pop()
|
|
56
|
+
return full
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function apply(ctx, config = {}) {
|
|
60
|
+
const retryMs = config.retryMs ?? 5_000
|
|
61
|
+
const file = join(kriyaHome(), "mirror-queue.json")
|
|
62
|
+
const warn = (text) => ctx.logger?.warn?.(`kriya mirror: ${text}`)
|
|
63
|
+
|
|
64
|
+
let queue = []
|
|
65
|
+
try {
|
|
66
|
+
const kept = JSON.parse(readFileSync(file, "utf8"))
|
|
67
|
+
if (Array.isArray(kept)) queue = kept
|
|
68
|
+
} catch {
|
|
69
|
+
// No queue yet
|
|
70
|
+
}
|
|
71
|
+
const save = () => {
|
|
72
|
+
const temporary = `${file}.tmp`
|
|
73
|
+
writeFileSync(temporary, JSON.stringify(queue), { mode: 0o600 })
|
|
74
|
+
if (process.platform !== "win32") chmodSync(temporary, 0o600)
|
|
75
|
+
renameSync(temporary, file)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// DSH session id → what's being collected; Kriya's session per DSH session
|
|
79
|
+
const live = new Map()
|
|
80
|
+
const opened = new Map()
|
|
81
|
+
let timer
|
|
82
|
+
let flushing = null
|
|
83
|
+
let failures = 0
|
|
84
|
+
let disposed = false
|
|
85
|
+
|
|
86
|
+
const schedule = (ms) => {
|
|
87
|
+
clearTimeout(timer)
|
|
88
|
+
timer = setTimeout(flush, ms)
|
|
89
|
+
timer.unref?.()
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// One queued turn: "done", "drop" (this session isn't mirrored), or "retry"
|
|
93
|
+
async function deliver(device, entry) {
|
|
94
|
+
try {
|
|
95
|
+
let session = opened.get(entry.deviceSessionId)
|
|
96
|
+
if (!session) {
|
|
97
|
+
const made = await call(device.url, "POST", "/sessions", {
|
|
98
|
+
token: device.token,
|
|
99
|
+
body: { deviceSessionId: entry.deviceSessionId, project: entry.project, title: entry.title },
|
|
100
|
+
})
|
|
101
|
+
session = { sessionId: made.sessionId, mirror: made.mirror }
|
|
102
|
+
opened.set(entry.deviceSessionId, session)
|
|
103
|
+
}
|
|
104
|
+
const body = { seq: entry.seq, text: entry.text, tools: entry.tools }
|
|
105
|
+
if (session.mirror === "full" && entry.full) body.full = entry.full
|
|
106
|
+
const send = () => call(device.url, "POST", `/sessions/${session.sessionId}/turns`, { token: device.token, body })
|
|
107
|
+
try {
|
|
108
|
+
await send()
|
|
109
|
+
} catch (error) {
|
|
110
|
+
// The person switched to summaries mid-session
|
|
111
|
+
if (error.code !== "mirror_summary_only" || !body.full) throw error
|
|
112
|
+
session.mirror = "summary"
|
|
113
|
+
delete body.full
|
|
114
|
+
await send()
|
|
115
|
+
}
|
|
116
|
+
return "done"
|
|
117
|
+
} catch (error) {
|
|
118
|
+
if (error.status === 400) {
|
|
119
|
+
warn(`Kriya refused a turn (${error.code}); skipped`)
|
|
120
|
+
return "done"
|
|
121
|
+
}
|
|
122
|
+
if (error.status === 0 || error.status === 429 || error.status >= 500) return "retry"
|
|
123
|
+
// Mirror off, signed out, no agent, an old client: not this session
|
|
124
|
+
if (error.code === "no_agent") warn(error.message)
|
|
125
|
+
return "drop"
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
async function flush() {
|
|
130
|
+
if (flushing) return flushing
|
|
131
|
+
flushing = (async () => {
|
|
132
|
+
const device = deviceFromEnv()
|
|
133
|
+
while (device && queue.length && !disposed) {
|
|
134
|
+
const entry = queue[0]
|
|
135
|
+
const outcome = await deliver(device, entry)
|
|
136
|
+
if (outcome === "retry") {
|
|
137
|
+
failures++
|
|
138
|
+
schedule(Math.min(retryMs * 2 ** (failures - 1), MAX_BACKOFF))
|
|
139
|
+
return
|
|
140
|
+
}
|
|
141
|
+
failures = 0
|
|
142
|
+
if (outcome === "drop") {
|
|
143
|
+
opened.set(entry.deviceSessionId, "off")
|
|
144
|
+
queue = queue.filter((e) => e.deviceSessionId !== entry.deviceSessionId)
|
|
145
|
+
} else queue.shift()
|
|
146
|
+
save()
|
|
147
|
+
}
|
|
148
|
+
})().finally(() => (flushing = null))
|
|
149
|
+
return flushing
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function enqueue(entry) {
|
|
153
|
+
queue.push(entry)
|
|
154
|
+
if (queue.length > MAX_QUEUE) queue.splice(0, queue.length - MAX_QUEUE)
|
|
155
|
+
save()
|
|
156
|
+
if (!failures) schedule(0)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const projectOf = (session) => {
|
|
160
|
+
let dir
|
|
161
|
+
try {
|
|
162
|
+
dir = ctx.get("workingDirectory")?.get(session)
|
|
163
|
+
} catch {
|
|
164
|
+
// Not composed: the launch folder
|
|
165
|
+
}
|
|
166
|
+
return cut(basename(dir || process.cwd()), 80)
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
ctx.on("session/event", (session, event) => {
|
|
170
|
+
const id = typeof session?.id === "string" ? session.id.slice(0, 100) : ""
|
|
171
|
+
if (disposed || !id || opened.get(id) === "off" || !deviceFromEnv()) return
|
|
172
|
+
let state = live.get(id)
|
|
173
|
+
if (!state) live.set(id, (state = { title: "", project: projectOf(session), turn: null }))
|
|
174
|
+
const data = event.data
|
|
175
|
+
const turn = state.turn
|
|
176
|
+
switch (event.type) {
|
|
177
|
+
case "user/message":
|
|
178
|
+
// The person's first message names the session (DSH's own context is a user message too)
|
|
179
|
+
if (!state.title && data?.source?.kind === "user")
|
|
180
|
+
state.title = cut(textOf(data.content).trim().split("\n")[0], 80)
|
|
181
|
+
break
|
|
182
|
+
case "turn/start":
|
|
183
|
+
state.turn = { seq: data.turn, texts: [], calls: new Map(), tools: [] }
|
|
184
|
+
break
|
|
185
|
+
case "tool/call":
|
|
186
|
+
turn?.calls.set(data.callId, { name: data.name, args: data.arguments, time: event.time })
|
|
187
|
+
break
|
|
188
|
+
case "tool/result": {
|
|
189
|
+
const started = turn?.calls.get(data.message?.toolCallId)
|
|
190
|
+
if (!started) break
|
|
191
|
+
const output = textOf(data.message.content)
|
|
192
|
+
const failed = data.message.isError || data.error
|
|
193
|
+
turn.tools.push({
|
|
194
|
+
name: cut(String(started.name), 60),
|
|
195
|
+
status: failed ? (REJECTED.test(output) ? "declined" : "error") : "ok",
|
|
196
|
+
ms: Math.max(0, event.time - started.time),
|
|
197
|
+
args: started.args,
|
|
198
|
+
output,
|
|
199
|
+
})
|
|
200
|
+
break
|
|
201
|
+
}
|
|
202
|
+
case "assistant/message": {
|
|
203
|
+
const text = textOf(data?.message?.content).trim()
|
|
204
|
+
if (text) turn?.texts.push(text)
|
|
205
|
+
break
|
|
206
|
+
}
|
|
207
|
+
case "turn/end": {
|
|
208
|
+
if (!turn) break
|
|
209
|
+
state.turn = null
|
|
210
|
+
// Tool details stay off the disk once Kriya has said this session is summaries only
|
|
211
|
+
const summaryOnly = opened.get(id)?.mirror === "summary"
|
|
212
|
+
enqueue({
|
|
213
|
+
deviceSessionId: id,
|
|
214
|
+
project: state.project,
|
|
215
|
+
title: state.title,
|
|
216
|
+
seq: turn.seq,
|
|
217
|
+
text: cut(turn.texts.join("\n\n"), MAX_TEXT),
|
|
218
|
+
tools: turn.tools.slice(0, MAX_TOOLS).map(({ name, status, ms }) => ({ name, status, ms })),
|
|
219
|
+
...(!summaryOnly && turn.tools.length && { full: fullOf(turn.tools) }),
|
|
220
|
+
})
|
|
221
|
+
break
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
})
|
|
225
|
+
|
|
226
|
+
// Turns left from an earlier run
|
|
227
|
+
if (queue.length) schedule(0)
|
|
228
|
+
ctx.effect(
|
|
229
|
+
() => () => {
|
|
230
|
+
disposed = true
|
|
231
|
+
clearTimeout(timer)
|
|
232
|
+
},
|
|
233
|
+
"kriya-mirror: stop"
|
|
234
|
+
)
|
|
235
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kriya-ai/harness-mirror",
|
|
3
|
+
"description": "Session mirror for the Kriya Harness: a summary of each DeepSeek Harness turn in a Kriya thread, with an offline queue",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"private": true,
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "index.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./index.js",
|
|
10
|
+
"./package.json": "./package.json"
|
|
11
|
+
},
|
|
12
|
+
"license": "UNLICENSED"
|
|
13
|
+
}
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
// The Overview tab, browser half: a right-sidebar page (the seat the Changes
|
|
2
|
+
// and Files tabs use) with one session at a glance: environment (this
|
|
3
|
+
// computer, the folder, the repository and branch), context and usage from
|
|
4
|
+
// DSH's token meter, the files changed, background jobs and connectors. It
|
|
5
|
+
// reads only this plugin's route (index.js); no DSH file is edited (HD-02).
|
|
6
|
+
window.__ModuleLoader__.load({
|
|
7
|
+
id: "@kriya-ai/harness-overview",
|
|
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-overview"
|
|
14
|
+
const KIND = "kriya-overview"
|
|
15
|
+
const API = "api/kriya.overview"
|
|
16
|
+
const REFRESH_MS = 4000
|
|
17
|
+
|
|
18
|
+
const CSS = `
|
|
19
|
+
.kh-ov { height: 100%; overflow: auto; color: var(--dsw-alias-label-primary); font-size: 13px; padding: 4px 0 16px; }
|
|
20
|
+
.kh-ov-sec { padding: 10px 14px; border-bottom: 1px solid var(--dsw-alias-border-l2); }
|
|
21
|
+
.kh-ov-sec:last-child { border-bottom: 0; }
|
|
22
|
+
.kh-ov-h { display: flex; align-items: center; justify-content: space-between; margin: 0 0 6px; font-size: 12px; font-weight: 600; color: var(--dsw-alias-label-secondary); }
|
|
23
|
+
.kh-ov-row { display: flex; align-items: center; gap: 8px; min-height: 28px; }
|
|
24
|
+
.kh-ov-row svg { flex: none; color: var(--dsw-alias-label-tertiary); }
|
|
25
|
+
.kh-ov-val { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
26
|
+
.kh-ov-mono { font-family: var(--dsw-font-code, ui-monospace, monospace); font-size: 12px; }
|
|
27
|
+
.kh-ov-dim { color: var(--dsw-alias-label-tertiary); }
|
|
28
|
+
.kh-ov-bar { height: 6px; border-radius: 3px; background: var(--dsw-alias-bg-layer-1, var(--dsw-alias-border-l2)); overflow: hidden; margin-top: 6px; }
|
|
29
|
+
.kh-ov-bar > span { display: block; height: 100%; background: var(--dsw-alias-link); }
|
|
30
|
+
.kh-ov-bar.warn > span { background: var(--dsw-alias-state-warn-label); }
|
|
31
|
+
.kh-ov-plus { color: var(--dsw-alias-state-success-primary); }
|
|
32
|
+
.kh-ov-minus { color: var(--dsw-alias-state-error-primary); }
|
|
33
|
+
.kh-ov-pill { flex: none; font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--dsw-alias-bg-layer-1, transparent); border: 1px solid var(--dsw-alias-border-l2); color: var(--dsw-alias-label-secondary); }
|
|
34
|
+
.kh-ov-pill.running { color: var(--dsw-alias-link); border-color: currentColor; }
|
|
35
|
+
.kh-ov-pill.failed, .kh-ov-pill.killed { color: var(--dsw-alias-state-error-primary); border-color: currentColor; }
|
|
36
|
+
.kh-ov-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; }
|
|
37
|
+
.kh-ov-btn:hover { background: var(--dsw-alias-interactive-bg-hover); }
|
|
38
|
+
.kh-ov-btn:focus-visible { outline: 2px solid var(--dsw-alias-link); outline-offset: -2px; }
|
|
39
|
+
.kh-ov-switch { flex: none; width: 44px; height: 26px; padding: 3px; border: 0; border-radius: 999px; background: var(--dsw-alias-border-l2); cursor: pointer; position: relative; }
|
|
40
|
+
.kh-ov-switch::before { content: ""; position: absolute; inset: -9px 0; }
|
|
41
|
+
.kh-ov-switch > span { display: block; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .15s; }
|
|
42
|
+
.kh-ov-switch.on { background: var(--dsw-alias-link); }
|
|
43
|
+
.kh-ov-switch.on > span { transform: translateX(18px); }
|
|
44
|
+
.kh-ov-switch:disabled { opacity: .5; cursor: default; }
|
|
45
|
+
.kh-ov-switch:focus-visible { outline: 2px solid var(--dsw-alias-link); outline-offset: 2px; }
|
|
46
|
+
.kh-ov-note2 { font-size: 12px; line-height: 1.45; color: var(--dsw-alias-label-tertiary); padding-bottom: 4px; }
|
|
47
|
+
.kh-ov-err { color: var(--dsw-alias-state-error-primary); }
|
|
48
|
+
.kh-ov-error { padding: 12px 14px; color: var(--dsw-alias-state-error-primary); }
|
|
49
|
+
.kh-ov-note { padding: 14px; color: var(--dsw-alias-label-tertiary); line-height: 1.5; }
|
|
50
|
+
`
|
|
51
|
+
|
|
52
|
+
function installStyles() {
|
|
53
|
+
const tag = document.createElement("style")
|
|
54
|
+
tag.dataset.plugin = PLUGIN
|
|
55
|
+
tag.textContent = CSS
|
|
56
|
+
document.head.appendChild(tag)
|
|
57
|
+
return () => tag.remove()
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const icon = (d, size = 16) =>
|
|
61
|
+
h(
|
|
62
|
+
"svg",
|
|
63
|
+
{ width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 1.7, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": true },
|
|
64
|
+
...d.map((path, i) => h("path", { key: i, d: path }))
|
|
65
|
+
)
|
|
66
|
+
const ICONS = {
|
|
67
|
+
computer: ["M4 5h16v10H4z", "M2 19h20"],
|
|
68
|
+
folder: ["M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2Z"],
|
|
69
|
+
repo: ["M6 3h11a1 1 0 0 1 1 1v14H7a2 2 0 0 0-2 2V5a2 2 0 0 1 1-2Z", "M5 20a2 2 0 0 0 2 1h11v-3"],
|
|
70
|
+
branch: ["M6 3v12", "M18 9a3 3 0 1 0 0-6 3 3 0 0 0 0 6Z", "M6 21a3 3 0 1 0 0-6 3 3 0 0 0 0 6Z", "M18 9a9 9 0 0 1-9 9"],
|
|
71
|
+
plug: ["M9 2v6", "M15 2v6", "M6 8h12v4a6 6 0 0 1-12 0Z", "M12 18v4"],
|
|
72
|
+
refresh: ["M20 11a8 8 0 1 0-2.3 5.7", "M20 4v7h-7"],
|
|
73
|
+
overview: ["M4 4h7v7H4z", "M13 4h7v4h-7z", "M13 10h7v10h-7z", "M4 13h7v7H4z"],
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const REMOTE = "api/kriya.remote"
|
|
77
|
+
|
|
78
|
+
function Toggle({ label, checked, disabled, onChange }) {
|
|
79
|
+
return h(
|
|
80
|
+
"button",
|
|
81
|
+
{ type: "button", role: "switch", "aria-checked": checked, "aria-label": label, disabled, className: `kh-ov-switch${checked ? " on" : ""}`, onClick: () => onChange(!checked) },
|
|
82
|
+
h("span", null)
|
|
83
|
+
)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// The switch beside a session's environment: on, this session shows up
|
|
87
|
+
// live in Kriya and Kriya can reach this computer; no command to run
|
|
88
|
+
function Remote({ sessionId }) {
|
|
89
|
+
const [state, setState] = useState(null)
|
|
90
|
+
const [error, setError] = useState(null)
|
|
91
|
+
const [busy, setBusy] = useState(false)
|
|
92
|
+
const call = useCallback(async (body) => {
|
|
93
|
+
const query = new URLSearchParams({ session: sessionId })
|
|
94
|
+
const response = await fetch(`${REMOTE}?${query}`, { method: body ? "POST" : "GET", credentials: "same-origin", ...(body && { headers: { "content-type": "application/json" }, body: JSON.stringify(body) }) })
|
|
95
|
+
const answer = await response.json().catch(() => ({}))
|
|
96
|
+
if (!response.ok) throw new Error(answer.error || `Kriya Harness answered ${response.status}.`)
|
|
97
|
+
setState(answer)
|
|
98
|
+
setError(null)
|
|
99
|
+
}, [sessionId])
|
|
100
|
+
useEffect(() => {
|
|
101
|
+
const read = () => call().catch((e) => setError(e.message))
|
|
102
|
+
read()
|
|
103
|
+
const timer = setInterval(read, REFRESH_MS)
|
|
104
|
+
return () => clearInterval(timer)
|
|
105
|
+
}, [call])
|
|
106
|
+
const change = async (body) => {
|
|
107
|
+
setBusy(true)
|
|
108
|
+
await call(body).catch((e) => setError(e.message))
|
|
109
|
+
setBusy(false)
|
|
110
|
+
}
|
|
111
|
+
if (!state) return null
|
|
112
|
+
const line = !state.signedIn
|
|
113
|
+
? "Sign in with kriya login to use this."
|
|
114
|
+
: state.unavailable
|
|
115
|
+
? "Not reaching Kriya: it's switched off on the server (harness.remoteControl in the Owner console). What happens now is kept and sent once it's on."
|
|
116
|
+
: !state.on
|
|
117
|
+
? "Follow this session and run tasks here from the Kriya app."
|
|
118
|
+
: state.daemon === "external"
|
|
119
|
+
? `On. Follow it at ${state.host}; kriya daemon is already listening.`
|
|
120
|
+
: state.folderOffered
|
|
121
|
+
? `On. Follow it at ${state.host}, Kriya Harness.`
|
|
122
|
+
: `On. Follow it at ${state.host}. Tasks from Kriya can't run in the home folder.`
|
|
123
|
+
return Section("Remote Control", [
|
|
124
|
+
h("div", { key: "t", className: "kh-ov-row" }, h("span", { className: "kh-ov-val" }, "Remote Control"), h(Toggle, { label: "Remote Control", checked: state.on, disabled: busy || !state.signedIn, onChange: (on) => change({ on }) })),
|
|
125
|
+
h("div", { key: "n", className: `kh-ov-note2${state.unavailable ? " kh-ov-err" : ""}` }, line),
|
|
126
|
+
error && h("div", { key: "e", className: "kh-ov-note2 kh-ov-err", role: "alert" }, error),
|
|
127
|
+
state.on && h("div", { key: "s", className: "kh-ov-row" }, h("span", { className: "kh-ov-val" }, "Allow serving"), h(Toggle, { label: "Allow serving from Kriya", checked: state.serve, disabled: busy, onChange: (serve) => change({ serve }) })),
|
|
128
|
+
state.on && typeof state.edit === "boolean" && h("div", { key: "e", className: "kh-ov-row" }, h("span", { className: "kh-ov-val" }, "Allow editing"), h(Toggle, { label: "Allow editing from Kriya", checked: state.edit, disabled: busy, onChange: (edit) => change({ edit }) })),
|
|
129
|
+
state.on && h("div", { key: "f", className: "kh-ov-row" }, h("span", { className: "kh-ov-val" }, "Allow Full access"), h(Toggle, { label: "Allow Full access from Kriya", checked: state.fullAccess, disabled: busy, onChange: (fullAccess) => change({ fullAccess }) })),
|
|
130
|
+
state.on && state.fullAccess && h("div", { key: "w", className: "kh-ov-note2 kh-ov-err" }, "Tasks from Kriya can then run with no sandbox and no questions on this computer."),
|
|
131
|
+
])
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const fmt = (n) => (n === undefined || n === null ? "—" : n >= 10_000 ? `${(n / 1000).toFixed(n >= 100_000 ? 0 : 1)}k` : String(n))
|
|
135
|
+
const home = (path) => (typeof path === "string" ? path.replace(/^\/(Users|home)\/[^/]+/, "~") : path)
|
|
136
|
+
const ago = (ms) => {
|
|
137
|
+
if (!ms) return ""
|
|
138
|
+
const s = Math.max(0, Math.round((Date.now() - ms) / 1000))
|
|
139
|
+
return s < 60 ? `${s}s` : s < 3600 ? `${Math.round(s / 60)}m` : `${Math.round(s / 3600)}h`
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const Row = (glyph, value, title, extra) =>
|
|
143
|
+
h("div", { className: "kh-ov-row", title }, glyph && icon(ICONS[glyph]), h("span", { className: "kh-ov-val" }, value), extra)
|
|
144
|
+
const Section = (title, children, action) =>
|
|
145
|
+
h("section", { className: "kh-ov-sec", "aria-label": title }, h("h3", { className: "kh-ov-h" }, title, action), children)
|
|
146
|
+
|
|
147
|
+
function Environment({ env, action }) {
|
|
148
|
+
const repo = env.repo
|
|
149
|
+
return Section("Environment", [
|
|
150
|
+
h(React.Fragment, { key: "c" }, Row("computer", `${env.computer} · ${env.os}`)),
|
|
151
|
+
h(React.Fragment, { key: "f" }, Row("folder", h("span", { className: "kh-ov-mono" }, home(env.folder)), env.folder)),
|
|
152
|
+
env.git
|
|
153
|
+
? [
|
|
154
|
+
h(React.Fragment, { key: "r" }, Row("repo", repo ? (repo.github ? repo.path : `${repo.host}/${repo.path}`) : h("span", { className: "kh-ov-dim" }, "No remote"), repo ? `${repo.host}/${repo.path}` : undefined, repo?.github && h("span", { className: "kh-ov-pill" }, "GitHub"))),
|
|
155
|
+
h(React.Fragment, { key: "b" }, Row("branch", env.branch ?? h("span", { className: "kh-ov-dim" }, "Detached HEAD"))),
|
|
156
|
+
]
|
|
157
|
+
: h(React.Fragment, { key: "n" }, Row("repo", h("span", { className: "kh-ov-dim" }, "Not a git repository"))),
|
|
158
|
+
], action)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function Context({ data }) {
|
|
162
|
+
if (!data.live) return Section("Context", h("div", { className: "kh-ov-dim" }, "Open this session to measure its context."))
|
|
163
|
+
const c = data.context
|
|
164
|
+
if (!c) return Section("Context", h("div", { className: "kh-ov-dim" }, "Not measured yet: it appears after the first answer."))
|
|
165
|
+
const pct = c.window ? Math.min(100, Math.round((c.used / c.window) * 100)) : null
|
|
166
|
+
const u = data.usage
|
|
167
|
+
return Section("Context", [
|
|
168
|
+
h("div", { key: "t", className: "kh-ov-row" }, h("span", { className: "kh-ov-val" }, c.window ? `${fmt(c.used)} of ${fmt(c.window)} tokens` : `${fmt(c.used)} tokens`), pct !== null && h("b", null, `${pct}%`)),
|
|
169
|
+
pct !== null &&
|
|
170
|
+
h("div", { key: "b", className: `kh-ov-bar${pct >= 80 ? " warn" : ""}`, role: "progressbar", "aria-label": "Context used", "aria-valuemin": 0, "aria-valuemax": 100, "aria-valuenow": pct }, h("span", { style: { width: `${pct}%` } })),
|
|
171
|
+
u && h("div", { key: "u", className: "kh-ov-row kh-ov-dim" }, `In ${fmt(u.input)} · out ${fmt(u.output)} · cache ${fmt(u.cacheRead)}`),
|
|
172
|
+
])
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function Changes({ changes }) {
|
|
176
|
+
if (!changes) return null
|
|
177
|
+
if (!changes.count) return Section("Changes", h("div", { className: "kh-ov-dim" }, "No changes against HEAD."))
|
|
178
|
+
return Section(
|
|
179
|
+
`Changes · ${changes.count}${changes.truncated ? "+" : ""}`,
|
|
180
|
+
changes.files.map((f) =>
|
|
181
|
+
h(
|
|
182
|
+
"div",
|
|
183
|
+
{ key: f.path, className: "kh-ov-row", title: f.path },
|
|
184
|
+
h("span", { className: "kh-ov-val kh-ov-mono" }, f.path),
|
|
185
|
+
f.added !== undefined && h("span", { className: "kh-ov-mono kh-ov-plus" }, `+${f.added}`),
|
|
186
|
+
f.deleted !== undefined && h("span", { className: "kh-ov-mono kh-ov-minus" }, `−${f.deleted}`)
|
|
187
|
+
)
|
|
188
|
+
)
|
|
189
|
+
)
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function Jobs({ jobs }) {
|
|
193
|
+
return Section(
|
|
194
|
+
`Background tasks${jobs.length ? ` · ${jobs.filter((j) => j.status === "running" || j.status === "stopping").length} running` : ""}`,
|
|
195
|
+
jobs.length
|
|
196
|
+
? jobs.map((j) =>
|
|
197
|
+
h("div", { key: j.id, className: "kh-ov-row", title: j.label }, h("span", { className: "kh-ov-val" }, j.label || j.kind), h("span", { className: "kh-ov-dim kh-ov-mono" }, ago(j.finishedAt ?? j.startedAt)), h("span", { className: `kh-ov-pill ${j.status}` }, j.status))
|
|
198
|
+
)
|
|
199
|
+
: h("div", { className: "kh-ov-dim" }, "None in this session.")
|
|
200
|
+
)
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function Connectors({ connectors }) {
|
|
204
|
+
return Section("Connectors", [
|
|
205
|
+
h(React.Fragment, { key: "k" }, Row("plug", connectors.kriya ? `Kriya · ${connectors.kriya}` : h("span", { className: "kh-ov-dim" }, "Not signed in to Kriya"))),
|
|
206
|
+
connectors.mcp.length
|
|
207
|
+
? connectors.mcp.map((m) => h(React.Fragment, { key: m.id }, Row("plug", m.name, undefined, h("span", { className: "kh-ov-pill" }, m.status))))
|
|
208
|
+
: h("div", { key: "m", className: "kh-ov-row kh-ov-dim" }, "No MCP servers connected."),
|
|
209
|
+
])
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function OverviewBody({ useTabInfo, sessionId }) {
|
|
213
|
+
const { tab } = useTabInfo()
|
|
214
|
+
const visible = tab?.visible !== false
|
|
215
|
+
const [data, setData] = useState(null)
|
|
216
|
+
const [error, setError] = useState(null)
|
|
217
|
+
|
|
218
|
+
const load = useCallback(async () => {
|
|
219
|
+
if (!sessionId) return
|
|
220
|
+
try {
|
|
221
|
+
const response = await fetch(`${API}?${new URLSearchParams({ session: sessionId })}`, { credentials: "same-origin" })
|
|
222
|
+
const body = await response.json().catch(() => ({}))
|
|
223
|
+
if (!response.ok) throw new Error(body.error || `Kriya answered ${response.status}.`)
|
|
224
|
+
setData(body)
|
|
225
|
+
setError(null)
|
|
226
|
+
} catch (e) {
|
|
227
|
+
setError(e.message === "Failed to fetch" ? "Kriya Harness isn't answering; is it still running?" : e.message)
|
|
228
|
+
}
|
|
229
|
+
}, [sessionId])
|
|
230
|
+
|
|
231
|
+
useEffect(() => {
|
|
232
|
+
if (!visible) return
|
|
233
|
+
load()
|
|
234
|
+
const timer = setInterval(load, REFRESH_MS)
|
|
235
|
+
return () => clearInterval(timer)
|
|
236
|
+
}, [visible, load])
|
|
237
|
+
|
|
238
|
+
if (!sessionId) return h("div", { className: "kh-ov-note" }, "Start or open a session to see its overview.")
|
|
239
|
+
if (error && !data) return h("div", { className: "kh-ov-error", role: "alert" }, error)
|
|
240
|
+
if (!data) return h("div", { className: "kh-ov-note" }, "Loading…")
|
|
241
|
+
const refresh = h("button", { type: "button", className: "kh-ov-btn", onClick: load, "aria-label": "Refresh the overview", title: "Refresh" }, icon(ICONS.refresh))
|
|
242
|
+
return h(
|
|
243
|
+
"div",
|
|
244
|
+
{ className: "kh-ov" },
|
|
245
|
+
error && h("div", { className: "kh-ov-error", role: "alert" }, error),
|
|
246
|
+
h(Environment, { key: "e", env: data.environment, action: refresh }),
|
|
247
|
+
h(Remote, { key: "r", sessionId }),
|
|
248
|
+
h(Context, { key: "c", data }),
|
|
249
|
+
h(Changes, { key: "ch", changes: data.changes }),
|
|
250
|
+
h(Jobs, { key: "j", jobs: data.jobs }),
|
|
251
|
+
h(Connectors, { key: "co", connectors: data.connectors })
|
|
252
|
+
)
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
const definition = {
|
|
256
|
+
id: PLUGIN,
|
|
257
|
+
kind: KIND,
|
|
258
|
+
priority: "extension",
|
|
259
|
+
title: () => "Overview",
|
|
260
|
+
guide: [{ id: "overview", order: 5, title: () => "Overview", description: () => "Environment, context, changes, tasks and connectors", icon: () => icon(ICONS.overview, 20) }],
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
const inject = ["slots", "sidebarRightTabs"]
|
|
264
|
+
|
|
265
|
+
function apply(ctx) {
|
|
266
|
+
if (typeof document !== "undefined") ctx.effect(installStyles, "kriya-overview: styles")
|
|
267
|
+
ctx.effect(() => ctx.sidebarRightTabs.register(definition), "kriya-overview: type")
|
|
268
|
+
ctx.effect(
|
|
269
|
+
() => ctx.slots.inject("sidebar.right.pane.tab", () => ctx.slots.register({ name: "sidebar.right.pane.tab", key: PLUGIN }, OverviewBody)),
|
|
270
|
+
"kriya-overview: body"
|
|
271
|
+
)
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
return { apply, inject, OverviewBody, definition, API }
|
|
275
|
+
},
|
|
276
|
+
})
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { platform } from "node:os"
|
|
2
|
+
|
|
3
|
+
import { ChangesError, listChanges } from "../../src/changes.js"
|
|
4
|
+
import { jobRows, meterFigures, originOf } from "../../src/overview.js"
|
|
5
|
+
import { readDevice } from "../../src/store.js"
|
|
6
|
+
|
|
7
|
+
// The Overview tab, node half: one read-only route on DSH's shared /api
|
|
8
|
+
// channel, inside Connection's fence (as plugins/changes). For one session:
|
|
9
|
+
// where it runs (this computer, the folder, the repository and branch), the
|
|
10
|
+
// token meter's context and usage figures (live sessions only), the files
|
|
11
|
+
// changed against HEAD, its background jobs, and what it is connected to.
|
|
12
|
+
// It reads; it never changes anything, and returns no credential or token.
|
|
13
|
+
|
|
14
|
+
export const name = "kriya-overview"
|
|
15
|
+
export const inject = ["connection", "sessions"]
|
|
16
|
+
|
|
17
|
+
export const ROUTE = "/api/kriya.overview"
|
|
18
|
+
const FILES = 8
|
|
19
|
+
const OS = { darwin: "macOS", linux: "Linux", win32: "Windows" }
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The route handler, separate from DSH so tests call it directly.
|
|
23
|
+
* @param {{ folderOf: (id: string) => Promise<string | undefined>, live: (id: string) => any, meter: (session: any) => object | undefined, jobs: (id: string) => any[], kriyaUrl: () => string | undefined }} host
|
|
24
|
+
*/
|
|
25
|
+
export function handler(host) {
|
|
26
|
+
return async (request) => {
|
|
27
|
+
const id = new URL(request.url).searchParams.get("session")
|
|
28
|
+
if (!id || id.length > 200) throw new ChangesError("Which session?")
|
|
29
|
+
const cwd = await host.folderOf(id)
|
|
30
|
+
if (!cwd) throw new ChangesError("That session isn't known here.")
|
|
31
|
+
// In a folder outside git, the session's own changes (Kriya's private store)
|
|
32
|
+
const changes = await listChanges(cwd, id, await host.startOf?.(id))
|
|
33
|
+
const session = host.live(id)
|
|
34
|
+
let kriya
|
|
35
|
+
try {
|
|
36
|
+
const url = host.kriyaUrl()
|
|
37
|
+
kriya = url ? new URL(url).host : undefined
|
|
38
|
+
} catch {
|
|
39
|
+
kriya = undefined
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
environment: {
|
|
43
|
+
computer: "This computer",
|
|
44
|
+
os: OS[platform()] ?? platform(),
|
|
45
|
+
folder: cwd,
|
|
46
|
+
git: Boolean(changes.git && !changes.shadow),
|
|
47
|
+
...(changes.git && !changes.shadow && { root: changes.root, branch: changes.branch, repo: await originOf(changes.root) }),
|
|
48
|
+
},
|
|
49
|
+
live: Boolean(session),
|
|
50
|
+
...(session ? meterFigures(host.meter(session)) : { context: null, usage: null }),
|
|
51
|
+
changes: changes.git ? { count: changes.files.length, truncated: changes.truncated, added: changes.added, deleted: changes.deleted, files: changes.files.slice(0, FILES) } : null,
|
|
52
|
+
jobs: jobRows(host.jobs(id)),
|
|
53
|
+
connectors: { kriya: kriya ?? null, mcp: [] },
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const reply = (body, status = 200) => Response.json(body, { status, headers: { "cache-control": "no-store" } })
|
|
59
|
+
|
|
60
|
+
/** A ChangesError is the person's to fix (400); anything else is ours (500), logged */
|
|
61
|
+
export async function answer(route, request, log = () => {}) {
|
|
62
|
+
try {
|
|
63
|
+
return reply(await route(request))
|
|
64
|
+
} catch (error) {
|
|
65
|
+
if (error instanceof ChangesError) return reply({ error: error.message }, 400)
|
|
66
|
+
log(error)
|
|
67
|
+
return reply({ error: "Kriya couldn't read this session's overview; see the terminal for details." }, 500)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function apply(ctx) {
|
|
72
|
+
const folderOf = async (id) => {
|
|
73
|
+
const live = ctx.sessions.get(id)?.header
|
|
74
|
+
const stored = live === undefined ? await ctx.get("sessionPersistence")?.stat(id) : undefined
|
|
75
|
+
return (live ?? stored?.header)?.cwd
|
|
76
|
+
}
|
|
77
|
+
const route = handler({
|
|
78
|
+
folderOf,
|
|
79
|
+
startOf: async (id) => (ctx.sessions.get(id)?.header ?? (await ctx.get("sessionPersistence")?.stat(id))?.header)?.createdAt,
|
|
80
|
+
live: (id) => ctx.sessions.get(id),
|
|
81
|
+
// Optional services: a profile without them shows no figures, never an error
|
|
82
|
+
meter: (session) => ctx.get("sessionProjections")?.snapshot(session, ["contextPressure", "tokenUsage"])?.values,
|
|
83
|
+
jobs: (id) => {
|
|
84
|
+
try {
|
|
85
|
+
return ctx.get("jobs")?.list(id) ?? []
|
|
86
|
+
} catch {
|
|
87
|
+
// Not this session's to list: show none rather than fail the tab
|
|
88
|
+
return []
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
kriyaUrl: () => readDevice()?.url,
|
|
92
|
+
})
|
|
93
|
+
const log = (error) => ctx.logger("kriya-overview").warn(error)
|
|
94
|
+
ctx.effect(() => ctx.connection.fetch.register({ path: ROUTE, methods: ["GET"], requestBody: "buffered", fetch: (request) => answer(route, request, log) }))
|
|
95
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kriya-ai/harness-overview",
|
|
3
|
+
"description": "The Overview tab of the Kriya Harness Web UI: a session's environment, context, changes, background tasks and connectors",
|
|
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
|
+
}
|