@codeworksh/cli 0.9.0-canary.157.1.g0c59cb43 → 0.9.0-canary.158.1.gdff28d0d

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 (126) hide show
  1. package/{acp-8-tGD7v8.mjs → acp-D1X6PAQd.mjs} +4 -4
  2. package/{acp-8-tGD7v8.mjs.map → acp-D1X6PAQd.mjs.map} +1 -1
  3. package/{add-DHMnQW99.mjs → add-BO0TXkKX.mjs} +8 -7
  4. package/add-BO0TXkKX.mjs.map +1 -0
  5. package/{add-zUESl6ET.mjs → add-BwC5Yb3Z.mjs} +5 -5
  6. package/{add-zUESl6ET.mjs.map → add-BwC5Yb3Z.mjs.map} +1 -1
  7. package/{catalog-XfqtqMDz.mjs → catalog-BhnZFkoq.mjs} +2 -2
  8. package/{catalog-XfqtqMDz.mjs.map → catalog-BhnZFkoq.mjs.map} +1 -1
  9. package/{check-DaAohHQB.mjs → check-n2oLWYrZ.mjs} +4 -4
  10. package/{check-DaAohHQB.mjs.map → check-n2oLWYrZ.mjs.map} +1 -1
  11. package/connect-CO-oR-Br.mjs +35 -0
  12. package/connect-CO-oR-Br.mjs.map +1 -0
  13. package/{control-Bumzv5lJ.mjs → control-Clr9Xyw9.mjs} +10 -9
  14. package/control-Clr9Xyw9.mjs.map +1 -0
  15. package/devices-aPlpoGGA.mjs +29 -0
  16. package/devices-aPlpoGGA.mjs.map +1 -0
  17. package/disconnect-B7HoGP0E.mjs +21 -0
  18. package/disconnect-B7HoGP0E.mjs.map +1 -0
  19. package/disconnect-gKR8hsnU.mjs +2 -0
  20. package/{service-utTS2IQu.mjs → discovery-D07MPnKd.mjs} +13 -37
  21. package/discovery-D07MPnKd.mjs.map +1 -0
  22. package/{entries-DEIZstjm.mjs → entries-BzfySpSJ.mjs} +3 -3
  23. package/{entries-DEIZstjm.mjs.map → entries-BzfySpSJ.mjs.map} +1 -1
  24. package/{error-CDGBK9Du.mjs → error-ippxl2z7.mjs} +552 -9
  25. package/error-ippxl2z7.mjs.map +1 -0
  26. package/{fork-D9G8UFMP.mjs → fork-lbhh_6QP.mjs} +8 -7
  27. package/fork-lbhh_6QP.mjs.map +1 -0
  28. package/identity-DbK4fABs.mjs +26 -0
  29. package/identity-DbK4fABs.mjs.map +1 -0
  30. package/{thread-oH9PJv_L.mjs → ids-cNIRx0-c.mjs} +11 -5
  31. package/ids-cNIRx0-c.mjs.map +1 -0
  32. package/index.mjs +39 -34
  33. package/index.mjs.map +1 -1
  34. package/{install-B3Jrv5qY.mjs → install-dfD5hzCS.mjs} +4 -4
  35. package/{install-B3Jrv5qY.mjs.map → install-dfD5hzCS.mjs.map} +1 -1
  36. package/{jsonc-CwZ1q4tQ.mjs → jsonc-CWL4-4yz.mjs} +2 -2
  37. package/{jsonc-CwZ1q4tQ.mjs.map → jsonc-CWL4-4yz.mjs.map} +1 -1
  38. package/{link-XTnNYTMG.mjs → link-D1cicwAl.mjs} +8 -6
  39. package/link-D1cicwAl.mjs.map +1 -0
  40. package/{list-CkcQPdvs.mjs → list-BKJgNMJm.mjs} +10 -12
  41. package/list-BKJgNMJm.mjs.map +1 -0
  42. package/{list-BWMsbeuT.mjs → list-C3McEC0O.mjs} +4 -4
  43. package/{list-BWMsbeuT.mjs.map → list-C3McEC0O.mjs.map} +1 -1
  44. package/{list-B56MDFRg.mjs → list-CGT6jT-r.mjs} +4 -4
  45. package/{list-B56MDFRg.mjs.map → list-CGT6jT-r.mjs.map} +1 -1
  46. package/{list-2wagSRhT.mjs → list-DZK016LF.mjs} +4 -4
  47. package/{list-2wagSRhT.mjs.map → list-DZK016LF.mjs.map} +1 -1
  48. package/{login-DEDr2Vyx.mjs → login-DuFDeGH-.mjs} +4 -4
  49. package/{login-DEDr2Vyx.mjs.map → login-DuFDeGH-.mjs.map} +1 -1
  50. package/{login-k_5cpvOg.mjs → login-XhIIF5Yu.mjs} +4 -4
  51. package/{login-k_5cpvOg.mjs.map → login-XhIIF5Yu.mjs.map} +1 -1
  52. package/{logout-CuhgmxyS.mjs → logout-CA1No9_2.mjs} +4 -4
  53. package/{logout-CuhgmxyS.mjs.map → logout-CA1No9_2.mjs.map} +1 -1
  54. package/{logout-DgfjJ4Qs.mjs → logout-Dpqw8tQZ.mjs} +4 -4
  55. package/{logout-DgfjJ4Qs.mjs.map → logout-Dpqw8tQZ.mjs.map} +1 -1
  56. package/package-DgfSc9nY.mjs +6 -0
  57. package/package-DgfSc9nY.mjs.map +1 -0
  58. package/package.json +3 -3
  59. package/pair-BC8a_KYX.mjs +15 -0
  60. package/pair-BC8a_KYX.mjs.map +1 -0
  61. package/{providers-DFBL85KS.mjs → providers--giKGohM.mjs} +4 -4
  62. package/{providers-DFBL85KS.mjs.map → providers--giKGohM.mjs.map} +1 -1
  63. package/reconnect-I9-Do_DK.mjs +2 -0
  64. package/{refresh-BevzQTKE.mjs → refresh-BIH3qn5A.mjs} +4 -4
  65. package/{refresh-BevzQTKE.mjs.map → refresh-BIH3qn5A.mjs.map} +1 -1
  66. package/{refresh-D1ikVUxv.mjs → refresh-Dg8WvRcq.mjs} +4 -4
  67. package/{refresh-D1ikVUxv.mjs.map → refresh-Dg8WvRcq.mjs.map} +1 -1
  68. package/{identity-jiAiU7Z0.mjs → registration-C6yiv31r.mjs} +27 -36
  69. package/registration-C6yiv31r.mjs.map +1 -0
  70. package/relay-CLPWErNw.mjs +319 -0
  71. package/relay-CLPWErNw.mjs.map +1 -0
  72. package/{relink-D-74aBQZ.mjs → relink-D8Koos_q.mjs} +9 -7
  73. package/relink-D8Koos_q.mjs.map +1 -0
  74. package/{reload-DQDThDsu.mjs → reload-C5-B0s9x.mjs} +6 -5
  75. package/reload-C5-B0s9x.mjs.map +1 -0
  76. package/{remove-DbGeM1mo.mjs → remove-6m5n17il.mjs} +4 -4
  77. package/{remove-DbGeM1mo.mjs.map → remove-6m5n17il.mjs.map} +1 -1
  78. package/{remove-C5Cdkluk.mjs → remove-VZO51J2m.mjs} +5 -5
  79. package/{remove-C5Cdkluk.mjs.map → remove-VZO51J2m.mjs.map} +1 -1
  80. package/{restart-B41PrPeq.mjs → restart-4NoPj76N.mjs} +5 -4
  81. package/{restart-B41PrPeq.mjs.map → restart-4NoPj76N.mjs.map} +1 -1
  82. package/revoke-Gu5N3Vzy.mjs +13 -0
  83. package/revoke-Gu5N3Vzy.mjs.map +1 -0
  84. package/{run-tgTFwaz6.mjs → run-RHrJN2Pv.mjs} +12 -14
  85. package/run-RHrJN2Pv.mjs.map +1 -0
  86. package/{runtime-CK2CunDw.mjs → runtime-CtLWuLd-.mjs} +48 -12
  87. package/runtime-CtLWuLd-.mjs.map +1 -0
  88. package/{serve-u3l-ZR4V.mjs → serve-BZ5FAU3h.mjs} +397 -35
  89. package/serve-BZ5FAU3h.mjs.map +1 -0
  90. package/service-CRnqz89w.mjs +79 -0
  91. package/service-CRnqz89w.mjs.map +1 -0
  92. package/{settings-DIqNg65Q.mjs → settings-DU140UBM.mjs} +3 -3
  93. package/{settings-DIqNg65Q.mjs.map → settings-DU140UBM.mjs.map} +1 -1
  94. package/{shared-DasNo1nI.mjs → shared-CC4WukJX.mjs} +4 -4
  95. package/{shared-DasNo1nI.mjs.map → shared-CC4WukJX.mjs.map} +1 -1
  96. package/{shared-D9lJX6cL.mjs → shared-Dzwbs5Lk.mjs} +7 -9
  97. package/shared-Dzwbs5Lk.mjs.map +1 -0
  98. package/{start-DaHslind.mjs → start-COhahq2E.mjs} +5 -4
  99. package/{start-DaHslind.mjs.map → start-COhahq2E.mjs.map} +1 -1
  100. package/{status-CvPbXQCn.mjs → status-Cau7bzuQ.mjs} +5 -4
  101. package/{status-CvPbXQCn.mjs.map → status-Cau7bzuQ.mjs.map} +1 -1
  102. package/{status-B1V5lctj.mjs → status-DJJOuCzL.mjs} +4 -4
  103. package/{status-B1V5lctj.mjs.map → status-DJJOuCzL.mjs.map} +1 -1
  104. package/{stop-BSy13mZw.mjs → stop-CC--mxXp.mjs} +5 -4
  105. package/{stop-BSy13mZw.mjs.map → stop-CC--mxXp.mjs.map} +1 -1
  106. package/{update-DKaDSMmZ.mjs → update-DMQLgDm3.mjs} +4 -4
  107. package/{update-DKaDSMmZ.mjs.map → update-DMQLgDm3.mjs.map} +1 -1
  108. package/add-DHMnQW99.mjs.map +0 -1
  109. package/control-Bumzv5lJ.mjs.map +0 -1
  110. package/disconnect-DyZh1VIG.mjs +0 -2
  111. package/error-CDGBK9Du.mjs.map +0 -1
  112. package/fork-D9G8UFMP.mjs.map +0 -1
  113. package/identity-jiAiU7Z0.mjs.map +0 -1
  114. package/link-XTnNYTMG.mjs.map +0 -1
  115. package/list-CkcQPdvs.mjs.map +0 -1
  116. package/package-CKwlCT6j.mjs +0 -6
  117. package/package-CKwlCT6j.mjs.map +0 -1
  118. package/reconnect-CfSVaPkd.mjs +0 -2
  119. package/relink-D-74aBQZ.mjs.map +0 -1
  120. package/reload-DQDThDsu.mjs.map +0 -1
  121. package/run-tgTFwaz6.mjs.map +0 -1
  122. package/runtime-CK2CunDw.mjs.map +0 -1
  123. package/serve-u3l-ZR4V.mjs.map +0 -1
  124. package/service-utTS2IQu.mjs.map +0 -1
  125. package/shared-D9lJX6cL.mjs.map +0 -1
  126. package/thread-oH9PJv_L.mjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"refresh-BevzQTKE.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 * as 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
+ {"version":3,"file":"refresh-BIH3qn5A.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 * as 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
- import { i as Cmd, t as handler } from "./runtime-CK2CunDw.mjs";
2
- import { f as writeOut, i as reportFailure, u as writeError } from "./error-CDGBK9Du.mjs";
3
- import { t as home } from "./catalog-XfqtqMDz.mjs";
1
+ import { a as reportFailure, f as writeError, m as writeOut } from "./error-ippxl2z7.mjs";
2
+ import { i as Cmd, t as handler } from "./runtime-CtLWuLd-.mjs";
3
+ import { t as home } from "./catalog-BhnZFkoq.mjs";
4
4
  import { Effect } from "effect";
5
5
  import { ModelCatalog } from "@codeworksh/harness/effect";
6
6
  //#region src/cli/cmd/handlers/models/refresh.ts
@@ -14,4 +14,4 @@ var refresh_default = handler(Cmd.commands.models.commands.refresh, Effect.fn("C
14
14
  //#endregion
15
15
  export { refresh_default as default };
16
16
 
17
- //# sourceMappingURL=refresh-D1ikVUxv.mjs.map
17
+ //# sourceMappingURL=refresh-Dg8WvRcq.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"refresh-D1ikVUxv.mjs","names":["Runtime.handler"],"sources":["../../src/cli/cmd/handlers/models/refresh.ts"],"sourcesContent":["import { ModelCatalog } from \"@codeworksh/harness/effect\";\nimport { Effect } from \"effect\";\nimport * as 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
+ {"version":3,"file":"refresh-Dg8WvRcq.mjs","names":["Runtime.handler"],"sources":["../../src/cli/cmd/handlers/models/refresh.ts"],"sourcesContent":["import { ModelCatalog } from \"@codeworksh/harness/effect\";\nimport { Effect } from \"effect\";\nimport * as 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,9 +1,19 @@
1
- import { t as version } from "./package-CKwlCT6j.mjs";
2
- import { Context, Effect, FileSystem, Layer, Option, Path, Schedule, Schema } from "effect";
3
- import { NodeServices } from "@effect/platform-node";
1
+ import { Effect, FileSystem, Layer, Path, Schedule, Schema } from "effect";
2
+ import { uuidv7 } from "uuidv7";
4
3
  import { isSea } from "node:sea";
5
- import { ChildProcess, ChildProcessSpawner } from "effect/process";
6
- import os from "node:os";
4
+ //#region src/framework/private.ts
5
+ /**
6
+ * Writes `text` to `path` for this user alone (0600): beside it first, then renamed over it, so a
7
+ * reader never sees half a file.
8
+ */
9
+ const write$1 = Effect.fn("Private.write")(function* (path, text) {
10
+ const fs = yield* FileSystem.FileSystem;
11
+ yield* fs.makeDirectory((yield* Path.Path).dirname(path), { recursive: true });
12
+ const temp = `${path}.${uuidv7()}.tmp`;
13
+ yield* fs.writeFileString(temp, text, { mode: 384 });
14
+ yield* fs.rename(temp, path);
15
+ });
16
+ //#endregion
7
17
  //#region src/server/registration.ts
8
18
  /**
9
19
  * How a running server advertises itself so later invocations can find it
@@ -22,7 +32,9 @@ const Info = Schema.Struct({
22
32
  /** The `ws://host:port/rpc/v1` endpoint a client connects to. */
23
33
  url: Schema.String,
24
34
  /** The TCP port the server bound, for a caller that would rather reuse it than default. */
25
- port: Schema.Int
35
+ port: Schema.Int,
36
+ /** The server's token for the life of its process: a local client sends it on every call. */
37
+ token: Schema.String
26
38
  });
27
39
  const infoJson = Schema.fromJsonString(Info);
28
40
  /** The registration file for a CodeWork home: `<home>/service.json`. */
@@ -30,15 +42,11 @@ const file = (home) => `${home}/service.json`;
30
42
  /** Where a background (`serve --service`) server writes its log: `<log>/server.log`, truncated per start. */
31
43
  const log = (logDir) => `${logDir}/server.log`;
32
44
  const decode = Schema.decodeUnknownEffect(infoJson);
33
- const write = Effect.fn("ServerRegistration.write")(function* (path, info) {
34
- const fs = yield* FileSystem.FileSystem;
35
- const paths = yield* Path.Path;
36
- yield* fs.makeDirectory(paths.dirname(path), { recursive: true });
37
- const encoded = yield* Schema.encodeEffect(infoJson)(info);
38
- const temp = `${path}.${info.pid}.tmp`;
39
- yield* fs.writeFileString(temp, encoded, { mode: 384 });
40
- yield* fs.rename(temp, path);
45
+ /** The registration at `path`; a missing or unreadable file is none. */
46
+ const read = (path) => Effect.gen(function* () {
47
+ return yield* (yield* FileSystem.FileSystem).readFileString(path).pipe(Effect.flatMap(decode), Effect.orElseSucceed(() => void 0));
41
48
  });
49
+ const write = (path, info) => Schema.encodeEffect(infoJson)(info).pipe(Effect.flatMap((encoded) => write$1(path, encoded)));
42
50
  /**
43
51
  * Publishes a registration for as long as this server lives, removing it on the
44
52
  * way out if it is still the one on file. A file left by a crash is overwritten
@@ -52,11 +60,11 @@ const write = Effect.fn("ServerRegistration.write")(function* (path, info) {
52
60
  const register = (options) => Layer.effectDiscard(Effect.gen(function* () {
53
61
  const path = file(options.home);
54
62
  const fs = yield* FileSystem.FileSystem;
55
- const current = fs.readFileString(path).pipe(Effect.flatMap(decode), Effect.option);
63
+ const current = read(path);
56
64
  const owns = (found) => found.pid === options.info.pid && found.url === options.info.url;
57
65
  yield* write(path, options.info);
58
- yield* Effect.addFinalizer(() => current.pipe(Effect.flatMap((found) => Option.isSome(found) && owns(found.value) ? fs.remove(path) : Effect.void), Effect.ignore));
59
- yield* current.pipe(Effect.flatMap((found) => Option.isNone(found) ? write(path, options.info).pipe(Effect.ignore, Effect.as(true)) : Effect.succeed(owns(found.value))), Effect.repeat({
66
+ yield* Effect.addFinalizer(() => current.pipe(Effect.flatMap((found) => found !== void 0 && owns(found) ? fs.remove(path) : Effect.void), Effect.ignore));
67
+ yield* current.pipe(Effect.flatMap((found) => found === void 0 ? write(path, options.info).pipe(Effect.ignore, Effect.as(true)) : Effect.succeed(owns(found))), Effect.repeat({
60
68
  while: (ours) => ours,
61
69
  schedule: Schedule.spaced("5 seconds")
62
70
  }), Effect.andThen(Effect.logWarning(`${path} names another server; shutting down`)), Effect.andThen(Effect.sync(() => process.kill(process.pid, "SIGTERM"))), Effect.forkScoped);
@@ -81,23 +89,6 @@ const command = () => {
81
89
  ];
82
90
  };
83
91
  //#endregion
84
- //#region src/server/identity.ts
85
- var Service = class extends Context.Service()("@codeworksh/cli/server/identity/Service") {};
86
- /** This process: a server answers with it, a client compares a server's version against it. */
87
- const current = {
88
- pid: process.pid,
89
- version
90
- };
91
- const hostName = Effect.gen(function* () {
92
- if (process.platform !== "darwin") return os.hostname().trim();
93
- return (yield* (yield* ChildProcessSpawner.ChildProcessSpawner).string(ChildProcess.make("scutil", ["--get", "ComputerName"])).pipe(Effect.orElseSucceed(() => ""))).trim() || os.hostname().replace(/\.local$/, "").trim();
94
- });
95
- /** The host's name is read once, when the server starts. */
96
- const layer = Layer.effect(Service, hostName.pipe(Effect.map((name) => Service.of(name === "" ? current : {
97
- ...current,
98
- host: { name }
99
- })))).pipe(Layer.provide(NodeServices.layer));
100
- //#endregion
101
- export { file as a, register as c, command as i, current as n, infoJson as o, layer as r, log as s, Service as t };
92
+ export { register as a, read as i, file as n, write$1 as o, log as r, command as t };
102
93
 
103
- //# sourceMappingURL=identity-jiAiU7Z0.mjs.map
94
+ //# sourceMappingURL=registration-C6yiv31r.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registration-C6yiv31r.mjs","names":["write","Private.write"],"sources":["../../src/framework/private.ts","../../src/server/registration.ts"],"sourcesContent":["import { Effect, FileSystem, Path } from \"effect\";\nimport { uuidv7 } from \"uuidv7\";\n\n/**\n * Writes `text` to `path` for this user alone (0600): beside it first, then renamed over it, so a\n * reader never sees half a file.\n */\nexport const write = Effect.fn(\"Private.write\")(function* (path: string, text: string) {\n\tconst fs = yield* FileSystem.FileSystem;\n\tyield* fs.makeDirectory((yield* Path.Path).dirname(path), { recursive: true });\n\tconst temp = `${path}.${uuidv7()}.tmp`;\n\tyield* fs.writeFileString(temp, text, { mode: 0o600 });\n\tyield* fs.rename(temp, path);\n});\n","import { Effect, FileSystem, Layer, Schedule, Schema } from \"effect\";\nimport { isSea } from \"node:sea\";\nimport * as Private from \"../framework/private.ts\";\n\n/**\n * How a running server advertises itself so later invocations can find it\n * without scanning ports or the process table.\n *\n * The file is a discovery hint, never proof: a caller reads it for the endpoint,\n * then asks the endpoint `server.info` and believes the answer only when the\n * live pid and version match the ones on file. A crashed server leaves a\n * registration behind; the failed probe is what retires it.\n */\nexport const Info = Schema.Struct({\n\t/** Operating system process identifier of the server that wrote this. */\n\tpid: Schema.Int,\n\t/** The build serving this endpoint; a mismatch means a different binary. */\n\tversion: Schema.String,\n\t/** The `ws://host:port/rpc/v1` endpoint a client connects to. */\n\turl: Schema.String,\n\t/** The TCP port the server bound, for a caller that would rather reuse it than default. */\n\tport: Schema.Int,\n\t/** The server's token for the life of its process: a local client sends it on every call. */\n\ttoken: Schema.String,\n});\nexport type Info = typeof Info.Type;\n\nconst infoJson = Schema.fromJsonString(Info);\n\n/** The registration file for a CodeWork home: `<home>/service.json`. */\nexport const file = (home: string) => `${home}/service.json`;\n\n/** Where a background (`serve --service`) server writes its log: `<log>/server.log`, truncated per start. */\nexport const log = (logDir: string) => `${logDir}/server.log`;\n\nconst decode = Schema.decodeUnknownEffect(infoJson);\n\n/** The registration at `path`; a missing or unreadable file is none. */\nexport const read = (path: string) =>\n\tEffect.gen(function* () {\n\t\tconst fs = yield* FileSystem.FileSystem;\n\t\treturn yield* fs.readFileString(path).pipe(\n\t\t\tEffect.flatMap(decode),\n\t\t\tEffect.orElseSucceed(() => undefined),\n\t\t);\n\t});\n\n// Private because it carries the token.\nconst write = (path: string, info: Info) =>\n\tSchema.encodeEffect(infoJson)(info).pipe(Effect.flatMap((encoded) => Private.write(path, encoded)));\n\n/**\n * Publishes a registration for as long as this server lives, removing it on the\n * way out if it is still the one on file. A file left by a crash is overwritten\n * by the next server to start, and retired by a probe that cannot confirm it.\n *\n * One home has one discoverable server. Every few seconds the file is checked:\n * a missing or unreadable file is written again, and a file naming another\n * server means this one lost discovery for good, so it shuts down rather than\n * run on where nothing can find or stop it.\n */\nexport const register = (options: { readonly home: string; readonly info: Info }) =>\n\tLayer.effectDiscard(\n\t\tEffect.gen(function* () {\n\t\t\tconst path = file(options.home);\n\t\t\tconst fs = yield* FileSystem.FileSystem;\n\t\t\tconst current = read(path);\n\t\t\tconst owns = (found: Info) => found.pid === options.info.pid && found.url === options.info.url;\n\n\t\t\tyield* write(path, options.info);\n\t\t\tyield* Effect.addFinalizer(() =>\n\t\t\t\tcurrent.pipe(\n\t\t\t\t\tEffect.flatMap((found) => (found !== undefined && owns(found) ? fs.remove(path) : Effect.void)),\n\t\t\t\t\tEffect.ignore,\n\t\t\t\t),\n\t\t\t);\n\t\t\t// Forked after the finalizer, so shutdown stops the watch before the file is removed.\n\t\t\tyield* current.pipe(\n\t\t\t\tEffect.flatMap((found) =>\n\t\t\t\t\tfound === undefined\n\t\t\t\t\t\t? write(path, options.info).pipe(Effect.ignore, Effect.as(true))\n\t\t\t\t\t\t: Effect.succeed(owns(found)),\n\t\t\t\t),\n\t\t\t\tEffect.repeat({ while: (ours) => ours, schedule: Schedule.spaced(\"5 seconds\") }),\n\t\t\t\tEffect.andThen(Effect.logWarning(`${path} names another server; shutting down`)),\n\t\t\t\t// The same graceful path `codework service stop` takes.\n\t\t\t\tEffect.andThen(Effect.sync(() => process.kill(process.pid, \"SIGTERM\"))),\n\t\t\t\tEffect.forkScoped,\n\t\t\t);\n\t\t}),\n\t);\n\n/**\n * The launcher command for a managed server: this same CLI, asked to serve.\n *\n * A packaged install runs `dist/pack/index.mjs`; under `--conditions=development`\n * the entry is TypeScript, and `process.execArgv` carries the conditions forward\n * so a managed server resolves workspace sources the same way this process did.\n * The standalone binary is its own entry.\n */\nexport const command = (): ReadonlyArray<string> => {\n\tif (isSea()) return [process.execPath];\n\tconst entry = process.argv[1];\n\tif (entry === undefined) return [process.execPath];\n\tconst runtime = import.meta.url.endsWith(\".ts\") ? process.execArgv : [];\n\treturn [process.execPath, ...runtime, entry];\n};\n"],"mappings":";;;;;;;;AAOA,MAAaA,UAAQ,OAAO,GAAG,eAAe,CAAC,CAAC,WAAW,MAAc,MAAc;CACtF,MAAM,KAAK,OAAO,WAAW;CAC7B,OAAO,GAAG,eAAe,OAAO,KAAK,KAAA,CAAM,QAAQ,IAAI,GAAG,EAAE,WAAW,KAAK,CAAC;CAC7E,MAAM,OAAO,GAAG,KAAK,GAAG,OAAO,EAAE;CACjC,OAAO,GAAG,gBAAgB,MAAM,MAAM,EAAE,MAAM,IAAM,CAAC;CACrD,OAAO,GAAG,OAAO,MAAM,IAAI;AAC5B,CAAC;;;;;;;;;;;;ACAD,MAAa,OAAO,OAAO,OAAO;;CAEjC,KAAK,OAAO;;CAEZ,SAAS,OAAO;;CAEhB,KAAK,OAAO;;CAEZ,MAAM,OAAO;;CAEb,OAAO,OAAO;AACf,CAAC;AAGD,MAAM,WAAW,OAAO,eAAe,IAAI;;AAG3C,MAAa,QAAQ,SAAiB,GAAG,KAAK;;AAG9C,MAAa,OAAO,WAAmB,GAAG,OAAO;AAEjD,MAAM,SAAS,OAAO,oBAAoB,QAAQ;;AAGlD,MAAa,QAAQ,SACpB,OAAO,IAAI,aAAa;CAEvB,OAAO,Q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,QAAQ,KAAK;CAC3B,IAAI,UAAU,KAAA,GAAW,OAAO,CAAC,QAAQ,QAAQ;CACjD,MAAM,UAAU,YAAY,IAAI,SAAS,KAAK,IAAI,QAAQ,WAAW,CAAC;CACtE,OAAO;EAAC,QAAQ;EAAU,GAAG;EAAS;CAAK;AAC5C"}
@@ -0,0 +1,319 @@
1
+ import { $ as sign, H as Api, K as PrivateKey, Q as publicOf, U as IdSource, V as ConnectError, W as MachineId, Y as generate, et as thumbprint } from "./error-ippxl2z7.mjs";
2
+ import { t as version } from "./package-DgfSc9nY.mjs";
3
+ import { o as write$1 } from "./registration-C6yiv31r.mjs";
4
+ import { r as hostName } from "./identity-DbK4fABs.mjs";
5
+ import { Clock, Config, Context, Duration, Effect, FileSystem, Layer, Option, Schedule, Schema } from "effect";
6
+ import { FetchHttpClient } from "effect/http";
7
+ import { uuidv7 } from "uuidv7";
8
+ import { HttpApiClient } from "effect/http-api";
9
+ import { NodeServices } from "@effect/platform-node";
10
+ //#region src/machine/file.ts
11
+ /**
12
+ * `<home>/machine.json`: who this home is as a machine, and its link to each connected workspace.
13
+ *
14
+ * It survives restarts (unlike `service.json`, which a server writes and removes) and holds private
15
+ * keys, so it is written 0600, atomically, and under a lock shared by `serve` and `codework connect`.
16
+ */
17
+ const Link = Schema.Struct({
18
+ name: Schema.String,
19
+ owner: Schema.Struct({
20
+ id: Schema.String,
21
+ name: Schema.NullOr(Schema.String)
22
+ }),
23
+ /** The relay the link was made with; heartbeats and disconnect go there. */
24
+ relay: Schema.String,
25
+ key: PrivateKey,
26
+ keyId: Schema.String,
27
+ /** Left locally, but the relay hasn't confirmed: the key is kept to revoke it once the relay answers. */
28
+ leaving: Schema.optionalKey(Schema.Boolean)
29
+ });
30
+ /** One key per home, vouching for each link key, so the relay knows every link of this home is one machine. */
31
+ const Identity = Schema.Struct({
32
+ key: PrivateKey,
33
+ keyId: Schema.String
34
+ });
35
+ const Machine = Schema.Struct({
36
+ id: Schema.String,
37
+ source: IdSource,
38
+ /** The user's own name for the machine; shown in place of the OS host name when set. */
39
+ givenName: Schema.optional(Schema.String),
40
+ identity: Schema.optional(Identity),
41
+ workspaces: Schema.Record(Schema.String, Link)
42
+ });
43
+ const json = Schema.fromJsonString(Machine);
44
+ var MachineError = class extends Schema.TaggedError()("Machine.MachineError", { message: Schema.String }) {};
45
+ const file = (home) => `${home}/machine.json`;
46
+ /** The machine as stored, or none before its first run. */
47
+ const read = Effect.fn("Machine.read")(function* (home) {
48
+ const fs = yield* FileSystem.FileSystem;
49
+ const path = file(home);
50
+ if (!(yield* fs.exists(path))) return Option.none();
51
+ const text = yield* fs.readFileString(path);
52
+ return Option.some(yield* Schema.decodeEffect(json)(text).pipe(Effect.mapError(() => new MachineError({ message: `${path} is not a valid machine file` }))));
53
+ });
54
+ const locked = (home, effect) => Effect.gen(function* () {
55
+ const fs = yield* FileSystem.FileSystem;
56
+ const lock = `${file(home)}.lock`;
57
+ yield* fs.makeDirectory(home, { recursive: true });
58
+ yield* fs.makeDirectory(lock).pipe(Effect.retry({
59
+ schedule: Schedule.spaced("50 millis"),
60
+ times: 100
61
+ }), Effect.mapError(() => new MachineError({ message: `${lock} is held by another process` })));
62
+ return yield* effect.pipe(Effect.ensuring(fs.remove(lock, { recursive: true }).pipe(Effect.ignore)));
63
+ });
64
+ const write = (home, machine) => Schema.encodeEffect(json)(machine).pipe(Effect.flatMap((encoded) => write$1(file(home), encoded)));
65
+ const newIdentity = Effect.gen(function* () {
66
+ const key = yield* generate();
67
+ return {
68
+ key,
69
+ keyId: yield* thumbprint(publicOf(key))
70
+ };
71
+ });
72
+ /** Reads, changes and writes the machine under the lock, creating its identity on first use. */
73
+ const update = (home, options, change) => locked(home, Effect.gen(function* () {
74
+ const existing = yield* read(home);
75
+ const machine = yield* Option.match(existing, {
76
+ onNone: () => Effect.succeed(created(options.machineId)),
77
+ onSome: (machine) => options.machineId === void 0 || options.machineId === machine.id ? Effect.succeed(machine) : Effect.fail(new MachineError({ message: `This home is machine ${machine.id}; its id can't change to ${options.machineId}. Use another --home.` }))
78
+ });
79
+ const identity = machine.identity ?? (yield* newIdentity);
80
+ const next = yield* change({
81
+ ...machine,
82
+ identity
83
+ });
84
+ yield* write(home, next);
85
+ return next;
86
+ }));
87
+ /** The home's identity, created with the machine on first use. */
88
+ const identity = Effect.fn("Machine.identity")(function* (home) {
89
+ const stored = yield* read(home);
90
+ if (Option.isSome(stored) && stored.value.identity !== void 0) return stored.value.identity;
91
+ return (yield* update(home, {}, Effect.succeed)).identity;
92
+ });
93
+ const created = (machineId) => machineId === void 0 ? {
94
+ id: uuidv7(),
95
+ source: "generated",
96
+ workspaces: {}
97
+ } : {
98
+ id: machineId,
99
+ source: "flag",
100
+ workspaces: {}
101
+ };
102
+ /** Validates a `--machine-id` before anything is written. */
103
+ const checkId = (machineId) => machineId === void 0 || Schema.is(MachineId)(machineId) ? Effect.void : Effect.fail(new MachineError({ message: `--machine-id must be 1-64 lowercase letters, digits or dashes, starting with a letter or digit` }));
104
+ /**
105
+ * Forgets the link to a workspace, only while it still holds `keyId`: a reconnect that saved a new key in
106
+ * the meantime keeps its link.
107
+ */
108
+ const removeLink = (home, workspaceId, keyId) => update(home, {}, (machine) => {
109
+ const { [workspaceId]: link, ...workspaces } = machine.workspaces;
110
+ return Effect.succeed(link === void 0 || link.keyId !== keyId ? machine : {
111
+ ...machine,
112
+ workspaces
113
+ });
114
+ });
115
+ /** Marks the link as leaving, only while it still holds `keyId`. */
116
+ const markLeaving = (home, workspaceId, keyId) => update(home, {}, (machine) => {
117
+ const link = machine.workspaces[workspaceId];
118
+ return Effect.succeed(link === void 0 || link.keyId !== keyId ? machine : {
119
+ ...machine,
120
+ workspaces: {
121
+ ...machine.workspaces,
122
+ [workspaceId]: {
123
+ ...link,
124
+ leaving: true
125
+ }
126
+ }
127
+ });
128
+ });
129
+ //#endregion
130
+ //#region src/machine/relay.ts
131
+ /** The relay's typed client at `url`. */
132
+ const at = (url) => HttpApiClient.make(Api, { baseUrl: url }).pipe(Effect.provide(FetchHttpClient.layer));
133
+ /**
134
+ * The relay new connects go to: `CODEWORK_RELAY_URL`, default https://relay.codework.sh. A link keeps
135
+ * talking to the relay it was made with, whatever this says later.
136
+ */
137
+ var Client = class Client extends Context.Service()("@codeworksh/cli/machine/relay/Client") {
138
+ static layer = Layer.effect(Client, Effect.gen(function* () {
139
+ const url = yield* Config.String("CODEWORK_RELAY_URL").pipe(Config.withDefault("https://relay.codework.sh"));
140
+ return {
141
+ url,
142
+ api: yield* at(url)
143
+ };
144
+ }));
145
+ };
146
+ /** What this machine says about itself to the relay. */
147
+ const describe = Effect.fn("Machine.describe")(function* (machine) {
148
+ const localHostName = yield* hostName.pipe(Effect.provide(NodeServices.layer));
149
+ return {
150
+ id: machine.id,
151
+ source: machine.source,
152
+ localHostName,
153
+ givenName: machine.givenName ?? null,
154
+ os: process.platform,
155
+ arch: process.arch,
156
+ version
157
+ };
158
+ });
159
+ /** This machine and its workspaces, as the desktop app shows them. */
160
+ const status = Effect.fn("Machine.status")(function* (home) {
161
+ const stored = yield* read(home);
162
+ const localHostName = yield* hostName.pipe(Effect.provide(NodeServices.layer));
163
+ if (stored._tag === "None") return {
164
+ id: null,
165
+ localHostName,
166
+ givenName: null,
167
+ workspaces: []
168
+ };
169
+ const machine = stored.value;
170
+ return {
171
+ id: machine.id,
172
+ localHostName,
173
+ givenName: machine.givenName ?? null,
174
+ workspaces: Object.entries(machine.workspaces).map(([id, link]) => ({
175
+ id,
176
+ name: link.name,
177
+ keyId: link.keyId,
178
+ leaving: link.leaving === true
179
+ }))
180
+ };
181
+ });
182
+ /**
183
+ * Names this machine for people: empty clears the name back to the OS's. The relay hears it on the
184
+ * next heartbeat.
185
+ */
186
+ const rename = Effect.fn("Machine.rename")(function* (home, givenName) {
187
+ const name = givenName.trim();
188
+ yield* update(home, {}, ({ givenName: _previous, ...machine }) => Effect.succeed(name === "" ? machine : {
189
+ ...machine,
190
+ givenName: name
191
+ }));
192
+ return yield* status(home);
193
+ });
194
+ /**
195
+ * Pairs this home with a workspace: registers a fresh key with the relay, shows the code a member
196
+ * approves, and polls with that key until the relay links it, then saves the link. Each workspace gets
197
+ * its own key, and only this process can take the link: a connect that stops is never linked.
198
+ */
199
+ const connect = Effect.fn("Machine.connect")(function* (options) {
200
+ const client = yield* Client;
201
+ yield* checkId(options.machineId);
202
+ const machine = yield* update(options.home, { machineId: options.machineId }, Effect.succeed);
203
+ const key = yield* generate();
204
+ const keyId = yield* thumbprint(publicOf(key));
205
+ const iat = yield* Clock.currentTimeMillis;
206
+ const binding = {
207
+ op: "identity.bind",
208
+ iat,
209
+ keyId
210
+ };
211
+ const claims = {
212
+ op: "pairing.create",
213
+ iat,
214
+ machine: yield* describe(machine),
215
+ workspaceId: options.workspaceId ?? null,
216
+ identity: yield* sign(binding, machine.identity.key, { embed: true })
217
+ };
218
+ const pairing = yield* client.api.machine.pair({ payload: { jws: yield* sign(claims, key, { embed: true }) } }).pipe(Effect.catchTag("Relay.NotFound", () => Effect.fail(new ConnectError({ message: "No such workspace" }))));
219
+ yield* options.onCode(pairing.userCode);
220
+ const poll = Effect.gen(function* () {
221
+ const claims = {
222
+ op: "pairing.poll",
223
+ iat: yield* Clock.currentTimeMillis
224
+ };
225
+ return yield* client.api.machine.poll({ payload: { jws: yield* sign(claims, key, { kid: keyId }) } });
226
+ }).pipe(Effect.catchTag("HttpClientError", (error) => Effect.logDebug("Pairing poll failed", error).pipe(Effect.as(void 0))));
227
+ let previous = machine;
228
+ const deadline = (yield* Clock.currentTimeMillis) + pairing.expiresIn * 1e3;
229
+ while ((yield* Clock.currentTimeMillis) < deadline) {
230
+ yield* Effect.sleep(Duration.seconds(pairing.interval));
231
+ const status = yield* poll;
232
+ if (status === void 0) continue;
233
+ if (status.status !== "approved") {
234
+ if (status.status === "pending") continue;
235
+ if (status.status === "expired") break;
236
+ return yield* new ConnectError({ message: status.status === "declined" ? "The connect was declined; run connect again for a new code" : "Another connect for this machine finished first" });
237
+ }
238
+ const { connected } = status;
239
+ const id = connected.workspace.id;
240
+ const stored = yield* update(options.home, {}, (current) => Effect.succeed(current.workspaces[id]?.keyId !== previous.workspaces[id]?.keyId ? current : {
241
+ ...current,
242
+ workspaces: {
243
+ ...current.workspaces,
244
+ [connected.workspace.id]: {
245
+ name: connected.workspace.name,
246
+ owner: connected.owner,
247
+ relay: client.url,
248
+ key,
249
+ keyId
250
+ }
251
+ }
252
+ }));
253
+ if (stored.workspaces[id]?.keyId === keyId) return connected;
254
+ previous = stored;
255
+ }
256
+ return yield* new ConnectError({ message: "The code expired before it was approved; run connect again" });
257
+ });
258
+ /**
259
+ * Asks the link's relay to revoke it, signed with its own key: true once the relay confirms, or says it
260
+ * was revoked already; false when it can't be reached in time.
261
+ */
262
+ const revoke = (machineId, workspaceId, link) => Effect.gen(function* () {
263
+ const claims = {
264
+ op: "machine.revoke",
265
+ iat: yield* Clock.currentTimeMillis,
266
+ jti: uuidv7(),
267
+ workspaceId,
268
+ machineId
269
+ };
270
+ yield* (yield* at(link.relay)).machine.revoke({ payload: { jws: yield* sign(claims, link.key, { kid: link.keyId }) } });
271
+ }).pipe(Effect.timeout("3 seconds"), Effect.as(true), Effect.catchTag("Relay.MachineRevoked", () => Effect.succeed(true)), Effect.catch((error) => Effect.logDebug(`Revoke at ${link.name} failed`, error).pipe(Effect.as(false))));
272
+ /**
273
+ * One heartbeat per connected workspace, each to the relay its link was made with, all at once. A link
274
+ * the relay refuses as revoked is removed, but only while it still holds the refused key. A leaving link
275
+ * asks for its revoke again instead, and is removed once the relay confirms.
276
+ */
277
+ const heartbeat = Effect.fn("Machine.heartbeat")(function* (home) {
278
+ const stored = yield* read(home);
279
+ if (stored._tag === "None") return;
280
+ const machine = stored.value;
281
+ const info = yield* describe(machine);
282
+ yield* Effect.forEach(Object.entries(machine.workspaces), ([workspaceId, link]) => link.leaving === true ? revoke(machine.id, workspaceId, link).pipe(Effect.flatMap((revoked) => revoked ? removeLink(home, workspaceId, link.keyId).pipe(Effect.asVoid) : Effect.void), Effect.catch((error) => Effect.logDebug(`Leaving ${link.name} failed`, error))) : Effect.gen(function* () {
283
+ const api = yield* at(link.relay);
284
+ const claims = {
285
+ op: "machine.heartbeat",
286
+ iat: yield* Clock.currentTimeMillis,
287
+ workspaceId,
288
+ machine: info
289
+ };
290
+ yield* api.machine.heartbeat({ payload: { jws: yield* sign(claims, link.key, { kid: link.keyId }) } });
291
+ }).pipe(Effect.timeout("10 seconds"), Effect.catchTags({
292
+ "Relay.MachineRevoked": (revoked) => Effect.logWarning(`Disconnected from ${link.name}: ${revoked.message}`).pipe(Effect.andThen(removeLink(home, workspaceId, link.keyId))),
293
+ "Relay.Unauthorized": (refused) => Effect.logWarning(`Heartbeat to ${link.name} refused: ${refused.message}`)
294
+ }), Effect.catch((error) => Effect.logDebug(`Heartbeat to ${link.name} failed`, error))), {
295
+ concurrency: "unbounded",
296
+ discard: true
297
+ });
298
+ });
299
+ /**
300
+ * Leaves a workspace: asks the link's relay to revoke it, then forgets it locally. When the relay can't
301
+ * confirm, the link is kept as leaving, with its key, and each heartbeat asks again until it does; the
302
+ * relay still lists it until then. `revoked` says whether it confirmed now.
303
+ */
304
+ const disconnect = Effect.fn("Machine.disconnect")(function* (home, workspaceId, expectedKeyId) {
305
+ const stored = yield* read(home);
306
+ const link = stored._tag === "Some" ? stored.value.workspaces[workspaceId] : void 0;
307
+ if (stored._tag === "None" || link === void 0) return yield* new ConnectError({ message: `This machine is not connected to workspace ${workspaceId}` });
308
+ if (expectedKeyId !== void 0 && link.keyId !== expectedKeyId) return yield* new ConnectError({ message: "This machine link has changed" });
309
+ const revoked = yield* revoke(stored.value.id, workspaceId, link);
310
+ yield* revoked ? removeLink(home, workspaceId, link.keyId) : markLeaving(home, workspaceId, link.keyId);
311
+ return {
312
+ workspace: link.name,
313
+ revoked
314
+ };
315
+ });
316
+ //#endregion
317
+ export { rename as a, read as c, heartbeat as i, connect as n, status as o, disconnect as r, identity as s, Client as t };
318
+
319
+ //# sourceMappingURL=relay-CLPWErNw.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"relay-CLPWErNw.mjs","names":["Jws.PrivateKey","Relay.IdSource","Private.write","Jws.generate","Jws.thumbprint","Jws.publicOf","Relay.MachineId","Relay.Api","pkg.version","File.read","File.update","File.checkId","Jws.generate","Jws.thumbprint","Jws.publicOf","Jws.sign","Machine.ConnectError","File.removeLink","File.markLeaving"],"sources":["../../src/machine/file.ts","../../src/machine/relay.ts"],"sourcesContent":["import { Jws, Relay } from \"@codeworksh/schema\";\nimport { Effect, FileSystem, Option, Schedule, Schema } from \"effect\";\nimport { uuidv7 } from \"uuidv7\";\nimport * as Private from \"../framework/private.ts\";\n\n/**\n * `<home>/machine.json`: who this home is as a machine, and its link to each connected workspace.\n *\n * It survives restarts (unlike `service.json`, which a server writes and removes) and holds private\n * keys, so it is written 0600, atomically, and under a lock shared by `serve` and `codework connect`.\n */\nconst Link = Schema.Struct({\n\tname: Schema.String,\n\towner: Schema.Struct({ id: Schema.String, name: Schema.NullOr(Schema.String) }),\n\t/** The relay the link was made with; heartbeats and disconnect go there. */\n\trelay: Schema.String,\n\tkey: Jws.PrivateKey,\n\tkeyId: Schema.String,\n\t/** Left locally, but the relay hasn't confirmed: the key is kept to revoke it once the relay answers. */\n\tleaving: Schema.optionalKey(Schema.Boolean),\n});\n\n/** One key per home, vouching for each link key, so the relay knows every link of this home is one machine. */\nconst Identity = Schema.Struct({ key: Jws.PrivateKey, keyId: Schema.String });\ntype Identity = typeof Identity.Type;\n\nexport const Machine = Schema.Struct({\n\tid: Schema.String,\n\tsource: Relay.IdSource,\n\t/** The user's own name for the machine; shown in place of the OS host name when set. */\n\tgivenName: Schema.optional(Schema.String),\n\t// Optional only for homes connected before identities existed; `update` gives every home one.\n\tidentity: Schema.optional(Identity),\n\tworkspaces: Schema.Record(Schema.String, Link),\n});\nexport type Machine = typeof Machine.Type;\n/** The machine as {@link update} hands it out: always with its identity. */\ntype Identified = Machine & { readonly identity: Identity };\n\nconst json = Schema.fromJsonString(Machine);\n\nclass MachineError extends Schema.TaggedError<MachineError>()(\"Machine.MachineError\", {\n\tmessage: Schema.String,\n}) {}\n\nconst file = (home: string) => `${home}/machine.json`;\n\n/** The machine as stored, or none before its first run. */\nexport const read = Effect.fn(\"Machine.read\")(function* (home: string) {\n\tconst fs = yield* FileSystem.FileSystem;\n\tconst path = file(home);\n\tif (!(yield* fs.exists(path))) return Option.none<Machine>();\n\tconst text = yield* fs.readFileString(path);\n\treturn Option.some(\n\t\tyield* Schema.decodeEffect(json)(text).pipe(\n\t\t\tEffect.mapError(() => new MachineError({ message: `${path} is not a valid machine file` })),\n\t\t),\n\t);\n});\n\n// One writer at a time: creating a directory either succeeds or fails, so it serves as a lock.\nconst locked = <A, E, R>(home: string, effect: Effect.Effect<A, E, R>) =>\n\tEffect.gen(function* () {\n\t\tconst fs = yield* FileSystem.FileSystem;\n\t\tconst lock = `${file(home)}.lock`;\n\t\tyield* fs.makeDirectory(home, { recursive: true });\n\t\tyield* fs.makeDirectory(lock).pipe(\n\t\t\tEffect.retry({ schedule: Schedule.spaced(\"50 millis\"), times: 100 }),\n\t\t\tEffect.mapError(() => new MachineError({ message: `${lock} is held by another process` })),\n\t\t);\n\t\treturn yield* effect.pipe(Effect.ensuring(fs.remove(lock, { recursive: true }).pipe(Effect.ignore)));\n\t});\n\nconst write = (home: string, machine: Machine) =>\n\tSchema.encodeEffect(json)(machine).pipe(Effect.flatMap((encoded) => Private.write(file(home), encoded)));\n\nconst newIdentity = Effect.gen(function* () {\n\tconst key = yield* Jws.generate();\n\treturn { key, keyId: yield* Jws.thumbprint(Jws.publicOf(key)) } satisfies Identity;\n});\n\n/** Reads, changes and writes the machine under the lock, creating its identity on first use. */\nexport const update = <E, R>(\n\thome: string,\n\toptions: { readonly machineId?: string | undefined },\n\tchange: (machine: Identified) => Effect.Effect<Identified, E, R>,\n) =>\n\tlocked(\n\t\thome,\n\t\tEffect.gen(function* () {\n\t\t\tconst existing = yield* read(home);\n\t\t\tconst machine = yield* Option.match(existing, {\n\t\t\t\tonNone: () => Effect.succeed(created(options.machineId)),\n\t\t\t\tonSome: (machine) =>\n\t\t\t\t\toptions.machineId === undefined || options.machineId === machine.id\n\t\t\t\t\t\t? Effect.succeed(machine)\n\t\t\t\t\t\t: Effect.fail(\n\t\t\t\t\t\t\t\tnew MachineError({\n\t\t\t\t\t\t\t\t\tmessage: `This home is machine ${machine.id}; its id can't change to ${options.machineId}. Use another --home.`,\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t),\n\t\t\t});\n\t\t\tconst identity = machine.identity ?? (yield* newIdentity);\n\t\t\tconst next = yield* change({ ...machine, identity });\n\t\t\tyield* write(home, next);\n\t\t\treturn next;\n\t\t}),\n\t);\n\n/** The home's identity, created with the machine on first use. */\nexport const identity = Effect.fn(\"Machine.identity\")(function* (home: string) {\n\tconst stored = yield* read(home);\n\tif (Option.isSome(stored) && stored.value.identity !== undefined) return stored.value.identity;\n\treturn (yield* update(home, {}, Effect.succeed)).identity;\n});\n\nconst created = (machineId: string | undefined): Machine =>\n\tmachineId === undefined\n\t\t? { id: uuidv7(), source: \"generated\", workspaces: {} }\n\t\t: { id: machineId, source: \"flag\", workspaces: {} };\n\n/** Validates a `--machine-id` before anything is written. */\nexport const checkId = (machineId: string | undefined) =>\n\tmachineId === undefined || Schema.is(Relay.MachineId)(machineId)\n\t\t? Effect.void\n\t\t: Effect.fail(\n\t\t\t\tnew MachineError({\n\t\t\t\t\tmessage: `--machine-id must be 1-64 lowercase letters, digits or dashes, starting with a letter or digit`,\n\t\t\t\t}),\n\t\t\t);\n\n/**\n * Forgets the link to a workspace, only while it still holds `keyId`: a reconnect that saved a new key in\n * the meantime keeps its link.\n */\nexport const removeLink = (home: string, workspaceId: string, keyId: string) =>\n\tupdate(home, {}, (machine) => {\n\t\tconst { [workspaceId]: link, ...workspaces } = machine.workspaces;\n\t\treturn Effect.succeed(link === undefined || link.keyId !== keyId ? machine : { ...machine, workspaces });\n\t});\n\n/** Marks the link as leaving, only while it still holds `keyId`. */\nexport const markLeaving = (home: string, workspaceId: string, keyId: string) =>\n\tupdate(home, {}, (machine) => {\n\t\tconst link = machine.workspaces[workspaceId];\n\t\treturn Effect.succeed(\n\t\t\tlink === undefined || link.keyId !== keyId\n\t\t\t\t? machine\n\t\t\t\t: { ...machine, workspaces: { ...machine.workspaces, [workspaceId]: { ...link, leaving: true } } },\n\t\t);\n\t});\n","import { NodeServices } from \"@effect/platform-node\";\nimport { Jws, Machine, Relay } from \"@codeworksh/schema\";\nimport { Clock, Config, Context, Duration, Effect, Layer } from \"effect\";\nimport { FetchHttpClient } from \"effect/http\";\nimport { HttpApiClient } from \"effect/http-api\";\nimport { uuidv7 } from \"uuidv7\";\nimport pkg from \"../../package.json\" with { type: \"json\" };\nimport { hostName } from \"../server/identity.ts\";\nimport * as File from \"./file.ts\";\n\n/** The relay's typed client at `url`. */\nconst at = (url: string) => HttpApiClient.make(Relay.Api, { baseUrl: url }).pipe(Effect.provide(FetchHttpClient.layer));\n\n/**\n * The relay new connects go to: `CODEWORK_RELAY_URL`, default https://relay.codework.sh. A link keeps\n * talking to the relay it was made with, whatever this says later.\n */\nexport class Client extends Context.Service<\n\tClient,\n\t{ readonly url: string; readonly api: HttpApiClient.ForApi<typeof Relay.Api> }\n>()(\"@codeworksh/cli/machine/relay/Client\") {\n\tstatic readonly layer = Layer.effect(\n\t\tClient,\n\t\tEffect.gen(function* () {\n\t\t\tconst url = yield* Config.String(\"CODEWORK_RELAY_URL\").pipe(Config.withDefault(\"https://relay.codework.sh\"));\n\t\t\treturn { url, api: yield* at(url) };\n\t\t}),\n\t);\n}\n\n/** What this machine says about itself to the relay. */\nconst describe = Effect.fn(\"Machine.describe\")(function* (machine: File.Machine) {\n\tconst localHostName = yield* hostName.pipe(Effect.provide(NodeServices.layer));\n\treturn {\n\t\tid: machine.id,\n\t\tsource: machine.source,\n\t\tlocalHostName,\n\t\tgivenName: machine.givenName ?? null,\n\t\tos: process.platform,\n\t\tarch: process.arch,\n\t\tversion: pkg.version,\n\t} satisfies Relay.MachineInfo;\n});\n\n/** This machine and its workspaces, as the desktop app shows them. */\nexport const status = Effect.fn(\"Machine.status\")(function* (home: string) {\n\tconst stored = yield* File.read(home);\n\tconst localHostName = yield* hostName.pipe(Effect.provide(NodeServices.layer));\n\tif (stored._tag === \"None\")\n\t\treturn { id: null, localHostName, givenName: null, workspaces: [] } satisfies Machine.Status;\n\tconst machine = stored.value;\n\treturn {\n\t\tid: machine.id,\n\t\tlocalHostName,\n\t\tgivenName: machine.givenName ?? null,\n\t\tworkspaces: Object.entries(machine.workspaces).map(([id, link]) => ({\n\t\t\tid,\n\t\t\tname: link.name,\n\t\t\tkeyId: link.keyId,\n\t\t\tleaving: link.leaving === true,\n\t\t})),\n\t} satisfies Machine.Status;\n});\n\n/**\n * Names this machine for people: empty clears the name back to the OS's. The relay hears it on the\n * next heartbeat.\n */\nexport const rename = Effect.fn(\"Machine.rename\")(function* (home: string, givenName: string) {\n\tconst name = givenName.trim();\n\tyield* File.update(home, {}, ({ givenName: _previous, ...machine }) =>\n\t\tEffect.succeed(name === \"\" ? machine : { ...machine, givenName: name }),\n\t);\n\treturn yield* status(home);\n});\n\n/**\n * Pairs this home with a workspace: registers a fresh key with the relay, shows the code a member\n * approves, and polls with that key until the relay links it, then saves the link. Each workspace gets\n * its own key, and only this process can take the link: a connect that stops is never linked.\n */\nexport const connect = Effect.fn(\"Machine.connect\")(function* (options: {\n\treadonly home: string;\n\treadonly workspaceId?: string | undefined;\n\treadonly machineId?: string | undefined;\n\treadonly onCode: (userCode: string) => Effect.Effect<void>;\n}) {\n\tconst client = yield* Client;\n\tyield* File.checkId(options.machineId);\n\tconst machine = yield* File.update(options.home, { machineId: options.machineId }, Effect.succeed);\n\tconst key = yield* Jws.generate();\n\tconst keyId = yield* Jws.thumbprint(Jws.publicOf(key));\n\tconst iat = yield* Clock.currentTimeMillis;\n\tconst binding: Relay.IdentityClaims = { op: \"identity.bind\", iat, keyId };\n\tconst claims: Relay.PairingClaims = {\n\t\top: \"pairing.create\",\n\t\tiat,\n\t\tmachine: yield* describe(machine),\n\t\tworkspaceId: options.workspaceId ?? null,\n\t\tidentity: yield* Jws.sign(binding, machine.identity.key, { embed: true }),\n\t};\n\tconst pairing = yield* client.api.machine\n\t\t.pair({ payload: { jws: yield* Jws.sign(claims, key, { embed: true }) } })\n\t\t.pipe(\n\t\t\tEffect.catchTag(\"Relay.NotFound\", () =>\n\t\t\t\tEffect.fail(new Machine.ConnectError({ message: \"No such workspace\" })),\n\t\t\t),\n\t\t);\n\tyield* options.onCode(pairing.userCode);\n\n\tconst poll = Effect.gen(function* () {\n\t\tconst claims: Relay.PollClaims = { op: \"pairing.poll\", iat: yield* Clock.currentTimeMillis };\n\t\treturn yield* client.api.machine.poll({ payload: { jws: yield* Jws.sign(claims, key, { kid: keyId }) } });\n\t}).pipe(\n\t\t// A dropped request or a relay restart doesn't end the connect; the next poll asks again.\n\t\tEffect.catchTag(\"HttpClientError\", (error) =>\n\t\t\tEffect.logDebug(\"Pairing poll failed\", error).pipe(Effect.as(undefined)),\n\t\t),\n\t);\n\tlet previous = machine;\n\tconst deadline = (yield* Clock.currentTimeMillis) + pairing.expiresIn * 1000;\n\twhile ((yield* Clock.currentTimeMillis) < deadline) {\n\t\tyield* Effect.sleep(Duration.seconds(pairing.interval));\n\t\tconst status = yield* poll;\n\t\tif (status === undefined) continue;\n\t\tif (status.status !== \"approved\") {\n\t\t\tif (status.status === \"pending\") continue;\n\t\t\tif (status.status === \"expired\") break;\n\t\t\treturn yield* new Machine.ConnectError({\n\t\t\t\tmessage:\n\t\t\t\t\tstatus.status === \"declined\"\n\t\t\t\t\t\t? \"The connect was declined; run connect again for a new code\"\n\t\t\t\t\t\t: \"Another connect for this machine finished first\",\n\t\t\t});\n\t\t}\n\t\tconst { connected } = status;\n\t\t// A poll response can arrive after another connect saved a different key.\n\t\t// Observe that change under the lock, then poll again before replacing it.\n\t\tconst id = connected.workspace.id;\n\t\tconst stored = yield* File.update(options.home, {}, (current) =>\n\t\t\tEffect.succeed(\n\t\t\t\tcurrent.workspaces[id]?.keyId !== previous.workspaces[id]?.keyId\n\t\t\t\t\t? current\n\t\t\t\t\t: {\n\t\t\t\t\t\t\t...current,\n\t\t\t\t\t\t\tworkspaces: {\n\t\t\t\t\t\t\t\t...current.workspaces,\n\t\t\t\t\t\t\t\t[connected.workspace.id]: {\n\t\t\t\t\t\t\t\t\tname: connected.workspace.name,\n\t\t\t\t\t\t\t\t\towner: connected.owner,\n\t\t\t\t\t\t\t\t\trelay: client.url,\n\t\t\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t\t\t\tkeyId,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t),\n\t\t);\n\t\tif (stored.workspaces[id]?.keyId === keyId) return connected;\n\t\tprevious = stored;\n\t}\n\treturn yield* new Machine.ConnectError({ message: \"The code expired before it was approved; run connect again\" });\n});\n\n/**\n * Asks the link's relay to revoke it, signed with its own key: true once the relay confirms, or says it\n * was revoked already; false when it can't be reached in time.\n */\nconst revoke = (machineId: string, workspaceId: string, link: File.Machine[\"workspaces\"][string]) =>\n\tEffect.gen(function* () {\n\t\tconst claims: Relay.RevokeClaims = {\n\t\t\top: \"machine.revoke\",\n\t\t\tiat: yield* Clock.currentTimeMillis,\n\t\t\tjti: uuidv7(),\n\t\t\tworkspaceId,\n\t\t\tmachineId,\n\t\t};\n\t\tconst api = yield* at(link.relay);\n\t\tyield* api.machine.revoke({ payload: { jws: yield* Jws.sign(claims, link.key, { kid: link.keyId }) } });\n\t}).pipe(\n\t\t// Leave time for the local update before the desktop RPC expires.\n\t\tEffect.timeout(\"3 seconds\"),\n\t\tEffect.as(true),\n\t\tEffect.catchTag(\"Relay.MachineRevoked\", () => Effect.succeed(true)),\n\t\tEffect.catch((error) => Effect.logDebug(`Revoke at ${link.name} failed`, error).pipe(Effect.as(false))),\n\t);\n\n/**\n * One heartbeat per connected workspace, each to the relay its link was made with, all at once. A link\n * the relay refuses as revoked is removed, but only while it still holds the refused key. A leaving link\n * asks for its revoke again instead, and is removed once the relay confirms.\n */\nexport const heartbeat = Effect.fn(\"Machine.heartbeat\")(function* (home: string) {\n\tconst stored = yield* File.read(home);\n\tif (stored._tag === \"None\") return;\n\tconst machine = stored.value;\n\tconst info = yield* describe(machine);\n\tyield* Effect.forEach(\n\t\tObject.entries(machine.workspaces),\n\t\t([workspaceId, link]) =>\n\t\t\tlink.leaving === true\n\t\t\t\t? revoke(machine.id, workspaceId, link).pipe(\n\t\t\t\t\t\tEffect.flatMap((revoked) =>\n\t\t\t\t\t\t\trevoked ? File.removeLink(home, workspaceId, link.keyId).pipe(Effect.asVoid) : Effect.void,\n\t\t\t\t\t\t),\n\t\t\t\t\t\tEffect.catch((error) => Effect.logDebug(`Leaving ${link.name} failed`, error)),\n\t\t\t\t\t)\n\t\t\t\t: Effect.gen(function* () {\n\t\t\t\t\t\tconst api = yield* at(link.relay);\n\t\t\t\t\t\tconst claims: Relay.HeartbeatClaims = {\n\t\t\t\t\t\t\top: \"machine.heartbeat\",\n\t\t\t\t\t\t\tiat: yield* Clock.currentTimeMillis,\n\t\t\t\t\t\t\tworkspaceId,\n\t\t\t\t\t\t\tmachine: info,\n\t\t\t\t\t\t};\n\t\t\t\t\t\tyield* api.machine.heartbeat({\n\t\t\t\t\t\t\tpayload: { jws: yield* Jws.sign(claims, link.key, { kid: link.keyId }) },\n\t\t\t\t\t\t});\n\t\t\t\t\t}).pipe(\n\t\t\t\t\t\tEffect.timeout(\"10 seconds\"),\n\t\t\t\t\t\tEffect.catchTags({\n\t\t\t\t\t\t\t\"Relay.MachineRevoked\": (revoked) =>\n\t\t\t\t\t\t\t\tEffect.logWarning(`Disconnected from ${link.name}: ${revoked.message}`).pipe(\n\t\t\t\t\t\t\t\t\tEffect.andThen(File.removeLink(home, workspaceId, link.keyId)),\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t// Refused but not revoked, most often a clock more than a minute off: worth seeing in the log.\n\t\t\t\t\t\t\t\"Relay.Unauthorized\": (refused) =>\n\t\t\t\t\t\t\t\tEffect.logWarning(`Heartbeat to ${link.name} refused: ${refused.message}`),\n\t\t\t\t\t\t}),\n\t\t\t\t\t\tEffect.catch((error) => Effect.logDebug(`Heartbeat to ${link.name} failed`, error)),\n\t\t\t\t\t),\n\t\t{ concurrency: \"unbounded\", discard: true },\n\t);\n});\n\n/**\n * Leaves a workspace: asks the link's relay to revoke it, then forgets it locally. When the relay can't\n * confirm, the link is kept as leaving, with its key, and each heartbeat asks again until it does; the\n * relay still lists it until then. `revoked` says whether it confirmed now.\n */\nexport const disconnect = Effect.fn(\"Machine.disconnect\")(function* (\n\thome: string,\n\tworkspaceId: string,\n\texpectedKeyId?: string,\n) {\n\tconst stored = yield* File.read(home);\n\tconst link = stored._tag === \"Some\" ? stored.value.workspaces[workspaceId] : undefined;\n\tif (stored._tag === \"None\" || link === undefined) {\n\t\treturn yield* new Machine.ConnectError({ message: `This machine is not connected to workspace ${workspaceId}` });\n\t}\n\tif (expectedKeyId !== undefined && link.keyId !== expectedKeyId)\n\t\treturn yield* new Machine.ConnectError({ message: \"This machine link has changed\" });\n\tconst revoked = yield* revoke(stored.value.id, workspaceId, link);\n\tyield* revoked ? File.removeLink(home, workspaceId, link.keyId) : File.markLeaving(home, workspaceId, link.keyId);\n\treturn { workspace: link.name, revoked };\n});\n"],"mappings":";;;;;;;;;;;;;;;;AAWA,MAAM,OAAO,OAAO,OAAO;CAC1B,MAAM,OAAO;CACb,OAAO,OAAO,OAAO;EAAE,IAAI,OAAO;EAAQ,MAAM,OAAO,OAAO,OAAO,MAAM;CAAE,CAAC;;CAE9E,OAAO,OAAO;CACd,KAAKA;CACL,OAAO,OAAO;;CAEd,SAAS,OAAO,YAAY,OAAO,OAAO;AAC3C,CAAC;;AAGD,MAAM,WAAW,OAAO,OAAO;CAAE,KAAKA;CAAgB,OAAO,OAAO;A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AACD,CAAC;;;;;;AAOD,MAAa,aAAa,OAAO,GAAG,oBAAoB,CAAC,CAAC,WACzD,MACA,aACA,eACC;CACD,MAAM,SAAS,OAAOR,KAAU,IAAI;CACpC,MAAM,OAAO,OAAO,SAAS,SAAS,OAAO,MAAM,WAAW,eAAe,KAAA;CAC7E,IAAI,OAAO,SAAS,UAAU,SAAS,KAAA,GACtC,OAAO,OAAO,IAAIO,aAAqB,EAAE,SAAS,8CAA8C,cAAc,CAAC;CAEhH,IAAI,kBAAkB,KAAA,KAAa,KAAK,UAAU,eACjD,OAAO,OAAO,IAAIA,aAAqB,EAAE,SAAS,gCAAgC,CAAC;CACpF,MAAM,UAAU,OAAO,OAAO,OAAO,MAAM,IAAI,aAAa,IAAI;CAChE,OAAO,UAAUC,WAAgB,MAAM,aAAa,KAAK,KAAK,IAAIC,YAAiB,MAAM,aAAa,KAAK,KAAK;CAChH,OAAO;EAAE,WAAW,KAAK;EAAM;CAAQ;AACxC,CAAC"}
@@ -1,23 +1,25 @@
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-CDGBK9Du.mjs";
3
- import { t as threadFlag } from "./thread-oH9PJv_L.mjs";
1
+ import { a as reportFailure, g as make, m as writeOut, p as writeJson, x as ThreadInfo } from "./error-ippxl2z7.mjs";
2
+ import { i as Cmd, t as handler } from "./runtime-CtLWuLd-.mjs";
3
+ import { t as connect } from "./service-CRnqz89w.mjs";
4
+ import { n as threadFlag, t as sessionId } from "./ids-cNIRx0-c.mjs";
4
5
  import { Effect, Option } from "effect";
5
- import { Sandbox, Session } from "@codeworksh/harness/effect";
6
+ import { Sandbox } from "@codeworksh/harness/effect";
6
7
  //#region src/cli/cmd/handlers/session/relink.ts
7
8
  var relink_default = handler(Cmd.commands.session.commands.relink, Effect.fn("CLI.session.relink")(function* ({ session, thread, directory, sandboxId, json, server }) {
9
+ const id = yield* sessionId(session);
8
10
  return yield* Effect.gen(function* () {
9
11
  const threadId = yield* threadFlag(thread);
10
12
  const info = yield* (yield* make)["session.relink"]({
11
- sessionId: Session.SessionSchema.ID.make(session),
13
+ sessionId: id,
12
14
  ...threadId === void 0 ? {} : { threadId },
13
15
  ...Option.isNone(sandboxId) ? {} : { sandbox: { id: Sandbox.SandboxInstance.ID.make(sandboxId.value) } },
14
16
  ...Option.isNone(directory) ? {} : { directory: directory.value }
15
17
  });
16
18
  if (json) return yield* writeJson(ThreadInfo, info);
17
19
  yield* writeOut(threadId === void 0 ? `Moved ${info.session.id} to ${info.session.directory}\n` : `Moved thread ${info.id} of ${info.session.id} to ${info.placement?.directory ?? info.session.directory}\n`);
18
- }).pipe(Effect.provide(layer(server)), Effect.scoped, Effect.catch(reportFailure));
20
+ }).pipe(connect(Option.getOrUndefined(server)), Effect.catch(reportFailure));
19
21
  }));
20
22
  //#endregion
21
23
  export { relink_default as default };
22
24
 
23
- //# sourceMappingURL=relink-D-74aBQZ.mjs.map
25
+ //# sourceMappingURL=relink-D8Koos_q.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"relink-D8Koos_q.mjs","names":["Runtime.handler","Client.make","Service.connect"],"sources":["../../src/cli/cmd/handlers/session/relink.ts"],"sourcesContent":["import { Sandbox } from \"@codeworksh/harness/effect\";\nimport { Effect, Option } from \"effect\";\nimport * as Runtime from \"../../../../framework/runtime.ts\";\nimport * as Client from \"../../../../server/client.ts\";\nimport * as Service from \"../../../service.ts\";\nimport { ThreadInfo } from \"../../../../server/contract.ts\";\nimport { reportFailure } from \"../../../error.ts\";\nimport { writeJson, writeOut } from \"../../../output.ts\";\nimport { sessionId, threadFlag } from \"../../../ids.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 id = yield* sessionId(session);\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: id,\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(Service.connect(Option.getOrUndefined(server)), Effect.catch(reportFailure));\n\t}),\n);\n"],"mappings":";;;;;;;AAWA,IAAA,iBAAeA,QACd,IAAI,SAAS,QAAQ,SAAS,QAC9B,OAAO,GAAG,oBAAoB,CAAC,CAAC,WAAW,EAAE,SAAS,QAAQ,WAAW,WAAW,MAAM,UAAU;CACnG,MAAM,KAAK,OAAO,UAAU,OAAO;CAmBnC,OAAO,OAlBS,OAAO,IAAI,aAAa;EACvC,MAAM,WAAW,OAAO,WAAW,MAAM;EAEzC,MAAM,OAAO,QAAO,OADDC,KAAAA,CACK,iBAAiB,CAAC;GACzC,WAAW;GACX,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,KAAKC,QAAgB,OAAO,eAAe,MAAM,CAAC,GAAG,OAAO,MAAM,aAAa,CAAC;AACvG,CAAC,CACF"}
@@ -1,6 +1,7 @@
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-CDGBK9Du.mjs";
3
- import { Effect } from "effect";
1
+ import { a as reportFailure, g as make, m as writeOut } from "./error-ippxl2z7.mjs";
2
+ import { i as Cmd, t as handler } from "./runtime-CtLWuLd-.mjs";
3
+ import { t as connect } from "./service-CRnqz89w.mjs";
4
+ import { Effect, Option } from "effect";
4
5
  //#region src/cli/cmd/handlers/plugin/reload.ts
5
6
  /**
6
7
  * Re-import every configured plugin in a running server.
@@ -18,9 +19,9 @@ var reload_default = handler(Cmd.commands.plugin.commands.reload, Effect.fn("CLI
18
19
  const result = yield* (yield* make)["plugin.reload"]({});
19
20
  yield* writeOut(result.failure === void 0 ? `Reloaded ${result.plugins} plugin${result.plugins === 1 ? "" : "s"}.\n` : `Reload failed, keeping ${result.plugins} loaded: ${result.failure}\n`);
20
21
  if (result.failure !== void 0) process.exitCode = 1;
21
- }).pipe(Effect.provide(layer(server)), Effect.scoped, Effect.catch(reportFailure));
22
+ }).pipe(connect(Option.getOrUndefined(server)), Effect.catch(reportFailure));
22
23
  }));
23
24
  //#endregion
24
25
  export { reload_default as default };
25
26
 
26
- //# sourceMappingURL=reload-DQDThDsu.mjs.map
27
+ //# sourceMappingURL=reload-C5-B0s9x.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reload-C5-B0s9x.mjs","names":["Runtime.handler","Client.make","Service.connect"],"sources":["../../src/cli/cmd/handlers/plugin/reload.ts"],"sourcesContent":["import { Effect, Option } from \"effect\";\nimport * as Runtime from \"../../../../framework/runtime.ts\";\nimport { reportFailure } from \"../../../error.ts\";\nimport { writeOut } from \"../../../output.ts\";\nimport * as Client from \"../../../../server/client.ts\";\nimport * as Service from \"../../../service.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(Service.connect(Option.getOrUndefined(server)), Effect.catch(reportFailure));\n\t}),\n);\n"],"mappings":";;;;;;;;;;;;;;;;AAmBA,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,KAAKC,QAAgB,OAAO,eAAe,MAAM,CAAC,GAAG,OAAO,MAAM,aAAa,CAAC;AACvG,CAAC,CACF"}