@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/runtime.ts ADDED
@@ -0,0 +1,112 @@
1
+ /** Runtime inspection and explicit actions. Reads never wake a session; an
2
+ * action is a write, which whoever runs the transcript reads. */
3
+ import { type Bundle, type Comp, type Graph } from '@yaks/graph'
4
+ import { line } from '@yaks/query'
5
+ import { dispatchStatus, swap } from '@yaks/session/admission'
6
+ import type { Agent } from './agent.ts'
7
+
8
+ export type RuntimeAction = 'interrupt' | 'cancel-queued' | 'resume'
9
+ export let runtimeRows = async (
10
+ g: Graph,
11
+ session: string,
12
+ ): Promise<Bundle[]> => {
13
+ let [selected, children] = await Promise.all([
14
+ g.read(line`.session&.entity.eid=${session}&*`),
15
+ g.read(line`.session&.spawned.parent=${session}&*`),
16
+ ])
17
+ return await Promise.all([...selected, ...children].map(async (b) => {
18
+ let id = b.entity.eid
19
+ let [attempt] = await g.read(
20
+ line`.entry.session=${id}&.attempt.state=inflight&.order=-entry.seq&.limit=1&*`,
21
+ )
22
+ let [tail] = await g.read(
23
+ line`.entry.session=${id}&!notice&.order=-entry.seq&.limit=1&*`,
24
+ )
25
+ let [call] = await g.read(
26
+ line`.entry.session=${id}&.call&.order=-entry.seq&.limit=1`,
27
+ )
28
+ let waiting = call &&
29
+ !(await g.read(line`.result.call=${call.entity.eid}&.limit=1`)).length
30
+ // Project existing facts only; nothing is written back as duplicate status.
31
+ return {
32
+ ...b,
33
+ ...attempt ? { attempt: attempt.attempt } : {},
34
+ ...waiting ? { call: call.call } : {},
35
+ ...tail?.interrupted ? { interrupted: tail.interrupted } : {},
36
+ ...tail?.failed ? { failed: tail.failed } : {},
37
+ // A result carrying its call's refusal answered the call; the turn
38
+ // goes on.
39
+ ...tail?.refusal && !tail.result ? { refusal: tail.refusal } : {},
40
+ ...(attempt ?? tail)?.created
41
+ ? { updated: (attempt ?? tail)!.created }
42
+ : {},
43
+ }
44
+ }))
45
+ }
46
+
47
+ export let runtimeAction = async (
48
+ a: Pick<Agent, 'h' | 'send'>,
49
+ session: string,
50
+ action: RuntimeAction,
51
+ ): Promise<string> => {
52
+ let [row] = await a.h.g.read(line`.session&.entity.eid=${session}`)
53
+ if (!row) throw new Error('Session not found')
54
+ if (action == 'interrupt') {
55
+ let [attempt] = await a.h.g.read(
56
+ line`.entry.session=${session}&.attempt.state=inflight`,
57
+ )
58
+ if (!attempt) return 'No cancellable model request is running.'
59
+ // The run holding the transcript sees the withdrawal and aborts the
60
+ // request (@yaks/session run.ts).
61
+ await a.h.g.apply([{
62
+ entity: { eid: crypto.randomUUID() },
63
+ entry: { session },
64
+ notice: {},
65
+ cancel: { target: attempt.entity.eid },
66
+ }])
67
+ return 'Cancellation requested. Provider must acknowledge abort; independent processes are unchanged.'
68
+ }
69
+ if (action == 'cancel-queued') {
70
+ let [row] = await a.h.g.read(
71
+ line`.session&.entity.eid=${session}&*`,
72
+ )
73
+ if (!row) throw new Error('Session not found')
74
+ if (dispatchStatus(row) != 'queued') {
75
+ throw new Error('Only queued work can be cancelled here')
76
+ }
77
+ // Preconditions prevent cancelling a child that started while the view was open.
78
+ if (
79
+ !await swap(a.h.g, session, 'queued', { state: 'settled' }, [{
80
+ entity: { eid: crypto.randomUUID() },
81
+ entry: { session },
82
+ stop: {},
83
+ content: {
84
+ body:
85
+ 'Queued session cancelled by the user; task state is unchanged.',
86
+ },
87
+ }])
88
+ ) {
89
+ throw new Error('Only queued work can be cancelled here')
90
+ }
91
+ return 'Queued session cancelled. Its task was not cancelled.'
92
+ }
93
+ if (action != 'resume') throw new Error('Unknown runtime action')
94
+ let [tail] = await a.h.g.read(
95
+ line`.entry.session=${session}&!notice&.order=-entry.seq&.limit=1&*`,
96
+ )
97
+ let [ask] = await a.h.g.read(
98
+ line`.entry.session=${session}&.ask&.order=-entry.seq&.limit=1&*`,
99
+ )
100
+ let interrupted = ask?.interrupted != null &&
101
+ !(tail?.refusal && !tail.result) && !tail?.exception
102
+ if ((row.session as Comp).status != 'settled' && !interrupted) {
103
+ throw new Error(
104
+ 'Continue requires idle or interrupted work; other failures and stopped work are not replayed',
105
+ )
106
+ }
107
+ await a.send(
108
+ session,
109
+ 'Continue from the current state. Preserve completed work; do not repeat completed tool operations.',
110
+ )
111
+ return 'Continuation input submitted; the previous request was not replayed.'
112
+ }
@@ -0,0 +1,203 @@
1
+ import { Refused } from "@yaks/graph/errors";
2
+ // Session homes are convenience defaults over durable workspace identities.
3
+ // Sandbox intentions are recorded before provisioning; changing a default never
4
+ // disposes a resource or changes the target of a previously launched process.
5
+ import { CallError } from "@yaks/tools/errors";
6
+ import { derivedEid } from "@yaks/graph/identity";
7
+ import { settle } from "@yaks/machine";
8
+ import { targetFor, unlent } from "@yaks/machine/targets";
9
+ import { isAbsolute, relative, resolve } from 'node:path/posix';
10
+ export let homeAt = (workspace, cwd)=>({
11
+ ...workspace ? {
12
+ workspace
13
+ } : {},
14
+ ...cwd ? {
15
+ cwd
16
+ } : {}
17
+ });
18
+ export let sessionCwd = async (g, session, fallback)=>{
19
+ let home = (await g.get([
20
+ session
21
+ ], [
22
+ 'home'
23
+ ]))[0]?.home;
24
+ return home?.cwd == null ? fallback : String(home.cwd);
25
+ };
26
+ export let machines = (g, sandboxes, resolveHome, workspaces)=>{
27
+ let home = async (session, supplied)=>{
28
+ let owner = (await g.get([
29
+ session
30
+ ], [
31
+ 'session',
32
+ 'home'
33
+ ]))[0];
34
+ let at = supplied ?? owner?.home ?? {};
35
+ if (at.workspace) return at;
36
+ let prepared = owner ? await resolveHome?.(session) : undefined;
37
+ if (prepared?.workspace) at = {
38
+ ...at,
39
+ ...prepared
40
+ };
41
+ else {
42
+ if (!sandboxes) {
43
+ throw await unlent(g);
44
+ }
45
+ at = {
46
+ ...at,
47
+ workspace: await sandboxes.request(derivedEid('session-sandbox|' + session))
48
+ };
49
+ }
50
+ if (owner) await g.apply([
51
+ {
52
+ entity: {
53
+ eid: session
54
+ },
55
+ home: at
56
+ }
57
+ ]);
58
+ return at;
59
+ };
60
+ let lent = async (session, supplied)=>{
61
+ let at = await home(session, supplied);
62
+ if (!workspaces) {
63
+ throw new Refused('This host lends no workspace execution binding');
64
+ }
65
+ let target = await targetFor(g, undefined, at);
66
+ let record = (await g.get([
67
+ target.workspace
68
+ ], [
69
+ 'workspace'
70
+ ]))[0]?.workspace;
71
+ return {
72
+ machine: await workspaces.connect(target.workspace),
73
+ root: String(record.root),
74
+ cwd: target.cwd
75
+ };
76
+ };
77
+ let limits = {
78
+ taskDefaults: async (parent)=>{
79
+ let at = (await g.get([
80
+ parent
81
+ ], [
82
+ 'home'
83
+ ]))[0]?.home;
84
+ let source = at?.workspace ? (await g.get([
85
+ String(at.workspace)
86
+ ], [
87
+ 'sandbox'
88
+ ]))[0]?.sandbox : undefined;
89
+ return {
90
+ sandbox: {
91
+ ...source?.from ? {
92
+ from: source.from
93
+ } : {}
94
+ }
95
+ };
96
+ },
97
+ childProperties: {
98
+ workspace: {
99
+ type: 'string',
100
+ description: 'Existing workspace; a default target, not permissions.'
101
+ },
102
+ sandbox: {
103
+ type: 'object',
104
+ description: 'Request a separate sandbox. Omit to share the parent workspace.',
105
+ properties: {
106
+ provider: {
107
+ type: 'string'
108
+ },
109
+ from: {
110
+ type: 'string'
111
+ },
112
+ image: {
113
+ type: 'string'
114
+ }
115
+ },
116
+ additionalProperties: false
117
+ },
118
+ cwd: {
119
+ type: 'string',
120
+ description: 'Command directory in the target filesystem; relative to the parent directory.'
121
+ }
122
+ },
123
+ prepareChild: async ({ parent, child, args })=>{
124
+ if (args.machine != null) {
125
+ throw new CallError('workspace', 'Use workspace or sandbox, not machine');
126
+ }
127
+ if (args.workspace != null && args.sandbox != null) {
128
+ throw new CallError('workspace', 'Select workspace or sandbox, not both');
129
+ }
130
+ let inherited = args.workspace != null || args.sandbox != null ? (await g.get([
131
+ parent
132
+ ], [
133
+ 'home'
134
+ ]))[0]?.home ?? {} : await home(parent);
135
+ let at;
136
+ if (args.sandbox != null) {
137
+ if (typeof args.sandbox != 'object' || Array.isArray(args.sandbox)) {
138
+ throw new CallError('sandbox', 'sandbox must be a request object');
139
+ }
140
+ if (!sandboxes) {
141
+ throw await unlent(g);
142
+ }
143
+ at = {
144
+ workspace: await sandboxes.request(derivedEid('session-sandbox|' + child), args.sandbox)
145
+ };
146
+ } else if (args.workspace != null) {
147
+ if (typeof args.workspace != 'string') {
148
+ throw new CallError('workspace', 'workspace must be an entity id');
149
+ }
150
+ at = {
151
+ workspace: args.workspace
152
+ };
153
+ await targetFor(g, undefined, at);
154
+ } else at = {
155
+ ...inherited
156
+ };
157
+ if (args.cwd != null) {
158
+ if (typeof args.cwd != 'string' || !args.cwd || args.cwd.includes('\0')) throw new CallError('cwd', 'cwd must be a nonempty path');
159
+ let base = inherited.cwd;
160
+ if (!isAbsolute(args.cwd) && !base) {
161
+ throw new CallError('cwd', 'Relative cwd requires a parent command directory');
162
+ }
163
+ at.cwd = resolve(base ?? '/', args.cwd);
164
+ }
165
+ return {
166
+ home: at
167
+ };
168
+ }
169
+ };
170
+ return {
171
+ home,
172
+ homeAt,
173
+ limits,
174
+ machine: async (session, supplied)=>(await lent(session, supplied)).machine,
175
+ cwd: async (session)=>(await lent(session)).cwd,
176
+ // Resource disposal is explicit, never a consequence of transcript state.
177
+ release: async ()=>{},
178
+ files: async function*(session, paths) {
179
+ let loan = await lent(session);
180
+ for (let path of paths){
181
+ let target = resolve(loan.cwd, path);
182
+ let scoped = relative(loan.root, target);
183
+ if (!scoped || scoped == '..' || scoped.startsWith('../') || isAbsolute(scoped)) {
184
+ throw new CallError('path', 'Workspace file is outside its export root: ' + path);
185
+ }
186
+ let quote = (path)=>"'" + path.replaceAll("'", "'\\''") + "'";
187
+ // Resolve links on the target before reading, not on the graph host.
188
+ let id = await loan.machine.start(`set -eu; root=$(cd -- ${quote(loan.root)} && pwd -P); file=$(realpath -e -- ${quote(target)}); if [ "$root" != / ]; then case "$file" in "$root"/*) ;; *) exit 1;; esac; fi; test -f "$file"; base64 -- "$file"`, loan.cwd);
189
+ let proc = await settle(loan.machine, id);
190
+ if (!proc) throw new Error('Workspace export lost its process');
191
+ if (proc.exit?.code != 0) {
192
+ throw new Error('Workspace export failed: ' + (await loan.machine.tail(id, 40)).join('\n'));
193
+ }
194
+ let binary = atob((await loan.machine.tail(id, Number.MAX_SAFE_INTEGER)).join(''));
195
+ yield {
196
+ path: scoped,
197
+ bytes: Uint8Array.from(binary, (c)=>c.charCodeAt(0))
198
+ };
199
+ }
200
+ }
201
+ };
202
+ };
203
+ //# sourceMappingURL=session_machines.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session_machines.js","sources":["./session_machines.ts"],"names":[],"mappings":"AAAA,SAAS,OAAO,kCAAuC;AACvD,4EAA4E;AAC5E,gFAAgF;AAChF,8EAA8E;AAC9E,SAAS,SAAS,kCAAuC;AAEzD,SAAS,UAAU,oCAAyC;AAC5D,SAAuB,MAAM,6BAAkC;AAC/D,SAAS,SAAS,EAAE,MAAM,qCAA2D;AAErF,SAAS,UAAU,EAAE,QAAQ,EAAE,OAAO,QAAQ,kBAAiB;AAG/D,OAAO,IAAI,SAAS,CAAC,WAAoB,MAAuB,CAAC;IAC/D,GAAG,YAAY;MAAE;IAAU,IAAI,CAAC,CAAC;IACjC,GAAG,MAAM;MAAE;IAAI,IAAI,CAAC,CAAC;EACvB,CAAC,EAAC;AACF,OAAO,IAAI,aAAa,OACtB,GACA,SACA;EAEA,IAAI,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC;IAAC;GAAQ,EAAE;IAAC;GAAO,CAAC,CAAC,CA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EAAqE;QACrE,IAAI,KAAK,MAAM,KAAK,OAAO,CAAC,KAAK,CAC/B,CAAC,sBAAsB,EACrB,MAAM,KAAK,IAAI,EAChB,mCAAmC,EAClC,MAAM,QACP,mHAAmH,CAAC,EACrH,KAAK,GAAG;QAEV,IAAI,OAAO,MAAM,OAAO,KAAK,OAAO,EAAE;QACtC,IAAI,CAAC,MAAM,MAAM,IAAI,MAAM;QAC3B,IAAI,KAAK,IAAI,EAAE,QAAQ,GAAG;UACxB,MAAM,IAAI,MACR,8BACE,CAAC,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,IAAI,GAAG,EAAE,IAAI,CAAC;QAE7C;QACA,IAAI,SAAS,KACX,CAAC,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,IAAI,OAAO,gBAAgB,CAAC,EAAE,IAAI,CAAC;QAE9D,MAAM;UACJ,MAAM;UACN,OAAO,WAAW,IAAI,CAAC,QAAQ,CAAC,IAAM,EAAE,UAAU,CAAC;QACrD;MACF;IACF;EACF;AACF,EAAC"}
@@ -0,0 +1,216 @@
1
+ import { Refused } from '@yaks/graph/errors'
2
+ // Session homes are convenience defaults over durable workspace identities.
3
+ // Sandbox intentions are recorded before provisioning; changing a default never
4
+ // disposes a resource or changes the target of a previously launched process.
5
+ import { CallError } from '@yaks/tools/errors'
6
+ import type { Comp, Graph } from 'jsr:@yaks/graph@0.2.36'
7
+ import { derivedEid } from '@yaks/graph/identity'
8
+ import { type Machine, settle } from '@yaks/machine'
9
+ import { targetFor, unlent, type Workspaces } from '@yaks/machine/targets'
10
+ import type { ChildLimits } from 'jsr:@yaks/session@0.2.36'
11
+ import { isAbsolute, relative, resolve } from 'node:path/posix'
12
+ import type { Host } from 'jsr:@yaks/host@0.2.36'
13
+
14
+ export let homeAt = (workspace?: string, cwd?: string): Comp => ({
15
+ ...workspace ? { workspace } : {},
16
+ ...cwd ? { cwd } : {},
17
+ })
18
+ export let sessionCwd = async (
19
+ g: Graph,
20
+ session: string,
21
+ fallback?: string,
22
+ ): Promise<string | undefined> => {
23
+ let home = (await g.get([session], ['home']))[0]?.home as Comp | undefined
24
+ return home?.cwd == null ? fallback : String(home.cwd)
25
+ }
26
+ export type WorkspaceFile = { path: string; bytes: Uint8Array }
27
+ export let machines = (
28
+ g: Graph,
29
+ sandboxes?: Host['sandboxes'],
30
+ resolveHome?: Host['resolveHome'],
31
+ workspaces?: Workspaces,
32
+ ): SessionMachines => {
33
+ let home = async (session: string, supplied?: Comp): Promise<Comp> => {
34
+ let owner = (await g.get([session], ['session', 'home']))[0]
35
+ let at = supplied ?? owner?.home as Comp | undefined ?? {}
36
+ if (at.workspace) return at
37
+ let prepared = owner ? await resolveHome?.(session) : undefined
38
+ if (prepared?.workspace) at = { ...at, ...prepared }
39
+ else {
40
+ if (!sandboxes) {
41
+ throw await unlent(g)
42
+ }
43
+ at = {
44
+ ...at,
45
+ workspace: await sandboxes.request(
46
+ derivedEid('session-sandbox|' + session),
47
+ ),
48
+ }
49
+ }
50
+ if (owner) await g.apply([{ entity: { eid: session }, home: at }])
51
+ return at
52
+ }
53
+ let lent = async (session: string, supplied?: Comp) => {
54
+ let at = await home(session, supplied)
55
+ if (!workspaces) {
56
+ throw new Refused('This host lends no workspace execution binding')
57
+ }
58
+ let target = await targetFor(g, undefined, at)
59
+ let record = (await g.get([target.workspace], ['workspace']))[0]
60
+ ?.workspace as Comp
61
+ return {
62
+ machine: await workspaces.connect(target.workspace),
63
+ root: String(record.root),
64
+ cwd: target.cwd,
65
+ }
66
+ }
67
+ let limits: ChildLimits = {
68
+ taskDefaults: async (parent) => {
69
+ let at = (await g.get([parent], ['home']))[0]?.home as Comp | undefined
70
+ let source = at?.workspace
71
+ ? (await g.get([String(at.workspace)], ['sandbox']))[0]?.sandbox as
72
+ | Comp
73
+ | undefined
74
+ : undefined
75
+ return { sandbox: { ...source?.from ? { from: source.from } : {} } }
76
+ },
77
+ childProperties: {
78
+ workspace: {
79
+ type: 'string',
80
+ description: 'Existing workspace; a default target, not permissions.',
81
+ },
82
+ sandbox: {
83
+ type: 'object',
84
+ description:
85
+ 'Request a separate sandbox. Omit to share the parent workspace.',
86
+ properties: {
87
+ provider: { type: 'string' },
88
+ from: { type: 'string' },
89
+ image: { type: 'string' },
90
+ },
91
+ additionalProperties: false,
92
+ },
93
+ cwd: {
94
+ type: 'string',
95
+ description:
96
+ 'Command directory in the target filesystem; relative to the parent directory.',
97
+ },
98
+ },
99
+ prepareChild: async ({ parent, child, args }) => {
100
+ if (args.machine != null) {
101
+ throw new CallError(
102
+ 'workspace',
103
+ 'Use workspace or sandbox, not machine',
104
+ )
105
+ }
106
+ if (args.workspace != null && args.sandbox != null) {
107
+ throw new CallError(
108
+ 'workspace',
109
+ 'Select workspace or sandbox, not both',
110
+ )
111
+ }
112
+ let inherited = args.workspace != null || args.sandbox != null
113
+ ? (await g.get([parent], ['home']))[0]?.home as Comp | undefined ?? {}
114
+ : await home(parent)
115
+ let at: Comp
116
+ if (args.sandbox != null) {
117
+ if (typeof args.sandbox != 'object' || Array.isArray(args.sandbox)) {
118
+ throw new CallError('sandbox', 'sandbox must be a request object')
119
+ }
120
+ if (!sandboxes) {
121
+ throw await unlent(g)
122
+ }
123
+ at = {
124
+ workspace: await sandboxes.request(
125
+ derivedEid('session-sandbox|' + child),
126
+ args.sandbox as {
127
+ provider?: string
128
+ from?: string
129
+ image?: string
130
+ },
131
+ ),
132
+ }
133
+ } else if (args.workspace != null) {
134
+ if (typeof args.workspace != 'string') {
135
+ throw new CallError('workspace', 'workspace must be an entity id')
136
+ }
137
+ at = { workspace: args.workspace }
138
+ await targetFor(g, undefined, at)
139
+ } else at = { ...inherited }
140
+ if (args.cwd != null) {
141
+ if (
142
+ typeof args.cwd != 'string' || !args.cwd || args.cwd.includes('\0')
143
+ ) throw new CallError('cwd', 'cwd must be a nonempty path')
144
+ let base = inherited.cwd as string | undefined
145
+ if (!isAbsolute(args.cwd) && !base) {
146
+ throw new CallError(
147
+ 'cwd',
148
+ 'Relative cwd requires a parent command directory',
149
+ )
150
+ }
151
+ at.cwd = resolve(base ?? '/', args.cwd)
152
+ }
153
+ return { home: at }
154
+ },
155
+ }
156
+ return {
157
+ home,
158
+ homeAt,
159
+ limits,
160
+ machine: async (session, supplied) =>
161
+ (await lent(session, supplied)).machine,
162
+ cwd: async (session) => (await lent(session)).cwd,
163
+ // Resource disposal is explicit, never a consequence of transcript state.
164
+ release: async () => {},
165
+ files: async function* (session, paths) {
166
+ let loan = await lent(session)
167
+ for (let path of paths) {
168
+ let target = resolve(loan.cwd, path)
169
+ let scoped = relative(loan.root, target)
170
+ if (
171
+ !scoped || scoped == '..' || scoped.startsWith('../') ||
172
+ isAbsolute(scoped)
173
+ ) {
174
+ throw new CallError(
175
+ 'path',
176
+ 'Workspace file is outside its export root: ' + path,
177
+ )
178
+ }
179
+ let quote = (path: string) => "'" + path.replaceAll("'", "'\\''") + "'"
180
+ // Resolve links on the target before reading, not on the graph host.
181
+ let id = await loan.machine.start(
182
+ `set -eu; root=$(cd -- ${
183
+ quote(loan.root)
184
+ } && pwd -P); file=$(realpath -e -- ${
185
+ quote(target)
186
+ }); if [ "$root" != / ]; then case "$file" in "$root"/*) ;; *) exit 1;; esac; fi; test -f "$file"; base64 -- "$file"`,
187
+ loan.cwd,
188
+ )
189
+ let proc = await settle(loan.machine, id)
190
+ if (!proc) throw new Error('Workspace export lost its process')
191
+ if (proc.exit?.code != 0) {
192
+ throw new Error(
193
+ 'Workspace export failed: ' +
194
+ (await loan.machine.tail(id, 40)).join('\n'),
195
+ )
196
+ }
197
+ let binary = atob(
198
+ (await loan.machine.tail(id, Number.MAX_SAFE_INTEGER)).join(''),
199
+ )
200
+ yield {
201
+ path: scoped,
202
+ bytes: Uint8Array.from(binary, (c) => c.charCodeAt(0)),
203
+ }
204
+ }
205
+ },
206
+ }
207
+ }
208
+ export type SessionMachines = {
209
+ home: (session: string, supplied?: Comp) => Promise<Comp>
210
+ machine: (session: string, supplied?: Comp) => Promise<Machine>
211
+ cwd: (session: string) => Promise<string | undefined>
212
+ homeAt: typeof homeAt
213
+ release: (session: string) => Promise<void>
214
+ files: (session: string, paths: string[]) => AsyncIterable<WorkspaceFile>
215
+ limits: ChildLimits
216
+ }
package/sheet.js ADDED
@@ -0,0 +1,55 @@
1
+ // What the harness wears in a terminal: @yaks/ui's components and @yaks/tui's
2
+ // widgets, the portable views' classes, and its own (its text tones, its
3
+ // composer's border, its panels' selections), all in @yaks/ui's default
4
+ // theme.
5
+ import * as generic from "@yaks/render/views";
6
+ import { composition, sheet } from "@yaks/ui";
7
+ let own = (c)=>({
8
+ Title: {
9
+ bold: true
10
+ },
11
+ Dim: {
12
+ fg: c.dim,
13
+ dim: true
14
+ },
15
+ Key: {
16
+ fg: c.active
17
+ },
18
+ Accent: {
19
+ fg: c.info
20
+ },
21
+ Good: {
22
+ fg: c.positive
23
+ },
24
+ Task: {
25
+ fg: c.hues[4]
26
+ },
27
+ Warn: {
28
+ fg: c.caution
29
+ },
30
+ Bad: {
31
+ fg: c.negative
32
+ },
33
+ Rule: {
34
+ fg: c.dim
35
+ },
36
+ Composer_Border: {
37
+ fg: c.dim,
38
+ dim: true
39
+ },
40
+ Selection_Active: {
41
+ bg: c.card,
42
+ fg: c.accent
43
+ },
44
+ Session_Selected: {
45
+ bg: c.card
46
+ }
47
+ });
48
+ // Frozen, so the painter composes it with its widgets' defaults once rather
49
+ // than on every paint (@yaks/tui's `compose`).
50
+ export let dress = Object.freeze({
51
+ ...sheet(composition),
52
+ ...generic.sheet(composition.theme.colors),
53
+ ...own(composition.theme.colors)
54
+ });
55
+ //# sourceMappingURL=sheet.js.map
package/sheet.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sheet.js","sources":["./sheet.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,yEAAyE;AACzE,wEAAwE;AACxE,SAAS;AAET,YAAY,uCAA4C;AAExD,SAAsB,WAAW,EAAE,KAAK,wBAA6B;AAErE,IAAI,MAAM,CAAC,IAAqB,CAAC;IAC/B,OAAO;MAAE,MAAM;IAAK;IACpB,KAAK;MAAE,IAAI,EAAE,GAAG;MAAE,KAAK;IAAK;IAC5B,KAAK;MAAE,IAAI,EAAE,MAAM;IAAC;IACpB,QAAQ;MAAE,IAAI,EAAE,IAAI;IAAC;IACrB,MAAM;MAAE,IAAI,EAAE,QAAQ;IAAC;IACvB,MAAM;MAAE,IAAI,EAAE,IAAI,CAAC,EAAE;IAAC;IACtB,MAAM;MAAE,IAAI,EAAE,OAAO;IAAC;IACtB,KAAK;MAAE,IAAI,EAAE,QAAQ;IAAC;IACtB,MAAM;MAAE,IAAI,EAAE,GAAG;IAAC;IAClB,iBAAiB;MAAE,IAAI,EAAE,GAAG;MAAE,KAAK;IAAK;IACxC,kBAAkB;MAAE,IAAI,EAAE,IAAI;MAAE,IAAI,EAAE,MAAM;IAAC;IAC7C,kBAAkB;MAAE,IAAI,EAAE,IAAI;IAAC;EACjC,CAAC;AAED,4EAA4E;AAC5E,+CAA+C;AAC/C,OAAO,IAAI,QAAe,OAAO,MAAM,CAAC;EACtC,GAAG,MAAM,YAAY;EACrB,GAAG,QAAQ,KAAK,CAAC,YAAY,KAAK,CAAC,MAAM,CAAC;EAC1C,GAAG,IAAI,YAAY,KAAK,CAAC,MAAM,CAAC;AAClC,GAAE"}
package/sheet.ts ADDED
@@ -0,0 +1,31 @@
1
+ // What the harness wears in a terminal: @yaks/ui's components and @yaks/tui's
2
+ // widgets, the portable views' classes, and its own (its text tones, its
3
+ // composer's border, its panels' selections), all in @yaks/ui's default
4
+ // theme.
5
+
6
+ import * as generic from '@yaks/render/views'
7
+ import type { Sheet } from 'jsr:@yaks/tui@0.2.36'
8
+ import { type Colors, composition, sheet } from '@yaks/ui'
9
+
10
+ let own = (c: Colors): Sheet => ({
11
+ Title: { bold: true },
12
+ Dim: { fg: c.dim, dim: true },
13
+ Key: { fg: c.active },
14
+ Accent: { fg: c.info },
15
+ Good: { fg: c.positive },
16
+ Task: { fg: c.hues[4] }, // a mode, told apart from Good
17
+ Warn: { fg: c.caution },
18
+ Bad: { fg: c.negative },
19
+ Rule: { fg: c.dim },
20
+ Composer_Border: { fg: c.dim, dim: true },
21
+ Selection_Active: { bg: c.card, fg: c.accent },
22
+ Session_Selected: { bg: c.card },
23
+ })
24
+
25
+ // Frozen, so the painter composes it with its widgets' defaults once rather
26
+ // than on every paint (@yaks/tui's `compose`).
27
+ export let dress: Sheet = Object.freeze({
28
+ ...sheet(composition),
29
+ ...generic.sheet(composition.theme.colors),
30
+ ...own(composition.theme.colors),
31
+ })
package/shutdown.js ADDED
@@ -0,0 +1,7 @@
1
+ /** Expected refusal of new frontend work after shutdown admission closes. */ export class ShuttingDown extends Error {
2
+ constructor(){
3
+ super('Worker is shutting down');
4
+ this.name = 'ShuttingDown';
5
+ }
6
+ }
7
+ //# sourceMappingURL=shutdown.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shutdown.js","sources":["./shutdown.ts"],"names":[],"mappings":"AAAA,2EAA2E,GAC3E,OAAO,MAAM,qBAAqB;EAChC,aAAc;IACZ,KAAK,CAAC;IACN,IAAI,CAAC,IAAI,GAAG;EACd;AACF"}
package/shutdown.ts ADDED
@@ -0,0 +1,7 @@
1
+ /** Expected refusal of new frontend work after shutdown admission closes. */
2
+ export class ShuttingDown extends Error {
3
+ constructor() {
4
+ super('Worker is shutting down')
5
+ this.name = 'ShuttingDown'
6
+ }
7
+ }