@exaudeus/workrail 1.13.1 → 1.13.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/dist/application/services/enhanced-loop-validator.d.ts +1 -0
- package/dist/application/services/enhanced-loop-validator.js +38 -7
- package/dist/application/use-cases/validate-workflow-json.js +2 -2
- package/dist/manifest.json +34 -34
- package/dist/mcp/handlers/v2-advance-core/outcome-success.js +3 -0
- package/dist/mcp/handlers/v2-error-mapping.d.ts +3 -0
- package/dist/mcp/handlers/v2-error-mapping.js +2 -0
- package/dist/mcp/handlers/v2-execution/continue-advance.js +7 -0
- package/dist/mcp/handlers/workflow.js +3 -2
- package/dist/v2/infra/local/directory-listing/index.d.ts +2 -1
- package/dist/v2/infra/local/directory-listing/index.js +8 -0
- package/dist/v2/infra/local/fs/index.d.ts +2 -1
- package/dist/v2/infra/local/fs/index.js +24 -0
- package/dist/v2/infra/local/session-summary-provider/index.js +1 -1
- package/dist/v2/ports/directory-listing.port.d.ts +5 -0
- package/dist/v2/ports/fs.port.d.ts +5 -0
- package/dist/v2/usecases/enumerate-sessions.d.ts +4 -0
- package/dist/v2/usecases/enumerate-sessions.js +13 -0
- package/package.json +1 -1
|
@@ -13,6 +13,7 @@ export declare class EnhancedLoopValidator {
|
|
|
13
13
|
validateLoopStep(step: LoopStepDefinition): EnhancedValidationResult;
|
|
14
14
|
private getLoopBodySteps;
|
|
15
15
|
private validateConditionalLogic;
|
|
16
|
+
private getPromptText;
|
|
16
17
|
private validatePromptLength;
|
|
17
18
|
private validateTemplateVariables;
|
|
18
19
|
private getKnownLoopVariables;
|
|
@@ -55,10 +55,40 @@ let EnhancedLoopValidator = class EnhancedLoopValidator {
|
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
+
getPromptText(step) {
|
|
59
|
+
if (step.prompt)
|
|
60
|
+
return step.prompt;
|
|
61
|
+
if (!step.promptBlocks)
|
|
62
|
+
return undefined;
|
|
63
|
+
const parts = [];
|
|
64
|
+
const b = step.promptBlocks;
|
|
65
|
+
if (typeof b.goal === 'string')
|
|
66
|
+
parts.push(b.goal);
|
|
67
|
+
if (Array.isArray(b.constraints)) {
|
|
68
|
+
for (const c of b.constraints) {
|
|
69
|
+
if (typeof c === 'string')
|
|
70
|
+
parts.push(c);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (Array.isArray(b.procedure)) {
|
|
74
|
+
for (const p of b.procedure) {
|
|
75
|
+
if (typeof p === 'string')
|
|
76
|
+
parts.push(p);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (Array.isArray(b.verify)) {
|
|
80
|
+
for (const v of b.verify) {
|
|
81
|
+
if (typeof v === 'string')
|
|
82
|
+
parts.push(v);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return parts.length > 0 ? parts.join('\n') : undefined;
|
|
86
|
+
}
|
|
58
87
|
validatePromptLength(step, warnings, suggestions) {
|
|
59
|
-
|
|
88
|
+
const promptText = this.getPromptText(step);
|
|
89
|
+
if (!promptText)
|
|
60
90
|
return;
|
|
61
|
-
const promptLength =
|
|
91
|
+
const promptLength = promptText.length;
|
|
62
92
|
if (promptLength > this.PROMPT_ERROR_THRESHOLD) {
|
|
63
93
|
warnings.push(`Step '${step.id}' has a very long prompt (${promptLength} characters). This may cause issues.`);
|
|
64
94
|
suggestions.push(`Consider splitting this into multiple steps or moving content to the guidance section.`);
|
|
@@ -67,7 +97,7 @@ let EnhancedLoopValidator = class EnhancedLoopValidator {
|
|
|
67
97
|
warnings.push(`Step '${step.id}' has a long prompt (${promptLength} characters).`);
|
|
68
98
|
suggestions.push(`For better maintainability, consider breaking this into smaller, focused steps.`);
|
|
69
99
|
}
|
|
70
|
-
const conditionalMatches = step.prompt
|
|
100
|
+
const conditionalMatches = step.prompt?.match(/\{\{[^}]*\?[^}]*\}\}/g);
|
|
71
101
|
if (conditionalMatches) {
|
|
72
102
|
let totalConditionalContent = 0;
|
|
73
103
|
for (const match of conditionalMatches) {
|
|
@@ -115,15 +145,16 @@ let EnhancedLoopValidator = class EnhancedLoopValidator {
|
|
|
115
145
|
const bodySteps = this.getLoopBodySteps(step);
|
|
116
146
|
if (step.loop.type === 'for' && bodySteps.length > 0) {
|
|
117
147
|
const firstStep = bodySteps[0];
|
|
118
|
-
|
|
148
|
+
const firstPrompt = this.getPromptText(firstStep);
|
|
149
|
+
if (firstPrompt?.includes('analysis') ||
|
|
119
150
|
firstStep.title?.toLowerCase().includes('analysis') ||
|
|
120
|
-
|
|
121
|
-
|
|
151
|
+
firstPrompt?.includes('Step 1') ||
|
|
152
|
+
firstPrompt?.includes('Structure')) {
|
|
122
153
|
info.push('Progressive analysis pattern detected.');
|
|
123
154
|
suggestions.push('Consider using the multi-step pattern with separate steps and runCondition for clearer structure.');
|
|
124
155
|
}
|
|
125
156
|
}
|
|
126
|
-
if (bodySteps.some(s => s
|
|
157
|
+
if (bodySteps.some(s => { const p = this.getPromptText(s); return p?.includes('===') && p?.includes('?'); })) {
|
|
127
158
|
info.push('Multi-conditional loop pattern detected.');
|
|
128
159
|
suggestions.push('For loops with multiple conditional paths, the separate steps pattern is more maintainable than inline conditionals.');
|
|
129
160
|
}
|
|
@@ -67,10 +67,10 @@ function generateSuggestions(errors) {
|
|
|
67
67
|
suggestions.push('Use semantic versioning format (e.g., "0.0.1", "1.0.0").');
|
|
68
68
|
}
|
|
69
69
|
if (errorText.includes('steps')) {
|
|
70
|
-
suggestions.push('Ensure the workflow has at least one step with id, title, and prompt
|
|
70
|
+
suggestions.push('Ensure the workflow has at least one step with id, title, and either prompt or promptBlocks.');
|
|
71
71
|
}
|
|
72
72
|
if (errorText.includes('step')) {
|
|
73
|
-
suggestions.push('Check that all steps have required fields: id, title, and prompt.');
|
|
73
|
+
suggestions.push('Check that all steps have required fields: id, title, and either prompt or promptBlocks.');
|
|
74
74
|
}
|
|
75
75
|
if (errorText.includes('pattern')) {
|
|
76
76
|
suggestions.push('Review the workflow schema documentation for correct field formats.');
|
package/dist/manifest.json
CHANGED
|
@@ -66,12 +66,12 @@
|
|
|
66
66
|
"bytes": 6252
|
|
67
67
|
},
|
|
68
68
|
"application/services/enhanced-loop-validator.d.ts": {
|
|
69
|
-
"sha256": "
|
|
70
|
-
"bytes":
|
|
69
|
+
"sha256": "bef909cb861b88beda04b44110f8abb18181bb82be22bfbde5fe819a66654d52",
|
|
70
|
+
"bytes": 801
|
|
71
71
|
},
|
|
72
72
|
"application/services/enhanced-loop-validator.js": {
|
|
73
|
-
"sha256": "
|
|
74
|
-
"bytes":
|
|
73
|
+
"sha256": "148e75778723842874037c1d0c4fc3ab737787ddb9e3c78c5386cd49abfd065e",
|
|
74
|
+
"bytes": 9020
|
|
75
75
|
},
|
|
76
76
|
"application/services/output-normalizer.d.ts": {
|
|
77
77
|
"sha256": "35bd9e50e984132f83dac874f90c2a4e9e8223202c6832426654232c5d7e2236",
|
|
@@ -166,8 +166,8 @@
|
|
|
166
166
|
"bytes": 345
|
|
167
167
|
},
|
|
168
168
|
"application/use-cases/validate-workflow-json.js": {
|
|
169
|
-
"sha256": "
|
|
170
|
-
"bytes":
|
|
169
|
+
"sha256": "87caff4501c5ee59ce73fc37762eeedc1e00253c7bf7f432349288e07810293f",
|
|
170
|
+
"bytes": 3690
|
|
171
171
|
},
|
|
172
172
|
"application/validation.d.ts": {
|
|
173
173
|
"sha256": "2b44ccd1db66c81d8d5306e4b3453b50c27bb5c2c4bec85191b325c339d188cc",
|
|
@@ -646,8 +646,8 @@
|
|
|
646
646
|
"bytes": 936
|
|
647
647
|
},
|
|
648
648
|
"mcp/handlers/v2-advance-core/outcome-success.js": {
|
|
649
|
-
"sha256": "
|
|
650
|
-
"bytes":
|
|
649
|
+
"sha256": "b0e2f52b8843b067b1ca1c3aa6e797d3b6ad7bf175c46b1f036e70fc2174f992",
|
|
650
|
+
"bytes": 6129
|
|
651
651
|
},
|
|
652
652
|
"mcp/handlers/v2-advance-events.d.ts": {
|
|
653
653
|
"sha256": "02cdb52a2c16dd619645b5496caf0880e57937bf21ea9efe44e6cd195cd43b94",
|
|
@@ -674,12 +674,12 @@
|
|
|
674
674
|
"bytes": 7199
|
|
675
675
|
},
|
|
676
676
|
"mcp/handlers/v2-error-mapping.d.ts": {
|
|
677
|
-
"sha256": "
|
|
678
|
-
"bytes":
|
|
677
|
+
"sha256": "1cf58654dd6f70a0e35b75435c835a410658a2c7220d1b86561124476c8742fa",
|
|
678
|
+
"bytes": 1798
|
|
679
679
|
},
|
|
680
680
|
"mcp/handlers/v2-error-mapping.js": {
|
|
681
|
-
"sha256": "
|
|
682
|
-
"bytes":
|
|
681
|
+
"sha256": "f63c6711fdd05cf89d7da5f1441a17efa540b2f4985f85759c7f740a6cf2e854",
|
|
682
|
+
"bytes": 10664
|
|
683
683
|
},
|
|
684
684
|
"mcp/handlers/v2-execution-helpers.d.ts": {
|
|
685
685
|
"sha256": "1e52f266e991a9447d1254bf047f6a09062b038ed3363a3818d1f5c91eed2fc8",
|
|
@@ -710,8 +710,8 @@
|
|
|
710
710
|
"bytes": 1830
|
|
711
711
|
},
|
|
712
712
|
"mcp/handlers/v2-execution/continue-advance.js": {
|
|
713
|
-
"sha256": "
|
|
714
|
-
"bytes":
|
|
713
|
+
"sha256": "864b892e6e69afbe300dbc748d0b6f3476d299b5cbaea36b5197748f9972611b",
|
|
714
|
+
"bytes": 8332
|
|
715
715
|
},
|
|
716
716
|
"mcp/handlers/v2-execution/continue-rehydrate.d.ts": {
|
|
717
717
|
"sha256": "af7475b7effe57f18fa8379bfd128d17afb2d27fe1c058c6f2ee8f5b2632e3d0",
|
|
@@ -790,8 +790,8 @@
|
|
|
790
790
|
"bytes": 1748
|
|
791
791
|
},
|
|
792
792
|
"mcp/handlers/workflow.js": {
|
|
793
|
-
"sha256": "
|
|
794
|
-
"bytes":
|
|
793
|
+
"sha256": "c95bbef83298b7d518e5e587147bdf83546bba77d3ef026c3598e8b0c6168004",
|
|
794
|
+
"bytes": 8233
|
|
795
795
|
},
|
|
796
796
|
"mcp/index.d.ts": {
|
|
797
797
|
"sha256": "525b4247cf90ba3af66769462bcfaab5dbf38ee8c49d2a9ceec1e4b38e33511b",
|
|
@@ -1802,20 +1802,20 @@
|
|
|
1802
1802
|
"bytes": 3036
|
|
1803
1803
|
},
|
|
1804
1804
|
"v2/infra/local/directory-listing/index.d.ts": {
|
|
1805
|
-
"sha256": "
|
|
1806
|
-
"bytes":
|
|
1805
|
+
"sha256": "3139014cb738db3b0f10beca01a3a4a35b9ab8e72c8889b3bbff204fdbcb6b6c",
|
|
1806
|
+
"bytes": 557
|
|
1807
1807
|
},
|
|
1808
1808
|
"v2/infra/local/directory-listing/index.js": {
|
|
1809
|
-
"sha256": "
|
|
1810
|
-
"bytes":
|
|
1809
|
+
"sha256": "f3ed94836fa657dc34692378635efa12a5446e5f63c07637b3476a872e5064b1",
|
|
1810
|
+
"bytes": 844
|
|
1811
1811
|
},
|
|
1812
1812
|
"v2/infra/local/fs/index.d.ts": {
|
|
1813
|
-
"sha256": "
|
|
1814
|
-
"bytes":
|
|
1813
|
+
"sha256": "dcfe3510dc6a8d92ededdb9c1376702dc88455ccb189eb7dc3ba2721b6b43d38",
|
|
1814
|
+
"bytes": 1437
|
|
1815
1815
|
},
|
|
1816
1816
|
"v2/infra/local/fs/index.js": {
|
|
1817
|
-
"sha256": "
|
|
1818
|
-
"bytes":
|
|
1817
|
+
"sha256": "6d898cf90fd022530fb4ee4c03e0127955895d9da0f4ef52d85d8843803466df",
|
|
1818
|
+
"bytes": 8262
|
|
1819
1819
|
},
|
|
1820
1820
|
"v2/infra/local/hmac-sha256/index.d.ts": {
|
|
1821
1821
|
"sha256": "dda3865510dfaf2f13947410d998da6ffecc9a2e728b3574f81e69d5db859815",
|
|
@@ -1878,8 +1878,8 @@
|
|
|
1878
1878
|
"bytes": 1004
|
|
1879
1879
|
},
|
|
1880
1880
|
"v2/infra/local/session-summary-provider/index.js": {
|
|
1881
|
-
"sha256": "
|
|
1882
|
-
"bytes":
|
|
1881
|
+
"sha256": "1d8a543361c582f6e089f63f24318ff7caf97a78659ecdc5b89152b78d18c6aa",
|
|
1882
|
+
"bytes": 5942
|
|
1883
1883
|
},
|
|
1884
1884
|
"v2/infra/local/sha256/index.d.ts": {
|
|
1885
1885
|
"sha256": "8a727b7e54a38275ca6f9f1b8730f97cfc0a212df035df1bdc58e716e6824230",
|
|
@@ -1954,16 +1954,16 @@
|
|
|
1954
1954
|
"bytes": 77
|
|
1955
1955
|
},
|
|
1956
1956
|
"v2/ports/directory-listing.port.d.ts": {
|
|
1957
|
-
"sha256": "
|
|
1958
|
-
"bytes":
|
|
1957
|
+
"sha256": "d707e849df351d2cf619942771b68dfeaa14095618ed3f3109e71da4d5f8d0fa",
|
|
1958
|
+
"bytes": 394
|
|
1959
1959
|
},
|
|
1960
1960
|
"v2/ports/directory-listing.port.js": {
|
|
1961
1961
|
"sha256": "d43aa81f5bc89faa359e0f97c814ba25155591ff078fbb9bfd40f8c7c9683230",
|
|
1962
1962
|
"bytes": 77
|
|
1963
1963
|
},
|
|
1964
1964
|
"v2/ports/fs.port.d.ts": {
|
|
1965
|
-
"sha256": "
|
|
1966
|
-
"bytes":
|
|
1965
|
+
"sha256": "49b481e09333784c5bbb95293a0cc1833ed5fe498aa3a52e86fad076fefe08d9",
|
|
1966
|
+
"bytes": 2182
|
|
1967
1967
|
},
|
|
1968
1968
|
"v2/ports/fs.port.js": {
|
|
1969
1969
|
"sha256": "d43aa81f5bc89faa359e0f97c814ba25155591ff078fbb9bfd40f8c7c9683230",
|
|
@@ -2178,12 +2178,12 @@
|
|
|
2178
2178
|
"bytes": 2678
|
|
2179
2179
|
},
|
|
2180
2180
|
"v2/usecases/enumerate-sessions.d.ts": {
|
|
2181
|
-
"sha256": "
|
|
2182
|
-
"bytes":
|
|
2181
|
+
"sha256": "46da8960bdeb154f79dee443425260f3ce18c50a0db01e7ab60700432d864857",
|
|
2182
|
+
"bytes": 699
|
|
2183
2183
|
},
|
|
2184
2184
|
"v2/usecases/enumerate-sessions.js": {
|
|
2185
|
-
"sha256": "
|
|
2186
|
-
"bytes":
|
|
2185
|
+
"sha256": "4ae73f47c1e8ebea0d9a48dc786e5e4d0442a38827c427378712e9d198410ae2",
|
|
2186
|
+
"bytes": 1050
|
|
2187
2187
|
},
|
|
2188
2188
|
"v2/usecases/execution-session-gate.d.ts": {
|
|
2189
2189
|
"sha256": "339c4a8e02a77416e725e063a57d39a20788244498ae2c7a31dc48d111af6280",
|
|
@@ -44,6 +44,9 @@ function buildSuccessOutcome(args) {
|
|
|
44
44
|
});
|
|
45
45
|
const nextRes = interpreter.next(compiledWf.value, advanced.value, v.mergedContext, artifactsForEval);
|
|
46
46
|
if (nextRes.isErr()) {
|
|
47
|
+
if (nextRes.error._tag === 'MissingContext') {
|
|
48
|
+
return errAsync({ kind: 'advance_next_missing_context', message: nextRes.error.message });
|
|
49
|
+
}
|
|
47
50
|
return errAsync({ kind: 'advance_next_failed', message: nextRes.error.message });
|
|
48
51
|
}
|
|
49
52
|
const out = nextRes.value;
|
|
@@ -122,6 +122,8 @@ function mapInternalErrorToToolError(e) {
|
|
|
122
122
|
return internalError('WorkRail could not record the workflow advancement. This is not caused by your input.', (0, v2_execution_helpers_js_1.internalSuggestion)('Retry the call.', 'WorkRail could not record the advancement.'));
|
|
123
123
|
case 'advance_next_failed':
|
|
124
124
|
return internalError('WorkRail could not compute the next workflow step. This is not caused by your input.', (0, v2_execution_helpers_js_1.internalSuggestion)('Retry the call.', 'WorkRail could not compute the next step.'));
|
|
125
|
+
case 'advance_next_missing_context':
|
|
126
|
+
return (0, types_js_1.errNotRetryable)('PRECONDITION_FAILED', e.message, { suggestion: 'Set the required context variable in the `context` field of your continue_workflow output. The variable must be a JSON array.' });
|
|
125
127
|
default:
|
|
126
128
|
const _exhaustive = e;
|
|
127
129
|
return internalError('WorkRail encountered an unexpected error. This is not caused by your input.', (0, v2_execution_helpers_js_1.internalSuggestion)('Retry the call.', 'WorkRail has an internal error.'));
|
|
@@ -120,6 +120,13 @@ function handleAdvanceIntent(args) {
|
|
|
120
120
|
}))
|
|
121
121
|
.mapErr((cause) => {
|
|
122
122
|
if ((0, v2_error_mapping_js_1.isInternalError)(cause)) {
|
|
123
|
+
if (cause.kind === 'advance_next_missing_context') {
|
|
124
|
+
return {
|
|
125
|
+
kind: 'precondition_failed',
|
|
126
|
+
message: cause.message,
|
|
127
|
+
suggestion: 'Set the required context variable in the `context` field of your continue_workflow output. The variable must be a JSON array.',
|
|
128
|
+
};
|
|
129
|
+
}
|
|
123
130
|
return {
|
|
124
131
|
kind: 'invariant_violation',
|
|
125
132
|
message: `Advance failed due to internal error: ${cause.kind}`,
|
|
@@ -153,8 +153,9 @@ async function handleWorkflowGetSchema(_input, ctx) {
|
|
|
153
153
|
stepStructure: {
|
|
154
154
|
id: 'string (required): Unique step identifier',
|
|
155
155
|
title: 'string (required): Human-readable step title',
|
|
156
|
-
prompt: 'string (
|
|
157
|
-
|
|
156
|
+
prompt: 'string (optional): Instructions for the step (use prompt OR promptBlocks)',
|
|
157
|
+
promptBlocks: 'object (optional): Structured prompt blocks (goal, constraints, procedure, outputRequired, verify)',
|
|
158
|
+
agentRole: 'string (optional): Role description for the agent',
|
|
158
159
|
validationCriteria: 'array (optional): Validation rules for step output',
|
|
159
160
|
},
|
|
160
161
|
},
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { ResultAsync } from 'neverthrow';
|
|
2
2
|
import type { FsError, DirectoryListingOpsPortV2 } from '../../../ports/fs.port.js';
|
|
3
|
-
import type { DirectoryListingPortV2 } from '../../../ports/directory-listing.port.js';
|
|
3
|
+
import type { DirectoryListingPortV2, DirEntryWithMtime } from '../../../ports/directory-listing.port.js';
|
|
4
4
|
export declare class LocalDirectoryListingV2 implements DirectoryListingPortV2 {
|
|
5
5
|
private readonly fs;
|
|
6
6
|
constructor(fs: DirectoryListingOpsPortV2);
|
|
7
7
|
readdir(dirPath: string): ResultAsync<readonly string[], FsError>;
|
|
8
|
+
readdirWithMtime(dirPath: string): ResultAsync<readonly DirEntryWithMtime[], FsError>;
|
|
8
9
|
}
|
|
@@ -14,5 +14,13 @@ class LocalDirectoryListingV2 {
|
|
|
14
14
|
return (0, neverthrow_1.errAsync)(e);
|
|
15
15
|
});
|
|
16
16
|
}
|
|
17
|
+
readdirWithMtime(dirPath) {
|
|
18
|
+
return this.fs.readdirWithMtime(dirPath).orElse((e) => {
|
|
19
|
+
if (e.code === 'FS_NOT_FOUND') {
|
|
20
|
+
return (0, neverthrow_1.okAsync)([]);
|
|
21
|
+
}
|
|
22
|
+
return (0, neverthrow_1.errAsync)(e);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
17
25
|
}
|
|
18
26
|
exports.LocalDirectoryListingV2 = LocalDirectoryListingV2;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ResultAsync } from 'neverthrow';
|
|
2
|
-
import type { FileSystemPortV2, FsError } from '../../../ports/fs.port.js';
|
|
2
|
+
import type { FileSystemPortV2, FsError, FsDirEntryWithMtime } from '../../../ports/fs.port.js';
|
|
3
3
|
export declare class NodeFileSystemV2 implements FileSystemPortV2 {
|
|
4
4
|
mkdirp(dirPath: string): ResultAsync<void, FsError>;
|
|
5
5
|
readFileUtf8(filePath: string): ResultAsync<string, FsError>;
|
|
@@ -24,4 +24,5 @@ export declare class NodeFileSystemV2 implements FileSystemPortV2 {
|
|
|
24
24
|
readonly sizeBytes: number;
|
|
25
25
|
}, FsError>;
|
|
26
26
|
readdir(dirPath: string): ResultAsync<readonly string[], FsError>;
|
|
27
|
+
readdirWithMtime(dirPath: string): ResultAsync<readonly FsDirEntryWithMtime[], FsError>;
|
|
27
28
|
}
|
|
@@ -38,6 +38,7 @@ const fs = __importStar(require("fs/promises"));
|
|
|
38
38
|
const fsCb = __importStar(require("fs"));
|
|
39
39
|
const fs_1 = require("fs");
|
|
40
40
|
const neverthrow_1 = require("neverthrow");
|
|
41
|
+
const path = __importStar(require("path"));
|
|
41
42
|
function nodeErrorCode(e) {
|
|
42
43
|
if (typeof e !== 'object' || e === null)
|
|
43
44
|
return undefined;
|
|
@@ -162,5 +163,28 @@ class NodeFileSystemV2 {
|
|
|
162
163
|
readdir(dirPath) {
|
|
163
164
|
return neverthrow_1.ResultAsync.fromPromise(fs.readdir(dirPath), (e) => mapFsError(e, dirPath));
|
|
164
165
|
}
|
|
166
|
+
readdirWithMtime(dirPath) {
|
|
167
|
+
return neverthrow_1.ResultAsync.fromPromise((async () => {
|
|
168
|
+
const entries = await fs.readdir(dirPath);
|
|
169
|
+
const withMtime = [];
|
|
170
|
+
let skipped = 0;
|
|
171
|
+
for (const name of entries) {
|
|
172
|
+
try {
|
|
173
|
+
const stats = await fs.stat(path.join(dirPath, name));
|
|
174
|
+
withMtime.push({ name, mtimeMs: stats.mtimeMs });
|
|
175
|
+
}
|
|
176
|
+
catch (e) {
|
|
177
|
+
const code = nodeErrorCode(e);
|
|
178
|
+
skipped++;
|
|
179
|
+
console.error(`[workrail:session-enum] Skipping ${name}: stat failed (${code ?? 'unknown'}: ${e instanceof Error ? e.message : String(e)})`);
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
if (skipped > 0) {
|
|
184
|
+
console.error(`[workrail:session-enum] Enumerated ${withMtime.length} sessions, skipped ${skipped} (stat failures)`);
|
|
185
|
+
}
|
|
186
|
+
return withMtime;
|
|
187
|
+
})(), (e) => mapFsError(e, dirPath));
|
|
188
|
+
}
|
|
165
189
|
}
|
|
166
190
|
exports.NodeFileSystemV2 = NodeFileSystemV2;
|
|
@@ -21,7 +21,7 @@ class LocalSessionSummaryProviderV2 {
|
|
|
21
21
|
this.ports = ports;
|
|
22
22
|
}
|
|
23
23
|
loadHealthySummaries() {
|
|
24
|
-
return (0, enumerate_sessions_js_1.
|
|
24
|
+
return (0, enumerate_sessions_js_1.enumerateSessionsByRecency)({
|
|
25
25
|
directoryListing: this.ports.directoryListing,
|
|
26
26
|
dataDir: this.ports.dataDir,
|
|
27
27
|
})
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import type { ResultAsync } from 'neverthrow';
|
|
2
2
|
import type { FsError } from './fs.port.js';
|
|
3
|
+
export interface DirEntryWithMtime {
|
|
4
|
+
readonly name: string;
|
|
5
|
+
readonly mtimeMs: number;
|
|
6
|
+
}
|
|
3
7
|
export interface DirectoryListingPortV2 {
|
|
4
8
|
readdir(dirPath: string): ResultAsync<readonly string[], FsError>;
|
|
9
|
+
readdirWithMtime(dirPath: string): ResultAsync<readonly DirEntryWithMtime[], FsError>;
|
|
5
10
|
}
|
|
@@ -45,8 +45,13 @@ export interface FileManipulationPortV2 {
|
|
|
45
45
|
unlink(filePath: string): ResultAsync<void, FsError>;
|
|
46
46
|
writeFileBytes(filePath: string, bytes: Uint8Array): ResultAsync<void, FsError>;
|
|
47
47
|
}
|
|
48
|
+
export interface FsDirEntryWithMtime {
|
|
49
|
+
readonly name: string;
|
|
50
|
+
readonly mtimeMs: number;
|
|
51
|
+
}
|
|
48
52
|
export interface DirectoryListingOpsPortV2 {
|
|
49
53
|
readdir(dirPath: string): ResultAsync<readonly string[], FsError>;
|
|
54
|
+
readdirWithMtime(dirPath: string): ResultAsync<readonly FsDirEntryWithMtime[], FsError>;
|
|
50
55
|
}
|
|
51
56
|
export interface CrashSafeFileOpsPortV2 extends DirectoryOpsPortV2, FileReadPortV2, FileDescriptorPortV2, FileManipulationPortV2, DirectoryListingOpsPortV2 {
|
|
52
57
|
}
|
|
@@ -7,3 +7,7 @@ export declare function enumerateSessions(ports: {
|
|
|
7
7
|
readonly directoryListing: DirectoryListingPortV2;
|
|
8
8
|
readonly dataDir: DataDirPortV2;
|
|
9
9
|
}): ResultAsync<readonly SessionId[], FsError>;
|
|
10
|
+
export declare function enumerateSessionsByRecency(ports: {
|
|
11
|
+
readonly directoryListing: DirectoryListingPortV2;
|
|
12
|
+
readonly dataDir: DataDirPortV2;
|
|
13
|
+
}): ResultAsync<readonly SessionId[], FsError>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.enumerateSessions = enumerateSessions;
|
|
4
|
+
exports.enumerateSessionsByRecency = enumerateSessionsByRecency;
|
|
4
5
|
const index_js_1 = require("../durable-core/ids/index.js");
|
|
5
6
|
const SESSION_DIR_PATTERN = /^sess_[a-zA-Z0-9_]+$/;
|
|
6
7
|
function enumerateSessions(ports) {
|
|
@@ -11,3 +12,15 @@ function enumerateSessions(ports) {
|
|
|
11
12
|
.sort()
|
|
12
13
|
.map((entry) => (0, index_js_1.asSessionId)(entry)));
|
|
13
14
|
}
|
|
15
|
+
function enumerateSessionsByRecency(ports) {
|
|
16
|
+
return ports.directoryListing
|
|
17
|
+
.readdirWithMtime(ports.dataDir.sessionsDir())
|
|
18
|
+
.map((entries) => entries
|
|
19
|
+
.filter((entry) => SESSION_DIR_PATTERN.test(entry.name))
|
|
20
|
+
.sort((a, b) => {
|
|
21
|
+
if (a.mtimeMs !== b.mtimeMs)
|
|
22
|
+
return b.mtimeMs - a.mtimeMs;
|
|
23
|
+
return a.name.localeCompare(b.name);
|
|
24
|
+
})
|
|
25
|
+
.map((entry) => (0, index_js_1.asSessionId)(entry.name)));
|
|
26
|
+
}
|