intentdna 1.8.7 → 1.9.0-rc.2
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/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +1 -1
- package/dist/cli/commands/candidate-promotion.d.ts +15 -0
- package/dist/cli/commands/candidate-promotion.js +197 -0
- package/dist/cli/commands/run-lifecycle.js +1 -0
- package/dist/cli/commands/run.js +76 -42
- package/dist/cli/commands/setup.d.ts +10 -0
- package/dist/cli/commands/setup.js +129 -36
- package/dist/cli/commands/source-assets.d.ts +32 -0
- package/dist/cli/commands/source-assets.js +154 -0
- package/dist/cli/commands/sync.js +52 -12
- package/dist/cli/commands/templates.js +59 -37
- package/dist/cli/index.js +161 -5
- package/dist/compiler/cascade.js +1 -1
- package/dist/hooks/cli.d.ts +6 -0
- package/dist/hooks/cli.js +118 -10
- package/dist/hooks/enforcement-boundary.d.ts +1 -1
- package/dist/hooks/protocol.d.ts +1 -1
- package/dist/hooks/state.d.ts +5 -0
- package/dist/hooks/state.js +21 -6
- package/dist/mcp/tools-state.js +251 -15
- package/dist/runtime/claude-sync-target.d.ts +2 -0
- package/dist/runtime/claude-sync-target.js +1 -1
- package/dist/runtime/evaluator.d.ts +13 -0
- package/dist/runtime/evaluator.js +46 -0
- package/dist/runtime/index.d.ts +8 -4
- package/dist/runtime/index.js +4 -2
- package/dist/runtime/plugin-adapter.d.ts +14 -1
- package/dist/runtime/plugin-adapter.js +23 -9
- package/dist/runtime/run-contracts.d.ts +5 -3
- package/dist/runtime/run-contracts.js +11 -1
- package/dist/runtime/run-controller.d.ts +15 -1
- package/dist/runtime/run-controller.js +235 -94
- package/dist/runtime/skill-adapter.js +24 -53
- package/dist/runtime/verifier.js +101 -2
- package/dist/runtime/workflow-plan-adapter.d.ts +2 -1
- package/dist/runtime/workflow-plan-adapter.js +78 -11
- package/dist/runtime/workflow-runtime-manifest.d.ts +48 -0
- package/dist/runtime/workflow-runtime-manifest.js +196 -0
- package/dist/runtime/workflow-variable-scopes.d.ts +12 -0
- package/dist/runtime/workflow-variable-scopes.js +55 -0
- package/dist/schema/types.d.ts +9 -0
- package/dist/schema/validate.js +29 -1
- package/dist/sources/authoring-packet.d.ts +8 -0
- package/dist/sources/authoring-packet.js +85 -0
- package/dist/sources/discovery.d.ts +7 -0
- package/dist/sources/discovery.js +150 -0
- package/dist/sources/license.d.ts +5 -0
- package/dist/sources/license.js +94 -0
- package/dist/sources/manifest.d.ts +11 -0
- package/dist/sources/manifest.js +84 -0
- package/dist/sources/skill-markdown.d.ts +6 -0
- package/dist/sources/skill-markdown.js +174 -0
- package/dist/sources/types.d.ts +125 -0
- package/dist/sources/types.js +1 -0
- package/dist/templates/asset-refinery.dna.yaml +192 -0
- package/dist/templates/flutter-behavior-lock.dna.yaml +17 -0
- package/dist/templates/flutter-refactoring-rescue.dna.yaml +11 -0
- package/dist/templates/flutter-rewrite.dna.yaml +154 -28
- package/dist/templates/metadata.js +2 -0
- package/dist/templates/multi-agent-handoff-coordination.dna.yaml +102 -37
- package/dist/templates/persistent-executor.dna.yaml +61 -3
- package/dist/templates/research-improvement.dna.yaml +295 -0
- package/dist/templates/subagent-parallel.dna.yaml +90 -17
- package/dist/templates/workflow-evidence-review.dna.yaml +8 -0
- package/dist/workflow/candidate-projection.d.ts +33 -0
- package/dist/workflow/candidate-projection.js +70 -0
- package/package.json +3 -1
- package/scripts/sync-release-plugin.cjs +87 -0
|
@@ -61,6 +61,20 @@ function retryAllowed(policy, attempt, outcome) {
|
|
|
61
61
|
return (attempt.attempt_number < policy.max_attempts
|
|
62
62
|
&& policy.retryable_outcomes.includes(outcome.kind));
|
|
63
63
|
}
|
|
64
|
+
function currentWorkflowRound(snapshot) {
|
|
65
|
+
return 1 + snapshot.events.filter((event) => event.type === "workflow_round_advanced").length;
|
|
66
|
+
}
|
|
67
|
+
function workflowRetryDelayMs(policy, completedRound) {
|
|
68
|
+
if (policy.backoff === "none")
|
|
69
|
+
return 0;
|
|
70
|
+
const multiplier = policy.backoff === "linear"
|
|
71
|
+
? completedRound
|
|
72
|
+
: 2 ** Math.max(0, completedRound - 1);
|
|
73
|
+
const delay = policy.initial_delay_ms * multiplier;
|
|
74
|
+
return policy.max_delay_ms === null
|
|
75
|
+
? delay
|
|
76
|
+
: Math.min(delay, policy.max_delay_ms);
|
|
77
|
+
}
|
|
64
78
|
function eventPayload(value) {
|
|
65
79
|
return value;
|
|
66
80
|
}
|
|
@@ -69,6 +83,8 @@ export class RunController {
|
|
|
69
83
|
resolver;
|
|
70
84
|
definitions;
|
|
71
85
|
definitionByStep;
|
|
86
|
+
workflowRetryLoop;
|
|
87
|
+
workflowRetrySteps;
|
|
72
88
|
providerForStep;
|
|
73
89
|
maxConcurrency;
|
|
74
90
|
leaseDurationMs;
|
|
@@ -101,6 +117,8 @@ export class RunController {
|
|
|
101
117
|
?? new HandoffResolver(new ImmutableResultStore(options.run_store));
|
|
102
118
|
this.definitions = [...options.steps];
|
|
103
119
|
this.definitionByStep = this.validateDefinitions(this.definitions);
|
|
120
|
+
this.workflowRetryLoop = options.workflow_retry_loop ?? null;
|
|
121
|
+
this.workflowRetrySteps = this.validateWorkflowRetryLoop(this.workflowRetryLoop);
|
|
104
122
|
this.providerForStep = options.provider_for_step;
|
|
105
123
|
this.maxConcurrency = options.max_concurrency;
|
|
106
124
|
this.leaseDurationMs = options.lease_duration_ms;
|
|
@@ -152,6 +170,32 @@ export class RunController {
|
|
|
152
170
|
}
|
|
153
171
|
return byStep;
|
|
154
172
|
}
|
|
173
|
+
validateWorkflowRetryLoop(policy) {
|
|
174
|
+
if (policy === null)
|
|
175
|
+
return new Set();
|
|
176
|
+
if (!Number.isSafeInteger(policy.max_retries)
|
|
177
|
+
|| policy.max_retries < 1
|
|
178
|
+
|| !Number.isSafeInteger(policy.initial_delay_ms)
|
|
179
|
+
|| policy.initial_delay_ms < 0
|
|
180
|
+
|| (policy.max_delay_ms !== null
|
|
181
|
+
&& (!Number.isSafeInteger(policy.max_delay_ms)
|
|
182
|
+
|| policy.max_delay_ms < 0))) {
|
|
183
|
+
throw new RunControllerError("invalid_configuration", "workflow retry loop has an invalid retry policy");
|
|
184
|
+
}
|
|
185
|
+
const stepIds = [...policy.step_ids];
|
|
186
|
+
if (stepIds.length === 0
|
|
187
|
+
|| new Set(stepIds).size !== stepIds.length
|
|
188
|
+
|| stepIds[0] !== policy.retry_from
|
|
189
|
+
|| stepIds[stepIds.length - 1] !== policy.completion_step) {
|
|
190
|
+
throw new RunControllerError("invalid_configuration", "workflow retry loop has an invalid Step range");
|
|
191
|
+
}
|
|
192
|
+
const definitionIndexes = stepIds.map((stepId) => (this.definitions.findIndex((definition) => definition.step_id === stepId)));
|
|
193
|
+
if (definitionIndexes.some((index) => index < 0)
|
|
194
|
+
|| definitionIndexes.some((index, position) => (position > 0 && index !== definitionIndexes[position - 1] + 1))) {
|
|
195
|
+
throw new RunControllerError("invalid_configuration", "workflow retry loop Steps must be a contiguous Controller segment");
|
|
196
|
+
}
|
|
197
|
+
return new Set(stepIds);
|
|
198
|
+
}
|
|
155
199
|
events(snapshot, inputs) {
|
|
156
200
|
return inputs.map((input, index) => ({
|
|
157
201
|
...input,
|
|
@@ -228,7 +272,8 @@ export class RunController {
|
|
|
228
272
|
}
|
|
229
273
|
const dependencies = this.dependenciesFor(definition, snapshot);
|
|
230
274
|
const failedDependency = dependencies.some((dependency) => terminalTask(dependency) && dependency.state !== "succeeded");
|
|
231
|
-
const ready = dependencies.every((dependency) => (dependency.state === "succeeded"
|
|
275
|
+
const ready = dependencies.every((dependency) => ((dependency.state === "succeeded"
|
|
276
|
+
|| dependency.state === "round_succeeded")
|
|
232
277
|
&& dependency.committed_result_id !== null
|
|
233
278
|
&& snapshot.results.some((result) => result.result_id === dependency.committed_result_id)));
|
|
234
279
|
if (!failedDependency && !ready)
|
|
@@ -272,11 +317,29 @@ export class RunController {
|
|
|
272
317
|
}
|
|
273
318
|
readyAt(definition, task, snapshot) {
|
|
274
319
|
const prior = attemptById(snapshot, task.current_attempt_id);
|
|
275
|
-
|
|
276
|
-
|
|
320
|
+
const attemptReadyAt = (!prior
|
|
321
|
+
|| prior.phase !== "terminal"
|
|
322
|
+
|| prior.completed_at === null)
|
|
323
|
+
? 0
|
|
324
|
+
: Date.parse(prior.completed_at)
|
|
325
|
+
+ retryDelayMs(definition.retry_policy, prior.attempt_number);
|
|
326
|
+
let workflowReadyAt = 0;
|
|
327
|
+
if (this.workflowRetryLoop !== null
|
|
328
|
+
&& definition.step_id === this.workflowRetryLoop.retry_from) {
|
|
329
|
+
for (let index = snapshot.events.length - 1; index >= 0; index -= 1) {
|
|
330
|
+
const event = snapshot.events[index];
|
|
331
|
+
if (event.type !== "workflow_round_advanced")
|
|
332
|
+
continue;
|
|
333
|
+
const payload = event.payload;
|
|
334
|
+
if (payload !== null
|
|
335
|
+
&& !Array.isArray(payload)
|
|
336
|
+
&& typeof payload.ready_at === "string") {
|
|
337
|
+
workflowReadyAt = Date.parse(payload.ready_at);
|
|
338
|
+
}
|
|
339
|
+
break;
|
|
340
|
+
}
|
|
277
341
|
}
|
|
278
|
-
return
|
|
279
|
-
+ retryDelayMs(definition.retry_policy, prior.attempt_number));
|
|
342
|
+
return Math.max(attemptReadyAt, workflowReadyAt);
|
|
280
343
|
}
|
|
281
344
|
async claimNextReady(runId) {
|
|
282
345
|
while (true) {
|
|
@@ -597,6 +660,7 @@ export class RunController {
|
|
|
597
660
|
attempt_id: claimed.claim.attempt_id,
|
|
598
661
|
worker_session_id: claimed.claim.worker_session_id,
|
|
599
662
|
attempt_number: claimed.attempt.attempt_number,
|
|
663
|
+
workflow_round: currentWorkflowRound(snapshot),
|
|
600
664
|
input_bindings: bindings,
|
|
601
665
|
retry_policy: claimed.definition.retry_policy,
|
|
602
666
|
created_at: createdAt,
|
|
@@ -606,6 +670,7 @@ export class RunController {
|
|
|
606
670
|
|| packet.attempt_id !== claimed.claim.attempt_id
|
|
607
671
|
|| packet.worker_session_id !== claimed.claim.worker_session_id
|
|
608
672
|
|| packet.attempt_number !== claimed.attempt.attempt_number
|
|
673
|
+
|| packet.workflow_round !== currentWorkflowRound(snapshot)
|
|
609
674
|
|| JSON.stringify(packet.input_bindings) !== JSON.stringify(bindings)
|
|
610
675
|
|| JSON.stringify(packet.execution.retry)
|
|
611
676
|
!== JSON.stringify(claimed.definition.retry_policy)) {
|
|
@@ -614,10 +679,10 @@ export class RunController {
|
|
|
614
679
|
await this.persistResolvedHandoffs(claimed.claim, bindings);
|
|
615
680
|
return packet;
|
|
616
681
|
}
|
|
617
|
-
async finalizeAttempt(claim, execution) {
|
|
682
|
+
async finalizeAttempt(claim, execution, requireUnexpiredClaim = true) {
|
|
618
683
|
while (true) {
|
|
619
684
|
const snapshot = await this.store.requireRun(claim.run_id);
|
|
620
|
-
const { task, attempt } = this.assertCurrentClaim(snapshot, claim,
|
|
685
|
+
const { task, attempt } = this.assertCurrentClaim(snapshot, claim, requireUnexpiredClaim);
|
|
621
686
|
if (attempt.phase === "terminal")
|
|
622
687
|
return snapshot;
|
|
623
688
|
if (execution.worker_session_id !== claim.worker_session_id
|
|
@@ -629,9 +694,19 @@ export class RunController {
|
|
|
629
694
|
}
|
|
630
695
|
const now = iso(this.now());
|
|
631
696
|
const runCancelling = snapshot.run.status === "cancelling";
|
|
632
|
-
const
|
|
697
|
+
const succeeded = execution.result.outcome.kind === "success";
|
|
698
|
+
const canRetryAttempt = (!runCancelling
|
|
699
|
+
&& !succeeded
|
|
633
700
|
&& retryAllowed(this.definitionByStep.get(claim.step_id).retry_policy, attempt, execution.result.outcome));
|
|
634
|
-
const
|
|
701
|
+
const inWorkflowLoop = this.workflowRetrySteps.has(claim.step_id);
|
|
702
|
+
const workflowRound = currentWorkflowRound(snapshot);
|
|
703
|
+
const canRetryWorkflow = (!runCancelling
|
|
704
|
+
&& !succeeded
|
|
705
|
+
&& !canRetryAttempt
|
|
706
|
+
&& inWorkflowLoop
|
|
707
|
+
&& this.workflowRetryLoop !== null
|
|
708
|
+
&& workflowRound <= this.workflowRetryLoop.max_retries);
|
|
709
|
+
const resultId = succeeded
|
|
635
710
|
? this.createResultId()
|
|
636
711
|
: null;
|
|
637
712
|
const result = resultId === null
|
|
@@ -642,25 +717,87 @@ export class RunController {
|
|
|
642
717
|
commit_status: "committed",
|
|
643
718
|
committed_at: now,
|
|
644
719
|
};
|
|
645
|
-
const nextState = result
|
|
646
|
-
? "succeeded"
|
|
647
|
-
: runCancelling
|
|
648
|
-
? "cancelled"
|
|
649
|
-
: canRetry
|
|
650
|
-
? "ready"
|
|
651
|
-
: "failed";
|
|
652
720
|
const terminalAttempt = {
|
|
653
721
|
...attempt,
|
|
654
722
|
phase: "terminal",
|
|
655
723
|
completed_at: execution.result.completed_at,
|
|
656
724
|
terminal_outcome: execution.result.outcome,
|
|
657
725
|
};
|
|
658
|
-
const
|
|
726
|
+
const updatedTasks = new Map();
|
|
727
|
+
let nextState;
|
|
728
|
+
let taskChangeReason = "attempt_terminal";
|
|
729
|
+
if (result && inWorkflowLoop) {
|
|
730
|
+
if (claim.step_id === this.workflowRetryLoop?.completion_step) {
|
|
731
|
+
nextState = "succeeded";
|
|
732
|
+
taskChangeReason = "workflow_round_completed";
|
|
733
|
+
for (const candidate of snapshot.tasks) {
|
|
734
|
+
if (this.workflowRetrySteps.has(candidate.step_id)
|
|
735
|
+
&& candidate.state === "round_succeeded") {
|
|
736
|
+
updatedTasks.set(candidate.step_id, {
|
|
737
|
+
...candidate,
|
|
738
|
+
state: "succeeded",
|
|
739
|
+
updated_at: now,
|
|
740
|
+
});
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
else {
|
|
745
|
+
nextState = "round_succeeded";
|
|
746
|
+
taskChangeReason = "awaiting_workflow_round_completion";
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
else if (result) {
|
|
750
|
+
nextState = "succeeded";
|
|
751
|
+
}
|
|
752
|
+
else if (runCancelling) {
|
|
753
|
+
nextState = "cancelled";
|
|
754
|
+
}
|
|
755
|
+
else if (canRetryAttempt) {
|
|
756
|
+
nextState = "ready";
|
|
757
|
+
taskChangeReason = "attempt_retry";
|
|
758
|
+
}
|
|
759
|
+
else if (canRetryWorkflow && this.workflowRetryLoop) {
|
|
760
|
+
nextState = claim.step_id === this.workflowRetryLoop.retry_from
|
|
761
|
+
? "ready"
|
|
762
|
+
: "dependency_blocked";
|
|
763
|
+
taskChangeReason = "workflow_round_retry";
|
|
764
|
+
for (const stepId of this.workflowRetryLoop.step_ids) {
|
|
765
|
+
const candidate = taskByStep(snapshot, stepId);
|
|
766
|
+
if (!candidate) {
|
|
767
|
+
throw new RunControllerError("invalid_definition", `workflow retry Step ${stepId} is missing from run ${claim.run_id}`);
|
|
768
|
+
}
|
|
769
|
+
updatedTasks.set(stepId, {
|
|
770
|
+
...candidate,
|
|
771
|
+
state: stepId === this.workflowRetryLoop.retry_from
|
|
772
|
+
? "ready"
|
|
773
|
+
: "dependency_blocked",
|
|
774
|
+
committed_result_id: null,
|
|
775
|
+
updated_at: now,
|
|
776
|
+
});
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
else {
|
|
780
|
+
nextState = "failed";
|
|
781
|
+
if (inWorkflowLoop) {
|
|
782
|
+
taskChangeReason = "workflow_retry_exhausted";
|
|
783
|
+
for (const candidate of snapshot.tasks) {
|
|
784
|
+
if (this.workflowRetrySteps.has(candidate.step_id)
|
|
785
|
+
&& candidate.state === "round_succeeded") {
|
|
786
|
+
updatedTasks.set(candidate.step_id, {
|
|
787
|
+
...candidate,
|
|
788
|
+
state: "skipped",
|
|
789
|
+
updated_at: now,
|
|
790
|
+
});
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
updatedTasks.set(claim.step_id, {
|
|
659
796
|
...task,
|
|
660
797
|
state: nextState,
|
|
661
798
|
committed_result_id: resultId,
|
|
662
799
|
updated_at: now,
|
|
663
|
-
};
|
|
800
|
+
});
|
|
664
801
|
const eventInputs = [
|
|
665
802
|
{
|
|
666
803
|
run_id: claim.run_id,
|
|
@@ -674,7 +811,8 @@ export class RunController {
|
|
|
674
811
|
payload: eventPayload({
|
|
675
812
|
outcome: execution.result.outcome.kind,
|
|
676
813
|
provider_event_count: execution.events.length,
|
|
677
|
-
retry:
|
|
814
|
+
retry: canRetryAttempt || canRetryWorkflow,
|
|
815
|
+
workflow_round: workflowRound,
|
|
678
816
|
}),
|
|
679
817
|
},
|
|
680
818
|
];
|
|
@@ -700,23 +838,83 @@ export class RunController {
|
|
|
700
838
|
idempotency_key: `claim:${claim.claim_token}:released`,
|
|
701
839
|
type: "task_claim_released",
|
|
702
840
|
occurred_at: now,
|
|
703
|
-
payload: eventPayload({
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
step_id: claim.step_id,
|
|
707
|
-
attempt_id: claim.attempt_id,
|
|
708
|
-
worker_session_id: claim.worker_session_id,
|
|
709
|
-
result_id: resultId,
|
|
710
|
-
idempotency_key: `task:${claim.step_id}:attempt:${claim.attempt_id}:${nextState}`,
|
|
711
|
-
type: "task_state_changed",
|
|
712
|
-
occurred_at: now,
|
|
713
|
-
payload: eventPayload({ from: task.state, to: nextState }),
|
|
841
|
+
payload: eventPayload({
|
|
842
|
+
terminal: !canRetryAttempt && !canRetryWorkflow,
|
|
843
|
+
}),
|
|
714
844
|
});
|
|
845
|
+
for (const updated of updatedTasks.values()) {
|
|
846
|
+
const prior = taskByStep(snapshot, updated.step_id);
|
|
847
|
+
if (!prior)
|
|
848
|
+
continue;
|
|
849
|
+
eventInputs.push({
|
|
850
|
+
run_id: claim.run_id,
|
|
851
|
+
step_id: updated.step_id,
|
|
852
|
+
attempt_id: updated.step_id === claim.step_id
|
|
853
|
+
? claim.attempt_id
|
|
854
|
+
: prior.current_attempt_id,
|
|
855
|
+
worker_session_id: updated.step_id === claim.step_id
|
|
856
|
+
? claim.worker_session_id
|
|
857
|
+
: attemptById(snapshot, prior.current_attempt_id)?.worker_session_id
|
|
858
|
+
?? null,
|
|
859
|
+
result_id: updated.committed_result_id,
|
|
860
|
+
idempotency_key: updated.step_id === claim.step_id
|
|
861
|
+
? `task:${claim.step_id}:attempt:${claim.attempt_id}:${updated.state}`
|
|
862
|
+
: `workflow:round:${workflowRound}:task:${updated.step_id}:${updated.state}`,
|
|
863
|
+
type: "task_state_changed",
|
|
864
|
+
occurred_at: now,
|
|
865
|
+
payload: eventPayload({
|
|
866
|
+
from: prior.state,
|
|
867
|
+
to: updated.state,
|
|
868
|
+
reason: taskChangeReason,
|
|
869
|
+
}),
|
|
870
|
+
});
|
|
871
|
+
}
|
|
872
|
+
if (canRetryWorkflow && this.workflowRetryLoop) {
|
|
873
|
+
const nextRound = workflowRound + 1;
|
|
874
|
+
const delayMs = workflowRetryDelayMs(this.workflowRetryLoop, workflowRound);
|
|
875
|
+
const readyAt = iso(new Date(this.now().getTime() + delayMs));
|
|
876
|
+
eventInputs.push({
|
|
877
|
+
run_id: claim.run_id,
|
|
878
|
+
step_id: this.workflowRetryLoop.retry_from,
|
|
879
|
+
attempt_id: claim.attempt_id,
|
|
880
|
+
worker_session_id: claim.worker_session_id,
|
|
881
|
+
result_id: null,
|
|
882
|
+
idempotency_key: `workflow:round:${nextRound}:advanced`,
|
|
883
|
+
type: "workflow_round_advanced",
|
|
884
|
+
occurred_at: now,
|
|
885
|
+
payload: eventPayload({
|
|
886
|
+
from_round: workflowRound,
|
|
887
|
+
to_round: nextRound,
|
|
888
|
+
retry_from: this.workflowRetryLoop.retry_from,
|
|
889
|
+
triggering_step: claim.step_id,
|
|
890
|
+
triggering_outcome: execution.result.outcome.kind,
|
|
891
|
+
ready_at: readyAt,
|
|
892
|
+
}),
|
|
893
|
+
});
|
|
894
|
+
}
|
|
895
|
+
else if (result
|
|
896
|
+
&& inWorkflowLoop
|
|
897
|
+
&& claim.step_id === this.workflowRetryLoop?.completion_step) {
|
|
898
|
+
eventInputs.push({
|
|
899
|
+
run_id: claim.run_id,
|
|
900
|
+
step_id: claim.step_id,
|
|
901
|
+
attempt_id: claim.attempt_id,
|
|
902
|
+
worker_session_id: claim.worker_session_id,
|
|
903
|
+
result_id: result.result_id,
|
|
904
|
+
idempotency_key: `workflow:round:${workflowRound}:completed`,
|
|
905
|
+
type: "workflow_round_completed",
|
|
906
|
+
occurred_at: now,
|
|
907
|
+
payload: eventPayload({
|
|
908
|
+
workflow_round: workflowRound,
|
|
909
|
+
completion_step: claim.step_id,
|
|
910
|
+
}),
|
|
911
|
+
});
|
|
912
|
+
}
|
|
715
913
|
try {
|
|
716
914
|
return (await this.store.updateRun({
|
|
717
915
|
run_id: claim.run_id,
|
|
718
916
|
expected_record_version: snapshot.record_version,
|
|
719
|
-
tasks: [
|
|
917
|
+
tasks: [...updatedTasks.values()],
|
|
720
918
|
attempts: [terminalAttempt],
|
|
721
919
|
events: this.events(snapshot, eventInputs),
|
|
722
920
|
...(result ? { results: [result] } : {}),
|
|
@@ -750,8 +948,7 @@ export class RunController {
|
|
|
750
948
|
},
|
|
751
949
|
};
|
|
752
950
|
}
|
|
753
|
-
async reclaimDeadAttempt(snapshot,
|
|
754
|
-
const now = iso(this.now());
|
|
951
|
+
async reclaimDeadAttempt(snapshot, attempt, claim) {
|
|
755
952
|
const cancelled = snapshot.run.status === "cancelling";
|
|
756
953
|
const outcome = cancelled
|
|
757
954
|
? {
|
|
@@ -766,65 +963,7 @@ export class RunController {
|
|
|
766
963
|
signal: null,
|
|
767
964
|
error: "owned worker was confirmed dead during resume",
|
|
768
965
|
};
|
|
769
|
-
|
|
770
|
-
const canRetry = !cancelled && retryAllowed(definition.retry_policy, attempt, outcome);
|
|
771
|
-
const nextState = cancelled ? "cancelled" : canRetry ? "ready" : "failed";
|
|
772
|
-
const terminalAttempt = {
|
|
773
|
-
...attempt,
|
|
774
|
-
phase: "terminal",
|
|
775
|
-
completed_at: now,
|
|
776
|
-
terminal_outcome: outcome,
|
|
777
|
-
};
|
|
778
|
-
const updatedTask = {
|
|
779
|
-
...task,
|
|
780
|
-
state: nextState,
|
|
781
|
-
updated_at: now,
|
|
782
|
-
};
|
|
783
|
-
await this.store.updateRun({
|
|
784
|
-
run_id: snapshot.run.run_id,
|
|
785
|
-
expected_record_version: snapshot.record_version,
|
|
786
|
-
tasks: [updatedTask],
|
|
787
|
-
attempts: [terminalAttempt],
|
|
788
|
-
events: this.events(snapshot, [
|
|
789
|
-
{
|
|
790
|
-
run_id: snapshot.run.run_id,
|
|
791
|
-
step_id: task.step_id,
|
|
792
|
-
attempt_id: attempt.attempt_id,
|
|
793
|
-
worker_session_id: attempt.worker_session_id,
|
|
794
|
-
result_id: null,
|
|
795
|
-
idempotency_key: `attempt:${attempt.attempt_id}:reclaimed-terminal`,
|
|
796
|
-
type: "attempt_terminal",
|
|
797
|
-
occurred_at: now,
|
|
798
|
-
payload: eventPayload({
|
|
799
|
-
outcome: outcome.kind,
|
|
800
|
-
retry: canRetry,
|
|
801
|
-
reconciliation: "dead",
|
|
802
|
-
}),
|
|
803
|
-
},
|
|
804
|
-
{
|
|
805
|
-
run_id: snapshot.run.run_id,
|
|
806
|
-
step_id: task.step_id,
|
|
807
|
-
attempt_id: attempt.attempt_id,
|
|
808
|
-
worker_session_id: attempt.worker_session_id,
|
|
809
|
-
result_id: null,
|
|
810
|
-
idempotency_key: `claim:${claim.claim_token}:reclaimed`,
|
|
811
|
-
type: "task_claim_released",
|
|
812
|
-
occurred_at: now,
|
|
813
|
-
payload: eventPayload({ expired: true, reconciled: "dead" }),
|
|
814
|
-
},
|
|
815
|
-
{
|
|
816
|
-
run_id: snapshot.run.run_id,
|
|
817
|
-
step_id: task.step_id,
|
|
818
|
-
attempt_id: attempt.attempt_id,
|
|
819
|
-
worker_session_id: attempt.worker_session_id,
|
|
820
|
-
result_id: null,
|
|
821
|
-
idempotency_key: `task:${task.step_id}:attempt:${attempt.attempt_id}:${nextState}`,
|
|
822
|
-
type: "task_state_changed",
|
|
823
|
-
occurred_at: now,
|
|
824
|
-
payload: eventPayload({ from: task.state, to: nextState }),
|
|
825
|
-
},
|
|
826
|
-
]),
|
|
827
|
-
});
|
|
966
|
+
await this.finalizeAttempt(claim, this.syntheticExecution(claim, outcome, attempt.started_at ?? iso(this.now())), false);
|
|
828
967
|
}
|
|
829
968
|
/**
|
|
830
969
|
* Resume never infers death from lease expiry alone. Reclaim is allowed only
|
|
@@ -853,7 +992,7 @@ export class RunController {
|
|
|
853
992
|
if (reconciliation !== "dead")
|
|
854
993
|
continue;
|
|
855
994
|
try {
|
|
856
|
-
await this.reclaimDeadAttempt(snapshot,
|
|
995
|
+
await this.reclaimDeadAttempt(snapshot, attempt, claim);
|
|
857
996
|
changed = true;
|
|
858
997
|
break;
|
|
859
998
|
}
|
|
@@ -882,7 +1021,9 @@ export class RunController {
|
|
|
882
1021
|
reason,
|
|
883
1022
|
};
|
|
884
1023
|
const tasks = snapshot.tasks
|
|
885
|
-
.filter((task) => (task.state === "dependency_blocked"
|
|
1024
|
+
.filter((task) => (task.state === "dependency_blocked"
|
|
1025
|
+
|| task.state === "ready"
|
|
1026
|
+
|| task.state === "round_succeeded"))
|
|
886
1027
|
.map((task) => ({
|
|
887
1028
|
...task,
|
|
888
1029
|
state: "cancelled",
|
|
@@ -10,6 +10,7 @@ import { mkdir, writeFile, readdir, readFile, rm } from "node:fs/promises";
|
|
|
10
10
|
import { join, resolve, sep } from "node:path";
|
|
11
11
|
import { getControllerKindMetadata } from "../schema/controller-registry.js";
|
|
12
12
|
import { assertSafeGeneratedName, toKebabCase } from "./agent-md.js";
|
|
13
|
+
import { resolveWorkflowVariableReferences, valueUsesArguments, workflowUsesArguments, } from "./workflow-runtime-manifest.js";
|
|
13
14
|
const SENTINEL = "<!-- intentdna:managed — do not edit manually -->";
|
|
14
15
|
function resolveContainedPath(baseDir, ...segments) {
|
|
15
16
|
const base = resolve(baseDir);
|
|
@@ -27,6 +28,7 @@ function isInteractiveRole(role) {
|
|
|
27
28
|
}
|
|
28
29
|
// ── Compile Controller → Skill ─────────────────────────────
|
|
29
30
|
export function compileControllerToSkill(controllerKey, controller, variables, workflows) {
|
|
31
|
+
const controllerVariables = variables ? resolveWorkflowVariableReferences(variables) : undefined;
|
|
30
32
|
const kindMetadata = getControllerKindMetadata(controller.kind);
|
|
31
33
|
if (!kindMetadata?.supportsSkillGeneration) {
|
|
32
34
|
throw new Error(`Unsupported controller kind: ${controller.kind}`);
|
|
@@ -194,8 +196,8 @@ export function compileControllerToSkill(controllerKey, controller, variables, w
|
|
|
194
196
|
lines.push("</Constraints>");
|
|
195
197
|
lines.push("");
|
|
196
198
|
let content = lines.join("\n") + "\n";
|
|
197
|
-
if (
|
|
198
|
-
for (const [key, value] of Object.entries(
|
|
199
|
+
if (controllerVariables) {
|
|
200
|
+
for (const [key, value] of Object.entries(controllerVariables)) {
|
|
199
201
|
content = content.replaceAll(`{{${key}}}`, value);
|
|
200
202
|
}
|
|
201
203
|
}
|
|
@@ -448,19 +450,18 @@ function workflowSkillMapEntry(skillName, dirName, plan) {
|
|
|
448
450
|
produces,
|
|
449
451
|
};
|
|
450
452
|
}
|
|
451
|
-
function inferredWorkflowAsset(ir) {
|
|
452
|
-
const sourceIds = [...new Set(ir?.source_dna_ids ?? [])]
|
|
453
|
-
.filter((sourceId) => sourceId.length > 0)
|
|
454
|
-
.filter((sourceId) => !sourceId.startsWith("species:"))
|
|
455
|
-
.filter((sourceId) => !sourceId.startsWith("enterprise:"));
|
|
456
|
-
return sourceIds.length === 1 ? sourceIds[0] : undefined;
|
|
457
|
-
}
|
|
458
453
|
export function compileWorkflowToSkill(plan, roles, ir, variables, options) {
|
|
459
454
|
const lines = [];
|
|
460
455
|
const skillName = `dna-${toKebabCase(plan.name)}`;
|
|
461
456
|
const surface = options?.surface ?? "claude_code";
|
|
462
457
|
const workflowId = plan.workflow_key ?? plan.source_workflow;
|
|
463
|
-
const
|
|
458
|
+
const skillVariables = variables ? resolveWorkflowVariableReferences(variables) : undefined;
|
|
459
|
+
const workflowVerifierSpecs = ir?.verifier_specs?.filter((spec) => spec.workflow_name === workflowId) ?? [];
|
|
460
|
+
const rolePostChecks = [...new Set(plan.steps.map((step) => step.role))]
|
|
461
|
+
.flatMap((roleName) => roles[roleName]?.post_checks ?? []);
|
|
462
|
+
const usesArguments = workflowUsesArguments(plan, skillVariables) ||
|
|
463
|
+
valueUsesArguments(workflowVerifierSpecs, skillVariables) ||
|
|
464
|
+
valueUsesArguments(rolePostChecks, skillVariables);
|
|
464
465
|
assertSafeGeneratedName(skillName, "skill name");
|
|
465
466
|
// Frontmatter
|
|
466
467
|
lines.push("---");
|
|
@@ -477,7 +478,7 @@ export function compileWorkflowToSkill(plan, roles, ir, variables, options) {
|
|
|
477
478
|
lines.push(`<!-- Compiled: ${new Date().toISOString()} -->`);
|
|
478
479
|
lines.push("");
|
|
479
480
|
// Title
|
|
480
|
-
lines.push(`# /${skillName}
|
|
481
|
+
lines.push(`# /${skillName}${usesArguments ? " <argument>" : ""}`);
|
|
481
482
|
lines.push("");
|
|
482
483
|
// Purpose
|
|
483
484
|
if (plan.description) {
|
|
@@ -489,18 +490,17 @@ export function compileWorkflowToSkill(plan, roles, ir, variables, options) {
|
|
|
489
490
|
lines.push("<Workflow_State>");
|
|
490
491
|
lines.push("At workflow start, call the MCP tool `dna_workflow_write` before any step or hook-triggering action so hook verifier evidence is attributed to this workflow instead of `*:direct`.");
|
|
491
492
|
lines.push(`Use workflow id \`${workflowId}\`.`);
|
|
492
|
-
|
|
493
|
-
|
|
493
|
+
lines.push("The MCP server initializes workflow_asset and resolved_variables from the compiled workflow runtime manifest. Do not submit either field from Skill text.");
|
|
494
|
+
const firstStep = plan.steps[0];
|
|
495
|
+
lines.push(`Initial state write: workflow=${workflowId}, current_step=${firstStep.id}, current_role=${firstStep.role}, iteration=1, active=true.`);
|
|
496
|
+
if (usesArguments) {
|
|
497
|
+
lines.push("Record the invocation argument as inputs.ARGUMENTS so handoff artifact paths like $ARGUMENTS can be resolved deterministically.");
|
|
494
498
|
}
|
|
495
499
|
else {
|
|
496
|
-
lines.push("
|
|
500
|
+
lines.push("This workflow has no invocation argument; omit inputs.ARGUMENTS from workflow state.");
|
|
497
501
|
}
|
|
498
|
-
|
|
499
|
-
lines.push(
|
|
500
|
-
lines.push("Record the invocation argument as inputs.ARGUMENTS so handoff artifact paths like $ARGUMENTS can be resolved deterministically.");
|
|
501
|
-
lines.push("If template variables are shown below, persist their resolved values as resolved_variables.");
|
|
502
|
-
lines.push("Before each workflow step, call `dna_workflow_write` again with workflow, workflow_asset only when safely inferred above, current_step, current_role, iteration, active=true, inputs.ARGUMENTS, and resolved_variables.");
|
|
503
|
-
lines.push("At workflow completion or terminal failure, call `dna_workflow_write` with active=false using the same workflow id and safe workflow_asset value.");
|
|
502
|
+
lines.push(`Before each workflow step, call \`dna_workflow_write\` again with workflow, current_step, current_role, iteration, active=true${usesArguments ? ", and inputs.ARGUMENTS" : ""}.`);
|
|
503
|
+
lines.push("At workflow completion or terminal failure, call `dna_workflow_write` with active=false using the same workflow id.");
|
|
504
504
|
lines.push("</Workflow_State>");
|
|
505
505
|
lines.push("");
|
|
506
506
|
// Required Context — context files that must be read before any work
|
|
@@ -627,7 +627,7 @@ export function compileWorkflowToSkill(plan, roles, ir, variables, options) {
|
|
|
627
627
|
const agentPrompt = escapePrompt(promptParts.join(" "));
|
|
628
628
|
lines.push(`${stepNumber}. **${step.id}**${optional}`);
|
|
629
629
|
lines.push(` ${step.description}${runIf}`);
|
|
630
|
-
lines.push(` Before this step, call \`dna_workflow_write\` with workflow=${workflowId}, current_step=${step.id}, current_role=${step.role}, iteration=<current iteration>, active=true
|
|
630
|
+
lines.push(` Before this step, call \`dna_workflow_write\` with workflow=${workflowId}, current_step=${step.id}, current_role=${step.role}, iteration=<current iteration>, active=true${usesArguments ? ", and inputs.ARGUMENTS" : ""}.`);
|
|
631
631
|
lines.push("");
|
|
632
632
|
if (humanOwned) {
|
|
633
633
|
lines.push(" **Human-owned gate (`model: human`)**");
|
|
@@ -813,28 +813,17 @@ export function compileWorkflowToSkill(plan, roles, ir, variables, options) {
|
|
|
813
813
|
lines.push("</Handoff>");
|
|
814
814
|
lines.push("");
|
|
815
815
|
}
|
|
816
|
-
// Variables — collect {{var_name}} references from the whole plan
|
|
817
|
-
const varRefs = collectVariableRefs(plan);
|
|
818
|
-
if (varRefs.size > 0) {
|
|
819
|
-
lines.push("<Variables>");
|
|
820
|
-
for (const varName of varRefs) {
|
|
821
|
-
const value = variables?.[varName];
|
|
822
|
-
lines.push(`- \`{{${varName}}}\`: ${value ?? varName}`);
|
|
823
|
-
}
|
|
824
|
-
lines.push("</Variables>");
|
|
825
|
-
lines.push("");
|
|
826
|
-
}
|
|
827
816
|
// Workflow Boundary — prevent cross-workflow execution
|
|
828
817
|
lines.push("<Workflow_Boundary>");
|
|
829
|
-
lines.push(`Before reporting final success, terminal failure, or exhaustion, call \`dna_workflow_write\` with workflow=${workflowId}, current_step=workflow_complete, current_role=workflow, active=false
|
|
818
|
+
lines.push(`Before reporting final success, terminal failure, or exhaustion, call \`dna_workflow_write\` with workflow=${workflowId}, current_step=workflow_complete, current_role=workflow, active=false.`);
|
|
830
819
|
lines.push("This workflow is COMPLETE. Do NOT proceed to any other workflow.");
|
|
831
820
|
lines.push("Report your results and STOP. The user will decide the next step.");
|
|
832
821
|
lines.push("</Workflow_Boundary>");
|
|
833
822
|
lines.push("");
|
|
834
823
|
let content = lines.join("\n") + "\n";
|
|
835
824
|
// Substitute project variables: {{var_name}} → value
|
|
836
|
-
if (
|
|
837
|
-
for (const [key, value] of Object.entries(
|
|
825
|
+
if (skillVariables) {
|
|
826
|
+
for (const [key, value] of Object.entries(skillVariables)) {
|
|
838
827
|
content = content.replaceAll(`{{${key}}}`, value);
|
|
839
828
|
}
|
|
840
829
|
}
|
|
@@ -847,24 +836,6 @@ export function compileWorkflowToSkill(plan, roles, ir, variables, options) {
|
|
|
847
836
|
mapEntry: workflowSkillMapEntry(skillName, dirName, plan),
|
|
848
837
|
});
|
|
849
838
|
}
|
|
850
|
-
/** Collect all {{var_name}} references from a workflow plan. */
|
|
851
|
-
function collectVariableRefs(plan) {
|
|
852
|
-
const refs = new Set();
|
|
853
|
-
const RE = /\{\{(\w+)\}\}/g;
|
|
854
|
-
const scan = (s) => {
|
|
855
|
-
if (!s)
|
|
856
|
-
return;
|
|
857
|
-
for (const m of s.matchAll(RE))
|
|
858
|
-
refs.add(m[1]);
|
|
859
|
-
};
|
|
860
|
-
scan(plan.name);
|
|
861
|
-
scan(plan.description);
|
|
862
|
-
for (const step of plan.steps) {
|
|
863
|
-
scan(step.description);
|
|
864
|
-
scan(step.prompt);
|
|
865
|
-
}
|
|
866
|
-
return refs;
|
|
867
|
-
}
|
|
868
839
|
// ── File Operations ────────────────────────────────────────
|
|
869
840
|
export async function writeSkillFiles(results, outputDir) {
|
|
870
841
|
const written = [];
|