@abelxiaoxing/cadence 1.3.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.
- package/README.md +172 -13
- package/agents/design-explorer.md +17 -11
- package/agents/diagnosis-worker.md +9 -1
- package/agents/implementation-worker.md +3 -1
- package/config/plan-draft.example.json +122 -0
- package/config/plan-draft.multiple-tasks.example.json +345 -0
- package/package.json +9 -5
- package/prompts/abel-design.md +141 -38
- package/prompts/abel-diagnose.md +10 -1
- package/prompts/abel-implement.md +118 -20
- package/prompts/abel-init.md +9 -2
- package/src/activity-contracts.ts +82 -0
- package/src/apply-transaction.ts +16 -14
- package/src/artifact-store.ts +17 -0
- package/src/candidate-artifact.ts +143 -0
- package/src/candidate-patch.ts +33 -12
- package/src/candidate-workspace.ts +74 -0
- package/src/canonical.ts +16 -0
- package/src/change-contract-schema.ts +191 -0
- package/src/change-contract.ts +273 -0
- package/src/change-verification.ts +896 -0
- package/src/child-model.ts +129 -0
- package/src/child-session.ts +296 -328
- package/src/contracts.ts +325 -109
- package/src/control-contracts.ts +51 -1
- package/src/delivery-compiler.ts +241 -141
- package/src/delivery-revision.ts +42 -0
- package/src/design-control.ts +182 -15
- package/src/design-diagnostics.ts +150 -0
- package/src/design-journal.ts +216 -72
- package/src/durable-contracts.ts +210 -0
- package/src/durable-workflow.ts +963 -0
- package/src/evidence-draft.ts +122 -0
- package/src/implement-graph.ts +14 -16
- package/src/implement-plan.ts +70 -0
- package/src/index.ts +341 -1405
- package/src/isolation-backend.ts +84 -23
- package/src/model-source.ts +22 -0
- package/src/package-candidate.ts +224 -0
- package/src/package-delivery.ts +486 -0
- package/src/package-verification.ts +509 -0
- package/src/package-workflow.ts +253 -0
- package/src/packet-runtime.ts +27 -48
- package/src/parent-provider.ts +86 -198
- package/src/phase-execution.ts +2248 -0
- package/src/pi-adapter.ts +19 -0
- package/src/plan-draft-summary.ts +146 -0
- package/src/plan-draft.ts +493 -0
- package/src/route-policy.ts +1 -11
- package/src/run-state.ts +4 -16
- package/src/run-store.ts +5 -144
- package/src/scoped-grep-worker.mjs +23 -0
- package/src/scoped-tools.ts +312 -116
- package/src/sqlite-schema.ts +171 -0
- package/src/storage-schema.ts +352 -0
- package/src/subagent-activity.ts +46 -67
- package/src/submit-tool.ts +40 -61
- package/src/task-ledger.ts +14 -55
- package/src/transport-budget.ts +32 -0
- package/src/verification-capability.ts +298 -102
- package/src/verification-environment.ts +213 -0
- package/src/verification-identity.ts +77 -0
- package/src/worker-broker.ts +134 -91
- package/src/workflow-engine.ts +28 -8285
- package/src/workflow-policy.ts +1388 -0
- package/src/workflow-recovery-policy.ts +95 -0
- package/src/workflow-scheduling.ts +105 -0
- package/src/workflow-state-machine.ts +4086 -0
- package/src/workflow-status.ts +384 -0
- package/src/workspace-io-entry.mjs +58 -0
- package/src/workspace-io-worker.mjs +991 -0
- package/src/workspace-io.ts +84 -0
- package/src/workspace-store.ts +125 -19
- package/skills/abel-workflow/SKILL.md +0 -205
- package/src/empty-resource-loader.ts +0 -38
- package/src/parent-payload-bridge.ts +0 -523
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { ImplementPlan } from "./implement-plan.ts";
|
|
2
|
+
|
|
3
|
+
export type RecoveryActionRequest = {
|
|
4
|
+
kind: "affected-repair" | "cumulative-repair" | "red-correction";
|
|
5
|
+
attempt: number;
|
|
6
|
+
};
|
|
7
|
+
export type RecoveryActionDecision =
|
|
8
|
+
| { allowed: true }
|
|
9
|
+
| {
|
|
10
|
+
allowed: false;
|
|
11
|
+
code: "repair-attempts-exhausted" | "artifact-attempts-exhausted";
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/** One policy for every nested recovery action; execution services supply facts only. */
|
|
15
|
+
export function decideRecoveryAction(
|
|
16
|
+
plan: ImplementPlan,
|
|
17
|
+
request: RecoveryActionRequest,
|
|
18
|
+
authority: { additionalAttempt?: boolean; verificationOnly?: boolean } = {},
|
|
19
|
+
): RecoveryActionDecision {
|
|
20
|
+
const correction = request.kind === "red-correction";
|
|
21
|
+
const limit =
|
|
22
|
+
authority.additionalAttempt || authority.verificationOnly
|
|
23
|
+
? 1
|
|
24
|
+
: correction
|
|
25
|
+
? plan.verification.artifactCorrection.maxAttempts
|
|
26
|
+
: plan.verification.repair.maxAttempts;
|
|
27
|
+
return Number.isSafeInteger(request.attempt) &&
|
|
28
|
+
request.attempt > 0 &&
|
|
29
|
+
request.attempt <= limit
|
|
30
|
+
? { allowed: true }
|
|
31
|
+
: {
|
|
32
|
+
allowed: false,
|
|
33
|
+
code: correction
|
|
34
|
+
? "artifact-attempts-exhausted"
|
|
35
|
+
: "repair-attempts-exhausted",
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface WorkflowRecoveryFeedback {
|
|
40
|
+
code: string;
|
|
41
|
+
attempt: number;
|
|
42
|
+
maxAttempts: number;
|
|
43
|
+
strategy:
|
|
44
|
+
| "revise-candidate"
|
|
45
|
+
| "refresh-candidate"
|
|
46
|
+
| "repair-verification"
|
|
47
|
+
| "compact-patch";
|
|
48
|
+
failureIdentities?: string[];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface WorkflowRecoveryFact {
|
|
52
|
+
key: string;
|
|
53
|
+
failures: number;
|
|
54
|
+
feedback: WorkflowRecoveryFeedback;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function recoveryExhausted(
|
|
58
|
+
incident: WorkflowRecoveryFact | undefined,
|
|
59
|
+
maximum: number,
|
|
60
|
+
granted: boolean,
|
|
61
|
+
): boolean {
|
|
62
|
+
return !granted && incident !== undefined && incident.failures >= maximum;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** A grant is a recommendation until the state machine validates and records it in its lease transaction. */
|
|
66
|
+
export function assessRecoveryGrant(input: {
|
|
67
|
+
current: boolean;
|
|
68
|
+
incident?: WorkflowRecoveryFact;
|
|
69
|
+
failureSequence: number;
|
|
70
|
+
requestedSequence: number;
|
|
71
|
+
reason: string;
|
|
72
|
+
previous: { route?: string | null; context?: string | null };
|
|
73
|
+
observed: { route?: string | null; context?: string | null };
|
|
74
|
+
budget?: { used: number; max_work: number };
|
|
75
|
+
}): string | undefined {
|
|
76
|
+
if (
|
|
77
|
+
!input.current ||
|
|
78
|
+
!input.incident ||
|
|
79
|
+
input.incident.failures < input.incident.feedback.maxAttempts ||
|
|
80
|
+
input.failureSequence !== input.requestedSequence
|
|
81
|
+
)
|
|
82
|
+
return "recovery-request-stale";
|
|
83
|
+
if (
|
|
84
|
+
(input.reason === "route-changed" &&
|
|
85
|
+
(!input.previous.route ||
|
|
86
|
+
input.previous.route === input.observed.route)) ||
|
|
87
|
+
(input.reason === "context-extended" &&
|
|
88
|
+
(!input.previous.context ||
|
|
89
|
+
input.previous.context === input.observed.context))
|
|
90
|
+
)
|
|
91
|
+
return "recovery-evidence-unavailable";
|
|
92
|
+
if (!input.budget || input.budget.used >= input.budget.max_work)
|
|
93
|
+
return "change-work-budget-exhausted";
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
@@ -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
|
+
}
|