@lornatang/dsh-codex-security 0.1.12 → 0.1.13
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/CHANGELOG.md +5 -0
- package/README.md +1 -1
- package/README.zh.md +1 -1
- package/docs/ARCHITECTURE.md +59 -59
- package/docs/ARTIFACTS.md +49 -49
- package/docs/CODEX-COMPATIBILITY.md +17 -17
- package/docs/SPEC.md +43 -43
- package/docs/TOOLS.md +364 -364
- package/docs/VALIDATION.md +33 -33
- package/docs/superpowers/plans/2026-11-16-deep-scan.md +71 -71
- package/docs/superpowers/specs/2026-11-16-deep-scan-design.md +31 -31
- package/lib/client.js +6 -1
- package/lib/constants.js +1 -1
- package/lib/deep-coordinator.js +80 -55
- package/lib/git.js +44 -8
- package/lib/service.js +65 -29
- package/lib/store.js +78 -39
- package/lib/target.js +27 -11
- package/lib/types/constants.d.ts +1 -1
- package/lib/types/deep-coordinator.d.ts +2 -8
- package/lib/types/git.d.ts +4 -0
- package/lib/types/index.d.ts +1 -1
- package/lib/types/service.d.ts +5 -3
- package/lib/types/store.d.ts +6 -1
- package/lib/types/target.d.ts +6 -2
- package/lib/types/util.d.ts +1 -0
- package/lib/util.js +18 -15
- package/package.json +1 -1
- package/schemas/coverage.schema.json +136 -136
- package/skills/README.md +122 -122
- package/skills/assess-patch-risk/SKILL.md +10 -10
- package/skills/attack-path-analysis/SKILL.md +10 -10
- package/skills/deep-security-scan/SKILL.md +15 -15
- package/skills/define-security-policy/SKILL.md +10 -10
- package/skills/finding-discovery/SKILL.md +10 -10
- package/skills/fix-finding/SKILL.md +14 -14
- package/skills/propose-security-hardening/SKILL.md +10 -10
- package/skills/track-findings/SKILL.md +12 -12
- package/skills/validation/SKILL.md +10 -10
- package/skills/verify-fix/SKILL.md +14 -14
package/docs/VALIDATION.md
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
# Validation
|
|
2
|
-
|
|
3
|
-
Run the automated checks from the repository root with Node.js 22.19 or later:
|
|
4
|
-
|
|
5
|
-
```bash
|
|
6
|
-
npm ci --no-audit --no-fund
|
|
7
|
-
npm run typecheck
|
|
8
|
-
npm test
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
`npm test` rebuilds the tracked host and client output and runs the Node test suite. The suite exercises real Cordis, DSH skill and tool registries, and the DSH tool execution pipeline without a user profile. It also covers scoped and diff targets, untracked files, snapshot changes, worker tool guards, bounded reads and delivered-content receipts, Deep budgets and deduplication, process death and authorized takeover, cross-process cancellation and index races, draft completeness, comparison guards, sealed artifacts and schema validation.
|
|
12
|
-
|
|
13
|
-
CI runs these checks on Linux, macOS and Windows with Node 22.19 and 24 as configured in the matrix. After committing any regenerated `lib/` files, `git diff --exit-code -- lib` verifies that another build is reproducible. The integration test uses the pinned DSH 0.2.2-rc.2 development packages. It does not replace a full manual DSH application or agent review.
|
|
14
|
-
|
|
15
|
-
## Package inspection
|
|
16
|
-
|
|
17
|
-
```bash
|
|
18
|
-
npm pack --dry-run
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
The package must include `lib/`, `cordis.patch.yml`, `skills/`, `references/`, `schemas/`, `docs/`, `examples/`, `README.md`, `CHANGELOG.md`, `LICENSE` and `NOTICE`. Source, tests and local dependencies are not published. The README and project documentation are in English.
|
|
22
|
-
|
|
23
|
-
## Optional isolated DSH check
|
|
24
|
-
|
|
25
|
-
Use a disposable DSH home rather than a working profile. Generate a tarball with `npm pack`, capture the actual filename printed by npm, and install it into a profile under that temporary home. Check that the host loads, all 16 skills can be read, and the workbench routes respond. Remove the disposable home after the check. This exercise may need npm registry access to install package dependencies.
|
|
26
|
-
|
|
27
|
-
## Artifact checks
|
|
28
|
-
|
|
29
|
-
Findings, coverage and manifest documents are validated against `schemas/` by the host before sealing. The regression suite independently validates generated examples and checks the SHA-256 digest of a sealed supporting artifact. Check a complete manual review as well when changing the workflow: account for each bound diff file, compare only compatible completed scans, and verify that attempted post-completion writes fail.
|
|
30
|
-
|
|
31
|
-
For an optional interoperability check, set `CODEX_SECURITY_REFERENCE_ROOT` to an installed Codex Security 0.1.32 plugin directory and run `npm test` with Python available on `PATH`. The test passes a generated completed scan to that installation's `scripts/validate_scan_contract.py`. CI does not require that separate plugin.
|
|
32
|
-
|
|
33
|
-
A green build confirms the exercised behavior. It does not establish that an agent actually reviewed every claimed surface or that the target has no vulnerabilities.
|
|
1
|
+
# Validation
|
|
2
|
+
|
|
3
|
+
Run the automated checks from the repository root with Node.js 22.19 or later:
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm ci --no-audit --no-fund
|
|
7
|
+
npm run typecheck
|
|
8
|
+
npm test
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
`npm test` rebuilds the tracked host and client output and runs the Node test suite. The suite exercises real Cordis, DSH skill and tool registries, and the DSH tool execution pipeline without a user profile. It also covers scoped and diff targets, untracked files, snapshot changes, worker tool guards, bounded reads and delivered-content receipts, Deep budgets and deduplication, process death and authorized takeover, cross-process cancellation and index races, draft completeness, comparison guards, sealed artifacts and schema validation.
|
|
12
|
+
|
|
13
|
+
CI runs these checks on Linux, macOS and Windows with Node 22.19 and 24 as configured in the matrix. After committing any regenerated `lib/` files, `git diff --exit-code -- lib` verifies that another build is reproducible. The integration test uses the pinned DSH 0.2.2-rc.2 development packages. It does not replace a full manual DSH application or agent review.
|
|
14
|
+
|
|
15
|
+
## Package inspection
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm pack --dry-run
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
The package must include `lib/`, `cordis.patch.yml`, `skills/`, `references/`, `schemas/`, `docs/`, `examples/`, `README.md`, `CHANGELOG.md`, `LICENSE` and `NOTICE`. Source, tests and local dependencies are not published. The README and project documentation are in English.
|
|
22
|
+
|
|
23
|
+
## Optional isolated DSH check
|
|
24
|
+
|
|
25
|
+
Use a disposable DSH home rather than a working profile. Generate a tarball with `npm pack`, capture the actual filename printed by npm, and install it into a profile under that temporary home. Check that the host loads, all 16 skills can be read, and the workbench routes respond. Remove the disposable home after the check. This exercise may need npm registry access to install package dependencies.
|
|
26
|
+
|
|
27
|
+
## Artifact checks
|
|
28
|
+
|
|
29
|
+
Findings, coverage and manifest documents are validated against `schemas/` by the host before sealing. The regression suite independently validates generated examples and checks the SHA-256 digest of a sealed supporting artifact. Check a complete manual review as well when changing the workflow: account for each bound diff file, compare only compatible completed scans, and verify that attempted post-completion writes fail.
|
|
30
|
+
|
|
31
|
+
For an optional interoperability check, set `CODEX_SECURITY_REFERENCE_ROOT` to an installed Codex Security 0.1.32 plugin directory and run `npm test` with Python available on `PATH`. The test passes a generated completed scan to that installation's `scripts/validate_scan_contract.py`. CI does not require that separate plugin.
|
|
32
|
+
|
|
33
|
+
A green build confirms the exercised behavior. It does not establish that an agent actually reviewed every claimed surface or that the target has no vulnerabilities.
|
|
@@ -1,71 +1,71 @@
|
|
|
1
|
-
# Deep Scan implementation plan
|
|
2
|
-
|
|
3
|
-
> Execute inline with `superpowers:executing-plans`; use a fresh reviewer before release.
|
|
4
|
-
|
|
5
|
-
**Goal:** Run bounded, isolated DSH review workers with durable cross-process recovery and a sealed, honest parent scan.
|
|
6
|
-
|
|
7
|
-
**Architecture:** A service-owned coordinator persists a campaign journal and uses local DSH activations. SQLite OS locks serialize campaign ownership, scan mutations and the shared index. Worker tools expose only a bound, verified source inventory, while a monotonic tool guard denies all other worker actions. Each accepted worker result is independently recorded and sealed before parent aggregation.
|
|
8
|
-
|
|
9
|
-
**Tech Stack:** TypeScript, Node.js >=22.19, built-in SQLite, DSH 0.2.2-rc.2/rc.3, Node test runner, GitHub Actions.
|
|
10
|
-
|
|
11
|
-
**Spec:** `docs/superpowers/specs/2026-11-16-deep-scan-design.md`.
|
|
12
|
-
|
|
13
|
-
## Global constraints
|
|
14
|
-
|
|
15
|
-
- Keep the npm name `@lornatang/dsh-codex-security`, preserve earlier uncommitted parity work and integrate the published v0.1.7 changes.
|
|
16
|
-
- No unsafe fallback when native/host capabilities, reliable lock semantics or worker confinement are unavailable.
|
|
17
|
-
- Automatic Deep does not accept diff targets; manual diff review remains available.
|
|
18
|
-
- Sealed scans are immutable and the parent may report partial coverage.
|
|
19
|
-
- Run Windows locally, the complete Linux/macOS/Windows matrix in GitHub CI, and the installed Codex artifact validator where available.
|
|
20
|
-
|
|
21
|
-
## Review focus
|
|
22
|
-
|
|
23
|
-
1. Two independent processes race to resume one campaign: exactly one owns it and a killed owner releases its lock.
|
|
24
|
-
2. Different scans update the shared index concurrently: neither scan disappears from the durable index.
|
|
25
|
-
3. A worker uses a scoped tool, transport, absolute path, traversal or swapped symlink: it cannot mutate the target or read outside the bound inventory.
|
|
26
|
-
4. An unfinished worker, process crash, timeout, changed target or conflicting duplicate must not produce a clean completed review.
|
|
27
|
-
5. A different session guesses a parent or child scan ID: every managed mutation fails without its recovery claim.
|
|
28
|
-
|
|
29
|
-
## Tasks
|
|
30
|
-
|
|
31
|
-
### Task 1: Cross-process state locks
|
|
32
|
-
|
|
33
|
-
**Files:** create `src/state-lock.ts`, `tests/state-lock.test.mjs`, `tests/fixtures/state-lock-process.mjs`; modify `src/store.ts`, `src/service.ts`.
|
|
34
|
-
|
|
35
|
-
**Interfaces:** `acquireStateLock(path, { signal?, timeoutMs? }): Promise<() => void>`; `ScanStore.serialize` uses the global index lock and reads the current on-disk index; scan mutation queues also use a per-scan lock.
|
|
36
|
-
|
|
37
|
-
- [x] Write tests for competing real processes, owner termination, timeout, concurrent scan/index updates and independent locks.
|
|
38
|
-
- [x] Run them and observe the intended missing-lock or lost-update failure.
|
|
39
|
-
- [x] Implement SQLite-backed OS-held locks with cancellation, never unlink the databases, and remove stale index-cache writes outside the index lock.
|
|
40
|
-
- [x] Run the lock tests and full suite; verify no unrelated standard scan regresses.
|
|
41
|
-
|
|
42
|
-
### Task 2: Bound worker source and tool guard
|
|
43
|
-
|
|
44
|
-
**Files:** create `src/deep-worker.ts`, `src/secure-read.ts`, `tests/deep-worker.test.mjs` and any process fixtures; modify `src/index.ts`, `src/types.ts`, `src/tools.ts`.
|
|
45
|
-
|
|
46
|
-
**Interfaces:** `WorkerRegistry.reserve(childId, boundSnapshot)` installs an identity before startup; the guard permits only the worker's inventory/read tools and scoped `structured_output`; secure reads return bytes only for a bound inventory path whose digest matches.
|
|
47
|
-
|
|
48
|
-
- [ ] Write tests for scope traversal, outside links, parent replacement, file changes, non-worker access and denial of native/scoped/PTC mutation tools.
|
|
49
|
-
- [ ] Observe the failures; implement pinned, cross-platform reads and the real DSH `tools.guard` integration, failing closed on unavailable enforcement.
|
|
50
|
-
- [ ] Verify tests using actual DSH tool registries and process fixtures, then run the full suite.
|
|
51
|
-
|
|
52
|
-
### Task 3: Durable coordinator and budget enforcement
|
|
53
|
-
|
|
54
|
-
**Files:** create `src/deep-scan.ts`, `tests/deep-scan.test.mjs`, `tests/fixtures/deep-scan-process.mjs`; modify `src/service.ts`, `src/store.ts`, `src/types.ts`.
|
|
55
|
-
|
|
56
|
-
**Interfaces:** `DeepCoordinator.start`, `resume`, `cancel`, `status` accept a host execution identity; a durable journal carries hashed recovery claim, full binding, deadline and run state. The DSH provider boundary uses `startActivation` with reserved child ID and structured output.
|
|
57
|
-
|
|
58
|
-
- [ ] Write tests for worker limits, attempt budget, no-new stopping, elapsed deadline, structured results, missing/failed workers, cancellation, crash/restart, concurrent resumes and target changes.
|
|
59
|
-
- [ ] Observe expected failures; implement journal transitions, exclusive campaign ownership, background lifecycle cleanup and reconciliation of child scans.
|
|
60
|
-
- [ ] Record and seal independent Standard child scans, merge findings and provenance conservatively, then seal the parent with correct complete/partial coverage.
|
|
61
|
-
- [ ] Test all managed parent and child mutations against owner identity and recovery claims; reject auto-deep diff targets.
|
|
62
|
-
- [ ] Run coordinator tests and full suite.
|
|
63
|
-
|
|
64
|
-
### Task 4: Host tools, documentation and release
|
|
65
|
-
|
|
66
|
-
**Files:** modify `src/tools.ts`, `src/index.ts`, `skills/deep-security-scan/SKILL.md`, `docs/CODEX-COMPATIBILITY.md`, user documentation, version files and `.github/workflows/ci.yml` only if needed; test real DSH registration and package output.
|
|
67
|
-
|
|
68
|
-
- [ ] Write a host integration test exercising start, status, resume and cancel with actual DSH tool execution identity; verify it fails before wiring.
|
|
69
|
-
- [ ] Wire generic and named deep start tools, recovery and cancellation, preserve manual Standard/diff behavior, and update the skill and docs.
|
|
70
|
-
- [ ] Run typecheck, the complete test suite, reference artifact validation, package dry run and reproducible build; request one fresh code review.
|
|
71
|
-
- [ ] Commit only after validation. Push the commit, wait for the GitHub OS matrix, publish a new GitHub release, and attempt npm publication; report authentication failures accurately.
|
|
1
|
+
# Deep Scan implementation plan
|
|
2
|
+
|
|
3
|
+
> Execute inline with `superpowers:executing-plans`; use a fresh reviewer before release.
|
|
4
|
+
|
|
5
|
+
**Goal:** Run bounded, isolated DSH review workers with durable cross-process recovery and a sealed, honest parent scan.
|
|
6
|
+
|
|
7
|
+
**Architecture:** A service-owned coordinator persists a campaign journal and uses local DSH activations. SQLite OS locks serialize campaign ownership, scan mutations and the shared index. Worker tools expose only a bound, verified source inventory, while a monotonic tool guard denies all other worker actions. Each accepted worker result is independently recorded and sealed before parent aggregation.
|
|
8
|
+
|
|
9
|
+
**Tech Stack:** TypeScript, Node.js >=22.19, built-in SQLite, DSH 0.2.2-rc.2/rc.3, Node test runner, GitHub Actions.
|
|
10
|
+
|
|
11
|
+
**Spec:** `docs/superpowers/specs/2026-11-16-deep-scan-design.md`.
|
|
12
|
+
|
|
13
|
+
## Global constraints
|
|
14
|
+
|
|
15
|
+
- Keep the npm name `@lornatang/dsh-codex-security`, preserve earlier uncommitted parity work and integrate the published v0.1.7 changes.
|
|
16
|
+
- No unsafe fallback when native/host capabilities, reliable lock semantics or worker confinement are unavailable.
|
|
17
|
+
- Automatic Deep does not accept diff targets; manual diff review remains available.
|
|
18
|
+
- Sealed scans are immutable and the parent may report partial coverage.
|
|
19
|
+
- Run Windows locally, the complete Linux/macOS/Windows matrix in GitHub CI, and the installed Codex artifact validator where available.
|
|
20
|
+
|
|
21
|
+
## Review focus
|
|
22
|
+
|
|
23
|
+
1. Two independent processes race to resume one campaign: exactly one owns it and a killed owner releases its lock.
|
|
24
|
+
2. Different scans update the shared index concurrently: neither scan disappears from the durable index.
|
|
25
|
+
3. A worker uses a scoped tool, transport, absolute path, traversal or swapped symlink: it cannot mutate the target or read outside the bound inventory.
|
|
26
|
+
4. An unfinished worker, process crash, timeout, changed target or conflicting duplicate must not produce a clean completed review.
|
|
27
|
+
5. A different session guesses a parent or child scan ID: every managed mutation fails without its recovery claim.
|
|
28
|
+
|
|
29
|
+
## Tasks
|
|
30
|
+
|
|
31
|
+
### Task 1: Cross-process state locks
|
|
32
|
+
|
|
33
|
+
**Files:** create `src/state-lock.ts`, `tests/state-lock.test.mjs`, `tests/fixtures/state-lock-process.mjs`; modify `src/store.ts`, `src/service.ts`.
|
|
34
|
+
|
|
35
|
+
**Interfaces:** `acquireStateLock(path, { signal?, timeoutMs? }): Promise<() => void>`; `ScanStore.serialize` uses the global index lock and reads the current on-disk index; scan mutation queues also use a per-scan lock.
|
|
36
|
+
|
|
37
|
+
- [x] Write tests for competing real processes, owner termination, timeout, concurrent scan/index updates and independent locks.
|
|
38
|
+
- [x] Run them and observe the intended missing-lock or lost-update failure.
|
|
39
|
+
- [x] Implement SQLite-backed OS-held locks with cancellation, never unlink the databases, and remove stale index-cache writes outside the index lock.
|
|
40
|
+
- [x] Run the lock tests and full suite; verify no unrelated standard scan regresses.
|
|
41
|
+
|
|
42
|
+
### Task 2: Bound worker source and tool guard
|
|
43
|
+
|
|
44
|
+
**Files:** create `src/deep-worker.ts`, `src/secure-read.ts`, `tests/deep-worker.test.mjs` and any process fixtures; modify `src/index.ts`, `src/types.ts`, `src/tools.ts`.
|
|
45
|
+
|
|
46
|
+
**Interfaces:** `WorkerRegistry.reserve(childId, boundSnapshot)` installs an identity before startup; the guard permits only the worker's inventory/read tools and scoped `structured_output`; secure reads return bytes only for a bound inventory path whose digest matches.
|
|
47
|
+
|
|
48
|
+
- [ ] Write tests for scope traversal, outside links, parent replacement, file changes, non-worker access and denial of native/scoped/PTC mutation tools.
|
|
49
|
+
- [ ] Observe the failures; implement pinned, cross-platform reads and the real DSH `tools.guard` integration, failing closed on unavailable enforcement.
|
|
50
|
+
- [ ] Verify tests using actual DSH tool registries and process fixtures, then run the full suite.
|
|
51
|
+
|
|
52
|
+
### Task 3: Durable coordinator and budget enforcement
|
|
53
|
+
|
|
54
|
+
**Files:** create `src/deep-scan.ts`, `tests/deep-scan.test.mjs`, `tests/fixtures/deep-scan-process.mjs`; modify `src/service.ts`, `src/store.ts`, `src/types.ts`.
|
|
55
|
+
|
|
56
|
+
**Interfaces:** `DeepCoordinator.start`, `resume`, `cancel`, `status` accept a host execution identity; a durable journal carries hashed recovery claim, full binding, deadline and run state. The DSH provider boundary uses `startActivation` with reserved child ID and structured output.
|
|
57
|
+
|
|
58
|
+
- [ ] Write tests for worker limits, attempt budget, no-new stopping, elapsed deadline, structured results, missing/failed workers, cancellation, crash/restart, concurrent resumes and target changes.
|
|
59
|
+
- [ ] Observe expected failures; implement journal transitions, exclusive campaign ownership, background lifecycle cleanup and reconciliation of child scans.
|
|
60
|
+
- [ ] Record and seal independent Standard child scans, merge findings and provenance conservatively, then seal the parent with correct complete/partial coverage.
|
|
61
|
+
- [ ] Test all managed parent and child mutations against owner identity and recovery claims; reject auto-deep diff targets.
|
|
62
|
+
- [ ] Run coordinator tests and full suite.
|
|
63
|
+
|
|
64
|
+
### Task 4: Host tools, documentation and release
|
|
65
|
+
|
|
66
|
+
**Files:** modify `src/tools.ts`, `src/index.ts`, `skills/deep-security-scan/SKILL.md`, `docs/CODEX-COMPATIBILITY.md`, user documentation, version files and `.github/workflows/ci.yml` only if needed; test real DSH registration and package output.
|
|
67
|
+
|
|
68
|
+
- [ ] Write a host integration test exercising start, status, resume and cancel with actual DSH tool execution identity; verify it fails before wiring.
|
|
69
|
+
- [ ] Wire generic and named deep start tools, recovery and cancellation, preserve manual Standard/diff behavior, and update the skill and docs.
|
|
70
|
+
- [ ] Run typecheck, the complete test suite, reference artifact validation, package dry run and reproducible build; request one fresh code review.
|
|
71
|
+
- [ ] Commit only after validation. Push the commit, wait for the GitHub OS matrix, publish a new GitHub release, and attempt npm publication; report authentication failures accurately.
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
# Deep Scan orchestration design
|
|
2
|
-
|
|
3
|
-
## Objective and constraints
|
|
4
|
-
|
|
5
|
-
Run independent, full-scope DSH security-review workers automatically, persist their results and bounded progress, recover after a host process exits, and produce an honest, compatible parent scan. Preserve the existing manual and standard scan APIs and the previously completed artifact-compatibility work. Do not weaken the user's current filesystem and export protections or silently start unrestricted workers. The npm package remains `@lornatang/dsh-codex-security`.
|
|
6
|
-
|
|
7
|
-
## Approaches considered
|
|
8
|
-
|
|
9
|
-
1. Delegate directly with the existing generic subagent tool. This is simple but inherits the parent's unrestricted tools and leaves budgets and recovery to the model; a prompt alone is not an authority boundary.
|
|
10
|
-
2. Run a plugin-owned coordinator over the DSH in-process subagent service, enforce a tool guard for specifically identified workers, and persist progress behind operating-system-owned cross-process locks. This preserves DSH's model selection while keeping worker authority and campaign state under the plugin's control. This is the selected approach.
|
|
11
|
-
3. Depend on an external Codex CLI or service. This would add separate credentials and a non-DSH execution dependency, so it is not the requested standalone DSH implementation.
|
|
12
|
-
|
|
13
|
-
## Coordinator and lifecycle
|
|
14
|
-
|
|
15
|
-
The coordinator starts or rejoins one deep parent. Its durable journal records immutable target binding and scope, the full file inventory and per-file digests, budgets, wall-clock deadline, run identities, run lifecycle, completed child scan IDs, processed outcomes, no-new count, stop reason, errors and parent assembly progress. It is written atomically before and after each externally visible step. Recovery reconciles the journal with completed or unfinished child scans and never treats lost work as a completed review. Once the elapsed deadline or run budget is exhausted it does not start new work, and it records unfinished coverage instead of claiming completion. Automatic Deep scans reject diff targets because the current worktree inventory cannot represent deleted or revision-only files; existing manual diff workflows remain available.
|
|
16
|
-
|
|
17
|
-
Use the host's `spawn` provider only when it is local, fresh-context, and supports structured results. Each worker receives the same bound target and scope but not prior workers' conclusions. Its prompt requests a complete independent review; its structured result is validated before a separate Standard child scan is recorded and sealed. The DSH structured-output schema uses only its supported subset; the resulting data is then validated against the full artifact contracts. At most `workers` run concurrently; `maxDiscoveryRuns` counts attempts. Process completed runs in a deterministic order when updating `stopAfterNoNew`. Already running workers are canceled or accounted for on stop, timeout, host disposal or explicit cancellation. A failed or interrupted worker is never counted as a clean review.
|
|
18
|
-
|
|
19
|
-
The parent merges matching target/rule/anchor/instance fingerprints only when the reported locations and dataflow are compatible, retains each worker's provenance, keeps unrelated instances separate, and records all worker coverage and unresolved work. Same-fingerprint findings at different locations or with conflicting dataflow remain unresolved and count as new; they are not silently merged. Findings with different identities also count as new even when they might describe the same issue. Conflicting or missing results produce partial coverage. A successful parent draft is sealed through the existing scan service; target changes or invalid evidence fail closed. If no worker yields a valid completed review, the parent is failed with diagnostics rather than reported clean. A completed zero-finding scan requires at least one complete worker with its own successful, full-content read receipt for every in-scope inventory file; receipts from different workers may not be combined to claim a complete review. Unavailable or oversized files remain deferred. If no worker meets that condition and no findings exist, the parent fails with diagnostics instead of remaining indefinitely running or reporting a clean scan. Receipts prove delivery to the agent, not comprehension or absence of vulnerabilities.
|
|
20
|
-
|
|
21
|
-
The start tool returns the scan ID and a random recovery claim promptly and exposes status, cancellation and explicit resume. The journal stores only a digest of the claim and the owner's session identity; resuming, canceling or mutating the parent or its managed child scans from another session requires the claim. If a process dies before the claim is delivered, recovery is limited to the original session; an inaccessible orphan must not be taken over without authorization. Existing manual scans retain their current API. The tool adapter forwards the actual DSH execution identity and cancellation signal; a model-supplied session ID is never trusted. Background work must be owned by the plugin's lifecycle and use the DSH subagent activation's supported lifetime. A restart does not fabricate a parent Agent: resume requires a live authorized calling agent. State survives across processes, while unavailable host services fail with an actionable error rather than silently falling back to unsafe delegation.
|
|
22
|
-
|
|
23
|
-
## Security and concurrency
|
|
24
|
-
|
|
25
|
-
Install a host tool guard before worker startup. Reserve the in-process activation's child ID and identify the worker before its first turn; deny every tool other than the dedicated read-only worker tools and DSH's scoped `structured_output`, including other scoped tools and program-execution transports. A dedicated native-tool worker preset installs its own inherited guard, so a later cold-resume remains confined; removing the preset or plugin makes resume fail closed. Worker access also requires a live coordinator binding. Restrict worker reads to the bound inventory and scope with pinned directory/file handles; reject traversal, links that escape the target and files whose snapshot changes. Count a full-file receipt only after the DSH tool pipeline accepts the read result; flush receipts before accepting a worker result. Existing service evidence reads for worker-submitted locations must use the same verified file handle, not validate a path and then reopen it. Repository contents are untrusted data. Worker outputs and saved receipts are validated, not executed.
|
|
26
|
-
|
|
27
|
-
Each campaign has a persistent local SQLite lock database held in an exclusive write transaction. SQLite uses OS locks and releases them when a process dies; the lock database is never unlinked during normal operation. Every shared parent mutation has a cross-process scan lock, and all index read-modify-write operations have a separate global index lock with fresh reads. Lock acquisition is bounded and cancellation-aware. Atomic checkpoint writes occur while the campaign owner holds the lock. On takeover the new process reconciles journal state before starting work. No PID-only stale-lock deletion or lease timeout may allow two live owners. State storage is a trusted local directory on a filesystem with reliable SQLite locking; unsupported locking or a compromised lock path fails closed.
|
|
28
|
-
|
|
29
|
-
## Verification and release
|
|
30
|
-
|
|
31
|
-
Exercise real filesystem and process behavior on Windows, Linux and macOS, using deterministic fake model responses at the DSH provider boundary. Tests cover concurrency limits, no-new and run budgets, elapsed time, cancellation, independent scopes, malformed results, denied tools and path escapes, process crash/restart, two competing owners, partial worker completion and target changes. Retain the existing export-race and artifact-compatibility suite. Test the actual DSH registries and activation interface in addition to the fake provider, and verify package contents and reproducible output. Run GitHub CI before a versioned GitHub release and attempt the npm release with the configured account.
|
|
1
|
+
# Deep Scan orchestration design
|
|
2
|
+
|
|
3
|
+
## Objective and constraints
|
|
4
|
+
|
|
5
|
+
Run independent, full-scope DSH security-review workers automatically, persist their results and bounded progress, recover after a host process exits, and produce an honest, compatible parent scan. Preserve the existing manual and standard scan APIs and the previously completed artifact-compatibility work. Do not weaken the user's current filesystem and export protections or silently start unrestricted workers. The npm package remains `@lornatang/dsh-codex-security`.
|
|
6
|
+
|
|
7
|
+
## Approaches considered
|
|
8
|
+
|
|
9
|
+
1. Delegate directly with the existing generic subagent tool. This is simple but inherits the parent's unrestricted tools and leaves budgets and recovery to the model; a prompt alone is not an authority boundary.
|
|
10
|
+
2. Run a plugin-owned coordinator over the DSH in-process subagent service, enforce a tool guard for specifically identified workers, and persist progress behind operating-system-owned cross-process locks. This preserves DSH's model selection while keeping worker authority and campaign state under the plugin's control. This is the selected approach.
|
|
11
|
+
3. Depend on an external Codex CLI or service. This would add separate credentials and a non-DSH execution dependency, so it is not the requested standalone DSH implementation.
|
|
12
|
+
|
|
13
|
+
## Coordinator and lifecycle
|
|
14
|
+
|
|
15
|
+
The coordinator starts or rejoins one deep parent. Its durable journal records immutable target binding and scope, the full file inventory and per-file digests, budgets, wall-clock deadline, run identities, run lifecycle, completed child scan IDs, processed outcomes, no-new count, stop reason, errors and parent assembly progress. It is written atomically before and after each externally visible step. Recovery reconciles the journal with completed or unfinished child scans and never treats lost work as a completed review. Once the elapsed deadline or run budget is exhausted it does not start new work, and it records unfinished coverage instead of claiming completion. Automatic Deep scans reject diff targets because the current worktree inventory cannot represent deleted or revision-only files; existing manual diff workflows remain available.
|
|
16
|
+
|
|
17
|
+
Use the host's `spawn` provider only when it is local, fresh-context, and supports structured results. Each worker receives the same bound target and scope but not prior workers' conclusions. Its prompt requests a complete independent review; its structured result is validated before a separate Standard child scan is recorded and sealed. The DSH structured-output schema uses only its supported subset; the resulting data is then validated against the full artifact contracts. At most `workers` run concurrently; `maxDiscoveryRuns` counts attempts. Process completed runs in a deterministic order when updating `stopAfterNoNew`. Already running workers are canceled or accounted for on stop, timeout, host disposal or explicit cancellation. A failed or interrupted worker is never counted as a clean review.
|
|
18
|
+
|
|
19
|
+
The parent merges matching target/rule/anchor/instance fingerprints only when the reported locations and dataflow are compatible, retains each worker's provenance, keeps unrelated instances separate, and records all worker coverage and unresolved work. Same-fingerprint findings at different locations or with conflicting dataflow remain unresolved and count as new; they are not silently merged. Findings with different identities also count as new even when they might describe the same issue. Conflicting or missing results produce partial coverage. A successful parent draft is sealed through the existing scan service; target changes or invalid evidence fail closed. If no worker yields a valid completed review, the parent is failed with diagnostics rather than reported clean. A completed zero-finding scan requires at least one complete worker with its own successful, full-content read receipt for every in-scope inventory file; receipts from different workers may not be combined to claim a complete review. Unavailable or oversized files remain deferred. If no worker meets that condition and no findings exist, the parent fails with diagnostics instead of remaining indefinitely running or reporting a clean scan. Receipts prove delivery to the agent, not comprehension or absence of vulnerabilities.
|
|
20
|
+
|
|
21
|
+
The start tool returns the scan ID and a random recovery claim promptly and exposes status, cancellation and explicit resume. The journal stores only a digest of the claim and the owner's session identity; resuming, canceling or mutating the parent or its managed child scans from another session requires the claim. If a process dies before the claim is delivered, recovery is limited to the original session; an inaccessible orphan must not be taken over without authorization. Existing manual scans retain their current API. The tool adapter forwards the actual DSH execution identity and cancellation signal; a model-supplied session ID is never trusted. Background work must be owned by the plugin's lifecycle and use the DSH subagent activation's supported lifetime. A restart does not fabricate a parent Agent: resume requires a live authorized calling agent. State survives across processes, while unavailable host services fail with an actionable error rather than silently falling back to unsafe delegation.
|
|
22
|
+
|
|
23
|
+
## Security and concurrency
|
|
24
|
+
|
|
25
|
+
Install a host tool guard before worker startup. Reserve the in-process activation's child ID and identify the worker before its first turn; deny every tool other than the dedicated read-only worker tools and DSH's scoped `structured_output`, including other scoped tools and program-execution transports. A dedicated native-tool worker preset installs its own inherited guard, so a later cold-resume remains confined; removing the preset or plugin makes resume fail closed. Worker access also requires a live coordinator binding. Restrict worker reads to the bound inventory and scope with pinned directory/file handles; reject traversal, links that escape the target and files whose snapshot changes. Count a full-file receipt only after the DSH tool pipeline accepts the read result; flush receipts before accepting a worker result. Existing service evidence reads for worker-submitted locations must use the same verified file handle, not validate a path and then reopen it. Repository contents are untrusted data. Worker outputs and saved receipts are validated, not executed.
|
|
26
|
+
|
|
27
|
+
Each campaign has a persistent local SQLite lock database held in an exclusive write transaction. SQLite uses OS locks and releases them when a process dies; the lock database is never unlinked during normal operation. Every shared parent mutation has a cross-process scan lock, and all index read-modify-write operations have a separate global index lock with fresh reads. Lock acquisition is bounded and cancellation-aware. Atomic checkpoint writes occur while the campaign owner holds the lock. On takeover the new process reconciles journal state before starting work. No PID-only stale-lock deletion or lease timeout may allow two live owners. State storage is a trusted local directory on a filesystem with reliable SQLite locking; unsupported locking or a compromised lock path fails closed.
|
|
28
|
+
|
|
29
|
+
## Verification and release
|
|
30
|
+
|
|
31
|
+
Exercise real filesystem and process behavior on Windows, Linux and macOS, using deterministic fake model responses at the DSH provider boundary. Tests cover concurrency limits, no-new and run budgets, elapsed time, cancellation, independent scopes, malformed results, denied tools and path escapes, process crash/restart, two competing owners, partial worker completion and target changes. Retain the existing export-race and artifact-compatibility suite. Test the actual DSH registries and activation interface in addition to the fake provider, and verify package contents and reproducible output. Run GitHub CI before a versioned GitHub release and attempt the npm release with the configured account.
|
package/lib/client.js
CHANGED
|
@@ -363,7 +363,12 @@ function Workbench() {
|
|
|
363
363
|
return () => { active = false; controller.abort(); };
|
|
364
364
|
}, [selectedId, reloadToken]);
|
|
365
365
|
const refresh = React.useCallback(() => { setActionError(null); setReloadToken(token => token + 1); }, []);
|
|
366
|
-
const selectScan = React.useCallback((scanId) => {
|
|
366
|
+
const selectScan = React.useCallback((scanId) => {
|
|
367
|
+
if (scanId === selectedId)
|
|
368
|
+
return;
|
|
369
|
+
setDetail(null);
|
|
370
|
+
setSelectedId(scanId);
|
|
371
|
+
}, [selectedId]);
|
|
367
372
|
const handleTriage = React.useCallback((scanId, findingId, nextStatus) => {
|
|
368
373
|
setBusyFindingId(findingId);
|
|
369
374
|
setActionError(null);
|
package/lib/constants.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export const PACKAGE_NAME = '@lornatang/dsh-codex-security';
|
|
2
2
|
export const PLUGIN_NAME = 'codex-security';
|
|
3
|
-
export const VERSION = '0.1.
|
|
3
|
+
export const VERSION = '0.1.13';
|
|
4
4
|
export const ROUTE_PREFIX = '/plugins/codex-security';
|
|
5
5
|
export const PRODUCER = { name: '@lornatang/dsh-codex-security', version: VERSION };
|
|
6
6
|
export const SKILL_NAMES = ['security-scan', 'security-diff-scan', 'deep-security-scan', 'fix-finding', 'verify-fix', 'triage-finding', 'threat-model', 'track-findings', 'resolve-dependency-alert', 'vulnerability-writeup', 'assess-patch-risk', 'attack-path-analysis', 'define-security-policy', 'finding-discovery', 'propose-security-hardening', 'validation'];
|
package/lib/deep-coordinator.js
CHANGED
|
@@ -6,7 +6,8 @@ import { assertWorkerSnapshotMatches, captureWorkerSnapshot } from './deep-worke
|
|
|
6
6
|
import { acquireStateLock } from './state-lock.js';
|
|
7
7
|
import { resolveTarget } from './target.js';
|
|
8
8
|
import { sourceRootIdentity } from './secure-read.js';
|
|
9
|
-
import {
|
|
9
|
+
import { newId, nowIso, readJson, sha256, writeJsonAtomic } from './util.js';
|
|
10
|
+
const RUN_PAYLOAD_KEYS = ['draft', 'receipts', 'findings', 'coverage', 'reviewState'];
|
|
10
11
|
const OUTPUT_SCHEMA = {
|
|
11
12
|
type: 'object', properties: { draftJson: { type: 'string', description: 'JSON object with findings and reviewState.' } },
|
|
12
13
|
required: ['draftJson'], additionalProperties: false,
|
|
@@ -33,10 +34,13 @@ export async function readDeepStatus(service, scanId, actor) {
|
|
|
33
34
|
if (!journal || journal.version !== 1 || journal.scanId !== scanId)
|
|
34
35
|
throw new Error('codex-security: Deep scan journal not found');
|
|
35
36
|
authorizeJournal(journal, actor);
|
|
37
|
+
const checkParent = journal.status === 'running' || journal.status === 'failed';
|
|
38
|
+
const parent = checkParent ? await service.store.get(scanId) : undefined;
|
|
39
|
+
const status = parent?.record.managedParent === scanId && parent.record.status === 'completed' ? 'completed' : journal.status;
|
|
36
40
|
return {
|
|
37
|
-
ok: true, scanId, status
|
|
41
|
+
ok: true, scanId, status, createdAt: journal.createdAt, deadline: new Date(journal.deadline).toISOString(),
|
|
38
42
|
budget: journal.budget, attempts: journal.runs.length, noNew: journal.noNew,
|
|
39
|
-
...(journal.stopReason ? { stopReason: journal.stopReason } : {}), ...(journal.error ? { error: journal.error } : {}),
|
|
43
|
+
...(journal.stopReason ? { stopReason: journal.stopReason } : {}), ...(journal.error && status !== 'completed' ? { error: journal.error } : {}),
|
|
40
44
|
availableFiles: Object.keys(journal.snapshot?.files ?? {}).length,
|
|
41
45
|
unavailableFiles: journal.snapshot?.unavailable?.length ?? 0,
|
|
42
46
|
runs: journal.runs.map((run) => ({ number: run.number, state: run.state, scanId: run.scanId,
|
|
@@ -69,49 +73,29 @@ export class DeepCoordinator {
|
|
|
69
73
|
cancelPath(scanId) { return join(this.service.store.stateDir, 'deep', scanId + '.cancel.json'); }
|
|
70
74
|
runSidecarDir(scanId) { return join(this.service.store.stateDir, 'deep', scanId + '.runs'); }
|
|
71
75
|
runSidecarPath(scanId, childId) { return join(this.runSidecarDir(scanId), childId + '.json'); }
|
|
72
|
-
|
|
73
|
-
/** Heavy per-worker results that no longer belong in the transition journal. */
|
|
74
|
-
runPayload(run) {
|
|
75
|
-
const payload = {};
|
|
76
|
-
if (run.draft !== undefined)
|
|
77
|
-
payload['draft'] = run.draft;
|
|
78
|
-
if (run.receipts !== undefined)
|
|
79
|
-
payload['receipts'] = run.receipts;
|
|
80
|
-
if (run.findings !== undefined)
|
|
81
|
-
payload['findings'] = run.findings;
|
|
82
|
-
if (run.coverage !== undefined)
|
|
83
|
-
payload['coverage'] = run.coverage;
|
|
84
|
-
if (run.reviewState !== undefined)
|
|
85
|
-
payload['reviewState'] = run.reviewState;
|
|
86
|
-
return payload;
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Journal transitions are written frequently. Keep only light run metadata in
|
|
90
|
-
* the journal and offload each worker's findings/coverage/receipts to a
|
|
91
|
-
* per-worker sidecar, written only when its payload actually changed.
|
|
92
|
-
*/
|
|
76
|
+
dirtyPayloads = new WeakSet();
|
|
93
77
|
async save(journal) {
|
|
94
|
-
if (journal.runs.some((run) => Object.keys(this.runPayload(run)).length > 0))
|
|
95
|
-
await ensureDir(this.runSidecarDir(journal.scanId));
|
|
96
78
|
for (const run of journal.runs) {
|
|
79
|
+
if (!this.dirtyPayloads.has(run))
|
|
80
|
+
continue;
|
|
97
81
|
if (!/^dcs_[a-f0-9]{24}$/.test(run.childId))
|
|
98
82
|
throw new Error('codex-security: invalid Deep worker id');
|
|
99
|
-
const payload =
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
if (this.sidecarHashes.get(cacheKey) === digest)
|
|
106
|
-
continue;
|
|
83
|
+
const payload = {};
|
|
84
|
+
for (const key of RUN_PAYLOAD_KEYS)
|
|
85
|
+
if (run[key] !== undefined)
|
|
86
|
+
payload[key] = run[key];
|
|
87
|
+
// A transition may reference the worker output only after the sidecar
|
|
88
|
+
// is on disk. An interrupted write leaves the prior transition replayable.
|
|
107
89
|
await writeJsonAtomic(this.runSidecarPath(journal.scanId, run.childId), payload);
|
|
108
|
-
|
|
90
|
+
run.hasPayload = true;
|
|
91
|
+
this.dirtyPayloads.delete(run);
|
|
109
92
|
}
|
|
110
93
|
const light = { ...journal, runs: journal.runs.map((run) => ({
|
|
111
94
|
number: run.number, childId: run.childId, scanId: run.scanId, state: run.state,
|
|
112
95
|
...(run.complete !== undefined ? { complete: run.complete } : {}),
|
|
113
96
|
...(run.error ? { error: run.error } : {}),
|
|
114
97
|
...(run.newCount !== undefined ? { newCount: run.newCount } : {}),
|
|
98
|
+
...(run.hasPayload ? { hasPayload: run.hasPayload } : {}),
|
|
115
99
|
})) };
|
|
116
100
|
await writeJsonAtomic(this.journalPath(journal.scanId), light);
|
|
117
101
|
}
|
|
@@ -121,20 +105,34 @@ export class DeepCoordinator {
|
|
|
121
105
|
const journal = await readJson(this.journalPath(scanId));
|
|
122
106
|
if (!journal || journal.version !== 1 || journal.scanId !== scanId)
|
|
123
107
|
throw new Error('codex-security: Deep scan journal not found');
|
|
108
|
+
return journal;
|
|
109
|
+
}
|
|
110
|
+
async restoreRunPayloads(journal, inlineOnly = false) {
|
|
124
111
|
for (const run of journal.runs) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
const payload = await readJson(this.runSidecarPath(scanId, run.childId)).catch(() => undefined);
|
|
130
|
-
if (!payload || typeof payload !== 'object')
|
|
112
|
+
const inline = RUN_PAYLOAD_KEYS.some((key) => run[key] !== undefined);
|
|
113
|
+
// A sidecar written before a crash is uncommitted if its run never
|
|
114
|
+
// advanced past 'started' in the journal.
|
|
115
|
+
if (!inline && (inlineOnly || (!run.hasPayload && (run.state === 'started' || run.state === 'abandoned'))))
|
|
131
116
|
continue;
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
117
|
+
if (!/^dcs_[a-f0-9]{24}$/.test(run.childId))
|
|
118
|
+
throw new Error('codex-security: invalid Deep worker id');
|
|
119
|
+
const payload = await readJson(this.runSidecarPath(journal.scanId, run.childId));
|
|
120
|
+
if (payload && typeof payload === 'object' && !Array.isArray(payload)) {
|
|
121
|
+
for (const key of RUN_PAYLOAD_KEYS) {
|
|
122
|
+
if (run[key] === undefined && payload[key] !== undefined)
|
|
123
|
+
run[key] = payload[key];
|
|
124
|
+
}
|
|
125
|
+
run.hasPayload = true;
|
|
126
|
+
}
|
|
127
|
+
else if (run.hasPayload && !inline) {
|
|
128
|
+
throw new Error('codex-security: Deep worker payload is missing: ' + run.childId);
|
|
135
129
|
}
|
|
130
|
+
if (!inlineOnly && !run.error && ((run.state === 'result' && (run.draft === undefined || !Array.isArray(run.receipts))) ||
|
|
131
|
+
(run.state === 'processed' && (!Array.isArray(run.findings) || !run.coverage))))
|
|
132
|
+
throw new Error('codex-security: Deep worker payload is incomplete: ' + run.childId);
|
|
133
|
+
if (inline)
|
|
134
|
+
this.dirtyPayloads.add(run);
|
|
136
135
|
}
|
|
137
|
-
return journal;
|
|
138
136
|
}
|
|
139
137
|
authorize(journal, actor, claim) {
|
|
140
138
|
authorizeJournal(journal, actor, claim);
|
|
@@ -205,6 +203,7 @@ export class DeepCoordinator {
|
|
|
205
203
|
this.authorize(journal, actor, args['recoveryClaim']);
|
|
206
204
|
if (journal.status !== 'running' && journal.status !== 'initializing')
|
|
207
205
|
throw new Error('codex-security: Deep scan is already ' + journal.status);
|
|
206
|
+
await this.restoreRunPayloads(journal);
|
|
208
207
|
this.launch(journal, actor, release);
|
|
209
208
|
started = true;
|
|
210
209
|
return { ok: true, scanId, status: 'running', resumed: true };
|
|
@@ -236,7 +235,9 @@ export class DeepCoordinator {
|
|
|
236
235
|
try {
|
|
237
236
|
const release = await acquireStateLock(this.lockPath(scanId), { timeoutMs: 0 });
|
|
238
237
|
try {
|
|
239
|
-
|
|
238
|
+
const journal = await this.read(scanId);
|
|
239
|
+
await this.restoreRunPayloads(journal, true);
|
|
240
|
+
await this.cancelOwned(journal);
|
|
240
241
|
}
|
|
241
242
|
finally {
|
|
242
243
|
release();
|
|
@@ -312,12 +313,18 @@ export class DeepCoordinator {
|
|
|
312
313
|
await this.save(journal);
|
|
313
314
|
}
|
|
314
315
|
async failOwned(journal, error) {
|
|
315
|
-
journal.status = 'failed';
|
|
316
|
-
journal.error = errorText(error);
|
|
317
316
|
const scan = await this.service.store.get(journal.scanId);
|
|
318
|
-
if (scan?.record.status === '
|
|
319
|
-
|
|
320
|
-
|
|
317
|
+
if (scan?.record.managedParent === journal.scanId && scan.record.status === 'completed') {
|
|
318
|
+
journal.status = 'completed';
|
|
319
|
+
delete journal.error;
|
|
320
|
+
}
|
|
321
|
+
else {
|
|
322
|
+
journal.status = 'failed';
|
|
323
|
+
journal.error = errorText(error);
|
|
324
|
+
if (scan?.record.status === 'running') {
|
|
325
|
+
const args = { scanId: journal.scanId, error: journal.error };
|
|
326
|
+
await this.managed(args, () => this.service.failScan(args));
|
|
327
|
+
}
|
|
321
328
|
}
|
|
322
329
|
await this.save(journal);
|
|
323
330
|
}
|
|
@@ -388,7 +395,8 @@ export class DeepCoordinator {
|
|
|
388
395
|
await Promise.race([activation.dispose().catch(() => undefined), delay(5000, undefined, { ref: false })]).catch(() => undefined);
|
|
389
396
|
}
|
|
390
397
|
}
|
|
391
|
-
async processResult(journal, run,
|
|
398
|
+
async processResult(journal, run, controller) {
|
|
399
|
+
const { signal } = controller;
|
|
392
400
|
signal.throwIfAborted();
|
|
393
401
|
if (run.error || !run.draft || !run.receipts) {
|
|
394
402
|
run.error ??= 'worker returned no complete result';
|
|
@@ -397,6 +405,7 @@ export class DeepCoordinator {
|
|
|
397
405
|
}
|
|
398
406
|
const snapshot = journal.snapshot;
|
|
399
407
|
const draft = validateDraft(run.draft);
|
|
408
|
+
this.dirtyPayloads.add(run);
|
|
400
409
|
run.reviewState = draft.reviewState;
|
|
401
410
|
const receipts = new Set(run.receipts);
|
|
402
411
|
for (const finding of draft.findings) {
|
|
@@ -435,7 +444,21 @@ export class DeepCoordinator {
|
|
|
435
444
|
await this.managed(childDraft, () => this.service.recordScanDraft(childDraft, { workerSnapshot: snapshot, signal }));
|
|
436
445
|
const completeArgs = { scanId: run.scanId };
|
|
437
446
|
signal.throwIfAborted();
|
|
438
|
-
await this.managed(completeArgs, () => this.service.completeScan(completeArgs, {
|
|
447
|
+
await this.managed(completeArgs, () => this.service.completeScan(completeArgs, {
|
|
448
|
+
signal,
|
|
449
|
+
withPublication: async (publish) => {
|
|
450
|
+
const release = await acquireStateLock(this.transitionPath(journal.scanId), { signal });
|
|
451
|
+
try {
|
|
452
|
+
if (await readJson(this.cancelPath(journal.scanId)))
|
|
453
|
+
controller.abort(new Error('Deep scan canceled'));
|
|
454
|
+
signal.throwIfAborted();
|
|
455
|
+
await publish();
|
|
456
|
+
}
|
|
457
|
+
finally {
|
|
458
|
+
release();
|
|
459
|
+
}
|
|
460
|
+
},
|
|
461
|
+
}));
|
|
439
462
|
}
|
|
440
463
|
else if (child.record.status !== 'completed')
|
|
441
464
|
throw new Error('codex-security: worker child scan is ' + child.record.status);
|
|
@@ -598,7 +621,7 @@ export class DeepCoordinator {
|
|
|
598
621
|
}
|
|
599
622
|
if (run.state === 'result') {
|
|
600
623
|
try {
|
|
601
|
-
await this.processResult(journal, run, controller
|
|
624
|
+
await this.processResult(journal, run, controller);
|
|
602
625
|
}
|
|
603
626
|
catch (error) {
|
|
604
627
|
await this.processFailure(journal, run, error, controller);
|
|
@@ -623,10 +646,12 @@ export class DeepCoordinator {
|
|
|
623
646
|
const next = inflight.shift();
|
|
624
647
|
const result = await next.result;
|
|
625
648
|
Object.assign(next.run, result);
|
|
649
|
+
if (result.draft !== undefined)
|
|
650
|
+
this.dirtyPayloads.add(next.run);
|
|
626
651
|
next.run.state = 'result';
|
|
627
652
|
await this.save(journal);
|
|
628
653
|
try {
|
|
629
|
-
await this.processResult(journal, next.run, controller
|
|
654
|
+
await this.processResult(journal, next.run, controller);
|
|
630
655
|
}
|
|
631
656
|
catch (error) {
|
|
632
657
|
await this.processFailure(journal, next.run, error, controller);
|