-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHomeController.php
More file actions
506 lines (486 loc) · 20.4 KB
/
HomeController.php
File metadata and controls
506 lines (486 loc) · 20.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
<?php
namespace App\Http\Controllers;
use App\Features\Desktop\MvpShell;
use App\Models\Workspace;
use App\Services\Surreal\SurrealRuntimeManager;
use App\Support\Features\DesktopUi;
use Illuminate\Http\Request;
use Illuminate\View\View;
use RuntimeException;
use Throwable;
class HomeController extends Controller
{
/**
* @return array<string, array{
* slug: string,
* label: string,
* meta: string,
* prefix: string,
* summary: string,
* room: string,
* roomStatus: string,
* participants: array<int, array{label: string, meta: string}>,
* notes: array<int, string>,
* tasks: array<int, array{label: string, status: string, summary: string}>,
* artifacts: array<int, array{label: string, kind: string, summary: string}>,
* decisions: array<int, array{label: string, owner: string, summary: string}>,
* messages: array<int, array{speaker: string, role: string, body: string, meta: string, tone: string}>
* }>
*/
private function workspaces(bool $localReady): array
{
return [
'katra-local' => [
'slug' => 'katra-local',
'label' => 'Katra Local',
'meta' => 'Local',
'prefix' => 'K',
'summary' => $localReady
? 'A local-first workspace on this device with the embedded Surreal runtime already available.'
: 'A local-first workspace on this device for conversations, tasks, artifacts, and decisions.',
'room' => '# design-room',
'roomStatus' => $localReady ? 'local' : 'draft',
'participants' => [
['label' => 'You', 'meta' => 'Human'],
['label' => 'Planner Agent', 'meta' => 'Worker'],
['label' => 'Research Model', 'meta' => 'Model'],
['label' => 'Context Agent', 'meta' => 'Worker'],
],
'notes' => [
'The core room should feel durable enough that work keeps accumulating here over time.',
'Tasks, artifacts, and decisions should stay linked without overtaking the room itself.',
'The first desktop shell should stay generic enough to seed other local-first products later on.',
],
'tasks' => [
[
'label' => 'Shape the MVP shell',
'status' => 'In review',
'summary' => 'Tighten the room layout, spacing, and navigation so the shell feels like an app instead of a staged page.',
],
[
'label' => 'Introduce connection switching',
'status' => 'Queued',
'summary' => 'Make room for local and remote instances without changing the top-level layout.',
],
[
'label' => 'Refine linked work',
'status' => 'Draft',
'summary' => 'Keep tasks, artifacts, and decisions close to the room without turning the whole shell into a dashboard.',
],
],
'artifacts' => [
[
'label' => 'Room layout',
'kind' => 'Note',
'summary' => 'Current draft for the center room and right-side context split.',
],
[
'label' => 'Brand guide',
'kind' => 'Guide',
'summary' => 'Nord palette, quieter type, and the current Katra identity rules.',
],
],
'decisions' => [
[
'label' => 'Persistent rooms',
'owner' => 'Product',
'summary' => 'One room per participant set should replace disposable transcript threads.',
],
[
'label' => 'Diagnostics stay hidden',
'owner' => 'Desktop',
'summary' => 'Connection and runtime details belong in logs or a developer view, not in the main shell.',
],
],
'messages' => [
[
'speaker' => 'You',
'role' => 'Human',
'tone' => 'plain',
'meta' => 'Just now',
'body' => 'This room should feel like the place where work already lives, not like a landing page that still needs to explain itself.',
],
[
'speaker' => 'Planner Agent',
'role' => 'Agent',
'tone' => 'accent',
'meta' => 'Note',
'body' => 'Keep the center focused on the room. Tasks, artifacts, and decisions can stay visible in the context rail without taking over the main flow.',
],
[
'speaker' => 'Research Model',
'role' => 'Model',
'tone' => 'subtle',
'meta' => 'Draft',
'body' => 'The layout should stay generic enough to support other local-first products later: rooms on the left, active work in the center, linked context on the right.',
],
],
],
'design-lab' => [
'slug' => 'design-lab',
'label' => 'Design Lab',
'meta' => 'Local',
'prefix' => 'D',
'summary' => 'A quieter workspace for shell structure, navigation studies, and UI direction.',
'room' => '# shell-studies',
'roomStatus' => 'draft',
'participants' => [
['label' => 'You', 'meta' => 'Human'],
['label' => 'Visual Agent', 'meta' => 'Worker'],
['label' => 'Layout Model', 'meta' => 'Model'],
['label' => 'Critique Agent', 'meta' => 'Worker'],
],
'notes' => [
'Reduce surface noise until the room can carry the experience on its own.',
'Treat navigation as durable structure, not as temporary marketing copy.',
'Let component work stay atomic so the shell can evolve without rewrites.',
],
'tasks' => [
[
'label' => 'Tighten sidebar density',
'status' => 'Active',
'summary' => 'Remove truncation pressure and make the workspace selector feel native to the app frame.',
],
[
'label' => 'Calm the center room',
'status' => 'Queued',
'summary' => 'Strip away explanatory blocks until the room reads clearly without helping text.',
],
],
'artifacts' => [
[
'label' => 'Sidebar studies',
'kind' => 'Mock',
'summary' => 'Current workspace selector and room list direction.',
],
[
'label' => 'Type rhythm',
'kind' => 'Spec',
'summary' => 'Reduced tracking and line-height targets for the desktop shell.',
],
],
'decisions' => [
[
'label' => 'No marketing copy in-app',
'owner' => 'Design',
'summary' => 'The desktop shell should assume the user already chose to be here.',
],
],
'messages' => [
[
'speaker' => 'You',
'role' => 'Human',
'tone' => 'plain',
'meta' => 'Now',
'body' => 'Let the workspace selector behave like a selector, not like a section accordion.',
],
[
'speaker' => 'Visual Agent',
'role' => 'Agent',
'tone' => 'accent',
'meta' => 'Draft',
'body' => 'Wider rails and calmer spacing are helping, but the shell still needs less explanation and more structure.',
],
],
],
'relay-cloud' => [
'slug' => 'relay-cloud',
'label' => 'Relay Cloud',
'meta' => 'Remote',
'prefix' => 'R',
'summary' => 'A remote instance view for shared orchestration, worker presence, and linked team context.',
'room' => '# relay-ops',
'roomStatus' => 'remote',
'participants' => [
['label' => 'You', 'meta' => 'Human'],
['label' => 'Ops Agent', 'meta' => 'Worker'],
['label' => 'Team Model', 'meta' => 'Model'],
['label' => 'Routing Agent', 'meta' => 'Worker'],
],
'notes' => [
'Remote work should preserve the same room model as local work.',
'The desktop app can be a client and a worker without splitting the product model in two.',
'Shared AI workloads should flow through a dedicated worker queue, not the default queue.',
],
'tasks' => [
[
'label' => 'Stage remote workers',
'status' => 'Queued',
'summary' => 'Make room for authenticated desktop workers contributing model capacity to a server instance.',
],
[
'label' => 'Define secure payloads',
'status' => 'Draft',
'summary' => 'Keep worker jobs minimized, private, and cleaned up after completion.',
],
],
'artifacts' => [
[
'label' => 'Queue boundary notes',
'kind' => 'Guide',
'summary' => 'Remote AI work should use a dedicated worker queue, separate from normal Laravel jobs.',
],
],
'decisions' => [
[
'label' => 'Same product model',
'owner' => 'Architecture',
'summary' => 'Local and remote should be different runtimes of the same Katra model, not separate apps.',
],
],
'messages' => [
[
'speaker' => 'You',
'role' => 'Human',
'tone' => 'plain',
'meta' => 'Latest',
'body' => 'A remote instance should still feel like the same workspace model, not a separate product mode.',
],
[
'speaker' => 'Ops Agent',
'role' => 'Agent',
'tone' => 'accent',
'meta' => 'Queued',
'body' => 'Desktop workers can stay available to authenticated instances while the main queue remains server-owned.',
],
],
],
];
}
/**
* @param array<string, array{
* slug: string,
* label: string,
* meta: string,
* prefix: string
* }> $workspaces
* @return array<int, array{label: string, meta?: string, active?: bool, muted?: bool, prefix: string, href: string}>
*/
private function workspaceLinks(array $workspaces, string $activeWorkspace): array
{
return collect($workspaces)
->map(fn (array $workspace): array => [
'label' => $workspace['label'],
'meta' => $workspace['meta'],
'active' => $workspace['slug'] === $activeWorkspace,
'prefix' => $workspace['prefix'],
'href' => route('home', ['workspace' => $workspace['slug']]),
])
->values()
->all();
}
/**
* @return array<int, array{label: string, active?: bool, prefix: string, tone: string}>
*/
private function favoriteLinks(string $activeRoom): array
{
return [
['label' => $activeRoom, 'active' => true, 'prefix' => '#', 'tone' => 'room'],
['label' => 'Derek Bourgeois', 'prefix' => 'D', 'tone' => 'human'],
['label' => 'Planner Agent', 'prefix' => '@', 'tone' => 'bot'],
];
}
/**
* @return array<int, array{label: string, active?: bool, prefix: string, tone: string}>
*/
private function roomLinks(string $activeRoom): array
{
return [
['label' => $activeRoom, 'active' => true, 'prefix' => '#', 'tone' => 'room'],
['label' => '# product-direction', 'prefix' => '#', 'tone' => 'room'],
['label' => 'Founders', 'prefix' => 'F', 'tone' => 'human'],
];
}
/**
* @return array<int, array{label: string, active?: bool, prefix: string, tone: string}>
*/
private function chatLinks(): array
{
return [
['label' => 'Derek Bourgeois', 'prefix' => 'D', 'tone' => 'human'],
['label' => 'Planner Agent', 'prefix' => '@', 'tone' => 'bot'],
['label' => 'Research Model', 'prefix' => '@', 'tone' => 'bot'],
];
}
/**
* @return array<int, array{
* label: string,
* value: string,
* prefix: string,
* tone: string,
* subtitle: string
* }>
*/
private function chatContacts(): array
{
return [
[
'label' => 'Derek Bourgeois',
'value' => 'derek-bourgeois',
'prefix' => 'D',
'tone' => 'human',
'subtitle' => 'Human',
],
[
'label' => 'Planner Agent',
'value' => 'planner-agent',
'prefix' => '@',
'tone' => 'bot',
'subtitle' => 'Agent',
],
[
'label' => 'Research Model',
'value' => 'research-model',
'prefix' => '@',
'tone' => 'bot',
'subtitle' => 'Model',
],
];
}
/**
* @return array<int, array{label: string, value: string}>
*/
private function workspaceTargets(): array
{
return [
['label' => 'Katra Local', 'value' => 'local'],
['label' => 'Relay Cloud', 'value' => 'relay-cloud'],
];
}
/**
* @param array{
* tasks: array<int, array{label: string, status: string, summary: string}>,
* artifacts: array<int, array{label: string, kind: string, summary: string}>,
* decisions: array<int, array{label: string, owner: string, summary: string}>
* } $workspace
* @return array<int, array{
* key: string,
* label: string,
* groups: array<int, array{
* label: string,
* items: array<int, array{
* label: string,
* meta: string,
* status: string,
* summary: string
* }>
* }>
* }>
*/
private function conversationNodeTabs(array $workspace): array
{
$openTasks = collect($workspace['tasks'])
->take(2)
->map(fn (array $task): array => [
'label' => $task['label'],
'meta' => $task['status'],
'status' => $task['status'],
'summary' => $task['summary'],
])
->values()
->all();
$openArtifacts = collect($workspace['artifacts'])
->take(1)
->map(fn (array $artifact): array => [
'label' => $artifact['label'],
'meta' => $artifact['kind'],
'status' => 'Open',
'summary' => $artifact['summary'],
])
->values()
->all();
$openDecisions = collect($workspace['decisions'])
->take(1)
->map(fn (array $decision): array => [
'label' => $decision['label'],
'meta' => $decision['owner'],
'status' => 'Open',
'summary' => $decision['summary'],
])
->values()
->all();
$closedTasks = collect($workspace['tasks'])
->slice(2, 1)
->map(fn (array $task): array => [
'label' => $task['label'],
'meta' => 'Closed',
'status' => 'Closed',
'summary' => $task['summary'],
])
->values()
->all();
$closedArtifacts = collect($workspace['artifacts'])
->slice(1, 1)
->map(fn (array $artifact): array => [
'label' => $artifact['label'],
'meta' => 'Archived',
'status' => 'Archived',
'summary' => $artifact['summary'],
])
->values()
->all();
$closedDecisions = collect($workspace['decisions'])
->slice(1, 1)
->map(fn (array $decision): array => [
'label' => $decision['label'],
'meta' => 'Settled',
'status' => 'Settled',
'summary' => $decision['summary'],
])
->values()
->all();
return [
[
'key' => 'open',
'label' => 'Open',
'groups' => [
['label' => 'Tasks', 'items' => $openTasks],
['label' => 'Artifacts', 'items' => $openArtifacts],
['label' => 'Decisions', 'items' => $openDecisions],
],
],
[
'key' => 'closed',
'label' => 'Closed',
'groups' => [
['label' => 'Tasks', 'items' => $closedTasks],
['label' => 'Artifacts', 'items' => $closedArtifacts],
['label' => 'Decisions', 'items' => $closedDecisions],
],
],
];
}
public function __invoke(Request $request, SurrealRuntimeManager $runtimeManager): View
{
$localReady = false;
$desktopUiStates = DesktopUi::states();
$mvpShellEnabled = DesktopUi::enabled($desktopUiStates, MvpShell::class);
try {
if ($runtimeManager->ensureReady()) {
Workspace::desktopPreview();
$localReady = true;
}
} catch (Throwable $exception) {
if (! $exception instanceof RuntimeException) {
report($exception);
}
}
$workspaces = $this->workspaces($localReady);
$selectedWorkspace = $request->string('workspace')->value();
$activeWorkspace = array_key_exists($selectedWorkspace, $workspaces) ? $selectedWorkspace : 'katra-local';
$activeWorkspaceState = $workspaces[$activeWorkspace];
return view('welcome', [
'mvpShellEnabled' => $mvpShellEnabled,
'activeWorkspace' => $activeWorkspaceState,
'workspaceLinks' => $this->workspaceLinks($workspaces, $activeWorkspace),
'workspaceTargets' => $this->workspaceTargets(),
'favoriteLinks' => $this->favoriteLinks($activeWorkspaceState['room']),
'roomLinks' => $this->roomLinks($activeWorkspaceState['room']),
'chatLinks' => $this->chatLinks(),
'chatContacts' => $this->chatContacts(),
'conversationNodeTabs' => $this->conversationNodeTabs($activeWorkspaceState),
'messages' => $activeWorkspaceState['messages'],
'participants' => $activeWorkspaceState['participants'],
]);
}
}