@exaudeus/workrail 2.0.0 → 3.0.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.
Files changed (72) hide show
  1. package/dist/application/services/compiler/template-registry.d.ts +4 -2
  2. package/dist/application/services/compiler/template-registry.js +97 -5
  3. package/dist/application/services/workflow-compiler.d.ts +5 -1
  4. package/dist/application/services/workflow-compiler.js +20 -7
  5. package/dist/application/use-cases/raw-workflow-file-scanner.d.ts +1 -1
  6. package/dist/application/use-cases/raw-workflow-file-scanner.js +2 -0
  7. package/dist/application/use-cases/validate-workflow-registry.js +2 -1
  8. package/dist/config/feature-flags.js +8 -0
  9. package/dist/di/container.js +10 -1
  10. package/dist/di/tokens.d.ts +1 -0
  11. package/dist/di/tokens.js +1 -0
  12. package/dist/engine/engine-factory.d.ts +3 -0
  13. package/dist/engine/engine-factory.js +295 -0
  14. package/dist/engine/index.d.ts +3 -0
  15. package/dist/engine/index.js +12 -0
  16. package/dist/engine/types.d.ts +130 -0
  17. package/dist/engine/types.js +18 -0
  18. package/dist/infrastructure/storage/file-workflow-storage.d.ts +1 -0
  19. package/dist/infrastructure/storage/file-workflow-storage.js +18 -3
  20. package/dist/infrastructure/storage/workflow-resolution.d.ts +9 -6
  21. package/dist/infrastructure/storage/workflow-resolution.js +14 -1
  22. package/dist/manifest.json +166 -94
  23. package/dist/mcp/handlers/shared/request-workflow-reader.d.ts +19 -0
  24. package/dist/mcp/handlers/shared/request-workflow-reader.js +50 -0
  25. package/dist/mcp/handlers/v2-checkpoint.d.ts +31 -1
  26. package/dist/mcp/handlers/v2-checkpoint.js +76 -64
  27. package/dist/mcp/handlers/v2-execution/continue-advance.d.ts +2 -0
  28. package/dist/mcp/handlers/v2-execution/continue-advance.js +5 -5
  29. package/dist/mcp/handlers/v2-execution/continue-rehydrate.d.ts +2 -0
  30. package/dist/mcp/handlers/v2-execution/continue-rehydrate.js +17 -22
  31. package/dist/mcp/handlers/v2-execution/index.d.ts +10 -17
  32. package/dist/mcp/handlers/v2-execution/index.js +44 -54
  33. package/dist/mcp/handlers/v2-execution/replay.d.ts +4 -15
  34. package/dist/mcp/handlers/v2-execution/replay.js +52 -128
  35. package/dist/mcp/handlers/v2-execution/start.d.ts +4 -3
  36. package/dist/mcp/handlers/v2-execution/start.js +32 -49
  37. package/dist/mcp/handlers/v2-token-ops.d.ts +45 -24
  38. package/dist/mcp/handlers/v2-token-ops.js +372 -32
  39. package/dist/mcp/handlers/v2-workflow.d.ts +1 -1
  40. package/dist/mcp/handlers/v2-workflow.js +25 -4
  41. package/dist/mcp/output-schemas.d.ts +104 -283
  42. package/dist/mcp/output-schemas.js +24 -22
  43. package/dist/mcp/server.js +8 -0
  44. package/dist/mcp/tool-descriptions.js +9 -2
  45. package/dist/mcp/types.d.ts +4 -0
  46. package/dist/mcp/v2/tools.d.ts +32 -53
  47. package/dist/mcp/v2/tools.js +27 -37
  48. package/dist/mcp/v2-response-formatter.js +12 -16
  49. package/dist/runtime/runtime-mode.d.ts +2 -0
  50. package/dist/v2/durable-core/domain/prompt-renderer.d.ts +1 -0
  51. package/dist/v2/durable-core/domain/prompt-renderer.js +5 -3
  52. package/dist/v2/durable-core/schemas/export-bundle/index.d.ts +14 -14
  53. package/dist/v2/durable-core/schemas/session/events.d.ts +4 -4
  54. package/dist/v2/durable-core/schemas/session/validation-event.d.ts +2 -2
  55. package/dist/v2/durable-core/tokens/payloads.d.ts +32 -32
  56. package/dist/v2/durable-core/tokens/short-token.d.ts +38 -0
  57. package/dist/v2/durable-core/tokens/short-token.js +126 -0
  58. package/dist/v2/durable-core/tokens/token-patterns.d.ts +4 -0
  59. package/dist/v2/durable-core/tokens/token-patterns.js +9 -0
  60. package/dist/v2/infra/in-memory/token-alias-store/index.d.ts +11 -0
  61. package/dist/v2/infra/in-memory/token-alias-store/index.js +38 -0
  62. package/dist/v2/infra/local/data-dir/index.d.ts +1 -0
  63. package/dist/v2/infra/local/data-dir/index.js +3 -0
  64. package/dist/v2/infra/local/token-alias-store/index.d.ts +16 -0
  65. package/dist/v2/infra/local/token-alias-store/index.js +117 -0
  66. package/dist/v2/ports/data-dir.port.d.ts +1 -0
  67. package/dist/v2/ports/token-alias-store.port.d.ts +33 -0
  68. package/dist/v2/ports/token-alias-store.port.js +2 -0
  69. package/package.json +8 -1
  70. package/workflows/coding-task-workflow-agentic.lean.v2.json +224 -0
  71. package/workflows/routines/philosophy-alignment.json +12 -12
  72. package/workflows/routines/tension-driven-design.json +63 -0
@@ -0,0 +1,130 @@
1
+ declare const StateTokenBrand: unique symbol;
2
+ declare const AckTokenBrand: unique symbol;
3
+ declare const CheckpointTokenBrand: unique symbol;
4
+ export type StateToken = string & {
5
+ readonly [StateTokenBrand]: never;
6
+ };
7
+ export type AckToken = string & {
8
+ readonly [AckTokenBrand]: never;
9
+ };
10
+ export type CheckpointToken = string & {
11
+ readonly [CheckpointTokenBrand]: never;
12
+ };
13
+ export declare function asStateToken(s: string): StateToken;
14
+ export declare function asAckToken(s: string): AckToken;
15
+ export declare function asCheckpointToken(s: string): CheckpointToken;
16
+ export declare function unwrapToken(t: StateToken | AckToken | CheckpointToken): string;
17
+ export interface PendingStep {
18
+ readonly stepId: string;
19
+ readonly title: string;
20
+ readonly prompt: string;
21
+ readonly agentRole?: string;
22
+ }
23
+ export type Autonomy = 'guided' | 'full_auto_stop_on_user_deps' | 'full_auto_never_stop';
24
+ export type RiskPolicy = 'conservative' | 'balanced' | 'aggressive';
25
+ export interface StepPreferences {
26
+ readonly autonomy: Autonomy;
27
+ readonly riskPolicy: RiskPolicy;
28
+ }
29
+ export type NextIntent = 'perform_pending_then_continue' | 'await_user_confirmation' | 'rehydrate_only' | 'complete';
30
+ export type BlockerCode = 'USER_ONLY_DEPENDENCY' | 'MISSING_REQUIRED_OUTPUT' | 'INVALID_REQUIRED_OUTPUT' | 'MISSING_REQUIRED_NOTES' | 'MISSING_CONTEXT_KEY' | 'CONTEXT_BUDGET_EXCEEDED' | 'REQUIRED_CAPABILITY_UNKNOWN' | 'REQUIRED_CAPABILITY_UNAVAILABLE' | 'INVARIANT_VIOLATION' | 'STORAGE_CORRUPTION_DETECTED';
31
+ export interface Blocker {
32
+ readonly code: BlockerCode;
33
+ readonly message: string;
34
+ readonly suggestedFix?: string;
35
+ }
36
+ interface StepResponseBase {
37
+ readonly stateToken: StateToken;
38
+ readonly ackToken: AckToken | null;
39
+ readonly checkpointToken: CheckpointToken | null;
40
+ readonly isComplete: boolean;
41
+ readonly preferences: StepPreferences;
42
+ readonly nextIntent: NextIntent;
43
+ }
44
+ export interface StepResponseOk extends StepResponseBase {
45
+ readonly kind: 'ok';
46
+ readonly pending: PendingStep | null;
47
+ }
48
+ export interface StepResponseBlocked extends StepResponseBase {
49
+ readonly kind: 'blocked';
50
+ readonly pending: PendingStep | null;
51
+ readonly blockers: readonly Blocker[];
52
+ readonly retryable: boolean;
53
+ readonly retryAckToken: AckToken | null;
54
+ }
55
+ export type StepResponse = StepResponseOk | StepResponseBlocked;
56
+ export interface CheckpointResponse {
57
+ readonly checkpointNodeId: string;
58
+ readonly stateToken: StateToken;
59
+ }
60
+ export interface WorkflowListItem {
61
+ readonly workflowId: string;
62
+ readonly name: string;
63
+ readonly description: string;
64
+ readonly version: string;
65
+ }
66
+ export interface WorkflowListResponse {
67
+ readonly workflows: readonly WorkflowListItem[];
68
+ }
69
+ export type InfraErrorCode = string;
70
+ export type EngineError = {
71
+ readonly kind: 'workflow_not_found';
72
+ readonly workflowId: string;
73
+ } | {
74
+ readonly kind: 'workflow_has_no_steps';
75
+ readonly workflowId: string;
76
+ } | {
77
+ readonly kind: 'workflow_compile_failed';
78
+ readonly message: string;
79
+ } | {
80
+ readonly kind: 'validation_failed';
81
+ readonly message: string;
82
+ } | {
83
+ readonly kind: 'token_invalid';
84
+ readonly message: string;
85
+ readonly code?: InfraErrorCode;
86
+ } | {
87
+ readonly kind: 'token_signing_failed';
88
+ readonly message: string;
89
+ } | {
90
+ readonly kind: 'session_error';
91
+ readonly message: string;
92
+ readonly code?: InfraErrorCode;
93
+ } | {
94
+ readonly kind: 'storage_error';
95
+ readonly message: string;
96
+ readonly code?: InfraErrorCode;
97
+ } | {
98
+ readonly kind: 'prompt_render_failed';
99
+ readonly message: string;
100
+ } | {
101
+ readonly kind: 'precondition_failed';
102
+ readonly message: string;
103
+ } | {
104
+ readonly kind: 'internal_error';
105
+ readonly message: string;
106
+ readonly code?: InfraErrorCode;
107
+ };
108
+ export type EngineResult<T> = {
109
+ readonly ok: true;
110
+ readonly value: T;
111
+ } | {
112
+ readonly ok: false;
113
+ readonly error: EngineError;
114
+ };
115
+ export declare function engineOk<T>(value: T): EngineResult<T>;
116
+ export declare function engineErr<T>(error: EngineError): EngineResult<T>;
117
+ export interface EngineConfig {
118
+ readonly dataDir?: string;
119
+ }
120
+ export interface WorkRailEngine {
121
+ readonly startWorkflow: (workflowId: string) => Promise<EngineResult<StepResponse>>;
122
+ readonly continueWorkflow: (stateToken: StateToken, ackToken: AckToken | null, output?: {
123
+ readonly notesMarkdown?: string;
124
+ readonly artifacts?: readonly unknown[];
125
+ }, context?: Readonly<Record<string, unknown>>) => Promise<EngineResult<StepResponse>>;
126
+ readonly checkpointWorkflow: (checkpointToken: CheckpointToken) => Promise<EngineResult<CheckpointResponse>>;
127
+ readonly listWorkflows: () => Promise<EngineResult<WorkflowListResponse>>;
128
+ readonly close: () => Promise<void>;
129
+ }
130
+ export {};
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.asStateToken = asStateToken;
4
+ exports.asAckToken = asAckToken;
5
+ exports.asCheckpointToken = asCheckpointToken;
6
+ exports.unwrapToken = unwrapToken;
7
+ exports.engineOk = engineOk;
8
+ exports.engineErr = engineErr;
9
+ function asStateToken(s) { return s; }
10
+ function asAckToken(s) { return s; }
11
+ function asCheckpointToken(s) { return s; }
12
+ function unwrapToken(t) { return t; }
13
+ function engineOk(value) {
14
+ return { ok: true, value };
15
+ }
16
+ function engineErr(error) {
17
+ return { ok: false, error };
18
+ }
@@ -26,6 +26,7 @@ export declare class FileWorkflowStorage implements IWorkflowStorage {
26
26
  private loadDefinitionFromFile;
27
27
  loadAllWorkflows(): Promise<readonly Workflow[]>;
28
28
  getWorkflowById(id: string): Promise<Workflow | null>;
29
+ getRoutineDefinitions(): Promise<ReadonlyMap<string, WorkflowDefinition>>;
29
30
  listWorkflowSummaries(): Promise<readonly WorkflowSummary[]>;
30
31
  save(definition: WorkflowDefinition): Promise<void>;
31
32
  }
@@ -55,6 +55,9 @@ class FileWorkflowStorage {
55
55
  continue;
56
56
  }
57
57
  }
58
+ if (!this.featureFlags.isEnabled('leanWorkflows') && file.includes('.lean.')) {
59
+ continue;
60
+ }
58
61
  if (!this.featureFlags.isEnabled('v2Tools') && file.includes('.v2.')) {
59
62
  continue;
60
63
  }
@@ -78,12 +81,14 @@ class FileWorkflowStorage {
78
81
  const flags = {
79
82
  v2Tools: this.featureFlags.isEnabled('v2Tools'),
80
83
  agenticRoutines: this.featureFlags.isEnabled('agenticRoutines'),
84
+ leanWorkflows: this.featureFlags.isEnabled('leanWorkflows'),
81
85
  };
82
86
  for (const [id, files] of idToFiles) {
83
87
  const candidates = files.map(f => ({
84
- variantKind: f.file.includes('.v2.') ? 'v2'
85
- : f.file.includes('.agentic.') ? 'agentic'
86
- : 'standard',
88
+ variantKind: f.file.includes('.lean.') ? 'lean'
89
+ : f.file.includes('.v2.') ? 'v2'
90
+ : f.file.includes('.agentic.') ? 'agentic'
91
+ : 'standard',
87
92
  identifier: f.file,
88
93
  }));
89
94
  const selection = (0, workflow_resolution_1.selectVariant)(candidates, flags);
@@ -159,6 +164,16 @@ class FileWorkflowStorage {
159
164
  }
160
165
  return workflow;
161
166
  }
167
+ async getRoutineDefinitions() {
168
+ const index = await this.getWorkflowIndex();
169
+ const routines = new Map();
170
+ for (const entry of index.values()) {
171
+ if (entry.id.startsWith('routine-')) {
172
+ routines.set(entry.id, entry.definition);
173
+ }
174
+ }
175
+ return routines;
176
+ }
162
177
  async listWorkflowSummaries() {
163
178
  const workflows = await this.loadAllWorkflows();
164
179
  return workflows.map(workflow_1.toWorkflowSummary);
@@ -1,19 +1,21 @@
1
1
  import type { Workflow } from '../../types/workflow.js';
2
2
  export type SourceRef = number;
3
+ export type VariantKind = 'lean' | 'v2' | 'agentic' | 'standard';
3
4
  export type VariantResolution = {
4
5
  readonly kind: 'only_variant';
5
6
  } | {
6
7
  readonly kind: 'feature_flag_selected';
7
- readonly selectedVariant: 'v2' | 'agentic' | 'standard';
8
- readonly availableVariants: readonly ('v2' | 'agentic' | 'standard')[];
8
+ readonly selectedVariant: VariantKind;
9
+ readonly availableVariants: readonly VariantKind[];
9
10
  readonly enabledFlags: {
10
11
  readonly v2Tools: boolean;
11
12
  readonly agenticRoutines: boolean;
13
+ readonly leanWorkflows: boolean;
12
14
  };
13
15
  } | {
14
16
  readonly kind: 'precedence_fallback';
15
- readonly selectedVariant: 'v2' | 'agentic' | 'standard';
16
- readonly availableVariants: readonly ('v2' | 'agentic' | 'standard')[];
17
+ readonly selectedVariant: VariantKind;
18
+ readonly availableVariants: readonly VariantKind[];
17
19
  };
18
20
  export type ResolutionReason = {
19
21
  readonly kind: 'unique';
@@ -39,15 +41,16 @@ export declare function resolveWorkflowCandidates(candidates: readonly {
39
41
  readonly workflows: readonly Workflow[];
40
42
  }[], variantResolutions: ReadonlyMap<string, ReadonlyMap<SourceRef, VariantResolution>>): readonly ResolvedWorkflow[];
41
43
  export interface VariantCandidate {
42
- readonly variantKind: 'v2' | 'agentic' | 'standard';
44
+ readonly variantKind: VariantKind;
43
45
  readonly identifier: string;
44
46
  }
45
47
  export interface VariantSelectionFlags {
46
48
  readonly v2Tools: boolean;
47
49
  readonly agenticRoutines: boolean;
50
+ readonly leanWorkflows: boolean;
48
51
  }
49
52
  export interface VariantSelectionResult {
50
- readonly selectedVariant: 'v2' | 'agentic' | 'standard';
53
+ readonly selectedVariant: VariantKind;
51
54
  readonly selectedIdentifier: string;
52
55
  readonly resolution: VariantResolution;
53
56
  }
@@ -79,9 +79,22 @@ function selectVariant(candidates, flags) {
79
79
  };
80
80
  }
81
81
  const availableVariants = candidates.map(c => c.variantKind);
82
+ const leanCandidate = candidates.find(c => c.variantKind === 'lean');
82
83
  const v2Candidate = candidates.find(c => c.variantKind === 'v2');
83
84
  const agenticCandidate = candidates.find(c => c.variantKind === 'agentic');
84
85
  const standardCandidate = candidates.find(c => c.variantKind === 'standard');
86
+ if (flags.leanWorkflows && leanCandidate) {
87
+ return {
88
+ selectedVariant: 'lean',
89
+ selectedIdentifier: leanCandidate.identifier,
90
+ resolution: {
91
+ kind: 'feature_flag_selected',
92
+ selectedVariant: 'lean',
93
+ availableVariants,
94
+ enabledFlags: flags,
95
+ },
96
+ };
97
+ }
85
98
  if (flags.v2Tools && v2Candidate) {
86
99
  return {
87
100
  selectedVariant: 'v2',
@@ -117,7 +130,7 @@ function selectVariant(candidates, flags) {
117
130
  },
118
131
  };
119
132
  }
120
- const fallback = v2Candidate ?? agenticCandidate ?? candidates[0];
133
+ const fallback = leanCandidate ?? v2Candidate ?? agenticCandidate ?? candidates[0];
121
134
  return {
122
135
  selectedVariant: fallback.variantKind,
123
136
  selectedIdentifier: fallback.identifier,