@kriya-ai/harness 0.2.5 → 2.0.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/RELEASE_NOTES.md +121 -0
- package/SAFETY.md +181 -0
- package/THIRD_PARTY_NOTICES.md +113 -0
- package/bin/kriya.js +188 -2
- package/bundle/cordis.patch.yml +60 -5
- package/contract/SOURCE.md +3 -3
- package/contract/contract.json +498 -3
- package/contract/schemas/api.json +64 -0
- package/contract/schemas/auth_matrix.json +44 -0
- package/contract/schemas/component_states.json +33 -0
- package/contract/schemas/design_tokens.json +34 -0
- package/contract/schemas/scene_direction.json +82 -0
- package/contract/schemas/threat_model.json +44 -0
- package/package.json +2 -1
- package/plugins/changes/client.js +5 -3
- package/plugins/deploy/index.js +215 -0
- package/plugins/deploy/package.json +13 -0
- package/plugins/grounding/index.js +81 -0
- package/plugins/grounding/lookup.js +373 -0
- package/plugins/grounding/package.json +13 -0
- package/plugins/kriya-tools/index.js +2 -1
- package/plugins/loop/index.js +381 -10
- package/plugins/mcp/index.js +79 -0
- package/plugins/mcp/package.json +13 -0
- package/plugins/mirror/index.js +17 -0
- package/plugins/overview/client.js +5 -2
- package/plugins/preview/client.js +12 -6
- package/plugins/progress/client.js +7 -4
- package/plugins/repo/index.js +230 -0
- package/plugins/repo/package.json +13 -0
- package/plugins/repo/repo.js +348 -0
- package/plugins/runstrip/client.js +436 -0
- package/plugins/runstrip/index.js +312 -0
- package/plugins/runstrip/package.json +23 -0
- package/src/cartridges.js +133 -0
- package/src/contracts.js +130 -0
- package/src/critic.js +78 -0
- package/src/daemon.js +7 -1
- package/src/doctor.js +67 -0
- package/src/edit/core/effects.js +185 -0
- package/src/edit/core/ffmpeg.js +65 -6
- package/src/edit/core/layout.js +46 -1
- package/src/edit/core/ops.js +169 -2
- package/src/edit/core/plan.js +65 -9
- package/src/edit/core/project.d.ts +24 -0
- package/src/edit/core/project.js +64 -0
- package/src/edit/core/solver.js +34 -6
- package/src/edit/core/style-brief.js +211 -0
- package/src/edit/core/style-packs.js +57 -0
- package/src/edit/core/type-kit.js +173 -0
- package/src/edit/director/ask.js +37 -3
- package/src/edit/director/assembly.js +829 -0
- package/src/edit/director/continuity.js +9 -1
- package/src/edit/director/custom-motion.js +88 -0
- package/src/edit/director/graphics.js +44 -10
- package/src/edit/director/intent.js +125 -0
- package/src/edit/director/mentions.js +52 -0
- package/src/edit/director/plan.js +43 -11
- package/src/edit/director/revise.js +132 -9
- package/src/edit/director/viewer.js +136 -0
- package/src/edit/director/watch-fix.js +119 -0
- package/src/edit/engine/captions.js +110 -5
- package/src/edit/engine/confine.js +81 -4
- package/src/edit/engine/custom.js +243 -0
- package/src/edit/engine/dna2.js +893 -0
- package/src/edit/engine/fonts.js +218 -0
- package/src/edit/engine/graphics.js +271 -10
- package/src/edit/engine/index.js +14 -5
- package/src/edit/engine/motion.js +148 -13
- package/src/edit/engine/music-bed.js +59 -1
- package/src/edit/engine/packs.js +11 -0
- package/src/edit/engine/reference2.js +26 -0
- package/src/edit/engine/sfx.js +56 -1
- package/src/edit/engine/tool.js +21 -5
- package/src/edit/gates/assembly.js +194 -0
- package/src/edit/gates/copy.js +7 -4
- package/src/edit/gates/index.js +72 -7
- package/src/edit/gates/reference.js +115 -0
- package/src/edit/gates/tile.js +96 -0
- package/src/edit/host/client.js +8 -3
- package/src/edit/host/clips.js +33 -0
- package/src/edit/host/jobs.js +9 -3
- package/src/edit/host/layers.js +134 -0
- package/src/edit/host/main.js +10 -3
- package/src/edit/host/paths.js +21 -3
- package/src/edit/host/preview.js +108 -0
- package/src/edit/host/projects.js +443 -34
- package/src/edit/host/server.js +235 -20
- package/src/edit/host/tavi.js +77 -0
- package/src/edit/index/index.js +3 -2
- package/src/edit/loop/make.js +28 -3
- package/src/edit/recipes/assembly.js +352 -0
- package/src/edit/recipes/graphic-clips.js +4 -2
- package/src/edit/recipes/openings.js +36 -0
- package/src/edit/recipes/reel.js +104 -14
- package/src/edit/recipes/reference-look.js +29 -0
- package/src/edit/recipes/short-from-long.js +3 -3
- package/src/edit/recipes/sound.js +71 -0
- package/src/edit/runtime/cli.js +26 -5
- package/src/edit/runtime/fetch.js +4 -4
- package/src/edit/runtime/licences.js +7 -1
- package/src/explore.js +103 -0
- package/src/failure.js +1 -1
- package/src/gate-commands.js +114 -0
- package/src/gates/api.js +127 -0
- package/src/gates/commands.js +111 -0
- package/src/gates/detectors.js +370 -0
- package/src/gates/http.js +62 -0
- package/src/gates/index.js +196 -0
- package/src/gates/page.js +264 -0
- package/src/gates/sast.js +64 -0
- package/src/gates/stack.js +110 -0
- package/src/gates/tenant.js +162 -0
- package/src/gates/three.js +431 -0
- package/src/gates/ui.js +111 -0
- package/src/gateway-proxy.js +20 -2
- package/src/launch.js +39 -5
- package/src/loop.js +199 -7
- package/src/mcp.js +126 -0
- package/src/milestones.js +188 -0
- package/src/modes.js +67 -0
- package/src/orchestra.js +50 -0
- package/src/outcomes.js +88 -0
- package/src/profiles.js +5 -0
- package/src/receipts.js +238 -0
- package/src/release.js +356 -0
- package/src/runstrip.js +122 -0
- package/src/stack.js +120 -0
- package/src/verify.js +67 -20
- package/studio/dist/fonts/fraunces.woff2 +0 -0
- package/studio/dist/fonts/geist.woff2 +0 -0
- package/studio/dist/fonts/jetbrains-mono.woff2 +0 -0
- package/studio/dist/studio.css +449 -1
- package/studio/dist/studio.js +3 -3
|
@@ -11,6 +11,8 @@ window.__ModuleLoader__.load({
|
|
|
11
11
|
const h = React.createElement
|
|
12
12
|
|
|
13
13
|
const PLUGIN = "@kriya-ai/harness-overview"
|
|
14
|
+
// Harness 2.0 W18: with --runstrip, plugins/runstrip names the four tracks and adds each one's section; absent, nothing changes
|
|
15
|
+
const tracks = () => globalThis.__kriyaTracks
|
|
14
16
|
const KIND = "kriya-overview"
|
|
15
17
|
const API = "api/kriya.overview"
|
|
16
18
|
const REFRESH_MS = 4000
|
|
@@ -244,6 +246,7 @@ window.__ModuleLoader__.load({
|
|
|
244
246
|
{ className: "kh-ov" },
|
|
245
247
|
error && h("div", { className: "kh-ov-error", role: "alert" }, error),
|
|
246
248
|
h(Environment, { key: "e", env: data.environment, action: refresh }),
|
|
249
|
+
tracks() && h(tracks().Project, { key: "p", sessionId }),
|
|
247
250
|
h(Remote, { key: "r", sessionId }),
|
|
248
251
|
h(Context, { key: "c", data }),
|
|
249
252
|
h(Changes, { key: "ch", changes: data.changes }),
|
|
@@ -256,8 +259,8 @@ window.__ModuleLoader__.load({
|
|
|
256
259
|
id: PLUGIN,
|
|
257
260
|
kind: KIND,
|
|
258
261
|
priority: "extension",
|
|
259
|
-
title: () => "Overview",
|
|
260
|
-
guide: [{ id: "overview", order
|
|
262
|
+
title: () => tracks()?.title[KIND] ?? "Overview",
|
|
263
|
+
guide: [{ id: "overview", get order() { return tracks()?.order[KIND] ?? 5 }, title: () => tracks()?.title[KIND] ?? "Overview", description: () => "Environment, context, changes, tasks and connectors", icon: () => icon(ICONS.overview, 20) }],
|
|
261
264
|
}
|
|
262
265
|
|
|
263
266
|
const inject = ["slots", "sidebarRightTabs"]
|
|
@@ -15,6 +15,8 @@ window.__ModuleLoader__.load({
|
|
|
15
15
|
const h = React.createElement
|
|
16
16
|
|
|
17
17
|
const PLUGIN = "@kriya-ai/harness-preview"
|
|
18
|
+
// Harness 2.0 W18: with --runstrip, plugins/runstrip names the four tracks and adds each one's section; absent, nothing changes
|
|
19
|
+
const tracks = () => globalThis.__kriyaTracks
|
|
18
20
|
const KIND = "kriya-preview"
|
|
19
21
|
const STORE = "kriya-preview:last"
|
|
20
22
|
|
|
@@ -94,7 +96,7 @@ window.__ModuleLoader__.load({
|
|
|
94
96
|
}
|
|
95
97
|
}
|
|
96
98
|
|
|
97
|
-
function FrameView() {
|
|
99
|
+
function FrameView({ viewport } = {}) {
|
|
98
100
|
const [input, setInput] = useState(remembered)
|
|
99
101
|
const [url, setUrl] = useState(null)
|
|
100
102
|
const [error, setError] = useState(null)
|
|
@@ -159,6 +161,8 @@ window.__ModuleLoader__.load({
|
|
|
159
161
|
key: stamp,
|
|
160
162
|
ref: frame,
|
|
161
163
|
className: "kh-pv-frame",
|
|
164
|
+
// Live track: a chosen viewport width, centred; wider than the column scrolls
|
|
165
|
+
...(viewport && { style: { flex: "1 0 auto", width: `${viewport}px`, maxWidth: "none", alignSelf: viewport > 1000 ? "flex-start" : "center" } }),
|
|
162
166
|
src: url,
|
|
163
167
|
title: `Preview of ${url}`,
|
|
164
168
|
referrerPolicy: "no-referrer",
|
|
@@ -281,7 +285,8 @@ window.__ModuleLoader__.load({
|
|
|
281
285
|
)
|
|
282
286
|
}
|
|
283
287
|
|
|
284
|
-
function PreviewBody({ useTabInfo }) {
|
|
288
|
+
function PreviewBody({ useTabInfo, sessionId }) {
|
|
289
|
+
const [viewport, setViewport] = useState(null)
|
|
285
290
|
const visible = useTabInfo?.().tab?.visible !== false
|
|
286
291
|
const [agent, setAgent] = useState(false)
|
|
287
292
|
const [mode, setMode] = useState("frame")
|
|
@@ -301,7 +306,7 @@ window.__ModuleLoader__.load({
|
|
|
301
306
|
}, [])
|
|
302
307
|
return h(
|
|
303
308
|
"div",
|
|
304
|
-
{ className: "kh-pv" },
|
|
309
|
+
{ className: "kh-pv", ...(viewport && { style: { overflowX: "auto" } }) },
|
|
305
310
|
agent &&
|
|
306
311
|
h(
|
|
307
312
|
"div",
|
|
@@ -309,7 +314,8 @@ window.__ModuleLoader__.load({
|
|
|
309
314
|
h("button", { type: "button", className: "kh-pv-mode", "aria-pressed": mode === "frame", onClick: () => setMode("frame") }, "Your app"),
|
|
310
315
|
h("button", { type: "button", className: "kh-pv-mode", "aria-pressed": mode === "agent", onClick: () => setMode("agent") }, "Agent's browser")
|
|
311
316
|
),
|
|
312
|
-
|
|
317
|
+
tracks() && h(tracks().Live, { sessionId, viewport, setViewport }),
|
|
318
|
+
mode === "agent" ? h(AgentView, { visible }) : h(FrameView, { viewport })
|
|
313
319
|
)
|
|
314
320
|
}
|
|
315
321
|
|
|
@@ -317,8 +323,8 @@ window.__ModuleLoader__.load({
|
|
|
317
323
|
id: PLUGIN,
|
|
318
324
|
kind: KIND,
|
|
319
325
|
priority: "extension",
|
|
320
|
-
title: () => "Preview",
|
|
321
|
-
guide: [{ id: "preview", order
|
|
326
|
+
title: () => tracks()?.title[KIND] ?? "Preview",
|
|
327
|
+
guide: [{ id: "preview", get order() { return tracks()?.order[KIND] ?? 7 }, title: () => tracks()?.title[KIND] ?? "Preview", description: () => "An app running on this computer (localhost)", icon: TabIcon }],
|
|
322
328
|
}
|
|
323
329
|
|
|
324
330
|
const inject = ["slots", "sidebarRightTabs"]
|
|
@@ -16,6 +16,8 @@ window.__ModuleLoader__.load({
|
|
|
16
16
|
const CHECK_API = "api/kriya.progress.check"
|
|
17
17
|
const REFRESH_MS = 3000
|
|
18
18
|
const MAX_ATTEMPTS = 4
|
|
19
|
+
// Harness 2.0 W18: with --runstrip, plugins/runstrip names the four tracks and adds each one's section; absent, nothing changes
|
|
20
|
+
const tracks = () => globalThis.__kriyaTracks
|
|
19
21
|
|
|
20
22
|
const CSS = `
|
|
21
23
|
.kh-pg { height: 100%; overflow: auto; color: var(--dsw-alias-label-primary); font-size: 13px; padding-bottom: 16px; }
|
|
@@ -225,7 +227,7 @@ window.__ModuleLoader__.load({
|
|
|
225
227
|
h(
|
|
226
228
|
"section",
|
|
227
229
|
{ className: "kh-pg-sec", "aria-label": "Verdict" },
|
|
228
|
-
h("h3", { className: "kh-pg-h" }, "Progress", refresh),
|
|
230
|
+
h("h3", { className: "kh-pg-h" }, tracks()?.title[KIND] ?? "Progress", refresh),
|
|
229
231
|
h(Flow, { data }),
|
|
230
232
|
h(Verdict, { v: data.verdict }),
|
|
231
233
|
data.plan && h("p", { className: "kh-pg-goal" }, data.plan.goal),
|
|
@@ -262,7 +264,8 @@ window.__ModuleLoader__.load({
|
|
|
262
264
|
{ className: "kh-pg-sec", "aria-label": "Check runs" },
|
|
263
265
|
h("h3", { className: "kh-pg-h" }, `Check runs${data.runs.length ? ` · ${data.runs.length}` : ""}`),
|
|
264
266
|
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
|
-
)
|
|
267
|
+
),
|
|
268
|
+
tracks() && h(tracks().Proof, { sessionId })
|
|
266
269
|
)
|
|
267
270
|
}
|
|
268
271
|
|
|
@@ -270,8 +273,8 @@ window.__ModuleLoader__.load({
|
|
|
270
273
|
id: PLUGIN,
|
|
271
274
|
kind: KIND,
|
|
272
275
|
priority: "extension",
|
|
273
|
-
title: () => "Progress",
|
|
274
|
-
guide: [{ id: "progress", order
|
|
276
|
+
title: () => tracks()?.title[KIND] ?? "Progress",
|
|
277
|
+
guide: [{ id: "progress", get order() { return tracks()?.order[KIND] ?? 6 }, title: () => tracks()?.title[KIND] ?? "Progress", description: () => "Goal, plan, each step's check and the verdict", icon: TabIcon }],
|
|
275
278
|
}
|
|
276
279
|
|
|
277
280
|
const inject = ["slots", "sidebarRightTabs"]
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { defineTool } from "@deepseek-ai/dsh-tools"
|
|
2
|
+
|
|
3
|
+
import { sessionBase } from "../../src/checkpoints.js"
|
|
4
|
+
import { projectRoot } from "../../src/skill-switches.js"
|
|
5
|
+
import { makeReceipt } from "../../src/receipts.js"
|
|
6
|
+
import { createRepo, FOREIGN, redact, RepoError, runner } from "./repo.js"
|
|
7
|
+
|
|
8
|
+
// Harness 2.0 W16, repository tools (Kriya-Tavi docs/kriya-harness/upgrade_2.0/
|
|
9
|
+
// GROUNDING_AND_CONNECTORS.md §2, WD-19). Reads run freely; branch, commit,
|
|
10
|
+
// push and the draft pull request run only after the person approves the exact
|
|
11
|
+
// action through DeepSeek Harness's own approval, which asks in Ask mode and
|
|
12
|
+
// refuses in Auto, Read only and Full access (approval `never`). Not tools, by
|
|
13
|
+
// design: merge, close, delete a branch, force push, comment, release, tag.
|
|
14
|
+
// After a draft pull request, its checks are polled by code (no model, no
|
|
15
|
+
// spend); a failing check is offered to the head as a step to propose. Off
|
|
16
|
+
// unless kriya was started with --repo-tools (KRIYA_REPO_TOOLS=on).
|
|
17
|
+
|
|
18
|
+
export const name = "kriya-repo"
|
|
19
|
+
export const inject = ["tools", "workingDirectory", "systemPrompt"]
|
|
20
|
+
|
|
21
|
+
const OBJECT = { schema: { type: "object", additionalProperties: true, properties: {} } }
|
|
22
|
+
const text = (v) => [{ type: "text", text: v.text ?? JSON.stringify(v) }]
|
|
23
|
+
const DECLINED = "The person didn't approve it (in Auto, Read only or Full access mode Kriya can't ask, so it refuses: use Ask mode)."
|
|
24
|
+
|
|
25
|
+
export const POLL_MS = 30_000
|
|
26
|
+
export const POLL_LIMIT_MS = 20 * 60_000
|
|
27
|
+
const FAILED = new Set(["FAILURE", "ERROR", "CANCELLED", "TIMED_OUT", "ACTION_REQUIRED", "STARTUP_FAILURE"])
|
|
28
|
+
const DONE = new Set([...FAILED, "SUCCESS", "SKIPPED", "NEUTRAL"])
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The CI loop (§2): `checks()` every `every` ms until every check has
|
|
32
|
+
* finished or `limit` passes; each failing check once, with its failing log
|
|
33
|
+
* lines, to `onFail`. Code only.
|
|
34
|
+
*/
|
|
35
|
+
export function ciPoller({ checks, logs, onFail, onDone = () => {}, every = POLL_MS, limit = POLL_LIMIT_MS, now = Date.now, setTimer = setTimeout }) {
|
|
36
|
+
const started = now()
|
|
37
|
+
const told = new Set()
|
|
38
|
+
let stopped = false
|
|
39
|
+
let timer
|
|
40
|
+
const tick = async () => {
|
|
41
|
+
if (stopped) return
|
|
42
|
+
let list = []
|
|
43
|
+
try {
|
|
44
|
+
list = (await checks()).checks ?? []
|
|
45
|
+
} catch {
|
|
46
|
+
// Unreachable for now: try again next time
|
|
47
|
+
}
|
|
48
|
+
for (const c of list.filter((c) => FAILED.has(String(c.state).toUpperCase()) && !told.has(c.name))) {
|
|
49
|
+
told.add(c.name)
|
|
50
|
+
const id = /\/runs\/(\d+)/.exec(c.link ?? "")?.[1]
|
|
51
|
+
const excerpt = id ? await logs(id).then((l) => l.text, () => "") : ""
|
|
52
|
+
onFail({ name: String(c.name).slice(0, 120), link: c.link, excerpt: excerpt.slice(0, 4000) })
|
|
53
|
+
}
|
|
54
|
+
const finished = list.length > 0 && list.every((c) => DONE.has(String(c.state).toUpperCase()))
|
|
55
|
+
if (finished || now() - started >= limit) {
|
|
56
|
+
stopped = true
|
|
57
|
+
onDone({ finished, checks: list })
|
|
58
|
+
return
|
|
59
|
+
}
|
|
60
|
+
timer = setTimer(tick, every)
|
|
61
|
+
timer?.unref?.()
|
|
62
|
+
}
|
|
63
|
+
timer = setTimer(tick, 0)
|
|
64
|
+
timer?.unref?.()
|
|
65
|
+
return { stop: () => ((stopped = true), clearTimeout(timer)) }
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** The CI section's text: failing checks the head should offer the person as a step. */
|
|
69
|
+
export function ciText(failures) {
|
|
70
|
+
if (!failures.length) return ""
|
|
71
|
+
return [
|
|
72
|
+
"CI on your draft pull request reported failures (polled by Kriya, reported by GitHub). For each, ask the person whether to add a plan step named exactly as below; plan it only if they say yes:",
|
|
73
|
+
...failures.map((f) => `- "Fix CI: ${f.name}"${f.excerpt ? `\n${f.excerpt}` : ""}`),
|
|
74
|
+
].join("\n")
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* @param {{ cwd: (exec: any) => Promise<string>, approve: (exec: any, reason: string) => Promise<boolean>, readOnly: (exec: any) => boolean, run?: any, started?: number, ci?: (root: string, repo: any) => void }} host
|
|
79
|
+
*/
|
|
80
|
+
export function repoTools(host) {
|
|
81
|
+
const repoOf = async (exec) => {
|
|
82
|
+
if (!exec.agent) throw new RepoError("This tool needs a session.")
|
|
83
|
+
const root = projectRoot(await host.cwd(exec))
|
|
84
|
+
return { root, repo: createRepo({ root, run: host.run ?? runner() }) }
|
|
85
|
+
}
|
|
86
|
+
// The files this session changed: against its first checkpoint (its builders' too), else nothing
|
|
87
|
+
const sessionChanged = (root, exec, run) => async () => {
|
|
88
|
+
const tree = await sessionBase(root, String(exec.agent.id), host.started).catch(() => undefined)
|
|
89
|
+
if (!tree) return []
|
|
90
|
+
const changed = (await run("git", ["diff", "--name-only", "-z", tree], root)).stdout.split("\0").filter(Boolean)
|
|
91
|
+
const untracked = (await run("git", ["ls-files", "--others", "--exclude-standard", "-z"], root)).stdout.split("\0").filter(Boolean)
|
|
92
|
+
const fresh = []
|
|
93
|
+
for (const f of untracked) if ((await run("git", ["cat-file", "-e", `${tree}:${f}`], root)).code !== 0) fresh.push(f)
|
|
94
|
+
return [...new Set([...changed, ...fresh])]
|
|
95
|
+
}
|
|
96
|
+
const read = (name, description, parameters, fn, title) =>
|
|
97
|
+
defineTool({
|
|
98
|
+
name,
|
|
99
|
+
description,
|
|
100
|
+
parameters,
|
|
101
|
+
output: { ...OBJECT, render: (_a, v) => text(v) },
|
|
102
|
+
execute: async (args, exec) => fn((await repoOf(exec)).repo, args ?? {}),
|
|
103
|
+
presentCall: (args) => ({ card: "generic", title, kind: "read", rawInput: JSON.stringify(args ?? {}).slice(0, 120) }),
|
|
104
|
+
})
|
|
105
|
+
const NUMBER = { number: { type: "number", description: "The pull request or issue number; the current branch's pull request when left out." } }
|
|
106
|
+
return [
|
|
107
|
+
read("repo_status", "The repository's branch, changed paths, remotes (host and path only) and connection state, with the next action.", {}, (r) => r.status(), "Repository status"),
|
|
108
|
+
read(
|
|
109
|
+
"repo_diff",
|
|
110
|
+
"The diff of the working tree (or the staged changes), at most 60 KB, else the list of files.",
|
|
111
|
+
{ staged: { type: "boolean", description: "The staged changes instead." }, paths: { type: "array", items: { type: "string" }, description: "Only these paths." } },
|
|
112
|
+
(r, a) => r.diff(a),
|
|
113
|
+
"Diff"
|
|
114
|
+
),
|
|
115
|
+
read("repo_log", "The latest commits, one line each (at most 50).", { n: { type: "number", description: "How many, 1 to 50 (default 20)." } }, (r, a) => r.log(a), "Commits"),
|
|
116
|
+
defineTool({
|
|
117
|
+
name: "repo_branch",
|
|
118
|
+
description: "Make and switch to a new branch kriya/<name>. The person approves it; refused with uncommitted changes.",
|
|
119
|
+
parameters: { name: { type: "string", required: true, description: "kriya/<name> or just <name>: 3 to 50 lower-case letters, digits or hyphens." } },
|
|
120
|
+
output: { ...OBJECT, render: (_a, v) => [{ type: "text", text: `On ${v.branch}.` }] },
|
|
121
|
+
async execute(args, exec) {
|
|
122
|
+
const { repo } = await repoOf(exec)
|
|
123
|
+
if (host.readOnly(exec)) throw new RepoError("Read only mode makes no branch.")
|
|
124
|
+
const plan = await repo.planBranch(args?.name)
|
|
125
|
+
if (!(await host.approve(exec, `Make branch ${plan.branch} from ${plan.from} and switch to it`))) throw new RepoError(DECLINED)
|
|
126
|
+
return repo.branch(plan.branch)
|
|
127
|
+
},
|
|
128
|
+
presentCall: (args) => ({ card: "generic", title: "Make a branch", kind: "execute", rawInput: String(args?.name ?? "") }),
|
|
129
|
+
}),
|
|
130
|
+
defineTool({
|
|
131
|
+
name: "repo_commit",
|
|
132
|
+
description: "Commit files this session changed, with a Conventional Commit message (subject at most 72 characters). The person approves it. Never .env files.",
|
|
133
|
+
parameters: {
|
|
134
|
+
paths: { type: "array", required: true, items: { type: "string" }, description: "The files to commit, relative to the repository." },
|
|
135
|
+
message: { type: "string", required: true, description: 'e.g. "fix(auth): refuse expired sessions", then an optional body.' },
|
|
136
|
+
},
|
|
137
|
+
output: { ...OBJECT, render: (_a, v) => [{ type: "text", text: `Committed ${v.commit}.` }] },
|
|
138
|
+
async execute(args, exec) {
|
|
139
|
+
const { root, repo } = await repoOf(exec)
|
|
140
|
+
if (host.readOnly(exec)) throw new RepoError("Read only mode commits nothing.")
|
|
141
|
+
const plan = await repo.planCommit(args ?? {}, sessionChanged(root, exec, host.run ?? runner()))
|
|
142
|
+
if (!(await host.approve(exec, `Commit on ${plan.branch}: "${plan.message.split("\n")[0]}" with ${plan.paths.join(", ")}`))) throw new RepoError(DECLINED)
|
|
143
|
+
return repo.commit(plan)
|
|
144
|
+
},
|
|
145
|
+
presentCall: (args) => ({ card: "generic", title: "Commit", kind: "execute", rawInput: String(args?.message ?? "").split("\n")[0] }),
|
|
146
|
+
}),
|
|
147
|
+
defineTool({
|
|
148
|
+
name: "repo_push",
|
|
149
|
+
description: "Push the current kriya/ branch to origin. G-SECRETS checks every outgoing commit first; the person approves the branch and its commits. Never the default branch, never forced.",
|
|
150
|
+
parameters: {},
|
|
151
|
+
output: { ...OBJECT, render: (_a, v) => [{ type: "text", text: `Pushed ${v.pushed}.` }] },
|
|
152
|
+
async execute(_args, exec) {
|
|
153
|
+
const { repo } = await repoOf(exec)
|
|
154
|
+
const plan = await repo.planPush()
|
|
155
|
+
if (!(await host.approve(exec, `Push ${plan.branch} to origin with ${plan.commits.length} commit(s):\n${plan.commits.join("\n")}`))) throw new RepoError(DECLINED)
|
|
156
|
+
return repo.push(plan.branch)
|
|
157
|
+
},
|
|
158
|
+
presentCall: () => ({ card: "generic", title: "Push", kind: "execute", rawInput: "" }),
|
|
159
|
+
}),
|
|
160
|
+
defineTool({
|
|
161
|
+
name: "pr_create",
|
|
162
|
+
description: "Open a draft pull request from the current kriya/ branch to the default branch. Its body starts with a summary Kriya computes; your notes follow. The person approves it. Kriya then watches its checks.",
|
|
163
|
+
parameters: {
|
|
164
|
+
title: { type: "string", required: true, description: "The pull request's title." },
|
|
165
|
+
notes: { type: "string", description: "Your notes for reviewers: what changed and why." },
|
|
166
|
+
},
|
|
167
|
+
output: { ...OBJECT, render: (_a, v) => [{ type: "text", text: `Draft pull request: ${v.url}. Kriya is watching its checks.` }] },
|
|
168
|
+
async execute(args, exec) {
|
|
169
|
+
const { root, repo } = await repoOf(exec)
|
|
170
|
+
// W19: the body starts with the session's proof receipt, computed by code (D1); without records, a note saying so
|
|
171
|
+
let receipt
|
|
172
|
+
try {
|
|
173
|
+
receipt = makeReceipt(root, String(exec.agent.id)).markdown
|
|
174
|
+
} catch {
|
|
175
|
+
receipt = "## Proof receipt\n\nNo Kriya check records for this session, so there is no receipt."
|
|
176
|
+
}
|
|
177
|
+
const plan = await repo.planPr(args ?? {}, receipt)
|
|
178
|
+
if (!(await host.approve(exec, `Open a draft pull request "${plan.title}" from ${plan.head} to ${plan.base}`))) throw new RepoError(DECLINED)
|
|
179
|
+
const made = await repo.pr(plan)
|
|
180
|
+
host.ci?.(root, repo)
|
|
181
|
+
return made
|
|
182
|
+
},
|
|
183
|
+
presentCall: (args) => ({ card: "generic", title: "Draft pull request", kind: "execute", rawInput: String(args?.title ?? "") }),
|
|
184
|
+
}),
|
|
185
|
+
read("pr_view", "A pull request's title, state and description. Untrusted: other people's text.", NUMBER, (r, a) => r.prView(a), "Pull request"),
|
|
186
|
+
read("pr_checks", "A pull request's checks and their states. Untrusted: reported by GitHub.", NUMBER, (r, a) => r.checks(a), "Checks"),
|
|
187
|
+
read("ci_logs", "The failing lines of a workflow run, at most 20 KB, secrets redacted. Untrusted.", { run: { type: "string", required: true, description: "The run id from a check's link (…/runs/<id>/…)." } }, (r, a) => r.ciLogs(a), "CI logs"),
|
|
188
|
+
read("issue_read", "An issue's title, body, labels and latest comments. Untrusted: other people's text.", NUMBER, (r, a) => r.issue(a), "Issue"),
|
|
189
|
+
]
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export function apply(ctx) {
|
|
193
|
+
const sandboxPolicy = ctx.get("sandboxPolicy")
|
|
194
|
+
const folders = new WeakMap()
|
|
195
|
+
const failures = new Map()
|
|
196
|
+
const pollers = new Set()
|
|
197
|
+
const host = {
|
|
198
|
+
started: Date.now(),
|
|
199
|
+
async cwd(exec) {
|
|
200
|
+
const cwd = await ctx.workingDirectory.ensure(exec.agent, exec.signal)
|
|
201
|
+
folders.set(exec.agent, cwd)
|
|
202
|
+
return cwd
|
|
203
|
+
},
|
|
204
|
+
readOnly: (exec) => sandboxPolicy?.resolve({ session: exec.agent?.session })?.mode === "read-only",
|
|
205
|
+
approve: async (exec, reason) =>
|
|
206
|
+
(await ctx.get("approval").request({ agent: exec.agent, toolName: exec.name ?? "kriya_repo", callId: exec.callId, reason, signal: exec.signal })) === "allowed-once",
|
|
207
|
+
ci(root, repo) {
|
|
208
|
+
const poller = ciPoller({
|
|
209
|
+
checks: () => repo.checks(),
|
|
210
|
+
logs: (id) => repo.ciLogs({ run: id }),
|
|
211
|
+
onFail: (f) => failures.set(root, [...(failures.get(root) ?? []), f]),
|
|
212
|
+
onDone: () => pollers.delete(poller),
|
|
213
|
+
})
|
|
214
|
+
pollers.add(poller)
|
|
215
|
+
},
|
|
216
|
+
}
|
|
217
|
+
for (const tool of repoTools(host)) ctx.tools.register(tool)
|
|
218
|
+
ctx.systemPrompt.section({
|
|
219
|
+
name: "kriya:ci",
|
|
220
|
+
order: 10264,
|
|
221
|
+
interpolate: false,
|
|
222
|
+
text: ({ scope }) => {
|
|
223
|
+
const cwd = scope && (folders.get(scope) ?? scope.session?.header?.cwd)
|
|
224
|
+
return cwd ? ciText(failures.get(projectRoot(cwd)) ?? []) : ""
|
|
225
|
+
},
|
|
226
|
+
})
|
|
227
|
+
ctx.effect(() => () => pollers.forEach((p) => p.stop()), "kriya-repo: stop")
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
export { FOREIGN, redact }
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kriya-ai/harness-repo",
|
|
3
|
+
"description": "Typed git and gh tools through the person's own login: reads freely, branch, commit, push and draft pull requests only with their approval",
|
|
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
|
+
}
|