@slope-dev/slope 1.35.0 → 1.36.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/cli/commands/loop.d.ts.map +1 -1
  2. package/dist/cli/commands/loop.js +5 -0
  3. package/dist/cli/commands/loop.js.map +1 -1
  4. package/dist/cli/commands/sprint.d.ts.map +1 -1
  5. package/dist/cli/commands/sprint.js +205 -3
  6. package/dist/cli/commands/sprint.js.map +1 -1
  7. package/dist/cli/commands/workflow.d.ts +2 -0
  8. package/dist/cli/commands/workflow.d.ts.map +1 -0
  9. package/dist/cli/commands/workflow.js +165 -0
  10. package/dist/cli/commands/workflow.js.map +1 -0
  11. package/dist/cli/index.js +7 -0
  12. package/dist/cli/index.js.map +1 -1
  13. package/dist/cli/loop/types.d.ts +4 -0
  14. package/dist/cli/loop/types.d.ts.map +1 -1
  15. package/dist/cli/loop/types.js.map +1 -1
  16. package/dist/cli/loop/workflow-adapter.d.ts +53 -0
  17. package/dist/cli/loop/workflow-adapter.d.ts.map +1 -0
  18. package/dist/cli/loop/workflow-adapter.js +123 -0
  19. package/dist/cli/loop/workflow-adapter.js.map +1 -0
  20. package/dist/cli/registry.d.ts.map +1 -1
  21. package/dist/cli/registry.js +8 -0
  22. package/dist/cli/registry.js.map +1 -1
  23. package/dist/core/guard.d.ts +1 -1
  24. package/dist/core/guard.d.ts.map +1 -1
  25. package/dist/core/guard.js +8 -0
  26. package/dist/core/guard.js.map +1 -1
  27. package/dist/core/index.d.ts +9 -1
  28. package/dist/core/index.d.ts.map +1 -1
  29. package/dist/core/index.js +8 -0
  30. package/dist/core/index.js.map +1 -1
  31. package/dist/core/store.d.ts +25 -1
  32. package/dist/core/store.d.ts.map +1 -1
  33. package/dist/core/types.d.ts +34 -0
  34. package/dist/core/types.d.ts.map +1 -1
  35. package/dist/core/workflow-engine.d.ts +89 -0
  36. package/dist/core/workflow-engine.d.ts.map +1 -0
  37. package/dist/core/workflow-engine.js +223 -0
  38. package/dist/core/workflow-engine.js.map +1 -0
  39. package/dist/core/workflow-loader.d.ts +21 -0
  40. package/dist/core/workflow-loader.d.ts.map +1 -0
  41. package/dist/core/workflow-loader.js +110 -0
  42. package/dist/core/workflow-loader.js.map +1 -0
  43. package/dist/core/workflow-validator.d.ts +19 -0
  44. package/dist/core/workflow-validator.d.ts.map +1 -0
  45. package/dist/core/workflow-validator.js +166 -0
  46. package/dist/core/workflow-validator.js.map +1 -0
  47. package/dist/core/workflow.d.ts +51 -0
  48. package/dist/core/workflow.d.ts.map +1 -0
  49. package/dist/core/workflow.js +190 -0
  50. package/dist/core/workflow.js.map +1 -0
  51. package/dist/mcp/index.d.ts +1 -1
  52. package/dist/mcp/index.d.ts.map +1 -1
  53. package/dist/mcp/index.js +138 -2
  54. package/dist/mcp/index.js.map +1 -1
  55. package/dist/mcp/index.test.js +10 -2
  56. package/dist/mcp/index.test.js.map +1 -1
  57. package/dist/mcp/registry.d.ts +1 -1
  58. package/dist/mcp/registry.d.ts.map +1 -1
  59. package/dist/mcp/registry.js +71 -0
  60. package/dist/mcp/registry.js.map +1 -1
  61. package/dist/store/index.d.ts +25 -1
  62. package/dist/store/index.d.ts.map +1 -1
  63. package/dist/store/index.js +144 -0
  64. package/dist/store/index.js.map +1 -1
  65. package/dist/store-pg/index.d.ts +25 -1
  66. package/dist/store-pg/index.d.ts.map +1 -1
  67. package/dist/store-pg/index.js +180 -0
  68. package/dist/store-pg/index.js.map +1 -1
  69. package/package.json +4 -2
  70. package/src/core/workflows/sprint-autonomous.yaml +59 -0
  71. package/src/core/workflows/sprint-lightweight.yaml +39 -0
  72. package/src/core/workflows/sprint-standard.yaml +77 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflow-loader.js","sourceRoot":"","sources":["../../src/core/workflow-loader.ts"],"names":[],"mappings":"AAAA,0BAA0B;AAC1B,kEAAkE;AAElE,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE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{ WorkflowDefinition } from './workflow.js';
2
+ /** A single validation error or warning */
3
+ export interface ValidationIssue {
4
+ message: string;
5
+ /** Dot-path to the problematic element (e.g., "phases[0].steps[1]") */
6
+ path?: string;
7
+ }
8
+ /** Result of validating a workflow definition */
9
+ export interface WorkflowValidationResult {
10
+ valid: boolean;
11
+ errors: ValidationIssue[];
12
+ warnings: ValidationIssue[];
13
+ }
14
+ /**
15
+ * Validate a parsed WorkflowDefinition for structural issues.
16
+ * Does NOT re-validate YAML parsing — assumes parseWorkflow() already succeeded.
17
+ */
18
+ export declare function validateWorkflow(def: WorkflowDefinition): WorkflowValidationResult;
19
+ //# sourceMappingURL=workflow-validator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflow-validator.d.ts","sourceRoot":"","sources":["../../src/core/workflow-validator.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAgB,MAAM,eAAe,CAAC;AAGtE,2CAA2C;AAC3C,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,uEAAuE;IACvE,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,iDAAiD;AACjD,MAAM,WAAW,wBAAwB;IACvC,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,eAAe,EAAE,CAAC;IAC1B,QAAQ,EAAE,eAAe,EAAE,CAAC;CAC7B;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,kBAAkB,GAAG,wBAAwB,CA6HlF"}
@@ -0,0 +1,166 @@
1
+ // SLOPE — Workflow Validator
2
+ // Validates WorkflowDefinitions for structural correctness before execution.
3
+ import { VALID_STEP_TYPES } from './workflow.js';
4
+ /**
5
+ * Validate a parsed WorkflowDefinition for structural issues.
6
+ * Does NOT re-validate YAML parsing — assumes parseWorkflow() already succeeded.
7
+ */
8
+ export function validateWorkflow(def) {
9
+ const errors = [];
10
+ const warnings = [];
11
+ // Version check
12
+ if (def.version !== '1') {
13
+ errors.push({ message: `Unsupported workflow version: "${def.version}" (expected "1")` });
14
+ }
15
+ // Name check
16
+ if (!def.name || def.name.trim().length === 0) {
17
+ errors.push({ message: 'Workflow name must be a non-empty string' });
18
+ }
19
+ // Collect all step IDs for uniqueness check
20
+ const allStepIds = new Map(); // step_id → phase_id
21
+ // Collect all variable references found in steps
22
+ const referencedVars = new Set();
23
+ const definedVars = new Set(Object.keys(def.variables ?? {}));
24
+ if (def.phases.length === 0) {
25
+ warnings.push({ message: 'Workflow has no phases' });
26
+ }
27
+ // Phase-level checks
28
+ const phaseIds = new Set();
29
+ for (let pi = 0; pi < def.phases.length; pi++) {
30
+ const phase = def.phases[pi];
31
+ const pPath = `phases[${pi}]`;
32
+ // Duplicate phase ID
33
+ if (phaseIds.has(phase.id)) {
34
+ errors.push({ message: `Duplicate phase ID: "${phase.id}"`, path: pPath });
35
+ }
36
+ phaseIds.add(phase.id);
37
+ // Empty steps
38
+ if (phase.steps.length === 0) {
39
+ warnings.push({ message: `Phase "${phase.id}" has no steps`, path: pPath });
40
+ }
41
+ // repeat_for variable reference
42
+ if (phase.repeat_for) {
43
+ referencedVars.add(phase.repeat_for);
44
+ if (definedVars.size > 0 && !definedVars.has(phase.repeat_for)) {
45
+ warnings.push({
46
+ message: `Phase "${phase.id}" references variable "${phase.repeat_for}" in repeat_for, but it is not defined in variables`,
47
+ path: `${pPath}.repeat_for`,
48
+ });
49
+ }
50
+ // on_timeout only makes sense with repeat_for
51
+ if (phase.timeout_per_item && !phase.on_timeout) {
52
+ warnings.push({
53
+ message: `Phase "${phase.id}" has timeout_per_item but no on_timeout behavior`,
54
+ path: `${pPath}.on_timeout`,
55
+ });
56
+ }
57
+ }
58
+ else {
59
+ // on_timeout without repeat_for
60
+ if (phase.on_timeout) {
61
+ warnings.push({
62
+ message: `Phase "${phase.id}" has on_timeout but no repeat_for — on_timeout is ignored`,
63
+ path: `${pPath}.on_timeout`,
64
+ });
65
+ }
66
+ }
67
+ // Step-level checks
68
+ for (let si = 0; si < phase.steps.length; si++) {
69
+ const step = phase.steps[si];
70
+ const sPath = `${pPath}.steps[${si}]`;
71
+ // Duplicate step ID across all phases
72
+ if (allStepIds.has(step.id)) {
73
+ errors.push({
74
+ message: `Duplicate step ID: "${step.id}" (also in phase "${allStepIds.get(step.id)}")`,
75
+ path: sPath,
76
+ });
77
+ }
78
+ allStepIds.set(step.id, phase.id);
79
+ // Valid step type
80
+ if (!VALID_STEP_TYPES.has(step.type)) {
81
+ errors.push({
82
+ message: `Invalid step type: "${step.type}"`,
83
+ path: `${sPath}.type`,
84
+ });
85
+ }
86
+ // Type-specific validation
87
+ validateStepByType(step, sPath, errors, warnings);
88
+ // blocks_next on terminal step is redundant
89
+ if (step.blocks_next && si === phase.steps.length - 1) {
90
+ warnings.push({
91
+ message: `Step "${step.id}" has blocks_next but is the last step in its phase — this is redundant`,
92
+ path: `${sPath}.blocks_next`,
93
+ });
94
+ }
95
+ // Collect variable references from string fields
96
+ collectVarRefs(step.command, referencedVars);
97
+ collectVarRefs(step.prompt, referencedVars);
98
+ if (step.rules)
99
+ step.rules.forEach(r => collectVarRefs(r, referencedVars));
100
+ if (step.conditions)
101
+ step.conditions.forEach(c => collectVarRefs(c, referencedVars));
102
+ }
103
+ }
104
+ // Warn about unreferenced variables
105
+ for (const varName of definedVars) {
106
+ if (!referencedVars.has(varName)) {
107
+ warnings.push({
108
+ message: `Variable "${varName}" is defined but never referenced`,
109
+ path: `variables.${varName}`,
110
+ });
111
+ }
112
+ }
113
+ return {
114
+ valid: errors.length === 0,
115
+ errors,
116
+ warnings,
117
+ };
118
+ }
119
+ /** Validate type-specific step requirements */
120
+ function validateStepByType(step, path, errors, warnings) {
121
+ switch (step.type) {
122
+ case 'command':
123
+ if (!step.command) {
124
+ errors.push({
125
+ message: `Command step "${step.id}" must have a "command" field`,
126
+ path: `${path}.command`,
127
+ });
128
+ }
129
+ break;
130
+ case 'validation':
131
+ if (!step.conditions?.length && !step.command) {
132
+ warnings.push({
133
+ message: `Validation step "${step.id}" has no conditions or command — it will always pass`,
134
+ path,
135
+ });
136
+ }
137
+ break;
138
+ case 'agent_input':
139
+ if (!step.required_fields?.length && !step.prompt) {
140
+ warnings.push({
141
+ message: `Agent input step "${step.id}" has no required_fields or prompt`,
142
+ path,
143
+ });
144
+ }
145
+ break;
146
+ case 'agent_work':
147
+ if (!step.prompt && !step.rules?.length) {
148
+ warnings.push({
149
+ message: `Agent work step "${step.id}" has no prompt or rules — agent has no guidance`,
150
+ path,
151
+ });
152
+ }
153
+ break;
154
+ }
155
+ }
156
+ /** Extract ${varName} references from a string */
157
+ function collectVarRefs(str, refs) {
158
+ if (!str)
159
+ return;
160
+ const pattern = /\$\{([a-zA-Z_][a-zA-Z0-9_]*)\}/g;
161
+ let match;
162
+ while ((match = pattern.exec(str)) !== null) {
163
+ refs.add(match[1]);
164
+ }
165
+ }
166
+ //# sourceMappingURL=workflow-validator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflow-validator.js","sourceRoot":"","sources":["../../src/core/workflow-validator.ts"],"names":[],"mappings":"AAAA,6BAA6B;AAC7B,6EAA6E;AAG7E,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAgBjD;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,GAAuB;IACtD,MAAM,MAAM,GAAsB,EAAE,CAAC;IACrC,MAAM,QAAQ,GAAsB,EAAE,CAAC;IAEvC,gBAAgB;IAChB,IAAI,GAAG,CAAC,OAAO,KAAK,GAAG,EAAE,CAAC;QACxB,MAAM,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,kCAAkC,GAAG,CAAC,OAAO,kBAAkB,EAAE,CAAC,CAAC;IAC5F,CAAC;IAED,aAAa;IACb,IAAI,CAAC,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC9C,MAAM,CAAC,IAAI,CAAC,EAAE,OAAO,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BAClD,QAAQ,CAAC,IAAI,CAAC;oBACZ,OAAO,EAAE,qBAAqB,IAAI,CAAC,EAAE,oCAAoC;oBACzE,IAAI;iBACL,CAAC,CAAC;YACL,CAAC;YACD,MAAM;QAER,KAAK,YAAY;YACf,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC;gBACxC,QAAQ,CAAC,IAAI,CAAC;oBACZ,OAAO,EAAE,oBAAoB,IAAI,CAAC,EAAE,kDAAkD;oBACtF,IAAI;iBACL,CAAC,CAAC;YACL,CAAC;YACD,MAAM;IACV,CAAC;AACH,CAAC;AAED,kDAAkD;AAClD,SAAS,cAAc,CAAC,GAAuB,EAAE,IAAiB;IAChE,IAAI,CAAC,GAAG;QAAE,OAAO;IACjB,MAAM,OAAO,GAAG,iCAAiC,CAAC;IAClD,IAAI,KAAK,CAAC;IACV,OAAO,CAAC,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;QAC5C,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACrB,CAAC;AACH,CAAC"}
@@ -0,0 +1,51 @@
1
+ /** Variable definition for workflow parameterization */
2
+ export interface WorkflowVariable {
3
+ required?: boolean;
4
+ type?: 'string' | 'integer' | 'array';
5
+ pattern?: string;
6
+ default?: string;
7
+ }
8
+ /** A single step within a workflow phase */
9
+ export interface WorkflowStep {
10
+ id: string;
11
+ type: 'command' | 'validation' | 'agent_input' | 'agent_work';
12
+ prompt?: string;
13
+ command?: string;
14
+ checkpoint?: string;
15
+ blocks_next?: boolean;
16
+ rules?: string[];
17
+ required_fields?: string[];
18
+ /** Validation conditions (for type=validation) */
19
+ conditions?: string[];
20
+ }
21
+ /** A phase containing ordered steps */
22
+ export interface WorkflowPhase {
23
+ id: string;
24
+ steps: WorkflowStep[];
25
+ /** Variable name containing array to iterate over */
26
+ repeat_for?: string;
27
+ /** Timeout in seconds for each repeated item */
28
+ timeout_per_item?: number;
29
+ /** Behavior when a repeated item times out */
30
+ on_timeout?: 'fail' | 'log_blocker_and_skip';
31
+ }
32
+ /** Top-level workflow definition */
33
+ export interface WorkflowDefinition {
34
+ name: string;
35
+ version: string;
36
+ description?: string;
37
+ variables?: Record<string, WorkflowVariable>;
38
+ phases: WorkflowPhase[];
39
+ }
40
+ /** Parse a YAML string into a WorkflowDefinition. Throws on invalid structure. */
41
+ export declare function parseWorkflow(yaml: string): WorkflowDefinition;
42
+ /** Valid step types for workflow definitions. Shared with the validator. */
43
+ export declare const VALID_STEP_TYPES: Set<string>;
44
+ /**
45
+ * Resolve `${varName}` references in all string values of a workflow definition.
46
+ * - Top-level string keys only (no nesting like `${x.y}`)
47
+ * - Missing variable at resolve time → error
48
+ * - Escaped `\${literal}` → `${literal}`
49
+ */
50
+ export declare function resolveVariables(def: WorkflowDefinition, vars: Record<string, string>): WorkflowDefinition;
51
+ //# sourceMappingURL=workflow.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflow.d.ts","sourceRoot":"","sources":["../../src/core/workflow.ts"],"names":[],"mappings":"AAOA,wDAAwD;AACxD,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,IAAI,CAAC,EAAE,QAAQ,GAAG,SAAS,GAAG,OAAO,CAAC;IACtC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,4CAA4C;AAC5C,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,SAAS,GAAG,YAAY,GAAG,aAAa,GAAG,YAAY,CAAC;IAC9D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,kDAAkD;IAClD,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;CACvB;AAED,uCAAuC;AACvC,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,YAAY,EAAE,CAAC;IACtB,qDAAqD;IACrD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,gDAAgD;IAChD,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,8CAA8C;IAC9C,UAAU,CAAC,EAAE,MAAM,GAAG,sBAAsB,CAAC;CAC9C;AAED,oCAAoC;AACpC,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IAC7C,MAAM,EAAE,aAAa,EAAE,CAAC;CACzB;AAID,kFAAkF;AAClF,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,CA0C9D;AAuBD,4EAA4E;AAC5E,eAAO,MAAM,gBAAgB,aAAkE,CAAC;AAoEhG;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,kBAAkB,EACvB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC3B,kBAAkB,CA0CpB"}
@@ -0,0 +1,190 @@
1
+ // SLOPE — Workflow Definition Types & YAML Parser
2
+ // Parses YAML 1.2 workflow definitions into typed structures for the workflow engine.
3
+ import { parseDocument } from 'yaml';
4
+ // --- Parser ---
5
+ /** Parse a YAML string into a WorkflowDefinition. Throws on invalid structure. */
6
+ export function parseWorkflow(yaml) {
7
+ const doc = parseDocument(yaml, { schema: 'core' });
8
+ if (doc.errors.length > 0) {
9
+ throw new Error(`YAML parse error: ${doc.errors[0].message}`);
10
+ }
11
+ const raw = doc.toJS();
12
+ if (!raw || typeof raw !== 'object') {
13
+ throw new Error('Workflow must be a YAML mapping');
14
+ }
15
+ // Required fields
16
+ if (!raw.name || typeof raw.name !== 'string') {
17
+ throw new Error('Workflow must have a string "name" field');
18
+ }
19
+ if (!raw.version || typeof raw.version !== 'string') {
20
+ throw new Error('Workflow must have a string "version" field');
21
+ }
22
+ if (!Array.isArray(raw.phases)) {
23
+ throw new Error('Workflow must have a "phases" array');
24
+ }
25
+ // Parse variables
26
+ const variables = raw.variables && typeof raw.variables === 'object' && !Array.isArray(raw.variables)
27
+ ? parseVariables(raw.variables)
28
+ : undefined;
29
+ // Parse phases
30
+ const phases = raw.phases.map((p, i) => parsePhase(p, i));
31
+ return {
32
+ name: raw.name,
33
+ version: raw.version,
34
+ description: typeof raw.description === 'string' ? raw.description : undefined,
35
+ variables,
36
+ phases,
37
+ };
38
+ }
39
+ function parseVariables(raw) {
40
+ const result = {};
41
+ for (const [key, val] of Object.entries(raw)) {
42
+ if (typeof val !== 'object' || val === null || Array.isArray(val)) {
43
+ throw new Error(`Variable "${key}" must be a mapping`);
44
+ }
45
+ const v = val;
46
+ result[key] = {
47
+ required: typeof v.required === 'boolean' ? v.required : undefined,
48
+ type: isVariableType(v.type) ? v.type : undefined,
49
+ pattern: typeof v.pattern === 'string' ? v.pattern : undefined,
50
+ default: v.default !== undefined ? String(v.default) : undefined,
51
+ };
52
+ }
53
+ return result;
54
+ }
55
+ function isVariableType(val) {
56
+ return val === 'string' || val === 'integer' || val === 'array';
57
+ }
58
+ /** Valid step types for workflow definitions. Shared with the validator. */
59
+ export const VALID_STEP_TYPES = new Set(['command', 'validation', 'agent_input', 'agent_work']);
60
+ function parsePhase(raw, index) {
61
+ if (!raw || typeof raw !== 'object' || Array.isArray(raw)) {
62
+ throw new Error(`Phase at index ${index} must be a mapping`);
63
+ }
64
+ const p = raw;
65
+ if (!p.id || typeof p.id !== 'string') {
66
+ throw new Error(`Phase at index ${index} must have a string "id"`);
67
+ }
68
+ if (!Array.isArray(p.steps)) {
69
+ throw new Error(`Phase "${p.id}" must have a "steps" array`);
70
+ }
71
+ const steps = p.steps.map((s, si) => parseStep(s, p.id, si));
72
+ return {
73
+ id: p.id,
74
+ steps,
75
+ repeat_for: typeof p.repeat_for === 'string' ? p.repeat_for : undefined,
76
+ timeout_per_item: typeof p.timeout_per_item === 'number' ? p.timeout_per_item : undefined,
77
+ on_timeout: p.on_timeout === 'fail' || p.on_timeout === 'log_blocker_and_skip'
78
+ ? p.on_timeout
79
+ : undefined,
80
+ };
81
+ }
82
+ function parseStep(raw, phaseId, index) {
83
+ if (!raw || typeof raw !== 'object' || Array.isArray(raw)) {
84
+ throw new Error(`Step at index ${index} in phase "${phaseId}" must be a mapping`);
85
+ }
86
+ const s = raw;
87
+ if (!s.id || typeof s.id !== 'string') {
88
+ throw new Error(`Step at index ${index} in phase "${phaseId}" must have a string "id"`);
89
+ }
90
+ if (!s.type || typeof s.type !== 'string' || !VALID_STEP_TYPES.has(s.type)) {
91
+ throw new Error(`Step "${s.id}" in phase "${phaseId}" must have a valid "type" (command|validation|agent_input|agent_work)`);
92
+ }
93
+ return {
94
+ id: s.id,
95
+ type: s.type,
96
+ prompt: typeof s.prompt === 'string' ? s.prompt : undefined,
97
+ command: typeof s.command === 'string' ? s.command : undefined,
98
+ checkpoint: typeof s.checkpoint === 'string' ? s.checkpoint : undefined,
99
+ blocks_next: typeof s.blocks_next === 'boolean' ? s.blocks_next : undefined,
100
+ rules: Array.isArray(s.rules) ? s.rules.map(r => String(r)) : undefined,
101
+ required_fields: Array.isArray(s.required_fields)
102
+ ? s.required_fields.map(r => String(r))
103
+ : undefined,
104
+ conditions: Array.isArray(s.conditions)
105
+ ? s.conditions.map(c => String(c))
106
+ : undefined,
107
+ };
108
+ }
109
+ // --- Variable Interpolation ---
110
+ /**
111
+ * Resolve `${varName}` references in all string values of a workflow definition.
112
+ * - Top-level string keys only (no nesting like `${x.y}`)
113
+ * - Missing variable at resolve time → error
114
+ * - Escaped `\${literal}` → `${literal}`
115
+ */
116
+ export function resolveVariables(def, vars) {
117
+ // Validate all required variables are provided
118
+ if (def.variables) {
119
+ for (const [name, spec] of Object.entries(def.variables)) {
120
+ if (spec.required && !(name in vars) && spec.default === undefined) {
121
+ throw new Error(`Required variable "${name}" not provided`);
122
+ }
123
+ }
124
+ }
125
+ // Build resolved vars: provided values + defaults
126
+ const resolved = {};
127
+ if (def.variables) {
128
+ for (const [name, spec] of Object.entries(def.variables)) {
129
+ if (name in vars) {
130
+ resolved[name] = vars[name];
131
+ }
132
+ else if (spec.default !== undefined) {
133
+ resolved[name] = spec.default;
134
+ }
135
+ }
136
+ }
137
+ // Also include any extra vars not in the schema
138
+ for (const [name, val] of Object.entries(vars)) {
139
+ if (!(name in resolved)) {
140
+ resolved[name] = val;
141
+ }
142
+ }
143
+ // Validate patterns
144
+ if (def.variables) {
145
+ for (const [name, spec] of Object.entries(def.variables)) {
146
+ if (spec.pattern && name in resolved) {
147
+ const re = new RegExp(spec.pattern);
148
+ if (!re.test(resolved[name])) {
149
+ throw new Error(`Variable "${name}" value "${resolved[name]}" does not match pattern "${spec.pattern}"`);
150
+ }
151
+ }
152
+ }
153
+ }
154
+ // Deep-clone and interpolate all string values (avoids JSON.stringify escape issues)
155
+ return deepInterpolate(def, resolved);
156
+ }
157
+ /** Recursively walk a value, interpolating ${var} in all strings. */
158
+ function deepInterpolate(value, vars) {
159
+ if (typeof value === 'string') {
160
+ return interpolateString(value, vars);
161
+ }
162
+ if (Array.isArray(value)) {
163
+ return value.map(item => deepInterpolate(item, vars));
164
+ }
165
+ if (value !== null && typeof value === 'object') {
166
+ const result = {};
167
+ for (const [key, val] of Object.entries(value)) {
168
+ result[key] = deepInterpolate(val, vars);
169
+ }
170
+ return result;
171
+ }
172
+ return value;
173
+ }
174
+ /** Interpolate ${var} references in a string. Throws on unresolved variables. */
175
+ function interpolateString(str, vars) {
176
+ // Replace escaped \${ with a placeholder, then restore after interpolation
177
+ const PLACEHOLDER = '\x00ESCAPED_DOLLAR\x00';
178
+ let result = str.replace(/\\\$\{/g, PLACEHOLDER);
179
+ // Find and replace ${varName} references
180
+ result = result.replace(/\$\{([a-zA-Z_][a-zA-Z0-9_]*)\}/g, (_match, name) => {
181
+ if (!(name in vars)) {
182
+ throw new Error(`Unresolved variable reference: \${${name}}`);
183
+ }
184
+ return vars[name];
185
+ });
186
+ // Restore escaped references as literal ${
187
+ result = result.replaceAll(PLACEHOLDER, '${');
188
+ return result;
189
+ }
190
+ //# sourceMappingURL=workflow.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflow.js","sourceRoot":"","sources":["../../src/core/workflow.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAClD,sFAAsF;AAEtF,OAAO,EAAE,aAAa,EAAE,MAAM,MAAM,CAAC;AA+CrC,iBAAiB;AAEjB,kFAAkF;AAClF,MAAM,UAAU,aAAa,CAAC,IAAY;IACxC,MAAM,GAAG,GAAG,aAAa,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAEpD,IAAI,GAAG,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,qBAAqB,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;IAChE,CAAC;IAED,MAAM,GAAG,GAAG,GAAG,CAAC,IAAI,EAA6B,CAAC;IAElD,IAAI,CAAC,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QACpC,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;IACrD,CAAC;IAED,kBAAkB;IAClB,IAAI,CAAC,GAAG,CAAC,IAAI,IAAI,OAAO,GAAG,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC9C,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;IAC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type { SlopeStore, SlopeConfig } from '../core/index.js';
4
4
  /** Tool names exposed by this MCP server (for tests and tool discovery). */
5
- export declare const SLOPE_MCP_TOOL_NAMES: readonly ["search", "execute", "context_search", "session_status", "acquire_claim", "check_conflicts", "store_status", "testing_session_start", "testing_session_finding", "testing_session_end", "testing_session_status", "testing_plan_status"];
5
+ export declare const SLOPE_MCP_TOOL_NAMES: readonly ["search", "execute", "context_search", "session_status", "acquire_claim", "check_conflicts", "store_status", "testing_session_start", "testing_session_finding", "testing_session_end", "testing_session_status", "testing_plan_status", "workflow_next", "workflow_complete", "workflow_status"];
6
6
  /** Detection results for hook/settings activation status. */
7
7
  export interface SetupHints {
8
8
  guardsInstalled: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":";AAwBA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAKpE,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAMhE,4EAA4E;AAC5E,eAAO,MAAM,oBAAoB,oPAAqP,CAAC;AAEvR,6DAA6D;AAC7D,MAAM,WAAW,UAAU;IACzB,eAAe,EAAE,OAAO,CAAC;IACzB,uBAAuB,EAAE,OAAO,CAAC;IACjC,kBAAkB,EAAE,OAAO,CAAC;CAC7B;AAED,0EAA0E;AAC1E,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,MAAM,GAAG,UAAU,CAkChE;AAED,6EAA6E;AAC7E,wBAAgB,cAAc,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,GAAG,IAAI,CA+B/D;AAED,wBAAgB,sBAAsB,CAAC,KAAK,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,EAAE,UAAU,EAAE,SAAS,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,SAAS,CA+nBvI"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":";AAwBA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAKpE,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAMhE,4EAA4E;AAC5E,eAAO,MAAM,oBAAoB,6SAA8S,CAAC;AAEhV,6DAA6D;AAC7D,MAAM,WAAW,UAAU;IACzB,eAAe,EAAE,OAAO,CAAC;IACzB,uBAAuB,EAAE,OAAO,CAAC;IACjC,kBAAkB,EAAE,OAAO,CAAC;CAC7B;AAED,0EAA0E;AAC1E,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,MAAM,GAAG,UAAU,CAkChE;AAED,6EAA6E;AAC7E,wBAAgB,cAAc,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,GAAG,IAAI,CA+B/D;AAED,wBAAgB,sBAAsB,CAAC,KAAK,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,EAAE,UAAU,EAAE,SAAS,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,SAAS,CA6yBvI"}
package/dist/mcp/index.js CHANGED
@@ -27,10 +27,10 @@ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
27
27
  import { z } from 'zod';
28
28
  import { SLOPE_REGISTRY, SLOPE_TYPES } from './registry.js';
29
29
  import { runInSandbox } from './sandbox.js';
30
- import { checkConflicts, loadFlows, checkFlowStaleness, checkStoreHealth, METAPHOR_SCHEMA, listMetaphors, buildInterviewContext, generateInterviewSteps, loadConfig, parseTestPlan, getAreasNeedingTest, hasEmbeddingSupport, embed, deduplicateByFile, formatContextForAgent } from '../core/index.js';
30
+ import { checkConflicts, loadFlows, checkFlowStaleness, checkStoreHealth, METAPHOR_SCHEMA, listMetaphors, buildInterviewContext, generateInterviewSteps, loadConfig, parseTestPlan, getAreasNeedingTest, hasEmbeddingSupport, embed, deduplicateByFile, formatContextForAgent, WorkflowEngine, loadWorkflow, resolveVariables } from '../core/index.js';
31
31
  import { gaming } from '../core/metaphors/gaming.js';
32
32
  /** Tool names exposed by this MCP server (for tests and tool discovery). */
33
- export const SLOPE_MCP_TOOL_NAMES = ['search', 'execute', 'context_search', 'session_status', 'acquire_claim', 'check_conflicts', 'store_status', 'testing_session_start', 'testing_session_finding', 'testing_session_end', 'testing_session_status', 'testing_plan_status'];
33
+ export const SLOPE_MCP_TOOL_NAMES = ['search', 'execute', 'context_search', 'session_status', 'acquire_claim', 'check_conflicts', 'store_status', 'testing_session_start', 'testing_session_finding', 'testing_session_end', 'testing_session_status', 'testing_plan_status', 'workflow_next', 'workflow_complete', 'workflow_status'];
34
34
  /** Detect which SLOPE hooks and settings are activated in the project. */
35
35
  export function detectSetupHints(projectRoot) {
36
36
  const hints = {
@@ -614,6 +614,142 @@ export function createSlopeToolsServer(store, setupHints, storeType, config) {
614
614
  };
615
615
  return { content: [{ type: 'text', text: JSON.stringify(response, null, 2) }] };
616
616
  });
617
+ // --- Workflow Tools ---
618
+ /** Resolve project root, falling back to cwd */
619
+ function safeProjectRoot() {
620
+ try {
621
+ return findProjectRoot(process.cwd());
622
+ }
623
+ catch {
624
+ return process.cwd();
625
+ }
626
+ }
627
+ const workflowEngine = new WorkflowEngine();
628
+ server.tool('workflow_next', 'Get the next step in a workflow execution. Returns the current step to execute, or signals completion.', {
629
+ execution_id: z.string().optional().describe('Workflow execution ID'),
630
+ session_id: z.string().optional().describe('Session ID to find active execution'),
631
+ }, async ({ execution_id, session_id }) => {
632
+ try {
633
+ let execId = execution_id;
634
+ // Fallback: find execution by session
635
+ if (!execId && session_id) {
636
+ const executions = await store.listExecutions({ status: 'running' });
637
+ const match = executions.find(e => e.session_id === session_id);
638
+ if (!match) {
639
+ return { content: [{ type: 'text', text: JSON.stringify({ error: `No active workflow execution found for session "${session_id}"` }) }], isError: true };
640
+ }
641
+ execId = match.id;
642
+ }
643
+ if (!execId) {
644
+ return { content: [{ type: 'text', text: JSON.stringify({ error: 'Either execution_id or session_id is required' }) }], isError: true };
645
+ }
646
+ const execution = await store.getExecution(execId);
647
+ if (!execution) {
648
+ return { content: [{ type: 'text', text: JSON.stringify({ error: `Execution "${execId}" not found` }) }], isError: true };
649
+ }
650
+ // Load and resolve the workflow definition
651
+ const def = resolveVariables(loadWorkflow(execution.workflow_name, safeProjectRoot()), execution.variables);
652
+ const next = await workflowEngine.next(execId, def, store);
653
+ return {
654
+ content: [{
655
+ type: 'text',
656
+ text: JSON.stringify({
657
+ execution_id: execId,
658
+ ...next,
659
+ }, null, 2),
660
+ }],
661
+ };
662
+ }
663
+ catch (err) {
664
+ return { content: [{ type: 'text', text: JSON.stringify({ error: err.message }) }], isError: true };
665
+ }
666
+ });
667
+ server.tool('workflow_complete', 'Complete the current step in a workflow execution and advance to the next step.', {
668
+ execution_id: z.string().describe('Workflow execution ID'),
669
+ step_id: z.string().describe('Step ID being completed'),
670
+ output: z.record(z.unknown()).optional().describe('Step output data'),
671
+ exit_code: z.number().optional().describe('Exit code for command steps'),
672
+ }, async ({ execution_id, step_id, output, exit_code }) => {
673
+ try {
674
+ const execution = await store.getExecution(execution_id);
675
+ if (!execution) {
676
+ return { content: [{ type: 'text', text: JSON.stringify({ error: `Execution "${execution_id}" not found` }) }], isError: true };
677
+ }
678
+ const def = resolveVariables(loadWorkflow(execution.workflow_name, safeProjectRoot()), execution.variables);
679
+ const result = await workflowEngine.complete(execution_id, step_id, { output: output, exit_code }, def, store);
680
+ return {
681
+ content: [{
682
+ type: 'text',
683
+ text: JSON.stringify({
684
+ execution_id,
685
+ ...result,
686
+ }, null, 2),
687
+ }],
688
+ };
689
+ }
690
+ catch (err) {
691
+ return { content: [{ type: 'text', text: JSON.stringify({ error: err.message }) }], isError: true };
692
+ }
693
+ });
694
+ server.tool('workflow_status', 'Show the status of a workflow execution with progress summary.', {
695
+ execution_id: z.string().optional().describe('Specific execution ID, or omit for all active executions'),
696
+ }, async ({ execution_id }) => {
697
+ try {
698
+ if (execution_id) {
699
+ const execution = await store.getExecution(execution_id);
700
+ if (!execution) {
701
+ return { content: [{ type: 'text', text: JSON.stringify({ error: `Execution "${execution_id}" not found` }) }], isError: true };
702
+ }
703
+ // Load def to compute total steps (accounting for repeat_for multiplier)
704
+ let totalSteps = 0;
705
+ try {
706
+ const def = resolveVariables(loadWorkflow(execution.workflow_name, safeProjectRoot()), execution.variables);
707
+ totalSteps = def.phases.reduce((sum, p) => {
708
+ const stepCount = p.steps.length;
709
+ if (p.repeat_for && execution.variables[p.repeat_for]) {
710
+ const items = execution.variables[p.repeat_for].split(',').filter(Boolean);
711
+ return sum + stepCount * items.length;
712
+ }
713
+ return sum + stepCount;
714
+ }, 0);
715
+ }
716
+ catch { /* def not available — ok */ }
717
+ return {
718
+ content: [{
719
+ type: 'text',
720
+ text: JSON.stringify({
721
+ ...execution,
722
+ progress: {
723
+ completed_steps: execution.completed_steps.length,
724
+ total_steps: totalSteps || undefined,
725
+ },
726
+ }, null, 2),
727
+ }],
728
+ };
729
+ }
730
+ // List all active executions
731
+ const active = await store.listExecutions({ status: 'running' });
732
+ return {
733
+ content: [{
734
+ type: 'text',
735
+ text: JSON.stringify({
736
+ active_executions: active.map(e => ({
737
+ id: e.id,
738
+ workflow_name: e.workflow_name,
739
+ sprint_id: e.sprint_id,
740
+ current_phase: e.current_phase,
741
+ current_step: e.current_step,
742
+ completed_steps: e.completed_steps.length,
743
+ started_at: e.started_at,
744
+ })),
745
+ }, null, 2),
746
+ }],
747
+ };
748
+ }
749
+ catch (err) {
750
+ return { content: [{ type: 'text', text: JSON.stringify({ error: err.message }) }], isError: true };
751
+ }
752
+ });
617
753
  }
618
754
  return server;
619
755
  }