@deksden-com/dd-flow-cli 0.9.0-beta.13 → 0.9.0-beta.133
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 +666 -0
- package/README.md +101 -1
- package/dist/build-info.json +10 -10
- package/dist/cli/argument-values.js +38 -0
- package/dist/cli/command-inputs.js +306 -0
- package/dist/cli/help.js +88 -12
- package/dist/cli/hook-ingress.js +78 -0
- package/dist/cli/input-preparation.js +116 -0
- package/dist/cli/native-hook-ingress.js +80 -0
- package/dist/cli/run-cli.js +1465 -450
- package/dist/cli/runtime-maintenance-diagnostics.js +46 -0
- package/dist/cli/runtime-maintenance-ingress.js +52 -0
- package/dist/cli/runtime-process.js +153 -0
- package/dist/cli.js +17 -2
- package/dist/domain/stage-catalog.js +1 -1
- package/dist/harness-runtime/DD-ZCODE.md +99 -0
- package/dist/harness-runtime/bin/dd-agy.mjs +56 -0
- package/dist/harness-runtime/bin/dd-codex.mjs +27 -0
- package/dist/harness-runtime/bin/dd-droid.mjs +34 -0
- package/dist/harness-runtime/bin/dd-grok.mjs +40 -0
- package/dist/harness-runtime/bin/dd-opencode.mjs +22 -0
- package/dist/harness-runtime/bin/dd-zcode.mjs +87 -0
- package/dist/harness-runtime/lib/adapter-timeouts.d.mts +5 -0
- package/dist/harness-runtime/lib/adapter-timeouts.mjs +34 -0
- package/dist/harness-runtime/lib/agy-hooks.d.mts +1 -0
- package/dist/harness-runtime/lib/agy-hooks.mjs +9 -0
- package/dist/harness-runtime/lib/codex-capacity-policy.d.mts +10 -0
- package/dist/harness-runtime/lib/codex-capacity-policy.mjs +89 -0
- package/dist/harness-runtime/lib/daemon-observation.d.mts +2 -0
- package/dist/harness-runtime/lib/daemon-observation.mjs +163 -0
- package/dist/harness-runtime/lib/daemon-operations.mjs +370 -0
- package/dist/harness-runtime/lib/dd-agy-daemon.d.mts +6 -0
- package/dist/harness-runtime/lib/dd-agy-daemon.mjs +693 -0
- package/dist/harness-runtime/lib/dd-agy.mjs +59 -0
- package/dist/harness-runtime/lib/dd-codex-daemon.d.mts +1 -0
- package/dist/harness-runtime/lib/dd-codex-daemon.mjs +190 -0
- package/dist/harness-runtime/lib/dd-codex.d.mts +1 -0
- package/dist/harness-runtime/lib/dd-codex.mjs +805 -0
- package/dist/harness-runtime/lib/dd-droid-daemon.mjs +128 -0
- package/dist/harness-runtime/lib/dd-droid.mjs +561 -0
- package/dist/harness-runtime/lib/dd-grok-daemon.mjs +490 -0
- package/dist/harness-runtime/lib/dd-grok.mjs +177 -0
- package/dist/harness-runtime/lib/dd-opencode-daemon.mjs +255 -0
- package/dist/harness-runtime/lib/dd-opencode.mjs +128 -0
- package/dist/harness-runtime/lib/dd-zcode-daemon.mjs +703 -0
- package/dist/harness-runtime/lib/dd-zcode.mjs +1108 -0
- package/dist/harness-runtime/lib/delegation-instructions.d.mts +13 -0
- package/dist/harness-runtime/lib/delegation-instructions.mjs +144 -0
- package/dist/harness-runtime/lib/dispatch-fence.mjs +14 -0
- package/dist/harness-runtime/lib/driver-recovery.mjs +139 -0
- package/dist/harness-runtime/lib/droid-observation.mjs +66 -0
- package/dist/harness-runtime/lib/lease-renewal.d.mts +8 -0
- package/dist/harness-runtime/lib/lease-renewal.mjs +36 -0
- package/dist/harness-runtime/lib/lifecycle-command.d.mts +20 -0
- package/dist/harness-runtime/lib/lifecycle-command.mjs +272 -0
- package/dist/harness-runtime/lib/lifecycle-contract.d.mts +10 -0
- package/dist/harness-runtime/lib/lifecycle-contract.mjs +19 -0
- package/dist/harness-runtime/lib/managed-daemon.d.mts +12 -0
- package/dist/harness-runtime/lib/managed-daemon.mjs +619 -0
- package/dist/harness-runtime/lib/model-observations.mjs +101 -0
- package/dist/harness-runtime/lib/native-children.d.mts +13 -0
- package/dist/harness-runtime/lib/native-children.mjs +78 -0
- package/dist/harness-runtime/lib/native-hook-command.d.mts +7 -0
- package/dist/harness-runtime/lib/native-hook-command.mjs +251 -0
- package/dist/harness-runtime/lib/native-streams.mjs +45 -0
- package/dist/harness-runtime/lib/observation-clock.d.mts +18 -0
- package/dist/harness-runtime/lib/observation-clock.mjs +92 -0
- package/dist/harness-runtime/lib/operation-context.mjs +5 -0
- package/dist/harness-runtime/lib/operation-errors.d.mts +14 -0
- package/dist/harness-runtime/lib/operation-errors.mjs +116 -0
- package/dist/harness-runtime/lib/operation-progress.d.mts +7 -0
- package/dist/harness-runtime/lib/operation-progress.mjs +112 -0
- package/dist/harness-runtime/lib/process-json.d.mts +5 -0
- package/dist/harness-runtime/lib/process-json.mjs +201 -0
- package/dist/harness-runtime/lib/process-snapshot.mjs +10 -0
- package/dist/harness-runtime/lib/runner-events.mjs +200 -0
- package/dist/harness-runtime/lib/runner-lock.mjs +42 -0
- package/dist/harness-runtime/lib/session-settlement.mjs +30 -0
- package/dist/harness-runtime/lib/setup-progress.d.mts +9 -0
- package/dist/harness-runtime/lib/setup-progress.mjs +51 -0
- package/dist/harness-runtime/lib/tool-observations.d.mts +21 -0
- package/dist/harness-runtime/lib/tool-observations.mjs +228 -0
- package/dist/harness-runtime/lib/zcode-usage.mjs +55 -0
- package/dist/protocol/local-files.js +18 -9
- package/dist/runtime/context.js +8 -4
- package/dist/schemas/agent-profile.schema.json +1 -1
- package/dist/schemas/code-review-result.schema.json +1 -1
- package/dist/schemas/code-verification.schema.json +7 -5
- package/dist/schemas/code-work-batch.schema.json +2 -2
- package/dist/schemas/flow-run.schema.json +2 -0
- package/dist/schemas/plan-review-decision.schema.json +3 -3
- package/dist/schemas/plan-review-result.schema.json +2 -2
- package/dist/schemas/run-control-receipt.schema.json +118 -0
- package/dist/schemas/run-control-request.schema.json +36 -0
- package/dist/schemas/vnext-protocol-plan.schema.json +2 -2
- package/dist/services/branch-context.js +3 -3
- package/dist/services/canon.js +11 -8
- package/dist/services/check-runner-evidence.js +121 -0
- package/dist/services/cleanup.js +133 -40
- package/dist/services/cli-operation-classifier.js +22 -24
- package/dist/services/code-checks.js +851 -109
- package/dist/services/codex-capacity.js +367 -0
- package/dist/services/codex-hook-delivery.js +32 -0
- package/dist/services/command-context.js +80 -0
- package/dist/services/compatibility-preflight.js +13 -3
- package/dist/services/config.js +11 -8
- package/dist/services/continuation-outcome.js +20 -0
- package/dist/services/controller-fanout.js +119 -0
- package/dist/services/dashboard.js +135 -56
- package/dist/services/engines.js +245 -119
- package/dist/services/eval-snapshots.js +1146 -105
- package/dist/services/execution-policy.js +181 -0
- package/dist/services/external-work-launch.js +230 -0
- package/dist/services/harness-adapter.js +329 -36
- package/dist/services/harness-config.js +2 -0
- package/dist/services/hooks.js +747 -325
- package/dist/services/lanes.js +78 -65
- package/dist/services/lifecycle-command.js +1 -288
- package/dist/services/lifecycle-contract.js +1 -0
- package/dist/services/lifecycle-invocations.js +1774 -0
- package/dist/services/managed-daemon-binding.js +38 -0
- package/dist/services/managed-lease-monitor.js +133 -0
- package/dist/services/managed-processes.js +409 -51
- package/dist/services/merge-queue.js +228 -149
- package/dist/services/merge-server.js +163 -35
- package/dist/services/migrations.js +37 -16
- package/dist/services/native-daemon-history.js +49 -0
- package/dist/services/native-session-control.js +39 -0
- package/dist/services/plan-runtime.js +26 -11
- package/dist/services/plans.js +28 -25
- package/dist/services/projects.js +20 -15
- package/dist/services/prompts.js +28 -17
- package/dist/services/protocols.js +163 -87
- package/dist/services/recovery-observation-budget.js +121 -0
- package/dist/services/recovery-snapshot-database.js +145 -0
- package/dist/services/repair-intents.js +42 -0
- package/dist/services/review-copy.js +157 -0
- package/dist/services/review-deferral.js +23 -0
- package/dist/services/run-control-receipt.js +56 -0
- package/dist/services/run-control-worker.js +411 -0
- package/dist/services/run-control.js +985 -0
- package/dist/services/run-controller-adapter.js +399 -0
- package/dist/services/run-controller-capture.js +179 -0
- package/dist/services/run-controller-process.js +187 -0
- package/dist/services/run-controller-recovery.js +289 -0
- package/dist/services/run-controller-state.js +97 -0
- package/dist/services/run-controller.js +1035 -0
- package/dist/services/run-engine-bindings.js +1 -1
- package/dist/services/run-fork.js +147 -0
- package/dist/services/run-observations.js +152 -0
- package/dist/services/run-projection.js +22 -64
- package/dist/services/run-recovery-guard.js +75 -0
- package/dist/services/run-recovery-runtime.js +112 -0
- package/dist/services/run-recovery.js +349 -0
- package/dist/services/runs.js +558 -217
- package/dist/services/runtime-budget.js +430 -0
- package/dist/services/runtime-command.js +43 -0
- package/dist/services/runtime-scope-capture.js +52 -0
- package/dist/services/runtime-scope-control.js +468 -0
- package/dist/services/runtime-scope-resume.js +599 -0
- package/dist/services/runtime-scope-stop.js +180 -0
- package/dist/services/runtime-scope-worker.js +287 -0
- package/dist/services/runtime-service.js +96 -0
- package/dist/services/schema-validation.js +10 -8
- package/dist/services/scope-writer-cleanup.js +27 -0
- package/dist/services/sessions.js +35 -69
- package/dist/services/stage-blocker.js +17 -7
- package/dist/services/stage-context.js +185 -19
- package/dist/services/stage-lifecycle.js +98 -107
- package/dist/services/stage-pause.js +89 -75
- package/dist/services/stage-report-renderer.js +158 -6
- package/dist/services/stage-work-graph.js +35 -0
- package/dist/services/tooling.js +32 -23
- package/dist/services/usage.js +49 -101
- package/dist/services/verification-matrix.js +374 -0
- package/dist/services/vnext-code-review.js +222 -87
- package/dist/services/vnext-code.js +324 -251
- package/dist/services/vnext-contracts.js +10 -1
- package/dist/services/vnext-execution-profile.js +79 -4
- package/dist/services/vnext-fanout.js +177 -17
- package/dist/services/vnext-merge.js +335 -113
- package/dist/services/vnext-plan-review.js +276 -126
- package/dist/services/vnext-plan.js +227 -102
- package/dist/services/vnext-protocolize.js +335 -82
- package/dist/services/vnext-specify.js +119 -81
- package/dist/services/work-registry.js +1038 -192
- package/dist/services/workspace-bootstrap.js +87 -0
- package/dist/services/workspace-files.js +85 -0
- package/dist/services/worktrees.js +98 -44
- package/dist/shared/entity-references.js +8 -0
- package/dist/shared/errors.js +17 -0
- package/dist/storage/agent-output.js +26 -0
- package/dist/storage/database.js +781 -37
- package/dist/storage/foreign-key-transaction.js +39 -0
- package/dist/storage/immutable-input.js +45 -0
- package/dist/storage/import-guard.js +102 -0
- package/dist/storage/native-cleanup.js +52 -0
- package/dist/storage/paths.js +17 -4
- package/dist/storage/projection-lock.js +73 -0
- package/dist/storage/work-references.js +23 -0
- package/dist/storage/writer-contract.js +77 -0
- package/dist/storage/writer-migration.js +85 -0
- package/package.json +30 -13
- package/tools/repair-paused-run-status.mjs +84 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { AppError } from "../shared/errors.js";
|
|
4
|
+
import { managedProcessRuntimeHome, managedProcessStatus } from "./managed-processes.js";
|
|
5
|
+
export function readNativeDaemonState(stateDir) {
|
|
6
|
+
if (!path.isAbsolute(stateDir))
|
|
7
|
+
throw new AppError("daemon_owner_mismatch", "Native state directory must be absolute", 1);
|
|
8
|
+
return JSON.parse(fs.readFileSync(path.join(stateDir, "daemon.json"), "utf8"));
|
|
9
|
+
}
|
|
10
|
+
/** A shared directory or logical owner is not a physical provider binding. */
|
|
11
|
+
export function managedProviderBelongsToDaemon(provider, daemon, state) {
|
|
12
|
+
const child = JSON.parse(provider.metadata_json), parent = JSON.parse(daemon.metadata_json);
|
|
13
|
+
return provider.kind === daemon.kind.replace(/-daemon$/, "-provider")
|
|
14
|
+
&& state.provider_process?.id === provider.id && state.provider_process.lease_token === provider.lease_token
|
|
15
|
+
&& Boolean(provider.pid && provider.pid_started_at && daemon.pid && daemon.pid_started_at)
|
|
16
|
+
&& state.provider_pid === provider.pid && child.owner_pid === daemon.pid && child.owner_pid_started_at === daemon.pid_started_at
|
|
17
|
+
&& provider.owner_id === daemon.owner_id && provider.project_id === daemon.project_id && provider.run_id === daemon.run_id && provider.work_id === daemon.work_id
|
|
18
|
+
&& child.state_dir === parent.state_dir && child.role === parent.role && child.dd_flow_home === parent.dd_flow_home && child.adapter_executable === parent.adapter_executable
|
|
19
|
+
&& child.dispatch_barrier === "run-generation@1" && child.budget?.scope_id === parent.budget?.scope_id;
|
|
20
|
+
}
|
|
21
|
+
/** Identity proof only. Liveness and clean shutdown are separate caller decisions. */
|
|
22
|
+
export function requireManagedDaemonBinding(context, input) {
|
|
23
|
+
const state = readNativeDaemonState(input.stateDir);
|
|
24
|
+
const owner = state.config?.runtime_owner;
|
|
25
|
+
const record = managedProcessStatus(context).find(record => record.id === state.resource_process?.id);
|
|
26
|
+
const metadata = record && JSON.parse(record.metadata_json);
|
|
27
|
+
if (!record || !owner || !record.kind.endsWith("-daemon")
|
|
28
|
+
|| record.lease_token !== state.resource_process?.lease_token
|
|
29
|
+
|| !record.pid || record.pid !== state.pid || !record.pid_started_at
|
|
30
|
+
|| record.owner_id !== owner.owner_id || input.ownerId !== undefined && record.owner_id !== input.ownerId
|
|
31
|
+
|| record.project_id !== input.projectId || owner.project_id !== input.projectId
|
|
32
|
+
|| record.run_id !== input.runId || owner.run_id !== input.runId
|
|
33
|
+
|| metadata?.state_dir !== input.stateDir || owner.state_dir !== input.stateDir
|
|
34
|
+
|| owner.dd_flow_home !== context.ddFlowHome || managedProcessRuntimeHome(record, context) !== context.ddFlowHome) {
|
|
35
|
+
throw new AppError("daemon_owner_mismatch", "Native daemon has no proven physical ownership in this RUN and runtime home", 1);
|
|
36
|
+
}
|
|
37
|
+
return { state, process: record };
|
|
38
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
2
|
+
import { AppError } from "../shared/errors.js";
|
|
3
|
+
import { createRenewalState, maintenanceRetryable, renewalConfirmed, renewalDelay, renewalFailure, renewalRemaining, RENEWAL_POLICY } from "../harness-runtime/lib/lease-renewal.mjs";
|
|
4
|
+
/** Registry renewals happen outside RUN writers. Assertions never renew. */
|
|
5
|
+
export function managedLeaseMonitor(renew, leaseExpiresAt = null) {
|
|
6
|
+
const episode = createRenewalState({ leaseExpiresAt });
|
|
7
|
+
let expiry = 0;
|
|
8
|
+
let failure = null;
|
|
9
|
+
let lost = false;
|
|
10
|
+
let fatal = null;
|
|
11
|
+
let closing = false;
|
|
12
|
+
let pending;
|
|
13
|
+
const shutdown = new AbortController();
|
|
14
|
+
const retainAuthority = (leaseExpiresAt) => {
|
|
15
|
+
if (!renewalConfirmed(episode, performance.now(), leaseExpiresAt))
|
|
16
|
+
throw new AppError("managed_lease_receipt_invalid", "Confirmation has no current persisted expiry", 1);
|
|
17
|
+
expiry = Date.parse(leaseExpiresAt);
|
|
18
|
+
};
|
|
19
|
+
const uncertain = () => new AppError("controller_lease_unconfirmed", "Managed lease requires confirmation outside the writer", 1, { cause: failure, exhausted: episode.exhausted, closing });
|
|
20
|
+
const assertNoRenewal = () => {
|
|
21
|
+
if (closing)
|
|
22
|
+
throw uncertain();
|
|
23
|
+
if (fatal)
|
|
24
|
+
throw fatal;
|
|
25
|
+
if (lost)
|
|
26
|
+
throw new AppError("controller_lease_lost", "Managed owner was replaced or retired", 1);
|
|
27
|
+
if (failure || Date.now() >= expiry)
|
|
28
|
+
throw uncertain();
|
|
29
|
+
};
|
|
30
|
+
const tick = () => {
|
|
31
|
+
if (closing)
|
|
32
|
+
throw uncertain();
|
|
33
|
+
if (fatal)
|
|
34
|
+
throw fatal;
|
|
35
|
+
if (lost || failure && !renewalRemaining(episode) || episode.exhausted)
|
|
36
|
+
return;
|
|
37
|
+
try {
|
|
38
|
+
episode.uncertainSince ??= performance.now();
|
|
39
|
+
const remaining = renewalRemaining(episode);
|
|
40
|
+
if (!remaining) {
|
|
41
|
+
failure = uncertain();
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const receipt = renew(Math.min(RENEWAL_POLICY.attemptMs, remaining));
|
|
45
|
+
if (!receipt.owned) {
|
|
46
|
+
lost = true;
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const value = Date.parse(receipt.lease_expires_at);
|
|
50
|
+
if (!Number.isFinite(value))
|
|
51
|
+
throw new AppError("managed_lease_receipt_invalid", "Renewal has no valid persisted expiry", 1);
|
|
52
|
+
if (value <= Date.now())
|
|
53
|
+
throw new AppError("controller_lease_unconfirmed", "Renewal receipt has already expired", 1);
|
|
54
|
+
if (renewalConfirmed(episode, performance.now(), receipt.lease_expires_at)) {
|
|
55
|
+
expiry = value;
|
|
56
|
+
failure = null;
|
|
57
|
+
}
|
|
58
|
+
else
|
|
59
|
+
failure = uncertain();
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
failure = error;
|
|
63
|
+
if (maintenanceRetryable(error) || error instanceof AppError && error.code === "controller_lease_unconfirmed")
|
|
64
|
+
renewalFailure(episode);
|
|
65
|
+
else {
|
|
66
|
+
fatal = error;
|
|
67
|
+
throw error;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
const assertConfirmed = () => { tick(); assertNoRenewal(); };
|
|
72
|
+
const runConfirmation = async (assertCurrent) => {
|
|
73
|
+
for (;;) {
|
|
74
|
+
if (closing)
|
|
75
|
+
throw uncertain();
|
|
76
|
+
assertCurrent();
|
|
77
|
+
tick();
|
|
78
|
+
try {
|
|
79
|
+
assertNoRenewal();
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
if (lost || episode.exhausted || !renewalRemaining(episode))
|
|
84
|
+
throw error;
|
|
85
|
+
try {
|
|
86
|
+
await delay(Math.min(renewalDelay(episode), renewalRemaining(episode)), undefined, { signal: shutdown.signal });
|
|
87
|
+
}
|
|
88
|
+
catch (cause) {
|
|
89
|
+
if (closing)
|
|
90
|
+
throw uncertain();
|
|
91
|
+
throw cause;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
const ensureConfirmed = async (assertCurrent = () => { }) => {
|
|
97
|
+
if (closing)
|
|
98
|
+
throw uncertain();
|
|
99
|
+
if (pending)
|
|
100
|
+
assertCurrent();
|
|
101
|
+
pending ??= runConfirmation(assertCurrent).finally(() => { pending = undefined; });
|
|
102
|
+
await pending;
|
|
103
|
+
if (closing)
|
|
104
|
+
throw uncertain();
|
|
105
|
+
assertCurrent();
|
|
106
|
+
assertNoRenewal();
|
|
107
|
+
};
|
|
108
|
+
const background = (assertCurrent, onFailure, onConfirmed = () => { }) => {
|
|
109
|
+
void ensureConfirmed(assertCurrent).then(() => {
|
|
110
|
+
if (closing)
|
|
111
|
+
return;
|
|
112
|
+
try {
|
|
113
|
+
onConfirmed();
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
fatal = failure = error;
|
|
117
|
+
throw error;
|
|
118
|
+
}
|
|
119
|
+
}).catch(error => {
|
|
120
|
+
if (closing)
|
|
121
|
+
return;
|
|
122
|
+
try {
|
|
123
|
+
onFailure(error);
|
|
124
|
+
}
|
|
125
|
+
catch (reporting) {
|
|
126
|
+
fatal = failure = reporting;
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
};
|
|
130
|
+
return { tick, assertNoRenewal, assertConfirmed, ensureConfirmed, background, retainAuthority,
|
|
131
|
+
close: () => { closing = true; shutdown.abort(); },
|
|
132
|
+
isConfirmed: () => !closing && !lost && !failure && Date.now() < expiry };
|
|
133
|
+
}
|