@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
package/bin/kriya.js ADDED
@@ -0,0 +1,577 @@
1
+ #!/usr/bin/env node
2
+ import { existsSync, readFileSync, rmSync, writeFileSync } from "node:fs"
3
+ import { join } from "node:path"
4
+
5
+ import { handoff, HandoffError, pull } from "../plugins/kriya-handoff/index.js"
6
+ import { KriyaError, me, revokeDevice } from "../src/api.js"
7
+ import { doctor, nodeOk } from "../src/doctor.js"
8
+ import { runDsh } from "../src/launch.js"
9
+ import { daemonPidFile, runDaemon, serviceDefinition } from "../src/daemon.js"
10
+ import { serve, servedFolder, ServeError } from "../src/world.js"
11
+ import { HEAVY_CATALOG, linkSkills, SKILL_ROOTS, skillsDir, SkillsError, unlinkSkill, visibleSkills } from "../src/local-skills.js"
12
+ import { CheckpointError, listCheckpoints, trackedRoot, undo } from "../src/checkpoints.js"
13
+ import { clearCheck, confirmCheck, confirmedCheck, discoverChecks, MAX_ATTEMPTS, sessionReport, VerifyError } from "../src/verify.js"
14
+ import { projectRoot, setSkillSwitch, SwitchError } from "../src/skill-switches.js"
15
+ import { confirmRule, dismissRule, forgetRule, listRules, RulesError } from "../src/rules.js"
16
+ import { login } from "../src/login.js"
17
+ import { APP_MODES, FULL_ACCESS_WARNING, MODES, ModeError, parseMode, planJob, switchEnv } from "../src/modes.js"
18
+ import { CLIENT_VERSION, DSH_VERSION, kriyaHome } from "../src/paths.js"
19
+ import { deleteDevice, ensureHome, kriyaUrl, readDevice } from "../src/store.js"
20
+
21
+ // `kriya`: the Kriya Harness command (DSH_DISTRIBUTION §2). It signs in,
22
+ // picks a Kriya profile and hands over to DSH's own launcher.
23
+
24
+ const HELP = `Kriya Harness (beta)
25
+
26
+ Usage:
27
+ kriya login [--url <your Kriya address>] [--no-browser]
28
+ kriya [--mode <mode>] [--no-loop] [--loop-v2] [--loop-guard] [--strict-loop] [--defensive] [--recon] [--jit-tools] [--no-browser-tools] [--router] [--no-budget] [--anchor] [--no-open] [--port <n>]
29
+ open the agent in your browser (local, 127.0.0.1)
30
+ kriya run [--mode <mode>] [--no-loop] [--loop-v2] [--loop-guard] [--strict-loop] [--defensive] [--recon] [--jit-tools] [--no-browser-tools] [--router] [--no-budget] [--anchor] "<job>"
31
+ run one job and print the answer (--json for events)
32
+ kriya acp the agent for editors: an ACP server on stdin/stdout
33
+ kriya usage [--json] this month's Kriya Harness spend and limit
34
+ (your editor starts it; kriya acp --help for details)
35
+ kriya handoff ["<note>"]
36
+ hand this repository's uncommitted work to your Kriya
37
+ agent in a cloud workspace (HEAD must be on GitHub)
38
+ kriya pull [<workspace id>]
39
+ bring a workspace's changes back on a new branch
40
+ kriya/pull-<id> (default: your last handoff)
41
+ kriya daemon [--folder <path>]… [--allow-full-access] [--allow-serve] [--allow-edit]
42
+ let Kriya (/harness, your phone) run tasks, health checks,
43
+ rule decisions, handoff and pull on this computer, in this
44
+ folder and each --folder only, while it runs
45
+ kriya daemon install [same options]
46
+ keep it running in the background (launchd / systemd)
47
+ kriya daemon uninstall
48
+ kriya serve [folder] let your Kriya agents work on this machine: cloud tasks
49
+ run commands and change files in new subfolders of
50
+ <folder> (default: this folder) while it runs
51
+ kriya skills the SKILL.md skills your agent sees in this folder
52
+ kriya skills link <folder> [--only <a,b>]
53
+ add a folder of skills (superpowers, ponytail, ECC, your
54
+ own) to ~/.kriya/skills, as links
55
+ kriya skills unlink <name>
56
+ kriya skills off <name> [--everywhere]
57
+ take a skill out of the agent's list for this project
58
+ (or everywhere), so it costs no tokens; nothing is deleted
59
+ kriya skills on <name>
60
+ remove a linked skill
61
+ kriya verify this project's check and the ones it defines
62
+ kriya verify use <number> | "<command>"
63
+ confirm the check the agent runs (the Kriya loop): its exit
64
+ code alone says whether the work passes
65
+ kriya verify clear forget this project's check
66
+ kriya verify status [--session <id>] [--json]
67
+ where the newest session here stands, with each check
68
+ run as evidence; exits 0 only when verified
69
+ kriya undo put this repository's files back one step (with the loop
70
+ the agent saves a checkpoint before each change)
71
+ kriya undo --list the checkpoints, newest first
72
+ kriya undo <number> go back to one of them; what an undo replaces is kept
73
+ kriya rules rules the loop proposed from repeated failures, and yours
74
+ kriya rules confirm <number> ["<your wording>"]
75
+ let the agent see a proposed rule (only you can)
76
+ kriya rules dismiss <number> | forget <number>
77
+ kriya doctor check this machine, the sign-in and the gateway
78
+ kriya logout sign this device out
79
+ kriya --version
80
+
81
+ Modes (--mode; default ask):
82
+ ${Object.entries(MODES)
83
+ .map(([name, mode]) => ` ${name.padEnd(6)}${mode.what}`)
84
+ .join("\n")}
85
+ In the app, switch with the Permissions control or /permission, and type
86
+ /plan to plan first. plan as a --mode is for kriya run.
87
+
88
+ The Kriya loop (on; --no-loop turns it off): the agent checks its own work
89
+ with kriya_verify, which runs the check you confirmed (kriya verify use)
90
+ and reports pass, fail, or blocked after ${MAX_ATTEMPTS} failed runs, from the exit
91
+ code alone. Before each change it saves a checkpoint on Kriya's own git
92
+ ref (kriya undo); your branches, index and stash are never touched.
93
+
94
+ The turn budget (on; --no-budget turns it off): each turn is bounded by
95
+ code: at most 150 steps (KRIYA_MAX_STEPS), 60 minutes (KRIYA_TURN_MINUTES)
96
+ and 10 identical tool calls in a row (KRIYA_MAX_REPEATS). Near a limit the
97
+ agent is told to wrap up; at a limit the turn stops as "blocked" (kriya
98
+ run exits 1). Each step's builder (with the loop) is bounded more tightly:
99
+ 40 steps (KRIYA_BUILDER_STEPS), 15 minutes (KRIYA_BUILDER_MINUTES); the
100
+ check still runs on what a stopped builder left.
101
+
102
+ --loop-v2 (beta, off): plan steps name the steps they need, so one blocked
103
+ step skips only what depends on it; a failed check is classified (syntax,
104
+ type, assertion, environment, timeout) and cut to its failing lines; a
105
+ pass that changed tests must also pass with the committed tests; a worse
106
+ attempt is set aside; a failure seen twice is proposed as a rule.
107
+
108
+ --browser-tools (on where Google Chrome is installed; --no-browser-tools turns it
109
+ off): the agent gets a browser for apps on this computer
110
+ (localhost only), on your installed Google Chrome with its own profile:
111
+ open, read, screenshot, click, type, console and network, to test what it
112
+ builds. The Preview tab shows and drives the same page.
113
+
114
+ --router (beta, off): for each request, a short brief of the skills
115
+ likely to help and the tools to start with, chosen by code from its
116
+ words; it hides and adds nothing.
117
+
118
+ --anchor (beta): your own messages are kept word for word where compaction
119
+ never condenses them, so a requirement survives a summary that drops it.
120
+
121
+ Run it in a folder you can afford to change; see SAFETY.md.`
122
+
123
+ const ACP_HELP = `kriya acp: the Kriya Harness agent for editors that speak the Agent Client
124
+ Protocol (ACP v1). The editor starts it and talks over stdin/stdout; stdout
125
+ carries only protocol frames, messages go to stderr. It's the same agent as
126
+ \`kriya\`: Kriya's models, skills and memory tools, phone approvals and the
127
+ mirror, with the same permission defaults. Sign in first with kriya login.
128
+
129
+ In your editor's agent settings, use the command: kriya acp`
130
+
131
+ const NOTICE = `Kriya Harness is a beta built on DeepSeek Harness, a developer preview that
132
+ hasn't had a security audit. The agent can read and change files and run
133
+ commands on this machine, starting in the folder you open it in. Use a
134
+ folder you can afford to lose, keep backups, and read SAFETY.md.
135
+ `
136
+
137
+ const SERVE_NOTICE = `kriya serve lets your Kriya agents' cloud tasks run commands and change
138
+ files on this machine, as you, with your network: there is no sandbox. They
139
+ work only in new subfolders of the folder you serve, but a command can reach
140
+ anything you can. Serve a folder on a machine you can afford to change, and
141
+ stop with Ctrl-C when you're done.
142
+ `
143
+
144
+ const say = (line) => process.stdout.write(`${line}\n`)
145
+
146
+ function firstRunNotice() {
147
+ ensureHome()
148
+ const marker = join(kriyaHome(), ".notice-shown")
149
+ if (existsSync(marker)) return
150
+ process.stderr.write(`${NOTICE}\n`)
151
+ writeFileSync(marker, `${new Date().toISOString()}\n`)
152
+ }
153
+
154
+ // The workspace of the last handoff from this machine, for a bare `kriya pull`
155
+ const lastWorkspace = () => join(kriyaHome(), "last-workspace")
156
+
157
+ function option(args, name) {
158
+ const at = args.indexOf(name)
159
+ if (at === -1) return undefined
160
+ const value = args[at + 1]
161
+ args.splice(at, 2)
162
+ return value
163
+ }
164
+
165
+ // The loop, budget and kept-request switches (src/modes.js switchEnv)
166
+ const useLoop = (args) => switchEnv(args)
167
+
168
+ function signedIn() {
169
+ const device = readDevice()
170
+ if (!device) {
171
+ say("Run `kriya login` to connect your Kriya account.")
172
+ process.exit(1)
173
+ }
174
+ return device
175
+ }
176
+
177
+ async function main(argv) {
178
+ const [command, ...args] = argv
179
+ if (command === "--version" || command === "-v") {
180
+ say(`kriya ${CLIENT_VERSION} (Kriya Harness beta, built on DeepSeek Harness ${DSH_VERSION})`)
181
+ return 0
182
+ }
183
+ if (command === "--help" || command === "-h" || command === "help") {
184
+ say(HELP)
185
+ return 0
186
+ }
187
+ if (!nodeOk()) {
188
+ say(`Kriya Harness needs Node 24.9 or later; this is ${process.versions.node}.`)
189
+ return 1
190
+ }
191
+ firstRunNotice()
192
+
193
+ switch (command) {
194
+ case "login": {
195
+ const given = option(args, "--url") ?? process.env.KRIYA_URL ?? readDevice()?.url
196
+ if (!given) {
197
+ say("Which Kriya? Run `kriya login --url https://<your Kriya address>`.")
198
+ return 1
199
+ }
200
+ const browser = !args.includes("--no-browser")
201
+ await login(kriyaUrl(given), { browser })
202
+ return 0
203
+ }
204
+ case "logout": {
205
+ const device = readDevice()
206
+ if (!device) {
207
+ say("Not signed in.")
208
+ return 0
209
+ }
210
+ try {
211
+ await revokeDevice(device.url, device.token)
212
+ } catch (error) {
213
+ // Signed out here either way; the person can revoke it in Account → Devices
214
+ if (!(error instanceof KriyaError) || error.status !== 401)
215
+ say(`Couldn't tell Kriya (${error.message}); revoke this device in Account → Devices.`)
216
+ }
217
+ deleteDevice()
218
+ say("Signed out.")
219
+ return 0
220
+ }
221
+ case "doctor":
222
+ return (await doctor()) ? 0 : 1
223
+ // Track E: nothing under src/edit/ loads unless the switch is on
224
+ case "edit": {
225
+ useLoop(args)
226
+ if (process.env.KRIYA_EDIT !== "on") {
227
+ say("Editing is off. Set KRIYA_EDIT=on, or add --edit, to use it.")
228
+ return 1
229
+ }
230
+ const { editCommand } = await import("../src/edit/runtime/cli.js")
231
+ return editCommand(args)
232
+ }
233
+ // This month's Kriya Harness spend from Kriya's own ledger (GET /me);
234
+ // --json is one line for scripts, KriyaBench's spend meter among them
235
+ case "usage": {
236
+ const device = signedIn()
237
+ const { harness } = await me(device.url, device.token)
238
+ if (args.includes("--json")) say(JSON.stringify({ usedMicroInr: harness.usedMicroInr, capMicroInr: harness.capMicroInr, unpriced: harness.unpriced }))
239
+ else say(`This month: ₹${(harness.usedMicroInr / 1e6).toFixed(2)} of ₹${(harness.capMicroInr / 1e6).toFixed(2)}${harness.unpriced ? ` (${harness.unpriced} not priced yet)` : ""}.`)
240
+ return 0
241
+ }
242
+ case "skills": {
243
+ const [action, target] = args
244
+ if (action === "link") {
245
+ if (!target) throw new SkillsError("Which folder? kriya skills link <folder> [--only <a,b>]")
246
+ const only = option(args, "--only")?.split(",").filter(Boolean)
247
+ const { linked, kept } = linkSkills(target, only)
248
+ const left = kept.length > 10 ? `${kept.length} names` : kept.join(", ")
249
+ say(`Linked ${linked.length} skill(s) into ${skillsDir()}${kept.length ? `; already there, left alone: ${left}` : ""}.`)
250
+ } else if (action === "unlink") {
251
+ if (!target) throw new SkillsError("Which skill? kriya skills unlink <name>")
252
+ unlinkSkill(target)
253
+ say(`Unlinked ${target}.`)
254
+ } else if (action === "off" || action === "on") {
255
+ if (!target) throw new SkillsError(`Which skill? kriya skills ${action} <name>`)
256
+ const state = action === "on" ? "on" : args.includes("--everywhere") ? "off-everywhere" : "off-here"
257
+ try {
258
+ setSkillSwitch(process.cwd(), target, state)
259
+ } catch (error) {
260
+ if (error instanceof SwitchError) throw new SkillsError(error.message)
261
+ throw error
262
+ }
263
+ say(state === "on" ? `${target} is on.` : `${target} is off ${state === "off-here" ? `in ${projectRoot(process.cwd())}` : "everywhere"}.`)
264
+ } else if (action) {
265
+ say(`Unknown skills command ${action}.\n\n${HELP}`)
266
+ return 1
267
+ }
268
+ const { skills, shadowed, catalogChars, offChars, off, broken, warnings } = await visibleSkills(process.cwd())
269
+ const where = (skill) => SKILL_ROOTS[skill.source] ?? skill.source
270
+ const state = (skill) => (off.has(skill.name) ? ` (off ${off.get(skill.name) === "here" ? "in this project" : "everywhere"})` : "")
271
+ for (const skill of skills) say(` ${skill.name.padEnd(36)} ${where(skill)}${state(skill)}`)
272
+ for (const skill of shadowed) say(` ${skill.name.padEnd(36)} ${where(skill)} (hidden by the one above)`)
273
+ for (const name of broken) say(` ${name.padEnd(36)} broken link: its folder is gone (kriya skills unlink ${name})`)
274
+ for (const warning of warnings) say(` not loaded: ${warning}`)
275
+ // The agent gets the catalog once per session and resends it with every request
276
+ const offCount = skills.filter((s) => off.has(s.name)).length
277
+ say(
278
+ `${skills.length - offCount} skill(s) on, ${offCount} off; the catalog is about ${Math.round(catalogChars / 4)} tokens on every request` +
279
+ (offChars ? ` (turning skills off saves about ${Math.round(offChars / 4)}).` : ".")
280
+ )
281
+ if (catalogChars > HEAVY_CATALOG) say("That's a lot for every request: kriya skills off <name> for the ones this project doesn't need.")
282
+ say("Your Kriya agent's own skills come on top of these.")
283
+ return 0
284
+ }
285
+ case "verify": {
286
+ const [action, ...rest] = args
287
+ if (action === "use") {
288
+ const suggestions = discoverChecks(process.cwd())
289
+ const pick = rest.join(" ").trim()
290
+ const chosen = /^\d+$/.test(pick) ? suggestions[Number(pick) - 1]?.command : pick
291
+ if (/^\d+$/.test(pick) && !chosen) throw new VerifyError(`There's no check ${pick}; kriya verify lists them.`)
292
+ const { root, command } = confirmCheck(process.cwd(), chosen)
293
+ say(`Confirmed for ${root}: ${command}`)
294
+ say("With the Kriya loop (on by default), the agent's work passes only when this exits 0.")
295
+ return 0
296
+ }
297
+ if (action === "clear") {
298
+ say(clearCheck(process.cwd()) ? "Forgot this project's check; work here is \"not checked\" again." : "This project had no check.")
299
+ return 0
300
+ }
301
+ if (action === "status") {
302
+ const json = rest.includes("--json")
303
+ const report = await sessionReport(process.cwd(), option(rest, "--session"))
304
+ if (json) say(JSON.stringify(report))
305
+ else {
306
+ say(`Verdict: ${report.status}${report.stale ? " (files changed since the last pass)" : ""}${report.session ? ` (session ${report.session})` : ""}`)
307
+ for (const s of report.steps) say(` ${s.status.padEnd(7)} ${s.step} (${s.attempts} run${s.attempts === 1 ? "" : "s"})`)
308
+ for (const r of report.runs) say(` ${r.at} ${r.step}: ${r.status}, exit ${r.exitCode ?? "none"}${r.kind ? `, ${r.kind}` : ""}${r.stalled ? `, stopped: ${r.stalled}` : ""} \`${r.command}\``)
309
+ }
310
+ return report.status === "verified" ? 0 : 1
311
+ }
312
+ if (action !== undefined) {
313
+ say(`Unknown verify command ${action}.\n\n${HELP}`)
314
+ return 1
315
+ }
316
+ const check = confirmedCheck(process.cwd())
317
+ say(check ? `Check for ${check.root}: ${check.command} (confirmed ${check.confirmedAt})` : "No check confirmed for this project: with the Kriya loop, work here ends \"not checked\".")
318
+ const suggestions = discoverChecks(process.cwd())
319
+ if (suggestions.length) {
320
+ say("\nThis project defines:")
321
+ suggestions.forEach((s, i) => say(` ${i + 1}. ${s.command.padEnd(28)} ${s.source}`))
322
+ say("\nkriya verify use <number> to confirm one, or kriya verify use \"<command>\".")
323
+ } else say('This project defines no check Kriya recognises; kriya verify use "<command>" sets one.')
324
+ return 0
325
+ }
326
+ case "rules": {
327
+ const [action, n, ...words] = args
328
+ if (action === "confirm") say(`Confirmed; the loop's builders now see: ${confirmRule(process.cwd(), n, words.join(" "))}`)
329
+ else if (action === "dismiss") say(`Dismissed; it won't be proposed again: ${dismissRule(process.cwd(), n)}`)
330
+ else if (action === "forget") say(`Removed: ${forgetRule(process.cwd(), n)}`)
331
+ else if (action !== undefined) {
332
+ say(`Unknown rules command ${action}.\n\n${HELP}`)
333
+ return 1
334
+ } else {
335
+ const { proposed, confirmed } = listRules(process.cwd())
336
+ say(confirmed.length ? `Rules you confirmed for ${projectRoot(process.cwd())}:` : "No confirmed rules for this project.")
337
+ confirmed.forEach((t, i) => say(` ${i + 1}. ${t}`))
338
+ if (proposed.length) {
339
+ say("\nProposed by the loop (from failures seen twice; the agent doesn't see these):")
340
+ proposed.forEach((t, i) => say(` ${i + 1}. ${t}`))
341
+ say('\nkriya rules confirm <number> ["<your wording>"], or kriya rules dismiss <number>.')
342
+ }
343
+ }
344
+ return 0
345
+ }
346
+ case "undo": {
347
+ const [arg, ...rest] = args
348
+ if (rest.length || (arg !== undefined && arg !== "--list" && !/^\d+$/.test(arg))) {
349
+ say(`kriya undo takes --list or a number.\n\n${HELP}`)
350
+ return 1
351
+ }
352
+ if (arg === "--list") {
353
+ const root = (await trackedRoot(process.cwd()))?.root
354
+ if (!root) throw new CheckpointError("Kriya doesn't track this folder (your home folder or a drive root), so there are no checkpoints.")
355
+ const list = await listCheckpoints(root)
356
+ if (!list.length) {
357
+ say("No checkpoints yet: the Kriya loop saves one before each change the agent makes.")
358
+ return 0
359
+ }
360
+ list.forEach((c, i) => say(` ${String(i + 1).padStart(3)}. ${c.at.replace("T", " ").slice(0, 19)} ${c.kind === "undone" ? "(saved by an undo) " : ""}${c.label}`))
361
+ say("\nkriya undo <number> goes back to one; kriya undo goes back one step.")
362
+ return 0
363
+ }
364
+ const { restored, changed, saved } = await undo(process.cwd(), { target: arg === undefined ? undefined : Number(arg) })
365
+ if (!changed) say(`The files already match "${restored.label}".`)
366
+ else {
367
+ say(`Back to "${restored.label}" (${changed} file${changed === 1 ? "" : "s"} changed).`)
368
+ say("What it replaced is kept: kriya undo --list shows it as saved by an undo.")
369
+ }
370
+ return 0
371
+ }
372
+ case "handoff": {
373
+ const device = signedIn()
374
+ const done = await handoff(device, process.cwd(), args.join(" "))
375
+ writeFileSync(lastWorkspace(), `${done.workspaceId}\n`)
376
+ say(`Handed off (${done.bytes} bytes of changes). Your agent carries on in Kriya:`)
377
+ say(` ${done.url}`)
378
+ say(`Workspace ${done.workspaceId}; bring its changes back with kriya pull.`)
379
+ return 0
380
+ }
381
+ case "pull": {
382
+ const device = signedIn()
383
+ const id = args[0] ?? (existsSync(lastWorkspace()) ? readFileSync(lastWorkspace(), "utf8").trim() : "")
384
+ if (!id) {
385
+ say("Which workspace? Run kriya pull <workspace id>.")
386
+ return 1
387
+ }
388
+ const done = await pull(device, process.cwd(), id)
389
+ say(`On branch ${done.branch}: the workspace's changes on ${done.baseSha.slice(0, 12)} (${done.bytes} bytes).`)
390
+ say("Review them with git diff HEAD, then commit or merge as you like.")
391
+ return 0
392
+ }
393
+ case "daemon": {
394
+ const sub = args[0] === "install" || args[0] === "uninstall" ? args.shift() : null
395
+ const folders = []
396
+ let allowFullAccess = false
397
+ let allowServe = false
398
+ let allowEdit = false
399
+ for (let i = 0; i < args.length; i++) {
400
+ if (args[i] === "--folder" && args[i + 1]) folders.push(args[++i])
401
+ else if (args[i] === "--allow-full-access") allowFullAccess = true
402
+ else if (args[i] === "--allow-serve") allowServe = true
403
+ else if (args[i] === "--allow-edit") allowEdit = true
404
+ else {
405
+ say("Usage: kriya daemon [install|uninstall] [--folder <path>]… [--allow-full-access] [--allow-serve] [--allow-edit]")
406
+ return 1
407
+ }
408
+ }
409
+ const { resolve } = await import("node:path")
410
+ const offered = [process.cwd(), ...folders].map((f) => resolve(f))
411
+ if (sub) {
412
+ const { mkdirSync, unlinkSync } = await import("node:fs")
413
+ const { spawnSync } = await import("node:child_process")
414
+ const { dirname } = await import("node:path")
415
+ const service = serviceDefinition({
416
+ bin: new URL(import.meta.url).pathname,
417
+ args: [...offered.flatMap((f) => ["--folder", f]), ...(allowFullAccess ? ["--allow-full-access"] : []), ...(allowServe ? ["--allow-serve"] : []), ...(allowEdit ? ["--allow-edit"] : [])],
418
+ })
419
+ if (!service) {
420
+ say("kriya daemon install supports macOS (launchd) and Linux (systemd). Run kriya daemon in a terminal instead.")
421
+ return 1
422
+ }
423
+ const run = (steps) => steps.every(([cmd, ...rest]) => spawnSync(cmd, rest, { stdio: "inherit" }).status === 0)
424
+ if (sub === "uninstall") {
425
+ if (!existsSync(service.path)) {
426
+ say("The daemon isn't installed.")
427
+ return 0
428
+ }
429
+ run(service.stop)
430
+ unlinkSync(service.path)
431
+ say("The daemon is uninstalled; Kriya can't reach this computer until you start it again.")
432
+ return 0
433
+ }
434
+ signedIn()
435
+ mkdirSync(dirname(service.path), { recursive: true })
436
+ if (existsSync(service.path)) run(service.stop)
437
+ writeFileSync(service.path, service.content, { mode: 0o600 })
438
+ if (!run(service.start)) {
439
+ say(`Wrote ${service.path}, but it didn't start; see the message above.`)
440
+ return 1
441
+ }
442
+ say(`The daemon runs in the background for: ${offered.join(", ")}.`)
443
+ say(`Logs: ~/.kriya/daemon.log. Stop it with kriya daemon uninstall.`)
444
+ return 0
445
+ }
446
+ const device = signedIn()
447
+ if (allowFullAccess) process.stderr.write(`kriya daemon: Full access from Kriya is allowed. ${FULL_ACCESS_WARNING}\n`)
448
+ const stop = new AbortController()
449
+ process.once("SIGINT", () => stop.abort())
450
+ process.once("SIGTERM", () => stop.abort())
451
+ writeFileSync(daemonPidFile(), String(process.pid), { mode: 0o600 })
452
+ // Asking for it by name turns editing on for this daemon and its Edit Host
453
+ if (allowEdit) process.env.KRIYA_EDIT = "on"
454
+ await runDaemon({ device, folders: offered, allowFullAccess, allowServe, allowEdit, signal: stop.signal, log: say })
455
+ rmSync(daemonPidFile(), { force: true })
456
+ say("kriya daemon stopped.")
457
+ return 0
458
+ }
459
+ case "serve": {
460
+ if (args.length > 1 || args[0]?.startsWith("-")) {
461
+ say("Usage: kriya serve [folder]")
462
+ return 1
463
+ }
464
+ const device = signedIn()
465
+ const folder = await servedFolder(args[0] ?? process.cwd())
466
+ process.stderr.write(`${SERVE_NOTICE}\n`)
467
+ const stop = new AbortController()
468
+ process.once("SIGINT", () => stop.abort())
469
+ process.once("SIGTERM", () => stop.abort())
470
+ await serve({ device, folder, say, signal: stop.signal })
471
+ say("Stopped serving.")
472
+ return 0
473
+ }
474
+ case "run": {
475
+ useLoop(args)
476
+ const mode = parseMode(option(args, "--mode"))
477
+ const device = signedIn()
478
+ if (mode === "full") process.stderr.write(`${FULL_ACCESS_WARNING}\n`)
479
+ // The job is the first argument that isn't a flag; plan asks for a plan
480
+ const job = args.findIndex((arg) => !arg.startsWith("-"))
481
+ if (mode === "plan" && job !== -1) args[job] = planJob(args[job])
482
+ return runDsh("kriya-run", args, device, mode)
483
+ }
484
+ case "acp": {
485
+ // Stdout carries only ACP frames (newline-delimited JSON-RPC), so
486
+ // everything kriya itself says goes to stderr. DSH's ACP app takes no
487
+ // options but --help; the transport is stdio, the editor's choice
488
+ const help = args.length === 1 && (args[0] === "--help" || args[0] === "-h")
489
+ if (args.length && !help) {
490
+ process.stderr.write(`kriya acp takes no options but --help.\n`)
491
+ return 1
492
+ }
493
+ if (help) {
494
+ say(ACP_HELP)
495
+ return 0
496
+ }
497
+ const device = readDevice()
498
+ if (!device) {
499
+ process.stderr.write("kriya: run `kriya login` to connect your Kriya account.\n")
500
+ return 1
501
+ }
502
+ // The same defaults as kriya run (U10), from the editor's environment
503
+ useLoop([])
504
+ return runDsh("kriya-acp", [], device)
505
+ }
506
+ case undefined:
507
+ case "--mode":
508
+ case "--loop":
509
+ case "--budget":
510
+ case "--anchor":
511
+ case "--no-loop":
512
+ case "--loop-v2":
513
+ case "--no-loop-v2":
514
+ case "--loop-guard":
515
+ case "--no-loop-guard":
516
+ case "--strict-loop":
517
+ case "--no-strict-loop":
518
+ case "--defensive":
519
+ case "--no-defensive":
520
+ case "--recon":
521
+ case "--no-recon":
522
+ case "--jit-tools":
523
+ case "--no-jit-tools":
524
+ case "--browser-tools":
525
+ case "--no-browser-tools":
526
+ case "--router":
527
+ case "--no-router":
528
+ case "--edit":
529
+ case "--no-edit":
530
+ case "--no-budget":
531
+ case "--no-anchor":
532
+ case "--no-open":
533
+ case "--port": {
534
+ // Only these Web UI flags pass through; never --host, so the UI stays on 127.0.0.1
535
+ const flags = command === undefined ? [] : [command, ...args]
536
+ useLoop(flags)
537
+ const port = option(flags, "--port")
538
+ const mode = option(flags, "--mode")
539
+ if (mode === "plan") {
540
+ say("In the app, type /plan to plan first. --mode plan is for kriya run.")
541
+ return 1
542
+ }
543
+ const chosen = parseMode(mode, APP_MODES)
544
+ if (port !== undefined && !/^\d{2,5}$/.test(port)) {
545
+ say("--port takes a number, e.g. --port 8080.")
546
+ return 1
547
+ }
548
+ if (flags.some((flag) => flag !== "--no-open")) {
549
+ say(`Unknown option ${flags.find((flag) => flag !== "--no-open")}.\n\n${HELP}`)
550
+ return 1
551
+ }
552
+ const device = signedIn()
553
+ if (chosen === "full") process.stderr.write(`${FULL_ACCESS_WARNING}\n`)
554
+ return runDsh("kriya", [...flags, ...(port ? ["--port", port] : [])], device, chosen)
555
+ }
556
+ default:
557
+ say(`Unknown command ${command}.\n\n${HELP}`)
558
+ return 1
559
+ }
560
+ }
561
+
562
+ main(process.argv.slice(2)).then(
563
+ (code) => process.exit(code),
564
+ (error) => {
565
+ const known =
566
+ error instanceof KriyaError ||
567
+ error instanceof HandoffError ||
568
+ error instanceof ServeError ||
569
+ error instanceof ModeError ||
570
+ error instanceof SkillsError ||
571
+ error instanceof VerifyError ||
572
+ error instanceof CheckpointError ||
573
+ error instanceof RulesError
574
+ process.stderr.write(`kriya: ${known ? error.message : error?.message ?? error}\n`)
575
+ process.exit(1)
576
+ }
577
+ )