@llm4ts/runner 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +61 -0
  3. package/dist/Cli.d.ts +5 -0
  4. package/dist/Cli.d.ts.map +1 -0
  5. package/dist/Cli.js +36 -0
  6. package/dist/Cli.js.map +1 -0
  7. package/dist/CoderPolicy.d.ts +12 -0
  8. package/dist/CoderPolicy.d.ts.map +1 -0
  9. package/dist/CoderPolicy.js +59 -0
  10. package/dist/CoderPolicy.js.map +1 -0
  11. package/dist/Connectors.d.ts +28 -0
  12. package/dist/Connectors.d.ts.map +1 -0
  13. package/dist/Connectors.js +165 -0
  14. package/dist/Connectors.js.map +1 -0
  15. package/dist/Doctor.d.ts +4 -0
  16. package/dist/Doctor.d.ts.map +1 -0
  17. package/dist/Doctor.js +33 -0
  18. package/dist/Doctor.js.map +1 -0
  19. package/dist/FlowArgs.d.ts +34 -0
  20. package/dist/FlowArgs.d.ts.map +1 -0
  21. package/dist/FlowArgs.js +136 -0
  22. package/dist/FlowArgs.js.map +1 -0
  23. package/dist/FlowRunner.d.ts +48 -0
  24. package/dist/FlowRunner.d.ts.map +1 -0
  25. package/dist/FlowRunner.js +97 -0
  26. package/dist/FlowRunner.js.map +1 -0
  27. package/dist/McpStdio.d.ts +7 -0
  28. package/dist/McpStdio.d.ts.map +1 -0
  29. package/dist/McpStdio.js +19 -0
  30. package/dist/McpStdio.js.map +1 -0
  31. package/dist/NodeGeminiCliExecutor.d.ts +7 -0
  32. package/dist/NodeGeminiCliExecutor.d.ts.map +1 -0
  33. package/dist/NodeGeminiCliExecutor.js +26 -0
  34. package/dist/NodeGeminiCliExecutor.js.map +1 -0
  35. package/dist/NodeHttpClient.d.ts +5 -0
  36. package/dist/NodeHttpClient.d.ts.map +1 -0
  37. package/dist/NodeHttpClient.js +109 -0
  38. package/dist/NodeHttpClient.js.map +1 -0
  39. package/dist/NodePlainFileStore.d.ts +5 -0
  40. package/dist/NodePlainFileStore.d.ts.map +1 -0
  41. package/dist/NodePlainFileStore.js +64 -0
  42. package/dist/NodePlainFileStore.js.map +1 -0
  43. package/dist/NodeProcessExecutor.d.ts +5 -0
  44. package/dist/NodeProcessExecutor.d.ts.map +1 -0
  45. package/dist/NodeProcessExecutor.js +212 -0
  46. package/dist/NodeProcessExecutor.js.map +1 -0
  47. package/dist/NodeRuntime.d.ts +4 -0
  48. package/dist/NodeRuntime.d.ts.map +1 -0
  49. package/dist/NodeRuntime.js +11 -0
  50. package/dist/NodeRuntime.js.map +1 -0
  51. package/dist/NodeTemporaryFiles.d.ts +5 -0
  52. package/dist/NodeTemporaryFiles.d.ts.map +1 -0
  53. package/dist/NodeTemporaryFiles.js +30 -0
  54. package/dist/NodeTemporaryFiles.js.map +1 -0
  55. package/dist/NodeWorkspace.d.ts +6 -0
  56. package/dist/NodeWorkspace.d.ts.map +1 -0
  57. package/dist/NodeWorkspace.js +231 -0
  58. package/dist/NodeWorkspace.js.map +1 -0
  59. package/dist/Package.d.ts +2 -0
  60. package/dist/Package.d.ts.map +1 -0
  61. package/dist/Package.js +2 -0
  62. package/dist/Package.js.map +1 -0
  63. package/dist/ReviewFingerprint.d.ts +2 -0
  64. package/dist/ReviewFingerprint.d.ts.map +1 -0
  65. package/dist/ReviewFingerprint.js +13 -0
  66. package/dist/ReviewFingerprint.js.map +1 -0
  67. package/dist/Terminal.d.ts +46 -0
  68. package/dist/Terminal.d.ts.map +1 -0
  69. package/dist/Terminal.js +226 -0
  70. package/dist/Terminal.js.map +1 -0
  71. package/dist/TerminalInteraction.d.ts +4 -0
  72. package/dist/TerminalInteraction.d.ts.map +1 -0
  73. package/dist/TerminalInteraction.js +25 -0
  74. package/dist/TerminalInteraction.js.map +1 -0
  75. package/dist/cli-main.d.ts +3 -0
  76. package/dist/cli-main.d.ts.map +1 -0
  77. package/dist/cli-main.js +39 -0
  78. package/dist/cli-main.js.map +1 -0
  79. package/package.json +74 -0
  80. package/src/Cli.ts +51 -0
  81. package/src/CoderPolicy.ts +82 -0
  82. package/src/Connectors.ts +225 -0
  83. package/src/Doctor.ts +44 -0
  84. package/src/FlowArgs.ts +167 -0
  85. package/src/FlowRunner.ts +220 -0
  86. package/src/McpStdio.ts +41 -0
  87. package/src/NodeGeminiCliExecutor.ts +56 -0
  88. package/src/NodeHttpClient.ts +224 -0
  89. package/src/NodePlainFileStore.ts +75 -0
  90. package/src/NodeProcessExecutor.ts +331 -0
  91. package/src/NodeRuntime.ts +19 -0
  92. package/src/NodeTemporaryFiles.ts +46 -0
  93. package/src/NodeWorkspace.ts +282 -0
  94. package/src/Package.ts +1 -0
  95. package/src/ReviewFingerprint.ts +13 -0
  96. package/src/Terminal.ts +329 -0
  97. package/src/TerminalInteraction.ts +43 -0
  98. package/src/cli-main.ts +53 -0
@@ -0,0 +1,43 @@
1
+ import { createInterface } from "node:readline/promises"
2
+ import { stdin, stderr } from "node:process"
3
+ import * as Effect from "effect/Effect"
4
+ import { ProcessError } from "@llm4ts/flow/FlowError"
5
+ import type { ApprovalPolicy, InteractionShape } from "@llm4ts/flow/Interaction"
6
+ import { ApprovalAllowed, ApprovalDenied } from "@llm4ts/flow/Interaction"
7
+
8
+ export const terminalInteraction: InteractionShape = {
9
+ ask: (question) =>
10
+ Effect.acquireUseRelease(
11
+ Effect.sync(() =>
12
+ createInterface({
13
+ input: stdin,
14
+ output: stderr
15
+ })
16
+ ),
17
+ (terminal) =>
18
+ Effect.tryPromise({
19
+ try: () => terminal.question(`❓ ${question}\n> `),
20
+ catch: (error) =>
21
+ ProcessError.make({
22
+ message: "terminal input",
23
+ detail: error instanceof Error ? error.message : String(error)
24
+ })
25
+ }),
26
+ (terminal) => Effect.sync(() => terminal.close())
27
+ )
28
+ }
29
+
30
+ export const terminalApprovalPolicy = (
31
+ interaction: InteractionShape = terminalInteraction
32
+ ): ApprovalPolicy => ({
33
+ decide: (toolName, input) =>
34
+ interaction
35
+ .ask(`Allow tool '${toolName}' with input ${JSON.stringify(input)}? [y/N]`)
36
+ .pipe(
37
+ Effect.map((answer) =>
38
+ /^(y|yes)$/iu.test(answer.trim())
39
+ ? new ApprovalAllowed()
40
+ : ApprovalDenied.make({ reason: "operator denied" })
41
+ )
42
+ )
43
+ })
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env node
2
+ import { readFileSync } from "node:fs"
3
+ import * as Effect from "effect/Effect"
4
+ import { makeCliProgram } from "./Cli.ts"
5
+ import { makeDoctorProgram } from "./Doctor.ts"
6
+ import { FlowHelp, parseFlowArgs } from "./FlowArgs.ts"
7
+
8
+ const argv = process.argv.slice(2)
9
+
10
+ const packageVersion = (): string => {
11
+ const manifest: unknown = JSON.parse(
12
+ readFileSync(new URL("../package.json", import.meta.url), "utf8")
13
+ )
14
+ return typeof manifest === "object" &&
15
+ manifest !== null &&
16
+ "version" in manifest &&
17
+ typeof manifest.version === "string"
18
+ ? manifest.version
19
+ : "unknown"
20
+ }
21
+
22
+ const flowProgram = (): Effect.Effect<void> => {
23
+ const parsed = parseFlowArgs(argv)
24
+ if (parsed.ok && parsed.value.help === true) {
25
+ return Effect.sync(() => process.stdout.write(FlowHelp))
26
+ }
27
+ if (parsed.ok && parsed.value.version === true) {
28
+ return Effect.sync(() => process.stdout.write(`${packageVersion()}\n`))
29
+ }
30
+ return makeCliProgram(argv).pipe(
31
+ Effect.match({
32
+ onFailure: (error) => {
33
+ process.stderr.write(`${error.message}\n`)
34
+ return error._tag === "ScriptUsage" ? 2 : 1
35
+ },
36
+ onSuccess: () => 0
37
+ }),
38
+ Effect.flatMap((exitCode) =>
39
+ Effect.sync(() => {
40
+ process.exitCode = exitCode
41
+ })
42
+ )
43
+ )
44
+ }
45
+
46
+ const main =
47
+ argv[0] === "doctor"
48
+ ? makeDoctorProgram().pipe(
49
+ Effect.flatMap((report) => Effect.sync(() => process.stdout.write(report)))
50
+ )
51
+ : flowProgram()
52
+
53
+ Effect.runFork(main)