@effected/engine 0.18.2 → 0.20.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.
@@ -1,8 +1,8 @@
1
- import { NotAPackageError } from "./BuildRun.js";
2
- import { ErrorText, PathContainment } from "@effected/kit";
3
- import { Effect, FileSystem, Path, Predicate, Result, Schema } from "effect";
4
1
  import { EffectedConfigSchema } from "@effected/bundler";
5
2
  import { AtomicFile } from "@effected/files";
3
+ import { ErrorText, PathContainment } from "@effected/kit";
4
+ import { Effect, FileSystem, Path, Predicate, Result, Schema } from "effect";
5
+ import { NotAPackageError } from "./BuildRun.js";
6
6
 
7
7
  // src/build/ActionInit.ts
8
8
  /**
@@ -167,18 +167,26 @@ const DEV_DEPENDENCIES = [
167
167
  const isControl = (code) => code < 32 && code !== 9 || code >= 127 && code <= 159;
168
168
  const codePoint = (character) => `U+${(character.codePointAt(0) ?? 0).toString(16).toUpperCase().padStart(4, "0")}`;
169
169
  const yamlString = (value) => JSON.stringify(value).replace(/[\u007F-\u009F\u2028\u2029]/g, (character) => `\\u${codePoint(character).slice(2)}`);
170
- const effectedToml = `${EffectedConfigSchema.directive}
170
+ const tomlHead = `${EffectedConfigSchema.directive}
171
171
 
172
172
  # \`effected action build\` reads the [action] tables. A key left out takes its default.
173
173
 
174
174
  [action.entries]
175
175
  main = "src/main.ts"
176
-
176
+ `;
177
+ const effectedToml = `${tomlHead}
177
178
  # Copies each build to .github/actions/local, the target act and CI smoke-test.
178
179
  [action.persistLocal]
179
180
  enabled = true
180
181
  path = ".github/actions/local"
181
182
  `;
183
+ const localEffectedToml = `${tomlHead}
184
+ # Persists each build to .github/actions/<package directory name> at the workspace root and keeps no package dist.
185
+ [action.persistLocal]
186
+ base = "workspace"
187
+ dist = false
188
+ `;
189
+ const localGitignore = "dist/\n.action-staging/\n";
182
190
  const actionYml = (input) => `# The single source of the action's input and output names and their defaults: code mirrors them.
183
191
  name: ${yamlString(input.name)}
184
192
  description: ${yamlString(input.description)}
@@ -276,7 +284,7 @@ var ActionInit = class ActionInit {
276
284
  files: [
277
285
  ActionScaffoldFile.make({
278
286
  path: "effected.toml",
279
- contents: effectedToml
287
+ contents: input.local === true ? localEffectedToml : effectedToml
280
288
  }),
281
289
  ActionScaffoldFile.make({
282
290
  path: "action.yml",
@@ -293,7 +301,11 @@ var ActionInit = class ActionInit {
293
301
  ActionScaffoldFile.make({
294
302
  path: "tsconfig.json",
295
303
  contents: tsconfigJson
296
- })
304
+ }),
305
+ ...input.local === true && input.gitignore !== false ? [ActionScaffoldFile.make({
306
+ path: ".gitignore",
307
+ contents: localGitignore
308
+ })] : []
297
309
  ],
298
310
  dependencies: DEPENDENCIES,
299
311
  devDependencies: DEV_DEPENDENCIES
@@ -436,15 +448,21 @@ var ActionInit = class ActionInit {
436
448
  * the packages to add.
437
449
  */
438
450
  static run = Effect.fn("ActionInit.run")(function* (input, deps) {
439
- const cwd = (yield* Path.Path).resolve(deps.cwd);
451
+ const path = yield* Path.Path;
452
+ const cwd = path.resolve(deps.cwd);
440
453
  const manifest = yield* readManifest(cwd);
441
454
  const name = blank(input.name) ? manifest.name : input.name;
442
455
  if (blank(name)) return yield* new ActionMetadataMissingError({ field: "name" });
443
456
  const description = blank(input.description) ? manifest.description : input.description;
444
457
  if (blank(description)) return yield* new ActionMetadataMissingError({ field: "description" });
458
+ const fs = yield* FileSystem.FileSystem;
459
+ const local = input.local === true;
460
+ const hasGitignore = local ? yield* fs.exists(path.join(cwd, ".gitignore")) : false;
445
461
  const scaffold = ActionInit.plan({
446
462
  name: yield* checked("name", name ?? ""),
447
- description: yield* checked("description", description ?? "")
463
+ description: yield* checked("description", description ?? ""),
464
+ local,
465
+ gitignore: !hasGitignore
448
466
  });
449
467
  const { written, overwritten } = yield* ActionInit.write(scaffold, {
450
468
  cwd,
@@ -1,8 +1,8 @@
1
- import { ActionRunResult } from "./ActionRunResult.js";
2
- import { readPackageName, workspaceRootOf } from "./BuildRun.js";
3
- import { Effect, Layer, Path, Schema } from "effect";
4
1
  import { ActionBuildResult, ActionBuilder, BuildResult, EffectedConfigFile } from "@effected/bundler";
5
2
  import { WorkspaceDiscovery, WorkspaceRoot } from "@effected/workspaces";
3
+ import { Effect, Layer, Path, Schema } from "effect";
4
+ import { ActionRunResult } from "./ActionRunResult.js";
5
+ import { readPackageName, workspaceRootOf } from "./BuildRun.js";
6
6
 
7
7
  // src/build/ActionRun.ts
8
8
  /**
@@ -27,7 +27,8 @@ const failedResult = (error) => ActionRunResult.make({
27
27
  entries: [],
28
28
  duration: 0
29
29
  }),
30
- persisted: false
30
+ persisted: false,
31
+ ...error._tag === "CheckFailed" ? { drift: error.drift } : {}
31
32
  })
32
33
  });
33
34
  /**
@@ -39,6 +40,10 @@ const failedResult = (error) => ActionRunResult.make({
39
40
  * not start or finish: no `package.json`, a config that will not load, no `[action]` table, an entry that is missing
40
41
  * with validation off, and a file that cannot be cleaned, written or persisted.
41
42
  *
43
+ * With `check`, it writes nothing and a check that finds drift is the verdict `failed` with `result.drift`; the error
44
+ * channel adds `CheckUnavailable` (nothing persisted to compare), `NoOutput` (`dist = false` with persisting off) and
45
+ * `PersistPathError` (a persist path the bundler refuses).
46
+ *
42
47
  * It appends to no journal: the build and issue journals record package builds only.
43
48
  *
44
49
  * @public
@@ -57,16 +62,19 @@ var ActionRun = class {
57
62
  if (config.action === void 0) return yield* new NotAnActionError({ cwd });
58
63
  return yield* ActionBuilder.build({
59
64
  cwd,
65
+ root,
60
66
  config: config.action,
61
67
  validate: input.validate,
62
68
  persist: input.persist,
63
- ci: deps.ci
69
+ ci: deps.ci,
70
+ check: input.check
64
71
  }).pipe(Effect.map((result) => ActionRunResult.make({
65
72
  verdict: "ok",
66
73
  result
67
74
  })), Effect.catchTags({
68
75
  ValidationFailed: (error) => Effect.succeed(failedResult(error)),
69
- BuildFailed: (error) => Effect.succeed(failedResult(error))
76
+ BuildFailed: (error) => Effect.succeed(failedResult(error)),
77
+ CheckFailed: (error) => Effect.succeed(failedResult(error))
70
78
  }));
71
79
  });
72
80
  };
@@ -1,5 +1,5 @@
1
- import { Schema } from "effect";
2
1
  import { ActionBuildResult } from "@effected/bundler";
2
+ import { Schema } from "effect";
3
3
 
4
4
  // src/build/ActionRunResult.ts
5
5
  /**
package/build/BuildRun.js CHANGED
@@ -1,9 +1,9 @@
1
- import { acquireBuildLock, buildLockPath } from "./BuildLock.js";
2
- import { BuildRunResult } from "./BuildRunResult.js";
3
- import { DateTime, Effect, FileSystem, Layer, Option, Path, PlatformError, Predicate, Schema } from "effect";
4
1
  import { BuildIssuesSchema, BuildJournal, Bundler, EffectedConfigError, EffectedConfigFile, IssueJournal, flattenIssues, loadPlugins } from "@effected/bundler";
5
2
  import { NodeJournalWatcher } from "@effected/jsonl/node";
6
3
  import { WorkspaceDiscovery, WorkspaceRoot } from "@effected/workspaces";
4
+ import { DateTime, Effect, FileSystem, Layer, Option, Path, PlatformError, Predicate, Schema } from "effect";
5
+ import { acquireBuildLock, buildLockPath } from "./BuildLock.js";
6
+ import { BuildRunResult } from "./BuildRunResult.js";
7
7
 
8
8
  // src/build/BuildRun.ts
9
9
  /**
@@ -1,5 +1,5 @@
1
- import { Schema } from "effect";
2
1
  import { BuildIssuesSchema, BuildReport, ResolvedEffectedConfig } from "@effected/bundler";
2
+ import { Schema } from "effect";
3
3
 
4
4
  // src/build/BuildRunResult.ts
5
5
  /**
@@ -0,0 +1,279 @@
1
+ import { EffectedConfigFile, PersistTarget } from "@effected/bundler";
2
+ import { WorkspaceDiscovery, WorkspaceRoot } from "@effected/workspaces";
3
+ import { Deferred, Effect, FiberMap, FileSystem, Layer, Option, Path, PlatformError, Queue, Semaphore, Stream } from "effect";
4
+ import { NotAnActionError } from "./ActionRun.js";
5
+ import { readPackageName, workspaceRootOf } from "./BuildRun.js";
6
+
7
+ // src/build/BuildWatch.ts
8
+ /**
9
+ * What every watched build ignores: package-relative paths a build writes, matched on `/` boundaries.
10
+ *
11
+ * @remarks
12
+ * An entry covers the path itself, everything under it, and the directories it lives in, so a build creating
13
+ * `.github/actions/local` triggers nothing with its `.github` and `.github/actions` directory events. A path that only
14
+ * shares a prefix (`distribution`), or a file beside an entry (`.github/workflows/ci.yml`), still triggers.
15
+ *
16
+ * @public
17
+ */
18
+ const DEFAULT_EXCLUDES = [
19
+ "dist",
20
+ "node_modules",
21
+ ".turbo",
22
+ ".git",
23
+ ".cache",
24
+ "tsdoc.json",
25
+ ".actrc",
26
+ ".github/workflows/act-test.yml",
27
+ ".github/actions/local",
28
+ ".action-staging"
29
+ ];
30
+ const CONFIG_NAME = "effected.toml";
31
+ /** Discovery from `cwd`, as `BuildRun` and `ActionRun` provide it to the root search and the config load. */
32
+ const discoveryFrom = (cwd) => WorkspaceDiscovery.layer({ cwd }).pipe(Layer.provide(WorkspaceRoot.layer));
33
+ /**
34
+ * Whether an exclusion covers `path`, on `/` boundaries: `path` is the excluded path, lies under it, or is a directory
35
+ * it lives in. A build creating `.github/actions/local` also creates `.github` and `.github/actions`, and those
36
+ * directory events are the build's own; a file under them that no exclusion names still triggers.
37
+ */
38
+ const isUnder = (path, prefix) => {
39
+ const trimmed = trimExclusion(prefix);
40
+ return isCovered(path, prefix) || trimmed !== "" && trimmed.startsWith(`${path}/`);
41
+ };
42
+ /**
43
+ * An `@effected/files` `AtomicFile` temp, `.effected-<base36>.tmp`, which an action persist leaves for a moment beside
44
+ * `.actrc` and `act-test.yml` before renaming it into place. Never a source, so never a trigger.
45
+ */
46
+ const ATOMIC_TEMP = /(^|\/)\.effected-[0-9a-z]+\.tmp$/;
47
+ const trimExclusion = (prefix) => prefix.replace(/^\.\//, "").replace(/\/+$/, "");
48
+ /** Whether `path` is an excluded path or lies under it, on `/` boundaries: a top-level directory never watched. */
49
+ const isCovered = (path, prefix) => {
50
+ const trimmed = trimExclusion(prefix);
51
+ return trimmed !== "" && (path === trimmed || path.startsWith(`${trimmed}/`));
52
+ };
53
+ /** The config as it is now, or `None` when it will not load; a watch's exclusions never fail. */
54
+ const loadConfig = (target) => EffectedConfigFile.load({
55
+ cwd: target.cwd,
56
+ root: target.root
57
+ }).pipe(Effect.provide(discoveryFrom(target.cwd)), Effect.option);
58
+ /**
59
+ * {@link DEFAULT_EXCLUDES} plus each of `paths` that resolves inside the package, package-relative with `/`. Outside
60
+ * the package no watched event can match one, and at the package itself it would exclude everything.
61
+ */
62
+ const withInside = (path, cwd, paths) => {
63
+ const added = [];
64
+ for (const entry of paths) {
65
+ const relative = path.relative(cwd, path.resolve(cwd, entry)).split(path.sep).join("/");
66
+ if (relative !== "" && relative !== ".." && !relative.startsWith("../") && !path.isAbsolute(relative) && !DEFAULT_EXCLUDES.includes(relative) && !added.includes(relative)) added.push(relative);
67
+ }
68
+ return added.length === 0 ? DEFAULT_EXCLUDES : [...DEFAULT_EXCLUDES, ...added];
69
+ };
70
+ /**
71
+ * Rebuild on change.
72
+ *
73
+ * @public
74
+ */
75
+ var BuildWatch = class {
76
+ /**
77
+ * Resolves what a watch covers, refusing a directory that cannot be built at all: no `package.json`, a workspace
78
+ * root that cannot be discovered, or, for an action, a config that loads with no `[action]` table. A config that
79
+ * will not load is not refused, because it is an edit the watch must survive.
80
+ */
81
+ static target = (cwd, kind) => Effect.gen(function* () {
82
+ const resolved = (yield* Path.Path).resolve(cwd);
83
+ yield* readPackageName(resolved);
84
+ const discovery = discoveryFrom(resolved);
85
+ const root = yield* workspaceRootOf(resolved).pipe(Effect.provide(discovery));
86
+ if (kind === "action") {
87
+ const loaded = yield* EffectedConfigFile.load({
88
+ cwd: resolved,
89
+ root
90
+ }).pipe(Effect.provide(discovery), Effect.option);
91
+ if (Option.isSome(loaded) && loaded.value.config.action === void 0) return yield* new NotAnActionError({ cwd: resolved });
92
+ }
93
+ return {
94
+ cwd: resolved,
95
+ root
96
+ };
97
+ });
98
+ /**
99
+ * A package's exclusions: {@link DEFAULT_EXCLUDES} plus each `[package.build.meta] localPaths` directory inside the
100
+ * package, package-relative, read from the config as it is now. Every build copies the API model into each one, so
101
+ * without them the watch would rebuild itself. Any config that will not load, or `meta = false`, gives the defaults.
102
+ */
103
+ static packageExcludes = (target) => Effect.gen(function* () {
104
+ const path = yield* Path.Path;
105
+ const loaded = yield* loadConfig(target);
106
+ const meta = Option.isSome(loaded) ? loaded.value.config.package.build.meta : false;
107
+ return withInside(path, target.cwd, meta === false ? [] : meta.localPaths);
108
+ });
109
+ /**
110
+ * An action's exclusions: {@link DEFAULT_EXCLUDES} plus its enabled `persistLocal.path`, package-relative, read
111
+ * from the config as it is now. `persist: false`, the `--no-persist` build that writes nothing there, leaves that
112
+ * path watched. Any config that will not load, or has no `[action]` table, gives the defaults.
113
+ */
114
+ static actionExcludes = (target, options) => Effect.gen(function* () {
115
+ if (options?.persist === false) return DEFAULT_EXCLUDES;
116
+ const path = yield* Path.Path;
117
+ const loaded = yield* loadConfig(target);
118
+ if (Option.isNone(loaded) || loaded.value.config.action === void 0) return DEFAULT_EXCLUDES;
119
+ const resolved = yield* PersistTarget.resolve(loaded.value.config.action, {
120
+ cwd: target.cwd,
121
+ root: target.root
122
+ }).pipe(Effect.option);
123
+ if (Option.isNone(resolved) || !resolved.value.enabled) return DEFAULT_EXCLUDES;
124
+ const realCwd = yield* (yield* FileSystem.FileSystem).realPath(target.cwd).pipe(Effect.orElseSucceed(() => target.cwd));
125
+ return withInside(path, realCwd, [resolved.value.outputPath]);
126
+ });
127
+ /**
128
+ * Builds once with `Initial` after every watcher is installed, then once per settled batch of changes, for as long
129
+ * as it runs. Fails with a watcher's `PlatformError`, or when a watcher stops; `build`'s errors propagate.
130
+ *
131
+ * @remarks
132
+ * The package directory is watched non-recursively, and each of its top-level directories that no exclusion covers
133
+ * gets a recursive watch of its own, so an excluded `node_modules`, `.git` or `dist` is never walked. A directory
134
+ * that is only where an exclusion lives, such as `.github`, is watched, and its events are filtered. The set follows
135
+ * the package: a new top-level directory is watched from its first event, a removed one's watch is dropped, and the
136
+ * exclusions are re-read after each batch. `<root>/.config` is watched while it exists, including one created after
137
+ * the watch starts. A watch stopping fails the run, except that a top-level directory's or `<root>/.config`'s watch
138
+ * ending once the directory is gone is that directory going away.
139
+ */
140
+ static run = (options) => Effect.scoped(Effect.gen(function* () {
141
+ const fs = yield* FileSystem.FileSystem;
142
+ const path = yield* Path.Path;
143
+ const cwd = path.resolve(options.cwd);
144
+ const root = path.resolve(options.root);
145
+ const debounce = options.debounce ?? "100 millis";
146
+ const toRelative = (absolute) => path.relative(cwd, absolute).split(path.sep).join("/");
147
+ const absoluteIn = (dir, eventPath) => path.resolve(dir, eventPath);
148
+ const inPackage = (absolute) => {
149
+ const relative = toRelative(absolute);
150
+ return relative === "" || relative === ".." || relative.startsWith("../") ? void 0 : relative;
151
+ };
152
+ const configDir = path.join(root, ".config");
153
+ /** The root-tier `effected.toml` directly in `dir`, as a batch entry, or nothing. */
154
+ const configIn = (dir) => (absolute) => path.dirname(absolute) === dir && path.basename(absolute) === CONFIG_NAME ? toRelative(absolute) : void 0;
155
+ const fixed = [{
156
+ dir: cwd,
157
+ accept: inPackage,
158
+ topLevel: true
159
+ }];
160
+ const rootTier = root !== cwd && (yield* fs.exists(root));
161
+ if (rootTier) fixed.push({
162
+ dir: root,
163
+ topLevel: false,
164
+ accept: configIn(root)
165
+ });
166
+ const pending = yield* Queue.unbounded();
167
+ const offer = (entry) => entry === void 0 ? Effect.void : Queue.offer(pending, entry);
168
+ const stopped = (dir) => PlatformError.systemError({
169
+ _tag: "Unknown",
170
+ module: "FileSystem",
171
+ method: "watch",
172
+ pathOrDescriptor: dir,
173
+ description: "The watcher stopped."
174
+ });
175
+ const directoryAt = (dir) => Effect.map(Effect.option(fs.stat(dir)), Option.filter((info) => info.type === "Directory"));
176
+ const watchWhilePresent = (dir, recursive, accept) => {
177
+ const ready = Deferred.makeUnsafe();
178
+ return {
179
+ ready,
180
+ watching: Effect.flatMap(directoryAt(dir), (armedOn) => {
181
+ const armedIno = Option.flatMap(armedOn, (info) => info.ino);
182
+ const unlessGone = (error) => Effect.flatMap(directoryAt(dir), (now) => {
183
+ const nowIno = Option.flatMap(now, (info) => info.ino);
184
+ return Option.isSome(now) && (Option.isNone(armedIno) || Option.isNone(nowIno) || armedIno.value === nowIno.value) ? Effect.fail(error) : Effect.void;
185
+ });
186
+ return fs.watch(dir, {
187
+ recursive,
188
+ onReady: () => {
189
+ Deferred.doneUnsafe(ready, Effect.void);
190
+ }
191
+ }).pipe(Stream.runForEach((event) => offer(accept(absoluteIn(dir, event.path)))), Effect.matchEffect({
192
+ onFailure: unlessGone,
193
+ onSuccess: () => unlessGone(stopped(dir))
194
+ }));
195
+ }).pipe(Effect.ensuring(Effect.sync(() => Deferred.doneUnsafe(ready, Effect.void))))
196
+ };
197
+ };
198
+ const directories = yield* FiberMap.make();
199
+ const arm = (name) => {
200
+ const { ready, watching } = watchWhilePresent(path.join(cwd, name), true, inPackage);
201
+ return Effect.as(FiberMap.run(directories, name, watching, { onlyIfMissing: true }), ready);
202
+ };
203
+ const configWatch = yield* FiberMap.make();
204
+ const configPermit = yield* Semaphore.make(1);
205
+ const claimConfig = Effect.gen(function* () {
206
+ if (!rootTier || (yield* FiberMap.has(configWatch, "config")) || !(yield* fs.exists(configDir))) return Option.none();
207
+ const { ready, watching } = watchWhilePresent(configDir, false, configIn(configDir));
208
+ yield* FiberMap.run(configWatch, "config", watching, { onlyIfMissing: true });
209
+ return Option.some(ready);
210
+ });
211
+ const armConfig = Semaphore.withPermit(configPermit, claimConfig);
212
+ const configEvent = Effect.gen(function* () {
213
+ const armed = yield* Semaphore.withPermit(configPermit, Effect.andThen(FiberMap.remove(configWatch, "config"), claimConfig));
214
+ if (Option.isSome(armed)) yield* Deferred.await(armed.value);
215
+ yield* offer(toRelative(path.join(configDir, CONFIG_NAME)));
216
+ });
217
+ const permit = yield* Semaphore.make(1);
218
+ const reconcile = Semaphore.withPermit(permit, Effect.gen(function* () {
219
+ const excludes = yield* options.exclude;
220
+ const wanted = /* @__PURE__ */ new Set();
221
+ for (const name of yield* fs.readDirectory(cwd)) {
222
+ if (excludes.some((prefix) => isCovered(name, prefix))) continue;
223
+ const info = yield* Effect.option(fs.stat(path.join(cwd, name)));
224
+ if (Option.isSome(info) && info.value.type === "Directory") wanted.add(name);
225
+ }
226
+ for (const [name] of [...directories]) if (!wanted.has(name)) yield* FiberMap.remove(directories, name);
227
+ const armed = [];
228
+ for (const name of wanted) if (!(yield* FiberMap.has(directories, name))) armed.push(yield* arm(name));
229
+ return armed;
230
+ }));
231
+ const fixedReady = fixed.map(() => Deferred.makeUnsafe());
232
+ const watching = Stream.mergeAll(fixed.map((target, index) => fs.watch(target.dir, { onReady: () => {
233
+ Deferred.doneUnsafe(fixedReady[index], Effect.void);
234
+ } }).pipe(Stream.map((event) => ({
235
+ target,
236
+ absolute: absoluteIn(target.dir, event.path)
237
+ })), Stream.concat(Stream.fail(stopped(target.dir))))), { concurrency: "unbounded" }).pipe(Stream.runForEach(({ target, absolute }) => {
238
+ const entry = target.accept(absolute);
239
+ if (target.topLevel) return entry === void 0 ? Effect.void : Effect.andThen(reconcile, offer(entry));
240
+ return absolute === configDir ? configEvent : offer(entry);
241
+ }), Effect.andThen(Effect.never));
242
+ const nextBatch = Effect.gen(function* () {
243
+ const batch = new Set(yield* Queue.takeAll(pending));
244
+ while (true) {
245
+ const more = yield* Effect.timeoutOption(Queue.takeAll(pending), debounce);
246
+ if (Option.isNone(more)) break;
247
+ for (const entry of more.value) batch.add(entry);
248
+ }
249
+ const excludes = yield* options.exclude;
250
+ return [...batch].filter((entry) => !ATOMIC_TEMP.test(entry) && !excludes.some((prefix) => isUnder(entry, prefix))).sort();
251
+ });
252
+ const consuming = Effect.gen(function* () {
253
+ const armed = yield* reconcile;
254
+ const config = yield* armConfig;
255
+ yield* Effect.forEach([
256
+ ...fixedReady,
257
+ ...armed,
258
+ ...Option.toArray(config)
259
+ ], Deferred.await, { discard: true });
260
+ yield* options.build({ _tag: "Initial" });
261
+ while (true) {
262
+ const paths = yield* nextBatch;
263
+ yield* reconcile;
264
+ if (paths.length > 0) yield* options.build({
265
+ _tag: "Changed",
266
+ paths
267
+ });
268
+ }
269
+ });
270
+ return yield* Effect.raceAllFirst([
271
+ watching,
272
+ consuming,
273
+ Effect.andThen(FiberMap.join(directories), Effect.never),
274
+ Effect.andThen(FiberMap.join(configWatch), Effect.never)
275
+ ]);
276
+ }));
277
+ };
278
+
279
+ export { BuildWatch, DEFAULT_EXCLUDES };
package/build.d.ts CHANGED
@@ -3,8 +3,8 @@
3
3
  *
4
4
  * @packageDocumentation
5
5
  */
6
- import { ActionBuildResult, ActionBuildResult as ActionBuildResult$1, ActionValidation, ActionYmlPathError, BuildIssues, BuildIssues as BuildIssues$1, BuildReport, BuildReport as BuildReport$1, BuildResult, BundleFailed, BundleResult, BundlerSeams, CleanError, ConfigValidationError, EffectedConfigError, PassReport, PersistLocalError, PluginLoadError, ResolvedEffectedConfig, ValidationIssue, ValidationResult, WriteError, renderCiAnnotations } from "@effected/bundler";
7
6
  import { Duration, Effect, FileSystem, Layer, Option, Path, PlatformError, Schema } from "effect";
7
+ import { ActionBuildResult, ActionBuildResult as ActionBuildResult$1, ActionValidation, ActionYmlPathError, BuildIssues, BuildIssues as BuildIssues$1, BuildReport, BuildReport as BuildReport$1, BuildResult, BundleFailed, BundleResult, BundlerSeams, CheckUnavailable, CleanError, ConfigValidationError, EffectedConfigError, NoOutput, PassReport, PersistLocalError, PersistPathError, PluginLoadError, ResolvedEffectedConfig, ValidationIssue, ValidationResult, WriteError, renderCiAnnotations } from "@effected/bundler";
8
8
  import { AppendError, JournalWatcher } from "@effected/jsonl";
9
9
  declare const BuildLockHolder_base: Schema.Class<BuildLockHolder, Schema.Struct<{
10
10
  /** The holding process. */
@@ -356,6 +356,10 @@ interface ActionScaffoldInput {
356
356
  readonly name: string;
357
357
  /** What the action does, one line. */
358
358
  readonly description: string;
359
+ /** Persist to the workspace root's `.github/actions/<name>` and keep no package `dist`. Omitted, false. */
360
+ readonly local?: boolean;
361
+ /** With `local`, whether to scaffold a `.gitignore` for `dist/` and `.action-staging/`. Omitted, true. */
362
+ readonly gitignore?: boolean;
359
363
  }
360
364
  /**
361
365
  * What one `action init` was asked to do, as the flags or tool parameters said it. A name or description left out is
@@ -368,6 +372,8 @@ interface ActionInitInput {
368
372
  readonly description?: string;
369
373
  /** Replace files that already exist. */
370
374
  readonly force: boolean;
375
+ /** Scaffold the local-only shape: persist to the workspace root and keep no package `dist`. Omitted, false. */
376
+ readonly local?: boolean;
371
377
  }
372
378
  /**
373
379
  * What the process boundary supplies for `action init`.
@@ -480,6 +486,8 @@ interface ActionRunInput {
480
486
  readonly validate: boolean;
481
487
  /** Whether to copy the build locally. `persistLocal.enabled = false` turns that off too. */
482
488
  readonly persist: boolean;
489
+ /** Whether to compare the build with the committed one instead of persisting it. */
490
+ readonly check: boolean;
483
491
  }
484
492
  /**
485
493
  * What the process boundary supplies for an action build: the parts of {@link BuildRunDeps} it uses.
@@ -496,13 +504,115 @@ type ActionRunDeps = Pick<BuildRunDeps, "cwd" | "ci">;
496
504
  * not start or finish: no `package.json`, a config that will not load, no `[action]` table, an entry that is missing
497
505
  * with validation off, and a file that cannot be cleaned, written or persisted.
498
506
  *
507
+ * With `check`, it writes nothing and a check that finds drift is the verdict `failed` with `result.drift`; the error
508
+ * channel adds `CheckUnavailable` (nothing persisted to compare), `NoOutput` (`dist = false` with persisting off) and
509
+ * `PersistPathError` (a persist path the bundler refuses).
510
+ *
499
511
  * It appends to no journal: the build and issue journals record package builds only.
500
512
  *
501
513
  * @public
502
514
  */
503
515
  export declare class ActionRun {
504
516
  private constructor();
505
- static readonly run: (input: ActionRunInput, deps: ActionRunDeps) => Effect.Effect<ActionRunResult, EffectedConfigError | NotAPackageError | NotAnActionError | BundleFailed | CleanError | WriteError | PersistLocalError | ActionYmlPathError | PlatformError.PlatformError, FileSystem.FileSystem | Path.Path>;
517
+ static readonly run: (input: ActionRunInput, deps: ActionRunDeps) => Effect.Effect<ActionRunResult, EffectedConfigError | NotAPackageError | NotAnActionError | BundleFailed | CleanError | WriteError | PersistLocalError | PersistPathError | CheckUnavailable | NoOutput | ActionYmlPathError | PlatformError.PlatformError, FileSystem.FileSystem | Path.Path>;
518
+ }
519
+ /**
520
+ * Why a watched build runs: the first build, or a settled batch of changes.
521
+ *
522
+ * @public
523
+ */
524
+ type WatchTrigger = {
525
+ readonly _tag: "Initial";
526
+ } | {
527
+ readonly _tag: "Changed";
528
+ /**
529
+ * The changed paths, de-duplicated and sorted, relative to the package directory with `/` separators; a
530
+ * root-tier `effected.toml` reads as `../…`.
531
+ */
532
+ readonly paths: ReadonlyArray<string>;
533
+ };
534
+ /**
535
+ * What every watched build ignores: package-relative paths a build writes, matched on `/` boundaries.
536
+ *
537
+ * @remarks
538
+ * An entry covers the path itself, everything under it, and the directories it lives in, so a build creating
539
+ * `.github/actions/local` triggers nothing with its `.github` and `.github/actions` directory events. A path that only
540
+ * shares a prefix (`distribution`), or a file beside an entry (`.github/workflows/ci.yml`), still triggers.
541
+ *
542
+ * @public
543
+ */
544
+ export declare const DEFAULT_EXCLUDES: ReadonlyArray<string>;
545
+ /**
546
+ * What {@link BuildWatch.run} watches and what it runs.
547
+ *
548
+ * @public
549
+ */
550
+ interface BuildWatchOptions<E, R> {
551
+ /** The package directory, absolute. */
552
+ readonly cwd: string;
553
+ /** The workspace root, absolute. */
554
+ readonly root: string;
555
+ /**
556
+ * Package-relative paths to ignore, re-evaluated before each batch is filtered. Each covers itself, what lies under
557
+ * it, and the directories it lives in, as {@link DEFAULT_EXCLUDES} does.
558
+ */
559
+ readonly exclude: Effect.Effect<ReadonlyArray<string>, never, R>;
560
+ /** How long the watched tree must be quiet before a batch is cut; omitted, 100 milliseconds. */
561
+ readonly debounce?: Duration.Input;
562
+ /** One build; its errors end the watch. */
563
+ readonly build: (trigger: WatchTrigger) => Effect.Effect<void, E, R>;
564
+ }
565
+ /**
566
+ * The directories a watch covers, resolved once at startup.
567
+ *
568
+ * @public
569
+ */
570
+ interface WatchTarget {
571
+ /** The package directory, absolute. */
572
+ readonly cwd: string;
573
+ /** The workspace root, absolute; `cwd` itself when there is no workspace above it. */
574
+ readonly root: string;
575
+ }
576
+ /**
577
+ * Rebuild on change.
578
+ *
579
+ * @public
580
+ */
581
+ export declare class BuildWatch {
582
+ /**
583
+ * Resolves what a watch covers, refusing a directory that cannot be built at all: no `package.json`, a workspace
584
+ * root that cannot be discovered, or, for an action, a config that loads with no `[action]` table. A config that
585
+ * will not load is not refused, because it is an edit the watch must survive.
586
+ */
587
+ static readonly target: (cwd: string, kind: "package" | "action") => Effect.Effect<WatchTarget, NotAPackageError | NotAnActionError | EffectedConfigError | PlatformError.PlatformError, FileSystem.FileSystem | Path.Path>;
588
+ /**
589
+ * A package's exclusions: {@link DEFAULT_EXCLUDES} plus each `[package.build.meta] localPaths` directory inside the
590
+ * package, package-relative, read from the config as it is now. Every build copies the API model into each one, so
591
+ * without them the watch would rebuild itself. Any config that will not load, or `meta = false`, gives the defaults.
592
+ */
593
+ static readonly packageExcludes: (target: WatchTarget) => Effect.Effect<ReadonlyArray<string>, never, FileSystem.FileSystem | Path.Path>;
594
+ /**
595
+ * An action's exclusions: {@link DEFAULT_EXCLUDES} plus its enabled `persistLocal.path`, package-relative, read
596
+ * from the config as it is now. `persist: false`, the `--no-persist` build that writes nothing there, leaves that
597
+ * path watched. Any config that will not load, or has no `[action]` table, gives the defaults.
598
+ */
599
+ static readonly actionExcludes: (target: WatchTarget, options?: {
600
+ readonly persist?: boolean;
601
+ }) => Effect.Effect<ReadonlyArray<string>, never, FileSystem.FileSystem | Path.Path>;
602
+ /**
603
+ * Builds once with `Initial` after every watcher is installed, then once per settled batch of changes, for as long
604
+ * as it runs. Fails with a watcher's `PlatformError`, or when a watcher stops; `build`'s errors propagate.
605
+ *
606
+ * @remarks
607
+ * The package directory is watched non-recursively, and each of its top-level directories that no exclusion covers
608
+ * gets a recursive watch of its own, so an excluded `node_modules`, `.git` or `dist` is never walked. A directory
609
+ * that is only where an exclusion lives, such as `.github`, is watched, and its events are filtered. The set follows
610
+ * the package: a new top-level directory is watched from its first event, a removed one's watch is dropped, and the
611
+ * exclusions are re-read after each batch. `<root>/.config` is watched while it exists, including one created after
612
+ * the watch starts. A watch stopping fails the run, except that a top-level directory's or `<root>/.config`'s watch
613
+ * ending once the directory is gone is that directory going away.
614
+ */
615
+ static readonly run: <E, R>(options: BuildWatchOptions<E, R>) => Effect.Effect<never, E | PlatformError.PlatformError, R | FileSystem.FileSystem | Path.Path>;
506
616
  }
507
- export { ActionBuildResult, type ActionInitDeps, type ActionInitInput, type ActionRunDeps, type ActionRunInput, type ActionScaffoldInput, ActionValidation, type BuildIssues, type BuildLockOptions, type BuildProgress, type BuildReport, BuildResult, type BuildRunDeps, type BuildRunInput, type BundleResult, type ValidationIssue, ValidationResult, renderCiAnnotations };
617
+ export { ActionBuildResult, type ActionInitDeps, type ActionInitInput, type ActionRunDeps, type ActionRunInput, type ActionScaffoldInput, ActionValidation, type BuildIssues, type BuildLockOptions, type BuildProgress, type BuildReport, BuildResult, type BuildRunDeps, type BuildRunInput, type BuildWatchOptions, type BundleResult, type ValidationIssue, ValidationResult, type WatchTarget, type WatchTrigger, renderCiAnnotations };
508
618
  //# sourceMappingURL=build.d.ts.map
package/build.js CHANGED
@@ -1,9 +1,10 @@
1
+ import { ActionBuildResult, ActionValidation, BuildResult, ValidationResult, renderCiAnnotations } from "@effected/bundler";
1
2
  import { ActionInit, ActionInitResult, ActionMetadataInvalidError, ActionMetadataMissingError, ActionScaffold, ActionScaffoldFile, ScaffoldConflict, ScaffoldConflictError, ScaffoldExistsError, ScaffoldWriteError } from "./build/ActionInit.js";
2
3
  import { ActionRun, NotAnActionError } from "./build/ActionRun.js";
3
4
  import { ActionRunResult } from "./build/ActionRunResult.js";
4
5
  import { BuildLockHolder, BuildLockTimeoutError } from "./build/BuildLock.js";
5
6
  import { BuildRun, NotAPackageError } from "./build/BuildRun.js";
6
7
  import { BuildRunResult } from "./build/BuildRunResult.js";
7
- import { ActionBuildResult, ActionValidation, BuildResult, ValidationResult, renderCiAnnotations } from "@effected/bundler";
8
+ import { BuildWatch, DEFAULT_EXCLUDES } from "./build/BuildWatch.js";
8
9
 
9
- export { ActionBuildResult, ActionInit, ActionInitResult, ActionMetadataInvalidError, ActionMetadataMissingError, ActionRun, ActionRunResult, ActionScaffold, ActionScaffoldFile, ActionValidation, BuildLockHolder, BuildLockTimeoutError, BuildResult, BuildRun, BuildRunResult, NotAPackageError, NotAnActionError, ScaffoldConflict, ScaffoldConflictError, ScaffoldExistsError, ScaffoldWriteError, ValidationResult, renderCiAnnotations };
10
+ export { ActionBuildResult, ActionInit, ActionInitResult, ActionMetadataInvalidError, ActionMetadataMissingError, ActionRun, ActionRunResult, ActionScaffold, ActionScaffoldFile, ActionValidation, BuildLockHolder, BuildLockTimeoutError, BuildResult, BuildRun, BuildRunResult, BuildWatch, DEFAULT_EXCLUDES, NotAPackageError, NotAnActionError, ScaffoldConflict, ScaffoldConflictError, ScaffoldExistsError, ScaffoldWriteError, ValidationResult, renderCiAnnotations };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effected/engine",
3
- "version": "0.18.2",
3
+ "version": "0.20.0",
4
4
  "private": false,
5
5
  "description": "The effected tool's shared logic, consumed by its CLI and MCP front ends",
6
6
  "keywords": [
@@ -46,17 +46,17 @@
46
46
  }
47
47
  },
48
48
  "dependencies": {
49
- "@effected/bundler": "0.6.2",
49
+ "@effected/bundler": "0.7.0",
50
50
  "@effected/files": "0.3.0",
51
51
  "@effected/jsonc": "0.25.0",
52
52
  "@effected/jsonl": "0.19.0",
53
53
  "@effected/kit": "0.14.0",
54
54
  "@effected/schemastore": "0.33.1",
55
55
  "@effected/source": "0.5.0",
56
- "@effected/workspaces": "0.48.1",
56
+ "@effected/workspaces": "0.48.2",
57
57
  "ajv": "8.20.0",
58
58
  "ajv-formats": "3.0.1",
59
- "effect": "4.1.4",
59
+ "effect": "4.1.5",
60
60
  "jiti": "~2.7.0"
61
61
  },
62
62
  "peerDependencies": {
@@ -1,6 +1,6 @@
1
- import { makeAjv } from "./internal/ajv.js";
2
- import { Effect, Layer } from "effect";
3
1
  import { InstanceFinding, InstanceValidator, InstanceValidatorError } from "@effected/schemastore";
2
+ import { Effect, Layer } from "effect";
3
+ import { makeAjv } from "./internal/ajv.js";
4
4
 
5
5
  // src/schema/AjvInstanceValidator.ts
6
6
  const findingFromAjvError = (error) => InstanceFinding.make({
@@ -1,6 +1,6 @@
1
- import { makeAjv } from "./internal/ajv.js";
2
- import { Effect, Layer } from "effect";
3
1
  import { SchemaValidator, SchemaValidatorError, ValidationFinding } from "@effected/schemastore";
2
+ import { Effect, Layer } from "effect";
3
+ import { makeAjv } from "./internal/ajv.js";
4
4
 
5
5
  // src/schema/AjvValidator.ts
6
6
  const findingFromAjvError = (error) => ValidationFinding.make({
@@ -1,10 +1,10 @@
1
- import { causeMessage } from "./internal/causeMessage.js";
2
- import { flattenSchemaError } from "./internal/decode.js";
3
1
  import { createRequire } from "node:module";
4
2
  import { PathContainment } from "@effected/kit";
5
- import { Effect, FileSystem, Path, Predicate, Result, Schema } from "effect";
6
3
  import { CatalogEntry, SchemaVersioning, isSchemastoreConfig } from "@effected/schemastore";
4
+ import { Effect, FileSystem, Path, Predicate, Result, Schema } from "effect";
7
5
  import { createJiti } from "jiti";
6
+ import { causeMessage } from "./internal/causeMessage.js";
7
+ import { flattenSchemaError } from "./internal/decode.js";
8
8
 
9
9
  // src/schema/ConfigLoader.ts
10
10
  /**
package/schema/Report.js CHANGED
@@ -1,6 +1,6 @@
1
+ import { Schema } from "effect";
1
2
  import { RunReport } from "./RunReport.js";
2
3
  import { VersionMismatch } from "./VersionCheck.js";
3
- import { Schema } from "effect";
4
4
 
5
5
  // src/schema/Report.ts
6
6
  const findingLine = (finding) => ` ${finding.label} at "${finding.path}": ${finding.message}`;
@@ -1,5 +1,5 @@
1
- import { Schema, SchemaTransformation } from "effect";
2
1
  import { PipelineFinding, SchemaVersion } from "@effected/schemastore";
2
+ import { Schema, SchemaTransformation } from "effect";
3
3
 
4
4
  // src/schema/RunReport.ts
5
5
  /**
package/schema/Runner.js CHANGED
@@ -1,10 +1,10 @@
1
- import { ConfigLoader } from "./ConfigLoader.js";
2
- import { decodeJson, flattenSchemaError } from "./internal/decode.js";
3
- import { CatalogReport, CatalogSliceReport, DocumentDiff, MergedCatalogReport, RunReport, SchemaReport } from "./RunReport.js";
4
- import { Effect, FileSystem, Option, Order, Path, Predicate, Result, Schema } from "effect";
5
1
  import { AtomicFile } from "@effected/files";
6
2
  import { CanonicalJson, CatalogEntry, DriftPolicy, SchemaFileWriteError, SchemaPipeline, SchemaVersioning } from "@effected/schemastore";
7
3
  import { LineDiff } from "@effected/source";
4
+ import { Effect, FileSystem, Option, Order, Path, Predicate, Result, Schema } from "effect";
5
+ import { ConfigLoader } from "./ConfigLoader.js";
6
+ import { decodeJson, flattenSchemaError } from "./internal/decode.js";
7
+ import { CatalogReport, CatalogSliceReport, DocumentDiff, MergedCatalogReport, RunReport, SchemaReport } from "./RunReport.js";
8
8
 
9
9
  // src/schema/Runner.ts
10
10
  /**
@@ -1,10 +1,10 @@
1
+ import { SchemaFile } from "@effected/schemastore";
2
+ import { Effect, Option, Schema } from "effect";
1
3
  import { AjvValidator } from "./AjvValidator.js";
2
4
  import { ConfigLoader } from "./ConfigLoader.js";
3
5
  import { Runner } from "./Runner.js";
4
6
  import { RunReport } from "./RunReport.js";
5
7
  import { VersionCheck, VersionMismatch, VersionMismatchError } from "./VersionCheck.js";
6
- import { Effect, Option, Schema } from "effect";
7
- import { SchemaFile } from "@effected/schemastore";
8
8
 
9
9
  // src/schema/SchemaRun.ts
10
10
  /**
@@ -1,10 +1,10 @@
1
+ import { Jsonc } from "@effected/jsonc";
2
+ import { InstanceValidator } from "@effected/schemastore";
3
+ import { LineIndex } from "@effected/source";
4
+ import { Effect, FileSystem, JsonPointer, Option, Path, Predicate, Result, Schema, SchemaTransformation } from "effect";
1
5
  import { AjvInstanceValidator } from "./AjvInstanceValidator.js";
2
6
  import { ConfigLoader } from "./ConfigLoader.js";
3
7
  import { VersionCheck, VersionMismatch, VersionMismatchError } from "./VersionCheck.js";
4
- import { Effect, FileSystem, JsonPointer, Option, Path, Predicate, Result, Schema, SchemaTransformation } from "effect";
5
- import { InstanceValidator } from "@effected/schemastore";
6
- import { LineIndex } from "@effected/source";
7
- import { Jsonc } from "@effected/jsonc";
8
8
 
9
9
  // src/schema/SchemaValidate.ts
10
10
  /**
@@ -1,5 +1,5 @@
1
- import { Option, Schema } from "effect";
2
1
  import { SchemastoreVersion } from "@effected/schemastore";
2
+ import { Option, Schema } from "effect";
3
3
 
4
4
  // src/schema/VersionCheck.ts
5
5
  const UNBUILT = "0.0.0";