t3code-cli 0.10.0 → 0.12.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.
- package/README.md +75 -11
- package/dist/application.js +2 -2
- package/dist/auth.js +1 -1
- package/dist/bin.js +86754 -2675
- package/dist/cli.js +15 -2
- package/dist/config.js +120 -2
- package/dist/connection.js +2 -12
- package/dist/index.js +1 -1
- package/dist/node.js +6 -0
- package/dist/orchestration.js +2 -2
- package/dist/rpc.js +2 -2
- package/dist/runtime.js +2 -2
- package/dist/shared.js +43850 -38040
- package/dist/src/application/actions.d.ts +25 -0
- package/dist/src/application/index.d.ts +3 -2
- package/dist/src/application/layer.d.ts +99 -842
- package/dist/src/application/model-selection.d.ts +17 -2
- package/dist/src/application/models.d.ts +1 -87
- package/dist/src/application/project-commands.d.ts +31 -2
- package/dist/src/application/projects.d.ts +15 -137
- package/dist/src/application/service.d.ts +147 -5
- package/dist/src/application/shell-sequence.d.ts +5 -4
- package/dist/src/application/terminals.d.ts +66 -0
- package/dist/src/application/thread-commands.d.ts +48 -1
- package/dist/src/application/thread-update.d.ts +8 -0
- package/dist/src/application/thread-wait.d.ts +4 -6
- package/dist/src/application/threads.d.ts +36 -14
- package/dist/src/auth/error.d.ts +2 -1
- package/dist/src/auth/index.d.ts +1 -1
- package/dist/src/auth/layer.d.ts +34 -6
- package/dist/src/auth/local-base-dir.d.ts +5 -2
- package/dist/src/auth/local-origin.d.ts +3 -3
- package/dist/src/auth/local-token.d.ts +3 -3
- package/dist/src/auth/service.d.ts +15 -3
- package/dist/src/auth/type.d.ts +40 -1
- package/dist/src/cli/env/flag.d.ts +2 -0
- package/dist/src/cli/env/index.d.ts +2 -0
- package/dist/src/cli/env/selection-layer.d.ts +3 -0
- package/dist/src/cli/flags.d.ts +5 -0
- package/dist/src/cli/format/index.d.ts +1 -0
- package/dist/src/cli/format/output.d.ts +12 -0
- package/dist/src/cli/index.d.ts +4 -0
- package/dist/src/cli/runtime/index.d.ts +1 -0
- package/dist/src/cli/runtime/service.d.ts +16 -0
- package/dist/src/{scope → cli/scope}/resolve.d.ts +5 -4
- package/dist/src/config/config.d.ts +49 -0
- package/dist/src/config/credential/cipher-node.d.ts +3 -0
- package/dist/src/config/credential/cipher-web.d.ts +3 -0
- package/dist/src/config/credential/cipher.d.ts +29 -0
- package/dist/src/config/credential/env.d.ts +3 -0
- package/dist/src/config/credential/error.d.ts +8 -0
- package/dist/src/config/credential/index.d.ts +6 -0
- package/dist/src/config/credential/service.d.ts +34 -0
- package/dist/src/config/env/env.d.ts +55 -0
- package/dist/src/config/env/index.d.ts +2 -0
- package/dist/src/{layout/base-dir.d.ts → config/env/layout.d.ts} +0 -1
- package/dist/src/config/environment-name/index.d.ts +1 -0
- package/dist/src/config/environment-name/name.d.ts +10 -0
- package/dist/src/config/error.d.ts +4 -11
- package/dist/src/config/index.d.ts +10 -5
- package/dist/src/config/keystore/error.d.ts +8 -0
- package/dist/src/config/keystore/file.d.ts +9 -0
- package/dist/src/config/keystore/index.d.ts +4 -0
- package/dist/src/config/keystore/keyring-node.d.ts +4 -0
- package/dist/src/config/keystore/service.d.ts +33 -0
- package/dist/src/config/paths/index.d.ts +1 -0
- package/dist/src/config/paths/paths.d.ts +6 -0
- package/dist/src/config/persist/file-mode.d.ts +4 -0
- package/dist/src/config/persist/migration.d.ts +68 -0
- package/dist/src/config/persist/persist.d.ts +40 -0
- package/dist/src/config/persist/schema.d.ts +68 -0
- package/dist/src/config/resolve/resolve.d.ts +40 -0
- package/dist/src/config/selection/index.d.ts +1 -0
- package/dist/src/config/selection/resolve.d.ts +4 -0
- package/dist/src/config/selection/service.d.ts +10 -0
- package/dist/src/config/types.d.ts +36 -0
- package/dist/src/config/url/error.d.ts +10 -0
- package/dist/src/config/url/index.d.ts +2 -0
- package/dist/src/connection/index.d.ts +0 -1
- package/dist/src/contracts/index.d.ts +1 -1
- package/dist/src/domain/error.d.ts +27 -1
- package/dist/src/domain/helpers.d.ts +8 -2
- package/dist/src/domain/model-config.d.ts +30 -1
- package/dist/src/domain/thread-activities.d.ts +1 -1
- package/dist/src/domain/thread-lifecycle.d.ts +3 -2
- package/dist/src/index.d.ts +1 -2
- package/dist/src/{connection/node.d.ts → node/connection.d.ts} +1 -1
- package/dist/src/node/index.d.ts +1 -0
- package/dist/src/orchestration/index.d.ts +1 -1
- package/dist/src/orchestration/layer.d.ts +120 -829
- package/dist/src/orchestration/service.d.ts +2 -1
- package/dist/src/rpc/error.d.ts +5 -3
- package/dist/src/rpc/index.d.ts +5 -1
- package/dist/src/rpc/layer.d.ts +1166 -40
- package/dist/src/rpc/operation.d.ts +6280 -0
- package/dist/src/rpc/ws-group.d.ts +372 -27
- package/dist/src/runtime/index.d.ts +1 -2
- package/dist/src/runtime/layer.d.ts +12 -8
- package/dist/src/t3tools/index.d.ts +1 -1
- package/dist/t3tools.js +2 -2
- package/package.json +27 -19
- package/src/application/actions.test.ts +328 -0
- package/src/application/actions.ts +475 -0
- package/src/application/index.ts +32 -2
- package/src/application/layer.ts +43 -5
- package/src/application/model-selection.ts +70 -4
- package/src/application/models.ts +14 -14
- package/src/application/project-commands.ts +38 -5
- package/src/application/projects.ts +49 -20
- package/src/application/service.ts +275 -78
- package/src/application/shell-sequence.ts +6 -8
- package/src/application/terminals.ts +208 -0
- package/src/application/thread-commands.test.ts +43 -0
- package/src/application/thread-commands.ts +82 -1
- package/src/application/thread-update.ts +72 -0
- package/src/application/thread-wait.ts +47 -48
- package/src/application/threads.test.ts +172 -0
- package/src/application/threads.ts +128 -45
- package/src/auth/error.ts +2 -1
- package/src/auth/index.ts +7 -0
- package/src/auth/layer.test-utils.ts +34 -0
- package/src/auth/layer.ts +116 -34
- package/src/auth/local-base-dir.ts +13 -6
- package/src/auth/local-origin.ts +10 -7
- package/src/auth/local-token.ts +28 -23
- package/src/auth/service.test.ts +200 -0
- package/src/auth/service.ts +27 -3
- package/src/auth/transport.ts +2 -2
- package/src/auth/type.ts +47 -1
- package/src/bin.ts +26 -6
- package/src/cli/action-format.ts +110 -0
- package/src/cli/action.ts +398 -0
- package/src/cli/app.ts +8 -0
- package/src/cli/auth.ts +76 -23
- package/src/cli/env/flag.ts +8 -0
- package/src/cli/env/index.ts +2 -0
- package/src/cli/env/selection-layer.test.ts +49 -0
- package/src/cli/env/selection-layer.ts +27 -0
- package/src/cli/env.ts +107 -0
- package/src/cli/error.ts +26 -3
- package/src/cli/extra-args.test.ts +32 -0
- package/src/cli/extra-args.ts +22 -0
- package/src/cli/flags.ts +26 -1
- package/src/cli/format/auth.ts +92 -0
- package/src/cli/format/human.ts +131 -0
- package/src/cli/format/index.ts +12 -0
- package/src/cli/format/model.ts +29 -0
- package/src/cli/format/output.ts +51 -0
- package/src/cli/format/project.ts +32 -0
- package/src/cli/format/terminal.ts +87 -0
- package/src/cli/format/thread.test.ts +34 -0
- package/src/cli/format/thread.ts +185 -0
- package/src/cli/index.ts +20 -0
- package/src/cli/input/layer.ts +20 -0
- package/src/cli/input/service.ts +1 -0
- package/src/cli/interaction/confirm.ts +64 -0
- package/src/cli/interaction/self-action.ts +36 -0
- package/src/cli/message-input.ts +1 -1
- package/src/cli/model.ts +9 -5
- package/src/cli/project.ts +15 -8
- package/src/cli/projects/delete.ts +51 -0
- package/src/cli/require.ts +9 -7
- package/src/cli/runtime/index.ts +1 -0
- package/src/cli/runtime/service.ts +28 -0
- package/src/{scope → cli/scope}/resolve.ts +11 -9
- package/src/cli/terminal/attach.ts +29 -0
- package/src/cli/terminal/create.ts +55 -0
- package/src/cli/terminal/destroy.ts +62 -0
- package/src/cli/terminal/encoding.test.ts +63 -0
- package/src/cli/terminal/encoding.ts +23 -0
- package/src/cli/terminal/error.ts +14 -0
- package/src/cli/terminal/io-node-layer.ts +82 -0
- package/src/cli/terminal/io-service.ts +25 -0
- package/src/cli/terminal/list.ts +36 -0
- package/src/cli/terminal/read.test-utils.ts +48 -0
- package/src/cli/terminal/read.test.ts +35 -0
- package/src/cli/terminal/read.ts +99 -0
- package/src/cli/terminal/scope.ts +35 -0
- package/src/cli/terminal/shared.ts +250 -0
- package/src/cli/terminal/stream.ts +61 -0
- package/src/cli/terminal/wait.test.ts +148 -0
- package/src/cli/terminal/wait.ts +223 -0
- package/src/cli/terminal/write.test.ts +34 -0
- package/src/cli/terminal/write.ts +133 -0
- package/src/cli/terminal.ts +26 -0
- package/src/cli/thread.ts +8 -0
- package/src/cli/threads/approve.ts +11 -7
- package/src/cli/threads/archive.ts +23 -25
- package/src/cli/threads/callback.ts +6 -4
- package/src/cli/threads/delete.ts +67 -0
- package/src/cli/threads/interrupt.ts +57 -0
- package/src/cli/threads/list.test.ts +71 -0
- package/src/cli/threads/list.ts +25 -13
- package/src/cli/threads/messages.ts +11 -7
- package/src/cli/threads/respond.ts +11 -7
- package/src/cli/threads/send.ts +39 -9
- package/src/cli/threads/show.ts +11 -7
- package/src/cli/threads/start.ts +18 -13
- package/src/cli/threads/unarchive.ts +48 -0
- package/src/cli/threads/update.ts +155 -0
- package/src/cli/threads/wait.ts +11 -7
- package/src/cli/wait-events.ts +1 -1
- package/src/config/config.ts +260 -0
- package/src/config/credential/cipher-node.ts +40 -0
- package/src/config/credential/cipher-web.ts +82 -0
- package/src/config/credential/cipher.ts +39 -0
- package/src/config/credential/env.ts +13 -0
- package/src/config/credential/error.ts +9 -0
- package/src/config/credential/index.ts +6 -0
- package/src/config/credential/service.test-utils.ts +25 -0
- package/src/config/credential/service.test.ts +116 -0
- package/src/config/credential/service.ts +205 -0
- package/src/config/env/env.test-utils.ts +14 -0
- package/src/config/env/env.ts +81 -0
- package/src/config/env/index.ts +2 -0
- package/src/{layout/base-dir.ts → config/env/layout.ts} +0 -9
- package/src/config/environment-name/index.ts +7 -0
- package/src/config/environment-name/name.test.ts +66 -0
- package/src/config/environment-name/name.ts +49 -0
- package/src/config/error.ts +6 -8
- package/src/config/index.ts +16 -5
- package/src/config/keystore/error.ts +9 -0
- package/src/config/keystore/file.ts +96 -0
- package/src/config/keystore/index.ts +4 -0
- package/src/config/keystore/keyring-node.test.ts +12 -0
- package/src/config/keystore/keyring-node.ts +100 -0
- package/src/config/keystore/service.test-utils.ts +15 -0
- package/src/config/keystore/service.test.ts +18 -0
- package/src/config/keystore/service.ts +29 -0
- package/src/config/layer.test-utils.ts +45 -0
- package/src/config/layer.test.ts +209 -0
- package/src/config/paths/index.ts +1 -0
- package/src/config/paths/paths.ts +36 -0
- package/src/config/persist/file-mode.ts +21 -0
- package/src/config/persist/migration.test.ts +71 -0
- package/src/config/persist/migration.ts +82 -0
- package/src/config/persist/persist.test.ts +113 -0
- package/src/config/persist/persist.ts +65 -0
- package/src/config/persist/schema.ts +37 -0
- package/src/config/platform.test-utils.ts +20 -0
- package/src/config/resolve/resolve.test-utils.ts +20 -0
- package/src/config/resolve/resolve.test.ts +137 -0
- package/src/config/resolve/resolve.ts +104 -0
- package/src/config/selection/index.ts +1 -0
- package/src/config/selection/resolve.ts +14 -0
- package/src/config/selection/service.ts +29 -0
- package/src/config/temp-home.test-utils.ts +7 -0
- package/src/config/types.ts +49 -0
- package/src/config/url/error.ts +8 -0
- package/src/config/url/index.ts +7 -0
- package/src/config/url/url.test.ts +31 -0
- package/src/connection/index.ts +0 -1
- package/src/contracts/index.ts +1 -1
- package/src/domain/error.ts +39 -1
- package/src/domain/helpers.test.ts +1 -1
- package/src/domain/helpers.ts +1 -1
- package/src/domain/model-config.ts +5 -1
- package/src/domain/thread-activities.test.ts +1 -1
- package/src/domain/thread-activities.ts +1 -1
- package/src/domain/thread-lifecycle.test.ts +1 -1
- package/src/domain/thread-lifecycle.ts +15 -1
- package/src/effect.test-utils.ts +25 -0
- package/src/index.ts +1 -1
- package/src/{connection/node.ts → node/connection.ts} +1 -1
- package/src/node/index.ts +1 -0
- package/src/orchestration/index.ts +1 -1
- package/src/orchestration/layer.ts +34 -86
- package/src/orchestration/service.ts +5 -1
- package/src/rpc/error.ts +12 -2
- package/src/rpc/index.ts +5 -1
- package/src/rpc/layer.ts +1 -1
- package/src/rpc/operation.ts +83 -0
- package/src/rpc/ws-group.ts +25 -1
- package/src/runtime/index.ts +2 -1
- package/src/runtime/layer.test-utils.ts +32 -0
- package/src/runtime/layer.test.ts +66 -0
- package/src/runtime/layer.ts +22 -11
- package/src/t3tools/index.ts +1 -1
- package/src/types/marked-terminal.d.ts +11 -0
- package/dist/layout.js +0 -2
- package/dist/scope.js +0 -2
- package/dist/src/cli/output-format.d.ts +0 -9
- package/dist/src/config/layer.d.ts +0 -22
- package/dist/src/config/service.d.ts +0 -22
- package/dist/src/environment/layer.d.ts +0 -3
- package/dist/src/environment/service.d.ts +0 -12
- package/dist/src/layout/index.d.ts +0 -1
- package/dist/upstream-t3code/packages/contracts/src/auth.d.ts +0 -441
- package/dist/upstream-t3code/packages/contracts/src/baseSchemas.d.ts +0 -38
- package/dist/upstream-t3code/packages/contracts/src/desktopBootstrap.d.ts +0 -14
- package/dist/upstream-t3code/packages/contracts/src/editor.d.ts +0 -124
- package/dist/upstream-t3code/packages/contracts/src/environment.d.ts +0 -64
- package/dist/upstream-t3code/packages/contracts/src/environmentHttp.d.ts +0 -785
- package/dist/upstream-t3code/packages/contracts/src/filesystem.d.ts +0 -26
- package/dist/upstream-t3code/packages/contracts/src/git.d.ts +0 -500
- package/dist/upstream-t3code/packages/contracts/src/index.d.ts +0 -25
- package/dist/upstream-t3code/packages/contracts/src/ipc.d.ts +0 -496
- package/dist/upstream-t3code/packages/contracts/src/keybindings.d.ts +0 -133
- package/dist/upstream-t3code/packages/contracts/src/model.d.ts +0 -112
- package/dist/upstream-t3code/packages/contracts/src/orchestration.d.ts +0 -7338
- package/dist/upstream-t3code/packages/contracts/src/project.d.ts +0 -45
- package/dist/upstream-t3code/packages/contracts/src/provider.d.ts +0 -130
- package/dist/upstream-t3code/packages/contracts/src/providerInstance.d.ts +0 -99
- package/dist/upstream-t3code/packages/contracts/src/providerRuntime.d.ts +0 -4450
- package/dist/upstream-t3code/packages/contracts/src/relay.d.ts +0 -1262
- package/dist/upstream-t3code/packages/contracts/src/relayClient.d.ts +0 -48
- package/dist/upstream-t3code/packages/contracts/src/remoteAccess.d.ts +0 -45
- package/dist/upstream-t3code/packages/contracts/src/review.d.ts +0 -37
- package/dist/upstream-t3code/packages/contracts/src/rpc.d.ts +0 -8710
- package/dist/upstream-t3code/packages/contracts/src/server.d.ts +0 -2336
- package/dist/upstream-t3code/packages/contracts/src/settings.d.ts +0 -292
- package/dist/upstream-t3code/packages/contracts/src/sourceControl.d.ts +0 -177
- package/dist/upstream-t3code/packages/contracts/src/terminal.d.ts +0 -333
- package/dist/upstream-t3code/packages/contracts/src/vcs.d.ts +0 -148
- package/src/cli/auth-format.ts +0 -45
- package/src/cli/model-format.ts +0 -18
- package/src/cli/output-format.ts +0 -41
- package/src/cli/project-format.ts +0 -11
- package/src/cli/thread-format.ts +0 -121
- package/src/config/layer.ts +0 -105
- package/src/config/service.ts +0 -26
- package/src/environment/layer.ts +0 -12
- package/src/environment/service.ts +0 -13
- package/src/layout/index.ts +0 -1
- /package/dist/src/{scope → cli/scope}/index.d.ts +0 -0
- /package/dist/src/config/{url.d.ts → url/url.d.ts} +0 -0
- /package/src/{scope → cli/scope}/index.ts +0 -0
- /package/src/config/{url.ts → url/url.ts} +0 -0
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import "vite-plus/test/config";
|
|
2
|
+
|
|
3
|
+
import * as Cause from "effect/Cause";
|
|
4
|
+
import * as Effect from "effect/Effect";
|
|
5
|
+
import * as Exit from "effect/Exit";
|
|
6
|
+
import * as Layer from "effect/Layer";
|
|
7
|
+
import * as NodeServices from "@effect/platform-node/NodeServices";
|
|
8
|
+
import * as Option from "effect/Option";
|
|
9
|
+
import * as Stream from "effect/Stream";
|
|
10
|
+
import { assert, describe, expect, it } from "@effect/vitest";
|
|
11
|
+
import { Command } from "effect/unstable/cli";
|
|
12
|
+
import { fromPartial } from "@total-typescript/shoehorn";
|
|
13
|
+
|
|
14
|
+
import { T3Application } from "../../application/service.ts";
|
|
15
|
+
import { T3Config } from "../../config/config.ts";
|
|
16
|
+
import * as CliRuntime from "../../cli/runtime/service.ts";
|
|
17
|
+
import { t3CliEnvConfigLayer } from "../../config/env/env.test-utils.ts";
|
|
18
|
+
import { T3Output } from "../output/service.ts";
|
|
19
|
+
import { TerminalCliError } from "./error.ts";
|
|
20
|
+
import { resolveMetadataWait, waitTerminalCommand } from "./wait.ts";
|
|
21
|
+
|
|
22
|
+
describe("resolveMetadataWait", () => {
|
|
23
|
+
it("resolves closed immediately when terminal is missing from snapshot", () => {
|
|
24
|
+
const resolution = resolveMetadataWait(
|
|
25
|
+
{ type: "snapshot", terminals: [] },
|
|
26
|
+
"closed",
|
|
27
|
+
"thread-1",
|
|
28
|
+
"term-1",
|
|
29
|
+
);
|
|
30
|
+
expect(resolution).toEqual({
|
|
31
|
+
kind: "result",
|
|
32
|
+
value: {
|
|
33
|
+
threadId: "thread-1",
|
|
34
|
+
terminalId: "term-1",
|
|
35
|
+
target: "closed",
|
|
36
|
+
status: "closed",
|
|
37
|
+
alreadySatisfied: true,
|
|
38
|
+
missingTreatedAsClosed: true,
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("uses the same exited error when terminal is missing from snapshot or removed", () => {
|
|
44
|
+
const missing = resolveMetadataWait(
|
|
45
|
+
{ type: "snapshot", terminals: [] },
|
|
46
|
+
"exited",
|
|
47
|
+
"thread-1",
|
|
48
|
+
"term-1",
|
|
49
|
+
);
|
|
50
|
+
const removed = resolveMetadataWait(
|
|
51
|
+
{ type: "remove", threadId: "thread-1", terminalId: "term-1" },
|
|
52
|
+
"exited",
|
|
53
|
+
"thread-1",
|
|
54
|
+
"term-1",
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
expect(missing?.kind).toBe("fail");
|
|
58
|
+
expect(removed?.kind).toBe("fail");
|
|
59
|
+
if (missing?.kind === "fail" && removed?.kind === "fail") {
|
|
60
|
+
expect(missing.error.message).toBe(removed.error.message);
|
|
61
|
+
expect(missing.error).toBeInstanceOf(TerminalCliError);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
describe("waitTerminalCommand", () => {
|
|
67
|
+
const testLayer = Layer.mergeAll(
|
|
68
|
+
Layer.succeed(
|
|
69
|
+
T3Application,
|
|
70
|
+
fromPartial({
|
|
71
|
+
getTerminal: () => Effect.die("getTerminal should not be called"),
|
|
72
|
+
watchTerminalMetadata: () =>
|
|
73
|
+
Stream.make({
|
|
74
|
+
type: "snapshot" as const,
|
|
75
|
+
terminals: [],
|
|
76
|
+
}),
|
|
77
|
+
}),
|
|
78
|
+
),
|
|
79
|
+
Layer.succeed(
|
|
80
|
+
T3Config,
|
|
81
|
+
fromPartial({
|
|
82
|
+
resolve: () =>
|
|
83
|
+
Effect.succeed({
|
|
84
|
+
url: "ws://localhost",
|
|
85
|
+
token: "token",
|
|
86
|
+
source: "config",
|
|
87
|
+
local: true,
|
|
88
|
+
}),
|
|
89
|
+
}),
|
|
90
|
+
),
|
|
91
|
+
Layer.succeed(T3Output, {
|
|
92
|
+
writeStdout: () => Effect.void,
|
|
93
|
+
writeStderr: () => Effect.void,
|
|
94
|
+
printJson: () => Effect.void,
|
|
95
|
+
printNdjson: () => Effect.void,
|
|
96
|
+
printInfo: () => Effect.void,
|
|
97
|
+
}),
|
|
98
|
+
NodeServices.layer,
|
|
99
|
+
CliRuntime.layer,
|
|
100
|
+
t3CliEnvConfigLayer("/tmp/t3cli-test"),
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
it.layer(testLayer)("waitTerminalCommand", (t) => {
|
|
104
|
+
t.effect("does not require getTerminal before waiting for closed", () =>
|
|
105
|
+
Effect.gen(function* () {
|
|
106
|
+
const run = Command.runWith(waitTerminalCommand, { version: "0.0.0-test" });
|
|
107
|
+
const exit = yield* run([
|
|
108
|
+
"--thread",
|
|
109
|
+
"thread-1",
|
|
110
|
+
"term-1",
|
|
111
|
+
"--for",
|
|
112
|
+
"closed",
|
|
113
|
+
"--format",
|
|
114
|
+
"json",
|
|
115
|
+
]).pipe(Effect.exit);
|
|
116
|
+
assert.isTrue(Exit.isSuccess(exit));
|
|
117
|
+
}),
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
t.effect("uses exited error without getTerminal when terminal is already missing", () =>
|
|
121
|
+
Effect.gen(function* () {
|
|
122
|
+
const run = Command.runWith(waitTerminalCommand, { version: "0.0.0-test" });
|
|
123
|
+
const exit = yield* run([
|
|
124
|
+
"--thread",
|
|
125
|
+
"thread-1",
|
|
126
|
+
"term-1",
|
|
127
|
+
"--for",
|
|
128
|
+
"exited",
|
|
129
|
+
"--format",
|
|
130
|
+
"json",
|
|
131
|
+
]).pipe(Effect.exit);
|
|
132
|
+
assert.isTrue(Exit.isFailure(exit));
|
|
133
|
+
if (!Exit.isFailure(exit)) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
const error = Cause.findErrorOption(exit.cause);
|
|
137
|
+
assert.isTrue(Option.isSome(error));
|
|
138
|
+
if (Option.isSome(error)) {
|
|
139
|
+
assert.instanceOf(error.value, TerminalCliError);
|
|
140
|
+
assert.equal(
|
|
141
|
+
error.value.message,
|
|
142
|
+
"terminal closed before an exited event was observed: term-1",
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
}),
|
|
146
|
+
);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import * as Option from "effect/Option";
|
|
3
|
+
import * as Stream from "effect/Stream";
|
|
4
|
+
import type { TerminalMetadataStreamEvent, TerminalSummary } from "@t3tools/contracts";
|
|
5
|
+
import { Argument, Command, Flag } from "effect/unstable/cli";
|
|
6
|
+
|
|
7
|
+
import { T3Application } from "../../application/service.ts";
|
|
8
|
+
import { extraArgsConfig } from "../extra-args.ts";
|
|
9
|
+
import { CliRuntime } from "../../cli/runtime/service.ts";
|
|
10
|
+
import { loadT3CliEnv } from "../../config/env/env.ts";
|
|
11
|
+
import { formatFlag, threadFlag } from "../flags.ts";
|
|
12
|
+
import { resolveOutputFormat } from "../format/output.ts";
|
|
13
|
+
import { T3Output } from "../output/service.ts";
|
|
14
|
+
import { TerminalCliError } from "./error.ts";
|
|
15
|
+
import { requireCommandThreadId } from "./scope.ts";
|
|
16
|
+
|
|
17
|
+
const terminalWaitTargetChoices = ["exited", "closed", "ended"] as const;
|
|
18
|
+
type TerminalWaitTarget = (typeof terminalWaitTargetChoices)[number];
|
|
19
|
+
|
|
20
|
+
type WaitResult =
|
|
21
|
+
| {
|
|
22
|
+
readonly threadId: string;
|
|
23
|
+
readonly terminalId: string;
|
|
24
|
+
readonly target: TerminalWaitTarget;
|
|
25
|
+
readonly status: string;
|
|
26
|
+
readonly exitCode?: number | null;
|
|
27
|
+
readonly exitSignal?: number | null;
|
|
28
|
+
readonly updatedAt?: string;
|
|
29
|
+
readonly sequence?: number;
|
|
30
|
+
readonly alreadySatisfied: boolean;
|
|
31
|
+
readonly missingTreatedAsClosed?: true;
|
|
32
|
+
}
|
|
33
|
+
| {
|
|
34
|
+
readonly threadId: string;
|
|
35
|
+
readonly terminalId: string;
|
|
36
|
+
readonly target: TerminalWaitTarget;
|
|
37
|
+
readonly status: "exited" | "closed";
|
|
38
|
+
readonly exitCode?: number | null;
|
|
39
|
+
readonly exitSignal?: number | null;
|
|
40
|
+
readonly sequence?: number;
|
|
41
|
+
readonly alreadySatisfied: false;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
type WaitResolution =
|
|
45
|
+
| { readonly kind: "result"; readonly value: WaitResult }
|
|
46
|
+
| { readonly kind: "fail"; readonly error: TerminalCliError };
|
|
47
|
+
|
|
48
|
+
export const waitTerminalCommand = Command.make(
|
|
49
|
+
"wait",
|
|
50
|
+
{
|
|
51
|
+
thread: threadFlag,
|
|
52
|
+
terminalId: Argument.string("terminal-id"),
|
|
53
|
+
target: Flag.choice("for", terminalWaitTargetChoices).pipe(Flag.withDefault("exited")),
|
|
54
|
+
format: formatFlag,
|
|
55
|
+
...extraArgsConfig,
|
|
56
|
+
},
|
|
57
|
+
({ thread, terminalId, target, format }) =>
|
|
58
|
+
Effect.gen(function* () {
|
|
59
|
+
const application = yield* T3Application;
|
|
60
|
+
const cliRuntime = yield* CliRuntime;
|
|
61
|
+
const t3CliEnv = yield* loadT3CliEnv;
|
|
62
|
+
const output = yield* T3Output;
|
|
63
|
+
const threadId = yield* requireCommandThreadId({ thread });
|
|
64
|
+
const resolvedFormat = resolveOutputFormat(format, cliRuntime, t3CliEnv, "json");
|
|
65
|
+
|
|
66
|
+
const resolution = yield* application.watchTerminalMetadata().pipe(
|
|
67
|
+
Stream.map((event) => resolveMetadataWait(event, target, threadId, terminalId)),
|
|
68
|
+
Stream.filter((value): value is WaitResolution => value !== null),
|
|
69
|
+
Stream.runHead,
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
if (Option.isNone(resolution)) {
|
|
73
|
+
yield* Effect.fail(
|
|
74
|
+
new TerminalCliError({
|
|
75
|
+
message: "terminal wait stream ended unexpectedly",
|
|
76
|
+
threadId,
|
|
77
|
+
terminalId,
|
|
78
|
+
}),
|
|
79
|
+
);
|
|
80
|
+
} else if (resolution.value.kind === "fail") {
|
|
81
|
+
yield* Effect.fail(resolution.value.error);
|
|
82
|
+
} else {
|
|
83
|
+
const result = resolution.value.value;
|
|
84
|
+
if (resolvedFormat === "json") {
|
|
85
|
+
yield* output.printJson(result);
|
|
86
|
+
} else {
|
|
87
|
+
yield* output.printInfo(formatWaitHuman(result));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}),
|
|
91
|
+
).pipe(Command.withDescription("wait for terminal lifecycle events"));
|
|
92
|
+
|
|
93
|
+
function terminalClosedBeforeExitError(threadId: string, terminalId: string) {
|
|
94
|
+
return new TerminalCliError({
|
|
95
|
+
message: `terminal closed before an exited event was observed: ${terminalId}`,
|
|
96
|
+
threadId,
|
|
97
|
+
terminalId,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function resolveMetadataWait(
|
|
102
|
+
event: TerminalMetadataStreamEvent,
|
|
103
|
+
target: TerminalWaitTarget,
|
|
104
|
+
threadId: string,
|
|
105
|
+
terminalId: string,
|
|
106
|
+
): WaitResolution | null {
|
|
107
|
+
if (event.type === "snapshot") {
|
|
108
|
+
const terminal = event.terminals.find(
|
|
109
|
+
(candidate) => candidate.threadId === threadId && candidate.terminalId === terminalId,
|
|
110
|
+
);
|
|
111
|
+
if (terminal !== undefined) {
|
|
112
|
+
if (targetSatisfiedBySummary(target, terminal)) {
|
|
113
|
+
return {
|
|
114
|
+
kind: "result",
|
|
115
|
+
value: {
|
|
116
|
+
threadId: terminal.threadId,
|
|
117
|
+
terminalId: terminal.terminalId,
|
|
118
|
+
target,
|
|
119
|
+
status: terminal.status,
|
|
120
|
+
exitCode: terminal.exitCode,
|
|
121
|
+
exitSignal: terminal.exitSignal,
|
|
122
|
+
updatedAt: terminal.updatedAt,
|
|
123
|
+
alreadySatisfied: true,
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
if (target === "closed" || target === "ended") {
|
|
130
|
+
return {
|
|
131
|
+
kind: "result",
|
|
132
|
+
value: {
|
|
133
|
+
threadId,
|
|
134
|
+
terminalId,
|
|
135
|
+
target,
|
|
136
|
+
status: "closed",
|
|
137
|
+
alreadySatisfied: true,
|
|
138
|
+
missingTreatedAsClosed: true,
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
return {
|
|
143
|
+
kind: "fail",
|
|
144
|
+
error: terminalClosedBeforeExitError(threadId, terminalId),
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (event.type === "upsert") {
|
|
149
|
+
if (event.terminal.threadId !== threadId || event.terminal.terminalId !== terminalId) {
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
if ((target === "exited" || target === "ended") && event.terminal.status === "exited") {
|
|
153
|
+
return {
|
|
154
|
+
kind: "result",
|
|
155
|
+
value: {
|
|
156
|
+
threadId,
|
|
157
|
+
terminalId,
|
|
158
|
+
target,
|
|
159
|
+
status: "exited",
|
|
160
|
+
exitCode: event.terminal.exitCode,
|
|
161
|
+
exitSignal: event.terminal.exitSignal,
|
|
162
|
+
alreadySatisfied: false,
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (event.threadId !== threadId || event.terminalId !== terminalId) {
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (target === "exited") {
|
|
174
|
+
return {
|
|
175
|
+
kind: "fail",
|
|
176
|
+
error: terminalClosedBeforeExitError(threadId, terminalId),
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (target === "closed" || target === "ended") {
|
|
181
|
+
return {
|
|
182
|
+
kind: "result",
|
|
183
|
+
value: {
|
|
184
|
+
threadId,
|
|
185
|
+
terminalId,
|
|
186
|
+
target,
|
|
187
|
+
status: "closed",
|
|
188
|
+
alreadySatisfied: false,
|
|
189
|
+
},
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
return null;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function targetSatisfiedBySummary(target: TerminalWaitTarget, terminal: TerminalSummary) {
|
|
197
|
+
if (target === "exited") {
|
|
198
|
+
return terminal.status === "exited";
|
|
199
|
+
}
|
|
200
|
+
if (target === "closed") {
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
return terminal.status === "exited";
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function formatWaitHuman(input: {
|
|
207
|
+
readonly threadId: string;
|
|
208
|
+
readonly terminalId: string;
|
|
209
|
+
readonly status: string;
|
|
210
|
+
readonly alreadySatisfied: boolean;
|
|
211
|
+
readonly exitCode?: number | null;
|
|
212
|
+
readonly exitSignal?: number | null;
|
|
213
|
+
}) {
|
|
214
|
+
const details = [
|
|
215
|
+
typeof input.exitCode === "number" ? `code ${input.exitCode}` : null,
|
|
216
|
+
typeof input.exitSignal === "number" ? `signal ${input.exitSignal}` : null,
|
|
217
|
+
]
|
|
218
|
+
.filter((value): value is string => value !== null)
|
|
219
|
+
.join(", ");
|
|
220
|
+
return details.length > 0
|
|
221
|
+
? `terminal ${input.status}: ${input.terminalId} (${input.threadId}) ${details}`
|
|
222
|
+
: `terminal ${input.status}: ${input.terminalId} (${input.threadId})`;
|
|
223
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import "vite-plus/test/config";
|
|
2
|
+
|
|
3
|
+
import * as Cause from "effect/Cause";
|
|
4
|
+
import * as Effect from "effect/Effect";
|
|
5
|
+
import * as Exit from "effect/Exit";
|
|
6
|
+
import * as Option from "effect/Option";
|
|
7
|
+
import { assert, describe, it } from "@effect/vitest";
|
|
8
|
+
import { Command } from "effect/unstable/cli";
|
|
9
|
+
|
|
10
|
+
import { InvalidFlagCombinationError } from "../error.ts";
|
|
11
|
+
import { terminalCommandTestLayer } from "./read.test-utils.ts";
|
|
12
|
+
import { writeTerminalCommand } from "./write.ts";
|
|
13
|
+
|
|
14
|
+
describe("writeTerminalCommand", () => {
|
|
15
|
+
it.layer(terminalCommandTestLayer)("writeTerminalCommand", (t) => {
|
|
16
|
+
t.effect("rejects multiple payload sources", () =>
|
|
17
|
+
Effect.gen(function* () {
|
|
18
|
+
const run = Command.runWith(writeTerminalCommand, { version: "0.0.0-test" });
|
|
19
|
+
const exit = yield* run(["--thread", "thread-1", "term-1", "hello", "--stdin"]).pipe(
|
|
20
|
+
Effect.exit,
|
|
21
|
+
);
|
|
22
|
+
assert.isTrue(Exit.isFailure(exit));
|
|
23
|
+
if (!Exit.isFailure(exit)) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const error = Cause.findErrorOption(exit.cause);
|
|
27
|
+
assert.isTrue(Option.isSome(error));
|
|
28
|
+
if (Option.isSome(error)) {
|
|
29
|
+
assert.instanceOf(error.value, InvalidFlagCombinationError);
|
|
30
|
+
}
|
|
31
|
+
}),
|
|
32
|
+
);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import * as Option from "effect/Option";
|
|
3
|
+
import { Argument, Command, Flag } from "effect/unstable/cli";
|
|
4
|
+
|
|
5
|
+
import { extraArgsConfig } from "../extra-args.ts";
|
|
6
|
+
import { formatTerminalWrittenHuman } from "../format/terminal.ts";
|
|
7
|
+
import { T3Application } from "../../application/service.ts";
|
|
8
|
+
import { CliRuntime } from "../../cli/runtime/service.ts";
|
|
9
|
+
import { loadT3CliEnv } from "../../config/env/env.ts";
|
|
10
|
+
import { InvalidFlagCombinationError } from "../error.ts";
|
|
11
|
+
import { T3Input } from "../input/service.ts";
|
|
12
|
+
import { formatFlag, threadFlag } from "../flags.ts";
|
|
13
|
+
import { resolveOutputFormat } from "../format/output.ts";
|
|
14
|
+
import { T3Output } from "../output/service.ts";
|
|
15
|
+
import { decodeBase64Payload, decodeHexPayload } from "./encoding.ts";
|
|
16
|
+
import { TerminalCliError } from "./error.ts";
|
|
17
|
+
import { requireCommandThreadId } from "./scope.ts";
|
|
18
|
+
|
|
19
|
+
export const writeTerminalCommand = Command.make(
|
|
20
|
+
"write",
|
|
21
|
+
{
|
|
22
|
+
thread: threadFlag,
|
|
23
|
+
terminalId: Argument.string("terminal-id"),
|
|
24
|
+
data: Argument.string("data").pipe(Argument.optional),
|
|
25
|
+
stdin: Flag.boolean("stdin"),
|
|
26
|
+
hex: Flag.string("hex").pipe(Flag.optional),
|
|
27
|
+
base64: Flag.string("base64").pipe(Flag.optional),
|
|
28
|
+
quiet: Flag.boolean("quiet"),
|
|
29
|
+
format: formatFlag,
|
|
30
|
+
...extraArgsConfig,
|
|
31
|
+
},
|
|
32
|
+
({ thread, terminalId, data, stdin, hex, base64, quiet, format }) =>
|
|
33
|
+
Effect.gen(function* () {
|
|
34
|
+
const output = yield* T3Output;
|
|
35
|
+
const inputService = yield* T3Input;
|
|
36
|
+
const application = yield* T3Application;
|
|
37
|
+
const cliRuntime = yield* CliRuntime;
|
|
38
|
+
const t3CliEnv = yield* loadT3CliEnv;
|
|
39
|
+
const threadId = yield* requireCommandThreadId({ thread });
|
|
40
|
+
const argumentData = Option.getOrUndefined(data);
|
|
41
|
+
const hexData = Option.getOrUndefined(hex);
|
|
42
|
+
const base64Data = Option.getOrUndefined(base64);
|
|
43
|
+
const inputCount = [
|
|
44
|
+
stdin,
|
|
45
|
+
argumentData !== undefined,
|
|
46
|
+
hexData !== undefined,
|
|
47
|
+
base64Data !== undefined,
|
|
48
|
+
].filter(Boolean).length;
|
|
49
|
+
|
|
50
|
+
if (inputCount !== 1) {
|
|
51
|
+
yield* Effect.fail(
|
|
52
|
+
new InvalidFlagCombinationError({
|
|
53
|
+
message: "provide exactly one of <data>, --stdin, --hex <data>, or --base64 <data>",
|
|
54
|
+
}),
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const payload =
|
|
59
|
+
hexData !== undefined
|
|
60
|
+
? yield* decodeHexPayloadOrFail(hexData, threadId, terminalId)
|
|
61
|
+
: base64Data !== undefined
|
|
62
|
+
? yield* decodeBase64PayloadOrFail(base64Data, threadId, terminalId)
|
|
63
|
+
: stdin
|
|
64
|
+
? yield* inputService.readStdinBinary()
|
|
65
|
+
: argumentData!;
|
|
66
|
+
if (payload.length === 0) {
|
|
67
|
+
yield* Effect.fail(
|
|
68
|
+
new TerminalCliError({
|
|
69
|
+
message: "terminal write payload is empty",
|
|
70
|
+
threadId,
|
|
71
|
+
terminalId,
|
|
72
|
+
}),
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
yield* application.writeTerminal({
|
|
77
|
+
terminal: {
|
|
78
|
+
threadId,
|
|
79
|
+
terminalId,
|
|
80
|
+
},
|
|
81
|
+
data: payload,
|
|
82
|
+
});
|
|
83
|
+
if (quiet) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const bytes = Buffer.byteLength(payload, "latin1");
|
|
87
|
+
const resolvedFormat = resolveOutputFormat(format, cliRuntime, t3CliEnv, "json");
|
|
88
|
+
if (resolvedFormat === "json") {
|
|
89
|
+
yield* output.printJson({
|
|
90
|
+
threadId,
|
|
91
|
+
terminalId,
|
|
92
|
+
bytes,
|
|
93
|
+
encoding: hexData !== undefined ? "hex" : base64Data !== undefined ? "base64" : "latin1",
|
|
94
|
+
});
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
yield* output.printInfo(
|
|
98
|
+
formatTerminalWrittenHuman({
|
|
99
|
+
terminalId,
|
|
100
|
+
threadId,
|
|
101
|
+
bytes,
|
|
102
|
+
}),
|
|
103
|
+
);
|
|
104
|
+
}),
|
|
105
|
+
).pipe(Command.withDescription("write raw data to a terminal"));
|
|
106
|
+
|
|
107
|
+
function decodeHexPayloadOrFail(value: string, threadId: string, terminalId: string) {
|
|
108
|
+
const decoded = decodeHexPayload(value);
|
|
109
|
+
if (decoded === undefined) {
|
|
110
|
+
return Effect.fail(
|
|
111
|
+
new TerminalCliError({
|
|
112
|
+
message: "invalid hex payload",
|
|
113
|
+
threadId,
|
|
114
|
+
terminalId,
|
|
115
|
+
}),
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
return Effect.succeed(decoded);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function decodeBase64PayloadOrFail(value: string, threadId: string, terminalId: string) {
|
|
122
|
+
const decoded = decodeBase64Payload(value);
|
|
123
|
+
if (decoded === undefined) {
|
|
124
|
+
return Effect.fail(
|
|
125
|
+
new TerminalCliError({
|
|
126
|
+
message: "invalid base64 payload",
|
|
127
|
+
threadId,
|
|
128
|
+
terminalId,
|
|
129
|
+
}),
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
return Effect.succeed(decoded);
|
|
133
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Command } from "effect/unstable/cli";
|
|
2
|
+
|
|
3
|
+
import { attachTerminalCommand } from "./terminal/attach.ts";
|
|
4
|
+
import { createTerminalCommand } from "./terminal/create.ts";
|
|
5
|
+
import { destroyTerminalCommand } from "./terminal/destroy.ts";
|
|
6
|
+
import { listTerminalCommand } from "./terminal/list.ts";
|
|
7
|
+
import { readTerminalCommand } from "./terminal/read.ts";
|
|
8
|
+
import { streamTerminalCommand } from "./terminal/stream.ts";
|
|
9
|
+
import { waitTerminalCommand } from "./terminal/wait.ts";
|
|
10
|
+
import { writeTerminalCommand } from "./terminal/write.ts";
|
|
11
|
+
|
|
12
|
+
export function createTerminalCommandGroup() {
|
|
13
|
+
return Command.make("terminal").pipe(
|
|
14
|
+
Command.withDescription("terminal commands"),
|
|
15
|
+
Command.withSubcommands([
|
|
16
|
+
listTerminalCommand,
|
|
17
|
+
createTerminalCommand,
|
|
18
|
+
attachTerminalCommand,
|
|
19
|
+
readTerminalCommand,
|
|
20
|
+
streamTerminalCommand,
|
|
21
|
+
waitTerminalCommand,
|
|
22
|
+
writeTerminalCommand,
|
|
23
|
+
destroyTerminalCommand,
|
|
24
|
+
]),
|
|
25
|
+
);
|
|
26
|
+
}
|
package/src/cli/thread.ts
CHANGED
|
@@ -3,7 +3,11 @@ import { Command } from "effect/unstable/cli";
|
|
|
3
3
|
import { approveThreadCommand } from "./threads/approve.ts";
|
|
4
4
|
import { archiveThreadCommand } from "./threads/archive.ts";
|
|
5
5
|
import { callbackThreadCommand } from "./threads/callback.ts";
|
|
6
|
+
import { deleteThreadCommand } from "./threads/delete.ts";
|
|
7
|
+
import { interruptThreadCommand } from "./threads/interrupt.ts";
|
|
6
8
|
import { respondThreadCommand } from "./threads/respond.ts";
|
|
9
|
+
import { unarchiveThreadCommand } from "./threads/unarchive.ts";
|
|
10
|
+
import { updateThreadCommand } from "./threads/update.ts";
|
|
7
11
|
|
|
8
12
|
export function createThreadCommand() {
|
|
9
13
|
return Command.make("thread").pipe(
|
|
@@ -12,6 +16,10 @@ export function createThreadCommand() {
|
|
|
12
16
|
approveThreadCommand,
|
|
13
17
|
respondThreadCommand,
|
|
14
18
|
archiveThreadCommand,
|
|
19
|
+
interruptThreadCommand,
|
|
20
|
+
unarchiveThreadCommand,
|
|
21
|
+
updateThreadCommand,
|
|
22
|
+
deleteThreadCommand,
|
|
15
23
|
callbackThreadCommand,
|
|
16
24
|
]),
|
|
17
25
|
);
|
|
@@ -2,12 +2,14 @@ import * as Effect from "effect/Effect";
|
|
|
2
2
|
import * as Option from "effect/Option";
|
|
3
3
|
import { Command, Flag } from "effect/unstable/cli";
|
|
4
4
|
|
|
5
|
+
import { extraArgsConfig } from "../extra-args.ts";
|
|
5
6
|
import { formatFlag, threadFlag } from "../flags.ts";
|
|
6
7
|
import { MissingRequestError, MissingThreadError } from "../error.ts";
|
|
7
|
-
import { resolveThreadId } from "
|
|
8
|
+
import { resolveThreadId } from "../scope/index.ts";
|
|
8
9
|
import { T3Application } from "../../application/service.ts";
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
10
|
+
import { CliRuntime } from "../../cli/runtime/service.ts";
|
|
11
|
+
import { loadT3CliEnv } from "../../config/env/env.ts";
|
|
12
|
+
import { resolveOutputFormat } from "../format/output.ts";
|
|
11
13
|
import { T3Output } from "../output/service.ts";
|
|
12
14
|
|
|
13
15
|
const approvalDecisionFlag = Flag.choice("decision", ["accept", "decline", "cancel"] as const).pipe(
|
|
@@ -26,15 +28,17 @@ export const approveThreadCommand = Command.make(
|
|
|
26
28
|
request: requestFlag,
|
|
27
29
|
decision: approvalDecisionFlag,
|
|
28
30
|
format: formatFlag,
|
|
31
|
+
...extraArgsConfig,
|
|
29
32
|
},
|
|
30
33
|
({ thread, request, decision, format }) =>
|
|
31
34
|
Effect.gen(function* () {
|
|
32
35
|
const application = yield* T3Application;
|
|
33
|
-
const
|
|
36
|
+
const cliRuntime = yield* CliRuntime;
|
|
37
|
+
const t3CliEnv = yield* loadT3CliEnv;
|
|
34
38
|
const output = yield* T3Output;
|
|
35
39
|
const threadId = resolveThreadId({
|
|
36
40
|
value: Option.getOrUndefined(thread),
|
|
37
|
-
|
|
41
|
+
scope: t3CliEnv.scope,
|
|
38
42
|
});
|
|
39
43
|
if (threadId === undefined) {
|
|
40
44
|
return yield* Effect.fail(
|
|
@@ -49,13 +53,13 @@ export const approveThreadCommand = Command.make(
|
|
|
49
53
|
new MissingRequestError({ message: "request id is required: pass --request" }),
|
|
50
54
|
);
|
|
51
55
|
}
|
|
52
|
-
const resolvedFormat = resolveOutputFormat(format,
|
|
56
|
+
const resolvedFormat = resolveOutputFormat(format, cliRuntime, t3CliEnv, "json");
|
|
53
57
|
const result = yield* application.approveThread({ threadId, requestId, decision });
|
|
54
58
|
if (resolvedFormat === "json") {
|
|
55
59
|
return yield* output.printJson(result);
|
|
56
60
|
}
|
|
57
61
|
return yield* output.printInfo(
|
|
58
|
-
`approval submitted: ${result.requestId}
|
|
62
|
+
`approval submitted: ${result.requestId} (sequence ${result.dispatch.sequence})`,
|
|
59
63
|
);
|
|
60
64
|
}),
|
|
61
65
|
).pipe(Command.withDescription("respond to a pending approval request"));
|