@tienne/gestalt 0.160.0 → 0.161.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/_shared/conductor-plan.md +32 -0
- package/dist/plugin/skills/conductor/SKILL.md +9 -2
- package/dist/plugin/skills/device/SKILL.md +4 -1
- package/dist/plugin/skills/device/references/tools.md +43 -0
- package/dist/plugin/skills/execute/SKILL.md +18 -2
- package/dist/plugin/skills/interview/SKILL.md +8 -2
- package/dist/plugin/skills/spec/SKILL.md +19 -3
- package/dist/src/agent-sync/run-store.d.ts +4 -4
- package/dist/src/cli/commands/conductor-approval.d.ts +32 -0
- package/dist/src/cli/commands/conductor-approval.d.ts.map +1 -0
- package/dist/src/cli/commands/conductor-approval.js +207 -0
- package/dist/src/cli/commands/conductor-approval.js.map +1 -0
- package/dist/src/cli/commands/conductor-plan.d.ts +10 -0
- package/dist/src/cli/commands/conductor-plan.d.ts.map +1 -0
- package/dist/src/cli/commands/conductor-plan.js +301 -0
- package/dist/src/cli/commands/conductor-plan.js.map +1 -0
- package/dist/src/cli/commands/conductor.d.ts +116 -0
- package/dist/src/cli/commands/conductor.d.ts.map +1 -1
- package/dist/src/cli/commands/conductor.js +697 -72
- 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 +104 -12
- package/dist/src/cli/index.js.map +1 -1
- package/dist/src/conductor/activity-tick.d.ts +2 -1
- package/dist/src/conductor/activity-tick.d.ts.map +1 -1
- package/dist/src/conductor/activity-tick.js +19 -10
- package/dist/src/conductor/activity-tick.js.map +1 -1
- package/dist/src/conductor/adapters.d.ts.map +1 -1
- package/dist/src/conductor/adapters.js +13 -8
- package/dist/src/conductor/adapters.js.map +1 -1
- package/dist/src/conductor/approval-overlap.d.ts +13 -0
- package/dist/src/conductor/approval-overlap.d.ts.map +1 -0
- package/dist/src/conductor/approval-overlap.js +53 -0
- package/dist/src/conductor/approval-overlap.js.map +1 -0
- package/dist/src/conductor/approval-server.d.ts +69 -0
- package/dist/src/conductor/approval-server.d.ts.map +1 -0
- package/dist/src/conductor/approval-server.js +279 -0
- package/dist/src/conductor/approval-server.js.map +1 -0
- package/dist/src/conductor/archive.d.ts.map +1 -1
- package/dist/src/conductor/archive.js +8 -6
- package/dist/src/conductor/archive.js.map +1 -1
- package/dist/src/conductor/bot-approval.d.ts +82 -1
- package/dist/src/conductor/bot-approval.d.ts.map +1 -1
- package/dist/src/conductor/bot-approval.js +362 -24
- package/dist/src/conductor/bot-approval.js.map +1 -1
- package/dist/src/conductor/bot-handoff-coordination.d.ts +24 -0
- package/dist/src/conductor/bot-handoff-coordination.d.ts.map +1 -0
- package/dist/src/conductor/bot-handoff-coordination.js +98 -0
- package/dist/src/conductor/bot-handoff-coordination.js.map +1 -0
- package/dist/src/conductor/bot-handoff-edit.d.ts +21 -0
- package/dist/src/conductor/bot-handoff-edit.d.ts.map +1 -0
- package/dist/src/conductor/bot-handoff-edit.js +141 -0
- package/dist/src/conductor/bot-handoff-edit.js.map +1 -0
- package/dist/src/conductor/bot-handoff-record.d.ts +20 -0
- package/dist/src/conductor/bot-handoff-record.d.ts.map +1 -0
- package/dist/src/conductor/bot-handoff-record.js +21 -0
- package/dist/src/conductor/bot-handoff-record.js.map +1 -0
- package/dist/src/conductor/bot-handoff.d.ts +45 -0
- package/dist/src/conductor/bot-handoff.d.ts.map +1 -0
- package/dist/src/conductor/bot-handoff.js +430 -0
- package/dist/src/conductor/bot-handoff.js.map +1 -0
- package/dist/src/conductor/bot-owner.d.ts +8 -3
- package/dist/src/conductor/bot-owner.d.ts.map +1 -1
- package/dist/src/conductor/bot-owner.js +23 -5
- package/dist/src/conductor/bot-owner.js.map +1 -1
- package/dist/src/conductor/deployment-evidence.d.ts +21 -0
- package/dist/src/conductor/deployment-evidence.d.ts.map +1 -0
- package/dist/src/conductor/deployment-evidence.js +133 -0
- package/dist/src/conductor/deployment-evidence.js.map +1 -0
- package/dist/src/conductor/engine.d.ts +12 -2
- package/dist/src/conductor/engine.d.ts.map +1 -1
- package/dist/src/conductor/engine.js +267 -47
- package/dist/src/conductor/engine.js.map +1 -1
- package/dist/src/conductor/gate-completion.d.ts +12 -0
- package/dist/src/conductor/gate-completion.d.ts.map +1 -0
- package/dist/src/conductor/gate-completion.js +111 -0
- package/dist/src/conductor/gate-completion.js.map +1 -0
- package/dist/src/conductor/gates.d.ts +5 -1
- package/dist/src/conductor/gates.d.ts.map +1 -1
- package/dist/src/conductor/gates.js +26 -23
- package/dist/src/conductor/gates.js.map +1 -1
- package/dist/src/conductor/input-error.d.ts +7 -0
- package/dist/src/conductor/input-error.d.ts.map +1 -0
- package/dist/src/conductor/input-error.js +7 -0
- package/dist/src/conductor/input-error.js.map +1 -0
- 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 +23 -8
- package/dist/src/conductor/intake.js.map +1 -1
- package/dist/src/conductor/launcher.d.ts +20 -2
- package/dist/src/conductor/launcher.d.ts.map +1 -1
- package/dist/src/conductor/launcher.js +35 -7
- package/dist/src/conductor/launcher.js.map +1 -1
- package/dist/src/conductor/monitor.d.ts +18 -0
- package/dist/src/conductor/monitor.d.ts.map +1 -0
- package/dist/src/conductor/monitor.js +110 -0
- package/dist/src/conductor/monitor.js.map +1 -0
- package/dist/src/conductor/orca-approval-attestation.d.ts +91 -0
- package/dist/src/conductor/orca-approval-attestation.d.ts.map +1 -0
- package/dist/src/conductor/orca-approval-attestation.js +85 -0
- package/dist/src/conductor/orca-approval-attestation.js.map +1 -0
- package/dist/src/conductor/orca-automation.d.ts +17 -0
- package/dist/src/conductor/orca-automation.d.ts.map +1 -0
- package/dist/src/conductor/orca-automation.js +87 -0
- package/dist/src/conductor/orca-automation.js.map +1 -0
- package/dist/src/conductor/orca-item-approval.d.ts +55 -0
- package/dist/src/conductor/orca-item-approval.d.ts.map +1 -0
- package/dist/src/conductor/orca-item-approval.js +155 -0
- package/dist/src/conductor/orca-item-approval.js.map +1 -0
- package/dist/src/conductor/pr-watch.d.ts +6 -0
- package/dist/src/conductor/pr-watch.d.ts.map +1 -1
- package/dist/src/conductor/pr-watch.js +69 -1
- package/dist/src/conductor/pr-watch.js.map +1 -1
- package/dist/src/conductor/prepared-plan.d.ts +488 -0
- package/dist/src/conductor/prepared-plan.d.ts.map +1 -0
- package/dist/src/conductor/prepared-plan.js +51 -0
- package/dist/src/conductor/prepared-plan.js.map +1 -0
- package/dist/src/conductor/slack-state.d.ts +21 -0
- package/dist/src/conductor/slack-state.d.ts.map +1 -0
- package/dist/src/conductor/slack-state.js +151 -0
- package/dist/src/conductor/slack-state.js.map +1 -0
- package/dist/src/conductor/slack.d.ts +35 -5
- package/dist/src/conductor/slack.d.ts.map +1 -1
- package/dist/src/conductor/slack.js +153 -25
- package/dist/src/conductor/slack.js.map +1 -1
- package/dist/src/conductor/store.d.ts +11 -5
- package/dist/src/conductor/store.d.ts.map +1 -1
- package/dist/src/conductor/store.js +225 -16
- package/dist/src/conductor/store.js.map +1 -1
- package/dist/src/conductor/successful-tick.d.ts +8 -0
- package/dist/src/conductor/successful-tick.d.ts.map +1 -0
- package/dist/src/conductor/successful-tick.js +33 -0
- package/dist/src/conductor/successful-tick.js.map +1 -0
- package/dist/src/conductor/types.d.ts +119 -1
- package/dist/src/conductor/types.d.ts.map +1 -1
- package/dist/src/conductor/types.js.map +1 -1
- package/dist/src/conductor/webauthn-approval.d.ts +81 -0
- package/dist/src/conductor/webauthn-approval.d.ts.map +1 -0
- package/dist/src/conductor/webauthn-approval.js +181 -0
- package/dist/src/conductor/webauthn-approval.js.map +1 -0
- package/dist/src/conductor/worker-completion.d.ts +11 -0
- package/dist/src/conductor/worker-completion.d.ts.map +1 -0
- package/dist/src/conductor/worker-completion.js +34 -0
- package/dist/src/conductor/worker-completion.js.map +1 -0
- package/dist/src/core/errors.d.ts +4 -0
- package/dist/src/core/errors.d.ts.map +1 -1
- package/dist/src/core/errors.js +8 -0
- package/dist/src/core/errors.js.map +1 -1
- package/dist/src/core/json-file.d.ts.map +1 -1
- package/dist/src/core/json-file.js +2 -0
- package/dist/src/core/json-file.js.map +1 -1
- package/dist/src/core/types.d.ts +7 -0
- package/dist/src/core/types.d.ts.map +1 -1
- package/dist/src/digest/blocks.d.ts +36 -36
- package/dist/src/digest/diagram-schema.d.ts +4 -4
- package/dist/src/digest/lens-source.d.ts +6 -6
- package/dist/src/digest/lens-widget-schema.d.ts +10 -10
- package/dist/src/digest/prd-schema.d.ts +66 -66
- package/dist/src/digest/schema.d.ts +219 -219
- package/dist/src/events/types.d.ts +2 -0
- package/dist/src/events/types.d.ts.map +1 -1
- package/dist/src/events/types.js +2 -0
- package/dist/src/events/types.js.map +1 -1
- package/dist/src/execute/orchestrators/evaluation.d.ts.map +1 -1
- package/dist/src/execute/orchestrators/evaluation.js +4 -3
- package/dist/src/execute/orchestrators/evaluation.js.map +1 -1
- package/dist/src/execute/orchestrators/execution.d.ts.map +1 -1
- package/dist/src/execute/orchestrators/execution.js +4 -3
- package/dist/src/execute/orchestrators/execution.js.map +1 -1
- package/dist/src/execute/orchestrators/planning.d.ts +3 -1
- package/dist/src/execute/orchestrators/planning.d.ts.map +1 -1
- package/dist/src/execute/orchestrators/planning.js +19 -3
- package/dist/src/execute/orchestrators/planning.js.map +1 -1
- package/dist/src/execute/passthrough-engine.d.ts +3 -1
- package/dist/src/execute/passthrough-engine.d.ts.map +1 -1
- package/dist/src/execute/passthrough-engine.js +3 -0
- package/dist/src/execute/passthrough-engine.js.map +1 -1
- package/dist/src/execute/plan-destination.d.ts +16 -0
- package/dist/src/execute/plan-destination.d.ts.map +1 -0
- package/dist/src/execute/plan-destination.js +86 -0
- package/dist/src/execute/plan-destination.js.map +1 -0
- package/dist/src/execute/plan-schema.d.ts +335 -0
- package/dist/src/execute/plan-schema.d.ts.map +1 -0
- package/dist/src/execute/plan-schema.js +52 -0
- package/dist/src/execute/plan-schema.js.map +1 -0
- package/dist/src/execute/repository.d.ts.map +1 -1
- package/dist/src/execute/repository.js +16 -2
- package/dist/src/execute/repository.js.map +1 -1
- package/dist/src/execute/session.d.ts +6 -0
- package/dist/src/execute/session.d.ts.map +1 -1
- package/dist/src/execute/session.js +92 -1
- package/dist/src/execute/session.js.map +1 -1
- package/dist/src/harness-review/related-repos.d.ts +1 -0
- package/dist/src/harness-review/related-repos.d.ts.map +1 -1
- package/dist/src/harness-review/related-repos.js +4 -0
- package/dist/src/harness-review/related-repos.js.map +1 -1
- package/dist/src/mcp/schemas.d.ts +36 -20
- package/dist/src/mcp/schemas.d.ts.map +1 -1
- package/dist/src/mcp/schemas.js +10 -44
- package/dist/src/mcp/schemas.js.map +1 -1
- package/dist/src/mcp/server.d.ts.map +1 -1
- package/dist/src/mcp/server.js +6 -8
- package/dist/src/mcp/server.js.map +1 -1
- package/dist/src/mcp/tools/execute/evaluate.js +4 -4
- package/dist/src/mcp/tools/execute/evaluate.js.map +1 -1
- package/dist/src/mcp/tools/execute/execution.d.ts.map +1 -1
- package/dist/src/mcp/tools/execute/execution.js +5 -3
- package/dist/src/mcp/tools/execute/execution.js.map +1 -1
- package/dist/src/mcp/tools/execute/planning.d.ts +1 -0
- package/dist/src/mcp/tools/execute/planning.d.ts.map +1 -1
- package/dist/src/mcp/tools/execute/planning.js +117 -4
- package/dist/src/mcp/tools/execute/planning.js.map +1 -1
- package/dist/src/mcp/tools/execute/utility.js +4 -0
- package/dist/src/mcp/tools/execute/utility.js.map +1 -1
- package/dist/src/mcp/tools/execute/utils.d.ts +1 -0
- package/dist/src/mcp/tools/execute/utils.d.ts.map +1 -1
- package/dist/src/mcp/tools/execute/utils.js +6 -0
- package/dist/src/mcp/tools/execute/utils.js.map +1 -1
- package/dist/src/mcp/tools/execute-passthrough.d.ts.map +1 -1
- package/dist/src/mcp/tools/execute-passthrough.js +23 -7
- package/dist/src/mcp/tools/execute-passthrough.js.map +1 -1
- package/dist/src/mcp/tools/spec-passthrough.d.ts +2 -1
- package/dist/src/mcp/tools/spec-passthrough.d.ts.map +1 -1
- package/dist/src/mcp/tools/spec-passthrough.js +15 -1
- package/dist/src/mcp/tools/spec-passthrough.js.map +1 -1
- package/dist/src/mcp/tools/spec.d.ts +2 -1
- package/dist/src/mcp/tools/spec.d.ts.map +1 -1
- package/dist/src/mcp/tools/spec.js +15 -1
- package/dist/src/mcp/tools/spec.js.map +1 -1
- package/dist/src/research/schema.d.ts +26 -26
- package/dist/src/spec/generator.d.ts.map +1 -1
- package/dist/src/spec/generator.js +1 -0
- package/dist/src/spec/generator.js.map +1 -1
- package/dist/src/spec/passthrough-generator.d.ts.map +1 -1
- package/dist/src/spec/passthrough-generator.js +2 -0
- package/dist/src/spec/passthrough-generator.js.map +1 -1
- package/dist/src/spec/repository.d.ts +8 -0
- package/dist/src/spec/repository.d.ts.map +1 -0
- package/dist/src/spec/repository.js +37 -0
- package/dist/src/spec/repository.js.map +1 -0
- package/package.json +1 -1
- package/plugin/.codex-plugin/plugin.json +1 -1
- package/plugin/.mcp.json +1 -1
- package/plugin/commands/gestalt-execute.md +4 -0
- package/plugin/commands/gestalt-interview.md +3 -1
- package/plugin/commands/gestalt-spec.md +4 -0
- package/plugin/mcp.json +1 -1
- package/plugin/skills/_shared/conductor-plan.md +32 -0
- package/plugin/skills/conductor/SKILL.md +9 -2
- package/plugin/skills/device/SKILL.md +4 -1
- package/plugin/skills/device/references/tools.md +43 -0
- package/plugin/skills/execute/SKILL.md +18 -2
- package/plugin/skills/interview/SKILL.md +8 -2
- package/plugin/skills/spec/SKILL.md +19 -3
|
@@ -2,20 +2,29 @@ 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 { setTimeout as delay } from 'node:timers/promises';
|
|
5
6
|
import { handleGithubOrder, readGithubOrder } from '../../conductor/bot-github.js';
|
|
6
|
-
import {
|
|
7
|
+
import { handoffBot } from '../../conductor/bot-handoff.js';
|
|
8
|
+
import { automationCoordinationDir, automationCoordinationRoot, handoffCancellationPending, } from '../../conductor/bot-handoff-coordination.js';
|
|
9
|
+
import { readEditReceipt } from '../../conductor/bot-handoff-edit.js';
|
|
10
|
+
import { decisionId, decisionReceipt, decisionTarget, gateApprovalMessage, matchBotGate, readBotPolicy, loadBotPolicy, approverStatus, approverGuidance, assertApproverReady, terminalResolveCommand, approverRegistry, peekBotPolicy, readMergeEvidence, verifyGateApproval, } from '../../conductor/bot-approval.js';
|
|
11
|
+
import { officialOrcaApprovalIssuer, ORCA_APPROVAL_UNAVAILABLE, orcaApprovalTargetHash, verifyOrcaApproval, } from '../../conductor/orca-approval-attestation.js';
|
|
12
|
+
import { itemBinding, OrcaContractError, readItemDecision, readOrcaItem, } from '../../conductor/orca-item-approval.js';
|
|
7
13
|
import { assertBotOwner, changeBotOwner, currentBotOwner, targetBotOwner, readBotOwnership, } from '../../conductor/bot-owner.js';
|
|
8
14
|
import { loadConfig, WAIT_MAX_SEC_LIMIT } from '../../core/config.js';
|
|
9
15
|
import { getVersion } from '../../core/version.js';
|
|
10
16
|
import { writeJsonAtomic } from '../../core/json-file.js';
|
|
11
17
|
import { fileDeploySource, fileQueue, GhAccounts, GhAccountSwitcher, GhPrStateSource, GhPrWatchSource, prWatchTargets, hostJiraClient, hostSlackClient, writeDeploySignal, writeQueueMessage, } from '../../conductor/adapters.js';
|
|
12
|
-
import {
|
|
18
|
+
import { approveDeployment, readDeploymentEvidence } from '../../conductor/deployment-evidence.js';
|
|
19
|
+
import { acquireLock, afterHumanMerge, rateLimitEntries, deliverGateDecision, decisionMessage, recordGateDelivery, recheckSignedDecision, inboxDirOf, tick, staleTickWarning, writeReport, } from '../../conductor/engine.js';
|
|
13
20
|
import { orderActivity } from '../../conductor/activity.js';
|
|
14
21
|
import { existingRepoContext, repoContextPath } from '../../conductor/context.js';
|
|
15
22
|
import { currentSessionId, handoffNotice, handoffRecordPath, handoffStatus, isSessionId, resolveHandoffModel, launchHandoff, readCompactions, readHandoffRecord, readSessionRegisteredAt, recordHandoff, registerSession, writeHandoffFile, } from '../../conductor/handoff.js';
|
|
16
23
|
import { findActiveConductor, readSupersededRecord, supersededRecordPath, supersedeOthers, touchSessionTick, } from '../../conductor/session-owner.js';
|
|
17
24
|
import { readAutoCompactWindow } from '../../conductor/claude-settings.js';
|
|
18
25
|
import { readRecentEvents } from '../../conductor/recent-events.js';
|
|
26
|
+
import { readConductorMonitor } from '../../conductor/monitor.js';
|
|
27
|
+
import { readLastSuccessfulTick } from '../../conductor/successful-tick.js';
|
|
19
28
|
import { removeOrderRefCopies } from '../../conductor/ref-copy.js';
|
|
20
29
|
import { archiveAndCompress, DEFAULT_ARCHIVE_DAYS, PROMPTS_DIR, pruneArchive, dailyArchiveFor, } from '../../conductor/archive.js';
|
|
21
30
|
import { resolveGate } from '../../conductor/gates.js';
|
|
@@ -30,12 +39,15 @@ import { normalizePrRef } from '../../conductor/pr-ref.js';
|
|
|
30
39
|
import { saveSkillCheckpoint } from '../../conductor/resume.js';
|
|
31
40
|
import { currentSessionTab, nameConductorTab, renameHandoffTabs, } from '../../conductor/tab-title.js';
|
|
32
41
|
import { clearCloseClaim, closeHandedOffTabs, handoffCloseLine, } from '../../conductor/handoff-close.js';
|
|
33
|
-
import { draftSlack } from '../../conductor/slack.js';
|
|
42
|
+
import { confirmSlackDelivery, draftSlack, pendingSlackDelivery } from '../../conductor/slack.js';
|
|
43
|
+
import { isSlackChannelId } from '../../conductor/slack-state.js';
|
|
34
44
|
import { claimWaitOwner, consumeWaitCarry, hasWaitCarry, mergeWaitCarry, readSeen, saveWaitCarry, shownLines, WAIT_REPORT_FILE, waitForAttention, withWaitOwnerLock, writeSeen, } from '../../conductor/wait.js';
|
|
35
45
|
import { ConductorStore } from '../../conductor/store.js';
|
|
46
|
+
import { APPROVAL_PORT, assertionSchema, verifyWebAuthnAssertion, webAuthnApprovers, webAuthnChallenge, } from '../../conductor/webauthn-approval.js';
|
|
47
|
+
import { InputError } from '../../conductor/input-error.js';
|
|
36
48
|
import { resolveStateDir } from '../../conductor/state-dir.js';
|
|
37
49
|
import { INTAKE_KINDS, ISSUE_TYPES, JIRA_STATUSES, ORDER_SCOPES, WORKER_KINDS, TERMINAL_ORDER_STATUSES, } from '../../conductor/types.js';
|
|
38
|
-
function open(opts) {
|
|
50
|
+
export function open(opts) {
|
|
39
51
|
const config = loadConfig().conductor;
|
|
40
52
|
return { store: ConductorStore.open(resolveStateDir(opts.stateDir, config)), config };
|
|
41
53
|
}
|
|
@@ -67,7 +79,7 @@ function launchersFor(ctx, env) {
|
|
|
67
79
|
* 컨덕터와 같은 자리, 같은 환경이라 여기서 못 막고 지시서 규칙에만 기댄다. 사고를 막는 장치이지
|
|
68
80
|
* 적대적인 워커를 막는 경계는 아니다.
|
|
69
81
|
*/
|
|
70
|
-
function assertConductorSession(ctx, command, cwd = process.cwd()) {
|
|
82
|
+
export function assertConductorSession(ctx, command, cwd = process.cwd()) {
|
|
71
83
|
assertCanSpawn(process.env);
|
|
72
84
|
const w = workerAt(cwd, ctx.store.workers());
|
|
73
85
|
if (w)
|
|
@@ -339,8 +351,13 @@ export function conductorOrderShowCommand(id, opts) {
|
|
|
339
351
|
}
|
|
340
352
|
console.log(`refs: ${refs.map(terminalText).join(', ') || '없음'}`);
|
|
341
353
|
console.log('gate:');
|
|
342
|
-
for (const g of gates)
|
|
354
|
+
for (const g of gates) {
|
|
343
355
|
console.log(` ${g.id} ${g.type} ${g.status} ${g.decision ?? '-'} ${terminalText(g.reason)}${g.answer ? ` 답: ${terminalText(g.answer)}` : ''}`);
|
|
356
|
+
if (g.receipt) {
|
|
357
|
+
for (const line of botDecisionStatus(g).itemReport?.split('\n') ?? [])
|
|
358
|
+
console.log(` ${terminalText(line)}`);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
344
361
|
console.log('bypass:');
|
|
345
362
|
for (const b of bypasses)
|
|
346
363
|
console.log(` ${b.at} ${terminalText(b.need)} ${terminalText(b.action)}`);
|
|
@@ -410,6 +427,17 @@ export function conductorExecPathCommand(opts) {
|
|
|
410
427
|
console.log([out.node, ...out.args].join(' '));
|
|
411
428
|
});
|
|
412
429
|
}
|
|
430
|
+
export async function conductorMonitorCommand(opts) {
|
|
431
|
+
try {
|
|
432
|
+
const dir = resolveStateDir(opts.stateDir, loadConfig().conductor);
|
|
433
|
+
const owner = readBotOwnership(dir).active;
|
|
434
|
+
const orca = await readConductorMonitor(owner);
|
|
435
|
+
print({ owner: owner ?? null, orca });
|
|
436
|
+
}
|
|
437
|
+
catch (e) {
|
|
438
|
+
exitWithError(e);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
413
441
|
export function conductorStatusCommand(opts) {
|
|
414
442
|
run(() => {
|
|
415
443
|
const { store, config } = open(opts);
|
|
@@ -427,6 +455,7 @@ export function conductorStatusCommand(opts) {
|
|
|
427
455
|
return print({
|
|
428
456
|
stateDir: store.dir,
|
|
429
457
|
lastTickAt: store.snapshot.lastTickAt ?? null,
|
|
458
|
+
lastSuccessfulTickAt: readLastSuccessfulTick(store.dir),
|
|
430
459
|
orders: orders.map((o) => {
|
|
431
460
|
const w = o.workerId ? store.worker(o.workerId) : undefined;
|
|
432
461
|
return {
|
|
@@ -477,6 +506,7 @@ export function conductorStatusCommand(opts) {
|
|
|
477
506
|
openedAt: g.openedAt,
|
|
478
507
|
})),
|
|
479
508
|
conductor: conductorSummary({ store, config }),
|
|
509
|
+
approvers: statusApprovers(store, config, orders),
|
|
480
510
|
...recentEventsField(store),
|
|
481
511
|
});
|
|
482
512
|
}
|
|
@@ -499,6 +529,12 @@ export function conductorStatusCommand(opts) {
|
|
|
499
529
|
}
|
|
500
530
|
for (const b of bypassesOf.get('') ?? [])
|
|
501
531
|
console.log(`bypass ${b.at} ${b.need} ${b.action}`);
|
|
532
|
+
const approvers = statusApprovers(store, config, orders);
|
|
533
|
+
if (approvers.policy !== 'present')
|
|
534
|
+
console.log(`승인자: 봇 정책 파일이 ${approvers.policy === 'missing' ? '없어요' : '깨져서 못 읽어요'}. 봇 채팅에서는 게이트를 못 닫아요`);
|
|
535
|
+
else
|
|
536
|
+
for (const a of approvers.repos)
|
|
537
|
+
console.log(`승인자 ${a.repo} 머지 ${a.merge ? `${a.merge}명` : '미등록'} 게이트 ${a.gate ? `${a.gate}명` : '미등록'}`);
|
|
502
538
|
for (const g of gates)
|
|
503
539
|
console.log(`게이트 ${g.id} ${g.type} ${g.reason}`);
|
|
504
540
|
});
|
|
@@ -519,6 +555,13 @@ function checkpointOf(store, orderId) {
|
|
|
519
555
|
},
|
|
520
556
|
};
|
|
521
557
|
}
|
|
558
|
+
/** 지금 보이는 주문과 경로를 등록한 레포, 정책에 적힌 레포의 승인자 등록 상태 */
|
|
559
|
+
function statusApprovers(store, config, orders) {
|
|
560
|
+
return approverRegistry(store.dir, [
|
|
561
|
+
...orders.map((o) => o.repo),
|
|
562
|
+
...Object.keys(config.repoPaths ?? {}),
|
|
563
|
+
]);
|
|
564
|
+
}
|
|
522
565
|
/**
|
|
523
566
|
* 컨덕터 자체의 값. 저장소와 설정에서 이미 아는 것만 싣는다.
|
|
524
567
|
* 컴팩트 횟수와 세션 id, 작업 디렉토리는 살아 있는 컨덕터 세션을 찾았을 때만 싣는다.
|
|
@@ -532,7 +575,10 @@ function conductorSummary(ctx) {
|
|
|
532
575
|
w.stopReason === 'disconnected' &&
|
|
533
576
|
store.order(w.orderId)?.workerId === w.id &&
|
|
534
577
|
!TERMINAL_ORDER_STATUSES.has(store.order(w.orderId).status)).length;
|
|
535
|
-
const botOwner = readBotOwnership(store.dir)
|
|
578
|
+
const { active: botOwner, revision: botOwnerRevision, handoffs } = readBotOwnership(store.dir);
|
|
579
|
+
const latestHandoff = handoffs.at(-1);
|
|
580
|
+
const cancelCleanupPending = latestHandoff &&
|
|
581
|
+
handoffCancellationPending(store.dir, latestHandoff, automationCoordinationRoot());
|
|
536
582
|
const session = botOwner
|
|
537
583
|
? undefined
|
|
538
584
|
: findActiveConductor(store.dir, '', Date.now(), activeConductorWindowMs(config));
|
|
@@ -543,7 +589,25 @@ function conductorSummary(ctx) {
|
|
|
543
589
|
queuedOrders: store.queuedOrders().length,
|
|
544
590
|
prWatchRepos: config.prWatchRepos,
|
|
545
591
|
disconnectedWorkers: disconnected,
|
|
546
|
-
...(botOwner ? { botOwner } : {}),
|
|
592
|
+
...(botOwner ? { botOwner, botOwnerRevision } : {}),
|
|
593
|
+
...(latestHandoff
|
|
594
|
+
? {
|
|
595
|
+
botHandoff: {
|
|
596
|
+
requestId: latestHandoff.id,
|
|
597
|
+
automationId: latestHandoff.automationId,
|
|
598
|
+
fromChatId: latestHandoff.from,
|
|
599
|
+
toChatId: latestHandoff.to,
|
|
600
|
+
status: cancelCleanupPending ? 'partial' : (latestHandoff.outcome ?? 'partial'),
|
|
601
|
+
...(!cancelCleanupPending && latestHandoff.outcome === 'cancelled'
|
|
602
|
+
? { cancelScope: 'gestalt' }
|
|
603
|
+
: {}),
|
|
604
|
+
...botHandoffEditStatus(latestHandoff),
|
|
605
|
+
...(cancelCleanupPending ? { retryStage: 'reconcile-edit' } : {}),
|
|
606
|
+
responsibleChatId: botOwner?.chatId,
|
|
607
|
+
verifiedNextRunAt: latestHandoff.nextRunAt,
|
|
608
|
+
},
|
|
609
|
+
}
|
|
610
|
+
: {}),
|
|
547
611
|
...(session
|
|
548
612
|
? {
|
|
549
613
|
compactions: readCompactions(store.dir, session.sessionId).count,
|
|
@@ -552,6 +616,31 @@ function conductorSummary(ctx) {
|
|
|
552
616
|
: {}),
|
|
553
617
|
};
|
|
554
618
|
}
|
|
619
|
+
function botHandoffEditStatus(handoff) {
|
|
620
|
+
const editAttemptId = handoff.editAttempt;
|
|
621
|
+
if (!editAttemptId)
|
|
622
|
+
return !handoff.outcome && handoff.editUncertain !== undefined
|
|
623
|
+
? { retryStage: 'reconcile-edit' }
|
|
624
|
+
: {};
|
|
625
|
+
let receipt;
|
|
626
|
+
let editReceipt;
|
|
627
|
+
try {
|
|
628
|
+
const dir = automationCoordinationDir(automationCoordinationRoot(), handoff.automationId);
|
|
629
|
+
receipt = readEditReceipt(dir, handoff.approval, editAttemptId);
|
|
630
|
+
editReceipt = receipt?.outcome ?? 'prepared';
|
|
631
|
+
}
|
|
632
|
+
catch {
|
|
633
|
+
editReceipt = 'unreadable';
|
|
634
|
+
}
|
|
635
|
+
return {
|
|
636
|
+
editAttemptId,
|
|
637
|
+
editReceipt,
|
|
638
|
+
...(receipt?.dispatchedAt ? { editDispatchedAt: receipt.dispatchedAt } : {}),
|
|
639
|
+
...(!handoff.outcome && (editReceipt === 'dispatched' || editReceipt === 'unreadable')
|
|
640
|
+
? { retryStage: 'reconcile-edit' }
|
|
641
|
+
: {}),
|
|
642
|
+
};
|
|
643
|
+
}
|
|
555
644
|
function rateLimitLine(e) {
|
|
556
645
|
const via = e.source === 'text' ? ', 출력 문구로 판단' : '';
|
|
557
646
|
return `한도 대기: ${e.workerId} ${e.since}부터${e.resetsAt ? `, 풀리는 시각 ${e.resetsAt}` : ''}${via}`;
|
|
@@ -587,7 +676,7 @@ export async function conductorTickCommand(opts) {
|
|
|
587
676
|
exitWithError(e);
|
|
588
677
|
}
|
|
589
678
|
}
|
|
590
|
-
async function tickBotCaller(ctx) {
|
|
679
|
+
export async function tickBotCaller(ctx) {
|
|
591
680
|
try {
|
|
592
681
|
return await currentBotOwner();
|
|
593
682
|
}
|
|
@@ -670,8 +759,10 @@ async function runConductorTick(ctx, opts, sessionId, caller, onClose = () => {
|
|
|
670
759
|
jira: hostJiraClient(deferred),
|
|
671
760
|
slack: hostSlackClient(deferred),
|
|
672
761
|
deploy: fileDeploySource(join(ctx.store.dir, 'deploy')),
|
|
762
|
+
deploymentEvidence: (target) => readDeploymentEvidence(target, gh),
|
|
673
763
|
...(prSource ? { prSource } : {}),
|
|
674
764
|
prState: new GhPrStateSource({ accounts: gh }),
|
|
765
|
+
readApprovalEvidence: (ref) => readMergeEvidence(ref, gh),
|
|
675
766
|
...(queue ? { queue } : {}),
|
|
676
767
|
...(Object.keys(ctx.config.accounts).length > 0
|
|
677
768
|
? { accounts: new GhAccountSwitcher({ accounts: gh }) }
|
|
@@ -681,13 +772,13 @@ async function runConductorTick(ctx, opts, sessionId, caller, onClose = () => {
|
|
|
681
772
|
const report = await tick(ctx.store, deps, {
|
|
682
773
|
force: opts.force === true,
|
|
683
774
|
admit: () => assertBotOwner(ctx.store.dir, caller),
|
|
775
|
+
inputErrors: () => [
|
|
776
|
+
...(queue?.errors ?? []),
|
|
777
|
+
...(watch?.errors ?? []),
|
|
778
|
+
...[...(prSource?.truncatedRepos ?? [])].map((repo) => `${repo}: 열린 PR이 상한에 닿아 뒤쪽 PR은 이번 감시에서 빠졌어요`),
|
|
779
|
+
],
|
|
684
780
|
});
|
|
685
781
|
report.hostActions.push(...deferred);
|
|
686
|
-
// 건너뛴 tick은 감시를 안 돌았다. 경로 누락 오류를 붙이면 출력이 그걸 건너뛴 이유로 보여 준다
|
|
687
|
-
if (!report.skipped)
|
|
688
|
-
report.errors.push(...(queue?.errors ?? []), ...(watch?.errors ?? []));
|
|
689
|
-
for (const repo of prSource?.truncatedRepos ?? [])
|
|
690
|
-
report.errors.push(`${repo}: 열린 PR이 상한에 닿아 뒤쪽 PR은 이번 감시에서 빠졌어요`);
|
|
691
782
|
const handoff = sessionId ? sessionHandoff(ctx, sessionId) : undefined;
|
|
692
783
|
return { report, ...(handoff ? { handoff } : {}), handoffClose };
|
|
693
784
|
}
|
|
@@ -1023,11 +1114,96 @@ export function conductorGateListCommand(opts) {
|
|
|
1023
1114
|
}
|
|
1024
1115
|
});
|
|
1025
1116
|
}
|
|
1117
|
+
export async function conductorWorkerDecisionCommand(opts) {
|
|
1118
|
+
try {
|
|
1119
|
+
assertOwnWorkerId(opts.worker);
|
|
1120
|
+
const ctx = open(opts);
|
|
1121
|
+
const lock = await waitForDecisionLock(ctx);
|
|
1122
|
+
try {
|
|
1123
|
+
ctx.store.reload();
|
|
1124
|
+
const gate = Object.values(ctx.store.snapshot.gates).find((g) => g.receipt?.deliveryId === opts.delivery);
|
|
1125
|
+
const order = gate?.orderId ? ctx.store.order(gate.orderId) : undefined;
|
|
1126
|
+
const worker = ctx.store.worker(opts.worker);
|
|
1127
|
+
if (!gate ||
|
|
1128
|
+
(gate.receipt?.workerId ?? order?.workerId) !== opts.worker ||
|
|
1129
|
+
!worker ||
|
|
1130
|
+
worker.kind === 'orca-worktree' ||
|
|
1131
|
+
worker.orderId !== gate.orderId)
|
|
1132
|
+
throw new Error('이 워커가 받을 수 있는 전달 ID가 아니에요');
|
|
1133
|
+
const received = (alreadyReceived, report) => ({
|
|
1134
|
+
deliveryId: opts.delivery,
|
|
1135
|
+
alreadyReceived,
|
|
1136
|
+
processing: report ? 'reported' : 'pending',
|
|
1137
|
+
...(report ? { workerReport: report } : {}),
|
|
1138
|
+
});
|
|
1139
|
+
if (gate.workerReport)
|
|
1140
|
+
return print(received(true, gate.workerReport));
|
|
1141
|
+
if (opts.report !== undefined) {
|
|
1142
|
+
const ref = opts.report.trim();
|
|
1143
|
+
if (!gate.hostOfferedAt || !ref || ref.length > 500)
|
|
1144
|
+
throw new Error('결정을 조회한 뒤 처리 결과를 확인할 참조를 500자 이내로 주세요');
|
|
1145
|
+
const at = ctx.store.timestamp();
|
|
1146
|
+
const workerReport = { at, workerId: worker.id, ref };
|
|
1147
|
+
ctx.store.append({
|
|
1148
|
+
type: 'gate-delivery',
|
|
1149
|
+
at,
|
|
1150
|
+
gateId: gate.id,
|
|
1151
|
+
pending: false,
|
|
1152
|
+
outcome: gate.deliveryOutcome === 'superseded' ? 'superseded' : 'delivered',
|
|
1153
|
+
...(gate.deliveryDetail && gate.deliveryOutcome === 'superseded'
|
|
1154
|
+
? { detail: gate.deliveryDetail }
|
|
1155
|
+
: {}),
|
|
1156
|
+
workerReport,
|
|
1157
|
+
});
|
|
1158
|
+
return print(received(true, workerReport));
|
|
1159
|
+
}
|
|
1160
|
+
if (order?.workerId !== opts.worker ||
|
|
1161
|
+
(order.status !== 'running' &&
|
|
1162
|
+
order.status !== 'waiting-gate' &&
|
|
1163
|
+
order.status !== 'escalated') ||
|
|
1164
|
+
(worker.status !== 'running' && worker.status !== 'starting') ||
|
|
1165
|
+
(!gate.deliveryPending && gate.deliveryOutcome !== 'delivered'))
|
|
1166
|
+
throw new Error('이 결정은 지금 받을 수 없어요. 컨덕터에서 전달 상태를 확인해 주세요');
|
|
1167
|
+
const gh = new GhAccounts(ctx.config.accounts);
|
|
1168
|
+
const changed = await recheckSignedDecision(ctx.store, gate, {
|
|
1169
|
+
...launchersFor(ctx, process.env),
|
|
1170
|
+
readApprovalEvidence: (ref) => readMergeEvidence(ref, gh),
|
|
1171
|
+
});
|
|
1172
|
+
if (changed)
|
|
1173
|
+
throw new Error(changed.detail);
|
|
1174
|
+
if (!gate.hostOfferedAt) {
|
|
1175
|
+
const at = ctx.store.timestamp();
|
|
1176
|
+
ctx.store.append({
|
|
1177
|
+
type: 'gate-delivery',
|
|
1178
|
+
at,
|
|
1179
|
+
gateId: gate.id,
|
|
1180
|
+
pending: true,
|
|
1181
|
+
outcome: 'host-action',
|
|
1182
|
+
hostOfferedAt: at,
|
|
1183
|
+
});
|
|
1184
|
+
}
|
|
1185
|
+
return print({
|
|
1186
|
+
...received(Boolean(gate.hostOfferedAt) || gate.deliveryOutcome === 'delivered'),
|
|
1187
|
+
decision: gate.decision,
|
|
1188
|
+
message: decisionMessage(gate),
|
|
1189
|
+
nextAction: '같은 전달 ID의 기존 처리 결과를 먼저 대조하세요. 처리 후 --report로 결과 참조를 남겨 주세요.',
|
|
1190
|
+
});
|
|
1191
|
+
}
|
|
1192
|
+
finally {
|
|
1193
|
+
lock.release();
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
catch (error) {
|
|
1197
|
+
exitWithError(error);
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1026
1200
|
export async function conductorGateResolveCommand(gateId, opts) {
|
|
1027
1201
|
try {
|
|
1028
1202
|
const picked = [opts.approve, opts.reject, opts.takeOver].filter(Boolean).length;
|
|
1029
1203
|
if (picked !== 1)
|
|
1030
1204
|
throw new Error('--approve, --reject, --take-over 중 하나만 주세요');
|
|
1205
|
+
if (opts.completedDeploy !== undefined && (!opts.approve || opts.deferDelivery))
|
|
1206
|
+
throw new Error('--completed-deploy는 이미 끝난 배포 주문의 --approve에만 쓸 수 있어요');
|
|
1031
1207
|
const ctx = open(opts);
|
|
1032
1208
|
assertConductorSession(ctx, 'gate resolve');
|
|
1033
1209
|
if (await tickBotCaller(ctx))
|
|
@@ -1042,6 +1218,19 @@ export async function conductorGateResolveCommand(gateId, opts) {
|
|
|
1042
1218
|
throw new Error(`모르는 게이트예요: ${gateId}`);
|
|
1043
1219
|
if (gate.status !== 'open')
|
|
1044
1220
|
throw new Error(`이미 종료된 게이트예요: ${gateId}`);
|
|
1221
|
+
if (opts.completedDeploy !== undefined) {
|
|
1222
|
+
const order = gate.orderId ? ctx.store.order(gate.orderId) : undefined;
|
|
1223
|
+
if (order?.scope !== 'approval' || order.status !== 'done')
|
|
1224
|
+
throw new Error('끝난 승인 주문의 배포 게이트만 완료 대조를 예약할 수 있어요');
|
|
1225
|
+
const approvedDeployment = approveDeployment(gate, order.repo, opts.completedDeploy);
|
|
1226
|
+
const closed = resolveGate(ctx.store, gateId, 'approved', opts.answer, {
|
|
1227
|
+
approvedDeployment,
|
|
1228
|
+
});
|
|
1229
|
+
if (opts.json)
|
|
1230
|
+
return print({ gate: closed });
|
|
1231
|
+
console.log(`${gateId} 배포 범위를 승인했어요. 다음 tick에서 성공 증빙을 대조해요`);
|
|
1232
|
+
return;
|
|
1233
|
+
}
|
|
1045
1234
|
if (opts.takeOver) {
|
|
1046
1235
|
if (!gate.orderId)
|
|
1047
1236
|
throw new Error(`${gateId}는 주문이 없는 게이트라 넘겨받을 주문이 없어요`);
|
|
@@ -1216,21 +1405,66 @@ function queueDirOf(ctx) {
|
|
|
1216
1405
|
}
|
|
1217
1406
|
export function conductorSlackDraftCommand(opts) {
|
|
1218
1407
|
run(() => {
|
|
1219
|
-
const
|
|
1408
|
+
const ctx = open(opts);
|
|
1409
|
+
const { store } = ctx;
|
|
1410
|
+
if (!isSlackChannelId(opts.channel))
|
|
1411
|
+
throw new Error('Slack 채널 이름 대신 채널 ID를 주세요');
|
|
1220
1412
|
const text = readFileSync(opts.textFile, 'utf-8').trim();
|
|
1221
1413
|
if (!text)
|
|
1222
1414
|
throw new Error('초안이 비었어요');
|
|
1223
|
-
const
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1415
|
+
const lock = acquireDecisionLock(ctx);
|
|
1416
|
+
try {
|
|
1417
|
+
store.reload();
|
|
1418
|
+
const { gate, reused } = draftSlack(store, {
|
|
1419
|
+
channel: opts.channel,
|
|
1420
|
+
text,
|
|
1421
|
+
...(opts.order ? { orderId: opts.order } : {}),
|
|
1422
|
+
...(opts.thread ? { threadTs: opts.thread } : {}),
|
|
1423
|
+
}, join(store.dir, 'slack'));
|
|
1424
|
+
if (opts.json)
|
|
1425
|
+
return print({ gateId: gate.id, reused });
|
|
1426
|
+
console.log(`승인을 기다려요: ${gate.id}${reused ? ' (같은 초안이 이미 올라가 있어요)' : ''}`);
|
|
1427
|
+
}
|
|
1428
|
+
finally {
|
|
1429
|
+
lock.release();
|
|
1430
|
+
}
|
|
1232
1431
|
});
|
|
1233
1432
|
}
|
|
1433
|
+
export async function conductorSlackDeliveryCommand(gateId, opts) {
|
|
1434
|
+
try {
|
|
1435
|
+
const ctx = open(opts);
|
|
1436
|
+
assertConductorSession(ctx, 'slack delivery');
|
|
1437
|
+
assertBotOwner(ctx.store.dir, await tickBotCaller(ctx));
|
|
1438
|
+
ctx.store.reload();
|
|
1439
|
+
print(pendingSlackDelivery(ctx.store, gateId));
|
|
1440
|
+
}
|
|
1441
|
+
catch (error) {
|
|
1442
|
+
exitWithError(error);
|
|
1443
|
+
}
|
|
1444
|
+
}
|
|
1445
|
+
export async function conductorSlackPostedCommand(gateId, opts) {
|
|
1446
|
+
try {
|
|
1447
|
+
const ctx = open(opts);
|
|
1448
|
+
assertConductorSession(ctx, 'slack posted');
|
|
1449
|
+
const caller = await tickBotCaller(ctx);
|
|
1450
|
+
const resultData = JSON.parse(readFileSync(opts.resultFile, 'utf8'));
|
|
1451
|
+
const lock = acquireDecisionLock(ctx);
|
|
1452
|
+
try {
|
|
1453
|
+
assertBotOwner(ctx.store.dir, caller);
|
|
1454
|
+
const result = confirmSlackDelivery(ctx.store, gateId, resultData);
|
|
1455
|
+
ctx.store.flushSnapshot();
|
|
1456
|
+
if (opts.json)
|
|
1457
|
+
return print({ gateId, ...result });
|
|
1458
|
+
console.log(result.recorded ? 'Slack 게시 결과를 남겼어요' : '같은 Slack 게시 결과가 이미 있어요');
|
|
1459
|
+
}
|
|
1460
|
+
finally {
|
|
1461
|
+
lock.release();
|
|
1462
|
+
}
|
|
1463
|
+
}
|
|
1464
|
+
catch (error) {
|
|
1465
|
+
exitWithError(error);
|
|
1466
|
+
}
|
|
1467
|
+
}
|
|
1234
1468
|
export function conductorMetricsCommand(opts) {
|
|
1235
1469
|
run(() => {
|
|
1236
1470
|
const since = Date.parse(opts.since);
|
|
@@ -1286,7 +1520,7 @@ function nonNegativeInt(v, flag) {
|
|
|
1286
1520
|
throw new Error(`${flag}는 0 이상의 정수여야 해요: ${v}`);
|
|
1287
1521
|
return n;
|
|
1288
1522
|
}
|
|
1289
|
-
function print(v) {
|
|
1523
|
+
export function print(v) {
|
|
1290
1524
|
console.log(JSON.stringify(v, null, 2));
|
|
1291
1525
|
}
|
|
1292
1526
|
function run(body) {
|
|
@@ -1297,7 +1531,7 @@ function run(body) {
|
|
|
1297
1531
|
exitWithError(e);
|
|
1298
1532
|
}
|
|
1299
1533
|
}
|
|
1300
|
-
function exitWithError(e) {
|
|
1534
|
+
export function exitWithError(e) {
|
|
1301
1535
|
console.error(e instanceof Error ? e.message : String(e));
|
|
1302
1536
|
process.exit(1);
|
|
1303
1537
|
}
|
|
@@ -1347,17 +1581,72 @@ export async function conductorBotReleaseCommand(opts) {
|
|
|
1347
1581
|
exitWithError(error);
|
|
1348
1582
|
}
|
|
1349
1583
|
}
|
|
1584
|
+
export async function conductorBotHandoffCommand(opts) {
|
|
1585
|
+
try {
|
|
1586
|
+
const ctx = open(opts);
|
|
1587
|
+
assertConductorSession(ctx, 'bot handoff');
|
|
1588
|
+
if (await tickBotCaller(ctx))
|
|
1589
|
+
throw new Error('인계는 운영자 터미널에서 실행해 주세요');
|
|
1590
|
+
const result = await handoffBot(ctx.store.dir, opts);
|
|
1591
|
+
if (opts.json)
|
|
1592
|
+
print(result);
|
|
1593
|
+
else {
|
|
1594
|
+
const labels = {
|
|
1595
|
+
ready: '승인 가능',
|
|
1596
|
+
blocked: '인계 보류',
|
|
1597
|
+
partial: '인계 진행 중',
|
|
1598
|
+
completed: '인계 완료',
|
|
1599
|
+
cancelled: '로컬 인계 요청 취소',
|
|
1600
|
+
};
|
|
1601
|
+
console.log(`${labels[result.status]} · 요청 ${result.requestId}`);
|
|
1602
|
+
console.log(`인계 채팅 ${result.fromChatId} → ${result.toChatId}`);
|
|
1603
|
+
console.log(`현재 책임 채팅: ${result.responsibleChatId ?? '등록 없음'} (리비전 ${result.ownerRevision})`);
|
|
1604
|
+
const automationLabel = result.replayed ? '종료 당시 자동화' : '자동화';
|
|
1605
|
+
console.log(`${automationLabel} ${result.automationId}: ${result.automationChatId ?? '현재 대상 미확인'}`);
|
|
1606
|
+
if (result.schedule)
|
|
1607
|
+
console.log(`주기: ${result.schedule}`);
|
|
1608
|
+
if (result.orcaVerification === 'observed')
|
|
1609
|
+
console.log('Orca의 채팅과 일정은 별도로 조회했어요');
|
|
1610
|
+
if (result.verifiedNextRunAt !== undefined)
|
|
1611
|
+
console.log(`조회 당시 다음 정기 실행: ${new Date(result.verifiedNextRunAt).toISOString()}`);
|
|
1612
|
+
if (result.approval)
|
|
1613
|
+
console.log(`인계 승인: 같은 명령에 --approve ${result.approval}`);
|
|
1614
|
+
if (result.retryStage)
|
|
1615
|
+
console.log(`재개 단계: ${result.retryStage}`);
|
|
1616
|
+
if (result.editAttemptId)
|
|
1617
|
+
console.log(`Orca 편집 시도 ID ${result.editAttemptId}`);
|
|
1618
|
+
if (result.editDispatchedAt)
|
|
1619
|
+
console.log(`Orca 편집 요청 시각 ${result.editDispatchedAt}`);
|
|
1620
|
+
if (result.detail)
|
|
1621
|
+
console.log(result.detail);
|
|
1622
|
+
}
|
|
1623
|
+
if (result.status === 'blocked' || result.status === 'partial')
|
|
1624
|
+
process.exitCode = 1;
|
|
1625
|
+
}
|
|
1626
|
+
catch (error) {
|
|
1627
|
+
exitWithError(error);
|
|
1628
|
+
}
|
|
1629
|
+
}
|
|
1350
1630
|
function acquireDecisionLock(ctx) {
|
|
1351
1631
|
const lock = acquireLock(ctx.store.dir);
|
|
1352
1632
|
if (!lock.ok)
|
|
1353
1633
|
throw new Error('컨덕터가 상태를 갱신 중이에요. 잠시 뒤 게이트를 다시 확인해 주세요');
|
|
1354
1634
|
return lock;
|
|
1355
1635
|
}
|
|
1636
|
+
async function waitForDecisionLock(ctx) {
|
|
1637
|
+
const deadline = Date.now() + 20_000;
|
|
1638
|
+
do {
|
|
1639
|
+
const lock = acquireLock(ctx.store.dir);
|
|
1640
|
+
if (lock.ok)
|
|
1641
|
+
return lock;
|
|
1642
|
+
await delay(100);
|
|
1643
|
+
} while (Date.now() < deadline);
|
|
1644
|
+
throw new InputError('컨덕터가 상태를 갱신 중이에요. 잠시 뒤 같은 결정을 다시 요청해 주세요');
|
|
1645
|
+
}
|
|
1356
1646
|
async function closeAndDeliver(ctx, gateId, decision, options) {
|
|
1357
1647
|
const { store } = ctx;
|
|
1358
1648
|
const closed = resolveGate(store, gateId, decision, options.answer, {
|
|
1359
1649
|
deliveryPending: options.defer,
|
|
1360
|
-
...(options.signer ? { decisionBy: options.signer } : {}),
|
|
1361
1650
|
});
|
|
1362
1651
|
const delivered = await deliverGateDecision(store, closed, launchersFor(ctx, process.env), {
|
|
1363
1652
|
defer: options.defer,
|
|
@@ -1374,37 +1663,192 @@ async function requireBotOperator(ctx) {
|
|
|
1374
1663
|
assertBotOwner(ctx.store.dir, caller);
|
|
1375
1664
|
return caller;
|
|
1376
1665
|
}
|
|
1666
|
+
const DELIVERY_LABELS = {
|
|
1667
|
+
pending: '대기 중(다음 tick이 전해요)',
|
|
1668
|
+
delivered: '전달됨',
|
|
1669
|
+
failed: '실패',
|
|
1670
|
+
'host-action': '호스트 작업으로 넘김',
|
|
1671
|
+
'no-worker': '받을 워커 없음',
|
|
1672
|
+
unknown: '결과 확인 필요',
|
|
1673
|
+
superseded: '새 결정 필요',
|
|
1674
|
+
};
|
|
1675
|
+
/** 결정과 워커 전달을 따로 싣는다. 승인했어도 워커가 아직 못 받았을 수 있어서다 */
|
|
1377
1676
|
function botDecisionStatus(gate) {
|
|
1677
|
+
const receipt = gate.receipt;
|
|
1678
|
+
const delivery = receipt
|
|
1679
|
+
? (gate.deliveryOutcome ?? 'pending')
|
|
1680
|
+
: gate.deliveryPending
|
|
1681
|
+
? 'pending'
|
|
1682
|
+
: (gate.deliveryOutcome ?? 'unknown');
|
|
1683
|
+
const nextAction = receipt ? approvalNextAction(gate) : undefined;
|
|
1684
|
+
const processing = gate.workerReport
|
|
1685
|
+
? 'reported'
|
|
1686
|
+
: gate.deliveryOutcome === 'no-worker'
|
|
1687
|
+
? 'no-worker'
|
|
1688
|
+
: gate.deliveryOutcome === 'delivered' ||
|
|
1689
|
+
gate.deliveryOutcome === 'unknown' ||
|
|
1690
|
+
(gate.deliveryOutcome === 'superseded' && gate.hostOfferedAt)
|
|
1691
|
+
? 'unknown'
|
|
1692
|
+
: gate.deliveryOutcome === 'superseded'
|
|
1693
|
+
? 'superseded'
|
|
1694
|
+
: 'pending';
|
|
1695
|
+
const source = gate.decisionSource;
|
|
1696
|
+
const decided = gate.decision === 'approved' ? '승인' : gate.decision === 'rejected' ? '거절' : gate.decision;
|
|
1697
|
+
const approvalLabel = source?.attestation ? 'Orca 증빙' : '서명';
|
|
1378
1698
|
return {
|
|
1379
1699
|
gateId: gate.id,
|
|
1380
1700
|
decision: gate.decision ?? 'open',
|
|
1381
1701
|
...(gate.decisionBy ? { signer: gate.decisionBy } : {}),
|
|
1382
|
-
|
|
1383
|
-
|
|
1702
|
+
...(source ? { source } : {}),
|
|
1703
|
+
delivery,
|
|
1704
|
+
...(receipt
|
|
1705
|
+
? {
|
|
1706
|
+
decisionId: receipt.id,
|
|
1707
|
+
deliveryId: receipt.deliveryId,
|
|
1708
|
+
receivedAt: gate.resolvedAt,
|
|
1709
|
+
gateApplication: 'applied',
|
|
1710
|
+
appliedAt: gate.resolvedAt,
|
|
1711
|
+
target: {
|
|
1712
|
+
repo: receipt.repo,
|
|
1713
|
+
prRef: receipt.prRef,
|
|
1714
|
+
head: receipt.head,
|
|
1715
|
+
base: receipt.base,
|
|
1716
|
+
},
|
|
1717
|
+
deliveryPending: gate.deliveryPending === true,
|
|
1718
|
+
processing,
|
|
1719
|
+
...(gate.hostOfferedAt ? { hostOfferedAt: gate.hostOfferedAt } : {}),
|
|
1720
|
+
...(gate.workerReport ? { workerReport: gate.workerReport } : {}),
|
|
1721
|
+
nextAction,
|
|
1722
|
+
}
|
|
1723
|
+
: {}),
|
|
1724
|
+
...(gate.deliveryAttempts
|
|
1725
|
+
? {
|
|
1726
|
+
...(receipt ? { deliveryAttempts: gate.deliveryAttempts } : {}),
|
|
1727
|
+
...(delivery !== 'delivered' ? { failedAttempts: gate.deliveryAttempts } : {}),
|
|
1728
|
+
}
|
|
1729
|
+
: {}),
|
|
1730
|
+
...(gate.deliveryDetail ? { deliveryDetail: gate.deliveryDetail } : {}),
|
|
1731
|
+
...(gate.decision
|
|
1732
|
+
? {
|
|
1733
|
+
itemReport: [
|
|
1734
|
+
`판단: ${decided}${gate.decisionBy ? ` (${approvalLabel} ${gate.decisionBy})` : ''}${source ? `, Orca 항목 ${source.item}의 답 ${source.answer}` : ''}`,
|
|
1735
|
+
...(receipt ? [`결정 접수 및 게이트 반영: ${gate.resolvedAt}`] : []),
|
|
1736
|
+
`워커 전달: ${DELIVERY_LABELS[delivery] ?? delivery}${gate.deliveryAttempts ? `, 시도 ${gate.deliveryAttempts}번` : ''}`,
|
|
1737
|
+
...(gate.workerReport ? [`워커 처리 보고: ${gate.workerReport.ref}`] : []),
|
|
1738
|
+
...(gate.deliveryDetail ? [gate.deliveryDetail] : []),
|
|
1739
|
+
...(nextAction ? [nextAction] : []),
|
|
1740
|
+
].join('\n'),
|
|
1741
|
+
}
|
|
1742
|
+
: {}),
|
|
1384
1743
|
};
|
|
1385
1744
|
}
|
|
1745
|
+
function approvalNextAction(gate) {
|
|
1746
|
+
switch (gate.deliveryOutcome) {
|
|
1747
|
+
case 'superseded':
|
|
1748
|
+
return '변경된 대상에 대해 새 결정을 접수해 주세요.';
|
|
1749
|
+
case 'host-action':
|
|
1750
|
+
return gate.hostOfferedAt
|
|
1751
|
+
? '같은 전달 ID로 처리 결과를 대조한 뒤 워커가 결과 참조를 남깁니다.'
|
|
1752
|
+
: '호스트가 워커에 전달하고 워커가 전달 ID로 조회합니다.';
|
|
1753
|
+
case 'unknown':
|
|
1754
|
+
return gate.deliveryPending
|
|
1755
|
+
? '다음 tick이 같은 전달 ID로 Orca의 결과를 확인합니다.'
|
|
1756
|
+
: '마지막 전달은 워커의 보고와 대조해 주세요.';
|
|
1757
|
+
case 'failed':
|
|
1758
|
+
return '다음 tick이 같은 결정으로 다시 시도합니다.';
|
|
1759
|
+
case 'delivered':
|
|
1760
|
+
return gate.workerReport ? undefined : '워커의 실제 처리 결과는 워커 보고에서 확인해 주세요.';
|
|
1761
|
+
case 'no-worker':
|
|
1762
|
+
return undefined;
|
|
1763
|
+
default:
|
|
1764
|
+
return '다음 tick이 전달 대상을 확인합니다.';
|
|
1765
|
+
}
|
|
1766
|
+
}
|
|
1767
|
+
const GATE_REQUESTS = {
|
|
1768
|
+
merge: '머지 승인 또는 거절',
|
|
1769
|
+
'file-overlap': '같은 파일을 고치는 주문을 이어서 진행할지',
|
|
1770
|
+
'review-manual-switch': '답글만 달린 PR을 다시 리뷰할지',
|
|
1771
|
+
};
|
|
1772
|
+
async function botGateEvidence(ctx, target) {
|
|
1773
|
+
return target.ref
|
|
1774
|
+
? readMergeEvidence(target.ref, new GhAccounts(ctx.config.accounts))
|
|
1775
|
+
: undefined;
|
|
1776
|
+
}
|
|
1777
|
+
/** 서명 문자열에 PR과 HEAD가 들어가는 게이트는 그 값을 못 읽으면 승인 페이지에 원인을 400으로 돌려준다 */
|
|
1778
|
+
async function touchIdGateEvidence(ctx, target) {
|
|
1779
|
+
const evidence = await botGateEvidence(ctx, target);
|
|
1780
|
+
if (!evidence && (target.gate.type === 'merge' || target.gate.type === 'review-manual-switch'))
|
|
1781
|
+
throw new InputError('이 게이트는 PR과 HEAD를 읽어야 서명을 확인할 수 있어요');
|
|
1782
|
+
return evidence;
|
|
1783
|
+
}
|
|
1386
1784
|
export async function conductorBotGateCommand(gateId, opts) {
|
|
1387
1785
|
try {
|
|
1388
1786
|
const ctx = open(opts);
|
|
1389
|
-
await requireBotOperator(ctx);
|
|
1390
|
-
const
|
|
1787
|
+
const caller = await requireBotOperator(ctx);
|
|
1788
|
+
const resolved = ctx.store.snapshot.gates[gateId];
|
|
1789
|
+
if (resolved?.receipt) {
|
|
1790
|
+
const { repo, prRef } = resolved.receipt;
|
|
1791
|
+
return print({
|
|
1792
|
+
...botDecisionStatus(resolved),
|
|
1793
|
+
type: resolved.type,
|
|
1794
|
+
repo,
|
|
1795
|
+
...(prRef ? { pr: `https://github.com/${prRef.replace('#', '/pull/')}` } : {}),
|
|
1796
|
+
request: GATE_REQUESTS[resolved.type],
|
|
1797
|
+
reason: resolved.reason,
|
|
1798
|
+
refs: resolved.refs,
|
|
1799
|
+
});
|
|
1800
|
+
}
|
|
1801
|
+
const target = matchBotGate(ctx.store, gateId);
|
|
1802
|
+
const { gate } = target;
|
|
1391
1803
|
const base = {
|
|
1392
1804
|
...botDecisionStatus(gate),
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1805
|
+
type: gate.type,
|
|
1806
|
+
repo: target.repo,
|
|
1807
|
+
...(target.title ? { title: target.title } : {}),
|
|
1808
|
+
...(target.url ? { pr: target.url } : {}),
|
|
1809
|
+
request: GATE_REQUESTS[gate.type],
|
|
1397
1810
|
reason: gate.reason,
|
|
1811
|
+
refs: gate.refs,
|
|
1398
1812
|
};
|
|
1399
1813
|
if (gate.status === 'resolved')
|
|
1400
1814
|
return print(base);
|
|
1401
|
-
|
|
1815
|
+
// 승인자가 없으면 서명을 요구할 이유가 없다. 봇이 터미널 안내로 바로 가게 서명 재료를 싣지 않는다
|
|
1816
|
+
const read = peekBotPolicy(ctx.store.dir);
|
|
1817
|
+
const policy = 'policy' in read ? read.policy : undefined;
|
|
1818
|
+
const gap = 'unreadable' in read ? 'unreadable' : approverStatus(policy, gate.type, target.repo).gap;
|
|
1819
|
+
if (gap)
|
|
1820
|
+
return print({
|
|
1821
|
+
...base,
|
|
1822
|
+
approverReady: false,
|
|
1823
|
+
approverGap: gap,
|
|
1824
|
+
guidance: approverGuidance(gate, target.repo, gap),
|
|
1825
|
+
terminal: {
|
|
1826
|
+
approved: terminalResolveCommand(gate.id, 'approved'),
|
|
1827
|
+
rejected: terminalResolveCommand(gate.id, 'rejected'),
|
|
1828
|
+
},
|
|
1829
|
+
});
|
|
1830
|
+
const evidence = await botGateEvidence(ctx, target);
|
|
1831
|
+
const issuer = await officialOrcaApprovalIssuer(caller);
|
|
1832
|
+
const touchId = touchIdLinks(ctx, gate.id, webAuthnApprovers(policy, gate.type, target.repo));
|
|
1402
1833
|
print({
|
|
1403
1834
|
...base,
|
|
1404
|
-
|
|
1835
|
+
approverReady: true,
|
|
1836
|
+
...touchId,
|
|
1837
|
+
...(evidence ? { evidence } : {}),
|
|
1405
1838
|
messages: {
|
|
1406
|
-
approved:
|
|
1407
|
-
rejected:
|
|
1839
|
+
approved: gateApprovalMessage(target, evidence?.head, 'approved', evidence?.base),
|
|
1840
|
+
rejected: gateApprovalMessage(target, evidence?.head, 'rejected', evidence?.base),
|
|
1841
|
+
},
|
|
1842
|
+
orcaItem: {
|
|
1843
|
+
binding: itemBinding(target, evidence?.head, evidence?.base),
|
|
1844
|
+
options: issuer ? ['승인', '거절'] : [],
|
|
1845
|
+
buttonApproval: issuer
|
|
1846
|
+
? {
|
|
1847
|
+
enabled: true,
|
|
1848
|
+
targetHash: orcaApprovalTargetHash(decisionTarget(ctx.store, target), evidence),
|
|
1849
|
+
}
|
|
1850
|
+
: { enabled: false, diagnostic: ORCA_APPROVAL_UNAVAILABLE },
|
|
1851
|
+
answer: '첫 줄에 승인 또는 거절, 둘째 줄에 서명 <승인자-ID> <base64>',
|
|
1408
1852
|
},
|
|
1409
1853
|
});
|
|
1410
1854
|
}
|
|
@@ -1412,46 +1856,227 @@ export async function conductorBotGateCommand(gateId, opts) {
|
|
|
1412
1856
|
exitWithError(error);
|
|
1413
1857
|
}
|
|
1414
1858
|
}
|
|
1415
|
-
|
|
1859
|
+
/**
|
|
1860
|
+
* 승인자가 Touch ID 키를 등록할 때의 주소로 승인 페이지 링크를 만든다. --port로 등록했으면 그 포트로 띄워야
|
|
1861
|
+
* origin이 맞는다. 승인자마다 포트가 다르면 첫 승인자의 주소를 쓴다
|
|
1862
|
+
*/
|
|
1863
|
+
function touchIdLinks(ctx, gateId, approvers) {
|
|
1864
|
+
const first = approvers[0];
|
|
1865
|
+
if (!first)
|
|
1866
|
+
return {};
|
|
1867
|
+
const origin = first.credential.origin;
|
|
1868
|
+
const port = Number(new URL(origin).port) || APPROVAL_PORT;
|
|
1869
|
+
const link = (decision) => `${origin}/gate/${encodeURIComponent(gateId)}?decision=${decision}`;
|
|
1870
|
+
return {
|
|
1871
|
+
touchId: {
|
|
1872
|
+
links: { approved: link('approved'), rejected: link('rejected') },
|
|
1873
|
+
start: `gestalt conductor approval serve --detach --state-dir ${JSON.stringify(ctx.store.dir)}${port === APPROVAL_PORT ? '' : ` --port ${port}`}`,
|
|
1874
|
+
},
|
|
1875
|
+
};
|
|
1876
|
+
}
|
|
1877
|
+
function verifyBotDecision(policy, target, receiptTarget, evidence, request) {
|
|
1878
|
+
if ('webauthn' in request) {
|
|
1879
|
+
const { webauthn, decision, nonce, origin } = request;
|
|
1880
|
+
const approver = webAuthnApprovers(policy, target.gate.type, target.repo).find((a) => a.credential.credentialId === webauthn.credentialId);
|
|
1881
|
+
if (!approver)
|
|
1882
|
+
throw new InputError(`이 레포의 ${target.gate.type === 'merge' ? '머지' : '게이트'} 승인자로 등록된 Touch ID 키가 아니에요`);
|
|
1883
|
+
const { signCount } = verifyWebAuthnAssertion(approver.credential, {
|
|
1884
|
+
challenge: webAuthnChallenge(gateApprovalMessage(target, evidence?.head, decision, evidence?.base), nonce),
|
|
1885
|
+
origin,
|
|
1886
|
+
}, webauthn);
|
|
1887
|
+
return {
|
|
1888
|
+
id: decisionId(approver.id, Buffer.from(webauthn.signature, 'base64url').toString('base64')),
|
|
1889
|
+
signer: approver.id,
|
|
1890
|
+
via: { kind: 'webauthn', credentialId: webauthn.credentialId, signCount },
|
|
1891
|
+
};
|
|
1892
|
+
}
|
|
1893
|
+
if ('issuer' in request) {
|
|
1894
|
+
const { issuer, proof, decision, source } = request;
|
|
1895
|
+
const targetHash = orcaApprovalTargetHash(receiptTarget, evidence);
|
|
1896
|
+
return verifyOrcaApproval(issuer, proof, { source, decision, target, targetHash }, policy);
|
|
1897
|
+
}
|
|
1898
|
+
verifyGateApproval(policy, target.gate.type, target.repo, request.signer, gateApprovalMessage(target, evidence?.head, request.decision, evidence?.base), request.signature);
|
|
1899
|
+
return { ...request, id: decisionId(request.signer, request.signature) };
|
|
1900
|
+
}
|
|
1901
|
+
/**
|
|
1902
|
+
* 잠금 안에서 게이트와 승인 근거를 확인한다. 머지 결정은 GitHub HEAD까지 다시 읽어 승인 대상과 맞춘다.
|
|
1903
|
+
*/
|
|
1904
|
+
async function applyBotDecision(ctx, { caller, request }, gateId, beforeTarget, evidence, sameSource) {
|
|
1905
|
+
const lock = await waitForDecisionLock(ctx);
|
|
1416
1906
|
try {
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
const decision = oneOf(opts.decision, ['approved', 'rejected'], '--decision');
|
|
1420
|
-
const { gate, ref } = matchMergeGate(ctx.store, gateId);
|
|
1421
|
-
const evidence = gate.status === 'open'
|
|
1422
|
-
? await readMergeEvidence(ref, new GhAccounts(ctx.config.accounts))
|
|
1423
|
-
: undefined;
|
|
1424
|
-
const lock = acquireLock(ctx.store.dir);
|
|
1425
|
-
if (!lock.ok)
|
|
1426
|
-
throw new Error('컨덕터가 상태를 갱신 중이에요. 잠시 뒤 게이트를 다시 확인해 주세요');
|
|
1427
|
-
try {
|
|
1907
|
+
// Touch ID 승인은 운영 봇이 아니라 승인자 본인이 연 페이지에서 온다. 승인 근거는 서명이라 봇 운영권을 묻지 않는다
|
|
1908
|
+
if (caller || !('webauthn' in request))
|
|
1428
1909
|
assertBotOwner(ctx.store.dir, caller);
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
throw new Error('리뷰 준비가 끝난 열린 PR만 머지 승인할 수 있어요');
|
|
1437
|
-
verifyMergeApproval(readBotPolicy(ctx.store.dir), current.order.repo, opts.signer, approvalMessage(current.gate, ref, evidence.head, decision), opts.signature);
|
|
1438
|
-
const result = await closeAndDeliver(ctx, gateId, decision, {
|
|
1439
|
-
defer: true,
|
|
1440
|
-
signer: opts.signer,
|
|
1441
|
-
...(decision === 'approved'
|
|
1910
|
+
ctx.store.reload();
|
|
1911
|
+
const existing = ctx.store.snapshot.gates[gateId];
|
|
1912
|
+
if (existing?.status === 'resolved')
|
|
1913
|
+
return {
|
|
1914
|
+
...botDecisionStatus(existing),
|
|
1915
|
+
alreadyResolved: true,
|
|
1916
|
+
...(existing.receipt && 'signature' in request
|
|
1442
1917
|
? {
|
|
1443
|
-
|
|
1918
|
+
sameDecision: existing.decision === request.decision &&
|
|
1919
|
+
existing.receipt.id === decisionId(request.signer, request.signature),
|
|
1444
1920
|
}
|
|
1445
1921
|
: {}),
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1922
|
+
...(sameSource ? { sameAnswer: sameSource(existing) } : {}),
|
|
1923
|
+
};
|
|
1924
|
+
const current = matchBotGate(ctx.store, gateId);
|
|
1925
|
+
const receiptTarget = decisionTarget(ctx.store, current);
|
|
1926
|
+
if (receiptTarget !== beforeTarget)
|
|
1927
|
+
throw new InputError('게이트나 PR이 바뀌었어요. 다시 확인해 주세요');
|
|
1928
|
+
const head = evidence?.head;
|
|
1929
|
+
const { decision } = request;
|
|
1930
|
+
const approval = verifyBotDecision(assertApproverReady(loadBotPolicy(ctx.store.dir), current.gate, current.repo), current, receiptTarget, evidence, request);
|
|
1931
|
+
let checked;
|
|
1932
|
+
if (current.ref) {
|
|
1933
|
+
const now = await botGateEvidence(ctx, current);
|
|
1934
|
+
if (!now || !head || now.head !== head)
|
|
1935
|
+
throw new InputError('PR HEAD가 바뀌었어요. 새 HEAD로 다시 승인받아 주세요');
|
|
1936
|
+
if (evidence?.base !== now.base)
|
|
1937
|
+
throw new InputError('PR의 base 브랜치가 바뀌었어요. 다시 확인해 주세요');
|
|
1938
|
+
if (current.gate.type === 'merge' &&
|
|
1939
|
+
decision === 'approved' &&
|
|
1940
|
+
(now.state !== 'OPEN' || now.draft))
|
|
1941
|
+
throw new InputError('리뷰 준비가 끝난 열린 PR만 머지 승인할 수 있어요');
|
|
1942
|
+
checked = now;
|
|
1451
1943
|
}
|
|
1452
|
-
|
|
1453
|
-
|
|
1944
|
+
if (approval.expiresAt !== undefined && approval.expiresAt <= Date.now())
|
|
1945
|
+
throw new InputError('Orca 승인 증빙의 유효기간을 벗어났어요');
|
|
1946
|
+
const answer = current.gate.type === 'merge' && checked && decision === 'approved'
|
|
1947
|
+
? `승인된 PR HEAD는 ${checked.head}입니다. 머지는 반드시 --match-head-commit ${checked.head}로 제한하세요. HEAD가 바뀌면 새 승인을 요청하세요.`
|
|
1948
|
+
: undefined;
|
|
1949
|
+
const closed = resolveGate(ctx.store, gateId, decision, answer, {
|
|
1950
|
+
deliveryPending: true,
|
|
1951
|
+
decisionBy: approval.signer,
|
|
1952
|
+
receipt: decisionReceipt(ctx.store, current, approval.id, checked),
|
|
1953
|
+
...(approval.source ? { decisionSource: approval.source } : {}),
|
|
1954
|
+
...(approval.via ? { decisionVia: approval.via } : {}),
|
|
1955
|
+
});
|
|
1956
|
+
return { ...botDecisionStatus(closed), errors: [] };
|
|
1957
|
+
}
|
|
1958
|
+
finally {
|
|
1959
|
+
lock.release();
|
|
1960
|
+
}
|
|
1961
|
+
}
|
|
1962
|
+
/** 승인 페이지는 승인자가 보는 자리라 깨진 정책 파일도 경로 대신 안내 문구로 돌려준다 */
|
|
1963
|
+
function touchIdPolicy(dir, gate, repo) {
|
|
1964
|
+
const read = peekBotPolicy(dir);
|
|
1965
|
+
if ('unreadable' in read)
|
|
1966
|
+
throw new InputError(approverGuidance(gate, repo, 'unreadable'));
|
|
1967
|
+
return assertApproverReady(read.policy, gate, repo);
|
|
1968
|
+
}
|
|
1969
|
+
/**
|
|
1970
|
+
* Touch ID 승인 페이지가 서명 전에 보여 줄 게이트 내용과 challenge. 봇 운영권 없이 승인자 본인이 연다.
|
|
1971
|
+
* nonce는 승인 서버가 발급해 메모리에 둔 값이다
|
|
1972
|
+
*/
|
|
1973
|
+
export async function touchIdGateOptions(opts, gateId, decision, nonce) {
|
|
1974
|
+
const ctx = open(opts);
|
|
1975
|
+
if (!ctx.store.snapshot.gates[gateId])
|
|
1976
|
+
throw new InputError('게이트를 찾을 수 없어요');
|
|
1977
|
+
const target = matchBotGate(ctx.store, gateId);
|
|
1978
|
+
if (target.gate.status !== 'open')
|
|
1979
|
+
throw new InputError('이미 닫힌 게이트예요');
|
|
1980
|
+
const policy = touchIdPolicy(ctx.store.dir, target.gate, target.repo);
|
|
1981
|
+
const approvers = webAuthnApprovers(policy, target.gate.type, target.repo);
|
|
1982
|
+
if (!approvers.length)
|
|
1983
|
+
throw new InputError(`${target.repo} 레포에는 이 게이트를 닫을 Touch ID 승인자가 없어요. gestalt conductor approver enroll로 먼저 등록해 주세요`);
|
|
1984
|
+
const evidence = await touchIdGateEvidence(ctx, target);
|
|
1985
|
+
return {
|
|
1986
|
+
gate: {
|
|
1987
|
+
id: target.gate.id,
|
|
1988
|
+
type: target.gate.type,
|
|
1989
|
+
repo: target.repo,
|
|
1990
|
+
reason: target.gate.reason,
|
|
1991
|
+
refs: target.gate.refs ?? [],
|
|
1992
|
+
...(target.url ? { pr: target.url } : {}),
|
|
1993
|
+
},
|
|
1994
|
+
...(evidence ? { head: evidence.head } : {}),
|
|
1995
|
+
decision,
|
|
1996
|
+
challenge: webAuthnChallenge(gateApprovalMessage(target, evidence?.head, decision, evidence?.base), nonce),
|
|
1997
|
+
nonce,
|
|
1998
|
+
credentialIds: approvers.map((a) => a.credential.credentialId),
|
|
1999
|
+
};
|
|
2000
|
+
}
|
|
2001
|
+
/** Touch ID 서명으로 게이트를 닫는다. 서명 확인과 잠금, 기록은 봇 결정과 같은 경로를 탄다 */
|
|
2002
|
+
export async function touchIdGateDecide(opts, gateId, decision, raw, server) {
|
|
2003
|
+
const parsed = assertionSchema.safeParse(raw);
|
|
2004
|
+
if (!parsed.success)
|
|
2005
|
+
throw new InputError('WebAuthn 응답 형식을 확인하지 못했어요');
|
|
2006
|
+
const ctx = open(opts);
|
|
2007
|
+
const target = ctx.store.snapshot.gates[gateId]?.receipt
|
|
2008
|
+
? undefined
|
|
2009
|
+
: matchBotGate(ctx.store, gateId);
|
|
2010
|
+
const beforeTarget = target ? decisionTarget(ctx.store, target) : undefined;
|
|
2011
|
+
if (target?.gate.status === 'open')
|
|
2012
|
+
touchIdPolicy(ctx.store.dir, target.gate, target.repo);
|
|
2013
|
+
const evidence = target?.gate.status === 'open' ? await touchIdGateEvidence(ctx, target) : undefined;
|
|
2014
|
+
return applyBotDecision(ctx, { request: { decision, webauthn: parsed.data, ...server } }, gateId, beforeTarget, evidence);
|
|
2015
|
+
}
|
|
2016
|
+
export async function conductorBotDecideCommand(gateId, opts) {
|
|
2017
|
+
try {
|
|
2018
|
+
const ctx = open(opts);
|
|
2019
|
+
const caller = await requireBotOperator(ctx);
|
|
2020
|
+
const decision = oneOf(opts.decision, ['approved', 'rejected'], '--decision');
|
|
2021
|
+
const target = ctx.store.snapshot.gates[gateId]?.receipt
|
|
2022
|
+
? undefined
|
|
2023
|
+
: matchBotGate(ctx.store, gateId);
|
|
2024
|
+
const beforeTarget = target ? decisionTarget(ctx.store, target) : undefined;
|
|
2025
|
+
// 승인자가 없으면 GitHub를 읽기 전에 터미널 안내로 멈춘다. 잠금 안에서 한 번 더 본다
|
|
2026
|
+
if (target?.gate.status === 'open')
|
|
2027
|
+
assertApproverReady(loadBotPolicy(ctx.store.dir), target.gate, target.repo);
|
|
2028
|
+
const evidence = target?.gate.status === 'open' ? await botGateEvidence(ctx, target) : undefined;
|
|
2029
|
+
print(await applyBotDecision(ctx, { caller, request: { decision, signer: opts.signer, signature: opts.signature } }, gateId, beforeTarget, evidence));
|
|
2030
|
+
}
|
|
2031
|
+
catch (error) {
|
|
2032
|
+
exitWithError(error);
|
|
2033
|
+
}
|
|
2034
|
+
}
|
|
2035
|
+
/**
|
|
2036
|
+
* Orca가 저장한 항목의 답을 확인하고 승인자 서명이나 공식 증빙으로 게이트를 닫는다.
|
|
2037
|
+
*/
|
|
2038
|
+
export async function conductorBotItemDecideCommand(gateId, opts) {
|
|
2039
|
+
try {
|
|
2040
|
+
const ctx = open(opts);
|
|
2041
|
+
const caller = await requireBotOperator(ctx);
|
|
2042
|
+
const item = Number(opts.item);
|
|
2043
|
+
if (!Number.isSafeInteger(item) || item <= 0)
|
|
2044
|
+
throw new Error('--item은 Orca 항목 번호예요');
|
|
2045
|
+
const sameSource = (gate) => gate.decisionSource?.botId === caller.botId &&
|
|
2046
|
+
gate.decisionSource.chatId === caller.chatId &&
|
|
2047
|
+
gate.decisionSource.item === item &&
|
|
2048
|
+
gate.decisionSource.question === opts.question &&
|
|
2049
|
+
gate.decisionSource.answer === opts.answer;
|
|
2050
|
+
const resolved = ctx.store.snapshot.gates[gateId];
|
|
2051
|
+
const target = resolved?.receipt ? undefined : matchBotGate(ctx.store, gateId);
|
|
2052
|
+
if (resolved?.status === 'resolved')
|
|
2053
|
+
return print({
|
|
2054
|
+
...botDecisionStatus(resolved),
|
|
2055
|
+
alreadyResolved: true,
|
|
2056
|
+
sameAnswer: sameSource(resolved),
|
|
2057
|
+
});
|
|
2058
|
+
if (!target)
|
|
2059
|
+
throw new Error('결정할 게이트를 찾을 수 없어요');
|
|
2060
|
+
const beforeTarget = decisionTarget(ctx.store, target);
|
|
2061
|
+
assertApproverReady(loadBotPolicy(ctx.store.dir), target.gate, target.repo);
|
|
2062
|
+
const evidence = await botGateEvidence(ctx, target);
|
|
2063
|
+
const read = readItemDecision({
|
|
2064
|
+
show: await readOrcaItem(item),
|
|
2065
|
+
owner: caller,
|
|
2066
|
+
item,
|
|
2067
|
+
question: opts.question,
|
|
2068
|
+
answer: opts.answer,
|
|
2069
|
+
binding: itemBinding(target, evidence?.head, evidence?.base),
|
|
2070
|
+
});
|
|
2071
|
+
if (read.kind === 'signed') {
|
|
2072
|
+
print(await applyBotDecision(ctx, { caller, request: read }, gateId, beforeTarget, evidence, sameSource));
|
|
2073
|
+
return;
|
|
1454
2074
|
}
|
|
2075
|
+
const issuer = await officialOrcaApprovalIssuer(caller);
|
|
2076
|
+
if (!issuer)
|
|
2077
|
+
throw new OrcaContractError();
|
|
2078
|
+
const proof = await issuer.read(read.source);
|
|
2079
|
+
print(await applyBotDecision(ctx, { caller, request: { ...read, issuer, proof } }, gateId, beforeTarget, evidence, sameSource));
|
|
1455
2080
|
}
|
|
1456
2081
|
catch (error) {
|
|
1457
2082
|
exitWithError(error);
|