@fungi.computer/shed 0.9.1 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -16
- package/backend/methods.ts +175 -37
- package/backend/observation.ts +67 -0
- package/backend/process-page.ts +25 -3
- package/backend/runs.ts +222 -30
- package/backend/test/key-processes.node.test.ts +586 -0
- package/backend/test/methods.test.ts +24 -4
- package/backend/test/observation.node.test.ts +421 -0
- package/backend/test/runs.node.test.ts +16 -6
- package/dist/assets/{index-DT5cobOX.js → index-DqaFSc_Z.js} +1 -1
- package/dist/index.html +1 -1
- package/package.json +6 -6
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { it, type TestContext } from "node:test";
|
|
3
|
+
import { DatabaseSync } from "node:sqlite";
|
|
4
|
+
import { Base64 } from "effect/encoding";
|
|
5
|
+
import * as z from "zod";
|
|
6
|
+
import type { HostActor } from "@fungi.computer/puffball/app-method-runtime";
|
|
7
|
+
import {
|
|
8
|
+
mintComputerProcessId,
|
|
9
|
+
type ComputerProcess,
|
|
10
|
+
} from "@fungi.computer/computer-contract";
|
|
11
|
+
import { runObservationSchema } from "@fungi.computer/agar/run-observation";
|
|
12
|
+
import { appBackend, type ShedMethodContext } from "../methods.js";
|
|
13
|
+
import { createShedRuns } from "../runs.js";
|
|
14
|
+
|
|
15
|
+
type Caller = Parameters<typeof appBackend.call>[3];
|
|
16
|
+
const keyOne: HostActor = { kind: "team-key", keyId: "key_one" };
|
|
17
|
+
const keyTwo: HostActor = { kind: "team-key", keyId: "key_two" };
|
|
18
|
+
const scope = { kind: "standalone" as const, tenant: "default" };
|
|
19
|
+
const as = (actor: HostActor): Caller => ({
|
|
20
|
+
scope,
|
|
21
|
+
actor,
|
|
22
|
+
computerId: "computer_one",
|
|
23
|
+
});
|
|
24
|
+
const started = z.looseObject({
|
|
25
|
+
process: z.looseObject({ id: z.string() }),
|
|
26
|
+
logPath: z.string(),
|
|
27
|
+
});
|
|
28
|
+
const bytesWindow = 131072;
|
|
29
|
+
|
|
30
|
+
/** One Computer whose processes the test edits, with a log of real bytes. */
|
|
31
|
+
function fixture(t: TestContext, seed?: (database: DatabaseSync) => void) {
|
|
32
|
+
const database = new DatabaseSync(":memory:");
|
|
33
|
+
t.after(() => {
|
|
34
|
+
database.close();
|
|
35
|
+
});
|
|
36
|
+
seed?.(database);
|
|
37
|
+
const sql = {
|
|
38
|
+
exec(query: string, ...values: (string | number | null)[]) {
|
|
39
|
+
const rows = database.prepare(query).all(...values);
|
|
40
|
+
return { toArray: () => rows };
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
const processes = new Map<string, ComputerProcess>();
|
|
44
|
+
const log = { size: 0 };
|
|
45
|
+
const behavior = { holdsOnStop: false };
|
|
46
|
+
const unexpected = () => Promise.reject(new Error("Unexpected binding call"));
|
|
47
|
+
let clock = 0;
|
|
48
|
+
const computer = {
|
|
49
|
+
ports: unexpected,
|
|
50
|
+
exec: unexpected,
|
|
51
|
+
preview: unexpected,
|
|
52
|
+
processStart: (input: {
|
|
53
|
+
command: string;
|
|
54
|
+
cwd?: string;
|
|
55
|
+
port?: number;
|
|
56
|
+
requestId?: string;
|
|
57
|
+
}) => {
|
|
58
|
+
clock += 1;
|
|
59
|
+
const process: ComputerProcess = {
|
|
60
|
+
id: mintComputerProcessId(),
|
|
61
|
+
port: input.port ?? null,
|
|
62
|
+
command: input.command,
|
|
63
|
+
cwd: input.cwd ?? null,
|
|
64
|
+
state: "running",
|
|
65
|
+
exitCode: null,
|
|
66
|
+
sync: "synced",
|
|
67
|
+
startedAt: clock,
|
|
68
|
+
endedAt: null,
|
|
69
|
+
endedReason: null,
|
|
70
|
+
};
|
|
71
|
+
processes.set(process.id, process);
|
|
72
|
+
return Promise.resolve(process);
|
|
73
|
+
},
|
|
74
|
+
processes: () =>
|
|
75
|
+
Promise.resolve({ processes: [...processes.values()].reverse() }),
|
|
76
|
+
processKill: (input: { id: string }) => {
|
|
77
|
+
const process = processes.get(input.id);
|
|
78
|
+
if (process === undefined) return unexpected();
|
|
79
|
+
if (process.state !== "running")
|
|
80
|
+
return Promise.resolve({ process, signalled: false });
|
|
81
|
+
if (behavior.holdsOnStop)
|
|
82
|
+
return Promise.resolve({ process, signalled: true });
|
|
83
|
+
const ended: ComputerProcess = {
|
|
84
|
+
...process,
|
|
85
|
+
state: "exited",
|
|
86
|
+
exitCode: 143,
|
|
87
|
+
endedAt: 99,
|
|
88
|
+
};
|
|
89
|
+
processes.set(input.id, ended);
|
|
90
|
+
return Promise.resolve({ process: ended, signalled: true });
|
|
91
|
+
},
|
|
92
|
+
read: (input: { path: string; byteOffset: number; byteLength: number }) => {
|
|
93
|
+
if (input.byteOffset > log.size)
|
|
94
|
+
return Promise.reject(new Error("Byte offset exceeds file size"));
|
|
95
|
+
const length = Math.min(input.byteLength, log.size - input.byteOffset);
|
|
96
|
+
return Promise.resolve({
|
|
97
|
+
path: input.path,
|
|
98
|
+
byteOffset: input.byteOffset,
|
|
99
|
+
content: Base64.encode(new Uint8Array(length).fill(120)),
|
|
100
|
+
encoding: "base64",
|
|
101
|
+
truncated: input.byteOffset + length < log.size,
|
|
102
|
+
});
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
const context: ShedMethodContext = {
|
|
106
|
+
runs: createShedRuns(sql),
|
|
107
|
+
env: { COMPUTER: computer },
|
|
108
|
+
};
|
|
109
|
+
return { database, context, processes, log, behavior };
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const observe = async (
|
|
113
|
+
f: ReturnType<typeof fixture>,
|
|
114
|
+
id: string,
|
|
115
|
+
actor: HostActor = keyOne,
|
|
116
|
+
cursor?: number,
|
|
117
|
+
) =>
|
|
118
|
+
appBackend.call(
|
|
119
|
+
"observe",
|
|
120
|
+
cursor === undefined ? { id } : { id, cursor },
|
|
121
|
+
f.context,
|
|
122
|
+
as(actor),
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
const start = async (
|
|
126
|
+
f: ReturnType<typeof fixture>,
|
|
127
|
+
requestId: string,
|
|
128
|
+
actor: HostActor = keyOne,
|
|
129
|
+
) =>
|
|
130
|
+
started.parse(
|
|
131
|
+
await appBackend.call(
|
|
132
|
+
"start",
|
|
133
|
+
{ command: "pnpm dev", requestId },
|
|
134
|
+
f.context,
|
|
135
|
+
as(actor),
|
|
136
|
+
),
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
/** A process the Computer reports that Shed never started, such as the terminal's. */
|
|
140
|
+
function outsider(
|
|
141
|
+
f: ReturnType<typeof fixture>,
|
|
142
|
+
change: Partial<ComputerProcess>,
|
|
143
|
+
) {
|
|
144
|
+
const process: ComputerProcess = {
|
|
145
|
+
id: mintComputerProcessId(),
|
|
146
|
+
port: null,
|
|
147
|
+
command: "ls",
|
|
148
|
+
cwd: null,
|
|
149
|
+
state: "exited",
|
|
150
|
+
exitCode: 0,
|
|
151
|
+
sync: "synced",
|
|
152
|
+
startedAt: 50,
|
|
153
|
+
endedAt: 60,
|
|
154
|
+
endedReason: null,
|
|
155
|
+
...change,
|
|
156
|
+
};
|
|
157
|
+
f.processes.set(process.id, process);
|
|
158
|
+
return process;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
void it("maps every Computer process state to a run, with cost null", async (t) => {
|
|
162
|
+
const f = fixture(t);
|
|
163
|
+
const cases: [
|
|
164
|
+
string,
|
|
165
|
+
Partial<ComputerProcess>,
|
|
166
|
+
{ state: string; reason?: string },
|
|
167
|
+
][] = [
|
|
168
|
+
[
|
|
169
|
+
"running",
|
|
170
|
+
{ state: "running", exitCode: null, endedAt: null },
|
|
171
|
+
{ state: "running" },
|
|
172
|
+
],
|
|
173
|
+
["exit 0", { exitCode: 0 }, { state: "completed" }],
|
|
174
|
+
["exit 2", { exitCode: 2 }, { state: "failed", reason: "nonzero_exit" }],
|
|
175
|
+
[
|
|
176
|
+
"idle-sleep",
|
|
177
|
+
{ exitCode: null, endedReason: "idle-sleep" },
|
|
178
|
+
{ state: "failed", reason: "computer_slept" },
|
|
179
|
+
],
|
|
180
|
+
[
|
|
181
|
+
"exit never observed",
|
|
182
|
+
{ exitCode: null },
|
|
183
|
+
{ state: "unknown", reason: "exit_unobserved" },
|
|
184
|
+
],
|
|
185
|
+
[
|
|
186
|
+
"uncertain",
|
|
187
|
+
{ state: "uncertain", exitCode: null, endedAt: null },
|
|
188
|
+
{ state: "unknown", reason: "computer_unreachable" },
|
|
189
|
+
],
|
|
190
|
+
];
|
|
191
|
+
for (const [name, change, expected] of cases) {
|
|
192
|
+
const process = outsider(f, change);
|
|
193
|
+
const run = runObservationSchema.parse(await observe(f, process.id));
|
|
194
|
+
assert.equal(run.state, expected.state, name);
|
|
195
|
+
assert.equal(run.reason, expected.reason, name);
|
|
196
|
+
assert.equal(run.source, "shed.process", name);
|
|
197
|
+
assert.equal(run.id, process.id, name);
|
|
198
|
+
assert.equal(run.cost, null, name);
|
|
199
|
+
assert.equal(run.log, null, name);
|
|
200
|
+
assert.deepEqual(run.outputs, [], name);
|
|
201
|
+
assert.equal(run.startedAt, 50, name);
|
|
202
|
+
assert.equal(run.endedAt, process.endedAt ?? undefined, name);
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
void it("reads a caller's stop as cancelled, and a stop still pending as running", async (t) => {
|
|
207
|
+
const f = fixture(t);
|
|
208
|
+
const own = await start(f, "r1");
|
|
209
|
+
assert.equal(
|
|
210
|
+
runObservationSchema.parse(await observe(f, own.process.id)).state,
|
|
211
|
+
"running",
|
|
212
|
+
);
|
|
213
|
+
await appBackend.call("stop", { id: own.process.id }, f.context, as(keyOne));
|
|
214
|
+
const run = runObservationSchema.parse(await observe(f, own.process.id));
|
|
215
|
+
assert.equal(run.state, "cancelled");
|
|
216
|
+
assert.equal(run.reason, "stopped");
|
|
217
|
+
assert.equal(run.endedAt, 99);
|
|
218
|
+
|
|
219
|
+
f.behavior.holdsOnStop = true;
|
|
220
|
+
const held = await start(f, "r2");
|
|
221
|
+
await appBackend.call("stop", { id: held.process.id }, f.context, as(keyOne));
|
|
222
|
+
const stopping = runObservationSchema.parse(
|
|
223
|
+
await observe(f, held.process.id),
|
|
224
|
+
);
|
|
225
|
+
assert.equal(stopping.state, "running");
|
|
226
|
+
assert.equal(stopping.reason, "stopping");
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
void it("does not read a stop that signalled nothing as cancelled", async (t) => {
|
|
230
|
+
const f = fixture(t);
|
|
231
|
+
const own = await start(f, "r1");
|
|
232
|
+
const running = f.processes.get(own.process.id);
|
|
233
|
+
assert.ok(running);
|
|
234
|
+
f.processes.set(own.process.id, {
|
|
235
|
+
...running,
|
|
236
|
+
state: "exited",
|
|
237
|
+
exitCode: 0,
|
|
238
|
+
endedAt: 9,
|
|
239
|
+
});
|
|
240
|
+
const reply = z
|
|
241
|
+
.looseObject({ signalled: z.boolean() })
|
|
242
|
+
.parse(
|
|
243
|
+
await appBackend.call(
|
|
244
|
+
"stop",
|
|
245
|
+
{ id: own.process.id },
|
|
246
|
+
f.context,
|
|
247
|
+
as(keyOne),
|
|
248
|
+
),
|
|
249
|
+
);
|
|
250
|
+
assert.equal(reply.signalled, false);
|
|
251
|
+
assert.equal(
|
|
252
|
+
runObservationSchema.parse(await observe(f, own.process.id)).state,
|
|
253
|
+
"completed",
|
|
254
|
+
);
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
void it("reads a restarted process as cancelled and links the new run by parentId", async (t) => {
|
|
258
|
+
const f = fixture(t);
|
|
259
|
+
const parent = await start(f, "r1");
|
|
260
|
+
const restarted = z
|
|
261
|
+
.looseObject({
|
|
262
|
+
process: z.looseObject({ id: z.string() }),
|
|
263
|
+
parentId: z.string(),
|
|
264
|
+
})
|
|
265
|
+
.parse(
|
|
266
|
+
await appBackend.call(
|
|
267
|
+
"restart",
|
|
268
|
+
{ id: parent.process.id, requestId: "again" },
|
|
269
|
+
f.context,
|
|
270
|
+
as(keyOne),
|
|
271
|
+
),
|
|
272
|
+
);
|
|
273
|
+
const old = runObservationSchema.parse(await observe(f, parent.process.id));
|
|
274
|
+
assert.equal(old.state, "cancelled");
|
|
275
|
+
const next = runObservationSchema.parse(
|
|
276
|
+
await observe(f, restarted.process.id),
|
|
277
|
+
);
|
|
278
|
+
assert.equal(next.state, "running");
|
|
279
|
+
assert.equal(next.parentId, parent.process.id);
|
|
280
|
+
assert.equal(old.parentId, undefined);
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
void it("walks a log with the returned cursor until eof, 128 KiB at a time", async (t) => {
|
|
284
|
+
const f = fixture(t);
|
|
285
|
+
const own = await start(f, "r1");
|
|
286
|
+
f.log.size = bytesWindow * 2 + 5;
|
|
287
|
+
const steps: { cursor: number; size: number; eof: boolean }[] = [];
|
|
288
|
+
let cursor = 0;
|
|
289
|
+
for (let step = 0; step < 10; step++) {
|
|
290
|
+
const run = runObservationSchema.parse(
|
|
291
|
+
await observe(f, own.process.id, keyOne, cursor),
|
|
292
|
+
);
|
|
293
|
+
assert.ok(run.log, "an owned process carries a log position");
|
|
294
|
+
assert.ok(run.log.cursor - cursor <= bytesWindow);
|
|
295
|
+
steps.push(run.log);
|
|
296
|
+
cursor = run.log.cursor;
|
|
297
|
+
if (run.log.eof) break;
|
|
298
|
+
}
|
|
299
|
+
assert.deepEqual(steps, [
|
|
300
|
+
{ cursor: bytesWindow, size: bytesWindow, eof: false },
|
|
301
|
+
{ cursor: bytesWindow * 2, size: bytesWindow * 2, eof: false },
|
|
302
|
+
{ cursor: bytesWindow * 2 + 5, size: bytesWindow * 2 + 5, eof: true },
|
|
303
|
+
]);
|
|
304
|
+
const again = runObservationSchema.parse(
|
|
305
|
+
await observe(f, own.process.id, keyOne, cursor),
|
|
306
|
+
);
|
|
307
|
+
assert.deepEqual(again.log, { cursor, size: cursor, eof: true });
|
|
308
|
+
assert.deepEqual(again.outputs, [{ kind: "log", ref: own.logPath }]);
|
|
309
|
+
const empty = fixture(t);
|
|
310
|
+
const fresh = await start(empty, "r1");
|
|
311
|
+
assert.deepEqual(
|
|
312
|
+
runObservationSchema.parse(await observe(empty, fresh.process.id)).log,
|
|
313
|
+
{ cursor: 0, size: 0, eof: true },
|
|
314
|
+
);
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
void it("keeps another caller's log and records out of an observation", async (t) => {
|
|
318
|
+
const f = fixture(t);
|
|
319
|
+
const own = await start(f, "r1");
|
|
320
|
+
f.log.size = 10;
|
|
321
|
+
const other = runObservationSchema.parse(
|
|
322
|
+
await observe(f, own.process.id, keyTwo),
|
|
323
|
+
);
|
|
324
|
+
assert.equal(other.log, null);
|
|
325
|
+
assert.deepEqual(other.outputs, []);
|
|
326
|
+
assert.deepEqual(await observe(f, mintComputerProcessId()), {
|
|
327
|
+
error: "not_found",
|
|
328
|
+
});
|
|
329
|
+
assert.deepEqual(
|
|
330
|
+
await appBackend.call("observe", { id: own.process.id }, f.context, {
|
|
331
|
+
scope,
|
|
332
|
+
actor: keyOne,
|
|
333
|
+
computerId: null,
|
|
334
|
+
}),
|
|
335
|
+
{ error: "not_granted" },
|
|
336
|
+
);
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
void it("lists each process with its run, and the same run observe returns", async (t) => {
|
|
340
|
+
const f = fixture(t);
|
|
341
|
+
const own = await start(f, "r1");
|
|
342
|
+
const other = outsider(f, { exitCode: 3 });
|
|
343
|
+
const page = z
|
|
344
|
+
.object({
|
|
345
|
+
processes: z.array(
|
|
346
|
+
z.looseObject({
|
|
347
|
+
id: z.string(),
|
|
348
|
+
controllable: z.boolean(),
|
|
349
|
+
run: runObservationSchema,
|
|
350
|
+
}),
|
|
351
|
+
),
|
|
352
|
+
})
|
|
353
|
+
.parse(await appBackend.call("listProcesses", {}, f.context, as(keyOne)));
|
|
354
|
+
assert.deepEqual(
|
|
355
|
+
page.processes.map((row) => [row.id, row.controllable, row.run.state]),
|
|
356
|
+
[
|
|
357
|
+
[other.id, false, "failed"],
|
|
358
|
+
[own.process.id, true, "running"],
|
|
359
|
+
],
|
|
360
|
+
);
|
|
361
|
+
for (const row of page.processes) {
|
|
362
|
+
assert.equal(row.run.log, null);
|
|
363
|
+
assert.equal(row.run.cost, null);
|
|
364
|
+
assert.equal(row.run.id, row.id);
|
|
365
|
+
}
|
|
366
|
+
const observed = runObservationSchema.parse(
|
|
367
|
+
await observe(f, other.id, keyOne),
|
|
368
|
+
);
|
|
369
|
+
assert.deepEqual(observed, page.processes[0]?.run);
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
void it("adds stoppedAt in place and reads an old row as not cancelled", async (t) => {
|
|
373
|
+
const process = mintComputerProcessId();
|
|
374
|
+
const f = fixture(t, (database) => {
|
|
375
|
+
// A row as written before ports, restarts and stops were recorded.
|
|
376
|
+
database.exec(
|
|
377
|
+
"CREATE TABLE shed_native_process_claims (requestKey TEXT PRIMARY KEY, computerId TEXT NOT NULL, command TEXT NOT NULL, cwd TEXT, processId TEXT, phase TEXT NOT NULL, startedAt INTEGER, exitCode INTEGER, logPath TEXT NOT NULL, gitAccess TEXT)",
|
|
378
|
+
);
|
|
379
|
+
database
|
|
380
|
+
.prepare(
|
|
381
|
+
"INSERT INTO shed_native_process_claims (requestKey,computerId,command,cwd,processId,phase,startedAt,exitCode,logPath,gitAccess) VALUES (?,?,?,?,?,?,?,?,?,?)",
|
|
382
|
+
)
|
|
383
|
+
.run(
|
|
384
|
+
JSON.stringify([keyOne, "start", "old"]),
|
|
385
|
+
"computer_one",
|
|
386
|
+
"pnpm dev",
|
|
387
|
+
null,
|
|
388
|
+
process,
|
|
389
|
+
"running",
|
|
390
|
+
5,
|
|
391
|
+
null,
|
|
392
|
+
"/workspace/.fungi/runs/old/out.log",
|
|
393
|
+
null,
|
|
394
|
+
);
|
|
395
|
+
});
|
|
396
|
+
f.processes.set(process, {
|
|
397
|
+
id: process,
|
|
398
|
+
port: null,
|
|
399
|
+
command: "pnpm dev",
|
|
400
|
+
cwd: null,
|
|
401
|
+
state: "exited",
|
|
402
|
+
exitCode: 0,
|
|
403
|
+
sync: "synced",
|
|
404
|
+
startedAt: 5,
|
|
405
|
+
endedAt: 8,
|
|
406
|
+
endedReason: null,
|
|
407
|
+
});
|
|
408
|
+
const columns = z
|
|
409
|
+
.array(z.object({ name: z.string() }))
|
|
410
|
+
.parse(
|
|
411
|
+
f.database.prepare("PRAGMA table_info(shed_native_process_claims)").all(),
|
|
412
|
+
)
|
|
413
|
+
.map((column) => column.name);
|
|
414
|
+
assert.ok(columns.includes("stoppedAt"));
|
|
415
|
+
const run = runObservationSchema.parse(await observe(f, process));
|
|
416
|
+
assert.equal(run.state, "completed");
|
|
417
|
+
assert.equal(run.reason, undefined);
|
|
418
|
+
assert.deepEqual(run.outputs, [
|
|
419
|
+
{ kind: "log", ref: "/workspace/.fungi/runs/old/out.log" },
|
|
420
|
+
]);
|
|
421
|
+
});
|
|
@@ -435,7 +435,7 @@ void it("requires the host key and Computer, and refuses to restart after a lost
|
|
|
435
435
|
const input = { command: "printf once" };
|
|
436
436
|
await assert.rejects(
|
|
437
437
|
appBackend.call("run", input, context, caller),
|
|
438
|
-
/host idempotency key/,
|
|
438
|
+
/request id or host idempotency key/,
|
|
439
439
|
);
|
|
440
440
|
await assert.rejects(
|
|
441
441
|
appBackend.call("run", input, context, {
|
|
@@ -984,6 +984,9 @@ void it("drops the superseded claim table and keeps a current claim across reope
|
|
|
984
984
|
"exitCode",
|
|
985
985
|
"logPath",
|
|
986
986
|
"gitAccess",
|
|
987
|
+
"port",
|
|
988
|
+
"parentId",
|
|
989
|
+
"stoppedAt",
|
|
987
990
|
]);
|
|
988
991
|
// Reopening never drops the current table: the claim replays, no new start.
|
|
989
992
|
assert.deepEqual(
|
|
@@ -1184,7 +1187,6 @@ void it("starts a declared port and binds retry identity to the native process p
|
|
|
1184
1187
|
/identity conflicts/,
|
|
1185
1188
|
);
|
|
1186
1189
|
for (const selector of [
|
|
1187
|
-
{ requestId: "guest-selected" },
|
|
1188
1190
|
{ requestScope: "installation:other" },
|
|
1189
1191
|
{ computerId: "computer-other" },
|
|
1190
1192
|
{ method: "guest-selected" },
|
|
@@ -1203,6 +1205,17 @@ void it("starts a declared port and binds retry identity to the native process p
|
|
|
1203
1205
|
appBackend.call("run", input, restored, caller),
|
|
1204
1206
|
/Unrecognized key/,
|
|
1205
1207
|
);
|
|
1208
|
+
// A requestId is the caller's own replay key. The host's key outranks it, so
|
|
1209
|
+
// it neither selects another process nor reaches the Computer.
|
|
1210
|
+
assert.deepEqual(
|
|
1211
|
+
await appBackend.call(
|
|
1212
|
+
"start",
|
|
1213
|
+
{ ...input, requestId: "guest-selected" },
|
|
1214
|
+
restored,
|
|
1215
|
+
caller,
|
|
1216
|
+
),
|
|
1217
|
+
result,
|
|
1218
|
+
);
|
|
1206
1219
|
assert.equal(requests.length, 1);
|
|
1207
1220
|
});
|
|
1208
1221
|
|
|
@@ -1480,10 +1493,7 @@ void it("refuses the same member raw-key log on a different Computer with zero r
|
|
|
1480
1493
|
assert.equal(reads, 0);
|
|
1481
1494
|
});
|
|
1482
1495
|
|
|
1483
|
-
const refusedActors: HostActor[] = [
|
|
1484
|
-
{ kind: "agent", agentId: "agent_other" },
|
|
1485
|
-
{ kind: "team-key", keyId: "key_other" },
|
|
1486
|
-
];
|
|
1496
|
+
const refusedActors: HostActor[] = [{ kind: "agent", agentId: "agent_other" }];
|
|
1487
1497
|
for (const actor of refusedActors)
|
|
1488
1498
|
for (const method of ["start", "run"]) {
|
|
1489
1499
|
void it(`refuses ${actor.kind} ${method} before a native start or dangling claim`, async (t) => {
|
|
@@ -1739,4 +1739,4 @@ ${e.join(`
|
|
|
1739
1739
|
`),this.draw()],{kind:`interrupt`},`^C`);let t=this.#w();return this.#t={text:``,cursor:0},this.#p([R9(this.#S()),z9(`${t.ansi}^C\r\n`),this.draw()],P9,`${t.plain}^C`)}#v(e,t){let n=this.#n??``;if(e.key===`Escape`)return this.#n=null,this.#m();if(e.key===`Enter`||t===`r`&&!e.shiftKey){let t=this.#e.search(n,this.#t.text);return t!==null&&(this.#t={text:t,cursor:t.length}),e.key===`Enter`&&(this.#n=null),this.#m()}return e.key===`Backspace`?(this.#n=A9({text:n,cursor:n.length},{type:`backspace`}).text,this.#m()):this.#f()}#y(){let{text:e,cursor:t}=this.#t;if(t!==e.length)return this.#f();let n=xLe(e);return n===null?this.#f():`kind`in n?this.#b(n.message):n.length===1?(this.#i=null,this.#h(`${n[0].name} `)):this.#i===e?(this.#i=null,this.#b(n.map(e=>`${e.name}${e.where===`full`?` ⚡`:``}`).join(` · `))):(this.#i=e,this.#f())}#b(e){let t=this.#w();return this.#p([R9(this.#S()),z9(`${t.ansi}\r\n${L9(e)}\r\n`),this.draw()],P9,`${t.plain}\n${e}`)}#x(){let{text:e}=this.#t,t=this.#w(),n=R9(this.#S());if(e.trim().length===0)return this.#p([n,z9(`${t.ansi}\r\n`),this.draw()]);let r=e9(e);if(r.kind!==`command`&&r.kind!==`invalid`){if(this.#t={text:``,cursor:0},r.kind===`light`){let e=`Already in the light shell.`;return this.#p([n,z9(`${t.ansi}\r\n${e}\r\n`),this.draw()],P9,`${t.plain}\n${e}`)}return this.#e=new O9,this.#r=`closed`,this.#p([n,z9(`${t.ansi}\r\n`)],{kind:`exit`},t.plain)}let i=r.kind===`command`?r.route:{where:`invalid`,message:r.message};if(i.where===`invalid`)return this.#p([n,z9(`${t.ansi}\r\n${L9(i.message)}\r\n`),this.draw()],P9,`${t.plain}\n${i.message}`);this.#e.record(e),this.#t={text:``,cursor:0};let a=r.kind===`command`?r.command:e,o={command:a,cwd:this.#a,env:this.#o};if(i.where===`full`){if(this.#r=`full`,this.#u)return this.#p([n],{kind:`escalate`,request:o},t.plain);let e=`Starting the full shell for ${a}…`;return this.#p([n,z9(`${t.ansi}\r\n${e}\r\n`)],{kind:`escalate`,request:o},`${t.plain}\n${e}`)}return this.#r=`busy`,this.#p([n,z9(`${t.ansi}\r\n`)],{kind:`run`,request:o},t.plain)}#S(){let e=this.#c>0?`${j9}[${String(this.#c)}A`:``;return this.#c=0,`${e}\r${j9}[J`}#C(){let e=this.#s===0?`✓`:`✗ ${String(this.#s)}`,t=` fungi@${this.#d} ${this.#a} `;return{ansi:`${I9(this.#s===0?`32`:`31`,e)}${t}${I9(`36`,`◦light`)} ➜ `,plain:`${e}${t}◦light ➜ `}}#w(){let e=this.#C();return{ansi:e.ansi+this.#t.text,plain:e.plain+this.#t.text}}#T(e){let t=this.#l,{text:n,cursor:r}=this.#t,i,a,o=``;if(this.#n!==null){let e=`(reverse-i-search)'${this.#n}': `;i={ansi:I9(`2`,e),plain:e},a=n}else{i=this.#C();let e=this.route,t=e.where===`invalid`?`31;4:3`:e.where===`full`?`33`:`32`;a=n.length>0?I9(t,n):``,o=this.#g()??``}let s=D9(i.plain),c=s+D9(n)+D9(o),l=s+D9(n.slice(0,r)),u=i.ansi+a+(o?I9(`2`,o):``);c>0&&c%t===0&&(u+=` \r`);let d=B9(c,t),f=B9(l,t);return e&&(d.row>f.row&&(u+=`${j9}[${String(d.row-f.row)}A`),u+=`${j9}[${String(f.col+1)}G`),this.#c=f.row,u}},gRe=300,_Re=262144,vRe=class{#e;#t;#n=`light`;#r=[];#i=0;#a=!1;#o=null;#s;#c=!1;#l=!1;#u=new TextEncoder;constructor(e,{computerName:t,columns:n}){this.#e=e,this.#t=new hRe({computerName:t,columns:n})}start(){this.#e.live(this.#t.draw().text),this.#g()}repaint(e){this.#t.setColumns(e),this.#n===`light`&&this.#t.phase===`idle`&&this.#e.live(this.#t.draw().text)}setColumns(e){this.#t.setColumns(e)}setSessionOpen(e){this.#a=e,this.#t.setFullReady(e)}key(e){if(this.#n!==`light`)return!1;let t=this.#t.key(e);return this.#f(t),t.consumed}input(e){return this.#n===`light`&&(this.#f(this.#t.input(e)),!0)}output(e){if(this.#n===`full`){this.#e.commit(e);return}for(this.#r.push(e),this.#i+=e.byteLength;this.#i>_Re&&this.#r.length>1;)this.#i-=this.#r.shift()?.byteLength??0}ptyEnded(){this.setSessionOpen(!1),this.#d(),this.#n===`full`&&(this.#n=`light`,this.#f(this.#t.returnFromFull()),this.#e.connect().catch(e=>{this.#l?wm(e):Cm(`Could not reconnect the terminal. Try again.`,e)}))}reopen(){this.#f(this.#t.reopen())}dispose(){this.#l=!0,this.#o?.abort(),clearTimeout(this.#s)}#d(){this.#r=[],this.#i=0}#f(e){if(!this.#l){e.effect.kind===`clear`&&this.#e.forget();for(let t of e.chunks)t.record?this.#e.commit(this.#u.encode(t.text)):this.#e.live(t.text);switch(e.log.length>0&&this.#e.log(e.log),e.effect.kind){case`run`:this.#p(e.effect.request);break;case`escalate`:this.#m(e.effect.request.command);break;case`interrupt`:this.#o?.abort(),this.#h(!1)}this.#g()}}#p(e){let t=new AbortController;this.#o=t,this.#s=setTimeout(()=>{this.#h(!0)},gRe),this.#e.runLight(e,t.signal).then(e=>{t.signal.aborted||this.#f(this.#t.finish(e))}).catch(e=>{if(t.signal.aborted){wm(e);return}Cm(`Could not run the command. Try again.`,e),this.#f(this.#t.fail(`light`))}).finally(()=>{this.#o===t&&(this.#o=null,this.#h(!1))})}#m(e){this.#n=`full`;let t=()=>this.#e.send(`${e}\n`),n=e=>{if(this.#l){wm(e);return}Cm(`Could not open the full shell. Try again.`,e),this.#n===`full`&&(this.#n=`light`,this.#d(),this.#f(this.#t.fail(`full`)))};if(this.#a){for(let e of this.#r)this.#e.commit(e);this.#d(),t().catch(n);return}this.#d(),this.#e.connect().then(t).catch(n)}#h(e){clearTimeout(this.#s),this.#c!==e&&(this.#c=e,this.#g())}#g(){if(this.#l)return;let e=this.#t.route;this.#e.view({phase:this.#t.phase,route:e.where,routeLabel:e.where===`invalid`?`invalid: ${e.message}`:e.where===`full`?`full shell`:`light shell`,busy:this.#c&&this.#t.phase===`busy`})}};function V9(e){return e.replace(/\p{Cc}/gu,` `)}function H9(e,t){let n=[],r=``;for(let i of e){let e=r?`${r} · ${i}`:i;r&&e.length>t?(n.push(r),r=i):r=e}return n.push(r),n.join(`
|
|
1740
1740
|
`)}function yRe({cols:e,information:t,light:n=!1}){let r=t.teamName!==`unconfigured`,i=[V9(t.computerName)];return r&&i.push(`Team ${V9(t.teamName)}`),t.modelDoor!==`unconfigured`&&t.modelDoor!==t.computerName&&i.push(`model: ${V9(t.modelDoor)}`),i.push(`up ${String(Math.floor(t.uptimeSeconds/60))}m`),t.version!==`0.0.0`&&i.push(`${r?`Fungi`:`Computer`} ${V9(t.version)}`),`${H9(i,e)}\n${n?H9([`light shell`,`instant`,`try: ls`,`rg TODO`,`jq . package.json`],e):`try: ls · pwd · node -v · exit`}\n\n`.replace(/\r?\n/g,`\r
|
|
1741
1741
|
`)}function bRe(e){return`Connecting to ${V9(e)}…\r\n`}var xRe=4194304,U9=13,W9={phase:`idle`,route:`light`,routeLabel:`light shell`,busy:!1};function SRe({app:e,computerId:t,screen:n,light:r,onStatusChange:i,onTerminalReady:a,openRuntimeSetup:o}){let[s,c]=(0,I.useState)(!1),[l,u]=(0,I.useState)(0),d=(0,I.useRef)(null),f=(0,I.useRef)(null),p=(0,I.useRef)(null),m=(0,I.useRef)(null),h=(0,I.useRef)(null),g=(0,I.useRef)([]),_=(0,I.useRef)(0),v=(0,I.useRef)(null),y=(0,I.useRef)(null),[b,x]=(0,I.useState)(!1),[S,C]=(0,I.useState)(`starting`),[w,T]=(0,I.useState)(0),[E,D]=(0,I.useState)(null),[O,k]=(0,I.useState)(null);(0,I.useEffect)(()=>{i?.({name:E,state:S,information:O})},[E,S,O,i]),(0,I.useEffect)(()=>{if(!b||!a)return;let e=()=>{let e=p.current;if(!e)throw Error(`Shed terminal is no longer mounted`);return e};h.current??={write:(t,n)=>{e().write(t,n)},reset:()=>{let t=e();t.reset(),t.write(`\x1B[2J\x1B[3J\x1B[H`)},resize:(t,n)=>{e().resize(t,n)},paint:()=>Promise.resolve().then(()=>{let t=e(),{renderer:n,wasmTerm:r}=t;if(!n||!r)throw Error(`Shed terminal renderer is unavailable`);n.render(r,!0,t.getViewportY(),t)})},a(h.current)},[b,a]);let A=(0,I.useRef)(r);A.current=r;let j=(0,I.useRef)(null),[M,N]=(0,I.useState)(W9),[P,ee]=(0,I.useState)([]),te=(0,I.useRef)(0),ne=r!==void 0,re=(0,I.useCallback)(e=>{for(g.current.push(e),_.current+=e.byteLength;_.current>xRe&&g.current.length>1;){let e=g.current.shift();_.current-=e?.byteLength??0}p.current?.write(e)},[]);(0,I.useEffect)(()=>{let e=!0,t=0,n,r,i,a=()=>{let t=p.current,n=m.current,r=d.current,a=f.current;if(!e||!t||!n||!r||!a||r.clientWidth===0||r.clientHeight===0)return;let o=getComputedStyle(a),s=parseFloat(o.paddingLeft)+parseFloat(o.paddingRight),c=parseFloat(o.paddingTop)+parseFloat(o.paddingBottom);if(a.clientWidth<=s||a.clientHeight<=c)return;let l=n.proposeDimensions();if(!l)return;if(t.cols!==l.cols||t.rows!==l.rows){if(t.cols!==l.cols&&_.current>0&&i){i(l);return}t.resize(l.cols,l.rows),j.current?.setColumns(t.cols)}x(!0);let u=y.current;u&&u.resize({cols:Math.max(2,t.cols),rows:Math.max(2,t.rows)}).catch(t=>{e?Cm(`The terminal operation failed. Try reconnecting.`,t):wm(t)})},o=()=>p.current?.blur(),s=()=>{cancelAnimationFrame(t),t=requestAnimationFrame(()=>{!e||document.visibilityState!==`visible`||(a(),p.current?.focus())})},c=()=>{document.visibilityState===`hidden`?o():s()},l=f.current,u=d.current;if(!l||!u)return;let h=t=>{if(t.isComposing)return;let n=j.current,r=t=>{v.current?.write(new TextEncoder().encode(t)).catch(t=>{e?Cm(`The terminal operation failed. Try reconnecting.`,t):wm(t)})},i=e=>n?.key({key:e,ctrlKey:!1,altKey:!1,metaKey:!1,shiftKey:!1,isComposing:!1})??!1;switch(t.inputType){case`deleteContentBackward`:t.preventDefault(),i(`Backspace`)||r(``);break;case`insertLineBreak`:case`insertParagraph`:t.preventDefault(),i(`Enter`)||r(`\r`);break;case`insertText`:if(!t.data)return;t.preventDefault(),n?.input(t.data)||r(t.data)}};l.addEventListener(`beforeinput`,h);let b=l.closest(`[data-theme]`)??document.documentElement,S=()=>getComputedStyle(l).getPropertyValue(`--font-mono`)||`Maple Mono, ui-monospace, monospace`;return Promise.all([PE(),FE(U9,S())]).then(([t])=>{if(!e)return;let d=Ku(b)??`mocha`,f=(n,r)=>{p.current?.dispose(),l.replaceChildren();let i=_r(n),o=new zfe({ghostty:t,cursorBlink:!0,cursorStyle:`block`,fontSize:U9,fontFamily:S(),theme:i,...r});p.current=o,o.open(l);let s=new Wfe;o.loadAddon(s),m.current=s;let c=new TextEncoder;o.onData(t=>{j.current?.input(t)||v.current?.write(c.encode(t)).catch(t=>{e?Cm(`The terminal operation failed. Try reconnecting.`,t):wm(t)})}),o.attachCustomKeyEventHandler(e=>j.current?.key(e)??!1),o.write(`\x1B[2J\x1B[3J\x1B[H`);for(let e of g.current)o.write(e);j.current?.repaint(o.cols),document.fonts.ready.then(a),a()};i=e=>{f(d,e)},f(d),r=iee(t=>{t===d||!_r(t)||(d=t,FE(U9,S()).then(()=>{if(!e||t!==d)return;let n=p.current;f(t,n?{cols:n.cols,rows:n.rows}:void 0)}).catch(t=>{if(!e){wm(t);return}Cm(`The terminal operation failed. Try reconnecting.`,t),C(`failed`)}))},b),n=new ResizeObserver(a),n.observe(u),document.addEventListener(`visibilitychange`,c),window.addEventListener(`blur`,o),window.addEventListener(`focus`,s)}).catch(t=>{if(!e){wm(t);return}Cm(`The terminal operation failed. Try reconnecting.`,t),C(`failed`)}),()=>{e=!1,cancelAnimationFrame(t),l.removeEventListener(`beforeinput`,h),n?.disconnect(),r?.(),document.removeEventListener(`visibilitychange`,c),window.removeEventListener(`blur`,o),window.removeEventListener(`focus`,s),y.current?.close().catch(e=>{wm(e)});try{p.current?.dispose()}catch(e){wm(e)}p.current=null,m.current=null}},[l]),(0,I.useEffect)(()=>{if(!b)return;let n=!0,r,i,a,o=null,s=null,c=null,l=new AbortController,u=new TextEncoder;C(`starting`),D(null),k(null),N(W9),ee([]);let d=async()=>{let t=p.current;if(!t)return null;let r=await ope(e.capabilities,{cols:Math.max(2,t.cols),rows:Math.max(2,t.rows)},{signal:l.signal});return n?r:(await r.close(),null)},f=e=>(a=e,y.current=e,r=e.output.getReader(),i=e.input.getWriter(),v.current=i,s?.setSessionOpen(!0),r),m=()=>{v.current===i&&(v.current=null),i?.releaseLock(),y.current===a&&(y.current=null),a?.close().catch(e=>{wm(e)})},h=async(e,t)=>{try{for(;;){let e=await t.read();if(l.signal.aborted||e.done)break;let n=e.value.slice();s?s.output(n):re(n)}}catch(e){if(l.signal.aborted){wm(e);return}Cm(`The terminal operation failed. Try reconnecting.`,e),C(`failed`);return}l.signal.aborted||y.current!==e||(m(),s?s.ptyEnded():C(`closed`))},x=()=>y.current?Promise.resolve():(o??=(async()=>{let e=await d();e&&h(e,f(e))})().finally(()=>{o=null}),o);return(async()=>{let e=p.current;if(e){g.current=[],_.current=0,e.reset(),e.write(`\x1B[2J\x1B[3J\x1B[H`),re(u.encode(bRe(t)));try{let t=await d();if(!t)return;g.current=[],_.current=0,p.current?.reset(),p.current?.write(`\x1B[2J\x1B[3J\x1B[H`);let n=Math.max(2,p.current?.cols??e.cols);if(re(u.encode(yRe({cols:n,information:t.information,light:A.current!==void 0}))),A.current){let e=new vRe({live:e=>p.current?.write(e),commit:re,forget:()=>{g.current=[],_.current=0},send:e=>{let t=v.current;return t?t.write(u.encode(e)):Promise.reject(Error(`The full shell is not open`))},connect:x,runLight:(e,t)=>{let n=A.current;return n?n.runLight(e,t):Promise.reject(Error(`The light shell is unavailable`))},view:N,log:e=>{let t=e.split(`
|
|
1742
|
-
`).map(e=>({id:te.current+=1,text:e}));ee(e=>[...e,...t].slice(-500))}},{computerName:t.information.computerName,columns:n});s=e,c={key:t=>e.key(t),input:t=>e.input(t),repaint:t=>{e.repaint(t)},setColumns:t=>{e.setColumns(t)},reopen:()=>{e.reopen()}},j.current=c,e.start()}D(t.information.computerName),k(t.information);let r=f(t);C(`open`),await h(t,r)}catch(e){if(l.signal.aborted){wm(e);return}Cm(`The terminal operation failed. Try reconnecting.`,e),C(`failed`)}}})(),()=>{n=!1,l.abort(),s?.dispose(),j.current===c&&(j.current=null),r?.cancel().catch(e=>{wm(e)}),v.current===i&&(v.current=null),i?.releaseLock(),y.current===a&&(y.current=null),a?.close().catch(e=>{wm(e)})}},[e,t,w,b,re]),(0,I.useEffect)(()=>{let e=requestAnimationFrame(()=>{n?p.current?.blur():p.current?.focus()});return()=>{cancelAnimationFrame(e)}},[!!n]);let ie=M.phase===`idle`?`light`:M.phase;return(0,F.jsxs)(`div`,{className:`relative flex min-h-0 min-w-0 flex-1 flex-col`,"data-shell-state":ne?ie:void 0,"data-route":ne?M.route:void 0,children:[(0,F.jsx)($E,{className:`flex min-h-0 min-w-0 flex-1 overflow-hidden`,children:(0,F.jsxs)(`div`,{ref:d,className:`relative min-h-0 flex-1 overflow-hidden`,children:[(0,F.jsx)(`div`,{ref:f,className:`terminal-host absolute inset-0 overflow-hidden px-2 pt-1 pb-0.5${n?` opacity-0`:``}`,"aria-hidden":n?!0:void 0}),n?(0,F.jsx)(`div`,{className:`absolute inset-0 flex flex-col`,children:n}):null,ne&&!n&&M.busy?(0,F.jsx)(`div`,{className:`pointer-events-none absolute right-3 bottom-2`,children:(0,F.jsx)(dm,{"data-shell-busy":`true`,size:`sm`,tone:`primary`,label:`Running command`})}):null,ne&&!n&&M.phase===`closed`?(0,F.jsx)(`div`,{className:`absolute bottom-2 left-2`,children:(0,F.jsx)(KE,{size:`sm`,variant:`accent`,onClick:()=>{j.current?.reopen(),p.current?.focus()},children:`Reopen shell`})}):null]})}),ne?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`div`,{role:`log`,"aria-label":`Shell output`,className:`sr-only`,children:P.map(e=>(0,F.jsx)(`div`,{children:e.text},e.id))}),(0,F.jsx)(`div`,{role:`status`,"aria-live":`polite`,className:`sr-only`,children:M.routeLabel})]}):null,!n&&S===`failed`&&(0,F.jsx)(`div`,{className:`absolute inset-0 flex overflow-auto bg-base-200 p-4`,children:(0,F.jsx)(_D,{className:`m-auto max-w-[28rem]`,variant:`panel`,title:`Terminal could not connect`,description:`Retry the connection, or open Computer settings to check the runtime.`,primaryAction:{label:`Retry`,onSelect:()=>{C(`starting`),b?T(e=>e+1):u(e=>e+1)}},actions:o?(0,F.jsx)(KE,{size:`sm`,variant:`ghost`,loading:s,onClick:()=>{c(!0),o().then(e=>{c(!1),e===`unavailable`&&Nn.error(`Open System Settings → Computers from the desktop menu.`)},e=>{c(!1),Cm(`Could not open Computer settings. Try again.`,e)})},children:`Open settings`}):void 0})}),!n&&S===`closed`&&(0,F.jsxs)(`div`,{className:`absolute inset-0 grid content-center justify-items-center gap-2 bg-base-200 p-4 text-center`,children:[(0,F.jsx)(`p`,{className:`m-0 text-sm`,children:`Terminal session ended.`}),b&&(0,F.jsx)(KE,{className:`terminal-reopen`,size:`sm`,variant:`accent`,onClick:()=>{T(e=>e+1)},children:`Reopen terminal`})]})]})}uE(`app.backend`,1,Pu(()=>dE({request:pE(fE(Hl().transform(e=>Om(e))))})));var G9=uE(`app.methods`,1,Pu(()=>dE({call:pE(fE(Hl().transform(e=>Om(e))))}))),K9=Zl({error:uu([`not_granted`,`revoked`,`grantor_lost_authority`,`unavailable`,`invalid`,`invalid_path`,`too_large`,`conflict`,`not_found`])}),q9=Zl({error:fu(`attachment_budget_exceeded`),kind:uu([`exec`,`write`]),retryAfterMs:Pl().int().min(1).max(864e5)}),J9=Zl({error:fu(`timeout`),requestId:_9.shape.requestId});eu([K9,q9,J9]);var CRe=c9.refine(e=>!e.split(`/`).includes(`..`),`Parent path segments are not allowed`),wRe=PLe({maximumTimeMs:45e3}).omit({requestId:!0,backend:!0}).extend({cwd:CRe.optional()}),Y9=ELe+2,TRe=eu([m9.pick({stdout:!0,stderr:!0,exitCode:!0}).extend({stdout:ul().max(Y9),stderr:ul().max(Y9),stdoutTruncated:Rl(),stderrTruncated:Rl()}).refine(e=>new TextEncoder().encode(e.stdout).byteLength<=Y9&&new TextEncoder().encode(e.stderr).byteLength<=Y9,`Command stream exceeds the native Computer output bound`),K9,q9,J9.pick({error:!0}),Zl({error:fu(`output_unavailable`)})]),ERe=`export FORCE_COLOR=1 CLICOLOR_FORCE=1 COLORTERM=truecolor TERM=xterm-256color; `;function DRe(e){return 79+e.length<=16384?`${ERe}${e}`:e}async function ORe(e,t,n){let r=SLe(t.command);if(r)return{stdout:``,stderr:`light: ${r.name} does not persist here yet; run \`full ${t.command}\` instead.\n`,exitCode:1,cwd:t.cwd,env:t.env};if(!e.has(G9))throw new yx(`Computer execution is not available`,{code:`CAPABILITY_DENIED`,retryable:!1});let i=wRe.parse({command:DRe(t.command),cwd:t.cwd}),a=await e.require(G9).call(`runCommand`,JSON.stringify(i));n.throwIfAborted();let o=TRe.parse(a);if(`error`in o&&o.error===`output_unavailable`)throw new yx(`The command produced no result`,{code:`DISCONNECTED`,retryable:!0});if(`error`in o)throw new yx(`The Computer declined this command: ${o.error}`,{code:`CAPABILITY_DENIED`,retryable:o.error===`unavailable`});return{stdout:o.stdout,stderr:o.stderr,exitCode:o.exitCode,cwd:t.cwd,env:t.env}}function kRe({app:e,computerId:t,screen:n,onStatusChange:r,openRuntimeSetup:i}){let[a,o]=(0,I.useState)(`starting`),[s,c]=(0,I.useState)(!1),l=(0,I.useCallback)(e=>{r?.({name:e.name,state:e.state}),c(e.information!==null),o(e.state)},[r]);return(0,F.jsx)(SRe,{app:e,computerId:t,screen:n??(!s&&a===`starting`?(0,F.jsx)(`div`,{className:`grid h-full min-h-0 flex-1 place-items-center`,children:(0,F.jsx)(dm,{size:`sm`,tone:`primary`,label:`Starting shell`})}):void 0),light:{runLight:(t,n)=>ORe(e.capabilities,t,n)},onStatusChange:l,openRuntimeSetup:i})}var X9=(0,I.forwardRef)(function({className:e,count:t,density:n=`row`,dismissAriaLabel:r,dismissLabel:i=`Dismiss`,message:a,onDismiss:o,onRetry:s,retryAriaLabel:c,retryLabel:l=`Retry`,role:u=`status`,...d},f){return(0,F.jsxs)(`div`,{...d,className:Od(`caps-failure-line`,e),"data-density":n,ref:f,role:u,children:[(0,F.jsx)(ym,{glyph:`dot`,tone:`error`}),(0,F.jsxs)(`span`,{className:`caps-failure-line-copy`,children:[(0,F.jsx)(`span`,{children:a}),t!==void 0&&t>1?(0,F.jsxs)(`span`,{className:`caps-failure-line-count`,children:[`Failed `,t,` times`]}):null]}),s||o?(0,F.jsxs)(`span`,{className:`caps-failure-line-actions`,children:[s?(0,F.jsx)(KE,{"aria-label":c,size:`sm`,variant:`outline`,onClick:s,children:l}):null,o?(0,F.jsx)(KE,{"aria-label":r,size:`sm`,variant:`ghost`,onClick:o,children:i}):null]}):null]})});function ARe({duration:e,paused:t=!1,onBurnt:n,className:r}){let i=(0,I.useRef)(null),a=(0,I.useRef)(null),o=(0,I.useRef)(n);return(0,I.useEffect)(()=>{o.current=n},[n]),(0,I.useLayoutEffect)(()=>{let t=i.current;if(!t)return;if(!Bd(t)){let t=setTimeout(()=>{o.current()},e);return()=>{clearTimeout(t)}}let n=Id(t),r=Math.max(1,Math.round(e/1e3)),s=t.animate([{transform:`scaleX(1)`},{transform:`scaleX(0)`}],{duration:e,easing:n.reduced?`steps(${String(r)}, end)`:zd(n,`linear`),fill:`forwards`});return s.addEventListener(`finish`,()=>{o.current()}),a.current=s,()=>{s.cancel(),a.current=null}},[e]),(0,I.useEffect)(()=>{let e=a.current;e&&(t?e.pause():e.playState===`paused`&&e.play())},[t]),(0,F.jsx)(`span`,{ref:i,"aria-hidden":`true`,className:Od(`caps-fuse`,r)})}var jRe=(0,I.forwardRef)(function({children:e,onCommit:t,armedAnnouncement:n,undoneAnnouncement:r,undoLabel:i=`Undo`,undoMs:a=5e3,className:o,onKeyDown:s,onPointerEnter:c,onPointerLeave:l,...u},d){let[f,p]=(0,I.useState)(!1),[m,h]=(0,I.useState)(!1),[g,_]=(0,I.useState)(``),v=(0,I.useId)(),y=()=>{p(!1),_(r)};return(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(KE,{...u,ref:d,"aria-label":f?void 0:u[`aria-label`],"aria-labelledby":f?void 0:u[`aria-labelledby`],"aria-describedby":f?v:u[`aria-describedby`],className:Od(`caps-undo-action`,o),"data-armed":f?``:void 0,onClick:()=>{if(f){y();return}p(!0),_(n)},onKeyDown:e=>{s?.(e),f&&e.key===`Escape`&&(e.preventDefault(),y())},onPointerEnter:e=>{c?.(e),h(!0)},onPointerLeave:e=>{l?.(e),h(!1)},children:[f?i:e,f?(0,F.jsx)(ARe,{duration:a,paused:m,onBurnt:()=>{p(!1),_(``),t()}}):null]}),(0,F.jsx)(Nd,{id:v,children:`Press Escape to undo.`}),(0,F.jsx)(Nd,{role:`status`,children:g})]})}),MRe=R({port:zE.fields.port.annotate(cP({label:`Port`,min:1,max:65535}))});function NRe({openPreview:e,openId:t,onOpenChange:n,processNavigation:r=null,leading:i,trailing:a,placement:o=`housing`,extraItems:s=[],hostInset:c,processesInPane:l=!1}){let{ports:{items:u,status:d,actions:f,refresh:p,expose:m,unexpose:h},processes:{items:g,loading:_,error:v,refresh:y}}=MP(),b=PP({openPreview:e,processNavigation:t===`processes`?r:null}),x=CP({schema:MRe,defaultValues:{port:5173},onSubmit:async({port:e})=>await m?.(e)?{kind:`saved`}:{kind:`refused`,fields:{port:`Couldn't expose port ${String(e)}. Try again.`}}}),S=()=>{x.form.setFieldMeta(`port`,e=>({...e,errorMap:{...e.errorMap,onServer:void 0}}))},C=async e=>{await m?.(e)&&x.form.state.values.port===e&&S()},w=u?.length??0,T=new Map;for(let e of u??[])T.set(e.port,e);for(let[e,t]of f??[])t.expose&&!T.has(e)&&T.set(e,null);let E=g!==null||_||v!==null,D=d===`not-configured`?(0,F.jsx)(FD,{title:`Preview service isn't configured`,children:`You can still work in the terminal.`}):u===null&&d===`unavailable`?(0,F.jsx)(FD,{title:`Port listing isn't available`,children:`You can still work in the terminal.`}):u===null&&d===`loading`?(0,F.jsx)(kP,{message:`Loading web previews`,size:`sm`,framed:!1}):u===null&&d===`error`?(0,F.jsx)(X9,{message:`Couldn't load exposed ports.`,onRetry:p?()=>void p():void 0}):(0,F.jsxs)(F.Fragment,{children:[T.size>0?(0,F.jsx)(NP,{label:`Exposed ports`,order:Array.from(T.keys(),String),children:Array.from(T,([t,n])=>{let r=f?.get(t),i=r?.status===`pending`,a=r?.status===`failed`?r.expose?`Couldn't expose port ${String(t)}. Try again.`:`Couldn't remove exposure. Try again.`:null;return(0,F.jsx)(PD,{[AP]:String(t),role:`listitem`,"data-shed-port":t,icon:(0,F.jsx)(rr,{size:16,"aria-hidden":`true`}),primary:a?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(`span`,{className:`block`,children:[`Port `,t]}),(0,F.jsx)(`span`,{role:`status`,className:`block whitespace-normal text-xs font-normal text-error`,children:a})]}):`Port ${String(t)}`,actions:n?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(KE,{size:`sm`,variant:`ghost`,disabled:i,onClick:()=>{e(n)},"aria-label":`Open preview of port ${String(t)}`,children:[(0,F.jsx)(er,{size:14,"aria-hidden":`true`}),`Open preview`]}),(0,F.jsx)(jRe,{"aria-label":`Stop exposing port ${String(t)}`,armedAnnouncement:`Port ${String(t)} closes in 5 seconds.`,undoneAnnouncement:`Port ${String(t)} stays open.`,size:`sm`,variant:`ghost`,className:`hover:text-error`,disabled:!h||i,onCommit:()=>{h?.(t)},children:i?r.expose?`Exposing…`:`Removing…`:`Remove exposure`})]}):(0,F.jsx)(KE,{size:`xs`,variant:`ghost`,disabled:!m||i,"aria-label":`Expose port ${String(t)}`,onClick:()=>{C(t)},children:i?`Exposing…`:`Try again`})},t)})}):(0,F.jsx)(FD,{title:`No exposed ports`,children:`Running a web server? Expose its port below to open a preview.`}),(0,F.jsx)(x.form.Subscribe,{selector:e=>({submitting:e.isSubmitting,port:e.values.port}),children:({submitting:e,port:t})=>{let n=e||f?.get(t)?.status===`pending`,r=m===void 0||n;return(0,F.jsx)(EP,{model:x,className:`mt-3 px-2`,"aria-label":`Expose a port`,disabled:r,footer:null,children:(0,F.jsxs)(`div`,{className:`flex min-w-0 items-start gap-2`,children:[(0,F.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,F.jsx)(iP,{model:x,disabled:r})}),(0,F.jsx)(KE,{className:`self-end`,type:`submit`,disabled:r,loading:n,onClick:S,children:`Expose`})]})})}}),d===`loading`&&u!==null?(0,F.jsx)(kP,{message:`Refreshing exposed ports…`,size:`sm`,framed:!1}):null,d===`error`&&u!==null?(0,F.jsx)(X9,{message:`Couldn't refresh exposed ports. The list may be out of date.`,onRetry:p?()=>void p():void 0}):null]}),O=[{id:`ports`,label:`Ports`,count:w,title:`Exposed ports`,actions:(0,F.jsx)(ND,{"aria-label":`Refresh exposed ports`,title:`Refresh exposed ports`,icon:(0,F.jsx)(lr,{}),size:`xs`,iconSize:`xs`,disabled:!p||d===`loading`,onClick:()=>{p?.()}}),content:D},{id:`processes`,label:`Processes`,count:g?.filter(e=>e.state===`running`).length,title:`Processes`,disabled:!E,accessibleLabel:E?void 0:`Processes can't be listed yet`,actions:(0,F.jsx)(ND,{"aria-label":`Refresh processes`,title:`Refresh processes`,icon:(0,F.jsx)(lr,{}),size:`xs`,iconSize:`xs`,disabled:!y||_,onClick:()=>{y?.()}}),content:b},...s];return(0,F.jsx)(Mme,{items:l?O.filter(e=>e.id!==`processes`):O,openId:t,onOpenChange:n,leading:i,trailing:a,placement:o,...c===void 0?{}:{hostInset:c},align:o===`host`?`start`:`end`})}function Z9({port:e,onClose:t,onPopOut:n}){let[r,i]=(0,I.useState)(0);return(0,F.jsxs)(`section`,{className:`flex h-full min-h-0 w-full min-w-0 flex-col overflow-hidden rounded-field bg-base-100`,"aria-label":`Preview port ${String(e.port)}`,children:[(0,F.jsxs)(`div`,{className:`shed-browser-controls flex h-8 shrink-0 items-center gap-1 border-b border-base-300 px-1`,children:[(0,F.jsxs)(`span`,{className:`min-w-0 flex-1 truncate px-2 font-mono text-xs`,children:[`:`,e.port]}),(0,F.jsx)(ND,{"aria-label":`Open preview in new window`,title:`Open preview in new window`,icon:(0,F.jsx)(er,{}),size:`xs`,iconSize:`xs`,onClick:n}),(0,F.jsx)(ND,{"aria-label":`Reload preview`,title:`Reload preview`,icon:(0,F.jsx)(lr,{}),size:`xs`,iconSize:`xs`,onClick:()=>{i(e=>e+1)}}),(0,F.jsx)(ND,{"aria-label":`Close preview`,title:`Close preview`,icon:(0,F.jsx)(dr,{"aria-hidden":`true`}),size:`xs`,iconSize:`xs`,onClick:t})]}),(0,F.jsx)(`iframe`,{className:`shed-preview-frame block min-h-0 w-full flex-1 border-0 bg-base-100`,sandbox:`allow-scripts allow-same-origin allow-popups`,src:e.previewUrl,title:`Preview · port ${String(e.port)}`},`${String(e.port)}:${String(r)}`)]})}var PRe=Rb(VE.fields.id);function FRe({app:e}){let t=lE(e?.context)??null;return(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(hne,{}),(0,F.jsx)(IRe,{app:e,appContext:t},JSON.stringify([e?.identity.surfaceId,t?.computerId]))]})}function IRe({app:e,appContext:t}){let n=t?.computerId??null,{query:r,ports:i,status:a,actions:o,enabled:s,change:c}=mbe(e,t?.visibility===`visible`),l=(0,I.useCallback)(async()=>{await r.refetch()},[r.refetch]),{query:u,stop:d,startCommand:f,output:p,actions:m,enabled:h}=fbe(e,t?.visibility===`visible`),g=(0,I.useCallback)(async()=>{await u.refetch()},[u.refetch]),_=(0,I.useRef)({refreshPorts:l,refreshProcesses:g});if(_.current={refreshPorts:l,refreshProcesses:g},(0,I.useEffect)(()=>{if(e)return Dne(e.commands,RRe(()=>_.current.refreshPorts(),()=>_.current.refreshProcesses()))},[e]),t?.teamHasComputers===!1)return(0,F.jsx)(LRe,{onAllowAccess:e&&!t.computerAccessGranted?()=>void e.ui.requestAppPermissions({computers:[`computer.execute`]}).catch(e=>{Cm(`Could not open App permissions. Try again.`,e)}):void 0});let v=h&&u.isError?npe(u.error):null,y=v?.action===`retry`?g:v?.action===`grant`&&e?()=>void e.ui.requestAppPermissions({computers:[`computer.execute`]}).catch(e=>{Cm(`Could not open App permissions. Try again.`,e)}):void 0;return(0,F.jsx)(jP.Provider,{value:{ports:{items:i,status:a,actions:o,refresh:s?l:void 0,expose:s?e=>c(e,!0):void 0,unexpose:s?e=>{c(e,!1)}:void 0},processes:{items:h?u.data?.processes??null:null,loading:h&&u.isFetching,error:v,unavailableReason:t?.setup?.terminal===`missing`?t.setup.terminalReason??`The command runner is not connected.`:void 0,output:h?p:void 0,fix:y,actions:m,refresh:h?g:void 0,start:h?f:void 0,stop:h?e=>{d.mutate(e)}:void 0}},children:(0,F.jsx)(zRe,{app:e,computerId:n,computerAccessGranted:t?.computerAccessGranted===!0},n)})}function LRe({onAllowAccess:e}){return(0,F.jsx)(`main`,{className:`grid h-full min-h-0 grid-cols-1 place-items-center bg-base-200 p-6 text-base-content`,children:(0,F.jsx)(_D,{className:`w-full max-w-[460px]`,"data-absence":`team-computers-empty`,variant:`panel`,visual:(0,F.jsx)(`span`,{className:`inline-grid size-16 place-items-center rounded-full bg-base-200 text-primary`,children:(0,F.jsx)(hD,{name:`computer`,size:48})}),title:`No Computer yet.`,description:e?`No Computer is attached to this window. Allow Computer access to use one here.`:`No Computer is attached to this window.`,actions:e?(0,F.jsx)(KE,{size:`sm`,onClick:e,children:`Allow Computer access`}):null})})}function RRe(e,t){return[{id:`refresh-processes`,title:`Refresh processes`,category:`Computer`,description:`Refresh the running processes on this Computer.`,projections:{palette:{}},handler:t},{id:`refresh-ports`,title:`Refresh forwarded ports`,category:`Computer`,description:`Refresh the forwarded ports on this Computer.`,projections:{palette:{}},handler:e}]}function zRe({app:e,computerId:t,computerAccessGranted:n=!1}){let r=(0,I.useRef)(null),[i,a]=(0,I.useState)({width:0,height:0});(0,I.useEffect)(()=>{let e=r.current;if(!e)return;let t=new ResizeObserver(([e])=>{a({width:e.contentRect.width,height:e.contentRect.height})});return t.observe(e),()=>{t.disconnect()}},[]);let o=t!==null&&e?.capabilities.has(WE)===!0,{ports:{items:s,status:c},processes:{items:l,loading:u,error:d}}=MP(),[f,p]=(0,I.useState)(null),m=lE(e?.context),h=m?.openRequest??null,g=m?.setup?.terminal===`exec-only`,_=(0,I.useRef)(null),[v,y]=(0,I.useState)(null);(0,I.useEffect)(()=>{if(t===null||h?.kind!==`navigate`||_.current===h.requestId)return;let e=h.params.filter(({key:e})=>e===`process`);if(e.length!==1)return;let n=dh(PRe(e[0]?.value));n!==null&&(_.current=h.requestId,y({requestId:h.requestId,processId:n}),p(g?null:`processes`))},[t,h,g]);let[b,x]=(0,I.useState)(void 0),[S,C]=(0,I.useState)(null),[w,T]=(0,I.useState)(!1),[E,D]=(0,I.useState)(null),O=(0,I.useCallback)(e=>{t!==null&&D({...e,computerId:t})},[t]),k=o&&E?.computerId===t?E:null,A=i.width<540,j=s?.find(e=>e.port===S)??null,M=e=>{if(e.openMode===`external-only`){window.open(e.previewUrl,`_blank`,`noopener,noreferrer`);return}C(e.port),T(!0),p(null)},N=l!==null||u||d!==null,P=Vpe({app:e,terminal:k,processes:d===null?l===null?u?{kind:`loading`}:{kind:`unavailable`}:{kind:`loaded`,count:l.length}:{kind:`error`},ports:c===`error`?{kind:`error`}:c===`loaded`&&s!==null?{kind:`loaded`,count:s.length}:c===`loading`?{kind:`loading`}:{kind:`unavailable`}});return cfe(e,t===null?[]:[...g?[{kind:`text`,id:`terminal`,text:`Commands ready`,tone:`success`}]:k?[{kind:`text`,id:`terminal`,text:`Terminal ${k.state}`,tone:VRe(k.state)}]:o?[]:[{kind:`text`,id:`terminal`,text:`Terminal unavailable`,tone:`warning`}],...c===`not-configured`?[]:[{kind:`button`,id:`ports`,text:`Ports`,icon:`ports`,count:s?.length??0,opens:`dialog`,expanded:f===`ports`}],...g?[]:[{kind:`button`,id:`processes`,text:`Processes`,icon:`processes`,opens:`dialog`,expanded:f===`processes`,count:l?.filter(e=>e.state===`running`).length??0,disabled:!N,title:N?`Processes on this Computer`:`Processes can't be listed yet`}],...A&&j?[{kind:`toggle`,id:`screen`,text:`:${String(j.port)}`,pressed:w}]:[],{kind:`button`,id:`access`,text:`Access`,icon:`access`,opens:`dialog`,expanded:f===`access`,title:o?`Shed can run commands on this Computer`:`Shed can't run commands on this Computer`}],e=>e.itemId===`screen`?(T(e=>!e),!0):g&&e.itemId===`processes`?!1:[`ports`,`processes`,`access`].includes(e.itemId)?(x(e.anchor?.start),p(t=>t===e.itemId?null:e.itemId),!0):!1),(0,F.jsxs)(`main`,{className:`shed-workspace flex h-full min-h-0 w-full flex-col overflow-hidden bg-base-200 font-sans text-base-content`,"aria-label":`Shed Computers workspace`,children:[(0,F.jsx)(`div`,{ref:r,className:`relative min-h-0 flex-1`,children:(0,F.jsx)(Tme,{bounds:i,tiling:{layout:`main-top`,mainSize:i.width>=540?i.height*.5:i.height,gap:8},children:(0,F.jsx)(BRe,{app:e,computerId:t,computerAccessGranted:n,terminalAvailable:o,bounds:i,narrow:A,preview:j,previewVisible:w,onClosePreview:()=>{T(!1),C(null)},onTerminalStatus:O,execOnly:g,openPreview:M,processNavigation:v})})}),t===null?null:(0,F.jsx)(NRe,{processesInPane:g,placement:`host`,openPreview:M,openId:f,onOpenChange:p,processNavigation:v,extraItems:[P],...b===void 0?{}:{hostInset:b}})]})}function BRe({app:e,computerId:t,computerAccessGranted:n,terminalAvailable:r,bounds:i,narrow:a,preview:o,previewVisible:s,onClosePreview:c,onTerminalStatus:l,execOnly:u,openPreview:d,processNavigation:f}){let p=Eme(),m=lE(e?.context),h=m?.setup?.terminal===`missing`,g=o!==null&&s&&!a,_=(0,I.useRef)(!1);(0,I.useEffect)(()=>{if(!g){_.current=!1;return}_.current||(_.current=!0,requestAnimationFrame(()=>{p.swap(`terminal`,`preview`)}))},[p,g]);let v=()=>{c(),p.zoomedId===`preview`&&p.zoom(null)},y=()=>{o&&window.open(o.previewUrl,`_blank`,`noopener,noreferrer`)};return(0,F.jsxs)(F.Fragment,{children:[g?(0,F.jsx)(Q9,{id:`preview`,children:(0,F.jsx)(`div`,{className:`flex h-full min-h-0 w-full min-w-0 flex-col`,children:(0,F.jsx)(Z9,{port:o,onClose:v,onPopOut:y})})}):null,(0,F.jsx)(Q9,{id:`terminal`,children:(0,F.jsx)(`section`,{className:`flex h-full min-h-0 w-full flex-col overflow-hidden`,"aria-label":u?`Processes`:`Terminal`,children:h?(0,F.jsx)(_D,{className:`m-auto max-w-lg p-6`,role:`status`,variant:`hint`,title:`Commands are unavailable`,description:m.setup.terminalReason??`The command runner is not connected. Reopen Shed to reconnect.`}):t!==null&&u?a&&o&&s?(0,F.jsx)(Z9,{port:o,onClose:v,onPopOut:y}):(0,F.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto pb-6`,children:(0,F.jsxs)(`div`,{className:`mx-auto w-full max-w-3xl`,children:[(0,F.jsxs)(`header`,{className:`flex items-center gap-4 px-4 pt-5 sm:px-6 sm:pt-6`,children:[(0,F.jsx)(hD,{name:`computer`,size:48}),(0,F.jsxs)(`div`,{className:`min-w-0 space-y-1`,children:[(0,F.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Run a command`}),(0,F.jsx)(`p`,{className:`text-sm text-base-content/70`,children:`Run commands in your working folder and read the results here.`})]})]}),(0,F.jsx)(ube,{openPreview:d,processNavigation:f})]})}):t!==null&&e&&r?(0,F.jsx)(kRe,{app:e,computerId:t,onStatusChange:l,openRuntimeSetup:()=>e.ui.openSetup(`computer`),screen:a&&o&&s?(0,F.jsx)(Z9,{port:o,onClose:v,onPopOut:y}):void 0},t):(0,F.jsx)(F.Fragment,{children:(0,F.jsx)(_D,{className:`grid min-h-0 flex-1 content-center justify-items-center p-4 text-center`,"data-absence":t?`terminal-permission`:`computer-context`,role:`status`,variant:`hint`,title:t?`Terminal unavailable`:`No Computer selected`,description:t?`Shed can’t run commands on this Computer yet. Allow Computer access in the window controls.`:n?`No Computer is attached to this window.`:`No Computer is attached to this window. Allow Computer access to use one here.`,actions:e&&t===null&&!n?(0,F.jsx)(KE,{size:`sm`,onClick:()=>void e.ui.requestAppPermissions({computers:[`computer.execute`]}).catch(e=>{Cm(`Could not open App permissions. Try again.`,e)}),children:`Allow Computer access`}):null})})})}),g?(0,F.jsx)(`div`,{className:`absolute inset-x-0 z-20 -translate-y-1/2`,style:{top:(p.divider?.position??i.height/2)+8},children:p.divider?(0,F.jsx)(Gpe,{className:`absolute left-1/2 -translate-x-1/2`,"aria-label":`Preview and terminal size`,orientation:`horizontal`,variant:`notch`,value:p.divider.position,min:p.divider.min,max:p.divider.max,onValueChange:p.resizeMain,onDoubleClick:()=>{p.resizeMain(i.height/2)},...p.divider.props}):null}):null]})}function Q9({id:e,children:t}){let n=Dme({id:e,frame:{x:0,y:0,width:560,height:180},minima:{width:240,height:e===`preview`?140:120}});return(0,F.jsx)(`div`,{className:`shed-pane absolute flex min-h-0 min-w-0 p-1`,"data-shed-pane":e,hidden:!n.visible,style:{left:n.frame.x,top:n.frame.y,width:n.frame.width,height:n.frame.height},children:t})}function VRe(e){return e===`open`?`success`:e===`failed`?`error`:e===`starting`?`warning`:`neutral`}var $9=document.getElementById(`shed-root`);if(!$9)throw Error(`Shed root is missing`);PE().catch(e=>{Cm(`The terminal operation failed. Try reconnecting.`,e)}),ofe($9,{name:`Shed`,queryClient:Cfe()},({app:e})=>(0,I.createElement)(FRe,{app:e}));
|
|
1742
|
+
`).map(e=>({id:te.current+=1,text:e}));ee(e=>[...e,...t].slice(-500))}},{computerName:t.information.computerName,columns:n});s=e,c={key:t=>e.key(t),input:t=>e.input(t),repaint:t=>{e.repaint(t)},setColumns:t=>{e.setColumns(t)},reopen:()=>{e.reopen()}},j.current=c,e.start()}D(t.information.computerName),k(t.information);let r=f(t);C(`open`),await h(t,r)}catch(e){if(l.signal.aborted){wm(e);return}Cm(`The terminal operation failed. Try reconnecting.`,e),C(`failed`)}}})(),()=>{n=!1,l.abort(),s?.dispose(),j.current===c&&(j.current=null),r?.cancel().catch(e=>{wm(e)}),v.current===i&&(v.current=null),i?.releaseLock(),y.current===a&&(y.current=null),a?.close().catch(e=>{wm(e)})}},[e,t,w,b,re]),(0,I.useEffect)(()=>{let e=requestAnimationFrame(()=>{n?p.current?.blur():p.current?.focus()});return()=>{cancelAnimationFrame(e)}},[!!n]);let ie=M.phase===`idle`?`light`:M.phase;return(0,F.jsxs)(`div`,{className:`relative flex min-h-0 min-w-0 flex-1 flex-col`,"data-shell-state":ne?ie:void 0,"data-route":ne?M.route:void 0,children:[(0,F.jsx)($E,{className:`flex min-h-0 min-w-0 flex-1 overflow-hidden`,children:(0,F.jsxs)(`div`,{ref:d,className:`relative min-h-0 flex-1 overflow-hidden`,children:[(0,F.jsx)(`div`,{ref:f,className:`terminal-host absolute inset-0 overflow-hidden px-2 pt-1 pb-0.5${n?` opacity-0`:``}`,"aria-hidden":n?!0:void 0}),n?(0,F.jsx)(`div`,{className:`absolute inset-0 flex flex-col`,children:n}):null,ne&&!n&&M.busy?(0,F.jsx)(`div`,{className:`pointer-events-none absolute right-3 bottom-2`,children:(0,F.jsx)(dm,{"data-shell-busy":`true`,size:`sm`,tone:`primary`,label:`Running command`})}):null,ne&&!n&&M.phase===`closed`?(0,F.jsx)(`div`,{className:`absolute bottom-2 left-2`,children:(0,F.jsx)(KE,{size:`sm`,variant:`accent`,onClick:()=>{j.current?.reopen(),p.current?.focus()},children:`Reopen shell`})}):null]})}),ne?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`div`,{role:`log`,"aria-label":`Shell output`,className:`sr-only`,children:P.map(e=>(0,F.jsx)(`div`,{children:e.text},e.id))}),(0,F.jsx)(`div`,{role:`status`,"aria-live":`polite`,className:`sr-only`,children:M.routeLabel})]}):null,!n&&S===`failed`&&(0,F.jsx)(`div`,{className:`absolute inset-0 flex overflow-auto bg-base-200 p-4`,children:(0,F.jsx)(_D,{className:`m-auto max-w-[28rem]`,variant:`panel`,title:`Terminal could not connect`,description:`Retry the connection, or open Computer settings to check the runtime.`,primaryAction:{label:`Retry`,onSelect:()=>{C(`starting`),b?T(e=>e+1):u(e=>e+1)}},actions:o?(0,F.jsx)(KE,{size:`sm`,variant:`ghost`,loading:s,onClick:()=>{c(!0),o().then(e=>{c(!1),e===`unavailable`&&Nn.error(`Open System Settings → Computers from the desktop menu.`)},e=>{c(!1),Cm(`Could not open Computer settings. Try again.`,e)})},children:`Open settings`}):void 0})}),!n&&S===`closed`&&(0,F.jsxs)(`div`,{className:`absolute inset-0 grid content-center justify-items-center gap-2 bg-base-200 p-4 text-center`,children:[(0,F.jsx)(`p`,{className:`m-0 text-sm`,children:`Terminal session ended.`}),b&&(0,F.jsx)(KE,{className:`terminal-reopen`,size:`sm`,variant:`accent`,onClick:()=>{T(e=>e+1)},children:`Reopen terminal`})]})]})}uE(`app.backend`,1,Pu(()=>dE({request:pE(fE(Hl().transform(e=>Om(e))))})));var G9=uE(`app.methods`,1,Pu(()=>dE({call:pE(fE(Hl().transform(e=>Om(e))))})));uE(`app.region`,1,Pu(()=>dE({connect:pE(dE({messages:pE(Vu(ReadableStream).transform(e=>e.pipeThrough(new TransformStream({transform(e,t){t.enqueue(ul().parse(e))}})))),send:mE,close:mE}))})));var K9=Zl({error:uu([`not_granted`,`revoked`,`grantor_lost_authority`,`unavailable`,`invalid`,`invalid_path`,`too_large`,`conflict`,`not_found`])}),q9=Zl({error:fu(`attachment_budget_exceeded`),kind:uu([`exec`,`write`]),retryAfterMs:Pl().int().min(1).max(864e5)}),J9=Zl({error:fu(`timeout`),requestId:_9.shape.requestId});eu([K9,q9,J9]);var CRe=c9.refine(e=>!e.split(`/`).includes(`..`),`Parent path segments are not allowed`),wRe=PLe({maximumTimeMs:45e3}).omit({requestId:!0,backend:!0}).extend({cwd:CRe.optional()}),Y9=ELe+2,TRe=eu([m9.pick({stdout:!0,stderr:!0,exitCode:!0}).extend({stdout:ul().max(Y9),stderr:ul().max(Y9),stdoutTruncated:Rl(),stderrTruncated:Rl()}).refine(e=>new TextEncoder().encode(e.stdout).byteLength<=Y9&&new TextEncoder().encode(e.stderr).byteLength<=Y9,`Command stream exceeds the native Computer output bound`),K9,q9,J9.pick({error:!0}),Zl({error:fu(`output_unavailable`)})]),ERe=`export FORCE_COLOR=1 CLICOLOR_FORCE=1 COLORTERM=truecolor TERM=xterm-256color; `;function DRe(e){return 79+e.length<=16384?`${ERe}${e}`:e}async function ORe(e,t,n){let r=SLe(t.command);if(r)return{stdout:``,stderr:`light: ${r.name} does not persist here yet; run \`full ${t.command}\` instead.\n`,exitCode:1,cwd:t.cwd,env:t.env};if(!e.has(G9))throw new yx(`Computer execution is not available`,{code:`CAPABILITY_DENIED`,retryable:!1});let i=wRe.parse({command:DRe(t.command),cwd:t.cwd}),a=await e.require(G9).call(`runCommand`,JSON.stringify(i));n.throwIfAborted();let o=TRe.parse(a);if(`error`in o&&o.error===`output_unavailable`)throw new yx(`The command produced no result`,{code:`DISCONNECTED`,retryable:!0});if(`error`in o)throw new yx(`The Computer declined this command: ${o.error}`,{code:`CAPABILITY_DENIED`,retryable:o.error===`unavailable`});return{stdout:o.stdout,stderr:o.stderr,exitCode:o.exitCode,cwd:t.cwd,env:t.env}}function kRe({app:e,computerId:t,screen:n,onStatusChange:r,openRuntimeSetup:i}){let[a,o]=(0,I.useState)(`starting`),[s,c]=(0,I.useState)(!1),l=(0,I.useCallback)(e=>{r?.({name:e.name,state:e.state}),c(e.information!==null),o(e.state)},[r]);return(0,F.jsx)(SRe,{app:e,computerId:t,screen:n??(!s&&a===`starting`?(0,F.jsx)(`div`,{className:`grid h-full min-h-0 flex-1 place-items-center`,children:(0,F.jsx)(dm,{size:`sm`,tone:`primary`,label:`Starting shell`})}):void 0),light:{runLight:(t,n)=>ORe(e.capabilities,t,n)},onStatusChange:l,openRuntimeSetup:i})}var X9=(0,I.forwardRef)(function({className:e,count:t,density:n=`row`,dismissAriaLabel:r,dismissLabel:i=`Dismiss`,message:a,onDismiss:o,onRetry:s,retryAriaLabel:c,retryLabel:l=`Retry`,role:u=`status`,...d},f){return(0,F.jsxs)(`div`,{...d,className:Od(`caps-failure-line`,e),"data-density":n,ref:f,role:u,children:[(0,F.jsx)(ym,{glyph:`dot`,tone:`error`}),(0,F.jsxs)(`span`,{className:`caps-failure-line-copy`,children:[(0,F.jsx)(`span`,{children:a}),t!==void 0&&t>1?(0,F.jsxs)(`span`,{className:`caps-failure-line-count`,children:[`Failed `,t,` times`]}):null]}),s||o?(0,F.jsxs)(`span`,{className:`caps-failure-line-actions`,children:[s?(0,F.jsx)(KE,{"aria-label":c,size:`sm`,variant:`outline`,onClick:s,children:l}):null,o?(0,F.jsx)(KE,{"aria-label":r,size:`sm`,variant:`ghost`,onClick:o,children:i}):null]}):null]})});function ARe({duration:e,paused:t=!1,onBurnt:n,className:r}){let i=(0,I.useRef)(null),a=(0,I.useRef)(null),o=(0,I.useRef)(n);return(0,I.useEffect)(()=>{o.current=n},[n]),(0,I.useLayoutEffect)(()=>{let t=i.current;if(!t)return;if(!Bd(t)){let t=setTimeout(()=>{o.current()},e);return()=>{clearTimeout(t)}}let n=Id(t),r=Math.max(1,Math.round(e/1e3)),s=t.animate([{transform:`scaleX(1)`},{transform:`scaleX(0)`}],{duration:e,easing:n.reduced?`steps(${String(r)}, end)`:zd(n,`linear`),fill:`forwards`});return s.addEventListener(`finish`,()=>{o.current()}),a.current=s,()=>{s.cancel(),a.current=null}},[e]),(0,I.useEffect)(()=>{let e=a.current;e&&(t?e.pause():e.playState===`paused`&&e.play())},[t]),(0,F.jsx)(`span`,{ref:i,"aria-hidden":`true`,className:Od(`caps-fuse`,r)})}var jRe=(0,I.forwardRef)(function({children:e,onCommit:t,armedAnnouncement:n,undoneAnnouncement:r,undoLabel:i=`Undo`,undoMs:a=5e3,className:o,onKeyDown:s,onPointerEnter:c,onPointerLeave:l,...u},d){let[f,p]=(0,I.useState)(!1),[m,h]=(0,I.useState)(!1),[g,_]=(0,I.useState)(``),v=(0,I.useId)(),y=()=>{p(!1),_(r)};return(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(KE,{...u,ref:d,"aria-label":f?void 0:u[`aria-label`],"aria-labelledby":f?void 0:u[`aria-labelledby`],"aria-describedby":f?v:u[`aria-describedby`],className:Od(`caps-undo-action`,o),"data-armed":f?``:void 0,onClick:()=>{if(f){y();return}p(!0),_(n)},onKeyDown:e=>{s?.(e),f&&e.key===`Escape`&&(e.preventDefault(),y())},onPointerEnter:e=>{c?.(e),h(!0)},onPointerLeave:e=>{l?.(e),h(!1)},children:[f?i:e,f?(0,F.jsx)(ARe,{duration:a,paused:m,onBurnt:()=>{p(!1),_(``),t()}}):null]}),(0,F.jsx)(Nd,{id:v,children:`Press Escape to undo.`}),(0,F.jsx)(Nd,{role:`status`,children:g})]})}),MRe=R({port:zE.fields.port.annotate(cP({label:`Port`,min:1,max:65535}))});function NRe({openPreview:e,openId:t,onOpenChange:n,processNavigation:r=null,leading:i,trailing:a,placement:o=`housing`,extraItems:s=[],hostInset:c,processesInPane:l=!1}){let{ports:{items:u,status:d,actions:f,refresh:p,expose:m,unexpose:h},processes:{items:g,loading:_,error:v,refresh:y}}=MP(),b=PP({openPreview:e,processNavigation:t===`processes`?r:null}),x=CP({schema:MRe,defaultValues:{port:5173},onSubmit:async({port:e})=>await m?.(e)?{kind:`saved`}:{kind:`refused`,fields:{port:`Couldn't expose port ${String(e)}. Try again.`}}}),S=()=>{x.form.setFieldMeta(`port`,e=>({...e,errorMap:{...e.errorMap,onServer:void 0}}))},C=async e=>{await m?.(e)&&x.form.state.values.port===e&&S()},w=u?.length??0,T=new Map;for(let e of u??[])T.set(e.port,e);for(let[e,t]of f??[])t.expose&&!T.has(e)&&T.set(e,null);let E=g!==null||_||v!==null,D=d===`not-configured`?(0,F.jsx)(FD,{title:`Preview service isn't configured`,children:`You can still work in the terminal.`}):u===null&&d===`unavailable`?(0,F.jsx)(FD,{title:`Port listing isn't available`,children:`You can still work in the terminal.`}):u===null&&d===`loading`?(0,F.jsx)(kP,{message:`Loading web previews`,size:`sm`,framed:!1}):u===null&&d===`error`?(0,F.jsx)(X9,{message:`Couldn't load exposed ports.`,onRetry:p?()=>void p():void 0}):(0,F.jsxs)(F.Fragment,{children:[T.size>0?(0,F.jsx)(NP,{label:`Exposed ports`,order:Array.from(T.keys(),String),children:Array.from(T,([t,n])=>{let r=f?.get(t),i=r?.status===`pending`,a=r?.status===`failed`?r.expose?`Couldn't expose port ${String(t)}. Try again.`:`Couldn't remove exposure. Try again.`:null;return(0,F.jsx)(PD,{[AP]:String(t),role:`listitem`,"data-shed-port":t,icon:(0,F.jsx)(rr,{size:16,"aria-hidden":`true`}),primary:a?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(`span`,{className:`block`,children:[`Port `,t]}),(0,F.jsx)(`span`,{role:`status`,className:`block whitespace-normal text-xs font-normal text-error`,children:a})]}):`Port ${String(t)}`,actions:n?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(KE,{size:`sm`,variant:`ghost`,disabled:i,onClick:()=>{e(n)},"aria-label":`Open preview of port ${String(t)}`,children:[(0,F.jsx)(er,{size:14,"aria-hidden":`true`}),`Open preview`]}),(0,F.jsx)(jRe,{"aria-label":`Stop exposing port ${String(t)}`,armedAnnouncement:`Port ${String(t)} closes in 5 seconds.`,undoneAnnouncement:`Port ${String(t)} stays open.`,size:`sm`,variant:`ghost`,className:`hover:text-error`,disabled:!h||i,onCommit:()=>{h?.(t)},children:i?r.expose?`Exposing…`:`Removing…`:`Remove exposure`})]}):(0,F.jsx)(KE,{size:`xs`,variant:`ghost`,disabled:!m||i,"aria-label":`Expose port ${String(t)}`,onClick:()=>{C(t)},children:i?`Exposing…`:`Try again`})},t)})}):(0,F.jsx)(FD,{title:`No exposed ports`,children:`Running a web server? Expose its port below to open a preview.`}),(0,F.jsx)(x.form.Subscribe,{selector:e=>({submitting:e.isSubmitting,port:e.values.port}),children:({submitting:e,port:t})=>{let n=e||f?.get(t)?.status===`pending`,r=m===void 0||n;return(0,F.jsx)(EP,{model:x,className:`mt-3 px-2`,"aria-label":`Expose a port`,disabled:r,footer:null,children:(0,F.jsxs)(`div`,{className:`flex min-w-0 items-start gap-2`,children:[(0,F.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,F.jsx)(iP,{model:x,disabled:r})}),(0,F.jsx)(KE,{className:`self-end`,type:`submit`,disabled:r,loading:n,onClick:S,children:`Expose`})]})})}}),d===`loading`&&u!==null?(0,F.jsx)(kP,{message:`Refreshing exposed ports…`,size:`sm`,framed:!1}):null,d===`error`&&u!==null?(0,F.jsx)(X9,{message:`Couldn't refresh exposed ports. The list may be out of date.`,onRetry:p?()=>void p():void 0}):null]}),O=[{id:`ports`,label:`Ports`,count:w,title:`Exposed ports`,actions:(0,F.jsx)(ND,{"aria-label":`Refresh exposed ports`,title:`Refresh exposed ports`,icon:(0,F.jsx)(lr,{}),size:`xs`,iconSize:`xs`,disabled:!p||d===`loading`,onClick:()=>{p?.()}}),content:D},{id:`processes`,label:`Processes`,count:g?.filter(e=>e.state===`running`).length,title:`Processes`,disabled:!E,accessibleLabel:E?void 0:`Processes can't be listed yet`,actions:(0,F.jsx)(ND,{"aria-label":`Refresh processes`,title:`Refresh processes`,icon:(0,F.jsx)(lr,{}),size:`xs`,iconSize:`xs`,disabled:!y||_,onClick:()=>{y?.()}}),content:b},...s];return(0,F.jsx)(Mme,{items:l?O.filter(e=>e.id!==`processes`):O,openId:t,onOpenChange:n,leading:i,trailing:a,placement:o,...c===void 0?{}:{hostInset:c},align:o===`host`?`start`:`end`})}function Z9({port:e,onClose:t,onPopOut:n}){let[r,i]=(0,I.useState)(0);return(0,F.jsxs)(`section`,{className:`flex h-full min-h-0 w-full min-w-0 flex-col overflow-hidden rounded-field bg-base-100`,"aria-label":`Preview port ${String(e.port)}`,children:[(0,F.jsxs)(`div`,{className:`shed-browser-controls flex h-8 shrink-0 items-center gap-1 border-b border-base-300 px-1`,children:[(0,F.jsxs)(`span`,{className:`min-w-0 flex-1 truncate px-2 font-mono text-xs`,children:[`:`,e.port]}),(0,F.jsx)(ND,{"aria-label":`Open preview in new window`,title:`Open preview in new window`,icon:(0,F.jsx)(er,{}),size:`xs`,iconSize:`xs`,onClick:n}),(0,F.jsx)(ND,{"aria-label":`Reload preview`,title:`Reload preview`,icon:(0,F.jsx)(lr,{}),size:`xs`,iconSize:`xs`,onClick:()=>{i(e=>e+1)}}),(0,F.jsx)(ND,{"aria-label":`Close preview`,title:`Close preview`,icon:(0,F.jsx)(dr,{"aria-hidden":`true`}),size:`xs`,iconSize:`xs`,onClick:t})]}),(0,F.jsx)(`iframe`,{className:`shed-preview-frame block min-h-0 w-full flex-1 border-0 bg-base-100`,sandbox:`allow-scripts allow-same-origin allow-popups`,src:e.previewUrl,title:`Preview · port ${String(e.port)}`},`${String(e.port)}:${String(r)}`)]})}var PRe=Rb(VE.fields.id);function FRe({app:e}){let t=lE(e?.context)??null;return(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(hne,{}),(0,F.jsx)(IRe,{app:e,appContext:t},JSON.stringify([e?.identity.surfaceId,t?.computerId]))]})}function IRe({app:e,appContext:t}){let n=t?.computerId??null,{query:r,ports:i,status:a,actions:o,enabled:s,change:c}=mbe(e,t?.visibility===`visible`),l=(0,I.useCallback)(async()=>{await r.refetch()},[r.refetch]),{query:u,stop:d,startCommand:f,output:p,actions:m,enabled:h}=fbe(e,t?.visibility===`visible`),g=(0,I.useCallback)(async()=>{await u.refetch()},[u.refetch]),_=(0,I.useRef)({refreshPorts:l,refreshProcesses:g});if(_.current={refreshPorts:l,refreshProcesses:g},(0,I.useEffect)(()=>{if(e)return Dne(e.commands,RRe(()=>_.current.refreshPorts(),()=>_.current.refreshProcesses()))},[e]),t?.teamHasComputers===!1)return(0,F.jsx)(LRe,{onAllowAccess:e&&!t.computerAccessGranted?()=>void e.ui.requestAppPermissions({computers:[`computer.execute`]}).catch(e=>{Cm(`Could not open App permissions. Try again.`,e)}):void 0});let v=h&&u.isError?npe(u.error):null,y=v?.action===`retry`?g:v?.action===`grant`&&e?()=>void e.ui.requestAppPermissions({computers:[`computer.execute`]}).catch(e=>{Cm(`Could not open App permissions. Try again.`,e)}):void 0;return(0,F.jsx)(jP.Provider,{value:{ports:{items:i,status:a,actions:o,refresh:s?l:void 0,expose:s?e=>c(e,!0):void 0,unexpose:s?e=>{c(e,!1)}:void 0},processes:{items:h?u.data?.processes??null:null,loading:h&&u.isFetching,error:v,unavailableReason:t?.setup?.terminal===`missing`?t.setup.terminalReason??`The command runner is not connected.`:void 0,output:h?p:void 0,fix:y,actions:m,refresh:h?g:void 0,start:h?f:void 0,stop:h?e=>{d.mutate(e)}:void 0}},children:(0,F.jsx)(zRe,{app:e,computerId:n,computerAccessGranted:t?.computerAccessGranted===!0},n)})}function LRe({onAllowAccess:e}){return(0,F.jsx)(`main`,{className:`grid h-full min-h-0 grid-cols-1 place-items-center bg-base-200 p-6 text-base-content`,children:(0,F.jsx)(_D,{className:`w-full max-w-[460px]`,"data-absence":`team-computers-empty`,variant:`panel`,visual:(0,F.jsx)(`span`,{className:`inline-grid size-16 place-items-center rounded-full bg-base-200 text-primary`,children:(0,F.jsx)(hD,{name:`computer`,size:48})}),title:`No Computer yet.`,description:e?`No Computer is attached to this window. Allow Computer access to use one here.`:`No Computer is attached to this window.`,actions:e?(0,F.jsx)(KE,{size:`sm`,onClick:e,children:`Allow Computer access`}):null})})}function RRe(e,t){return[{id:`refresh-processes`,title:`Refresh processes`,category:`Computer`,description:`Refresh the running processes on this Computer.`,projections:{palette:{}},handler:t},{id:`refresh-ports`,title:`Refresh forwarded ports`,category:`Computer`,description:`Refresh the forwarded ports on this Computer.`,projections:{palette:{}},handler:e}]}function zRe({app:e,computerId:t,computerAccessGranted:n=!1}){let r=(0,I.useRef)(null),[i,a]=(0,I.useState)({width:0,height:0});(0,I.useEffect)(()=>{let e=r.current;if(!e)return;let t=new ResizeObserver(([e])=>{a({width:e.contentRect.width,height:e.contentRect.height})});return t.observe(e),()=>{t.disconnect()}},[]);let o=t!==null&&e?.capabilities.has(WE)===!0,{ports:{items:s,status:c},processes:{items:l,loading:u,error:d}}=MP(),[f,p]=(0,I.useState)(null),m=lE(e?.context),h=m?.openRequest??null,g=m?.setup?.terminal===`exec-only`,_=(0,I.useRef)(null),[v,y]=(0,I.useState)(null);(0,I.useEffect)(()=>{if(t===null||h?.kind!==`navigate`||_.current===h.requestId)return;let e=h.params.filter(({key:e})=>e===`process`);if(e.length!==1)return;let n=dh(PRe(e[0]?.value));n!==null&&(_.current=h.requestId,y({requestId:h.requestId,processId:n}),p(g?null:`processes`))},[t,h,g]);let[b,x]=(0,I.useState)(void 0),[S,C]=(0,I.useState)(null),[w,T]=(0,I.useState)(!1),[E,D]=(0,I.useState)(null),O=(0,I.useCallback)(e=>{t!==null&&D({...e,computerId:t})},[t]),k=o&&E?.computerId===t?E:null,A=i.width<540,j=s?.find(e=>e.port===S)??null,M=e=>{if(e.openMode===`external-only`){window.open(e.previewUrl,`_blank`,`noopener,noreferrer`);return}C(e.port),T(!0),p(null)},N=l!==null||u||d!==null,P=Vpe({app:e,terminal:k,processes:d===null?l===null?u?{kind:`loading`}:{kind:`unavailable`}:{kind:`loaded`,count:l.length}:{kind:`error`},ports:c===`error`?{kind:`error`}:c===`loaded`&&s!==null?{kind:`loaded`,count:s.length}:c===`loading`?{kind:`loading`}:{kind:`unavailable`}});return cfe(e,t===null?[]:[...g?[{kind:`text`,id:`terminal`,text:`Commands ready`,tone:`success`}]:k?[{kind:`text`,id:`terminal`,text:`Terminal ${k.state}`,tone:VRe(k.state)}]:o?[]:[{kind:`text`,id:`terminal`,text:`Terminal unavailable`,tone:`warning`}],...c===`not-configured`?[]:[{kind:`button`,id:`ports`,text:`Ports`,icon:`ports`,count:s?.length??0,opens:`dialog`,expanded:f===`ports`}],...g?[]:[{kind:`button`,id:`processes`,text:`Processes`,icon:`processes`,opens:`dialog`,expanded:f===`processes`,count:l?.filter(e=>e.state===`running`).length??0,disabled:!N,title:N?`Processes on this Computer`:`Processes can't be listed yet`}],...A&&j?[{kind:`toggle`,id:`screen`,text:`:${String(j.port)}`,pressed:w}]:[],{kind:`button`,id:`access`,text:`Access`,icon:`access`,opens:`dialog`,expanded:f===`access`,title:o?`Shed can run commands on this Computer`:`Shed can't run commands on this Computer`}],e=>e.itemId===`screen`?(T(e=>!e),!0):g&&e.itemId===`processes`?!1:[`ports`,`processes`,`access`].includes(e.itemId)?(x(e.anchor?.start),p(t=>t===e.itemId?null:e.itemId),!0):!1),(0,F.jsxs)(`main`,{className:`shed-workspace flex h-full min-h-0 w-full flex-col overflow-hidden bg-base-200 font-sans text-base-content`,"aria-label":`Shed Computers workspace`,children:[(0,F.jsx)(`div`,{ref:r,className:`relative min-h-0 flex-1`,children:(0,F.jsx)(Tme,{bounds:i,tiling:{layout:`main-top`,mainSize:i.width>=540?i.height*.5:i.height,gap:8},children:(0,F.jsx)(BRe,{app:e,computerId:t,computerAccessGranted:n,terminalAvailable:o,bounds:i,narrow:A,preview:j,previewVisible:w,onClosePreview:()=>{T(!1),C(null)},onTerminalStatus:O,execOnly:g,openPreview:M,processNavigation:v})})}),t===null?null:(0,F.jsx)(NRe,{processesInPane:g,placement:`host`,openPreview:M,openId:f,onOpenChange:p,processNavigation:v,extraItems:[P],...b===void 0?{}:{hostInset:b}})]})}function BRe({app:e,computerId:t,computerAccessGranted:n,terminalAvailable:r,bounds:i,narrow:a,preview:o,previewVisible:s,onClosePreview:c,onTerminalStatus:l,execOnly:u,openPreview:d,processNavigation:f}){let p=Eme(),m=lE(e?.context),h=m?.setup?.terminal===`missing`,g=o!==null&&s&&!a,_=(0,I.useRef)(!1);(0,I.useEffect)(()=>{if(!g){_.current=!1;return}_.current||(_.current=!0,requestAnimationFrame(()=>{p.swap(`terminal`,`preview`)}))},[p,g]);let v=()=>{c(),p.zoomedId===`preview`&&p.zoom(null)},y=()=>{o&&window.open(o.previewUrl,`_blank`,`noopener,noreferrer`)};return(0,F.jsxs)(F.Fragment,{children:[g?(0,F.jsx)(Q9,{id:`preview`,children:(0,F.jsx)(`div`,{className:`flex h-full min-h-0 w-full min-w-0 flex-col`,children:(0,F.jsx)(Z9,{port:o,onClose:v,onPopOut:y})})}):null,(0,F.jsx)(Q9,{id:`terminal`,children:(0,F.jsx)(`section`,{className:`flex h-full min-h-0 w-full flex-col overflow-hidden`,"aria-label":u?`Processes`:`Terminal`,children:h?(0,F.jsx)(_D,{className:`m-auto max-w-lg p-6`,role:`status`,variant:`hint`,title:`Commands are unavailable`,description:m.setup.terminalReason??`The command runner is not connected. Reopen Shed to reconnect.`}):t!==null&&u?a&&o&&s?(0,F.jsx)(Z9,{port:o,onClose:v,onPopOut:y}):(0,F.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto pb-6`,children:(0,F.jsxs)(`div`,{className:`mx-auto w-full max-w-3xl`,children:[(0,F.jsxs)(`header`,{className:`flex items-center gap-4 px-4 pt-5 sm:px-6 sm:pt-6`,children:[(0,F.jsx)(hD,{name:`computer`,size:48}),(0,F.jsxs)(`div`,{className:`min-w-0 space-y-1`,children:[(0,F.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Run a command`}),(0,F.jsx)(`p`,{className:`text-sm text-base-content/70`,children:`Run commands in your working folder and read the results here.`})]})]}),(0,F.jsx)(ube,{openPreview:d,processNavigation:f})]})}):t!==null&&e&&r?(0,F.jsx)(kRe,{app:e,computerId:t,onStatusChange:l,openRuntimeSetup:()=>e.ui.openSetup(`computer`),screen:a&&o&&s?(0,F.jsx)(Z9,{port:o,onClose:v,onPopOut:y}):void 0},t):(0,F.jsx)(F.Fragment,{children:(0,F.jsx)(_D,{className:`grid min-h-0 flex-1 content-center justify-items-center p-4 text-center`,"data-absence":t?`terminal-permission`:`computer-context`,role:`status`,variant:`hint`,title:t?`Terminal unavailable`:`No Computer selected`,description:t?`Shed can’t run commands on this Computer yet. Allow Computer access in the window controls.`:n?`No Computer is attached to this window.`:`No Computer is attached to this window. Allow Computer access to use one here.`,actions:e&&t===null&&!n?(0,F.jsx)(KE,{size:`sm`,onClick:()=>void e.ui.requestAppPermissions({computers:[`computer.execute`]}).catch(e=>{Cm(`Could not open App permissions. Try again.`,e)}),children:`Allow Computer access`}):null})})})}),g?(0,F.jsx)(`div`,{className:`absolute inset-x-0 z-20 -translate-y-1/2`,style:{top:(p.divider?.position??i.height/2)+8},children:p.divider?(0,F.jsx)(Gpe,{className:`absolute left-1/2 -translate-x-1/2`,"aria-label":`Preview and terminal size`,orientation:`horizontal`,variant:`notch`,value:p.divider.position,min:p.divider.min,max:p.divider.max,onValueChange:p.resizeMain,onDoubleClick:()=>{p.resizeMain(i.height/2)},...p.divider.props}):null}):null]})}function Q9({id:e,children:t}){let n=Dme({id:e,frame:{x:0,y:0,width:560,height:180},minima:{width:240,height:e===`preview`?140:120}});return(0,F.jsx)(`div`,{className:`shed-pane absolute flex min-h-0 min-w-0 p-1`,"data-shed-pane":e,hidden:!n.visible,style:{left:n.frame.x,top:n.frame.y,width:n.frame.width,height:n.frame.height},children:t})}function VRe(e){return e===`open`?`success`:e===`failed`?`error`:e===`starting`?`warning`:`neutral`}var $9=document.getElementById(`shed-root`);if(!$9)throw Error(`Shed root is missing`);PE().catch(e=>{Cm(`The terminal operation failed. Try reconnecting.`,e)}),ofe($9,{name:`Shed`,queryClient:Cfe()},({app:e})=>(0,I.createElement)(FRe,{app:e}));
|
package/dist/index.html
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
<meta charset="UTF-8" />
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
6
|
<title>Shed</title>
|
|
7
|
-
<script type="module" crossorigin src="./assets/index-
|
|
7
|
+
<script type="module" crossorigin src="./assets/index-DqaFSc_Z.js"></script>
|
|
8
8
|
<link rel="stylesheet" crossorigin href="./assets/index-zjjMF3-_.css">
|
|
9
9
|
</head>
|
|
10
10
|
<body
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fungi.computer/shed",
|
|
3
3
|
"description": "Shed: a terminal on your Computer, with its ports and processes, for Oyster",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.10.0",
|
|
5
5
|
"author": "Levi <levi@technomancy.dev>",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"@fungi.computer/cairn": "0.1.0",
|
|
9
|
-
"@fungi.computer/agar": "0.
|
|
10
|
-
"@fungi.computer/caps": "0.12.
|
|
9
|
+
"@fungi.computer/agar": "0.22.0",
|
|
10
|
+
"@fungi.computer/caps": "0.12.1",
|
|
11
11
|
"@fungi.computer/maosaico": "0.1.2",
|
|
12
12
|
"@fungi.computer/sigils": "0.3.2",
|
|
13
13
|
"@fungi.computer/stipe": "0.1.1",
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
"@tanstack/react-query": "5.102.8",
|
|
23
23
|
"effect": "4.0.2",
|
|
24
24
|
"zod": "4.4.3",
|
|
25
|
-
"@fungi.computer/braid": "0.5.
|
|
25
|
+
"@fungi.computer/braid": "0.5.2",
|
|
26
26
|
"@fungi.computer/gills": "0.4.0",
|
|
27
|
-
"@fungi.computer/computer-contract": "0.5.
|
|
27
|
+
"@fungi.computer/computer-contract": "0.5.6"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@ladle/react": "5.1.1",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"vitest": "4.1.11",
|
|
40
40
|
"playwright": "1.62.1",
|
|
41
41
|
"@cloudflare/workers-types": "5.20260828.1",
|
|
42
|
-
"@fungi.computer/puffball": "0.
|
|
42
|
+
"@fungi.computer/puffball": "0.12.0",
|
|
43
43
|
"esbuild": "0.28.2",
|
|
44
44
|
"eslint": "10.9.1",
|
|
45
45
|
"tsx": "4.23.12",
|