@tienne/gestalt 0.157.0 → 0.159.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.
- package/dist/package.json +1 -1
- package/dist/plugin/.codex-plugin/plugin.json +1 -1
- package/dist/plugin/skills/conductor/SKILL.md +16 -62
- package/dist/src/cli/commands/conductor-results.d.ts.map +1 -1
- package/dist/src/cli/commands/conductor-results.js +7 -2
- package/dist/src/cli/commands/conductor-results.js.map +1 -1
- package/dist/src/cli/commands/conductor.d.ts +24 -0
- package/dist/src/cli/commands/conductor.d.ts.map +1 -1
- package/dist/src/cli/commands/conductor.js +349 -47
- package/dist/src/cli/commands/conductor.js.map +1 -1
- package/dist/src/cli/index.d.ts.map +1 -1
- package/dist/src/cli/index.js +69 -7
- package/dist/src/cli/index.js.map +1 -1
- package/dist/src/conductor/adapters.d.ts.map +1 -1
- package/dist/src/conductor/adapters.js +1 -0
- package/dist/src/conductor/adapters.js.map +1 -1
- package/dist/src/conductor/archive.d.ts +109 -2
- package/dist/src/conductor/archive.d.ts.map +1 -1
- package/dist/src/conductor/archive.js +443 -39
- package/dist/src/conductor/archive.js.map +1 -1
- package/dist/src/conductor/bot-approval.d.ts +26 -0
- package/dist/src/conductor/bot-approval.d.ts.map +1 -0
- package/dist/src/conductor/bot-approval.js +78 -0
- package/dist/src/conductor/bot-approval.js.map +1 -0
- package/dist/src/conductor/bot-github.d.ts +58 -0
- package/dist/src/conductor/bot-github.d.ts.map +1 -0
- package/dist/src/conductor/bot-github.js +127 -0
- package/dist/src/conductor/bot-github.js.map +1 -0
- package/dist/src/conductor/bot-owner.d.ts +22 -0
- package/dist/src/conductor/bot-owner.d.ts.map +1 -0
- package/dist/src/conductor/bot-owner.js +125 -0
- package/dist/src/conductor/bot-owner.js.map +1 -0
- package/dist/src/conductor/engine.d.ts +36 -1
- package/dist/src/conductor/engine.d.ts.map +1 -1
- package/dist/src/conductor/engine.js +120 -8
- package/dist/src/conductor/engine.js.map +1 -1
- package/dist/src/conductor/fold.d.ts +3 -1
- package/dist/src/conductor/fold.d.ts.map +1 -1
- package/dist/src/conductor/fold.js +142 -19
- package/dist/src/conductor/fold.js.map +1 -1
- package/dist/src/conductor/gates.d.ts +9 -1
- package/dist/src/conductor/gates.d.ts.map +1 -1
- package/dist/src/conductor/gates.js +19 -1
- package/dist/src/conductor/gates.js.map +1 -1
- package/dist/src/conductor/handoff.d.ts +1 -0
- package/dist/src/conductor/handoff.d.ts.map +1 -1
- package/dist/src/conductor/handoff.js +1 -1
- package/dist/src/conductor/handoff.js.map +1 -1
- package/dist/src/conductor/intake.d.ts +2 -0
- package/dist/src/conductor/intake.d.ts.map +1 -1
- package/dist/src/conductor/intake.js +21 -3
- package/dist/src/conductor/intake.js.map +1 -1
- package/dist/src/conductor/jira.d.ts +2 -0
- package/dist/src/conductor/jira.d.ts.map +1 -1
- package/dist/src/conductor/jira.js.map +1 -1
- package/dist/src/conductor/launcher.d.ts.map +1 -1
- package/dist/src/conductor/launcher.js +2 -0
- package/dist/src/conductor/launcher.js.map +1 -1
- package/dist/src/conductor/pr-watch.d.ts.map +1 -1
- package/dist/src/conductor/pr-watch.js +1 -2
- package/dist/src/conductor/pr-watch.js.map +1 -1
- package/dist/src/conductor/result.d.ts.map +1 -1
- package/dist/src/conductor/result.js +21 -0
- package/dist/src/conductor/result.js.map +1 -1
- package/dist/src/conductor/store.d.ts +26 -2
- package/dist/src/conductor/store.d.ts.map +1 -1
- package/dist/src/conductor/store.js +82 -14
- package/dist/src/conductor/store.js.map +1 -1
- package/dist/src/conductor/types.d.ts +25 -0
- package/dist/src/conductor/types.d.ts.map +1 -1
- package/dist/src/conductor/types.js.map +1 -1
- package/dist/src/core/config.d.ts +23 -0
- package/dist/src/core/config.d.ts.map +1 -1
- package/dist/src/core/config.js +5 -0
- package/dist/src/core/config.js.map +1 -1
- package/package.json +1 -1
- package/plugin/.codex-plugin/plugin.json +1 -1
- package/plugin/.mcp.json +1 -1
- package/plugin/mcp.json +1 -1
- package/plugin/skills/conductor/SKILL.md +16 -62
|
@@ -2,11 +2,14 @@ import { randomUUID } from 'node:crypto';
|
|
|
2
2
|
import { mkdirSync, readFileSync, realpathSync, rmSync, statSync } from 'node:fs';
|
|
3
3
|
import { homedir } from 'node:os';
|
|
4
4
|
import { dirname, join, resolve } from 'node:path';
|
|
5
|
+
import { handleGithubOrder, readGithubOrder } from '../../conductor/bot-github.js';
|
|
6
|
+
import { approvalMessage, matchMergeGate, readBotPolicy, readMergeEvidence, verifyMergeApproval, } from '../../conductor/bot-approval.js';
|
|
7
|
+
import { assertBotOwner, changeBotOwner, currentBotOwner, targetBotOwner, readBotOwnership, } from '../../conductor/bot-owner.js';
|
|
5
8
|
import { loadConfig, WAIT_MAX_SEC_LIMIT } from '../../core/config.js';
|
|
6
9
|
import { getVersion } from '../../core/version.js';
|
|
7
10
|
import { writeJsonAtomic } from '../../core/json-file.js';
|
|
8
11
|
import { fileDeploySource, fileQueue, GhAccounts, GhAccountSwitcher, GhPrStateSource, GhPrWatchSource, prWatchTargets, hostJiraClient, hostSlackClient, writeDeploySignal, writeQueueMessage, } from '../../conductor/adapters.js';
|
|
9
|
-
import { acquireLock, afterHumanMerge, rateLimitEntries, deliverGateDecision, inboxDirOf, tick, staleTickWarning, writeReport, } from '../../conductor/engine.js';
|
|
12
|
+
import { acquireLock, afterHumanMerge, rateLimitEntries, deliverGateDecision, recordGateDelivery, inboxDirOf, tick, staleTickWarning, writeReport, } from '../../conductor/engine.js';
|
|
10
13
|
import { orderActivity } from '../../conductor/activity.js';
|
|
11
14
|
import { existingRepoContext, repoContextPath } from '../../conductor/context.js';
|
|
12
15
|
import { currentSessionId, handoffNotice, handoffRecordPath, handoffStatus, isSessionId, resolveHandoffModel, launchHandoff, readCompactions, readHandoffRecord, readSessionRegisteredAt, recordHandoff, registerSession, writeHandoffFile, } from '../../conductor/handoff.js';
|
|
@@ -14,7 +17,7 @@ import { findActiveConductor, readSupersededRecord, supersededRecordPath, supers
|
|
|
14
17
|
import { readAutoCompactWindow } from '../../conductor/claude-settings.js';
|
|
15
18
|
import { readRecentEvents } from '../../conductor/recent-events.js';
|
|
16
19
|
import { removeOrderRefCopies } from '../../conductor/ref-copy.js';
|
|
17
|
-
import {
|
|
20
|
+
import { archiveAndCompress, DEFAULT_ARCHIVE_DAYS, PROMPTS_DIR, pruneArchive, dailyArchiveFor, } from '../../conductor/archive.js';
|
|
18
21
|
import { resolveGate } from '../../conductor/gates.js';
|
|
19
22
|
import { terminalText } from '../../conductor/terminal-text.js';
|
|
20
23
|
import { intakeOrder, ISSUE_KEY_RE, KNOWN_SKILLS, oneLine } from '../../conductor/intake.js';
|
|
@@ -37,7 +40,7 @@ function open(opts) {
|
|
|
37
40
|
return { store: ConductorStore.open(resolveStateDir(opts.stateDir, config)), config };
|
|
38
41
|
}
|
|
39
42
|
function launchersFor(ctx, env) {
|
|
40
|
-
const promptDir = join(ctx.store.dir,
|
|
43
|
+
const promptDir = join(ctx.store.dir, PROMPTS_DIR);
|
|
41
44
|
const orca = detectOrca(env);
|
|
42
45
|
const launchers = {
|
|
43
46
|
subagent: new SubagentLauncher({ promptDir }),
|
|
@@ -123,6 +126,14 @@ export function conductorOrderAddCommand(opts) {
|
|
|
123
126
|
}
|
|
124
127
|
: {}),
|
|
125
128
|
...(opts.pr ? { prRef: prRef(opts.pr) } : {}),
|
|
129
|
+
...(opts.deploys?.length
|
|
130
|
+
? {
|
|
131
|
+
deploys: opts.deploys
|
|
132
|
+
.flatMap((v) => v.split(','))
|
|
133
|
+
.map((v) => v.trim())
|
|
134
|
+
.filter(Boolean),
|
|
135
|
+
}
|
|
136
|
+
: {}),
|
|
126
137
|
}, { defaultScope: ctx.config.defaultScope }, { trusted: true });
|
|
127
138
|
if ('removedAt' in out) {
|
|
128
139
|
if (opts.json)
|
|
@@ -203,17 +214,26 @@ export async function conductorArchiveCommand(opts) {
|
|
|
203
214
|
try {
|
|
204
215
|
const ctx = open(opts);
|
|
205
216
|
assertConductorSession(ctx, 'archive');
|
|
217
|
+
if (opts.before !== undefined)
|
|
218
|
+
throw new Error('--before는 archive prune에서만 받아요');
|
|
206
219
|
// Number('')가 0이라 빈 값이 끝난 주문을 전부 옮기지 않게 숫자만 받는다
|
|
207
220
|
if (opts.olderThan !== undefined && !/^\d+$/.test(opts.olderThan))
|
|
208
221
|
throw new Error(`--older-than은 0 이상의 정수(일)로 주세요: ${opts.olderThan}`);
|
|
209
222
|
const days = opts.olderThan === undefined ? DEFAULT_ARCHIVE_DAYS : Number(opts.olderThan);
|
|
210
223
|
if (!Number.isSafeInteger(days))
|
|
211
224
|
throw new Error(`--older-than은 0 이상의 정수(일)로 주세요: ${opts.olderThan}`);
|
|
212
|
-
|
|
225
|
+
// 묶기는 보관을 마쳐 잠금을 놓은 뒤 다시 잡는다. 그사이 tick이 잡았으면 다음 보관 때 묶는다
|
|
226
|
+
const result = await archiveAndCompress(ctx.store.dir, {
|
|
227
|
+
days,
|
|
228
|
+
dryRun: opts.dryRun === true,
|
|
229
|
+
now: () => new Date(),
|
|
230
|
+
});
|
|
213
231
|
if (result.status === 'locked')
|
|
214
|
-
throw
|
|
232
|
+
throw lockedError(result.holder);
|
|
215
233
|
if (opts.json)
|
|
216
234
|
return print(result);
|
|
235
|
+
const months = result.status === 'archived' ? result.compressed : [];
|
|
236
|
+
const warnings = result.status === 'archived' ? result.warnings : [];
|
|
217
237
|
const verb = result.status === 'dry-run' ? '옮길' : '옮긴';
|
|
218
238
|
console.log(`${verb} 주문 ${result.orders.length}개, 지운 주문의 이벤트 ${result.removed.length}개, 버린 컨덕터 게이트 ${result.gates.length}개 (${days}일 기준)`);
|
|
219
239
|
for (const o of result.orders)
|
|
@@ -222,14 +242,52 @@ export async function conductorArchiveCommand(opts) {
|
|
|
222
242
|
console.log(` ${r.id} removed archive/${r.month}/${r.id}`);
|
|
223
243
|
for (const b of result.blocked)
|
|
224
244
|
console.log(`못 옮겨요: ${b.reason}`);
|
|
225
|
-
if (result.status === 'archived')
|
|
226
|
-
|
|
227
|
-
|
|
245
|
+
if (result.status === 'archived') {
|
|
246
|
+
const { prompts, activity, handoffs } = result.swept;
|
|
247
|
+
if (prompts + activity + handoffs > 0)
|
|
248
|
+
console.log(`지운 운영 파일: prompts ${prompts}개, activity ${activity}개, handoffs ${handoffs}개`);
|
|
249
|
+
}
|
|
250
|
+
for (const m of months)
|
|
251
|
+
console.log(`묶었어요: archive/${m}.tar.gz`);
|
|
252
|
+
for (const w of warnings)
|
|
253
|
+
console.log(`경고: ${w}`);
|
|
228
254
|
}
|
|
229
255
|
catch (e) {
|
|
230
256
|
exitWithError(e);
|
|
231
257
|
}
|
|
232
258
|
}
|
|
259
|
+
function lockedError(holder) {
|
|
260
|
+
return new Error(`다른 프로세스(${holder ?? '알 수 없음'})가 저장소를 쓰는 중이에요. 잠시 뒤 다시 불러 주세요`);
|
|
261
|
+
}
|
|
262
|
+
/** `archive [action]`을 나눈다. 모르는 동작도 다른 오류처럼 exitWithError로 끝낸다 */
|
|
263
|
+
export async function conductorArchiveAction(action, opts) {
|
|
264
|
+
if (action === undefined)
|
|
265
|
+
return conductorArchiveCommand(opts);
|
|
266
|
+
if (action === 'prune')
|
|
267
|
+
return conductorArchivePruneCommand(opts);
|
|
268
|
+
exitWithError(new Error(`모르는 동작이에요: ${action}. prune만 받아요`));
|
|
269
|
+
}
|
|
270
|
+
/** `before`보다 앞선 달의 보관소를 지운다. 자동으로는 안 돌고 사람이 부른다 */
|
|
271
|
+
export function conductorArchivePruneCommand(opts) {
|
|
272
|
+
run(() => {
|
|
273
|
+
const ctx = open(opts);
|
|
274
|
+
assertConductorSession(ctx, 'archive prune');
|
|
275
|
+
if (opts.before === undefined)
|
|
276
|
+
throw new Error('archive prune은 --before <YYYY-MM>이 필요해요');
|
|
277
|
+
if (opts.olderThan !== undefined)
|
|
278
|
+
throw new Error('--older-than은 archive prune에서 안 받아요');
|
|
279
|
+
const before = opts.before;
|
|
280
|
+
const result = pruneArchive(ctx.store.dir, before, { dryRun: opts.dryRun === true });
|
|
281
|
+
if (result.status === 'locked')
|
|
282
|
+
throw lockedError(result.holder);
|
|
283
|
+
if (opts.json)
|
|
284
|
+
return print(result);
|
|
285
|
+
const verb = result.status === 'dry-run' ? '지울' : '지운';
|
|
286
|
+
console.log(`${verb} 달 ${result.months.length}개 (${before}보다 앞선 달)`);
|
|
287
|
+
for (const p of result.paths)
|
|
288
|
+
console.log(` ${p}`);
|
|
289
|
+
});
|
|
290
|
+
}
|
|
233
291
|
export function conductorOrderShowCommand(id, opts) {
|
|
234
292
|
run(() => {
|
|
235
293
|
const { store } = open(opts);
|
|
@@ -248,6 +306,12 @@ export function conductorOrderShowCommand(id, opts) {
|
|
|
248
306
|
console.log(`설명: ${order.description ? terminalText(order.description) : '없음'}`);
|
|
249
307
|
console.log(`체인: ${order.skillChain.join(' → ')}`);
|
|
250
308
|
console.log(`PR: ${order.prRef ? terminalText(order.prRef) : '없음'}`);
|
|
309
|
+
if (order.deploys?.length) {
|
|
310
|
+
const recorded = order.deploysRecordedAt
|
|
311
|
+
? ` (${order.deploysRecordedAt}에 배포 성공 기록)`
|
|
312
|
+
: '';
|
|
313
|
+
console.log(`배포 대상: ${order.deploys.join(', ')}${recorded}`);
|
|
314
|
+
}
|
|
251
315
|
if (order.humanOwnedAt)
|
|
252
316
|
console.log(`사람이 넘겨받은 시각: ${order.humanOwnedAt}`);
|
|
253
317
|
if (order.cancelReason)
|
|
@@ -383,6 +447,9 @@ export function conductorStatusCommand(opts) {
|
|
|
383
447
|
...(o.baseBranch ? { baseBranch: o.baseBranch } : {}),
|
|
384
448
|
...(o.prRef ? { pr: o.prRef } : {}),
|
|
385
449
|
...(o.issueKey ? { issue: o.issueKey } : {}),
|
|
450
|
+
...(o.deploys?.length ? { deploys: o.deploys } : {}),
|
|
451
|
+
...(o.deployResult ? { deployResult: o.deployResult } : {}),
|
|
452
|
+
...(o.deploysRecordedAt ? { deploysRecordedAt: o.deploysRecordedAt } : {}),
|
|
386
453
|
// 상태는 merged 그대로라 바깥 화면이 끝난 주문과 배포 대기를 이 값으로 가른다
|
|
387
454
|
awaitingDeploy: isAwaitingDeploy(o),
|
|
388
455
|
...(o.humanOwnedAt ? { humanOwnedAt: o.humanOwnedAt } : {}),
|
|
@@ -465,7 +532,10 @@ function conductorSummary(ctx) {
|
|
|
465
532
|
w.stopReason === 'disconnected' &&
|
|
466
533
|
store.order(w.orderId)?.workerId === w.id &&
|
|
467
534
|
!TERMINAL_ORDER_STATUSES.has(store.order(w.orderId).status)).length;
|
|
468
|
-
const
|
|
535
|
+
const botOwner = readBotOwnership(store.dir).active;
|
|
536
|
+
const session = botOwner
|
|
537
|
+
? undefined
|
|
538
|
+
: findActiveConductor(store.dir, '', Date.now(), activeConductorWindowMs(config));
|
|
469
539
|
return {
|
|
470
540
|
pollIntervalSec: config.pollIntervalSec,
|
|
471
541
|
maxWorkers: config.maxConcurrentWorkers,
|
|
@@ -473,6 +543,7 @@ function conductorSummary(ctx) {
|
|
|
473
543
|
queuedOrders: store.queuedOrders().length,
|
|
474
544
|
prWatchRepos: config.prWatchRepos,
|
|
475
545
|
disconnectedWorkers: disconnected,
|
|
546
|
+
...(botOwner ? { botOwner } : {}),
|
|
476
547
|
...(session
|
|
477
548
|
? {
|
|
478
549
|
compactions: readCompactions(store.dir, session.sessionId).count,
|
|
@@ -503,8 +574,9 @@ export async function conductorTickCommand(opts) {
|
|
|
503
574
|
try {
|
|
504
575
|
const ctx = open(opts);
|
|
505
576
|
assertConductorSession(ctx, 'tick');
|
|
506
|
-
const
|
|
507
|
-
const
|
|
577
|
+
const caller = await tickBotCaller(ctx);
|
|
578
|
+
const sessionId = await enterTickSession(ctx, opts.takeOver === true, caller);
|
|
579
|
+
const outcome = await runConductorTick(ctx, opts, sessionId, caller, (r) => (handoffClose = r));
|
|
508
580
|
if (opts.json)
|
|
509
581
|
return print(tickJson(outcome));
|
|
510
582
|
printTickLines(outcome);
|
|
@@ -515,12 +587,25 @@ export async function conductorTickCommand(opts) {
|
|
|
515
587
|
exitWithError(e);
|
|
516
588
|
}
|
|
517
589
|
}
|
|
590
|
+
async function tickBotCaller(ctx) {
|
|
591
|
+
try {
|
|
592
|
+
return await currentBotOwner();
|
|
593
|
+
}
|
|
594
|
+
catch (error) {
|
|
595
|
+
if (readBotOwnership(ctx.store.dir).active || process.env['ORCA_STRUCTURED_SESSION'])
|
|
596
|
+
throw error;
|
|
597
|
+
return undefined;
|
|
598
|
+
}
|
|
599
|
+
}
|
|
518
600
|
/**
|
|
519
601
|
* 인계했거나 넘겨받힌 세션이면 거절하고 처음 보는 세션이면 등록해 탭 이름을 붙인다. 세션 id를 돌려준다.
|
|
520
602
|
* 다른 탭에서 주문만 넣으려다 컨덕터가 둘이 되지 않도록, 처음 등록하는 세션은 최근에 tick을 돌린
|
|
521
603
|
* 다른 컨덕터 세션이 있으면 거절한다. takeOver면 그 세션을 넘겨받는다.
|
|
522
604
|
*/
|
|
523
|
-
async function enterTickSession(ctx, takeOver) {
|
|
605
|
+
async function enterTickSession(ctx, takeOver, caller) {
|
|
606
|
+
assertBotOwner(ctx.store.dir, caller);
|
|
607
|
+
if (caller)
|
|
608
|
+
return undefined;
|
|
524
609
|
const sessionId = currentSessionId();
|
|
525
610
|
if (!sessionId)
|
|
526
611
|
return undefined;
|
|
@@ -557,7 +642,7 @@ function activeConductorWindowMs(config) {
|
|
|
557
642
|
return config.staleAfterSec * 2 * 1000;
|
|
558
643
|
}
|
|
559
644
|
/** tick 한 번. tick 명령과 wait가 함께 쓴다. onClose는 tick 본문이 던져도 닫기 결과를 남기게 한다 */
|
|
560
|
-
async function runConductorTick(ctx, opts, sessionId, onClose = () => { }) {
|
|
645
|
+
async function runConductorTick(ctx, opts, sessionId, caller, onClose = () => { }) {
|
|
561
646
|
// wait가 도는 사이 인계했거나 다른 세션이 넘겨받았으면 다음 tick에서 거절해 wait를 끝낸다
|
|
562
647
|
if (sessionId) {
|
|
563
648
|
withWaitOwnerLock(ctx.store.dir, () => {
|
|
@@ -578,6 +663,7 @@ async function runConductorTick(ctx, opts, sessionId, onClose = () => { }) {
|
|
|
578
663
|
? new GhPrWatchSource({ repoPaths: watch.repoPaths, accounts: gh })
|
|
579
664
|
: undefined;
|
|
580
665
|
const queue = opts.queue !== false ? fileQueue(queueDirOf(ctx)) : undefined;
|
|
666
|
+
const archive = dailyArchiveFor(ctx.config, ctx.store.dir);
|
|
581
667
|
const deps = {
|
|
582
668
|
config: ctx.config,
|
|
583
669
|
...launchersFor(ctx, process.env),
|
|
@@ -590,8 +676,12 @@ async function runConductorTick(ctx, opts, sessionId, onClose = () => { }) {
|
|
|
590
676
|
...(Object.keys(ctx.config.accounts).length > 0
|
|
591
677
|
? { accounts: new GhAccountSwitcher({ accounts: gh }) }
|
|
592
678
|
: {}),
|
|
679
|
+
...(archive ? { archive } : {}),
|
|
593
680
|
};
|
|
594
|
-
const report = await tick(ctx.store, deps, {
|
|
681
|
+
const report = await tick(ctx.store, deps, {
|
|
682
|
+
force: opts.force === true,
|
|
683
|
+
admit: () => assertBotOwner(ctx.store.dir, caller),
|
|
684
|
+
});
|
|
595
685
|
report.hostActions.push(...deferred);
|
|
596
686
|
// 건너뛴 tick은 감시를 안 돌았다. 경로 누락 오류를 붙이면 출력이 그걸 건너뛴 이유로 보여 준다
|
|
597
687
|
if (!report.skipped)
|
|
@@ -627,6 +717,10 @@ function printTickLines({ report, handoff, handoffClose }) {
|
|
|
627
717
|
console.log(`${l.orderId} ${rateLimitLine(l)}`);
|
|
628
718
|
for (const h of report.humanOwned)
|
|
629
719
|
console.log(humanOwnedLine(h));
|
|
720
|
+
for (const d of report.deployTargets)
|
|
721
|
+
console.log(d.outcome === 'recorded'
|
|
722
|
+
? `배포 성공 기록: ${d.orderId} (배포 주문 ${d.deployOrderId})`
|
|
723
|
+
: `배포 기록 건너뜀: ${d.orderId} (${d.reason ?? '-'})`);
|
|
630
724
|
for (const w of report.warnings)
|
|
631
725
|
console.log(`경고: ${w}`);
|
|
632
726
|
for (const e of report.errors)
|
|
@@ -653,9 +747,11 @@ export async function conductorWaitCommand(opts, loop = {}) {
|
|
|
653
747
|
const maxWaitSec = opts.maxWaitSec ?? ctx.config.waitMaxSec;
|
|
654
748
|
if (!Number.isInteger(maxWaitSec) || maxWaitSec < 1 || maxWaitSec > WAIT_MAX_SEC_LIMIT)
|
|
655
749
|
throw new Error(`--max-wait-sec는 1~${WAIT_MAX_SEC_LIMIT} 사이의 정수여야 해요`);
|
|
656
|
-
const
|
|
750
|
+
const caller = await tickBotCaller(ctx);
|
|
751
|
+
const sessionId = await enterTickSession(ctx, opts.takeOver === true, caller);
|
|
657
752
|
const owner = claimWaitOwner(ctx.store.dir, sessionId, () => {
|
|
658
|
-
|
|
753
|
+
assertBotOwner(ctx.store.dir, caller);
|
|
754
|
+
if (sessionId || caller)
|
|
659
755
|
return;
|
|
660
756
|
const active = findActiveConductor(ctx.store.dir, '', Date.now(), activeConductorWindowMs(ctx.config));
|
|
661
757
|
if (active) {
|
|
@@ -667,7 +763,7 @@ export async function conductorWaitCommand(opts, loop = {}) {
|
|
|
667
763
|
// 간격은 wait가 직접 잰다. 시계 하한에 맡기면 호스트가 방금 돌린 tick 때문에 첫 주기를 통째로 건너뛴다
|
|
668
764
|
runTick: async () => {
|
|
669
765
|
handoffClose = [];
|
|
670
|
-
return runConductorTick(ctx, { ...opts, force: true }, sessionId, (r) => (handoffClose = r));
|
|
766
|
+
return runConductorTick(ctx, { ...opts, force: true }, sessionId, caller, (r) => (handoffClose = r));
|
|
671
767
|
},
|
|
672
768
|
sleep: loop.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms))),
|
|
673
769
|
now: loop.now ?? (() => Date.now()),
|
|
@@ -904,6 +1000,7 @@ export function conductorWorkerReportCommand(opts) {
|
|
|
904
1000
|
...(opts.spawnTitle
|
|
905
1001
|
? { spawnRequest: { title: opts.spawnTitle, detail: opts.spawnDetail ?? '' } }
|
|
906
1002
|
: {}),
|
|
1003
|
+
...(opts.deployRef ? { deployRef: opts.deployRef } : {}),
|
|
907
1004
|
};
|
|
908
1005
|
const name = writeReport(inboxDirOf(ctx.store, {}), raw, ctx.config.resultMaxChars);
|
|
909
1006
|
if (opts.json)
|
|
@@ -933,33 +1030,44 @@ export async function conductorGateResolveCommand(gateId, opts) {
|
|
|
933
1030
|
throw new Error('--approve, --reject, --take-over 중 하나만 주세요');
|
|
934
1031
|
const ctx = open(opts);
|
|
935
1032
|
assertConductorSession(ctx, 'gate resolve');
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
if (
|
|
940
|
-
throw new Error(
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
gateId
|
|
946
|
-
|
|
1033
|
+
if (await tickBotCaller(ctx))
|
|
1034
|
+
throw new Error('봇 채팅에서는 서명한 결정만 bot decide로 접수해요');
|
|
1035
|
+
const lock = acquireLock(ctx.store.dir);
|
|
1036
|
+
if (!lock.ok)
|
|
1037
|
+
throw new Error('컨덕터가 상태를 갱신 중이에요. 잠시 뒤 게이트를 다시 확인해 주세요');
|
|
1038
|
+
try {
|
|
1039
|
+
ctx.store.reload();
|
|
1040
|
+
const gate = ctx.store.snapshot.gates[gateId];
|
|
1041
|
+
if (!gate)
|
|
1042
|
+
throw new Error(`모르는 게이트예요: ${gateId}`);
|
|
1043
|
+
if (gate.status !== 'open')
|
|
1044
|
+
throw new Error(`이미 종료된 게이트예요: ${gateId}`);
|
|
1045
|
+
if (opts.takeOver) {
|
|
1046
|
+
if (!gate.orderId)
|
|
1047
|
+
throw new Error(`${gateId}는 주문이 없는 게이트라 넘겨받을 주문이 없어요`);
|
|
1048
|
+
const r = await takeOver(ctx.store, gate.orderId, launchersFor(ctx, process.env).launchers, {
|
|
1049
|
+
gateId,
|
|
1050
|
+
...(opts.answer ? { answer: opts.answer } : {}),
|
|
1051
|
+
});
|
|
1052
|
+
return printOwnership(opts, r, `${gateId}를 닫고 ${r.order.id}를 사람이 넘겨받았어요`);
|
|
1053
|
+
}
|
|
1054
|
+
const { closed, delivered } = await closeAndDeliver(ctx, gateId, opts.approve ? 'approved' : 'rejected', {
|
|
1055
|
+
...(opts.answer !== undefined ? { answer: opts.answer } : {}),
|
|
1056
|
+
defer: opts.deferDelivery === true,
|
|
947
1057
|
});
|
|
948
|
-
|
|
1058
|
+
if (opts.json)
|
|
1059
|
+
return print({ gate: ctx.store.snapshot.gates[gateId] ?? closed, ...delivered });
|
|
1060
|
+
console.log(`${gateId}를 ${closed.decision === 'approved' ? '승인' : '거절'}했어요`);
|
|
1061
|
+
if (delivered.deferred)
|
|
1062
|
+
console.log('결정은 다음 tick이 워커에 전해요');
|
|
1063
|
+
for (const a of delivered.hostActions)
|
|
1064
|
+
console.log(`할 일: ${JSON.stringify(a)}`);
|
|
1065
|
+
for (const e of delivered.errors)
|
|
1066
|
+
console.log(`오류: ${e}`);
|
|
1067
|
+
}
|
|
1068
|
+
finally {
|
|
1069
|
+
lock.release();
|
|
949
1070
|
}
|
|
950
|
-
const closed = resolveGate(ctx.store, gateId, opts.approve ? 'approved' : 'rejected', opts.answer);
|
|
951
|
-
const delivered = await deliverGateDecision(ctx.store, closed, launchersFor(ctx, process.env), {
|
|
952
|
-
defer: opts.deferDelivery === true,
|
|
953
|
-
});
|
|
954
|
-
if (opts.json)
|
|
955
|
-
return print({ gate: ctx.store.snapshot.gates[gateId] ?? closed, ...delivered });
|
|
956
|
-
console.log(`${gateId}를 ${closed.decision === 'approved' ? '승인' : '거절'}했어요`);
|
|
957
|
-
if (delivered.deferred)
|
|
958
|
-
console.log('결정은 다음 tick이 워커에 전해요');
|
|
959
|
-
for (const a of delivered.hostActions)
|
|
960
|
-
console.log(`할 일: ${JSON.stringify(a)}`);
|
|
961
|
-
for (const e of delivered.errors)
|
|
962
|
-
console.log(`오류: ${e}`);
|
|
963
1071
|
}
|
|
964
1072
|
catch (e) {
|
|
965
1073
|
exitWithError(e);
|
|
@@ -983,8 +1091,15 @@ export async function conductorOrderTakeOverCommand(id, opts) {
|
|
|
983
1091
|
try {
|
|
984
1092
|
const ctx = open(opts);
|
|
985
1093
|
assertConductorSession(ctx, 'order take-over');
|
|
986
|
-
const
|
|
987
|
-
|
|
1094
|
+
const lock = acquireDecisionLock(ctx);
|
|
1095
|
+
try {
|
|
1096
|
+
ctx.store.reload();
|
|
1097
|
+
const r = await takeOver(ctx.store, id, launchersFor(ctx, process.env).launchers);
|
|
1098
|
+
printOwnership(opts, r, `${id}를 사람이 넘겨받았어요. tick이 PR 머지를 지켜봐요`);
|
|
1099
|
+
}
|
|
1100
|
+
finally {
|
|
1101
|
+
lock.release();
|
|
1102
|
+
}
|
|
988
1103
|
}
|
|
989
1104
|
catch (e) {
|
|
990
1105
|
exitWithError(e);
|
|
@@ -994,9 +1109,16 @@ export async function conductorOrderCancelCommand(id, opts) {
|
|
|
994
1109
|
try {
|
|
995
1110
|
const ctx = open(opts);
|
|
996
1111
|
assertConductorSession(ctx, 'order cancel');
|
|
997
|
-
const
|
|
998
|
-
|
|
999
|
-
|
|
1112
|
+
const lock = acquireDecisionLock(ctx);
|
|
1113
|
+
try {
|
|
1114
|
+
ctx.store.reload();
|
|
1115
|
+
const reason = opts.reason ? oneLine(opts.reason, 300) : undefined;
|
|
1116
|
+
const r = await cancelOrder(ctx.store, id, launchersFor(ctx, process.env).launchers, reason);
|
|
1117
|
+
printOwnership(opts, r, `${id}를 취소했어요`);
|
|
1118
|
+
}
|
|
1119
|
+
finally {
|
|
1120
|
+
lock.release();
|
|
1121
|
+
}
|
|
1000
1122
|
}
|
|
1001
1123
|
catch (e) {
|
|
1002
1124
|
exitWithError(e);
|
|
@@ -1193,4 +1315,184 @@ function recentEventsField(store) {
|
|
|
1193
1315
|
return { recentEvents: [], recentEventsError: e.message };
|
|
1194
1316
|
}
|
|
1195
1317
|
}
|
|
1318
|
+
export async function conductorBotBindCommand(opts) {
|
|
1319
|
+
try {
|
|
1320
|
+
const ctx = open(opts);
|
|
1321
|
+
assertConductorSession(ctx, 'bot bind');
|
|
1322
|
+
if (await tickBotCaller(ctx))
|
|
1323
|
+
throw new Error('운영권은 운영자 터미널에서 등록해 주세요');
|
|
1324
|
+
const next = await targetBotOwner(opts.bot, opts.chat);
|
|
1325
|
+
changeBotOwner(ctx.store.dir, opts.fromChat, next);
|
|
1326
|
+
if (opts.json)
|
|
1327
|
+
return print(next);
|
|
1328
|
+
console.log(`운영권을 ${next.name}의 채팅 ${next.chatId}에 등록했어요`);
|
|
1329
|
+
}
|
|
1330
|
+
catch (error) {
|
|
1331
|
+
exitWithError(error);
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1334
|
+
export async function conductorBotReleaseCommand(opts) {
|
|
1335
|
+
try {
|
|
1336
|
+
const ctx = open(opts);
|
|
1337
|
+
assertConductorSession(ctx, 'bot release');
|
|
1338
|
+
if (await tickBotCaller(ctx))
|
|
1339
|
+
throw new Error('운영권은 운영자 터미널에서 종료해 주세요');
|
|
1340
|
+
changeBotOwner(ctx.store.dir, opts.fromChat);
|
|
1341
|
+
if (opts.json)
|
|
1342
|
+
return print({ released: opts.fromChat });
|
|
1343
|
+
console.log('봇의 운영권을 종료했어요');
|
|
1344
|
+
}
|
|
1345
|
+
catch (error) {
|
|
1346
|
+
exitWithError(error);
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
function acquireDecisionLock(ctx) {
|
|
1350
|
+
const lock = acquireLock(ctx.store.dir);
|
|
1351
|
+
if (!lock.ok)
|
|
1352
|
+
throw new Error('컨덕터가 상태를 갱신 중이에요. 잠시 뒤 게이트를 다시 확인해 주세요');
|
|
1353
|
+
return lock;
|
|
1354
|
+
}
|
|
1355
|
+
async function closeAndDeliver(ctx, gateId, decision, options) {
|
|
1356
|
+
const { store } = ctx;
|
|
1357
|
+
const closed = resolveGate(store, gateId, decision, options.answer, {
|
|
1358
|
+
deliveryPending: options.defer,
|
|
1359
|
+
...(options.signer ? { decisionBy: options.signer } : {}),
|
|
1360
|
+
});
|
|
1361
|
+
const delivered = await deliverGateDecision(store, closed, launchersFor(ctx, process.env), {
|
|
1362
|
+
defer: options.defer,
|
|
1363
|
+
});
|
|
1364
|
+
if (delivered.outcome)
|
|
1365
|
+
recordGateDelivery(store, gateId, delivered.outcome);
|
|
1366
|
+
return { closed, delivered };
|
|
1367
|
+
}
|
|
1368
|
+
async function requireBotOperator(ctx) {
|
|
1369
|
+
assertConductorSession(ctx, 'bot 게이트');
|
|
1370
|
+
const caller = await currentBotOwner();
|
|
1371
|
+
if (!caller)
|
|
1372
|
+
throw new Error('Orca 운영 봇 채팅에서 실행해 주세요');
|
|
1373
|
+
assertBotOwner(ctx.store.dir, caller);
|
|
1374
|
+
return caller;
|
|
1375
|
+
}
|
|
1376
|
+
function botDecisionStatus(gate) {
|
|
1377
|
+
return {
|
|
1378
|
+
gateId: gate.id,
|
|
1379
|
+
decision: gate.decision ?? 'open',
|
|
1380
|
+
...(gate.decisionBy ? { signer: gate.decisionBy } : {}),
|
|
1381
|
+
delivery: gate.deliveryPending ? 'pending' : (gate.deliveryOutcome ?? 'unknown'),
|
|
1382
|
+
...(gate.deliveryAttempts ? { failedAttempts: gate.deliveryAttempts } : {}),
|
|
1383
|
+
};
|
|
1384
|
+
}
|
|
1385
|
+
export async function conductorBotGateCommand(gateId, opts) {
|
|
1386
|
+
try {
|
|
1387
|
+
const ctx = open(opts);
|
|
1388
|
+
await requireBotOperator(ctx);
|
|
1389
|
+
const { gate, order, ref, url } = matchMergeGate(ctx.store, gateId);
|
|
1390
|
+
const base = {
|
|
1391
|
+
...botDecisionStatus(gate),
|
|
1392
|
+
repo: order.repo,
|
|
1393
|
+
title: order.title,
|
|
1394
|
+
pr: url,
|
|
1395
|
+
request: '머지 승인 또는 거절',
|
|
1396
|
+
reason: gate.reason,
|
|
1397
|
+
};
|
|
1398
|
+
if (gate.status === 'resolved')
|
|
1399
|
+
return print(base);
|
|
1400
|
+
const evidence = await readMergeEvidence(ref, new GhAccounts(ctx.config.accounts));
|
|
1401
|
+
print({
|
|
1402
|
+
...base,
|
|
1403
|
+
evidence,
|
|
1404
|
+
messages: {
|
|
1405
|
+
approved: approvalMessage(gate, ref, evidence.head, 'approved'),
|
|
1406
|
+
rejected: approvalMessage(gate, ref, evidence.head, 'rejected'),
|
|
1407
|
+
},
|
|
1408
|
+
});
|
|
1409
|
+
}
|
|
1410
|
+
catch (error) {
|
|
1411
|
+
exitWithError(error);
|
|
1412
|
+
}
|
|
1413
|
+
}
|
|
1414
|
+
export async function conductorBotDecideCommand(gateId, opts) {
|
|
1415
|
+
try {
|
|
1416
|
+
const ctx = open(opts);
|
|
1417
|
+
const caller = await requireBotOperator(ctx);
|
|
1418
|
+
const decision = oneOf(opts.decision, ['approved', 'rejected'], '--decision');
|
|
1419
|
+
const { gate, ref } = matchMergeGate(ctx.store, gateId);
|
|
1420
|
+
const evidence = gate.status === 'open'
|
|
1421
|
+
? await readMergeEvidence(ref, new GhAccounts(ctx.config.accounts))
|
|
1422
|
+
: undefined;
|
|
1423
|
+
const lock = acquireLock(ctx.store.dir);
|
|
1424
|
+
if (!lock.ok)
|
|
1425
|
+
throw new Error('컨덕터가 상태를 갱신 중이에요. 잠시 뒤 게이트를 다시 확인해 주세요');
|
|
1426
|
+
try {
|
|
1427
|
+
assertBotOwner(ctx.store.dir, caller);
|
|
1428
|
+
ctx.store.reload();
|
|
1429
|
+
const current = matchMergeGate(ctx.store, gateId);
|
|
1430
|
+
if (current.gate.status === 'resolved')
|
|
1431
|
+
return print({ ...botDecisionStatus(current.gate), alreadyResolved: true });
|
|
1432
|
+
if (!evidence || current.ref !== ref)
|
|
1433
|
+
throw new Error('게이트나 PR이 바뀌었어요. 다시 확인해 주세요');
|
|
1434
|
+
if (decision === 'approved' && (evidence.state !== 'OPEN' || evidence.draft))
|
|
1435
|
+
throw new Error('리뷰 준비가 끝난 열린 PR만 머지 승인할 수 있어요');
|
|
1436
|
+
verifyMergeApproval(readBotPolicy(ctx.store.dir), current.order.repo, opts.signer, approvalMessage(current.gate, ref, evidence.head, decision), opts.signature);
|
|
1437
|
+
const result = await closeAndDeliver(ctx, gateId, decision, {
|
|
1438
|
+
defer: true,
|
|
1439
|
+
signer: opts.signer,
|
|
1440
|
+
...(decision === 'approved'
|
|
1441
|
+
? {
|
|
1442
|
+
answer: `승인된 PR HEAD는 ${evidence.head}입니다. 머지는 반드시 --match-head-commit ${evidence.head}로 제한하세요. HEAD가 바뀌면 새 승인을 요청하세요.`,
|
|
1443
|
+
}
|
|
1444
|
+
: {}),
|
|
1445
|
+
});
|
|
1446
|
+
print({
|
|
1447
|
+
...botDecisionStatus(ctx.store.snapshot.gates[gateId] ?? result.closed),
|
|
1448
|
+
errors: result.delivered.errors,
|
|
1449
|
+
});
|
|
1450
|
+
}
|
|
1451
|
+
finally {
|
|
1452
|
+
lock.release();
|
|
1453
|
+
}
|
|
1454
|
+
}
|
|
1455
|
+
catch (error) {
|
|
1456
|
+
exitWithError(error);
|
|
1457
|
+
}
|
|
1458
|
+
}
|
|
1459
|
+
export async function conductorBotGithubCommand(link, opts) {
|
|
1460
|
+
try {
|
|
1461
|
+
const ctx = open(opts);
|
|
1462
|
+
assertConductorSession(ctx, 'bot github');
|
|
1463
|
+
const caller = await currentBotOwner();
|
|
1464
|
+
const policy = readBotPolicy(ctx.store.dir);
|
|
1465
|
+
if (!caller ||
|
|
1466
|
+
caller.botId !== policy['githubIntakeBotId'] ||
|
|
1467
|
+
caller.botId === readBotOwnership(ctx.store.dir).active?.botId)
|
|
1468
|
+
throw new Error('등록된 팀 주문 접수 봇 채팅에서 실행해 주세요');
|
|
1469
|
+
const request = await readGithubOrder(link, policy, new GhAccounts(ctx.config.accounts));
|
|
1470
|
+
print(handleGithubOrder(ctx.store, request));
|
|
1471
|
+
}
|
|
1472
|
+
catch (error) {
|
|
1473
|
+
exitWithError(error);
|
|
1474
|
+
}
|
|
1475
|
+
}
|
|
1476
|
+
export async function conductorCheckBotMutation(command, opts) {
|
|
1477
|
+
try {
|
|
1478
|
+
const ctx = open(opts);
|
|
1479
|
+
const caller = await tickBotCaller(ctx);
|
|
1480
|
+
if (!caller)
|
|
1481
|
+
return;
|
|
1482
|
+
if (command === 'order add') {
|
|
1483
|
+
assertBotOwner(ctx.store.dir, caller);
|
|
1484
|
+
if (!opts.deploys?.length &&
|
|
1485
|
+
(opts.scope === undefined || opts.scope === 'approval') &&
|
|
1486
|
+
(opts.skills === undefined || opts.skills === 'solve,ship')) {
|
|
1487
|
+
opts.scope = 'approval';
|
|
1488
|
+
opts.skills = 'solve,ship';
|
|
1489
|
+
return;
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1492
|
+
throw new Error('이 변경은 운영자 터미널에서 실행해 주세요');
|
|
1493
|
+
}
|
|
1494
|
+
catch (error) {
|
|
1495
|
+
exitWithError(error);
|
|
1496
|
+
}
|
|
1497
|
+
}
|
|
1196
1498
|
//# sourceMappingURL=conductor.js.map
|