fnloom 0.1.0 → 0.2.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.
Files changed (113) hide show
  1. package/README.md +31 -18
  2. package/package.json +2 -7
  3. package/packages/build/package.json +1 -1
  4. package/packages/cli/package.json +1 -1
  5. package/packages/cli/src/commands/available.ts +63 -22
  6. package/packages/cli/src/commands/install.ts +86 -28
  7. package/packages/cli/src/index.ts +3 -2
  8. package/packages/cli/src/local.ts +6 -0
  9. package/packages/cli/src/premade.ts +80 -0
  10. package/packages/core/package.json +1 -1
  11. package/packages/hub/package.json +1 -1
  12. package/packages/hub/src/link/process.ts +6 -1
  13. package/packages/sdk/package.json +1 -1
  14. package/packages/web/package.json +1 -1
  15. package/premade/claude.zip +0 -0
  16. package/premade/database.zip +0 -0
  17. package/premade/web.zip +0 -0
  18. package/scripts/dev-env.ts +4 -4
  19. package/scripts/stack.ts +42 -27
  20. package/scripts/start.ts +26 -16
  21. package/systems/api/package.json +1 -1
  22. package/systems/code/package.json +1 -1
  23. package/systems/embedder/package.json +1 -1
  24. package/systems/fs/package.json +1 -1
  25. package/systems/google-calendar/package.json +1 -1
  26. package/systems/input/package.json +1 -1
  27. package/systems/mcp/package.json +1 -1
  28. package/systems/ollama/package.json +1 -1
  29. package/systems/schedule/package.json +1 -1
  30. package/systems/template/package.json +1 -1
  31. package/systems/widgets/package.json +1 -1
  32. package/systems/claude/client/FleetPage.vue +0 -132
  33. package/systems/claude/client/NewSessionForm.vue +0 -62
  34. package/systems/claude/client/SessionList.vue +0 -64
  35. package/systems/claude/client/SessionPage.vue +0 -199
  36. package/systems/claude/client/TaskList.vue +0 -61
  37. package/systems/claude/client/fakes.ts +0 -186
  38. package/systems/claude/client/host.ts +0 -23
  39. package/systems/claude/client/index.ts +0 -15
  40. package/systems/claude/client/logic.ts +0 -270
  41. package/systems/claude/client/state.ts +0 -344
  42. package/systems/claude/package.json +0 -23
  43. package/systems/claude/server/agent-sdk.ts +0 -379
  44. package/systems/claude/server/driver.ts +0 -153
  45. package/systems/claude/server/env.ts +0 -64
  46. package/systems/claude/server/fake-driver.ts +0 -112
  47. package/systems/claude/server/fleet.ts +0 -376
  48. package/systems/claude/server/impl.ts +0 -568
  49. package/systems/claude/server/index.ts +0 -8
  50. package/systems/claude/server/main.ts +0 -38
  51. package/systems/claude/server/preview.ts +0 -76
  52. package/systems/claude/server/questions.ts +0 -117
  53. package/systems/claude/server/transcript.ts +0 -83
  54. package/systems/claude/shared/index.ts +0 -262
  55. package/systems/claude/shared/session.ts +0 -284
  56. package/systems/claude/shared/shapes.ts +0 -106
  57. package/systems/claude/system.json +0 -18
  58. package/systems/claude/tsconfig.json +0 -6
  59. package/systems/database/package.json +0 -25
  60. package/systems/database/server/author.ts +0 -41
  61. package/systems/database/server/authoring.ts +0 -322
  62. package/systems/database/server/catalog.ts +0 -117
  63. package/systems/database/server/compile.ts +0 -332
  64. package/systems/database/server/dialects.ts +0 -17
  65. package/systems/database/server/drivers/database.ts +0 -71
  66. package/systems/database/server/drivers/index.ts +0 -23
  67. package/systems/database/server/drivers/postgres.ts +0 -157
  68. package/systems/database/server/drivers/sqlite.ts +0 -151
  69. package/systems/database/server/drivers/sqlserver.ts +0 -176
  70. package/systems/database/server/env.ts +0 -35
  71. package/systems/database/server/fixture.ts +0 -169
  72. package/systems/database/server/impl.ts +0 -793
  73. package/systems/database/server/index.ts +0 -7
  74. package/systems/database/server/instance.ts +0 -398
  75. package/systems/database/server/main.ts +0 -47
  76. package/systems/database/server/pick.ts +0 -97
  77. package/systems/database/server/queries.ts +0 -390
  78. package/systems/database/server/results.ts +0 -39
  79. package/systems/database/server/schema.ts +0 -59
  80. package/systems/database/server/table-fns.ts +0 -237
  81. package/systems/database/server/types.ts +0 -253
  82. package/systems/database/shared/index.ts +0 -544
  83. package/systems/database/shared/shapes.ts +0 -413
  84. package/systems/database/system.json +0 -14
  85. package/systems/database/tsconfig.json +0 -6
  86. package/systems/web/client/ReadView.vue +0 -110
  87. package/systems/web/client/SearchView.vue +0 -215
  88. package/systems/web/client/StatusChip.vue +0 -38
  89. package/systems/web/client/fakes.ts +0 -48
  90. package/systems/web/client/index.ts +0 -15
  91. package/systems/web/client/view.ts +0 -131
  92. package/systems/web/package.json +0 -22
  93. package/systems/web/server/chrome.ts +0 -121
  94. package/systems/web/server/crawl.ts +0 -333
  95. package/systems/web/server/env.ts +0 -63
  96. package/systems/web/server/guard.ts +0 -60
  97. package/systems/web/server/http.ts +0 -89
  98. package/systems/web/server/impl.ts +0 -203
  99. package/systems/web/server/index.ts +0 -71
  100. package/systems/web/server/loader.ts +0 -104
  101. package/systems/web/server/main.ts +0 -70
  102. package/systems/web/server/mentions.ts +0 -111
  103. package/systems/web/server/problem.ts +0 -72
  104. package/systems/web/server/renderer.ts +0 -243
  105. package/systems/web/server/robots.ts +0 -75
  106. package/systems/web/server/searches.ts +0 -29
  107. package/systems/web/server/tavily.ts +0 -144
  108. package/systems/web/server/testing.ts +0 -165
  109. package/systems/web/server/uploads.ts +0 -33
  110. package/systems/web/shared/index.ts +0 -343
  111. package/systems/web/shared/urls.ts +0 -60
  112. package/systems/web/system.json +0 -15
  113. package/systems/web/tsconfig.json +0 -6
@@ -1,199 +0,0 @@
1
- <script setup lang="ts">
2
- /**
3
- * One Claude session (`/s/claude/session/<instance>/<session>`): where it works and how it is set, what waits on the
4
- * person (its approvals and questions as cards answered right here; they also show in its chat and the inbox), its
5
- * transcript drawn with the chat's own parts (the person's messages as bubbles, Claude's turns as answers with their
6
- * reasoning folded and tool uses as run cards, a stretch of them folded into one section; a subagent's own with
7
- * `?task=`), its tasks and workflows with their progress, and the chat's composer pinned under it. Send, Stop
8
- * (interrupt), Stop session and the permission mode act on it as the person's runs in the session's chat, each
9
- * waiting for its run to settle with its outcome, so a send that went through is never reported as failed.
10
- */
11
- import { InstanceName, type Json, type Remember, type SessionId } from '@harness/core';
12
- import type { PageViewOf } from '@harness/sdk';
13
- import { computed, nextTick, onBeforeUnmount, ref, shallowRef, watch } from 'vue';
14
- import { CLAUDE_PAGES, CLAUDE_SYSTEM, ClaudePermissionMode, ClaudeSessionId, asksPerson, type ClaudeContract, type ClaudeControl } from '../shared/index.ts';
15
- import { plainClick } from './host.ts';
16
- import TaskList from './TaskList.vue';
17
- import { folderName, isLive, MODE_CHOICES, MODE_LABEL, statusLook, taskTree, transcriptEntries } from './logic.ts';
18
- import { ClaudeSessionStore, type WaitingCard } from './state.ts';
19
-
20
- /** How often the session is read again while the page is open (ms). */
21
- const REFRESH = 3_000;
22
-
23
- const view = defineProps<PageViewOf<ClaudeContract>>();
24
- const host = view.host;
25
- const { Frame, Badge, Banner, Button, Select, Empty, Skeleton, Approval, Conversation, Composer } = host.components;
26
-
27
- const task = computed(() => host.query.get('task') ?? '');
28
- const now = ref(Date.now());
29
-
30
- const store = shallowRef<ClaudeSessionStore | undefined>(undefined);
31
- const end = ref<HTMLElement | null>(null);
32
- watch(() => [view.path[0] ?? '', view.path[1] ?? '', task.value] as const, ([rawInstance, rawSession, agent]) => {
33
- store.value?.close();
34
- const instance = InstanceName.safeParse(rawInstance);
35
- const session = ClaudeSessionId.safeParse(rawSession);
36
- if (!instance.success || !session.success) { store.value = undefined; return; }
37
- const next = new ClaudeSessionStore({ hub: host.hub, runs: (options) => host.runs(options), inbox: host.inbox }, { instance: instance.data, session: session.data }, agent === '' ? undefined : agent);
38
- store.value = next;
39
- // open at the newest: the end of the transcript, by the composer
40
- void next.open().then(() => nextTick(() => { end.value?.scrollIntoView({ block: 'end' }); }));
41
- }, { immediate: true });
42
- onBeforeUnmount(() => { store.value?.close(); });
43
- host.live(() => { now.value = Date.now(); void store.value?.refresh(); }, REFRESH);
44
-
45
- const record = computed(() => store.value?.record.value?.value);
46
- const title = computed(() => record.value?.title || (record.value === undefined ? 'Claude session' : folderName(record.value.folder)));
47
- const look = computed(() => (record.value === undefined ? undefined : statusLook(record.value)));
48
- const live = computed(() => record.value !== undefined && isLive(record.value.status));
49
- const tasks = computed(() => taskTree(record.value?.tasks ?? []));
50
- const openTask = computed(() => record.value?.tasks.find((t) => t.id === task.value));
51
- const waiting = computed(() => store.value?.waiting.value ?? []);
52
- const entries = computed(() => transcriptEntries(store.value?.items.value ?? [], store.value?.busy.value ?? false));
53
- /** The fleet, and this session's main transcript (a subagent's is open with `?task=`). */
54
- const FLEET = { page: CLAUDE_PAGES.fleet, query: {} } as const;
55
- const MAIN = computed(() => ({ query: { ...host.query.values, task: undefined } }));
56
- const fleetHref = computed(() => host.href(FLEET));
57
- const mainHref = computed(() => host.href(MAIN.value));
58
- function toFleet(event: MouseEvent): void { if (plainClick(event)) { host.go(FLEET); } }
59
- function toMain(event: MouseEvent): void { if (plainClick(event)) { host.go(MAIN.value); } }
60
- function toChat(event: MouseEvent, chat: SessionId): void { if (plainClick(event)) { host.goChat(chat); } }
61
-
62
- const mode = computed({
63
- get: (): string => record.value?.permissionMode ?? 'default',
64
- set: (next: string) => {
65
- const parsed = ClaudePermissionMode.safeParse(next);
66
- if (parsed.success && parsed.data !== record.value?.permissionMode) { void act('mode', parsed.data); }
67
- },
68
- });
69
- const composerNote = computed(() => {
70
- if (record.value === undefined) { return ''; }
71
- if (record.value.status === 'closed' || record.value.status === 'failed') { return 'Sending resumes the session.'; }
72
- return record.value.status === 'working' ? 'Claude reads it after the current step.' : '';
73
- });
74
-
75
- /** What the composer holds: it clears only once the message went. */
76
- const text = ref('');
77
-
78
- async function act(action: ClaudeControl['action'], next?: ClaudePermissionMode): Promise<void> {
79
- const current = store.value;
80
- if (current === undefined) { return; }
81
- if (await current.control(action, next)) { host.notify.ok(next !== undefined ? (asksPerson(next) ? `Approve ${MODE_LABEL[next]} on its card` : `Mode: ${MODE_LABEL[next]}`) : action === 'stop' ? 'Session stopped' : 'Interrupted'); }
82
- else { host.notify.error(action === 'mode' ? "Couldn't switch the mode" : action === 'stop' ? "Couldn't stop it" : "Couldn't interrupt it", current.problem.value); }
83
- }
84
-
85
- async function send(): Promise<void> {
86
- const current = store.value;
87
- const message = text.value.trim();
88
- if (current === undefined || message === '') { return; }
89
- const sent = await current.send(message);
90
- if (!sent) { host.notify.error("Couldn't send it", current.problem.value); return; }
91
- if (text.value.trim() === message) { text.value = ''; }
92
- await nextTick();
93
- end.value?.scrollIntoView({ block: 'end', behavior: 'smooth' });
94
- }
95
-
96
- async function decide(card: WaitingCard, approve: boolean, remember: Remember, reason: string, answer: Json | undefined): Promise<void> {
97
- const current = store.value;
98
- if (current === undefined) { return; }
99
- if (await current.decide(card, approve, remember, reason, answer)) { host.notify.ok(card.approval.ask !== undefined && approve ? 'Answered' : approve ? 'Approved' : 'Denied'); }
100
- else { host.notify.error("Couldn't send your answer", current.problem.value); }
101
- }
102
- </script>
103
-
104
- <template>
105
- <Frame :title="title" keep-title width="full">
106
- <template #crumb><a :href="fleetHref" @click="toFleet">Claude</a></template>
107
- <template v-if="record" #actions>
108
- <span class="mode">
109
- <span class="mode-word" aria-hidden="true">Permissions</span>
110
- <Select v-model="mode" :options="MODE_CHOICES" label="Permission mode" hide-label size="sm" :disabled="store?.controlling.value ?? false" data-testid="claude-mode" />
111
- </span>
112
- <Button v-if="live" size="sm" variant="secondary" icon="stop" data-testid="claude-stop" @click="act('stop')">Stop session</Button>
113
- </template>
114
-
115
- <Skeleton v-if="store === undefined || store.loading.value" shape="lines" :lines="6" />
116
- <Empty v-else-if="store.missing.value" icon="search" title="No such session of yours" body="It may be on another machine, or belong to someone else.">
117
- <template #actions><a :href="fleetHref" @click="toFleet">Back to your sessions</a></template>
118
- </Empty>
119
- <Banner v-else-if="record === undefined" tone="danger">{{ store.problem.value || "Couldn't read this session." }}</Banner>
120
-
121
- <div v-else class="session" data-testid="claude-session">
122
- <div class="facts" data-testid="claude-facts">
123
- <Badge v-if="look" :tone="look.tone" dot :live="look.live" data-testid="status">{{ look.word }}</Badge>
124
- <code class="folder" :title="record.folder">{{ record.folder }}</code>
125
- <span>{{ record.instance }}</span>
126
- <span v-if="record.model">{{ record.model }}</span>
127
- <span v-if="record.agent">as {{ record.agent }}</span>
128
- <span>{{ record.turns }} {{ record.turns === 1 ? 'turn' : 'turns' }}</span>
129
- <span class="cost" title="What the session has cost">{{ host.format.cost(record.costUsd) }}</span>
130
- <span :title="host.format.fullTime(record.updatedAt)">{{ host.format.relativeTime(record.updatedAt, now) }}</span>
131
- <a v-if="record.chat" :href="host.chatHref(record.chat)" data-testid="claude-chat" @click="toChat($event, record.chat)">Open its chat</a>
132
- </div>
133
- <Banner v-if="record.problem" tone="danger">{{ record.problem }}</Banner>
134
-
135
- <section v-if="waiting.length > 0" class="waiting" aria-label="Waiting for you" data-testid="claude-waiting">
136
- <Approval
137
- v-for="card in waiting" :key="card.approval.id" :approval="card.approval" :in-chat="card.inChat"
138
- @decide="(approve: boolean, remember: Remember, reason: string, answer: Json | undefined) => decide(card, approve, remember, reason, answer)"
139
- />
140
- </section>
141
- <p v-else-if="store.awaiting.value" class="note">
142
- Your run waits for approval in <a v-if="record.chat" :href="host.chatHref(record.chat)" @click="toChat($event, record.chat)">the session's chat</a><template v-else>the session's chat</template>.
143
- </p>
144
-
145
- <div class="body" :class="{ 'with-side': tasks.length > 0 }">
146
- <aside v-if="tasks.length > 0" class="side" aria-label="Tasks and workflows">
147
- <h2 class="heading">Tasks and workflows</h2>
148
- <TaskList :nodes="tasks" :open="task" />
149
- </aside>
150
- <div class="main">
151
- <Banner v-if="task !== ''" tone="accent" data-testid="claude-task-banner">
152
- The transcript of {{ openTask?.name || openTask?.description || 'a subagent' }}.
153
- <template #actions><a :href="mainHref" @click="toMain">Main transcript</a></template>
154
- </Banner>
155
- <Banner v-if="store.transcriptProblem.value" tone="danger">{{ store.transcriptProblem.value }}</Banner>
156
- <div v-if="store.older.value || store.transcriptLoading.value" class="earlier">
157
- <Button size="sm" variant="ghost" icon="chevron-up" :loading="store.transcriptLoading.value" data-testid="transcript-more" @click="store.more()">Show earlier</Button>
158
- </div>
159
- <Conversation :entries="entries" :agent="'Claude'" :system="CLAUDE_SYSTEM" :streaming="store.busy.value" data-testid="claude-transcript" />
160
- <p v-if="entries.length === 0 && !store.transcriptLoading.value && !store.transcriptProblem.value" class="note">Nothing in the transcript yet.</p>
161
- <div ref="end" class="end" aria-hidden="true" />
162
- <div v-if="task === ''" class="dock" data-testid="claude-composer">
163
- <Composer
164
- v-model="text" placeholder="Message Claude" :sending="store.sending.value" :running="store.busy.value" :stopping="store.controlling.value" :note="composerNote"
165
- @send="send" @stop="act('interrupt')"
166
- />
167
- </div>
168
- </div>
169
- </div>
170
- </div>
171
- </Frame>
172
- </template>
173
-
174
- <style scoped>
175
- .mode { display: inline-flex; align-items: center; gap: var(--space-2); }
176
- .mode-word { color: var(--text-dim); font-size: var(--text-sm); white-space: nowrap; }
177
- .session { display: grid; gap: var(--space-4); min-width: 0; }
178
- .facts { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1) var(--space-3); min-width: 0; color: var(--text-dim); font-size: var(--text-sm); }
179
- .folder { overflow: hidden; max-width: 100%; text-overflow: ellipsis; white-space: nowrap; }
180
- .cost { font-variant-numeric: tabular-nums; }
181
- .waiting { display: grid; gap: var(--space-3); min-width: 0; }
182
- .body { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-5); align-items: start; min-width: 0; }
183
- .body.with-side { grid-template-columns: minmax(0, 1fr) minmax(240px, 320px); }
184
- .main { display: grid; gap: var(--space-3); min-width: 0; grid-column: 1; grid-row: 1; max-width: 860px; width: 100%; justify-self: center; }
185
- .side { display: grid; gap: var(--space-3); min-width: 0; grid-column: 2; grid-row: 1; position: sticky; top: var(--space-4); padding: var(--space-3); border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); }
186
- .heading { margin: 0; font-size: var(--text-sm); font-weight: var(--weight-strong); }
187
- .note { margin: 0; color: var(--text-dim); font-size: var(--text-sm); }
188
- .earlier { display: flex; justify-content: center; }
189
- .end { height: 1px; }
190
- /* the composer stays pinned under the transcript, as in the chat */
191
- .dock { position: sticky; bottom: 0; z-index: 1; padding: var(--space-2) 0 var(--space-3); background: linear-gradient(to bottom, transparent, var(--bg) 30%); }
192
- /* on a phone the select says what it is by its value; the word would push Stop off the row */
193
- @media (max-width: 559.98px) { .mode-word { display: none; } }
194
- @media (max-width: 899.98px) {
195
- .body.with-side { grid-template-columns: minmax(0, 1fr); }
196
- .side { grid-column: 1; grid-row: 1; position: static; }
197
- .main { grid-row: 2; }
198
- }
199
- </style>
@@ -1,61 +0,0 @@
1
- <script setup lang="ts">
2
- /**
3
- * A session's tasks and workflows with their progress, as a tree: each task its kind, name, status and latest progress
4
- * line, the tasks it started under it. A subagent's own transcript opens from its row (`?task=`); the one open is
5
- * marked, and its link goes back to the main transcript.
6
- */
7
- import { plainClick, usePageHost } from './host.ts';
8
- import { TASK_ICON, TASK_LOOK, type TaskNode } from './logic.ts';
9
-
10
- defineProps<{
11
- nodes: readonly TaskNode[];
12
- /** The task whose transcript is open ('' for the main one). */
13
- open: string;
14
- depth?: number;
15
- }>();
16
-
17
- const host = usePageHost();
18
- const { Badge, Icon } = host.components;
19
- /** The session page with this task's transcript open, or the main one again when it is the open one. */
20
- const toTask = (id: string, open: string) => ({ query: { ...host.query.values, task: open === id ? undefined : id } });
21
-
22
- function go(event: MouseEvent, id: string, open: string): void {
23
- if (plainClick(event)) { host.go(toTask(id, open)); }
24
- }
25
- </script>
26
-
27
- <template>
28
- <ul class="tasks" :class="{ nested: (depth ?? 0) > 0 }" data-testid="claude-tasks">
29
- <li v-for="node in nodes" :key="node.task.id" :data-task="node.task.id">
30
- <div class="row" :class="{ open: open === node.task.id }">
31
- <span class="kind" :title="node.task.kind"><Icon :name="TASK_ICON[node.task.kind]" :size="14" /></span>
32
- <span class="main">
33
- <span class="top">
34
- <span class="name">{{ node.task.name || node.task.description }}</span>
35
- <Badge :tone="TASK_LOOK[node.task.status].tone" dot :live="TASK_LOOK[node.task.status].live">{{ TASK_LOOK[node.task.status].word }}</Badge>
36
- </span>
37
- <span v-if="node.task.name && node.task.description" class="description">{{ node.task.description }}</span>
38
- <span v-if="node.task.progress" class="progress" data-testid="task-progress">{{ node.task.progress }}</span>
39
- <a v-if="node.task.kind === 'agent'" class="link" :href="host.href(toTask(node.task.id, open))" data-testid="task-transcript" @click="go($event, node.task.id, open)">
40
- {{ open === node.task.id ? 'Back to the main transcript' : 'Its transcript' }}
41
- </a>
42
- </span>
43
- </div>
44
- <TaskList v-if="node.children.length > 0" :nodes="node.children" :open="open" :depth="(depth ?? 0) + 1" />
45
- </li>
46
- </ul>
47
- </template>
48
-
49
- <style scoped>
50
- .tasks { display: grid; gap: var(--space-2); margin: 0; padding: 0; list-style: none; min-width: 0; }
51
- .tasks.nested { margin-top: var(--space-2); padding-left: var(--space-4); border-left: 1px solid var(--border); }
52
- .row { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: var(--space-2); min-width: 0; padding: var(--space-1); border-radius: var(--radius); }
53
- .row.open { background: var(--accent-soft); }
54
- .kind { display: grid; place-items: center; width: 24px; height: 24px; border-radius: var(--radius); background: var(--surface-2); color: var(--text-dim); }
55
- .main { display: grid; gap: 2px; min-width: 0; }
56
- .top { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1) var(--space-2); }
57
- .name { font-size: var(--text-sm); font-weight: var(--weight-medium); overflow-wrap: anywhere; }
58
- .description, .progress { color: var(--text-dim); font-size: var(--text-xs); overflow-wrap: anywhere; }
59
- .progress { font-family: var(--mono); }
60
- .link { width: fit-content; font-size: var(--text-xs); }
61
- </style>
@@ -1,186 +0,0 @@
1
- /**
2
- * Fakes for the Claude pages' tests: a session record; the hub as a real ayepi web client whose HTTP answers come from
3
- * the test (the `records` and `readFn` reads, so queries are checked against the hub's own spec); a page's runs and
4
- * inbox that record what they were asked; and a page host whose shared components are plain stand-ins (the app's own
5
- * are tested with the app). Each stand-in draws its props as data attributes and its slots.
6
- */
7
- import { client } from '@ayepi/core/client';
8
- import { ActorId, DataRecord, hubWebSpec, Json, RecordQuery, type Approval, type HubWebSpec, type RecordPage, type RunId } from '@harness/core';
9
- import type { ComposerProps, ConversationProps, HubClient, LoadStateProps, PageHost, PageInbox, PageRuns, PageRunsOptions, RunOutcome, SharedComponents } from '@harness/sdk';
10
- import { h, reactive, shallowReactive, type FunctionalComponent } from 'vue';
11
- import { z } from 'zod';
12
- import { ClaudeSession } from '../shared/session.ts';
13
-
14
- export const T0 = 1_762_000_000_000;
15
- export const SESSION = '0b6f3c1e-4a3e-4c55-9d5c-2f1e8a7b9c10';
16
-
17
- /** A session as the hub keeps it. */
18
- export function sessionValue(overrides: Partial<ClaudeSession> = {}): ClaudeSession {
19
- return ClaudeSession.parse({
20
- instance: 'main', session: SESSION, folder: 'C:/code/shop', title: 'Fix checkout', status: 'waiting', owner: 'act_ada', permissionMode: 'default',
21
- waiting: ['run_w1'], asking: [], tasks: [], turns: 2, costUsd: 0.12, startedAt: T0, updatedAt: T0, ...overrides,
22
- });
23
- }
24
-
25
- /** A session's record. */
26
- export function sessionRecord(value: unknown, id = 'rec_01JABCDEFGHJKMNPQRSTVWXYZ0'): DataRecord {
27
- return DataRecord.parse({ id, type: 'claude/Session', value: Json.parse(value), title: 'Fix checkout', version: 1, createdAt: T0, updatedAt: T0 });
28
- }
29
-
30
- /** What the fake hub answers. */
31
- export interface HubAnswers {
32
- records(query: RecordQuery): RecordPage;
33
- readFn?(input: { readonly fn: string; readonly args: Json }): Json;
34
- }
35
-
36
- /** The hub's web API as a real client, its `records` and `readFn` answered by the test; what each was asked is kept. */
37
- export function fakeHub(answers: HubAnswers) {
38
- const calls: { records: RecordQuery[]; readFn: { fn: string; args: Json }[] } = { records: [], readFn: [] };
39
- const answer = (name: string, body: unknown): unknown => {
40
- if (name === 'records') { const query = RecordQuery.parse(body); calls.records.push(query); return answers.records(query); }
41
- if (name === 'readFn') {
42
- const input = z.object({ fn: z.string(), args: Json }).parse(body);
43
- calls.readFn.push(input);
44
- return answers.readFn?.(input) ?? { items: [], offset: 0, end: 0 };
45
- }
46
- throw new Error(`the fake hub has no ${name}`);
47
- };
48
- const hub: HubClient = client<HubWebSpec>({
49
- baseUrl: 'http://hub.test/api', manifest: hubWebSpec,
50
- fetchImpl: async (request) => {
51
- const name = new URL(request.url).pathname.split('/').filter((part) => part !== '').at(-1) ?? '';
52
- const text = await request.text();
53
- try {
54
- return Response.json(answer(name, text === '' ? undefined : JSON.parse(text)));
55
- } catch (error) {
56
- return Response.json({ error: { code: 'FAILED', message: error instanceof Error ? error.message : String(error) } }, { status: 422 });
57
- }
58
- },
59
- });
60
- return { hub, calls };
61
- }
62
-
63
- /** What a fake page's runs hold: the test sets them. */
64
- export interface FakeRunsState {
65
- approvals: Approval[];
66
- args: Map<RunId, Json>;
67
- problem: string;
68
- }
69
-
70
- /** What a fake page's runs were asked. */
71
- export interface FakeRunsCalls {
72
- runs: { fn: string; args: Json; on?: string | undefined }[];
73
- attached: string[];
74
- made: string[];
75
- closed: number;
76
- approved: { id: string; approve: boolean; answer: Json | undefined }[];
77
- }
78
-
79
- /** A page's runs: each run is recorded and answered by `answer`; its approvals and their runs' args are the test's. */
80
- export function fakeRuns(answer: (fn: string, args: Json) => RunOutcome = () => ({ ok: true, output: null })) {
81
- const state: FakeRunsState = shallowReactive({ approvals: [], args: new Map(), problem: '' });
82
- const calls: FakeRunsCalls = { runs: [], attached: [], made: [], closed: 0, approved: [] };
83
- const make = (options: PageRunsOptions): PageRuns => {
84
- calls.made.push(options.title());
85
- return {
86
- get approvals() { return state.approvals; },
87
- get problem() { return state.problem; },
88
- argsOf: (run) => state.args.get(run),
89
- attach: (session) => { calls.attached.push(session); },
90
- run: (fn, args, more) => { calls.runs.push({ fn, args, on: more?.on }); more?.waiting?.(); return Promise.resolve(answer(fn, args)); },
91
- approve: (approval, approve, _remember, _reason, given) => { calls.approved.push({ id: approval.id, approve, answer: given }); return Promise.resolve(true); },
92
- refresh: () => undefined,
93
- close: () => { calls.closed++; },
94
- };
95
- };
96
- return { make, state, calls };
97
- }
98
-
99
- /** The inbox's approvals, by run. */
100
- export function fakeInbox(approvals: readonly Approval[] = []) {
101
- const loaded: RunId[][] = [];
102
- const decided: { id: string; approve: boolean; answer: Json | undefined }[] = [];
103
- const inbox: PageInbox = {
104
- byRun: (run) => approvals.find((approval) => approval.run === run),
105
- load: (runs) => { loaded.push([...runs]); return Promise.resolve(); },
106
- decide: (approval, approve, _reason, answer) => { decided.push({ id: approval.id, approve, answer }); return Promise.resolve(true); },
107
- problem: '',
108
- };
109
- return { inbox, loaded, decided };
110
- }
111
-
112
- /**
113
- * A stand-in for a shared component: a `div` naming it, its model as `data-value` (with an `input` that edits a text
114
- * model, so a test types into it), and its slots.
115
- */
116
- function standIn<P extends object>(name: string): FunctionalComponent<P, { 'update:modelValue': [value: string] }> {
117
- const part: FunctionalComponent<P, { 'update:modelValue': [value: string] }> = (props, { slots, attrs, emit }) => {
118
- // a prop no stand-in declares keeps the name the template wrote it with
119
- const model: unknown = Reflect.get(props, 'modelValue') ?? Reflect.get(props, 'model-value');
120
- const open: unknown = Reflect.get(props, 'open');
121
- return h('div', { ...attrs, 'data-part': name, 'data-value': model === undefined ? undefined : JSON.stringify(model) }, [
122
- typeof model === 'string' ? h('input', { value: model, onInput: (event: Event) => { if (event.target instanceof HTMLInputElement) { emit('update:modelValue', event.target.value); } } }) : undefined,
123
- slots['crumb']?.(), slots['actions']?.(), open === false ? undefined : slots['default']?.(), open === false ? undefined : slots['footer']?.(),
124
- ]);
125
- };
126
- part.displayName = `Fake${name}`;
127
- return part;
128
- }
129
-
130
- /** The shared components as stand-ins: `LoadState` draws its content once ready (else its empty slot), `Conversation` its entries. */
131
- export function fakeComponents(): SharedComponents {
132
- const LoadState: FunctionalComponent<LoadStateProps> = (props, { slots }) => h('div', { 'data-part': 'LoadState' },
133
- props.loading ? 'loading' : props.problem !== '' ? props.problem : props.empty ? slots['empty']?.() : props.ready ? slots['default']?.() : undefined);
134
- const Conversation: FunctionalComponent<ConversationProps> = (props, { attrs }) => h('div', {
135
- ...attrs, 'data-part': 'Conversation', 'data-entries': JSON.stringify(props.entries), 'data-streaming': String(props.streaming === true),
136
- });
137
- // the composer: a box for the text, Send and Stop, so a test types and presses them as a person would
138
- const Composer: FunctionalComponent<ComposerProps, { 'update:modelValue': [text: string]; send: []; stop: [] }> = (props, { emit, attrs }) => h('div', { ...attrs, 'data-part': 'Composer' }, [
139
- h('textarea', { value: props.modelValue, onInput: (event: Event) => { if (event.target instanceof HTMLTextAreaElement) { emit('update:modelValue', event.target.value); } } }),
140
- h('button', { 'data-action': 'send', onClick: () => { emit('send'); } }, 'Send'),
141
- h('button', { 'data-action': 'stop', onClick: () => { emit('stop'); } }, 'Stop'),
142
- ]);
143
- Composer.props = ['modelValue'];
144
- Composer.emits = ['update:modelValue', 'send', 'stop'];
145
- return {
146
- Frame: standIn('Frame'), Input: standIn('Input'), Markdown: standIn('Markdown'), Icon: standIn('Icon'), Empty: standIn('Empty'), LoadState,
147
- Reasoning: standIn('Reasoning'), Typing: standIn('Typing'), ResourceViewer: standIn('ResourceViewer'), ValueEditor: standIn('ValueEditor'),
148
- Button: standIn('Button'), Select: standIn('Select'), Textarea: standIn('Textarea'), Dialog: standIn('Dialog'), Banner: standIn('Banner'), Badge: standIn('Badge'),
149
- Skeleton: standIn('Skeleton'), FnPill: standIn('FnPill'), Approval: standIn('Approval'), Conversation, Composer,
150
- };
151
- }
152
-
153
- /** A page host over these fakes, at a URL query the test can change (`query`), recording where the page went and what it said. */
154
- export function fakeHost(options: { hub: HubClient; runs?: ReturnType<typeof fakeRuns>; inbox?: PageInbox; query?: Readonly<Record<string, string>> }) {
155
- const query = reactive<Record<string, string>>({ ...options.query });
156
- const moves: unknown[] = [];
157
- const notes: { tone: 'ok' | 'error'; title: string; detail?: string | undefined }[] = [];
158
- const set = (patch: Readonly<Record<string, string | undefined>>): void => {
159
- for (const [key, value] of Object.entries(patch)) { if (value === undefined || value === '') { Reflect.deleteProperty(query, key); } else { query[key] = value; } }
160
- };
161
- const runs = options.runs ?? fakeRuns();
162
- const host: PageHost = {
163
- user: { id: ActorId.parse('act_ada'), kind: 'user', name: 'Ada', role: 'member', email: 'ada@example.test' },
164
- hub: options.hub,
165
- query: {
166
- get values() { return { ...query }; },
167
- get: (key) => query[key],
168
- set: (patch) => { set(patch); },
169
- bind: (key, fallback = '') => ({ get value() { return query[key] ?? fallback; }, set value(next: string) { set({ [key]: next === fallback ? undefined : next }); } }),
170
- },
171
- href: (to) => `/s/claude/${to.page ?? 'here'}/${(to.path ?? []).join('/')}`,
172
- chatHref: (session) => `/c/${session}`,
173
- goChat: (session) => { moves.push({ chat: session }); },
174
- runHref: (run) => `/run/${run}`,
175
- goRun: (run) => { moves.push({ run }); },
176
- go: (to) => { moves.push(to); },
177
- openChat: () => Promise.resolve(),
178
- components: fakeComponents(),
179
- runs: (made) => runs.make(made),
180
- inbox: options.inbox ?? fakeInbox().inbox,
181
- notify: { ok: (title, detail) => { notes.push({ tone: 'ok', title, detail }); }, error: (title, detail) => { notes.push({ tone: 'error', title, detail }); } },
182
- format: { cost: (usd) => `$${usd.toFixed(2)}`, relativeTime: () => 'just now', fullTime: () => 'today' },
183
- live: () => undefined,
184
- };
185
- return { host, query, moves, notes, runs };
186
- }
@@ -1,23 +0,0 @@
1
- /**
2
- * The page host for the parts under a Claude page (`inject(PAGE_HOST)`): the same host the page gets as `host`, so a
3
- * row links to a session and draws with the app's components without each part being handed them.
4
- */
5
- import { PAGE_HOST, type PageHost } from '@harness/sdk';
6
- import { inject } from 'vue';
7
-
8
- /** The page's host; throws outside a system page. */
9
- export function usePageHost(): PageHost {
10
- const host = inject(PAGE_HOST);
11
- if (host === undefined) { throw new Error('a Claude page part needs the page host (PAGE_HOST)'); }
12
- return host;
13
- }
14
-
15
- /**
16
- * Whether a click on a link is a plain one, which the page handles by moving itself (`host.go`); a click that opens a
17
- * new tab or window keeps the link's own way. A plain click's default is prevented.
18
- */
19
- export function plainClick(event: MouseEvent): boolean {
20
- if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey || event.button !== 0) { return false; }
21
- event.preventDefault();
22
- return true;
23
- }
@@ -1,15 +0,0 @@
1
- /**
2
- * The claude system's client (item 8/9): its pages, typed by its contract. The app loads this build from the hub and
3
- * draws the fleet at `/s/claude/sessions` and one session at `/s/claude/session/<instance>/<session>` while the system
4
- * is installed and live; both draw with the app's own components and the chat's own parts (`host.components`).
5
- */
6
- // typescript-eslint can't see the types of .vue modules from .ts files; vue-tsc checks this file
7
- /* eslint-disable @typescript-eslint/no-unsafe-assignment */
8
- import { client } from '@harness/sdk';
9
- import { claude } from '../shared/index.ts';
10
- import FleetPage from './FleetPage.vue';
11
- import SessionPage from './SessionPage.vue';
12
-
13
- export default client(claude, {
14
- pages: { FleetPage, SessionPage },
15
- });