@codeworksh/cli 0.7.0 → 0.8.0-dev.20261106085021
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{acp-GGhof_w_.mjs → acp-CXEcV0M8.mjs} +3 -3
- package/{acp-GGhof_w_.mjs.map → acp-CXEcV0M8.mjs.map} +1 -1
- package/{add-CGjQkVRs.mjs → add-31QB-o0_.mjs} +4 -4
- package/{add-CGjQkVRs.mjs.map → add-31QB-o0_.mjs.map} +1 -1
- package/{add-DArbv6Op.mjs → add-Dgy0iTEQ.mjs} +3 -3
- package/{add-DArbv6Op.mjs.map → add-Dgy0iTEQ.mjs.map} +1 -1
- package/{check-BRHzx5p0.mjs → check-BoANDJxT.mjs} +3 -3
- package/{check-BRHzx5p0.mjs.map → check-BoANDJxT.mjs.map} +1 -1
- package/{control-F0bo3rXh.mjs → control-CQxWGS4k.mjs} +4 -4
- package/{control-F0bo3rXh.mjs.map → control-CQxWGS4k.mjs.map} +1 -1
- package/disconnect-BiLuV4JZ.mjs +2 -0
- package/{entries-DnbFTTLU.mjs → entries-DpL4xhu0.mjs} +3 -3
- package/{entries-DnbFTTLU.mjs.map → entries-DpL4xhu0.mjs.map} +1 -1
- package/{error--BWou73I.mjs → error-CPyvkO4x.mjs} +189 -6
- package/error-CPyvkO4x.mjs.map +1 -0
- package/{fork-DlhNFPUB.mjs → fork-CjZteIbk.mjs} +3 -3
- package/{fork-DlhNFPUB.mjs.map → fork-CjZteIbk.mjs.map} +1 -1
- package/{identity-Bcl1KlX-.mjs → identity-kubcIgQ6.mjs} +2 -2
- package/{identity-Bcl1KlX-.mjs.map → identity-kubcIgQ6.mjs.map} +1 -1
- package/index.mjs +33 -33
- package/{install-DRJ5KKyb.mjs → install-BUfEBtrj.mjs} +3 -3
- package/{install-DRJ5KKyb.mjs.map → install-BUfEBtrj.mjs.map} +1 -1
- package/{jsonc-Cel7I0yd.mjs → jsonc-Ca0uQLm-.mjs} +2 -2
- package/{jsonc-Cel7I0yd.mjs.map → jsonc-Ca0uQLm-.mjs.map} +1 -1
- package/{link-CJE1PRTf.mjs → link-ZuzWj9qt.mjs} +2 -2
- package/{link-CJE1PRTf.mjs.map → link-ZuzWj9qt.mjs.map} +1 -1
- package/{list-B3kSn78f.mjs → list-6QTwXTKO.mjs} +3 -3
- package/{list-B3kSn78f.mjs.map → list-6QTwXTKO.mjs.map} +1 -1
- package/{list-Cf-zESJf.mjs → list-BnIIcMI3.mjs} +2 -2
- package/{list-Cf-zESJf.mjs.map → list-BnIIcMI3.mjs.map} +1 -1
- package/{list-TLhgvlKp.mjs → list-DDuzyNv0.mjs} +2 -2
- package/{list-TLhgvlKp.mjs.map → list-DDuzyNv0.mjs.map} +1 -1
- package/{list-Df4ngZjL.mjs → list-DPbF2uMB.mjs} +3 -3
- package/{list-Df4ngZjL.mjs.map → list-DPbF2uMB.mjs.map} +1 -1
- package/{login-oWLqnAQK.mjs → login-BtuROCPJ.mjs} +3 -3
- package/{login-oWLqnAQK.mjs.map → login-BtuROCPJ.mjs.map} +1 -1
- package/{login-BJ3d7FM_.mjs → login-CGXU21AK.mjs} +3 -3
- package/{login-BJ3d7FM_.mjs.map → login-CGXU21AK.mjs.map} +1 -1
- package/{logout-D44pgH6b.mjs → logout-Bnk2hxfZ.mjs} +3 -3
- package/{logout-D44pgH6b.mjs.map → logout-Bnk2hxfZ.mjs.map} +1 -1
- package/{logout-ClrNQ8LO.mjs → logout-DUn8KSjX.mjs} +3 -3
- package/{logout-ClrNQ8LO.mjs.map → logout-DUn8KSjX.mjs.map} +1 -1
- package/package-Bynyv1vo.mjs +6 -0
- package/package-Bynyv1vo.mjs.map +1 -0
- package/package.json +3 -3
- package/{providers-ozcPo-AJ.mjs → providers-GEdlDJHp.mjs} +2 -2
- package/{providers-ozcPo-AJ.mjs.map → providers-GEdlDJHp.mjs.map} +1 -1
- package/reconnect-ChE5ETwx.mjs +2 -0
- package/{refresh-B6iT5eWN.mjs → refresh-93t2pSpb.mjs} +2 -2
- package/{refresh-B6iT5eWN.mjs.map → refresh-93t2pSpb.mjs.map} +1 -1
- package/{refresh-CH7lLrF3.mjs → refresh-DGJW3rSp.mjs} +3 -3
- package/{refresh-CH7lLrF3.mjs.map → refresh-DGJW3rSp.mjs.map} +1 -1
- package/{relink-BvrynRLV.mjs → relink-Djy5t7D2.mjs} +3 -3
- package/{relink-BvrynRLV.mjs.map → relink-Djy5t7D2.mjs.map} +1 -1
- package/{reload-qYk-KlpL.mjs → reload-Dm464rPC.mjs} +2 -2
- package/{reload-qYk-KlpL.mjs.map → reload-Dm464rPC.mjs.map} +1 -1
- package/{remove-Be5ytOgR.mjs → remove-DBT19X2j.mjs} +3 -3
- package/{remove-Be5ytOgR.mjs.map → remove-DBT19X2j.mjs.map} +1 -1
- package/{remove-CTzOWKTq.mjs → remove-f7C_vEOD.mjs} +4 -4
- package/{remove-CTzOWKTq.mjs.map → remove-f7C_vEOD.mjs.map} +1 -1
- package/{restart-Dhlrvevr.mjs → restart-1Ig29_n9.mjs} +3 -3
- package/{restart-Dhlrvevr.mjs.map → restart-1Ig29_n9.mjs.map} +1 -1
- package/{run-BX65GBq_.mjs → run-CTFksYXE.mjs} +3 -3
- package/{run-BX65GBq_.mjs.map → run-CTFksYXE.mjs.map} +1 -1
- package/{serve-y19CU2VR.mjs → serve-CvQGTSvM.mjs} +171 -31
- package/serve-CvQGTSvM.mjs.map +1 -0
- package/{service-Df8gDfve.mjs → service-BrM1uS4y.mjs} +3 -3
- package/{service-Df8gDfve.mjs.map → service-BrM1uS4y.mjs.map} +1 -1
- package/{settings-BzAk8lIo.mjs → settings-DasbTMFs.mjs} +3 -3
- package/{settings-BzAk8lIo.mjs.map → settings-DasbTMFs.mjs.map} +1 -1
- package/{shared-BnR3BFZM.mjs → shared-CDyNsYBy.mjs} +3 -3
- package/{shared-BnR3BFZM.mjs.map → shared-CDyNsYBy.mjs.map} +1 -1
- package/{shared-BU8-Q5m8.mjs → shared-CiSbTY59.mjs} +2 -2
- package/{shared-BU8-Q5m8.mjs.map → shared-CiSbTY59.mjs.map} +1 -1
- package/{start-DrVnKdfd.mjs → start-DK6WdgM4.mjs} +3 -3
- package/{start-DrVnKdfd.mjs.map → start-DK6WdgM4.mjs.map} +1 -1
- package/{status-B-AAul1G.mjs → status-CHcJyF_7.mjs} +3 -3
- package/{status-B-AAul1G.mjs.map → status-CHcJyF_7.mjs.map} +1 -1
- package/{status-BrL3Eecl.mjs → status-DSZESc80.mjs} +3 -3
- package/{status-BrL3Eecl.mjs.map → status-DSZESc80.mjs.map} +1 -1
- package/{stop-D-OJCp9e.mjs → stop-ZXaQQ8wJ.mjs} +3 -3
- package/{stop-D-OJCp9e.mjs.map → stop-ZXaQQ8wJ.mjs.map} +1 -1
- package/{thread-BuNept5V.mjs → thread-I6vNdC0y.mjs} +2 -2
- package/{thread-BuNept5V.mjs.map → thread-I6vNdC0y.mjs.map} +1 -1
- package/{update-DoS5AWg6.mjs → update-C3llbIB0.mjs} +3 -3
- package/{update-DoS5AWg6.mjs.map → update-C3llbIB0.mjs.map} +1 -1
- package/disconnect-DemFNh2P.mjs +0 -2
- package/error--BWou73I.mjs.map +0 -1
- package/package-CDB-uxy3.mjs +0 -6
- package/package-CDB-uxy3.mjs.map +0 -1
- package/reconnect-BcJtQx3U.mjs +0 -2
- package/serve-y19CU2VR.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refresh-
|
|
1
|
+
{"version":3,"file":"refresh-93t2pSpb.mjs","names":["Runtime.handler"],"sources":["../../src/cli/cmd/handlers/models/refresh.ts"],"sourcesContent":["import { ModelCatalog } from \"@codeworksh/harness/effect\";\nimport { Effect } from \"effect\";\nimport { Runtime } from \"../../../../framework/runtime.ts\";\nimport { reportFailure } from \"../../../error.ts\";\nimport { writeError, writeOut } from \"../../../output.ts\";\nimport { Cmd } from \"../../cmd.ts\";\nimport { home } from \"./catalog.ts\";\n\nexport default Runtime.handler(\n\tCmd.commands.models.commands.refresh,\n\tEffect.fn(\"CLI.models.refresh\")(function* ({ force }) {\n\t\tconst program = Effect.gen(function* () {\n\t\t\tconst status = yield* ModelCatalog.refresh(yield* home, { force });\n\t\t\tyield* writeError(\n\t\t\t\tstatus.refreshed\n\t\t\t\t\t? `Refreshed model catalog at ${status.path}\\n`\n\t\t\t\t\t: `Model catalog at ${status.path} is fresh; pass --force to download it anyway\\n`,\n\t\t\t);\n\t\t\tyield* writeOut(`${status.path}\\n`);\n\t\t});\n\n\t\treturn yield* program.pipe(Effect.catch(reportFailure));\n\t}),\n);\n"],"mappings":";;;;;;AAQA,IAAA,kBAAeA,QACd,IAAI,SAAS,OAAO,SAAS,SAC7B,OAAO,GAAG,oBAAoB,CAAC,CAAC,WAAW,EAAE,SAAS;CAWrD,OAAO,OAVS,OAAO,IAAI,aAAa;EACvC,MAAM,SAAS,OAAO,aAAa,QAAQ,OAAO,MAAM,EAAE,MAAM,CAAC;EACjE,OAAO,WACN,OAAO,YACJ,8BAA8B,OAAO,KAAK,MAC1C,oBAAoB,OAAO,KAAK,gDACpC;EACA,OAAO,SAAS,GAAG,OAAO,KAAK,GAAG;CACnC,CAEoB,CAAC,CAAC,KAAK,OAAO,MAAM,aAAa,CAAC;AACvD,CAAC,CACF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { i as Cmd, t as handler } from "./runtime-CK2CunDw.mjs";
|
|
2
|
-
import { f as writeOut, i as reportFailure, m as make, n as OAuthError, t as InvalidInputError, u as writeError } from "./error
|
|
3
|
-
import { a as oauthProviderLabel, n as attempt, o as selectProvider, r as localOps, s as withServer, t as assertServerScope } from "./shared-
|
|
2
|
+
import { f as writeOut, i as reportFailure, m as make, n as OAuthError, t as InvalidInputError, u as writeError } from "./error-CPyvkO4x.mjs";
|
|
3
|
+
import { a as oauthProviderLabel, n as attempt, o as selectProvider, r as localOps, s as withServer, t as assertServerScope } from "./shared-CiSbTY59.mjs";
|
|
4
4
|
import { Effect, Option } from "effect";
|
|
5
5
|
import { formatOAuthSummary, oauthNotice, oauthRefreshIssue } from "@codeworksh/aikit/oauth/summary";
|
|
6
6
|
//#region src/cli/cmd/handlers/auth/refresh.ts
|
|
@@ -32,4 +32,4 @@ var refresh_default = handler(Cmd.commands.auth.commands.refresh, Effect.fn("CLI
|
|
|
32
32
|
//#endregion
|
|
33
33
|
export { refresh_default as default };
|
|
34
34
|
|
|
35
|
-
//# sourceMappingURL=refresh-
|
|
35
|
+
//# sourceMappingURL=refresh-DGJW3rSp.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refresh-
|
|
1
|
+
{"version":3,"file":"refresh-DGJW3rSp.mjs","names":["Runtime.handler","Client.make"],"sources":["../../src/cli/cmd/handlers/auth/refresh.ts"],"sourcesContent":["import { formatOAuthSummary, oauthNotice, oauthRefreshIssue } from \"@codeworksh/aikit/oauth/summary\";\nimport { Effect, Option } from \"effect\";\nimport { Runtime } from \"../../../../framework/runtime.ts\";\nimport { InvalidInputError, OAuthError, reportFailure } from \"../../../error.ts\";\nimport { writeError, writeOut } from \"../../../output.ts\";\nimport { Cmd } from \"../../cmd.ts\";\nimport {\n\tassertServerScope,\n\tattempt,\n\tClient,\n\tlocalOps,\n\toauthProviderLabel,\n\tselectProvider,\n\twithServer,\n} from \"./shared.ts\";\n\nexport default Runtime.handler(\n\tCmd.commands.auth.commands.refresh,\n\tEffect.fn(\"CLI.auth.refresh\")(function* ({ server, openaiCodex, githubCopilot, authFile, json }) {\n\t\tconst program = Effect.gen(function* () {\n\t\t\tconst provider = yield* selectProvider({ openaiCodex, githubCopilot });\n\t\t\tconst blocked = oauthRefreshIssue(provider);\n\t\t\tif (blocked !== undefined) return yield* new InvalidInputError({ message: blocked });\n\n\t\t\tconst name = oauthProviderLabel(provider);\n\n\t\t\tif (Option.isSome(server)) {\n\t\t\t\tyield* assertServerScope(authFile);\n\t\t\t\treturn yield* withServer(\n\t\t\t\t\tserver.value,\n\t\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\t\tconst rpc = yield* Client.make;\n\t\t\t\t\t\tconst info = yield* rpc[\"auth.refresh\"]({ provider });\n\t\t\t\t\t\tif (info === null) {\n\t\t\t\t\t\t\treturn yield* new OAuthError({ message: oauthNotice(\"missing\", provider, \"the server\") });\n\t\t\t\t\t\t}\n\t\t\t\t\t\tyield* writeError(`${oauthNotice(\"refreshed\", provider, \"the server\")}\\n`);\n\t\t\t\t\t\tyield* writeOut(formatOAuthSummary(info, { json }));\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst ops = yield* localOps(provider, authFile);\n\t\t\tconst summary = yield* attempt(`failed to read ${name} credentials`, () => ops.refreshed());\n\t\t\tif (summary === undefined) {\n\t\t\t\treturn yield* new OAuthError({ message: oauthNotice(\"missing\", provider, ops.path) });\n\t\t\t}\n\t\t\tyield* writeError(`${oauthNotice(\"refreshed\", provider, ops.path)}\\n`);\n\t\t\tyield* writeOut(formatOAuthSummary(summary, { json }));\n\t\t});\n\n\t\treturn yield* program.pipe(Effect.catch(reportFailure));\n\t}),\n);\n"],"mappings":";;;;;;AAgBA,IAAA,kBAAeA,QACd,IAAI,SAAS,KAAK,SAAS,SAC3B,OAAO,GAAG,kBAAkB,CAAC,CAAC,WAAW,EAAE,QAAQ,aAAa,eAAe,UAAU,QAAQ;CAiChG,OAAO,OAhCS,OAAO,IAAI,aAAa;EACvC,MAAM,WAAW,OAAO,eAAe;GAAE;GAAa;EAAc,CAAC;EACrE,MAAM,UAAU,kBAAkB,QAAQ;EAC1C,IAAI,YAAY,KAAA,GAAW,OAAO,OAAO,IAAI,kBAAkB,EAAE,SAAS,QAAQ,CAAC;EAEnF,MAAM,OAAO,mBAAmB,QAAQ;EAExC,IAAI,OAAO,OAAO,MAAM,GAAG;GAC1B,OAAO,kBAAkB,QAAQ;GACjC,OAAO,OAAO,WACb,OAAO,OACP,OAAO,IAAI,aAAa;IAEvB,MAAM,OAAO,QAAO,OADDC,KAAAA,CACK,eAAe,CAAC,EAAE,SAAS,CAAC;IACpD,IAAI,SAAS,MACZ,OAAO,OAAO,IAAI,WAAW,EAAE,SAAS,YAAY,WAAW,UAAU,YAAY,EAAE,CAAC;IAEzF,OAAO,WAAW,GAAG,YAAY,aAAa,UAAU,YAAY,EAAE,GAAG;IACzE,OAAO,SAAS,mBAAmB,MAAM,EAAE,KAAK,CAAC,CAAC;GACnD,CAAC,CACF;EACD;EAEA,MAAM,MAAM,OAAO,SAAS,UAAU,QAAQ;EAC9C,MAAM,UAAU,OAAO,QAAQ,kBAAkB,KAAK,qBAAqB,IAAI,UAAU,CAAC;EAC1F,IAAI,YAAY,KAAA,GACf,OAAO,OAAO,IAAI,WAAW,EAAE,SAAS,YAAY,WAAW,UAAU,IAAI,IAAI,EAAE,CAAC;EAErF,OAAO,WAAW,GAAG,YAAY,aAAa,UAAU,IAAI,IAAI,EAAE,GAAG;EACrE,OAAO,SAAS,mBAAmB,SAAS,EAAE,KAAK,CAAC,CAAC;CACtD,CAEoB,CAAC,CAAC,KAAK,OAAO,MAAM,aAAa,CAAC;AACvD,CAAC,CACF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { i as Cmd, t as handler } from "./runtime-CK2CunDw.mjs";
|
|
2
|
-
import { d as writeJson, f as writeOut, i as reportFailure, m as make, p as layer, y as ThreadInfo } from "./error
|
|
3
|
-
import { t as threadFlag } from "./thread-
|
|
2
|
+
import { d as writeJson, f as writeOut, i as reportFailure, m as make, p as layer, y as ThreadInfo } from "./error-CPyvkO4x.mjs";
|
|
3
|
+
import { t as threadFlag } from "./thread-I6vNdC0y.mjs";
|
|
4
4
|
import { Effect, Option } from "effect";
|
|
5
5
|
import { Sandbox, Session } from "@codeworksh/harness/effect";
|
|
6
6
|
//#region src/cli/cmd/handlers/session/relink.ts
|
|
@@ -20,4 +20,4 @@ var relink_default = handler(Cmd.commands.session.commands.relink, Effect.fn("CL
|
|
|
20
20
|
//#endregion
|
|
21
21
|
export { relink_default as default };
|
|
22
22
|
|
|
23
|
-
//# sourceMappingURL=relink-
|
|
23
|
+
//# sourceMappingURL=relink-Djy5t7D2.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"relink-
|
|
1
|
+
{"version":3,"file":"relink-Djy5t7D2.mjs","names":["Runtime.handler","Client.make","Client.layer"],"sources":["../../src/cli/cmd/handlers/session/relink.ts"],"sourcesContent":["import { Sandbox, Session } from \"@codeworksh/harness/effect\";\nimport { Effect, Option } from \"effect\";\nimport { Runtime } from \"../../../../framework/runtime.ts\";\nimport { Client } from \"../../../../server/client.ts\";\nimport { ThreadInfo } from \"../../../../server/contract.ts\";\nimport { reportFailure } from \"../../../error.ts\";\nimport { writeJson, writeOut } from \"../../../output.ts\";\nimport { threadFlag } from \"../../../thread.ts\";\nimport { Cmd } from \"../../cmd.ts\";\n\nexport default Runtime.handler(\n\tCmd.commands.session.commands.relink,\n\tEffect.fn(\"CLI.session.relink\")(function* ({ session, thread, directory, sandboxId, json, server }) {\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 info = yield* rpc[\"session.relink\"]({\n\t\t\t\tsessionId: Session.SessionSchema.ID.make(session),\n\t\t\t\t...(threadId === undefined ? {} : { threadId }),\n\t\t\t\t...(Option.isNone(sandboxId) ? {} : { sandbox: { id: Sandbox.SandboxInstance.ID.make(sandboxId.value) } }),\n\t\t\t\t...(Option.isNone(directory) ? {} : { directory: directory.value }),\n\t\t\t});\n\t\t\tif (json) return yield* writeJson(ThreadInfo, info);\n\t\t\t// Without `--thread` the session's default moved; a thread with its own placement stays put.\n\t\t\tyield* writeOut(\n\t\t\t\tthreadId === undefined\n\t\t\t\t\t? `Moved ${info.session.id} to ${info.session.directory}\\n`\n\t\t\t\t\t: `Moved thread ${info.id} of ${info.session.id} to ${info.placement?.directory ?? info.session.directory}\\n`,\n\t\t\t);\n\t\t});\n\n\t\treturn yield* program.pipe(Effect.provide(Client.layer(server)), Effect.scoped, Effect.catch(reportFailure));\n\t}),\n);\n"],"mappings":";;;;;;AAUA,IAAA,iBAAeA,QACd,IAAI,SAAS,QAAQ,SAAS,QAC9B,OAAO,GAAG,oBAAoB,CAAC,CAAC,WAAW,EAAE,SAAS,QAAQ,WAAW,WAAW,MAAM,UAAU;CAmBnG,OAAO,OAlBS,OAAO,IAAI,aAAa;EACvC,MAAM,WAAW,OAAO,WAAW,MAAM;EAEzC,MAAM,OAAO,QAAO,OADDC,KAAAA,CACK,iBAAiB,CAAC;GACzC,WAAW,QAAQ,cAAc,GAAG,KAAK,OAAO;GAChD,GAAI,aAAa,KAAA,IAAY,CAAC,IAAI,EAAE,SAAS;GAC7C,GAAI,OAAO,OAAO,SAAS,IAAI,CAAC,IAAI,EAAE,SAAS,EAAE,IAAI,QAAQ,gBAAgB,GAAG,KAAK,UAAU,KAAK,EAAE,EAAE;GACxG,GAAI,OAAO,OAAO,SAAS,IAAI,CAAC,IAAI,EAAE,WAAW,UAAU,MAAM;EAClE,CAAC;EACD,IAAI,MAAM,OAAO,OAAO,UAAU,YAAY,IAAI;EAElD,OAAO,SACN,aAAa,KAAA,IACV,SAAS,KAAK,QAAQ,GAAG,MAAM,KAAK,QAAQ,UAAU,MACtD,gBAAgB,KAAK,GAAG,MAAM,KAAK,QAAQ,GAAG,MAAM,KAAK,WAAW,aAAa,KAAK,QAAQ,UAAU,GAC5G;CACD,CAEoB,CAAC,CAAC,KAAK,OAAO,QAAQC,MAAa,MAAM,CAAC,GAAG,OAAO,QAAQ,OAAO,MAAM,aAAa,CAAC;AAC5G,CAAC,CACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { i as Cmd, t as handler } from "./runtime-CK2CunDw.mjs";
|
|
2
|
-
import { f as writeOut, i as reportFailure, m as make, p as layer } from "./error
|
|
2
|
+
import { f as writeOut, i as reportFailure, m as make, p as layer } from "./error-CPyvkO4x.mjs";
|
|
3
3
|
import { Effect } from "effect";
|
|
4
4
|
//#region src/cli/cmd/handlers/plugin/reload.ts
|
|
5
5
|
/**
|
|
@@ -23,4 +23,4 @@ var reload_default = handler(Cmd.commands.plugin.commands.reload, Effect.fn("CLI
|
|
|
23
23
|
//#endregion
|
|
24
24
|
export { reload_default as default };
|
|
25
25
|
|
|
26
|
-
//# sourceMappingURL=reload-
|
|
26
|
+
//# sourceMappingURL=reload-Dm464rPC.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reload-
|
|
1
|
+
{"version":3,"file":"reload-Dm464rPC.mjs","names":["Runtime.handler","Client.make","Client.layer"],"sources":["../../src/cli/cmd/handlers/plugin/reload.ts"],"sourcesContent":["import { Effect } from \"effect\";\nimport { Runtime } from \"../../../../framework/runtime.ts\";\nimport { reportFailure } from \"../../../error.ts\";\nimport { writeOut } from \"../../../output.ts\";\nimport { Client } from \"../../../../server/client.ts\";\nimport { Cmd } from \"../../cmd.ts\";\n\n/**\n * Re-import every configured plugin in a running server.\n *\n * It exists for exactly one case: a **local** plugin edited in place. Nothing in settings changed\n * and no generation moved -- a local source is never copied into the store, so it has none -- and\n * the module registry holds the old module against an unchanged URL. Everything else the runtime\n * notices for itself at the next exchange.\n *\n * There is no local form, and that is not an omission. In a CLI every run is a fresh process, so\n * the load pass happens at startup and a reload would have nothing to do.\n */\nexport default Runtime.handler(\n\tCmd.commands.plugin.commands.reload,\n\tEffect.fn(\"CLI.plugin.reload\")(function* ({ server }) {\n\t\tconst program = Effect.gen(function* () {\n\t\t\tconst rpc = yield* Client.make;\n\t\t\tconst result = yield* rpc[\"plugin.reload\"]({});\n\t\t\t// A reload that failed still reports the set that stayed loaded: the server kept\n\t\t\t// working, which is the whole point of not failing it.\n\t\t\tyield* writeOut(\n\t\t\t\tresult.failure === undefined\n\t\t\t\t\t? `Reloaded ${result.plugins} plugin${result.plugins === 1 ? \"\" : \"s\"}.\\n`\n\t\t\t\t\t: `Reload failed, keeping ${result.plugins} loaded: ${result.failure}\\n`,\n\t\t\t);\n\t\t\tif (result.failure !== undefined) process.exitCode = 1;\n\t\t});\n\n\t\treturn yield* program.pipe(Effect.provide(Client.layer(server)), Effect.scoped, Effect.catch(reportFailure));\n\t}),\n);\n"],"mappings":";;;;;;;;;;;;;;;AAkBA,IAAA,iBAAeA,QACd,IAAI,SAAS,OAAO,SAAS,QAC7B,OAAO,GAAG,mBAAmB,CAAC,CAAC,WAAW,EAAE,UAAU;CAcrD,OAAO,OAbS,OAAO,IAAI,aAAa;EAEvC,MAAM,SAAS,QAAO,OADHC,KAAAA,CACO,gBAAgB,CAAC,CAAC,CAAC;EAG7C,OAAO,SACN,OAAO,YAAY,KAAA,IAChB,YAAY,OAAO,QAAQ,SAAS,OAAO,YAAY,IAAI,KAAK,IAAI,OACpE,0BAA0B,OAAO,QAAQ,WAAW,OAAO,QAAQ,GACvE;EACA,IAAI,OAAO,YAAY,KAAA,GAAW,QAAQ,WAAW;CACtD,CAEoB,CAAC,CAAC,KAAK,OAAO,QAAQC,MAAa,MAAM,CAAC,GAAG,OAAO,QAAQ,OAAO,MAAM,aAAa,CAAC;AAC5G,CAAC,CACF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { i as Cmd, t as handler } from "./runtime-CK2CunDw.mjs";
|
|
2
|
-
import { f as writeOut, i as reportFailure } from "./error
|
|
3
|
-
import { a as resolveTarget, c as withPluginsLock, i as readPlugins, l as writePlugins, o as spellings, r as matching, t as identify } from "./settings-
|
|
2
|
+
import { f as writeOut, i as reportFailure } from "./error-CPyvkO4x.mjs";
|
|
3
|
+
import { a as resolveTarget, c as withPluginsLock, i as readPlugins, l as writePlugins, o as spellings, r as matching, t as identify } from "./settings-DasbTMFs.mjs";
|
|
4
4
|
import { Effect, FileSystem, Option, Path } from "effect";
|
|
5
5
|
import { Global } from "@codeworksh/harness/effect";
|
|
6
6
|
//#region src/cli/cmd/handlers/plugin/remove.ts
|
|
@@ -34,4 +34,4 @@ var remove_default = handler(Cmd.commands.plugin.commands.remove, Effect.fn("CLI
|
|
|
34
34
|
//#endregion
|
|
35
35
|
export { remove_default as default };
|
|
36
36
|
|
|
37
|
-
//# sourceMappingURL=remove-
|
|
37
|
+
//# sourceMappingURL=remove-DBT19X2j.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remove-
|
|
1
|
+
{"version":3,"file":"remove-DBT19X2j.mjs","names":["Runtime.handler"],"sources":["../../src/cli/cmd/handlers/plugin/remove.ts"],"sourcesContent":["import { Global } from \"@codeworksh/harness/effect\";\nimport { Effect, FileSystem, Option, Path } from \"effect\";\nimport { Runtime } from \"../../../../framework/runtime.ts\";\nimport { reportFailure } from \"../../../error.ts\";\nimport { writeOut } from \"../../../output.ts\";\nimport { Cmd } from \"../../cmd.ts\";\nimport {\n\tidentify,\n\tmatching,\n\treadPlugins,\n\tresolveTarget,\n\tspellings,\n\twithPluginsLock,\n\twritePlugins,\n} from \"./settings.ts\";\n\nexport default Runtime.handler(\n\tCmd.commands.plugin.commands.remove,\n\tEffect.fn(\"CLI.plugin.remove\")(function* ({ package: reference, global: userWide }) {\n\t\tconst program = Effect.gen(function* () {\n\t\t\tconst shared = yield* Cmd.spec;\n\t\t\tconst path = yield* Path.Path;\n\t\t\tconst fs = yield* FileSystem.FileSystem;\n\t\t\tconst paths = yield* Global.resolve(Option.isNone(shared.home) ? {} : { home: shared.home.value });\n\t\t\tconst target = yield* resolveTarget(shared, userWide, undefined, false);\n\t\t\t// Removing from a directory that is not a project is a read-only no-op. In particular, it\n\t\t\t// must not create the marker that would make this directory shadow a real project later.\n\t\t\tif (!(yield* fs.exists(path.dirname(target.path)))) {\n\t\t\t\tyield* writeOut(`Plugin \"${reference}\" is not configured in ${target.path}\\n`);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst spelled = yield* spellings(reference, path.resolve(\".\"));\n\t\t\tyield* withPluginsLock(\n\t\t\t\ttarget.path,\n\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\tconst { source, plugins } = yield* readPlugins(target.path);\n\t\t\t\t\t// Both the module entry and any configuration written against it: the package it was\n\t\t\t\t\t// added as, the path or version it was written with, and the ID it declares all name\n\t\t\t\t\t// the one plugin being removed.\n\t\t\t\t\tconst entries = yield* identify(plugins, target.path, paths.cache);\n\t\t\t\t\tconst selected = matching(entries, spelled);\n\t\t\t\t\tconst kept = entries.filter((entry) => !selected.has(entry)).map((entry) => entry.value);\n\t\t\t\t\tif (kept.length === plugins.length) {\n\t\t\t\t\t\tyield* writeOut(`Plugin \"${reference}\" is not configured in ${target.path}\\n`);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tyield* writePlugins(target.path, source, kept);\n\t\t\t\t\tconst dropped = plugins.length - kept.length;\n\t\t\t\t\tyield* writeOut(\n\t\t\t\t\t\t`Removed ${dropped} ${dropped === 1 ? \"entry\" : \"entries\"} for \"${reference}\" from ${target.path}\\n`,\n\t\t\t\t\t);\n\t\t\t\t}),\n\t\t\t);\n\t\t});\n\n\t\treturn yield* program.pipe(Effect.catch(reportFailure));\n\t}),\n);\n"],"mappings":";;;;;;AAgBA,IAAA,iBAAeA,QACd,IAAI,SAAS,OAAO,SAAS,QAC7B,OAAO,GAAG,mBAAmB,CAAC,CAAC,WAAW,EAAE,SAAS,WAAW,QAAQ,YAAY;CAqCnF,OAAO,OApCS,OAAO,IAAI,aAAa;EACvC,MAAM,SAAS,OAAO,IAAI;EAC1B,MAAM,OAAO,OAAO,KAAK;EACzB,MAAM,KAAK,OAAO,WAAW;EAC7B,MAAM,QAAQ,OAAO,OAAO,QAAQ,OAAO,OAAO,OAAO,IAAI,IAAI,CAAC,IAAI,EAAE,MAAM,OAAO,KAAK,MAAM,CAAC;EACjG,MAAM,SAAS,OAAO,cAAc,QAAQ,UAAU,KAAA,GAAW,KAAK;EAGtE,IAAI,EAAE,OAAO,GAAG,OAAO,KAAK,QAAQ,OAAO,IAAI,CAAC,IAAI;GACnD,OAAO,SAAS,WAAW,UAAU,yBAAyB,OAAO,KAAK,GAAG;GAC7E;EACD;EACA,MAAM,UAAU,OAAO,UAAU,WAAW,KAAK,QAAQ,GAAG,CAAC;EAC7D,OAAO,gBACN,OAAO,MACP,OAAO,IAAI,aAAa;GACvB,MAAM,EAAE,QAAQ,YAAY,OAAO,YAAY,OAAO,IAAI;GAI1D,MAAM,UAAU,OAAO,SAAS,SAAS,OAAO,MAAM,MAAM,KAAK;GACjE,MAAM,WAAW,SAAS,SAAS,OAAO;GAC1C,MAAM,OAAO,QAAQ,QAAQ,UAAU,CAAC,SAAS,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,UAAU,MAAM,KAAK;GACvF,IAAI,KAAK,WAAW,QAAQ,QAAQ;IACnC,OAAO,SAAS,WAAW,UAAU,yBAAyB,OAAO,KAAK,GAAG;IAC7E;GACD;GACA,OAAO,aAAa,OAAO,MAAM,QAAQ,IAAI;GAC7C,MAAM,UAAU,QAAQ,SAAS,KAAK;GACtC,OAAO,SACN,WAAW,QAAQ,GAAG,YAAY,IAAI,UAAU,UAAU,QAAQ,UAAU,SAAS,OAAO,KAAK,GAClG;EACD,CAAC,CACF;CACD,CAEoB,CAAC,CAAC,KAAK,OAAO,MAAM,aAAa,CAAC;AACvD,CAAC,CACF"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { i as Cmd, t as handler } from "./runtime-CK2CunDw.mjs";
|
|
2
|
-
import { f as writeOut, i as reportFailure, t as InvalidInputError } from "./error
|
|
3
|
-
import { r as write, t as locked } from "./jsonc-
|
|
4
|
-
import { a as readServers, n as configured } from "./shared-
|
|
2
|
+
import { f as writeOut, i as reportFailure, t as InvalidInputError } from "./error-CPyvkO4x.mjs";
|
|
3
|
+
import { r as write, t as locked } from "./jsonc-Ca0uQLm-.mjs";
|
|
4
|
+
import { a as readServers, n as configured } from "./shared-CDyNsYBy.mjs";
|
|
5
5
|
import { Effect, FileSystem } from "effect";
|
|
6
6
|
//#region src/cli/cmd/handlers/mcp/remove.ts
|
|
7
7
|
var remove_default = handler(Cmd.commands.mcp.commands.remove, Effect.fn("CLI.mcp.remove")(function* ({ name, local }) {
|
|
@@ -23,4 +23,4 @@ var remove_default = handler(Cmd.commands.mcp.commands.remove, Effect.fn("CLI.mc
|
|
|
23
23
|
//#endregion
|
|
24
24
|
export { remove_default as default };
|
|
25
25
|
|
|
26
|
-
//# sourceMappingURL=remove-
|
|
26
|
+
//# sourceMappingURL=remove-f7C_vEOD.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remove-
|
|
1
|
+
{"version":3,"file":"remove-f7C_vEOD.mjs","names":["Runtime.handler","Jsonc.locked","Jsonc.write"],"sources":["../../src/cli/cmd/handlers/mcp/remove.ts"],"sourcesContent":["import { Effect, FileSystem } from \"effect\";\nimport { Runtime } from \"../../../../framework/runtime.ts\";\nimport { InvalidInputError, reportFailure } from \"../../../error.ts\";\nimport { Jsonc } from \"../../../jsonc.ts\";\nimport { writeOut } from \"../../../output.ts\";\nimport { Cmd } from \"../../cmd.ts\";\nimport { configured, readServers } from \"./shared.ts\";\n\nexport default Runtime.handler(\n\tCmd.commands.mcp.commands.remove,\n\tEffect.fn(\"CLI.mcp.remove\")(function* ({ name, local }) {\n\t\tconst program = Effect.gen(function* () {\n\t\t\tconst { user, project, servers } = yield* configured();\n\t\t\tconst path = local ? project : user;\n\t\t\tconst level = local ? \"project\" : \"user\";\n\t\t\tconst fs = yield* FileSystem.FileSystem;\n\t\t\t// No file, nothing to remove: locking it would make its directory, and a `.codework/` here.\n\t\t\tconst removed =\n\t\t\t\t(yield* fs.exists(path)) &&\n\t\t\t\t(yield* Jsonc.locked(\n\t\t\t\t\tpath,\n\t\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\t\tconst { source, servers } = yield* readServers(path);\n\t\t\t\t\t\tif (servers[name] === undefined) return false;\n\t\t\t\t\t\tyield* Jsonc.write(path, source, [\"mcpServers\", name], undefined);\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t}),\n\t\t\t\t));\n\t\t\tif (removed) return yield* writeOut(`Removed ${level} MCP server \"${name}\" from ${path}.\\n`);\n\t\t\tconst other = servers.find((server) => server.name === name && server.file !== path);\n\t\t\tconst hint =\n\t\t\t\tother === undefined\n\t\t\t\t\t? \"\"\n\t\t\t\t\t: ` It is defined in ${other.file}; ${other.file === project ? \"use --local\" : \"omit --local\"}.`;\n\t\t\treturn yield* new InvalidInputError({\n\t\t\t\tmessage: `no ${level} MCP server named \"${name}\" in ${path}.${hint}`,\n\t\t\t});\n\t\t});\n\t\treturn yield* program.pipe(Effect.catch(reportFailure));\n\t}),\n);\n"],"mappings":";;;;;;AAQA,IAAA,iBAAeA,QACd,IAAI,SAAS,IAAI,SAAS,QAC1B,OAAO,GAAG,gBAAgB,CAAC,CAAC,WAAW,EAAE,MAAM,SAAS;CA4BvD,OAAO,OA3BS,OAAO,IAAI,aAAa;EACvC,MAAM,EAAE,MAAM,SAAS,YAAY,OAAO,WAAW;EACrD,MAAM,OAAO,QAAQ,UAAU;EAC/B,MAAM,QAAQ,QAAQ,YAAY;EAclC,KAVE,QAAO,OAHS,WAAW,WAAA,CAGjB,OAAO,IAAI,OACrB,OAAOC,OACP,MACA,OAAO,IAAI,aAAa;GACvB,MAAM,EAAE,QAAQ,YAAY,OAAO,YAAY,IAAI;GACnD,IAAI,QAAQ,UAAU,KAAA,GAAW,OAAO;GACxC,OAAOC,MAAY,MAAM,QAAQ,CAAC,cAAc,IAAI,GAAG,KAAA,CAAS;GAChE,OAAO;EACR,CAAC,CACF,IACY,OAAO,OAAO,SAAS,WAAW,MAAM,eAAe,KAAK,SAAS,KAAK,IAAI;EAC3F,MAAM,QAAQ,QAAQ,MAAM,WAAW,OAAO,SAAS,QAAQ,OAAO,SAAS,IAAI;EACnF,MAAM,OACL,UAAU,KAAA,IACP,KACA,qBAAqB,MAAM,KAAK,IAAI,MAAM,SAAS,UAAU,gBAAgB,eAAe;EAChG,OAAO,OAAO,IAAI,kBAAkB,EACnC,SAAS,MAAM,MAAM,qBAAqB,KAAK,OAAO,KAAK,GAAG,OAC/D,CAAC;CACF,CACoB,CAAC,CAAC,KAAK,OAAO,MAAM,aAAa,CAAC;AACvD,CAAC,CACF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { i as Cmd, t as handler } from "./runtime-CK2CunDw.mjs";
|
|
2
|
-
import { f as writeOut, i as reportFailure } from "./error
|
|
3
|
-
import { a as stop, i as ensure, n as options } from "./service-
|
|
2
|
+
import { f as writeOut, i as reportFailure } from "./error-CPyvkO4x.mjs";
|
|
3
|
+
import { a as stop, i as ensure, n as options } from "./service-BrM1uS4y.mjs";
|
|
4
4
|
import { Effect } from "effect";
|
|
5
5
|
//#region src/cli/cmd/handlers/service/restart.ts
|
|
6
6
|
var restart_default = handler(Cmd.commands.service.commands.restart, Effect.fn("CLI.service.restart")(function* ({ host, port }) {
|
|
@@ -18,4 +18,4 @@ var restart_default = handler(Cmd.commands.service.commands.restart, Effect.fn("
|
|
|
18
18
|
//#endregion
|
|
19
19
|
export { restart_default as default };
|
|
20
20
|
|
|
21
|
-
//# sourceMappingURL=restart-
|
|
21
|
+
//# sourceMappingURL=restart-1Ig29_n9.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"restart-
|
|
1
|
+
{"version":3,"file":"restart-1Ig29_n9.mjs","names":["Runtime.handler","options","Service.options","Discovery.stop","Discovery.ensure"],"sources":["../../src/cli/cmd/handlers/service/restart.ts"],"sourcesContent":["import { Effect } from \"effect\";\nimport { Runtime } from \"../../../../framework/runtime.ts\";\nimport { Discovery } from \"../../../../server/discovery.ts\";\nimport { reportFailure } from \"../../../error.ts\";\nimport { writeOut } from \"../../../output.ts\";\nimport { Service } from \"../../../service.ts\";\nimport { Cmd } from \"../../cmd.ts\";\n\nexport default Runtime.handler(\n\tCmd.commands.service.commands.restart,\n\tEffect.fn(\"CLI.service.restart\")(function* ({ host, port }) {\n\t\tconst options = yield* Service.options(yield* Cmd.spec, { host, port });\n\t\tyield* Discovery.stop(options.home);\n\t\tconst server = yield* Discovery.ensure({ ...options, replace: true });\n\t\tyield* writeOut(`${server.url}\\n`);\n\t}, Effect.catch(reportFailure)),\n);\n"],"mappings":";;;;;AAQA,IAAA,kBAAeA,QACd,IAAI,SAAS,QAAQ,SAAS,SAC9B,OAAO,GAAG,qBAAqB,CAAC,CAAC,WAAW,EAAE,MAAM,QAAQ;CAC3D,MAAMC,YAAU,OAAOC,QAAgB,OAAO,IAAI,MAAM;EAAE;EAAM;CAAK,CAAC;CACtE,OAAOC,KAAeF,UAAQ,IAAI;CAClC,MAAM,SAAS,OAAOG,OAAiB;EAAE,GAAGH;EAAS,SAAS;CAAK,CAAC;CACpE,OAAO,SAAS,GAAG,OAAO,IAAI,GAAG;AAClC,GAAG,OAAO,MAAM,aAAa,CAAC,CAC/B"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { i as Cmd, t as handler } from "./runtime-CK2CunDw.mjs";
|
|
2
|
-
import { a as addUsage, c as terminalColumns, f as writeOut, h as run, l as usage, m as make, o as emptyUsage, p as layer, r as renderError, s as header, t as InvalidInputError, u as writeError } from "./error
|
|
2
|
+
import { a as addUsage, c as terminalColumns, f as writeOut, h as run, l as usage, m as make, o as emptyUsage, p as layer, r as renderError, s as header, t as InvalidInputError, u as writeError } from "./error-CPyvkO4x.mjs";
|
|
3
3
|
import { t as harnessOptions } from "./harness-6d8TlAVk.mjs";
|
|
4
|
-
import { t as threadFlag } from "./thread-
|
|
4
|
+
import { t as threadFlag } from "./thread-I6vNdC0y.mjs";
|
|
5
5
|
import { Effect, Exit, Fiber, Logger, Option, Queue, Ref, Schema, Stream } from "effect";
|
|
6
6
|
import { EventList, Harness, Sandbox, Session } from "@codeworksh/harness/effect";
|
|
7
7
|
//#region src/cli/cmd/handlers/run.ts
|
|
@@ -159,4 +159,4 @@ var run_default = handler(Cmd.commands.run, Effect.fn("CLI.run", { level: "Info"
|
|
|
159
159
|
//#endregion
|
|
160
160
|
export { run_default as default };
|
|
161
161
|
|
|
162
|
-
//# sourceMappingURL=run-
|
|
162
|
+
//# sourceMappingURL=run-CTFksYXE.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-BX65GBq_.mjs","names":["Runtime.handler","Client.make","Client.run","Client.layer"],"sources":["../../src/cli/cmd/handlers/run.ts"],"sourcesContent":["import { EventList, type EventSchema, Harness, Sandbox, Session } from \"@codeworksh/harness/effect\";\nimport { Effect, Exit, Fiber, Logger, Option, Queue, Ref, Schema, Stream } from \"effect\";\nimport { Runtime } from \"../../../framework/runtime.ts\";\nimport { Client } from \"../../../server/client.ts\";\nimport { InvalidInputError, renderError } from \"../../error.ts\";\nimport { harnessOptions } from \"../../harness.ts\";\nimport {\n\taddUsage,\n\temptyUsage,\n\theader,\n\tterminalColumns,\n\tusage,\n\ttype UsageSummary,\n\twriteError,\n\twriteOut,\n} from \"../../output.ts\";\nimport { threadFlag } from \"../../thread.ts\";\nimport { Cmd } from \"../cmd.ts\";\n\ninterface RenderState {\n\treadonly usage: UsageSummary;\n\treadonly textSeen: boolean;\n\treadonly textEndsWithNewline: boolean;\n\treadonly reason?: EventList.LLMEnded[\"data\"][\"reason\"];\n}\n\nconst initialRenderState: RenderState = {\n\tusage: emptyUsage,\n\ttextSeen: false,\n\ttextEndsWithNewline: false,\n};\n\nconst isTextDelta = Schema.is(EventList.LLMTextDelta);\nconst isLLMEnded = Schema.is(EventList.LLMEnded);\nconst isTurnEnded = Schema.is(EventList.TurnEnded);\n\nconst render = (state: Ref.Ref<RenderState>, ended?: Queue.Queue<string>) =>\n\tEffect.fn(\"CLI.render\")(function* (event: EventSchema.Payload) {\n\t\tif (isTextDelta(event)) {\n\t\t\tyield* writeOut(event.data.delta);\n\t\t\tif (event.data.delta.length > 0) {\n\t\t\t\tyield* Ref.update(state, (current) => ({\n\t\t\t\t\t...current,\n\t\t\t\t\ttextSeen: true,\n\t\t\t\t\ttextEndsWithNewline: event.data.delta.endsWith(\"\\n\"),\n\t\t\t\t}));\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tif (isLLMEnded(event)) {\n\t\t\tyield* Ref.update(state, (current) => ({\n\t\t\t\t...current,\n\t\t\t\tusage: addUsage(current.usage, event.data.message),\n\t\t\t\treason: event.data.reason,\n\t\t\t}));\n\t\t\treturn;\n\t\t}\n\t\tif (ended !== undefined && isTurnEnded(event)) {\n\t\t\tyield* Queue.offer(ended, event.data.messageId);\n\t\t}\n\t});\n\nconst finish = Effect.fn(\"CLI.finish\")(function* (state: Ref.Ref<RenderState>, columns: number) {\n\tconst rendered = yield* Ref.get(state);\n\tif (rendered.textSeen && !rendered.textEndsWithNewline) yield* writeOut(\"\\n\");\n\tyield* writeError(usage(rendered.usage, columns));\n\tif (rendered.reason === \"length\") {\n\t\tyield* writeError(\"Response was truncated: the model reached its output token limit.\\n\");\n\t\tyield* Effect.sync(() => {\n\t\t\tprocess.exitCode = 1;\n\t\t});\n\t}\n});\n\nconst awaitMessage = Effect.fn(\"CLI.awaitMessage\")(function* (ended: Queue.Queue<string>, messageId: string) {\n\twhile ((yield* Queue.take(ended)) !== messageId) {\n\t\t// Earlier turns in the same drain are expected when a tool call continues.\n\t}\n});\n\nconst selectSandbox = Effect.fn(\"CLI.selectSandbox\", { level: \"Info\" })(function* (input: Sandbox.Selection) {\n\tconst selection = yield* Sandbox.resolve(input);\n\tif (selection.created && selection.info !== undefined) {\n\t\tconst id = selection.info.id;\n\t\tyield* Effect.addFinalizer(() => Effect.ignore(Sandbox.stop(id)));\n\t}\n\treturn selection.info;\n});\n\nexport default Runtime.handler(\n\tCmd.commands.run,\n\tEffect.fn(\"CLI.run\", { level: \"Info\" })(function* ({\n\t\tprompt,\n\t\tsession,\n\t\tthread,\n\t\tcwd,\n\t\tsandboxDriver,\n\t\tsandboxProviderId,\n\t\tsandboxId,\n\t\tprovider,\n\t\tmodel,\n\t\tthinking,\n\t\tserver,\n\t}) {\n\t\tconst shared = yield* Cmd.spec;\n\t\tif (\n\t\t\tOption.isSome(session) &&\n\t\t\t(Option.isSome(cwd) ||\n\t\t\t\tOption.isSome(sandboxDriver) ||\n\t\t\t\tOption.isSome(sandboxProviderId) ||\n\t\t\t\tOption.isSome(sandboxId))\n\t\t) {\n\t\t\treturn yield* new InvalidInputError({\n\t\t\t\tmessage:\n\t\t\t\t\t\"--cwd, --sandbox-driver, --sandbox-id, and --sandbox-provider-id can only be used when creating a new session\",\n\t\t\t});\n\t\t}\n\t\tif (Option.isSome(thread) && Option.isNone(session)) {\n\t\t\treturn yield* new InvalidInputError({ message: \"--thread continues a thread of --session\" });\n\t\t}\n\t\tconst threadId = yield* threadFlag(thread);\n\t\tif (Option.isSome(provider) !== Option.isSome(model)) {\n\t\t\treturn yield* new InvalidInputError({ message: \"--provider and --model must be provided together\" });\n\t\t}\n\t\tif (Option.isSome(sandboxProviderId) && Option.isNone(sandboxDriver)) {\n\t\t\treturn yield* new InvalidInputError({\n\t\t\t\tmessage: \"--sandbox-provider-id requires a remote --sandbox-driver\",\n\t\t\t});\n\t\t}\n\t\tif (Option.isSome(server) && [shared.home, shared.database, shared.userConfigDir].some(Option.isSome)) {\n\t\t\treturn yield* new InvalidInputError({\n\t\t\t\tmessage: \"--home, --database, and --user-config-dir belong on codework serve when using --server\",\n\t\t\t});\n\t\t}\n\n\t\tif (Option.isSome(sandboxId) && (Option.isSome(sandboxDriver) || Option.isSome(sandboxProviderId))) {\n\t\t\treturn yield* new InvalidInputError({\n\t\t\t\tmessage: \"--sandbox-id cannot be combined with --sandbox-driver or --sandbox-provider-id\",\n\t\t\t});\n\t\t}\n\t\tconst selection: Sandbox.Selection = Option.isSome(sandboxId)\n\t\t\t? { id: Sandbox.SandboxInstance.ID.make(sandboxId.value) }\n\t\t\t: {\n\t\t\t\t\tdriver: Option.getOrElse(sandboxDriver, () => \"local\"),\n\t\t\t\t\t...(Option.isNone(sandboxProviderId) ? {} : { providerResourceId: sandboxProviderId.value }),\n\t\t\t\t};\n\n\t\t// The session's host directory, with no flag to set it: a person running a command is always\n\t\t// somewhere, and that somewhere is what they mean by \"this project\". `--cwd` is a different\n\t\t// thing entirely -- where the work runs inside the session's space, which may be a sandbox\n\t\t// on another machine.\n\t\tconst hostDir = Session.AbsolutePath.make(process.cwd());\n\n\t\tconst runtime = {\n\t\t\t...(Option.isNone(provider) || Option.isNone(model)\n\t\t\t\t? {}\n\t\t\t\t: { model: { provider: provider.value, id: model.value } }),\n\t\t\t...(Option.isNone(thinking) ? {} : { thinkingLevel: thinking.value }),\n\t\t};\n\t\tconst remote = Effect.gen(function* () {\n\t\t\tconst rpc = yield* Client.make;\n\t\t\tconst info = Option.isSome(session)\n\t\t\t\t? yield* rpc[\"thread.configure\"]({\n\t\t\t\t\t\tsessionId: Session.SessionSchema.ID.make(session.value),\n\t\t\t\t\t\t...(threadId === undefined ? {} : { threadId }),\n\t\t\t\t\t\truntime,\n\t\t\t\t\t})\n\t\t\t\t: yield* rpc[\"session.create\"]({\n\t\t\t\t\t\truntime,\n\t\t\t\t\t\t...(Option.isNone(cwd) ? {} : { directory: cwd.value }),\n\t\t\t\t\t\thostDir,\n\t\t\t\t\t\tsandbox: selection,\n\t\t\t\t\t});\n\t\t\tconst state = yield* Ref.make(initialRenderState);\n\t\t\tconst columns = terminalColumns();\n\t\t\tyield* writeError(\n\t\t\t\theader({\n\t\t\t\t\tsessionId: info.session.id,\n\t\t\t\t\tsandbox: info.session.sandbox?.driver ?? \"local\",\n\t\t\t\t\tdirectory: info.placement?.directory ?? info.session.directory,\n\t\t\t\t\tcolumns,\n\t\t\t\t}),\n\t\t\t);\n\t\t\tif (info.session.sandbox !== undefined) yield* writeError(`sandbox-id: ${info.session.sandbox.id}\\n`);\n\t\t\tyield* Client.run(rpc, { sessionId: info.session.id, threadId: info.id, text: prompt }, render(state)).pipe(\n\t\t\t\tEffect.onInterrupt(() =>\n\t\t\t\t\trpc[\"thread.interrupt\"]({ sessionId: info.session.id, threadId: info.id }).pipe(\n\t\t\t\t\t\tEffect.timeout(\"5 seconds\"),\n\t\t\t\t\t\tEffect.ignore,\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t);\n\t\t\tyield* finish(state, columns);\n\t\t});\n\t\tconst program = Effect.gen(function* () {\n\t\t\tlet handle: Session.ThreadHandle;\n\t\t\tif (Option.isSome(session)) {\n\t\t\t\thandle = yield* Session.attach({\n\t\t\t\t\tsessionId: Session.SessionSchema.ID.make(session.value),\n\t\t\t\t\t...(threadId === undefined ? {} : { threadId }),\n\t\t\t\t\t...runtime,\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tconst selected = yield* selectSandbox(selection);\n\t\t\t\tconst created = yield* Session.create({\n\t\t\t\t\t...runtime,\n\t\t\t\t\t...(selected === undefined ? {} : { sandbox: selected }),\n\t\t\t\t\t...(Option.isNone(cwd) ? {} : { directory: cwd.value }),\n\t\t\t\t\thostDir,\n\t\t\t\t});\n\t\t\t\thandle = created.main;\n\t\t\t}\n\t\t\tconst ended = yield* Queue.unbounded<string>();\n\t\t\tconst renderState = yield* Ref.make(initialRenderState);\n\t\t\tconst printer = yield* handle\n\t\t\t\t.events()\n\t\t\t\t.pipe(Stream.runForEach(render(renderState, ended)), Effect.forkScoped({ startImmediately: true }));\n\n\t\t\tconst info = yield* handle.info;\n\t\t\tconst columns = terminalColumns();\n\t\t\tyield* writeError(\n\t\t\t\theader({\n\t\t\t\t\tsessionId: handle.sessionId,\n\t\t\t\t\tsandbox: info.session.sandbox?.driver ?? \"local\",\n\t\t\t\t\tdirectory: info.placement?.directory ?? info.session.directory,\n\t\t\t\t\tcolumns,\n\t\t\t\t}),\n\t\t\t);\n\t\t\t// The local command joins execution to retain typed error details. Ctrl+C is the user stopping\n\t\t\t// the run, as on the remote path: named so, the next server start does not resume it.\n\t\t\tconst execution = yield* handle.prompt({ text: prompt, delivery: \"followUp\" }).pipe(\n\t\t\t\tEffect.andThen(handle.resume()),\n\t\t\t\tEffect.onInterrupt(() => handle.interrupt().pipe(Effect.timeout(\"5 seconds\"), Effect.ignore)),\n\t\t\t\tEffect.exit,\n\t\t\t);\n\t\t\tyield* handle.wait();\n\t\t\tif (Exit.isFailure(execution)) return yield* Effect.failCause(execution.cause);\n\t\t\tconst leaf = (yield* handle.history()).at(-1);\n\t\t\tif (leaf !== undefined) yield* awaitMessage(ended, leaf.entry.id);\n\t\t\tyield* Fiber.interrupt(printer);\n\t\t\tyield* finish(renderState, columns);\n\t\t});\n\n\t\t// Scope inside the provided layer, so the run's finalizers (stopping a created sandbox) close\n\t\t// while the harness and its database are still open.\n\t\tconst execute = Effect.gen(function* () {\n\t\t\tif (Option.isSome(server))\n\t\t\t\treturn yield* remote.pipe(Effect.scoped, Effect.provide(Client.layer(server.value)));\n\t\t\t// Stdout carries only the response; harness logs go with the rest of the diagnostics.\n\t\t\treturn yield* program.pipe(\n\t\t\t\tEffect.scoped,\n\t\t\t\tEffect.provide(Harness.layer(harnessOptions(shared))),\n\t\t\t\tEffect.provideService(Logger.LogToStderr, true),\n\t\t\t);\n\t\t});\n\t\treturn yield* execute.pipe(\n\t\t\tEffect.catch((error) =>\n\t\t\t\twriteError(renderError(error)).pipe(\n\t\t\t\t\tEffect.andThen(\n\t\t\t\t\t\tEffect.sync(() => {\n\t\t\t\t\t\t\tprocess.exitCode = 1;\n\t\t\t\t\t\t}),\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t),\n\t\t);\n\t}),\n);\n"],"mappings":";;;;;;;AA0BA,MAAM,qBAAkC;CACvC,OAAO;CACP,UAAU;CACV,qBAAqB;AACtB;AAEA,MAAM,cAAc,OAAO,GAAG,UAAU,YAAY;AACpD,MAAM,aAAa,OAAO,GAAG,UAAU,QAAQ;AAC/C,MAAM,cAAc,OAAO,GAAG,UAAU,SAAS;AAEjD,MAAM,UAAU,OAA6B,UAC5C,OAAO,GAAG,YAAY,CAAC,CAAC,WAAW,OAA4B;CAC9D,IAAI,YAAY,KAAK,GAAG;EACvB,OAAO,SAAS,MAAM,KAAK,KAAK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,KAAK,OAAO,QAAQ,WAAW,GAAG,OAAO,MAAM,CAAC,GAC5F,OAAO,IACR;EACA,OAAO,OAAO,KAAK;EACnB,IAAI,KAAK,UAAU,SAAS,GAAG,OAAO,OAAO,OAAO,UAAU,UAAU,KAAK;EAC7E,MAAM,QAAQ,OAAO,OAAO,QAAQ,EAAA,CAAG,GAAG,EAAE;EAC5C,IAAI,SAAS,KAAA,GAAW,OAAO,aAAa,OAAO,KAAK,MAAM,EAAE;EAChE,OAAO,MAAM,UAAU,OAAO;EAC9B,OAAO,OAAO,aAAa,OAAO;CACnC,CAAC;CAcD,OAAO,OAVS,OAAO,IAAI,aAAa;EACvC,IAAI,OAAO,OAAO,MAAM,GACvB,OAAO,OAAO,OAAO,KAAK,OAAO,QAAQ,OAAO,QAAQC,MAAa,OAAO,KAAK,CAAC,CAAC;EAEpF,OAAO,OAAO,QAAQ,KACrB,OAAO,QACP,OAAO,QAAQ,QAAQ,MAAM,eAAe,MAAM,CAAC,CAAC,GACpD,OAAO,eAAe,OAAO,aAAa,IAAI,CAC/C;CACD,CACoB,CAAC,CAAC,KACrB,OAAO,OAAO,UACb,WAAW,YAAY,KAAK,CAAC,CAAC,CAAC,KAC9B,OAAO,QACN,OAAO,WAAW;EACjB,QAAQ,WAAW;CACpB,CAAC,CACF,CACD,CACD,CACD;AACD,CAAC,CACF"}
|
|
1
|
+
{"version":3,"file":"run-CTFksYXE.mjs","names":["Runtime.handler","Client.make","Client.run","Client.layer"],"sources":["../../src/cli/cmd/handlers/run.ts"],"sourcesContent":["import { EventList, type EventSchema, Harness, Sandbox, Session } from \"@codeworksh/harness/effect\";\nimport { Effect, Exit, Fiber, Logger, Option, Queue, Ref, Schema, Stream } from \"effect\";\nimport { Runtime } from \"../../../framework/runtime.ts\";\nimport { Client } from \"../../../server/client.ts\";\nimport { InvalidInputError, renderError } from \"../../error.ts\";\nimport { harnessOptions } from \"../../harness.ts\";\nimport {\n\taddUsage,\n\temptyUsage,\n\theader,\n\tterminalColumns,\n\tusage,\n\ttype UsageSummary,\n\twriteError,\n\twriteOut,\n} from \"../../output.ts\";\nimport { threadFlag } from \"../../thread.ts\";\nimport { Cmd } from \"../cmd.ts\";\n\ninterface RenderState {\n\treadonly usage: UsageSummary;\n\treadonly textSeen: boolean;\n\treadonly textEndsWithNewline: boolean;\n\treadonly reason?: EventList.LLMEnded[\"data\"][\"reason\"];\n}\n\nconst initialRenderState: RenderState = {\n\tusage: emptyUsage,\n\ttextSeen: false,\n\ttextEndsWithNewline: false,\n};\n\nconst isTextDelta = Schema.is(EventList.LLMTextDelta);\nconst isLLMEnded = Schema.is(EventList.LLMEnded);\nconst isTurnEnded = Schema.is(EventList.TurnEnded);\n\nconst render = (state: Ref.Ref<RenderState>, ended?: Queue.Queue<string>) =>\n\tEffect.fn(\"CLI.render\")(function* (event: EventSchema.Payload) {\n\t\tif (isTextDelta(event)) {\n\t\t\tyield* writeOut(event.data.delta);\n\t\t\tif (event.data.delta.length > 0) {\n\t\t\t\tyield* Ref.update(state, (current) => ({\n\t\t\t\t\t...current,\n\t\t\t\t\ttextSeen: true,\n\t\t\t\t\ttextEndsWithNewline: event.data.delta.endsWith(\"\\n\"),\n\t\t\t\t}));\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tif (isLLMEnded(event)) {\n\t\t\tyield* Ref.update(state, (current) => ({\n\t\t\t\t...current,\n\t\t\t\tusage: addUsage(current.usage, event.data.message),\n\t\t\t\treason: event.data.reason,\n\t\t\t}));\n\t\t\treturn;\n\t\t}\n\t\tif (ended !== undefined && isTurnEnded(event)) {\n\t\t\tyield* Queue.offer(ended, event.data.messageId);\n\t\t}\n\t});\n\nconst finish = Effect.fn(\"CLI.finish\")(function* (state: Ref.Ref<RenderState>, columns: number) {\n\tconst rendered = yield* Ref.get(state);\n\tif (rendered.textSeen && !rendered.textEndsWithNewline) yield* writeOut(\"\\n\");\n\tyield* writeError(usage(rendered.usage, columns));\n\tif (rendered.reason === \"length\") {\n\t\tyield* writeError(\"Response was truncated: the model reached its output token limit.\\n\");\n\t\tyield* Effect.sync(() => {\n\t\t\tprocess.exitCode = 1;\n\t\t});\n\t}\n});\n\nconst awaitMessage = Effect.fn(\"CLI.awaitMessage\")(function* (ended: Queue.Queue<string>, messageId: string) {\n\twhile ((yield* Queue.take(ended)) !== messageId) {\n\t\t// Earlier turns in the same drain are expected when a tool call continues.\n\t}\n});\n\nconst selectSandbox = Effect.fn(\"CLI.selectSandbox\", { level: \"Info\" })(function* (input: Sandbox.Selection) {\n\tconst selection = yield* Sandbox.resolve(input);\n\tif (selection.created && selection.info !== undefined) {\n\t\tconst id = selection.info.id;\n\t\tyield* Effect.addFinalizer(() => Effect.ignore(Sandbox.stop(id)));\n\t}\n\treturn selection.info;\n});\n\nexport default Runtime.handler(\n\tCmd.commands.run,\n\tEffect.fn(\"CLI.run\", { level: \"Info\" })(function* ({\n\t\tprompt,\n\t\tsession,\n\t\tthread,\n\t\tcwd,\n\t\tsandboxDriver,\n\t\tsandboxProviderId,\n\t\tsandboxId,\n\t\tprovider,\n\t\tmodel,\n\t\tthinking,\n\t\tserver,\n\t}) {\n\t\tconst shared = yield* Cmd.spec;\n\t\tif (\n\t\t\tOption.isSome(session) &&\n\t\t\t(Option.isSome(cwd) ||\n\t\t\t\tOption.isSome(sandboxDriver) ||\n\t\t\t\tOption.isSome(sandboxProviderId) ||\n\t\t\t\tOption.isSome(sandboxId))\n\t\t) {\n\t\t\treturn yield* new InvalidInputError({\n\t\t\t\tmessage:\n\t\t\t\t\t\"--cwd, --sandbox-driver, --sandbox-id, and --sandbox-provider-id can only be used when creating a new session\",\n\t\t\t});\n\t\t}\n\t\tif (Option.isSome(thread) && Option.isNone(session)) {\n\t\t\treturn yield* new InvalidInputError({ message: \"--thread continues a thread of --session\" });\n\t\t}\n\t\tconst threadId = yield* threadFlag(thread);\n\t\tif (Option.isSome(provider) !== Option.isSome(model)) {\n\t\t\treturn yield* new InvalidInputError({ message: \"--provider and --model must be provided together\" });\n\t\t}\n\t\tif (Option.isSome(sandboxProviderId) && Option.isNone(sandboxDriver)) {\n\t\t\treturn yield* new InvalidInputError({\n\t\t\t\tmessage: \"--sandbox-provider-id requires a remote --sandbox-driver\",\n\t\t\t});\n\t\t}\n\t\tif (Option.isSome(server) && [shared.home, shared.database, shared.userConfigDir].some(Option.isSome)) {\n\t\t\treturn yield* new InvalidInputError({\n\t\t\t\tmessage: \"--home, --database, and --user-config-dir belong on codework serve when using --server\",\n\t\t\t});\n\t\t}\n\n\t\tif (Option.isSome(sandboxId) && (Option.isSome(sandboxDriver) || Option.isSome(sandboxProviderId))) {\n\t\t\treturn yield* new InvalidInputError({\n\t\t\t\tmessage: \"--sandbox-id cannot be combined with --sandbox-driver or --sandbox-provider-id\",\n\t\t\t});\n\t\t}\n\t\tconst selection: Sandbox.Selection = Option.isSome(sandboxId)\n\t\t\t? { id: Sandbox.SandboxInstance.ID.make(sandboxId.value) }\n\t\t\t: {\n\t\t\t\t\tdriver: Option.getOrElse(sandboxDriver, () => \"local\"),\n\t\t\t\t\t...(Option.isNone(sandboxProviderId) ? {} : { providerResourceId: sandboxProviderId.value }),\n\t\t\t\t};\n\n\t\t// The session's host directory, with no flag to set it: a person running a command is always\n\t\t// somewhere, and that somewhere is what they mean by \"this project\". `--cwd` is a different\n\t\t// thing entirely -- where the work runs inside the session's space, which may be a sandbox\n\t\t// on another machine.\n\t\tconst hostDir = Session.AbsolutePath.make(process.cwd());\n\n\t\tconst runtime = {\n\t\t\t...(Option.isNone(provider) || Option.isNone(model)\n\t\t\t\t? {}\n\t\t\t\t: { model: { provider: provider.value, id: model.value } }),\n\t\t\t...(Option.isNone(thinking) ? {} : { thinkingLevel: thinking.value }),\n\t\t};\n\t\tconst remote = Effect.gen(function* () {\n\t\t\tconst rpc = yield* Client.make;\n\t\t\tconst info = Option.isSome(session)\n\t\t\t\t? yield* rpc[\"thread.configure\"]({\n\t\t\t\t\t\tsessionId: Session.SessionSchema.ID.make(session.value),\n\t\t\t\t\t\t...(threadId === undefined ? {} : { threadId }),\n\t\t\t\t\t\truntime,\n\t\t\t\t\t})\n\t\t\t\t: yield* rpc[\"session.create\"]({\n\t\t\t\t\t\truntime,\n\t\t\t\t\t\t...(Option.isNone(cwd) ? {} : { directory: cwd.value }),\n\t\t\t\t\t\thostDir,\n\t\t\t\t\t\tsandbox: selection,\n\t\t\t\t\t});\n\t\t\tconst state = yield* Ref.make(initialRenderState);\n\t\t\tconst columns = terminalColumns();\n\t\t\tyield* writeError(\n\t\t\t\theader({\n\t\t\t\t\tsessionId: info.session.id,\n\t\t\t\t\tsandbox: info.session.sandbox?.driver ?? \"local\",\n\t\t\t\t\tdirectory: info.placement?.directory ?? info.session.directory,\n\t\t\t\t\tcolumns,\n\t\t\t\t}),\n\t\t\t);\n\t\t\tif (info.session.sandbox !== undefined) yield* writeError(`sandbox-id: ${info.session.sandbox.id}\\n`);\n\t\t\tyield* Client.run(rpc, { sessionId: info.session.id, threadId: info.id, text: prompt }, render(state)).pipe(\n\t\t\t\tEffect.onInterrupt(() =>\n\t\t\t\t\trpc[\"thread.interrupt\"]({ sessionId: info.session.id, threadId: info.id }).pipe(\n\t\t\t\t\t\tEffect.timeout(\"5 seconds\"),\n\t\t\t\t\t\tEffect.ignore,\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t);\n\t\t\tyield* finish(state, columns);\n\t\t});\n\t\tconst program = Effect.gen(function* () {\n\t\t\tlet handle: Session.ThreadHandle;\n\t\t\tif (Option.isSome(session)) {\n\t\t\t\thandle = yield* Session.attach({\n\t\t\t\t\tsessionId: Session.SessionSchema.ID.make(session.value),\n\t\t\t\t\t...(threadId === undefined ? {} : { threadId }),\n\t\t\t\t\t...runtime,\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tconst selected = yield* selectSandbox(selection);\n\t\t\t\tconst created = yield* Session.create({\n\t\t\t\t\t...runtime,\n\t\t\t\t\t...(selected === undefined ? {} : { sandbox: selected }),\n\t\t\t\t\t...(Option.isNone(cwd) ? {} : { directory: cwd.value }),\n\t\t\t\t\thostDir,\n\t\t\t\t});\n\t\t\t\thandle = created.main;\n\t\t\t}\n\t\t\tconst ended = yield* Queue.unbounded<string>();\n\t\t\tconst renderState = yield* Ref.make(initialRenderState);\n\t\t\tconst printer = yield* handle\n\t\t\t\t.events()\n\t\t\t\t.pipe(Stream.runForEach(render(renderState, ended)), Effect.forkScoped({ startImmediately: true }));\n\n\t\t\tconst info = yield* handle.info;\n\t\t\tconst columns = terminalColumns();\n\t\t\tyield* writeError(\n\t\t\t\theader({\n\t\t\t\t\tsessionId: handle.sessionId,\n\t\t\t\t\tsandbox: info.session.sandbox?.driver ?? \"local\",\n\t\t\t\t\tdirectory: info.placement?.directory ?? info.session.directory,\n\t\t\t\t\tcolumns,\n\t\t\t\t}),\n\t\t\t);\n\t\t\t// The local command joins execution to retain typed error details. Ctrl+C is the user stopping\n\t\t\t// the run, as on the remote path: named so, the next server start does not resume it.\n\t\t\tconst execution = yield* handle.prompt({ text: prompt, delivery: \"followUp\" }).pipe(\n\t\t\t\tEffect.andThen(handle.resume()),\n\t\t\t\tEffect.onInterrupt(() => handle.interrupt().pipe(Effect.timeout(\"5 seconds\"), Effect.ignore)),\n\t\t\t\tEffect.exit,\n\t\t\t);\n\t\t\tyield* handle.wait();\n\t\t\tif (Exit.isFailure(execution)) return yield* Effect.failCause(execution.cause);\n\t\t\tconst leaf = (yield* handle.history()).at(-1);\n\t\t\tif (leaf !== undefined) yield* awaitMessage(ended, leaf.entry.id);\n\t\t\tyield* Fiber.interrupt(printer);\n\t\t\tyield* finish(renderState, columns);\n\t\t});\n\n\t\t// Scope inside the provided layer, so the run's finalizers (stopping a created sandbox) close\n\t\t// while the harness and its database are still open.\n\t\tconst execute = Effect.gen(function* () {\n\t\t\tif (Option.isSome(server))\n\t\t\t\treturn yield* remote.pipe(Effect.scoped, Effect.provide(Client.layer(server.value)));\n\t\t\t// Stdout carries only the response; harness logs go with the rest of the diagnostics.\n\t\t\treturn yield* program.pipe(\n\t\t\t\tEffect.scoped,\n\t\t\t\tEffect.provide(Harness.layer(harnessOptions(shared))),\n\t\t\t\tEffect.provideService(Logger.LogToStderr, true),\n\t\t\t);\n\t\t});\n\t\treturn yield* execute.pipe(\n\t\t\tEffect.catch((error) =>\n\t\t\t\twriteError(renderError(error)).pipe(\n\t\t\t\t\tEffect.andThen(\n\t\t\t\t\t\tEffect.sync(() => {\n\t\t\t\t\t\t\tprocess.exitCode = 1;\n\t\t\t\t\t\t}),\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t),\n\t\t);\n\t}),\n);\n"],"mappings":";;;;;;;AA0BA,MAAM,qBAAkC;CACvC,OAAO;CACP,UAAU;CACV,qBAAqB;AACtB;AAEA,MAAM,cAAc,OAAO,GAAG,UAAU,YAAY;AACpD,MAAM,aAAa,OAAO,GAAG,UAAU,QAAQ;AAC/C,MAAM,cAAc,OAAO,GAAG,UAAU,SAAS;AAEjD,MAAM,UAAU,OAA6B,UAC5C,OAAO,GAAG,YAAY,CAAC,CAAC,WAAW,OAA4B;CAC9D,IAAI,YAAY,KAAK,GAAG;EACvB,OAAO,SAAS,MAAM,KAAK,KAAK;EAChC,IAAI,MAAM,KAAK,MAAM,SAAS,GAC7B,OAAO,IAAI,OAAO,QAAQ,aAAa;GACtC,GAAG;GACH,UAAU;GACV,qBAAqB,MAAM,KAAK,MAAM,SAAS,IAAI;EACpD,EAAE;EAEH;CACD;CACA,IAAI,WAAW,KAAK,GAAG;EACtB,OAAO,IAAI,OAAO,QAAQ,aAAa;GACtC,GAAG;GACH,OAAO,SAAS,QAAQ,OAAO,MAAM,KAAK,OAAO;GACjD,QAAQ,MAAM,KAAK;EACpB,EAAE;EACF;CACD;CACA,IAAI,UAAU,KAAA,KAAa,YAAY,KAAK,GAC3C,OAAO,MAAM,MAAM,OAAO,MAAM,KAAK,SAAS;AAEhD,CAAC;AAEF,MAAM,SAAS,OAAO,GAAG,YAAY,CAAC,CAAC,WAAW,OAA6B,SAAiB;CAC/F,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AC;EAEpF,OAAO,OAAO,QAAQ,KACrB,OAAO,QACP,OAAO,QAAQ,QAAQ,MAAM,eAAe,MAAM,CAAC,CAAC,GACpD,OAAO,eAAe,OAAO,aAAa,IAAI,CAC/C;CACD,CACoB,CAAC,CAAC,KACrB,OAAO,OAAO,UACb,WAAW,YAAY,KAAK,CAAC,CAAC,CAAC,KAC9B,OAAO,QACN,OAAO,WAAW;EACjB,QAAQ,WAAW;CACpB,CAAC,CACF,CACD,CACD,CACD;AACD,CAAC,CACF"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { i as Cmd, t as handler } from "./runtime-CK2CunDw.mjs";
|
|
2
|
-
import { C as Core, S as Connected, T as ofThread, _ as HostError, b as path, g as Api, r as renderError, u as writeError, v as OAuthError, w as encode, x as decode } from "./error
|
|
2
|
+
import { C as Core, S as Connected, T as ofThread, _ as HostError, b as path, g as Api, r as renderError, u as writeError, v as OAuthError, w as encode, x as decode } from "./error-CPyvkO4x.mjs";
|
|
3
3
|
import { t as harnessOptions } from "./harness-6d8TlAVk.mjs";
|
|
4
|
-
import { c as register, r as layer$6, s as log, t as Service$4 } from "./identity-
|
|
5
|
-
import { Cause, Clock, Context, Data, DateTime, Effect, Exit, Fiber, FileSystem, Layer, Logger, Option, Path, PubSub, Queue, Ref, Schedule, Schema, Scope, Semaphore, Stream } from "effect";
|
|
4
|
+
import { c as register, r as layer$6, s as log, t as Service$4 } from "./identity-kubcIgQ6.mjs";
|
|
5
|
+
import { Cause, Clock, Context, Data, DateTime, Effect, Exit, Fiber, FileSystem, Layer, Logger, Option, Path, Predicate, PubSub, Queue, Ref, Schedule, Schema, Scope, Semaphore, Stream } from "effect";
|
|
6
6
|
import { Model } from "@codeworksh/aikit";
|
|
7
7
|
import { HttpRouter, HttpServer } from "effect/http";
|
|
8
|
-
import { Control, Event, EventList, EventRegistry, EventSchema, Git, Global, Harness, Mcp, ModelCatalog, Project, PromptSchema, Sandbox, Session, SessionStore, Settings, State, ThreadSchema, ThreadStore, expandTilde } from "@codeworksh/harness/effect";
|
|
8
|
+
import { Control, Event, EventList, EventRegistry, EventSchema, Git, Global, Harness, Mcp, ModelCatalog, Project, PromptSchema, Sandbox, Session, SessionStore, Settings, State, Store, Sync, ThreadSchema, ThreadStore, expandTilde } from "@codeworksh/harness/effect";
|
|
9
9
|
import { NodeHttpServer } from "@effect/platform-node";
|
|
10
10
|
import { RpcSerialization, RpcServer } from "effect/rpc";
|
|
11
11
|
import { summarizeGitHubCopilot, summarizeOpenAICodex } from "@codeworksh/aikit/oauth/summary";
|
|
@@ -821,6 +821,28 @@ const layer$2 = (options = {}) => Layer.effect(Service, Effect.gen(function* ()
|
|
|
821
821
|
logout: (provider) => attempt(() => provider === "openai-codex" ? codex.logout() : copilot.logout())
|
|
822
822
|
});
|
|
823
823
|
}));
|
|
824
|
+
/** Every row past `from` up to `head`, page by page, then `synced` at that head. */
|
|
825
|
+
const range = (from, head, page, synced) => Stream.paginate({ rev: from }, (cursor) => page(cursor, head.rev).pipe(Effect.map(({ items, next }) => [items, Option.fromUndefinedOr(next)]))).pipe(Stream.concat(Stream.make(synced(head))));
|
|
826
|
+
/**
|
|
827
|
+
* A revision-ordered stream: `start` at the head when it opens, then every row past the last head
|
|
828
|
+
* sent, page by page, and `synced` at the new head after each commit. The doorbell is registered
|
|
829
|
+
* before the first read, so no commit falls between.
|
|
830
|
+
*/
|
|
831
|
+
const watch = (start, page, synced) => Stream.unwrap(Effect.gen(function* () {
|
|
832
|
+
const store = yield* Store.Service;
|
|
833
|
+
const wake = yield* store.wake;
|
|
834
|
+
let sent;
|
|
835
|
+
const round = Stream.unwrap(Effect.gen(function* () {
|
|
836
|
+
const head = yield* store.head;
|
|
837
|
+
if (head.rev === sent) return Stream.empty;
|
|
838
|
+
const from = sent;
|
|
839
|
+
sent = head.rev;
|
|
840
|
+
return from === void 0 ? start(head) : range(from, head, page, synced);
|
|
841
|
+
}));
|
|
842
|
+
return Stream.make(void 0).pipe(Stream.concat(Stream.fromSubscription(wake)), Stream.flatMap(() => round));
|
|
843
|
+
}));
|
|
844
|
+
/** `watch` from revision `after`: every row past it first, then the same live. */
|
|
845
|
+
const follow = (after, page, synced) => watch((head) => range(after, head, page, synced), page, synced);
|
|
824
846
|
//#endregion
|
|
825
847
|
//#region src/server/handlers.ts
|
|
826
848
|
const toSandboxInfo = (info) => ({
|
|
@@ -837,15 +859,21 @@ const toSandboxInfo = (info) => ({
|
|
|
837
859
|
});
|
|
838
860
|
const toSessionInfo = (info) => ({
|
|
839
861
|
id: info.id,
|
|
862
|
+
spaceId: info.spaceId,
|
|
863
|
+
slug: info.slug,
|
|
840
864
|
directory: info.directory,
|
|
841
865
|
...info.hostDir === void 0 ? {} : { hostDir: info.hostDir },
|
|
842
866
|
...info.sandbox === void 0 ? {} : { sandbox: toSandboxInfo(info.sandbox) },
|
|
843
867
|
...info.project === void 0 ? {} : { project: info.project },
|
|
868
|
+
...info.tag === void 0 ? {} : { tag: info.tag },
|
|
869
|
+
...info.metadata === void 0 ? {} : { metadata: info.metadata },
|
|
870
|
+
createdAt: info.createdAt,
|
|
844
871
|
updatedAt: info.updatedAt,
|
|
845
872
|
mainThreadId: info.mainThreadId
|
|
846
873
|
});
|
|
847
|
-
const
|
|
874
|
+
const toThreadSummary = (info) => ({
|
|
848
875
|
id: info.id,
|
|
876
|
+
sessionId: info.sessionId,
|
|
849
877
|
origin: info.origin,
|
|
850
878
|
...info.title === void 0 ? {} : { title: info.title },
|
|
851
879
|
updatedAt: info.updatedAt,
|
|
@@ -854,8 +882,36 @@ const toThreadInfo = (info) => ({
|
|
|
854
882
|
...info.foundation === void 0 ? {} : { foundation: info.foundation },
|
|
855
883
|
...info.placement === void 0 ? {} : { placement: info.placement },
|
|
856
884
|
usage: info.usage,
|
|
857
|
-
|
|
885
|
+
runState: info.runState,
|
|
886
|
+
...info.runStateAt === void 0 ? {} : { runStateAt: info.runStateAt },
|
|
887
|
+
...info.lastRun === void 0 ? {} : { lastRun: info.lastRun },
|
|
888
|
+
restarts: info.restarts,
|
|
889
|
+
...info.attempt === void 0 ? {} : { attempt: info.attempt },
|
|
890
|
+
createdSeq: info.createdSeq,
|
|
891
|
+
createdAt: info.createdAt
|
|
858
892
|
});
|
|
893
|
+
const toThreadInfo = (info) => {
|
|
894
|
+
const { sessionId: _, ...summary } = toThreadSummary(info);
|
|
895
|
+
return {
|
|
896
|
+
...summary,
|
|
897
|
+
session: toSessionInfo(info.session)
|
|
898
|
+
};
|
|
899
|
+
};
|
|
900
|
+
const toIndexItem = (change) => {
|
|
901
|
+
switch (change._tag) {
|
|
902
|
+
case "Session": return {
|
|
903
|
+
_tag: "Session",
|
|
904
|
+
session: toSessionInfo(change.session),
|
|
905
|
+
rev: change.rev
|
|
906
|
+
};
|
|
907
|
+
case "Thread": return {
|
|
908
|
+
_tag: "Thread",
|
|
909
|
+
thread: toThreadSummary(change.thread),
|
|
910
|
+
rev: change.rev
|
|
911
|
+
};
|
|
912
|
+
default: return change;
|
|
913
|
+
}
|
|
914
|
+
};
|
|
859
915
|
const runtimeInput = (runtime) => ({
|
|
860
916
|
...runtime?.model == null ? {} : { model: runtime.model },
|
|
861
917
|
...runtime?.thinkingLevel == null ? {} : { thinkingLevel: runtime.thinkingLevel },
|
|
@@ -868,6 +924,69 @@ const decodeFailedReply = Schema.decodeUnknownOption(Schema.fromJsonString(Schem
|
|
|
868
924
|
model: Schema.String
|
|
869
925
|
})));
|
|
870
926
|
const replyError = (data) => Option.map(decodeFailedReply(data), (reply) => `${reply.provider.id}/${reply.model}: ${reply.errorMessage}`);
|
|
927
|
+
/** A line entry for the wire; the harness's own entries (compactions, resets, notices) are left out. */
|
|
928
|
+
const toHistoryEntries = ({ entry, parts, size }) => entry.type === "user" || entry.type === "assistant" ? [{
|
|
929
|
+
id: entry.id,
|
|
930
|
+
threadId: entry.threadId,
|
|
931
|
+
seq: entry.seq,
|
|
932
|
+
role: entry.type,
|
|
933
|
+
state: entry.state,
|
|
934
|
+
createdAt: DateTime.toEpochMillis(entry.createdAt),
|
|
935
|
+
updatedAt: DateTime.toEpochMillis(entry.updatedAt),
|
|
936
|
+
parts: parts.flatMap((part) => Option.toArray(decode(part.data))),
|
|
937
|
+
size,
|
|
938
|
+
...Option.match(entry.type === "assistant" ? replyError(entry.data) : Option.none(), {
|
|
939
|
+
onNone: () => ({}),
|
|
940
|
+
onSome: (error) => ({ error })
|
|
941
|
+
})
|
|
942
|
+
}] : [];
|
|
943
|
+
const toQueuedPrompt = (input) => ({
|
|
944
|
+
id: input.id,
|
|
945
|
+
delivery: input.delivery,
|
|
946
|
+
text: PromptSchema.Prompt.text(input.prompt),
|
|
947
|
+
admittedSeq: input.admittedSeq,
|
|
948
|
+
createdAt: DateTime.toEpochMillis(input.timeCreated)
|
|
949
|
+
});
|
|
950
|
+
const toThreadItems = (change) => change._tag === "Entry" ? toHistoryEntries(change.entry).map((entry) => ({
|
|
951
|
+
_tag: "Entry",
|
|
952
|
+
entry,
|
|
953
|
+
rev: change.rev
|
|
954
|
+
})) : [{
|
|
955
|
+
_tag: "Inbox",
|
|
956
|
+
prompt: toQueuedPrompt(change.prompt),
|
|
957
|
+
state: change.state,
|
|
958
|
+
rev: change.rev
|
|
959
|
+
}];
|
|
960
|
+
const deltaKinds = {
|
|
961
|
+
[EventList.LLMTextDelta.type]: "text",
|
|
962
|
+
[EventList.LLMThinkingDelta.type]: "thinking"
|
|
963
|
+
};
|
|
964
|
+
const decodeDelta = Schema.decodeUnknownOption(Schema.Struct({
|
|
965
|
+
messageId: Schema.String,
|
|
966
|
+
partIndex: Schema.Int,
|
|
967
|
+
offset: Schema.Int,
|
|
968
|
+
delta: Schema.String
|
|
969
|
+
}));
|
|
970
|
+
/** A live text or thinking delta of the feed as a `thread.sync` item. */
|
|
971
|
+
const toDeltaItem = (envelope) => {
|
|
972
|
+
const kind = deltaKinds[envelope.type];
|
|
973
|
+
if (kind === void 0) return void 0;
|
|
974
|
+
return Option.match(decodeDelta(envelope.data), {
|
|
975
|
+
onNone: () => void 0,
|
|
976
|
+
onSome: ({ messageId, partIndex, offset, delta }) => ({
|
|
977
|
+
_tag: "Delta",
|
|
978
|
+
delta: {
|
|
979
|
+
entryId: messageId,
|
|
980
|
+
partIndex,
|
|
981
|
+
kind,
|
|
982
|
+
offset,
|
|
983
|
+
delta
|
|
984
|
+
}
|
|
985
|
+
})
|
|
986
|
+
});
|
|
987
|
+
};
|
|
988
|
+
/** Bytes of entries a first `thread.sync` or a `thread.page` sends when the client names no budget. */
|
|
989
|
+
const defaultBudget = 1048576;
|
|
871
990
|
const threadInfo = (threadId) => Session.threadInfo(threadId).pipe(Effect.map(toThreadInfo));
|
|
872
991
|
const exported = (name, self) => self.pipe(Effect.withSpan(name, {
|
|
873
992
|
level: "Info",
|
|
@@ -890,14 +1009,28 @@ const layer$1 = Api.toLayer(Effect.gen(function* () {
|
|
|
890
1009
|
const mcp = yield* Mcp.Service;
|
|
891
1010
|
const host = yield* Service$1;
|
|
892
1011
|
const clones = yield* Service$3;
|
|
1012
|
+
const store = yield* Store.Service;
|
|
893
1013
|
const mcpControl = (operation) => Effect.fnUntraced(function* ({ server, ...ref }) {
|
|
894
1014
|
return yield* mcp[operation](yield* resolve(ref), server);
|
|
895
1015
|
});
|
|
896
1016
|
return Api.of({
|
|
897
|
-
"server.info": ()
|
|
898
|
-
|
|
899
|
-
|
|
1017
|
+
"server.info": Effect.fnUntraced(function* () {
|
|
1018
|
+
const head = yield* store.head;
|
|
1019
|
+
return {
|
|
1020
|
+
pid: identity.pid,
|
|
1021
|
+
version: identity.version,
|
|
1022
|
+
storeId: head.id,
|
|
1023
|
+
rev: head.rev
|
|
1024
|
+
};
|
|
900
1025
|
}),
|
|
1026
|
+
"index.sync": ({ after }) => follow(after, (from, upto) => Sync.index(from, upto, 500).pipe(Effect.map(({ items, next }) => ({
|
|
1027
|
+
items: items.map(toIndexItem),
|
|
1028
|
+
...next === void 0 ? {} : { next }
|
|
1029
|
+
}))), (head) => ({
|
|
1030
|
+
_tag: "Synced",
|
|
1031
|
+
storeId: head.id,
|
|
1032
|
+
rev: head.rev
|
|
1033
|
+
})),
|
|
901
1034
|
"auth.save": ({ credentials }) => oauth.save(credentials),
|
|
902
1035
|
"auth.status": ({ provider }) => oauth.status(provider),
|
|
903
1036
|
"auth.refresh": ({ provider }) => oauth.refresh(provider),
|
|
@@ -1026,28 +1159,33 @@ const layer$1 = Api.toLayer(Effect.gen(function* () {
|
|
|
1026
1159
|
};
|
|
1027
1160
|
}),
|
|
1028
1161
|
"thread.history": Effect.fnUntraced(function* (ref) {
|
|
1029
|
-
return { entries: (yield* threads.line(yield* resolve(ref))).flatMap(
|
|
1030
|
-
id: entry.id,
|
|
1031
|
-
threadId: entry.threadId,
|
|
1032
|
-
seq: entry.seq,
|
|
1033
|
-
role: entry.type,
|
|
1034
|
-
state: entry.state,
|
|
1035
|
-
createdAt: DateTime.toEpochMillis(entry.createdAt),
|
|
1036
|
-
updatedAt: DateTime.toEpochMillis(entry.updatedAt),
|
|
1037
|
-
parts: parts.flatMap((part) => Option.toArray(decode(part.data))),
|
|
1038
|
-
...Option.match(entry.type === "assistant" ? replyError(entry.data) : Option.none(), {
|
|
1039
|
-
onNone: () => ({}),
|
|
1040
|
-
onSome: (error) => ({ error })
|
|
1041
|
-
})
|
|
1042
|
-
}] : []) };
|
|
1162
|
+
return { entries: (yield* threads.line(yield* resolve(ref))).flatMap(toHistoryEntries) };
|
|
1043
1163
|
}),
|
|
1044
1164
|
"thread.queue": Effect.fnUntraced(function* (ref) {
|
|
1045
|
-
return { entries: (yield* control.pending(yield* resolve(ref))).map(
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1165
|
+
return { entries: (yield* control.pending(yield* resolve(ref))).map(toQueuedPrompt) };
|
|
1166
|
+
}),
|
|
1167
|
+
"thread.sync": ({ after, budget, ...ref }) => Stream.unwrap(Effect.gen(function* () {
|
|
1168
|
+
const threadId = yield* resolve(ref);
|
|
1169
|
+
const deltas = yield* feed.subscribe;
|
|
1170
|
+
const synced = (head, floor) => ({
|
|
1171
|
+
_tag: "Synced",
|
|
1172
|
+
storeId: head.id,
|
|
1173
|
+
rev: head.rev,
|
|
1174
|
+
...floor === void 0 ? {} : { floor }
|
|
1175
|
+
});
|
|
1176
|
+
const page = (from, upto) => Sync.thread(threadId, from, upto, 500).pipe(Effect.map(({ items, next }) => ({
|
|
1177
|
+
items: items.flatMap(toThreadItems),
|
|
1178
|
+
...next === void 0 ? {} : { next }
|
|
1179
|
+
})));
|
|
1180
|
+
return (after === void 0 ? watch((head) => Stream.fromEffect(Sync.open(threadId, budget ?? defaultBudget, 500)).pipe(Stream.flatMap(({ items, floor }) => Stream.fromIterable([...items.flatMap(toThreadItems), synced(head, floor)]))), page, synced) : follow(after, page, synced)).pipe(Stream.merge(deltas.pipe(Stream.filter(ofThread(threadId)), Stream.map(toDeltaItem), Stream.filter(Predicate.isNotUndefined))));
|
|
1181
|
+
})),
|
|
1182
|
+
"thread.page": Effect.fnUntraced(function* ({ before, limit, budget, ...ref }) {
|
|
1183
|
+
return { entries: (yield* threads.linePage({
|
|
1184
|
+
threadId: yield* resolve(ref),
|
|
1185
|
+
before,
|
|
1186
|
+
limit,
|
|
1187
|
+
budget: budget ?? defaultBudget
|
|
1188
|
+
})).toReversed().flatMap(toHistoryEntries) };
|
|
1051
1189
|
}),
|
|
1052
1190
|
"thread.prompt": Effect.fnUntraced(function* ({ text, delivery, id, ...ref }) {
|
|
1053
1191
|
return { threadId: (yield* control.prompt({
|
|
@@ -1136,6 +1274,8 @@ const managedShutdown = Layer.unwrap(Effect.gen(function* () {
|
|
|
1136
1274
|
}));
|
|
1137
1275
|
return Layer.empty;
|
|
1138
1276
|
}));
|
|
1277
|
+
/** Ends the stored runs the last server left open, before the listener opens: a client never sees them live. */
|
|
1278
|
+
const sweep = Layer.effectDiscard(Effect.flatMap(Control.Service, (control) => control.sweep));
|
|
1139
1279
|
/**
|
|
1140
1280
|
* Resumes the runs the last server left unfinished, whether it crashed or shut down: the session
|
|
1141
1281
|
* table records them as they start, so this needs nothing from the previous process.
|
|
@@ -1175,7 +1315,7 @@ const layer = (options) => {
|
|
|
1175
1315
|
return HttpRouter.serve(rpc, { disableListenLog: true }).pipe(Layer.provideMerge(managedShutdown), Layer.provideMerge(resumeUnfinished), Layer.provide(layer$2(options.harness.home === void 0 ? {} : { home: options.harness.home })), Layer.provide(layer$3), Layer.provide(layer$5)).pipe(Layer.provideMerge(announce), Layer.provideMerge(NodeHttpServer.layer(createServer, {
|
|
1176
1316
|
host: options.host,
|
|
1177
1317
|
port: options.port
|
|
1178
|
-
})), Layer.provide(RpcSerialization.layerNdjson), Layer.provide(layer$6), Layer.provide(Harness.layer(options.harness)));
|
|
1318
|
+
})), Layer.provide(RpcSerialization.layerNdjson), Layer.provide(layer$6), Layer.provide(sweep), Layer.provide(Harness.layer(options.harness)));
|
|
1179
1319
|
};
|
|
1180
1320
|
//#endregion
|
|
1181
1321
|
//#region src/cli/cmd/handlers/serve.ts
|
|
@@ -1205,4 +1345,4 @@ var serve_default = handler(Cmd.commands.serve, Effect.fn("CLI.serve", { level:
|
|
|
1205
1345
|
//#endregion
|
|
1206
1346
|
export { serve_default as default };
|
|
1207
1347
|
|
|
1208
|
-
//# sourceMappingURL=serve-
|
|
1348
|
+
//# sourceMappingURL=serve-CvQGTSvM.mjs.map
|