crysk 0.0.0 → 0.3.1
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/LICENSE +176 -0
- package/README.md +611 -3
- package/bin/pr-hero.js +166 -0
- package/config/models/anthropic.json +5 -0
- package/dist/SKILL-7e3725zn.md +496 -0
- package/dist/SKILL-7q35wcaz.md +66 -0
- package/dist/SKILL-9at22381.md +74 -0
- package/dist/SKILL-ex2hxxh3.md +134 -0
- package/dist/SKILL-y8rv8msh.md +134 -0
- package/dist/SKILL-ygka1bs0.md +515 -0
- package/dist/adjudicator-dtg2axnh.md +86 -0
- package/dist/admission-config.example-a9vqmmad.json +9 -0
- package/dist/ci-admission-camfbx2b.md +122 -0
- package/dist/ci-admission-qk9r9taq.md +124 -0
- package/dist/cli.js +42501 -0
- package/dist/consolidate-ac0mnfyj.md +24 -0
- package/dist/deep-review-lifecycle-m698ybjp.md +362 -0
- package/dist/deep-review-logic-a6b1gczf.md +156 -0
- package/dist/deep-review-parity-0ec904db.md +120 -0
- package/dist/deep-review-reliability-qyakbjb9.md +125 -0
- package/dist/deep-review-resilience-3tz8y26e.md +118 -0
- package/dist/index.js +20190 -0
- package/dist/opencode-ci-7b0be64p.md +141 -0
- package/dist/review-refuter-j4e9gezy.md +71 -0
- package/dist/scout-yvp153q7.md +140 -0
- package/dist/summarizer-zca44nxa.md +18 -0
- package/dist/workflow-w1g9szna.yml +151 -0
- package/package.json +81 -4
- package/prompts/consolidate.md +24 -0
- package/prompts/default/PROVENANCE.md +18 -0
- package/prompts/default/deep-review-lifecycle.md +362 -0
- package/prompts/default/deep-review-logic.md +156 -0
- package/prompts/default/deep-review-parity.md +120 -0
- package/prompts/default/deep-review-reliability.md +125 -0
- package/prompts/default/deep-review-resilience.md +118 -0
- package/prompts/default/review-refuter.md +71 -0
- package/prompts/scout.md +140 -0
- package/prompts/summarizer.md +18 -0
- package/skills/crysk/SKILL.md +74 -0
- package/skills/crysk-ci-setup/SKILL.md +134 -0
- package/skills/crysk-ci-setup/assets/admission-config.example.json +9 -0
- package/skills/crysk-ci-setup/assets/workflow.yml +151 -0
- package/skills/crysk-ci-setup/references/ci-admission.md +124 -0
- package/skills/crysk-ci-setup/references/opencode-ci.md +141 -0
- package/skills/crysk-loop/SKILL.md +515 -0
- package/skills/crysk-loop/adjudicator.md +86 -0
- package/skills/crysk-pr/SKILL.md +66 -0
- package/src/agent-env.ts +1084 -0
- package/src/asset-manifest.ts +83 -0
- package/src/assets.d.ts +6 -0
- package/src/assets.ts +183 -0
- package/src/brand-paths.ts +155 -0
- package/src/brand.ts +255 -0
- package/src/ci/admission-ledger.ts +350 -0
- package/src/ci/classify-error.ts +73 -0
- package/src/ci/cli-record.ts +271 -0
- package/src/ci/force-comment.ts +39 -0
- package/src/ci/gates.ts +945 -0
- package/src/ci/outcome.ts +2181 -0
- package/src/ci/override.ts +187 -0
- package/src/ci/publish.ts +1639 -0
- package/src/ci/reporter.ts +626 -0
- package/src/ci/review-admission.ts +910 -0
- package/src/ci/review-levels.ts +310 -0
- package/src/ci/review-policy.ts +18 -0
- package/src/ci/review-risk.ts +184 -0
- package/src/ci/setup.ts +844 -0
- package/src/ci/trigger.ts +1353 -0
- package/src/cli.ts +348 -0
- package/src/commands/activity.ts +67 -0
- package/src/commands/ci-setup-questions.ts +397 -0
- package/src/commands/ci-setup.ts +381 -0
- package/src/commands/config.ts +99 -0
- package/src/commands/doctor.ts +108 -0
- package/src/commands/init.ts +139 -0
- package/src/commands/mcp.ts +10 -0
- package/src/commands/menu.ts +129 -0
- package/src/commands/post.ts +302 -0
- package/src/commands/skills.ts +83 -0
- package/src/commands/status.ts +173 -0
- package/src/commands/triage.ts +342 -0
- package/src/commands/uninstall.ts +37 -0
- package/src/commands/upgrade.ts +214 -0
- package/src/commands/usage.ts +98 -0
- package/src/compare/compare.ts +28 -0
- package/src/compare/floor-test.ts +471 -0
- package/src/compare/martian-adapter.ts +80 -0
- package/src/config/config.ts +267 -0
- package/src/corpus/corpus.ts +1094 -0
- package/src/corpus/preflight.ts +1789 -0
- package/src/diversity/accounting.ts +90 -0
- package/src/diversity/adjudication.ts +145 -0
- package/src/diversity/admission.ts +60 -0
- package/src/diversity/benchmark.ts +195 -0
- package/src/diversity/clustering.ts +285 -0
- package/src/diversity/errors.ts +7 -0
- package/src/diversity/identity.ts +285 -0
- package/src/diversity/index.ts +11 -0
- package/src/diversity/pipeline-integration.ts +448 -0
- package/src/diversity/projection.ts +57 -0
- package/src/diversity/self-contained.ts +68 -0
- package/src/diversity/target-validation.ts +179 -0
- package/src/doctor-migration.ts +209 -0
- package/src/doctor.ts +723 -0
- package/src/errors.ts +83 -0
- package/src/execution/admission.ts +75 -0
- package/src/execution/atomic-write.ts +35 -0
- package/src/execution/attempt-evidence.ts +415 -0
- package/src/execution/bucket-id.ts +136 -0
- package/src/execution/concurrency-limiter.ts +175 -0
- package/src/execution/contracts.ts +443 -0
- package/src/execution/failure-classification.ts +42 -0
- package/src/execution/failure-policy.ts +240 -0
- package/src/execution/harness.ts +2548 -0
- package/src/execution/settlement.ts +348 -0
- package/src/execution/spawned-process.ts +66 -0
- package/src/execution/spend-limiter.ts +424 -0
- package/src/execution/step-artifacts.ts +55 -0
- package/src/execution/usage-normalized.ts +469 -0
- package/src/git/git.ts +396 -0
- package/src/git/identity.ts +64 -0
- package/src/git/refs.ts +140 -0
- package/src/home-preflight.ts +443 -0
- package/src/home.ts +243 -0
- package/src/ignore-file.ts +336 -0
- package/src/ignore-read.ts +118 -0
- package/src/index.ts +34 -0
- package/src/legacy-launchd.ts +29 -0
- package/src/mcp/mcp.ts +150 -0
- package/src/mcp/preflight.ts +407 -0
- package/src/menu-context.ts +192 -0
- package/src/model/catalog.ts +251 -0
- package/src/model/exec-snapshots.ts +390 -0
- package/src/model/free-discovery.ts +302 -0
- package/src/model/provider-capabilities.ts +814 -0
- package/src/model/routing.ts +600 -0
- package/src/pr/admission.ts +984 -0
- package/src/pr/answered-findings.ts +169 -0
- package/src/pr/ci-admission-gate.ts +743 -0
- package/src/pr/ci-publish.ts +76 -0
- package/src/pr/discovery.ts +432 -0
- package/src/pr/inline.ts +507 -0
- package/src/pr/plan.ts +366 -0
- package/src/pr/posting.ts +115 -0
- package/src/pr/pr-status.ts +845 -0
- package/src/pr/pr.ts +3642 -0
- package/src/pr/preflight.ts +1031 -0
- package/src/pr/publish-outcome.ts +361 -0
- package/src/pr/range.ts +119 -0
- package/src/pr/reverts-preflight.ts +606 -0
- package/src/pr/reverts.ts +377 -0
- package/src/pr/review-pr.ts +927 -0
- package/src/pr/status.ts +154 -0
- package/src/pr/target.ts +388 -0
- package/src/pr/teardown.ts +437 -0
- package/src/pr/worktree-setup.ts +60 -0
- package/src/production-runtime.ts +1877 -0
- package/src/progress.ts +487 -0
- package/src/rereview/adjudicate.ts +89 -0
- package/src/rereview/classify.ts +362 -0
- package/src/rereview/identity.ts +211 -0
- package/src/rereview/plan.ts +308 -0
- package/src/rereview/prepare.ts +1025 -0
- package/src/rereview/state.ts +767 -0
- package/src/rereview/verify.ts +241 -0
- package/src/review/boundary.ts +105 -0
- package/src/review/consolidate.ts +246 -0
- package/src/review/dedupe.ts +368 -0
- package/src/review/drafts.ts +448 -0
- package/src/review/findings-conformance.ts +120 -0
- package/src/review/findings.ts +714 -0
- package/src/review/pipeline.ts +3977 -0
- package/src/review/preflight.ts +3575 -0
- package/src/review/prompt-set.ts +177 -0
- package/src/review/proof-refs.ts +187 -0
- package/src/review/report.ts +1821 -0
- package/src/review/review.ts +490 -0
- package/src/review/root-cause.ts +120 -0
- package/src/review/route-preflight.ts +289 -0
- package/src/review/run.ts +601 -0
- package/src/review/scout.ts +323 -0
- package/src/review/size-gate.ts +595 -0
- package/src/review/spec.ts +235 -0
- package/src/review/step-runner.ts +233 -0
- package/src/runner-authority.ts +596 -0
- package/src/security/binding-policy.ts +115 -0
- package/src/security/credential-broker.ts +773 -0
- package/src/security/evidence-redaction.ts +62 -0
- package/src/security/execution-authority.ts +27 -0
- package/src/security/redact.ts +71 -0
- package/src/security/workspace-read-broker.ts +466 -0
- package/src/server/client.ts +190 -0
- package/src/server/preflight.ts +217 -0
- package/src/server/server.ts +327 -0
- package/src/signal-handler.ts +50 -0
- package/src/store/activity.ts +413 -0
- package/src/store/backfill-preflight.ts +49 -0
- package/src/store/backfill.ts +141 -0
- package/src/store/gc-preflight.ts +206 -0
- package/src/store/gc.ts +424 -0
- package/src/store/metrics-preflight.ts +229 -0
- package/src/store/metrics.ts +236 -0
- package/src/store/preflight.ts +748 -0
- package/src/store/store.ts +693 -0
- package/src/system-tools.ts +355 -0
- package/src/transport-registry.ts +1124 -0
- package/src/transports/claude-code-cli.ts +1348 -0
- package/src/transports/opencode-admission.ts +515 -0
- package/src/transports/opencode-client.ts +3328 -0
- package/src/transports/opencode-evidence.ts +557 -0
- package/src/transports/opencode-mcp.ts +248 -0
- package/src/transports/opencode-sdk.ts +2294 -0
- package/src/transports/opencode-server.ts +535 -0
- package/src/triage/adjudication.ts +113 -0
- package/src/triage/reply.ts +125 -0
- package/src/triage/triage.ts +255 -0
- package/src/ui/activity.ts +173 -0
- package/src/ui/config-edit.ts +816 -0
- package/src/ui/config.ts +462 -0
- package/src/ui/menu.ts +1325 -0
- package/src/ui/plan.ts +1039 -0
- package/src/ui/primitives.ts +300 -0
- package/src/ui/progress.ts +298 -0
- package/src/ui/result.ts +552 -0
- package/src/ui/review-menu.ts +312 -0
- package/src/ui/select.ts +528 -0
- package/src/ui/tree.ts +178 -0
- package/src/uninstaller.ts +479 -0
- package/src/updater.ts +836 -0
- package/src/usage.ts +77 -0
- package/src/watch/preflight.ts +1389 -0
- package/src/watch/watch.ts +1235 -0
- package/src/wizard.ts +877 -0
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
// §5.1 typed settlement: every session resolves a SettlementReceipt whose
|
|
2
|
+
// termination/resource/remote status, timestamps, warnings and closed
|
|
3
|
+
// late-write fence are assembled here — pure and offline-testable, with the
|
|
4
|
+
// clock injected so no test ever sleeps to produce a timestamp.
|
|
5
|
+
import type { RunnerBackend } from "#model/provider-capabilities";
|
|
6
|
+
import type { ProviderTerminalProof } from "./contracts";
|
|
7
|
+
|
|
8
|
+
// §5.1 shapes verbatim.
|
|
9
|
+
export interface WriteLease {
|
|
10
|
+
readonly id: string;
|
|
11
|
+
readonly valid: boolean;
|
|
12
|
+
invalidate(reason: string): void;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type SettlementOutcome =
|
|
16
|
+
| "completed"
|
|
17
|
+
| "failed"
|
|
18
|
+
| "cancelled_confirmed"
|
|
19
|
+
| "local_fenced_remote_unconfirmed"
|
|
20
|
+
| "local_termination_unconfirmed";
|
|
21
|
+
|
|
22
|
+
export interface SettlementReceipt {
|
|
23
|
+
readonly sessionId: string;
|
|
24
|
+
readonly attempt: number;
|
|
25
|
+
readonly outcome: SettlementOutcome;
|
|
26
|
+
readonly termination: {
|
|
27
|
+
readonly requested: boolean;
|
|
28
|
+
readonly confirmation:
|
|
29
|
+
| "not_required"
|
|
30
|
+
| "process_group_exited"
|
|
31
|
+
| "sdk_abort_confirmed"
|
|
32
|
+
| "unconfirmed";
|
|
33
|
+
readonly signalCascade?: readonly ("SIGTERM" | "SIGKILL")[];
|
|
34
|
+
};
|
|
35
|
+
readonly resources: {
|
|
36
|
+
readonly localReleased: boolean;
|
|
37
|
+
readonly processGroupAlive: boolean | "unknown" | "not_applicable";
|
|
38
|
+
readonly remoteStatus:
|
|
39
|
+
| "completed"
|
|
40
|
+
| "cancelled"
|
|
41
|
+
| "failed"
|
|
42
|
+
| "unknown_may_continue";
|
|
43
|
+
};
|
|
44
|
+
readonly timestamps: {
|
|
45
|
+
readonly startedAt: string;
|
|
46
|
+
readonly abortRequestedAt?: string;
|
|
47
|
+
readonly leaseInvalidatedAt?: string;
|
|
48
|
+
readonly terminationConfirmedAt?: string;
|
|
49
|
+
readonly settledAt: string;
|
|
50
|
+
};
|
|
51
|
+
readonly lateWriteFence: {
|
|
52
|
+
readonly leaseId: string;
|
|
53
|
+
readonly closed: true;
|
|
54
|
+
readonly rejectedEvents: number;
|
|
55
|
+
};
|
|
56
|
+
readonly warnings: readonly string[];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface ActiveSession {
|
|
60
|
+
readonly id: string;
|
|
61
|
+
readonly attempt: number;
|
|
62
|
+
readonly controller: AbortController;
|
|
63
|
+
readonly transport: RunnerBackend;
|
|
64
|
+
readonly writeLease: WriteLease;
|
|
65
|
+
readonly cancellationDeadlineMs: number;
|
|
66
|
+
readonly settled: Promise<SettlementReceipt>;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export type TerminalOrigin = "provider" | "transport" | "harness";
|
|
70
|
+
export type TerminalStatus = "completed" | "failed" | "cancelled";
|
|
71
|
+
|
|
72
|
+
export const DEFAULT_CANCELLATION_DEADLINE_MS = 7500;
|
|
73
|
+
|
|
74
|
+
// §5.3 step 4: fixed harness margin over each declared deadline. Injectable in
|
|
75
|
+
// the harness so offline tests can exercise grace expiry without sleeping a
|
|
76
|
+
// real second; production always uses this value.
|
|
77
|
+
export const HARNESS_GRACE_MARGIN_MS = 1000;
|
|
78
|
+
|
|
79
|
+
const QUARANTINE_WARNING =
|
|
80
|
+
// §5.3 step 6: quarantine the transport/rate-limit bucket on synthesis.
|
|
81
|
+
"no transport terminal arrived before the settlement grace expired; transport/rate-limit bucket quarantined and remote job may continue";
|
|
82
|
+
|
|
83
|
+
export interface WriteLeaseHooks {
|
|
84
|
+
onInvalidate?: (reason: string) => void;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function createWriteLease(
|
|
88
|
+
id: string,
|
|
89
|
+
hooks?: WriteLeaseHooks,
|
|
90
|
+
): WriteLease {
|
|
91
|
+
let isValid = true;
|
|
92
|
+
return {
|
|
93
|
+
get id(): string {
|
|
94
|
+
return id;
|
|
95
|
+
},
|
|
96
|
+
get valid(): boolean {
|
|
97
|
+
return isValid;
|
|
98
|
+
},
|
|
99
|
+
invalidate(reason: string): void {
|
|
100
|
+
// First invalidation wins (§5.3 step 2); repeats are inert so a late
|
|
101
|
+
// sink close cannot resurrect or double-count the fence.
|
|
102
|
+
if (!isValid) return;
|
|
103
|
+
isValid = false;
|
|
104
|
+
hooks?.onInvalidate?.(reason);
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export interface SettlementOptions {
|
|
110
|
+
// Injectable ISO-timestamp source (§5.1 timestamps must be testable offline).
|
|
111
|
+
readonly now?: () => string;
|
|
112
|
+
readonly leaseId?: string;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export interface SettlementReceiptExtras {
|
|
116
|
+
readonly requested?: boolean;
|
|
117
|
+
readonly confirmation?: SettlementReceipt["termination"]["confirmation"];
|
|
118
|
+
readonly signalCascade?: readonly ("SIGTERM" | "SIGKILL")[];
|
|
119
|
+
readonly localReleased?: boolean;
|
|
120
|
+
readonly processGroupAlive?: SettlementReceipt["resources"]["processGroupAlive"];
|
|
121
|
+
readonly remoteStatus?: SettlementReceipt["resources"]["remoteStatus"];
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export interface AcceptedTerminal {
|
|
125
|
+
readonly origin: TerminalOrigin;
|
|
126
|
+
readonly status: TerminalStatus;
|
|
127
|
+
readonly proof?: ProviderTerminalProof;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export interface SettlementSession {
|
|
131
|
+
readonly sessionId: string;
|
|
132
|
+
readonly attempt: number;
|
|
133
|
+
readonly writeLease: WriteLease;
|
|
134
|
+
// §5.1/§5.3 step 5 compare-and-set terminal slot: the first valid terminal
|
|
135
|
+
// wins; later ones are counted (rejectedCount) but never replace it.
|
|
136
|
+
acceptTerminal(
|
|
137
|
+
origin: TerminalOrigin,
|
|
138
|
+
status: TerminalStatus,
|
|
139
|
+
proof?: ProviderTerminalProof,
|
|
140
|
+
): boolean;
|
|
141
|
+
readonly terminal: AcceptedTerminal | undefined;
|
|
142
|
+
readonly rejectedCount: number;
|
|
143
|
+
rejectDataPlaneEvents(count?: number): void;
|
|
144
|
+
readonly rejectedEvents: number;
|
|
145
|
+
addWarning(warning: string): void;
|
|
146
|
+
readonly warnings: readonly string[];
|
|
147
|
+
markAbortRequested(): void;
|
|
148
|
+
markLeaseInvalidated(): void;
|
|
149
|
+
markTerminationConfirmed(): void;
|
|
150
|
+
close(): void;
|
|
151
|
+
receipt(
|
|
152
|
+
outcome: SettlementOutcome,
|
|
153
|
+
extras?: SettlementReceiptExtras,
|
|
154
|
+
): SettlementReceipt;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export function createSettlement(
|
|
158
|
+
sessionId: string,
|
|
159
|
+
attempt: number,
|
|
160
|
+
options?: SettlementOptions,
|
|
161
|
+
): SettlementSession {
|
|
162
|
+
const now = options?.now ?? (() => new Date().toISOString());
|
|
163
|
+
const writeLease = createWriteLease(
|
|
164
|
+
options?.leaseId ?? `${sessionId}-lease`,
|
|
165
|
+
{
|
|
166
|
+
onInvalidate: () => {
|
|
167
|
+
if (leaseInvalidatedAt === undefined) leaseInvalidatedAt = now();
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
const startedAt = now();
|
|
173
|
+
let abortRequestedAt: string | undefined;
|
|
174
|
+
let leaseInvalidatedAt: string | undefined;
|
|
175
|
+
let terminationConfirmedAt: string | undefined;
|
|
176
|
+
|
|
177
|
+
let terminal: AcceptedTerminal | undefined;
|
|
178
|
+
let rejectedCount = 0;
|
|
179
|
+
let rejectedEvents = 0;
|
|
180
|
+
const warnings: string[] = [];
|
|
181
|
+
let closed = false;
|
|
182
|
+
|
|
183
|
+
const invalidateLease = (reason: string): void => {
|
|
184
|
+
if (!writeLease.valid) return;
|
|
185
|
+
writeLease.invalidate(reason);
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
const session: SettlementSession = {
|
|
189
|
+
sessionId,
|
|
190
|
+
attempt,
|
|
191
|
+
writeLease,
|
|
192
|
+
acceptTerminal(origin, status, proof) {
|
|
193
|
+
// §4.4/§5.3 step 5: compare-and-set — first valid terminal wins; once
|
|
194
|
+
// the fence is closed nothing may win at all, only be counted.
|
|
195
|
+
if (closed || terminal !== undefined) {
|
|
196
|
+
rejectedCount++;
|
|
197
|
+
return false;
|
|
198
|
+
}
|
|
199
|
+
terminal = { origin, status, proof };
|
|
200
|
+
if (proof !== undefined && terminationConfirmedAt === undefined) {
|
|
201
|
+
terminationConfirmedAt = now();
|
|
202
|
+
}
|
|
203
|
+
return true;
|
|
204
|
+
},
|
|
205
|
+
get terminal(): AcceptedTerminal | undefined {
|
|
206
|
+
return terminal;
|
|
207
|
+
},
|
|
208
|
+
get rejectedCount(): number {
|
|
209
|
+
return rejectedCount;
|
|
210
|
+
},
|
|
211
|
+
rejectDataPlaneEvents(count = 1): void {
|
|
212
|
+
rejectedEvents += count;
|
|
213
|
+
},
|
|
214
|
+
get rejectedEvents(): number {
|
|
215
|
+
return rejectedEvents;
|
|
216
|
+
},
|
|
217
|
+
addWarning(warning: string): void {
|
|
218
|
+
warnings.push(warning);
|
|
219
|
+
},
|
|
220
|
+
get warnings(): readonly string[] {
|
|
221
|
+
return warnings;
|
|
222
|
+
},
|
|
223
|
+
markAbortRequested(): void {
|
|
224
|
+
if (abortRequestedAt === undefined) abortRequestedAt = now();
|
|
225
|
+
},
|
|
226
|
+
markLeaseInvalidated(): void {
|
|
227
|
+
invalidateLease("lease invalidated (§5.3 step 2)");
|
|
228
|
+
},
|
|
229
|
+
markTerminationConfirmed(): void {
|
|
230
|
+
if (terminationConfirmedAt === undefined) terminationConfirmedAt = now();
|
|
231
|
+
},
|
|
232
|
+
close(): void {
|
|
233
|
+
closed = true;
|
|
234
|
+
invalidateLease("settlement closed");
|
|
235
|
+
},
|
|
236
|
+
receipt(outcome, extras) {
|
|
237
|
+
// A receipt always implies a closed fence (§13 line 738).
|
|
238
|
+
closed = true;
|
|
239
|
+
invalidateLease(`receipt issued for outcome ${outcome}`);
|
|
240
|
+
if (
|
|
241
|
+
extras?.confirmation === "process_group_exited" ||
|
|
242
|
+
extras?.confirmation === "sdk_abort_confirmed"
|
|
243
|
+
) {
|
|
244
|
+
session.markTerminationConfirmed();
|
|
245
|
+
}
|
|
246
|
+
const requested =
|
|
247
|
+
extras?.requested ??
|
|
248
|
+
(abortRequestedAt !== undefined ||
|
|
249
|
+
outcome === "cancelled_confirmed" ||
|
|
250
|
+
outcome === "local_fenced_remote_unconfirmed" ||
|
|
251
|
+
outcome === "local_termination_unconfirmed");
|
|
252
|
+
const confirmation =
|
|
253
|
+
extras?.confirmation ??
|
|
254
|
+
(outcome === "cancelled_confirmed"
|
|
255
|
+
? terminal?.proof
|
|
256
|
+
? "process_group_exited"
|
|
257
|
+
: "sdk_abort_confirmed"
|
|
258
|
+
: outcome === "completed" || outcome === "failed"
|
|
259
|
+
? terminal?.proof
|
|
260
|
+
? "process_group_exited"
|
|
261
|
+
: "not_required"
|
|
262
|
+
: "unconfirmed");
|
|
263
|
+
const remoteStatus =
|
|
264
|
+
extras?.remoteStatus ??
|
|
265
|
+
(outcome === "completed"
|
|
266
|
+
? "completed"
|
|
267
|
+
: outcome === "failed"
|
|
268
|
+
? "failed"
|
|
269
|
+
: outcome === "cancelled_confirmed"
|
|
270
|
+
? "cancelled"
|
|
271
|
+
: "unknown_may_continue");
|
|
272
|
+
return {
|
|
273
|
+
sessionId,
|
|
274
|
+
attempt,
|
|
275
|
+
outcome,
|
|
276
|
+
termination: {
|
|
277
|
+
requested:
|
|
278
|
+
requested ||
|
|
279
|
+
outcome === "cancelled_confirmed" ||
|
|
280
|
+
outcome === "local_fenced_remote_unconfirmed" ||
|
|
281
|
+
outcome === "local_termination_unconfirmed",
|
|
282
|
+
confirmation,
|
|
283
|
+
...(extras?.signalCascade
|
|
284
|
+
? { signalCascade: extras.signalCascade }
|
|
285
|
+
: {}),
|
|
286
|
+
},
|
|
287
|
+
resources: {
|
|
288
|
+
localReleased: extras?.localReleased ?? true,
|
|
289
|
+
processGroupAlive: extras?.processGroupAlive ?? "unknown",
|
|
290
|
+
remoteStatus,
|
|
291
|
+
},
|
|
292
|
+
timestamps: {
|
|
293
|
+
startedAt,
|
|
294
|
+
...(abortRequestedAt !== undefined ? { abortRequestedAt } : {}),
|
|
295
|
+
...(leaseInvalidatedAt !== undefined ? { leaseInvalidatedAt } : {}),
|
|
296
|
+
...(terminationConfirmedAt !== undefined
|
|
297
|
+
? { terminationConfirmedAt }
|
|
298
|
+
: {}),
|
|
299
|
+
settledAt: now(),
|
|
300
|
+
},
|
|
301
|
+
lateWriteFence: {
|
|
302
|
+
leaseId: writeLease.id,
|
|
303
|
+
closed: true,
|
|
304
|
+
rejectedEvents,
|
|
305
|
+
},
|
|
306
|
+
warnings: [...warnings],
|
|
307
|
+
};
|
|
308
|
+
},
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
return session;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// §5.3 step 6: no transport terminal before grace expiry — synthesize an
|
|
315
|
+
// unconfirmed receipt, record the quarantine note, keep remote status honest.
|
|
316
|
+
export function synthesizeUnconfirmed(
|
|
317
|
+
settlement: SettlementSession,
|
|
318
|
+
extras?: {
|
|
319
|
+
readonly processGroupAlive?: SettlementReceipt["resources"]["processGroupAlive"];
|
|
320
|
+
readonly warning?: string;
|
|
321
|
+
readonly outcome?:
|
|
322
|
+
| "local_termination_unconfirmed"
|
|
323
|
+
| "local_fenced_remote_unconfirmed";
|
|
324
|
+
},
|
|
325
|
+
): SettlementReceipt {
|
|
326
|
+
settlement.addWarning(extras?.warning ?? QUARANTINE_WARNING);
|
|
327
|
+
return settlement.receipt(
|
|
328
|
+
extras?.outcome ?? "local_termination_unconfirmed",
|
|
329
|
+
{
|
|
330
|
+
confirmation: "unconfirmed",
|
|
331
|
+
processGroupAlive: extras?.processGroupAlive ?? "unknown",
|
|
332
|
+
remoteStatus: "unknown_may_continue",
|
|
333
|
+
},
|
|
334
|
+
);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// §5.1: settled always resolves to a receipt — programmer/invariant failures
|
|
338
|
+
// convert to local_termination_unconfirmed with an internal warning so
|
|
339
|
+
// collection cannot hang.
|
|
340
|
+
export function synthesizeInternalFailure(
|
|
341
|
+
settlement: SettlementSession,
|
|
342
|
+
cause: unknown,
|
|
343
|
+
): SettlementReceipt {
|
|
344
|
+
const message = cause instanceof Error ? cause.message : String(cause);
|
|
345
|
+
return synthesizeUnconfirmed(settlement, {
|
|
346
|
+
warning: `internal settlement invariant failure converted per §5.1: ${message}`,
|
|
347
|
+
});
|
|
348
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// The registry of live child processes a transport has spawned, and the
|
|
2
|
+
// emergency kill-switch over it (cli.ts's shutdown path calls
|
|
3
|
+
// killAllChildProcesses so a Ctrl-C never leaves an orphaned `claude` CLI
|
|
4
|
+
// process running).
|
|
5
|
+
//
|
|
6
|
+
// Split out of review/step-runner.ts (architecture guard C2):
|
|
7
|
+
// transports/claude-code-cli.ts is the spawner and needs this registry, but
|
|
8
|
+
// review/step-runner.ts itself depends on execution/harness.ts (via
|
|
9
|
+
// StepExecutionHarness), which depends on transport-registry.ts, which
|
|
10
|
+
// depends on transports/claude-code-cli.ts — so claude-code-cli.ts importing
|
|
11
|
+
// this registry FROM step-runner.ts closed a value-import cycle back through
|
|
12
|
+
// harness.ts. This file has no imports of its own — a true leaf every side
|
|
13
|
+
// can depend on one-way.
|
|
14
|
+
|
|
15
|
+
export interface SpawnedProcess {
|
|
16
|
+
stdout: ReadableStream<Uint8Array>;
|
|
17
|
+
stderr: ReadableStream<Uint8Array>;
|
|
18
|
+
exited: Promise<number>;
|
|
19
|
+
kill(): void;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const ACTIVE_CHILD_PROCS = new Set<SpawnedProcess>();
|
|
23
|
+
|
|
24
|
+
export function killAllChildProcesses(): void {
|
|
25
|
+
for (const proc of ACTIVE_CHILD_PROCS) {
|
|
26
|
+
try {
|
|
27
|
+
proc.kill();
|
|
28
|
+
} catch {
|
|
29
|
+
// Swallowed — process may have already exited
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
ACTIVE_CHILD_PROCS.clear();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Long-lived children that own more than a process. An OpenCode server holds a
|
|
36
|
+
// projected credential directory too, and its `close()` both stops it (TERM,
|
|
37
|
+
// bounded grace, KILL) and destroys that projection. `kill()` alone would leave
|
|
38
|
+
// the credential on disk, so these are closed, not killed. cli.ts's signal
|
|
39
|
+
// path awaits closeAllServers() right after killAllChildProcesses(): before
|
|
40
|
+
// this registry existed the server was in no list at all, outlived a SIGTERM'd
|
|
41
|
+
// pr-hero, and kept its session (and its spend) alive.
|
|
42
|
+
export const ACTIVE_SERVER_CLOSERS = new Set<() => Promise<void>>();
|
|
43
|
+
|
|
44
|
+
// Latched by the signal sweep and never reset in production: a server armed
|
|
45
|
+
// after the sweep (a launch whose credential projection straddled the signal,
|
|
46
|
+
// or a relaunch) would be in no registry anyone reads again, so launches
|
|
47
|
+
// check this and refuse instead.
|
|
48
|
+
let shuttingDown = false;
|
|
49
|
+
|
|
50
|
+
export function serversShuttingDown(): boolean {
|
|
51
|
+
return shuttingDown;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Tests run many sweeps in one process; production runs at most one.
|
|
55
|
+
export function resetServerShutdownForTests(): void {
|
|
56
|
+
shuttingDown = false;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export async function closeAllServers(): Promise<void> {
|
|
60
|
+
shuttingDown = true;
|
|
61
|
+
const closers = [...ACTIVE_SERVER_CLOSERS];
|
|
62
|
+
ACTIVE_SERVER_CLOSERS.clear();
|
|
63
|
+
// allSettled: one server that fails to close must not keep the others (and
|
|
64
|
+
// their credentials) alive. Each close is already time-bounded.
|
|
65
|
+
await Promise.allSettled(closers.map((close) => close()));
|
|
66
|
+
}
|