@momentiq/dark-factory-cli 0.1.0-alpha.4
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 +201 -0
- package/README.md +150 -0
- package/dist/adapters/_shared.d.ts +45 -0
- package/dist/adapters/_shared.d.ts.map +1 -0
- package/dist/adapters/_shared.js +200 -0
- package/dist/adapters/_shared.js.map +1 -0
- package/dist/adapters/codex-sdk.d.ts +279 -0
- package/dist/adapters/codex-sdk.d.ts.map +1 -0
- package/dist/adapters/codex-sdk.js +930 -0
- package/dist/adapters/codex-sdk.js.map +1 -0
- package/dist/adapters/critic-result-schema.d.ts +215 -0
- package/dist/adapters/critic-result-schema.d.ts.map +1 -0
- package/dist/adapters/critic-result-schema.js +153 -0
- package/dist/adapters/critic-result-schema.js.map +1 -0
- package/dist/adapters/critic.d.ts +62 -0
- package/dist/adapters/critic.d.ts.map +1 -0
- package/dist/adapters/critic.js +79 -0
- package/dist/adapters/critic.js.map +1 -0
- package/dist/adapters/cursor-sdk.d.ts +153 -0
- package/dist/adapters/cursor-sdk.d.ts.map +1 -0
- package/dist/adapters/cursor-sdk.js +818 -0
- package/dist/adapters/cursor-sdk.js.map +1 -0
- package/dist/adapters/gemini-sdk.d.ts +113 -0
- package/dist/adapters/gemini-sdk.d.ts.map +1 -0
- package/dist/adapters/gemini-sdk.js +532 -0
- package/dist/adapters/gemini-sdk.js.map +1 -0
- package/dist/adapters/grok-direct-sdk.d.ts +148 -0
- package/dist/adapters/grok-direct-sdk.d.ts.map +1 -0
- package/dist/adapters/grok-direct-sdk.js +694 -0
- package/dist/adapters/grok-direct-sdk.js.map +1 -0
- package/dist/branch-protection/audit_branch_protection.py +759 -0
- package/dist/branch-protection/index.d.ts +25 -0
- package/dist/branch-protection/index.d.ts.map +1 -0
- package/dist/branch-protection/index.js +70 -0
- package/dist/branch-protection/index.js.map +1 -0
- package/dist/branch-protection/spec-default.yaml +314 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +581 -0
- package/dist/cli.js.map +1 -0
- package/dist/cycle-doc-validator/index.d.ts +43 -0
- package/dist/cycle-doc-validator/index.d.ts.map +1 -0
- package/dist/cycle-doc-validator/index.js +69 -0
- package/dist/cycle-doc-validator/index.js.map +1 -0
- package/dist/cycle-doc-validator/validate_cycle_doc.py +1260 -0
- package/dist/cycle-tracker-sync/attribute_pr_cycle_ref.py +384 -0
- package/dist/cycle-tracker-sync/index.d.ts +20 -0
- package/dist/cycle-tracker-sync/index.d.ts.map +1 -0
- package/dist/cycle-tracker-sync/index.js +71 -0
- package/dist/cycle-tracker-sync/index.js.map +1 -0
- package/dist/cycle-tracker-sync/sync_cycle_trackers.py +1093 -0
- package/dist/evidence/audit-trail.d.ts +59 -0
- package/dist/evidence/audit-trail.d.ts.map +1 -0
- package/dist/evidence/audit-trail.js +283 -0
- package/dist/evidence/audit-trail.js.map +1 -0
- package/dist/evidence/index.d.ts +4 -0
- package/dist/evidence/index.d.ts.map +1 -0
- package/dist/evidence/index.js +29 -0
- package/dist/evidence/index.js.map +1 -0
- package/dist/evidence/per-sha.d.ts +13 -0
- package/dist/evidence/per-sha.d.ts.map +1 -0
- package/dist/evidence/per-sha.js +97 -0
- package/dist/evidence/per-sha.js.map +1 -0
- package/dist/evidence/quality-gates.d.ts +19 -0
- package/dist/evidence/quality-gates.d.ts.map +1 -0
- package/dist/evidence/quality-gates.js +212 -0
- package/dist/evidence/quality-gates.js.map +1 -0
- package/dist/git.d.ts +40 -0
- package/dist/git.d.ts.map +1 -0
- package/dist/git.js +414 -0
- package/dist/git.js.map +1 -0
- package/dist/glob.d.ts +4 -0
- package/dist/glob.d.ts.map +1 -0
- package/dist/glob.js +99 -0
- package/dist/glob.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +33 -0
- package/dist/index.js.map +1 -0
- package/dist/paths.d.ts +12 -0
- package/dist/paths.d.ts.map +1 -0
- package/dist/paths.js +42 -0
- package/dist/paths.js.map +1 -0
- package/dist/policy/baseline.d.ts +15 -0
- package/dist/policy/baseline.d.ts.map +1 -0
- package/dist/policy/baseline.js +115 -0
- package/dist/policy/baseline.js.map +1 -0
- package/dist/policy/config.d.ts +64 -0
- package/dist/policy/config.d.ts.map +1 -0
- package/dist/policy/config.js +363 -0
- package/dist/policy/config.js.map +1 -0
- package/dist/policy/gate.d.ts +80 -0
- package/dist/policy/gate.d.ts.map +1 -0
- package/dist/policy/gate.js +1019 -0
- package/dist/policy/gate.js.map +1 -0
- package/dist/policy/index.d.ts +7 -0
- package/dist/policy/index.d.ts.map +1 -0
- package/dist/policy/index.js +14 -0
- package/dist/policy/index.js.map +1 -0
- package/dist/policy/merge-queue.d.ts +183 -0
- package/dist/policy/merge-queue.d.ts.map +1 -0
- package/dist/policy/merge-queue.js +310 -0
- package/dist/policy/merge-queue.js.map +1 -0
- package/dist/policy/profile.d.ts +98 -0
- package/dist/policy/profile.d.ts.map +1 -0
- package/dist/policy/profile.js +156 -0
- package/dist/policy/profile.js.map +1 -0
- package/dist/policy/tdd-classifier.d.ts +18 -0
- package/dist/policy/tdd-classifier.d.ts.map +1 -0
- package/dist/policy/tdd-classifier.js +79 -0
- package/dist/policy/tdd-classifier.js.map +1 -0
- package/dist/prompt.d.ts +13 -0
- package/dist/prompt.d.ts.map +1 -0
- package/dist/prompt.js +175 -0
- package/dist/prompt.js.map +1 -0
- package/dist/report.d.ts +88 -0
- package/dist/report.d.ts.map +1 -0
- package/dist/report.js +376 -0
- package/dist/report.js.map +1 -0
- package/dist/runner.d.ts +30 -0
- package/dist/runner.d.ts.map +1 -0
- package/dist/runner.js +456 -0
- package/dist/runner.js.map +1 -0
- package/dist/security.d.ts +2 -0
- package/dist/security.d.ts.map +1 -0
- package/dist/security.js +19 -0
- package/dist/security.js.map +1 -0
- package/dist/trusted-surface/rebind.d.ts +10 -0
- package/dist/trusted-surface/rebind.d.ts.map +1 -0
- package/dist/trusted-surface/rebind.js +154 -0
- package/dist/trusted-surface/rebind.js.map +1 -0
- package/package.json +78 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { type CriticConfig, type CriticResult, type CriticStatusMessage, type DoctorCheck, type ReviewPacket } from "@momentiq/dark-factory-schemas";
|
|
2
|
+
import type { CriticAdapter, CriticReviewOptions } from "./critic.js";
|
|
3
|
+
export { normalizeCriticEcho } from "./_shared.js";
|
|
4
|
+
export declare const CURSOR_SDK_ADAPTER_ID = "cursor-sdk";
|
|
5
|
+
export declare const CURSOR_API_KEY_ENV = "CURSOR_API_KEY";
|
|
6
|
+
export declare const RETRY_BACKOFF_MS: readonly number[];
|
|
7
|
+
export declare const PERMANENT_ERROR_CODES: ReadonlySet<string>;
|
|
8
|
+
export type AttemptOutcome = {
|
|
9
|
+
kind: "success";
|
|
10
|
+
result: CriticResult;
|
|
11
|
+
} | {
|
|
12
|
+
kind: "retryable_failure";
|
|
13
|
+
errorCode: string | null;
|
|
14
|
+
statusMessage: CriticStatusMessage | null;
|
|
15
|
+
message: string;
|
|
16
|
+
runId: string | null;
|
|
17
|
+
agentId: string | null;
|
|
18
|
+
} | {
|
|
19
|
+
kind: "permanent_failure";
|
|
20
|
+
errorCode: string | null;
|
|
21
|
+
statusMessage: CriticStatusMessage | null;
|
|
22
|
+
result: CriticResult;
|
|
23
|
+
};
|
|
24
|
+
export type RetryableFailure = Extract<AttemptOutcome, {
|
|
25
|
+
kind: "retryable_failure";
|
|
26
|
+
}>;
|
|
27
|
+
/**
|
|
28
|
+
* Cycle 322.1 — Pure retry-loop runner.
|
|
29
|
+
*
|
|
30
|
+
* Drives a sequence of `attempt(idx)` calls under the
|
|
31
|
+
* {@link RETRY_BACKOFF_MS} schedule, dispatching on the returned
|
|
32
|
+
* {@link AttemptOutcome}:
|
|
33
|
+
* - `success` / `permanent_failure` → return immediately, no more
|
|
34
|
+
* attempts.
|
|
35
|
+
* - `retryable_failure` → record the failure and (if budget
|
|
36
|
+
* remains) sleep + try again.
|
|
37
|
+
*
|
|
38
|
+
* Honors `signal` between attempts and during backoff sleeps; on
|
|
39
|
+
* abort, builds a terminal result via `buildExhausted` with the
|
|
40
|
+
* last failure context (so callers can surface "what was the last
|
|
41
|
+
* upstream error" even when cancellation cut the loop short).
|
|
42
|
+
*
|
|
43
|
+
* Extracted as a free function so:
|
|
44
|
+
* - 322.2 Gemini and 322.3 Grok adapters inherit the retry pattern
|
|
45
|
+
* without copy-paste drift.
|
|
46
|
+
* - The loop is unit-testable with scripted outcomes + a mock
|
|
47
|
+
* `sleep` (see `tests/cursor-retry-loop.test.ts`) — no SDK mock
|
|
48
|
+
* required.
|
|
49
|
+
*/
|
|
50
|
+
export declare function runRetryLoop(args: {
|
|
51
|
+
attempt: (idx: number) => Promise<AttemptOutcome>;
|
|
52
|
+
signal?: AbortSignal;
|
|
53
|
+
sleep?: (idx: number, signal: AbortSignal | undefined) => Promise<void>;
|
|
54
|
+
buildExhausted: (info: {
|
|
55
|
+
last: RetryableFailure | null;
|
|
56
|
+
totalAttempts: number;
|
|
57
|
+
aborted: boolean;
|
|
58
|
+
}) => CriticResult;
|
|
59
|
+
}): Promise<CriticResult>;
|
|
60
|
+
export declare class CursorSdkAdapter implements CriticAdapter {
|
|
61
|
+
private readonly options;
|
|
62
|
+
readonly id = "cursor-sdk";
|
|
63
|
+
readonly requiredEnvVars: readonly string[];
|
|
64
|
+
constructor(options?: {
|
|
65
|
+
apiKey?: string;
|
|
66
|
+
});
|
|
67
|
+
review(packet: ReviewPacket, critic: CriticConfig, options: CriticReviewOptions): Promise<CriticResult>;
|
|
68
|
+
private attemptReview;
|
|
69
|
+
doctor(critic: CriticConfig): Promise<DoctorCheck[]>;
|
|
70
|
+
}
|
|
71
|
+
export declare function buildModelSelection(critic: CriticConfig): {
|
|
72
|
+
id: string;
|
|
73
|
+
params?: Array<{
|
|
74
|
+
id: string;
|
|
75
|
+
value: string;
|
|
76
|
+
}>;
|
|
77
|
+
};
|
|
78
|
+
export declare function checkRunFinished(runStatus: string | undefined): string | null;
|
|
79
|
+
export declare function extractRuntimeModel(agent: unknown): {
|
|
80
|
+
id: string;
|
|
81
|
+
params?: Array<{
|
|
82
|
+
id: string;
|
|
83
|
+
value: string;
|
|
84
|
+
}>;
|
|
85
|
+
} | undefined;
|
|
86
|
+
/**
|
|
87
|
+
* Pull structured status fields from an SDKStatusMessage stream event.
|
|
88
|
+
*
|
|
89
|
+
* The Cursor SDK streams `SDKStatusMessage` events before the terminal
|
|
90
|
+
* RunResult; when an upstream incident is in progress these carry the
|
|
91
|
+
* SDK's own human-readable explanation (e.g.,
|
|
92
|
+
* `{ status: "error", message: "Upstream model gpt-5.5 returned
|
|
93
|
+
* capacity_exceeded after retry policy exhausted" }`). The runtime
|
|
94
|
+
* shape is intentionally not pinned to a TypeScript type from the SDK
|
|
95
|
+
* because the SDK may evolve the field names; this extractor probes
|
|
96
|
+
* the documented Cursor surface AND falls back to a top-level
|
|
97
|
+
* `{ status, message }` shape so a slightly older or newer SDK still
|
|
98
|
+
* surfaces the signal.
|
|
99
|
+
*
|
|
100
|
+
* Returns `null` when the event is not a status message or lacks the
|
|
101
|
+
* structured payload (the common case — most stream events are
|
|
102
|
+
* `assistant` / `thinking` / `tool_call`).
|
|
103
|
+
*/
|
|
104
|
+
export declare function extractStatusMessage(event: unknown): CriticStatusMessage | null;
|
|
105
|
+
/**
|
|
106
|
+
* Probe a terminal RunResult for the SDK's structured error code.
|
|
107
|
+
*
|
|
108
|
+
* The Cursor SDK has used at least four field names for this code
|
|
109
|
+
* across versions: `errorCode` (current), `error_code`, `code`, and
|
|
110
|
+
* `error.code` (nested under an `error` object). Probe in that order
|
|
111
|
+
* — first non-empty string wins. Returns `null` when none are
|
|
112
|
+
* present, which means the SDK did not surface a structured code at
|
|
113
|
+
* all (treat as "transient unless proven otherwise" so retry policy
|
|
114
|
+
* applies).
|
|
115
|
+
*/
|
|
116
|
+
export declare function extractRunErrorCode(result: unknown): string | null;
|
|
117
|
+
/**
|
|
118
|
+
* Policy gate: decide whether a terminal Cursor SDK failure is
|
|
119
|
+
* retryable.
|
|
120
|
+
*
|
|
121
|
+
* Returns `false` (DO NOT retry) when:
|
|
122
|
+
* - `runId` is null/undefined — the SDK never accepted the request;
|
|
123
|
+
* this is an infrastructure failure (network, sandbox, adapter
|
|
124
|
+
* init), not an API-layer failure that retry can paper over.
|
|
125
|
+
* - `errorCode` is in {@link PERMANENT_ERROR_CODES} — retrying an
|
|
126
|
+
* auth failure or quota-exceeded just wastes budget AND can mask
|
|
127
|
+
* the real fault.
|
|
128
|
+
*
|
|
129
|
+
* Returns `true` (retry allowed) when the failure carries a `runId`
|
|
130
|
+
* AND `errorCode` is either missing OR not on the permanent-deny
|
|
131
|
+
* list. The 26/27 retryable-failure success rate documented at
|
|
132
|
+
* `RETRY_BACKOFF_MS` drives this policy without per-vendor heuristics.
|
|
133
|
+
*/
|
|
134
|
+
export declare function shouldRetryRunFailure(input: {
|
|
135
|
+
result: unknown;
|
|
136
|
+
errorCode: string | null;
|
|
137
|
+
runId: string | null;
|
|
138
|
+
}): boolean;
|
|
139
|
+
/**
|
|
140
|
+
* AbortSignal-aware sleep used between retry attempts.
|
|
141
|
+
*
|
|
142
|
+
* Resolves after `RETRY_BACKOFF_MS[idx]` ms, OR rejects immediately
|
|
143
|
+
* with an Error whose `name === "AbortError"` if the signal is (or
|
|
144
|
+
* becomes) aborted. The abort handler also clears the pending timer
|
|
145
|
+
* so a long backoff doesn't leak a Node timer after the caller
|
|
146
|
+
* cancelled.
|
|
147
|
+
*
|
|
148
|
+
* Throws synchronously (via the returned rejected promise) on
|
|
149
|
+
* out-of-range `idx` so an indexing bug in the caller fails loud
|
|
150
|
+
* instead of silently sleeping zero ms.
|
|
151
|
+
*/
|
|
152
|
+
export declare function sleepForRetry(idx: number, signal: AbortSignal | undefined): Promise<void>;
|
|
153
|
+
//# sourceMappingURL=cursor-sdk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{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