@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/steps_bench.ts ADDED
@@ -0,0 +1,155 @@
1
+ /** Native step overhead with an instantly answered scripted model and no I/O.
2
+ * Fixture composition, verification and cleanup are outside the timed boundary. */
3
+
4
+ import { type Samples, stopwatch } from 'jsr:@yaks/benchmark@0.2.36'
5
+ import type { Comp } from 'jsr:@yaks/graph@0.2.36'
6
+ import type { Model } from 'jsr:@yaks/model@0.2.36'
7
+ import { textOf, transcript } from 'jsr:@yaks/session@0.2.36'
8
+ import { standaloneMain } from '../../bench/standalone-main.ts'
9
+ import { seed } from './agent.ts'
10
+ import { agent } from './agent.ts'
11
+ import { harness } from './testing.ts'
12
+
13
+ const ROUNDS = 3
14
+ const STEPS = 12
15
+ const PROMPT = 'Run the finite scripted workload.'
16
+
17
+ let check = (holds: boolean, message: string) => {
18
+ if (!holds) throw new Error(`harness-steps: ${message}`)
19
+ }
20
+
21
+ let round = async (steps: number) => {
22
+ const h = await harness(':memory:')
23
+ let asks = 0, calls = 0, issued = 0, pendingTurns = 0
24
+ const model: Model = (request) => {
25
+ asks++
26
+ check(asks <= 2 * steps + 1, 'script exceeded its finite model-call limit')
27
+ // Pending. remains a protocol result; the final answer can be a later
28
+ // user update rather than a replacement result.
29
+ const final = (text: string) =>
30
+ request.items.some((item) =>
31
+ item.kind == 'result'
32
+ ? item.output.split('\n').includes(text)
33
+ : item.kind == 'user' && item.text.includes(text)
34
+ )
35
+ let completed = 0
36
+ while (completed < steps && final(`echoed ${completed + 1}!`)) completed++
37
+ let items: Awaited<ReturnType<Model>>['items']
38
+ if (completed < issued) {
39
+ pendingTurns++
40
+ check(
41
+ pendingTurns <= issued,
42
+ 'the same progress owed repeated model turns',
43
+ )
44
+ items = [{ kind: 'assistant', text: 'Continue when the tool finishes.' }]
45
+ } else if (issued < steps) {
46
+ issued++
47
+ items = [{ kind: 'call', id: `call-${issued}`, name: 'echo', args: '{}' }]
48
+ } else {
49
+ items = [{ kind: 'assistant', text: 'done' }]
50
+ }
51
+ return Promise.resolve({ id: `reply-${asks}`, model: 'scripted', items })
52
+ }
53
+ const tools = [{
54
+ name: 'echo',
55
+ description: 'Instant scripted answer',
56
+ parameters: { type: 'object', properties: {} },
57
+ run: () => `echoed ${++calls}!`,
58
+ }]
59
+ await h.g.apply(seed({ provider: 'openai', model: 'scripted', tools }), {
60
+ trusted: true,
61
+ })
62
+ const a = agent({
63
+ h,
64
+ name: 'scripted',
65
+ tools,
66
+ model,
67
+ })
68
+ let timer: ReturnType<typeof setTimeout> | undefined
69
+ try {
70
+ const took = stopwatch()
71
+ const entries = await Promise.race([
72
+ (async () => {
73
+ const session = await a.start(PROMPT)
74
+ await a.idle(session)
75
+ return await transcript(h.g, session)
76
+ })(),
77
+ new Promise<never>((_, reject) => {
78
+ timer = setTimeout(
79
+ () => reject(new Error('harness-steps timed out')),
80
+ 30_000,
81
+ )
82
+ }),
83
+ ])
84
+ const elapsed = took()
85
+ clearTimeout(timer)
86
+ const reply = entries.at(-1)!
87
+ const asyncCalls = entries.filter((entry) => !!entry.tool_async)
88
+ const results = entries.filter((entry) => !!entry.result)
89
+ const progress = entries.filter((entry) => !!entry.tool_progress)
90
+ check(
91
+ textOf(reply) == 'done',
92
+ `wrong final output: ${
93
+ JSON.stringify(reply)
94
+ }; asks=${asks}, calls=${calls}`,
95
+ )
96
+ check(
97
+ asks == steps + pendingTurns + 1 && calls == steps &&
98
+ issued == steps,
99
+ 'wrong model/tool step count',
100
+ )
101
+ check(asyncCalls.length == steps, 'did not dispatch real async tools')
102
+ check(results.length == steps, 'wrong completed result count')
103
+ // Historical baselines wrote one progress entry per tool; current sessions
104
+ // write only the result. Both run the same scripted model and tools.
105
+ check(
106
+ progress.length == 0 || progress.length == steps,
107
+ 'tool progress covered only part of the workload',
108
+ )
109
+ check(
110
+ entries.some((entry) => !entry.output && textOf(entry) == PROMPT),
111
+ 'input lost',
112
+ )
113
+ for (let i = 0; i < steps; i++) {
114
+ check(textOf(results[i]) == `echoed ${i + 1}!`, 'persisted result lost')
115
+ check(
116
+ (results[i].result as Comp).call == asyncCalls[i].entity.eid,
117
+ 'result has wrong call',
118
+ )
119
+ }
120
+ return {
121
+ value: elapsed.value / (steps || 1),
122
+ cpu: elapsed.cpu / (steps || 1),
123
+ counts: {
124
+ modelCalls: asks,
125
+ pendingTurns,
126
+ toolSteps: calls,
127
+ results: results.length,
128
+ asyncCalls: asyncCalls.length,
129
+ progress: progress.length,
130
+ entries: entries.length,
131
+ },
132
+ }
133
+ } finally {
134
+ clearTimeout(timer)
135
+ await a.close()
136
+ }
137
+ }
138
+
139
+ export async function measure(
140
+ _args: string[] = [],
141
+ ): Promise<Record<string, Samples>> {
142
+ const samples: Record<string, Samples> = {}
143
+ for (
144
+ const [name, steps] of [['no-tools', 0], ['tool-step', STEPS]] as const
145
+ ) {
146
+ // Warm the same code paths without carrying transcript growth into samples.
147
+ await round(steps)
148
+ const rounds = []
149
+ for (let i = 0; i < ROUNDS; i++) rounds.push(await round(steps))
150
+ samples[name] = rounds
151
+ }
152
+ return samples
153
+ }
154
+
155
+ if (import.meta.main) await standaloneMain('harness-steps')
package/store.js ADDED
@@ -0,0 +1,31 @@
1
+ // The graph a harness runs over: the one a `yak` config names, composed as
2
+ // every `yak` process composes it (@yaks/cli `compose`), and seen the way the
3
+ // runner and its tools use it. The harness keeps no graph of its own: which
4
+ // packages make it up, and so what a write means, is the config's to say, and
5
+ // a graph it runs over is the same graph with the same rules whichever process
6
+ // opened it.
7
+ /** The graph a `yak` config composed, as a harness runs over it: its store,
8
+ * graph, effects and vault are the host's. Closing the harness runs `close`,
9
+ * which by default leaves the host open for whoever composed it to close. */ export let hosted = (host, close = ()=>{})=>{
10
+ return {
11
+ person: host.config.person,
12
+ plugins: host.config.plugins,
13
+ store: host.storage,
14
+ g: host.graph,
15
+ fx: host.fx,
16
+ vocab: host.vocab,
17
+ me: host.me,
18
+ gone: host.gone,
19
+ vault: host.vault,
20
+ artifacts: host.artifacts,
21
+ sandboxes: host.sandboxes,
22
+ resolveHome: host.resolveHome,
23
+ workspaces: host.workspaces,
24
+ reply: host.reply,
25
+ report: host.report,
26
+ hostTools: ()=>host.tools,
27
+ migrations: host.storage.migrations,
28
+ close
29
+ };
30
+ };
31
+ //# sourceMappingURL=store.js.map
package/store.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.js","sources":["./store.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,8EAA8E;AAC9E,4EAA4E;AAC5E,8EAA8E;AAC9E,+EAA+E;AAC/E,aAAa;AAiDb;;2EAE2E,GAC3E,OAAO,IAAI,SAAS,CAClB,MACA,QAAoC,KAAO,CAAC;EAE5C,OAAO;IACL,QAAQ,KAAK,MAAM,CAAC,MAAM;IAC1B,SAAS,KAAK,MAAM,CAAC,OAAO;IAC5B,OAAO,KAAK,OAAO;IACnB,GAAG,KAAK,KAAK;IACb,IAAI,KAAK,EAAE;IACX,OAAO,KAAK,KAAK;IACjB,IAAI,KAAK,EAAE;IACX,MAAM,KAAK,IAAI;IACf,OAAO,KAAK,KAAK;IACjB,WAAW,KAAK,SAAS;IACzB,WAAW,KAAK,SAAS;IACzB,aAAa,KAAK,WAAW;IAC7B,YAAY,KAAK,UAAU;IAC3B,OAAO,KAAK,KAAK;IACjB,QAAQ,KAAK,MAAM;IACnB,WAAW,IAAM,KAAK,KAAK;IAC3B,YAAY,KAAK,OAAO,CAAC,UAAU;IACnC;EACF;AACF,EAAC"}
package/store.ts ADDED
@@ -0,0 +1,82 @@
1
+ // The graph a harness runs over: the one a `yak` config names, composed as
2
+ // every `yak` process composes it (@yaks/cli `compose`), and seen the way the
3
+ // runner and its tools use it. The harness keeps no graph of its own: which
4
+ // packages make it up, and so what a write means, is the config's to say, and
5
+ // a graph it runs over is the same graph with the same rules whichever process
6
+ // opened it.
7
+
8
+ import { type Blobs } from '@yaks/blob'
9
+ import type { Effects } from 'jsr:@yaks/effects@0.2.36'
10
+ import type { Eid, Graph, NamedTool, Storage } from 'jsr:@yaks/graph@0.2.36'
11
+ import type { Vocab } from 'jsr:@yaks/vocab@0.2.36'
12
+ import type { Host, MigrationMonitor, Plug } from 'jsr:@yaks/host@0.2.36'
13
+ import type { Vault } from 'jsr:@yaks/secrets@0.2.36'
14
+ import type { Reply } from 'jsr:@yaks/tools@0.2.36'
15
+
16
+ /** A graph as a harness runs over it: the store under it, the graph
17
+ * over it, the effects registry the runner is handled on, and the process
18
+ * working it. */
19
+ export type Harness = {
20
+ /** The configured person whose default provider accounts serve native sessions. */
21
+ person?: Eid
22
+ /** the plugins the config names: the providers among them are the ones
23
+ * a session may ask (./providers.ts) */
24
+ plugins?: readonly Plug[]
25
+ store: Storage
26
+ g: Graph
27
+ fx: Effects
28
+ vocab: Vocab
29
+ /** the process row this graph is worked by: what a run's lease names */
30
+ me: Eid
31
+ /** whether a lease's holder is over, so what it held is had now rather than
32
+ * at its expiry (@yaks/cli `Host.gone`) */
33
+ gone: (holder: Eid) => Promise<boolean>
34
+ /** where this graph's secrets are kept — its sign-ins among them */
35
+ vault: Vault
36
+ /** Explicitly lent workspace and sandbox bindings; no host disk is assumed. */
37
+ sandboxes?: Host['sandboxes']
38
+ resolveHome?: Host['resolveHome']
39
+ workspaces?: Host['workspaces']
40
+ /** Binary artifacts shared with the host's blob door. */
41
+ artifacts: Blobs
42
+ /** what a tool call the agent makes directly is owed beside its answer,
43
+ * as the host's own runner adds it (@yaks/cli `Host.reply`): the entities
44
+ * near one it just created, among them */
45
+ reply?: Reply
46
+ /** The host's catch boundary, delivering original failures to its tracker. */
47
+ report?: Host['report']
48
+ /** every tool the host runs, its plugins' own among them (`memory_around`),
49
+ * read when a transcript names one the harness does not carry for all */
50
+ hostTools?: () => NamedTool[]
51
+ migrations?: MigrationMonitor
52
+ close: () => void | Promise<void>
53
+ }
54
+
55
+ /** The graph a `yak` config composed, as a harness runs over it: its store,
56
+ * graph, effects and vault are the host's. Closing the harness runs `close`,
57
+ * which by default leaves the host open for whoever composed it to close. */
58
+ export let hosted = (
59
+ host: Host,
60
+ close: () => void | Promise<void> = () => {},
61
+ ): Harness => {
62
+ return {
63
+ person: host.config.person,
64
+ plugins: host.config.plugins,
65
+ store: host.storage,
66
+ g: host.graph,
67
+ fx: host.fx,
68
+ vocab: host.vocab,
69
+ me: host.me,
70
+ gone: host.gone,
71
+ vault: host.vault,
72
+ artifacts: host.artifacts,
73
+ sandboxes: host.sandboxes,
74
+ resolveHome: host.resolveHome,
75
+ workspaces: host.workspaces,
76
+ reply: host.reply,
77
+ report: host.report,
78
+ hostTools: () => host.tools,
79
+ migrations: host.storage.migrations,
80
+ close,
81
+ }
82
+ }
package/streaming.js ADDED
@@ -0,0 +1,3 @@
1
+ /** Resolve host streaming configuration without depending on provider support. */ import * as systemProcess from "@yaks/process/system";
2
+ export let streamingEnabled = (options, env = systemProcess.env.get)=>options.streaming ?? options.stream ?? env('HARNESS_STREAM') != '0';
3
+ //# sourceMappingURL=streaming.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"streaming.js","sources":["./streaming.ts"],"names":[],"mappings":"AAAA,gFAAgF,GAEhF,YAAY,+CAAoD;AAChE,OAAO,IAAI,mBAAmB,CAC5B,SACA,MAA4C,cAAc,GAAG,CAAC,GAAG,GAEjE,QAAQ,SAAS,IAAI,QAAQ,MAAM,IAAI,IAAI,qBAAqB,IAAG"}
package/streaming.ts ADDED
@@ -0,0 +1,8 @@
1
+ /** Resolve host streaming configuration without depending on provider support. */
2
+
3
+ import * as systemProcess from '@yaks/process/system'
4
+ export let streamingEnabled = (
5
+ options: { streaming?: boolean; stream?: boolean },
6
+ env: (name: string) => string | undefined = systemProcess.env.get,
7
+ ): boolean =>
8
+ options.streaming ?? options.stream ?? env('HARNESS_STREAM') != '0'
@@ -0,0 +1,76 @@
1
+ /** Isolated synthetic comparison; not a live provider benchmark.
2
+ * deno run -A packages/harness/streaming_bench.ts */
3
+
4
+ import { graph, transient } from 'jsr:@yaks/graph@0.2.36'
5
+ import { ram } from 'jsr:@yaks/ram@0.2.36'
6
+ import { loadVocab } from 'jsr:@yaks/vocab@0.2.36'
7
+ import { subscriptions } from 'jsr:@yaks/api@0.2.36'
8
+ import { type Samples, stopwatch } from 'jsr:@yaks/benchmark@0.2.36'
9
+ import { standaloneMain } from '../../bench/standalone-main.ts'
10
+
11
+ export async function measure(
12
+ _args: string[] = [],
13
+ ): Promise<Record<string, Samples>> {
14
+ let results: Record<string, Samples> = {}
15
+ const vocab = loadVocab([{
16
+ $defs: {
17
+ doc: {
18
+ component: true,
19
+ properties: { body: { type: 'string' } },
20
+ },
21
+ },
22
+ }])
23
+ for (const live of [false, true]) {
24
+ const g = graph({ vocab, storage: ram(vocab) })
25
+ await g.apply([{ entity: { eid: 'd' }, doc: { body: '' } }])
26
+ let writes = 0, bytes = 0, frames = 0
27
+ g.use({
28
+ name: 'counter',
29
+ hooks: {
30
+ effect: (b) => {
31
+ writes++
32
+ return b
33
+ },
34
+ },
35
+ })
36
+ const subs = subscriptions(g)
37
+ await subs.open(
38
+ (frame) => {
39
+ bytes += JSON.stringify(frame).length
40
+ frames++
41
+ },
42
+ 'd',
43
+ '.doc',
44
+ )
45
+ const took = stopwatch(), count = 2000, text = 'abcdefghij'
46
+ if (live) {
47
+ const writer = await transient(g).begin('d', 'doc', 'body', 'stream')
48
+ for (let i = 0; i < count; i++) writer.append(text)
49
+ await writer.commit()
50
+ } else {
51
+ for (let i = 0; i < count; i++) {
52
+ await g.apply([{
53
+ entity: { eid: 'd' },
54
+ doc: { body: text.repeat(i + 1) },
55
+ }])
56
+ }
57
+ }
58
+ await Promise.resolve()
59
+ results[live ? 'transient' : 'apply'] = {
60
+ ...took(),
61
+ source: 'batch',
62
+ counts: {
63
+ deltas: count,
64
+ characters: count * text.length,
65
+ writes,
66
+ frames,
67
+ serializedCharacters: bytes,
68
+ },
69
+ }
70
+ }
71
+ return results
72
+ }
73
+
74
+ if (import.meta.main) {
75
+ await standaloneMain('harness-streaming')
76
+ }
@@ -0,0 +1,97 @@
1
+ /** Isolated session-switch benchmark. No default database is opened. */
2
+
3
+ import * as fs from 'jsr:@yaks/file@0.2.36/io'
4
+ import { remote } from './remote.ts'
5
+ import type { Bundle } from 'jsr:@yaks/graph@0.2.36'
6
+ /* @ts-types="npm:@types/react@19.3.0" */ import { createElement as node } from 'npm:react@19.3.0'
7
+ import { App } from './app.ts'
8
+ import { frontend } from './frontend.ts'
9
+ import { at, harness, mount } from './testing.ts'
10
+ import { type Sample, type Samples, stopwatch } from 'jsr:@yaks/benchmark@0.2.36'
11
+ import { standaloneMain } from '../../bench/standalone-main.ts'
12
+ import { fixture } from '../../bench/fixture.ts'
13
+
14
+ let seeded = fixture(async (path: string, count: number, depth: number) => {
15
+ let h = await harness(path)
16
+ try {
17
+ for (let i = 0; i < count; i++) {
18
+ let bundles: Bundle[] = [{
19
+ entity: { eid: 's' + i },
20
+ session: { id: 's' + i },
21
+ }]
22
+ let length = i < 2 ? depth : 10
23
+ for (let j = 0; j < length; j++) {
24
+ bundles.push({
25
+ entity: { eid: 'e' + i + '-' + j },
26
+ entry: { session: 's' + i, seq: j + 1 },
27
+ content: {
28
+ body: (j ? 'body ' : 'title ') + i + ' ' + 'x'.repeat(1000),
29
+ },
30
+ ...(j ? { output: { source: 'e' + i + '-0' } } : {}),
31
+ })
32
+ }
33
+ await h.g.apply(bundles)
34
+ }
35
+ } finally {
36
+ await h.close()
37
+ }
38
+ })
39
+
40
+ export async function measure(
41
+ args: string[] = [],
42
+ ): Promise<Record<string, Samples>> {
43
+ let directory = await fs.makeTempDir()
44
+ let count = Number(args[0] ?? 100)
45
+ let depth = Number(args[1] ?? 1000)
46
+ await seeded(directory + '/test.db', count, depth)
47
+ let r = await remote({
48
+ config: at(directory + '/test.db'),
49
+ cwd: directory,
50
+ fake: true,
51
+ })
52
+ let samples: Sample[] = []
53
+ let ui = frontend()
54
+ let screen = await mount(
55
+ () => node(App, { agent: r.agent, subscribe: r.subscribe, frontend: ui }),
56
+ 120,
57
+ 32,
58
+ )
59
+ let timerLast = performance.now(), delay = 0
60
+ let timer = setInterval(() => {
61
+ let now = performance.now()
62
+ delay = Math.max(delay, now - timerLast - 2)
63
+ timerLast = now
64
+ }, 2)
65
+ try {
66
+ // Match the user path: select in the UI graph, wait for the requested
67
+ // transcript to reach the painter. Sidebar text alone cannot satisfy this.
68
+ for (let i = 0; i < 12; i++) {
69
+ let which = i % 2
70
+ let start = performance.now(), took = stopwatch()
71
+ ui.patch({ selected: 's' + which, generation: i + 1 })
72
+ while (!screen.text().includes('body ' + which + ' ')) {
73
+ if (performance.now() - start > 30000) {
74
+ throw new Error('Switch never painted')
75
+ }
76
+ await new Promise((resolve) => setTimeout(resolve, 1))
77
+ }
78
+ samples.push(took())
79
+ }
80
+ return {
81
+ switch: samples.map((sample) => ({
82
+ ...sample,
83
+ details: { traffic: r.traffic, timerDelay: Math.max(0, delay) },
84
+ source: 'paint',
85
+ counts: { sessions: count, depth },
86
+ })),
87
+ }
88
+ } finally {
89
+ clearInterval(timer)
90
+ screen.free()
91
+ ui.close()
92
+ await r.close()
93
+ await fs.remove(directory, { recursive: true })
94
+ }
95
+ }
96
+
97
+ if (import.meta.main) await standaloneMain('harness-switch')
package/testing.ts ADDED
@@ -0,0 +1,177 @@
1
+ /** Harness graphs, runners and workspace fixtures that stay in process. */
2
+
3
+ import * as fs from 'jsr:@yaks/file@0.2.36/io'
4
+
5
+ import { type Runner, running } from 'jsr:@yaks/session@0.2.36'
6
+ import { compose, type Config } from 'jsr:@yaks/cli@0.2.36/host'
7
+ import { install } from 'jsr:@yaks/connections@0.2.36'
8
+ import { type Harness, hosted } from './store.ts'
9
+ /* @ts-types="npm:@types/react@19.3.0" */ import { type ComponentType } from 'npm:react@19.3.0'
10
+ import { mount as tui } from 'jsr:@yaks/tui@0.2.36/testing'
11
+ import { ansi } from '../tui/paint.ts'
12
+ import { dress } from './sheet.ts'
13
+ import { HARNESS } from './default.ts'
14
+
15
+ /** The packages a harness graph is made of in these tests: what a transcript
16
+ * is (@yaks/session), what it asks for and what answers (@yaks/tools,
17
+ * @yaks/context, @yaks/model and its providers), what a reply carries
18
+ * (@yaks/blob), the programs it starts (@yaks/process), the knocks a session
19
+ * running outside the graph hears (@yaks/notify), the sign-ins it keeps
20
+ * (@yaks/secrets, @yaks/connections), the runs its commits owe (@yaks/effects),
21
+ * the work it is doing, and the harness's own words; and which tables each
22
+ * entity is in (@yaks/archetype), so a read asks those tables alone, as the
23
+ * box's own graph does. In a config's order: a
24
+ * later package's computed property wins, so @yaks/session's claim is the step
25
+ * in a task's status it contributes. */
26
+ export let PLUGINS: string[] = [
27
+ '@yaks/kernel',
28
+ '@yaks/provenance',
29
+ '@yaks/id',
30
+ '@yaks/key',
31
+ '@yaks/alias',
32
+ '@yaks/secrets',
33
+ '@yaks/edge',
34
+ '@yaks/blob',
35
+ '@yaks/doc',
36
+ '@yaks/archetype',
37
+ '@yaks/effects',
38
+ '@yaks/task',
39
+ '@yaks/project',
40
+ '@yaks/session',
41
+ '@yaks/tools',
42
+ '@yaks/model',
43
+ '@yaks/openai',
44
+ '@yaks/openrouter',
45
+ '@yaks/claude',
46
+ '@yaks/process',
47
+ '@yaks/notify',
48
+ '@yaks/machine',
49
+ '@yaks/context',
50
+ '@yaks/connections',
51
+ '@yaks/mcp-client',
52
+ '@yaks/git',
53
+ '@yaks/persona',
54
+ '@yaks/topic',
55
+ '@yaks/harness',
56
+ '@yaks/sandbox',
57
+ ]
58
+
59
+ /** A config naming the graph at `db` (`:memory:` by default) made of
60
+ * {@link PLUGINS}; `lease` is how long a run it claims stands. */
61
+ export let at = (db = ':memory:', lease?: number): Config => ({
62
+ db,
63
+ plugins: PLUGINS,
64
+ ...lease ? { lease } : {},
65
+ })
66
+
67
+ /** That graph, composed and open, as a harness runs over it, with the
68
+ * integrations a process serving its effects installs on the way up (the
69
+ * OpenRouter sign-in goes through one); closing it closes the graph. */
70
+ export let harness = async (
71
+ db = ':memory:',
72
+ lease?: number,
73
+ ): Promise<Harness & { sql: import('jsr:@yaks/sql@0.2.36').Statements }> => {
74
+ let host = await compose(at(db, lease), ['graph'], undefined, {})
75
+ let g = host.graph
76
+ await g.apply(await install(g.read), { trusted: true })
77
+ await g.apply([
78
+ { entity: { eid: '$model' }, model: { name: 'gpt-6-astra' } },
79
+ { entity: { eid: '$provider' }, provider: { name: 'openai' } },
80
+ {
81
+ entity: { eid: '$serves' },
82
+ edge: { from: '$provider', to: '$model' },
83
+ serves: { name: 'gpt-6-astra' },
84
+ },
85
+ {
86
+ entity: { eid: HARNESS },
87
+ using: { provider: '$provider', model: '$model' },
88
+ },
89
+ ], { trusted: true })
90
+ let h = { ...hosted(host, () => host.close()), sql: host.storage.statements }
91
+ // Tests of model turns need a durable default intention, not a local provider.
92
+ h.sandboxes = {
93
+ request: async (id) => {
94
+ if (!(await g.get([id]))[0]) {
95
+ await g.apply([{
96
+ entity: { eid: id },
97
+ workspace: {},
98
+ sandbox: { provider: 'fixture' },
99
+ pending: {},
100
+ }])
101
+ }
102
+ return id
103
+ },
104
+ }
105
+ return h
106
+ }
107
+
108
+ /** The runner over `h`, lent `deps`, working its pool as an agent does;
109
+ * `stop()` leaves the pool once what it started has settled. */
110
+ export let working = (h: Harness, deps: Omit<Runner, 'holder'>) => {
111
+ let leave = new AbortController()
112
+ h.fx.handle(running(h.g, { holder: h.me, gone: h.gone, ...deps }))
113
+ let work = h.fx.work(h.g, leave.signal)
114
+ return {
115
+ stop: async () => {
116
+ leave.abort()
117
+ await h.fx.stop()
118
+ await work
119
+ },
120
+ }
121
+ }
122
+
123
+ /** A harness view on a fake terminal, dressed as the harness is. */
124
+ export let mount = (App: ComponentType, columns?: number, rows?: number) =>
125
+ tui(App, columns, rows, dress)
126
+
127
+ /** The escape that opens text wearing `name`, one of the harness's classes,
128
+ * in whatever theme it is dressed: what a test looks for in the bytes a
129
+ * view wrote, so it checks the class a part wears and not a colour. A class
130
+ * that paints nothing has no escape, and is refused. */
131
+ export let wears = (name: string): string => {
132
+ let open = ansi([{ text: '', style: dress[name] ?? {} }])
133
+ if (!open) throw new Error(`${name} paints nothing`)
134
+ return open.slice(0, -'\x1b[0m'.length)
135
+ }
136
+
137
+ /** A workspace reading only the fixture's temporary directory, without a shell. */
138
+ export let attachedWorkspace = async (h: Pick<Harness, 'g'>, root: string) => {
139
+ let workspace = crypto.randomUUID()
140
+ await h.g.apply([{ entity: { eid: workspace }, workspace: { root } }])
141
+ let inside = (path: string) => path == root || path.startsWith(root + '/')
142
+ let files: import('jsr:@yaks/machine@0.2.36').Workspace = {
143
+ start: () => Promise.reject(new Error('Fixture does not start commands')),
144
+ look: () => Promise.resolve(null),
145
+ tail: () => Promise.resolve([]),
146
+ kill: () => Promise.resolve(),
147
+ read: (path) =>
148
+ inside(path)
149
+ ? fs.readTextFile(path)
150
+ : Promise.reject(new Error('Outside fixture workspace')),
151
+ write: (path, body) =>
152
+ inside(path)
153
+ ? fs.writeTextFile(path, body)
154
+ : Promise.reject(new Error('Outside fixture workspace')),
155
+ stat: (paths) =>
156
+ Promise.all(paths.map(async (path) => {
157
+ if (!inside(path)) return { kind: 'missing' as const }
158
+ try {
159
+ let info = await fs.stat(path)
160
+ return {
161
+ kind: info.isDirectory ? 'directory' as const : 'file' as const,
162
+ canonical: await fs.realPath(path),
163
+ }
164
+ } catch (error) {
165
+ if (!fs.isNotFound(error)) throw error
166
+ let link = await fs.lstat(path).catch(() => undefined)
167
+ return {
168
+ kind: link?.isSymlink ? 'dangling' as const : 'missing' as const,
169
+ }
170
+ }
171
+ })),
172
+ }
173
+ return {
174
+ workspace,
175
+ workspaces: { connect: (_workspace: string) => Promise.resolve(files) },
176
+ }
177
+ }