@zeroroot-ai/zerocool 0.6.0 → 0.7.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/dispatch.d.ts +61 -4
- package/dist/dispatch.js +123 -4
- package/dist/fix.d.ts +73 -12
- package/dist/fix.js +106 -9
- package/package.json +2 -2
package/dist/dispatch.d.ts
CHANGED
|
@@ -46,8 +46,9 @@
|
|
|
46
46
|
* GIBSON_CALLBACK_INSECURE "1" to dial the callback listener without TLS (kind)
|
|
47
47
|
* GIBSON_MISSION_ID / GIBSON_MISSION_RUN_ID / GIBSON_AGENT_RUN_ID provenance
|
|
48
48
|
* ZEROCOOL_WORKSPACE working directory (defaults to the cwd)
|
|
49
|
-
* ZEROCOOL_TASK force a task kind ("source-analysis"
|
|
50
|
-
* own context `zerocool.task`
|
|
49
|
+
* ZEROCOOL_TASK force a task kind ("source-analysis", "watch",
|
|
50
|
+
* "fix"); the Task's own context `zerocool.task`
|
|
51
|
+
* is the normal way
|
|
51
52
|
* GIBSON_OPENCODE_SESSION_ID continue an earlier opencode session
|
|
52
53
|
* GIBSON_TIMEOUT_MS hard deadline for the run, in ms
|
|
53
54
|
*
|
|
@@ -57,7 +58,8 @@
|
|
|
57
58
|
*/
|
|
58
59
|
import { type AgentOutcome, type TaskHarness } from "@zeroroot-ai/sdk";
|
|
59
60
|
import { type FindingsBackend } from "./findings.js";
|
|
60
|
-
import { type
|
|
61
|
+
import { type FindingSource, type FindingStatusWriter, type FixPlanner, type Workspace } from "./fix.js";
|
|
62
|
+
import { type GitLabClient, type GitLabWriter } from "./gitlab.js";
|
|
61
63
|
import { runOpencode } from "./opencode-run.js";
|
|
62
64
|
import type { SemgrepRunner } from "./semgrep.js";
|
|
63
65
|
import { type ScanLauncher, type WatchCheckpoints } from "./watch.js";
|
|
@@ -151,7 +153,7 @@ export declare function decodeTask(taskB64: string | undefined): DecodedTask;
|
|
|
151
153
|
*/
|
|
152
154
|
export declare function typedValueString(val: unknown): string | undefined;
|
|
153
155
|
/** The task kinds a sandboxed dispatch can serve. */
|
|
154
|
-
export type DispatchTaskKind = "opencode" | "source-analysis" | "watch";
|
|
156
|
+
export type DispatchTaskKind = "opencode" | "source-analysis" | "watch" | "fix";
|
|
155
157
|
/**
|
|
156
158
|
* Which task this dispatch runs. The mission node says so in the Task's
|
|
157
159
|
* context (`zerocool.task`); ZEROCOOL_TASK forces it for a hand-run sandbox.
|
|
@@ -190,6 +192,29 @@ export interface DispatchDeps {
|
|
|
190
192
|
taskKind?: DispatchTaskKind;
|
|
191
193
|
/** Watch seams: no GitLab, no World and no child missions in a test. */
|
|
192
194
|
watch?: WatchDeps;
|
|
195
|
+
/** Fix seams: no GitLab, no graph and no checkout in a test. */
|
|
196
|
+
fix?: FixDeps;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* The fix task's injectable seams.
|
|
200
|
+
*
|
|
201
|
+
* `planner` and `workspace` have no default. The Fix decides what to change
|
|
202
|
+
* and runs the repository's own tests before anything is pushed, and neither
|
|
203
|
+
* is something this process can synthesise: a default planner would be one
|
|
204
|
+
* that changes nothing, and a default workspace would be one whose tests
|
|
205
|
+
* always pass. Both would turn a missing dependency into a Fix that reports
|
|
206
|
+
* success having done nothing, so a dispatch without them fails instead.
|
|
207
|
+
*/
|
|
208
|
+
export interface FixDeps {
|
|
209
|
+
gitlab?: GitLabWriter;
|
|
210
|
+
findings?: FindingSource;
|
|
211
|
+
status?: FindingStatusWriter;
|
|
212
|
+
planner?: FixPlanner;
|
|
213
|
+
workspace?: Workspace;
|
|
214
|
+
/** Resolve the GitLab token. Defaults to the harness `GetCredential`. */
|
|
215
|
+
credential?: (name: string) => Promise<string>;
|
|
216
|
+
/** Cap on merge requests opened by one pass. */
|
|
217
|
+
maxMergeRequests?: number;
|
|
193
218
|
}
|
|
194
219
|
/** The watch task's injectable seams. Everything the loop reaches out through. */
|
|
195
220
|
export interface WatchDeps {
|
|
@@ -242,6 +267,38 @@ export declare function runSourceAnalysisDispatch(ctx: DispatchContext, deps?: D
|
|
|
242
267
|
* `watch.interval_ms` poll cadence; defaults to 30s
|
|
243
268
|
*/
|
|
244
269
|
export declare function runWatchDispatch(ctx: DispatchContext, deps?: DispatchDeps): Promise<AgentOutcome>;
|
|
270
|
+
/**
|
|
271
|
+
* The fix task, sandboxed (zerocool-plugins#89, finished in #96).
|
|
272
|
+
*
|
|
273
|
+
* What the always-on agent does after a Scan mission lands: read the
|
|
274
|
+
* Application's Findings over the task grant, work them in priority order,
|
|
275
|
+
* and for each one it can act on rewrite the repository, run the repository's
|
|
276
|
+
* own tests, and only then open a merge request that merges itself on a green
|
|
277
|
+
* pipeline. See `fix.ts` for why the order is tests-then-push and why this
|
|
278
|
+
* never marks a Finding `verified`.
|
|
279
|
+
*
|
|
280
|
+
* THE READ AND THE STATUS WRITE TRAVEL ON THE DISPATCH GRANT, not on a
|
|
281
|
+
* component identity — this process has none. `applicationFindings` and
|
|
282
|
+
* `observe` both reach the daemon as the task, so the run holds exactly the
|
|
283
|
+
* authority its dispatch granted.
|
|
284
|
+
*
|
|
285
|
+
* A REJECTED READ FAILS THE RUN. `harnessFindingSource` does not catch it, and
|
|
286
|
+
* neither does this: an unreachable graph reported as an empty backlog is a
|
|
287
|
+
* Fix that says the Application is clean while the backlog is live, and it
|
|
288
|
+
* reads identically to health.
|
|
289
|
+
*
|
|
290
|
+
* Task context keys it reads:
|
|
291
|
+
* `zerocool.task` selector, "fix"
|
|
292
|
+
* `application` the Application whose Findings are worked (required)
|
|
293
|
+
* `gitlab.project` `group/project` on the instance (required)
|
|
294
|
+
* `gitlab.url` instance base url; defaults to gitlab.com
|
|
295
|
+
* `gitlab.ref` branch merge requests target; defaults to `main`
|
|
296
|
+
* `gitlab.credential` tenant secret holding the project access token
|
|
297
|
+
* `repository.commit` the commit the Scan ran against — what the status lands on
|
|
298
|
+
* `pipeline.url` the pipeline page, linked from the commit status
|
|
299
|
+
* `fix.max_merge_requests` cap on merge requests opened in one pass
|
|
300
|
+
*/
|
|
301
|
+
export declare function runFixDispatch(ctx: DispatchContext, deps?: DispatchDeps): Promise<AgentOutcome>;
|
|
245
302
|
/**
|
|
246
303
|
* Resolve a tenant secret through the harness on the dispatch grant. The value
|
|
247
304
|
* is returned to the caller and never logged: it is the GitLab token, and the
|
package/dist/dispatch.js
CHANGED
|
@@ -46,8 +46,9 @@
|
|
|
46
46
|
* GIBSON_CALLBACK_INSECURE "1" to dial the callback listener without TLS (kind)
|
|
47
47
|
* GIBSON_MISSION_ID / GIBSON_MISSION_RUN_ID / GIBSON_AGENT_RUN_ID provenance
|
|
48
48
|
* ZEROCOOL_WORKSPACE working directory (defaults to the cwd)
|
|
49
|
-
* ZEROCOOL_TASK force a task kind ("source-analysis"
|
|
50
|
-
* own context `zerocool.task`
|
|
49
|
+
* ZEROCOOL_TASK force a task kind ("source-analysis", "watch",
|
|
50
|
+
* "fix"); the Task's own context `zerocool.task`
|
|
51
|
+
* is the normal way
|
|
51
52
|
* GIBSON_OPENCODE_SESSION_ID continue an earlier opencode session
|
|
52
53
|
* GIBSON_TIMEOUT_MS hard deadline for the run, in ms
|
|
53
54
|
*
|
|
@@ -55,10 +56,11 @@
|
|
|
55
56
|
* {@link dispatchChildEnv} — that is the opencode plugin's own contract, fed from
|
|
56
57
|
* the GIBSON_CG_JWT this process reads.
|
|
57
58
|
*/
|
|
58
|
-
import { openTaskHarness } from "@zeroroot-ai/sdk";
|
|
59
|
+
import { observe, openTaskHarness, taskKnowledge } from "@zeroroot-ai/sdk";
|
|
59
60
|
import { join } from "node:path";
|
|
60
61
|
import { taskFindingsBackend } from "./findings.js";
|
|
61
|
-
import {
|
|
62
|
+
import { harnessFindingSource, harnessFindingStatus, runFix, } from "./fix.js";
|
|
63
|
+
import { gitlabRest, gitlabRestWriter } from "./gitlab.js";
|
|
62
64
|
import { runOpencode } from "./opencode-run.js";
|
|
63
65
|
import { DEFAULT_REF, harnessScanLauncher, runWatchLoop, worldCheckpoints, } from "./watch.js";
|
|
64
66
|
import { formatSourceAnalysis, harnessTriageModel, runSourceAnalysis, } from "./source-analysis.js";
|
|
@@ -183,6 +185,8 @@ export function dispatchTaskKind(ctx, env = {}) {
|
|
|
183
185
|
return "source-analysis";
|
|
184
186
|
if (kind === "watch")
|
|
185
187
|
return "watch";
|
|
188
|
+
if (kind === "fix")
|
|
189
|
+
return "fix";
|
|
186
190
|
return "opencode";
|
|
187
191
|
}
|
|
188
192
|
/**
|
|
@@ -245,6 +249,9 @@ export async function runDispatch(ctx, deps = {}) {
|
|
|
245
249
|
if (kind === "watch") {
|
|
246
250
|
return runWatchDispatch(ctx, deps);
|
|
247
251
|
}
|
|
252
|
+
if (kind === "fix") {
|
|
253
|
+
return runFixDispatch(ctx, deps);
|
|
254
|
+
}
|
|
248
255
|
const run = deps.run ?? runOpencode;
|
|
249
256
|
const result = await run({
|
|
250
257
|
goal: ctx.goal,
|
|
@@ -412,6 +419,118 @@ export async function runWatchDispatch(ctx, deps = {}) {
|
|
|
412
419
|
harness?.stop();
|
|
413
420
|
}
|
|
414
421
|
}
|
|
422
|
+
/**
|
|
423
|
+
* The fix task, sandboxed (zerocool-plugins#89, finished in #96).
|
|
424
|
+
*
|
|
425
|
+
* What the always-on agent does after a Scan mission lands: read the
|
|
426
|
+
* Application's Findings over the task grant, work them in priority order,
|
|
427
|
+
* and for each one it can act on rewrite the repository, run the repository's
|
|
428
|
+
* own tests, and only then open a merge request that merges itself on a green
|
|
429
|
+
* pipeline. See `fix.ts` for why the order is tests-then-push and why this
|
|
430
|
+
* never marks a Finding `verified`.
|
|
431
|
+
*
|
|
432
|
+
* THE READ AND THE STATUS WRITE TRAVEL ON THE DISPATCH GRANT, not on a
|
|
433
|
+
* component identity — this process has none. `applicationFindings` and
|
|
434
|
+
* `observe` both reach the daemon as the task, so the run holds exactly the
|
|
435
|
+
* authority its dispatch granted.
|
|
436
|
+
*
|
|
437
|
+
* A REJECTED READ FAILS THE RUN. `harnessFindingSource` does not catch it, and
|
|
438
|
+
* neither does this: an unreachable graph reported as an empty backlog is a
|
|
439
|
+
* Fix that says the Application is clean while the backlog is live, and it
|
|
440
|
+
* reads identically to health.
|
|
441
|
+
*
|
|
442
|
+
* Task context keys it reads:
|
|
443
|
+
* `zerocool.task` selector, "fix"
|
|
444
|
+
* `application` the Application whose Findings are worked (required)
|
|
445
|
+
* `gitlab.project` `group/project` on the instance (required)
|
|
446
|
+
* `gitlab.url` instance base url; defaults to gitlab.com
|
|
447
|
+
* `gitlab.ref` branch merge requests target; defaults to `main`
|
|
448
|
+
* `gitlab.credential` tenant secret holding the project access token
|
|
449
|
+
* `repository.commit` the commit the Scan ran against — what the status lands on
|
|
450
|
+
* `pipeline.url` the pipeline page, linked from the commit status
|
|
451
|
+
* `fix.max_merge_requests` cap on merge requests opened in one pass
|
|
452
|
+
*/
|
|
453
|
+
export async function runFixDispatch(ctx, deps = {}) {
|
|
454
|
+
const f = deps.fix ?? {};
|
|
455
|
+
const application = ctx.taskContext.application || "";
|
|
456
|
+
const projectPath = ctx.taskContext["gitlab.project"] || "";
|
|
457
|
+
const targetRef = ctx.taskContext["gitlab.ref"] || DEFAULT_REF;
|
|
458
|
+
const commit = ctx.taskContext["repository.commit"] || "";
|
|
459
|
+
const credentialName = ctx.taskContext["gitlab.credential"] || "gitlab-token";
|
|
460
|
+
if (!application) {
|
|
461
|
+
throw new Error("fix: the mission node set no `application` in the task context. The Fix reads one " +
|
|
462
|
+
"Application's Findings and writes back to them; without one it cannot tell which " +
|
|
463
|
+
"backlog it is working.");
|
|
464
|
+
}
|
|
465
|
+
if (!f.gitlab && !projectPath) {
|
|
466
|
+
throw new Error("fix: the mission node set no `gitlab.project` in the task context, so there is no " +
|
|
467
|
+
"project to open a merge request against.");
|
|
468
|
+
}
|
|
469
|
+
// No default planner and no default workspace: see FixDeps. A Fix that
|
|
470
|
+
// cannot change anything or cannot test what it changed must not report a
|
|
471
|
+
// clean pass over a backlog it never touched.
|
|
472
|
+
if (!f.planner) {
|
|
473
|
+
throw new Error("fix: no planner was supplied, so this dispatch could only report every finding unfixed");
|
|
474
|
+
}
|
|
475
|
+
if (!f.workspace) {
|
|
476
|
+
throw new Error("fix: no workspace was supplied, so no change could be made or tested");
|
|
477
|
+
}
|
|
478
|
+
const needsHarness = !f.gitlab || !f.findings || !f.status || !f.credential;
|
|
479
|
+
const opened = needsHarness && !deps.harness;
|
|
480
|
+
const harness = needsHarness
|
|
481
|
+
? (deps.harness ??
|
|
482
|
+
((c) => openTaskHarness({ endpoint: c.callbackEndpoint, token: c.callbackToken, insecure: c.insecure ?? false })))(ctx)
|
|
483
|
+
: undefined;
|
|
484
|
+
try {
|
|
485
|
+
const gitlab = f.gitlab ??
|
|
486
|
+
gitlabRestWriter({
|
|
487
|
+
projectPath,
|
|
488
|
+
token: await (f.credential ?? harnessCredential(harness))(credentialName),
|
|
489
|
+
...(ctx.taskContext["gitlab.url"] ? { baseUrl: ctx.taskContext["gitlab.url"] } : {}),
|
|
490
|
+
});
|
|
491
|
+
const findings = f.findings ?? harnessFindingSource(taskKnowledge(harness));
|
|
492
|
+
const status = f.status ??
|
|
493
|
+
harnessFindingStatus((entity) => observe(harness, { lifecycleEntity: entity }));
|
|
494
|
+
const cap = Number(ctx.taskContext["fix.max_merge_requests"] || Number.NaN);
|
|
495
|
+
const summary = await runFix({
|
|
496
|
+
application,
|
|
497
|
+
commit,
|
|
498
|
+
targetRef,
|
|
499
|
+
findings,
|
|
500
|
+
status,
|
|
501
|
+
planner: f.planner,
|
|
502
|
+
workspace: f.workspace,
|
|
503
|
+
gitlab,
|
|
504
|
+
...(ctx.taskContext["pipeline.url"] ? { pipelineUrl: ctx.taskContext["pipeline.url"] } : {}),
|
|
505
|
+
...(f.maxMergeRequests !== undefined
|
|
506
|
+
? { maxMergeRequests: f.maxMergeRequests }
|
|
507
|
+
: Number.isFinite(cap) && cap > 0
|
|
508
|
+
? { maxMergeRequests: cap }
|
|
509
|
+
: {}),
|
|
510
|
+
...(deps.onEvent ? { onEvent: (e) => deps.onEvent?.(JSON.stringify(e)) } : {}),
|
|
511
|
+
});
|
|
512
|
+
const fixing = summary.outcomes.filter((o) => o.result === "fixing").length;
|
|
513
|
+
const merged = summary.outcomes.filter((o) => o.result === "merged").length;
|
|
514
|
+
const unfixed = summary.outcomes.filter((o) => o.result === "unfixed").length;
|
|
515
|
+
return {
|
|
516
|
+
output: `fix ${application}@${commit.slice(0, 12) || "unknown"}: ${fixing} merge request(s) opened, ` +
|
|
517
|
+
`${merged} merged, ${unfixed} left for a human`,
|
|
518
|
+
success: true,
|
|
519
|
+
metadata: {
|
|
520
|
+
task: "fix",
|
|
521
|
+
application,
|
|
522
|
+
commit,
|
|
523
|
+
fixing: String(fixing),
|
|
524
|
+
merged: String(merged),
|
|
525
|
+
unfixed: String(unfixed),
|
|
526
|
+
},
|
|
527
|
+
};
|
|
528
|
+
}
|
|
529
|
+
finally {
|
|
530
|
+
if (opened)
|
|
531
|
+
harness?.stop();
|
|
532
|
+
}
|
|
533
|
+
}
|
|
415
534
|
/**
|
|
416
535
|
* Resolve a tenant secret through the harness on the dispatch grant. The value
|
|
417
536
|
* is returned to the caller and never logged: it is the GitLab token, and the
|
package/dist/fix.d.ts
CHANGED
|
@@ -26,15 +26,14 @@ import type { FileChange, GitLabWriter, MergeRequest } from "./gitlab.js";
|
|
|
26
26
|
* `fix.test.ts` proves that with a sentinel that would show up in every
|
|
27
27
|
* recorded output if it ever did.
|
|
28
28
|
*
|
|
29
|
-
* TWO SEAMS ARE
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* implementation to add and nothing here changes.
|
|
29
|
+
* THE TWO PLATFORM SEAMS ARE LIVE. Reading an Application's Findings and
|
|
30
|
+
* writing a Finding's status arrived on the TypeScript wire in
|
|
31
|
+
* `@zeroroot-ai/sdk@0.10.0` (sdk-ts#51), so {@link harnessFindingSource} and
|
|
32
|
+
* {@link harnessFindingStatus} below back {@link FindingSource} and
|
|
33
|
+
* {@link FindingStatusWriter} on the per-dispatch task grant. They stayed
|
|
34
|
+
* seams rather than becoming direct calls, which is what let this file be
|
|
35
|
+
* driven by stubs before the wire existed and still be driven by them in
|
|
36
|
+
* tests now that it does.
|
|
38
37
|
*/
|
|
39
38
|
/** Severities, worst first. Used for the note's counts and for a stable order. */
|
|
40
39
|
export declare const SEVERITIES: readonly ["critical", "high", "medium", "low", "info"];
|
|
@@ -50,12 +49,15 @@ export interface FixableFinding {
|
|
|
50
49
|
/** Where it is: a `Package`, a `Repository` file, or a `Service`. */
|
|
51
50
|
placeLabel: string;
|
|
52
51
|
placeKey: string;
|
|
53
|
-
/**
|
|
52
|
+
/**
|
|
53
|
+
* `P1`..`P4`, what a triage pass decided (gibson#1684). **Absent means no
|
|
54
|
+
* pass has decided yet, never "unimportant"** — see {@link byWorkOrder}.
|
|
55
|
+
*/
|
|
54
56
|
priority?: string;
|
|
55
57
|
/** The merge request already opened for this Finding, when it is `fixing`. */
|
|
56
58
|
mergeRequestIid?: number;
|
|
57
59
|
}
|
|
58
|
-
/** Reads an Application's Findings.
|
|
60
|
+
/** Reads an Application's Findings. Backed by {@link harnessFindingSource}. */
|
|
59
61
|
export interface FindingSource {
|
|
60
62
|
/**
|
|
61
63
|
* The Application's Findings in the given statuses, **in the order they
|
|
@@ -65,7 +67,7 @@ export interface FindingSource {
|
|
|
65
67
|
*/
|
|
66
68
|
findings(application: string, statuses: string[]): Promise<FixableFinding[]>;
|
|
67
69
|
}
|
|
68
|
-
/** Moves a Finding through its statuses.
|
|
70
|
+
/** Moves a Finding through its statuses. Backed by {@link harnessFindingStatus}. */
|
|
69
71
|
export interface FindingStatusWriter {
|
|
70
72
|
/** Record that a merge request now proposes this Finding's fix. */
|
|
71
73
|
markFixing(findingId: string, mr: MergeRequest): Promise<void>;
|
|
@@ -205,3 +207,62 @@ export declare function statusDescription(summary: FixSummary): string;
|
|
|
205
207
|
export declare function mergeRequestBody(finding: FixableFinding, plan: FixPlan): string;
|
|
206
208
|
/** The note posted on each merge request: what this pass did, in full. */
|
|
207
209
|
export declare function noteBody(summary: FixSummary): string;
|
|
210
|
+
/**
|
|
211
|
+
* The order the Fix works Findings in: priority first, severity beneath it,
|
|
212
|
+
* then the Finding id so a pass over unchanged input is deterministic.
|
|
213
|
+
*
|
|
214
|
+
* Deterministic order matters beyond tidiness: the merge-request cap means the
|
|
215
|
+
* tail of this list is what gets deferred to the next pass, so an unstable
|
|
216
|
+
* sort would defer a different Finding each run and none would ever be worked.
|
|
217
|
+
*/
|
|
218
|
+
export declare function byWorkOrder(a: FixableFinding, b: FixableFinding): number;
|
|
219
|
+
/**
|
|
220
|
+
* Read an Application's Findings over the task grant (sdk-ts#51).
|
|
221
|
+
*
|
|
222
|
+
* The rejection is deliberately NOT caught. `applicationFindings` throws when
|
|
223
|
+
* the graph is unreachable, and swallowing that into an empty list is the one
|
|
224
|
+
* failure this whole seam exists to prevent: the Fix would report a clean
|
|
225
|
+
* Application over a live backlog, and it would look exactly like health.
|
|
226
|
+
*/
|
|
227
|
+
export declare function harnessFindingSource(knowledge: KnowledgeReadsFindings): FindingSource;
|
|
228
|
+
/** The single read the Fix needs from a knowledge source. */
|
|
229
|
+
export interface KnowledgeReadsFindings {
|
|
230
|
+
applicationFindings(opts: {
|
|
231
|
+
application: string;
|
|
232
|
+
statuses?: string[];
|
|
233
|
+
limit?: number;
|
|
234
|
+
}): Promise<ReadFinding[]>;
|
|
235
|
+
}
|
|
236
|
+
/** The fields of an `ApplicationFinding` the Fix reads. */
|
|
237
|
+
export interface ReadFinding {
|
|
238
|
+
findingId: string;
|
|
239
|
+
status: string;
|
|
240
|
+
severity: string;
|
|
241
|
+
vulnerabilityId: string;
|
|
242
|
+
placeLabel: string;
|
|
243
|
+
placeKey: string;
|
|
244
|
+
priority: string;
|
|
245
|
+
}
|
|
246
|
+
/** Writes one lifecycle sighting. Satisfied by the SDK's `observe`. */
|
|
247
|
+
export type ObserveLifecycle = (entity: {
|
|
248
|
+
label: string;
|
|
249
|
+
idProperties: Record<string, string>;
|
|
250
|
+
properties?: Record<string, string>;
|
|
251
|
+
}) => Promise<void>;
|
|
252
|
+
/**
|
|
253
|
+
* Move a Finding through its statuses over the task grant (sdk-ts#51).
|
|
254
|
+
*
|
|
255
|
+
* The Finding is named by its `brain_id` in `idProperties`, so the write lands
|
|
256
|
+
* on the node the scan raised rather than creating a second one beside it.
|
|
257
|
+
*
|
|
258
|
+
* Only the properties this transition decides are sent. A sighting that omits
|
|
259
|
+
* a property leaves whatever an earlier one established; one that sets it to
|
|
260
|
+
* `""` erases it. The Fix decides a status and, when it has one, the merge
|
|
261
|
+
* request — it decides nothing about severity, priority or reason, so it sends
|
|
262
|
+
* none of them and cannot blank what the scan or a triage pass recorded.
|
|
263
|
+
*
|
|
264
|
+
* There is no `markVerified`, and there is no branch here that could reach it.
|
|
265
|
+
* `verified` follows a rescan not seeing the weakness again, and absence is not
|
|
266
|
+
* an observation this process can make (gibson#1686).
|
|
267
|
+
*/
|
|
268
|
+
export declare function harnessFindingStatus(observe: ObserveLifecycle): FindingStatusWriter;
|
package/dist/fix.js
CHANGED
|
@@ -25,15 +25,14 @@
|
|
|
25
25
|
* `fix.test.ts` proves that with a sentinel that would show up in every
|
|
26
26
|
* recorded output if it ever did.
|
|
27
27
|
*
|
|
28
|
-
* TWO SEAMS ARE
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
* implementation to add and nothing here changes.
|
|
28
|
+
* THE TWO PLATFORM SEAMS ARE LIVE. Reading an Application's Findings and
|
|
29
|
+
* writing a Finding's status arrived on the TypeScript wire in
|
|
30
|
+
* `@zeroroot-ai/sdk@0.10.0` (sdk-ts#51), so {@link harnessFindingSource} and
|
|
31
|
+
* {@link harnessFindingStatus} below back {@link FindingSource} and
|
|
32
|
+
* {@link FindingStatusWriter} on the per-dispatch task grant. They stayed
|
|
33
|
+
* seams rather than becoming direct calls, which is what let this file be
|
|
34
|
+
* driven by stubs before the wire existed and still be driven by them in
|
|
35
|
+
* tests now that it does.
|
|
37
36
|
*/
|
|
38
37
|
/** Severities, worst first. Used for the note's counts and for a stable order. */
|
|
39
38
|
export const SEVERITIES = ["critical", "high", "medium", "low", "info"];
|
|
@@ -253,3 +252,101 @@ function firstLines(output, n = 3) {
|
|
|
253
252
|
function message(e) {
|
|
254
253
|
return e instanceof Error ? e.message : String(e);
|
|
255
254
|
}
|
|
255
|
+
// --------------------------------------------------------------------------
|
|
256
|
+
// the platform seams, backed by the task grant (zerocool-plugins#96)
|
|
257
|
+
// --------------------------------------------------------------------------
|
|
258
|
+
/**
|
|
259
|
+
* Priority order, worst first. `P1` is the most urgent thing a triage pass
|
|
260
|
+
* found; anything it has not ranked sorts AFTER everything it has.
|
|
261
|
+
*
|
|
262
|
+
* An unranked Finding is not a low-priority one — it is one no pass has
|
|
263
|
+
* decided about yet (gibson#1684). Ranking it as `P4` would be inventing a
|
|
264
|
+
* decision nobody took, and the triage agent's keep-previous rule would then
|
|
265
|
+
* preserve that invention on the next pass. So unranked sorts last among
|
|
266
|
+
* peers rather than being scored, and severity breaks the tie beneath it, so
|
|
267
|
+
* a critical unranked Finding still outranks a low unranked one.
|
|
268
|
+
*/
|
|
269
|
+
const PRIORITY_ORDER = ["p1", "p2", "p3", "p4"];
|
|
270
|
+
function priorityRank(priority) {
|
|
271
|
+
const i = PRIORITY_ORDER.indexOf((priority ?? "").toLowerCase());
|
|
272
|
+
return i === -1 ? PRIORITY_ORDER.length : i;
|
|
273
|
+
}
|
|
274
|
+
function severityRank(severity) {
|
|
275
|
+
const i = SEVERITIES.indexOf(severity.toLowerCase());
|
|
276
|
+
return i === -1 ? SEVERITIES.length : i;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* The order the Fix works Findings in: priority first, severity beneath it,
|
|
280
|
+
* then the Finding id so a pass over unchanged input is deterministic.
|
|
281
|
+
*
|
|
282
|
+
* Deterministic order matters beyond tidiness: the merge-request cap means the
|
|
283
|
+
* tail of this list is what gets deferred to the next pass, so an unstable
|
|
284
|
+
* sort would defer a different Finding each run and none would ever be worked.
|
|
285
|
+
*/
|
|
286
|
+
export function byWorkOrder(a, b) {
|
|
287
|
+
const p = priorityRank(a.priority) - priorityRank(b.priority);
|
|
288
|
+
if (p !== 0)
|
|
289
|
+
return p;
|
|
290
|
+
const s = severityRank(a.severity) - severityRank(b.severity);
|
|
291
|
+
if (s !== 0)
|
|
292
|
+
return s;
|
|
293
|
+
return a.id.localeCompare(b.id);
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Read an Application's Findings over the task grant (sdk-ts#51).
|
|
297
|
+
*
|
|
298
|
+
* The rejection is deliberately NOT caught. `applicationFindings` throws when
|
|
299
|
+
* the graph is unreachable, and swallowing that into an empty list is the one
|
|
300
|
+
* failure this whole seam exists to prevent: the Fix would report a clean
|
|
301
|
+
* Application over a live backlog, and it would look exactly like health.
|
|
302
|
+
*/
|
|
303
|
+
export function harnessFindingSource(knowledge) {
|
|
304
|
+
return {
|
|
305
|
+
async findings(application, statuses) {
|
|
306
|
+
const found = await knowledge.applicationFindings({ application, statuses });
|
|
307
|
+
return found
|
|
308
|
+
.map((f) => ({
|
|
309
|
+
id: f.findingId,
|
|
310
|
+
status: f.status,
|
|
311
|
+
severity: f.severity,
|
|
312
|
+
vulnerabilityId: f.vulnerabilityId,
|
|
313
|
+
placeLabel: f.placeLabel,
|
|
314
|
+
placeKey: f.placeKey,
|
|
315
|
+
// Omitted rather than defaulted: empty means no pass has decided.
|
|
316
|
+
...(f.priority ? { priority: f.priority } : {}),
|
|
317
|
+
}))
|
|
318
|
+
.sort(byWorkOrder);
|
|
319
|
+
},
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Move a Finding through its statuses over the task grant (sdk-ts#51).
|
|
324
|
+
*
|
|
325
|
+
* The Finding is named by its `brain_id` in `idProperties`, so the write lands
|
|
326
|
+
* on the node the scan raised rather than creating a second one beside it.
|
|
327
|
+
*
|
|
328
|
+
* Only the properties this transition decides are sent. A sighting that omits
|
|
329
|
+
* a property leaves whatever an earlier one established; one that sets it to
|
|
330
|
+
* `""` erases it. The Fix decides a status and, when it has one, the merge
|
|
331
|
+
* request — it decides nothing about severity, priority or reason, so it sends
|
|
332
|
+
* none of them and cannot blank what the scan or a triage pass recorded.
|
|
333
|
+
*
|
|
334
|
+
* There is no `markVerified`, and there is no branch here that could reach it.
|
|
335
|
+
* `verified` follows a rescan not seeing the weakness again, and absence is not
|
|
336
|
+
* an observation this process can make (gibson#1686).
|
|
337
|
+
*/
|
|
338
|
+
export function harnessFindingStatus(observe) {
|
|
339
|
+
const write = (findingId, properties) => observe({ label: "Finding", idProperties: { brain_id: findingId }, properties });
|
|
340
|
+
return {
|
|
341
|
+
async markFixing(findingId, mr) {
|
|
342
|
+
await write(findingId, {
|
|
343
|
+
status: "fixing",
|
|
344
|
+
merge_request_iid: String(mr.iid),
|
|
345
|
+
merge_request_url: mr.webUrl,
|
|
346
|
+
});
|
|
347
|
+
},
|
|
348
|
+
async markFixed(findingId) {
|
|
349
|
+
await write(findingId, { status: "fixed" });
|
|
350
|
+
},
|
|
351
|
+
};
|
|
352
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zeroroot-ai/zerocool",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "opencode plugin: Gibson platform integration (zerocool). Zero-config LLM, tools, findings, knowledge, delegate/missions.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"test": "tsc -p tsconfig.test.json && node --test \"dist-test/**/*.test.js\""
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@zeroroot-ai/sdk": "^0.
|
|
26
|
+
"@zeroroot-ai/sdk": "^0.10.0"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"@opencode-ai/plugin": "*"
|