create-efforge 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.
- package/README.md +44 -96
- package/dist/bin.js +7 -0
- package/dist/cli.js +21 -2
- package/dist/commands/add.js +233 -33
- package/dist/commands/create.js +189 -56
- package/dist/commands/list.js +80 -0
- package/dist/exec.js +16 -3
- package/dist/prompts/flow.js +16 -5
- package/dist/prompts/navigable.js +111 -15
- package/dist/rules.js +5 -2
- package/dist/slots.js +20 -0
- package/dist/write.js +3 -1
- package/package.json +1 -1
- package/templates/ai/effect-ai-byok/files/core/llm-crypto.test.ts +42 -37
- package/templates/ai/effect-ai-byok/files/routes/ai.tsx +5 -5
- package/templates/auth/better-auth/files/shared/components/user-menu.tsx +1 -1
- package/templates/auth/better-auth/files/shared/routes/sign-in.tsx +3 -3
- package/templates/auth/better-auth/files/shared/routes/sign-up.tsx +3 -3
- package/templates/auth/better-auth-orgs/files/components/org-switcher.tsx +1 -1
- package/templates/auth/better-auth-orgs/files/routes/accept-invite.$id.tsx +1 -1
- package/templates/auth/better-auth-orgs/files/routes/app/settings/members.tsx +11 -7
- package/templates/auth/better-auth-orgs/files/routes/onboarding.tsx +3 -3
- package/templates/base/addon.json +4 -0
- package/templates/base/files/AGENTS.md +12 -0
- package/templates/base/files/README.md +4 -0
- package/templates/base/files/root/lint/effect-tests.js +45 -0
- package/templates/base/files/root/vite.config.ts +25 -0
- package/templates/extras/realtime/files/realtime-demo.tsx +2 -2
|
@@ -1,15 +1,32 @@
|
|
|
1
|
+
import { stripVTControlCharacters } from "node:util";
|
|
1
2
|
import * as p from "@clack/prompts";
|
|
2
|
-
import { Context, Effect, Layer, Schema } from "effect";
|
|
3
|
+
import { Cause, Context, Effect, Layer, Schema } from "effect";
|
|
3
4
|
import pc from "picocolors";
|
|
4
5
|
/** Returned by a prompt when the user picked "Back". */
|
|
5
6
|
export const GoBack = Symbol.for("efforge/GoBack");
|
|
6
7
|
export class Cancelled extends Schema.TaggedError()("Cancelled", {}) {
|
|
7
8
|
}
|
|
9
|
+
/** A prompt was needed but stdin is not a terminal (CI, pipes): fail fast instead of hanging. */
|
|
10
|
+
export class NeedsInput extends Schema.TaggedError()("NeedsInput", {
|
|
11
|
+
id: Schema.String,
|
|
12
|
+
options: Schema.Array(Schema.String),
|
|
13
|
+
}) {
|
|
14
|
+
}
|
|
8
15
|
export class PromptIO extends Context.Service()("efforge/PromptIO") {
|
|
9
16
|
}
|
|
10
17
|
const BACK = "\u0000back";
|
|
11
18
|
const backChoice = { value: BACK, label: pc.dim("← Back") };
|
|
12
|
-
const ask = (
|
|
19
|
+
const ask = (id, options, run) => process.stdin.isTTY
|
|
20
|
+
? Effect.promise(run).pipe(Effect.flatMap((v) => p.isCancel(v) ? Effect.fail(new Cancelled()) : Effect.succeed(v)))
|
|
21
|
+
: Effect.fail(new NeedsInput({ id, options }));
|
|
22
|
+
const interactive = () => process.stdout.isTTY && !p.isCI();
|
|
23
|
+
/** Elapsed time, shown only once it's worth reading (`always` for installs). */
|
|
24
|
+
const seconds = (start, always = false) => {
|
|
25
|
+
const s = (performance.now() - start) / 1000;
|
|
26
|
+
return always || s >= 1 ? ` ${pc.dim(`${s.toFixed(1)}s`)}` : "";
|
|
27
|
+
};
|
|
28
|
+
/** Keeps the streamed lines readable: no colour codes, no carriage-return progress redraws. */
|
|
29
|
+
const clean = (line) => stripVTControlCharacters(line.split("\r").pop() ?? "").trimEnd();
|
|
13
30
|
const toOption = (c) => (c.hint === undefined
|
|
14
31
|
? { value: c.value, label: c.label }
|
|
15
32
|
: { value: c.value, label: c.label, hint: c.hint });
|
|
@@ -18,12 +35,12 @@ const toOption = (c) => (c.hint === undefined
|
|
|
18
35
|
* entry: last in a select, and in a multiselect (picking it alone goes back).
|
|
19
36
|
*/
|
|
20
37
|
export const livePromptIO = {
|
|
21
|
-
select: (o) => ask(() => p.select({
|
|
38
|
+
select: (o) => ask(o.id, o.options.map((c) => c.value), () => p.select({
|
|
22
39
|
message: o.message,
|
|
23
40
|
options: [...o.options.map(toOption), ...(o.canGoBack ? [backChoice] : [])],
|
|
24
41
|
...(o.initial === undefined ? {} : { initialValue: o.initial }),
|
|
25
42
|
})).pipe(Effect.map((v) => (v === BACK ? GoBack : v))),
|
|
26
|
-
multiselect: (o) => ask(() => p.multiselect({
|
|
43
|
+
multiselect: (o) => ask(o.id, o.options.map((c) => c.value), () => p.multiselect({
|
|
27
44
|
message: o.canGoBack
|
|
28
45
|
? `${o.message} ${pc.dim("(select Back alone to go back)")}`
|
|
29
46
|
: o.message,
|
|
@@ -31,15 +48,18 @@ export const livePromptIO = {
|
|
|
31
48
|
initialValues: [...(o.initial ?? [])],
|
|
32
49
|
required: false,
|
|
33
50
|
})).pipe(Effect.map((v) => v.includes(BACK) && v.length === 1 ? GoBack : v.filter((x) => x !== BACK))),
|
|
34
|
-
text: (o) => ask(() => p.text({
|
|
51
|
+
text: (o) => ask(o.id, [], () => p.text({
|
|
35
52
|
message: o.message,
|
|
36
53
|
...(o.placeholder === undefined ? {} : { placeholder: o.placeholder }),
|
|
37
54
|
...(o.defaultValue === undefined ? {} : { defaultValue: o.defaultValue }),
|
|
38
55
|
...(o.validate === undefined
|
|
39
56
|
? {}
|
|
40
|
-
: {
|
|
57
|
+
: {
|
|
58
|
+
// an emptied field submits "" (not undefined) after an error; both mean the default
|
|
59
|
+
validate: (v) => o.validate?.(v === undefined || v === "" ? (o.defaultValue ?? "") : v),
|
|
60
|
+
}),
|
|
41
61
|
})),
|
|
42
|
-
confirm: (o) => ask(() => p.confirm({
|
|
62
|
+
confirm: (o) => ask(o.id, [], () => p.confirm({
|
|
43
63
|
message: o.message,
|
|
44
64
|
...(o.initial === undefined ? {} : { initialValue: o.initial }),
|
|
45
65
|
})),
|
|
@@ -48,14 +68,78 @@ export const livePromptIO = {
|
|
|
48
68
|
info: (message) => Effect.sync(() => p.log.info(message)),
|
|
49
69
|
note: (body, title) => Effect.sync(() => p.note(body, title)),
|
|
50
70
|
outro: (message) => Effect.sync(() => p.outro(message)),
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
71
|
+
warn: (message) => Effect.sync(() => p.log.warn(message)),
|
|
72
|
+
// Spinners redraw the terminal: in CI or a pipe, print one line per step instead.
|
|
73
|
+
step: (label, eff) => run(label, () => eff, false),
|
|
74
|
+
task: (label, eff) => run(label, eff, true),
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* A one-line spinner. Not clack's: that one puts stdin in raw mode and answers Ctrl-C with
|
|
78
|
+
* `process.exit(0)`, which skips cleanup and reports success. Here Ctrl-C stays a SIGINT, so the
|
|
79
|
+
* run is interrupted, child processes stop, and the caller can say what is left to do.
|
|
80
|
+
*/
|
|
81
|
+
const spinner = (label) => {
|
|
82
|
+
const out = process.stdout;
|
|
83
|
+
const frames = ["◒", "◐", "◓", "◑"];
|
|
84
|
+
let text = label;
|
|
85
|
+
let frame = 0;
|
|
86
|
+
// a wrapped line can't be redrawn with \r, so everything is cut to the terminal width
|
|
87
|
+
const fit = (s) => {
|
|
88
|
+
const room = (out.columns || 80) - 4;
|
|
89
|
+
const plain = stripVTControlCharacters(s);
|
|
90
|
+
return plain.length <= room ? s : `${plain.slice(0, room - 1)}…`;
|
|
91
|
+
};
|
|
92
|
+
const render = () => out.write(`\r\u001b[2K${pc.magenta(frames[frame++ % 4] ?? "")} ${fit(text)}`);
|
|
93
|
+
const showCursor = () => out.write("\u001b[?25h");
|
|
94
|
+
out.write(`${pc.gray("│")}\n\u001b[?25l`);
|
|
95
|
+
process.once("exit", showCursor);
|
|
96
|
+
render();
|
|
97
|
+
const timer = setInterval(render, 80);
|
|
98
|
+
return {
|
|
99
|
+
message: (s) => {
|
|
100
|
+
text = s;
|
|
101
|
+
},
|
|
102
|
+
end: (symbol, s) => {
|
|
103
|
+
clearInterval(timer);
|
|
104
|
+
process.off("exit", showCursor);
|
|
105
|
+
out.write(`\r\u001b[2K${symbol} ${fit(s)}\n`);
|
|
106
|
+
showCursor();
|
|
107
|
+
},
|
|
108
|
+
};
|
|
58
109
|
};
|
|
110
|
+
const run = (label, eff, live) => Effect.suspend(() => {
|
|
111
|
+
const start = performance.now();
|
|
112
|
+
const done = (exit) => {
|
|
113
|
+
const ok = exit._tag === "Success";
|
|
114
|
+
const interrupted = !ok && Cause.hasInterruptsOnly(exit.cause);
|
|
115
|
+
return {
|
|
116
|
+
ok,
|
|
117
|
+
interrupted,
|
|
118
|
+
msg: ok
|
|
119
|
+
? `${pc.green("✓")} ${label}${seconds(start, live)}`
|
|
120
|
+
: interrupted
|
|
121
|
+
? `${label} ${pc.dim("(cancelled)")}`
|
|
122
|
+
: `${label} failed`,
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
if (!interactive()) {
|
|
126
|
+
if (live)
|
|
127
|
+
p.log.message(`${label}…`);
|
|
128
|
+
return eff(() => { }).pipe(Effect.onExit((exit) => Effect.sync(() => {
|
|
129
|
+
const { ok, interrupted, msg } = done(exit);
|
|
130
|
+
(ok ? p.log.message : interrupted ? p.log.warn : p.log.error)(msg);
|
|
131
|
+
})));
|
|
132
|
+
}
|
|
133
|
+
const s = spinner(label);
|
|
134
|
+
return eff((line) => {
|
|
135
|
+
const text = clean(line);
|
|
136
|
+
if (text !== "")
|
|
137
|
+
s.message(`${label} ${pc.dim(text)}`);
|
|
138
|
+
}).pipe(Effect.onExit((exit) => Effect.sync(() => {
|
|
139
|
+
const { ok, interrupted, msg } = done(exit);
|
|
140
|
+
s.end(ok ? pc.green("◇") : interrupted ? pc.red("■") : pc.red("▲"), msg);
|
|
141
|
+
})));
|
|
142
|
+
});
|
|
59
143
|
export const PromptIOLive = Layer.succeed(PromptIO, livePromptIO);
|
|
60
144
|
// --- scripted layer (tests) ---------------------------------------------------
|
|
61
145
|
export const CANCEL = Symbol.for("efforge/Cancel");
|
|
@@ -84,14 +168,26 @@ export const scriptedPromptIO = (answers) => {
|
|
|
84
168
|
options: o.options.map((c) => c.value),
|
|
85
169
|
canGoBack: o.canGoBack,
|
|
86
170
|
}),
|
|
87
|
-
|
|
171
|
+
// like the live prompt, an answer that fails `validate` is reported and asked again
|
|
172
|
+
text: (o) => {
|
|
173
|
+
const loop = Effect.suspend(() => take({ kind: "text", id: o.id, options: [], canGoBack: false })).pipe(Effect.flatMap((a) => {
|
|
174
|
+
const error = typeof a === "string" ? o.validate?.(a) : undefined;
|
|
175
|
+
if (error === undefined)
|
|
176
|
+
return Effect.succeed(a);
|
|
177
|
+
output.push(`invalid ${o.id}: ${error}`);
|
|
178
|
+
return loop;
|
|
179
|
+
}));
|
|
180
|
+
return loop;
|
|
181
|
+
},
|
|
88
182
|
confirm: (o) => take({ kind: "confirm", id: o.id, options: [], canGoBack: false }),
|
|
89
183
|
intro: (t) => Effect.sync(() => void output.push(`intro: ${t}`)),
|
|
90
184
|
section: (t) => Effect.sync(() => void output.push(`section: ${t}`)),
|
|
91
185
|
info: (m) => Effect.sync(() => void output.push(`info: ${m}`)),
|
|
186
|
+
warn: (m) => Effect.sync(() => void output.push(`warn: ${m}`)),
|
|
92
187
|
note: (b, t) => Effect.sync(() => void output.push(`note ${t}: ${b}`)),
|
|
93
188
|
outro: (m) => Effect.sync(() => void output.push(`outro: ${m}`)),
|
|
94
189
|
step: (label, eff) => Effect.sync(() => void output.push(`step: ${label}`)).pipe(Effect.andThen(eff)),
|
|
190
|
+
task: (label, eff) => Effect.sync(() => void output.push(`step: ${label}`)).pipe(Effect.andThen(eff(() => { }))),
|
|
95
191
|
};
|
|
96
192
|
return { layer: Layer.succeed(PromptIO, io), shown, output };
|
|
97
193
|
};
|
package/dist/rules.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Effect, Schema } from "effect";
|
|
2
|
-
import { available, slots } from "./slots.js";
|
|
2
|
+
import { available, slots, whyUnavailable } from "./slots.js";
|
|
3
3
|
import { SlotId } from "./stack.js";
|
|
4
4
|
export class IncompatibleStack extends Schema.TaggedError()("IncompatibleStack", {
|
|
5
5
|
slot: SlotId,
|
|
@@ -16,7 +16,10 @@ export const validate = (config) => Effect.gen(function* () {
|
|
|
16
16
|
const values = slot.id === "extras" ? config.extras : [config[slot.id]];
|
|
17
17
|
for (const value of values) {
|
|
18
18
|
if (!allowed.includes(value)) {
|
|
19
|
-
|
|
19
|
+
const reason = whyUnavailable(slot.id, value, config);
|
|
20
|
+
return yield* new IncompatibleStack(reason === undefined
|
|
21
|
+
? { slot: slot.id, value, allowed }
|
|
22
|
+
: { slot: slot.id, value, allowed, reason });
|
|
20
23
|
}
|
|
21
24
|
}
|
|
22
25
|
}
|
package/dist/slots.js
CHANGED
|
@@ -94,3 +94,23 @@ export const available = (slot, partial) => {
|
|
|
94
94
|
return true;
|
|
95
95
|
});
|
|
96
96
|
};
|
|
97
|
+
/**
|
|
98
|
+
* Why `value` isn't available for `slot` given `partial`, phrased for the user; undefined when it is
|
|
99
|
+
* available, or isn't an option of the slot at all (an unknown value, not a conflict).
|
|
100
|
+
*/
|
|
101
|
+
export const whyUnavailable = (slot, value, partial) => {
|
|
102
|
+
const def = slots.find((s) => s.id === slot);
|
|
103
|
+
if (def === undefined || !def.options.some((o) => o.id === value))
|
|
104
|
+
return undefined;
|
|
105
|
+
if (available(slot, partial).some((o) => o.id === value))
|
|
106
|
+
return undefined;
|
|
107
|
+
if (cloudflareOnly.has(value))
|
|
108
|
+
return `${value} needs the Cloudflare runtime`;
|
|
109
|
+
if (slot === "orm" && partial.database === "none")
|
|
110
|
+
return "an ORM needs a database, and the database is none";
|
|
111
|
+
if (slot === "orm")
|
|
112
|
+
return `a database needs an ORM; pick one of drizzle, effect-sql`;
|
|
113
|
+
if (slot === "auth")
|
|
114
|
+
return "auth stores users in the database, and the database is none";
|
|
115
|
+
return undefined;
|
|
116
|
+
};
|
package/dist/write.js
CHANGED
|
@@ -8,13 +8,15 @@ export class WriteFailed extends Schema.TaggedError()("WriteFailed", {
|
|
|
8
8
|
message: Schema.String,
|
|
9
9
|
}) {
|
|
10
10
|
}
|
|
11
|
+
const ignorable = new Set([".git", ".DS_Store", "Thumbs.db"]);
|
|
11
12
|
/** Writes `tree` under `dir`. Refuses an existing non-empty directory; creates it otherwise. */
|
|
12
13
|
export const writeTree = (dir, tree) => Effect.gen(function* () {
|
|
13
14
|
const fs = yield* FileSystem.FileSystem;
|
|
14
15
|
const path = yield* Path.Path;
|
|
15
16
|
if (yield* fs.exists(dir)) {
|
|
16
17
|
const entries = yield* fs.readDirectory(dir);
|
|
17
|
-
|
|
18
|
+
// an empty repo (only .git) or OS clutter still counts as empty
|
|
19
|
+
if (entries.some((f) => !ignorable.has(f)))
|
|
18
20
|
return yield* new TargetNotEmpty({ dir });
|
|
19
21
|
}
|
|
20
22
|
yield* fs.makeDirectory(dir, { recursive: true });
|
package/package.json
CHANGED
|
@@ -1,47 +1,52 @@
|
|
|
1
|
+
import { describe, expect, it } from "@effect/vitest"
|
|
1
2
|
import { Effect } from "effect"
|
|
2
|
-
import { describe, expect, it } from "vitest"
|
|
3
3
|
import { decryptSecret, encryptSecret, loadEncryptionKey } from "../src/llm-crypto"
|
|
4
4
|
|
|
5
5
|
const keyText = btoa(String.fromCharCode(...new Uint8Array(32).fill(7)))
|
|
6
|
-
const run = <A, E>(effect: Effect.Effect<A, E>) => Effect.runPromise(effect)
|
|
7
6
|
|
|
8
7
|
describe("llm-crypto", () => {
|
|
9
|
-
it("round-trips a secret and never stores it in the clear",
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
8
|
+
it.effect("round-trips a secret and never stores it in the clear", () =>
|
|
9
|
+
Effect.gen(function* () {
|
|
10
|
+
const key = yield* loadEncryptionKey(keyText)
|
|
11
|
+
const sealed = yield* encryptSecret(key, "sk-secret-1234", "org_1")
|
|
12
|
+
expect(sealed).not.toContain("sk-secret")
|
|
13
|
+
expect(sealed.startsWith("v1.")).toBe(true)
|
|
14
|
+
expect(yield* decryptSecret(key, sealed, "org_1")).toBe("sk-secret-1234")
|
|
15
|
+
}),
|
|
16
|
+
)
|
|
16
17
|
|
|
17
|
-
it("uses a fresh IV each time",
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
18
|
+
it.effect("uses a fresh IV each time", () =>
|
|
19
|
+
Effect.gen(function* () {
|
|
20
|
+
const key = yield* loadEncryptionKey(keyText)
|
|
21
|
+
const [a, b] = yield* Effect.all(
|
|
22
|
+
[encryptSecret(key, "same", "org_1"), encryptSecret(key, "same", "org_1")],
|
|
23
|
+
{ concurrency: "unbounded" },
|
|
24
|
+
)
|
|
25
|
+
expect(a).not.toBe(b)
|
|
26
|
+
}),
|
|
27
|
+
)
|
|
25
28
|
|
|
26
|
-
it("refuses a ciphertext moved to another organization or tampered with",
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
29
|
+
it.effect("refuses a ciphertext moved to another organization or tampered with", () =>
|
|
30
|
+
Effect.gen(function* () {
|
|
31
|
+
const key = yield* loadEncryptionKey(keyText)
|
|
32
|
+
const sealed = yield* encryptSecret(key, "sk-secret", "org_1")
|
|
33
|
+
expect(yield* Effect.flip(decryptSecret(key, sealed, "org_2"))).toMatchObject({
|
|
34
|
+
_tag: "LlmError",
|
|
35
|
+
})
|
|
36
|
+
const parts = sealed.split(".")
|
|
37
|
+
const tampered = `${parts[0]}.${parts[1]}.${btoa("x".repeat(24))}`
|
|
38
|
+
expect(yield* Effect.flip(decryptSecret(key, tampered, "org_1"))).toMatchObject({
|
|
39
|
+
_tag: "LlmError",
|
|
40
|
+
})
|
|
41
|
+
}),
|
|
42
|
+
)
|
|
38
43
|
|
|
39
|
-
it("rejects a missing, malformed or wrong-sized key at load time",
|
|
40
|
-
|
|
41
|
-
[undefined, "", "not base64!", btoa("short")]
|
|
42
|
-
|
|
43
|
-
)
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
it.effect("rejects a missing, malformed or wrong-sized key at load time", () =>
|
|
45
|
+
Effect.gen(function* () {
|
|
46
|
+
const errors = yield* Effect.forEach([undefined, "", "not base64!", btoa("short")], (bad) =>
|
|
47
|
+
Effect.flip(loadEncryptionKey(bad)),
|
|
48
|
+
)
|
|
49
|
+
for (const error of errors) expect(error).toMatchObject({ _tag: "LlmConfigError" })
|
|
50
|
+
}),
|
|
51
|
+
)
|
|
47
52
|
})
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createFileRoute, useRouter } from "@tanstack/react-router"
|
|
2
|
-
import { type
|
|
2
|
+
import { type SubmitEvent, useState } from "react"
|
|
3
3
|
import { toast } from "sonner"
|
|
4
4
|
import { Button } from "@/components/ui/button"
|
|
5
5
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
|
|
@@ -56,7 +56,7 @@ function AiSettings() {
|
|
|
56
56
|
const { canManage, configured, last4 } = settings
|
|
57
57
|
const needsUrl = provider === "ollama" || provider === "openai"
|
|
58
58
|
|
|
59
|
-
async function save(event:
|
|
59
|
+
async function save(event: SubmitEvent<HTMLFormElement>) {
|
|
60
60
|
event.preventDefault()
|
|
61
61
|
const form = event.currentTarget
|
|
62
62
|
const data = new FormData(form)
|
|
@@ -113,7 +113,7 @@ function AiSettings() {
|
|
|
113
113
|
</p>
|
|
114
114
|
)}
|
|
115
115
|
{canManage ? (
|
|
116
|
-
<form onSubmit={save} className="space-y-4">
|
|
116
|
+
<form onSubmit={(event) => void save(event)} className="space-y-4">
|
|
117
117
|
<div className="space-y-2">
|
|
118
118
|
<Label htmlFor="ai-provider">Provider</Label>
|
|
119
119
|
<select
|
|
@@ -172,10 +172,10 @@ function AiSettings() {
|
|
|
172
172
|
<Button type="submit">Save</Button>
|
|
173
173
|
{configured ? (
|
|
174
174
|
<>
|
|
175
|
-
<Button type="button" variant="outline" onClick={test}>
|
|
175
|
+
<Button type="button" variant="outline" onClick={() => void test()}>
|
|
176
176
|
Test
|
|
177
177
|
</Button>
|
|
178
|
-
<Button type="button" variant="outline" onClick={clear}>
|
|
178
|
+
<Button type="button" variant="outline" onClick={() => void clear()}>
|
|
179
179
|
Remove key
|
|
180
180
|
</Button>
|
|
181
181
|
</>
|
|
@@ -37,7 +37,7 @@ export function UserMenu({ name, email }: { name: string; email: string }) {
|
|
|
37
37
|
<div className="text-xs font-normal text-muted-foreground">{email}</div>
|
|
38
38
|
</DropdownMenuLabel>
|
|
39
39
|
<DropdownMenuSeparator />
|
|
40
|
-
<DropdownMenuItem onSelect={signOut}>Sign out</DropdownMenuItem>
|
|
40
|
+
<DropdownMenuItem onSelect={() => void signOut()}>Sign out</DropdownMenuItem>
|
|
41
41
|
</DropdownMenuContent>
|
|
42
42
|
</DropdownMenu>
|
|
43
43
|
)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createFileRoute, Link, redirect } from "@tanstack/react-router"
|
|
2
|
-
import { type
|
|
2
|
+
import { type SubmitEvent, useState } from "react"
|
|
3
3
|
import { AuthCard } from "@/components/auth-card"
|
|
4
4
|
import { Button } from "@/components/ui/button"
|
|
5
5
|
import { Input } from "@/components/ui/input"
|
|
@@ -22,7 +22,7 @@ function SignIn() {
|
|
|
22
22
|
const [error, setError] = useState<string | null>(null)
|
|
23
23
|
const [pending, setPending] = useState(false)
|
|
24
24
|
|
|
25
|
-
async function onSubmit(event:
|
|
25
|
+
async function onSubmit(event: SubmitEvent<HTMLFormElement>) {
|
|
26
26
|
event.preventDefault()
|
|
27
27
|
const form = new FormData(event.currentTarget)
|
|
28
28
|
setPending(true)
|
|
@@ -56,7 +56,7 @@ function SignIn() {
|
|
|
56
56
|
</>
|
|
57
57
|
}
|
|
58
58
|
>
|
|
59
|
-
<form method="post" onSubmit={onSubmit} className="space-y-4">
|
|
59
|
+
<form method="post" onSubmit={(event) => void onSubmit(event)} className="space-y-4">
|
|
60
60
|
<div className="space-y-2">
|
|
61
61
|
<Label htmlFor="email">Email</Label>
|
|
62
62
|
<Input id="email" name="email" type="email" autoComplete="email" required />
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createFileRoute, Link, redirect } from "@tanstack/react-router"
|
|
2
|
-
import { type
|
|
2
|
+
import { type SubmitEvent, useState } from "react"
|
|
3
3
|
import { AuthCard } from "@/components/auth-card"
|
|
4
4
|
import { Button } from "@/components/ui/button"
|
|
5
5
|
import { Input } from "@/components/ui/input"
|
|
@@ -22,7 +22,7 @@ function SignUp() {
|
|
|
22
22
|
const [error, setError] = useState<string | null>(null)
|
|
23
23
|
const [pending, setPending] = useState(false)
|
|
24
24
|
|
|
25
|
-
async function onSubmit(event:
|
|
25
|
+
async function onSubmit(event: SubmitEvent<HTMLFormElement>) {
|
|
26
26
|
event.preventDefault()
|
|
27
27
|
const form = new FormData(event.currentTarget)
|
|
28
28
|
setPending(true)
|
|
@@ -57,7 +57,7 @@ function SignUp() {
|
|
|
57
57
|
</>
|
|
58
58
|
}
|
|
59
59
|
>
|
|
60
|
-
<form method="post" onSubmit={onSubmit} className="space-y-4">
|
|
60
|
+
<form method="post" onSubmit={(event) => void onSubmit(event)} className="space-y-4">
|
|
61
61
|
<div className="space-y-2">
|
|
62
62
|
<Label htmlFor="name">Name</Label>
|
|
63
63
|
<Input id="name" name="name" autoComplete="name" required />
|
|
@@ -47,7 +47,7 @@ export function OrgSwitcher({
|
|
|
47
47
|
<DropdownMenuContent align="start" className="w-56">
|
|
48
48
|
<DropdownMenuLabel>Organizations</DropdownMenuLabel>
|
|
49
49
|
{organizations.map((org) => (
|
|
50
|
-
<DropdownMenuItem key={org.id} onSelect={() => select(org.id)}>
|
|
50
|
+
<DropdownMenuItem key={org.id} onSelect={() => void select(org.id)}>
|
|
51
51
|
<span className="flex-1 truncate">{org.name}</span>
|
|
52
52
|
{org.id === activeId ? <Check className="size-4" /> : null}
|
|
53
53
|
</DropdownMenuItem>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createFileRoute } from "@tanstack/react-router"
|
|
2
|
-
import { type
|
|
2
|
+
import { type SubmitEvent, useState } from "react"
|
|
3
3
|
import { toast } from "sonner"
|
|
4
4
|
import { Button } from "@/components/ui/button"
|
|
5
5
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
|
|
@@ -43,7 +43,7 @@ function Members() {
|
|
|
43
43
|
const canManage = me?.role === "owner" || me?.role === "admin"
|
|
44
44
|
const pending = org.invitations.filter((invitation) => invitation.status === "pending")
|
|
45
45
|
|
|
46
|
-
async function invite(event:
|
|
46
|
+
async function invite(event: SubmitEvent<HTMLFormElement>) {
|
|
47
47
|
event.preventDefault()
|
|
48
48
|
const form = event.currentTarget
|
|
49
49
|
const data = new FormData(form)
|
|
@@ -110,7 +110,7 @@ function Members() {
|
|
|
110
110
|
</option>
|
|
111
111
|
))}
|
|
112
112
|
</select>
|
|
113
|
-
<Button variant="outline" size="sm" onClick={() => remove(member.id)}>
|
|
113
|
+
<Button variant="outline" size="sm" onClick={() => void remove(member.id)}>
|
|
114
114
|
Remove
|
|
115
115
|
</Button>
|
|
116
116
|
</>
|
|
@@ -132,7 +132,7 @@ function Members() {
|
|
|
132
132
|
</CardDescription>
|
|
133
133
|
</CardHeader>
|
|
134
134
|
<CardContent className="space-y-4">
|
|
135
|
-
<form onSubmit={invite} className="flex items-end gap-2">
|
|
135
|
+
<form onSubmit={(event) => void invite(event)} className="flex items-end gap-2">
|
|
136
136
|
<div className="flex-1 space-y-2">
|
|
137
137
|
<Label htmlFor="invite-email">Email</Label>
|
|
138
138
|
<Input id="invite-email" name="email" type="email" required />
|
|
@@ -159,7 +159,7 @@ function Members() {
|
|
|
159
159
|
value={link}
|
|
160
160
|
onFocus={(e) => e.target.select()}
|
|
161
161
|
/>
|
|
162
|
-
<Button variant="outline" onClick={() => copy(link)}>
|
|
162
|
+
<Button variant="outline" onClick={() => void copy(link)}>
|
|
163
163
|
Copy
|
|
164
164
|
</Button>
|
|
165
165
|
</div>
|
|
@@ -178,11 +178,15 @@ function Members() {
|
|
|
178
178
|
<Button
|
|
179
179
|
variant="outline"
|
|
180
180
|
size="sm"
|
|
181
|
-
onClick={() => copy(inviteLink(invitation.id))}
|
|
181
|
+
onClick={() => void copy(inviteLink(invitation.id))}
|
|
182
182
|
>
|
|
183
183
|
Copy link
|
|
184
184
|
</Button>
|
|
185
|
-
<Button
|
|
185
|
+
<Button
|
|
186
|
+
variant="outline"
|
|
187
|
+
size="sm"
|
|
188
|
+
onClick={() => void cancel(invitation.id)}
|
|
189
|
+
>
|
|
186
190
|
Cancel
|
|
187
191
|
</Button>
|
|
188
192
|
</li>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createFileRoute, redirect } from "@tanstack/react-router"
|
|
2
|
-
import { type
|
|
2
|
+
import { type SubmitEvent, useState } from "react"
|
|
3
3
|
import { AuthCard } from "@/components/auth-card"
|
|
4
4
|
import { Button } from "@/components/ui/button"
|
|
5
5
|
import { Input } from "@/components/ui/input"
|
|
@@ -28,7 +28,7 @@ function Onboarding() {
|
|
|
28
28
|
const [error, setError] = useState<string | null>(null)
|
|
29
29
|
const [pending, setPending] = useState(false)
|
|
30
30
|
|
|
31
|
-
async function onSubmit(event:
|
|
31
|
+
async function onSubmit(event: SubmitEvent<HTMLFormElement>) {
|
|
32
32
|
event.preventDefault()
|
|
33
33
|
const name = formField(new FormData(event.currentTarget), "name").trim()
|
|
34
34
|
setPending(true)
|
|
@@ -47,7 +47,7 @@ function Onboarding() {
|
|
|
47
47
|
title="Create your organization"
|
|
48
48
|
description="Organizations hold your members and your data. You can create more later."
|
|
49
49
|
>
|
|
50
|
-
<form method="post" onSubmit={onSubmit} className="space-y-4">
|
|
50
|
+
<form method="post" onSubmit={(event) => void onSubmit(event)} className="space-y-4">
|
|
51
51
|
<div className="space-y-2">
|
|
52
52
|
<Label htmlFor="name">Organization name</Label>
|
|
53
53
|
<Input id="name" name="name" placeholder="Acme Inc." required />
|
|
@@ -19,10 +19,22 @@ Rules for AI agents (and humans) working in this repo. Read this before changing
|
|
|
19
19
|
- Failures are tagged errors (`Data.TaggedError`) in the error channel, handled with `Effect.catchTag`.
|
|
20
20
|
- Validate data at boundaries (requests, env, storage, third-party responses) with `Schema`.
|
|
21
21
|
- Reach Cloudflare bindings (R2, D1, KV, Durable Objects, ...) only through `effect-cf`.
|
|
22
|
+
`apps/web/src/server/cloudflare.ts` is the one file that imports `env` from `cloudflare:workers`;
|
|
23
|
+
lint rejects it anywhere else.
|
|
22
24
|
- Never wrap an Effect in `try/catch`, and never use `async`/`await` inside `Effect.gen`; use `yield*`.
|
|
23
25
|
- Provide layers at entry points only (`runtime.ts`, scripts), not inside library code.
|
|
24
26
|
- No `any`. Use `unknown` and narrow it with `Schema` or a type guard.
|
|
25
27
|
- Keep `E` types specific; `unknown` or `any` in an error channel is a lint error.
|
|
28
|
+
- Model a multi-step lifecycle (order, invite, job) as a tagged union of states
|
|
29
|
+
(`Data.TaggedEnum`) and match on it, not as a set of boolean flags.
|
|
30
|
+
|
|
31
|
+
## Tests
|
|
32
|
+
|
|
33
|
+
- Write Effect tests with `it.effect` and `it.layer` from `@effect/vitest`. `Effect.run*` and
|
|
34
|
+
`ManagedRuntime.make` in a test file are lint errors (`lint/effect-tests.js`).
|
|
35
|
+
- Swap services with test layers; do not mock modules.
|
|
36
|
+
- Where a fake would behave differently from the platform (D1, R2, Durable Objects, Workflows),
|
|
37
|
+
check the behaviour under `pnpm dev` too: it runs your Worker in workerd with local bindings.
|
|
26
38
|
|
|
27
39
|
## UI
|
|
28
40
|
|
|
@@ -9,6 +9,10 @@ pnpm install
|
|
|
9
9
|
pnpm dev # http://localhost:5173 (or the port Vite prints)
|
|
10
10
|
```
|
|
11
11
|
|
|
12
|
+
With a database, set it up before the first `pnpm dev`: for Postgres, `docker compose up -d --wait`, then `pnpm db:migrate` (Postgres and D1). Anything that queries it, sign-up included, fails until the tables exist. `AGENTS.md` describes the database workflow for this stack.
|
|
13
|
+
|
|
14
|
+
Local secrets live in `.dev.vars` (in `.env` with Alchemy); `.env.example` lists the variables each add-on needs.
|
|
15
|
+
|
|
12
16
|
## Scripts
|
|
13
17
|
|
|
14
18
|
| Command | What it does |
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// Effect tests run through @effect/vitest (`it.effect`, `it.layer`), which supplies the test
|
|
2
|
+
// services and reports failures with their full cause. Running an Effect by hand skips both.
|
|
3
|
+
const runners = new Set([
|
|
4
|
+
"runCallback",
|
|
5
|
+
"runFork",
|
|
6
|
+
"runPromise",
|
|
7
|
+
"runPromiseExit",
|
|
8
|
+
"runSync",
|
|
9
|
+
"runSyncExit",
|
|
10
|
+
])
|
|
11
|
+
|
|
12
|
+
const manualRunner = (callee) => {
|
|
13
|
+
if (callee.type !== "MemberExpression" || callee.object.type !== "Identifier") return undefined
|
|
14
|
+
if (callee.property.type !== "Identifier") return undefined
|
|
15
|
+
const object = callee.object.name
|
|
16
|
+
const method = callee.property.name
|
|
17
|
+
if (object === "Effect" && runners.has(method)) return `Effect.${method}`
|
|
18
|
+
if (object === "ManagedRuntime" && method === "make") return "ManagedRuntime.make"
|
|
19
|
+
return undefined
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export default {
|
|
23
|
+
meta: { name: "effect-tests" },
|
|
24
|
+
rules: {
|
|
25
|
+
"no-manual-runtime": {
|
|
26
|
+
meta: {
|
|
27
|
+
type: "problem",
|
|
28
|
+
docs: {
|
|
29
|
+
description: "Run Effects in tests with it.effect or it.layer from @effect/vitest",
|
|
30
|
+
},
|
|
31
|
+
messages: {
|
|
32
|
+
manual: "{{name}} in a test: use it.effect or it.layer from @effect/vitest instead.",
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
create(context) {
|
|
36
|
+
return {
|
|
37
|
+
CallExpression(node) {
|
|
38
|
+
const name = manualRunner(node.callee)
|
|
39
|
+
if (name !== undefined) context.report({ node, messageId: "manual", data: { name } })
|
|
40
|
+
},
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
}
|