@kriya-ai/harness 0.2.4 → 2.0.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.
- 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 +49 -0
- package/contract/SOURCE.md +3 -3
- package/contract/contract.json +504 -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 +376 -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 +426 -0
- package/plugins/runstrip/index.js +301 -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 +82 -5
- package/src/edit/core/layout.js +46 -1
- package/src/edit/core/ops.js +175 -3
- package/src/edit/core/plan.js +95 -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/transitions.js +17 -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 +137 -0
- package/src/edit/director/custom-motion.js +88 -0
- package/src/edit/director/graphics.js +186 -0
- package/src/edit/director/intent.js +125 -0
- package/src/edit/director/mentions.js +52 -0
- package/src/edit/director/plan.js +89 -12
- package/src/edit/director/revise.js +172 -7
- 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 +439 -0
- package/src/edit/engine/index.js +14 -5
- package/src/edit/engine/motion.js +153 -14
- 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 +76 -8
- package/src/edit/gates/picture.js +6 -3
- package/src/edit/gates/reference.js +115 -0
- package/src/edit/gates/tile.js +96 -0
- package/src/edit/host/client.js +4 -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 +17 -7
- package/src/edit/host/paths.js +34 -3
- package/src/edit/host/preview.js +108 -0
- package/src/edit/host/projects.js +494 -29
- package/src/edit/host/server.js +263 -19
- package/src/edit/host/tavi.js +77 -0
- package/src/edit/loop/make.js +44 -3
- package/src/edit/recipes/assembly.js +352 -0
- package/src/edit/recipes/graphic-clips.js +59 -0
- package/src/edit/recipes/openings.js +36 -0
- package/src/edit/recipes/reel.js +138 -17
- 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 -3
- 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 +407 -0
- package/src/gates/ui.js +111 -0
- package/src/launch.js +15 -3
- package/src/loop.js +199 -7
- package/src/mcp.js +126 -0
- package/src/milestones.js +188 -0
- package/src/modes.js +32 -0
- package/src/orchestra.js +43 -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 +452 -3
- package/studio/dist/studio.js +3 -3
package/src/verify.js
CHANGED
|
@@ -220,15 +220,22 @@ const git = (cwd, args, input, encoding = "utf8") =>
|
|
|
220
220
|
* @returns {Promise<{ fingerprint: string, changed: string[] } | undefined>}
|
|
221
221
|
* changed: paths that differ from HEAD (staged, unstaged, untracked)
|
|
222
222
|
*/
|
|
223
|
-
export async function workTree(cwd) {
|
|
223
|
+
export async function workTree(cwd, base = "HEAD") {
|
|
224
224
|
const status = await git(cwd, ["status", "--porcelain=v1", "-z", "--untracked-files=all", "--no-renames"])
|
|
225
225
|
if (status === null) return undefined
|
|
226
226
|
const head = ((await git(cwd, ["rev-parse", "--verify", "-q", "HEAD"])) ?? "no commit").trim()
|
|
227
227
|
const root = ((await git(cwd, ["rev-parse", "--show-toplevel"])) ?? cwd).trim()
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
228
|
+
// Harness 2.0 W16: with a plan's base (repository tools on), files committed since it count as changed too
|
|
229
|
+
const committed = base === "HEAD" ? "" : ((await git(root, ["diff", "--name-only", "-z", "--no-renames", base, "HEAD"])) ?? "")
|
|
230
|
+
const changed = [
|
|
231
|
+
...new Set([
|
|
232
|
+
...status
|
|
233
|
+
.split("\0")
|
|
234
|
+
.filter(Boolean)
|
|
235
|
+
.map((entry) => entry.slice(3)),
|
|
236
|
+
...committed.split("\0").filter(Boolean),
|
|
237
|
+
]),
|
|
238
|
+
]
|
|
232
239
|
const present = changed.filter((rel) => existsSync(join(root, rel)))
|
|
233
240
|
const hashes = present.length ? await git(root, ["hash-object", "--stdin-paths"], present.join("\n") + "\n") : ""
|
|
234
241
|
const fingerprint = createHash("sha256").update(`${head}\0${status}\0${hashes ?? "unreadable"}`).digest("hex").slice(0, 16)
|
|
@@ -258,14 +265,14 @@ export const checkFiles = (paths) => paths.filter((p) => CHECK_FILE.some((re) =>
|
|
|
258
265
|
* session's first checkpoint.
|
|
259
266
|
* @returns {Promise<undefined | Awaited<ReturnType<typeof run>>>} undefined outside a repository or before a first commit
|
|
260
267
|
*/
|
|
261
|
-
export async function onOriginals(cwd, paths, run) {
|
|
268
|
+
export async function onOriginals(cwd, paths, run, base = "HEAD") {
|
|
262
269
|
const root = (await git(cwd, ["rev-parse", "--show-toplevel"]))?.trim()
|
|
263
|
-
if (!root || (await git(root, ["rev-parse", "--verify", "-q",
|
|
270
|
+
if (!root || (await git(root, ["rev-parse", "--verify", "-q", base])) === null) return undefined
|
|
264
271
|
const saved = []
|
|
265
272
|
try {
|
|
266
273
|
for (const rel of paths) {
|
|
267
274
|
const file = join(root, rel)
|
|
268
|
-
const original = await git(root, ["show",
|
|
275
|
+
const original = await git(root, ["show", `${base}:${rel}`], undefined, "buffer")
|
|
269
276
|
const entry = { file, mine: existsSync(file) ? readFileSync(file) : null }
|
|
270
277
|
saved.push(entry)
|
|
271
278
|
if (original === null) rmSync(file, { force: true })
|
|
@@ -303,7 +310,8 @@ const matches = (pattern, rel) => (/\*+$/.test(pattern) ? rel.startsWith(pattern
|
|
|
303
310
|
async function strictBefore(cwd, plan, work, run, defensive) {
|
|
304
311
|
const root = await gitRoot(cwd)
|
|
305
312
|
if (!root || !work?.changed.length) return undefined
|
|
306
|
-
const
|
|
313
|
+
const base = baseOf(plan)
|
|
314
|
+
const head = (rel) => git(root, ["show", `${base}:${rel}`])
|
|
307
315
|
const hit = work.changed.find((rel) => plan?.invariants?.some((p) => matches(p, rel)))
|
|
308
316
|
if (hit) return refusal("invariant broken", "the plan's invariants", `${hit} must not change in this task (the plan's invariants). Put it back and solve this another way.`)
|
|
309
317
|
const checks = new Set(checkFiles(work.changed))
|
|
@@ -321,7 +329,7 @@ async function strictBefore(cwd, plan, work, run, defensive) {
|
|
|
321
329
|
let neighbours = []
|
|
322
330
|
if (defensive) {
|
|
323
331
|
const graph = importGraph(root)
|
|
324
|
-
const diffs = await diffsOf(root, work.changed)
|
|
332
|
+
const diffs = await diffsOf(root, work.changed, base)
|
|
325
333
|
const found = sentinel(diffs, { tenancy: graph.files.some((rel) => /\bwithUser\(/.test(graph.text(rel))) })
|
|
326
334
|
if (found.length) return refusal("invariant violated", "the invariant sentinel", findings(found.map((f) => `${f.file}:${f.line} [${f.rule}] ${f.why}`)))
|
|
327
335
|
// The neighbours' suites too: the work isn't done if it passes here and breaks there
|
|
@@ -338,8 +346,15 @@ async function strictBefore(cwd, plan, work, run, defensive) {
|
|
|
338
346
|
return undefined
|
|
339
347
|
}
|
|
340
348
|
|
|
341
|
-
const diffsOf = async (root, changed) =>
|
|
342
|
-
Promise.all(changed.map(async (rel) => ({ rel, before: await git(root, ["show",
|
|
349
|
+
const diffsOf = async (root, changed, base = "HEAD") =>
|
|
350
|
+
Promise.all(changed.map(async (rel) => ({ rel, before: await git(root, ["show", `${base}:${rel}`]), after: fileNow(join(root, rel)) })))
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* Harness 2.0 W16 (repository tools): "the code before this session" is the
|
|
354
|
+
* commit kriya_plan recorded, so a commit made in the session can't make
|
|
355
|
+
* weakened tests the new originals. Without one, HEAD, exactly as before.
|
|
356
|
+
*/
|
|
357
|
+
export const baseOf = (plan) => (typeof plan?.base === "string" && /^[0-9a-f]{40}$/.test(plan.base) ? plan.base : "HEAD")
|
|
343
358
|
|
|
344
359
|
const findings = (lines) => `${lines.slice(0, 12).join("\n")}${lines.length > 12 ? `\n… ${lines.length - 12} more` : ""}`
|
|
345
360
|
|
|
@@ -351,7 +366,7 @@ const findings = (lines) => `${lines.slice(0, 12).join("\n")}${lines.length > 12
|
|
|
351
366
|
async function defensiveAfter(cwd, plan, work) {
|
|
352
367
|
const root = await gitRoot(cwd)
|
|
353
368
|
if (!root || !work?.changed.length) return undefined
|
|
354
|
-
const diffs = await diffsOf(root, work.changed)
|
|
369
|
+
const diffs = await diffsOf(root, work.changed, baseOf(plan))
|
|
355
370
|
const hazards = reviewDiff(importGraph(root), diffs)
|
|
356
371
|
if (hazards.length) return refusal("regression hazard", "the diff review", findings(hazards.map((h) => `${h.file}${h.line ? `:${h.line}` : ""} [${h.hazard}] ${h.why}`)))
|
|
357
372
|
const surface = newSurface(diffs)
|
|
@@ -377,7 +392,7 @@ async function strictAfter(cwd, sessionId, plan, work, check, run, defensive, fi
|
|
|
377
392
|
if (!code.length) return undefined
|
|
378
393
|
// The red phase, proved: on the code as it was, the check (with any new test) must fail
|
|
379
394
|
const kept = await checkpoint(cwd, sessionId, "before the check on the old code").catch(() => undefined)
|
|
380
|
-
const old = kept && (await onOriginals(cwd, code, () => run(check.command)))
|
|
395
|
+
const old = kept && (await onOriginals(cwd, code, () => run(check.command), baseOf(plan)))
|
|
381
396
|
if (old?.aborted) throw new VerifyError("The check was stopped.")
|
|
382
397
|
if (old?.exitCode === 0 && !old.timedOut)
|
|
383
398
|
return refusal("no reproduction", check.command, "The check also passes on the code before your change, so nothing proves the bug or its fix. Add a test that fails on the old code and passes on the new.")
|
|
@@ -499,7 +514,7 @@ export const stepLabel = (plan, n) => normalStep(`${n} ${plan.steps[n - 1].title
|
|
|
499
514
|
* guard (KRIYA_LOOP_GUARD=on): a failure's class and excerpt too, with its signature, and the excerpt kept in the run so a resumed step can use it
|
|
500
515
|
* strict (KRIYA_STRICT_LOOP=on): the checks of strictBefore and strictAfter around the person's check; never in Read only
|
|
501
516
|
*/
|
|
502
|
-
export async function verifyStep({ cwd, sessionId, step, run, now = () => new Date(), tree = workTree, v2, guard, strict }) {
|
|
517
|
+
export async function verifyStep({ cwd, sessionId, step, run, now = () => new Date(), tree = workTree, v2, guard, strict, gates, expect }) {
|
|
503
518
|
const label = normalStep(step)
|
|
504
519
|
const check = confirmedCheck(cwd)
|
|
505
520
|
if (!check) return { status: "not configured", step: label, suggestions: discoverChecks(cwd) }
|
|
@@ -507,9 +522,10 @@ export async function verifyStep({ cwd, sessionId, step, run, now = () => new Da
|
|
|
507
522
|
if (before?.status === "blocked") return { status: "blocked", step: label, attempts: before.attempts, command: check.command }
|
|
508
523
|
// The files this run checks, taken before the command (a check that writes
|
|
509
524
|
// files, e.g. a build, doesn't make its own pass stale)
|
|
510
|
-
const
|
|
525
|
+
const base = baseOf(readProgress(check.root, sessionId).plan)
|
|
526
|
+
const work = await (base === "HEAD" ? tree(cwd) : tree(cwd, base))
|
|
511
527
|
const started = now()
|
|
512
|
-
const hard = strict && !strict.readOnly
|
|
528
|
+
const hard = strict && !strict.readOnly && expect !== "red"
|
|
513
529
|
const plan = hard ? readProgress(check.root, sessionId).plan : undefined
|
|
514
530
|
const early = hard ? await strictBefore(cwd, plan, work, run, strict.defensive) : undefined
|
|
515
531
|
const result = early ?? (await run(check.command))
|
|
@@ -517,13 +533,33 @@ export async function verifyStep({ cwd, sessionId, step, run, now = () => new Da
|
|
|
517
533
|
const passes = (r) => r.exitCode === 0 && !r.timedOut
|
|
518
534
|
let status = passes(result) ? "pass" : "fail"
|
|
519
535
|
let touched = work && status === "pass" ? checkFiles(work.changed) : []
|
|
536
|
+
// Harness 2.0 W5, a spec-test step (ORCHESTRA §7): its tests can't pass before the code exists, so it passes
|
|
537
|
+
// only red for the right reason: the check fails now, passes with the new check files moved aside (the
|
|
538
|
+
// strict loop's red-phase proof), and the failure isn't a syntax error
|
|
539
|
+
let red
|
|
540
|
+
if (expect === "red") {
|
|
541
|
+
const tests = work ? checkFiles(work.changed) : []
|
|
542
|
+
const failing = classify(result)
|
|
543
|
+
if (passes(result)) red = refusal("not red", check.command, "The check passes with the new tests, so they test nothing the code lacks yet. Write tests for what the next steps add, named after their criteria (AC-1, AC-2, …), so they fail now.")
|
|
544
|
+
else if (failing.kind === "syntax") red = refusal("syntax", check.command, failing.excerpt)
|
|
545
|
+
else if (!tests.length) red = refusal("not red", check.command, "This step changed no test file. A spec step writes the tests, and only the tests.")
|
|
546
|
+
else {
|
|
547
|
+
const without = await onOriginals(cwd, tests, () => run(check.command), base)
|
|
548
|
+
if (without?.aborted) throw new VerifyError("The check was stopped.")
|
|
549
|
+
if (!without) red = refusal("not red", check.command, "Kriya can't set the new tests aside here (no git repository with a commit), so it can't prove they are what fails.")
|
|
550
|
+
else if (!passes(without)) red = refusal("red for another reason", check.command, `The check fails even without the new tests, so their failure proves nothing. Fix that first:\n${classify(without).excerpt}`)
|
|
551
|
+
else red = { ...result, exitCode: 0, red: true }
|
|
552
|
+
}
|
|
553
|
+
if (red.own) [status, touched] = ["fail", []]
|
|
554
|
+
else [status, touched] = ["pass", []]
|
|
555
|
+
}
|
|
520
556
|
// v2 and strict: a pass that changed tests or the check's files must hold on the originals too
|
|
521
|
-
let checked = result
|
|
557
|
+
let checked = red ?? result
|
|
522
558
|
let weakened
|
|
523
559
|
if (((v2 && !v2.readOnly) || hard) && touched.length) {
|
|
524
560
|
// The work's own files are saved first, so a crash mid-swap loses nothing (kriya undo); no save, no swap
|
|
525
561
|
const kept = await checkpoint(cwd, sessionId, "before the check on the committed tests").catch(() => undefined)
|
|
526
|
-
const originals = kept && (await onOriginals(cwd, touched, () => run(check.command)))
|
|
562
|
+
const originals = kept && (await onOriginals(cwd, touched, () => run(check.command), base))
|
|
527
563
|
if (originals?.aborted) throw new VerifyError("The check was stopped.")
|
|
528
564
|
if (originals && !passes(originals)) [status, checked, weakened, touched] = ["fail", originals, touched, []]
|
|
529
565
|
}
|
|
@@ -533,9 +569,15 @@ export async function verifyStep({ cwd, sessionId, step, run, now = () => new Da
|
|
|
533
569
|
const late = await strictAfter(cwd, sessionId, plan, work, check, run, strict.defensive, !open.length)
|
|
534
570
|
if (late) [status, checked, touched] = ["fail", late, []]
|
|
535
571
|
}
|
|
572
|
+
// Harness 2.0 gates (--gates): after a pass, the step's gates; the first failure fails the run
|
|
573
|
+
let gated
|
|
574
|
+
if (gates && status === "pass") {
|
|
575
|
+
gated = await gates({ root: check.root, changed: work?.changed ?? [], output: checked.output ?? "", rerun: () => run(check.command), command: (c) => run(c), label, recorded: readProgress(check.root, sessionId).contracts ?? {} })
|
|
576
|
+
if (gated.failure) [status, checked, touched] = ["fail", refusal(gated.failure.kind, `gate ${gated.failure.id}`, gated.failure.excerpt), []]
|
|
577
|
+
}
|
|
536
578
|
// A refusal's words are its whole output; a rung's error is cut like any other
|
|
537
579
|
const classified = () => (checked.own ? { kind: checked.kind, excerpt: checked.output } : weakened ? { kind: "tests changed", excerpt: classify(checked).excerpt } : { ...classify(checked), ...(checked.kind && { kind: checked.kind }) })
|
|
538
|
-
const failure = (v2 || guard) && status === "fail" ? classified() : undefined
|
|
580
|
+
const failure = (v2 || guard || gated?.failure || red?.own) && status === "fail" ? classified() : undefined
|
|
539
581
|
const sig = guard && failure ? createHash("sha256").update(signature(check.command, failure)).digest("hex").slice(0, 16) : undefined
|
|
540
582
|
const progress = recordRun(check.root, sessionId, {
|
|
541
583
|
at: started.toISOString(),
|
|
@@ -551,7 +593,11 @@ export async function verifyStep({ cwd, sessionId, step, run, now = () => new Da
|
|
|
551
593
|
...(weakened && { weakened }),
|
|
552
594
|
...(sig && { sig, excerpt: failure.excerpt.slice(0, KEPT_OUTPUT) }),
|
|
553
595
|
...(checked.level && { level: checked.level }),
|
|
596
|
+
...(checked.red && { red: true }),
|
|
597
|
+
...(gated && { gates: gated.results.map(({ id, status: s, reason, note }) => ({ id, status: s, ...(reason && { reason }), ...(note && { note: String(note).slice(0, 600) }) })) }),
|
|
554
598
|
})
|
|
599
|
+
// The owning role's contracts, hashed once its step passes (the contract bus's ledger)
|
|
600
|
+
if (gated && status === "pass" && Object.keys(gated.contracts).length) writeProgress(check.root, sessionId, { ...progress, contracts: { ...(progress.contracts ?? {}), ...gated.contracts } })
|
|
555
601
|
const proposed = (v2 || strict) && failure && noteFailure(check.root, check.command, failure, now)
|
|
556
602
|
const after = verdict(progress)
|
|
557
603
|
const mine = after.steps.find((s) => s.step === label)
|
|
@@ -570,6 +616,7 @@ export async function verifyStep({ cwd, sessionId, step, run, now = () => new Da
|
|
|
570
616
|
...(weakened && { weakened }),
|
|
571
617
|
...(proposed && { proposed: proposed.text }),
|
|
572
618
|
...(sig && { signature: sig }),
|
|
619
|
+
...(gated && { gates: gated.results }),
|
|
573
620
|
}
|
|
574
621
|
}
|
|
575
622
|
|
|
Binary file
|
|
Binary file
|
|
Binary file
|