create-actuate 0.1.2 → 0.3.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 CHANGED
@@ -13,6 +13,8 @@ Templates come from [actuate-run/templates](https://github.com/actuate-run/templ
13
13
  cd my-tool && npm install && npx actuate dev
14
14
  ```
15
15
 
16
+ The hello starter comes with `actuator.test.ts` (run it with `npx actuate test`; it uses `node:test` and `@actuate/cli/testing`, nothing else to install) and an `AGENTS.md` that tells coding agents how to check an actuator before it's deployed. A template that ships its own `actuator.test.ts` gets it too.
17
+
16
18
  [Quickstart](https://actuate.run/docs/getting-started/quickstart/)
17
19
 
18
20
  ---
package/dist/bin.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  scaffold
4
- } from "./chunk-OPZ7TO7T.js";
4
+ } from "./chunk-YL5ZWOZQ.js";
5
5
 
6
6
  // src/bin.ts
7
7
  import { relative } from "path";
@@ -20,11 +20,16 @@ try {
20
20
  ...values.template ? { template: values.template } : {},
21
21
  ...values.ref ? { ref: values.ref } : {}
22
22
  });
23
+ const cd = relative(process.cwd(), dir);
23
24
  console.log(`
24
25
  Next:
25
- cd ${relative(process.cwd(), dir) || "."}
26
- npm install
27
- npx actuate dev
26
+ ${cd ? ` cd ${cd}
27
+ ` : ""} npm install
28
+ npx actuate dev run it locally, with the platform's guards
29
+ npx actuate test run its tests
30
+ npx actuate doctor check Node, providers and login
31
+
32
+ Docs: https://actuate.run/docs/getting-started/quickstart/
28
33
  `);
29
34
  } catch (err) {
30
35
  console.error(err instanceof Error ? err.message : err);
@@ -42,14 +42,63 @@ export default defineActuator({
42
42
  },
43
43
  });
44
44
  `;
45
+ var HELLO_TEST = `import { test } from "node:test";
46
+ import assert from "node:assert/strict";
47
+ import { testActuator } from "@actuate/cli/testing";
48
+ import actuator from "./actuator.js";
49
+
50
+ test("greets, sleeps, then follows up", async () => {
51
+ const t = testActuator(actuator);
52
+ const run = await t.start({ name: "Aina" });
53
+ assert.equal(run.status, "WAITING"); // asleep until the follow-up
54
+
55
+ await t.advance("10 seconds"); // the test clock: no real waiting
56
+ assert.equal(t.run(run.runId).status, "COMPLETED");
57
+ assert.deepEqual(t.rows("greetings").map((r) => r.name), ["Aina"]);
58
+ assert.deepEqual(t.logs(run.runId).map((l) => l.message), ["Hello, Aina!", "Still there, Aina?"]);
59
+ // A budget: fails if a change makes this run cost more passes or rows.
60
+ assert.deepEqual(t.usage(run.runId).passes, 2);
61
+ assert.ok(t.usage(run.runId).rowsWritten <= 20);
62
+ });
63
+
64
+ test("refuses an empty name before any code runs", async () => {
65
+ const t = testActuator(actuator);
66
+ await assert.rejects(t.start({ name: "" }), /name/);
67
+ });
68
+ `;
69
+ var AGENTS_MD = `# Working on this actuator
70
+
71
+ This is an [Actuate](https://actuate.run) actuator: \`actuator.ts\` exports \`defineActuator({ ... })\`.
72
+ \`run\` is replayed from the top after every sleep, wait and retry, so every side effect
73
+ (provider calls, fetch, database writes, Date.now(), Math.random()) goes inside \`ctx.step.do\`.
74
+
75
+ Before you call a change done:
76
+
77
+ 1. \`npx actuate check --platform\`: replay safety, plus the hosted platform's deploy checks.
78
+ 2. \`npx actuate test\`: the tests (\`*.test.ts\`, written with \`@actuate/cli/testing\`). Add one
79
+ for each behaviour you change; pin passes and rows written with \`t.usage(runId)\`.
80
+ 3. \`npx actuate dev\`, then \`npx actuate run '{...}' --local\` and \`npx actuate logs <runId> --local\`
81
+ to try it by hand. Local runs get the platform's guards and show rows read and written.
82
+ 4. \`npx actuate deploy --dry-run\`, and only then \`npx actuate deploy\`: every deploy attempt
83
+ counts against the monthly deploy budget, failed ones included.
84
+
85
+ \`npx actuate <command> --help\` explains each command; \`--json\` gives machine-readable output.
86
+ Guide: https://actuate.run/docs/guides/best-practices/
87
+ `;
45
88
  function scaffoldFiles(name, actuatorSource, extra = {}) {
46
89
  const pkg = {
47
90
  name,
48
91
  private: true,
49
92
  type: "module",
50
- scripts: { dev: "actuate dev", check: "actuate check", deploy: "actuate deploy", typecheck: "tsc --noEmit" },
93
+ scripts: {
94
+ dev: "actuate dev",
95
+ test: "actuate test",
96
+ check: "actuate check --platform",
97
+ deploy: "actuate deploy",
98
+ typecheck: "tsc --noEmit"
99
+ },
51
100
  dependencies: { "@actuate/sdk": SDK_VERSION },
52
- devDependencies: { "@actuate/cli": SDK_VERSION, typescript: "^5.9.3" }
101
+ devDependencies: { "@actuate/cli": SDK_VERSION, "@types/node": "^22.10.0", typescript: "^5.9.3" }
53
102
  };
54
103
  return {
55
104
  "package.json": JSON.stringify(pkg, null, 2) + "\n",
@@ -71,19 +120,23 @@ function scaffoldFiles(name, actuatorSource, extra = {}) {
71
120
  ) + "\n",
72
121
  ".gitignore": "node_modules/\n.actuate/\n.dev.vars\n.env\n",
73
122
  "actuate.config.json": "{}\n",
123
+ "AGENTS.md": AGENTS_MD,
74
124
  "actuator.ts": actuatorSource,
75
125
  ...extra
76
126
  };
77
127
  }
78
128
  async function fetchTemplate(template, ref, doFetch) {
79
129
  if (!/^[a-z0-9][a-z0-9-]*$/.test(template)) throw new Error(`Invalid template name "${template}"`);
130
+ if (!/^[A-Za-z0-9][A-Za-z0-9._/-]*$/.test(ref) || ref.split("/").some((part) => part === "." || part === "..")) {
131
+ throw new Error(`Invalid git ref "${ref}"`);
132
+ }
80
133
  const raw = (file) => `https://raw.githubusercontent.com/${TEMPLATES_REPO}/${ref}/${template}/${file}`;
81
134
  const res = await doFetch(raw("actuator.ts"));
82
135
  if (!res.ok) {
83
136
  throw new Error(`Template "${template}" not found in ${TEMPLATES_REPO}@${ref} (HTTP ${res.status}). Templates: https://github.com/${TEMPLATES_REPO}`);
84
137
  }
85
138
  const files = { "actuator.ts": await res.text() };
86
- for (const optional of ["README.md", ".env.example", "actuate.config.json"]) {
139
+ for (const optional of ["README.md", ".env.example", "actuate.config.json", "actuator.test.ts"]) {
87
140
  const r = await doFetch(raw(optional));
88
141
  if (r.ok) files[optional] = await r.text();
89
142
  }
@@ -98,7 +151,7 @@ async function scaffold(options) {
98
151
  const template = options.template ?? "hello";
99
152
  let files;
100
153
  if (template === "hello") {
101
- files = scaffoldFiles(basename(dir), HELLO_ACTUATOR);
154
+ files = scaffoldFiles(basename(dir), HELLO_ACTUATOR, { "actuator.test.ts": HELLO_TEST });
102
155
  } else {
103
156
  const fetched = await fetchTemplate(template, options.ref ?? "main", options.fetch ?? fetch);
104
157
  const { "actuator.ts": source, ...rest } = fetched;
@@ -114,6 +167,8 @@ export {
114
167
  TEMPLATES_REPO,
115
168
  SDK_VERSION,
116
169
  HELLO_ACTUATOR,
170
+ HELLO_TEST,
171
+ AGENTS_MD,
117
172
  scaffoldFiles,
118
173
  scaffold
119
174
  };
package/dist/index.d.ts CHANGED
@@ -14,8 +14,12 @@ interface ScaffoldOptions {
14
14
  log?: (line: string) => void;
15
15
  }
16
16
  declare const HELLO_ACTUATOR = "import { defineActuator, z } from \"@actuate/sdk\";\n\nexport const ConfigSchema = z.object({\n greeting: z.string().default(\"Hello\"),\n followUpAfter: z.enum([\"10 seconds\", \"1 hour\", \"1 day\"]).default(\"10 seconds\"),\n});\n\nexport const InputSchema = z.object({\n name: z.string().min(1).describe(\"Who to greet\"),\n});\n\nexport default defineActuator({\n name: \"hello\",\n description: \"Greets someone, waits, then follows up. A starting point for your own actuator.\",\n config: ConfigSchema,\n input: InputSchema,\n // For MCP clients: this tool adds a row and sends nothing outside, so it isn't destructive.\n hints: { destructive: false, openWorld: false },\n async run(ctx, input, config) {\n await ctx.db.migrate([\n \"CREATE TABLE greetings (run_id TEXT PRIMARY KEY, name TEXT NOT NULL, greeted_at TEXT NOT NULL)\",\n ]);\n\n const greetedAt = await ctx.step.do(\"greet\", async () => {\n const at = new Date().toISOString();\n await ctx.db.sql`INSERT INTO greetings (run_id, name, greeted_at) VALUES (${ctx.runId}, ${input.name}, ${at})`;\n ctx.log.info(`${config.greeting}, ${input.name}!`);\n return at;\n });\n\n // The run hibernates here. Nothing runs, and nothing is billed, until it wakes.\n await ctx.step.sleep(config.followUpAfter);\n\n await ctx.step.do(\"follow-up\", () => ctx.log.info(`Still there, ${input.name}?`));\n return { greetedAt };\n },\n});\n";
17
+ /** The hello starter's test: `actuate test` runs it with node:test, no other dependency needed. */
18
+ declare const HELLO_TEST = "import { test } from \"node:test\";\nimport assert from \"node:assert/strict\";\nimport { testActuator } from \"@actuate/cli/testing\";\nimport actuator from \"./actuator.js\";\n\ntest(\"greets, sleeps, then follows up\", async () => {\n const t = testActuator(actuator);\n const run = await t.start({ name: \"Aina\" });\n assert.equal(run.status, \"WAITING\"); // asleep until the follow-up\n\n await t.advance(\"10 seconds\"); // the test clock: no real waiting\n assert.equal(t.run(run.runId).status, \"COMPLETED\");\n assert.deepEqual(t.rows(\"greetings\").map((r) => r.name), [\"Aina\"]);\n assert.deepEqual(t.logs(run.runId).map((l) => l.message), [\"Hello, Aina!\", \"Still there, Aina?\"]);\n // A budget: fails if a change makes this run cost more passes or rows.\n assert.deepEqual(t.usage(run.runId).passes, 2);\n assert.ok(t.usage(run.runId).rowsWritten <= 20);\n});\n\ntest(\"refuses an empty name before any code runs\", async () => {\n const t = testActuator(actuator);\n await assert.rejects(t.start({ name: \"\" }), /name/);\n});\n";
19
+ /** For coding agents (and people): the commands that check an actuator before it is deployed. */
20
+ declare const AGENTS_MD = "# Working on this actuator\n\nThis is an [Actuate](https://actuate.run) actuator: `actuator.ts` exports `defineActuator({ ... })`.\n`run` is replayed from the top after every sleep, wait and retry, so every side effect\n(provider calls, fetch, database writes, Date.now(), Math.random()) goes inside `ctx.step.do`.\n\nBefore you call a change done:\n\n1. `npx actuate check --platform`: replay safety, plus the hosted platform's deploy checks.\n2. `npx actuate test`: the tests (`*.test.ts`, written with `@actuate/cli/testing`). Add one\n for each behaviour you change; pin passes and rows written with `t.usage(runId)`.\n3. `npx actuate dev`, then `npx actuate run '{...}' --local` and `npx actuate logs <runId> --local`\n to try it by hand. Local runs get the platform's guards and show rows read and written.\n4. `npx actuate deploy --dry-run`, and only then `npx actuate deploy`: every deploy attempt\n counts against the monthly deploy budget, failed ones included.\n\n`npx actuate <command> --help` explains each command; `--json` gives machine-readable output.\nGuide: https://actuate.run/docs/guides/best-practices/\n";
17
21
  declare function scaffoldFiles(name: string, actuatorSource: string, extra?: Record<string, string>): Record<string, string>;
18
22
  /** Create a new actuator project. Returns the absolute directory. */
19
23
  declare function scaffold(options: ScaffoldOptions): Promise<string>;
20
24
 
21
- export { HELLO_ACTUATOR, SDK_VERSION, type ScaffoldOptions, TEMPLATES_REPO, scaffold, scaffoldFiles };
25
+ export { AGENTS_MD, HELLO_ACTUATOR, HELLO_TEST, SDK_VERSION, type ScaffoldOptions, TEMPLATES_REPO, scaffold, scaffoldFiles };
package/dist/index.js CHANGED
@@ -1,12 +1,16 @@
1
1
  import {
2
+ AGENTS_MD,
2
3
  HELLO_ACTUATOR,
4
+ HELLO_TEST,
3
5
  SDK_VERSION,
4
6
  TEMPLATES_REPO,
5
7
  scaffold,
6
8
  scaffoldFiles
7
- } from "./chunk-OPZ7TO7T.js";
9
+ } from "./chunk-YL5ZWOZQ.js";
8
10
  export {
11
+ AGENTS_MD,
9
12
  HELLO_ACTUATOR,
13
+ HELLO_TEST,
10
14
  SDK_VERSION,
11
15
  TEMPLATES_REPO,
12
16
  scaffold,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-actuate",
3
- "version": "0.1.2",
3
+ "version": "0.3.0",
4
4
  "description": "Scaffold an Actuate actuator: npm create actuate [dir] -- --template <name>",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",