@deksden-com/dd-flow-cli 0.9.0-beta.10 → 0.9.0-beta.100

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 (146) hide show
  1. package/CHANGELOG.md +491 -0
  2. package/README.md +68 -0
  3. package/dist/build-info.json +8 -8
  4. package/dist/cli/command-inputs.js +305 -0
  5. package/dist/cli/help.js +89 -13
  6. package/dist/cli/hook-ingress.js +82 -0
  7. package/dist/cli/input-preparation.js +116 -0
  8. package/dist/cli/run-cli.js +1437 -384
  9. package/dist/cli.js +6 -2
  10. package/dist/harness-runtime/DD-ZCODE.md +99 -0
  11. package/dist/harness-runtime/bin/dd-agy.mjs +39 -0
  12. package/dist/harness-runtime/bin/dd-codex.mjs +25 -0
  13. package/dist/harness-runtime/bin/dd-droid.mjs +33 -0
  14. package/dist/harness-runtime/bin/dd-grok.mjs +30 -0
  15. package/dist/harness-runtime/bin/dd-opencode.mjs +21 -0
  16. package/dist/harness-runtime/bin/dd-zcode.mjs +83 -0
  17. package/dist/harness-runtime/lib/daemon-operations.mjs +215 -0
  18. package/dist/harness-runtime/lib/dd-agy-daemon.mjs +449 -0
  19. package/dist/harness-runtime/lib/dd-agy.mjs +59 -0
  20. package/dist/harness-runtime/lib/dd-codex-daemon.d.mts +1 -0
  21. package/dist/harness-runtime/lib/dd-codex-daemon.mjs +146 -0
  22. package/dist/harness-runtime/lib/dd-codex.mjs +562 -0
  23. package/dist/harness-runtime/lib/dd-droid-daemon.mjs +125 -0
  24. package/dist/harness-runtime/lib/dd-droid.mjs +468 -0
  25. package/dist/harness-runtime/lib/dd-grok-daemon.mjs +300 -0
  26. package/dist/harness-runtime/lib/dd-grok.mjs +174 -0
  27. package/dist/harness-runtime/lib/dd-opencode-daemon.mjs +217 -0
  28. package/dist/harness-runtime/lib/dd-opencode.mjs +98 -0
  29. package/dist/harness-runtime/lib/dd-zcode-daemon.mjs +644 -0
  30. package/dist/harness-runtime/lib/dd-zcode.mjs +941 -0
  31. package/dist/harness-runtime/lib/delegation-instructions.d.mts +10 -0
  32. package/dist/harness-runtime/lib/delegation-instructions.mjs +130 -0
  33. package/dist/harness-runtime/lib/dispatch-fence.mjs +14 -0
  34. package/dist/harness-runtime/lib/driver-recovery.mjs +129 -0
  35. package/dist/harness-runtime/lib/droid-observation.mjs +66 -0
  36. package/dist/harness-runtime/lib/managed-daemon.mjs +267 -0
  37. package/dist/harness-runtime/lib/model-observations.mjs +77 -0
  38. package/dist/harness-runtime/lib/native-hook-command.d.mts +1 -0
  39. package/dist/harness-runtime/lib/native-hook-command.mjs +34 -0
  40. package/dist/harness-runtime/lib/observation-clock.mjs +36 -0
  41. package/dist/harness-runtime/lib/operation-context.mjs +5 -0
  42. package/dist/harness-runtime/lib/operation-errors.mjs +19 -0
  43. package/dist/harness-runtime/lib/process-json.mjs +70 -0
  44. package/dist/harness-runtime/lib/process-snapshot.mjs +10 -0
  45. package/dist/harness-runtime/lib/runner-events.mjs +200 -0
  46. package/dist/harness-runtime/lib/runner-lock.mjs +42 -0
  47. package/dist/harness-runtime/lib/session-settlement.mjs +30 -0
  48. package/dist/harness-runtime/lib/tool-observations.d.mts +17 -0
  49. package/dist/harness-runtime/lib/tool-observations.mjs +153 -0
  50. package/dist/harness-runtime/lib/zcode-usage.mjs +54 -0
  51. package/dist/schemas/agent-profile.schema.json +1 -1
  52. package/dist/schemas/code-review-result.schema.json +1 -1
  53. package/dist/schemas/code-work-batch.schema.json +3 -3
  54. package/dist/schemas/code-work-result.schema.json +3 -3
  55. package/dist/schemas/plan-review-result.schema.json +2 -2
  56. package/dist/schemas/run-control-receipt.schema.json +99 -0
  57. package/dist/schemas/run-control-request.schema.json +36 -0
  58. package/dist/schemas/vnext-protocol-plan.schema.json +2 -2
  59. package/dist/services/canon.js +11 -8
  60. package/dist/services/cleanup.js +57 -13
  61. package/dist/services/cli-operation-classifier.js +22 -24
  62. package/dist/services/code-checks.js +543 -96
  63. package/dist/services/codex-hook-delivery.js +28 -0
  64. package/dist/services/command-context.js +80 -0
  65. package/dist/services/config.js +11 -8
  66. package/dist/services/continuation-outcome.js +20 -0
  67. package/dist/services/controller-fanout.js +134 -0
  68. package/dist/services/dashboard.js +103 -31
  69. package/dist/services/engines.js +121 -76
  70. package/dist/services/eval-snapshots.js +832 -73
  71. package/dist/services/execution-policy.js +170 -0
  72. package/dist/services/external-work-launch.js +110 -0
  73. package/dist/services/harness-adapter.js +147 -24
  74. package/dist/services/harness-config.js +2 -0
  75. package/dist/services/hooks.js +596 -300
  76. package/dist/services/lanes.js +61 -53
  77. package/dist/services/lifecycle-command.js +103 -17
  78. package/dist/services/lifecycle-contract.js +30 -0
  79. package/dist/services/lifecycle-invocations.js +1128 -0
  80. package/dist/services/managed-daemon-binding.js +38 -0
  81. package/dist/services/managed-processes.js +283 -27
  82. package/dist/services/merge-queue.js +179 -104
  83. package/dist/services/merge-server.js +73 -28
  84. package/dist/services/migrations.js +14 -9
  85. package/dist/services/native-daemon-history.js +49 -0
  86. package/dist/services/native-session-control.js +39 -0
  87. package/dist/services/plan-runtime.js +19 -8
  88. package/dist/services/plans.js +28 -25
  89. package/dist/services/projects.js +18 -5
  90. package/dist/services/prompts.js +23 -16
  91. package/dist/services/protocols.js +64 -20
  92. package/dist/services/recovery-observation-budget.js +61 -0
  93. package/dist/services/recovery-snapshot-database.js +107 -0
  94. package/dist/services/repair-intents.js +40 -0
  95. package/dist/services/run-control-receipt.js +56 -0
  96. package/dist/services/run-control-worker.js +363 -0
  97. package/dist/services/run-control.js +876 -0
  98. package/dist/services/run-controller-adapter.js +222 -0
  99. package/dist/services/run-controller-capture.js +136 -0
  100. package/dist/services/run-controller-process.js +189 -0
  101. package/dist/services/run-controller-recovery.js +222 -0
  102. package/dist/services/run-controller-state.js +36 -0
  103. package/dist/services/run-controller.js +803 -0
  104. package/dist/services/run-engine-bindings.js +1 -1
  105. package/dist/services/run-fork.js +138 -0
  106. package/dist/services/run-observations.js +112 -0
  107. package/dist/services/run-recovery-runtime.js +69 -0
  108. package/dist/services/run-recovery.js +343 -0
  109. package/dist/services/runs.js +368 -74
  110. package/dist/services/runtime-budget.js +439 -0
  111. package/dist/services/runtime-command.js +43 -0
  112. package/dist/services/runtime-scope-capture.js +50 -0
  113. package/dist/services/runtime-scope-control.js +450 -0
  114. package/dist/services/runtime-scope-resume.js +565 -0
  115. package/dist/services/runtime-scope-stop.js +99 -0
  116. package/dist/services/runtime-scope-worker.js +243 -0
  117. package/dist/services/runtime-service.js +97 -0
  118. package/dist/services/schema-validation.js +10 -8
  119. package/dist/services/sessions.js +35 -69
  120. package/dist/services/stage-blocker.js +17 -7
  121. package/dist/services/stage-context.js +44 -18
  122. package/dist/services/stage-lifecycle.js +99 -102
  123. package/dist/services/stage-pause.js +84 -55
  124. package/dist/services/stage-work-graph.js +35 -0
  125. package/dist/services/usage.js +37 -93
  126. package/dist/services/vnext-code-review.js +185 -79
  127. package/dist/services/vnext-code.js +282 -248
  128. package/dist/services/vnext-execution-profile.js +5 -3
  129. package/dist/services/vnext-fanout.js +164 -17
  130. package/dist/services/vnext-merge.js +291 -104
  131. package/dist/services/vnext-plan-review.js +139 -81
  132. package/dist/services/vnext-plan.js +138 -69
  133. package/dist/services/vnext-protocolize.js +129 -56
  134. package/dist/services/vnext-specify.js +88 -65
  135. package/dist/services/work-registry.js +705 -162
  136. package/dist/services/workspace-bootstrap.js +76 -0
  137. package/dist/services/worktrees.js +85 -35
  138. package/dist/shared/entity-references.js +8 -0
  139. package/dist/shared/errors.js +12 -0
  140. package/dist/storage/database.js +459 -32
  141. package/dist/storage/paths.js +17 -4
  142. package/dist/storage/work-references.js +23 -0
  143. package/dist/storage/writer-contract.js +77 -0
  144. package/dist/storage/writer-migration.js +102 -0
  145. package/package.json +24 -13
  146. package/tools/repair-paused-run-status.mjs +59 -0
@@ -0,0 +1,116 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import crypto from "node:crypto";
4
+ import { AppError, isAppError } from "../shared/errors.js";
5
+ import { validateSchema } from "../services/schema-validation.js";
6
+ export function prepareError(error, input = {}) {
7
+ if (isAppError(error)) {
8
+ // A malformed user input is safely correctable. A broken schema registry,
9
+ // binding, or storage is not; do not disguise infrastructure damage as a
10
+ // retryable command typo.
11
+ const inputErrorCodes = new Set([
12
+ "usage", "validation", "schema_validation", "invalid_json", "not_found",
13
+ "path_escape", "input_file_missing", "input_file_not_regular", "input_file_unreadable",
14
+ "response_file_parent_invalid", "response_file_invalid", "context_checksum_mismatch", "invalid_run_config_state", "invalid_work_state", "invalid_stage_state", "runtime_budget_invalid", "runtime_scope_manifest_invalid", "runtime_scope_resume_invalid",
15
+ "fork_path_conflict", "fork_output_not_empty", "fork_checkpoint_invalid", "fork_engine_unavailable", "snapshot_missing",
16
+ "repair_check_declaration_missing", "review_repair_check_required", "review_check_reference_unknown", "semantic_status_inconsistent", "migration_report_invalid", "controller_context_missing", "snapshot_output_inside_runtime"
17
+ ]);
18
+ if (!inputErrorCodes.has(error.code) && error.details.phase !== "prepare")
19
+ throw error;
20
+ throw new AppError(error.code, error.message, 2, {
21
+ ...error.details,
22
+ phase: "prepare",
23
+ effect: error.details.effect ?? "no_effect",
24
+ recoverable: error.details.recoverable ?? true,
25
+ ...input
26
+ });
27
+ }
28
+ const code = error?.code;
29
+ if (typeof input.file !== "string" || !["ENOENT", "EACCES", "EPERM", "EISDIR", "ENOTDIR", "ELOOP", "ENAMETOOLONG"].includes(code ?? ""))
30
+ throw error;
31
+ throw new AppError("input_file_unreadable", `Cannot read input file${typeof input.file === "string" ? `: ${input.file}` : ""}`, 2, {
32
+ phase: "prepare", effect: "no_effect", recoverable: true, ...input, cause: code ?? String(error)
33
+ });
34
+ }
35
+ export function prepareTextFile(file, label = "input file") {
36
+ const prepared = prepareFileBytes(file, label);
37
+ return { file: prepared.file, text: prepared.bytes.toString("utf8") };
38
+ }
39
+ export function prepareFileBytes(file, label = "input file") {
40
+ const absolute = path.resolve(file);
41
+ let descriptor;
42
+ try {
43
+ descriptor = fs.openSync(absolute, fs.constants.O_RDONLY | fs.constants.O_NONBLOCK);
44
+ const stat = fs.fstatSync(descriptor);
45
+ if (!stat.isFile()) {
46
+ throw new AppError("input_file_not_regular", `${label} must be a readable regular file: ${absolute}`, 2, { file: absolute, label });
47
+ }
48
+ return { file: absolute, bytes: fs.readFileSync(descriptor) };
49
+ }
50
+ catch (error) {
51
+ if (error?.code === "ENOENT") {
52
+ throw new AppError("input_file_missing", `${label} does not exist: ${absolute}`, 2, {
53
+ phase: "prepare", effect: "no_effect", recoverable: true, file: absolute, label
54
+ });
55
+ }
56
+ return prepareError(error, { file: absolute, label });
57
+ }
58
+ finally {
59
+ if (descriptor !== undefined)
60
+ fs.closeSync(descriptor);
61
+ }
62
+ }
63
+ export function prepareJsonText(text, input) {
64
+ try {
65
+ return { file: input.file, text, value: JSON.parse(text) };
66
+ }
67
+ catch {
68
+ // Keep the established public code so agents can recognise this as a
69
+ // safe correction-and-retry condition.
70
+ throw new AppError("invalid_json", `Invalid JSON in ${input.label ?? "input"}: ${input.file}`, 2, {
71
+ phase: "prepare", effect: "no_effect", recoverable: true, file: input.file, label: input.label ?? "input",
72
+ cause: "Invalid JSON syntax", input_sha256: crypto.createHash("sha256").update(text).digest("hex")
73
+ });
74
+ }
75
+ }
76
+ export function prepareJsonFile(file, label = "input JSON") {
77
+ const prepared = prepareTextFile(file, label);
78
+ return prepareJsonText(prepared.text, { file: prepared.file, label });
79
+ }
80
+ export function prepareJsonSchema(file, label, schema) {
81
+ const prepared = prepareJsonFile(file, label);
82
+ try {
83
+ validateSchema({ ...schema, file: prepared.file, data: prepared.value });
84
+ }
85
+ catch (error) {
86
+ return prepareError(error, { file: prepared.file, label });
87
+ }
88
+ return prepared;
89
+ }
90
+ /** Read-only destination check; execution still handles filesystem races. */
91
+ export function prepareOutputFile(value) { return prepareOutput(value, false); }
92
+ export function prepareOutputDirectory(value) { return prepareOutput(value, true); }
93
+ function prepareOutput(value, directory) {
94
+ const file = path.resolve(value);
95
+ try {
96
+ let ancestor = directory ? file : path.dirname(file);
97
+ while (!fs.existsSync(ancestor) && path.dirname(ancestor) !== ancestor)
98
+ ancestor = path.dirname(ancestor);
99
+ if (!fs.statSync(ancestor).isDirectory())
100
+ throw new AppError("validation", "Output parent must be a directory", 2);
101
+ fs.accessSync(ancestor, fs.constants.W_OK | fs.constants.X_OK);
102
+ if (fs.existsSync(file)) {
103
+ const stat = fs.statSync(file);
104
+ if (directory ? !stat.isDirectory() : !stat.isFile())
105
+ throw new AppError("validation", directory ? "Output must name a directory" : "Output must name a regular file", 2);
106
+ fs.accessSync(file, fs.constants.W_OK | (directory ? fs.constants.X_OK : 0));
107
+ }
108
+ return file;
109
+ }
110
+ catch (error) {
111
+ const code = error?.code;
112
+ if (["ENOENT", "EACCES", "EPERM", "ENOTDIR", "ELOOP", "ENAMETOOLONG"].includes(code ?? ""))
113
+ return prepareError(new AppError("validation", "Output destination is not writable or has an invalid parent", 2, { cause: code }), { file, parameter: "output" });
114
+ return prepareError(error, { file, parameter: "output" });
115
+ }
116
+ }