@codeworksh/cli 0.5.0 → 0.6.0-dev.20261102120654

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 (103) hide show
  1. package/README.md +27 -2
  2. package/{acp-JnyJmRCD.mjs → acp-LdSUzAM5.mjs} +92 -42
  3. package/acp-LdSUzAM5.mjs.map +1 -0
  4. package/add-CzFz-Mfb.mjs +87 -0
  5. package/add-CzFz-Mfb.mjs.map +1 -0
  6. package/{add-Dzsv-fKd.mjs → add-fJlj0O2v.mjs} +5 -5
  7. package/add-fJlj0O2v.mjs.map +1 -0
  8. package/{catalog-C1G3pzHZ.mjs → catalog-DCjYMhro.mjs} +2 -2
  9. package/{catalog-C1G3pzHZ.mjs.map → catalog-DCjYMhro.mjs.map} +1 -1
  10. package/{check-DhojkK_E.mjs → check-7oL3UVdX.mjs} +4 -4
  11. package/{check-DhojkK_E.mjs.map → check-7oL3UVdX.mjs.map} +1 -1
  12. package/control-Bd2G-Unk.mjs +31 -0
  13. package/control-Bd2G-Unk.mjs.map +1 -0
  14. package/disconnect-Dpt7LKVl.mjs +2 -0
  15. package/{entries-KpYvZdpi.mjs → entries-hMxcOaPm.mjs} +3 -3
  16. package/{entries-KpYvZdpi.mjs.map → entries-hMxcOaPm.mjs.map} +1 -1
  17. package/{error-BMI81XvR.mjs → error-BVSfzBzb.mjs} +240 -91
  18. package/error-BVSfzBzb.mjs.map +1 -0
  19. package/fork-BtL-68qs.mjs +32 -0
  20. package/fork-BtL-68qs.mjs.map +1 -0
  21. package/{identity-BA1-EGoN.mjs → identity-W03yrB1j.mjs} +2 -2
  22. package/{identity-BA1-EGoN.mjs.map → identity-W03yrB1j.mjs.map} +1 -1
  23. package/index.mjs +41 -25
  24. package/index.mjs.map +1 -1
  25. package/{install-BLRDBzp1.mjs → install-Dqx1TWtz.mjs} +4 -4
  26. package/{install-BLRDBzp1.mjs.map → install-Dqx1TWtz.mjs.map} +1 -1
  27. package/jsonc-BwztMdEB.mjs +58 -0
  28. package/jsonc-BwztMdEB.mjs.map +1 -0
  29. package/{link--UnM2qnT.mjs → link-BilIb5jN.mjs} +3 -3
  30. package/{link--UnM2qnT.mjs.map → link-BilIb5jN.mjs.map} +1 -1
  31. package/list-BUPm4Bsu.mjs +71 -0
  32. package/list-BUPm4Bsu.mjs.map +1 -0
  33. package/list-BdMdlBjQ.mjs +36 -0
  34. package/list-BdMdlBjQ.mjs.map +1 -0
  35. package/{list-BE4xSEe3.mjs → list-D1sa8t4P.mjs} +4 -4
  36. package/{list-BE4xSEe3.mjs.map → list-D1sa8t4P.mjs.map} +1 -1
  37. package/{list-9fVqelid.mjs → list-DV3VGuTp.mjs} +4 -4
  38. package/{list-9fVqelid.mjs.map → list-DV3VGuTp.mjs.map} +1 -1
  39. package/login-COjr-kTw.mjs +59 -0
  40. package/login-COjr-kTw.mjs.map +1 -0
  41. package/{login-CRwxi5WD.mjs → login-DC6bw2pG.mjs} +4 -4
  42. package/{login-CRwxi5WD.mjs.map → login-DC6bw2pG.mjs.map} +1 -1
  43. package/{logout-C89X0B9M.mjs → logout-CfyRsTUE.mjs} +4 -4
  44. package/{logout-C89X0B9M.mjs.map → logout-CfyRsTUE.mjs.map} +1 -1
  45. package/logout-D02BdsX6.mjs +17 -0
  46. package/logout-D02BdsX6.mjs.map +1 -0
  47. package/package-Bw5VboWd.mjs +6 -0
  48. package/package-Bw5VboWd.mjs.map +1 -0
  49. package/package.json +4 -4
  50. package/{providers-BrXJvY2P.mjs → providers-8XcCtqG7.mjs} +4 -4
  51. package/{providers-BrXJvY2P.mjs.map → providers-8XcCtqG7.mjs.map} +1 -1
  52. package/reconnect-C4KrnFkT.mjs +2 -0
  53. package/{refresh-D0wBP2Go.mjs → refresh-CPt2ua-n.mjs} +4 -4
  54. package/{refresh-D0wBP2Go.mjs.map → refresh-CPt2ua-n.mjs.map} +1 -1
  55. package/{refresh--j0Pj4Cw.mjs → refresh-zDPc39tX.mjs} +4 -4
  56. package/{refresh--j0Pj4Cw.mjs.map → refresh-zDPc39tX.mjs.map} +1 -1
  57. package/relink-Cr5T6W7K.mjs +23 -0
  58. package/relink-Cr5T6W7K.mjs.map +1 -0
  59. package/{reload-DgPawyzr.mjs → reload-xhRj21Ic.mjs} +3 -3
  60. package/{reload-DgPawyzr.mjs.map → reload-xhRj21Ic.mjs.map} +1 -1
  61. package/remove-BuO_0yjy.mjs +26 -0
  62. package/remove-BuO_0yjy.mjs.map +1 -0
  63. package/{remove-DfFme5w2.mjs → remove-DRBU8YfV.mjs} +4 -4
  64. package/{remove-DfFme5w2.mjs.map → remove-DRBU8YfV.mjs.map} +1 -1
  65. package/{restart-DDrkmn2h.mjs → restart-B_Cuf5vn.mjs} +4 -4
  66. package/{restart-DDrkmn2h.mjs.map → restart-B_Cuf5vn.mjs.map} +1 -1
  67. package/{run-CVRkm_Iz.mjs → run-B3acSsVy.mjs} +34 -18
  68. package/run-B3acSsVy.mjs.map +1 -0
  69. package/{runtime-B43doHjV.mjs → runtime-CwoLsQy7.mjs} +173 -3
  70. package/runtime-CwoLsQy7.mjs.map +1 -0
  71. package/{serve-DDw1dCvW.mjs → serve-PS5XsA4y.mjs} +122 -75
  72. package/serve-PS5XsA4y.mjs.map +1 -0
  73. package/{service-DJR6nPam.mjs → service-DR7kmnwi.mjs} +3 -3
  74. package/{service-DJR6nPam.mjs.map → service-DR7kmnwi.mjs.map} +1 -1
  75. package/{settings-BfmoL27m.mjs → settings-Ct8kxLeD.mjs} +8 -36
  76. package/settings-Ct8kxLeD.mjs.map +1 -0
  77. package/shared-5A9FR7Lo.mjs +88 -0
  78. package/shared-5A9FR7Lo.mjs.map +1 -0
  79. package/{shared-CnuCjvcG.mjs → shared-CfaUYDk4.mjs} +3 -3
  80. package/{shared-CnuCjvcG.mjs.map → shared-CfaUYDk4.mjs.map} +1 -1
  81. package/{start-DwhV9ucd.mjs → start-D22ugY3U.mjs} +4 -4
  82. package/{start-DwhV9ucd.mjs.map → start-D22ugY3U.mjs.map} +1 -1
  83. package/{status-DVzFDoek.mjs → status-DDhz93PH.mjs} +4 -4
  84. package/{status-DVzFDoek.mjs.map → status-DDhz93PH.mjs.map} +1 -1
  85. package/{status-Bklxb3u6.mjs → status-Jc_6Vlia.mjs} +4 -4
  86. package/{status-Bklxb3u6.mjs.map → status-Jc_6Vlia.mjs.map} +1 -1
  87. package/{stop-DI91UvG_.mjs → stop-BlpzoWlh.mjs} +4 -4
  88. package/{stop-DI91UvG_.mjs.map → stop-BlpzoWlh.mjs.map} +1 -1
  89. package/thread-skUkybyv.mjs +15 -0
  90. package/thread-skUkybyv.mjs.map +1 -0
  91. package/{tui-Cdim7SjU.mjs → tui-B8dgX8RJ.mjs} +5 -5
  92. package/{tui-Cdim7SjU.mjs.map → tui-B8dgX8RJ.mjs.map} +1 -1
  93. package/{update-D0XPVfJu.mjs → update-oK_209iL.mjs} +4 -4
  94. package/{update-D0XPVfJu.mjs.map → update-oK_209iL.mjs.map} +1 -1
  95. package/acp-JnyJmRCD.mjs.map +0 -1
  96. package/add-Dzsv-fKd.mjs.map +0 -1
  97. package/error-BMI81XvR.mjs.map +0 -1
  98. package/package-Bi5FfVSP.mjs +0 -6
  99. package/package-Bi5FfVSP.mjs.map +0 -1
  100. package/run-CVRkm_Iz.mjs.map +0 -1
  101. package/runtime-B43doHjV.mjs.map +0 -1
  102. package/serve-DDw1dCvW.mjs.map +0 -1
  103. package/settings-BfmoL27m.mjs.map +0 -1
@@ -0,0 +1,31 @@
1
+ import { i as Cmd, t as handler } from "./runtime-CwoLsQy7.mjs";
2
+ import { f as writeOut, i as reportFailure, m as make, p as layer } from "./error-BVSfzBzb.mjs";
3
+ import { r as describe, t as MARKS } from "./shared-5A9FR7Lo.mjs";
4
+ import { t as threadFlag } from "./thread-skUkybyv.mjs";
5
+ import { Effect } from "effect";
6
+ import { Session } from "@codeworksh/harness/effect";
7
+ //#region src/cli/cmd/handlers/mcp/control.ts
8
+ /**
9
+ * `reconnect` and `disconnect`: one RPC on a thread's server in a running server, which acts on the
10
+ * instance every thread sharing it uses. Exits 1 when the server did not end up as asked.
11
+ */
12
+ const control = (operation) => Effect.fn(`CLI.mcp.${operation}`)(function* ({ name, session, thread, server }) {
13
+ return yield* Effect.gen(function* () {
14
+ const threadId = yield* threadFlag(thread);
15
+ const status = yield* (yield* make)[`mcp.${operation}`]({
16
+ sessionId: Session.SessionSchema.ID.make(session),
17
+ ...threadId === void 0 ? {} : { threadId },
18
+ server: name
19
+ });
20
+ const lines = [`${MARKS[status.state]} ${status.server} ${describe(status.state, status.tools.length, status.skipped)}`];
21
+ if (status.error !== void 0) for (const line of status.error.split("\n")) lines.push(` ${line}`);
22
+ yield* writeOut(`${lines.join("\n")}\n`);
23
+ if (status.state !== (operation === "connect" ? "connected" : "disconnected")) process.exitCode = 1;
24
+ }).pipe(Effect.provide(layer(server)), Effect.scoped, Effect.catch(reportFailure));
25
+ });
26
+ const reconnect = handler(Cmd.commands.mcp.commands.reconnect, control("connect"));
27
+ const disconnect = handler(Cmd.commands.mcp.commands.disconnect, control("disconnect"));
28
+ //#endregion
29
+ export { reconnect as n, disconnect as t };
30
+
31
+ //# sourceMappingURL=control-Bd2G-Unk.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"control-Bd2G-Unk.mjs","names":["Client.make","Client.layer","Runtime.handler"],"sources":["../../src/cli/cmd/handlers/mcp/control.ts"],"sourcesContent":["import { Session } from \"@codeworksh/harness/effect\";\nimport { Effect, type Option } from \"effect\";\nimport { Runtime } from \"../../../../framework/runtime.ts\";\nimport { Client } from \"../../../../server/client.ts\";\nimport { reportFailure } from \"../../../error.ts\";\nimport { writeOut } from \"../../../output.ts\";\nimport { threadFlag } from \"../../../thread.ts\";\nimport { Cmd } from \"../../cmd.ts\";\nimport { describe, MARKS } from \"./shared.ts\";\n\n/**\n * `reconnect` and `disconnect`: one RPC on a thread's server in a running server, which acts on the\n * instance every thread sharing it uses. Exits 1 when the server did not end up as asked.\n */\nexport const control = (operation: \"connect\" | \"disconnect\") =>\n\tEffect.fn(`CLI.mcp.${operation}`)(function* ({\n\t\tname,\n\t\tsession,\n\t\tthread,\n\t\tserver,\n\t}: {\n\t\treadonly name: string;\n\t\treadonly session: string;\n\t\treadonly thread: Option.Option<string>;\n\t\treadonly server: string;\n\t}) {\n\t\tconst program = Effect.gen(function* () {\n\t\t\tconst threadId = yield* threadFlag(thread);\n\t\t\tconst rpc = yield* Client.make;\n\t\t\tconst status = yield* rpc[`mcp.${operation}`]({\n\t\t\t\tsessionId: Session.SessionSchema.ID.make(session),\n\t\t\t\t...(threadId === undefined ? {} : { threadId }),\n\t\t\t\tserver: name,\n\t\t\t});\n\t\t\tconst lines = [\n\t\t\t\t`${MARKS[status.state]} ${status.server} ${describe(status.state, status.tools.length, status.skipped)}`,\n\t\t\t];\n\t\t\tif (status.error !== undefined) for (const line of status.error.split(\"\\n\")) lines.push(` ${line}`);\n\t\t\tyield* writeOut(`${lines.join(\"\\n\")}\\n`);\n\t\t\tif (status.state !== (operation === \"connect\" ? \"connected\" : \"disconnected\")) process.exitCode = 1;\n\t\t});\n\t\treturn yield* program.pipe(Effect.provide(Client.layer(server)), Effect.scoped, Effect.catch(reportFailure));\n\t});\n\nexport const reconnect = Runtime.handler(Cmd.commands.mcp.commands.reconnect, control(\"connect\"));\nexport const disconnect = Runtime.handler(Cmd.commands.mcp.commands.disconnect, control(\"disconnect\"));\n"],"mappings":";;;;;;;;;;;AAcA,MAAa,WAAW,cACvB,OAAO,GAAG,WAAW,WAAW,CAAC,CAAC,WAAW,EAC5C,MACA,SACA,QACA,UAME;CAgBF,OAAO,OAfS,OAAO,IAAI,aAAa;EACvC,MAAM,WAAW,OAAO,WAAW,MAAM;EAEzC,MAAM,SAAS,QAAO,OADHA,KAAAA,CACO,OAAO,YAAY,CAAC;GAC7C,WAAW,QAAQ,cAAc,GAAG,KAAK,OAAO;GAChD,GAAI,aAAa,KAAA,IAAY,CAAC,IAAI,EAAE,SAAS;GAC7C,QAAQ;EACT,CAAC;EACD,MAAM,QAAQ,CACb,GAAG,MAAM,OAAO,OAAO,GAAG,OAAO,OAAO,IAAI,SAAS,OAAO,OAAO,OAAO,MAAM,QAAQ,OAAO,OAAO,GACvG;EACA,IAAI,OAAO,UAAU,KAAA,GAAW,KAAK,MAAM,QAAQ,OAAO,MAAM,MAAM,IAAI,GAAG,MAAM,KAAK,OAAO,MAAM;EACrG,OAAO,SAAS,GAAG,MAAM,KAAK,IAAI,EAAE,GAAG;EACvC,IAAI,OAAO,WAAW,cAAc,YAAY,cAAc,iBAAiB,QAAQ,WAAW;CACnG,CACoB,CAAC,CAAC,KAAK,OAAO,QAAQC,MAAa,MAAM,CAAC,GAAG,OAAO,QAAQ,OAAO,MAAM,aAAa,CAAC;AAC5G,CAAC;AAEF,MAAa,YAAYC,QAAgB,IAAI,SAAS,IAAI,SAAS,WAAW,QAAQ,SAAS,CAAC;AAChG,MAAa,aAAaA,QAAgB,IAAI,SAAS,IAAI,SAAS,YAAY,QAAQ,YAAY,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { t as disconnect } from "./control-Bd2G-Unk.mjs";
2
+ export { disconnect as default };
@@ -1,5 +1,5 @@
1
- import { d as writeOut } from "./error-BMI81XvR.mjs";
2
- import { s as userLayer } from "./settings-BfmoL27m.mjs";
1
+ import { f as writeOut } from "./error-BVSfzBzb.mjs";
2
+ import { s as userLayer } from "./settings-Ct8kxLeD.mjs";
3
3
  import { Effect, Option, Path } from "effect";
4
4
  import { Global, Plugin, Settings } from "@codeworksh/harness/effect";
5
5
  //#region src/cli/cmd/handlers/plugin/entries.ts
@@ -87,4 +87,4 @@ const fetchable = (target) => target === void 0 || target.kind === "local" ? voi
87
87
  //#endregion
88
88
  export { targeted as a, read as i, local as n, probe as r, fetchable as t };
89
89
 
90
- //# sourceMappingURL=entries-KpYvZdpi.mjs.map
90
+ //# sourceMappingURL=entries-hMxcOaPm.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"entries-KpYvZdpi.mjs","names":[],"sources":["../../src/cli/cmd/handlers/plugin/entries.ts"],"sourcesContent":["import { Global, Plugin, Settings } from \"@codeworksh/harness/effect\";\nimport { Effect, Option, Path } from \"effect\";\nimport { writeOut } from \"../../../output.ts\";\nimport { userLayer, type Shared } from \"./settings.ts\";\n\n/**\n * Every plugin entry the settings files name, across every layer, in the order they accumulate.\n *\n * This is what `install`, `list`, `check` and `update` all operate on: unlike `add` and `remove`,\n * none of them writes an entry. They read what is already there and act on the store -- each one\n * under the `.npmrc` context of the file that declared it, which is what keys the artifact.\n */\nexport interface Entry {\n\t/** The reference as the settings file spells it: the string a person will search for. */\n\treadonly written: string;\n\t/** The same reference, anchored to the file that declared it. This is what resolves. */\n\treadonly reference: string;\n\t/** Which settings file owns it: the last to declare it in the view that needs it. */\n\treadonly file: string;\n\t/**\n\t * The `.npmrc` anchor for the entry's store identity: the project that declared it, so the\n\t * registry context is the same wherever this command happens to run.\n\t */\n\treadonly from: string;\n\t/** Absent for an unparseable entry and for a local path. */\n\treadonly target: Plugin.Target | undefined;\n}\n\n/** Only a string entry loads a module; `{ package }` is configuration for one already selected. */\nconst moduleOf = (entry: unknown): string | undefined => (typeof entry === \"string\" ? entry : undefined);\n\nexport const read = Effect.fn(\"CLI.plugin.entries\")(function* (shared: Shared) {\n\tconst nodePath = yield* Path.Path;\n\t// The directory the command runs in resolves its app-level flags. No session links it to\n\t// another host directory, so it is the command's anchor too: project settings are discovered\n\t// from here, and a relative spec typed here resolves here.\n\tconst hostCwd = nodePath.resolve(\".\");\n\tconst hostDir = hostCwd;\n\tconst paths = yield* Global.resolve(Option.isNone(shared.home) ? {} : { home: shared.home.value });\n\tconst root = yield* Settings.projectRoot(hostDir, paths.home);\n\tconst layers = { home: paths.home, ...userLayer(shared, hostCwd) };\n\t/*\n\t * The runtime resolves plugins in two views, and each needs its own artifact on disk: boot\n\t * reads the user layers alone, and a session reads every layer. Within a view the last file to\n\t * declare a reference owns it, so a spec both layers name is owned by the user file at boot and\n\t * by the project file in the project's sessions -- two `.npmrc` anchors, and possibly two\n\t * registries. Collapsing it to one owner leaves one of those views without its artifact.\n\t */\n\tconst boot = yield* Settings.load(layers);\n\tconst views = root === undefined ? [boot] : [boot, yield* Settings.load({ ...layers, hostDir: root })];\n\n\t// One entry per store artifact, so two anchors on one registry stay a single line. A later\n\t// view names the file, which is the one a person in this project would edit.\n\tconst entries = new Map<string, Entry>();\n\tfor (const view of views) {\n\t\t// views is [boot] outside a project, or [boot, session] inside one.\n\t\t// Boot comes first, and the order matters (see below).\n\t\tfor (const [reference, one] of Settings.modules(view.declared)) {\n\t\t\t// Already anchored to the file that declared it, so `hostDir` here only affects a\n\t\t\t// reference no settings file produced.\n\t\t\tconst target = Option.getOrUndefined(yield* Plugin.parse(reference, hostDir).pipe(Effect.option));\n\t\t\tconst from = Plugin.anchor(one.file, hostDir);\n\t\t\tconst key = yield* identity(target, reference, from, paths.cache);\n\t\t\tentries.set(key, { written: moduleOf(one.written) ?? reference, reference, file: one.file, from, target });\n\t\t}\n\t}\n\treturn { entries: [...entries.values()] as ReadonlyArray<Entry>, cache: paths.cache, hostDir };\n});\n\n/**\n * What makes two entries one artifact: the store's own key for a fetched target, the file for a\n * local one. A registry that cannot be read keeps the entry apart, so its install reports why.\n */\nconst identity = (target: Plugin.Target | undefined, reference: string, from: string, cache: string) => {\n\tconst fetched = fetchable(target);\n\tif (fetched === undefined) return Effect.succeed(target?.kind === \"local\" ? target.path : reference);\n\treturn Plugin.identity(fetched, cache, from).pipe(Effect.orElseSucceed(() => `${reference}\\0${from}`));\n};\n\n/** What a reference names, whatever version it was written with: a package, a git spec, a file. */\nconst source = (reference: string, hostDir: string) =>\n\tPlugin.canonical(reference, hostDir).pipe(Effect.orElseSucceed(() => reference));\n\n/**\n * The entries a command acts on: all of them, or every one `spec` names.\n *\n * Matched by source identity, the way the `plugins` array reads -- `@acme/x` selects\n * `@acme/x@^1`, a relative path selects the file it resolves to from `hostDir`, and a local package\n * also answers to the name its `package.json` declares. A plugin ID is not a spelling of anything\n * in that array, so it matches nothing. Every match is kept: a spec both layers declare under\n * different registries is two artifacts, and both answer to it.\n */\nexport const targeted = Effect.fn(\"CLI.plugin.targeted\")(function* (\n\tentries: ReadonlyArray<Entry>,\n\tspec: Option.Option<string>,\n\t/** The host directory the command resolves from, which a relative spec is typed against. */\n\thostDir: string,\n) {\n\tif (Option.isNone(spec)) return entries;\n\tconst wanted = yield* source(spec.value, hostDir);\n\tconst selected: Entry[] = [];\n\tfor (const entry of entries) {\n\t\tconst named =\n\t\t\t(yield* source(entry.reference, hostDir)) === wanted ||\n\t\t\t(entry.target?.kind === \"local\" && (yield* Plugin.localName(entry.target.path)) === wanted);\n\t\tif (named) selected.push(entry);\n\t}\n\tif (selected.length === 0) {\n\t\tyield* writeOut(`Plugin \"${spec.value}\" is not configured. Run \\`codework plugin list\\` to see what is.\\n`);\n\t\tprocess.exitCode = 1;\n\t}\n\treturn selected as ReadonlyArray<Entry>;\n});\n\n/**\n * A local plugin has no revision to compare and is never copied into the store. Skipped quietly\n * when a command walks everything; named, it says why nothing happened.\n */\nexport const local = (entry: Entry, spec: Option.Option<string>) =>\n\tOption.isSome(spec) ? writeOut(`${entry.reference} local: no remote revision to compare\\n`) : Effect.void;\n\n/**\n * The network half, handed to the store so the store itself never opens a socket.\n *\n * `probe` bypasses pacote's own metadata cache, because a staleness check that reads a cache is\n * not a staleness check. `from` is the host directory: a probe that read a different `.npmrc`\n * chain than the install would answer about a registry nothing is ever fetched from.\n */\nexport const probe =\n\t(cache: string, from: string): Plugin.Probe =>\n\t(target) =>\n\t\tPlugin.probe(target, cache, from);\n\n/** Only a fetched target has a store entry; a local one is loaded where it lies. */\nexport const fetchable = (target: Plugin.Target | undefined): Plugin.Fetchable | undefined =>\n\ttarget === undefined || target.kind === \"local\" ? undefined : target;\n"],"mappings":";;;;;;AA6BA,MAAM,YAAY,UAAwC,OAAO,UAAU,WAAW,QAAQ,KAAA;AAE9F,MAAa,OAAO,OAAO,GAAG,oBAAoB,CAAC,CAAC,WAAW,QAAgB;CAK9E,MAAM,WAAU,OAJQ,KAAK,KAAA,CAIJ,QAAQ,GAAG;CACpC,MAAM,UAAU;CAChB,MAAM,QAAQ,OAAO,OAAO,QAAQ,OAAO,OAAO,OAAO,IAAI,IAAI,CAAC,IAAI,EAAE,MAAM,OAAO,KAAK,MAAM,CAAC;CACjG,MAAM,OAAO,OAAO,SAAS,YAAY,SAAS,MAAM,IAAI;CAC5D,MAAM,SAAS;EAAE,MAAM,MAAM;EAAM,GAAG,UAAU,QAAQ,OAAO;CAAE;CAQjE,MAAM,OAAO,OAAO,SAAS,KAAK,MAAM;CACxC,MAAM,QAAQ,SAAS,KAAA,IAAY,CAAC,IAAI,IAAI,CAAC,MAAM,OAAO,SAAS,KAAK;EAAE,GAAG;EAAQ,SAAS;CAAK,CAAC,CAAC;CAIrG,MAAM,0BAAU,IAAI,IAAmB;CACvC,KAAK,MAAM,QAAQ,OAGlB,KAAK,MAAM,CAAC,WAAW,QAAQ,SAAS,QAAQ,KAAK,QAAQ,GAAG;EAG/D,MAAM,SAAS,OAAO,eAAe,OAAO,OAAO,MAAM,WAAW,OAAO,CAAC,CAAC,KAAK,OAAO,MAAM,CAAC;EAChG,MAAM,OAAO,OAAO,OAAO,IAAI,MAAM,OAAO;EAC5C,MAAM,MAAM,OAAO,SAAS,QAAQ,WAAW,MAAM,MAAM,KAAK;EAChE,QAAQ,IAAI,KAAK;GAAE,SAAS,SAAS,IAAI,OAAO,KAAK;GAAW;GAAW,MAAM,IAAI;GAAM;GAAM;EAAO,CAAC;CAC1G;CAED,OAAO;EAAE,SAAS,CAAC,GAAG,QAAQ,OAAO,CAAC;EAA2B,OAAO,MAAM;EAAO;CAAQ;AAC9F,CAAC;;;;;AAMD,MAAM,YAAY,QAAmC,WAAmB,MAAc,UAAkB;CACvG,MAAM,UAAU,UAAU,MAAM;CAChC,IAAI,YAAY,KAAA,GAAW,OAAO,OAAO,QAAQ,QAAQ,SAAS,UAAU,OAAO,OAAO,SAAS;CACnG,OAAO,OAAO,SAAS,SAAS,OAAO,IAAI,CAAC,CAAC,KAAK,OAAO,oBAAoB,GAAG,UAAU,IAAI,MAAM,CAAC;AACtG;;AAGA,MAAM,UAAU,WAAmB,YAClC,OAAO,UAAU,WAAW,OAAO,CAAC,CAAC,KAAK,OAAO,oBAAoB,SAAS,CAAC;;;;;;;;;;AAWhF,MAAa,WAAW,OAAO,GAAG,qBAAqB,CAAC,CAAC,WACxD,SACA,MAEA,SACC;CACD,IAAI,OAAO,OAAO,IAAI,GAAG,OAAO;CAChC,MAAM,SAAS,OAAO,OAAO,KAAK,OAAO,OAAO;CAChD,MAAM,WAAoB,CAAC;CAC3B,KAAK,MAAM,SAAS,SAInB,KAFE,OAAO,OAAO,MAAM,WAAW,OAAO,OAAO,UAC7C,MAAM,QAAQ,SAAS,YAAY,OAAO,OAAO,UAAU,MAAM,OAAO,IAAI,OAAO,QAC1E,SAAS,KAAK,KAAK;CAE/B,IAAI,SAAS,WAAW,GAAG;EAC1B,OAAO,SAAS,WAAW,KAAK,MAAM,oEAAoE;EAC1G,QAAQ,WAAW;CACpB;CACA,OAAO;AACR,CAAC;;;;;AAMD,MAAa,SAAS,OAAc,SACnC,OAAO,OAAO,IAAI,IAAI,SAAS,GAAG,MAAM,UAAU,yCAAyC,IAAI,OAAO;;;;;;;;AASvG,MAAa,SACX,OAAe,UACf,WACA,OAAO,MAAM,QAAQ,OAAO,IAAI;;AAGlC,MAAa,aAAa,WACzB,WAAW,KAAA,KAAa,OAAO,SAAS,UAAU,KAAA,IAAY"}
1
+ {"version":3,"file":"entries-hMxcOaPm.mjs","names":[],"sources":["../../src/cli/cmd/handlers/plugin/entries.ts"],"sourcesContent":["import { Global, Plugin, Settings } from \"@codeworksh/harness/effect\";\nimport { Effect, Option, Path } from \"effect\";\nimport { writeOut } from \"../../../output.ts\";\nimport { userLayer, type Shared } from \"./settings.ts\";\n\n/**\n * Every plugin entry the settings files name, across every layer, in the order they accumulate.\n *\n * This is what `install`, `list`, `check` and `update` all operate on: unlike `add` and `remove`,\n * none of them writes an entry. They read what is already there and act on the store -- each one\n * under the `.npmrc` context of the file that declared it, which is what keys the artifact.\n */\nexport interface Entry {\n\t/** The reference as the settings file spells it: the string a person will search for. */\n\treadonly written: string;\n\t/** The same reference, anchored to the file that declared it. This is what resolves. */\n\treadonly reference: string;\n\t/** Which settings file owns it: the last to declare it in the view that needs it. */\n\treadonly file: string;\n\t/**\n\t * The `.npmrc` anchor for the entry's store identity: the project that declared it, so the\n\t * registry context is the same wherever this command happens to run.\n\t */\n\treadonly from: string;\n\t/** Absent for an unparseable entry and for a local path. */\n\treadonly target: Plugin.Target | undefined;\n}\n\n/** Only a string entry loads a module; `{ package }` is configuration for one already selected. */\nconst moduleOf = (entry: unknown): string | undefined => (typeof entry === \"string\" ? entry : undefined);\n\nexport const read = Effect.fn(\"CLI.plugin.entries\")(function* (shared: Shared) {\n\tconst nodePath = yield* Path.Path;\n\t// The directory the command runs in resolves its app-level flags. No session links it to\n\t// another host directory, so it is the command's anchor too: project settings are discovered\n\t// from here, and a relative spec typed here resolves here.\n\tconst hostCwd = nodePath.resolve(\".\");\n\tconst hostDir = hostCwd;\n\tconst paths = yield* Global.resolve(Option.isNone(shared.home) ? {} : { home: shared.home.value });\n\tconst root = yield* Settings.projectRoot(hostDir, paths.home);\n\tconst layers = { home: paths.home, ...userLayer(shared, hostCwd) };\n\t/*\n\t * The runtime resolves plugins in two views, and each needs its own artifact on disk: boot\n\t * reads the user layers alone, and a session reads every layer. Within a view the last file to\n\t * declare a reference owns it, so a spec both layers name is owned by the user file at boot and\n\t * by the project file in the project's sessions -- two `.npmrc` anchors, and possibly two\n\t * registries. Collapsing it to one owner leaves one of those views without its artifact.\n\t */\n\tconst boot = yield* Settings.load(layers);\n\tconst views = root === undefined ? [boot] : [boot, yield* Settings.load({ ...layers, hostDir: root })];\n\n\t// One entry per store artifact, so two anchors on one registry stay a single line. A later\n\t// view names the file, which is the one a person in this project would edit.\n\tconst entries = new Map<string, Entry>();\n\tfor (const view of views) {\n\t\t// views is [boot] outside a project, or [boot, session] inside one.\n\t\t// Boot comes first, and the order matters (see below).\n\t\tfor (const [reference, one] of Settings.modules(view.declared)) {\n\t\t\t// Already anchored to the file that declared it, so `hostDir` here only affects a\n\t\t\t// reference no settings file produced.\n\t\t\tconst target = Option.getOrUndefined(yield* Plugin.parse(reference, hostDir).pipe(Effect.option));\n\t\t\tconst from = Plugin.anchor(one.file, hostDir);\n\t\t\tconst key = yield* identity(target, reference, from, paths.cache);\n\t\t\tentries.set(key, { written: moduleOf(one.written) ?? reference, reference, file: one.file, from, target });\n\t\t}\n\t}\n\treturn { entries: [...entries.values()] as ReadonlyArray<Entry>, cache: paths.cache, hostDir };\n});\n\n/**\n * What makes two entries one artifact: the store's own key for a fetched target, the file for a\n * local one. A registry that cannot be read keeps the entry apart, so its install reports why.\n */\nconst identity = (target: Plugin.Target | undefined, reference: string, from: string, cache: string) => {\n\tconst fetched = fetchable(target);\n\tif (fetched === undefined) return Effect.succeed(target?.kind === \"local\" ? target.path : reference);\n\treturn Plugin.identity(fetched, cache, from).pipe(Effect.orElseSucceed(() => `${reference}\\0${from}`));\n};\n\n/** What a reference names, whatever version it was written with: a package, a git spec, a file. */\nconst source = (reference: string, hostDir: string) =>\n\tPlugin.canonical(reference, hostDir).pipe(Effect.orElseSucceed(() => reference));\n\n/**\n * The entries a command acts on: all of them, or every one `spec` names.\n *\n * Matched by source identity, the way the `plugins` array reads -- `@acme/x` selects\n * `@acme/x@^1`, a relative path selects the file it resolves to from `hostDir`, and a local package\n * also answers to the name its `package.json` declares. A plugin ID is not a spelling of anything\n * in that array, so it matches nothing. Every match is kept: a spec both layers declare under\n * different registries is two artifacts, and both answer to it.\n */\nexport const targeted = Effect.fn(\"CLI.plugin.targeted\")(function* (\n\tentries: ReadonlyArray<Entry>,\n\tspec: Option.Option<string>,\n\t/** The host directory the command resolves from, which a relative spec is typed against. */\n\thostDir: string,\n) {\n\tif (Option.isNone(spec)) return entries;\n\tconst wanted = yield* source(spec.value, hostDir);\n\tconst selected: Entry[] = [];\n\tfor (const entry of entries) {\n\t\tconst named =\n\t\t\t(yield* source(entry.reference, hostDir)) === wanted ||\n\t\t\t(entry.target?.kind === \"local\" && (yield* Plugin.localName(entry.target.path)) === wanted);\n\t\tif (named) selected.push(entry);\n\t}\n\tif (selected.length === 0) {\n\t\tyield* writeOut(`Plugin \"${spec.value}\" is not configured. Run \\`codework plugin list\\` to see what is.\\n`);\n\t\tprocess.exitCode = 1;\n\t}\n\treturn selected as ReadonlyArray<Entry>;\n});\n\n/**\n * A local plugin has no revision to compare and is never copied into the store. Skipped quietly\n * when a command walks everything; named, it says why nothing happened.\n */\nexport const local = (entry: Entry, spec: Option.Option<string>) =>\n\tOption.isSome(spec) ? writeOut(`${entry.reference} local: no remote revision to compare\\n`) : Effect.void;\n\n/**\n * The network half, handed to the store so the store itself never opens a socket.\n *\n * `probe` bypasses pacote's own metadata cache, because a staleness check that reads a cache is\n * not a staleness check. `from` is the host directory: a probe that read a different `.npmrc`\n * chain than the install would answer about a registry nothing is ever fetched from.\n */\nexport const probe =\n\t(cache: string, from: string): Plugin.Probe =>\n\t(target) =>\n\t\tPlugin.probe(target, cache, from);\n\n/** Only a fetched target has a store entry; a local one is loaded where it lies. */\nexport const fetchable = (target: Plugin.Target | undefined): Plugin.Fetchable | undefined =>\n\ttarget === undefined || target.kind === \"local\" ? undefined : target;\n"],"mappings":";;;;;;AA6BA,MAAM,YAAY,UAAwC,OAAO,UAAU,WAAW,QAAQ,KAAA;AAE9F,MAAa,OAAO,OAAO,GAAG,oBAAoB,CAAC,CAAC,WAAW,QAAgB;CAK9E,MAAM,WAAU,OAJQ,KAAK,KAAA,CAIJ,QAAQ,GAAG;CACpC,MAAM,UAAU;CAChB,MAAM,QAAQ,OAAO,OAAO,QAAQ,OAAO,OAAO,OAAO,IAAI,IAAI,CAAC,IAAI,EAAE,MAAM,OAAO,KAAK,MAAM,CAAC;CACjG,MAAM,OAAO,OAAO,SAAS,YAAY,SAAS,MAAM,IAAI;CAC5D,MAAM,SAAS;EAAE,MAAM,MAAM;EAAM,GAAG,UAAU,QAAQ,OAAO;CAAE;CAQjE,MAAM,OAAO,OAAO,SAAS,KAAK,MAAM;CACxC,MAAM,QAAQ,SAAS,KAAA,IAAY,CAAC,IAAI,IAAI,CAAC,MAAM,OAAO,SAAS,KAAK;EAAE,GAAG;EAAQ,SAAS;CAAK,CAAC,CAAC;CAIrG,MAAM,0BAAU,IAAI,IAAmB;CACvC,KAAK,MAAM,QAAQ,OAGlB,KAAK,MAAM,CAAC,WAAW,QAAQ,SAAS,QAAQ,KAAK,QAAQ,GAAG;EAG/D,MAAM,SAAS,OAAO,eAAe,OAAO,OAAO,MAAM,WAAW,OAAO,CAAC,CAAC,KAAK,OAAO,MAAM,CAAC;EAChG,MAAM,OAAO,OAAO,OAAO,IAAI,MAAM,OAAO;EAC5C,MAAM,MAAM,OAAO,SAAS,QAAQ,WAAW,MAAM,MAAM,KAAK;EAChE,QAAQ,IAAI,KAAK;GAAE,SAAS,SAAS,IAAI,OAAO,KAAK;GAAW;GAAW,MAAM,IAAI;GAAM;GAAM;EAAO,CAAC;CAC1G;CAED,OAAO;EAAE,SAAS,CAAC,GAAG,QAAQ,OAAO,CAAC;EAA2B,OAAO,MAAM;EAAO;CAAQ;AAC9F,CAAC;;;;;AAMD,MAAM,YAAY,QAAmC,WAAmB,MAAc,UAAkB;CACvG,MAAM,UAAU,UAAU,MAAM;CAChC,IAAI,YAAY,KAAA,GAAW,OAAO,OAAO,QAAQ,QAAQ,SAAS,UAAU,OAAO,OAAO,SAAS;CACnG,OAAO,OAAO,SAAS,SAAS,OAAO,IAAI,CAAC,CAAC,KAAK,OAAO,oBAAoB,GAAG,UAAU,IAAI,MAAM,CAAC;AACtG;;AAGA,MAAM,UAAU,WAAmB,YAClC,OAAO,UAAU,WAAW,OAAO,CAAC,CAAC,KAAK,OAAO,oBAAoB,SAAS,CAAC;;;;;;;;;;AAWhF,MAAa,WAAW,OAAO,GAAG,qBAAqB,CAAC,CAAC,WACxD,SACA,MAEA,SACC;CACD,IAAI,OAAO,OAAO,IAAI,GAAG,OAAO;CAChC,MAAM,SAAS,OAAO,OAAO,KAAK,OAAO,OAAO;CAChD,MAAM,WAAoB,CAAC;CAC3B,KAAK,MAAM,SAAS,SAInB,KAFE,OAAO,OAAO,MAAM,WAAW,OAAO,OAAO,UAC7C,MAAM,QAAQ,SAAS,YAAY,OAAO,OAAO,UAAU,MAAM,OAAO,IAAI,OAAO,QAC1E,SAAS,KAAK,KAAK;CAE/B,IAAI,SAAS,WAAW,GAAG;EAC1B,OAAO,SAAS,WAAW,KAAK,MAAM,oEAAoE;EAC1G,QAAQ,WAAW;CACpB;CACA,OAAO;AACR,CAAC;;;;;AAMD,MAAa,SAAS,OAAc,SACnC,OAAO,OAAO,IAAI,IAAI,SAAS,GAAG,MAAM,UAAU,yCAAyC,IAAI,OAAO;;;;;;;;AASvG,MAAa,SACX,OAAe,UACf,WACA,OAAO,MAAM,QAAQ,OAAO,IAAI;;AAGlC,MAAa,aAAa,WACzB,WAAW,KAAA,KAAa,OAAO,SAAS,UAAU,KAAA,IAAY"}
@@ -1,6 +1,6 @@
1
1
  import { Deferred, Duration, Effect, Layer, Predicate, Schema, Stream } from "effect";
2
2
  import { Model } from "@codeworksh/aikit";
3
- import { Control, Event, EventList, EventSchema, Location, ModelCatalog, Plugin, Project, PromptSchema, Runner, Sandbox, SandboxError, Session, SessionStore, Settings, optional } from "@codeworksh/harness/effect";
3
+ import { Control, Event, EventList, EventSchema, Location, McpError, ModelCatalog, Plugin, Project, PromptSchema, Runner, Sandbox, SandboxError, Session, SessionStore, Settings, ThreadSchema, ThreadStore, optional } from "@codeworksh/harness/effect";
4
4
  import { SandboxProvider } from "@codeworksh/harness/sandbox";
5
5
  import { NodeSocket } from "@effect/platform-node";
6
6
  import { Rpc, RpcClient, RpcGroup, RpcSerialization } from "effect/rpc";
@@ -22,6 +22,8 @@ const EventEnvelope = Schema.Struct({
22
22
  metadata: optional(Schema.Record(Schema.String, Schema.String)),
23
23
  data: Schema.Unknown
24
24
  });
25
+ /** Whether an event belongs to a thread: every thread-scoped event names its `threadId`. */
26
+ const ofThread = (threadId) => (event) => Predicate.hasProperty(event.data, "threadId") && event.data.threadId === threadId;
25
27
  var UnknownEventTypeError = class extends Schema.TaggedError()("UnknownEventTypeError", { type: Schema.String }) {};
26
28
  /** The transport's own readiness frame; it has no meaning inside the harness. */
27
29
  const Connected = EventSchema.define({
@@ -135,9 +137,9 @@ const SandboxInfo = Schema.Struct({
135
137
  createdAt: Schema.DateFromString,
136
138
  updatedAt: Schema.DateFromString
137
139
  });
140
+ /** The container: where its threads run by default, and which host project it reads. */
138
141
  const SessionInfo = Schema.Struct({
139
142
  id: Session.SessionSchema.ID,
140
- title: Schema.String,
141
143
  directory: Session.AbsolutePath,
142
144
  /** The host directory this session is anchored to. Absent when it has none. */
143
145
  hostDir: optional(Session.AbsolutePath),
@@ -147,22 +149,75 @@ const SessionInfo = Schema.Struct({
147
149
  id: Schema.String,
148
150
  name: Schema.String
149
151
  })),
152
+ /** Last activity in any of its threads, epoch milliseconds. */
153
+ updatedAt: Schema.Finite,
154
+ /** Where unaddressed prompts go. */
155
+ mainThreadId: ThreadSchema.ID
156
+ });
157
+ const ThreadOrigin = Schema.Union([
158
+ Schema.Struct({ kind: Schema.Literal("main") }),
159
+ Schema.Struct({
160
+ kind: Schema.Literal("fork"),
161
+ threadId: Schema.String,
162
+ entryId: Schema.String
163
+ }),
164
+ Schema.Struct({
165
+ kind: Schema.Literal("subagent"),
166
+ threadId: Schema.String,
167
+ callId: Schema.String,
168
+ entryId: optional(Schema.String)
169
+ })
170
+ ]);
171
+ /** Billed usage of a thread's own entries; what it inherits through a fork point counts for its source. */
172
+ const ThreadUsage = Schema.Struct({
173
+ /** Total cost in US dollars, from the catalog's prices. */
174
+ cost: Schema.Finite,
175
+ input: Schema.Int,
176
+ output: Schema.Int,
177
+ cacheRead: Schema.Int,
178
+ cacheWrite: Schema.Int
179
+ });
180
+ /** One linear transcript of a session, with the session embedded. */
181
+ const ThreadInfo = Schema.Struct({
182
+ id: ThreadSchema.ID,
183
+ origin: ThreadOrigin,
184
+ /** Absent until its first own prompt; clients show a fork's source title until then. */
185
+ title: optional(Schema.String),
150
186
  /** Last activity, epoch milliseconds. */
151
187
  updatedAt: Schema.Finite,
152
- /** The model chosen for this session; absent when settings decide. */
188
+ /** The model chosen for this thread; absent when settings decide. */
153
189
  model: optional(Schema.Struct({
154
190
  provider: Schema.String,
155
191
  id: Schema.String
156
192
  })),
157
- /** The thinking level chosen for this session; absent when settings decide. */
193
+ /** The thinking level chosen for this thread; absent when settings decide. */
158
194
  thinkingLevel: optional(Schema.Enum(Model.ThinkingLevelEnum)),
159
- /** Its unfinished run was cut off by restarts too often to resume on its own; the next prompt runs it. */
160
- parked: optional(Schema.Boolean)
195
+ /** The prompt foundation chosen for this thread; absent when prompt plugins render it. */
196
+ foundation: optional(Schema.String),
197
+ /** Where it runs instead of the session's space and directory. */
198
+ placement: optional(Schema.Struct({
199
+ spaceId: Schema.String,
200
+ directory: Session.AbsolutePath
201
+ })),
202
+ usage: ThreadUsage,
203
+ session: SessionInfo
161
204
  });
162
- /** One message on a session's active branch, oldest first. */
205
+ /** A thread of a session: `threadId`, or the session's `main` thread when absent. */
206
+ const ThreadRef = {
207
+ sessionId: Session.SessionSchema.ID,
208
+ threadId: optional(ThreadSchema.ID)
209
+ };
210
+ /** A thread's MCP server, by the name its `mcp.json` gives it. */
211
+ const McpServerRef = {
212
+ ...ThreadRef,
213
+ server: Schema.String
214
+ };
215
+ /** One message in a thread's line (inherited ones first), oldest first. */
163
216
  const HistoryEntry = Schema.Struct({
164
- /** The entry id: what live events and `session.message` refer to. */
217
+ /** The entry id: what live events and `thread.message` refer to. */
165
218
  id: Schema.String,
219
+ /** The thread that wrote it: this one, or a source it was forked from. */
220
+ threadId: Schema.String,
166
221
  /** Its place in the session's durable log; live events continue from it. */
167
222
  seq: Schema.Int,
168
223
  role: Schema.Literals(["user", "assistant"]),
@@ -176,7 +231,9 @@ const HistoryEntry = Schema.Struct({
176
231
  createdAt: Schema.Finite,
177
232
  /** Epoch milliseconds of the last change; for a reply, when it ended once it is no longer a draft. */
178
233
  updatedAt: Schema.Finite,
179
- parts: Schema.Array(Part)
234
+ parts: Schema.Array(Part),
235
+ /** Why a reply failed, as `provider/model: reason`; absent for one that ended normally or was stopped. */
236
+ error: optional(Schema.String)
180
237
  });
181
238
  /** A prompt admitted but not yet in the conversation: a steer waiting for the next model request, or a follow-up for the next turn. */
182
239
  const QueuedPrompt = Schema.Struct({
@@ -194,12 +251,14 @@ const LogSynced = Schema.Struct({
194
251
  aggregateId: Schema.String,
195
252
  seq: optional(Schema.Int)
196
253
  });
254
+ /** A thread's model, thinking and foundation choices: a given field replaces the stored one, `null` clears it. */
197
255
  const RuntimeConfig = Schema.Struct({
198
- model: optional(Schema.Struct({
256
+ model: optional(Schema.NullOr(Schema.Struct({
199
257
  provider: Schema.String,
200
258
  id: Schema.String
201
- })),
202
- thinkingLevel: optional(Schema.Enum(Model.ThinkingLevelEnum))
259
+ }))),
260
+ thinkingLevel: optional(Schema.NullOr(Schema.Enum(Model.ThinkingLevelEnum))),
261
+ foundation: optional(Schema.NullOr(Schema.NonEmptyString))
203
262
  });
204
263
  const SandboxRef = Sandbox.Selection;
205
264
  /** A model to choose, by the catalog's id and display name, with the thinking levels it supports. */
@@ -251,9 +310,11 @@ const OAuthInfo = Schema.Struct({
251
310
  });
252
311
  const SessionErrors = Schema.Union([
253
312
  SessionStore.SessionNotFoundError,
313
+ ThreadStore.ThreadNotFoundError,
254
314
  SessionStore.SessionLinkedSpaceNotFoundError,
255
315
  SessionStore.RelinkError
256
316
  ]);
317
+ const ThreadErrors = Schema.Union([SessionStore.SessionNotFoundError, ThreadStore.ThreadNotFoundError]);
257
318
  const SandboxErrors = Schema.Union([
258
319
  SandboxError.SandboxNotFoundError,
259
320
  SandboxError.SandboxDriverNotRegisteredError,
@@ -266,6 +327,26 @@ const SandboxErrors = Schema.Union([
266
327
  SandboxError.SandboxBusyError
267
328
  ]);
268
329
  const LocationErrors = Schema.Union([Location.DirectoryNotFoundError, Location.NotDirectoryError]);
330
+ /** One of a thread's MCP servers as that thread sees it. */
331
+ const McpStatus = Schema.Struct({
332
+ server: Schema.String,
333
+ state: EventList.McpState,
334
+ error: optional(Schema.String),
335
+ /** Tools the server offered when last listed, each with its exposure in the thread. */
336
+ tools: Schema.Array(Schema.Struct({
337
+ name: Schema.String,
338
+ exposure: Schema.Literals([
339
+ "direct",
340
+ "codemode",
341
+ "deferred",
342
+ "hidden"
343
+ ])
344
+ })),
345
+ resources: Schema.Boolean,
346
+ /** Tools it listed last that were left out because the MCP SDK rejects them; absent when none were. */
347
+ skipped: optional(EventList.McpSkipped)
348
+ });
349
+ const McpErrors = Schema.Union([ThreadErrors, McpError.UnknownServerError]);
269
350
  const Api = RpcGroup.make(
270
351
  /**
271
352
  * The server's own identity: the process and build a client is talking to.
@@ -302,8 +383,10 @@ const Api = RpcGroup.make(
302
383
  success: Schema.Void,
303
384
  error: OAuthError$1
304
385
  }),
386
+ /** A session and its `main` thread; the main thread's info, with the session embedded. */
305
387
  Rpc.make("session.create", {
306
388
  payload: {
389
+ /** The main thread's title; absent = its first prompt names it. */
307
390
  title: optional(Schema.String),
308
391
  directory: optional(Schema.String),
309
392
  /**
@@ -325,7 +408,7 @@ const Api = RpcGroup.make(
325
408
  */
326
409
  project: optional(Schema.Struct({ name: ProjectName }))
327
410
  },
328
- success: SessionInfo,
411
+ success: ThreadInfo,
329
412
  error: Schema.Union([
330
413
  SessionErrors,
331
414
  SandboxErrors,
@@ -365,39 +448,67 @@ const Api = RpcGroup.make(
365
448
  }),
366
449
  error: Schema.Union([Settings.SettingsError, Runner.ModelCatalogError])
367
450
  }),
368
- Rpc.make("session.list", {
369
- payload: {},
370
- success: Schema.Array(SessionInfo)
371
- }),
372
451
  /**
373
- * The conversation on a session's active branch: user and assistant messages, oldest first.
374
- * Other branches and the harness's own entries (compactions, summaries) are left out.
452
+ * Point an existing session at a host directory, or clear it with `null`.
453
+ *
454
+ * Not `session.relink`: that moves where the *work* happens, this changes which host directory
455
+ * the session is *anchored to*. Conflating them would recreate exactly the `cwd`/`hostDir`
456
+ * confusion the split exists to remove, which is why they sound alike and stay apart.
375
457
  */
376
- Rpc.make("session.history", {
377
- payload: { sessionId: Session.SessionSchema.ID },
378
- success: Schema.Struct({ entries: Schema.Array(HistoryEntry) }),
458
+ Rpc.make("session.link", {
459
+ payload: {
460
+ sessionId: Session.SessionSchema.ID,
461
+ /** Absent clears the anchor, leaving the session with no host directory. */
462
+ hostDir: optional(Session.AbsolutePath)
463
+ },
464
+ success: SessionInfo,
379
465
  error: SessionStore.SessionNotFoundError
380
466
  }),
381
467
  /**
382
- * Prompts admitted but not yet promoted, in admission order. Admission and promotion are
383
- * durable events, so a client following `session.log` rereads this whenever the log moves.
468
+ * Moves where the work happens. Without `threadId`, the session's default space and directory,
469
+ * which every thread without its own placement follows; with it, that thread's placement only.
470
+ * Answers with the addressed thread (`main` when absent): its `placement` and embedded session
471
+ * show where it now runs.
384
472
  */
385
- Rpc.make("session.queue", {
473
+ Rpc.make("session.relink", {
474
+ payload: {
475
+ sessionId: Session.SessionSchema.ID,
476
+ threadId: optional(ThreadSchema.ID),
477
+ sandbox: optional(SandboxRef),
478
+ directory: optional(Schema.String)
479
+ },
480
+ success: ThreadInfo,
481
+ error: Schema.Union([
482
+ SessionErrors,
483
+ SandboxErrors,
484
+ LocationErrors
485
+ ])
486
+ }),
487
+ /** Stops every thread, then removes the session with its log. `deleted` is false when it did not exist. */
488
+ Rpc.make("session.delete", {
386
489
  payload: { sessionId: Session.SessionSchema.ID },
387
- success: Schema.Struct({ entries: Schema.Array(QueuedPrompt) }),
388
- error: SessionStore.SessionNotFoundError
490
+ success: Schema.Struct({ deleted: Schema.Boolean })
491
+ }),
492
+ /** Interrupts every running thread of the session. */
493
+ Rpc.make("session.interrupt", {
494
+ payload: { sessionId: Session.SessionSchema.ID },
495
+ success: Schema.Struct({ interrupted: Schema.Boolean })
389
496
  }),
390
497
  /**
391
498
  * A session's durable events after `after` (exclusive; omitted reads from the start), then a
392
499
  * `log.synced` marker at the head read when the call began. With `follow`, each event then
393
- * streams as it commits; without it the stream ends at the marker.
500
+ * streams as it commits; without it the stream ends at the marker. Every thread of the session
501
+ * writes this one log; events name their `threadId`.
394
502
  * Ephemeral events (text and tool progress deltas) are never stored, so they are not here;
395
503
  * `event.subscribe` carries them live. To resume, pass the higher of the last event's
396
504
  * `durable.seq` and the last marker's `seq`: the marker can sit past the last event sent.
505
+ * With `threadId`, only that thread's events; the marker still names the session's head. A fork's
506
+ * own log starts at its `session.thread.forked`: what it inherits is in `thread.history`.
397
507
  */
398
508
  Rpc.make("session.log", {
399
509
  payload: {
400
510
  sessionId: Session.SessionSchema.ID,
511
+ threadId: optional(ThreadSchema.ID),
401
512
  after: optional(Schema.Int),
402
513
  follow: optional(Schema.Boolean)
403
514
  },
@@ -405,105 +516,118 @@ const Api = RpcGroup.make(
405
516
  error: Schema.Union([SessionStore.SessionNotFoundError, EncodingError]),
406
517
  stream: true
407
518
  }),
408
- Rpc.make("session.configure", {
409
- payload: {
410
- sessionId: Session.SessionSchema.ID,
411
- runtime: RuntimeConfig
412
- },
413
- success: SessionInfo,
414
- error: SessionStore.SessionNotFoundError
519
+ /** Threads newest first, each with its session embedded: of one session, or all. */
520
+ Rpc.make("thread.list", {
521
+ payload: { sessionId: optional(Session.SessionSchema.ID) },
522
+ success: Schema.Array(ThreadInfo)
415
523
  }),
416
- Rpc.make("session.info", {
417
- payload: { sessionId: Session.SessionSchema.ID },
418
- success: SessionInfo,
419
- error: SessionStore.SessionNotFoundError
524
+ Rpc.make("thread.info", {
525
+ payload: ThreadRef,
526
+ success: ThreadInfo,
527
+ error: ThreadErrors
420
528
  }),
421
529
  /**
422
- * Point an existing session at a host directory, or clear it with `null`.
423
- *
424
- * Not `session.relink`: that moves where the *work* happens, this changes which host directory
425
- * the session is *anchored to*. Conflating them would recreate exactly the `cwd`/`hostDir`
426
- * confusion the split exists to remove, which is why they sound alike and stay apart.
530
+ * The conversation in a thread's line: user and assistant messages, inherited ones first, oldest
531
+ * first. The harness's own entries (compactions, resets, notices) are left out.
427
532
  */
428
- Rpc.make("session.link", {
533
+ Rpc.make("thread.history", {
534
+ payload: ThreadRef,
535
+ success: Schema.Struct({ entries: Schema.Array(HistoryEntry) }),
536
+ error: ThreadErrors
537
+ }),
538
+ /**
539
+ * Prompts admitted to the thread but not yet promoted, in admission order. Admission and
540
+ * promotion are durable events, so a client following `session.log` rereads this whenever the
541
+ * log moves.
542
+ */
543
+ Rpc.make("thread.queue", {
544
+ payload: ThreadRef,
545
+ success: Schema.Struct({ entries: Schema.Array(QueuedPrompt) }),
546
+ error: ThreadErrors
547
+ }),
548
+ Rpc.make("thread.configure", {
429
549
  payload: {
430
- sessionId: Session.SessionSchema.ID,
431
- /** Absent clears the anchor, leaving the session with no host directory. */
432
- hostDir: optional(Session.AbsolutePath)
550
+ ...ThreadRef,
551
+ runtime: RuntimeConfig
433
552
  },
434
- success: SessionInfo,
435
- error: SessionStore.SessionNotFoundError
553
+ success: ThreadInfo,
554
+ error: ThreadErrors
436
555
  }),
437
- Rpc.make("session.relink", {
556
+ /**
557
+ * A new thread whose history continues from this one's line through `entryId`, which must be
558
+ * committed. `before` stops at the entry's predecessor and returns its text to edit again.
559
+ */
560
+ Rpc.make("thread.fork", {
438
561
  payload: {
439
- sessionId: Session.SessionSchema.ID,
440
- sandbox: optional(SandboxRef),
441
- directory: optional(Schema.String)
562
+ ...ThreadRef,
563
+ entryId: Schema.String,
564
+ mode: optional(Schema.Literals(["at", "before"]))
442
565
  },
443
- success: SessionInfo,
444
- error: Schema.Union([
445
- SessionErrors,
446
- SandboxErrors,
447
- LocationErrors
448
- ])
566
+ success: Schema.Struct({
567
+ thread: ThreadInfo,
568
+ text: optional(Schema.String)
569
+ }),
570
+ error: Schema.Union([ThreadErrors, ThreadStore.ForkError])
449
571
  }),
450
- Rpc.make("session.prompt", {
572
+ Rpc.make("thread.prompt", {
451
573
  payload: {
452
- sessionId: Session.SessionSchema.ID,
574
+ ...ThreadRef,
453
575
  text: Schema.String,
454
576
  delivery: optional(PromptSchema.Delivery),
455
577
  id: optional(Session.SessionMessageSchema.ID)
456
578
  },
457
- success: Schema.Void,
458
- error: Schema.Union([SessionStore.SessionNotFoundError, Control.PromptConflictError])
579
+ success: Schema.Struct({ threadId: ThreadSchema.ID }),
580
+ error: Schema.Union([ThreadErrors, Control.PromptConflictError])
459
581
  }),
460
582
  /**
461
583
  * Withdraws a queued prompt before it joins the conversation. `cancelled` is false when it had
462
584
  * already been promoted (it then stays in the conversation) or no pending prompt has that id.
463
585
  */
464
- Rpc.make("session.cancel", {
586
+ Rpc.make("thread.cancel", {
465
587
  payload: {
466
- sessionId: Session.SessionSchema.ID,
588
+ ...ThreadRef,
467
589
  messageId: Session.SessionMessageSchema.ID
468
590
  },
469
591
  success: Schema.Struct({ cancelled: Schema.Boolean }),
470
- error: SessionStore.SessionNotFoundError
592
+ error: ThreadErrors
471
593
  }),
472
594
  /**
473
595
  * Moves a queued prompt to the other lane or rewrites it, keeping its place in the queue.
474
- * `delivery: "steer"` also wakes the session, so a prompt left waiting after a stop runs now.
596
+ * `delivery: "steer"` also wakes the thread, so a prompt left waiting after a stop runs now.
475
597
  * `updated` is false when it had already been promoted or cancelled, or no pending prompt has that id.
476
598
  */
477
- Rpc.make("session.update", {
599
+ Rpc.make("thread.update", {
478
600
  payload: {
479
- sessionId: Session.SessionSchema.ID,
601
+ ...ThreadRef,
480
602
  messageId: Session.SessionMessageSchema.ID,
481
603
  delivery: optional(PromptSchema.Delivery),
482
604
  text: optional(Schema.String)
483
605
  },
484
606
  success: Schema.Struct({ updated: Schema.Boolean }),
485
- error: SessionStore.SessionNotFoundError
607
+ error: ThreadErrors
486
608
  }),
487
- Rpc.make("session.interrupt", {
488
- payload: { sessionId: Session.SessionSchema.ID },
489
- success: Schema.Struct({ interrupted: Schema.Boolean })
609
+ Rpc.make("thread.interrupt", {
610
+ payload: ThreadRef,
611
+ success: Schema.Struct({ interrupted: Schema.Boolean }),
612
+ error: ThreadErrors
490
613
  }),
491
614
  /**
492
- * Whether a prompt materialized into the conversation. An admitted prompt
493
- * that is still queued has no entry yet, so this is the projection a client
494
- * reconciles against when the volatile stream left it unsure
615
+ * Whether a prompt materialized into the thread's conversation. An admitted prompt that is still
616
+ * queued has no entry yet, so this is the projection a client reconciles against when the
617
+ * volatile stream left it unsure.
495
618
  */
496
- Rpc.make("session.message", {
619
+ Rpc.make("thread.message", {
497
620
  payload: {
498
- sessionId: Session.SessionSchema.ID,
621
+ ...ThreadRef,
499
622
  messageId: Session.SessionMessageSchema.ID
500
623
  },
501
- success: Schema.Struct({ found: Schema.Boolean })
624
+ success: Schema.Struct({ found: Schema.Boolean }),
625
+ error: ThreadErrors
502
626
  }),
503
- Rpc.make("session.wait", {
504
- payload: { sessionId: Session.SessionSchema.ID },
627
+ Rpc.make("thread.wait", {
628
+ payload: ThreadRef,
505
629
  success: Schema.Void,
506
- error: SessionStore.SessionNotFoundError
630
+ error: ThreadErrors
507
631
  }),
508
632
  /**
509
633
  * Re-import every configured plugin, for the whole server.
@@ -519,6 +643,21 @@ const Api = RpcGroup.make(
519
643
  failure: optional(Schema.String)
520
644
  })
521
645
  }),
646
+ /**
647
+ * Close the instance behind a thread's MCP server, or its attempt, and connect it afresh, for
648
+ * every thread sharing it. Answers once that attempt finished, with the server's state then.
649
+ */
650
+ Rpc.make("mcp.connect", {
651
+ payload: McpServerRef,
652
+ success: McpStatus,
653
+ error: McpErrors
654
+ }),
655
+ /** Close it, for every thread sharing it, and keep it closed until `mcp.connect` or a config change. */
656
+ Rpc.make("mcp.disconnect", {
657
+ payload: McpServerRef,
658
+ success: McpStatus,
659
+ error: McpErrors
660
+ }),
522
661
  Rpc.make("sandbox.drivers", {
523
662
  payload: {},
524
663
  success: Schema.Array(Schema.Struct({
@@ -548,8 +687,12 @@ const Api = RpcGroup.make(
548
687
  success: Schema.Void,
549
688
  error: SandboxErrors
550
689
  }),
690
+ /**
691
+ * Every event the server publishes, live, after a `server.connected` frame. With `threadId`,
692
+ * only the events naming that thread; the frame still comes first.
693
+ */
551
694
  Rpc.make("event.subscribe", {
552
- payload: {},
695
+ payload: { threadId: optional(ThreadSchema.ID) },
553
696
  success: EventEnvelope,
554
697
  error: Schema.Union([Event.SubscriptionOverflowError, EncodingError]),
555
698
  stream: true
@@ -568,7 +711,7 @@ var ExecutionError = class extends Schema.TaggedError()("Client.ExecutionError",
568
711
  /**
569
712
  * Runs one prompt against a server and renders its output.
570
713
  *
571
- * Sessions are shared, so the stream carries other clients' work too and every
714
+ * Threads are shared, so the stream carries other clients' work too and every
572
715
  * terminal event has to be attributed before it is believed. A terminal that
573
716
  * arrives before our own prompt is promoted belongs to somebody else's drain:
574
717
  * it is remembered rather than raised, and forgotten the moment our prompt is
@@ -594,9 +737,9 @@ const run = Effect.fn("Client.run")(function* (rpc, input, render) {
594
737
  ...event.data.error.status === void 0 ? {} : { status: event.data.error.status }
595
738
  });
596
739
  };
597
- const consume = rpc["event.subscribe"]({}).pipe(Stream.mapEffect(Effect.fnUntraced(function* (envelope) {
740
+ const consume = rpc["event.subscribe"]({ threadId: input.threadId }).pipe(Stream.mapEffect(Effect.fnUntraced(function* (envelope) {
598
741
  if (envelope.type === Connected.type) {
599
- yield* rpc["session.prompt"]({
742
+ yield* rpc["thread.prompt"]({
600
743
  ...input,
601
744
  id,
602
745
  delivery: "followUp"
@@ -604,7 +747,7 @@ const run = Effect.fn("Client.run")(function* (rpc, input, render) {
604
747
  return;
605
748
  }
606
749
  const event = yield* decode$1(envelope).pipe(Effect.catchTag("UnknownEventTypeError", () => Effect.void));
607
- if (event === void 0 || !Predicate.hasProperty(event.data, "sessionId") || event.data.sessionId !== input.sessionId) return;
750
+ if (event === void 0) return;
608
751
  if (Schema.is(EventList.PromptAdmitted)(event) && event.data.messageId === id) admitted = true;
609
752
  if (Schema.is(EventList.Prompted)(event) && event.data.messageId === id) {
610
753
  promoted = true;
@@ -626,8 +769,12 @@ const run = Effect.fn("Client.run")(function* (rpc, input, render) {
626
769
  yield* render(event);
627
770
  })), Stream.takeUntil(() => settled), Stream.runDrain);
628
771
  let abandoned = false;
629
- const reconcile = Deferred.await(stalled).pipe(Effect.andThen(rpc["session.wait"]({ sessionId: input.sessionId })), Effect.andThen(rpc["session.message"]({
772
+ const reconcile = Deferred.await(stalled).pipe(Effect.andThen(rpc["thread.wait"]({
773
+ sessionId: input.sessionId,
774
+ threadId: input.threadId
775
+ })), Effect.andThen(rpc["thread.message"]({
630
776
  sessionId: input.sessionId,
777
+ threadId: input.threadId,
631
778
  messageId: id
632
779
  })), Effect.andThen(({ found }) => found ? Effect.never : Effect.sync(() => {
633
780
  abandoned = true;
@@ -683,6 +830,8 @@ const usage = (summary, columns) => {
683
830
  return `${divider("usage", columns)}${row("model", model)}${row("tokens", `${number.format(summary.input)} input · ${number.format(summary.output)} output${reasoning} · ${number.format(summary.totalTokens)} total`)}${row("cache", `${number.format(summary.cacheRead)} read · ${number.format(summary.cacheWrite)} write`)}${row("cost", `${formatCost(summary.cost)} · ${turns}`)}`;
684
831
  };
685
832
  const writeOut = (value) => Effect.sync(() => void process.stdout.write(value));
833
+ /** A value in its wire form, as indented JSON. */
834
+ const writeJson = (schema, value) => Schema.encodeEffect(schema)(value).pipe(Effect.orDie, Effect.flatMap((encoded) => writeOut(`${JSON.stringify(encoded, null, " ")}\n`)));
686
835
  const writeError = (value) => Effect.sync(() => void process.stderr.write(value));
687
836
  const terminalColumns = () => process.stderr.isTTY ? process.stderr.columns ?? 72 : 72;
688
837
  //#endregion
@@ -844,6 +993,6 @@ const reportFailure = (error) => writeError(renderError(error)).pipe(Effect.andT
844
993
  process.exitCode = 1;
845
994
  })));
846
995
  //#endregion
847
- export { path as _, addUsage as a, Core as b, terminalColumns as c, writeOut as d, layer as f, OAuthError$1 as g, Api as h, reportFailure as i, usage as l, run as m, OAuthError as n, emptyUsage as o, make as p, renderError as r, header as s, InvalidInputError as t, writeError as u, decode as v, encode as x, Connected as y };
996
+ export { encode as C, Core as S, OAuthError$1 as _, addUsage as a, decode as b, terminalColumns as c, writeJson as d, writeOut as f, Api as g, run as h, reportFailure as i, usage as l, make as m, OAuthError as n, emptyUsage as o, layer as p, renderError as r, header as s, InvalidInputError as t, writeError as u, ThreadInfo as v, ofThread as w, Connected as x, path as y };
848
997
 
849
- //# sourceMappingURL=error-BMI81XvR.mjs.map
998
+ //# sourceMappingURL=error-BVSfzBzb.mjs.map