@yaks/harness 0.0.0-stage → 0.2.36

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 (230) hide show
  1. package/FRONTEND.md +170 -0
  2. package/LICENSE +202 -0
  3. package/MCPAuthPanel.js +166 -0
  4. package/MCPAuthPanel.js.map +1 -0
  5. package/MCPAuthPanel.ts +184 -0
  6. package/ModelPanel.js +124 -0
  7. package/ModelPanel.js.map +1 -0
  8. package/ModelPanel.ts +143 -0
  9. package/PersonaPanel.js +106 -0
  10. package/PersonaPanel.js.map +1 -0
  11. package/PersonaPanel.ts +110 -0
  12. package/README.md +1570 -2
  13. package/RuntimePanel.js +180 -0
  14. package/RuntimePanel.js.map +1 -0
  15. package/RuntimePanel.ts +205 -0
  16. package/STREAMING.md +101 -0
  17. package/WINDOWS.md +78 -0
  18. package/WORKER.md +221 -0
  19. package/_dist/agent.d.ts +197 -0
  20. package/_dist/agent.d.ts.map +1 -0
  21. package/_dist/cli.d.ts +10 -0
  22. package/_dist/cli.d.ts.map +1 -0
  23. package/_dist/conversations.d.ts +45 -0
  24. package/_dist/conversations.d.ts.map +1 -0
  25. package/_dist/default.d.ts +32 -0
  26. package/_dist/default.d.ts.map +1 -0
  27. package/_dist/detail.d.ts +16 -0
  28. package/_dist/detail.d.ts.map +1 -0
  29. package/_dist/diagnostics.d.ts +5 -0
  30. package/_dist/diagnostics.d.ts.map +1 -0
  31. package/_dist/effects.d.ts +35 -0
  32. package/_dist/effects.d.ts.map +1 -0
  33. package/_dist/http.d.ts +12 -0
  34. package/_dist/http.d.ts.map +1 -0
  35. package/_dist/isolated.d.ts +6 -0
  36. package/_dist/isolated.d.ts.map +1 -0
  37. package/_dist/local.d.ts +74 -0
  38. package/_dist/local.d.ts.map +1 -0
  39. package/_dist/machine.d.ts +3 -0
  40. package/_dist/machine.d.ts.map +1 -0
  41. package/_dist/mcp_auth.d.ts +8 -0
  42. package/_dist/mcp_auth.d.ts.map +1 -0
  43. package/_dist/mod.d.ts +43 -0
  44. package/_dist/mod.d.ts.map +1 -0
  45. package/_dist/model_selection.d.ts +8 -0
  46. package/_dist/model_selection.d.ts.map +1 -0
  47. package/_dist/routes.d.ts +11 -0
  48. package/_dist/routes.d.ts.map +1 -0
  49. package/_dist/runs.d.ts +7 -0
  50. package/_dist/runs.d.ts.map +1 -0
  51. package/_dist/runtime.d.ts +2 -0
  52. package/_dist/runtime.d.ts.map +1 -0
  53. package/_dist/session_machines.d.ts +18 -0
  54. package/_dist/session_machines.d.ts.map +1 -0
  55. package/_dist/skills.d.ts +11 -0
  56. package/_dist/skills.d.ts.map +1 -0
  57. package/_dist/store.d.ts +38 -0
  58. package/_dist/store.d.ts.map +1 -0
  59. package/_dist/tools.d.ts +28 -0
  60. package/_dist/tools.d.ts.map +1 -0
  61. package/_dist/view.d.ts +5 -0
  62. package/_dist/view.d.ts.map +1 -0
  63. package/_dist/vocab.d.ts +7 -0
  64. package/_dist/vocab.d.ts.map +1 -0
  65. package/_dist/worn.d.ts +52 -0
  66. package/_dist/worn.d.ts.map +1 -0
  67. package/agent.js +773 -0
  68. package/agent.js.map +1 -0
  69. package/agent.ts +959 -0
  70. package/app.js +811 -0
  71. package/app.js.map +1 -0
  72. package/app.ts +868 -0
  73. package/artifact_tools.js +186 -0
  74. package/artifact_tools.js.map +1 -0
  75. package/artifact_tools.ts +190 -0
  76. package/backend_worker.ts +286 -0
  77. package/cli.js +43 -0
  78. package/cli.js.map +1 -0
  79. package/cli.ts +48 -0
  80. package/conversations.js +526 -0
  81. package/conversations.js.map +1 -0
  82. package/conversations.ts +576 -0
  83. package/conversations_testing.ts +162 -0
  84. package/default.js +162 -0
  85. package/default.js.map +1 -0
  86. package/default.ts +168 -0
  87. package/deferred_model.ts +1 -0
  88. package/deno.json +1 -0
  89. package/detail.js +50 -0
  90. package/detail.js.map +1 -0
  91. package/detail.ts +75 -0
  92. package/diagnostics.js +132 -0
  93. package/diagnostics.js.map +1 -0
  94. package/diagnostics.ts +150 -0
  95. package/draft_vault.js +149 -0
  96. package/draft_vault.js.map +1 -0
  97. package/draft_vault.ts +176 -0
  98. package/effects.js +233 -0
  99. package/effects.js.map +1 -0
  100. package/effects.ts +250 -0
  101. package/frontend/vocab.json +376 -0
  102. package/frontend.js +511 -0
  103. package/frontend.js.map +1 -0
  104. package/frontend.ts +389 -0
  105. package/http.js +107 -0
  106. package/http.js.map +1 -0
  107. package/http.ts +105 -0
  108. package/input_text.js +91 -0
  109. package/input_text.js.map +1 -0
  110. package/input_text.ts +99 -0
  111. package/instructions.js +111 -0
  112. package/instructions.js.map +1 -0
  113. package/instructions.ts +145 -0
  114. package/isolated.js +512 -0
  115. package/isolated.js.map +1 -0
  116. package/isolated.ts +502 -0
  117. package/keyboard.js +544 -0
  118. package/keyboard.js.map +1 -0
  119. package/keyboard.ts +403 -0
  120. package/legacy_instructions.js +3 -0
  121. package/legacy_instructions.js.map +1 -0
  122. package/legacy_instructions.ts +13 -0
  123. package/local.js +181 -0
  124. package/local.js.map +1 -0
  125. package/local.ts +282 -0
  126. package/machine.js +3 -0
  127. package/machine.js.map +1 -0
  128. package/machine.ts +8 -0
  129. package/mcp.js +123 -0
  130. package/mcp.js.map +1 -0
  131. package/mcp.ts +141 -0
  132. package/mcp_auth.js +63 -0
  133. package/mcp_auth.js.map +1 -0
  134. package/mcp_auth.ts +91 -0
  135. package/mcp_authorize.js +17 -0
  136. package/mcp_authorize.js.map +1 -0
  137. package/mcp_authorize.ts +18 -0
  138. package/mcp_registry.js +178 -0
  139. package/mcp_registry.js.map +1 -0
  140. package/mcp_registry.ts +193 -0
  141. package/mod.js +43 -0
  142. package/mod.js.map +1 -0
  143. package/mod.ts +45 -0
  144. package/model_selection.js +72 -0
  145. package/model_selection.js.map +1 -0
  146. package/model_selection.ts +86 -0
  147. package/numbers.js +6 -0
  148. package/numbers.js.map +1 -0
  149. package/numbers.ts +8 -0
  150. package/package.json +106 -4
  151. package/panels.js +119 -0
  152. package/panels.js.map +1 -0
  153. package/panels.ts +259 -0
  154. package/patch.js +329 -0
  155. package/patch.js.map +1 -0
  156. package/patch.ts +325 -0
  157. package/perf.ts +65 -0
  158. package/providers.js +36 -0
  159. package/providers.js.map +1 -0
  160. package/providers.ts +53 -0
  161. package/remote.js +441 -0
  162. package/remote.js.map +1 -0
  163. package/remote.ts +446 -0
  164. package/results.js +49 -0
  165. package/results.js.map +1 -0
  166. package/results.ts +39 -0
  167. package/routes.js +64 -0
  168. package/routes.js.map +1 -0
  169. package/routes.ts +87 -0
  170. package/runs.js +478 -0
  171. package/runs.js.map +1 -0
  172. package/runs.ts +479 -0
  173. package/runtime/vocab.json +36 -0
  174. package/runtime.js +105 -0
  175. package/runtime.js.map +1 -0
  176. package/runtime.ts +112 -0
  177. package/session_machines.js +203 -0
  178. package/session_machines.js.map +1 -0
  179. package/session_machines.ts +216 -0
  180. package/sheet.js +55 -0
  181. package/sheet.js.map +1 -0
  182. package/sheet.ts +31 -0
  183. package/shutdown.js +7 -0
  184. package/shutdown.js.map +1 -0
  185. package/shutdown.ts +7 -0
  186. package/skills.js +116 -0
  187. package/skills.js.map +1 -0
  188. package/skills.ts +114 -0
  189. package/startup_bench.ts +140 -0
  190. package/status.js +82 -0
  191. package/status.js.map +1 -0
  192. package/status.ts +97 -0
  193. package/steps.baseline.json +28 -0
  194. package/steps_bench.ts +155 -0
  195. package/store.js +31 -0
  196. package/store.js.map +1 -0
  197. package/store.ts +82 -0
  198. package/streaming.js +3 -0
  199. package/streaming.js.map +1 -0
  200. package/streaming.ts +8 -0
  201. package/streaming_bench.ts +76 -0
  202. package/switch_bench.ts +97 -0
  203. package/testing.ts +177 -0
  204. package/tools.js +287 -0
  205. package/tools.js.map +1 -0
  206. package/tools.ts +313 -0
  207. package/transcript.js +149 -0
  208. package/transcript.js.map +1 -0
  209. package/transcript.ts +187 -0
  210. package/tree.js +97 -0
  211. package/tree.js.map +1 -0
  212. package/tree.ts +114 -0
  213. package/unfinished.js +186 -0
  214. package/unfinished.js.map +1 -0
  215. package/unfinished.ts +198 -0
  216. package/view.js +92 -0
  217. package/view.js.map +1 -0
  218. package/view.ts +102 -0
  219. package/vocab.js +23 -0
  220. package/vocab.js.map +1 -0
  221. package/vocab.json +494 -0
  222. package/vocab.ts +22 -0
  223. package/window_bench.ts +114 -0
  224. package/worker_bench.ts +72 -0
  225. package/workspace.js +21 -0
  226. package/workspace.js.map +1 -0
  227. package/workspace.ts +17 -0
  228. package/worn.js +194 -0
  229. package/worn.js.map +1 -0
  230. package/worn.ts +246 -0
package/keyboard.ts ADDED
@@ -0,0 +1,403 @@
1
+ import { useWatch } from '@yaks/ux'
2
+ import { derivedEid } from '@yaks/graph/identity'
3
+ /** Harness modes are graph state; the key interceptor and text surfaces are not. */
4
+ /* @ts-types="npm:@types/react@19.3.0" */ import { createElement as h } from 'react'
5
+ import type { Comp } from 'jsr:@yaks/graph@0.2.36'
6
+ import {
7
+ beginVisual,
8
+ copyText,
9
+ type Key,
10
+ pressFocused,
11
+ pressTo,
12
+ useKeymap,
13
+ visualKey,
14
+ type VisualState,
15
+ } from '@yaks/tui'
16
+ import type { Frontend } from './frontend.ts'
17
+
18
+ // NORMAL bindings own both routing and help; aliases share one definition.
19
+ type Binding = {
20
+ keys: string[]
21
+ help: string
22
+ focus?: 'transcript' | 'sidebar'
23
+ transcript?: Key
24
+ sidebar?: Key
25
+ action?: Key
26
+ }
27
+ const ctrl = (text: string): Key => ({ name: 'char', text, ctrl: true })
28
+ const bindings: Binding[] = [
29
+ { keys: ['h', 'left'], help: 'cursor left', transcript: { name: 'left' } },
30
+ { keys: ['l', 'right'], help: 'cursor right', transcript: { name: 'right' } },
31
+ {
32
+ keys: ['j', 'down'],
33
+ help: 'next entry / sidebar item',
34
+ transcript: { name: 'down' },
35
+ sidebar: ctrl('j'),
36
+ },
37
+ {
38
+ keys: ['k', 'up'],
39
+ help: 'previous entry / sidebar item',
40
+ transcript: { name: 'up' },
41
+ sidebar: ctrl('k'),
42
+ },
43
+ {
44
+ keys: ['Ctrl+u'],
45
+ help: 'half page up in focused pane',
46
+ transcript: ctrl('u'),
47
+ sidebar: ctrl('u'),
48
+ },
49
+ {
50
+ keys: ['Ctrl+d'],
51
+ help: 'half page down in focused pane',
52
+ transcript: ctrl('d'),
53
+ sidebar: ctrl('d'),
54
+ },
55
+ {
56
+ keys: ['gg', 'Ctrl+home'],
57
+ help: 'focused pane start',
58
+ transcript: { name: 'home', ctrl: true },
59
+ sidebar: { name: 'home', ctrl: true },
60
+ },
61
+ {
62
+ keys: ['G', 'Ctrl+end'],
63
+ help: 'focused pane end',
64
+ transcript: { name: 'end', ctrl: true },
65
+ sidebar: { name: 'end', ctrl: true },
66
+ },
67
+ {
68
+ keys: ['Ctrl+b', 'pageup'],
69
+ help: 'transcript previous page',
70
+ transcript: { name: 'pageup' },
71
+ },
72
+ {
73
+ keys: ['Ctrl+f', 'pagedown'],
74
+ help: 'transcript next page',
75
+ transcript: { name: 'pagedown' },
76
+ },
77
+ {
78
+ keys: ['n'],
79
+ help: 'next / previous root session: n / p',
80
+ action: ctrl('n'),
81
+ },
82
+ { keys: ['p'], help: 'previous root session', action: ctrl('p') },
83
+ { keys: ['o'], help: 'new session', action: ctrl('o') },
84
+ { keys: ['t'], help: 'toggle message / task', action: { name: 'tab' } },
85
+ {
86
+ keys: ['a'],
87
+ help: 'archive selected session',
88
+ action: { name: 'char', text: 'a', alt: true },
89
+ },
90
+ {
91
+ keys: ['z'],
92
+ help: 'show archived',
93
+ action: { name: 'char', text: 'z', alt: true },
94
+ },
95
+ { keys: ['s'], help: 'show settled', action: ctrl('s') },
96
+ { keys: ['b'], help: 'browse or close recent sessions', action: ctrl('b') },
97
+ { keys: ['>'], help: 'next session page', action: ctrl('f') },
98
+ { keys: ['<'], help: 'previous session page', action: ctrl('g') },
99
+ ]
100
+ export const shortcuts = [
101
+ ['i', 'INSERT: edit the draft'],
102
+ ...bindings.map(({ keys, help }) => [keys[0], help]),
103
+ ['Ctrl+w h/l', 'focus transcript / sidebar (Tab toggles)'],
104
+ ['v', 'VISUAL rendered selection; hjkl move, y copy, Esc NORMAL'],
105
+ ['Enter', 'inspect selected entry source; [/] chunks; Esc returns'],
106
+ ['? / Esc', 'show / dismiss help'],
107
+ ['A', 'authorize a connection (private return-URL input)'],
108
+ ['m', 'choose model (provider follows the model)'],
109
+ ['P', 'choose persona for a new session'],
110
+ ['r', 'runtime panel: j/k select, x interrupt/cancel queued, c continue'],
111
+ ['Ctrl+U', 'INSERT / VISUAL: cut entire draft'],
112
+ ['Alt+p', 'insert saved local yank into draft'],
113
+ ['Ctrl+C', 'quit'],
114
+ ]
115
+
116
+ export let Keyboard = ({ ui, action }: {
117
+ ui: Frontend
118
+ action: (key: Key) => boolean | void
119
+ }) => {
120
+ let state = useWatch(ui.keyboard)[0].keyboard as Comp
121
+ useKeymap((key) => {
122
+ let current = () =>
123
+ ui.client.ent(derivedEid('harness-frontend|keyboard'))!.keyboard as Comp
124
+ if (key.ctrl && key.text == 'c') return false
125
+ if (
126
+ key.ctrl && key.text == 'u' &&
127
+ (current().mode == 'INSERT' ||
128
+ Boolean(
129
+ (ui.client.ent(derivedEid('harness-frontend|visual'))!
130
+ .visual as VisualState).surface,
131
+ ))
132
+ ) {
133
+ let text = String(
134
+ (ui.client.ent(derivedEid('harness-frontend|draft'))!.draft as Comp)
135
+ .text ?? '',
136
+ )
137
+ if (!text) return true
138
+ let visual = ui.client.ent(derivedEid('harness-frontend|visual'))!
139
+ .visual as VisualState
140
+ ui.select({ ...visual, yank: text })
141
+ // Persist the recovery copy before requesting the clipboard or clearing input.
142
+ try {
143
+ let copied = copyText(text)
144
+ ui.edit({ text: '', at: 0 })
145
+ ui.keys({
146
+ clipboard: copied
147
+ ? 'Draft cut; clipboard copy requested; local yank saved'
148
+ : 'Draft cut to local yank; clipboard unavailable',
149
+ })
150
+ } catch {
151
+ ui.keys({
152
+ clipboard: 'Clipboard write failed; draft retained; local yank saved',
153
+ })
154
+ }
155
+ return true
156
+ }
157
+ if (key.alt && key.text == 'p') {
158
+ const yank = String(
159
+ (ui.client.ent(derivedEid('harness-frontend|visual'))!
160
+ .visual as VisualState).yank ?? '',
161
+ )
162
+ const draft = ui.client.ent(derivedEid('harness-frontend|draft'))!
163
+ .draft as Comp
164
+ const text = String(draft.text ?? ''), at = Number(draft.at ?? 0)
165
+ if (yank) {
166
+ ui.edit({
167
+ text: text.slice(0, at) + yank + text.slice(at),
168
+ at: at + yank.length,
169
+ })
170
+ }
171
+ ui.keys({
172
+ clipboard: yank ? 'Local yank inserted' : 'Local yank is empty',
173
+ })
174
+ return true
175
+ }
176
+ let s = current()
177
+ let visual = ui.client.ent(derivedEid('harness-frontend|visual'))!
178
+ .visual as VisualState
179
+ if (visual.surface) {
180
+ visualKey(key)
181
+ if (
182
+ !((ui.client.ent(derivedEid('harness-frontend|visual'))!
183
+ .visual as VisualState).surface)
184
+ ) {
185
+ ui.keys({ mode: 'NORMAL', pending: '' })
186
+ }
187
+ return true
188
+ }
189
+ if (s.detail) {
190
+ if (key.name == 'escape' || key.text == 'q') {
191
+ ui.keys({ detail: false, detailText: '', detailError: '' })
192
+ } else if (key.text == ']' && s.detailNext != null) {
193
+ ui.keys({ detailStart: Number(s.detailNext) })
194
+ } else if (key.text == '[') {
195
+ ui.keys({ detailStart: Math.max(0, Number(s.detailStart ?? 0) - 4096) })
196
+ } else {pressTo(
197
+ 'entry-detail',
198
+ key.text == 'j'
199
+ ? { name: 'down' }
200
+ : key.text == 'k'
201
+ ? { name: 'up' }
202
+ : key,
203
+ )}
204
+ return true
205
+ }
206
+ if (s.models) return false
207
+ if (key.name == 'escape') {
208
+ const session =
209
+ (ui.client.ent(derivedEid('harness-frontend|view'))!.frontend as Comp)
210
+ .selected ??
211
+ 'new'
212
+ pressTo('transcript-' + session, key)
213
+ ui.keys({
214
+ mode: 'NORMAL',
215
+ ...(s.mode == 'INSERT' ? { focus: 'transcript' } : {}),
216
+ help: false,
217
+ runtime: false,
218
+ pending: '',
219
+ })
220
+ if (s.mode == 'INSERT') {
221
+ // Keep the desired end position while a bounded transcript fetches its
222
+ // tail. The list clamps these coordinates against the final entry.
223
+ ui.client.mutate([{
224
+ entity: { eid: derivedEid('viewport-' + session) },
225
+ viewport: {
226
+ cursorRow: Number.MAX_SAFE_INTEGER,
227
+ cursorCol: Number.MAX_SAFE_INTEGER,
228
+ anchorId: null,
229
+ anchorRow: null,
230
+ anchorCol: null,
231
+ },
232
+ }])
233
+ pressTo('transcript-' + session, { name: 'end', ctrl: true })
234
+ }
235
+ return true
236
+ }
237
+ if (s.mode == 'INSERT') {
238
+ // Preserve the previous explicit selection shortcut.
239
+ if (key.alt && key.text == 'v') {
240
+ beginVisual('input')
241
+ if (
242
+ (ui.client.ent(derivedEid('harness-frontend|visual'))!
243
+ .visual as VisualState).surface
244
+ ) {
245
+ ui.keys({ mode: 'VISUAL' })
246
+ }
247
+ return true
248
+ }
249
+ return false
250
+ }
251
+ if (
252
+ key.name == 'char' && !key.ctrl && !key.alt && (key.text?.length ?? 0) > 1
253
+ ) {
254
+ // Decoder batches printable bytes. Stop splitting when a command enters INSERT.
255
+ for (let text of key.text!) {
256
+ if (current().mode == 'INSERT') pressFocused({ ...key, text })
257
+ else if (current().mode == 'VISUAL') {
258
+ command({ ...key, text })
259
+ } else command({ ...key, text })
260
+ }
261
+ return true
262
+ }
263
+ return command(key)
264
+ function command(k: Key): boolean {
265
+ s = current()
266
+ let text = k.name == 'char' && !k.alt && !k.ctrl ? k.text : undefined
267
+ if (k.ctrl && k.text == 'w') {
268
+ ui.keys({ pending: 'window' })
269
+ return true
270
+ }
271
+ if (s.pending == 'window') {
272
+ ui.keys({
273
+ pending: '',
274
+ ...(text == 'h'
275
+ ? { focus: 'transcript' }
276
+ : text == 'l'
277
+ ? { focus: 'sidebar' }
278
+ : {}),
279
+ })
280
+ return true
281
+ }
282
+ if (text == 'm') {
283
+ ui.keys({
284
+ models: true,
285
+ personas: false,
286
+ modelIndex: 0,
287
+ modelFeedback: '',
288
+ })
289
+ return true
290
+ }
291
+ if (
292
+ text == 'P' &&
293
+ (ui.client.ent(derivedEid('harness-frontend|view'))!.frontend as Comp)
294
+ .selected == null
295
+ ) {
296
+ ui.keys({
297
+ personas: true,
298
+ models: false,
299
+ personaIndex: 0,
300
+ personaFeedback: '',
301
+ })
302
+ return true
303
+ }
304
+ if (text == 'r') {
305
+ ui.keys({ runtime: !s.runtime })
306
+ return true
307
+ }
308
+ if (s.runtime) return false
309
+ if (s.help) {
310
+ if (text == '?' || k.name == 'escape') ui.keys({ help: false })
311
+ return true
312
+ }
313
+ if (text == '?') {
314
+ ui.keys({ help: true, pending: '' })
315
+ return true
316
+ }
317
+ if (text == 'i') {
318
+ const selectedSession =
319
+ (ui.client.ent(derivedEid('harness-frontend|view'))!.frontend as Comp)
320
+ .selected ?? 'new'
321
+ pressTo('transcript-' + selectedSession, { name: 'escape' })
322
+ ui.keys({ mode: 'INSERT', pending: '' })
323
+ return true
324
+ }
325
+ if (k.name == 'tab') {
326
+ ui.keys({
327
+ focus: s.focus == 'transcript' ? 'sidebar' : 'transcript',
328
+ pending: '',
329
+ })
330
+ return true
331
+ }
332
+ let id = 'transcript-' +
333
+ String(
334
+ (ui.client.ent(derivedEid('harness-frontend|view'))!.frontend as Comp)
335
+ .selected ?? 'new',
336
+ )
337
+ if (k.name == 'enter' && s.focus == 'transcript') {
338
+ ui.keys({
339
+ detail: true,
340
+ detailStart: 0,
341
+ detailText: '',
342
+ detailError: '',
343
+ detailRevision: '',
344
+ detailNext: null,
345
+ })
346
+ return true
347
+ }
348
+ if (text == 'v') {
349
+ if (!pressTo(id, { name: 'char', text: 'v' }) && beginVisual(id)) {
350
+ ui.keys({ mode: 'VISUAL', focus: 'transcript', pending: '' })
351
+ }
352
+ return true
353
+ }
354
+ if (text == 'y' && s.mode == 'VISUAL') {
355
+ pressTo(id, k)
356
+ return true
357
+ }
358
+ if (text == 'g' && s.pending != 'g') {
359
+ ui.keys({ pending: 'g' })
360
+ return true
361
+ }
362
+ ui.keys({ pending: '' })
363
+ let chord = text == 'g' && s.pending == 'g'
364
+ ? 'gg'
365
+ : !k.alt
366
+ ? (k.ctrl ? 'Ctrl+' : '') + (k.name == 'char' ? k.text : k.name)
367
+ : ''
368
+ let binding = bindings.find((binding) => binding.keys.includes(chord))
369
+ if (binding?.focus) ui.keys({ focus: binding.focus })
370
+ else if (binding?.action) action(binding.action)
371
+ else if (binding) {
372
+ if (s.focus == 'sidebar') {
373
+ if (binding.sidebar) action(binding.sidebar)
374
+ } else if (binding.transcript) pressTo(id, binding.transcript)
375
+ }
376
+ return true
377
+ }
378
+ })
379
+ return h(
380
+ 'div',
381
+ null,
382
+ h(
383
+ 'div',
384
+ { className: 'Entry_Hint' },
385
+ String(state.mode) +
386
+ (state.mode == 'NORMAL'
387
+ ? ' · ' + state.focus + ' · ? help'
388
+ : ' · Esc NORMAL'),
389
+ ),
390
+ state.clipboard
391
+ ? h('div', { className: 'Entry_Hint' }, String(state.clipboard))
392
+ : null,
393
+ state.help
394
+ ? h(
395
+ 'div',
396
+ { border: 'Composer_Border' },
397
+ ...shortcuts.map(([key, description]) =>
398
+ h('div', { wrap: '1', key }, key.padEnd(12) + description)
399
+ ),
400
+ )
401
+ : null,
402
+ )
403
+ }
@@ -0,0 +1,3 @@
1
+ /** Compatibility only: never inject this retired CLI default into a request. */ const retired = 'You are an agent in a self-contained harness. You have a shell, and the ' + 'graph you yourself live in: your transcript, the work on your list and ' + 'the programs you start are all entities you can read and write with the ' + 'graph_ tools. Be terse; say what you did, not what you are about to do.';
2
+ /** Preserve custom session instructions and explicit host configuration. */ export let inheritedInstructions = (inherited, configured)=>inherited == null || inherited == retired ? configured : inherited;
3
+ //# sourceMappingURL=legacy_instructions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"legacy_instructions.js","sources":["./legacy_instructions.ts"],"names":[],"mappings":"AAAA,8EAA8E,GAC9E,MAAM,UACJ,6EACA,4EACA,6EACA;AAEF,0EAA0E,GAC1E,OAAO,IAAI,wBAAwB,CACjC,WACA,aAEA,aAAa,QAAQ,aAAa,UAAU,aAAa,UAAS"}
@@ -0,0 +1,13 @@
1
+ /** Compatibility only: never inject this retired CLI default into a request. */
2
+ const retired =
3
+ 'You are an agent in a self-contained harness. You have a shell, and the ' +
4
+ 'graph you yourself live in: your transcript, the work on your list and ' +
5
+ 'the programs you start are all entities you can read and write with the ' +
6
+ 'graph_ tools. Be terse; say what you did, not what you are about to do.'
7
+
8
+ /** Preserve custom session instructions and explicit host configuration. */
9
+ export let inheritedInstructions = (
10
+ inherited: string | undefined,
11
+ configured: string | undefined,
12
+ ): string | undefined =>
13
+ inherited == null || inherited == retired ? configured : inherited
package/local.js ADDED
@@ -0,0 +1,181 @@
1
+ // Provider-backed capabilities lent to the native runner. Sessions see the
2
+ // graph and machines, never a host checkout. Credentials, MCP and diagnostics
3
+ // remain host integrations; shell and file work is routed through providers.
4
+ import * as systemProcess from "@yaks/process/system";
5
+ import { watchMigrations } from "@yaks/sqlite/migration";
6
+ import { render as tree } from "@yaks/react";
7
+ import { agent } from "./agent.js";
8
+ import { authorize } from "./mcp_authorize.js";
9
+ import { mcpTools } from "./mcp.js";
10
+ import { streamingEnabled } from "./streaming.js";
11
+ import { imageContext, registered } from "./artifact_tools.js";
12
+ import { diagnostics } from "./diagnostics.js";
13
+ import { homeAt, machines } from "./session_machines.js";
14
+ import { homeAt as checkoutHome } from "./workspace.js";
15
+ import { openingFor } from "./instructions.js";
16
+ import { transcriptViews } from "./transcript.js";
17
+ import { graphTools, harnessTools, skillTools } from "./tools.js";
18
+ import { skillItems } from "./skills.js";
19
+ import { pooledHttp } from "./http.js";
20
+ import { configured, lending } from "./providers.js";
21
+ import { kindsIndex } from "@yaks/vocab/runtime";
22
+ export { hosted } from "./store.js";
23
+ export { graphTools, harnessTools } from "./tools.js";
24
+ /** What this machine lends an agent over `h`: the models of the providers its
25
+ * config names, over its credentials and sign-ins, the workspace and sandbox
26
+ * bindings, the MCP servers, the pictures, the instruction files where a
27
+ * session opens, the persona and topic each of its asks is told afresh, and
28
+ * where a defect is written. */ export let here = async (h, opts = {})=>{
29
+ let env = opts.env ?? systemProcess.env.get;
30
+ let http = pooledHttp(opts.http);
31
+ let auth = authorize(h);
32
+ let providers = await configured(h.plugins, lending(h, auth.signin, http.fetch, env)).catch(async (error)=>{
33
+ http.close();
34
+ await auth.close();
35
+ throw error;
36
+ });
37
+ let detach = h.report ? diagnostics().attach(h.report) : ()=>{};
38
+ let report = (error, where)=>diagnostics().report(error, where);
39
+ let binding = machines(h.g, opts.sandboxes ?? h.sandboxes, h.resolveHome, opts.workspaces ?? h.workspaces);
40
+ const mcp = mcpTools(h, auth.signin, auth.mcp);
41
+ h.fx.created('mcp_server', mcp.refresh).changed('mcp_server', mcp.refresh).removed('mcp_server', mcp.refresh);
42
+ let named;
43
+ let lent = {
44
+ ...binding.limits,
45
+ ...opts,
46
+ h,
47
+ model: opts.model,
48
+ providers: {
49
+ ...providers,
50
+ ...opts.providers
51
+ },
52
+ tools: opts.tools ?? [
53
+ ...harnessTools(h.g, {
54
+ ...opts,
55
+ machines: binding,
56
+ workspaceEffects: !opts.workspaces && h.fx.slots().some((s)=>s.id == 'shell' && !!s.run),
57
+ workspaces: opts.workspaces ?? h.workspaces,
58
+ artifacts: h.artifacts,
59
+ reply: h.reply
60
+ }),
61
+ ...skillTools(h.g, h.reply)
62
+ ],
63
+ remote: mcp.snapshot,
64
+ // The host's other tools, its plugins' own among them, adapted the first
65
+ // time a transcript is offered one by name: a session whose persona
66
+ // contains task_new and search carries those and nothing else, as a
67
+ // builder's offered memory_around and memory_save does.
68
+ named: ()=>named ??= graphTools(h.g, {
69
+ tools: h.hostTools?.(),
70
+ reply: h.reply
71
+ }),
72
+ streaming: streamingEnabled(opts, env),
73
+ // A session here may run for weeks, so no ask is told a snapshot from the
74
+ // day it opened: each says the persona it wears and the topic it is
75
+ // opened on, and is offered the tools that persona contains, as they read
76
+ // now, once its cached prefix has expired.
77
+ wear: {
78
+ topic: true,
79
+ tools: true
80
+ },
81
+ // Each ask opens with the kinds this graph makes, as an MCP connection's
82
+ // instructions carry them (@yaks/mcp), so a session writes whole ones.
83
+ opens: kindsIndex(h.vocab),
84
+ opening: async (persona)=>{
85
+ let home = opts.workspace ? {
86
+ workspace: opts.workspace,
87
+ ...opts.cwd ? {
88
+ cwd: opts.cwd
89
+ } : {}
90
+ } : opts.cwd ? await checkoutHome(h.g, opts.cwd) : homeAt();
91
+ return {
92
+ home,
93
+ ...await openingFor(h.g, home, opts.workspaces ?? h.workspaces, {
94
+ persona
95
+ })
96
+ };
97
+ },
98
+ context: (window, entries)=>imageContext(h.g, window, entries, h.artifacts),
99
+ requestItems: (_, _entries, current)=>skillItems(h.g, current),
100
+ report,
101
+ release: async ()=>{
102
+ http.close();
103
+ await auth.close();
104
+ await diagnostics().drain();
105
+ detach();
106
+ }
107
+ };
108
+ return {
109
+ lent,
110
+ authorize: auth.run,
111
+ anchor: opts.model?.anchor,
112
+ report
113
+ };
114
+ };
115
+ /**
116
+ * Start the harness here, over a graph a `yak` config composed: lend the agent
117
+ * this machine, and work the runs its commits owe.
118
+ *
119
+ * ```ts ignore
120
+ * import { hosted, local } from '@yaks/harness/local'
121
+ *
122
+ * let a = await local({ h: hosted(host), model: fake })
123
+ * let s = await a.start('reply with the word pong')
124
+ * await a.idle(s)
125
+ * ```
126
+ */ export let local = async (opts)=>{
127
+ // A harness spread into the options is refused, including for untyped
128
+ // JavaScript callers, whose options TypeScript never saw.
129
+ for (let key of [
130
+ 'path',
131
+ 'db',
132
+ 'store',
133
+ 'g',
134
+ 'fx',
135
+ 'vocab',
136
+ 'close'
137
+ ]){
138
+ if (Object.hasOwn(opts, key)) {
139
+ throw new TypeError('Pass the harness as local({ h: hosted(host) }), not spread options');
140
+ }
141
+ }
142
+ let h = opts.h;
143
+ let env = opts.env ?? systemProcess.env.get;
144
+ let { lent, authorize, anchor, report } = await here(h, opts);
145
+ let watch;
146
+ let a = agent({
147
+ ...lent,
148
+ release: async ()=>{
149
+ watch?.stop();
150
+ await lent.release?.();
151
+ await h.close();
152
+ }
153
+ });
154
+ let l = Object.assign(a, {
155
+ authorizeMCP: a.admitted(authorize),
156
+ // What the terminal draws inline: a PNG, and not a large one.
157
+ image: a.admitted(async (eid)=>{
158
+ let { bytes, mediaType } = await registered(h.g, eid, h.artifacts);
159
+ if (mediaType != 'image/png' || bytes.length > 4 * 1024 * 1024) {
160
+ throw new Error('Not a displayable PNG artifact');
161
+ }
162
+ return bytes;
163
+ }),
164
+ entry: (b)=>tree(transcriptViews, b, 'Transcript', h.vocab, {
165
+ inlineImages: env('HARNESS_GRAPHICS') == 'kitty',
166
+ image: (eid)=>l.image(eid),
167
+ names: a.names,
168
+ anchor
169
+ })
170
+ });
171
+ watch = h.migrations && watchMigrations(h.migrations, (reason)=>{
172
+ // Stop scheduling immediately, but leave SQLite open for admitted work to
173
+ // drain. Restart is an explicit owner action, not a migration side effect.
174
+ void l.close(reason).catch((error)=>report(error, {
175
+ phase: 'migration-drain'
176
+ }));
177
+ console.error(reason.message);
178
+ }, opts.migrationPollMs ?? 1000, opts.clock);
179
+ return l;
180
+ };
181
+ //# sourceMappingURL=local.js.map
package/local.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"local.js","sources":["./local.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,8EAA8E;AAC9E,6EAA6E;AAE7E,YAAY,+CAAoD;AAKhE,SAAS,eAAe,sCAA2C;AACnE,SAAS,UAAU,IAAI,2BAAgC;AAEvD,SAAqB,KAAK,qBAA4C;AACtE,SAAS,SAAS,6BAA4B;AAE9C,SAAS,QAAQ,mBAAkB;AACnC,SAAS,gBAAgB,yBAAwB;AACjD,SAAS,YAAY,EAAE,UAAU,8BAA6B;AAC9D,SAAS,WAAW,2BAA+C;AACnE,SAAS,MAAM,EAAE,QAAQ,gCAA+B;AACxD,SAAS,UAAU,YAAY,yBAAwB;AACvD,SAAS,UAAU,4BAA2B;AAC9C,S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