@gtrabanco/agentic-workflow-schema 3.1.0 → 3.2.0
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.es.md +27 -0
- package/README.md +25 -0
- package/dist/index.d.ts +90 -0
- package/dist/index.js +402 -0
- package/package.json +1 -1
package/README.es.md
CHANGED
|
@@ -155,3 +155,30 @@ publicado. Los campos aditivos son minor; arreglos de parser, documentación o
|
|
|
155
155
|
implementación son patch. Consulta la
|
|
156
156
|
[orquestación programática](../../docs/workflow/ORCHESTRATION.es.md) para el
|
|
157
157
|
protocolo de driver.
|
|
158
|
+
|
|
159
|
+
## Decisor de transición del workflow
|
|
160
|
+
|
|
161
|
+
Exporta `decideWorkflowAction(input)` — una función pura y determinista que
|
|
162
|
+
combina un `WorkflowSnapshot v1`, el último `SkillOutcome v1` validado y una
|
|
163
|
+
`WorkflowDecisionPolicy` provista por el driver para decidir si puede invocar
|
|
164
|
+
la siguiente habilidad, debe refrescar con `workflow-status` o debe detenerse.
|
|
165
|
+
|
|
166
|
+
```ts
|
|
167
|
+
function decideWorkflowAction(input: WorkflowDecisionInput): WorkflowActionDecision
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
- **Elisión segura:** cuando el snapshot está congelado y la habilidad →
|
|
171
|
+
siguiente intento está probada por la tabla congelada
|
|
172
|
+
`WORKFLOW_TRANSITION_TABLE`, el driver invoca directamente sin llamar a
|
|
173
|
+
`workflow-status`.
|
|
174
|
+
- **Respaldo obligatorio:** en evidencia ausente, revisión obsoleta, estado
|
|
175
|
+
bloqueado, contradicciones, efectos no autorizados o cualquier transición
|
|
176
|
+
no reconocida, la función retorna `sense` (llamar `workflow-status`) o
|
|
177
|
+
`stop` (terminar).
|
|
178
|
+
|
|
179
|
+
**Puntos obligatorios de sensor:** ejecución inicial (sin outcome), ejecución
|
|
180
|
+
recuperada (revisión obsoleta), snapshot desconocido o contradicho, siguiente
|
|
181
|
+
intento no reconocido, y cualquier transición no en la tabla cerrada.
|
|
182
|
+
|
|
183
|
+
Consulta el [SPEC](../features/24-workflow-transition-decider/SPEC.md) para el
|
|
184
|
+
diseño completo, tablas de transición y vocabulario de códigos de razón.
|
package/README.md
CHANGED
|
@@ -145,6 +145,31 @@ It refuses a nonzero issue count without identities, an unmatched unit id, and
|
|
|
145
145
|
unstructured prose. The compatibility diagnostics make every repair visible to
|
|
146
146
|
the driver.
|
|
147
147
|
|
|
148
|
+
## Workflow transition decider
|
|
149
|
+
|
|
150
|
+
Export `decideWorkflowAction(input)` — a pure, deterministic function that
|
|
151
|
+
combines a `WorkflowSnapshot v1`, the last validated `SkillOutcome v1`, and a
|
|
152
|
+
caller-provided `WorkflowDecisionPolicy` to decide whether a headless driver
|
|
153
|
+
may invoke the next skill, must refresh with `workflow-status`, or must stop.
|
|
154
|
+
|
|
155
|
+
```ts
|
|
156
|
+
function decideWorkflowAction(input: WorkflowDecisionInput): WorkflowActionDecision
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
- **Safe elision:** when the snapshot is frozen and the last skill → next intent
|
|
160
|
+
is proven by the frozen `WORKFLOW_TRANSITION_TABLE`, the driver invokes
|
|
161
|
+
directly without calling `workflow-status`.
|
|
162
|
+
- **Mandatory fallback:** on missing evidence, stale revision, blocked status,
|
|
163
|
+
contradictions, unauthorized effects, or any unrecognized transition, the
|
|
164
|
+
function returns `sense` (call `workflow-status`) or `stop` (terminate).
|
|
165
|
+
|
|
166
|
+
**Mandatory sensor points:** initial run (no outcome), recovered run (stale
|
|
167
|
+
revision), snapshot state unknown or contradicted, unrecognized next intent,
|
|
168
|
+
and any transition not in the closed table.
|
|
169
|
+
|
|
170
|
+
See [SPEC](../features/24-workflow-transition-decider/SPEC.md) for the full
|
|
171
|
+
design, transition tables, and reason-code vocabulary.
|
|
172
|
+
|
|
148
173
|
Package major versions signal a breaking change to any published contract.
|
|
149
174
|
Additive contract fields are minor; parser, documentation, or implementation
|
|
150
175
|
fixes are patch releases. See
|
package/dist/index.d.ts
CHANGED
|
@@ -173,6 +173,96 @@ export type StrictEnvelopeParseResult = {
|
|
|
173
173
|
export declare function parseEnvelopeV2Strict(text: string): StrictEnvelopeParseResult;
|
|
174
174
|
export type WorkflowIntent = "init-workspace" | "status" | "discover-repository-state" | "resolve-repository-state" | "design-feature" | "plan-feature" | "plan-fix" | "triage-issue" | "execute-phase" | "review-change" | "loop-review-fold" | "audit-pr" | "merge" | "ask-human" | "stop" | "none";
|
|
175
175
|
export declare const WORKFLOW_INTENTS: readonly WorkflowIntent[];
|
|
176
|
+
/** Sense reason codes: transition cannot proceed without more sensor input. */
|
|
177
|
+
export declare const WORKFLOW_DECISION_SENSE_CODES: readonly ["sense-initial", "sense-stale-revision", "sense-missing-evidence", "sense-unknown-state", "sense-unlisted-transition"];
|
|
178
|
+
export type WorkflowDecisionSenseReason = (typeof WORKFLOW_DECISION_SENSE_CODES)[number];
|
|
179
|
+
/** Stop reason codes: the transition is explicitly blocked or must terminate. */
|
|
180
|
+
export declare const WORKFLOW_DECISION_STOP_CODES: readonly ["stop-blocked", "stop-needs-input", "stop-failed", "stop-contradiction", "stop-policy-denied", "stop-forbidden-transition"];
|
|
181
|
+
export type WorkflowDecisionStopReason = (typeof WORKFLOW_DECISION_STOP_CODES)[number];
|
|
182
|
+
/** Invoke reason codes: transition is proven and allowed. */
|
|
183
|
+
export declare const WORKFLOW_DECISION_INVOKE_CODES: readonly ["invoke-proven-transition"];
|
|
184
|
+
export type WorkflowDecisionInvokeReason = (typeof WORKFLOW_DECISION_INVOKE_CODES)[number];
|
|
185
|
+
export type WorkflowDecisionReasonCode = WorkflowDecisionSenseReason | WorkflowDecisionStopReason | WorkflowDecisionInvokeReason;
|
|
186
|
+
/** Policy a caller provides to control the transition decision. */
|
|
187
|
+
export interface WorkflowDecisionPolicy {
|
|
188
|
+
/** Intents the caller is permitted to invoke. */
|
|
189
|
+
readonly allowedIntents: readonly WorkflowIntent[];
|
|
190
|
+
/** Whether the caller has forge-write authorization. */
|
|
191
|
+
readonly forgeWriteAuthorized: boolean;
|
|
192
|
+
}
|
|
193
|
+
/** Input to the transition decision function. */
|
|
194
|
+
export interface WorkflowDecisionInput {
|
|
195
|
+
/** A validated WorkflowSnapshot v1. */
|
|
196
|
+
readonly snapshot: WorkflowSnapshot;
|
|
197
|
+
/** The last validated SkillOutcome v1, or null. */
|
|
198
|
+
readonly lastOutcome: SkillOutcome | null;
|
|
199
|
+
/** The revision at which the last outcome was recorded. */
|
|
200
|
+
readonly lastOutcomeSourceRevision: string | null;
|
|
201
|
+
/** Closed caller policy governing what transitions are permitted. */
|
|
202
|
+
readonly policy: WorkflowDecisionPolicy;
|
|
203
|
+
}
|
|
204
|
+
/** Intent values that may be directly invoked (excludes non-invocation intents). */
|
|
205
|
+
export type WorkflowInvocableIntent = Exclude<WorkflowIntent, "status" | "ask-human" | "stop" | "none">;
|
|
206
|
+
export type WorkflowActionDecision = {
|
|
207
|
+
readonly kind: "invoke";
|
|
208
|
+
readonly intent: WorkflowInvocableIntent;
|
|
209
|
+
readonly targets: readonly string[];
|
|
210
|
+
readonly reasonCode: "invoke-proven-transition";
|
|
211
|
+
readonly evidenceRefs: readonly string[];
|
|
212
|
+
readonly detail: string;
|
|
213
|
+
} | {
|
|
214
|
+
readonly kind: "sense";
|
|
215
|
+
readonly intent: "status";
|
|
216
|
+
readonly targets: readonly [];
|
|
217
|
+
readonly reasonCode: WorkflowDecisionSenseReason;
|
|
218
|
+
readonly evidenceRefs: readonly string[];
|
|
219
|
+
readonly detail: string;
|
|
220
|
+
} | {
|
|
221
|
+
readonly kind: "stop";
|
|
222
|
+
readonly intent: "ask-human" | "stop";
|
|
223
|
+
readonly targets: readonly string[];
|
|
224
|
+
readonly reasonCode: WorkflowDecisionStopReason;
|
|
225
|
+
readonly evidenceRefs: readonly string[];
|
|
226
|
+
readonly detail: string;
|
|
227
|
+
};
|
|
228
|
+
/** One row of the direct-invocation transition table. */
|
|
229
|
+
export interface WorkflowTransitionTableRow {
|
|
230
|
+
/** The last validated skill / workflow intent. */
|
|
231
|
+
readonly key: WorkflowIntent;
|
|
232
|
+
/** Allowed next intents (may be empty, or contain a single literal "*" for wildcard). */
|
|
233
|
+
readonly allowed: readonly string[];
|
|
234
|
+
/** Description of the row conditions (arity, identity, state constraints). */
|
|
235
|
+
readonly condition: string;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Frozen, versioned direct-invocation transition table.
|
|
239
|
+
*
|
|
240
|
+
* Maps each last-validated skill to its allowed next intents. Rows whose
|
|
241
|
+
* `allowed` array contains a literal "frozen" permit transitions only when
|
|
242
|
+
* the snapshot repository state is "frozen"; rows with an empty array
|
|
243
|
+
* explicitly forbid any transition (return sense/stop rather than invoke).
|
|
244
|
+
*
|
|
245
|
+
* Derived condition semantics (from the Design):
|
|
246
|
+
* none → sense-initial
|
|
247
|
+
* init-workspace → exactly discover-repository-state
|
|
248
|
+
* workflow-status → broad set of planning/execution skills
|
|
249
|
+
* discover-repository-state → row allowed iff snapshot.state === "frozen"
|
|
250
|
+
* resolve-repository-state → row allowed iff snapshot.contradictions.length > 0
|
|
251
|
+
* design-feature, plan-feature → 0..n allowed, each must be a plan/execute skill
|
|
252
|
+
* plan-fix → exactly 1, must be triage-issue
|
|
253
|
+
* triage-issue → 1..n allowed, each must be an issue identity string
|
|
254
|
+
* init-workspace, discover-repository-state → 0 allowed → stop-forbidden-transition
|
|
255
|
+
* resolve-repository-state → each allowed must match a contradiction field
|
|
256
|
+
* merge → exactly 1, must be the PR identity from audit-pr
|
|
257
|
+
*/
|
|
258
|
+
export declare const WORKFLOW_TRANSITION_TABLE: readonly WorkflowTransitionTableRow[];
|
|
259
|
+
/**
|
|
260
|
+
* Decide whether a headless consumer may invoke the next skill, must refresh
|
|
261
|
+
* with workflow-status, or must stop.
|
|
262
|
+
*
|
|
263
|
+
* Pure, deterministic, fail-closed — no I/O, no randomness, no locale.
|
|
264
|
+
*/
|
|
265
|
+
export declare function decideWorkflowAction(input: WorkflowDecisionInput): WorkflowActionDecision;
|
|
176
266
|
/** Role a built-in skill plays in the workflow pipeline. */
|
|
177
267
|
export declare const SKILL_ROLES: readonly ["sensor", "planner", "executor", "reviewer", "auditor", "publisher"];
|
|
178
268
|
export type SkillRole = (typeof SKILL_ROLES)[number];
|
package/dist/index.js
CHANGED
|
@@ -445,6 +445,408 @@ export const WORKFLOW_INTENTS = [
|
|
|
445
445
|
"none",
|
|
446
446
|
];
|
|
447
447
|
// ---------------------------------------------------------------------------
|
|
448
|
+
// Workflow transition decider — reason codes, decision types, transition table
|
|
449
|
+
// ---------------------------------------------------------------------------
|
|
450
|
+
/** Sense reason codes: transition cannot proceed without more sensor input. */
|
|
451
|
+
export const WORKFLOW_DECISION_SENSE_CODES = Object.freeze([
|
|
452
|
+
"sense-initial",
|
|
453
|
+
"sense-stale-revision",
|
|
454
|
+
"sense-missing-evidence",
|
|
455
|
+
"sense-unknown-state",
|
|
456
|
+
"sense-unlisted-transition",
|
|
457
|
+
]);
|
|
458
|
+
/** Stop reason codes: the transition is explicitly blocked or must terminate. */
|
|
459
|
+
export const WORKFLOW_DECISION_STOP_CODES = Object.freeze([
|
|
460
|
+
"stop-blocked",
|
|
461
|
+
"stop-needs-input",
|
|
462
|
+
"stop-failed",
|
|
463
|
+
"stop-contradiction",
|
|
464
|
+
"stop-policy-denied",
|
|
465
|
+
"stop-forbidden-transition",
|
|
466
|
+
]);
|
|
467
|
+
/** Invoke reason codes: transition is proven and allowed. */
|
|
468
|
+
export const WORKFLOW_DECISION_INVOKE_CODES = Object.freeze([
|
|
469
|
+
"invoke-proven-transition",
|
|
470
|
+
]);
|
|
471
|
+
/**
|
|
472
|
+
* Frozen, versioned direct-invocation transition table.
|
|
473
|
+
*
|
|
474
|
+
* Maps each last-validated skill to its allowed next intents. Rows whose
|
|
475
|
+
* `allowed` array contains a literal "frozen" permit transitions only when
|
|
476
|
+
* the snapshot repository state is "frozen"; rows with an empty array
|
|
477
|
+
* explicitly forbid any transition (return sense/stop rather than invoke).
|
|
478
|
+
*
|
|
479
|
+
* Derived condition semantics (from the Design):
|
|
480
|
+
* none → sense-initial
|
|
481
|
+
* init-workspace → exactly discover-repository-state
|
|
482
|
+
* workflow-status → broad set of planning/execution skills
|
|
483
|
+
* discover-repository-state → row allowed iff snapshot.state === "frozen"
|
|
484
|
+
* resolve-repository-state → row allowed iff snapshot.contradictions.length > 0
|
|
485
|
+
* design-feature, plan-feature → 0..n allowed, each must be a plan/execute skill
|
|
486
|
+
* plan-fix → exactly 1, must be triage-issue
|
|
487
|
+
* triage-issue → 1..n allowed, each must be an issue identity string
|
|
488
|
+
* init-workspace, discover-repository-state → 0 allowed → stop-forbidden-transition
|
|
489
|
+
* resolve-repository-state → each allowed must match a contradiction field
|
|
490
|
+
* merge → exactly 1, must be the PR identity from audit-pr
|
|
491
|
+
*/
|
|
492
|
+
export const WORKFLOW_TRANSITION_TABLE = Object.freeze([
|
|
493
|
+
// Last skill = none → no transition possible
|
|
494
|
+
{
|
|
495
|
+
key: "none",
|
|
496
|
+
allowed: [],
|
|
497
|
+
condition: "no last validated skill; return sense-initial",
|
|
498
|
+
},
|
|
499
|
+
// init-workspace → discover-repository-state only
|
|
500
|
+
{
|
|
501
|
+
key: "init-workspace",
|
|
502
|
+
allowed: ["discover-repository-state"],
|
|
503
|
+
condition: "exactly 1 target; any other target → stop-forbidden-transition",
|
|
504
|
+
},
|
|
505
|
+
// status → broad planning and execution set
|
|
506
|
+
{
|
|
507
|
+
key: "status",
|
|
508
|
+
allowed: [
|
|
509
|
+
"init-workspace",
|
|
510
|
+
"discover-repository-state",
|
|
511
|
+
"resolve-repository-state",
|
|
512
|
+
"design-feature",
|
|
513
|
+
"plan-feature",
|
|
514
|
+
"plan-fix",
|
|
515
|
+
"triage-issue",
|
|
516
|
+
"execute-phase",
|
|
517
|
+
"review-change",
|
|
518
|
+
"loop-review-fold",
|
|
519
|
+
"audit-pr",
|
|
520
|
+
"ask-human",
|
|
521
|
+
"stop",
|
|
522
|
+
],
|
|
523
|
+
condition: "all allowed intents after status",
|
|
524
|
+
},
|
|
525
|
+
// discover-repository-state → planning allowed only when repo is frozen
|
|
526
|
+
{
|
|
527
|
+
key: "discover-repository-state",
|
|
528
|
+
allowed: [
|
|
529
|
+
"resolve-repository-state",
|
|
530
|
+
"design-feature",
|
|
531
|
+
"plan-feature",
|
|
532
|
+
"plan-fix",
|
|
533
|
+
"triage-issue",
|
|
534
|
+
"execute-phase",
|
|
535
|
+
"review-change",
|
|
536
|
+
"loop-review-fold",
|
|
537
|
+
"audit-pr",
|
|
538
|
+
"ask-human",
|
|
539
|
+
"stop",
|
|
540
|
+
],
|
|
541
|
+
condition: "row allowed only when snapshot.repositoryState === 'frozen';"
|
|
542
|
+
+ " any target when state is not frozen → sense-missing-evidence",
|
|
543
|
+
},
|
|
544
|
+
// resolve-repository-state → contradiction targets only
|
|
545
|
+
{
|
|
546
|
+
key: "resolve-repository-state",
|
|
547
|
+
allowed: ["resolve-repository-state"],
|
|
548
|
+
condition: "0..n allowed, each === a snapshot contradiction field identity;"
|
|
549
|
+
+ " non-contradiction target → stop-forbidden-transition",
|
|
550
|
+
},
|
|
551
|
+
// design-feature → next roadmap unit or the active unit / named dependency
|
|
552
|
+
{
|
|
553
|
+
key: "design-feature",
|
|
554
|
+
allowed: [
|
|
555
|
+
"plan-feature",
|
|
556
|
+
"plan-fix",
|
|
557
|
+
"triage-issue",
|
|
558
|
+
"execute-phase",
|
|
559
|
+
"review-change",
|
|
560
|
+
"loop-review-fold",
|
|
561
|
+
"audit-pr",
|
|
562
|
+
"ask-human",
|
|
563
|
+
"stop",
|
|
564
|
+
],
|
|
565
|
+
condition: "0..n allowed, each must be the next roadmap unit, the active unit id,"
|
|
566
|
+
+ " or the named dependency unit recorded by the last outcome;"
|
|
567
|
+
+ " non-allowed target → stop-forbidden-transition",
|
|
568
|
+
},
|
|
569
|
+
// plan-feature → active or dependency unit, max 1
|
|
570
|
+
{
|
|
571
|
+
key: "plan-feature",
|
|
572
|
+
allowed: [
|
|
573
|
+
"triage-issue",
|
|
574
|
+
"execute-phase",
|
|
575
|
+
"review-change",
|
|
576
|
+
"loop-review-fold",
|
|
577
|
+
"audit-pr",
|
|
578
|
+
"ask-human",
|
|
579
|
+
"stop",
|
|
580
|
+
],
|
|
581
|
+
condition: "0..1 allowed; 0 → next roadmap unit; 1 → active unit id or named dependency;"
|
|
582
|
+
+ ">1 → stop-forbidden-transition",
|
|
583
|
+
},
|
|
584
|
+
// plan-fix → triage-issue only, exactly 1
|
|
585
|
+
{
|
|
586
|
+
key: "plan-fix",
|
|
587
|
+
allowed: ["triage-issue"],
|
|
588
|
+
condition: "exactly 1 target (the issue identity); 0 → sense-missing-evidence;"
|
|
589
|
+
+ ">1 → stop-forbidden-transition",
|
|
590
|
+
},
|
|
591
|
+
// triage-issue → issue identities, 1..n
|
|
592
|
+
{
|
|
593
|
+
key: "triage-issue",
|
|
594
|
+
allowed: [
|
|
595
|
+
"execute-phase",
|
|
596
|
+
"review-change",
|
|
597
|
+
"loop-review-fold",
|
|
598
|
+
"audit-pr",
|
|
599
|
+
"ask-human",
|
|
600
|
+
"stop",
|
|
601
|
+
],
|
|
602
|
+
condition: "1..n allowed, each must be an issue identity recorded by the last outcome;"
|
|
603
|
+
+ " 0 → sense-missing-evidence",
|
|
604
|
+
},
|
|
605
|
+
// execute-phase → planning and execution, max 1
|
|
606
|
+
{
|
|
607
|
+
key: "execute-phase",
|
|
608
|
+
allowed: [
|
|
609
|
+
"design-feature",
|
|
610
|
+
"plan-feature",
|
|
611
|
+
"plan-fix",
|
|
612
|
+
"triage-issue",
|
|
613
|
+
"review-change",
|
|
614
|
+
"loop-review-fold",
|
|
615
|
+
"audit-pr",
|
|
616
|
+
"ask-human",
|
|
617
|
+
"stop",
|
|
618
|
+
],
|
|
619
|
+
condition: "0..1 allowed; each must be a plan/execute skill or ask-human/stop;"
|
|
620
|
+
+ ">1 → stop-forbidden-transition",
|
|
621
|
+
},
|
|
622
|
+
// review-change → planning and execution
|
|
623
|
+
{
|
|
624
|
+
key: "review-change",
|
|
625
|
+
allowed: [
|
|
626
|
+
"plan-feature",
|
|
627
|
+
"plan-fix",
|
|
628
|
+
"triage-issue",
|
|
629
|
+
"execute-phase",
|
|
630
|
+
"review-change",
|
|
631
|
+
"loop-review-fold",
|
|
632
|
+
"audit-pr",
|
|
633
|
+
"ask-human",
|
|
634
|
+
"stop",
|
|
635
|
+
],
|
|
636
|
+
condition: "0..n allowed, each must be a plan/execute/review skill or ask-human/stop;"
|
|
637
|
+
+ " non-allowed target → stop-forbidden-transition",
|
|
638
|
+
},
|
|
639
|
+
// loop-review-fold → planning and execution
|
|
640
|
+
{
|
|
641
|
+
key: "loop-review-fold",
|
|
642
|
+
allowed: [
|
|
643
|
+
"plan-feature",
|
|
644
|
+
"plan-fix",
|
|
645
|
+
"triage-issue",
|
|
646
|
+
"execute-phase",
|
|
647
|
+
"review-change",
|
|
648
|
+
"loop-review-fold",
|
|
649
|
+
"audit-pr",
|
|
650
|
+
"ask-human",
|
|
651
|
+
"stop",
|
|
652
|
+
],
|
|
653
|
+
condition: "0..n allowed, each must be a plan/execute/review skill or ask-human/stop;"
|
|
654
|
+
+ " non-allowed target → stop-forbidden-transition",
|
|
655
|
+
},
|
|
656
|
+
// audit-pr → merge, execute-phase, or stop
|
|
657
|
+
{
|
|
658
|
+
key: "audit-pr",
|
|
659
|
+
allowed: ["merge", "execute-phase", "ask-human", "stop"],
|
|
660
|
+
condition: "exactly 1 allowed: merge, execute-phase, ask-human, or stop;"
|
|
661
|
+
+ ">1 → stop-forbidden-transition",
|
|
662
|
+
},
|
|
663
|
+
// merge → none (end of pipeline)
|
|
664
|
+
{
|
|
665
|
+
key: "merge",
|
|
666
|
+
allowed: [],
|
|
667
|
+
condition: "merge is the terminal action; no allowed transitions;"
|
|
668
|
+
+ " any target → stop-forbidden-transition",
|
|
669
|
+
},
|
|
670
|
+
]);
|
|
671
|
+
// ---------------------------------------------------------------------------
|
|
672
|
+
// Workflow transition decider — decideWorkflowAction pipeline
|
|
673
|
+
// ---------------------------------------------------------------------------
|
|
674
|
+
/** Build evidence refs from snapshot provenance and contradictions. */
|
|
675
|
+
function buildEvidenceRefs(snapshot, lastOutcome) {
|
|
676
|
+
const refs = [];
|
|
677
|
+
for (const p of snapshot.provenance) {
|
|
678
|
+
refs.push(`${p.field}@${p.source}:${p.line}`);
|
|
679
|
+
}
|
|
680
|
+
for (const c of snapshot.contradictions) {
|
|
681
|
+
refs.push(`contradiction:${c.field}`);
|
|
682
|
+
}
|
|
683
|
+
if (lastOutcome && lastOutcome.evidence_refs.length > 0) {
|
|
684
|
+
refs.push(...lastOutcome.evidence_refs);
|
|
685
|
+
}
|
|
686
|
+
return refs;
|
|
687
|
+
}
|
|
688
|
+
/** Check effect authorization: the target skill must declare at least one effect.
|
|
689
|
+
* Built-in terminal actions without a capability profile are allowed.
|
|
690
|
+
*/
|
|
691
|
+
function checkEffectAuth(intent) {
|
|
692
|
+
const profile = workflowSkillProfile(intent);
|
|
693
|
+
if (profile === undefined)
|
|
694
|
+
return true; // no profile → allowed (built-in terminal)
|
|
695
|
+
return profile.capabilities !== undefined && profile.capabilities.effects.length > 0;
|
|
696
|
+
}
|
|
697
|
+
/** Check evidence authorization: all required evidence must be present.
|
|
698
|
+
* Intents without a capability profile are allowed (no required evidence).
|
|
699
|
+
*/
|
|
700
|
+
function checkEvidenceAuth(intent, evidenceRefs) {
|
|
701
|
+
const profile = workflowSkillProfile(intent);
|
|
702
|
+
if (profile === undefined)
|
|
703
|
+
return true; // no profile → allowed
|
|
704
|
+
const required = profile.capabilities?.requiredEvidence;
|
|
705
|
+
if (required === undefined || required.length === 0)
|
|
706
|
+
return true;
|
|
707
|
+
for (const req of required) {
|
|
708
|
+
if (!evidenceRefs.includes(req))
|
|
709
|
+
return false;
|
|
710
|
+
}
|
|
711
|
+
return true;
|
|
712
|
+
}
|
|
713
|
+
/** Policy gate: check allowed intents and forge-write authorization. */
|
|
714
|
+
function checkPolicyGate(intent, policy) {
|
|
715
|
+
if (!policy.allowedIntents.includes(intent))
|
|
716
|
+
return false;
|
|
717
|
+
if (policy.forgeWriteAuthorized === false && intent === "merge")
|
|
718
|
+
return false;
|
|
719
|
+
return true;
|
|
720
|
+
}
|
|
721
|
+
/**
|
|
722
|
+
* Decide whether a headless consumer may invoke the next skill, must refresh
|
|
723
|
+
* with workflow-status, or must stop.
|
|
724
|
+
*
|
|
725
|
+
* Pure, deterministic, fail-closed — no I/O, no randomness, no locale.
|
|
726
|
+
*/
|
|
727
|
+
export function decideWorkflowAction(input) {
|
|
728
|
+
// Defensive: malformed input never throws
|
|
729
|
+
if (typeof input !== "object" || input === null ||
|
|
730
|
+
!("snapshot" in input) || !("lastOutcome" in input) || !("policy" in input)) {
|
|
731
|
+
return { kind: "sense", intent: "status", targets: [], reasonCode: "sense-missing-evidence", evidenceRefs: [], detail: "malformed input" };
|
|
732
|
+
}
|
|
733
|
+
const policy = input.policy;
|
|
734
|
+
if (typeof policy !== "object" || policy === null || !("allowedIntents" in policy) || !("forgeWriteAuthorized" in policy)) {
|
|
735
|
+
return { kind: "stop", intent: "stop", targets: [], reasonCode: "stop-policy-denied", evidenceRefs: [], detail: "malformed policy" };
|
|
736
|
+
}
|
|
737
|
+
const typedPolicy = policy;
|
|
738
|
+
// Validate snapshot
|
|
739
|
+
const snapshotResult = validateWorkflowSnapshotV1(input.snapshot);
|
|
740
|
+
if (!snapshotResult.ok) {
|
|
741
|
+
return { kind: "sense", intent: "status", targets: [], reasonCode: "sense-missing-evidence", evidenceRefs: [], detail: `malformed snapshot: ${snapshotResult.errors.join(", ")}` };
|
|
742
|
+
}
|
|
743
|
+
const snapshot = snapshotResult.snapshot;
|
|
744
|
+
// Initial: no last outcome
|
|
745
|
+
if (input.lastOutcome === null) {
|
|
746
|
+
return { kind: "sense", intent: "status", targets: [], reasonCode: "sense-initial", evidenceRefs: [], detail: "no last validated outcome" };
|
|
747
|
+
}
|
|
748
|
+
// Freshness: stale revision
|
|
749
|
+
if (input.lastOutcomeSourceRevision !== null &&
|
|
750
|
+
snapshot.sourceRevision !== input.lastOutcomeSourceRevision) {
|
|
751
|
+
return { kind: "sense", intent: "status", targets: [], reasonCode: "sense-stale-revision", evidenceRefs: [], detail: `outcome from revision ${input.lastOutcomeSourceRevision} does not match current ${snapshot.sourceRevision}` };
|
|
752
|
+
}
|
|
753
|
+
// Build evidence refs
|
|
754
|
+
const evidenceRefs = buildEvidenceRefs(snapshot, input.lastOutcome);
|
|
755
|
+
// Outcome-status stop routing
|
|
756
|
+
const status = input.lastOutcome.status;
|
|
757
|
+
if (status === "blocked") {
|
|
758
|
+
return { kind: "stop", intent: "stop", targets: input.lastOutcome.blockers.map((b) => b.id), reasonCode: "stop-blocked", evidenceRefs: [], detail: "outcome blocked" };
|
|
759
|
+
}
|
|
760
|
+
if (status === "needs-input") {
|
|
761
|
+
return { kind: "stop", intent: "stop", targets: input.lastOutcome.questions.map((q) => q.id), reasonCode: "stop-needs-input", evidenceRefs: [], detail: "outcome needs input" };
|
|
762
|
+
}
|
|
763
|
+
if (status === "failed") {
|
|
764
|
+
const targets = input.lastOutcome.discoveries.length > 0
|
|
765
|
+
? input.lastOutcome.discoveries.map((d) => d.summary)
|
|
766
|
+
: [];
|
|
767
|
+
return { kind: "stop", intent: "stop", targets, reasonCode: "stop-failed", evidenceRefs: [], detail: "outcome failed" };
|
|
768
|
+
}
|
|
769
|
+
// Contradiction routing
|
|
770
|
+
if (snapshot.contradictions.length > 0) {
|
|
771
|
+
const proposal = input.lastOutcome.next.intent;
|
|
772
|
+
if (proposal === "resolve-repository-state") {
|
|
773
|
+
const contradictionFields = snapshot.contradictions.map((c) => c.field);
|
|
774
|
+
const allowedContradictionTargets = contradictionFields.length > 0
|
|
775
|
+
? ["resolve-repository-state"]
|
|
776
|
+
: [];
|
|
777
|
+
if (allowedContradictionTargets.includes(proposal)) {
|
|
778
|
+
return {
|
|
779
|
+
kind: "stop", intent: "stop", targets: contradictionFields,
|
|
780
|
+
reasonCode: "stop-contradiction",
|
|
781
|
+
evidenceRefs: snapshot.contradictions.map((c) => `contradiction:${c.field}`),
|
|
782
|
+
detail: "snapshot contradictions present",
|
|
783
|
+
};
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
// Non-matching proposal under contradiction
|
|
787
|
+
return {
|
|
788
|
+
kind: "stop", intent: "stop", targets: [],
|
|
789
|
+
reasonCode: "stop-contradiction",
|
|
790
|
+
evidenceRefs: snapshot.contradictions.map((c) => `contradiction:${c.field}`),
|
|
791
|
+
detail: "snapshot contradictions present",
|
|
792
|
+
};
|
|
793
|
+
}
|
|
794
|
+
// Recommendation → closed-table match
|
|
795
|
+
const proposal = input.lastOutcome.next.intent;
|
|
796
|
+
const targets = input.lastOutcome.next.targets || [];
|
|
797
|
+
const lastSkill = input.lastOutcome.skill;
|
|
798
|
+
const entry = WORKFLOW_TRANSITION_TABLE.find((r) => r.key === lastSkill);
|
|
799
|
+
if (entry === undefined) {
|
|
800
|
+
return { kind: "sense", intent: "status", targets: [], reasonCode: "sense-unlisted-transition", evidenceRefs: [], detail: `unlisted transition: ${lastSkill}` };
|
|
801
|
+
}
|
|
802
|
+
// Check if proposal is in the allowed list for the last skill
|
|
803
|
+
if (!entry.allowed.includes(proposal)) {
|
|
804
|
+
return { kind: "sense", intent: "status", targets: [], reasonCode: "sense-unlisted-transition", evidenceRefs: [], detail: `${proposal} not allowed after ${entry.key}` };
|
|
805
|
+
}
|
|
806
|
+
// Row condition checks
|
|
807
|
+
if (proposal === "discover-repository-state") {
|
|
808
|
+
if (snapshot.repositoryState !== "frozen") {
|
|
809
|
+
return { kind: "sense", intent: "status", targets: [], reasonCode: "sense-missing-evidence", evidenceRefs: [], detail: "repository not frozen" };
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
if (lastSkill === "resolve-repository-state") {
|
|
813
|
+
const contradictionFields = snapshot.contradictions.map((c) => c.field);
|
|
814
|
+
if (contradictionFields.length > 0 && !contradictionFields.includes(targets[0])) {
|
|
815
|
+
return { kind: "stop", intent: "stop", targets, reasonCode: "stop-forbidden-transition", evidenceRefs: [], detail: `target ${targets[0]} does not match contradiction fields` };
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
// Effect authorization
|
|
819
|
+
if (!checkEffectAuth(proposal)) {
|
|
820
|
+
return { kind: "stop", intent: "stop", targets: [], reasonCode: "stop-forbidden-transition", evidenceRefs: [], detail: "unauthorized effect" };
|
|
821
|
+
}
|
|
822
|
+
// Evidence authorization
|
|
823
|
+
if (!checkEvidenceAuth(proposal, evidenceRefs)) {
|
|
824
|
+
return { kind: "sense", intent: "status", targets: [], reasonCode: "sense-missing-evidence", evidenceRefs: [], detail: "missing required evidence" };
|
|
825
|
+
}
|
|
826
|
+
// Policy gate
|
|
827
|
+
if (!checkPolicyGate(proposal, typedPolicy)) {
|
|
828
|
+
return { kind: "stop", intent: "stop", targets: [], reasonCode: "stop-policy-denied", evidenceRefs: [], detail: "policy denied" };
|
|
829
|
+
}
|
|
830
|
+
// Non-invocable intents can never reach invoke
|
|
831
|
+
if (proposal === "status" || proposal === "ask-human" || proposal === "stop" || proposal === "none") {
|
|
832
|
+
return { kind: "stop", intent: "stop", targets: [], reasonCode: "stop-forbidden-transition", evidenceRefs: [], detail: "non-invocable intent" };
|
|
833
|
+
}
|
|
834
|
+
// Target count validation for audit-pr: exactly 1 target
|
|
835
|
+
if (lastSkill === "audit-pr" && targets.length !== 1) {
|
|
836
|
+
return { kind: "stop", intent: "stop", targets, reasonCode: "stop-forbidden-transition", evidenceRefs: [], detail: targets.length === 0 ? "missing target" : "extra targets" };
|
|
837
|
+
}
|
|
838
|
+
// Proven transition — invoke
|
|
839
|
+
const invocable = proposal;
|
|
840
|
+
// Proven transition — invoke
|
|
841
|
+
return {
|
|
842
|
+
kind: "invoke", intent: invocable,
|
|
843
|
+
targets: targets.length > 0 ? targets : [],
|
|
844
|
+
reasonCode: "invoke-proven-transition",
|
|
845
|
+
evidenceRefs,
|
|
846
|
+
detail: `invoke-proven-transition: ${proposal} to [${targets.join(", ") || "*"}]`,
|
|
847
|
+
};
|
|
848
|
+
}
|
|
849
|
+
// ---------------------------------------------------------------------------
|
|
448
850
|
// Capability metadata — closed vocabularies, immutable exports (issue #136)
|
|
449
851
|
// ---------------------------------------------------------------------------
|
|
450
852
|
/** Role a built-in skill plays in the workflow pipeline. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gtrabanco/agentic-workflow-schema",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "Versioned machine contracts, JSON Schemas, parsers, and deterministic document snapshots for agentic-workflow orchestration.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agentic-workflow",
|