@jmoyers/harness 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 (214) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +145 -0
  3. package/native/ptyd/Cargo.lock +16 -0
  4. package/native/ptyd/Cargo.toml +7 -0
  5. package/native/ptyd/src/main.rs +257 -0
  6. package/package.json +90 -0
  7. package/scripts/build-ptyd.sh +73 -0
  8. package/scripts/control-plane-daemon.ts +277 -0
  9. package/scripts/cursor-hook-relay.ts +82 -0
  10. package/scripts/harness-animate.ts +469 -0
  11. package/scripts/harness-bin.js +77 -0
  12. package/scripts/harness-core.ts +1 -0
  13. package/scripts/harness-inspector.ts +439 -0
  14. package/scripts/harness.ts +2493 -0
  15. package/src/adapters/agent-session-state.ts +390 -0
  16. package/src/cli/gateway-record.ts +173 -0
  17. package/src/codex/live-session.ts +872 -0
  18. package/src/config/config-core.ts +1359 -0
  19. package/src/config/secrets-core.ts +170 -0
  20. package/src/control-plane/agent-realtime-api.ts +2441 -0
  21. package/src/control-plane/codex-session-stream.ts +392 -0
  22. package/src/control-plane/codex-telemetry.ts +1325 -0
  23. package/src/control-plane/lifecycle-hooks.ts +706 -0
  24. package/src/control-plane/session-summary.ts +380 -0
  25. package/src/control-plane/status/agent-status-reducer.ts +21 -0
  26. package/src/control-plane/status/reducer-base.ts +170 -0
  27. package/src/control-plane/status/reducers/claude-status-reducer.ts +37 -0
  28. package/src/control-plane/status/reducers/codex-status-reducer.ts +48 -0
  29. package/src/control-plane/status/reducers/critique-status-reducer.ts +15 -0
  30. package/src/control-plane/status/reducers/cursor-status-reducer.ts +37 -0
  31. package/src/control-plane/status/reducers/terminal-status-reducer.ts +15 -0
  32. package/src/control-plane/status/session-status-engine.ts +76 -0
  33. package/src/control-plane/stream-client.ts +396 -0
  34. package/src/control-plane/stream-command-parser.ts +1673 -0
  35. package/src/control-plane/stream-protocol.ts +1808 -0
  36. package/src/control-plane/stream-server-background.ts +486 -0
  37. package/src/control-plane/stream-server-command.ts +2557 -0
  38. package/src/control-plane/stream-server-connection.ts +234 -0
  39. package/src/control-plane/stream-server-observed-filter.ts +112 -0
  40. package/src/control-plane/stream-server-session-runtime.ts +566 -0
  41. package/src/control-plane/stream-server-state-store.ts +15 -0
  42. package/src/control-plane/stream-server.ts +3192 -0
  43. package/src/cursor/managed-hooks.ts +282 -0
  44. package/src/domain/conversations.ts +414 -0
  45. package/src/domain/directories.ts +78 -0
  46. package/src/domain/repositories.ts +123 -0
  47. package/src/domain/tasks.ts +148 -0
  48. package/src/domain/workspace.ts +156 -0
  49. package/src/events/normalized-events.ts +124 -0
  50. package/src/mux/ansi-integrity.ts +103 -0
  51. package/src/mux/control-plane-op-queue.ts +212 -0
  52. package/src/mux/conversation-rail.ts +339 -0
  53. package/src/mux/double-click.ts +78 -0
  54. package/src/mux/dual-pane-core.ts +435 -0
  55. package/src/mux/harness-core-ui.ts +817 -0
  56. package/src/mux/input-shortcuts.ts +667 -0
  57. package/src/mux/live-mux/actions-conversation.ts +344 -0
  58. package/src/mux/live-mux/actions-repository.ts +246 -0
  59. package/src/mux/live-mux/actions-task.ts +115 -0
  60. package/src/mux/live-mux/args.ts +142 -0
  61. package/src/mux/live-mux/command-menu.ts +298 -0
  62. package/src/mux/live-mux/control-plane-records.ts +546 -0
  63. package/src/mux/live-mux/conversation-state.ts +188 -0
  64. package/src/mux/live-mux/directory-resolution.ts +34 -0
  65. package/src/mux/live-mux/event-mapping.ts +96 -0
  66. package/src/mux/live-mux/gateway-profiler.ts +152 -0
  67. package/src/mux/live-mux/gateway-render-trace.ts +177 -0
  68. package/src/mux/live-mux/gateway-status-timeline.ts +166 -0
  69. package/src/mux/live-mux/git-parsing.ts +131 -0
  70. package/src/mux/live-mux/git-snapshot.ts +263 -0
  71. package/src/mux/live-mux/git-state.ts +136 -0
  72. package/src/mux/live-mux/global-shortcut-handlers.ts +143 -0
  73. package/src/mux/live-mux/home-pane-actions.ts +58 -0
  74. package/src/mux/live-mux/home-pane-drop.ts +44 -0
  75. package/src/mux/live-mux/home-pane-entity-click.ts +96 -0
  76. package/src/mux/live-mux/home-pane-pointer.ts +96 -0
  77. package/src/mux/live-mux/input-forwarding.ts +112 -0
  78. package/src/mux/live-mux/layout.ts +30 -0
  79. package/src/mux/live-mux/left-nav-activation.ts +103 -0
  80. package/src/mux/live-mux/left-nav.ts +85 -0
  81. package/src/mux/live-mux/left-rail-actions.ts +118 -0
  82. package/src/mux/live-mux/left-rail-conversation-click.ts +82 -0
  83. package/src/mux/live-mux/left-rail-pointer.ts +74 -0
  84. package/src/mux/live-mux/modal-command-menu-handler.ts +101 -0
  85. package/src/mux/live-mux/modal-conversation-handlers.ts +217 -0
  86. package/src/mux/live-mux/modal-input-reducers.ts +94 -0
  87. package/src/mux/live-mux/modal-overlays.ts +287 -0
  88. package/src/mux/live-mux/modal-pointer.ts +70 -0
  89. package/src/mux/live-mux/modal-prompt-handlers.ts +187 -0
  90. package/src/mux/live-mux/modal-task-editor-handler.ts +156 -0
  91. package/src/mux/live-mux/observed-stream.ts +87 -0
  92. package/src/mux/live-mux/palette-parsing.ts +128 -0
  93. package/src/mux/live-mux/pointer-routing.ts +108 -0
  94. package/src/mux/live-mux/process-usage.ts +53 -0
  95. package/src/mux/live-mux/project-pane-pointer.ts +44 -0
  96. package/src/mux/live-mux/rail-layout.ts +244 -0
  97. package/src/mux/live-mux/render-trace-analysis.ts +213 -0
  98. package/src/mux/live-mux/render-trace-state.ts +84 -0
  99. package/src/mux/live-mux/repository-folding.ts +207 -0
  100. package/src/mux/live-mux/runtime-shutdown.ts +51 -0
  101. package/src/mux/live-mux/selection.ts +411 -0
  102. package/src/mux/live-mux/startup-utils.ts +187 -0
  103. package/src/mux/live-mux/status-timeline-state.ts +82 -0
  104. package/src/mux/live-mux/task-pane-shortcuts.ts +206 -0
  105. package/src/mux/live-mux/terminal-palette.ts +79 -0
  106. package/src/mux/new-thread-prompt.ts +165 -0
  107. package/src/mux/project-tree.ts +295 -0
  108. package/src/mux/render-frame.ts +113 -0
  109. package/src/mux/runtime-wiring.ts +185 -0
  110. package/src/mux/selector-index.ts +160 -0
  111. package/src/mux/startup-sequencer.ts +238 -0
  112. package/src/mux/task-composer.ts +289 -0
  113. package/src/mux/task-focused-pane.ts +417 -0
  114. package/src/mux/task-screen-keybindings.ts +539 -0
  115. package/src/mux/terminal-input-modes.ts +35 -0
  116. package/src/mux/workspace-path.ts +55 -0
  117. package/src/mux/workspace-rail-model.ts +701 -0
  118. package/src/mux/workspace-rail.ts +247 -0
  119. package/src/perf/perf-core.ts +307 -0
  120. package/src/pty/pty_host.ts +217 -0
  121. package/src/pty/session-broker.ts +158 -0
  122. package/src/recording/terminal-recording.ts +383 -0
  123. package/src/services/control-plane.ts +567 -0
  124. package/src/services/conversation-lifecycle.ts +176 -0
  125. package/src/services/conversation-startup-hydration.ts +47 -0
  126. package/src/services/directory-hydration.ts +49 -0
  127. package/src/services/event-persistence.ts +104 -0
  128. package/src/services/mux-ui-state-persistence.ts +82 -0
  129. package/src/services/output-load-sampler.ts +231 -0
  130. package/src/services/process-usage-refresh.ts +88 -0
  131. package/src/services/recording.ts +75 -0
  132. package/src/services/render-trace-recorder.ts +177 -0
  133. package/src/services/runtime-control-actions.ts +123 -0
  134. package/src/services/runtime-control-plane-ops.ts +131 -0
  135. package/src/services/runtime-conversation-actions.ts +113 -0
  136. package/src/services/runtime-conversation-activation.ts +78 -0
  137. package/src/services/runtime-conversation-starter.ts +171 -0
  138. package/src/services/runtime-conversation-title-edit.ts +149 -0
  139. package/src/services/runtime-directory-actions.ts +164 -0
  140. package/src/services/runtime-envelope-handler.ts +198 -0
  141. package/src/services/runtime-git-state.ts +92 -0
  142. package/src/services/runtime-input-pipeline.ts +50 -0
  143. package/src/services/runtime-input-router.ts +202 -0
  144. package/src/services/runtime-layout-resize.ts +236 -0
  145. package/src/services/runtime-left-rail-render.ts +159 -0
  146. package/src/services/runtime-main-pane-input.ts +230 -0
  147. package/src/services/runtime-modal-input.ts +119 -0
  148. package/src/services/runtime-navigation-input.ts +207 -0
  149. package/src/services/runtime-process-wiring.ts +68 -0
  150. package/src/services/runtime-rail-input.ts +287 -0
  151. package/src/services/runtime-render-flush.ts +146 -0
  152. package/src/services/runtime-render-lifecycle.ts +104 -0
  153. package/src/services/runtime-render-orchestrator.ts +108 -0
  154. package/src/services/runtime-render-pipeline.ts +167 -0
  155. package/src/services/runtime-render-state.ts +72 -0
  156. package/src/services/runtime-repository-actions.ts +197 -0
  157. package/src/services/runtime-right-pane-render.ts +132 -0
  158. package/src/services/runtime-shutdown.ts +79 -0
  159. package/src/services/runtime-stream-subscriptions.ts +56 -0
  160. package/src/services/runtime-task-composer-persistence.ts +139 -0
  161. package/src/services/runtime-task-editor-actions.ts +83 -0
  162. package/src/services/runtime-task-pane-actions.ts +198 -0
  163. package/src/services/runtime-task-pane-shortcuts.ts +189 -0
  164. package/src/services/runtime-task-pane.ts +62 -0
  165. package/src/services/runtime-workspace-actions.ts +153 -0
  166. package/src/services/runtime-workspace-observed-events.ts +190 -0
  167. package/src/services/session-projection-instrumentation.ts +190 -0
  168. package/src/services/startup-background-probe.ts +91 -0
  169. package/src/services/startup-background-resume.ts +65 -0
  170. package/src/services/startup-orchestrator.ts +166 -0
  171. package/src/services/startup-output-tracker.ts +54 -0
  172. package/src/services/startup-paint-tracker.ts +115 -0
  173. package/src/services/startup-persisted-conversation-queue.ts +45 -0
  174. package/src/services/startup-settled-gate.ts +67 -0
  175. package/src/services/startup-shutdown.ts +53 -0
  176. package/src/services/startup-span-tracker.ts +77 -0
  177. package/src/services/startup-state-hydration.ts +94 -0
  178. package/src/services/startup-visibility.ts +35 -0
  179. package/src/services/status-timeline-recorder.ts +144 -0
  180. package/src/services/task-pane-selection-actions.ts +153 -0
  181. package/src/services/task-planning-hydration.ts +58 -0
  182. package/src/services/task-planning-observed-events.ts +89 -0
  183. package/src/services/workspace-observed-events.ts +113 -0
  184. package/src/store/control-plane-store-normalize.ts +760 -0
  185. package/src/store/control-plane-store-types.ts +224 -0
  186. package/src/store/control-plane-store.ts +2951 -0
  187. package/src/store/event-store.ts +253 -0
  188. package/src/store/sqlite.ts +81 -0
  189. package/src/terminal/compat-matrix.ts +345 -0
  190. package/src/terminal/differential-checkpoints.ts +132 -0
  191. package/src/terminal/parity-suite.ts +441 -0
  192. package/src/terminal/snapshot-oracle.ts +1840 -0
  193. package/src/ui/conversation-input-forwarder.ts +114 -0
  194. package/src/ui/conversation-selection-input.ts +103 -0
  195. package/src/ui/debug-footer-notice.ts +39 -0
  196. package/src/ui/global-shortcut-input.ts +126 -0
  197. package/src/ui/input-preflight.ts +68 -0
  198. package/src/ui/input-token-router.ts +312 -0
  199. package/src/ui/input.ts +238 -0
  200. package/src/ui/kit.ts +509 -0
  201. package/src/ui/left-nav-input.ts +80 -0
  202. package/src/ui/left-rail-pointer-input.ts +148 -0
  203. package/src/ui/main-pane-pointer-input.ts +150 -0
  204. package/src/ui/modals/manager.ts +192 -0
  205. package/src/ui/mux-theme.ts +529 -0
  206. package/src/ui/panes/conversation.ts +19 -0
  207. package/src/ui/panes/home-gridfire.ts +302 -0
  208. package/src/ui/panes/home.ts +109 -0
  209. package/src/ui/panes/left-rail.ts +12 -0
  210. package/src/ui/panes/project.ts +44 -0
  211. package/src/ui/pointer-routing-input.ts +158 -0
  212. package/src/ui/repository-fold-input.ts +91 -0
  213. package/src/ui/screen.ts +210 -0
  214. package/src/ui/surface.ts +224 -0
@@ -0,0 +1,78 @@
1
+ export class DirectoryManager<TDirectoryRecord, TGitSummary> {
2
+ private readonly directoriesById = new Map<string, TDirectoryRecord>();
3
+ private readonly gitSummaryByDirectoryId = new Map<string, TGitSummary>();
4
+
5
+ constructor() {}
6
+
7
+ readonlyDirectories(): ReadonlyMap<string, TDirectoryRecord> {
8
+ return this.directoriesById;
9
+ }
10
+
11
+ readonlyGitSummaries(): ReadonlyMap<string, TGitSummary> {
12
+ return this.gitSummaryByDirectoryId;
13
+ }
14
+
15
+ mutableGitSummaries(): Map<string, TGitSummary> {
16
+ return this.gitSummaryByDirectoryId;
17
+ }
18
+
19
+ hasDirectory(directoryId: string): boolean {
20
+ return this.directoriesById.has(directoryId);
21
+ }
22
+
23
+ getDirectory(directoryId: string): TDirectoryRecord | undefined {
24
+ return this.directoriesById.get(directoryId);
25
+ }
26
+
27
+ setDirectory(directoryId: string, directory: TDirectoryRecord): void {
28
+ this.directoriesById.set(directoryId, directory);
29
+ }
30
+
31
+ deleteDirectory(directoryId: string): void {
32
+ this.directoriesById.delete(directoryId);
33
+ }
34
+
35
+ clearDirectories(): void {
36
+ this.directoriesById.clear();
37
+ }
38
+
39
+ directoryIds(): readonly string[] {
40
+ return [...this.directoriesById.keys()];
41
+ }
42
+
43
+ directoriesSize(): number {
44
+ return this.directoriesById.size;
45
+ }
46
+
47
+ firstDirectoryId(): string | null {
48
+ const iterator = this.directoriesById.keys().next();
49
+ if (iterator.done === true) {
50
+ return null;
51
+ }
52
+ return iterator.value;
53
+ }
54
+
55
+ resolveActiveDirectoryId(activeDirectoryId: string | null): string | null {
56
+ if (activeDirectoryId !== null && this.directoriesById.has(activeDirectoryId)) {
57
+ return activeDirectoryId;
58
+ }
59
+ return this.firstDirectoryId();
60
+ }
61
+
62
+ ensureGitSummary(directoryId: string, loadingSummary: TGitSummary): void {
63
+ if (!this.gitSummaryByDirectoryId.has(directoryId)) {
64
+ this.gitSummaryByDirectoryId.set(directoryId, loadingSummary);
65
+ }
66
+ }
67
+
68
+ syncGitSummariesWithDirectories(loadingSummary: TGitSummary): void {
69
+ for (const directoryId of this.directoriesById.keys()) {
70
+ this.ensureGitSummary(directoryId, loadingSummary);
71
+ }
72
+ for (const directoryId of this.gitSummaryByDirectoryId.keys()) {
73
+ if (!this.directoriesById.has(directoryId)) {
74
+ this.gitSummaryByDirectoryId.delete(directoryId);
75
+ }
76
+ }
77
+ }
78
+ }
@@ -0,0 +1,123 @@
1
+ export class RepositoryManager<TRepositoryRecord, TRepositorySnapshot> {
2
+ private readonly repositories = new Map<string, TRepositoryRecord>();
3
+ private readonly repositoryAssociationByDirectoryId = new Map<string, string>();
4
+ private readonly directoryRepositorySnapshotByDirectoryId = new Map<
5
+ string,
6
+ TRepositorySnapshot
7
+ >();
8
+ private readonly collapsedRepositoryGroupIds = new Set<string>();
9
+ private readonly expandedRepositoryGroupIds = new Set<string>();
10
+
11
+ constructor() {}
12
+
13
+ mutableRepositories(): Map<string, TRepositoryRecord> {
14
+ return this.repositories;
15
+ }
16
+
17
+ readonlyRepositories(): ReadonlyMap<string, TRepositoryRecord> {
18
+ return this.repositories;
19
+ }
20
+
21
+ mutableDirectoryAssociations(): Map<string, string> {
22
+ return this.repositoryAssociationByDirectoryId;
23
+ }
24
+
25
+ readonlyDirectoryAssociations(): ReadonlyMap<string, string> {
26
+ return this.repositoryAssociationByDirectoryId;
27
+ }
28
+
29
+ mutableDirectorySnapshots(): Map<string, TRepositorySnapshot> {
30
+ return this.directoryRepositorySnapshotByDirectoryId;
31
+ }
32
+
33
+ readonlyDirectorySnapshots(): ReadonlyMap<string, TRepositorySnapshot> {
34
+ return this.directoryRepositorySnapshotByDirectoryId;
35
+ }
36
+
37
+ readonlyCollapsedRepositoryGroupIds(): ReadonlySet<string> {
38
+ return this.collapsedRepositoryGroupIds;
39
+ }
40
+
41
+ clearRepositories(): void {
42
+ this.repositories.clear();
43
+ }
44
+
45
+ private isRepositoryGroupCollapsed(
46
+ repositoryGroupId: string,
47
+ repositoriesCollapsed: boolean,
48
+ ): boolean {
49
+ if (repositoriesCollapsed) {
50
+ return !this.expandedRepositoryGroupIds.has(repositoryGroupId);
51
+ }
52
+ return this.collapsedRepositoryGroupIds.has(repositoryGroupId);
53
+ }
54
+
55
+ collapseRepositoryGroup(repositoryGroupId: string, repositoriesCollapsed: boolean): void {
56
+ if (repositoriesCollapsed) {
57
+ this.expandedRepositoryGroupIds.delete(repositoryGroupId);
58
+ return;
59
+ }
60
+ this.collapsedRepositoryGroupIds.add(repositoryGroupId);
61
+ }
62
+
63
+ expandRepositoryGroup(repositoryGroupId: string, repositoriesCollapsed: boolean): void {
64
+ if (repositoriesCollapsed) {
65
+ this.expandedRepositoryGroupIds.add(repositoryGroupId);
66
+ return;
67
+ }
68
+ this.collapsedRepositoryGroupIds.delete(repositoryGroupId);
69
+ }
70
+
71
+ toggleRepositoryGroup(repositoryGroupId: string, repositoriesCollapsed: boolean): void {
72
+ if (this.isRepositoryGroupCollapsed(repositoryGroupId, repositoriesCollapsed)) {
73
+ this.expandRepositoryGroup(repositoryGroupId, repositoriesCollapsed);
74
+ return;
75
+ }
76
+ this.collapseRepositoryGroup(repositoryGroupId, repositoriesCollapsed);
77
+ }
78
+
79
+ collapseAllRepositoryGroups(): true {
80
+ this.collapsedRepositoryGroupIds.clear();
81
+ this.expandedRepositoryGroupIds.clear();
82
+ return true;
83
+ }
84
+
85
+ expandAllRepositoryGroups(): false {
86
+ this.collapsedRepositoryGroupIds.clear();
87
+ this.expandedRepositoryGroupIds.clear();
88
+ return false;
89
+ }
90
+
91
+ repositoryGroupIdForDirectory(directoryId: string, fallbackGroupId: string): string {
92
+ return this.repositoryAssociationByDirectoryId.get(directoryId) ?? fallbackGroupId;
93
+ }
94
+
95
+ setDirectoryRepositorySnapshot(directoryId: string, snapshot: TRepositorySnapshot): void {
96
+ this.directoryRepositorySnapshotByDirectoryId.set(directoryId, snapshot);
97
+ }
98
+
99
+ setDirectoryRepositoryAssociation(directoryId: string, repositoryId: string | null): void {
100
+ if (repositoryId === null) {
101
+ this.repositoryAssociationByDirectoryId.delete(directoryId);
102
+ return;
103
+ }
104
+ this.repositoryAssociationByDirectoryId.set(directoryId, repositoryId);
105
+ }
106
+
107
+ setRepository(repositoryId: string, repository: TRepositoryRecord): void {
108
+ this.repositories.set(repositoryId, repository);
109
+ }
110
+
111
+ syncWithDirectories(directoriesHas: (directoryId: string) => boolean): void {
112
+ for (const directoryId of this.repositoryAssociationByDirectoryId.keys()) {
113
+ if (!directoriesHas(directoryId)) {
114
+ this.repositoryAssociationByDirectoryId.delete(directoryId);
115
+ }
116
+ }
117
+ for (const directoryId of this.directoryRepositorySnapshotByDirectoryId.keys()) {
118
+ if (!directoriesHas(directoryId)) {
119
+ this.directoryRepositorySnapshotByDirectoryId.delete(directoryId);
120
+ }
121
+ }
122
+ }
123
+ }
@@ -0,0 +1,148 @@
1
+ export class TaskManager<
2
+ TTaskRecord extends { taskId: string },
3
+ TTaskComposerBuffer,
4
+ TTaskAutosaveTimer,
5
+ > {
6
+ private readonly tasksById = new Map<string, TTaskRecord>();
7
+ private readonly taskComposerByTaskId = new Map<string, TTaskComposerBuffer>();
8
+ private readonly taskAutosaveTimerByTaskId = new Map<string, TTaskAutosaveTimer>();
9
+
10
+ constructor() {}
11
+
12
+ readonlyTasks(): ReadonlyMap<string, TTaskRecord> {
13
+ return this.tasksById;
14
+ }
15
+
16
+ readonlyTaskComposers(): ReadonlyMap<string, TTaskComposerBuffer> {
17
+ return this.taskComposerByTaskId;
18
+ }
19
+
20
+ values(): IterableIterator<TTaskRecord> {
21
+ return this.tasksById.values();
22
+ }
23
+
24
+ getTask(taskId: string): TTaskRecord | undefined {
25
+ return this.tasksById.get(taskId);
26
+ }
27
+
28
+ hasTask(taskId: string): boolean {
29
+ return this.tasksById.has(taskId);
30
+ }
31
+
32
+ setTask(task: TTaskRecord): void {
33
+ this.tasksById.set(task.taskId, task);
34
+ }
35
+
36
+ deleteTask(taskId: string): boolean {
37
+ return this.tasksById.delete(taskId);
38
+ }
39
+
40
+ clearTasks(): void {
41
+ this.tasksById.clear();
42
+ }
43
+
44
+ getTaskComposer(taskId: string): TTaskComposerBuffer | undefined {
45
+ return this.taskComposerByTaskId.get(taskId);
46
+ }
47
+
48
+ setTaskComposer(taskId: string, buffer: TTaskComposerBuffer): void {
49
+ this.taskComposerByTaskId.set(taskId, buffer);
50
+ }
51
+
52
+ deleteTaskComposer(taskId: string): boolean {
53
+ return this.taskComposerByTaskId.delete(taskId);
54
+ }
55
+
56
+ clearTaskComposers(): void {
57
+ this.taskComposerByTaskId.clear();
58
+ }
59
+
60
+ autosaveTaskIds(): IterableIterator<string> {
61
+ return this.taskAutosaveTimerByTaskId.keys();
62
+ }
63
+
64
+ getTaskAutosaveTimer(taskId: string): TTaskAutosaveTimer | undefined {
65
+ return this.taskAutosaveTimerByTaskId.get(taskId);
66
+ }
67
+
68
+ setTaskAutosaveTimer(taskId: string, timer: TTaskAutosaveTimer): void {
69
+ this.taskAutosaveTimerByTaskId.set(taskId, timer);
70
+ }
71
+
72
+ deleteTaskAutosaveTimer(taskId: string): boolean {
73
+ return this.taskAutosaveTimerByTaskId.delete(taskId);
74
+ }
75
+
76
+ clearTaskAutosaveTimers(): void {
77
+ this.taskAutosaveTimerByTaskId.clear();
78
+ }
79
+
80
+ orderedTasks(
81
+ sortTasks: (tasks: readonly TTaskRecord[]) => readonly TTaskRecord[],
82
+ ): readonly TTaskRecord[] {
83
+ return sortTasks([...this.tasksById.values()]);
84
+ }
85
+
86
+ tasksForRepository(input: {
87
+ repositoryId: string | null;
88
+ sortTasks: (tasks: readonly TTaskRecord[]) => readonly TTaskRecord[];
89
+ taskRepositoryId: (task: TTaskRecord) => string | null;
90
+ }): readonly TTaskRecord[] {
91
+ if (input.repositoryId === null) {
92
+ return [];
93
+ }
94
+ return this.orderedTasks(input.sortTasks).filter(
95
+ (task) => input.taskRepositoryId(task) === input.repositoryId,
96
+ );
97
+ }
98
+
99
+ taskReorderPayloadIds(input: {
100
+ orderedActiveTaskIds: readonly string[];
101
+ sortTasks: (tasks: readonly TTaskRecord[]) => readonly TTaskRecord[];
102
+ isCompleted: (task: TTaskRecord) => boolean;
103
+ }): readonly string[] {
104
+ const completedTaskIds = this.orderedTasks(input.sortTasks)
105
+ .filter(input.isCompleted)
106
+ .map((task) => task.taskId);
107
+ return [...input.orderedActiveTaskIds, ...completedTaskIds];
108
+ }
109
+
110
+ reorderedActiveTaskIdsForDrop(input: {
111
+ draggedTaskId: string;
112
+ targetTaskId: string;
113
+ sortTasks: (tasks: readonly TTaskRecord[]) => readonly TTaskRecord[];
114
+ isCompleted: (task: TTaskRecord) => boolean;
115
+ }): readonly string[] | 'cannot-reorder-completed' | null {
116
+ const draggedTask = this.tasksById.get(input.draggedTaskId);
117
+ const targetTask = this.tasksById.get(input.targetTaskId);
118
+ if (draggedTask === undefined || targetTask === undefined) {
119
+ return null;
120
+ }
121
+ if (input.isCompleted(draggedTask) || input.isCompleted(targetTask)) {
122
+ return 'cannot-reorder-completed';
123
+ }
124
+ const orderedActiveTaskIds = this.orderedTasks(input.sortTasks)
125
+ .filter((task) => !input.isCompleted(task))
126
+ .map((task) => task.taskId);
127
+ return this.reorderIdsByMove(orderedActiveTaskIds, input.draggedTaskId, input.targetTaskId);
128
+ }
129
+
130
+ private reorderIdsByMove(
131
+ orderedIds: readonly string[],
132
+ movedId: string,
133
+ targetId: string,
134
+ ): readonly string[] | null {
135
+ const fromIndex = orderedIds.indexOf(movedId);
136
+ const targetIndex = orderedIds.indexOf(targetId);
137
+ if (fromIndex < 0 || targetIndex < 0 || fromIndex === targetIndex) {
138
+ return null;
139
+ }
140
+ const reordered = [...orderedIds];
141
+ const [moved] = reordered.splice(fromIndex, 1);
142
+ if (moved === undefined) {
143
+ return null;
144
+ }
145
+ reordered.splice(targetIndex, 0, moved);
146
+ return reordered;
147
+ }
148
+ }
@@ -0,0 +1,156 @@
1
+ import type { ProjectPaneSnapshot } from '../mux/harness-core-ui.ts';
2
+ import type { CommandMenuState } from '../mux/live-mux/command-menu.ts';
3
+ import type { LeftNavSelection } from '../mux/live-mux/left-nav.ts';
4
+ import type { PaneSelection, PaneSelectionDrag } from '../mux/live-mux/selection.ts';
5
+ import type { createNewThreadPromptState } from '../mux/new-thread-prompt.ts';
6
+ import type { TaskComposerBuffer } from '../mux/task-composer.ts';
7
+ import type { TaskFocusedPaneView } from '../mux/task-focused-pane.ts';
8
+ import type { buildWorkspaceRailViewRows } from '../mux/workspace-rail-model.ts';
9
+
10
+ type MainPaneMode = 'conversation' | 'project' | 'home';
11
+
12
+ export interface ConversationTitleEditState {
13
+ conversationId: string;
14
+ value: string;
15
+ lastSavedValue: string;
16
+ error: string | null;
17
+ persistInFlight: boolean;
18
+ debounceTimer: NodeJS.Timeout | null;
19
+ }
20
+
21
+ export interface RepositoryPromptState {
22
+ readonly mode: 'add' | 'edit';
23
+ readonly repositoryId: string | null;
24
+ readonly value: string;
25
+ readonly error: string | null;
26
+ }
27
+
28
+ export interface TaskEditorPromptState {
29
+ mode: 'create' | 'edit';
30
+ taskId: string | null;
31
+ title: string;
32
+ description: string;
33
+ repositoryIds: readonly string[];
34
+ repositoryIndex: number;
35
+ fieldIndex: 0 | 1 | 2;
36
+ error: string | null;
37
+ }
38
+
39
+ interface HomePaneDragState {
40
+ readonly kind: 'task' | 'repository';
41
+ readonly itemId: string;
42
+ readonly startedRowIndex: number;
43
+ readonly latestRowIndex: number;
44
+ readonly hasDragged: boolean;
45
+ }
46
+
47
+ type TaskEditorTarget = { kind: 'draft' } | { kind: 'task'; taskId: string };
48
+
49
+ interface WorkspaceModelInit {
50
+ activeDirectoryId: string | null;
51
+ leftNavSelection: LeftNavSelection;
52
+ latestTaskPaneView: TaskFocusedPaneView;
53
+ taskDraftComposer: TaskComposerBuffer;
54
+ repositoriesCollapsed: boolean;
55
+ shortcutsCollapsed: boolean;
56
+ }
57
+
58
+ export class WorkspaceModel {
59
+ activeDirectoryId: string | null;
60
+ mainPaneMode: MainPaneMode = 'conversation';
61
+ leftNavSelection: LeftNavSelection;
62
+ activeRepositorySelectionId: string | null = null;
63
+ repositoryToggleChordPrefixAtMs: number | null = null;
64
+ projectPaneSnapshot: ProjectPaneSnapshot | null = null;
65
+ projectPaneScrollTop = 0;
66
+ taskPaneScrollTop = 0;
67
+ latestTaskPaneView: TaskFocusedPaneView;
68
+ taskPaneSelectedTaskId: string | null = null;
69
+ taskPaneSelectedRepositoryId: string | null = null;
70
+ taskRepositoryDropdownOpen = false;
71
+ taskEditorTarget: TaskEditorTarget = { kind: 'draft' };
72
+ taskDraftComposer: TaskComposerBuffer;
73
+ taskPaneSelectionFocus: 'task' | 'repository' = 'task';
74
+ taskPaneNotice: string | null = null;
75
+ taskPaneTaskEditClickState: { entityId: string; atMs: number } | null = null;
76
+ taskPaneRepositoryEditClickState: { entityId: string; atMs: number } | null = null;
77
+ homePaneDragState: HomePaneDragState | null = null;
78
+
79
+ selection: PaneSelection | null = null;
80
+ selectionDrag: PaneSelectionDrag | null = null;
81
+ selectionPinnedFollowOutput: boolean | null = null;
82
+ repositoryPrompt: RepositoryPromptState | null = null;
83
+ commandMenu: CommandMenuState | null = null;
84
+ newThreadPrompt: ReturnType<typeof createNewThreadPromptState> | null = null;
85
+ addDirectoryPrompt: { value: string; error: string | null } | null = null;
86
+ taskEditorPrompt: TaskEditorPromptState | null = null;
87
+ conversationTitleEdit: ConversationTitleEditState | null = null;
88
+ conversationTitleEditClickState: { conversationId: string; atMs: number } | null = null;
89
+ paneDividerDragActive = false;
90
+ previousSelectionRows: readonly number[] = [];
91
+ latestRailViewRows: ReturnType<typeof buildWorkspaceRailViewRows> = [];
92
+
93
+ repositoriesCollapsed: boolean;
94
+ shortcutsCollapsed: boolean;
95
+
96
+ constructor(init: WorkspaceModelInit) {
97
+ this.activeDirectoryId = init.activeDirectoryId;
98
+ this.leftNavSelection = init.leftNavSelection;
99
+ this.latestTaskPaneView = init.latestTaskPaneView;
100
+ this.taskDraftComposer = init.taskDraftComposer;
101
+ this.repositoriesCollapsed = init.repositoriesCollapsed;
102
+ this.shortcutsCollapsed = init.shortcutsCollapsed;
103
+ }
104
+
105
+ selectLeftNavHome(): void {
106
+ this.leftNavSelection = {
107
+ kind: 'home',
108
+ };
109
+ }
110
+
111
+ selectLeftNavRepository(repositoryGroupId: string): void {
112
+ this.activeRepositorySelectionId = repositoryGroupId;
113
+ this.leftNavSelection = {
114
+ kind: 'repository',
115
+ repositoryId: repositoryGroupId,
116
+ };
117
+ }
118
+
119
+ selectLeftNavProject(directoryId: string, repositoryGroupId: string): void {
120
+ this.activeRepositorySelectionId = repositoryGroupId;
121
+ this.leftNavSelection = {
122
+ kind: 'project',
123
+ directoryId,
124
+ };
125
+ }
126
+
127
+ selectLeftNavConversation(sessionId: string): void {
128
+ this.leftNavSelection = {
129
+ kind: 'conversation',
130
+ sessionId,
131
+ };
132
+ }
133
+
134
+ enterProjectPane(directoryId: string, repositoryGroupId: string): void {
135
+ this.activeDirectoryId = directoryId;
136
+ this.selectLeftNavProject(directoryId, repositoryGroupId);
137
+ this.mainPaneMode = 'project';
138
+ this.homePaneDragState = null;
139
+ this.taskPaneTaskEditClickState = null;
140
+ this.taskPaneRepositoryEditClickState = null;
141
+ this.projectPaneScrollTop = 0;
142
+ }
143
+
144
+ enterHomePane(): void {
145
+ this.mainPaneMode = 'home';
146
+ this.selectLeftNavHome();
147
+ this.projectPaneSnapshot = null;
148
+ this.projectPaneScrollTop = 0;
149
+ this.taskPaneScrollTop = 0;
150
+ this.taskPaneNotice = null;
151
+ this.taskRepositoryDropdownOpen = false;
152
+ this.taskPaneTaskEditClickState = null;
153
+ this.taskPaneRepositoryEditClickState = null;
154
+ this.homePaneDragState = null;
155
+ }
156
+ }
@@ -0,0 +1,124 @@
1
+ import { randomUUID } from 'node:crypto';
2
+
3
+ type EventSource = 'provider' | 'meta';
4
+
5
+ type ProviderEventType =
6
+ | 'provider-thread-started'
7
+ | 'provider-turn-started'
8
+ | 'provider-turn-completed'
9
+ | 'provider-turn-failed'
10
+ | 'provider-turn-interrupted'
11
+ | 'provider-diff-updated'
12
+ | 'provider-text-delta'
13
+ | 'provider-tool-call-started'
14
+ | 'provider-tool-call-completed';
15
+
16
+ type MetaEventType =
17
+ | 'meta-attention-raised'
18
+ | 'meta-attention-cleared'
19
+ | 'meta-queue-updated'
20
+ | 'meta-conversation-handoff';
21
+
22
+ type EventType = ProviderEventType | MetaEventType;
23
+
24
+ export interface EventScope {
25
+ tenantId: string;
26
+ userId: string;
27
+ workspaceId: string;
28
+ worktreeId: string;
29
+ conversationId: string;
30
+ turnId?: string;
31
+ }
32
+
33
+ interface BaseEventPayload {
34
+ kind: string;
35
+ }
36
+
37
+ interface ThreadEventPayload extends BaseEventPayload {
38
+ kind: 'thread';
39
+ threadId: string;
40
+ }
41
+
42
+ interface TurnEventPayload extends BaseEventPayload {
43
+ kind: 'turn';
44
+ threadId: string;
45
+ turnId: string;
46
+ status: 'in-progress' | 'completed' | 'failed' | 'interrupted';
47
+ }
48
+
49
+ interface TextDeltaPayload extends BaseEventPayload {
50
+ kind: 'text-delta';
51
+ threadId: string;
52
+ turnId: string;
53
+ delta: string;
54
+ }
55
+
56
+ interface DiffUpdatedPayload extends BaseEventPayload {
57
+ kind: 'diff-updated';
58
+ threadId: string;
59
+ turnId: string;
60
+ summary: string;
61
+ }
62
+
63
+ interface ToolPayload extends BaseEventPayload {
64
+ kind: 'tool';
65
+ threadId: string;
66
+ turnId: string;
67
+ toolName: string;
68
+ }
69
+
70
+ interface AttentionPayload extends BaseEventPayload {
71
+ kind: 'attention';
72
+ threadId: string;
73
+ turnId: string;
74
+ reason: 'approval' | 'user-input' | 'stalled';
75
+ detail: string;
76
+ }
77
+
78
+ interface QueuePayload extends BaseEventPayload {
79
+ kind: 'queue';
80
+ queueSize: number;
81
+ }
82
+
83
+ type EventPayload =
84
+ | AttentionPayload
85
+ | DiffUpdatedPayload
86
+ | QueuePayload
87
+ | TextDeltaPayload
88
+ | ThreadEventPayload
89
+ | ToolPayload
90
+ | TurnEventPayload;
91
+
92
+ export interface NormalizedEventEnvelope {
93
+ schemaVersion: '1';
94
+ eventId: string;
95
+ source: EventSource;
96
+ type: EventType;
97
+ ts: string;
98
+ scope: EventScope;
99
+ payload: EventPayload;
100
+ }
101
+
102
+ function nowIsoString(clock?: () => Date): string {
103
+ const value = clock?.() ?? new Date();
104
+ return value.toISOString();
105
+ }
106
+
107
+ export function createNormalizedEvent(
108
+ source: EventSource,
109
+ type: EventType,
110
+ scope: EventScope,
111
+ payload: EventPayload,
112
+ clock?: () => Date,
113
+ idFactory?: () => string,
114
+ ): NormalizedEventEnvelope {
115
+ return {
116
+ schemaVersion: '1',
117
+ eventId: idFactory?.() ?? randomUUID(),
118
+ source,
119
+ type,
120
+ ts: nowIsoString(clock),
121
+ scope,
122
+ payload,
123
+ };
124
+ }