@deksden-com/dd-flow-cli 0.9.0-beta.13 → 0.9.0-beta.134

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.
Files changed (204) hide show
  1. package/CHANGELOG.md +687 -0
  2. package/README.md +101 -1
  3. package/dist/build-info.json +10 -10
  4. package/dist/cli/argument-values.js +38 -0
  5. package/dist/cli/command-inputs.js +306 -0
  6. package/dist/cli/help.js +88 -12
  7. package/dist/cli/hook-ingress.js +78 -0
  8. package/dist/cli/input-preparation.js +116 -0
  9. package/dist/cli/native-hook-ingress.js +80 -0
  10. package/dist/cli/run-cli.js +1465 -450
  11. package/dist/cli/runtime-maintenance-diagnostics.js +46 -0
  12. package/dist/cli/runtime-maintenance-ingress.js +52 -0
  13. package/dist/cli/runtime-process.js +153 -0
  14. package/dist/cli.js +17 -2
  15. package/dist/domain/stage-catalog.js +1 -1
  16. package/dist/harness-runtime/DD-ZCODE.md +99 -0
  17. package/dist/harness-runtime/bin/dd-agy.mjs +56 -0
  18. package/dist/harness-runtime/bin/dd-codex.mjs +27 -0
  19. package/dist/harness-runtime/bin/dd-droid.mjs +34 -0
  20. package/dist/harness-runtime/bin/dd-grok.mjs +40 -0
  21. package/dist/harness-runtime/bin/dd-opencode.mjs +22 -0
  22. package/dist/harness-runtime/bin/dd-zcode.mjs +87 -0
  23. package/dist/harness-runtime/lib/adapter-timeouts.d.mts +5 -0
  24. package/dist/harness-runtime/lib/adapter-timeouts.mjs +34 -0
  25. package/dist/harness-runtime/lib/agy-hooks.d.mts +1 -0
  26. package/dist/harness-runtime/lib/agy-hooks.mjs +9 -0
  27. package/dist/harness-runtime/lib/codex-capacity-policy.d.mts +10 -0
  28. package/dist/harness-runtime/lib/codex-capacity-policy.mjs +89 -0
  29. package/dist/harness-runtime/lib/daemon-observation.d.mts +2 -0
  30. package/dist/harness-runtime/lib/daemon-observation.mjs +163 -0
  31. package/dist/harness-runtime/lib/daemon-operations.mjs +370 -0
  32. package/dist/harness-runtime/lib/dd-agy-daemon.d.mts +6 -0
  33. package/dist/harness-runtime/lib/dd-agy-daemon.mjs +693 -0
  34. package/dist/harness-runtime/lib/dd-agy.mjs +59 -0
  35. package/dist/harness-runtime/lib/dd-codex-daemon.d.mts +1 -0
  36. package/dist/harness-runtime/lib/dd-codex-daemon.mjs +190 -0
  37. package/dist/harness-runtime/lib/dd-codex.d.mts +1 -0
  38. package/dist/harness-runtime/lib/dd-codex.mjs +805 -0
  39. package/dist/harness-runtime/lib/dd-droid-daemon.mjs +128 -0
  40. package/dist/harness-runtime/lib/dd-droid.mjs +561 -0
  41. package/dist/harness-runtime/lib/dd-grok-daemon.mjs +490 -0
  42. package/dist/harness-runtime/lib/dd-grok.mjs +177 -0
  43. package/dist/harness-runtime/lib/dd-opencode-daemon.mjs +255 -0
  44. package/dist/harness-runtime/lib/dd-opencode.mjs +128 -0
  45. package/dist/harness-runtime/lib/dd-zcode-daemon.mjs +703 -0
  46. package/dist/harness-runtime/lib/dd-zcode.mjs +1128 -0
  47. package/dist/harness-runtime/lib/delegation-instructions.d.mts +13 -0
  48. package/dist/harness-runtime/lib/delegation-instructions.mjs +144 -0
  49. package/dist/harness-runtime/lib/dispatch-fence.mjs +14 -0
  50. package/dist/harness-runtime/lib/driver-recovery.mjs +139 -0
  51. package/dist/harness-runtime/lib/droid-observation.mjs +66 -0
  52. package/dist/harness-runtime/lib/lease-renewal.d.mts +8 -0
  53. package/dist/harness-runtime/lib/lease-renewal.mjs +36 -0
  54. package/dist/harness-runtime/lib/lifecycle-command.d.mts +20 -0
  55. package/dist/harness-runtime/lib/lifecycle-command.mjs +272 -0
  56. package/dist/harness-runtime/lib/lifecycle-contract.d.mts +10 -0
  57. package/dist/harness-runtime/lib/lifecycle-contract.mjs +19 -0
  58. package/dist/harness-runtime/lib/managed-daemon.d.mts +12 -0
  59. package/dist/harness-runtime/lib/managed-daemon.mjs +619 -0
  60. package/dist/harness-runtime/lib/model-observations.mjs +101 -0
  61. package/dist/harness-runtime/lib/native-children.d.mts +14 -0
  62. package/dist/harness-runtime/lib/native-children.mjs +94 -0
  63. package/dist/harness-runtime/lib/native-hook-command.d.mts +7 -0
  64. package/dist/harness-runtime/lib/native-hook-command.mjs +251 -0
  65. package/dist/harness-runtime/lib/native-streams.mjs +45 -0
  66. package/dist/harness-runtime/lib/observation-clock.d.mts +18 -0
  67. package/dist/harness-runtime/lib/observation-clock.mjs +92 -0
  68. package/dist/harness-runtime/lib/operation-context.mjs +5 -0
  69. package/dist/harness-runtime/lib/operation-errors.d.mts +14 -0
  70. package/dist/harness-runtime/lib/operation-errors.mjs +116 -0
  71. package/dist/harness-runtime/lib/operation-progress.d.mts +7 -0
  72. package/dist/harness-runtime/lib/operation-progress.mjs +112 -0
  73. package/dist/harness-runtime/lib/process-json.d.mts +5 -0
  74. package/dist/harness-runtime/lib/process-json.mjs +201 -0
  75. package/dist/harness-runtime/lib/process-snapshot.mjs +10 -0
  76. package/dist/harness-runtime/lib/runner-events.mjs +200 -0
  77. package/dist/harness-runtime/lib/runner-lock.mjs +42 -0
  78. package/dist/harness-runtime/lib/session-settlement.mjs +30 -0
  79. package/dist/harness-runtime/lib/setup-progress.d.mts +9 -0
  80. package/dist/harness-runtime/lib/setup-progress.mjs +51 -0
  81. package/dist/harness-runtime/lib/tool-observations.d.mts +21 -0
  82. package/dist/harness-runtime/lib/tool-observations.mjs +228 -0
  83. package/dist/harness-runtime/lib/zcode-usage.mjs +55 -0
  84. package/dist/protocol/local-files.js +18 -9
  85. package/dist/runtime/context.js +8 -4
  86. package/dist/schemas/agent-profile.schema.json +1 -1
  87. package/dist/schemas/code-review-result.schema.json +1 -1
  88. package/dist/schemas/code-verification.schema.json +7 -5
  89. package/dist/schemas/code-work-batch.schema.json +2 -2
  90. package/dist/schemas/flow-run.schema.json +2 -0
  91. package/dist/schemas/plan-review-decision.schema.json +3 -3
  92. package/dist/schemas/plan-review-result.schema.json +2 -2
  93. package/dist/schemas/run-control-receipt.schema.json +118 -0
  94. package/dist/schemas/run-control-request.schema.json +36 -0
  95. package/dist/schemas/vnext-protocol-plan.schema.json +2 -2
  96. package/dist/services/branch-context.js +3 -3
  97. package/dist/services/canon.js +11 -8
  98. package/dist/services/check-runner-evidence.js +121 -0
  99. package/dist/services/cleanup.js +133 -40
  100. package/dist/services/cli-operation-classifier.js +22 -24
  101. package/dist/services/code-checks.js +851 -109
  102. package/dist/services/codex-capacity.js +367 -0
  103. package/dist/services/codex-hook-delivery.js +32 -0
  104. package/dist/services/command-context.js +80 -0
  105. package/dist/services/compatibility-preflight.js +13 -3
  106. package/dist/services/config.js +11 -8
  107. package/dist/services/continuation-outcome.js +20 -0
  108. package/dist/services/controller-fanout.js +136 -0
  109. package/dist/services/dashboard.js +135 -56
  110. package/dist/services/engines.js +245 -119
  111. package/dist/services/eval-snapshots.js +1146 -105
  112. package/dist/services/execution-policy.js +181 -0
  113. package/dist/services/external-work-launch.js +230 -0
  114. package/dist/services/harness-adapter.js +329 -36
  115. package/dist/services/harness-config.js +2 -0
  116. package/dist/services/hooks.js +753 -325
  117. package/dist/services/lanes.js +78 -65
  118. package/dist/services/lifecycle-command.js +1 -288
  119. package/dist/services/lifecycle-contract.js +1 -0
  120. package/dist/services/lifecycle-invocations.js +1828 -0
  121. package/dist/services/managed-daemon-binding.js +38 -0
  122. package/dist/services/managed-lease-monitor.js +133 -0
  123. package/dist/services/managed-processes.js +409 -51
  124. package/dist/services/merge-queue.js +228 -149
  125. package/dist/services/merge-server.js +163 -35
  126. package/dist/services/migrations.js +37 -16
  127. package/dist/services/native-daemon-history.js +49 -0
  128. package/dist/services/native-session-control.js +39 -0
  129. package/dist/services/plan-runtime.js +26 -11
  130. package/dist/services/plans.js +28 -25
  131. package/dist/services/projects.js +20 -15
  132. package/dist/services/prompts.js +28 -17
  133. package/dist/services/protocols.js +163 -87
  134. package/dist/services/recovery-observation-budget.js +121 -0
  135. package/dist/services/recovery-snapshot-database.js +145 -0
  136. package/dist/services/repair-intents.js +42 -0
  137. package/dist/services/review-copy.js +157 -0
  138. package/dist/services/review-deferral.js +23 -0
  139. package/dist/services/run-control-receipt.js +56 -0
  140. package/dist/services/run-control-worker.js +411 -0
  141. package/dist/services/run-control.js +985 -0
  142. package/dist/services/run-controller-adapter.js +399 -0
  143. package/dist/services/run-controller-capture.js +179 -0
  144. package/dist/services/run-controller-process.js +187 -0
  145. package/dist/services/run-controller-recovery.js +289 -0
  146. package/dist/services/run-controller-state.js +97 -0
  147. package/dist/services/run-controller.js +1035 -0
  148. package/dist/services/run-engine-bindings.js +1 -1
  149. package/dist/services/run-fork.js +147 -0
  150. package/dist/services/run-observations.js +152 -0
  151. package/dist/services/run-projection.js +22 -64
  152. package/dist/services/run-recovery-guard.js +75 -0
  153. package/dist/services/run-recovery-runtime.js +112 -0
  154. package/dist/services/run-recovery.js +349 -0
  155. package/dist/services/runs.js +558 -217
  156. package/dist/services/runtime-budget.js +430 -0
  157. package/dist/services/runtime-command.js +43 -0
  158. package/dist/services/runtime-scope-capture.js +52 -0
  159. package/dist/services/runtime-scope-control.js +468 -0
  160. package/dist/services/runtime-scope-resume.js +599 -0
  161. package/dist/services/runtime-scope-stop.js +180 -0
  162. package/dist/services/runtime-scope-worker.js +287 -0
  163. package/dist/services/runtime-service.js +96 -0
  164. package/dist/services/schema-validation.js +10 -8
  165. package/dist/services/scope-writer-cleanup.js +27 -0
  166. package/dist/services/sessions.js +35 -69
  167. package/dist/services/stage-blocker.js +17 -7
  168. package/dist/services/stage-context.js +185 -19
  169. package/dist/services/stage-lifecycle.js +98 -107
  170. package/dist/services/stage-pause.js +89 -75
  171. package/dist/services/stage-report-renderer.js +158 -6
  172. package/dist/services/stage-work-graph.js +35 -0
  173. package/dist/services/tooling.js +32 -23
  174. package/dist/services/usage.js +49 -101
  175. package/dist/services/verification-matrix.js +374 -0
  176. package/dist/services/vnext-code-review.js +222 -87
  177. package/dist/services/vnext-code.js +324 -251
  178. package/dist/services/vnext-contracts.js +10 -1
  179. package/dist/services/vnext-execution-profile.js +79 -4
  180. package/dist/services/vnext-fanout.js +182 -17
  181. package/dist/services/vnext-merge.js +335 -113
  182. package/dist/services/vnext-plan-review.js +276 -126
  183. package/dist/services/vnext-plan.js +227 -102
  184. package/dist/services/vnext-protocolize.js +335 -82
  185. package/dist/services/vnext-specify.js +119 -81
  186. package/dist/services/work-registry.js +1083 -194
  187. package/dist/services/workspace-bootstrap.js +87 -0
  188. package/dist/services/workspace-files.js +85 -0
  189. package/dist/services/worktrees.js +98 -44
  190. package/dist/shared/entity-references.js +8 -0
  191. package/dist/shared/errors.js +17 -0
  192. package/dist/storage/agent-output.js +26 -0
  193. package/dist/storage/database.js +785 -37
  194. package/dist/storage/foreign-key-transaction.js +39 -0
  195. package/dist/storage/immutable-input.js +45 -0
  196. package/dist/storage/import-guard.js +102 -0
  197. package/dist/storage/native-cleanup.js +52 -0
  198. package/dist/storage/paths.js +17 -4
  199. package/dist/storage/projection-lock.js +73 -0
  200. package/dist/storage/work-references.js +23 -0
  201. package/dist/storage/writer-contract.js +77 -0
  202. package/dist/storage/writer-migration.js +85 -0
  203. package/package.json +30 -13
  204. 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
+ }