copilot-operator 0.1.84 → 0.1.88
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/api/operator.controller.js +113 -0
- package/dist/src/api/operator.service.js +329 -32
- package/dist/src/config/schema.js +32 -0
- package/dist/src/orchestrator/cardText.js +91 -0
- package/dist/src/orchestrator/kerriganRunner.js +914 -0
- package/dist/src/orchestrator/leadRunner.js +25 -15
- package/dist/src/orchestrator/planMode.js +6 -4
- package/dist/src/orchestrator/taskRunner.js +93 -40
- package/dist/src/plan/kerrigan.js +109 -4
- package/dist/src/plan/systemGuide.js +227 -4
- package/dist/src/protocol/kerriganSchema.js +175 -0
- package/dist/src/session/compose.js +5 -1
- package/dist/src/session/store.js +9 -0
- package/dist/src/transport/chatTransport.js +6 -2
- package/dist/src/transport/copilotTransport.js +226 -11
- package/dist/src/transport/keptWindow.js +247 -0
- package/dist/src/transport/locators.js +14 -4
- package/dist/src/vcs/git.js +72 -2
- package/dist/src/vcs/operatorGit.js +409 -0
- package/dist/web/404.html +2 -2
- package/dist/web/_next/static/chunks/1077.26ca37faa3726fff.js +1 -0
- package/dist/web/_next/static/chunks/1548.f5790cd11a91309f.js +1 -0
- package/dist/web/_next/static/chunks/2163.aa9d9b82fcde6caa.js +1 -0
- package/dist/web/_next/static/chunks/714.b7dbce98ba0b59a8.js +1 -0
- package/dist/web/_next/static/chunks/7220.0ca53eefec5d01ea.js +1 -0
- package/dist/web/_next/static/chunks/7921-8f6503aba840928a.js +1 -0
- package/dist/web/_next/static/chunks/8124-1dba8babfcfbc6e2.js +1 -0
- package/dist/web/_next/static/chunks/8584.9f3b058a8f67d3d7.js +1 -0
- package/dist/web/_next/static/chunks/9067.107f6164157e0aa1.js +1 -0
- package/dist/web/_next/static/chunks/9747.984a86f70f9cd973.js +1 -0
- package/dist/web/_next/static/chunks/app/layout-127e5af1ebf21876.js +1 -0
- package/dist/web/_next/static/chunks/app/page-b71841852e6b9ff5.js +1 -0
- package/dist/web/_next/static/chunks/app/settings/page-95069cb94d79e909.js +1 -0
- package/dist/web/_next/static/chunks/webpack-c015bbeb103c0856.js +1 -0
- package/dist/web/_next/static/css/0c5d6d5914aa3824.css +1 -0
- package/dist/web/defaults.html +2 -2
- package/dist/web/defaults.txt +8 -8
- package/dist/web/index.html +3 -3
- package/dist/web/index.txt +9 -9
- package/dist/web/queue.html +2 -2
- package/dist/web/queue.txt +9 -9
- package/dist/web/settings.html +2 -2
- package/dist/web/settings.txt +9 -9
- package/dist/web/system.html +2 -2
- package/dist/web/system.txt +9 -9
- package/package.json +176 -173
- package/prompts/kerrigan1.md +169 -0
- package/prompts/lead1.md +4 -1
- package/prompts/level1.md +8 -1
- package/dist/web/_next/static/chunks/1077.e0136d293069ccb8.js +0 -1
- package/dist/web/_next/static/chunks/1548.5cc0c57b00c2e44f.js +0 -1
- package/dist/web/_next/static/chunks/2163.2af0979126ae613a.js +0 -1
- package/dist/web/_next/static/chunks/714.410e2b61aa8c72b7.js +0 -1
- package/dist/web/_next/static/chunks/7220.2c4e5173a060769f.js +0 -1
- package/dist/web/_next/static/chunks/7921-3d21f385338afdf9.js +0 -1
- package/dist/web/_next/static/chunks/8124-1dc34be1646970a8.js +0 -1
- package/dist/web/_next/static/chunks/8584.61650a59d2bfa54d.js +0 -1
- package/dist/web/_next/static/chunks/9067.553056fc9b6cf80e.js +0 -1
- package/dist/web/_next/static/chunks/9747.d5826524bf4b714d.js +0 -1
- package/dist/web/_next/static/chunks/app/layout-b8a1e0075a48b025.js +0 -1
- package/dist/web/_next/static/chunks/app/page-13147b69cf336831.js +0 -1
- package/dist/web/_next/static/chunks/app/settings/page-e3909ef6c2d8e321.js +0 -1
- package/dist/web/_next/static/chunks/webpack-19a2d7161f23b21d.js +0 -1
- package/dist/web/_next/static/css/f152f27d6afce55c.css +0 -1
- /package/dist/web/_next/static/{WU_J4Ke1d3xVfpW2acqqf → hLBBsG7Kn4vd0p_J-47BJ}/_buildManifest.js +0 -0
- /package/dist/web/_next/static/{WU_J4Ke1d3xVfpW2acqqf → hLBBsG7Kn4vd0p_J-47BJ}/_ssgManifest.js +0 -0
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import { WindowClosed } from './copilotTransport.js';
|
|
2
|
+
/** The chat asked for the answer it was writing when the window closed. */
|
|
3
|
+
export const ASK_AGAIN = 'The browser window was closed while you were writing your answer to my last message, so your answer did not reach ' +
|
|
4
|
+
'me. Send that answer again, in full and in the same format as before.';
|
|
5
|
+
/** Put before a message sent again after the window closed while it was being sent. */
|
|
6
|
+
export const SENT_AGAIN = '(Sent again: the browser window was closed while this message was being sent. If it reached you already, answer ' +
|
|
7
|
+
'this copy only.)';
|
|
8
|
+
/** Why a message stopped when its window was closed and Settings say not to open it again. */
|
|
9
|
+
export const CLOSED_NOT_REOPENED = 'the browser window was closed; nothing more was sent';
|
|
10
|
+
export class KeptWindow {
|
|
11
|
+
inner;
|
|
12
|
+
speak;
|
|
13
|
+
/** Whether a message is at work: only then is a window closed under it opened again. */
|
|
14
|
+
atWork = false;
|
|
15
|
+
/** How many times it may still be opened again for the message at work, of how many. */
|
|
16
|
+
left = 0;
|
|
17
|
+
allowed = 0;
|
|
18
|
+
signal;
|
|
19
|
+
/** It is being opened again now. */
|
|
20
|
+
back = null;
|
|
21
|
+
/** Why the work on the message cannot go on in it: closed past the number, or not put back on its conversation. */
|
|
22
|
+
gaveUp = null;
|
|
23
|
+
/** How many times it has gone, so a call can tell it went while it ran. */
|
|
24
|
+
generation = 0;
|
|
25
|
+
/** Which of those the last message sent went out in: an answer is read only from the window its message went in. */
|
|
26
|
+
sentIn = -1;
|
|
27
|
+
constructor(inner, speak = () => undefined) {
|
|
28
|
+
this.inner = inner;
|
|
29
|
+
this.speak = speak;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* A message is at work: a window closed under it is opened again up to `times` times (`limits.reopenWindow`; 0 is
|
|
33
|
+
* none, as before 2026-11-13), and its Stop ends a reopening under way. Called for each message the runner takes.
|
|
34
|
+
*/
|
|
35
|
+
holdWindow(times, signal) {
|
|
36
|
+
this.atWork = true;
|
|
37
|
+
this.allowed = Math.max(0, Math.floor(times));
|
|
38
|
+
this.left = this.allowed;
|
|
39
|
+
this.signal = signal;
|
|
40
|
+
this.gaveUp = null;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* No message at work any more: a window closed now is the next message's to open. Waits for a reopening under way; the
|
|
44
|
+
* window is then what it is — open, or gone — for whoever holds it next.
|
|
45
|
+
*/
|
|
46
|
+
async releaseWindow() {
|
|
47
|
+
this.atWork = false;
|
|
48
|
+
await this.back?.catch(() => undefined);
|
|
49
|
+
this.gaveUp = null;
|
|
50
|
+
}
|
|
51
|
+
/** How many times the window was opened again for the message at work. */
|
|
52
|
+
reopenedTimes() {
|
|
53
|
+
return this.allowed - this.left;
|
|
54
|
+
}
|
|
55
|
+
/** Told by the window when it went (its `window-closed`): opened again at once while a message is at work. */
|
|
56
|
+
windowWent() {
|
|
57
|
+
this.generation += 1;
|
|
58
|
+
if (!this.atWork || this.back)
|
|
59
|
+
return;
|
|
60
|
+
this.back = this.bringBack().finally(() => {
|
|
61
|
+
this.back = null;
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
async bringBack() {
|
|
65
|
+
for (;;) {
|
|
66
|
+
if (this.signal?.aborted) {
|
|
67
|
+
this.gaveUp = new WindowClosed('the browser window was closed, and the work was stopped before it was opened again; nothing more was sent');
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (this.left <= 0) {
|
|
71
|
+
this.gaveUp = new WindowClosed(this.allowed === 0
|
|
72
|
+
? CLOSED_NOT_REOPENED
|
|
73
|
+
: `the browser window was closed ${this.allowed + 1} times while this message was at work; it was opened again ${this.allowed} time(s), ` +
|
|
74
|
+
'as many as Settings allow for one message (limits.reopenWindow), so nothing more was sent');
|
|
75
|
+
this.speak('window-not-reopened', { reason: this.gaveUp.message, times: this.allowed });
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
this.left -= 1;
|
|
79
|
+
const time = this.allowed - this.left;
|
|
80
|
+
const gen = this.generation;
|
|
81
|
+
this.speak('window-reopening', { time, of: this.allowed });
|
|
82
|
+
try {
|
|
83
|
+
const at = await this.inner.reopen({ signal: this.signal });
|
|
84
|
+
if (this.generation !== gen)
|
|
85
|
+
continue;
|
|
86
|
+
this.speak('window-reopened', { time, of: this.allowed, ...('chatId' in at ? { chatId: at.chatId } : {}) });
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
catch (e) {
|
|
90
|
+
// Closed again while it was being opened: another time, if there is one left.
|
|
91
|
+
if (this.generation !== gen && !this.signal?.aborted)
|
|
92
|
+
continue;
|
|
93
|
+
const why = e.message;
|
|
94
|
+
this.gaveUp = new WindowClosed(e instanceof WindowClosed
|
|
95
|
+
? why
|
|
96
|
+
: this.signal?.aborted
|
|
97
|
+
? 'the browser window was closed, and the work was stopped while it was being opened again; nothing more was sent'
|
|
98
|
+
: `the browser window was closed, and it could not be opened again on its conversation: ${why}`);
|
|
99
|
+
this.speak('window-not-reopened', { reason: this.gaveUp.message, times: time });
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/** Before a call that needs the window: one being opened again is waited for; one that cannot be, said. */
|
|
105
|
+
async ready() {
|
|
106
|
+
if (!this.back && this.atWork && !this.gaveUp && this.inner.closedOutside())
|
|
107
|
+
this.windowWent();
|
|
108
|
+
if (this.back)
|
|
109
|
+
await this.back;
|
|
110
|
+
if (this.gaveUp)
|
|
111
|
+
throw this.gaveUp;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* A call on the window, made again when the window went while it ran and was opened again; `again` says it is the
|
|
115
|
+
* second time. Bounded by the number of times it may be opened: past it, `ready` throws.
|
|
116
|
+
*/
|
|
117
|
+
async withWindow(call) {
|
|
118
|
+
let again = false;
|
|
119
|
+
for (;;) {
|
|
120
|
+
await this.ready();
|
|
121
|
+
const gen = this.generation;
|
|
122
|
+
try {
|
|
123
|
+
return await call(again);
|
|
124
|
+
}
|
|
125
|
+
catch (e) {
|
|
126
|
+
const went = gen !== this.generation || this.inner.closedOutside();
|
|
127
|
+
if (!went || !this.atWork)
|
|
128
|
+
throw e;
|
|
129
|
+
again = true;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
async sendAndConfirm(text, attachments = [], maxAttempts) {
|
|
134
|
+
let wentIn = -1;
|
|
135
|
+
const before = await this.withWindow(async (again) => {
|
|
136
|
+
wentIn = this.generation;
|
|
137
|
+
if (again)
|
|
138
|
+
this.speak('message-sent-again', { chars: text.length });
|
|
139
|
+
return await this.inner.sendAndConfirm(again ? `${SENT_AGAIN}\n\n${text}` : text, attachments, maxAttempts);
|
|
140
|
+
});
|
|
141
|
+
// The window it went out in: closed as it was taken, its answer is asked for again (see `waitForReply`).
|
|
142
|
+
this.sentIn = wentIn;
|
|
143
|
+
return before;
|
|
144
|
+
}
|
|
145
|
+
async waitForReply(previousTurns) {
|
|
146
|
+
return await this.withWindow(async (again) => {
|
|
147
|
+
if (!again && this.sentIn === this.generation)
|
|
148
|
+
return await this.inner.waitForReply(previousTurns);
|
|
149
|
+
// The window its message went out in is gone, and with it the answer being written: asked for again.
|
|
150
|
+
const asked = this.generation;
|
|
151
|
+
const before = await this.inner.sendAndConfirm(ASK_AGAIN);
|
|
152
|
+
this.sentIn = asked;
|
|
153
|
+
this.speak('reply-asked-again', { text: ASK_AGAIN });
|
|
154
|
+
if (this.generation !== asked)
|
|
155
|
+
throw new WindowClosed('closed again as the answer was asked for');
|
|
156
|
+
return await this.inner.waitForReply(before);
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
/** Whether the window is gone for the work: closed, and not being opened again, or past opening again. */
|
|
160
|
+
closedOutside() {
|
|
161
|
+
if (this.gaveUp)
|
|
162
|
+
return true;
|
|
163
|
+
if (this.back)
|
|
164
|
+
return false;
|
|
165
|
+
return this.inner.closedOutside();
|
|
166
|
+
}
|
|
167
|
+
// --- the rest, as the window does them; made again in a window opened again under the work ----------------------
|
|
168
|
+
open() {
|
|
169
|
+
return this.inner.open();
|
|
170
|
+
}
|
|
171
|
+
async close() {
|
|
172
|
+
this.atWork = false;
|
|
173
|
+
await this.back?.catch(() => undefined);
|
|
174
|
+
await this.inner.close();
|
|
175
|
+
}
|
|
176
|
+
reopen(opts) {
|
|
177
|
+
return this.inner.reopen(opts);
|
|
178
|
+
}
|
|
179
|
+
isOpen() {
|
|
180
|
+
return this.inner.isOpen();
|
|
181
|
+
}
|
|
182
|
+
ensureSignedIn(...a) {
|
|
183
|
+
return this.inner.ensureSignedIn(...a);
|
|
184
|
+
}
|
|
185
|
+
signOut(...a) {
|
|
186
|
+
return this.inner.signOut(...a);
|
|
187
|
+
}
|
|
188
|
+
gotoChatAs(...a) {
|
|
189
|
+
return this.inner.gotoChatAs(...a);
|
|
190
|
+
}
|
|
191
|
+
findAccountsInPage(...a) {
|
|
192
|
+
return this.inner.findAccountsInPage(...a);
|
|
193
|
+
}
|
|
194
|
+
dumpFailure(...a) {
|
|
195
|
+
return this.inner.dumpFailure(...a);
|
|
196
|
+
}
|
|
197
|
+
recentCrash(...a) {
|
|
198
|
+
return this.inner.recentCrash(...a);
|
|
199
|
+
}
|
|
200
|
+
showNotice(...a) {
|
|
201
|
+
return this.withWindow(() => this.inner.showNotice(...a));
|
|
202
|
+
}
|
|
203
|
+
clearNotice(...a) {
|
|
204
|
+
return this.withWindow(() => this.inner.clearNotice(...a));
|
|
205
|
+
}
|
|
206
|
+
newChat(...a) {
|
|
207
|
+
return this.withWindow(() => this.inner.newChat(...a));
|
|
208
|
+
}
|
|
209
|
+
openConversation(...a) {
|
|
210
|
+
return this.withWindow(() => this.inner.openConversation(...a));
|
|
211
|
+
}
|
|
212
|
+
openConversationByName(...a) {
|
|
213
|
+
return this.withWindow(() => this.inner.openConversationByName(...a));
|
|
214
|
+
}
|
|
215
|
+
currentChatId(...a) {
|
|
216
|
+
return this.withWindow(() => this.inner.currentChatId(...a));
|
|
217
|
+
}
|
|
218
|
+
ensureOnChat(...a) {
|
|
219
|
+
return this.withWindow(() => this.inner.ensureOnChat(...a));
|
|
220
|
+
}
|
|
221
|
+
nameChat(...a) {
|
|
222
|
+
return this.withWindow(() => this.inner.nameChat(...a));
|
|
223
|
+
}
|
|
224
|
+
selectModel(...a) {
|
|
225
|
+
return this.withWindow(() => this.inner.selectModel(...a));
|
|
226
|
+
}
|
|
227
|
+
currentModel(...a) {
|
|
228
|
+
return this.withWindow(() => this.inner.currentModel(...a));
|
|
229
|
+
}
|
|
230
|
+
listModels(...a) {
|
|
231
|
+
return this.withWindow(() => this.inner.listModels(...a));
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
/** A window kept for the work, its `window-closed` heard as it happens. */
|
|
235
|
+
export function keptWindow(make, opts) {
|
|
236
|
+
let kept = null;
|
|
237
|
+
const inner = make({
|
|
238
|
+
...opts,
|
|
239
|
+
onEvent: (event, detail) => {
|
|
240
|
+
opts.onEvent?.(event, detail);
|
|
241
|
+
if (event === 'window-closed')
|
|
242
|
+
kept?.windowWent();
|
|
243
|
+
},
|
|
244
|
+
});
|
|
245
|
+
kept = new KeptWindow(inner, (event, detail) => opts.onEvent?.(event, detail));
|
|
246
|
+
return kept;
|
|
247
|
+
}
|
|
@@ -382,13 +382,23 @@ export const Surface = {
|
|
|
382
382
|
/** Chips that only the consumer surface shows. */
|
|
383
383
|
consumerMarkers: ['Shop', 'Play'],
|
|
384
384
|
};
|
|
385
|
-
/**
|
|
385
|
+
/**
|
|
386
|
+
* Chat URL. Microsoft is consolidating this to copilot.cloud.microsoft.
|
|
387
|
+
*
|
|
388
|
+
* The bot starts on `origin`; from then on a window goes to the chat's addresses on the host it found the chat on
|
|
389
|
+
* (`chatOrigin` in copilotTransport.ts), not through the old host's redirect: on 2026-11-17 the work machine's
|
|
390
|
+
* `m365.cloud.microsoft/chat` ended on `copilot.cloud.microsoft/home?es=SSR&redirfrom=mcmToCcm`, Copilot's home page,
|
|
391
|
+
* with no box to write in.
|
|
392
|
+
*/
|
|
386
393
|
export const Url = {
|
|
387
394
|
chat: 'https://m365.cloud.microsoft/chat',
|
|
388
|
-
|
|
395
|
+
origin: 'https://m365.cloud.microsoft',
|
|
396
|
+
/** A new chat, on whichever host. "New chat" is an anchor, so a plain navigation is equivalent to clicking it. */
|
|
397
|
+
newChatPath: '/chat?es=SSR',
|
|
389
398
|
newChat: 'https://m365.cloud.microsoft/chat?es=SSR',
|
|
390
|
-
/** Every conversation has a stable address: /chat/conversation/<uuid
|
|
391
|
-
|
|
399
|
+
/** Every conversation has a stable address: /chat/conversation/<uuid>, on whichever host. */
|
|
400
|
+
conversationPath: (id) => `/chat/conversation/${id}?es=SSR`,
|
|
401
|
+
conversation: (id, origin = 'https://m365.cloud.microsoft') => `${origin}/chat/conversation/${id}?es=SSR`,
|
|
392
402
|
/** Full chat list, used as the last resort when looking a chat up by name. */
|
|
393
403
|
allChats: 'https://m365.cloud.microsoft/chat/all?es=SSR',
|
|
394
404
|
};
|
package/dist/src/vcs/git.js
CHANGED
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
* - Nothing runs through a shell. `execFile` takes an argument list, so a branch name or a
|
|
16
16
|
* commit message cannot turn into another command.
|
|
17
17
|
*/
|
|
18
|
-
import { execFile, spawnSync } from 'node:child_process';
|
|
18
|
+
import { execFile, spawn, spawnSync } from 'node:child_process';
|
|
19
|
+
import { StringDecoder } from 'node:string_decoder';
|
|
19
20
|
import { existsSync, statSync } from 'node:fs';
|
|
20
21
|
import { readFile, stat } from 'node:fs/promises';
|
|
21
22
|
import { createHash } from 'node:crypto';
|
|
@@ -43,6 +44,12 @@ export const SAFE_GIT = [
|
|
|
43
44
|
function noHooksDir() {
|
|
44
45
|
return process.env.SystemRoot ? join(process.env.SystemRoot, 'System32', 'copilot-operator-no-hooks') : '/nonexistent';
|
|
45
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* The settings of the operator's own commit and push from the Git view (2026-11-11), the only git of the bot that runs
|
|
49
|
+
* the repository's hooks — and only once `vcs/operatorGit.ts` has found them to be the project's own, or the operator
|
|
50
|
+
* has said to run them. Still no fsmonitor program and no untracked cache.
|
|
51
|
+
*/
|
|
52
|
+
export const OWN_HOOKS_GIT = ['-c', 'core.fsmonitor=false', '-c', 'core.untrackedCache=false'];
|
|
46
53
|
/** Runs one git command in a directory. Never throws: the caller decides what a failure means. */
|
|
47
54
|
export function git(cwd, args, timeoutMs = 60_000, env,
|
|
48
55
|
/**
|
|
@@ -55,7 +62,7 @@ opts = {}) {
|
|
|
55
62
|
return new Promise((resolve) => {
|
|
56
63
|
let timedOut = false;
|
|
57
64
|
let timer;
|
|
58
|
-
const child = execFile('git', [...SAFE_GIT, ...args], { cwd, timeout: opts.killTree ? 0 : timeoutMs, windowsHide: opts.windowsHide ?? true, maxBuffer: 8 * 1024 * 1024, ...(env ? { env } : {}) }, (error, stdout, stderr) => {
|
|
65
|
+
const child = execFile('git', [...(opts.ownHooks ? OWN_HOOKS_GIT : SAFE_GIT), ...args], { cwd, timeout: opts.killTree ? 0 : timeoutMs, windowsHide: opts.windowsHide ?? true, maxBuffer: 8 * 1024 * 1024, ...(env ? { env } : {}) }, (error, stdout, stderr) => {
|
|
59
66
|
if (timer)
|
|
60
67
|
clearTimeout(timer);
|
|
61
68
|
const code = error?.code;
|
|
@@ -78,6 +85,69 @@ opts = {}) {
|
|
|
78
85
|
}
|
|
79
86
|
});
|
|
80
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* One git command whose output is read as it comes, stdout and stderr together in the order they arrive (2026-11-11):
|
|
90
|
+
* the operator's commit and push, whose hooks and remote talk for as long as they need, and whose every line the Git
|
|
91
|
+
* view shows while it runs. `ownHooks` runs the repository's hooks (see `OWN_HOOKS_GIT`); otherwise `SAFE_GIT`. Nothing
|
|
92
|
+
* is read from stdin, so a hook that waits for an answer gets none and ends. On the timeout git and everything it
|
|
93
|
+
* started are stopped. Never throws.
|
|
94
|
+
*/
|
|
95
|
+
export function gitLive(cwd, args, opts) {
|
|
96
|
+
const max = opts.maxChars ?? 200_000;
|
|
97
|
+
return new Promise((resolveLive) => {
|
|
98
|
+
let output = '';
|
|
99
|
+
let cut = false;
|
|
100
|
+
let timedOut = false;
|
|
101
|
+
let settled = false;
|
|
102
|
+
const add = (text) => {
|
|
103
|
+
if (!text)
|
|
104
|
+
return;
|
|
105
|
+
output += text;
|
|
106
|
+
if (output.length > max) {
|
|
107
|
+
output = output.slice(output.length - max);
|
|
108
|
+
cut = true;
|
|
109
|
+
}
|
|
110
|
+
opts.onOutput?.(output, cut);
|
|
111
|
+
};
|
|
112
|
+
const done = (r) => {
|
|
113
|
+
if (settled)
|
|
114
|
+
return;
|
|
115
|
+
settled = true;
|
|
116
|
+
clearTimeout(timer);
|
|
117
|
+
resolveLive({ ...r, output, cut, timedOut });
|
|
118
|
+
};
|
|
119
|
+
let child;
|
|
120
|
+
try {
|
|
121
|
+
child = spawn('git', [...(opts.ownHooks ? OWN_HOOKS_GIT : SAFE_GIT), ...args], { cwd, windowsHide: opts.windowsHide ?? true, stdio: ['ignore', 'pipe', 'pipe'], ...(opts.env ? { env: opts.env } : {}) });
|
|
122
|
+
}
|
|
123
|
+
catch (e) {
|
|
124
|
+
add(`git could not be started: ${e.message}\n`);
|
|
125
|
+
resolveLive({ ok: false, code: 1, output, cut, timedOut });
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
const out = new StringDecoder('utf8');
|
|
129
|
+
const err = new StringDecoder('utf8');
|
|
130
|
+
child.stdout?.on('data', (b) => add(out.write(b)));
|
|
131
|
+
child.stderr?.on('data', (b) => add(err.write(b)));
|
|
132
|
+
const timer = setTimeout(() => {
|
|
133
|
+
timedOut = true;
|
|
134
|
+
add(`\ngit gave up after ${Math.round(opts.timeoutMs / 1000)} s\n`);
|
|
135
|
+
if (process.platform === 'win32' && child.pid)
|
|
136
|
+
execFile('taskkill', ['/PID', String(child.pid), '/T', '/F'], { windowsHide: true }, () => undefined);
|
|
137
|
+
else
|
|
138
|
+
child.kill('SIGKILL');
|
|
139
|
+
}, opts.timeoutMs);
|
|
140
|
+
child.on('error', (e) => {
|
|
141
|
+
add(`git could not be started: ${e.message}\n`);
|
|
142
|
+
done({ ok: false, code: 1 });
|
|
143
|
+
});
|
|
144
|
+
child.on('close', (code) => {
|
|
145
|
+
add(out.end());
|
|
146
|
+
add(err.end());
|
|
147
|
+
done({ ok: code === 0 && !timedOut, code: typeof code === 'number' ? code : 1 });
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
}
|
|
81
151
|
/**
|
|
82
152
|
* One git command, synchronously, for the gate: it decides before a step starts, in a function with no await to give
|
|
83
153
|
* (see `exec/scriptFiles.ts`). Only reading commands go through it. Never throws: a git that is missing, fails or
|