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,220 @@
1
+ /**
2
+ * The tasks app's native screens: React Native components over the same functions, the same generated api, the same
3
+ * permissions and the same rules (shared/rules.ts) as the web app in src/. Nothing here is a port of src/App.tsx's
4
+ * markup: the web app renders DOM, this renders native views. What they share is what the app *is*.
5
+ *
6
+ * The host (generated by `feltkit build ios|android`) connects to the instance, holds the session in secure storage and
7
+ * renders this inside <FeltKitProvider>.
8
+ */
9
+ import { useEffect, useMemo, useRef, useState, type ReactNode } from "react";
10
+ import { ActivityIndicator, Button, FlatList, Pressable, SafeAreaView, StyleSheet, Switch, Text, TextInput, View } from "react-native";
11
+ import { useConnectionState, useMutation, useQueryState, useSession, type NativeAppProps } from "@feltdb/feltkit/native";
12
+ import { api } from "../feltkit/_generated/api";
13
+ import { can, describe } from "../shared/rules";
14
+
15
+ export default function App({ link, onLinkHandled }: NativeAppProps) {
16
+ const { session, signInAsDevUser, signIn, signUp, signOut } = useSession();
17
+ const live = useConnectionState();
18
+ const [notice, setNotice] = useState<string | null>(null);
19
+ const principal = session?.principal ?? null;
20
+ const permissions = session?.permissions ?? [];
21
+
22
+ // In development, sign in as the first dev user so the app works on first launch (the web app does the same).
23
+ const tried = useRef(false);
24
+ useEffect(() => {
25
+ if (session && !principal && session.devUsers.length && !tried.current) {
26
+ tried.current = true;
27
+ void signInAsDevUser(session.devUsers[0]!.id).catch((e) => setNotice(describe(e)));
28
+ }
29
+ }, [session, principal, signInAsDevUser]);
30
+
31
+ // A link that opened the app and needs a word from us (the host already handled the ones that need nothing).
32
+ useEffect(() => {
33
+ if (!link) return;
34
+ if (link.kind === "verified") setNotice(`${link.email} is verified.`);
35
+ else if (link.kind === "reset") setNotice("Open the web app to choose a new password: this app does not have that screen yet.");
36
+ else if (link.kind === "signed-in") setNotice(null);
37
+ else if ("message" in link) setNotice(link.message);
38
+ onLinkHandled();
39
+ }, [link, onLinkHandled]);
40
+
41
+ if (!session) {
42
+ return (
43
+ <Centered>
44
+ <ActivityIndicator accessibilityLabel="Loading" />
45
+ </Centered>
46
+ );
47
+ }
48
+ return (
49
+ <SafeAreaView style={styles.screen}>
50
+ <View style={styles.bar}>
51
+ <Text style={styles.title} accessibilityRole="header">
52
+ {session.application}
53
+ </Text>
54
+ <Text style={styles.muted}>{live ? "live" : "offline"}</Text>
55
+ {principal ? <Button title="Sign out" onPress={() => void signOut()} /> : null}
56
+ </View>
57
+ {notice ? (
58
+ <Text style={styles.notice} accessibilityRole="alert" onPress={() => setNotice(null)}>
59
+ {notice}
60
+ </Text>
61
+ ) : null}
62
+ {principal ? (
63
+ <Workspace canWrite={can(permissions, "tasks.write")} canComplete={can(permissions, "tasks.complete")} onError={(e) => setNotice(describe(e))} />
64
+ ) : (
65
+ <SignIn devUsers={session.devUsers} accounts={Boolean(session.accounts)} canSignUp={Boolean(session.accounts?.signUp)} onDev={signInAsDevUser} onSignIn={signIn} onSignUp={signUp} onError={(e) => setNotice(describe(e))} />
66
+ )}
67
+ </SafeAreaView>
68
+ );
69
+ }
70
+
71
+ interface Credentials {
72
+ email: string;
73
+ password: string;
74
+ }
75
+
76
+ function SignIn(props: { devUsers: Array<{ id: string; name: string }>; accounts: boolean; canSignUp: boolean; onDev(id: string): Promise<void>; onSignIn(i: Credentials): Promise<void>; onSignUp(i: Credentials): Promise<void>; onError(e: unknown): void }) {
77
+ const [email, setEmail] = useState("");
78
+ const [password, setPassword] = useState("");
79
+ const [busy, setBusy] = useState(false);
80
+ const attempt = (work: () => Promise<void>) => async () => {
81
+ setBusy(true);
82
+ try {
83
+ await work();
84
+ } catch (error) {
85
+ props.onError(error);
86
+ } finally {
87
+ setBusy(false);
88
+ }
89
+ };
90
+ return (
91
+ <View style={styles.pad}>
92
+ <Text style={styles.heading}>Sign in</Text>
93
+ {props.devUsers.map((u) => (
94
+ <Button key={u.id} title={`Continue as ${u.name}`} disabled={busy} onPress={attempt(() => props.onDev(u.id))} />
95
+ ))}
96
+ {props.accounts ? (
97
+ <>
98
+ <TextInput style={styles.input} value={email} onChangeText={setEmail} placeholder="E-mail" autoCapitalize="none" autoComplete="email" keyboardType="email-address" accessibilityLabel="E-mail" />
99
+ <TextInput style={styles.input} value={password} onChangeText={setPassword} placeholder="Password" secureTextEntry autoComplete="password" accessibilityLabel="Password" />
100
+ <Button title="Sign in" disabled={busy || !email || !password} onPress={attempt(() => props.onSignIn({ email, password }))} />
101
+ {props.canSignUp ? <Button title="Create account" disabled={busy || !email || !password} onPress={attempt(() => props.onSignUp({ email, password }))} /> : null}
102
+ </>
103
+ ) : null}
104
+ </View>
105
+ );
106
+ }
107
+
108
+ function Workspace({ canWrite, canComplete, onError }: { canWrite: boolean; canComplete: boolean; onError(e: unknown): void }) {
109
+ const projects = useQueryState(api.projects.list);
110
+ const [selected, setSelected] = useState<string | null>(null);
111
+ const list = projects.data ?? [];
112
+ const current = useMemo(() => list.find((p) => p.id === selected) ?? list[0] ?? null, [list, selected]);
113
+ if (projects.error) {
114
+ return (
115
+ <Centered>
116
+ <Text style={styles.notice}>{describe(projects.error)}</Text>
117
+ </Centered>
118
+ );
119
+ }
120
+ if (projects.isLoading && !projects.data) {
121
+ return (
122
+ <Centered>
123
+ <ActivityIndicator accessibilityLabel="Loading projects" />
124
+ </Centered>
125
+ );
126
+ }
127
+ if (!current) {
128
+ return (
129
+ <Centered>
130
+ <Text style={styles.muted}>No projects yet. Create one in the web app.</Text>
131
+ </Centered>
132
+ );
133
+ }
134
+ return (
135
+ <View style={styles.flex}>
136
+ <FlatList
137
+ horizontal
138
+ style={styles.chips}
139
+ data={list}
140
+ keyExtractor={(p) => p.id}
141
+ renderItem={({ item }) => (
142
+ <Pressable accessibilityRole="button" accessibilityState={{ selected: item.id === current.id }} onPress={() => setSelected(item.id)} style={[styles.chip, item.id === current.id && styles.chipOn]}>
143
+ <Text>
144
+ {item.name} · {item.open}
145
+ </Text>
146
+ </Pressable>
147
+ )}
148
+ />
149
+ <Tasks key={current.id} projectId={current.id} canWrite={canWrite} canComplete={canComplete} onError={onError} />
150
+ </View>
151
+ );
152
+ }
153
+
154
+ function Tasks({ projectId, canWrite, canComplete, onError }: { projectId: string; canWrite: boolean; canComplete: boolean; onError(e: unknown): void }) {
155
+ const tasks = useQueryState(api.tasks.list, { projectId });
156
+ const create = useMutation(api.tasks.create);
157
+ const setDone = useMutation(api.tasks.setDone);
158
+ const [title, setTitle] = useState("");
159
+ const adding = useRef(false);
160
+ const add = async () => {
161
+ if (!title.trim() || adding.current) return;
162
+ adding.current = true;
163
+ try {
164
+ await create({ projectId, title });
165
+ setTitle("");
166
+ } catch (error) {
167
+ onError(error);
168
+ } finally {
169
+ adding.current = false;
170
+ }
171
+ };
172
+ const items = tasks.data ?? [];
173
+ return (
174
+ <View style={styles.flex}>
175
+ {canWrite ? <TextInput style={styles.input} value={title} onChangeText={setTitle} onSubmitEditing={add} placeholder="Add a task" returnKeyType="done" maxLength={200} accessibilityLabel="New task" /> : null}
176
+ {tasks.isLoading && !tasks.data ? (
177
+ <Centered>
178
+ <ActivityIndicator accessibilityLabel="Loading tasks" />
179
+ </Centered>
180
+ ) : items.length === 0 ? (
181
+ <Centered>
182
+ <Text style={styles.muted}>No tasks yet.</Text>
183
+ </Centered>
184
+ ) : (
185
+ <FlatList
186
+ data={items}
187
+ keyExtractor={(t) => t.id}
188
+ renderItem={({ item }) => (
189
+ <View style={styles.row}>
190
+ <Switch value={item.done} disabled={!canComplete} accessibilityLabel={`${item.title}: ${item.done ? "done" : "open"}`} onValueChange={(done) => void setDone({ id: item.id, done }).catch(onError)} />
191
+ <Text style={[styles.flex, item.done && styles.done]}>{item.title}</Text>
192
+ </View>
193
+ )}
194
+ />
195
+ )}
196
+ </View>
197
+ );
198
+ }
199
+
200
+ function Centered({ children }: { children: ReactNode }) {
201
+ return <View style={styles.center}>{children}</View>;
202
+ }
203
+
204
+ const styles = StyleSheet.create({
205
+ screen: { flex: 1 },
206
+ flex: { flex: 1 },
207
+ pad: { padding: 16, gap: 12 },
208
+ center: { flex: 1, alignItems: "center", justifyContent: "center", padding: 24 },
209
+ bar: { flexDirection: "row", alignItems: "center", gap: 12, paddingHorizontal: 16, paddingVertical: 8 },
210
+ title: { flex: 1, fontSize: 20, fontWeight: "600" },
211
+ heading: { fontSize: 18, fontWeight: "600" },
212
+ muted: { opacity: 0.6 },
213
+ notice: { backgroundColor: "#fde8e8", color: "#7a1f1f", padding: 12, marginHorizontal: 16, borderRadius: 8 },
214
+ input: { borderWidth: StyleSheet.hairlineWidth, borderRadius: 8, padding: 10, marginHorizontal: 16, marginVertical: 6 },
215
+ chips: { flexGrow: 0, paddingHorizontal: 12, paddingVertical: 8 },
216
+ chip: { paddingHorizontal: 12, paddingVertical: 6, borderRadius: 16, borderWidth: StyleSheet.hairlineWidth, marginRight: 8 },
217
+ chipOn: { backgroundColor: "#e6eefc" },
218
+ row: { flexDirection: "row", alignItems: "center", gap: 12, paddingHorizontal: 16, paddingVertical: 10 },
219
+ done: { textDecorationLine: "line-through", opacity: 0.5 },
220
+ });
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "Tasks",
3
+ "bundleIdentifier": "dev.feltkit.example.tasks",
4
+ "scheme": "feltkit-tasks"
5
+ }
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "feltkit-example-tasks",
3
+ "private": true,
4
+ "version": "0.1.0",
5
+ "type": "module",
6
+ "scripts": {
7
+ "dev": "feltkit dev",
8
+ "build": "feltkit build",
9
+ "start": "feltkit start",
10
+ "test": "feltkit test",
11
+ "inspect": "feltkit inspect",
12
+ "deploy": "feltkit deploy",
13
+ "typecheck": "tsc --noEmit"
14
+ },
15
+ "dependencies": {
16
+ "@feltdb/feltkit": "0.5.0",
17
+ "@feltdb/webllm": ">=0.25.0 <1.0.0",
18
+ "@mlc-ai/web-llm": "^0.2.84",
19
+ "react": "19.3.1",
20
+ "react-dom": "19.3.1"
21
+ },
22
+ "devDependencies": {
23
+ "@types/node": "26.6.6",
24
+ "@types/react": "19.3.0",
25
+ "@types/react-dom": "19.3.0",
26
+ "@vitejs/plugin-react": "5.1.0",
27
+ "typescript": "7.0.2",
28
+ "vite": "7.3.7"
29
+ }
30
+ }
@@ -0,0 +1,7 @@
1
+ // Applies the saved theme before the app renders, so there is no light flash in dark mode.
2
+ // Same key and values as src/theme.tsx. A file, not an inline script, so it also works under
3
+ // a Content-Security-Policy that allows only same-origin scripts.
4
+ try {
5
+ var theme = localStorage.getItem("app:theme");
6
+ if (theme === "light" || theme === "dark") document.documentElement.dataset.theme = theme;
7
+ } catch (e) {}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * What the screens decide, shared by the web app (src/) and the native app (native/): no UI, no platform. The server
3
+ * enforces all of it on every call; this is only what a screen shows and how it words a refusal.
4
+ */
5
+
6
+ /** Same matching rule as AppPort: exact, "ns.*", or "*". */
7
+ export function can(granted: string[], permission: string): boolean {
8
+ return granted.some((g) => g === "*" || g === permission || (g.endsWith(".*") && permission.startsWith(g.slice(0, -1))));
9
+ }
10
+
11
+ /** A failed call, as a sentence for the person. */
12
+ export function describe(error: unknown): string {
13
+ const e = error as { code?: string; message?: string } | null;
14
+ if (e?.code === "FORBIDDEN") return `Not allowed: ${e.message}. Switch to a member to make changes.`;
15
+ if (e?.code === "UNAUTHORIZED") return "Sign in to continue.";
16
+ if (e?.code === "CONFLICT") return e.message ?? "That changed elsewhere.";
17
+ return e?.message ?? String(error);
18
+ }