create-feltkit 0.4.0 → 0.5.1

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 +13 -7
  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,179 @@
1
+ import { useEffect, useState, type ReactNode } from "react";
2
+ import type { EveFact } from "@feltdb/feltkit/client";
3
+ import { describe } from "../shared/rules";
4
+
5
+ export type Screen = "home" | "work" | "context" | "decisions" | "agent" | "activity" | "team";
6
+
7
+ export function ago(at: number | string | undefined): string {
8
+ if (at === undefined) return "";
9
+ const ms = Date.now() - (typeof at === "number" ? at : Date.parse(at));
10
+ const s = Math.round(ms / 1000);
11
+ if (s < 45) return "just now";
12
+ const m = Math.round(s / 60);
13
+ if (m < 60) return `${m} min ago`;
14
+ const h = Math.round(m / 60);
15
+ if (h < 24) return `${h} h ago`;
16
+ const d = Math.round(h / 24);
17
+ return d < 14 ? `${d} d ago` : new Date(Date.now() - ms).toLocaleDateString();
18
+ }
19
+
20
+ /** Re-render every 30 s so "5 min ago" stays true. */
21
+ export function useTick(): void {
22
+ const [, set] = useState(0);
23
+ useEffect(() => {
24
+ const t = setInterval(() => set((n) => n + 1), 30_000);
25
+ return () => clearInterval(t);
26
+ }, []);
27
+ }
28
+
29
+ export function who(actor: { id: string; type?: string; name?: string } | undefined, members?: Map<string, string>): string {
30
+ if (!actor) return "Someone";
31
+ if (actor.type === "agent" || actor.id.startsWith("worker:eve-")) return "Crew agent";
32
+ return actor.name ?? members?.get(actor.id) ?? actor.id;
33
+ }
34
+
35
+ export function Empty({ title, children, action }: { title: string; children?: ReactNode; action?: ReactNode }) {
36
+ return (
37
+ <div className="empty">
38
+ <strong>{title}</strong>
39
+ {children ? <span className="small">{children}</span> : null}
40
+ {action}
41
+ </div>
42
+ );
43
+ }
44
+
45
+ export function Failure({ error }: { error: unknown }) {
46
+ if (!error) return null;
47
+ return <div className="error" role="alert">{describe(error)}</div>;
48
+ }
49
+
50
+ export function Loading({ label = "Loading" }: { label?: string }) {
51
+ return <div className="empty" aria-busy="true"><span className="small">{label}…</span></div>;
52
+ }
53
+
54
+ /** A button whose action is async: disabled while it runs, its failure shown beside it. */
55
+ export function useRun(): { busy: boolean; error: unknown; run: (fn: () => Promise<unknown>) => Promise<boolean>; clear(): void } {
56
+ const [busy, setBusy] = useState(false);
57
+ const [error, setError] = useState<unknown>(null);
58
+ return {
59
+ busy,
60
+ error,
61
+ clear: () => setError(null),
62
+ run: async (fn) => {
63
+ setBusy(true);
64
+ setError(null);
65
+ try {
66
+ await fn();
67
+ return true;
68
+ } catch (e) {
69
+ setError(e);
70
+ return false;
71
+ } finally {
72
+ setBusy(false);
73
+ }
74
+ },
75
+ };
76
+ }
77
+
78
+ export const SOURCE_LABEL: Record<string, string> = { person: "Person", agent: "Agent", external: "External source", starter: "Starter" };
79
+ export const CONFIDENCE: Record<string, { label: string; tone: string }> = {
80
+ hypothesis: { label: "Hypothesis", tone: "outline" },
81
+ unverified: { label: "Unverified", tone: "warn" },
82
+ verified: { label: "Verified", tone: "ok" },
83
+ };
84
+ export const WS_STATUS: Record<string, string> = { "not-started": "Not started", "on-track": "On track", "at-risk": "At risk", blocked: "Blocked", done: "Done" };
85
+ export const TASK_STATUS: Record<string, string> = { open: "Open", ready: "Ready", blocked: "Blocked", claimed: "Claimed", in_progress: "In progress", completed: "Done", failed: "Failed", cancelled: "Cancelled" };
86
+
87
+ export function SourceBadge({ source }: { source: string }) {
88
+ return <span className={`badge ${source === "agent" ? "agent" : ""}`}>{SOURCE_LABEL[source] ?? source}</span>;
89
+ }
90
+ export function ConfidenceBadge({ confidence }: { confidence: string }) {
91
+ const c = CONFIDENCE[confidence] ?? { label: confidence, tone: "" };
92
+ return <span className={`badge ${c.tone}`}>{c.label}</span>;
93
+ }
94
+
95
+ // ---- the agent's sessions, read from eve's facts ------------------------------------------------------------------
96
+
97
+ export type TranscriptEntry =
98
+ | { kind: "user"; key: string; text: string; by: string }
99
+ | { kind: "assistant"; key: string; text: string }
100
+ | { kind: "call"; key: string; callId: string; tool: string; input: unknown; outcome?: string; output?: unknown; clearedBy?: string }
101
+ | { kind: "approval"; key: string; interactionId: string; prompt: string; callId?: string; outcome?: string };
102
+
103
+ export type SessionState = "working" | "waiting" | "idle" | "failed";
104
+
105
+ /** A session's transcript and state, derived only from what eve recorded. */
106
+ export function readSession(facts: EveFact[]): { entries: TranscriptEntry[]; state: SessionState; waiting: Array<{ interactionId: string; prompt: string; tool?: string; input?: unknown }> } {
107
+ const entries: TranscriptEntry[] = [];
108
+ const calls = new Map<string, Extract<TranscriptEntry, { kind: "call" }>>();
109
+ const approvals = new Map<string, Extract<TranscriptEntry, { kind: "approval" }>>();
110
+ const deliveries = new Map<string, string>();
111
+ let state: SessionState = "idle";
112
+ facts.forEach((f, i) => {
113
+ const d = (f.data ?? {}) as Record<string, any>;
114
+ switch (f.type) {
115
+ case "delivery.admitted":
116
+ deliveries.set(d.deliveryId, String(d.principal?.id ?? "").split(":").pop() ?? "");
117
+ break;
118
+ case "delivery.consumed": {
119
+ const text = (d.parts ?? []).filter((p: any) => p.kind === "text").map((p: any) => p.text).join("\n");
120
+ if (text) entries.push({ kind: "user", key: `u${i}`, text, by: deliveries.get(d.deliveryId) ?? "" });
121
+ break;
122
+ }
123
+ case "content.completed":
124
+ if (d.kind === "text" && d.phase === "reply" && d.value) entries.push({ kind: "assistant", key: `a${i}`, text: String(d.value) });
125
+ break;
126
+ case "call.requested": {
127
+ const entry = { kind: "call" as const, key: `c${d.callId}`, callId: d.callId, tool: d.capability?.name ?? "tool", input: d.input };
128
+ calls.set(d.callId, entry);
129
+ entries.push(entry);
130
+ break;
131
+ }
132
+ case "call.started":
133
+ if (calls.get(d.callId) && d.clearedBy?.interactionId) calls.get(d.callId)!.clearedBy = d.clearedBy.interactionId;
134
+ break;
135
+ case "call.settled":
136
+ if (calls.get(d.callId)) Object.assign(calls.get(d.callId)!, { outcome: d.outcome, output: d.output ?? d.error });
137
+ break;
138
+ case "interaction.opened": {
139
+ const entry = { kind: "approval" as const, key: `i${d.interactionId}`, interactionId: d.interactionId, prompt: d.request?.prompt ?? "Approve?", callId: d.subject?.callId };
140
+ approvals.set(d.interactionId, entry);
141
+ entries.push(entry);
142
+ break;
143
+ }
144
+ case "interaction.settled":
145
+ if (approvals.get(d.interactionId)) approvals.get(d.interactionId)!.outcome = d.response?.optionId === "approve" ? "approved" : d.outcome === "accepted" ? "denied" : d.outcome;
146
+ break;
147
+ case "turn.started":
148
+ state = "working";
149
+ break;
150
+ case "turn.paused":
151
+ state = "waiting";
152
+ break;
153
+ case "turn.settled":
154
+ state = d.outcome === "failed" ? "failed" : "idle";
155
+ break;
156
+ }
157
+ });
158
+ const waiting = [...approvals.values()].filter((a) => !a.outcome).map((a) => {
159
+ const call = a.callId ? calls.get(a.callId) : undefined;
160
+ return { interactionId: a.interactionId, prompt: a.prompt, ...(call ? { tool: call.tool, input: call.input } : {}) };
161
+ });
162
+ if (waiting.length) state = "waiting";
163
+ return { entries, state, waiting };
164
+ }
165
+
166
+ export const TOOL_LABEL: Record<string, string> = {
167
+ crew_workspace_overview: "Read the workspace",
168
+ crew_context_search: "Searched the workspace",
169
+ crew_context_read: "Read a context item",
170
+ crew_context_record: "Recorded in context",
171
+ crew_artifacts_create: "Created an artifact",
172
+ crew_decisions_propose: "Proposed a decision",
173
+ crew_tasks_list: "Read the tasks",
174
+ crew_tasks_add: "Add a task",
175
+ crew_tasks_note: "Noted progress",
176
+ crew_workstreams_update: "Change a workstream's status",
177
+ web_search: "Searched the web",
178
+ web_fetch: "Read a web page",
179
+ };
@@ -0,0 +1,111 @@
1
+ /**
2
+ * Run with `npm test` (`feltkit test`). Each test app gets its own FeltDB instance in a temporary directory:
3
+ * real storage, real authorization, nothing shared with development.
4
+ */
5
+ import { test } from "node:test";
6
+ import assert from "node:assert/strict";
7
+ import { createTestApp } from "@feltdb/feltkit/testing";
8
+ import { api } from "../feltkit/_generated/api.js";
9
+
10
+ async function workspace(t: Awaited<ReturnType<typeof createTestApp>>, name = "Launch") {
11
+ const { id } = await t.provisionTenant(name, { id: "ada", roles: ["person"] });
12
+ return id;
13
+ }
14
+
15
+ async function join(t: Awaited<ReturnType<typeof createTestApp>>, tenantId: string, who: string, role: string) {
16
+ const tenancy = t.runtime.tenancy!;
17
+ const owner = await tenancy.context(tenantId, "ada");
18
+ const { token } = await tenancy.invite({ ...owner!, principalId: "ada" }, { email: `${who}@example.com`, role });
19
+ await tenancy.accept(token, { id: who, type: "user", roles: ["person"] } as never, { allowAnyAddress: true });
20
+ }
21
+
22
+ test("a new workspace starts from Launch a Business: mission, five workstreams, starter work marked as hypotheses", async () => {
23
+ const t = await createTestApp();
24
+ try {
25
+ const tenant = await workspace(t);
26
+ const ada = t.as("ada", { tenant });
27
+ await ada.mutation(api.workspace.setup, { title: "Launch a Business", outcome: "Validate and launch a viable business.", template: "launch-a-business" });
28
+
29
+ const o = (await ada.query(api.workspace.overview)) as any;
30
+ assert.equal(o.mission.title, "Launch a Business");
31
+ assert.deepEqual(o.workstreams.map((w: any) => w.name), ["Customer Discovery", "Product & Offer", "Business Model", "Operations", "Go-to-Market"]);
32
+ assert.equal(o.evidence.tasks, 22);
33
+ assert.equal(o.evidence.verified, 0);
34
+ assert.equal(o.evidence.hypotheses, 4);
35
+ assert.equal(o.attention.decisions.length, 1);
36
+ assert.equal(o.next.action, "activate-agent");
37
+
38
+ const notes = (await ada.query(api.knowledge.list, {})) as any[];
39
+ assert.ok(notes.every((n) => n.source === "starter" && n.confidence === "hypothesis"));
40
+ await assert.rejects(ada.mutation(api.knowledge.verify, { id: notes[0].id, verified: true }), { code: "FAILED_PRECONDITION" });
41
+
42
+ const timeline = (await ada.query(api.activity.timeline, {})) as any[];
43
+ assert.ok(timeline.some((e) => e.type === "workspace.created" && e.actor.id === "ada"));
44
+ assert.ok(timeline.some((e) => e.origin === "work"));
45
+ await assert.rejects(ada.mutation(api.workspace.setup, { title: "Again", outcome: "x", template: "blank" }), { code: "CONFLICT" });
46
+ } finally {
47
+ await t.close();
48
+ }
49
+ });
50
+
51
+ test("members share one workspace; viewers read; another workspace sees nothing of it", async () => {
52
+ const t = await createTestApp();
53
+ try {
54
+ const tenant = await workspace(t);
55
+ await t.as("ada", { tenant }).mutation(api.workspace.setup, { title: "Launch a Business", outcome: "Validate demand.", template: "launch-a-business" });
56
+ await join(t, tenant, "lin", "member");
57
+ await join(t, tenant, "sam", "viewer");
58
+ const lin = t.as("lin", { tenant });
59
+ const sam = t.as({ id: "sam", roles: ["person"] }, { tenant });
60
+
61
+ const { id } = (await lin.mutation(api.knowledge.record, { kind: "finding", title: "Agencies track work in 4 tools", body: "Three of five interviewees use email, chat, a spreadsheet and an invoicing tool." })) as { id: string };
62
+ const seenByAda = (await t.as("ada", { tenant }).query(api.knowledge.list, {})) as any[];
63
+ assert.ok(seenByAda.some((c) => c.id === id && c.source === "person" && c.confidence === "unverified" && c.createdBy.id === "lin"));
64
+ await t.as("ada", { tenant }).mutation(api.knowledge.verify, { id, verified: true });
65
+ assert.equal(((await sam.query(api.workspace.overview)) as any).evidence.verified, 1);
66
+ await assert.rejects(sam.mutation(api.knowledge.record, { kind: "note", title: "x", body: "y" }), { code: "FORBIDDEN" });
67
+
68
+ const { id: other } = await t.provisionTenant("Other", { id: "lin", roles: ["person"] });
69
+ const linElsewhere = t.as("lin", { tenant: other });
70
+ assert.equal(((await linElsewhere.query(api.workspace.overview)) as any).setup, false);
71
+ assert.deepEqual(await linElsewhere.query(api.knowledge.list, {}), []);
72
+ } finally {
73
+ await t.close();
74
+ }
75
+ });
76
+
77
+ test("decisions are proposed, decided by a person, and revisited without losing history", async () => {
78
+ const t = await createTestApp();
79
+ try {
80
+ const tenant = await workspace(t);
81
+ const ada = t.as("ada", { tenant });
82
+ await ada.mutation(api.workspace.setup, { title: "Launch", outcome: "Launch.", template: "blank" });
83
+ const { id: finding } = (await ada.mutation(api.knowledge.record, { kind: "finding", title: "Agencies pay for coordination", body: "4 of 6 pay for a PM tool today." })) as { id: string };
84
+ const { id } = (await ada.mutation(api.decisions.propose, { question: "Which segment first?", recommendation: "Agencies", alternatives: ["Home services"], evidence: [finding] })) as { id: string };
85
+ await ada.mutation(api.decisions.decide, { id, outcome: "decided", rationale: "They already pay for a workaround." });
86
+ const { id: next } = (await ada.mutation(api.decisions.revisit, { id, decision: "Small professional practices", rationale: "Agencies churn tools too often." })) as { id: string };
87
+ const { chain, evidence } = (await ada.query(api.decisions.history, { id })) as any;
88
+ assert.deepEqual(chain.map((d: any) => [d.id, d.status]), [[next, "decided"], [id, "superseded"]]);
89
+ assert.equal(chain[1].decision, "Agencies");
90
+ assert.equal(evidence[0].id, finding);
91
+ await assert.rejects(ada.mutation(api.decisions.decide, { id, outcome: "decided", decision: "x" }), { code: "CONFLICT" });
92
+ } finally {
93
+ await t.close();
94
+ }
95
+ });
96
+
97
+ test("a mission edited by someone else since you read it is refused, not overwritten", async () => {
98
+ const t = await createTestApp();
99
+ try {
100
+ const tenant = await workspace(t);
101
+ const ada = t.as("ada", { tenant });
102
+ await ada.mutation(api.workspace.setup, { title: "Launch", outcome: "Launch.", template: "blank" });
103
+ await join(t, tenant, "lin", "admin");
104
+ const version = ((await ada.query(api.workspace.overview)) as any).mission.version;
105
+ await t.as("lin", { tenant }).mutation(api.workspace.updateMission, { version, stage: "validating" });
106
+ await assert.rejects(ada.mutation(api.workspace.updateMission, { version, title: "Something else" }), { code: "CONFLICT" });
107
+ assert.equal(((await ada.query(api.workspace.overview)) as any).mission.stage, "validating");
108
+ } finally {
109
+ await t.close();
110
+ }
111
+ });
@@ -3,14 +3,29 @@
3
3
  "target": "ES2022",
4
4
  "module": "ESNext",
5
5
  "moduleResolution": "Bundler",
6
- "lib": ["ES2023", "DOM", "DOM.Iterable"],
6
+ "lib": [
7
+ "ES2023",
8
+ "DOM",
9
+ "DOM.Iterable"
10
+ ],
7
11
  "jsx": "react-jsx",
8
12
  "strict": true,
9
13
  "noEmit": true,
10
14
  "skipLibCheck": true,
11
15
  "isolatedModules": true,
12
16
  "verbatimModuleSyntax": true,
13
- "types": ["node", "vite/client"]
17
+ "types": [
18
+ "node",
19
+ "vite/client"
20
+ ],
21
+ "resolveJsonModule": true
14
22
  },
15
- "include": ["src", "feltkit", "tests", "vite.config.ts"]
23
+ "include": [
24
+ "src",
25
+ "feltkit",
26
+ "tests",
27
+ "shared",
28
+ "agent",
29
+ "vite.config.ts"
30
+ ]
16
31
  }
@@ -1,7 +1,7 @@
1
1
  # The inventory service on Managed FeltDB. The image holds no state and no credentials:
2
2
  # FELTDB_URL, FELTDB_APPLICATION_ID and FELTDB_ENVIRONMENT come from the platform's configuration
3
3
  # and FELTDB_TOKEN from its secret store, at run time (README.md, "Deploy").
4
- FROM node:22-slim AS build
4
+ FROM node:26-slim AS build
5
5
  WORKDIR /app
6
6
  COPY package.json package-lock.json* ./
7
7
  RUN if [ -f package-lock.json ]; then npm ci --no-audit --no-fund; else npm install --no-audit --no-fund; fi
@@ -10,7 +10,7 @@ COPY . .
10
10
  # only stores what it declares.
11
11
  RUN npx feltkit contract --check && npx feltkit build && npm prune --omit=dev --no-audit --no-fund
12
12
 
13
- FROM node:22-slim
13
+ FROM node:26-slim
14
14
  ENV NODE_ENV=production PORT=8080
15
15
  WORKDIR /app
16
16
  COPY --from=build --chown=node:node /app ./
@@ -38,7 +38,7 @@ init-managed` creates *your application* in it, using your FeltDB account.
38
38
 
39
39
  ## Prerequisites
40
40
 
41
- - Node.js 20.11 or later, and npm.
41
+ - Node.js 26 or later, and npm.
42
42
  - A FeltDB account (`npm run managed:setup` creates one if the e-mail is new). The account
43
43
  creates the application and its keys, so you need permission to manage keys for it. The
44
44
  account service never issues a scope you don't hold.
@@ -20,11 +20,11 @@
20
20
  "deploy:fly": "node scripts/deploy-fly.mjs"
21
21
  },
22
22
  "dependencies": {
23
- "@feltdb/feltkit": "0.4.0"
23
+ "@feltdb/feltkit": "0.5.1"
24
24
  },
25
25
  "devDependencies": {
26
- "@feltdb/core": ">=0.23.0 <1.0.0",
27
- "@types/node": "22.19.1",
26
+ "@feltdb/core": ">=0.25.0 <1.0.0",
27
+ "@types/node": "26.6.6",
28
28
  "typescript": "7.0.2"
29
29
  }
30
30
  }