@db-lyon/flowkit 0.13.0 → 0.15.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.md +387 -386
- package/dist/.tsbuildinfo +1 -1
- package/dist/flow/runner.d.ts +12 -4
- package/dist/flow/runner.d.ts.map +1 -1
- package/dist/flow/runner.js +27 -12
- package/dist/flow/runner.js.map +1 -1
- package/dist/guard/index.d.ts +7 -0
- package/dist/guard/index.d.ts.map +1 -0
- package/dist/guard/index.js +5 -0
- package/dist/guard/index.js.map +1 -0
- package/dist/guard/pipeline.d.ts +22 -0
- package/dist/guard/pipeline.d.ts.map +1 -0
- package/dist/guard/pipeline.js +45 -0
- package/dist/guard/pipeline.js.map +1 -0
- package/dist/guard/registry.d.ts +20 -0
- package/dist/guard/registry.d.ts.map +1 -0
- package/dist/guard/registry.js +33 -0
- package/dist/guard/registry.js.map +1 -0
- package/dist/guard/task-guards.d.ts +89 -0
- package/dist/guard/task-guards.d.ts.map +1 -0
- package/dist/guard/task-guards.js +97 -0
- package/dist/guard/task-guards.js.map +1 -0
- package/dist/guard/types.d.ts +49 -0
- package/dist/guard/types.d.ts.map +1 -0
- package/dist/guard/types.js +38 -0
- package/dist/guard/types.js.map +1 -0
- package/dist/index.d.ts +8 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/dist/task/base-task.d.ts +65 -3
- package/dist/task/base-task.d.ts.map +1 -1
- package/dist/task/base-task.js +51 -5
- package/dist/task/base-task.js.map +1 -1
- package/dist/task/index.d.ts +2 -2
- package/dist/task/index.d.ts.map +1 -1
- package/dist/task/index.js +1 -1
- package/dist/task/index.js.map +1 -1
- package/dist/task/registry.d.ts +11 -3
- package/dist/task/registry.d.ts.map +1 -1
- package/dist/task/registry.js +11 -3
- package/dist/task/registry.js.map +1 -1
- package/docs/ai-agents.md +368 -368
- package/docs/api-reference.md +606 -458
- package/docs/configuration.md +347 -347
- package/docs/custom-tasks.md +271 -258
- package/docs/guards.md +133 -0
- package/docs/releases.md +59 -0
- package/package.json +59 -53
- package/dist/flow/references.d.ts +0 -39
- package/dist/flow/references.d.ts.map +0 -1
- package/dist/flow/references.js +0 -102
- package/dist/flow/references.js.map +0 -1
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { noopLogger } from '../logger.js';
|
|
2
|
+
/** `guard.<name>.<before|after><Scope?>` */
|
|
3
|
+
const GUARD_TASK_RE = /^guard\.(.+)\.(before|after)([A-Za-z][A-Za-z0-9]*)?$/;
|
|
4
|
+
/** Turn `beforeWrite` into the `write` scope key. */
|
|
5
|
+
function scopeKey(suffix) {
|
|
6
|
+
return suffix.charAt(0).toLowerCase() + suffix.slice(1);
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Build a `Guard` for every `guard.<name>.<phase>` task in `registry`.
|
|
10
|
+
*
|
|
11
|
+
* Throws if a task names a scope the host did not declare, so a typo in a
|
|
12
|
+
* plugin's task name surfaces at startup instead of becoming a guard that runs
|
|
13
|
+
* on every operation.
|
|
14
|
+
*/
|
|
15
|
+
export function discoverTaskGuards(registry, options) {
|
|
16
|
+
const log = options.logger ?? noopLogger;
|
|
17
|
+
const scopes = options.scopes ?? {};
|
|
18
|
+
const guards = [];
|
|
19
|
+
for (const taskName of registry.listRegistered()) {
|
|
20
|
+
const match = GUARD_TASK_RE.exec(taskName);
|
|
21
|
+
if (!match)
|
|
22
|
+
continue;
|
|
23
|
+
const [, name, phase, suffix] = match;
|
|
24
|
+
const fullPhase = `${phase}${suffix ?? ''}`;
|
|
25
|
+
let appliesTo;
|
|
26
|
+
if (suffix) {
|
|
27
|
+
const key = scopeKey(suffix);
|
|
28
|
+
appliesTo = scopes[key];
|
|
29
|
+
if (!appliesTo) {
|
|
30
|
+
const known = Object.keys(scopes);
|
|
31
|
+
throw new Error(`Task '${taskName}' declares guard scope '${key}', which is not registered. ` +
|
|
32
|
+
(known.length ? `Known scopes: ${known.join(', ')}.` : 'No scopes are registered.'));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const fail = (ctx, reason, cause) => ({
|
|
36
|
+
guard: name,
|
|
37
|
+
phase: fullPhase,
|
|
38
|
+
taskName,
|
|
39
|
+
ctx,
|
|
40
|
+
reason,
|
|
41
|
+
cause,
|
|
42
|
+
});
|
|
43
|
+
const runTask = async (ctx, result) => {
|
|
44
|
+
try {
|
|
45
|
+
// A guard task deliberately runs as ordinary work: `contextFor` returns
|
|
46
|
+
// a host context with no phase, so `registry.create` resolves
|
|
47
|
+
// DEFAULT_EXECUTION_PHASE and the task sees `'task'`. That is a
|
|
48
|
+
// decision, not an oversight — this is the seam where a `'guard'` phase
|
|
49
|
+
// would be introduced.
|
|
50
|
+
//
|
|
51
|
+
// It is not introduced now because the right granularity is unknown: a
|
|
52
|
+
// guard is `before` or `after` and may be scoped (`beforeWrite`), so a
|
|
53
|
+
// single `'guard'` value could be the wrong shape, and `ExecutionPhase`
|
|
54
|
+
// is a closed union whose members cannot be revised cheaply (adding one
|
|
55
|
+
// breaks exhaustive switches and `Record<ExecutionPhase, T>` in
|
|
56
|
+
// consumers). A host needing the distinction today can supply it
|
|
57
|
+
// itself, e.g. `contextFor: (c) => ({ ...ctx, isGuard: true })`, or read
|
|
58
|
+
// the task name, which is always `guard.<name>.<phase>`.
|
|
59
|
+
const task = await registry.create(taskName, options.contextFor(ctx), options.optionsFor(ctx, result));
|
|
60
|
+
return await task.run();
|
|
61
|
+
}
|
|
62
|
+
catch (e) {
|
|
63
|
+
const cause = e instanceof Error ? e : new Error(String(e));
|
|
64
|
+
const info = fail(ctx, cause.message, cause);
|
|
65
|
+
throw options.onError?.(info) ?? new Error(`guard '${name}' errored: ${cause.message}`);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
const guard = { name: `${name}.${fullPhase}`, appliesTo };
|
|
69
|
+
if (phase === 'before') {
|
|
70
|
+
guard.before = async (ctx) => {
|
|
71
|
+
const r = await runTask(ctx);
|
|
72
|
+
if (!r.success) {
|
|
73
|
+
const reason = r.error?.message ?? `denied by guard '${name}'`;
|
|
74
|
+
const info = fail(ctx, reason, r.error);
|
|
75
|
+
throw options.onDeny?.(info) ?? new Error(`blocked by guard '${name}': ${reason}`);
|
|
76
|
+
}
|
|
77
|
+
log.debug(`guard '${name}' allowed the operation`);
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
guard.after = async (ctx, result) => {
|
|
82
|
+
const r = await runTask(ctx, result);
|
|
83
|
+
if (r.success)
|
|
84
|
+
return;
|
|
85
|
+
const reason = r.error?.message ?? 'unknown failure';
|
|
86
|
+
const info = fail(ctx, reason, r.error);
|
|
87
|
+
if (options.onAfterFailure)
|
|
88
|
+
options.onAfterFailure(info);
|
|
89
|
+
else
|
|
90
|
+
log.debug(`after-guard '${name}' reported failure: ${reason}`);
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
guards.push(guard);
|
|
94
|
+
}
|
|
95
|
+
return guards;
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=task-guards.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"task-guards.js","sourceRoot":"","sources":["../../src/guard/task-guards.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG1C,4CAA4C;AAC5C,MAAM,aAAa,GAAG,sDAAsD,CAAC;AA6D7E,qDAAqD;AACrD,SAAS,QAAQ,CAAC,MAAc;IAC9B,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAC1D,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAChC,QAAsB,EACtB,OAAgD;IAEhD,MAAM,GAAG,GAAG,OAAO,CAAC,MAAM,IAAI,UAAU,CAAC;IACzC,MAAM,MAAM,GAAG,OAAO,CAAC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AAG,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC;oBACxC,MAAM,OAAO,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,IAAI,IAAI,KAAK,CAAC,qBAAqB,IAAI,MAAM,MAAM,EAAE,CAAC,CAAC;gBACrF,CAAC;gBACD,GAAG,CAAC,KAAK,CAAC,UAAU,IAAI,yBAAyB,CAAC,CAAC;YACrD,CAAC,CAAC;QACJ,CAAC;aAAM,CAAC;YACN,KAAK,CAAC,KAAK,GAAG,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE;gBAClC,MAAM,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;gBACrC,IAAI,CAAC,CAAC,OAAO;oBAAE,OAAO;gBACtB,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,EAAE,OAAO,IAAI,iBAAiB,CAAC;gBACrD,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC;gBACxC,IAAI,OAAO,CAAC,cAAc;oBAAE,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;;oBACpD,GAAG,CAAC,KAAK,CAAC,gBAAgB,IAAI,uBAAuB,MAAM,EAAE,CAAC,CAAC;YACtE,CAAC,CAAC;QACJ,CAAC;QAED,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Guards - a before/after pipeline around an arbitrary host operation.
|
|
3
|
+
*
|
|
4
|
+
* A guard sits on a seam the host already has (an RPC call, a write, a command
|
|
5
|
+
* dispatch) and may veto it, act on it, or observe its result. The pipeline
|
|
6
|
+
* knows nothing about what any guard does: access policy, source control,
|
|
7
|
+
* audit, rate limiting and approval gating are all just guards.
|
|
8
|
+
*
|
|
9
|
+
* Guards are generic over the host's per-call context. Flowkit requires only a
|
|
10
|
+
* `meta` scratch map; everything else (method name, params, connection handles,
|
|
11
|
+
* lazily computed enrichment) belongs to the host's own context type.
|
|
12
|
+
*
|
|
13
|
+
* These are distinct from `FlowRunnerHooks`, which fire around flow steps.
|
|
14
|
+
* A guard wraps one host operation and can deny it; a hook observes a step.
|
|
15
|
+
*/
|
|
16
|
+
/** The minimum a host context must provide. Extend it with whatever the host needs. */
|
|
17
|
+
export interface GuardContext {
|
|
18
|
+
/** Scratch space shared across guards for the life of one operation. */
|
|
19
|
+
readonly meta: Map<string, unknown>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* A guard on the pipeline. Every hook is optional; a guard with neither
|
|
23
|
+
* `before` nor `after` is inert but still legal (useful while wiring one up).
|
|
24
|
+
*/
|
|
25
|
+
export interface Guard<Ctx extends GuardContext = GuardContext, TResult = unknown> {
|
|
26
|
+
/** Stable identifier, used for logging and to break ordering ties. */
|
|
27
|
+
readonly name: string;
|
|
28
|
+
/** Lower runs first in `before` and last in `after`. Default 0. */
|
|
29
|
+
readonly order?: number;
|
|
30
|
+
/** Whether this guard participates in a given operation. Default: always. */
|
|
31
|
+
appliesTo?(ctx: Ctx): boolean | Promise<boolean>;
|
|
32
|
+
/** Runs before the operation. Throw to DENY it; side effects are allowed. */
|
|
33
|
+
before?(ctx: Ctx): Promise<void>;
|
|
34
|
+
/** Runs after a successful operation. Return a value to replace the result. */
|
|
35
|
+
after?(ctx: Ctx, result: TResult): Promise<TResult | void>;
|
|
36
|
+
}
|
|
37
|
+
/** Create the base context fields. Spread the result into the host's own context object. */
|
|
38
|
+
export declare function guardContextBase(): GuardContext;
|
|
39
|
+
/**
|
|
40
|
+
* Wrap a pure computation so it runs at most once per operation, caching into
|
|
41
|
+
* the context's `meta` map under `key`.
|
|
42
|
+
*
|
|
43
|
+
* Guard contexts commonly carry enrichment that is expensive to compute and
|
|
44
|
+
* that most guards never look at (which files a call touches, who the caller
|
|
45
|
+
* is). Deferring it means a guard that ignores the enrichment pays nothing,
|
|
46
|
+
* and a pipeline of guards that all consult it pays once.
|
|
47
|
+
*/
|
|
48
|
+
export declare function lazy<T>(ctx: GuardContext, key: string, compute: () => T): () => T;
|
|
49
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/guard/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,uFAAuF;AACvF,MAAM,WAAW,YAAY;IAC3B,wEAAwE;IACxE,QAAQ,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACrC;AAED;;;GAGG;AACH,MAAM,WAAW,KAAK,CAAC,GAAG,SAAS,YAAY,GAAG,YAAY,EAAE,OAAO,GAAG,OAAO;IAC/E,sEAAsE;IACtE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,mEAAmE;IACnE,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,6EAA6E;IAC7E,SAAS,CAAC,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACjD,6EAA6E;IAC7E,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACjC,+EAA+E;IAC/E,KAAK,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC;CAC5D;AAED,4FAA4F;AAC5F,wBAAgB,gBAAgB,IAAI,YAAY,CAE/C;AAED;;;;;;;;GAQG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,GAAG,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,CAOjF"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Guards - a before/after pipeline around an arbitrary host operation.
|
|
3
|
+
*
|
|
4
|
+
* A guard sits on a seam the host already has (an RPC call, a write, a command
|
|
5
|
+
* dispatch) and may veto it, act on it, or observe its result. The pipeline
|
|
6
|
+
* knows nothing about what any guard does: access policy, source control,
|
|
7
|
+
* audit, rate limiting and approval gating are all just guards.
|
|
8
|
+
*
|
|
9
|
+
* Guards are generic over the host's per-call context. Flowkit requires only a
|
|
10
|
+
* `meta` scratch map; everything else (method name, params, connection handles,
|
|
11
|
+
* lazily computed enrichment) belongs to the host's own context type.
|
|
12
|
+
*
|
|
13
|
+
* These are distinct from `FlowRunnerHooks`, which fire around flow steps.
|
|
14
|
+
* A guard wraps one host operation and can deny it; a hook observes a step.
|
|
15
|
+
*/
|
|
16
|
+
/** Create the base context fields. Spread the result into the host's own context object. */
|
|
17
|
+
export function guardContextBase() {
|
|
18
|
+
return { meta: new Map() };
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Wrap a pure computation so it runs at most once per operation, caching into
|
|
22
|
+
* the context's `meta` map under `key`.
|
|
23
|
+
*
|
|
24
|
+
* Guard contexts commonly carry enrichment that is expensive to compute and
|
|
25
|
+
* that most guards never look at (which files a call touches, who the caller
|
|
26
|
+
* is). Deferring it means a guard that ignores the enrichment pays nothing,
|
|
27
|
+
* and a pipeline of guards that all consult it pays once.
|
|
28
|
+
*/
|
|
29
|
+
export function lazy(ctx, key, compute) {
|
|
30
|
+
return () => {
|
|
31
|
+
if (ctx.meta.has(key))
|
|
32
|
+
return ctx.meta.get(key);
|
|
33
|
+
const value = compute();
|
|
34
|
+
ctx.meta.set(key, value);
|
|
35
|
+
return value;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/guard/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAyBH,4FAA4F;AAC5F,MAAM,UAAU,gBAAgB;IAC9B,OAAO,EAAE,IAAI,EAAE,IAAI,GAAG,EAAmB,EAAE,CAAC;AAC9C,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,IAAI,CAAI,GAAiB,EAAE,GAAW,EAAE,OAAgB;IACtE,OAAO,GAAG,EAAE;QACV,IAAI,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;YAAE,OAAO,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAM,CAAC;QACrD,MAAM,KAAK,GAAG,OAAO,EAAE,CAAC;QACxB,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QACzB,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,8 +3,8 @@ export { TaskOptionsSchema, TaskDefinitionSchema, FlowStepSchema, FlowDefinition
|
|
|
3
3
|
export type { TaskOptions, TaskDefinition, FlowStep, FlowDefinition, AgentTool, AgentBudget, AgentDefinition, EngineConfig, } from './config/schema.js';
|
|
4
4
|
export { loadConfig, loadRawYaml, findConfigFile } from './config/loader.js';
|
|
5
5
|
export type { LoadConfigOptions, LoadedConfig } from './config/loader.js';
|
|
6
|
-
export { BaseTask } from './task/base-task.js';
|
|
7
|
-
export type { TaskContext, TaskResult, RollbackRecord } from './task/base-task.js';
|
|
6
|
+
export { BaseTask, DEFAULT_EXECUTION_PHASE, resolveTaskContext } from './task/base-task.js';
|
|
7
|
+
export type { TaskContext, TaskContextInput, ResolvedTaskContext, ExecutionPhase, TaskResult, RollbackRecord, } from './task/base-task.js';
|
|
8
8
|
export { ShellTask } from './task/shell-task.js';
|
|
9
9
|
export type { ShellTaskOptions } from './task/shell-task.js';
|
|
10
10
|
export { TaskRegistry } from './task/registry.js';
|
|
@@ -24,6 +24,12 @@ export { redact, truncate, preview } from './task/redact.js';
|
|
|
24
24
|
export type { LLMProvider, LLMCompletionRequest, LLMCompletionResponse, LLMMessage, LLMRole, LLMToolCall, LLMToolDefinition, LLMToolChoice, LLMToolHandler, } from './task/llm-provider.js';
|
|
25
25
|
export { FlowRunner } from './flow/runner.js';
|
|
26
26
|
export type { FlowRunOptions, FlowStepResult, FlowRunResult, FlowRunnerHooks, FlowRunnerConfig, PlanStep, HookPhase, HookError, RollbackResult, } from './flow/runner.js';
|
|
27
|
+
export { GuardRegistry } from './guard/registry.js';
|
|
28
|
+
export { runGuarded } from './guard/pipeline.js';
|
|
29
|
+
export { discoverTaskGuards } from './guard/task-guards.js';
|
|
30
|
+
export type { DiscoverTaskGuardsOptions, GuardScope, GuardTaskFailure, } from './guard/task-guards.js';
|
|
31
|
+
export { guardContextBase, lazy } from './guard/types.js';
|
|
32
|
+
export type { Guard, GuardContext } from './guard/types.js';
|
|
27
33
|
export { resolveReferences } from './references.js';
|
|
28
34
|
export type { ReferenceableStep, ReferenceContext } from './references.js';
|
|
29
35
|
export { topologicalSort, CircularDependencyError, MissingDependencyError, } from './dag/resolver.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,cAAc,EACd,oBAAoB,EACpB,eAAe,EACf,iBAAiB,EACjB,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EACV,WAAW,EACX,cAAc,EACd,QAAQ,EACR,cAAc,EACd,SAAS,EACT,WAAW,EACX,eAAe,EACf,YAAY,GACb,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAC7E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1D,YAAY,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAG5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,YAAY,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAG3E,OAAO,EACL,eAAe,EACf,uBAAuB,EACvB,sBAAsB,GACvB,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAGjD,YAAY,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ export { deepMerge } from './config/deep-merge.js';
|
|
|
3
3
|
export { TaskOptionsSchema, TaskDefinitionSchema, FlowStepSchema, FlowDefinitionSchema, AgentToolSchema, AgentBudgetSchema, AgentDefinitionSchema, EngineConfigSchema, } from './config/schema.js';
|
|
4
4
|
export { loadConfig, loadRawYaml, findConfigFile } from './config/loader.js';
|
|
5
5
|
// Task
|
|
6
|
-
export { BaseTask } from './task/base-task.js';
|
|
6
|
+
export { BaseTask, DEFAULT_EXECUTION_PHASE, resolveTaskContext } from './task/base-task.js';
|
|
7
7
|
export { ShellTask } from './task/shell-task.js';
|
|
8
8
|
export { TaskRegistry } from './task/registry.js';
|
|
9
9
|
export { AgentPromptTask } from './task/agent-prompt-task.js';
|
|
@@ -15,6 +15,11 @@ export { createLedger, chargeLedger, ledgerExhausted, exhaustedLimit, } from './
|
|
|
15
15
|
export { redact, truncate, preview } from './task/redact.js';
|
|
16
16
|
// Flow
|
|
17
17
|
export { FlowRunner } from './flow/runner.js';
|
|
18
|
+
// Guard — before/after pipeline around a host operation
|
|
19
|
+
export { GuardRegistry } from './guard/registry.js';
|
|
20
|
+
export { runGuarded } from './guard/pipeline.js';
|
|
21
|
+
export { discoverTaskGuards } from './guard/task-guards.js';
|
|
22
|
+
export { guardContextBase, lazy } from './guard/types.js';
|
|
18
23
|
// References — shared by the task and flow layers
|
|
19
24
|
export { resolveReferences } from './references.js';
|
|
20
25
|
// DAG
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,SAAS;AACT,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,cAAc,EACd,oBAAoB,EACpB,eAAe,EACf,iBAAiB,EACjB,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,oBAAoB,CAAC;AAW5B,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAG7E,OAAO;AACP,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,SAAS;AACT,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,cAAc,EACd,oBAAoB,EACpB,eAAe,EACf,iBAAiB,EACjB,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,oBAAoB,CAAC;AAW5B,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAG7E,OAAO;AACP,OAAO,EAAE,QAAQ,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAS5F,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAE9D,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD,OAAO,EACL,aAAa,EACb,cAAc,EACd,eAAe,EACf,qBAAqB,GACtB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAEnE,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,cAAc,GACf,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAa7D,OAAO;AACP,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAY9C,wDAAwD;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAM5D,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAG1D,kDAAkD;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAGpD,MAAM;AACN,OAAO,EACL,eAAe,EACf,uBAAuB,EACvB,sBAAsB,GACvB,MAAM,mBAAmB,CAAC;AAK3B,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/task/base-task.d.ts
CHANGED
|
@@ -14,6 +14,13 @@ import type { ReferenceContext } from '../references.js';
|
|
|
14
14
|
* host instead, e.g. `context: { cache: new Map() }`.
|
|
15
15
|
*/
|
|
16
16
|
export interface TaskContext {
|
|
17
|
+
/**
|
|
18
|
+
* Lifecycle phase for this specific task invocation. Optional here because
|
|
19
|
+
* this is the shape a *host* builds, and Flowkit owns the value: the runner
|
|
20
|
+
* and `TaskRegistry.create` supply it before a task ever observes it. A
|
|
21
|
+
* running task reads it through `ResolvedTaskContext`, where it is required.
|
|
22
|
+
*/
|
|
23
|
+
readonly executionPhase?: ExecutionPhase;
|
|
17
24
|
logger?: Logger;
|
|
18
25
|
registry?: TaskRegistry;
|
|
19
26
|
/** LLM provider consumed by `AgentPromptTask` / `AgentTask`. */
|
|
@@ -54,6 +61,45 @@ export interface TaskContext {
|
|
|
54
61
|
__tokenLedger?: TokenLedger;
|
|
55
62
|
[key: string]: unknown;
|
|
56
63
|
}
|
|
64
|
+
/** Public lifecycle phases assigned by `FlowRunner` to each task invocation. */
|
|
65
|
+
export type ExecutionPhase = 'task' | 'on_start' | 'on_success' | 'on_failure' | 'finally' | 'rollback';
|
|
66
|
+
/**
|
|
67
|
+
* Host context accepted by runners and direct task construction.
|
|
68
|
+
*
|
|
69
|
+
* An alias of `TaskContext`, named for the boundary it documents. It is not an
|
|
70
|
+
* `Omit<TaskContext, 'executionPhase'>`: `TaskContext` carries a string index
|
|
71
|
+
* signature, so `keyof` it is `string | number` and `Omit` would erase every
|
|
72
|
+
* named field, silently turning the host-facing surface into `{[k: string]:
|
|
73
|
+
* unknown}` and dropping all compile-time checking of `logger`, `llm`, and the
|
|
74
|
+
* rest.
|
|
75
|
+
*/
|
|
76
|
+
export type TaskContextInput = TaskContext;
|
|
77
|
+
/**
|
|
78
|
+
* Context as a *running task* observes it: identical to `TaskContext` except
|
|
79
|
+
* the lifecycle phase is guaranteed present, because Flowkit resolved it during
|
|
80
|
+
* construction. This is the type of `BaseTask.ctx`.
|
|
81
|
+
*/
|
|
82
|
+
export type ResolvedTaskContext = TaskContext & {
|
|
83
|
+
readonly executionPhase: ExecutionPhase;
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Phase used when nothing better is known: direct construction, or a
|
|
87
|
+
* `registry.create()` whose caller supplied no phase. Declared once and
|
|
88
|
+
* referenced everywhere, so adding a phase or changing the fallback is a
|
|
89
|
+
* single-site edit rather than a hunt through the runner and the registry.
|
|
90
|
+
*/
|
|
91
|
+
export declare const DEFAULT_EXECUTION_PHASE: ExecutionPhase;
|
|
92
|
+
/**
|
|
93
|
+
* The one place a host context becomes a task context.
|
|
94
|
+
*
|
|
95
|
+
* Returns `ctx` **itself** when the phase is already set, which is every path
|
|
96
|
+
* through `FlowRunner`. That matters beyond allocation: a host may pass a class
|
|
97
|
+
* instance or a service object as its context, and copying would strip its
|
|
98
|
+
* prototype methods and break identity for anything comparing contexts. When a
|
|
99
|
+
* phase must be added, the prototype is carried onto the new object for the
|
|
100
|
+
* same reason.
|
|
101
|
+
*/
|
|
102
|
+
export declare function resolveTaskContext(ctx: TaskContextInput): ResolvedTaskContext;
|
|
57
103
|
/**
|
|
58
104
|
* Rollback record returned by a successful mutation task.
|
|
59
105
|
* The runner invokes `taskName` with `payload` (in reverse step order)
|
|
@@ -71,10 +117,24 @@ export interface TaskResult {
|
|
|
71
117
|
rollback?: RollbackRecord;
|
|
72
118
|
}
|
|
73
119
|
export declare abstract class BaseTask<TOpts = Record<string, unknown>> {
|
|
120
|
+
protected logger: Logger;
|
|
121
|
+
/**
|
|
122
|
+
* Typed `TaskContext`, not `ResolvedTaskContext`, so a subclass can narrow it
|
|
123
|
+
* to the host's own context interface (which is built from `TaskContext` and
|
|
124
|
+
* so leaves the phase optional). The value is always phase-resolved at
|
|
125
|
+
* runtime; a task that needs the non-optional type can assert
|
|
126
|
+
* `ResolvedTaskContext`.
|
|
127
|
+
*/
|
|
74
128
|
protected ctx: TaskContext;
|
|
75
129
|
protected options: TOpts;
|
|
76
|
-
|
|
77
|
-
|
|
130
|
+
constructor(ctx: TaskContextInput, options: TOpts);
|
|
131
|
+
/**
|
|
132
|
+
* Lifecycle phase for this invocation, always present. Read this rather than
|
|
133
|
+
* `ctx.executionPhase`: `ctx` is typed as the host-facing `TaskContext`, where
|
|
134
|
+
* the phase is optional so host context interfaces stay constructible, but
|
|
135
|
+
* Flowkit resolves it before any task observes it.
|
|
136
|
+
*/
|
|
137
|
+
protected get executionPhase(): ExecutionPhase;
|
|
78
138
|
abstract get taskName(): string;
|
|
79
139
|
abstract execute(): Promise<TaskResult>;
|
|
80
140
|
/** Override for option validation — called before execute(). */
|
|
@@ -87,6 +147,8 @@ export declare abstract class BaseTask<TOpts = Record<string, unknown>> {
|
|
|
87
147
|
* default options as an ordinary flow step or an agent tool, including
|
|
88
148
|
* `${ns.path}` interpolation of those defaults. `options` are this task's own
|
|
89
149
|
* runtime data and stay literal (see `resolveTaskCall`).
|
|
150
|
+
* The child receives a fresh context with the ordinary `task` phase while
|
|
151
|
+
* retaining the caller's host services and reference scope.
|
|
90
152
|
*
|
|
91
153
|
* Returns an unexecuted task instance — call `.run()` on it yourself when you
|
|
92
154
|
* need to inspect or configure the task before running.
|
|
@@ -94,7 +156,7 @@ export declare abstract class BaseTask<TOpts = Record<string, unknown>> {
|
|
|
94
156
|
protected resolve<T extends BaseTask = BaseTask>(taskName: string, options?: Record<string, unknown>): Promise<T>;
|
|
95
157
|
/**
|
|
96
158
|
* Resolve and execute another task by name in a single call.
|
|
97
|
-
* The resolved task shares
|
|
159
|
+
* The resolved task shares the caller's host services through a fresh context.
|
|
98
160
|
*/
|
|
99
161
|
protected call(taskName: string, options?: Record<string, unknown>): Promise<TaskResult>;
|
|
100
162
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-task.d.ts","sourceRoot":"","sources":["../../src/task/base-task.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAE3C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACrE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAGzD;;;;;;;;GAQG;AACH,MAAM,WAAW,WAAW;IAC1B,MAAM,CAAC,EAAE,MAA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SAAS,CAAC,OAAO,EAAE,KAAK,CAAC;gBAEb,GAAG,EAAE,gBAAgB,EAAE,OAAO,EAAE,KAAK;IAOjD;;;;;OAKG;IACH,SAAS,KAAK,cAAc,IAAI,cAAc,CAE7C;IAED,QAAQ,KAAK,QAAQ,IAAI,MAAM,CAAC;IAEhC,QAAQ,CAAC,OAAO,IAAI,OAAO,CAAC,UAAU,CAAC;IAEvC,gEAAgE;IAChE,SAAS,CAAC,QAAQ,IAAI,IAAI;IAE1B;;;;;;;;;;;;;OAaG;cACa,OAAO,CAAC,CAAC,SAAS,QAAQ,GAAG,QAAQ,EACnD,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,OAAO,CAAC,CAAC,CAAC;IAoBb;;;OAGG;cACa,IAAI,CAClB,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,OAAO,CAAC,UAAU,CAAC;IAKtB;;;OAGG;IACG,GAAG,IAAI,OAAO,CAAC,UAAU,CAAC;CA2BjC"}
|
package/dist/task/base-task.js
CHANGED
|
@@ -1,15 +1,56 @@
|
|
|
1
1
|
import { noopLogger } from '../logger.js';
|
|
2
2
|
import { resolveTaskCall } from './task-resolution.js';
|
|
3
|
+
/**
|
|
4
|
+
* Phase used when nothing better is known: direct construction, or a
|
|
5
|
+
* `registry.create()` whose caller supplied no phase. Declared once and
|
|
6
|
+
* referenced everywhere, so adding a phase or changing the fallback is a
|
|
7
|
+
* single-site edit rather than a hunt through the runner and the registry.
|
|
8
|
+
*/
|
|
9
|
+
export const DEFAULT_EXECUTION_PHASE = 'task';
|
|
10
|
+
/**
|
|
11
|
+
* The one place a host context becomes a task context.
|
|
12
|
+
*
|
|
13
|
+
* Returns `ctx` **itself** when the phase is already set, which is every path
|
|
14
|
+
* through `FlowRunner`. That matters beyond allocation: a host may pass a class
|
|
15
|
+
* instance or a service object as its context, and copying would strip its
|
|
16
|
+
* prototype methods and break identity for anything comparing contexts. When a
|
|
17
|
+
* phase must be added, the prototype is carried onto the new object for the
|
|
18
|
+
* same reason.
|
|
19
|
+
*/
|
|
20
|
+
export function resolveTaskContext(ctx) {
|
|
21
|
+
if (ctx.executionPhase !== undefined)
|
|
22
|
+
return ctx;
|
|
23
|
+
const proto = Object.getPrototypeOf(ctx);
|
|
24
|
+
return Object.assign(Object.create(proto), ctx, {
|
|
25
|
+
executionPhase: DEFAULT_EXECUTION_PHASE,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
3
28
|
export class BaseTask {
|
|
29
|
+
logger;
|
|
30
|
+
/**
|
|
31
|
+
* Typed `TaskContext`, not `ResolvedTaskContext`, so a subclass can narrow it
|
|
32
|
+
* to the host's own context interface (which is built from `TaskContext` and
|
|
33
|
+
* so leaves the phase optional). The value is always phase-resolved at
|
|
34
|
+
* runtime; a task that needs the non-optional type can assert
|
|
35
|
+
* `ResolvedTaskContext`.
|
|
36
|
+
*/
|
|
4
37
|
ctx;
|
|
5
38
|
options;
|
|
6
|
-
logger;
|
|
7
39
|
constructor(ctx, options) {
|
|
8
|
-
this.ctx = ctx;
|
|
40
|
+
this.ctx = resolveTaskContext(ctx);
|
|
9
41
|
this.options = options;
|
|
10
|
-
const parentLogger = ctx.logger ?? noopLogger;
|
|
42
|
+
const parentLogger = this.ctx.logger ?? noopLogger;
|
|
11
43
|
this.logger = parentLogger.child({ task: this.constructor.name });
|
|
12
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Lifecycle phase for this invocation, always present. Read this rather than
|
|
47
|
+
* `ctx.executionPhase`: `ctx` is typed as the host-facing `TaskContext`, where
|
|
48
|
+
* the phase is optional so host context interfaces stay constructible, but
|
|
49
|
+
* Flowkit resolves it before any task observes it.
|
|
50
|
+
*/
|
|
51
|
+
get executionPhase() {
|
|
52
|
+
return this.ctx.executionPhase;
|
|
53
|
+
}
|
|
13
54
|
/** Override for option validation — called before execute(). */
|
|
14
55
|
validate() { }
|
|
15
56
|
/**
|
|
@@ -20,6 +61,8 @@ export class BaseTask {
|
|
|
20
61
|
* default options as an ordinary flow step or an agent tool, including
|
|
21
62
|
* `${ns.path}` interpolation of those defaults. `options` are this task's own
|
|
22
63
|
* runtime data and stay literal (see `resolveTaskCall`).
|
|
64
|
+
* The child receives a fresh context with the ordinary `task` phase while
|
|
65
|
+
* retaining the caller's host services and reference scope.
|
|
23
66
|
*
|
|
24
67
|
* Returns an unexecuted task instance — call `.run()` on it yourself when you
|
|
25
68
|
* need to inspect or configure the task before running.
|
|
@@ -31,11 +74,14 @@ export class BaseTask {
|
|
|
31
74
|
'Tasks can only resolve other tasks when run via FlowRunner.');
|
|
32
75
|
}
|
|
33
76
|
const resolved = resolveTaskCall(taskName, this.ctx.taskDefinitions, options, this.ctx.taskReferenceContext);
|
|
34
|
-
|
|
77
|
+
// A task-to-task call is ordinary work: it does not inherit the caller's
|
|
78
|
+
// hook or rollback phase.
|
|
79
|
+
const childCtx = { ...this.ctx, executionPhase: DEFAULT_EXECUTION_PHASE };
|
|
80
|
+
return registry.create(resolved.classPath, childCtx, resolved.options);
|
|
35
81
|
}
|
|
36
82
|
/**
|
|
37
83
|
* Resolve and execute another task by name in a single call.
|
|
38
|
-
* The resolved task shares
|
|
84
|
+
* The resolved task shares the caller's host services through a fresh context.
|
|
39
85
|
*/
|
|
40
86
|
async call(taskName, options) {
|
|
41
87
|
const task = await this.resolve(taskName, options);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-task.js","sourceRoot":"","sources":["../../src/task/base-task.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAM1C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"base-task.js","sourceRoot":"","sources":["../../src/task/base-task.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAM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AAC,QAAQ,EAAE,CACnC,CAAC;YAEF,OAAO,MAAM,CAAC;QAChB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC;YACxC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,gBAAgB,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;YAExE,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;gBAChE,QAAQ;aACT,CAAC;QACJ,CAAC;IACH,CAAC;CACF"}
|
package/dist/task/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { BaseTask } from './base-task.js';
|
|
2
|
-
export type { TaskContext, TaskResult, RollbackRecord } from './base-task.js';
|
|
1
|
+
export { BaseTask, DEFAULT_EXECUTION_PHASE, resolveTaskContext } from './base-task.js';
|
|
2
|
+
export type { TaskContext, TaskContextInput, ResolvedTaskContext, ExecutionPhase, TaskResult, RollbackRecord, } from './base-task.js';
|
|
3
3
|
export { ShellTask } from './shell-task.js';
|
|
4
4
|
export type { ShellTaskOptions } from './shell-task.js';
|
|
5
5
|
export { TaskRegistry } from './registry.js';
|
package/dist/task/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/task/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/task/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACvF,YAAY,EACV,WAAW,EACX,gBAAgB,EAChB,mBAAmB,EACnB,cAAc,EACd,UAAU,EACV,cAAc,GACf,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,YAAY,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,YAAY,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAGrD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,YAAY,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,YAAY,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACvE,OAAO,EACL,aAAa,EACb,cAAc,EACd,eAAe,EACf,qBAAqB,GACtB,MAAM,iBAAiB,CAAC;AACzB,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACnF,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAC9D,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAC1E,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACxD,YAAY,EACV,WAAW,EACX,oBAAoB,EACpB,qBAAqB,EACrB,UAAU,EACV,OAAO,EACP,WAAW,EACX,iBAAiB,EACjB,aAAa,EACb,cAAc,GACf,MAAM,mBAAmB,CAAC"}
|
package/dist/task/index.js
CHANGED
package/dist/task/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/task/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/task/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AASvF,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAG7C,cAAc;AACd,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EACL,aAAa,EACb,cAAc,EACd,eAAe,EACf,qBAAqB,GACtB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAE9D,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/task/registry.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseTask, type TaskContext } from './base-task.js';
|
|
1
|
+
import { BaseTask, type TaskContext, type TaskContextInput } from './base-task.js';
|
|
2
2
|
export type TaskConstructor = new (ctx: TaskContext, options: Record<string, unknown>) => BaseTask;
|
|
3
3
|
export declare class TaskRegistry {
|
|
4
4
|
private classPathMap;
|
|
@@ -17,8 +17,16 @@ export declare class TaskRegistry {
|
|
|
17
17
|
* Falls back to dynamic import from the filesystem.
|
|
18
18
|
*/
|
|
19
19
|
resolve(classPathOrName: string): Promise<TaskConstructor>;
|
|
20
|
-
/**
|
|
21
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Resolve + instantiate in one call.
|
|
22
|
+
*
|
|
23
|
+
* The phase is resolved *before* construction, not left to `BaseTask`, so a
|
|
24
|
+
* host-authored constructor that reads `ctx.executionPhase` before calling
|
|
25
|
+
* `super()` sees the same value the task will. `resolveTaskContext` is a
|
|
26
|
+
* no-op when the caller already supplied a phase, which is every path through
|
|
27
|
+
* `FlowRunner`.
|
|
28
|
+
*/
|
|
29
|
+
create(classPathOrName: string, ctx: TaskContextInput, options: Record<string, unknown>): Promise<BaseTask>;
|
|
22
30
|
/**
|
|
23
31
|
* Wrap an existing registered task with a decorator class.
|
|
24
32
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/task/registry.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/task/registry.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,QAAQ,EAER,KAAK,WAAW,EAChB,KAAK,gBAAgB,EACtB,MAAM,gBAAgB,CAAC;AAExB,MAAM,MAAM,eAAe,GAAG,KAC5B,GAAG,EAAE,WAAW,EAChB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC7B,QAAQ,CAAC;AAEd,qBAAa,YAAY;IACvB,OAAO,CAAC,YAAY,CAAsC;IAC1D,OAAO,CAAC,OAAO,CAAsC;IACrD,OAAO,CAAC,YAAY,CAAsC;IAE1D,uDAAuD;IACvD,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,eAAe,GAAG,IAAI;IAKnD,gEAAgE;IAChE,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,eAAe,GAAG,IAAI;IAKjE,mCAAmC;IACnC,WAAW,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,GAAG,IAAI;IAO3D,mCAAmC;IACnC,kBAAkB,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,GAAG,IAAI;IAOlE;;;OAGG;IACG,OAAO,CAAC,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IAQhE;;;;;;;;OAQG;IACG,MAAM,CACV,eAAe,EAAE,MAAM,EACvB,GAAG,EAAE,gBAAgB,EACrB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC/B,OAAO,CAAC,QAAQ,CAAC;IAKpB;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,QAAQ,EAAE,eAAe,KAAK,eAAe,GAAG,IAAI;IAcjF,mDAAmD;IACnD,cAAc,IAAI,MAAM,EAAE;YAQZ,WAAW;IA0CzB,OAAO,CAAC,qBAAqB;CAW9B"}
|
package/dist/task/registry.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as path from 'node:path';
|
|
2
2
|
import * as fs from 'node:fs';
|
|
3
|
-
import { BaseTask } from './base-task.js';
|
|
3
|
+
import { BaseTask, resolveTaskContext, } from './base-task.js';
|
|
4
4
|
export class TaskRegistry {
|
|
5
5
|
classPathMap = new Map();
|
|
6
6
|
nameMap = new Map();
|
|
@@ -39,10 +39,18 @@ export class TaskRegistry {
|
|
|
39
39
|
return builtin;
|
|
40
40
|
return this.loadDynamic(classPathOrName);
|
|
41
41
|
}
|
|
42
|
-
/**
|
|
42
|
+
/**
|
|
43
|
+
* Resolve + instantiate in one call.
|
|
44
|
+
*
|
|
45
|
+
* The phase is resolved *before* construction, not left to `BaseTask`, so a
|
|
46
|
+
* host-authored constructor that reads `ctx.executionPhase` before calling
|
|
47
|
+
* `super()` sees the same value the task will. `resolveTaskContext` is a
|
|
48
|
+
* no-op when the caller already supplied a phase, which is every path through
|
|
49
|
+
* `FlowRunner`.
|
|
50
|
+
*/
|
|
43
51
|
async create(classPathOrName, ctx, options) {
|
|
44
52
|
const TaskClass = await this.resolve(classPathOrName);
|
|
45
|
-
return new TaskClass(ctx, options);
|
|
53
|
+
return new TaskClass(resolveTaskContext(ctx), options);
|
|
46
54
|
}
|
|
47
55
|
/**
|
|
48
56
|
* Wrap an existing registered task with a decorator class.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/task/registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/task/registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,EACL,QAAQ,EACR,kBAAkB,GAGnB,MAAM,gBAAgB,CAAC;AAOxB,MAAM,OAAO,YAAY;IACf,YAAY,GAAG,IAAI,GAAG,EAA2B,CAAC;IAClD,OAAO,GAAG,IAAI,GAAG,EAA2B,CAAC;IAC7C,YAAY,GAAG,IAAI,GAAG,EAA2B,CAAC;IAE1D,uDAAuD;IACvD,QAAQ,CAAC,IAAY,EAAE,IAAqB;QAC1C,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAC7B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,gEAAgE;IAChE,iBAAiB,CAAC,SAAiB,EAAE,IAAqB;QACxD,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;QACvC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,mCAAmC;IACnC,WAAW,CAAC,OAAwC;QAClD,KAAK,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;YACnD,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAC/B,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,mCAAmC;IACnC,kBAAkB,CAAC,OAAwC;QACzD,KAAK,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OA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