@nones/agentflow-strategy-workflow 0.1.0 → 0.6.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/LICENSE +21 -0
- package/README.md +152 -8
- package/package.json +7 -3
- package/src/expansion.ts +932 -0
- package/src/index.ts +35 -0
- package/src/internal.ts +43 -3
- package/src/strategy.ts +15 -2
- package/src/templates.ts +648 -0
package/src/index.ts
CHANGED
|
@@ -1 +1,36 @@
|
|
|
1
1
|
export { workflowStrategy } from "./strategy";
|
|
2
|
+
export {
|
|
3
|
+
canonicalJson,
|
|
4
|
+
expandWorkflow,
|
|
5
|
+
expansionToRunPlan,
|
|
6
|
+
sha256Digest,
|
|
7
|
+
WORKFLOW_EXPANSION_VERSION,
|
|
8
|
+
} from "./expansion";
|
|
9
|
+
export type {
|
|
10
|
+
WorkflowExpansion,
|
|
11
|
+
WorkflowPhase,
|
|
12
|
+
WorkflowRound,
|
|
13
|
+
WorkflowRoundMode,
|
|
14
|
+
WorkflowStep,
|
|
15
|
+
WorkflowStepDependency,
|
|
16
|
+
WorkflowStepKind,
|
|
17
|
+
WorkflowStepProvenance,
|
|
18
|
+
} from "./expansion";
|
|
19
|
+
export {
|
|
20
|
+
createWorkflowTemplateRegistry,
|
|
21
|
+
interpolateTemplateParameters,
|
|
22
|
+
parseWorkflowTemplate,
|
|
23
|
+
parseWorkflowTemplateJson,
|
|
24
|
+
previewWorkflowTemplate,
|
|
25
|
+
readWorkflowTemplateFile,
|
|
26
|
+
validateTemplateParameters,
|
|
27
|
+
workflowTemplateDigest,
|
|
28
|
+
WORKFLOW_TEMPLATE_VERSION,
|
|
29
|
+
WorkflowTemplateError,
|
|
30
|
+
} from "./templates";
|
|
31
|
+
export type {
|
|
32
|
+
ParsedWorkflowTemplate,
|
|
33
|
+
WorkflowTemplate,
|
|
34
|
+
WorkflowTemplatePreview,
|
|
35
|
+
WorkflowTemplateRegistry,
|
|
36
|
+
} from "./templates";
|
package/src/internal.ts
CHANGED
|
@@ -7,7 +7,21 @@ import type {
|
|
|
7
7
|
|
|
8
8
|
const ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._:-]*$/;
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Stable logical key: `<phase>/<round>/<step>`. This is the inspection and
|
|
12
|
+
* dependency namespace and is never an engine ID.
|
|
13
|
+
*/
|
|
14
|
+
const STEP_KEY_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._:-]*$/;
|
|
15
|
+
|
|
16
|
+
const PLAN_FIELDS = [
|
|
17
|
+
"waves",
|
|
18
|
+
"profile",
|
|
19
|
+
"artifacts",
|
|
20
|
+
"sealed",
|
|
21
|
+
"scripts",
|
|
22
|
+
"gates",
|
|
23
|
+
"metadata",
|
|
24
|
+
] as const;
|
|
11
25
|
const WAVE_FIELDS = ["id", "agents"] as const;
|
|
12
26
|
const AGENT_FIELDS = [
|
|
13
27
|
"id",
|
|
@@ -15,6 +29,7 @@ const AGENT_FIELDS = [
|
|
|
15
29
|
"cwd",
|
|
16
30
|
"profile",
|
|
17
31
|
"model",
|
|
32
|
+
"preset",
|
|
18
33
|
"settings",
|
|
19
34
|
"strategy",
|
|
20
35
|
"strategyInput",
|
|
@@ -87,6 +102,22 @@ export function expectId(value: unknown, path: string): string {
|
|
|
87
102
|
return id;
|
|
88
103
|
}
|
|
89
104
|
|
|
105
|
+
/**
|
|
106
|
+
* Engine-facing ID: accepted by core `assertId`, so `/` (wave `phase/round`)
|
|
107
|
+
* and `@` (foreach `item`) are allowed. Control characters and the 256-char
|
|
108
|
+
* cap still apply.
|
|
109
|
+
*/
|
|
110
|
+
export function expectEngineId(value: unknown, path: string): string {
|
|
111
|
+
const id = expectString(value, path);
|
|
112
|
+
if (id.length > 256) {
|
|
113
|
+
fail(path, "must be at most 256 characters");
|
|
114
|
+
}
|
|
115
|
+
if (/[\u0000-\u001f\u007f]/.test(id)) {
|
|
116
|
+
fail(path, "must not contain control characters");
|
|
117
|
+
}
|
|
118
|
+
return id;
|
|
119
|
+
}
|
|
120
|
+
|
|
90
121
|
export function assertJsonValue(
|
|
91
122
|
value: unknown,
|
|
92
123
|
path: string,
|
|
@@ -140,7 +171,7 @@ export function normalizeAgent(value: unknown, path: string): AgentSpec {
|
|
|
140
171
|
const record = expectRecord(value, path);
|
|
141
172
|
assertOnlyKeys(record, AGENT_FIELDS, path);
|
|
142
173
|
|
|
143
|
-
const id =
|
|
174
|
+
const id = expectEngineId(record.id, `${path}.id`);
|
|
144
175
|
const prompt = expectString(record.prompt, `${path}.prompt`);
|
|
145
176
|
const cwd = expectString(record.cwd, `${path}.cwd`);
|
|
146
177
|
|
|
@@ -155,6 +186,10 @@ export function normalizeAgent(value: unknown, path: string): AgentSpec {
|
|
|
155
186
|
if (model !== undefined) {
|
|
156
187
|
spec.model = model;
|
|
157
188
|
}
|
|
189
|
+
const preset = expectOptionalString(record.preset, `${path}.preset`);
|
|
190
|
+
if (preset !== undefined) {
|
|
191
|
+
spec.preset = preset;
|
|
192
|
+
}
|
|
158
193
|
|
|
159
194
|
if (record.settings !== undefined) {
|
|
160
195
|
const settings = expectRecord(record.settings, `${path}.settings`);
|
|
@@ -252,7 +287,7 @@ export function normalizeRunPlan(
|
|
|
252
287
|
const waveRecord = expectRecord(waveValue, wavePath);
|
|
253
288
|
assertOnlyKeys(waveRecord, WAVE_FIELDS, wavePath);
|
|
254
289
|
|
|
255
|
-
const id =
|
|
290
|
+
const id = expectEngineId(waveRecord.id, `${wavePath}.id`);
|
|
256
291
|
if (waveIds.has(id)) {
|
|
257
292
|
fail(`${wavePath}.id`, `duplicate wave id "${id}"`);
|
|
258
293
|
}
|
|
@@ -299,5 +334,10 @@ export function normalizeRunPlan(
|
|
|
299
334
|
plan.sealed = record.sealed;
|
|
300
335
|
}
|
|
301
336
|
|
|
337
|
+
for (const key of ["scripts", "gates", "metadata"] as const) {
|
|
338
|
+
if (record[key] !== undefined) {
|
|
339
|
+
Object.assign(plan, { [key]: cloneJson(record[key], `${path}.${key}`) });
|
|
340
|
+
}
|
|
341
|
+
}
|
|
302
342
|
return plan;
|
|
303
343
|
}
|
package/src/strategy.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { RunPlan, Strategy } from "@nones/agentflow-core";
|
|
2
|
-
import { normalizeRunPlan } from "./internal";
|
|
2
|
+
import { fail, isRecord, normalizeRunPlan } from "./internal";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Workflow strategy. Its input is already a RunPlan; compilation validates and
|
|
@@ -10,6 +10,19 @@ export const workflowStrategy: Strategy = {
|
|
|
10
10
|
id: "workflow",
|
|
11
11
|
singleAdapter: true,
|
|
12
12
|
compile(input: unknown): RunPlan {
|
|
13
|
-
|
|
13
|
+
const plan = normalizeRunPlan(input);
|
|
14
|
+
const payload = plan.metadata?.envelope?.payload;
|
|
15
|
+
if (
|
|
16
|
+
isRecord(payload) &&
|
|
17
|
+
Array.isArray(payload.unsupported) &&
|
|
18
|
+
payload.unsupported.length > 0
|
|
19
|
+
) {
|
|
20
|
+
fail(
|
|
21
|
+
"plan",
|
|
22
|
+
"contains steps the scheduler cannot admit: " +
|
|
23
|
+
payload.unsupported.join(", "),
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
return plan;
|
|
14
27
|
},
|
|
15
28
|
};
|