@codeworksh/cli 0.0.1-dev.20260923102823 → 0.0.1-dev.20260925125202

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 (75) hide show
  1. package/{add-D1yPPRz2.mjs → add-CIQSfxan.mjs} +5 -5
  2. package/{add-D1yPPRz2.mjs.map → add-CIQSfxan.mjs.map} +1 -1
  3. package/{catalog-BtH_l7f2.mjs → catalog-C5fDCgtx.mjs} +3 -3
  4. package/{catalog-BtH_l7f2.mjs.map → catalog-C5fDCgtx.mjs.map} +1 -1
  5. package/{check-B7Uh_G-l.mjs → check-B7bP5lRI.mjs} +15 -9
  6. package/check-B7bP5lRI.mjs.map +1 -0
  7. package/entries-CSY5N6jH.mjs +89 -0
  8. package/entries-CSY5N6jH.mjs.map +1 -0
  9. package/{error-DG5INUkQ.mjs → error-D0C5K2Av.mjs} +126 -71
  10. package/error-D0C5K2Av.mjs.map +1 -0
  11. package/{harness-LSywfXzo.mjs → harness-DXAwGk0B.mjs} +2 -2
  12. package/{harness-LSywfXzo.mjs.map → harness-DXAwGk0B.mjs.map} +1 -1
  13. package/index.mjs +18 -18
  14. package/{install-zXEeTQ8w.mjs → install-B02SIXwF.mjs} +4 -4
  15. package/{install-zXEeTQ8w.mjs.map → install-B02SIXwF.mjs.map} +1 -1
  16. package/{link-DquUj9D6.mjs → link-CA9XdPwj.mjs} +3 -3
  17. package/{link-DquUj9D6.mjs.map → link-CA9XdPwj.mjs.map} +1 -1
  18. package/{list-eorMHI-g.mjs → list-Bbo4XnG_.mjs} +4 -4
  19. package/{list-eorMHI-g.mjs.map → list-Bbo4XnG_.mjs.map} +1 -1
  20. package/{list-C1ZWDpwI.mjs → list-Ce1Ry4JN.mjs} +4 -4
  21. package/{list-C1ZWDpwI.mjs.map → list-Ce1Ry4JN.mjs.map} +1 -1
  22. package/{login-DEjauWkd.mjs → login-CagARGqW.mjs} +4 -4
  23. package/{login-DEjauWkd.mjs.map → login-CagARGqW.mjs.map} +1 -1
  24. package/{logout-BUY-ESj_.mjs → logout-CYYtjZL3.mjs} +4 -4
  25. package/{logout-BUY-ESj_.mjs.map → logout-CYYtjZL3.mjs.map} +1 -1
  26. package/package.json +4 -4
  27. package/{providers-wTGawU9e.mjs → providers-CoYj1SYv.mjs} +4 -4
  28. package/{providers-wTGawU9e.mjs.map → providers-CoYj1SYv.mjs.map} +1 -1
  29. package/{refresh-C7e_qZit.mjs → refresh-8_nfeYNZ.mjs} +4 -4
  30. package/{refresh-C7e_qZit.mjs.map → refresh-8_nfeYNZ.mjs.map} +1 -1
  31. package/{refresh-B2jxJmk1.mjs → refresh-D2a1ikea.mjs} +4 -4
  32. package/{refresh-B2jxJmk1.mjs.map → refresh-D2a1ikea.mjs.map} +1 -1
  33. package/{reload-B5LO2rk9.mjs → reload-C5ysPM58.mjs} +3 -3
  34. package/{reload-B5LO2rk9.mjs.map → reload-C5ysPM58.mjs.map} +1 -1
  35. package/{remove-CTVgJKXM.mjs → remove-BkbspSED.mjs} +4 -4
  36. package/{remove-CTVgJKXM.mjs.map → remove-BkbspSED.mjs.map} +1 -1
  37. package/{run-CORFA6op.mjs → run-CnxjZIGy.mjs} +4 -4
  38. package/{run-CORFA6op.mjs.map → run-CnxjZIGy.mjs.map} +1 -1
  39. package/{runtime-Bp4kILYn.mjs → runtime-B3dlWGfs.mjs} +25 -12
  40. package/runtime-B3dlWGfs.mjs.map +1 -0
  41. package/{serve-DzaOcgKC.mjs → serve-DaD7Eijz.mjs} +4 -4
  42. package/{serve-DzaOcgKC.mjs.map → serve-DaD7Eijz.mjs.map} +1 -1
  43. package/{settings-tMD7Y0ev.mjs → settings-BZXmb54m.mjs} +23 -18
  44. package/settings-BZXmb54m.mjs.map +1 -0
  45. package/{shared-D8hbPMPF.mjs → shared-BaTfajJ2.mjs} +3 -3
  46. package/{shared-D8hbPMPF.mjs.map → shared-BaTfajJ2.mjs.map} +1 -1
  47. package/{status-CrAKnTHQ.mjs → status-qJImmv6V.mjs} +4 -4
  48. package/{status-CrAKnTHQ.mjs.map → status-qJImmv6V.mjs.map} +1 -1
  49. package/{update-DK7kAVc3.mjs → update-CxcNv_t0.mjs} +15 -9
  50. package/update-CxcNv_t0.mjs.map +1 -0
  51. package/check-B7Uh_G-l.mjs.map +0 -1
  52. package/commonjs-bcl-ngMU.mjs +0 -160
  53. package/commonjs-bcl-ngMU.mjs.map +0 -1
  54. package/definitions-XbglYT7Q.mjs +0 -3348
  55. package/definitions-XbglYT7Q.mjs.map +0 -1
  56. package/entries-B4tUkrxs.mjs +0 -48
  57. package/entries-B4tUkrxs.mjs.map +0 -1
  58. package/error-DG5INUkQ.mjs.map +0 -1
  59. package/lib-BCUUrctP.mjs +0 -846
  60. package/lib-BCUUrctP.mjs.map +0 -1
  61. package/lib-CNtGmPS7.mjs +0 -16078
  62. package/lib-CNtGmPS7.mjs.map +0 -1
  63. package/lib-CZnS894S.mjs +0 -10868
  64. package/lib-CZnS894S.mjs.map +0 -1
  65. package/lib-DHoZNIet.mjs +0 -37659
  66. package/lib-DHoZNIet.mjs.map +0 -1
  67. package/p-map-CMI1i54p.mjs +0 -116
  68. package/p-map-CMI1i54p.mjs.map +0 -1
  69. package/runtime-Bp4kILYn.mjs.map +0 -1
  70. package/settings-tMD7Y0ev.mjs.map +0 -1
  71. package/type-defs-JBxRyl-4.mjs +0 -538
  72. package/type-defs-JBxRyl-4.mjs.map +0 -1
  73. package/update-DK7kAVc3.mjs.map +0 -1
  74. package/valid-Bc7tec52.mjs +0 -354
  75. package/valid-Bc7tec52.mjs.map +0 -1
@@ -1,27 +1,27 @@
1
1
  import { createRequire, registerHooks } from "node:module";
2
2
  import { Cause, Clock, Config, Context, Crypto, DateTime, Deferred, Duration, Effect, Encoding, Exit, Fiber, FiberSet, FileSystem, Layer, LayerMap, Option, Path, Predicate, PubSub, Queue, Ref, Result, Schedule, Schema, SchemaIssue, Scope, Semaphore, Stream, String as String$1 } from "effect";
3
3
  import { Message, Model, llm, stream } from "@codeworksh/aikit";
4
- import path from "node:path";
5
- import * as os from "node:os";
6
- import { homedir, tmpdir } from "node:os";
7
- import { fileURLToPath, pathToFileURL } from "node:url";
8
- import fs, { statSync } from "node:fs";
9
- import npa from "npm-package-arg";
10
4
  import { MessageID as ID, SessionID as ID$1 } from "@codeworksh/plugin/ids";
11
5
  import { Migrator, SqlClient, SqlError, SqlSchema } from "effect/unstable/sql";
12
6
  import { uuidv7 } from "uuidv7";
13
7
  import { SqliteClient, SqliteMigrator } from "@effect/sql-sqlite-node";
8
+ import * as os from "node:os";
9
+ import { homedir, tmpdir } from "node:os";
14
10
  import { NodeChildProcessSpawner, NodeCrypto, NodeFileSystem, NodePath, NodeSocket } from "@effect/platform-node";
15
11
  import { posix } from "@codeworksh/plugin/posix";
16
12
  import { Model as Model$1, VariantSchema } from "effect/unstable/schema";
17
13
  import { MemoryProvider, RealFSProvider, SqliteProvider, create } from "@platformatic/vfs";
14
+ import fs, { statSync } from "node:fs";
18
15
  import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process";
19
16
  import { Buffer as Buffer$1 } from "node:buffer";
20
17
  import { Bash } from "just-bash";
21
18
  import { SandboxDriver as SandboxDriver$3, SandboxProvider } from "@codeworksh/plugin/sandbox";
22
19
  import { DirectoryNotFoundError, DirectoryNotFoundError as DirectoryNotFoundError$1, Info, NotDirectoryError, NotDirectoryError as NotDirectoryError$1, Service, Service as Service$8 } from "@codeworksh/plugin/location";
23
20
  import { generateModels } from "@codeworksh/aikit/modelgen";
21
+ import { fileURLToPath, pathToFileURL } from "node:url";
22
+ import path from "node:path";
24
23
  import { Script, constants } from "node:vm";
24
+ import npa from "npm-package-arg";
25
25
  import * as AikitFailure from "@codeworksh/aikit/failure";
26
26
  import { JsonGitHubCopilotAuthStorage, getGitHubCopilotApiKey } from "@codeworksh/aikit/oauth/github/copilot";
27
27
  import { JsonOpenAICodexAuthStorage, getOpenAICodexApiKey } from "@codeworksh/aikit/oauth/openai/codex";
@@ -29,21 +29,10 @@ import "@codeworksh/plugin/tool/error";
29
29
  import { parse, printParseErrorCode } from "jsonc-parser";
30
30
  import { Rpc, RpcClient, RpcGroup, RpcSerialization } from "effect/unstable/rpc";
31
31
  //#region \0rolldown/runtime.js
32
- var __create = Object.create;
33
32
  var __defProp = Object.defineProperty;
34
33
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
35
34
  var __getOwnPropNames = Object.getOwnPropertyNames;
36
- var __getProtoOf = Object.getPrototypeOf;
37
35
  var __hasOwnProp = Object.prototype.hasOwnProperty;
38
- var __esmMin = (fn, res, err) => () => {
39
- if (err) throw err[0];
40
- try {
41
- return fn && (res = fn(fn = 0)), res;
42
- } catch (e) {
43
- throw err = [e], e;
44
- }
45
- };
46
- var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
47
36
  var __exportAll = (all, no_symbols) => {
48
37
  let target = {};
49
38
  for (var name in all) __defProp(target, name, {
@@ -64,12 +53,6 @@ var __copyProps = (to, from, except, desc) => {
64
53
  return to;
65
54
  };
66
55
  var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
67
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
68
- value: mod,
69
- enumerable: true
70
- }) : target, mod));
71
- var __toCommonJS = (mod) => __hasOwnProp.call(mod, "module.exports") ? mod["module.exports"] : __copyProps(__defProp({}, "__esModule", { value: true }), mod);
72
- var __require = /* #__PURE__ */ (() => createRequire(import.meta.url))();
73
56
  //#endregion
74
57
  //#region ../harness/src/schema.ts
75
58
  var schema_exports$8 = /* @__PURE__ */ __exportAll({});
@@ -6451,8 +6434,8 @@ const options = (dir, cache) => Effect.suspend(() => {
6451
6434
  });
6452
6435
  const npmOptions = (dir, cache) => Effect.gen(function* () {
6453
6436
  const config = yield* Effect.tryPromise(async () => {
6454
- const { default: Config } = await import("./lib-BCUUrctP.mjs").then((m) => /* @__PURE__ */ __toESM(m.default, 1));
6455
- const { definitions, flatten, nerfDarts, shorthands } = (await import("./definitions-XbglYT7Q.mjs").then((m) => /* @__PURE__ */ __toESM(m.default, 1))).default;
6437
+ const { default: Config } = await import("@npmcli/config");
6438
+ const { definitions, flatten, nerfDarts, shorthands } = (await import("@npmcli/config/lib/definitions/index.js")).default;
6456
6439
  const created = new Config({
6457
6440
  npmPath: fileURLToPath(new URL("..", import.meta.url)),
6458
6441
  cwd: dir,
@@ -6568,7 +6551,7 @@ const entrypoint = (directory, name) => Effect.gen(function* () {
6568
6551
  });
6569
6552
  const reify = Effect.fn("PluginNpm.reify")(function* ({ target, into, cache, from }) {
6570
6553
  const flat = yield* options(from, cache);
6571
- const { Arborist } = yield* Effect.promise(() => import("./lib-CNtGmPS7.mjs").then((m) => /* @__PURE__ */ __toESM(m.default, 1)));
6554
+ const { Arborist } = yield* Effect.promise(() => import("@npmcli/arborist"));
6572
6555
  const settings = {
6573
6556
  ...flat,
6574
6557
  ...target.mutable ? {
@@ -6662,7 +6645,7 @@ const probe = Effect.fn("PluginNpm.probe")(function* (target, cache, from) {
6662
6645
  noGitRevCache: true,
6663
6646
  _isRoot: true
6664
6647
  };
6665
- const { default: pacote } = yield* Effect.promise(() => import("./lib-DHoZNIet.mjs").then((n) => /* @__PURE__ */ __toESM(n.t(), 1)));
6648
+ const { default: pacote } = yield* Effect.promise(() => import("pacote"));
6666
6649
  return yield* Effect.tryPromise({
6667
6650
  try: async () => target.kind === "registry" ? (await pacote.manifest(target.spec, opts)).version : commitIn(await pacote.resolve(target.spec, opts)),
6668
6651
  catch: (cause) => new InstallError({
@@ -7282,6 +7265,12 @@ const Manifest = Schema.Struct({
7282
7265
  name: Schema.optional(Schema.String),
7283
7266
  exports: Schema.optional(Schema.Unknown)
7284
7267
  });
7268
+ const readManifest = (manifestPath) => fileSystem.readFileString(manifestPath).pipe(Effect.flatMap(Schema.decodeUnknownEffect(Schema.fromJsonString(Manifest))));
7269
+ /**
7270
+ * The name a local package declares, read without importing it: the alias the catalog registers
7271
+ * for it, so a `{ package }` entry and a command naming the package both reach it.
7272
+ */
7273
+ const localName = (location) => readManifest(hostPath.join(location, "package.json")).pipe(Effect.map((manifest) => manifest.name), Effect.orElseSucceed(() => void 0));
7285
7274
  const localUrl = Effect.fn("PluginLoader.localUrl")(function* (location, origin) {
7286
7275
  const escapes = (message) => new SourceError({
7287
7276
  reason: "plugin-escapes-root",
@@ -7292,7 +7281,7 @@ const localUrl = Effect.fn("PluginLoader.localUrl")(function* (location, origin)
7292
7281
  if ((yield* fileSystem.stat(location)).type !== "Directory") return { url: yield* Effect.try(() => resolveModule(location, hostPath.dirname(location))) };
7293
7282
  const manifestPath = hostPath.join(location, "package.json");
7294
7283
  if (!(yield* fileSystem.exists(manifestPath))) return { url: yield* Effect.try(() => resolveModule("./index", location)) };
7295
- const manifest = yield* fileSystem.readFileString(manifestPath).pipe(Effect.flatMap(Schema.decodeUnknownEffect(Schema.fromJsonString(Manifest))));
7284
+ const manifest = yield* readManifest(manifestPath);
7296
7285
  if (manifest.exports !== void 0) {
7297
7286
  const name = manifest.name;
7298
7287
  if (!name) return yield* escapes("a local package with exports must declare its name");
@@ -7568,7 +7557,9 @@ const select = Effect.fn("PluginCatalog.select")(function* (references, pool) {
7568
7557
  * walks those entries against the loaded set. Two things can be settled right there, and they are
7569
7558
  * the same question asked twice:
7570
7559
  *
7571
- * 1. a settings entry names a module that is not loaded, and the store holds it;
7560
+ * 1. a settings entry names a module that is not loaded, and the store holds it -- or it is loaded
7561
+ * from another file's artifact than the one that owns it in this view, and the store holds
7562
+ * the owner's;
7572
7563
  * 2. a loaded module is not the newest generation the store has.
7573
7564
  *
7574
7565
  * The second is what makes `plugin update` finish. Without it the question is "is this entry
@@ -7587,8 +7578,16 @@ const select = Effect.fn("PluginCatalog.select")(function* (references, pool) {
7587
7578
  const follow = Effect.fn("PluginCatalog.follow")(function* (references, pool, options, filed) {
7588
7579
  let moved = false;
7589
7580
  for (const reference of references) {
7590
- if (typeof reference !== "string" || pool.aliases.has(reference)) continue;
7591
- if (Option.isSome(yield* filed(reference, anchor$1(options.declared?.get(reference), options.hostDir)))) {
7581
+ if (typeof reference !== "string") continue;
7582
+ const owner = options.declared?.get(reference);
7583
+ const from = anchor$1(owner, options.hostDir);
7584
+ const id = pool.aliases.get(reference);
7585
+ if (id !== void 0) {
7586
+ const origin = pool.origins.get(id);
7587
+ if (owner === void 0 || origin?.reference !== reference) continue;
7588
+ if (anchor$1(origin.file, options.hostDir) === from) continue;
7589
+ }
7590
+ if (Option.isSome(yield* filed(reference, from))) {
7592
7591
  moved = true;
7593
7592
  break;
7594
7593
  }
@@ -8321,7 +8320,7 @@ const make$5 = (tools) => {
8321
8320
  if (before.value !== void 0 && !Schema.is(schema_exports.ToolBeforeResult)(before.value)) return yield* failureOutcome(call, Cause.die(/* @__PURE__ */ new Error("beforeToolCall returned an invalid result")), "beforeToolCall failed");
8322
8321
  if (before.value?.block) {
8323
8322
  const now = yield* Effect.clockWith((clock) => clock.currentTimeMillis);
8324
- return errored(call, [text(before.value.reason || "Tool execution was blocked")], now);
8323
+ return errored(call, [text(before.value?.reason || "Tool execution was blocked")], now);
8325
8324
  }
8326
8325
  }
8327
8326
  const latest = yield* Ref.make(Option.none());
@@ -8630,6 +8629,12 @@ const layer$7 = Layer.effect(Service$3, Effect.gen(function* () {
8630
8629
  }));
8631
8630
  //#endregion
8632
8631
  //#region ../harness/src/settings/settings.ts
8632
+ /**
8633
+ * An app-level `--user-config-dir` as the absolute directory it names: `~` is the user's home, and
8634
+ * a relative spelling is relative to `hostCwd` -- never to a session's `hostDir`, which is not
8635
+ * where the flag was typed.
8636
+ */
8637
+ const userConfigDir = (raw, hostCwd) => hostPath.resolve(hostCwd, expandTilde(raw, hostPath));
8633
8638
  /** The settings files a directory may hold, in the order it is searched. */
8634
8639
  const settingsIn = (directory) => [hostPath.join(directory, "settings.jsonc"), hostPath.join(directory, "settings.json")];
8635
8640
  /** A directory and every ancestor above it, nearest first. */
@@ -8679,13 +8684,7 @@ const projectRoot = Effect.fn("Settings.projectRoot")(function* (from, home) {
8679
8684
  * no project layer at all, which is what a session with no host directory gets.
8680
8685
  */
8681
8686
  function paths(input) {
8682
- const expanded = input.custom === void 0 ? void 0 : expandTilde(input.custom, hostPath);
8683
- const explicit = expanded === void 0 ? void 0 : input.from === void 0 ? expanded : hostPath.resolve(input.from, expanded);
8684
- return [
8685
- settingsIn(input.home),
8686
- input.root === void 0 ? [] : settingsIn(hostPath.join(input.root, appConfigDir)),
8687
- ...explicit === void 0 ? [] : [settingsIn(explicit)]
8688
- ];
8687
+ return [settingsIn(input.userConfigDir ?? input.home), input.root === void 0 ? [] : settingsIn(hostPath.join(input.root, appConfigDir))];
8689
8688
  }
8690
8689
  var SettingsError = class extends Schema.TaggedError()("SettingsError", {
8691
8690
  path: Schema.String,
@@ -8763,8 +8762,7 @@ const load$1 = Effect.fn("Settings.load")(function* (options) {
8763
8762
  const files = paths({
8764
8763
  home: options.home,
8765
8764
  root,
8766
- ...options.hostDir === void 0 ? {} : { from: hostPath.resolve(options.hostDir) },
8767
- ...options.userConfigDir === void 0 ? {} : { custom: options.userConfigDir }
8765
+ ...options.userConfigDir === void 0 ? {} : { userConfigDir: options.userConfigDir }
8768
8766
  });
8769
8767
  let settings = merge(schema_exports$1.defaults);
8770
8768
  let declared = schema_exports$1.defaults.declared;
@@ -8790,6 +8788,20 @@ const load$1 = Effect.fn("Settings.load")(function* (options) {
8790
8788
  declared
8791
8789
  };
8792
8790
  });
8791
+ /**
8792
+ * Each module reference once, owned by the **last** file to declare it (D6).
8793
+ *
8794
+ * The owner is not bookkeeping: its `.npmrc` chain keys the store artifact. The CLI that installs
8795
+ * a reference and the runtime that loads it must pick the same owner, or `plugin update` refreshes
8796
+ * an artifact the runtime never reads. Only a string entry loads a module, so only a string entry
8797
+ * owns one -- a `{ package }` patch in another file configures it and must not move its registry.
8798
+ * A reference keeps the position of its first declaration.
8799
+ */
8800
+ const modules = (declared) => {
8801
+ const owners = /* @__PURE__ */ new Map();
8802
+ for (const one of declared) if (typeof one.entry === "string") owners.set(one.entry, one);
8803
+ return owners;
8804
+ };
8793
8805
  const layer$6 = (options = {}) => Layer.effect(Service$2, Effect.gen(function* () {
8794
8806
  const global = yield* Service$17;
8795
8807
  return Service$2.of({ load: (hostDir) => load$1({
@@ -8833,8 +8845,14 @@ const resolver = (input) => typeof input === "string" ? () => input : input;
8833
8845
  * `references` says which entries the config pass walks. It is a function of the settings that
8834
8846
  * exchange read, so a caller that pinned an explicit list keeps it and everyone else follows the
8835
8847
  * files.
8848
+ *
8849
+ * `pool` is the **process view**: what boot loaded from the user layers. A session in a project
8850
+ * runs from that project's own view, a pool created from the process view the first time the
8851
+ * project is seen and moved only by its own sessions. The same spec can be owned by different
8852
+ * files -- and so name different registries -- in two views; one shared pool could hold only one of
8853
+ * those builds, and sessions in different projects would keep evicting each other's.
8836
8854
  */
8837
- const layer$5 = (options, pool, references, follow, rebuild) => {
8855
+ const layer$5 = (options, pool, references, follow, rebuild, viewOf = () => Effect.undefined) => {
8838
8856
  return Layer.effect(Service$1, Effect.gen(function* () {
8839
8857
  const runtime = yield* Service$3;
8840
8858
  const sessions = yield* Service$14;
@@ -8849,10 +8867,31 @@ const layer$5 = (options, pool, references, follow, rebuild) => {
8849
8867
  id,
8850
8868
  ...origin.file === void 0 ? {} : { file: origin.file }
8851
8869
  });
8852
- const activate = Effect.fn("State.activatePlugins")(function* (next) {
8853
- const previous = yield* Ref.get(pool);
8854
- yield* eventRegistry.replace([...next.plugins.values()]);
8855
- yield* Ref.set(pool, next);
8870
+ /** Project root to its view. The process view is `pool` itself. */
8871
+ const views = /* @__PURE__ */ new Map();
8872
+ /** Created from the process view on first use; called under `loading`, so never twice. */
8873
+ const poolOf = Effect.fnUntraced(function* (root) {
8874
+ if (root === void 0) return pool;
8875
+ const existing = views.get(root);
8876
+ if (existing !== void 0) return existing;
8877
+ const created = yield* Ref.make(yield* Ref.get(pool));
8878
+ views.set(root, created);
8879
+ return created;
8880
+ });
8881
+ const everyView = () => [[void 0, pool], ...views];
8882
+ /**
8883
+ * Every plugin some view runs, one per ID. Event types are process-wide, and two views
8884
+ * holding two builds of one plugin register its namespace once.
8885
+ */
8886
+ const union = Effect.fnUntraced(function* (target, next) {
8887
+ const plugins = /* @__PURE__ */ new Map();
8888
+ for (const [, ref] of everyView()) for (const [id, plugin] of ref === target ? next.plugins : (yield* Ref.get(ref)).plugins) plugins.set(id, plugin);
8889
+ return plugins;
8890
+ });
8891
+ const activate = Effect.fn("State.activatePlugins")(function* (target, next) {
8892
+ const previous = yield* Ref.get(target);
8893
+ yield* eventRegistry.replace([...(yield* union(target, next)).values()]);
8894
+ yield* Ref.set(target, next);
8856
8895
  for (const [id, origin] of next.origins) {
8857
8896
  if (next.plugins.get(id) === previous.plugins.get(id)) continue;
8858
8897
  yield* updated(origin, id, "loaded");
@@ -8872,16 +8911,21 @@ const layer$5 = (options, pool, references, follow, rebuild) => {
8872
8911
  });
8873
8912
  return Service$1.of({
8874
8913
  reload: Effect.gen(function* () {
8875
- const rebuilt = yield* rebuild().pipe(Effect.flatMap(activate), loading.withPermits(1), Effect.result);
8876
- if (rebuilt._tag === "Failure") {
8877
- yield* Effect.logWarning(`plugin reload failed, keeping the previous set: ${rebuilt.failure.message}`);
8878
- yield* publishFailed(rebuilt.failure);
8879
- return {
8880
- plugins: (yield* Ref.get(pool)).plugins.size,
8881
- failure: rebuilt.failure.message
8882
- };
8914
+ const failures = /* @__PURE__ */ new Map();
8915
+ for (const [root, target] of everyView()) {
8916
+ const rebuilt = yield* Ref.get(target).pipe(Effect.flatMap((current) => rebuild(root, current)), Effect.flatMap((next) => activate(target, next)), loading.withPermits(1), Effect.result);
8917
+ if (rebuilt._tag === "Failure") failures.set(rebuilt.failure.message, rebuilt.failure);
8883
8918
  }
8884
- return { plugins: rebuilt.success.plugins.size };
8919
+ for (const failure of failures.values()) {
8920
+ yield* Effect.logWarning(`plugin reload failed, keeping the previous set: ${failure.message}`);
8921
+ yield* publishFailed(failure);
8922
+ }
8923
+ const plugins = (yield* union(pool, yield* Ref.get(pool))).size;
8924
+ const [first] = failures.keys();
8925
+ return first === void 0 ? { plugins } : {
8926
+ plugins,
8927
+ failure: first
8928
+ };
8885
8929
  }),
8886
8930
  snapshot: Effect.fn("State.snapshot")(function* (sessionId) {
8887
8931
  const sessionOptions = Option.getOrElse(yield* runtime.get(sessionId), () => ({}));
@@ -8906,10 +8950,12 @@ const layer$5 = (options, pool, references, follow, rebuild) => {
8906
8950
  cause
8907
8951
  });
8908
8952
  const loaded = yield* Effect.gen(function* () {
8909
- const current = yield* Ref.get(pool);
8910
- const moved = yield* follow(refs, current, loadedSettings).pipe(Effect.tapError((cause) => publishFailed(cause, sessionId)));
8953
+ const root = yield* viewOf(hostDir);
8954
+ const target = yield* poolOf(root);
8955
+ const current = yield* Ref.get(target);
8956
+ const moved = yield* follow(refs, current, loadedSettings, root).pipe(Effect.tapError((cause) => publishFailed(cause, sessionId)));
8911
8957
  if (Option.isNone(moved)) return current;
8912
- return yield* activate(moved.value);
8958
+ return yield* activate(target, moved.value);
8913
8959
  }).pipe(loading.withPermits(1), Effect.mapError(failed));
8914
8960
  const chosen = yield* select(refs, loaded).pipe(Effect.mapError(failed));
8915
8961
  for (const reference of chosen.missing) {
@@ -9398,23 +9444,28 @@ const layer$2 = Layer.provideMerge(layer$3, layer$24);
9398
9444
  //#endregion
9399
9445
  //#region ../harness/src/effect/harness.ts
9400
9446
  const layer$1 = (options = {}) => Layer.unwrap(Effect.gen(function* () {
9401
- const paths = yield* resolve$3(options.home === void 0 ? {} : { home: options.home });
9402
9447
  const hostCwd = options.hostCwd ?? process.cwd();
9448
+ const paths = yield* resolve$3(options.home === void 0 ? {} : { home: hostPath.resolve(hostCwd, expandTilde(options.home, hostPath)) });
9403
9449
  const global = layerWith(paths);
9404
- const settingsOptions = options.userConfigDir === void 0 ? {} : { userConfigDir: hostPath.resolve(hostCwd, expandTilde(options.userConfigDir, hostPath)) };
9450
+ const settingsOptions = options.userConfigDir === void 0 ? {} : { userConfigDir: userConfigDir(options.userConfigDir, hostCwd) };
9405
9451
  const config = yield* load$1({
9406
9452
  ...settingsOptions,
9407
9453
  home: paths.home
9408
9454
  });
9409
9455
  const references = (settings) => options.plugins ?? [...builtins, ...settings.plugins];
9410
- /** Reference to the file that declared it, for failures that should name one. */
9411
- const declaredIn = (settings) => new Map(settings.declared.flatMap((one) => typeof one.entry === "string" ? [[one.entry, one.file]] : "package" in one.entry ? [[one.entry.package, one.file]] : []));
9456
+ /** Reference to the file that owns it: the `.npmrc` anchor, and what a failure names. */
9457
+ const declaredIn = (settings) => new Map(Array.from(modules(settings.declared), ([reference, one]) => [reference, one.file]));
9412
9458
  const catalogOptions = {
9413
9459
  builtins,
9414
9460
  cache: paths.cache,
9415
9461
  hostDir: hostCwd
9416
9462
  };
9417
- const filed = (reference, from) => parse$2(reference, hostCwd).pipe(Effect.flatMap((target) => target.kind === "local" ? fileSystem.exists(target.path).pipe(Effect.map((there) => there ? Option.some({}) : Option.none())) : resolve$2(target, paths.cache, from).pipe(Effect.map((entry) => Option.fromUndefinedOr(entry)))), Effect.orElseSucceed(() => Option.none()));
9463
+ /**
9464
+ * The host directory a view resolves against: a project view's is the root its sessions'
9465
+ * `hostDir` led to; only the process view falls back to `hostCwd`.
9466
+ */
9467
+ const hostDirOf = (root) => root ?? hostCwd;
9468
+ const filed = (reference, from) => parse$2(reference, from).pipe(Effect.flatMap((target) => target.kind === "local" ? fileSystem.exists(target.path).pipe(Effect.map((there) => there ? Option.some({}) : Option.none())) : resolve$2(target, paths.cache, from).pipe(Effect.map((entry) => Option.fromUndefinedOr(entry)))), Effect.orElseSucceed(() => Option.none()));
9418
9469
  const resolveOnly = {
9419
9470
  ...catalogOptions,
9420
9471
  install: required
@@ -9423,22 +9474,25 @@ const layer$1 = (options = {}) => Layer.unwrap(Effect.gen(function* () {
9423
9474
  ...resolveOnly,
9424
9475
  declared: declaredIn(config)
9425
9476
  }));
9426
- const followStore = (refs, current, settings) => follow(refs, current, {
9477
+ const followStore = (refs, current, settings, root) => follow(refs, current, {
9427
9478
  ...resolveOnly,
9479
+ hostDir: hostDirOf(root),
9428
9480
  declared: declaredIn(settings)
9429
9481
  }, filed);
9482
+ /** A session's view is its project root; one with no project runs from the process view. */
9483
+ const viewOf = (hostDir) => hostDir === void 0 ? Effect.undefined : projectRoot(hostDir, paths.home).pipe(Effect.orElseSucceed(() => void 0));
9430
9484
  let reloads = 0;
9431
- const rebuild = () => Effect.gen(function* () {
9485
+ const rebuild = (root, loaded) => Effect.gen(function* () {
9432
9486
  reloads += 1;
9433
9487
  const current = yield* load$1({
9434
9488
  ...settingsOptions,
9435
- home: paths.home
9489
+ home: paths.home,
9490
+ ...root === void 0 ? {} : { hostDir: root }
9436
9491
  });
9437
- const loaded = yield* Ref.get(pool);
9438
9492
  const retained = [];
9439
9493
  const configured = references(current);
9440
9494
  for (const origin of loaded.origins.values()) {
9441
- if (configured.includes(origin.reference) || Option.isSome(yield* filed(origin.reference, anchor$1(origin.file, hostCwd)))) {
9495
+ if (configured.includes(origin.reference) || Option.isSome(yield* filed(origin.reference, anchor$1(origin.file, hostDirOf(root))))) {
9442
9496
  retained.push(origin);
9443
9497
  continue;
9444
9498
  }
@@ -9450,6 +9504,7 @@ const layer$1 = (options = {}) => Layer.unwrap(Effect.gen(function* () {
9450
9504
  for (const [reference, file] of declaredIn(current)) known.set(reference, file);
9451
9505
  return yield* load$2(accumulated, {
9452
9506
  ...resolveOnly,
9507
+ hostDir: hostDirOf(root),
9453
9508
  declared: known,
9454
9509
  reload: reloads
9455
9510
  });
@@ -9462,7 +9517,7 @@ const layer$1 = (options = {}) => Layer.unwrap(Effect.gen(function* () {
9462
9517
  const authFile$1 = authFile(options.home === void 0 ? void 0 : paths.home);
9463
9518
  const open = options.llm ?? openWith(authFile$1 === void 0 ? {} : { authFile: authFile$1 });
9464
9519
  const loop = layer$4({ request: make$6(open) });
9465
- return layer$11.pipe(Layer.provideMerge(layer$8.pipe(Layer.provide(loop))), Layer.provideMerge(layer$5({}, pool, references, followStore, rebuild)), Layer.provideMerge(layer$6(settingsOptions)), Layer.provideMerge(layer$7), Layer.provideMerge(sandboxes), Layer.provideMerge(layer$23), Layer.provideMerge(layer$2), Layer.provideMerge(layer$26), Layer.provideMerge(layer$10(definitions)), Layer.provideMerge(database), Layer.provideMerge(global), Layer.provideMerge(layer$9({
9520
+ return layer$11.pipe(Layer.provideMerge(layer$8.pipe(Layer.provide(loop))), Layer.provideMerge(layer$5({}, pool, references, followStore, rebuild, viewOf)), Layer.provideMerge(layer$6(settingsOptions)), Layer.provideMerge(layer$7), Layer.provideMerge(sandboxes), Layer.provideMerge(layer$23), Layer.provideMerge(layer$2), Layer.provideMerge(layer$26), Layer.provideMerge(layer$10(definitions)), Layer.provideMerge(database), Layer.provideMerge(global), Layer.provideMerge(layer$9({
9466
9521
  home: paths.home,
9467
9522
  watch: options.watchModels ?? false
9468
9523
  })));
@@ -10316,6 +10371,6 @@ const reportFailure = (error) => writeError(renderError(error)).pipe(Effect.andT
10316
10371
  process.exitCode = 1;
10317
10372
  })));
10318
10373
  //#endregion
10319
- export { refresh$1 as $, stop as A, __toESM as At, check as B, link as C, ID$1 as Ct, list as D, __exportAll as Dt, drivers as E, __esmMin as Et, projectRoot as F, parse$2 as G, resolve$2 as H, anchor$1 as I, LoadError as J, probe as K, canonical as L, Service$1 as M, load$1 as N, register as O, __require as Ot, paths as P, providers as Q, definition$1 as R, get as S, resolve$3 as St, create$2 as T, __commonJSMin as Tt, update as U, required as V, lock as W, StoreError as X, SourceError as Y, models as Z, Connected as _, schema_exports$6 as _t, addUsage as a, Service$14 as at, attach as b, Service$17 as bt, terminalColumns as c, layer$24 as ct, writeOut as d, layer$26 as dt, sync as et, layer as f, LLMEnded as ft, OAuthError$1 as g, instance_exports as gt, Api as h, Prompt as ht, reportFailure as i, sandbox$1 as it, layer$1 as j, resolve as k, __toCommonJS as kt, usage as l, Service$16 as lt, run as m, TurnEnded as mt, OAuthError as n, Service$5 as nt, emptyUsage as o, SessionNotFoundError as ot, make as p, LLMTextDelta as pt, InstallError as q, renderError as r, sandbox as rt, header as s, SessionNotLinkedError as st, InvalidInputError as t, Service$4 as tt, writeError as u, SubscriptionOverflowError as ut, Core as v, layer$27 as vt, relink as w, schema_exports$8 as wt, create$1 as x, authFile as xt, encode as y, path$1 as yt, inspect as z };
10374
+ export { SourceError as $, stop as A, definition$1 as B, link as C, path$1 as Ct, list as D, ID$1 as Dt, drivers as E, resolve$3 as Et, paths as F, required as G, localName as H, projectRoot as I, lock as J, resolve$2 as K, userConfigDir as L, Service$1 as M, load$1 as N, register as O, schema_exports$8 as Ot, modules as P, LoadError as Q, anchor$1 as R, get as S, layer$27 as St, create$2 as T, authFile as Tt, check as U, inspect as V, digest as W, probe as X, parse$2 as Y, InstallError as Z, Connected as _, LLMTextDelta as _t, addUsage as a, Service$4 as at, attach as b, instance_exports as bt, terminalColumns as c, sandbox$1 as ct, writeOut as d, SessionNotLinkedError as dt, StoreError as et, layer as f, layer$24 as ft, OAuthError$1 as g, LLMEnded as gt, Api as h, layer$26 as ht, reportFailure as i, sync as it, layer$1 as j, resolve as k, usage as l, Service$14 as lt, run as m, SubscriptionOverflowError as mt, OAuthError as n, providers as nt, emptyUsage as o, Service$5 as ot, make as p, Service$16 as pt, update as q, renderError as r, refresh$1 as rt, header as s, sandbox as st, InvalidInputError as t, models as tt, writeError as u, SessionNotFoundError as ut, Core as v, TurnEnded as vt, relink as w, Service$17 as wt, create$1 as x, schema_exports$6 as xt, encode as y, Prompt as yt, canonical as z };
10320
10375
 
10321
- //# sourceMappingURL=error-DG5INUkQ.mjs.map
10376
+ //# sourceMappingURL=error-D0C5K2Av.mjs.map