@wrongstack/webui-server 0.284.0 → 0.285.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 (174) hide show
  1. package/dist/index.d.ts +11 -2300
  2. package/dist/index.d.ts.map +1 -0
  3. package/dist/index.js +1019 -277
  4. package/dist/index.js.map +7 -1
  5. package/dist/server/autophase-routes.d.ts +10 -0
  6. package/dist/server/autophase-routes.d.ts.map +1 -0
  7. package/dist/server/autophase-ws-handler.d.ts +87 -0
  8. package/dist/server/autophase-ws-handler.d.ts.map +1 -0
  9. package/dist/server/backend-services.d.ts +114 -0
  10. package/dist/server/backend-services.d.ts.map +1 -0
  11. package/dist/server/boot.d.ts +19 -0
  12. package/dist/server/boot.d.ts.map +1 -0
  13. package/dist/server/brain-routes.d.ts +9 -0
  14. package/dist/server/brain-routes.d.ts.map +1 -0
  15. package/dist/server/codebase-indexing.d.ts +15 -0
  16. package/dist/server/codebase-indexing.d.ts.map +1 -0
  17. package/dist/server/collaboration-ws-handler.d.ts +159 -0
  18. package/dist/server/collaboration-ws-handler.d.ts.map +1 -0
  19. package/dist/server/completion-handlers.d.ts +39 -0
  20. package/dist/server/completion-handlers.d.ts.map +1 -0
  21. package/dist/server/connection-handler.d.ts +72 -0
  22. package/dist/server/connection-handler.d.ts.map +1 -0
  23. package/dist/server/context-meta.d.ts +28 -0
  24. package/dist/server/context-meta.d.ts.map +1 -0
  25. package/dist/server/custom-context-modes.d.ts +43 -0
  26. package/dist/server/custom-context-modes.d.ts.map +1 -0
  27. package/dist/server/design-handlers.d.ts +40 -0
  28. package/dist/server/design-handlers.d.ts.map +1 -0
  29. package/dist/server/discover-mailbox-bridge.d.ts +26 -0
  30. package/dist/server/discover-mailbox-bridge.d.ts.map +1 -0
  31. package/dist/server/entry.d.ts +2 -2
  32. package/dist/server/entry.d.ts.map +1 -0
  33. package/dist/server/entry.js +811 -300
  34. package/dist/server/entry.js.map +7 -1
  35. package/dist/server/eternal-iteration-broadcast.d.ts +11 -0
  36. package/dist/server/eternal-iteration-broadcast.d.ts.map +1 -0
  37. package/dist/server/file-handlers.d.ts +45 -0
  38. package/dist/server/file-handlers.d.ts.map +1 -0
  39. package/dist/server/file-picker.d.ts +26 -0
  40. package/dist/server/file-picker.d.ts.map +1 -0
  41. package/dist/server/git-handlers.d.ts +55 -0
  42. package/dist/server/git-handlers.d.ts.map +1 -0
  43. package/dist/server/goal-handlers.d.ts +19 -0
  44. package/dist/server/goal-handlers.d.ts.map +1 -0
  45. package/dist/server/handlers/index.d.ts +12 -0
  46. package/dist/server/handlers/index.d.ts.map +1 -0
  47. package/dist/server/handlers/worklist-handlers.d.ts +49 -0
  48. package/dist/server/handlers/worklist-handlers.d.ts.map +1 -0
  49. package/dist/server/handlers.d.ts +1 -51
  50. package/dist/server/handlers.js +17 -8
  51. package/dist/server/handlers.js.map +7 -1
  52. package/dist/server/http-server/analytics-handler.d.ts +35 -0
  53. package/dist/server/http-server/analytics-handler.d.ts.map +1 -0
  54. package/dist/server/http-server/api-handlers.d.ts +44 -0
  55. package/dist/server/http-server/api-handlers.d.ts.map +1 -0
  56. package/dist/server/http-server.d.ts +108 -0
  57. package/dist/server/http-server.d.ts.map +1 -0
  58. package/dist/server/index.d.ts +93 -0
  59. package/dist/server/index.d.ts.map +1 -0
  60. package/dist/server/instance-registry.d.ts +63 -0
  61. package/dist/server/instance-registry.d.ts.map +1 -0
  62. package/dist/server/kanban-routes.d.ts +7 -0
  63. package/dist/server/kanban-routes.d.ts.map +1 -0
  64. package/dist/server/lifecycle.d.ts +51 -0
  65. package/dist/server/lifecycle.d.ts.map +1 -0
  66. package/dist/server/mailbox-handlers.d.ts +51 -0
  67. package/dist/server/mailbox-handlers.d.ts.map +1 -0
  68. package/dist/server/mailbox-routes.d.ts +10 -0
  69. package/dist/server/mailbox-routes.d.ts.map +1 -0
  70. package/dist/server/mcp-handlers.d.ts +46 -0
  71. package/dist/server/mcp-handlers.d.ts.map +1 -0
  72. package/dist/server/mcp-routes.d.ts +37 -0
  73. package/dist/server/mcp-routes.d.ts.map +1 -0
  74. package/dist/server/memory-handlers.d.ts +28 -0
  75. package/dist/server/memory-handlers.d.ts.map +1 -0
  76. package/dist/server/message-dispatcher.d.ts +41 -0
  77. package/dist/server/message-dispatcher.d.ts.map +1 -0
  78. package/dist/server/mode-handlers.d.ts +50 -0
  79. package/dist/server/mode-handlers.d.ts.map +1 -0
  80. package/dist/server/mode-routes.d.ts +8 -0
  81. package/dist/server/mode-routes.d.ts.map +1 -0
  82. package/dist/server/model-auto-discovery.d.ts +9 -0
  83. package/dist/server/model-auto-discovery.d.ts.map +1 -0
  84. package/dist/server/model-catalog.d.ts +16 -0
  85. package/dist/server/model-catalog.d.ts.map +1 -0
  86. package/dist/server/open-browser.d.ts +16 -0
  87. package/dist/server/open-browser.d.ts.map +1 -0
  88. package/dist/server/path-containment.d.ts +3 -0
  89. package/dist/server/path-containment.d.ts.map +1 -0
  90. package/dist/server/pending-confirms.d.ts +14 -0
  91. package/dist/server/pending-confirms.d.ts.map +1 -0
  92. package/dist/server/port-utils.d.ts +28 -0
  93. package/dist/server/port-utils.d.ts.map +1 -0
  94. package/dist/server/pre-context-services.d.ts +58 -0
  95. package/dist/server/pre-context-services.d.ts.map +1 -0
  96. package/dist/server/pref-helpers.d.ts +43 -0
  97. package/dist/server/pref-helpers.d.ts.map +1 -0
  98. package/dist/server/prefs-routes.d.ts +27 -0
  99. package/dist/server/prefs-routes.d.ts.map +1 -0
  100. package/dist/server/process-handlers.d.ts +20 -0
  101. package/dist/server/process-handlers.d.ts.map +1 -0
  102. package/dist/server/project-handlers.d.ts +53 -0
  103. package/dist/server/project-handlers.d.ts.map +1 -0
  104. package/dist/server/project-routes.d.ts +10 -0
  105. package/dist/server/project-routes.d.ts.map +1 -0
  106. package/dist/server/projects-manifest.d.ts +18 -0
  107. package/dist/server/projects-manifest.d.ts.map +1 -0
  108. package/dist/server/prompts-handlers.d.ts +38 -0
  109. package/dist/server/prompts-handlers.d.ts.map +1 -0
  110. package/dist/server/provider-config-io.d.ts +15 -0
  111. package/dist/server/provider-config-io.d.ts.map +1 -0
  112. package/dist/server/provider-config-standalone.d.ts +13 -0
  113. package/dist/server/provider-config-standalone.d.ts.map +1 -0
  114. package/dist/server/provider-handlers.d.ts +74 -0
  115. package/dist/server/provider-handlers.d.ts.map +1 -0
  116. package/dist/server/provider-keys.d.ts +53 -0
  117. package/dist/server/provider-keys.d.ts.map +1 -0
  118. package/dist/server/provider-routes.d.ts +13 -0
  119. package/dist/server/provider-routes.d.ts.map +1 -0
  120. package/dist/server/provider-store.d.ts +26 -0
  121. package/dist/server/provider-store.d.ts.map +1 -0
  122. package/dist/server/routes.d.ts +182 -0
  123. package/dist/server/routes.d.ts.map +1 -0
  124. package/dist/server/sdd-board-routes.d.ts +11 -0
  125. package/dist/server/sdd-board-routes.d.ts.map +1 -0
  126. package/dist/server/sdd-board-ws-handler.d.ts +57 -0
  127. package/dist/server/sdd-board-ws-handler.d.ts.map +1 -0
  128. package/dist/server/sdd-wizard-routes.d.ts +16 -0
  129. package/dist/server/sdd-wizard-routes.d.ts.map +1 -0
  130. package/dist/server/sdd-wizard-wiring.d.ts +26 -0
  131. package/dist/server/sdd-wizard-wiring.d.ts.map +1 -0
  132. package/dist/server/sdd-wizard-ws-handler.d.ts +66 -0
  133. package/dist/server/sdd-wizard-ws-handler.d.ts.map +1 -0
  134. package/dist/server/server-runtime.d.ts +118 -0
  135. package/dist/server/server-runtime.d.ts.map +1 -0
  136. package/dist/server/session-handlers.d.ts +44 -0
  137. package/dist/server/session-handlers.d.ts.map +1 -0
  138. package/dist/server/session-routes.d.ts +23 -0
  139. package/dist/server/session-routes.d.ts.map +1 -0
  140. package/dist/server/setup-events.d.ts +67 -0
  141. package/dist/server/setup-events.d.ts.map +1 -0
  142. package/dist/server/setup-screen.d.ts +44 -0
  143. package/dist/server/setup-screen.d.ts.map +1 -0
  144. package/dist/server/shell-git-routes.d.ts +10 -0
  145. package/dist/server/shell-git-routes.d.ts.map +1 -0
  146. package/dist/server/shell-open.d.ts +12 -0
  147. package/dist/server/shell-open.d.ts.map +1 -0
  148. package/dist/server/skills-handlers.d.ts +77 -0
  149. package/dist/server/skills-handlers.d.ts.map +1 -0
  150. package/dist/server/specs-routes.d.ts +11 -0
  151. package/dist/server/specs-routes.d.ts.map +1 -0
  152. package/dist/server/specs-ws-handler.d.ts +34 -0
  153. package/dist/server/specs-ws-handler.d.ts.map +1 -0
  154. package/dist/server/start-webui.d.ts +29 -0
  155. package/dist/server/start-webui.d.ts.map +1 -0
  156. package/dist/server/terminal-ws-handler.d.ts +70 -0
  157. package/dist/server/terminal-ws-handler.d.ts.map +1 -0
  158. package/dist/server/token-estimator.d.ts +66 -0
  159. package/dist/server/token-estimator.d.ts.map +1 -0
  160. package/dist/server/types.d.ts +143 -0
  161. package/dist/server/types.d.ts.map +1 -0
  162. package/dist/server/usage-cost.d.ts +39 -0
  163. package/dist/server/usage-cost.d.ts.map +1 -0
  164. package/dist/server/worktree-ws-handler.d.ts +67 -0
  165. package/dist/server/worktree-ws-handler.d.ts.map +1 -0
  166. package/dist/server/ws-auth.d.ts +83 -0
  167. package/dist/server/ws-auth.d.ts.map +1 -0
  168. package/dist/server/ws-payload-validation.d.ts +122 -0
  169. package/dist/server/ws-payload-validation.d.ts.map +1 -0
  170. package/dist/server/ws-utils.d.ts +38 -0
  171. package/dist/server/ws-utils.d.ts.map +1 -0
  172. package/dist/server/zip.d.ts +9 -0
  173. package/dist/server/zip.d.ts.map +1 -0
  174. package/package.json +11 -12
@@ -0,0 +1,10 @@
1
+ import type { WebSocket } from 'ws';
2
+ import type { WSClientMessage } from './types.js';
3
+ export interface AutoPhaseRouteHandlers {
4
+ handleMessage: (msg: {
5
+ type: string;
6
+ payload?: Record<string, unknown>;
7
+ }) => Promise<void>;
8
+ }
9
+ export declare function handleAutoPhaseRoute(_ws: WebSocket, msg: WSClientMessage, handlers: AutoPhaseRouteHandlers): Promise<boolean>;
10
+ //# sourceMappingURL=autophase-routes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"autophase-routes.d.ts","sourceRoot":"","sources":["../../src/server/autophase-routes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AACpC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,MAAM,WAAW,sBAAsB;IACrC,aAAa,EAAE,CAAC,GAAG,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5F;AAED,wBAAsB,oBAAoB,CACxC,GAAG,EAAE,SAAS,EACd,GAAG,EAAE,eAAe,EACpB,QAAQ,EAAE,sBAAsB,GAC/B,OAAO,CAAC,OAAO,CAAC,CAIlB"}
@@ -0,0 +1,87 @@
1
+ import type { WebSocket } from 'ws';
2
+ import type { Agent, Context, EventBus, Logger } from '@wrongstack/core';
3
+ interface AutoPhaseWSMessage {
4
+ type: string;
5
+ payload?: Record<string, unknown>;
6
+ }
7
+ /**
8
+ * AutoPhaseWebSocketHandler — WebSocket-based AutoPhase control.
9
+ *
10
+ * Message types:
11
+ * autophase.start → { title, phases?, autonomous? }
12
+ * autophase.pause → {}
13
+ * autophase.resume → {}
14
+ * autophase.stop → {}
15
+ * autophase.status → {}
16
+ * autophase.selectPhase → { phaseId }
17
+ * autophase.taskStatus → { taskId, status }
18
+ */
19
+ export declare class AutoPhaseWebSocketHandler {
20
+ private agent;
21
+ private context;
22
+ private logger;
23
+ private events?;
24
+ private projectRoot?;
25
+ private orchestrator;
26
+ private graph;
27
+ private store;
28
+ private clients;
29
+ private broadcastInterval;
30
+ /** Aborts in-flight task agents AND the planning turn when the run is stopped. */
31
+ private abort;
32
+ /** Set the instant a stop/clear/revert is requested, so a planning turn that
33
+ * resolves afterwards never launches the orchestrator (the abort alone can't
34
+ * cover the window between the LLM call resolving and the orchestrator start). */
35
+ private stopping;
36
+ /** Optional per-phase git-worktree isolation (lazily created at start). */
37
+ private worktrees;
38
+ /** Base branch + tip SHA captured at run start so a revert can git-revert the
39
+ * run's squash commits (history-preserving) instead of a destructive reset. */
40
+ private runBase;
41
+ /** Per-run worker identities so the board can show "who is on what". */
42
+ private usedNicknames;
43
+ constructor(agent: Agent, context: Context, logger: Logger, storeDir: string, events?: EventBus | undefined, projectRoot?: string | undefined);
44
+ addClient(ws: WebSocket): void;
45
+ handleMessage(msg: AutoPhaseWSMessage): Promise<void>;
46
+ private handleStart;
47
+ /**
48
+ * Halt the run NOW — at any phase. Sets `stopping` (so a planning turn that
49
+ * resolves afterwards bails), aborts in-flight agents, stops the orchestrator
50
+ * tick, and ends the live broadcast. The board is kept for review; use
51
+ * `autophase.clear` to reset or `autophase.revert` to undo the changes.
52
+ */
53
+ private handleStop;
54
+ /**
55
+ * Stop + wipe: tear down phase worktrees and reset to an empty board so the UI
56
+ * returns to the start screen ("new one"). Does NOT touch already-merged commits
57
+ * on the base branch — that is `autophase.revert`.
58
+ */
59
+ private handleClear;
60
+ /**
61
+ * Stop + undo: remove phase worktrees, then history-preservingly `git revert`
62
+ * every commit this run landed on the base branch (captured `runBase`..HEAD),
63
+ * then reset to an empty board. Refuses (reports a reason) on a dirty tree or a
64
+ * conflicting revert rather than leaving the tree half-reverted.
65
+ */
66
+ private handleRevert;
67
+ /** Generic fallback phases when the LLM planner produces nothing usable. */
68
+ private defaultPhases;
69
+ /** Plan phases+todos for the goal via the LLM; fall back to defaults on failure.
70
+ * The caller passes the run's abort signal so a stop during planning cancels
71
+ * the LLM turn (the previous fresh, never-aborted controller made planning
72
+ * uninterruptible). */
73
+ private planPhases;
74
+ private executeTaskWithAgent;
75
+ /** Persist + broadcast after an interactive board mutation. */
76
+ private afterBoardMutation;
77
+ private handleTaskStatusChange;
78
+ private startBroadcast;
79
+ private stopBroadcast;
80
+ private broadcastState;
81
+ private buildState;
82
+ private sendState;
83
+ private broadcast;
84
+ private send;
85
+ }
86
+ export {};
87
+ //# sourceMappingURL=autophase-ws-handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"autophase-ws-handler.d.ts","sourceRoot":"","sources":["../../src/server/autophase-ws-handler.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAYpC,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAoDzE,UAAU,kBAAkB;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,yBAAyB;IAqBlC,OAAO,CAAC,KAAK;IACb,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,MAAM;IAEd,OAAO,CAAC,MAAM,CAAC;IACf,OAAO,CAAC,WAAW,CAAC;IAzBtB,OAAO,CAAC,YAAY,CAAkC;IACtD,OAAO,CAAC,KAAK,CAA2B;IACxC,OAAO,CAAC,KAAK,CAAa;IAC1B,OAAO,CAAC,OAAO,CAAuB;IACtC,OAAO,CAAC,iBAAiB,CAA+C;IACxE,kFAAkF;IAClF,OAAO,CAAC,KAAK,CAAgC;IAC7C;;uFAEmF;IACnF,OAAO,CAAC,QAAQ,CAAS;IACzB,2EAA2E;IAC3E,OAAO,CAAC,SAAS,CAAgC;IACjD;oFACgF;IAChF,OAAO,CAAC,OAAO,CAAgD;IAC/D,wEAAwE;IACxE,OAAO,CAAC,aAAa,CAAqB;IAE1C,YACU,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,EACtB,QAAQ,EAAE,MAAM,EACR,MAAM,CAAC,EAAE,QAAQ,GAAG,SAAS,EAC7B,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,EAGzC;IAED,SAAS,CAAC,EAAE,EAAE,SAAS,GAAG,IAAI,CAS7B;IAEK,aAAa,CAAC,GAAG,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAyG1D;YAEa,WAAW;IAwIzB;;;;;OAKG;YACW,UAAU;IASxB;;;;OAIG;YACW,WAAW;IAYzB;;;;;OAKG;YACW,YAAY;IAsB1B,4EAA4E;IAC5E,OAAO,CAAC,aAAa;IAUrB;;;4BAGwB;YACV,UAAU;YA2BV,oBAAoB;IA+BlC,+DAA+D;IAC/D,OAAO,CAAC,kBAAkB;YAKZ,sBAAsB;IAcpC,OAAO,CAAC,cAAc;IAStB,OAAO,CAAC,aAAa;IAOrB,OAAO,CAAC,cAAc;IAOtB,OAAO,CAAC,UAAU;IAqGlB,OAAO,CAAC,SAAS;IAMjB,OAAO,CAAC,SAAS;IASjB,OAAO,CAAC,IAAI;CAKb"}
@@ -0,0 +1,114 @@
1
+ /**
2
+ * Post-context backend service construction for the standalone WebUI server.
3
+ *
4
+ * Phase 1c of the god-module split (issue: God-modules >1500 lines).
5
+ * `startWebUI` previously inlined ~400 lines of construction that runs
6
+ * AFTER `context` exists: the agent pipelines + collab middleware, the
7
+ * strategy compactor + auto-compaction middleware, the tool executor +
8
+ * agent, the tiered Brain + monitor, and the per-feature WebSocket
9
+ * handlers (AutoPhase, specs, SDD board/wizard, worktree, terminal, collab).
10
+ *
11
+ * All of that moves into `createAgentServices()`. The pre-context
12
+ * registries/stores (modelsRegistry, container, toolRegistry, session,
13
+ * tokenCounter, …) stay in `startWebUI` because they are interleaved with
14
+ * the `opts.services?` injection contract the CLI's embedded server
15
+ * relies on; lifting them would restructure that contract, which is a
16
+ * separate, higher-risk task.
17
+ *
18
+ * The factory is pure construction — no behaviour change. It returns a
19
+ * typed `AgentServices` object plus the `updateAutoCompactionMaxContext`
20
+ * closure (which needs the live `context`, `autoCompactor`, and
21
+ * `modelCapabilitiesRef` it just built).
22
+ */
23
+ import type { AutoCompactionMiddleware, BrainAutoRisk, CollaborationBus, Compactor, Context, MemoryStore, DefaultModeStore, EventBus, Logger, ModelsRegistry, ObservableBrainArbiter, PermissionPolicy, Provider, ProviderRegistry, SessionStore, SkillInstaller, SkillLoader, ToolRegistry, AgentPipelines, Container, SessionReader } from '@wrongstack/core';
24
+ import type { DefaultTokenCounter } from '@wrongstack/core/infrastructure';
25
+ /** Session shape returned by `SessionStore.create()`. */
26
+ type Session = Awaited<ReturnType<SessionStore['create']>>;
27
+ import { Agent, BrainMonitor, ToolExecutor, type AnnotationsStore } from '@wrongstack/core';
28
+ import type { MCPRegistry } from '@wrongstack/mcp';
29
+ import { AutoPhaseWebSocketHandler } from './autophase-ws-handler.js';
30
+ import { CollaborationWebSocketHandler } from './collaboration-ws-handler.js';
31
+ import { SddBoardWebSocketHandler } from './sdd-board-ws-handler.js';
32
+ import { SddWizardWebSocketHandler } from './sdd-wizard-ws-handler.js';
33
+ import { SpecsWebSocketHandler } from './specs-ws-handler.js';
34
+ import { TerminalWebSocketHandler } from './terminal-ws-handler.js';
35
+ import { WorktreeWebSocketHandler } from './worktree-ws-handler.js';
36
+ import type { Config, ProviderConfig } from '@wrongstack/core/types';
37
+ import type { WstackPaths } from '@wrongstack/core/utils';
38
+ export interface AgentServicesInput {
39
+ config: Config;
40
+ wpaths: WstackPaths;
41
+ logger: Logger;
42
+ projectRoot: string;
43
+ workingDir: string;
44
+ /** Pre-context services (built in startWebUI with opts.services injection). */
45
+ context: Context;
46
+ provider: Provider;
47
+ container: Container;
48
+ toolRegistry: ToolRegistry;
49
+ providerRegistry: ProviderRegistry;
50
+ modelsRegistry: ModelsRegistry;
51
+ events: EventBus;
52
+ mcpRegistry: MCPRegistry;
53
+ memoryStore: MemoryStore;
54
+ modeStore: DefaultModeStore;
55
+ customModeStore: import('./custom-context-modes.js').CustomModeStore;
56
+ skillLoader: SkillLoader | undefined;
57
+ skillInstaller: SkillInstaller | undefined;
58
+ tokenCounter: DefaultTokenCounter;
59
+ pipelines: AgentPipelines;
60
+ /** Mutable capabilities ref — the factory populates `.current`. */
61
+ modelCapabilitiesRef: {
62
+ current: unknown;
63
+ };
64
+ /** Returns the LIVE session (swapped on /new + resume) — read at send time. */
65
+ sessionGetter: () => Session;
66
+ /** Read-only session reader (collab replay-on-join). */
67
+ sessionReader: SessionReader;
68
+ /** Annotations store (collab notes). */
69
+ annotationsStore: AnnotationsStore;
70
+ }
71
+ export interface AgentServices {
72
+ collabBus: CollaborationBus;
73
+ compactor: Compactor;
74
+ autoCompactor: AutoCompactionMiddleware | undefined;
75
+ toolExecutor: ToolExecutor;
76
+ agent: Agent;
77
+ permissionPolicy: PermissionPolicy;
78
+ pipelines: AgentPipelines;
79
+ brain: ObservableBrainArbiter;
80
+ brainSettings: {
81
+ maxAutoRisk: BrainAutoRisk;
82
+ };
83
+ brainLog: Array<{
84
+ at: number;
85
+ kind: string;
86
+ question: string;
87
+ outcome: string;
88
+ }>;
89
+ brainMonitor: BrainMonitor;
90
+ codebaseIndexing: {
91
+ onFileWritten(filePath: string): void;
92
+ dispose(): void;
93
+ };
94
+ autoPhaseHandler: AutoPhaseWebSocketHandler;
95
+ specsHandler: SpecsWebSocketHandler;
96
+ sddBoardHandler: SddBoardWebSocketHandler;
97
+ sddWizardHandler: SddWizardWebSocketHandler;
98
+ worktreeHandler: WorktreeWebSocketHandler;
99
+ terminalHandler: TerminalWebSocketHandler;
100
+ collabHandler: CollaborationWebSocketHandler;
101
+ /** Refresh auto-compaction denominator on model switch. */
102
+ updateAutoCompactionMaxContext: (newProvider: Provider, providerId?: string, providerCfg?: ProviderConfig | undefined) => Promise<void>;
103
+ }
104
+ /**
105
+ * Build the post-context agent services: pipelines + middleware, compaction,
106
+ * tool executor + agent, Brain, and the per-feature WebSocket handlers.
107
+ *
108
+ * Returns everything `startWebUI` needs to wire routes + the dispatcher.
109
+ * The `updateAutoCompactionMaxContext` closure captures the live
110
+ * `autoCompactor` / `modelCapabilitiesRef` it built.
111
+ */
112
+ export declare function createAgentServices(input: AgentServicesInput): Promise<AgentServices>;
113
+ export {};
114
+ //# sourceMappingURL=backend-services.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"backend-services.d.ts","sourceRoot":"","sources":["../../src/server/backend-services.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,KAAK,EACV,wBAAwB,EAExB,aAAa,EACb,gBAAgB,EAChB,SAAS,EACT,OAAO,EACP,WAAW,EACX,gBAAgB,EAChB,QAAQ,EACR,MAAM,EACN,cAAc,EACd,sBAAsB,EACtB,gBAAgB,EAChB,QAAQ,EACR,gBAAgB,EAChB,YAAY,EACZ,cAAc,EACd,WAAW,EACX,YAAY,EACZ,cAAc,EACd,SAAS,EACT,aAAa,EACd,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAC3E,yDAAyD;AACzD,KAAK,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;AAC3D,OAAO,EACL,KAAK,EAEL,YAAY,EAiBZ,YAAY,EACZ,KAAK,gBAAgB,EACtB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,EAAE,6BAA6B,EAAE,MAAM,+BAA+B,CAAC;AAG9E,OAAO,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AACrE,OAAO,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AACvE,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AACpE,OAAO,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AASpE,OAAO,KAAK,EA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AAC;IACb,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,SAAS,EAAE,cAAc,CAAC;IAC1B,KAAK,EAAE,sBAAsB,CAAC;IAC9B,aAAa,EAAE;QAAE,WAAW,EAAE,aAAa,CAAA;KAAE,CAAC;IAC9C,QAAQ,EAAE,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACjF,YAAY,EAAE,YAAY,CAAC;IAC3B,gBAAgB,EAAE;QAAE,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,OAAO,IAAI,IAAI,CAAA;KAAE,CAAC;IAC7E,gBAAgB,EAAE,yBAAyB,CAAC;IAC5C,YAAY,EAAE,qBAAqB,CAAC;IACpC,eAAe,EAAE,wBAAwB,CAAC;IAC1C,gBAAgB,EAAE,yBAAyB,CAAC;IAC5C,eAAe,EAAE,wBAAwB,CAAC;IAC1C,eAAe,EAAE,wBAAwB,CAAC;IAC1C,aAAa,EAAE,6BAA6B,CAAC;IAC7C,2DAA2D;IAC3D,8BAA8B,EAAE,CAC9B,WAAW,EAAE,QAAQ,EACrB,UAAU,CAAC,EAAE,MAAM,EACnB,WAAW,CAAC,EAAE,cAAc,GAAG,SAAS,KACrC,OAAO,CAAC,IAAI,CAAC,CAAC;CACpB;AAED;;;;;;;GAOG;AACH,wBAAsB,mBAAmB,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,aAAa,CAAC,CAwX3F"}
@@ -0,0 +1,19 @@
1
+ import { type Config, type DefaultLogger, type DefaultSecretVault, type WstackPaths } from '@wrongstack/core';
2
+ export interface BootResult {
3
+ config: Config;
4
+ vault: DefaultSecretVault;
5
+ globalConfigPath: string;
6
+ projectRoot: string;
7
+ wpaths: WstackPaths;
8
+ logger: InstanceType<typeof DefaultLogger>;
9
+ }
10
+ /**
11
+ * Thin WebUI wrapper over the canonical `bootConfig` in `@wrongstack/core`
12
+ * (mirrors packages/cli/src/boot-config.ts). All real boot behavior — wstack
13
+ * path resolution, the AES-GCM `DefaultSecretVault`, plaintext-secret
14
+ * migration, and config load/merge — lives in core so the WebUI server and the
15
+ * CLI can't drift. Only the secret-migration notice label (`WebUI`) differs.
16
+ */
17
+ export declare function bootConfig(): Promise<BootResult>;
18
+ export declare function patchConfig(config: Config, updates: Partial<Config>): Config;
19
+ //# sourceMappingURL=boot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"boot.d.ts","sourceRoot":"","sources":["../../src/server/boot.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,MAAM,EACX,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACvB,KAAK,WAAW,EAEjB,MAAM,kBAAkB,CAAC;AAE1B,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,kBAAkB,CAAC;IAC1B,gBAAgB,EAAE,MAAM,CAAC;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,WAAW,CAAC;IACpB,MAAM,EAAE,YAAY,CAAC,OAAO,aAAa,CAAC,CAAC;CAC5C;AAED;;;;;;GAMG;AACH,wBAAsB,UAAU,IAAI,OAAO,CAAC,UAAU,CAAC,CAKtD;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,CAE5E"}
@@ -0,0 +1,9 @@
1
+ import type { WebSocket } from 'ws';
2
+ import type { WSClientMessage } from './types.js';
3
+ export interface BrainRouteHandlers {
4
+ status: (ws: WebSocket, msg: WSClientMessage) => Promise<void> | void;
5
+ risk: (ws: WebSocket, msg: WSClientMessage) => Promise<void> | void;
6
+ ask: (ws: WebSocket, msg: WSClientMessage) => Promise<void> | void;
7
+ }
8
+ export declare function handleBrainRoute(ws: WebSocket, msg: WSClientMessage, handlers: BrainRouteHandlers): Promise<boolean>;
9
+ //# sourceMappingURL=brain-routes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"brain-routes.d.ts","sourceRoot":"","sources":["../../src/server/brain-routes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AACpC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,CAAC,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,eAAe,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IACtE,IAAI,EAAE,CAAC,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,eAAe,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IACpE,GAAG,EAAE,CAAC,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,eAAe,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;CACpE;AAED,wBAAsB,gBAAgB,CACpC,EAAE,EAAE,SAAS,EACb,GAAG,EAAE,eAAe,EACpB,QAAQ,EAAE,kBAAkB,GAC3B,OAAO,CAAC,OAAO,CAAC,CAclB"}
@@ -0,0 +1,15 @@
1
+ import type { Context, IndexingConfig, Logger } from '@wrongstack/core';
2
+ export interface WebUICodebaseIndexingDeps {
3
+ config: {
4
+ indexing?: IndexingConfig | undefined;
5
+ };
6
+ context: Context;
7
+ projectRoot: string;
8
+ logger: Logger;
9
+ }
10
+ export interface WebUICodebaseIndexing {
11
+ onFileWritten(filePath: string): void;
12
+ dispose(): void;
13
+ }
14
+ export declare function setupWebUICodebaseIndexing(deps: WebUICodebaseIndexingDeps): WebUICodebaseIndexing;
15
+ //# sourceMappingURL=codebase-indexing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codebase-indexing.d.ts","sourceRoot":"","sources":["../../src/server/codebase-indexing.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAqBxE,MAAM,WAAW,yBAAyB;IACxC,MAAM,EAAE;QAAE,QAAQ,CAAC,EAAE,cAAc,GAAG,SAAS,CAAA;KAAE,CAAC;IAClD,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,qBAAqB;IACpC,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACtC,OAAO,IAAI,IAAI,CAAC;CACjB;AAED,wBAAgB,0BAA0B,CACxC,IAAI,EAAE,yBAAyB,GAC9B,qBAAqB,CAmFvB"}
@@ -0,0 +1,159 @@
1
+ import type { WebSocket } from 'ws';
2
+ import type { CollaborationBus, EventBus, Logger } from '@wrongstack/core';
3
+ import type { AnnotationsStore, SessionReader } from '@wrongstack/core/storage';
4
+ /**
5
+ * CollaborationWebSocketHandler — passive read-only session observer (Phase 1
6
+ * of idea #13 from IDEAS.md). Mirrors `WorktreeWebSocketHandler` and
7
+ * `AutoPhaseWebSocketHandler`.
8
+ *
9
+ * Capabilities in this phase:
10
+ * - A second human (or any client) joins an active agent run as an
11
+ * `observer` and receives a live mirror of the kernel's iteration /
12
+ * tool / subagent events.
13
+ * - The observer declares a `sessionId` on join (used for state scoping
14
+ * and future replay-on-join). Live event routing is session-agnostic
15
+ * for now — see the limitation note below.
16
+ * - The observer can leave at any time; cleanup runs on WS close/error.
17
+ * - The observer CANNOT modify the agent's state, pause it, or inject
18
+ * tool calls. Those capabilities land in Phase 2/3.
19
+ *
20
+ * Limitation (documented, acceptable for Phase 1):
21
+ * The webui server multiplexes every active session onto a single
22
+ * EventBus, and most event payloads (`tool.started`, `iteration.*`,
23
+ * `subagent.*`) do NOT carry a `sessionId` field. The webui's primary
24
+ * WS path works because it is the only consumer and assumes one
25
+ * active session at a time. We mirror that assumption here. When a
26
+ * future multi-session "session router" lands, this handler will be
27
+ * upgraded to filter by sessionId.
28
+ *
29
+ * Protocol additions (see `packages/webui/src/types.ts`):
30
+ * client → server: collab.join { sessionId, role: 'observer' }
31
+ * collab.leave { sessionId }
32
+ * server → client: collab.state (initial + 2s periodic)
33
+ * collab.participant.joined
34
+ * collab.participant.left
35
+ * collab.event (live kernel event mirror)
36
+ */
37
+ export declare class CollaborationWebSocketHandler {
38
+ private readonly events;
39
+ private readonly logger;
40
+ /**
41
+ * Optional reader over the on-disk session log. When provided, late
42
+ * joiners receive the last `REPLAY_LIMIT` events of the joined
43
+ * session before live mirroring begins. Without a reader, joining
44
+ * is still allowed — the observer simply starts from "now" with no
45
+ * historical context.
46
+ */
47
+ private readonly reader?;
48
+ /**
49
+ * Optional sidecar store for collaboration annotations. Required
50
+ * for the `annotator` role — without it, `collab.annotate` messages
51
+ * are rejected with an error.
52
+ */
53
+ private readonly annotations?;
54
+ /**
55
+ * Optional kernel-level pause/resume bus. Required for the
56
+ * `controller` role — without it, `collab.request_pause` is rejected
57
+ * with an error. Wired to the agent's `toolCall` pipeline via
58
+ * `collabPauseMiddleware` in the webui server boot.
59
+ */
60
+ private readonly bus?;
61
+ private readonly clients;
62
+ /** sessionId → participants currently watching it. */
63
+ private readonly bySession;
64
+ private broadcastInterval;
65
+ private readonly offs;
66
+ constructor(events: EventBus, logger: Logger,
67
+ /**
68
+ * Optional reader over the on-disk session log. When provided, late
69
+ * joiners receive the last `REPLAY_LIMIT` events of the joined
70
+ * session before live mirroring begins. Without a reader, joining
71
+ * is still allowed — the observer simply starts from "now" with no
72
+ * historical context.
73
+ */
74
+ reader?: SessionReader | undefined,
75
+ /**
76
+ * Optional sidecar store for collaboration annotations. Required
77
+ * for the `annotator` role — without it, `collab.annotate` messages
78
+ * are rejected with an error.
79
+ */
80
+ annotations?: AnnotationsStore | undefined,
81
+ /**
82
+ * Optional kernel-level pause/resume bus. Required for the
83
+ * `controller` role — without it, `collab.request_pause` is rejected
84
+ * with an error. Wired to the agent's `toolCall` pipeline via
85
+ * `collabPauseMiddleware` in the webui server boot.
86
+ */
87
+ bus?: CollaborationBus | undefined);
88
+ addClient(ws: WebSocket): void;
89
+ dispose(): void;
90
+ /**
91
+ * Dispatch a parsed client message. Returns true when the message was
92
+ * recognized and handled; false when the caller should ignore / log.
93
+ * Phase 1 only knows `collab.join` and `collab.leave`; unknown types
94
+ * return false so the upstream router can decide.
95
+ */
96
+ handleMessage(ws: WebSocket, msg: {
97
+ type: string;
98
+ payload?: unknown | undefined;
99
+ }): boolean;
100
+ private join;
101
+ private leave;
102
+ private handleDisconnect;
103
+ /**
104
+ * Look up the participant record for a given WS across all sessions.
105
+ * Returns null when the WS hasn't joined (e.g. the client sent a
106
+ * `collab.annotate` before `collab.join`).
107
+ */
108
+ private findParticipant;
109
+ private findParticipantById;
110
+ private handleAnnotate;
111
+ private handleResolve;
112
+ private subscribe;
113
+ private broadcastEvent;
114
+ /**
115
+ * Replay the last `REPLAY_LIMIT` events from the on-disk session log
116
+ * to a single observer (the late joiner). Each event is forwarded as
117
+ * a `collab.event` with `replay: true` so the client can distinguish
118
+ * history from the live stream.
119
+ *
120
+ * The session log stores typed `SessionEvent`s (`user_input`,
121
+ * `llm_response`, `tool_result`, etc.) — different from the kernel's
122
+ * bus events. We translate the most useful subset (`tool.*` and
123
+ * `iteration.*`-shaped ones) into the same `kind` namespace the live
124
+ * mirror uses, so the client can render a single activity strip.
125
+ */
126
+ private replayHistory;
127
+ /**
128
+ * Map a stored `SessionEvent` to a `collab.event.kind` so the live
129
+ * strip and the history strip can share a single rendering path.
130
+ * Returns null for events that don't have a meaningful live analog
131
+ * (e.g. `session_start`, file-snapshot bookkeeping, rewind markers).
132
+ */
133
+ private historyEventToKind;
134
+ private stateMessage;
135
+ private ensureBroadcast;
136
+ private stopBroadcast;
137
+ private broadcast;
138
+ private send;
139
+ private errorMessage;
140
+ private handleRequestPause;
141
+ private handleResume;
142
+ private handleGrantControl;
143
+ /**
144
+ * Phase 4 — handle a controller's manual tool-call injection.
145
+ * Validates the payload, queues it on the bus, and broadcasts
146
+ * the grant so observers see what just happened. The actual
147
+ * splice into the agent's pipeline is performed by the
148
+ * `collabInjectMiddleware` on the next tool call.
149
+ */
150
+ private handleInjectTool;
151
+ /**
152
+ * Bus callback: a queued injection was spliced into a real tool call. Re-emit
153
+ * `collab.injection.granted` with phase `'consumed'` and the now-known tool
154
+ * name. The injection carries no sessionId, so resolve it from the author's
155
+ * current session; if they've already left, fall back to every live session.
156
+ */
157
+ private broadcastInjectionConsumed;
158
+ }
159
+ //# sourceMappingURL=collaboration-ws-handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collaboration-ws-handler.d.ts","sourceRoot":"","sources":["../../src/server/collaboration-ws-handler.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AACpC,OAAO,KAAK,EAAE,gBAAgB,EAAyB,QAAQ,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAClG,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAchF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,qBAAa,6BAA6B;IAQtC,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB;;;;;;OAMG;IACH,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC;IACxB;;;;OAIG;IACH,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC;IAC7B;;;;;OAKG;IACH,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC;IA7BvB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAwB;IAChD,sDAAsD;IACtD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAuC;IACjE,OAAO,CAAC,iBAAiB,CAA+C;IACxE,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAyB;IAE9C,YACmB,MAAM,EAAE,QAAQ,EAChB,MAAM,EAAE,MAAM;IAC/B;;;;;;OAMG;IACc,MAAM,CAAC,EAAE,aAAa,GAAG,SAAS;IACnD;;;;OAIG;IACc,WAAW,CAAC,EAAE,gBAAgB,GAAG,SAAS;IAC3D;;;;;OAKG;IACc,GAAG,CAAC,EAAE,gBAAgB,GAAG,SAAS,EAMpD;IAID,SAAS,CAAC,EAAE,EAAE,SAAS,GAAG,IAAI,CAK7B;IAED,OAAO,IAAI,IAAI,CAId;IAID;;;;;OAKG;IACH,aAAa,CACX,EAAE,EAAE,SAAS,EACb,GAAG,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;KAAE,GACnD,OAAO,CAyCT;IAID,OAAO,CAAC,IAAI;IAmEZ,OAAO,CAAC,KAAK;IAIb,OAAO,CAAC,gBAAgB;IAwCxB;;;;OAIG;IACH,OAAO,CAAC,eAAe;IASvB,OAAO,CAAC,mBAAmB;YASb,cAAc;YA4Ed,aAAa;IA0E3B,OAAO,CAAC,SAAS;IA6CjB,OAAO,CAAC,cAAc;IAsBtB;;;;;;;;;;;OAWG;YACW,aAAa;IAiC3B;;;;;OAKG;IACH,OAAO,CAAC,kBAAkB;IAmB1B,OAAO,CAAC,YAAY;IAiBpB,OAAO,CAAC,eAAe;IASvB,OAAO,CAAC,aAAa;IAOrB,OAAO,CAAC,SAAS;IAiBjB,OAAO,CAAC,IAAI;IAQZ,OAAO,CAAC,YAAY;YAMN,kBAAkB;YAiDlB,YAAY;YA0CZ,kBAAkB;IAgDhC;;;;;;OAMG;YACW,gBAAgB;IAuF9B;;;;;OAKG;IACH,OAAO,CAAC,0BAA0B;CA8BnC"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Context-aware editor completion for the WebUI Monaco surface.
3
+ *
4
+ * The handler combines fast symbol-index hits with a short, JSON-only LLM call.
5
+ * It is intentionally side-effect free: it never writes files and only reads the
6
+ * existing codebase index when available.
7
+ */
8
+ import type { WebSocket } from 'ws';
9
+ import type { Context, Provider, Tool } from '@wrongstack/core';
10
+ export type CompletionItemKind = 'text' | 'method' | 'function' | 'constructor' | 'field' | 'variable' | 'class' | 'interface' | 'module' | 'property' | 'unit' | 'value' | 'enum' | 'keyword' | 'snippet' | 'file' | 'reference';
11
+ export interface CompletionSuggestion {
12
+ label: string;
13
+ insertText: string;
14
+ kind?: CompletionItemKind | undefined;
15
+ detail?: string | undefined;
16
+ documentation?: string | undefined;
17
+ sortText?: string | undefined;
18
+ source?: 'llm' | 'index' | 'lsp' | undefined;
19
+ }
20
+ export interface CompletionHandlerOptions {
21
+ projectRoot: string;
22
+ provider?: Provider | undefined;
23
+ model?: string | undefined;
24
+ indexDir?: string | undefined;
25
+ lspCompletion?: LspCompletionSource | undefined;
26
+ timeoutMs?: number | undefined;
27
+ }
28
+ export interface LspCompletionSourceRequest {
29
+ filePath: string;
30
+ lineNumber: number;
31
+ column: number;
32
+ content?: string | undefined;
33
+ triggerCharacter?: string | undefined;
34
+ signal: AbortSignal;
35
+ }
36
+ export type LspCompletionSource = (request: LspCompletionSourceRequest) => Promise<CompletionSuggestion[]>;
37
+ export declare function handleCompletionRequest(ws: WebSocket, msg: unknown, opts: CompletionHandlerOptions): Promise<void>;
38
+ export declare function createToolLspCompletionSource(tool: Tool | undefined, ctx: Context): LspCompletionSource | undefined;
39
+ //# sourceMappingURL=completion-handlers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"completion-handlers.d.ts","sourceRoot":"","sources":["../../src/server/completion-handlers.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AACpC,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAW,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAIzE,MAAM,MAAM,kBAAkB,GAC1B,MAAM,GACN,QAAQ,GACR,UAAU,GACV,aAAa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ACb,GAAG,EAAE,OAAO,EACZ,IAAI,EAAE,wBAAwB,GAC7B,OAAO,CAAC,IAAI,CAAC,CA4Ef;AAED,wBAAgB,6BAA6B,CAC3C,IAAI,EAAE,IAAI,GAAG,SAAS,EACtB,GAAG,EAAE,OAAO,GACX,mBAAmB,GAAG,SAAS,CAkBjC"}
@@ -0,0 +1,72 @@
1
+ /**
2
+ * WebSocket connection lifecycle for the standalone WebUI server.
3
+ *
4
+ * Phase 1b of the god-module split (issue: God-modules >1500 lines).
5
+ * `startWebUI` in `./index.ts` previously inlined:
6
+ * - per-connection message rate limiting (state + `checkRateLimit`)
7
+ * - the `handleConnection` callback registered on both WS servers
8
+ * - the F5-resilience replay (transcript + usage) shipped to every new
9
+ * connection so a browser refresh rehydrates without an extra round-trip
10
+ *
11
+ * All of that moves here. The factory returns the `(ws) => void` handler
12
+ * that `startWebUI` registers on `wssPrimary` / `wssSecondary`. Behaviour is
13
+ * preserved verbatim — rate-limit windows, the 2 000-message replay cap, the
14
+ * pending-confirm cleanup on close, and the error swallow on socket errors.
15
+ */
16
+ import type { Context, Message, Usage } from '@wrongstack/core';
17
+ import type { DefaultTokenCounter } from '@wrongstack/core/infrastructure';
18
+ import type { WebSocket } from 'ws';
19
+ import type { AutoPhaseWebSocketHandler } from './autophase-ws-handler.js';
20
+ import type { CollaborationWebSocketHandler } from './collaboration-ws-handler.js';
21
+ import type { SddBoardWebSocketHandler } from './sdd-board-ws-handler.js';
22
+ import type { SddWizardWebSocketHandler } from './sdd-wizard-ws-handler.js';
23
+ import type { SpecsWebSocketHandler } from './specs-ws-handler.js';
24
+ import type { TerminalWebSocketHandler } from './terminal-ws-handler.js';
25
+ import type { WorktreeWebSocketHandler } from './worktree-ws-handler.js';
26
+ import type { ConnectedClient, WSClientMessage } from './types.js';
27
+ import { type PendingConfirm } from './pending-confirms.js';
28
+ /** The session.start payload enriched with optional F5-replay fields. */
29
+ type SessionStartEnriched = Record<string, unknown>;
30
+ export interface ConnectionHandlerOptions {
31
+ /** Live session id — re-read every connect (mutable across /new + resume). */
32
+ getSessionId(): string;
33
+ /** Builds the rich session.start payload (model, costs, cwd, …). */
34
+ sessionStartPayload(): Promise<SessionStartEnriched>;
35
+ /** Token counter — `total()` feeds the replayUsage block. */
36
+ tokenCounter: DefaultTokenCounter;
37
+ /** Agent context — fallback source for replay when the session log is unavailable. */
38
+ context: Context;
39
+ /**
40
+ * Load the visible chat replay for a reconnecting client. Prefer the
41
+ * session log over `context.messages`: context is the model working set and
42
+ * may have been compacted, while the session log is the UI transcript.
43
+ */
44
+ loadReplay?: (() => Promise<{
45
+ messages: Message[];
46
+ usage?: Usage | undefined;
47
+ } | null>) | undefined;
48
+ /** Live WS clients map (shared with the dispatcher + broadcaster). */
49
+ clients: Map<WebSocket, ConnectedClient>;
50
+ /** Pending permission confirmations — drained to 'no' on disconnect. */
51
+ pendingConfirms: Map<string, PendingConfirm>;
52
+ /** Per-feature WS handlers that register each new client for their feeds. */
53
+ autoPhaseHandler: AutoPhaseWebSocketHandler;
54
+ specsHandler: SpecsWebSocketHandler;
55
+ sddBoardHandler: SddBoardWebSocketHandler;
56
+ sddWizardHandler: SddWizardWebSocketHandler;
57
+ worktreeHandler: WorktreeWebSocketHandler;
58
+ collabHandler: CollaborationWebSocketHandler;
59
+ terminalHandler: TerminalWebSocketHandler;
60
+ /** The inbound message dispatcher (handles parsed WSClientMessage). */
61
+ handleMessage: (ws: WebSocket, client: ConnectedClient, msg: WSClientMessage) => Promise<void>;
62
+ }
63
+ /**
64
+ * Build the `(ws) => void` connection handler.
65
+ *
66
+ * Owns the rate-limit state + the per-process connection-id sequence so two
67
+ * handlers built in the same process don't share buckets. Returns the handler
68
+ * plus a `dispose` for tests; production registers it directly on the servers.
69
+ */
70
+ export declare function createConnectionHandler(opts: ConnectionHandlerOptions): (ws: WebSocket) => void;
71
+ export {};
72
+ //# sourceMappingURL=connection-handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection-handler.d.ts","sour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KAAK,CAAC,EAAE,KAAK,GAAG,SAAS,CAAA;KAAE,GAAG,IAAI,CAAC,CAAC,GAAG,SAAS,CAAC;IACpG,sEAAsE;IACtE,OAAO,EAAE,GAAG,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;IACzC,wEAAwE;IACxE,eAAe,EAAE,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAC7C,6EAA6E;IAC7E,gBAAgB,EAAE,yBAAyB,CAAC;IAC5C,YAAY,EAAE,qBAAqB,CAAC;IACpC,eAAe,EAAE,wBAAwB,CAAC;IAC1C,gBAAgB,EAAE,yBAAyB,CAAC;IAC5C,eAAe,EAAE,wBAAwB,CAAC;IAC1C,aAAa,EAAE,6BAA6B,CAAC;IAC7C,eAAe,EAAE,wBAAwB,CAAC;IAC1C,uEAAuE;IACvE,aAAa,EAAE,CAAC,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,eAAe,EAAE,GAAG,EAAE,eAAe,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAChG;AA2BD;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,wBAAwB,GAC7B,CAAC,EAAE,EAAE,SAAS,KAAK,IAAI,CA4LzB"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Context-meta seeding for the standalone WebUI server.
3
+ *
4
+ * Phase 1c of the god-module split (issue: God-modules >1500 lines).
5
+ * `startWebUI` in `./index.ts` previously inlined a ~70-line block that
6
+ * mirrored the CLI's `getSettings()` mapping: it reads the persisted
7
+ * `config.json` shape and projects the relevant fields onto `context.meta`
8
+ * so the settings panel, autonomy engine, fallback chain, feature toggles,
9
+ * and Telegram extension state all reflect the persisted config on first
10
+ * connect — before any `prefs.update` arrives.
11
+ *
12
+ * Pure config → meta projection. No behaviour change.
13
+ */
14
+ import type { Config } from '@wrongstack/core/types';
15
+ /**
16
+ * Seed `context.meta` from the loaded config. Mirrors the CLI's
17
+ * `getSettings()` mapping so TUI and WebUI agree. Without this the snapshot
18
+ * is empty and every browser shows localStorage defaults (autonomy "off",
19
+ * etc.) regardless of what config.json says.
20
+ *
21
+ * The `context` is typed structurally so this module does not take a
22
+ * dependency on the higher `Context` class — anything with a writable
23
+ * `meta: Record<string, unknown>` works.
24
+ */
25
+ export declare function seedContextMeta(config: Config, context: {
26
+ meta: Record<string, unknown>;
27
+ }): void;
28
+ //# sourceMappingURL=context-meta.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-meta.d.ts","sourceRoot":"","sources":["../../src/server/context-meta.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAErD;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,MAAM,EACd,OAAO,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE,GACzC,IAAI,CAyEN"}