@codetreker/daynight 0.25.4 → 0.26.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 (170) hide show
  1. package/README.md +108 -4
  2. package/config.example.yml +3 -0
  3. package/dist/api/client.js +2 -2
  4. package/dist/api/client.js.map +1 -1
  5. package/dist/api/parse.js +14 -2
  6. package/dist/api/parse.js.map +1 -1
  7. package/dist/api/types.d.ts +4 -1
  8. package/dist/api/worker-mode.d.ts +6 -0
  9. package/dist/api/worker-mode.js +14 -0
  10. package/dist/api/worker-mode.js.map +1 -0
  11. package/dist/cli/commands.js +2 -0
  12. package/dist/cli/commands.js.map +1 -1
  13. package/dist/commands/controller/command-controls.d.ts +4 -0
  14. package/dist/commands/controller/command-controls.js +33 -0
  15. package/dist/commands/controller/command-controls.js.map +1 -0
  16. package/dist/commands/controller/definition.d.ts +3 -0
  17. package/dist/commands/controller/definition.js +22 -0
  18. package/dist/commands/controller/definition.js.map +1 -0
  19. package/dist/commands/controller/independent.d.ts +3 -0
  20. package/dist/commands/controller/independent.js +344 -0
  21. package/dist/commands/controller/independent.js.map +1 -0
  22. package/dist/commands/controller/index.d.ts +12 -0
  23. package/dist/commands/controller/index.js +73 -0
  24. package/dist/commands/controller/index.js.map +1 -0
  25. package/dist/commands/controller/launch-ticket.d.ts +49 -0
  26. package/dist/commands/controller/launch-ticket.js +99 -0
  27. package/dist/commands/controller/launch-ticket.js.map +1 -0
  28. package/dist/commands/controller/lifecycle-store.d.ts +84 -0
  29. package/dist/commands/controller/lifecycle-store.js +278 -0
  30. package/dist/commands/controller/lifecycle-store.js.map +1 -0
  31. package/dist/commands/controller/local-client.d.ts +44 -0
  32. package/dist/commands/controller/local-client.js +75 -0
  33. package/dist/commands/controller/local-client.js.map +1 -0
  34. package/dist/commands/controller/local-content.d.ts +23 -0
  35. package/dist/commands/controller/local-content.js +103 -0
  36. package/dist/commands/controller/local-content.js.map +1 -0
  37. package/dist/commands/controller/process-proof.d.ts +13 -0
  38. package/dist/commands/controller/process-proof.js +121 -0
  39. package/dist/commands/controller/process-proof.js.map +1 -0
  40. package/dist/commands/controller/providers/claude.d.ts +2 -0
  41. package/dist/commands/controller/providers/claude.js +470 -0
  42. package/dist/commands/controller/providers/claude.js.map +1 -0
  43. package/dist/commands/controller/providers/codex.d.ts +2 -0
  44. package/dist/commands/controller/providers/codex.js +254 -0
  45. package/dist/commands/controller/providers/codex.js.map +1 -0
  46. package/dist/commands/controller/providers/controls-claude.d.ts +26 -0
  47. package/dist/commands/controller/providers/controls-claude.js +138 -0
  48. package/dist/commands/controller/providers/controls-claude.js.map +1 -0
  49. package/dist/commands/controller/providers/controls-codex.d.ts +38 -0
  50. package/dist/commands/controller/providers/controls-codex.js +199 -0
  51. package/dist/commands/controller/providers/controls-codex.js.map +1 -0
  52. package/dist/commands/controller/providers/controls-copilot.d.ts +20 -0
  53. package/dist/commands/controller/providers/controls-copilot.js +143 -0
  54. package/dist/commands/controller/providers/controls-copilot.js.map +1 -0
  55. package/dist/commands/controller/providers/controls.d.ts +21 -0
  56. package/dist/commands/controller/providers/controls.js +53 -0
  57. package/dist/commands/controller/providers/controls.js.map +1 -0
  58. package/dist/commands/controller/providers/copilot-interactions.d.ts +47 -0
  59. package/dist/commands/controller/providers/copilot-interactions.js +295 -0
  60. package/dist/commands/controller/providers/copilot-interactions.js.map +1 -0
  61. package/dist/commands/controller/providers/copilot-projection.d.ts +11 -0
  62. package/dist/commands/controller/providers/copilot-projection.js +93 -0
  63. package/dist/commands/controller/providers/copilot-projection.js.map +1 -0
  64. package/dist/commands/controller/providers/copilot-runtime.d.ts +9 -0
  65. package/dist/commands/controller/providers/copilot-runtime.js +127 -0
  66. package/dist/commands/controller/providers/copilot-runtime.js.map +1 -0
  67. package/dist/commands/controller/providers/copilot.d.ts +2 -0
  68. package/dist/commands/controller/providers/copilot.js +309 -0
  69. package/dist/commands/controller/providers/copilot.js.map +1 -0
  70. package/dist/commands/controller/providers/interactions.d.ts +3 -0
  71. package/dist/commands/controller/providers/interactions.js +79 -0
  72. package/dist/commands/controller/providers/interactions.js.map +1 -0
  73. package/dist/commands/controller/providers/native-rpc.d.ts +28 -0
  74. package/dist/commands/controller/providers/native-rpc.js +85 -0
  75. package/dist/commands/controller/providers/native-rpc.js.map +1 -0
  76. package/dist/commands/controller/providers/projection.d.ts +23 -0
  77. package/dist/commands/controller/providers/projection.js +99 -0
  78. package/dist/commands/controller/providers/projection.js.map +1 -0
  79. package/dist/commands/controller/providers/turns.d.ts +7 -0
  80. package/dist/commands/controller/providers/turns.js +21 -0
  81. package/dist/commands/controller/providers/turns.js.map +1 -0
  82. package/dist/commands/controller/providers/types.d.ts +44 -0
  83. package/dist/commands/controller/providers/types.js +2 -0
  84. package/dist/commands/controller/providers/types.js.map +1 -0
  85. package/dist/commands/controller/recovery.d.ts +6 -0
  86. package/dist/commands/controller/recovery.js +22 -0
  87. package/dist/commands/controller/recovery.js.map +1 -0
  88. package/dist/commands/controller/relay.d.ts +18 -0
  89. package/dist/commands/controller/relay.js +299 -0
  90. package/dist/commands/controller/relay.js.map +1 -0
  91. package/dist/commands/controller/resume.d.ts +18 -0
  92. package/dist/commands/controller/resume.js +193 -0
  93. package/dist/commands/controller/resume.js.map +1 -0
  94. package/dist/commands/controller/runtime.d.ts +5 -0
  95. package/dist/commands/controller/runtime.js +455 -0
  96. package/dist/commands/controller/runtime.js.map +1 -0
  97. package/dist/commands/controller/windows-job.d.ts +3 -0
  98. package/dist/commands/controller/windows-job.js +59 -0
  99. package/dist/commands/controller/windows-job.js.map +1 -0
  100. package/dist/commands/controller/wire-display.d.ts +5 -0
  101. package/dist/commands/controller/wire-display.js +11 -0
  102. package/dist/commands/controller/wire-display.js.map +1 -0
  103. package/dist/commands/worker/backend.d.ts +7 -0
  104. package/dist/commands/worker/backend.js +7 -0
  105. package/dist/commands/worker/backend.js.map +1 -0
  106. package/dist/commands/worker/backends/grant-renewal.d.ts +13 -0
  107. package/dist/commands/worker/backends/grant-renewal.js +42 -0
  108. package/dist/commands/worker/backends/grant-renewal.js.map +1 -0
  109. package/dist/commands/worker/backends/session-api.d.ts +66 -0
  110. package/dist/commands/worker/backends/session-api.js +84 -0
  111. package/dist/commands/worker/backends/session-api.js.map +1 -0
  112. package/dist/commands/worker/backends/web-process.d.ts +79 -0
  113. package/dist/commands/worker/backends/web-process.js +156 -0
  114. package/dist/commands/worker/backends/web-process.js.map +1 -0
  115. package/dist/commands/worker/backends/web-store.d.ts +49 -0
  116. package/dist/commands/worker/backends/web-store.js +323 -0
  117. package/dist/commands/worker/backends/web-store.js.map +1 -0
  118. package/dist/commands/worker/backends/web-types.d.ts +83 -0
  119. package/dist/commands/worker/backends/web-types.js +3 -0
  120. package/dist/commands/worker/backends/web-types.js.map +1 -0
  121. package/dist/commands/worker/backends/web.d.ts +26 -0
  122. package/dist/commands/worker/backends/web.js +178 -0
  123. package/dist/commands/worker/backends/web.js.map +1 -0
  124. package/dist/commands/worker/config.js +12 -5
  125. package/dist/commands/worker/config.js.map +1 -1
  126. package/dist/commands/worker/control.d.ts +2 -0
  127. package/dist/commands/worker/control.js +11 -4
  128. package/dist/commands/worker/control.js.map +1 -1
  129. package/dist/commands/worker/coordinator.d.ts +7 -0
  130. package/dist/commands/worker/coordinator.js +138 -19
  131. package/dist/commands/worker/coordinator.js.map +1 -1
  132. package/dist/commands/worker/herdr/agents.js +5 -4
  133. package/dist/commands/worker/herdr/agents.js.map +1 -1
  134. package/dist/commands/worker/herdr/arguments.js +9 -4
  135. package/dist/commands/worker/herdr/arguments.js.map +1 -1
  136. package/dist/commands/worker/herdr/claude-input.d.ts +2 -0
  137. package/dist/commands/worker/herdr/claude-input.js +20 -0
  138. package/dist/commands/worker/herdr/claude-input.js.map +1 -0
  139. package/dist/commands/worker/herdr/instance.js +1 -1
  140. package/dist/commands/worker/herdr/instance.js.map +1 -1
  141. package/dist/commands/worker/herdr/preflight.d.ts +1 -1
  142. package/dist/commands/worker/herdr/preflight.js +31 -10
  143. package/dist/commands/worker/herdr/preflight.js.map +1 -1
  144. package/dist/commands/worker/herdr.js +5 -1
  145. package/dist/commands/worker/herdr.js.map +1 -1
  146. package/dist/commands/worker/prompts.js +5 -1
  147. package/dist/commands/worker/prompts.js.map +1 -1
  148. package/dist/commands/worker/repositories.js +2 -2
  149. package/dist/commands/worker/repositories.js.map +1 -1
  150. package/dist/commands/worker/runtime.js +62 -10
  151. package/dist/commands/worker/runtime.js.map +1 -1
  152. package/dist/commands/worker/setup-environment.d.ts +2 -1
  153. package/dist/commands/worker/setup-environment.js +10 -4
  154. package/dist/commands/worker/setup-environment.js.map +1 -1
  155. package/dist/commands/worker/setup.js +5 -5
  156. package/dist/commands/worker/setup.js.map +1 -1
  157. package/dist/commands/worker/store.d.ts +2 -1
  158. package/dist/commands/worker/store.js +19 -9
  159. package/dist/commands/worker/store.js.map +1 -1
  160. package/dist/commands/worker/types.d.ts +4 -1
  161. package/dist/session/controller-protocol.d.ts +245 -0
  162. package/dist/session/controller-protocol.js +218 -0
  163. package/dist/session/controller-protocol.js.map +1 -0
  164. package/dist/session/controls.d.ts +28 -0
  165. package/dist/session/controls.js +37 -0
  166. package/dist/session/controls.js.map +1 -0
  167. package/dist/session/protocol.d.ts +290 -0
  168. package/dist/session/protocol.js +307 -0
  169. package/dist/session/protocol.js.map +1 -0
  170. package/package.json +7 -2
@@ -0,0 +1,309 @@
1
+ import { CopilotControls } from "./controls-copilot.js";
2
+ import { randomUUID } from "node:crypto";
3
+ import { realpath, stat } from "node:fs/promises";
4
+ import { NativeRpcError, record, string } from "./native-rpc.js";
5
+ import { nativeEntryId, parseProviderArguments } from "./projection.js";
6
+ import { NativeTurns } from "./turns.js";
7
+ import { CopilotInteractions } from "./copilot-interactions.js";
8
+ import { CopilotProjection, copilotOwner } from "./copilot-projection.js";
9
+ import { copilotDeadline, startCopilotRuntime } from "./copilot-runtime.js";
10
+ export const openCopilotProvider = async (options) => {
11
+ const args = parseProviderArguments("copilot", options.args), cwd = await realpath(options.cwd);
12
+ if (!(await stat(cwd)).isDirectory())
13
+ throw new Error("Copilot working directory is not a directory.");
14
+ const nativeId = options.resumeNativeSessionId ?? randomUUID(), turns = new NativeTurns();
15
+ let controls, turnStartedAt = null;
16
+ let native, client;
17
+ let verified = false, closed = false, disconnected = false, dispatching = false;
18
+ let activity = "initializing", currentTurnId = null, interactionId = null;
19
+ let buffered = [], heartbeat, polling = false;
20
+ const cancelWaiters = new Set();
21
+ const state = () => options.onState({ nativeSessionId: verified ? nativeId : null, activity: closed ? "stopped" : disconnected ? "unknown" : interactions.waiting ? "waiting_input" : activity, currentTurnId, turnStartedAt, ...(controls ? { controls: controls.store.value } : {}),
22
+ capabilities: verified && !closed && !disconnected ? { send: true, steer: true, cancel: true, respond: true } : { send: false, steer: false, cancel: false, respond: false } });
23
+ const projection = new CopilotProjection(nativeId, options.onTimeline);
24
+ const interactions = new CopilotInteractions({ sessionId: nativeId, onTimeline: options.onTimeline, onChange: state,
25
+ permissionRpc: input => { if (!native)
26
+ return Promise.reject(new Error("Native Copilot session is not ready.")); return native.rpc.permissions.handlePendingPermissionRequest(input); } });
27
+ let rejectLost;
28
+ const lost = new Promise((_, reject) => { rejectLost = reject; });
29
+ void lost.catch(() => { });
30
+ const disconnect = (error) => {
31
+ if (closed || disconnected)
32
+ return;
33
+ disconnected = true;
34
+ controls?.close();
35
+ if (heartbeat)
36
+ clearInterval(heartbeat);
37
+ rejectLost(error);
38
+ interactions.dispose(error);
39
+ if (currentTurnId)
40
+ turns.complete(currentTurnId, error);
41
+ for (const waiter of cancelWaiters)
42
+ waiter.reject(error);
43
+ cancelWaiters.clear();
44
+ options.onTimeline({ entryId: nativeEntryId(nativeId, "connection-lost"), revision: "1", kind: "error", code: "native_connection_lost", message: error.message });
45
+ state();
46
+ options.onFatalError?.(error);
47
+ };
48
+ const call = (promise, label, ms = 30_000) => copilotDeadline(Promise.race([promise, lost]), label, ms);
49
+ const finish = (error) => {
50
+ if (currentTurnId)
51
+ turns.complete(currentTurnId, error);
52
+ currentTurnId = null;
53
+ turnStartedAt = null;
54
+ interactionId = null;
55
+ activity = "idle";
56
+ for (const waiter of cancelWaiters)
57
+ waiter.resolve();
58
+ cancelWaiters.clear();
59
+ state();
60
+ };
61
+ let todoRead = Promise.resolve();
62
+ const refreshTodos = () => {
63
+ todoRead = todoRead.then(async () => {
64
+ if (!native || closed || disconnected)
65
+ return;
66
+ const { rows } = await call(native.rpc.plan.readSqlTodos(), "Copilot todo read");
67
+ if (closed || disconnected)
68
+ return;
69
+ options.onTimeline({ entryId: nativeEntryId(nativeId, "todos"), revision: "1", kind: "todo", items: rows.flatMap(row => {
70
+ const text = row.title || row.description, id = row.id;
71
+ const status = row.status === "done" || row.status === "completed" ? "completed" : row.status === "in_progress" ? "in_progress" : row.status === "pending" ? "pending" : null;
72
+ if (!text || !id || !status) {
73
+ options.onTimeline({ entryId: nativeEntryId(nativeId, "todo-unavailable"), revision: "1", kind: "error", code: "unsupported_native_todo", message: "Some Copilot todo rows lack a supported identity, description, or status." });
74
+ return [];
75
+ }
76
+ return [{ id, text, status }];
77
+ }) });
78
+ }).catch(() => { options.onDiagnostic?.("Copilot todo state is unavailable."); });
79
+ };
80
+ const seen = new Set();
81
+ const accept = (event, history = false) => {
82
+ if (closed || disconnected || seen.has(event.id))
83
+ return;
84
+ seen.add(event.id);
85
+ projection.accept(event);
86
+ if (history)
87
+ return;
88
+ if (event.type === "session.todos_changed")
89
+ refreshTodos();
90
+ if (copilotOwner(event))
91
+ return;
92
+ const data = record(event.data), nextInteraction = string(data.interactionId);
93
+ if (event.type === "assistant.turn_start" || event.type === "user.message") {
94
+ if (currentTurnId && interactionId && nextInteraction && nextInteraction !== interactionId && data.delivery !== "steering")
95
+ finish(null);
96
+ if (!currentTurnId) {
97
+ currentTurnId = nativeEntryId(nativeId, `turn:${event.id}`);
98
+ const stamp = Date.parse(event.timestamp);
99
+ turnStartedAt = Number.isFinite(stamp) && event.type === "assistant.turn_start" ? new Date(stamp).toISOString() : null;
100
+ }
101
+ if (event.type === "assistant.turn_start" && !turnStartedAt) {
102
+ const stamp = Date.parse(event.timestamp);
103
+ if (Number.isFinite(stamp))
104
+ turnStartedAt = new Date(stamp).toISOString();
105
+ }
106
+ if (nextInteraction)
107
+ interactionId = nextInteraction;
108
+ activity = "working";
109
+ state();
110
+ }
111
+ else if (event.type === "assistant.idle" || event.type === "session.idle")
112
+ finish(null);
113
+ else if (event.type === "abort")
114
+ finish(new Error("Native Copilot turn was canceled."));
115
+ else if (event.type === "session.error")
116
+ finish(new Error(string(data.message) || "Native Copilot turn failed."));
117
+ else if (event.type === "session.shutdown")
118
+ disconnect(new Error("Native Copilot session closed; operation results are unknown."));
119
+ };
120
+ const onEvent = (event) => {
121
+ if (closed || disconnected)
122
+ return;
123
+ try {
124
+ interactions.accept(event);
125
+ if (buffered)
126
+ buffered.push(event);
127
+ else
128
+ accept(event);
129
+ }
130
+ catch {
131
+ disconnect(new Error("Native Copilot event could not be processed; operation results are unknown."));
132
+ }
133
+ };
134
+ const runtime = startCopilotRuntime({ ...options, cwd }, disconnect);
135
+ let closing;
136
+ const close = () => closing ??= (async () => {
137
+ closed = true;
138
+ controls?.close();
139
+ if (heartbeat)
140
+ clearInterval(heartbeat);
141
+ const error = new Error("Native Copilot process stopped; pending operation results are unknown.");
142
+ rejectLost(error);
143
+ interactions.dispose(error);
144
+ if (currentTurnId)
145
+ turns.complete(currentTurnId, error);
146
+ for (const waiter of cancelWaiters)
147
+ waiter.reject(error);
148
+ cancelWaiters.clear();
149
+ try {
150
+ if (native)
151
+ await copilotDeadline(native.disconnect(), "Copilot session disconnect", 2000);
152
+ }
153
+ catch {
154
+ options.onDiagnostic?.("Copilot session disconnect was unconfirmed; stopping its owned runtime.");
155
+ }
156
+ await runtime.close();
157
+ currentTurnId = null;
158
+ activity = "stopped";
159
+ state();
160
+ })();
161
+ try {
162
+ state();
163
+ client = await runtime.ready;
164
+ if (options.resumeNativeSessionId) {
165
+ const metadata = await call(client.getSessionMetadata(nativeId), "Copilot session metadata");
166
+ if (!metadata || metadata.sessionId !== nativeId || metadata.isRemote || !metadata.context?.workingDirectory || await realpath(metadata.context.workingDirectory) !== cwd)
167
+ throw new Error("Native Copilot history identity or working directory is unavailable.");
168
+ const usage = await call(client.rpc.sessions.checkInUse({ sessionIds: [nativeId] }), "Copilot session ownership");
169
+ if (usage.inUse.includes(nativeId))
170
+ throw new Error("Native Copilot session is already in use.");
171
+ }
172
+ let skillDirectories, skillDiscoveryError = null;
173
+ try {
174
+ const discovery = await call(client.rpc.skills.getDiscoveryPaths({ projectPaths: [cwd] }), "Copilot skill discovery");
175
+ skillDirectories = discovery.paths.map(entry => entry.path);
176
+ }
177
+ catch (error) {
178
+ skillDiscoveryError = error instanceof Error ? error.message : "Copilot skill discovery is unavailable.";
179
+ }
180
+ const config = { ...(skillDirectories ? { skillDirectories } : {}), sessionId: nativeId, workingDirectory: cwd, streaming: true, includeSubAgentStreamingEvents: true,
181
+ ...(!options.resumeNativeSessionId && options.model ? { model: options.model } : {}), ...(!options.resumeNativeSessionId && args.effort ? { reasoningEffort: args.effort } : {}),
182
+ onEvent, onPermissionRequest: () => interactions.onPermissionRequest(), onUserInputRequest: request => interactions.bindQuestion(request),
183
+ onElicitationRequest: request => interactions.bindElicitation(request), onExitPlanModeRequest: request => interactions.bindPlan(request) };
184
+ const opening = options.resumeNativeSessionId ? client.resumeSession(nativeId, config) : client.createSession(config);
185
+ void opening.then(async (opened) => { if (closed)
186
+ await copilotDeadline(opened.disconnect(), "Late Copilot session disconnect", 2000); }).catch(() => { });
187
+ native = await call(opening, "Copilot session open");
188
+ const snapshot = await call(native.rpc.metadata.snapshot(), "Copilot session identity");
189
+ if (native.sessionId !== nativeId || snapshot.sessionId !== nativeId || snapshot.isRemote || snapshot.alreadyInUse || !snapshot.workingDirectory || await realpath(snapshot.workingDirectory) !== cwd)
190
+ throw new Error("Native Copilot session identity or working directory mismatch.");
191
+ controls = new CopilotControls(native, state, options.onControlConfirmed, options.controlsRevisionFloor, skillDiscoveryError);
192
+ await controls.initialize(options.resumeNativeSessionId !== null, options.unattended);
193
+ const history = await call(native.getEvents(), "Copilot native history");
194
+ const { processing } = await call(native.rpc.metadata.isProcessing(), "Copilot foreground activity");
195
+ // Callbacks must bind immediately, but timeline replay precedes queued live
196
+ // updates. Finalized projection IDs prevent old deltas overwriting history.
197
+ const liveIds = new Set(buffered.map(event => event.id));
198
+ for (const event of history) {
199
+ if (!liveIds.has(event.id))
200
+ interactions.accept(event, true);
201
+ accept(event, true);
202
+ }
203
+ if (processing) {
204
+ const last = history.findLast(event => !copilotOwner(event) && (event.type === "user.message" || event.type === "assistant.turn_start"));
205
+ currentTurnId = nativeEntryId(nativeId, `turn:${last?.id ?? "processing"}`);
206
+ interactionId = last ? string(record(last.data).interactionId) || null : null;
207
+ }
208
+ activity = processing ? "working" : "idle";
209
+ verified = true;
210
+ const queued = buffered;
211
+ buffered = undefined;
212
+ for (const event of queued)
213
+ accept(event);
214
+ if (disconnected)
215
+ throw new Error("Copilot disconnected during session initialization.");
216
+ state();
217
+ refreshTodos();
218
+ // SDK exposes no public transport-close event. Observe owned process exit
219
+ // immediately and use its public ping to detect a broken live connection.
220
+ heartbeat = setInterval(() => {
221
+ if (polling || closed || disconnected || !client)
222
+ return;
223
+ polling = true;
224
+ void call(client.ping(), "Copilot connection health", 5000).catch(() => disconnect(new Error("Native Copilot connection lost; operation results are unknown."))).finally(() => { polling = false; });
225
+ }, 5000);
226
+ heartbeat.unref();
227
+ }
228
+ catch (error) {
229
+ await close();
230
+ throw error;
231
+ }
232
+ const send = async (text, operationId, expectedTurnId, displayPrompt) => {
233
+ if (closed || disconnected || dispatching || currentTurnId !== expectedTurnId || interactions.waiting)
234
+ throw new NativeRpcError(-32602, "Native Copilot turn changed or cannot accept input.");
235
+ const steering = currentTurnId !== null;
236
+ const turnId = currentTurnId ?? randomUUID();
237
+ if (!currentTurnId)
238
+ turnStartedAt = null;
239
+ currentTurnId = turnId;
240
+ dispatching = true;
241
+ activity = "working";
242
+ state();
243
+ let uncertain = false;
244
+ const sending = Promise.resolve().then(() => {
245
+ if (closed || disconnected || currentTurnId !== turnId)
246
+ throw new NativeRpcError(-32602, "Native Copilot turn changed before input dispatch.");
247
+ return native.send({ prompt: text, ...(displayPrompt ? { displayPrompt } : {}), mode: "immediate" });
248
+ });
249
+ // A settled SDK send carries its own native message ID. Prompt equality and
250
+ // locally generated operation IDs never establish native input acceptance.
251
+ void sending.then(messageId => {
252
+ dispatching = false;
253
+ if (uncertain && !closed && !disconnected && typeof messageId === "string" && messageId)
254
+ options.onInputObserved?.(operationId);
255
+ }, () => { dispatching = false; });
256
+ let messageId;
257
+ try {
258
+ messageId = await call(sending, "Copilot input acceptance", 60_000);
259
+ }
260
+ catch (error) {
261
+ uncertain = true;
262
+ throw error;
263
+ }
264
+ if (typeof messageId !== "string" || !messageId)
265
+ throw new Error("Copilot returned no native message identity; input result is unknown.");
266
+ return { disposition: steering ? "handled" : "started", turnId };
267
+ };
268
+ return {
269
+ nativeSessionId: nativeId, send,
270
+ async refreshControls() { await controls.refresh(); return { disposition: "handled" }; },
271
+ async setSetting(id, value, operationId, revision) { if (closed || disconnected || dispatching)
272
+ throw new NativeRpcError(-32602, "Native controls are unavailable."); await controls.set(id, value, operationId, revision); return { disposition: "handled" }; },
273
+ async executeCommand(id, args, operationId, revision, expectedTurnId) {
274
+ if (closed || disconnected || dispatching || currentTurnId !== null || expectedTurnId !== null || interactions.waiting)
275
+ throw new NativeRpcError(-32602, "Copilot commands require an idle session.");
276
+ const result = await controls.invoke(id, args, revision);
277
+ if (result.kind === "agent-prompt") {
278
+ if (result.mode && result.mode !== "interactive")
279
+ throw new NativeRpcError(-32602, "Copilot command requested an unsupported agent mode.");
280
+ return send(result.prompt, operationId, null, result.displayPrompt);
281
+ }
282
+ if (result.kind !== "text" && result.kind !== "completed")
283
+ throw new NativeRpcError(-32602, "Copilot command requires unsupported subcommand selection.");
284
+ const text = result.kind === "text" ? result.text : result.message;
285
+ if (text)
286
+ options.onTimeline({ entryId: nativeEntryId(nativeId, `command:${operationId}`), revision: "1", kind: "assistant_message", content: [{ type: "text", text }] });
287
+ return { disposition: "handled" };
288
+ },
289
+ async cancel(expectedTurnId) {
290
+ if (closed || disconnected || currentTurnId !== expectedTurnId)
291
+ throw new NativeRpcError(-32602, "Native Copilot turn changed.");
292
+ let waiter;
293
+ const stopped = new Promise((resolve, reject) => { waiter = { resolve, reject }; cancelWaiters.add(waiter); });
294
+ try {
295
+ const confirmation = call(stopped, "Copilot foreground cancellation");
296
+ const [, result] = await Promise.all([confirmation, call(native.rpc.interruptMainTurn({}), "Copilot interrupt")]);
297
+ if (!result.interrupted && currentTurnId !== null)
298
+ throw new Error("Copilot did not confirm foreground cancellation.");
299
+ return { disposition: "handled" };
300
+ }
301
+ finally {
302
+ cancelWaiters.delete(waiter);
303
+ }
304
+ },
305
+ respond: (id, revision, response) => interactions.respond(id, revision, response),
306
+ waitForTurn: (id, deadline) => turns.wait(id, deadline), close,
307
+ };
308
+ };
309
+ //# sourceMappingURL=copilot.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"copilot.js","sourceRoot":"","sources":["../../../../src/commands/controller/providers/copilot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,yBAAyB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AC;gBACtE,MAAM,CAAC,EAAE,MAAM,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,YAAY,EAAE,IAAI,CAAC,MAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,EAAE,CAAC,EAAE,mBAAmB,CAAC,CAAC,CAAC,CAAC;gBACnH,IAAI,CAAC,MAAM,CAAC,WAAW,IAAI,aAAa,KAAK,IAAI;oBAAE,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;gBACvH,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,CAAC;YACpC,CAAC;oBAAS,CAAC;gBAAC,aAAa,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAAC,CAAC;QAC7C,CAAC;QACD,OAAO,EAAE,CAAC,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE,EAAE,QAAQ,EAAE,QAAQ,CAAC;QACjF,WAAW,EAAE,CAAC,EAAE,EAAE,QAAQ,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,QAAQ,CAAC,EAAE,KAAK;KAC/D,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { InteractionResponse, SessionInteraction } from "../../../session/protocol.js";
2
+ export declare const validateResponse: (interaction: SessionInteraction, response: InteractionResponse) => void;
3
+ export declare const formInteraction: (title: string, value: unknown) => SessionInteraction;
@@ -0,0 +1,79 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { record, string } from "./native-rpc.js";
3
+ export const validateResponse = (interaction, response) => {
4
+ if (interaction.state !== "pending")
5
+ throw new Error("This native interaction is no longer pending.");
6
+ if (response.kind === "dismiss") {
7
+ if (interaction.kind === "approval" || !interaction.canDismiss)
8
+ throw new Error("Dismiss is not available.");
9
+ return;
10
+ }
11
+ if (interaction.kind !== response.kind)
12
+ throw new Error("Native interaction response kind does not match.");
13
+ if (interaction.kind === "approval" && response.kind === "approval") {
14
+ if (!interaction.actions.includes(response.action))
15
+ throw new Error("Approval action is not available.");
16
+ }
17
+ if (interaction.kind === "question" && response.kind === "question") {
18
+ for (const answer of response.answers)
19
+ if (!interaction.questions.some(q => q.questionId === answer.questionId))
20
+ throw new Error("Unknown question.");
21
+ for (const q of interaction.questions) {
22
+ const a = response.answers.find(a => a.questionId === q.questionId);
23
+ if ((!a || !a.optionIds.length && !a.text?.trim()) && q.required)
24
+ throw new Error("A required question is unanswered.");
25
+ if (!a)
26
+ continue;
27
+ if ((!q.multiple && a.optionIds.length > 1) || a.optionIds.some(id => !q.options.some(o => o.id === id)) || (!q.allowCustom && a.text))
28
+ throw new Error("Invalid question answer.");
29
+ }
30
+ }
31
+ if (interaction.kind === "form" && response.kind === "form") {
32
+ for (const answer of response.values)
33
+ if (!interaction.fields.some(f => f.fieldId === answer.fieldId))
34
+ throw new Error("Unknown form field.");
35
+ for (const f of interaction.fields) {
36
+ const v = response.values.find(a => a.fieldId === f.fieldId)?.value;
37
+ if (v === undefined || v === "" || Array.isArray(v) && !v.length) {
38
+ if (f.required)
39
+ throw new Error("A required field is missing.");
40
+ else
41
+ continue;
42
+ }
43
+ if (f.type === "text" && typeof v !== "string" || f.type === "boolean" && typeof v !== "boolean" || f.type === "number" && (typeof v !== "number" || !Number.isFinite(v) || f.min !== null && v < f.min || f.max !== null && v > f.max) || f.type === "select" && (typeof v !== "string" || !f.options.some(o => o.id === v)) || f.type === "multiselect" && (!Array.isArray(v) || v.some(x => !f.options.some(o => o.id === x))))
44
+ throw new Error("Invalid form value.");
45
+ }
46
+ }
47
+ };
48
+ // Unsupported schema constraints are rejected, rather than weakened in the browser.
49
+ export const formInteraction = (title, value) => {
50
+ const schema = record(value);
51
+ if (schema.type !== "object")
52
+ throw new Error("Unsupported native form schema.");
53
+ const allowedRoot = ["type", "properties", "required", "title", "description", "$schema"];
54
+ if (Object.keys(schema).some(k => !allowedRoot.includes(k)))
55
+ throw new Error("Unsupported native form constraint.");
56
+ const required = Array.isArray(schema.required) ? schema.required : [];
57
+ const fields = Object.entries(record(schema.properties)).map(([fieldId, raw]) => {
58
+ const p = record(raw);
59
+ if (Object.keys(p).some(k => !["type", "title", "description", "enum", "enumNames", "minimum", "maximum", "items", "default"].includes(k)))
60
+ throw new Error("Unsupported native form constraint.");
61
+ const base = { fieldId, label: string(p.title) || fieldId, required: required.includes(fieldId) };
62
+ if (p.type === "string" && Array.isArray(p.enum) && p.enum.every(x => typeof x === "string"))
63
+ return { ...base, type: "select", options: p.enum.map((x, i) => ({ id: x, label: Array.isArray(p.enumNames) ? string(p.enumNames[i]) || x : x })) };
64
+ if (p.type === "string")
65
+ return { ...base, type: "text", sensitive: false };
66
+ if (p.type === "number")
67
+ return { ...base, type: "number", min: typeof p.minimum === "number" ? p.minimum : null, max: typeof p.maximum === "number" ? p.maximum : null };
68
+ if (p.type === "boolean")
69
+ return { ...base, type: "boolean" };
70
+ const items = record(p.items);
71
+ if (p.type === "array" && items.type === "string" && Array.isArray(items.enum) && items.enum.every(x => typeof x === "string") && Object.keys(items).every(k => ["type", "enum"].includes(k)))
72
+ return { ...base, type: "multiselect", options: items.enum.map(x => ({ id: x, label: x })) };
73
+ throw new Error("Unsupported native form field.");
74
+ });
75
+ if (!fields.length)
76
+ throw new Error("Empty native form schema.");
77
+ return { interactionId: randomUUID(), revision: "1", state: "pending", kind: "form", title, fields, canDismiss: true };
78
+ };
79
+ //# sourceMappingURL=interactions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interactions.js","sourceRoot":"","sources":["../../../../src/commands/controller/providers/interactions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEjD,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,WAA+B,EAAE,QAA6B,EAAQ,EAAE;IACvG,IAAI,WAAW,CAAC,KAAK,KAAK,SA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CAAC,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;YAAE,OAAO,EAAE,GAAG,IAAI,EAAE,IAAI,EAAE,aAAa,EAAE,OAAO,EAAE,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,CAAW,EAAE,KAAK,EAAE,CAAW,EAAE,CAAC,CAAC,EAAE,CAAC;QAChT,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;IACH,IAAI,CAAC,MAAM,CAAC,MAAM;QAAE,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;IACjE,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;AACzH,CAAC,CAAC"}
@@ -0,0 +1,28 @@
1
+ import type { Readable, Writable } from "node:stream";
2
+ import type { EventEmitter } from "node:events";
3
+ export type NativeObject = Record<string, unknown>;
4
+ export declare const record: (value: unknown) => NativeObject;
5
+ export declare const string: (value: unknown) => string;
6
+ export declare class NativeRpcError extends Error {
7
+ readonly code: number;
8
+ constructor(code: number, message: string);
9
+ }
10
+ export declare class NativeRpc {
11
+ private readonly child;
12
+ private readonly timeout;
13
+ private readonly lines;
14
+ private sequence;
15
+ private closed;
16
+ private readonly pending;
17
+ constructor(child: EventEmitter & {
18
+ stdin: Writable;
19
+ stdout: Readable;
20
+ }, onMessage: (value: NativeObject) => void, timeout?: number);
21
+ request(method: string, params: unknown): Promise<unknown>;
22
+ notify(method: string, params?: unknown): void;
23
+ respond(id: unknown, result: unknown): void;
24
+ reject(id: unknown, message: string): void;
25
+ private write;
26
+ private fail;
27
+ dispose(): void;
28
+ }
@@ -0,0 +1,85 @@
1
+ import { createInterface } from "node:readline";
2
+ export const record = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? value : {};
3
+ export const string = (value) => typeof value === "string" ? value : "";
4
+ export class NativeRpcError extends Error {
5
+ code;
6
+ constructor(code, message) {
7
+ super(message);
8
+ this.code = code;
9
+ }
10
+ }
11
+ export class NativeRpc {
12
+ child;
13
+ timeout;
14
+ lines;
15
+ sequence = 0;
16
+ closed = false;
17
+ pending = new Map();
18
+ constructor(child, onMessage, timeout = 30_000) {
19
+ this.child = child;
20
+ this.timeout = timeout;
21
+ this.lines = createInterface({ input: child.stdout, crlfDelay: Infinity });
22
+ this.lines.on("line", line => {
23
+ if (Buffer.byteLength(line) > 16 * 1024 * 1024) {
24
+ this.fail(new Error("Native protocol frame exceeds limit."));
25
+ return;
26
+ }
27
+ let message;
28
+ try {
29
+ message = record(JSON.parse(line));
30
+ }
31
+ catch {
32
+ this.fail(new Error("Invalid native protocol frame."));
33
+ return;
34
+ }
35
+ if (typeof message.method === "string") {
36
+ onMessage(message);
37
+ return;
38
+ }
39
+ if (typeof message.id !== "number")
40
+ return;
41
+ const waiter = this.pending.get(message.id);
42
+ if (!waiter)
43
+ return;
44
+ clearTimeout(waiter.timer);
45
+ this.pending.delete(message.id);
46
+ if (message.error !== undefined) {
47
+ const error = record(message.error);
48
+ waiter.reject(new NativeRpcError(typeof error.code === "number" ? error.code : -1, string(error.message) || "Native operation rejected."));
49
+ }
50
+ else
51
+ waiter.resolve(message.result);
52
+ });
53
+ child.once("error", error => this.fail(error));
54
+ child.once("close", () => this.fail(new Error("Native process closed; unconfirmed operations remain unknown.")));
55
+ child.stdin.on("error", error => this.fail(error));
56
+ }
57
+ request(method, params) {
58
+ if (this.closed)
59
+ return Promise.reject(new Error("Native process is closed."));
60
+ const id = ++this.sequence;
61
+ return new Promise((resolve, reject) => {
62
+ const timer = setTimeout(() => { this.pending.delete(id); reject(new Error(`Native ${method} response timed out; result is unknown.`)); }, this.timeout);
63
+ this.pending.set(id, { resolve, reject, timer });
64
+ try {
65
+ this.write({ id, method, params });
66
+ }
67
+ catch (error) {
68
+ clearTimeout(timer);
69
+ this.pending.delete(id);
70
+ reject(error);
71
+ }
72
+ });
73
+ }
74
+ notify(method, params) { this.write({ method, ...(params === undefined ? {} : { params }) }); }
75
+ respond(id, result) { this.write({ id, result }); }
76
+ reject(id, message) { this.write({ id, error: { code: -32601, message } }); }
77
+ write(value) { if (this.closed)
78
+ throw new Error("Native process is closed."); this.child.stdin.write(JSON.stringify(value) + "\n"); }
79
+ fail(error) { this.closed = true; for (const waiter of this.pending.values()) {
80
+ clearTimeout(waiter.timer);
81
+ waiter.reject(error);
82
+ } this.pending.clear(); }
83
+ dispose() { this.fail(new Error("Native transport closed.")); this.lines.close(); }
84
+ }
85
+ //# sourceMappingURL=native-rpc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"native-rpc.js","sourceRoot":"","sources":["../../../../src/commands/controller/providers/native-rpc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAkB,MAAM,eAAe,CAAC;AAKhE,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,KAAc,EAAgB,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAqB,CAAC,CAAC,CAAC,EAAE,CAAC;AAC1J,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,KAAc,EAAU,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CA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I,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;IAC5F,KAAK,CAAC,KAAc,IAAU,IAAI,IAAI,CAAC,MAAM;QAAE,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IACpJ,IAAI,CAAC,KAAY,IAAU,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;QAAC,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IAChL,OAAO,KAAW,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;CAC1F"}
@@ -0,0 +1,23 @@
1
+ import type { ProviderEntry } from "./types.js";
2
+ export declare const nativeEntryId: (session: string, item: string) => string;
3
+ export declare const readable: (value: unknown) => string;
4
+ export declare const limited: (value: string) => string;
5
+ export type ProviderArguments = {
6
+ sandbox?: "read-only" | "workspace-write";
7
+ approvalPolicy?: "untrusted" | "on-request" | "never";
8
+ effort?: "low" | "medium" | "high" | "xhigh" | "max";
9
+ permissionMode?: "default" | "acceptEdits" | "plan";
10
+ additionalDirectories?: string[];
11
+ };
12
+ export declare const parseProviderArguments: (provider: "codex" | "claude" | "copilot", args: readonly string[]) => ProviderArguments;
13
+ export declare class CodexProjection {
14
+ private readonly sessionId;
15
+ private readonly emit;
16
+ private readonly content;
17
+ private readonly tools;
18
+ constructor(sessionId: string, emit: (entry: ProviderEntry) => void);
19
+ private base;
20
+ delta(id: string, delta: string, kind: "assistant_message" | "reasoning"): void;
21
+ toolDelta(id: string, delta: string): void;
22
+ item(value: unknown, completed: boolean): void;
23
+ }