t3code-cli 0.6.0 → 0.8.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 (50) hide show
  1. package/dist/auth.js +2 -2
  2. package/dist/bin.js +56 -5
  3. package/dist/connection.js +3 -3
  4. package/dist/{error-B2t1bAP9.js → error-ChTsLQTu.js} +2 -2
  5. package/dist/{error-jwMt3VoW.js → error-CjADNVm8.js} +1 -1
  6. package/dist/index.js +1 -1
  7. package/dist/{layer-DvHnKBYj.js → layer-CMo36MrX.js} +3 -3
  8. package/dist/{layer-CfC5qZol.js → layer-Do8wK1t6.js} +3 -3
  9. package/dist/{layer-DIg0RxSO.js → layer-DwI3Skkh.js} +69 -63
  10. package/dist/orchestration.js +1 -1
  11. package/dist/rpc.js +1 -1
  12. package/dist/runtime.js +1 -1
  13. package/dist/src/application/layer.d.ts +61 -0
  14. package/dist/src/application/models.d.ts +1 -0
  15. package/dist/src/application/projects.d.ts +9 -0
  16. package/dist/src/application/service.d.ts +9 -0
  17. package/dist/src/application/shell-sequence.d.ts +9 -0
  18. package/dist/src/application/thread-wait.d.ts +9 -0
  19. package/dist/src/application/threads.d.ts +52 -1
  20. package/dist/src/cli-path/layer.d.ts +3 -0
  21. package/dist/src/cli-path/service.d.ts +8 -0
  22. package/dist/src/domain/helpers.d.ts +11 -3
  23. package/dist/src/domain/model-config.d.ts +3 -0
  24. package/dist/src/domain/thread-lifecycle.d.ts +9 -0
  25. package/dist/src/orchestration/layer.d.ts +215 -0
  26. package/dist/src/rpc/layer.d.ts +466 -0
  27. package/dist/src/rpc/ws-group.d.ts +142 -0
  28. package/dist/src/runtime/layer.d.ts +1 -1
  29. package/dist/{src-KdbHqrex.js → src-aiFPmAG7.js} +169 -13
  30. package/dist/t3tools.js +2 -2
  31. package/dist/{transport-D3zBdZ1h.js → transport-MI0Z3d2T.js} +2 -2
  32. package/dist/upstream-t3code/packages/contracts/src/environmentHttp.d.ts +33 -10
  33. package/dist/upstream-t3code/packages/contracts/src/ipc.d.ts +6 -0
  34. package/dist/upstream-t3code/packages/contracts/src/orchestration.d.ts +657 -1
  35. package/dist/upstream-t3code/packages/contracts/src/provider.d.ts +14 -0
  36. package/dist/upstream-t3code/packages/contracts/src/providerRuntime.d.ts +175 -1
  37. package/dist/upstream-t3code/packages/contracts/src/rpc.d.ts +492 -0
  38. package/dist/upstream-t3code/packages/contracts/src/server.d.ts +45 -0
  39. package/dist/upstream-t3code/packages/contracts/src/settings.d.ts +21 -0
  40. package/dist/upstream-t3code/packages/contracts/src/terminal.d.ts +6 -3
  41. package/package.json +6 -3
  42. package/src/application/service.ts +13 -0
  43. package/src/application/threads.ts +15 -3
  44. package/src/cli/thread.ts +2 -0
  45. package/src/cli/threads/callback.ts +92 -0
  46. package/src/cli-path/layer.ts +10 -0
  47. package/src/cli-path/service.ts +7 -0
  48. package/src/domain/helpers.test.ts +103 -0
  49. package/src/domain/helpers.ts +61 -85
  50. package/src/runtime/layer.ts +2 -0
@@ -11,27 +11,20 @@ export const resolveProjectScope = Effect.fn("resolveProjectScope")(function* (
11
11
  snapshot: OrchestrationShellSnapshot,
12
12
  input: {
13
13
  readonly ref: string;
14
- readonly cwd: string;
15
14
  },
16
15
  ) {
17
- const absoluteRef = yield* resolveAbsolutePath(input.ref, input.cwd);
16
+ const path = yield* Path.Path;
18
17
 
19
18
  const byId = findProjectById(snapshot, input.ref);
20
19
  if (byId !== null) {
21
20
  return { project: byId };
22
21
  }
23
22
 
24
- const byExactPath = yield* findProjectByWorkspaceRoot(snapshot, absoluteRef, input.cwd);
25
- if (byExactPath !== undefined) {
26
- return { project: byExactPath };
27
- }
28
-
29
- const byAncestor = yield* findProjectByAncestorPath(snapshot, absoluteRef, input.cwd);
30
- if (byAncestor !== undefined) {
31
- return byAncestor;
23
+ if (!path.isAbsolute(input.ref)) {
24
+ return undefined;
32
25
  }
33
26
 
34
- return yield* findProjectByKnownWorktreePath(snapshot, absoluteRef, input.cwd);
27
+ return yield* findProjectByPathPriority(snapshot, path.normalize(input.ref));
35
28
  });
36
29
 
37
30
  export function findProjectById(
@@ -41,11 +34,6 @@ export function findProjectById(
41
34
  return snapshot.projects.find((project) => project.id === projectId) ?? null;
42
35
  }
43
36
 
44
- const resolveAbsolutePath = Effect.fn("resolveAbsolutePath")(function* (ref: string, cwd: string) {
45
- const path = yield* Path.Path;
46
- return path.isAbsolute(ref) ? path.normalize(ref) : path.normalize(path.resolve(cwd, ref));
47
- });
48
-
49
37
  const isDescendantPath = Effect.fn("isDescendantPath")(function* (parent: string, child: string) {
50
38
  const path = yield* Path.Path;
51
39
  if (child === parent) {
@@ -55,61 +43,23 @@ const isDescendantPath = Effect.fn("isDescendantPath")(function* (parent: string
55
43
  return relative.length > 0 && !relative.startsWith("..") && !path.isAbsolute(relative);
56
44
  });
57
45
 
58
- const findProjectByWorkspaceRoot = Effect.fn("findProjectByWorkspaceRoot")(function* (
59
- snapshot: OrchestrationShellSnapshot,
60
- absolutePath: string,
61
- cwd: string,
62
- ) {
63
- for (const project of snapshot.projects) {
64
- const workspaceRoot = yield* resolveAbsolutePath(project.workspaceRoot, cwd);
65
- if (workspaceRoot === absolutePath) {
66
- return project;
67
- }
68
- }
69
- return undefined;
70
- });
71
-
72
- const findProjectByAncestorPath = Effect.fn("findProjectByAncestorPath")(function* (
46
+ const findProjectByPathPriority = Effect.fn("findProjectByPathPriority")(function* (
73
47
  snapshot: OrchestrationShellSnapshot,
74
48
  absolutePath: string,
75
- cwd: string,
76
- ) {
77
- let bestProject: OrchestrationProjectShell | undefined;
78
- let bestWorkspaceRoot = "";
79
-
80
- for (const project of snapshot.projects) {
81
- const workspaceRoot = yield* resolveAbsolutePath(project.workspaceRoot, cwd);
82
- if (!(yield* isDescendantPath(workspaceRoot, absolutePath))) {
83
- continue;
84
- }
85
- if (workspaceRoot.length > bestWorkspaceRoot.length) {
86
- bestProject = project;
87
- bestWorkspaceRoot = workspaceRoot;
88
- }
89
- }
90
-
91
- if (bestProject === undefined) {
92
- return undefined;
93
- }
94
-
95
- if (absolutePath === bestWorkspaceRoot) {
96
- return { project: bestProject };
97
- }
98
-
99
- return {
100
- project: bestProject,
101
- inferredWorktreePath: absolutePath,
102
- };
103
- });
104
-
105
- const findProjectByKnownWorktreePath = Effect.fn("findProjectByKnownWorktreePath")(function* (
106
- snapshot: OrchestrationShellSnapshot,
107
- absolutePath: string,
108
- cwd: string,
109
49
  ) {
50
+ const path = yield* Path.Path;
110
51
  const projectsById = new Map(snapshot.projects.map((project) => [project.id, project]));
111
- let bestProject: OrchestrationProjectShell | undefined;
112
- let bestKnownPath = "";
52
+ const workspaceRoots = new Map(
53
+ snapshot.projects.map(
54
+ (project) => [project.id, path.normalize(project.workspaceRoot)] as const,
55
+ ),
56
+ );
57
+ const candidates: Array<{
58
+ readonly project: OrchestrationProjectShell;
59
+ readonly matchPath: string;
60
+ readonly workspaceRoot: string;
61
+ readonly source: "worktree" | "project";
62
+ }> = [];
113
63
 
114
64
  for (const thread of snapshot.threads) {
115
65
  if (thread.worktreePath === null) {
@@ -119,33 +69,59 @@ const findProjectByKnownWorktreePath = Effect.fn("findProjectByKnownWorktreePath
119
69
  if (project === undefined) {
120
70
  continue;
121
71
  }
122
- const knownPath = yield* resolveAbsolutePath(thread.worktreePath, cwd);
123
- if (!(yield* isDescendantPath(knownPath, absolutePath))) {
72
+ const workspaceRoot = workspaceRoots.get(thread.projectId);
73
+ if (workspaceRoot === undefined) {
124
74
  continue;
125
75
  }
126
- if (knownPath.length > bestKnownPath.length) {
127
- bestProject = project;
128
- bestKnownPath = knownPath;
76
+ const matchPath = path.normalize(thread.worktreePath);
77
+ if (!(yield* isDescendantPath(matchPath, absolutePath))) {
78
+ continue;
129
79
  }
80
+ candidates.push({
81
+ project,
82
+ matchPath,
83
+ workspaceRoot,
84
+ source: "worktree",
85
+ });
130
86
  }
131
87
 
132
- if (bestProject === undefined) {
133
- return undefined;
88
+ for (const project of snapshot.projects) {
89
+ const workspaceRoot = workspaceRoots.get(project.id);
90
+ if (workspaceRoot === undefined) {
91
+ continue;
92
+ }
93
+ if (!(yield* isDescendantPath(workspaceRoot, absolutePath))) {
94
+ continue;
95
+ }
96
+ candidates.push({
97
+ project,
98
+ matchPath: workspaceRoot,
99
+ workspaceRoot,
100
+ source: "project",
101
+ });
134
102
  }
135
103
 
136
- const workspaceRoot = yield* resolveAbsolutePath(bestProject.workspaceRoot, cwd);
137
- if (absolutePath === workspaceRoot) {
138
- return { project: bestProject };
104
+ if (candidates.length === 0) {
105
+ return undefined;
139
106
  }
140
107
 
141
- if (absolutePath === bestKnownPath) {
142
- return bestKnownPath === workspaceRoot
143
- ? { project: bestProject }
144
- : { project: bestProject, inferredWorktreePath: bestKnownPath };
108
+ candidates.sort((left, right) => {
109
+ if (left.matchPath.length !== right.matchPath.length) {
110
+ return right.matchPath.length - left.matchPath.length;
111
+ }
112
+ if (left.source === right.source) {
113
+ return 0;
114
+ }
115
+ return left.source === "worktree" ? -1 : 1;
116
+ });
117
+
118
+ const best = candidates[0]!;
119
+ if (absolutePath === best.matchPath) {
120
+ if (best.source === "worktree" && best.matchPath !== best.workspaceRoot) {
121
+ return { project: best.project, inferredWorktreePath: best.matchPath };
122
+ }
123
+ return { project: best.project };
145
124
  }
146
125
 
147
- return {
148
- project: bestProject,
149
- inferredWorktreePath: absolutePath,
150
- };
126
+ return { project: best.project, inferredWorktreePath: absolutePath };
151
127
  });
@@ -17,6 +17,7 @@ import { T3CodeConnectionProvider, makeT3CodeConnectionProvider } from "../conne
17
17
  import { T3OrchestrationLive } from "../orchestration/layer.ts";
18
18
  import { T3RpcLive } from "../rpc/layer.ts";
19
19
  import { NodeSqlClientFactoryLive } from "../sql/node-sqlite-client.ts";
20
+ import { NodeCliPathLayer } from "../cli-path/layer.ts";
20
21
 
21
22
  export const T3AuthTransportLayer = T3AuthTransportLive.pipe(
22
23
  Layer.provide(NodeHttpClient.layerUndici),
@@ -76,4 +77,5 @@ export const AppLayer = Layer.mergeAll(
76
77
  T3RpcLayer,
77
78
  T3OrchestrationLayer,
78
79
  T3ApplicationLayer,
80
+ NodeCliPathLayer,
79
81
  );