@abelxiaoxing/cadence 1.4.0 → 1.4.1

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 (49) hide show
  1. package/README.md +58 -4
  2. package/agents/design-explorer.md +17 -11
  3. package/agents/diagnosis-worker.md +9 -1
  4. package/agents/implementation-worker.md +3 -1
  5. package/config/plan-draft.example.json +122 -0
  6. package/config/plan-draft.multiple-tasks.example.json +345 -0
  7. package/package.json +5 -3
  8. package/prompts/abel-design.md +93 -44
  9. package/src/activity-contracts.ts +82 -0
  10. package/src/candidate-artifact.ts +143 -0
  11. package/src/candidate-patch.ts +31 -11
  12. package/src/candidate-workspace.ts +74 -0
  13. package/src/change-contract-schema.ts +191 -0
  14. package/src/change-contract.ts +5 -0
  15. package/src/change-verification.ts +896 -0
  16. package/src/child-model.ts +129 -0
  17. package/src/child-session.ts +293 -326
  18. package/src/contracts.ts +184 -76
  19. package/src/delivery-compiler.ts +103 -120
  20. package/src/delivery-revision.ts +42 -0
  21. package/src/design-control.ts +113 -4
  22. package/src/design-diagnostics.ts +150 -0
  23. package/src/durable-contracts.ts +210 -0
  24. package/src/durable-workflow.ts +148 -3570
  25. package/src/evidence-draft.ts +122 -0
  26. package/src/implement-graph.ts +3 -0
  27. package/src/implement-plan.ts +70 -0
  28. package/src/index.ts +59 -522
  29. package/src/model-source.ts +22 -0
  30. package/src/package-candidate.ts +224 -0
  31. package/src/package-workflow.ts +253 -0
  32. package/src/packet-runtime.ts +27 -48
  33. package/src/parent-provider.ts +86 -198
  34. package/src/phase-execution.ts +2248 -0
  35. package/src/pi-adapter.ts +19 -0
  36. package/src/plan-draft-summary.ts +146 -0
  37. package/src/plan-draft.ts +493 -0
  38. package/src/subagent-activity.ts +32 -66
  39. package/src/submit-tool.ts +20 -59
  40. package/src/transport-budget.ts +32 -0
  41. package/src/worker-broker.ts +37 -57
  42. package/src/workflow-policy.ts +14 -53
  43. package/src/workflow-recovery-policy.ts +95 -0
  44. package/src/workflow-scheduling.ts +105 -0
  45. package/src/workflow-state-machine.ts +105 -497
  46. package/src/workflow-status.ts +384 -0
  47. package/src/workspace-io-worker.mjs +7 -0
  48. package/src/empty-resource-loader.ts +0 -38
  49. package/src/parent-payload-bridge.ts +0 -523
@@ -0,0 +1,105 @@
1
+ import type { PlanTaskDraft } from "./implement-plan.ts";
2
+ import { type EngineTaskRow, taskConflicts } from "./workflow-policy.ts";
3
+
4
+ function taskPlan(row: EngineTaskRow): PlanTaskDraft {
5
+ return JSON.parse(row.plan_json) as PlanTaskDraft;
6
+ }
7
+ export function hasTaskConflict(
8
+ row: EngineTaskRow,
9
+ rows: EngineTaskRow[],
10
+ selectedTaskIds: ReadonlySet<string>,
11
+ ): boolean {
12
+ const candidate = taskPlan(row);
13
+ return rows.some((other) => {
14
+ if (other.task_id === row.task_id || other.state === "verified") {
15
+ return false;
16
+ }
17
+ if (other.state === "queued") {
18
+ if (row.state !== "queued") return false;
19
+ const candidatePosition = row.queue_position ?? Number.MAX_SAFE_INTEGER;
20
+ const otherPosition = other.queue_position ?? Number.MAX_SAFE_INTEGER;
21
+ if (
22
+ otherPosition > candidatePosition ||
23
+ (otherPosition === candidatePosition &&
24
+ other.task_order > row.task_order)
25
+ ) {
26
+ return false;
27
+ }
28
+ }
29
+ if (other.task_order > row.task_order && other.state === "pending") {
30
+ return false;
31
+ }
32
+ if (other.state === "pending" && !dependenciesVerified(other, rows)) {
33
+ return false;
34
+ }
35
+ const conflict = taskConflicts(candidate, taskPlan(other));
36
+ return (
37
+ conflict.taskLifetime ||
38
+ (conflict.verification &&
39
+ ([
40
+ "pending",
41
+ "phase-ready",
42
+ "phase-running",
43
+ "validating",
44
+ "queued",
45
+ ].includes(other.state) ||
46
+ selectedTaskIds.has(other.task_id)))
47
+ );
48
+ });
49
+ }
50
+
51
+ export function dependenciesVerified(
52
+ row: EngineTaskRow,
53
+ rows: EngineTaskRow[],
54
+ ): boolean {
55
+ const byId = new Map(rows.map((candidate) => [candidate.task_id, candidate]));
56
+ return taskPlan(row).dependsOn.every(
57
+ (dependency) => byId.get(dependency)?.state === "verified",
58
+ );
59
+ }
60
+
61
+ /** Simulate ordered queue decisions without storage access or launch authority. */
62
+ export function selectRunnableTasks(input: {
63
+ rows: readonly EngineTaskRow[];
64
+ attempted: ReadonlySet<string>;
65
+ activeTasks: number;
66
+ capacity: number;
67
+ nextQueuePosition: number;
68
+ }) {
69
+ const rows = input.rows.map((row) => ({ ...row }));
70
+ const runnable: string[] = [];
71
+ const selected = new Set<string>();
72
+ const updates: Array<
73
+ | { kind: "pending"; taskId: string }
74
+ | { kind: "queue"; taskId: string; reason: "conflict" | "capacity" }
75
+ > = [];
76
+ let position = input.nextQueuePosition;
77
+ let capacityBlocked = false;
78
+ for (const row of rows) {
79
+ if (row.state === "verified" || input.attempted.has(row.task_id)) continue;
80
+ if (!dependenciesVerified(row, rows)) {
81
+ if (row.state !== "pending") {
82
+ updates.push({ kind: "pending", taskId: row.task_id });
83
+ row.state = "pending";
84
+ row.pause_code = null;
85
+ row.queue_position = null;
86
+ }
87
+ continue;
88
+ }
89
+ const conflict = hasTaskConflict(row, rows, selected);
90
+ const capacity = input.activeTasks + runnable.length >= input.capacity;
91
+ if (conflict || capacity) {
92
+ const reason = conflict ? "conflict" : "capacity";
93
+ updates.push({ kind: "queue", taskId: row.task_id, reason });
94
+ if (row.state !== "queued" || row.queue_position === null)
95
+ row.queue_position = position++;
96
+ row.state = "queued";
97
+ row.pause_code = reason === "capacity" ? "worker-capacity" : null;
98
+ if (!conflict) capacityBlocked = true;
99
+ continue;
100
+ }
101
+ runnable.push(row.task_id);
102
+ selected.add(row.task_id);
103
+ }
104
+ return { runnable, updates, capacityBlocked };
105
+ }