create-feltkit 0.4.0 → 0.5.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 (74) hide show
  1. package/bin/create.js +3 -3
  2. package/package.json +4 -4
  3. package/scaffold.d.ts +1 -1
  4. package/scaffold.js +8 -5
  5. package/template/README.md +72 -177
  6. package/template/_gitignore +4 -0
  7. package/template/agent/agent.ts +28 -0
  8. package/template/agent/channels/eve.ts +6 -0
  9. package/template/agent/instructions.md +24 -0
  10. package/template/agent/lib/deterministic.ts +46 -0
  11. package/template/agent/lib/feltkit-capabilities.json +294 -0
  12. package/template/agent/tools/crew_artifacts_create.ts +4 -0
  13. package/template/agent/tools/crew_context_read.ts +4 -0
  14. package/template/agent/tools/crew_context_record.ts +4 -0
  15. package/template/agent/tools/crew_context_search.ts +4 -0
  16. package/template/agent/tools/crew_decisions_propose.ts +4 -0
  17. package/template/agent/tools/crew_tasks_add.ts +6 -0
  18. package/template/agent/tools/crew_tasks_list.ts +4 -0
  19. package/template/agent/tools/crew_tasks_note.ts +4 -0
  20. package/template/agent/tools/crew_workspace_overview.ts +4 -0
  21. package/template/agent/tools/crew_workstreams_update.ts +6 -0
  22. package/template/agent/tools/web_fetch.ts +1 -0
  23. package/template/agent/tools/web_search.ts +3 -0
  24. package/template/feltkit/_generated/api.ts +8 -4
  25. package/template/feltkit/activity.ts +26 -0
  26. package/template/feltkit/app.ts +147 -54
  27. package/template/feltkit/boards.ts +10 -0
  28. package/template/feltkit/decisions.ts +99 -0
  29. package/template/feltkit/knowledge.ts +119 -0
  30. package/template/feltkit/model.ts +96 -0
  31. package/template/feltkit/work.ts +45 -0
  32. package/template/feltkit/workspace.ts +171 -0
  33. package/template/index.html +1 -1
  34. package/template/native/App.tsx +249 -0
  35. package/template/package.json +11 -5
  36. package/template/shared/rules.ts +23 -0
  37. package/template/src/App.tsx +177 -528
  38. package/template/src/screens/activity.tsx +66 -0
  39. package/template/src/screens/agent.tsx +188 -0
  40. package/template/src/screens/context.tsx +71 -0
  41. package/template/src/screens/decisions.tsx +89 -0
  42. package/template/src/screens/home.tsx +140 -0
  43. package/template/src/screens/team.tsx +13 -0
  44. package/template/src/screens/work.tsx +149 -0
  45. package/template/src/styles.css +201 -118
  46. package/template/src/ui.tsx +179 -0
  47. package/template/tests/crew.test.ts +111 -0
  48. package/template/tsconfig.json +18 -3
  49. package/template-managed/Dockerfile +2 -2
  50. package/template-managed/README.md +1 -1
  51. package/template-managed/package.json +3 -3
  52. package/template-tasks/README.md +383 -0
  53. package/template-tasks/_gitignore +12 -0
  54. package/template-tasks/feltkit/_generated/api.ts +10 -0
  55. package/template-tasks/feltkit/app.ts +73 -0
  56. package/template-tasks/index.html +17 -0
  57. package/template-tasks/native/App.tsx +220 -0
  58. package/template-tasks/native/native.json +5 -0
  59. package/template-tasks/package.json +30 -0
  60. package/template-tasks/public/apple-touch-icon.png +0 -0
  61. package/template-tasks/public/favicon.png +0 -0
  62. package/template-tasks/public/theme.js +7 -0
  63. package/template-tasks/shared/rules.ts +18 -0
  64. package/template-tasks/src/App.tsx +557 -0
  65. package/template-tasks/src/main.tsx +17 -0
  66. package/template-tasks/src/styles.css +134 -0
  67. package/template-tasks/src/theme.tsx +58 -0
  68. package/template-tasks/tsconfig.json +16 -0
  69. package/template-tasks/vite.config.ts +6 -0
  70. /package/{template → template-tasks}/feltkit/inbox.ts +0 -0
  71. /package/{template → template-tasks}/feltkit/projects.ts +0 -0
  72. /package/{template → template-tasks}/feltkit/tasks.ts +0 -0
  73. /package/{template → template-tasks}/public/feltkit-mark.png +0 -0
  74. /package/{template → template-tasks}/tests/tasks.test.ts +0 -0
@@ -0,0 +1,66 @@
1
+ import { useState } from "react";
2
+ import { useQueryState } from "@feltdb/feltkit/react";
3
+ import { api } from "../../feltkit/_generated/api";
4
+ import { ago, Empty, Failure, useTick, who } from "../ui";
5
+ import { useMembers } from "../App";
6
+
7
+ const WORDS: Record<string, (d: any) => string> = {
8
+ "workspace.created": (d) => `set up the workspace${d.template ? " from Launch a Business" : ""}`,
9
+ "mission.updated": (d) => (d.stage ? `moved the mission to ${d.stage}` : "changed the mission"),
10
+ "workstream.status": (d) => `marked ${d.name} ${String(d.to).replace("-", " ")}${d.note ? `: ${d.note}` : ""}`,
11
+ "context.recorded": (d) => `recorded ${d.kind === "finding" ? "a finding" : d.kind}: ${d.title}`,
12
+ "context.verified": (d) => `verified: ${d.title}`,
13
+ "context.unverified": (d) => `took back verification of: ${d.title}`,
14
+ "artifact.created": (d) => `created the artifact ${d.title}`,
15
+ "decision.proposed": (d) => `asked: ${d.question}`,
16
+ "decision.made": (d) => `decided: ${d.question}`,
17
+ "decision.declined": (d) => `declined to decide: ${d.question}`,
18
+ "decision.revisited": (d) => `revisited: ${d.question}`,
19
+ "task.added": (d) => `added "${d.title}" to ${d.workstream}`,
20
+ "board.created": () => "created the work board",
21
+ "channel.created": (d) => `opened the workstream ${d.name ?? ""}`,
22
+ "thread.created": (d) => `created ${d.kind === "discussion" ? "a discussion" : "a task"}${d.title ? `: ${d.title}` : ""}`,
23
+ "message.posted": () => "posted a note",
24
+ "claim.started": () => "claimed a task",
25
+ "claim.ended": (d) => `released a task${d.reason ? ` (${d.reason})` : ""}`,
26
+ "status.changed": (d) => `moved a task to ${d.to ?? d.status ?? "a new status"}`,
27
+ "task.completed": () => "completed a task",
28
+ "task.failed": () => "marked a task failed",
29
+ "followup.scheduled": () => "scheduled a follow-up",
30
+ "followup.fired": () => "follow-up came due",
31
+ };
32
+
33
+ export function describeEntry(e: { type: string; data?: any }): string {
34
+ return (WORDS[e.type] ?? (() => e.type.replace(/[._]/g, " ")))(e.data ?? {});
35
+ }
36
+
37
+ /** The workspace's history, from the records FeltKit and Boards wrote as each change committed. */
38
+ export function Activity() {
39
+ useTick();
40
+ const members = useMembers();
41
+ const [origin, setOrigin] = useState<"all" | "workspace" | "work" | "agent">("all");
42
+ const timeline = useQueryState(api.activity.timeline, { limit: 200 });
43
+ const rows = ((timeline.data ?? []) as any[]).filter((e) => origin === "all" || (origin === "agent" ? e.actor?.id?.startsWith("worker:") : e.origin === origin));
44
+ return (
45
+ <div className="stack loose">
46
+ <div className="page-head"><div><div className="eyebrow">Activity</div><h1>Everything that happened</h1></div>
47
+ <div className="chips" role="group" aria-label="Filter">{(["all", "workspace", "work", "agent"] as const).map((o) => <button key={o} className="chip" aria-pressed={origin === o} onClick={() => setOrigin(o)}>{o === "all" ? "All" : o === "workspace" ? "Knowledge & decisions" : o === "work" ? "Work" : "Agent"}</button>)}</div></div>
48
+ <Failure error={timeline.error} />
49
+ <section className="panel">
50
+ <div className="list">
51
+ {rows.map((e) => {
52
+ const agent = e.actor?.id?.startsWith("worker:");
53
+ return (
54
+ <div key={e.id} className="tl-item">
55
+ <span className={`tl-icon ${agent ? "agent" : "person"}`} aria-hidden>{agent ? "✦" : (who(e.actor, members)[0] ?? "?").toUpperCase()}</span>
56
+ <div className="small"><strong>{who(e.actor, members)}</strong> {describeEntry(e)}{e.actor?.onBehalfOf ? <span className="muted"> for {who({ id: e.actor.onBehalfOf.id }, members)}</span> : null}</div>
57
+ <span className="tiny muted">{ago(e.at)}</span>
58
+ </div>
59
+ );
60
+ })}
61
+ {timeline.data && !rows.length ? <Empty title="Nothing here yet" /> : null}
62
+ </div>
63
+ </section>
64
+ </div>
65
+ );
66
+ }
@@ -0,0 +1,188 @@
1
+ import { useCallback, useEffect, useRef, useState } from "react";
2
+ import type { EveAgentStatus, EveFact, EveSessionInfo } from "@feltdb/feltkit/client";
3
+ import { useAuth, useFeltKit } from "@feltdb/feltkit/react";
4
+ import { ago, Empty, Failure, readSession, TOOL_LABEL, useRun, useTick, type SessionState } from "../ui";
5
+ import { useMembers } from "../App";
6
+
7
+ const AGENT = "crew";
8
+
9
+ export interface AgentSessions {
10
+ status: EveAgentStatus | null;
11
+ sessions: Array<EveSessionInfo & { state: SessionState; waiting: number }>;
12
+ latest: (EveSessionInfo & { state: SessionState }) | null;
13
+ waiting: number;
14
+ error: unknown;
15
+ refresh(): void;
16
+ }
17
+
18
+ /**
19
+ * The workspace's sessions with its agent and their state, as eve recorded them: refreshed every few seconds
20
+ * while the page is open (the agent's work does not depend on it; this only shows it).
21
+ */
22
+ export function useAgentSessions(): AgentSessions {
23
+ const client = useFeltKit();
24
+ const [status, setStatus] = useState<EveAgentStatus | null>(null);
25
+ const [sessions, setSessions] = useState<AgentSessions["sessions"]>([]);
26
+ const [error, setError] = useState<unknown>(null);
27
+ const [tick, setTick] = useState(0);
28
+ useEffect(() => {
29
+ let live = true;
30
+ const load = async () => {
31
+ try {
32
+ const agent = client.eve(AGENT);
33
+ const s = await agent.status();
34
+ if (!live) return;
35
+ setStatus(s);
36
+ if (!s.activated) return setSessions([]);
37
+ const list = await agent.sessions();
38
+ const recent = await Promise.all(list.slice(0, 6).map(async (x) => {
39
+ const read = readSession(await agent.history(x.id).catch(() => [] as EveFact[]));
40
+ return { ...x, state: read.state, waiting: read.waiting.length };
41
+ }));
42
+ if (live) { setSessions([...recent, ...list.slice(6).map((x) => ({ ...x, state: "idle" as SessionState, waiting: 0 }))]); setError(null); }
43
+ } catch (e) {
44
+ if (live) setError(e);
45
+ }
46
+ };
47
+ void load();
48
+ const t = setInterval(load, 4000);
49
+ return () => { live = false; clearInterval(t); };
50
+ }, [client, tick]);
51
+ return { status, sessions, latest: sessions[0] ?? null, waiting: sessions.reduce((n, s) => n + s.waiting, 0), error, refresh: () => setTick((n) => n + 1) };
52
+ }
53
+
54
+ const SUGGESTIONS = [
55
+ "Research our target customer segments and record each finding with its source.",
56
+ "Draft a customer interview guide as an artifact.",
57
+ "Review the workspace and propose the decision we should make next.",
58
+ "What changed since we last talked, and what do you recommend next?",
59
+ ];
60
+
61
+ export function Agent({ sessions, prompt, onPromptUsed }: { sessions: AgentSessions; prompt: string | null; onPromptUsed(): void }) {
62
+ useTick();
63
+ const auth = useAuth();
64
+ const client = useFeltKit();
65
+ const [open, setOpen] = useState<string | null>(null);
66
+ const activate = useRun();
67
+ const s = sessions.status;
68
+ const opened = useRef(false);
69
+ useEffect(() => {
70
+ if (opened.current || !sessions.sessions[0]) return;
71
+ opened.current = true;
72
+ if (!prompt) setOpen(sessions.sessions[0].id);
73
+ }, [sessions.sessions, prompt]);
74
+ if (!s) return sessions.error ? <Failure error={sessions.error} /> : <Empty title="Loading the agent…" />;
75
+ return (
76
+ <div className="stack loose">
77
+ <div className="page-head"><div><div className="eyebrow">Agent</div><h1>{s.displayName}</h1></div>
78
+ {s.activated ? <button className="btn agent" onClick={() => setOpen(null)}>New conversation</button> : null}</div>
79
+ <section className="panel">
80
+ <div className="agent-head">
81
+ <div className="agent-avatar" aria-hidden>✦</div>
82
+ <div className="grow stack tight">
83
+ <div className="row wrap"><strong>{s.activated ? "Member of this workspace" : "Not active here"}</strong><span className={`badge ${s.state === "ready" ? "ok" : "warn"}`}>{s.state === "ready" ? "Running" : s.state}</span></div>
84
+ <p className="small muted">Responsible for research, recording findings and artifacts, proposing decisions and next steps, and noting progress. It works only through this workspace's capabilities, as a member with the agent role, under the permissions of the person it works with. Changes to the plan wait for a person's approval.</p>
85
+ </div>
86
+ {!s.activated && auth.can("feltkit.workers.write") ? <button className="btn agent" disabled={activate.busy} onClick={() => activate.run(async () => { await client.eve(AGENT).activate(); sessions.refresh(); })}>Activate</button> : null}
87
+ </div>
88
+ <details className="panel-pad" style={{ borderTop: "1px solid var(--line)" }}>
89
+ <summary className="small" style={{ cursor: "pointer" }}>What it can do ({s.capabilities.length} capabilities)</summary>
90
+ <div className="chips" style={{ marginTop: 10 }}>
91
+ {s.capabilities.map((c) => <span key={c.capability} className={`badge ${c.approval === "required" ? "warn" : ""}`} title={c.allowed ? "" : "You may not call this, so it cannot do it for you"}>{c.capability}{c.approval === "required" ? " · needs approval" : ""}{c.allowed ? "" : " · not for you"}</span>)}
92
+ </div>
93
+ </details>
94
+ <Failure error={activate.error ?? sessions.error} />
95
+ </section>
96
+ {s.activated ? (
97
+ <div className="work">
98
+ <div className="stack tight streams" aria-label="Conversations">
99
+ {sessions.sessions.map((x) => (
100
+ <button key={x.id} aria-current={open === x.id} onClick={() => setOpen(x.id)}>
101
+ <span className="small clip" style={{ fontWeight: 600 }}>{x.title}</span>
102
+ <span className="row tiny muted">{x.waiting ? <span className="badge warn">Waiting</span> : x.state === "working" ? <span className="badge agent">Working</span> : null}{ago(x.createdAt)}</span>
103
+ </button>
104
+ ))}
105
+ {!sessions.sessions.length ? <p className="small muted" style={{ padding: 8 }}>No conversations yet.</p> : null}
106
+ </div>
107
+ {open ? <Session key={open} id={open} onChanged={sessions.refresh} /> : <NewSession prompt={prompt} onPromptUsed={onPromptUsed} onStarted={(id) => { setOpen(id); sessions.refresh(); }} />}
108
+ </div>
109
+ ) : <Empty title="Activate the agent to work with it">Activation makes it a member of this workspace with the agent role. You can remove it from Team at any time.</Empty>}
110
+ </div>
111
+ );
112
+ }
113
+
114
+ function NewSession({ prompt, onPromptUsed, onStarted }: { prompt: string | null; onPromptUsed(): void; onStarted(id: string): void }) {
115
+ const client = useFeltKit();
116
+ const [text, setText] = useState(prompt ?? "");
117
+ const { busy, error, run } = useRun();
118
+ useEffect(() => { if (prompt) { setText(prompt); onPromptUsed(); } }, [prompt]);
119
+ const start = (message: string) => run(async () => onStarted((await client.eve(AGENT).start(message)).sessionId));
120
+ return (
121
+ <section className="panel">
122
+ <div className="panel-head"><h2>New conversation</h2></div>
123
+ <div className="suggest" style={{ paddingTop: 14 }}>{SUGGESTIONS.map((s) => <button key={s} className="chip" onClick={() => setText(s)}>{s}</button>)}</div>
124
+ <form className="composer" onSubmit={(e) => { e.preventDefault(); if (text.trim()) void start(text.trim()); }}>
125
+ <label className="sr" htmlFor="agent-new">Message the agent</label>
126
+ <textarea id="agent-new" className="textarea grow" value={text} onChange={(e) => setText(e.target.value)} placeholder="Give it instructions, context or a question" style={{ height: 88 }} />
127
+ <button className="btn agent" disabled={busy || !text.trim()}>{busy ? "Starting…" : "Send"}</button>
128
+ </form>
129
+ <div style={{ padding: "0 14px 14px" }}><Failure error={error} /></div>
130
+ </section>
131
+ );
132
+ }
133
+
134
+ function Session({ id, onChanged }: { id: string; onChanged(): void }) {
135
+ const client = useFeltKit();
136
+ const members = useMembers();
137
+ const [facts, setFacts] = useState<EveFact[] | null>(null);
138
+ const [text, setText] = useState("");
139
+ const send = useRun();
140
+ const answer = useRun();
141
+ const end = useRef<HTMLDivElement>(null);
142
+ useEffect(() => client.eve(AGENT).follow(id, setFacts), [client, id]);
143
+ const read = facts ? readSession(facts) : null;
144
+ useEffect(() => { if (read) onChanged(); }, [read?.state, read?.waiting.length]);
145
+ useEffect(() => { end.current?.scrollIntoView({ block: "end" }); }, [read?.entries.length]);
146
+ const respond = useCallback((interactionId: string, decision: "approve" | "deny") => answer.run(async () => { await client.eve(AGENT).answer(id, interactionId, decision); onChanged(); }), [client, id]);
147
+ if (!read) return <section className="panel"><Empty title="Loading the conversation…" /></section>;
148
+ return (
149
+ <section className="panel" aria-label="Conversation">
150
+ <div className="panel-head">
151
+ <div className="row"><span className={`badge ${read.state === "working" ? "agent" : read.state === "waiting" ? "warn" : read.state === "failed" ? "danger" : ""}`}>{read.state === "working" ? "Working" : read.state === "waiting" ? "Waiting for approval" : read.state === "failed" ? "Failed" : "Idle"}</span></div>
152
+ <span className="tiny muted">Recorded durably: it continues if you close this page.</span>
153
+ </div>
154
+ <div className="transcript">
155
+ {read.entries.map((e) => {
156
+ if (e.kind === "user") return <div key={e.key} className="bubble user"><div className="tiny" style={{ opacity: 0.8 }}>{members.get(e.by) ?? e.by}</div>{e.text}</div>;
157
+ if (e.kind === "assistant") return <div key={e.key} className="bubble assistant">{e.text}</div>;
158
+ if (e.kind === "call") return (
159
+ <details key={e.key} className="call">
160
+ <summary className="row"><span className={`badge ${e.outcome === "completed" ? "ok" : e.outcome ? "danger" : "agent"}`}>{e.outcome === "completed" ? "Done" : e.outcome ? e.outcome : "Running"}</span><span>{TOOL_LABEL[e.tool] ?? e.tool}</span><span className="tiny muted">{e.tool.replace(/_/g, ".")}</span>{e.clearedBy ? <span className="badge accent">approved</span> : null}</summary>
161
+ <code>in: {JSON.stringify(e.input)}</code>
162
+ {e.output !== undefined ? <code>out: {JSON.stringify(e.output).slice(0, 600)}</code> : null}
163
+ </details>
164
+ );
165
+ return (
166
+ <div key={e.key} className="approval">
167
+ <div className="spread"><strong>{e.prompt}</strong>{e.outcome ? <span className={`badge ${e.outcome === "approved" ? "ok" : "danger"}`}>{e.outcome}</span> : <span className="badge warn">Needs a person</span>}</div>
168
+ {!e.outcome ? (
169
+ <>
170
+ <p className="small">Approving records an approval of exactly this request, by you; the agent then runs it under your workspace's rules.</p>
171
+ <div className="row"><button className="btn primary" disabled={answer.busy} onClick={() => respond(e.interactionId, "approve")}>Approve</button><button className="btn" disabled={answer.busy} onClick={() => respond(e.interactionId, "deny")}>Deny</button></div>
172
+ </>
173
+ ) : null}
174
+ </div>
175
+ );
176
+ })}
177
+ {read.state === "working" ? <div className="tiny muted">The agent is working…</div> : null}
178
+ <div ref={end} />
179
+ </div>
180
+ <Failure error={answer.error ?? send.error} />
181
+ <form className="composer" onSubmit={(e) => { e.preventDefault(); const m = text.trim(); if (m) void send.run(async () => { await client.eve(AGENT).send(id, m); setText(""); onChanged(); }); }}>
182
+ <label className="sr" htmlFor="agent-reply">Reply</label>
183
+ <textarea id="agent-reply" className="textarea grow" value={text} onChange={(e) => setText(e.target.value)} placeholder={read.state === "working" ? "Steer it: add context or change direction" : "Reply, or give it the next instruction"} />
184
+ <button className="btn agent" disabled={send.busy || !text.trim()}>Send</button>
185
+ </form>
186
+ </section>
187
+ );
188
+ }
@@ -0,0 +1,71 @@
1
+ import { useState } from "react";
2
+ import { useAuth, useFeltKit, useMutation, useQueryState } from "@feltdb/feltkit/react";
3
+ import { api } from "../../feltkit/_generated/api";
4
+ import { ago, ConfidenceBadge, Empty, Failure, SourceBadge, useRun, who } from "../ui";
5
+ import { useMembers } from "../App";
6
+
7
+ const FILTERS = [
8
+ { id: "all", label: "All" },
9
+ { id: "finding", label: "Findings" },
10
+ { id: "research", label: "Research" },
11
+ { id: "artifact", label: "Artifacts" },
12
+ { id: "note", label: "Notes" },
13
+ { id: "verified", label: "Verified" },
14
+ ] as const;
15
+
16
+ /** What the workspace knows, where each item came from, and what it is worth. */
17
+ export function ContextScreen({ workstreams }: { workstreams: any[] }) {
18
+ const auth = useAuth();
19
+ const members = useMembers();
20
+ const client = useFeltKit();
21
+ const [filter, setFilter] = useState<(typeof FILTERS)[number]["id"]>("all");
22
+ const [open, setOpen] = useState<string | null>(null);
23
+ const items = useQueryState(api.knowledge.list, filter === "all" ? {} : filter === "verified" ? { confidence: "verified" } : { kind: filter });
24
+ const verify = useMutation(api.knowledge.verify);
25
+ const record = useMutation(api.knowledge.record);
26
+ const [adding, setAdding] = useState(false);
27
+ const [draft, setDraft] = useState({ kind: "note" as "note" | "finding" | "research" | "reference", title: "", body: "", url: "", workstreamId: "" });
28
+ const { busy, error, run } = useRun();
29
+ const streamName = new Map(workstreams.map((w) => [w.id, w.name]));
30
+ const openArtifact = (id: string) => run(async () => { const link = await client.query(api.knowledge.artifactLink, { id }); window.open(client.fileUrl(link as any), "_blank", "noopener"); });
31
+ return (
32
+ <div className="stack loose">
33
+ <div className="page-head"><div><div className="eyebrow">Context</div><h1>What we know</h1><p className="muted small" style={{ marginTop: 6 }}>Every item says where it came from. Only a person verifies; starter content stays a hypothesis.</p></div>
34
+ {auth.can("crew.contribute") ? <button className="btn primary" onClick={() => setAdding((v) => !v)}>{adding ? "Cancel" : "Add context"}</button> : null}</div>
35
+ {adding ? (
36
+ <form className="panel panel-pad stack" onSubmit={(e) => { e.preventDefault(); void run(async () => { await record({ kind: draft.kind, title: draft.title.trim(), body: draft.body.trim(), ...(draft.url.trim() ? { url: draft.url.trim() } : {}), ...(draft.workstreamId ? { workstreamId: draft.workstreamId } : {}) }); setDraft({ ...draft, title: "", body: "", url: "" }); setAdding(false); }); }}>
37
+ <div className="row wrap">
38
+ <div className="field"><label htmlFor="c-kind">Kind</label><select id="c-kind" className="select" value={draft.kind} onChange={(e) => setDraft({ ...draft, kind: e.target.value as any })}><option value="note">Note</option><option value="finding">Finding</option><option value="research">Research</option><option value="reference">Reference</option></select></div>
39
+ <div className="field grow"><label htmlFor="c-ws">Workstream</label><select id="c-ws" className="select" value={draft.workstreamId} onChange={(e) => setDraft({ ...draft, workstreamId: e.target.value })}><option value="">None</option>{workstreams.map((w) => <option key={w.id} value={w.id}>{w.name}</option>)}</select></div>
40
+ </div>
41
+ <div className="field"><label htmlFor="c-title">Title</label><input id="c-title" className="input" value={draft.title} onChange={(e) => setDraft({ ...draft, title: e.target.value })} required maxLength={160} /></div>
42
+ <div className="field"><label htmlFor="c-body">What you learned</label><textarea id="c-body" className="textarea" value={draft.body} onChange={(e) => setDraft({ ...draft, body: e.target.value })} required /></div>
43
+ <div className="field"><label htmlFor="c-url">Source URL (optional)</label><input id="c-url" className="input" type="url" value={draft.url} onChange={(e) => setDraft({ ...draft, url: e.target.value })} /></div>
44
+ <div><button className="btn primary" disabled={busy}>Save to context</button></div>
45
+ </form>
46
+ ) : null}
47
+ <div className="chips" role="group" aria-label="Filter">{FILTERS.map((f) => <button key={f.id} className="chip" aria-pressed={filter === f.id} onClick={() => setFilter(f.id)}>{f.label}</button>)}</div>
48
+ <Failure error={error ?? items.error} />
49
+ <section className="panel">
50
+ <div className="list">
51
+ {((items.data ?? []) as any[]).map((c) => (
52
+ <div key={c.id} className="item" style={{ display: "grid", gap: 6 }}>
53
+ <div className="spread"><button className="ctx-title" style={{ background: "none", border: 0, padding: 0, cursor: "pointer", textAlign: "left" }} onClick={() => setOpen(open === c.id ? null : c.id)}>{c.title}</button>
54
+ <div className="row"><span className="badge">{c.kind}</span><SourceBadge source={c.source} /><ConfidenceBadge confidence={c.confidence} /></div></div>
55
+ <p className={`ctx-body ${open === c.id ? "full" : ""}`}>{c.body}</p>
56
+ <div className="row wrap tiny muted">
57
+ <span>{who(c.createdBy, members)} · {ago(c.createdAt)}</span>
58
+ {c.workstreamId ? <span>· {streamName.get(c.workstreamId)}</span> : null}
59
+ {c.url ? <a href={c.url} target="_blank" rel="noopener noreferrer">source</a> : null}
60
+ {c.verifiedBy ? <span>· verified by {who(c.verifiedBy, members)} {ago(c.verifiedAt)}</span> : null}
61
+ {c.fileId ? <button className="btn small" onClick={() => openArtifact(c.id)}>Open file</button> : null}
62
+ {auth.can("crew.decide") && c.source !== "starter" ? <button className="btn small" disabled={busy} onClick={() => run(() => verify({ id: c.id, verified: c.confidence !== "verified" }))}>{c.confidence === "verified" ? "Unverify" : "Mark verified"}</button> : null}
63
+ </div>
64
+ </div>
65
+ ))}
66
+ {items.data && !(items.data as any[]).length ? <Empty title="Nothing here yet">Add what you learn, or ask the agent to research and record findings with sources.</Empty> : null}
67
+ </div>
68
+ </section>
69
+ </div>
70
+ );
71
+ }
@@ -0,0 +1,89 @@
1
+ import { useState } from "react";
2
+ import { useAuth, useMutation, useQueryState } from "@feltdb/feltkit/react";
3
+ import { api } from "../../feltkit/_generated/api";
4
+ import { ago, ConfidenceBadge, Empty, Failure, useRun, who } from "../ui";
5
+ import { useMembers } from "../App";
6
+
7
+ /** The decision log: open questions, what was decided and why, and every earlier answer that a revisit replaced. */
8
+ export function Decisions({ workstreams }: { workstreams: any[] }) {
9
+ const auth = useAuth();
10
+ const all = useQueryState(api.decisions.list, {});
11
+ const propose = useMutation(api.decisions.propose);
12
+ const [asking, setAsking] = useState(false);
13
+ const [question, setQuestion] = useState("");
14
+ const [recommendation, setRecommendation] = useState("");
15
+ const { busy, error, run } = useRun();
16
+ const rows = (all.data ?? []) as any[];
17
+ const open = rows.filter((d) => d.status === "proposed");
18
+ const decided = rows.filter((d) => d.status === "decided");
19
+ const past = rows.filter((d) => d.status === "superseded" || d.status === "declined");
20
+ const streamName = new Map(workstreams.map((w) => [w.id, w.name]));
21
+ return (
22
+ <div className="stack loose">
23
+ <div className="page-head"><div><div className="eyebrow">Decisions</div><h1>What we decided, and why</h1></div>
24
+ {auth.can("crew.contribute") ? <button className="btn primary" onClick={() => setAsking((v) => !v)}>{asking ? "Cancel" : "Raise a question"}</button> : null}</div>
25
+ {asking ? (
26
+ <form className="panel panel-pad stack" onSubmit={(e) => { e.preventDefault(); void run(async () => { await propose({ question: question.trim(), ...(recommendation.trim() ? { recommendation: recommendation.trim() } : {}) }); setQuestion(""); setRecommendation(""); setAsking(false); }); }}>
27
+ <div className="field"><label htmlFor="d-q">Question</label><input id="d-q" className="input" value={question} onChange={(e) => setQuestion(e.target.value)} required maxLength={300} /></div>
28
+ <div className="field"><label htmlFor="d-r">Recommendation (optional)</label><textarea id="d-r" className="textarea" value={recommendation} onChange={(e) => setRecommendation(e.target.value)} /></div>
29
+ <div><button className="btn primary" disabled={busy}>Propose</button></div>
30
+ </form>
31
+ ) : null}
32
+ <Failure error={error ?? all.error} />
33
+ <section className="stack">
34
+ <h2>Open <span className="muted">({open.length})</span></h2>
35
+ {open.length ? open.map((d) => <Decision key={d.id} d={d} streamName={streamName} />) : <div className="panel"><Empty title="No open questions">Raise one, or ask the agent to propose the next decision with its evidence.</Empty></div>}
36
+ </section>
37
+ <section className="stack">
38
+ <h2>Decided <span className="muted">({decided.length})</span></h2>
39
+ {decided.length ? decided.map((d) => <Decision key={d.id} d={d} streamName={streamName} />) : <p className="small muted">Nothing decided yet.</p>}
40
+ </section>
41
+ {past.length ? <section className="stack"><h2>History</h2>{past.map((d) => <Decision key={d.id} d={d} streamName={streamName} />)}</section> : null}
42
+ </div>
43
+ );
44
+ }
45
+
46
+ function Decision({ d, streamName }: { d: any; streamName: Map<string, string> }) {
47
+ const auth = useAuth();
48
+ const members = useMembers();
49
+ const decide = useMutation(api.decisions.decide);
50
+ const revisit = useMutation(api.decisions.revisit);
51
+ const [mode, setMode] = useState<"decide" | "revisit" | null>(null);
52
+ const [answer, setAnswer] = useState(d.decision ?? "");
53
+ const [rationale, setRationale] = useState("");
54
+ const [showHistory, setShowHistory] = useState(false);
55
+ const history = useQueryState(api.decisions.history, showHistory ? { id: d.id } : "skip");
56
+ const { busy, error, run } = useRun();
57
+ const canDecide = auth.can("crew.decide");
58
+ return (
59
+ <article className={`panel decision ${d.status === "superseded" ? "superseded" : ""}`}>
60
+ <div className="spread"><strong>{d.question}</strong><span className={`badge ${d.status === "decided" ? "ok" : d.status === "proposed" ? "accent" : ""}`}>{d.status}</span></div>
61
+ {d.decision ? <blockquote>{d.status === "proposed" ? `Recommended: ${d.decision}` : d.decision}</blockquote> : null}
62
+ {d.rationale ? <p className="small"><span className="muted">Why: </span>{d.rationale}</p> : null}
63
+ {d.alternatives?.length ? <div className="row wrap small"><span className="muted">Considered:</span>{d.alternatives.map((a: string) => <span key={a} className="badge">{a}</span>)}</div> : null}
64
+ <div className="row wrap tiny muted">
65
+ <span>Proposed by {who(d.proposedBy, members)} {ago(d.proposedAt)}</span>
66
+ {d.decidedBy ? <span>· decided by {who(d.decidedBy, members)} {ago(d.decidedAt)}</span> : null}
67
+ {d.workstreamId ? <span>· {streamName.get(d.workstreamId)}</span> : null}
68
+ {d.evidence?.length ? <span>· {d.evidence.length} evidence</span> : null}
69
+ {d.supersedes || d.supersededBy ? <button className="btn small ghost" onClick={() => setShowHistory((v) => !v)}>{showHistory ? "Hide history" : "History"}</button> : null}
70
+ </div>
71
+ {showHistory && history.data ? (
72
+ <div className="stack tight">
73
+ {(history.data as any).chain.map((x: any) => <div key={x.id} className="msg"><span className="tiny muted">{x.status} · {who(x.decidedBy ?? x.proposedBy, members)} · {ago(x.decidedAt ?? x.proposedAt)}</span><span className="small">{x.decision}</span>{x.rationale ? <span className="tiny muted">{x.rationale}</span> : null}</div>)}
74
+ {(history.data as any).evidence.map((c: any) => <div key={c.id} className="row small"><ConfidenceBadge confidence={c.confidence} />{c.title}</div>)}
75
+ </div>
76
+ ) : null}
77
+ {canDecide && d.status === "proposed" && mode !== "decide" ? <div className="row"><button className="btn primary small" onClick={() => setMode("decide")}>Decide</button><button className="btn small" disabled={busy} onClick={() => run(() => decide({ id: d.id, outcome: "declined" }))}>Decline</button></div> : null}
78
+ {canDecide && d.status === "decided" && mode !== "revisit" ? <div><button className="btn small" onClick={() => { setAnswer(""); setMode("revisit"); }}>Revisit</button></div> : null}
79
+ {mode ? (
80
+ <form className="stack tight" onSubmit={(e) => { e.preventDefault(); void run(async () => { if (mode === "decide") await decide({ id: d.id, outcome: "decided", decision: answer.trim(), ...(rationale.trim() ? { rationale: rationale.trim() } : {}) }); else await revisit({ id: d.id, decision: answer.trim(), rationale: rationale.trim() }); setMode(null); }); }}>
81
+ <div className="field"><label htmlFor={`a-${d.id}`}>{mode === "decide" ? "Decision" : "New decision"}</label><input id={`a-${d.id}`} className="input" value={answer} onChange={(e) => setAnswer(e.target.value)} required /></div>
82
+ <div className="field"><label htmlFor={`r-${d.id}`}>Rationale</label><textarea id={`r-${d.id}`} className="textarea" value={rationale} onChange={(e) => setRationale(e.target.value)} required={mode === "revisit"} /></div>
83
+ <div className="row"><button className="btn primary small" disabled={busy}>{mode === "decide" ? "Record decision" : "Record revisit"}</button><button type="button" className="btn small ghost" onClick={() => setMode(null)}>Cancel</button></div>
84
+ </form>
85
+ ) : null}
86
+ <Failure error={error} />
87
+ </article>
88
+ );
89
+ }
@@ -0,0 +1,140 @@
1
+ import { useAuth, useFeltKit, useQueryState } from "@feltdb/feltkit/react";
2
+ import { api } from "../../feltkit/_generated/api";
3
+ import { STAGES, STAGE_LABEL } from "../../shared/rules";
4
+ import { ago, ConfidenceBadge, Failure, SourceBadge, useRun, useTick, who, WS_STATUS, type Screen } from "../ui";
5
+ import { describeEntry } from "./activity";
6
+ import type { AgentSessions } from "./agent";
7
+ import { useMembers } from "../App";
8
+
9
+ /**
10
+ * Mission Control: what we are trying to accomplish, where we are, what changed, what needs attention, what is
11
+ * happening automatically, and what to do next. Every number is a count of records; none is an estimate.
12
+ */
13
+ export function Home({ o, go, sessions }: { o: any; go: (s: Screen, prompt?: string) => void; sessions: AgentSessions }) {
14
+ useTick();
15
+ const auth = useAuth();
16
+ const client = useFeltKit();
17
+ const timeline = useQueryState(api.activity.timeline, { limit: 8 });
18
+ const activate = useRun();
19
+ const members = useMembers();
20
+ const stageIndex = STAGES.indexOf(o.mission.stage);
21
+ const e = o.evidence;
22
+ const nextButton = () => {
23
+ switch (o.next.action) {
24
+ case "activate-agent":
25
+ return auth.can("feltkit.workers.write") ? (
26
+ <button className="btn agent" disabled={activate.busy} onClick={() => activate.run(async () => { await client.eve("crew").activate(); sessions.refresh(); })}>{activate.busy ? "Activating…" : "Activate the agent"}</button>
27
+ ) : <span className="small muted">An owner or admin activates it.</span>;
28
+ case "invite": return <button className="btn primary" onClick={() => go("team")}>Invite people</button>;
29
+ case "decide": return <button className="btn primary" onClick={() => go("decisions")}>Open decisions</button>;
30
+ case "verify": return <button className="btn primary" onClick={() => go("context")}>Review findings</button>;
31
+ case "research": return <button className="btn agent" onClick={() => go("agent", "Research our first assumption: who is the customer and what problem do they pay to solve? Record each finding with its source.")}>Ask the agent</button>;
32
+ case "unblock": case "start": return <button className="btn primary" onClick={() => go("work")}>Open work</button>;
33
+ default: return <button className="btn agent" onClick={() => go("agent", "What changed since we last talked, and what do you recommend next?")}>Ask the agent</button>;
34
+ }
35
+ };
36
+ return (
37
+ <div className="stack loose">
38
+ <section className="panel mission" aria-labelledby="mission-title">
39
+ <div className="spread">
40
+ <div className="eyebrow">Mission</div>
41
+ <div className="stage" aria-label="Stage">{STAGES.map((s, i) => <span key={s} className={i === stageIndex ? "on" : i < stageIndex ? "past" : ""}>{STAGE_LABEL[s]}</span>)}</div>
42
+ </div>
43
+ <h1 id="mission-title">{o.mission.title}</h1>
44
+ <p className="mission-outcome">{o.mission.outcome}</p>
45
+ <div className="measures" aria-label="Evidence">
46
+ <div><strong>{e.verified}</strong><span className="small muted">verified findings</span></div>
47
+ <div><strong>{e.decisions}</strong><span className="small muted">decisions made</span></div>
48
+ <div><strong>{e.tasksDone}<span className="muted" style={{ fontSize: 14 }}>/{e.tasks}</span></strong><span className="small muted">tasks done</span></div>
49
+ <div><strong>{e.unverified + e.hypotheses}</strong><span className="small muted">assumptions to test</span></div>
50
+ </div>
51
+ </section>
52
+
53
+ <section className="next" aria-label="Next step">
54
+ <div className="grow"><div className="eyebrow">Next</div><h2>{o.next.title}</h2><p>{o.next.detail}</p></div>
55
+ {nextButton()}
56
+ </section>
57
+ <Failure error={activate.error} />
58
+
59
+ <div className="grid-2">
60
+ <div className="stack loose">
61
+ <section className="panel">
62
+ <div className="panel-head"><h2>Workstreams</h2><button className="btn ghost small" onClick={() => go("work")}>Open work</button></div>
63
+ <div className="list">
64
+ {o.workstreams.map((w: any) => (
65
+ <button key={w.id} className="item click" onClick={() => go("work")}>
66
+ <span className={`dot-status s-${w.status}`} style={{ marginTop: 7 }} />
67
+ <div className="grow stack tight">
68
+ <div className="spread"><strong className="clip">{w.name}</strong><span className="small muted">{WS_STATUS[w.status]}</span></div>
69
+ <div className="meter" aria-label={`${w.done} of ${w.tasks} tasks done`}>
70
+ <i className="m-done" style={{ width: `${w.tasks ? (100 * w.done) / w.tasks : 0}%` }} />
71
+ <i className="m-active" style={{ width: `${w.tasks ? (100 * w.active) / w.tasks : 0}%` }} />
72
+ <i className="m-blocked" style={{ width: `${w.tasks ? (100 * w.blocked) / w.tasks : 0}%` }} />
73
+ </div>
74
+ <div className="row small muted"><span>{w.done}/{w.tasks} done</span>{w.active ? <span>· {w.active} active</span> : null}{w.blocked ? <span className="badge danger">{w.blocked} blocked</span> : null}<span>· {w.evidence} verified</span></div>
75
+ </div>
76
+ </button>
77
+ ))}
78
+ </div>
79
+ </section>
80
+
81
+ <section className="panel">
82
+ <div className="panel-head"><h2>Recent activity</h2><button className="btn ghost small" onClick={() => go("activity")}>All activity</button></div>
83
+ <div className="list">
84
+ {(timeline.data ?? []).map((entry: any) => (
85
+ <div key={entry.id} className="item">
86
+ <div className="grow small"><strong>{who(entry.actor, members)}</strong> {describeEntry(entry)}</div>
87
+ <span className="tiny muted">{ago(entry.at)}</span>
88
+ </div>
89
+ ))}
90
+ {timeline.data && timeline.data.length === 0 ? <div className="item small muted">Nothing yet.</div> : null}
91
+ </div>
92
+ </section>
93
+ </div>
94
+
95
+ <div className="stack loose">
96
+ <section className="panel">
97
+ <div className="panel-head"><h2>Needs attention</h2></div>
98
+ <div className="list">
99
+ {sessions.waiting ? (
100
+ <button className="item click" onClick={() => go("agent")}><span className="badge warn">Approval</span><div className="grow small">The agent is waiting for {sessions.waiting === 1 ? "an approval" : `${sessions.waiting} approvals`}.</div></button>
101
+ ) : null}
102
+ {o.attention.blocked.map((t: any) => (
103
+ <button key={t.id} className="item click" onClick={() => go("work")}><span className="badge danger">Blocked</span><div className="grow small"><div className="clip">{t.title}</div><div className="muted tiny">{t.workstream}</div></div></button>
104
+ ))}
105
+ {o.attention.decisions.map((d: any) => (
106
+ <button key={d.id} className="item click" onClick={() => go("decisions")}><span className="badge accent">Decide</span><div className="grow small">{d.question}<div className="muted tiny">proposed by {who(d.proposedBy)}</div></div></button>
107
+ ))}
108
+ {o.attention.unverified.slice(0, 4).map((c: any) => (
109
+ <button key={c.id} className="item click" onClick={() => go("context")}><ConfidenceBadge confidence="unverified" /><div className="grow small"><div className="clip">{c.title}</div><div className="tiny"><SourceBadge source={c.source} /></div></div></button>
110
+ ))}
111
+ {!sessions.waiting && !o.attention.blocked.length && !o.attention.decisions.length && !o.attention.unverified.length ? <div className="item small muted">Nothing needs attention.</div> : null}
112
+ </div>
113
+ </section>
114
+
115
+ <section className="panel">
116
+ <div className="panel-head"><h2>Agent</h2><button className="btn ghost small" onClick={() => go("agent")}>Open</button></div>
117
+ <div className="panel-pad stack">
118
+ {!o.agentActive ? <p className="small muted">Not active in this workspace yet.</p> : sessions.latest ? (
119
+ <>
120
+ <div className="row"><span className={`badge ${sessions.latest.state === "working" ? "agent" : sessions.latest.state === "waiting" ? "warn" : sessions.latest.state === "failed" ? "danger" : ""}`}>{sessions.latest.state === "working" ? "Working" : sessions.latest.state === "waiting" ? "Waiting for you" : sessions.latest.state === "failed" ? "Failed" : "Idle"}</span><span className="small muted">{ago(sessions.latest.createdAt)}</span></div>
121
+ <p className="small clip">{sessions.latest.title}</p>
122
+ </>
123
+ ) : <p className="small muted">Active. Ask it to research, record findings, or draft a plan.</p>}
124
+ {o.agentActive ? <button className="btn agent small" onClick={() => go("agent", "What should we focus on next, given the mission and what we know so far?")}>Ask the agent</button> : null}
125
+ </div>
126
+ </section>
127
+
128
+ <section className="panel">
129
+ <div className="panel-head"><h2>Latest findings</h2><button className="btn ghost small" onClick={() => go("context")}>Context</button></div>
130
+ <div className="list">
131
+ {o.recentFindings.length ? o.recentFindings.slice(0, 5).map((c: any) => (
132
+ <div key={c.id} className="item"><div className="grow small stack tight"><div className="clip" style={{ fontWeight: 600 }}>{c.title}</div><div className="row"><SourceBadge source={c.source} /><ConfidenceBadge confidence={c.confidence} /><span className="tiny muted">{ago(c.createdAt)}</span></div></div></div>
133
+ )) : <div className="item small muted">No findings yet. The agent records what it learns here.</div>}
134
+ </div>
135
+ </section>
136
+ </div>
137
+ </div>
138
+ </div>
139
+ );
140
+ }
@@ -0,0 +1,13 @@
1
+ import { FeltKitAuthStyles, MembersPanel, TenantSettings, useAuth } from "@feltdb/feltkit/react";
2
+
3
+ /** The people (and the agent) in this workspace, their roles, and invitations: FeltKit's own panels. */
4
+ export function Team() {
5
+ const auth = useAuth();
6
+ return (
7
+ <div className="stack loose">
8
+ <FeltKitAuthStyles />
9
+ <div className="page-head"><div><div className="eyebrow">Team</div><h1>{auth.tenant?.name}</h1><p className="muted small" style={{ marginTop: 6 }}>Owners and admins invite people and set roles. Members work; viewers read. The agent is a member with the agent role.</p></div></div>
10
+ {auth.can("tenant.update") ? <TenantSettings /> : <MembersPanel />}
11
+ </div>
12
+ );
13
+ }