@vimhead.dev/norn 0.1.0-tip.35359392805.1 → 0.1.0-tip.35390859630.1
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/api.d.ts +88 -146
- package/dist/api.js +41 -77
- package/dist/index.d.ts +1 -1
- package/dist/index.js +0 -1
- package/dist/schema.js +3 -3
- package/package.json +1 -1
- package/dist/state-adapter.d.ts +0 -10
- package/dist/state-adapter.js +0 -70
package/dist/api.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CreateAgentSessionOptions, EventBus, PromptOptions } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import { Type, type
|
|
2
|
+
import { Type, type StaticDecode, type StaticEncode, type TCodec, type TSchema } from "typebox";
|
|
3
3
|
import type { TLocalizedValidationError } from "typebox/error";
|
|
4
4
|
declare const WORKFLOW_DECLARATION_KIND = "norn.workflow";
|
|
5
5
|
export type MaybePromise<T> = T | Promise<T>;
|
|
@@ -12,27 +12,32 @@ export type NornWorkflowIsolationMode = "runWorkspace" | "project";
|
|
|
12
12
|
export type NornWorkflowIsolation<Mode extends NornWorkflowIsolationMode = NornWorkflowIsolationMode> = {
|
|
13
13
|
readonly mode: Mode;
|
|
14
14
|
};
|
|
15
|
-
export type NornWorkflowDeclaration<Id extends string = string,
|
|
16
|
-
(
|
|
15
|
+
export type NornWorkflowDeclaration<Id extends string = string, ArgsSchema extends TSchema = TSchema, IsolationMode extends NornWorkflowIsolationMode = NornWorkflowIsolationMode, ConfigSchema extends TSchema | undefined = TSchema | undefined, Scope extends NornWorkflowScopeInfo | undefined = NornWorkflowScopeInfo | undefined> = {
|
|
16
|
+
(args: StaticEncode<ArgsSchema>): NornRunNext;
|
|
17
17
|
readonly kind: typeof WORKFLOW_DECLARATION_KIND;
|
|
18
18
|
readonly id: Id;
|
|
19
19
|
readonly isEntrypoint: boolean;
|
|
20
20
|
readonly instructions?: string;
|
|
21
|
-
readonly
|
|
22
|
-
readonly gate?:
|
|
21
|
+
readonly args: ArgsSchema;
|
|
22
|
+
readonly gate?: NornWorkflowGate<ArgsSchema> & {
|
|
23
|
+
describe?(context: NornWorkflowContext<ArgsSchema, IsolationMode, ConfigSchema, Scope>): MaybePromise<string>;
|
|
24
|
+
};
|
|
23
25
|
readonly isolation: NornWorkflowIsolation<IsolationMode>;
|
|
26
|
+
readonly config?: ConfigSchema;
|
|
27
|
+
readonly scope: Scope;
|
|
28
|
+
execute(context: NornWorkflowContext<ArgsSchema, IsolationMode, ConfigSchema, Scope>): MaybePromise<WorkflowResult>;
|
|
24
29
|
};
|
|
25
|
-
export type NornAnyWorkflowDeclaration = Pick<NornWorkflowDeclaration, keyof NornWorkflowDeclaration> & ((
|
|
26
|
-
export type NornWorkflowRefSchemaOptions<
|
|
27
|
-
readonly
|
|
30
|
+
export type NornAnyWorkflowDeclaration = Pick<NornWorkflowDeclaration, keyof NornWorkflowDeclaration> & ((args: never) => NornRunNext);
|
|
31
|
+
export type NornWorkflowRefSchemaOptions<ArgsSchema extends TSchema = TSchema> = {
|
|
32
|
+
readonly args?: ArgsSchema;
|
|
28
33
|
};
|
|
29
34
|
export type NornWorkflowRefInput = StaticEncode<typeof workflowReferenceInputSchema>;
|
|
30
|
-
export type NornWorkflowRefOutput<
|
|
31
|
-
export type
|
|
32
|
-
export type
|
|
33
|
-
export type NornWorkflowGate<
|
|
35
|
+
export type NornWorkflowRefOutput<ArgsSchema extends TSchema> = (args: StaticEncode<ArgsSchema> & object) => NornRunNext;
|
|
36
|
+
export type NornWorkflowArgsInput<TWorkflow extends NornAnyWorkflowDeclaration> = StaticEncode<TWorkflow["args"]>;
|
|
37
|
+
export type NornWorkflowArgs<TWorkflow extends NornAnyWorkflowDeclaration> = StaticDecode<TWorkflow["args"]>;
|
|
38
|
+
export type NornWorkflowGate<ArgsSchema extends TSchema> = unknown extends StaticEncode<ArgsSchema> ? NornWorkflowAnyGate : StaticEncode<ArgsSchema> extends Record<string, unknown> ? {
|
|
34
39
|
readonly enabled: true;
|
|
35
|
-
readonly fields?: readonly Extract<keyof StaticEncode<
|
|
40
|
+
readonly fields?: readonly Extract<keyof StaticEncode<ArgsSchema>, string>[];
|
|
36
41
|
} : {
|
|
37
42
|
readonly enabled: true;
|
|
38
43
|
readonly fields?: never;
|
|
@@ -44,94 +49,52 @@ type NornWorkflowInstructions = {
|
|
|
44
49
|
readonly isEntrypoint: false;
|
|
45
50
|
readonly instructions?: string;
|
|
46
51
|
};
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
readonly
|
|
51
|
-
readonly
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
readonly
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
readonly isolation?: NornWorkflowIsolation;
|
|
58
|
-
} & NornWorkflowInstructions;
|
|
59
|
-
export type NornWorkflowStateDefinition<Schema extends TSchema = TSchema, Id extends string = string> = {
|
|
60
|
-
readonly id: Id;
|
|
61
|
-
readonly description?: string;
|
|
62
|
-
readonly schema: Schema;
|
|
63
|
-
};
|
|
64
|
-
export type NornWorkflowStateDefinitionInput<Schema extends TSchema = TSchema, Id extends string | undefined = string | undefined> = {
|
|
65
|
-
readonly id?: Id;
|
|
66
|
-
readonly description?: string;
|
|
67
|
-
readonly schema: Schema;
|
|
68
|
-
};
|
|
69
|
-
export type NornWorkflowPluginWorkflows = Record<string, NornAnyWorkflowDefinition>;
|
|
70
|
-
export type NornWorkflowPluginStateTree = {
|
|
71
|
-
readonly [key: string]: NornWorkflowPluginStateTreeNode;
|
|
72
|
-
};
|
|
73
|
-
type NornStateSchema = TSchema & ({
|
|
74
|
-
readonly "~kind": string;
|
|
75
|
-
} | {
|
|
76
|
-
readonly "~unsafe": unknown;
|
|
77
|
-
});
|
|
78
|
-
export type NornWorkflowPluginStateTreeNode = NornStateSchema | NornWorkflowStateDefinitionInput | NornWorkflowPluginStateTree;
|
|
79
|
-
type JoinPath<Head extends string, Parts extends readonly string[]> = Parts extends readonly [] ? Head : Parts extends readonly [infer First extends string, ...infer Rest extends string[]] ? JoinPath<`${Head}.${First}`, Rest> : string;
|
|
80
|
-
type NornInvalidGateFields<TWorkflow> = TWorkflow extends {
|
|
81
|
-
readonly params: infer ParamsSchema extends TSchema;
|
|
82
|
-
readonly gate: {
|
|
83
|
-
readonly fields: infer Fields extends readonly string[];
|
|
84
|
-
};
|
|
85
|
-
} ? Exclude<Fields[number], Extract<keyof StaticEncode<ParamsSchema>, string>> : never;
|
|
86
|
-
type NornValidatedWorkflowGate<TWorkflow> = [NornInvalidGateFields<TWorkflow>] extends [never] ? unknown : {
|
|
87
|
-
readonly gate: {
|
|
88
|
-
readonly fields: readonly Extract<keyof StaticEncode<TWorkflow extends {
|
|
89
|
-
readonly params: infer ParamsSchema extends TSchema;
|
|
90
|
-
} ? ParamsSchema : TSchema>, string>[];
|
|
52
|
+
type RunForIsolation<Mode extends NornWorkflowIsolationMode> = Mode extends "project" ? NornProjectRun : NornRun;
|
|
53
|
+
type WorkflowConfig<Schema extends TSchema | undefined> = Schema extends TSchema ? StaticDecode<Schema> : undefined;
|
|
54
|
+
export type NornWorkflowContext<ArgsSchema extends TSchema = TSchema, Mode extends NornWorkflowIsolationMode = NornWorkflowIsolationMode, ConfigSchema extends TSchema | undefined = TSchema | undefined, Scope extends NornWorkflowScopeInfo | undefined = NornWorkflowScopeInfo | undefined> = {
|
|
55
|
+
readonly args: StaticDecode<ArgsSchema>;
|
|
56
|
+
readonly config: WorkflowConfig<ConfigSchema>;
|
|
57
|
+
readonly run: RunForIsolation<Mode>;
|
|
58
|
+
} & (Scope extends NornWorkflowScopeInfo ? {
|
|
59
|
+
readonly scope: {
|
|
60
|
+
readonly id: Scope["id"];
|
|
61
|
+
readonly config: WorkflowConfig<Scope["config"]>;
|
|
91
62
|
};
|
|
92
|
-
};
|
|
93
|
-
export type
|
|
94
|
-
readonly
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
readonly
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
} ? ExplicitId : `${PluginId}.${WorkflowKey}`, ParamsSchema, TWorkflow extends {
|
|
101
|
-
readonly isolation: {
|
|
102
|
-
readonly mode: infer IsolationMode extends NornWorkflowIsolationMode;
|
|
63
|
+
} : {});
|
|
64
|
+
export type NornWorkflowDefinition<Id extends string = string, ArgsSchema extends TSchema = TSchema, IsolationMode extends NornWorkflowIsolationMode = NornWorkflowIsolationMode, ConfigSchema extends TSchema | undefined = undefined, Scope extends NornWorkflowScopeInfo | undefined = undefined> = {
|
|
65
|
+
readonly id: Id;
|
|
66
|
+
readonly args: ArgsSchema;
|
|
67
|
+
readonly config?: ConfigSchema;
|
|
68
|
+
readonly isolation?: NornWorkflowIsolation<IsolationMode>;
|
|
69
|
+
readonly gate?: NornWorkflowGate<ArgsSchema> & {
|
|
70
|
+
describe?(context: NornWorkflowContext<ArgsSchema, IsolationMode, ConfigSchema, Scope>): MaybePromise<string>;
|
|
103
71
|
};
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
readonly [Key in keyof States]: States[Key] extends NornStateSchema ? NornWorkflowStateDefinition<States[Key], JoinPath<PluginId, [...Path, Key & string]>> : States[Key] extends NornWorkflowStateDefinitionInput<infer Schema extends NornStateSchema> ? NornWorkflowStateDefinition<Schema, States[Key] extends {
|
|
110
|
-
readonly id: infer Id extends string;
|
|
111
|
-
} ? Id : JoinPath<PluginId, [...Path, Key & string]>> : States[Key] extends NornWorkflowPluginStateTree ? NornQualifiedPluginStates<PluginId, States[Key], [...Path, Key & string]> : never;
|
|
72
|
+
execute(context: NornWorkflowContext<ArgsSchema, IsolationMode, ConfigSchema, Scope>): MaybePromise<WorkflowResult>;
|
|
73
|
+
} & NornWorkflowInstructions;
|
|
74
|
+
export type NornWorkflowScopeInfo = {
|
|
75
|
+
readonly id: string;
|
|
76
|
+
readonly config?: TSchema;
|
|
112
77
|
};
|
|
113
|
-
export type
|
|
114
|
-
readonly id:
|
|
115
|
-
readonly config
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
export
|
|
125
|
-
|
|
78
|
+
export type NornWorkflowScope<Id extends string, ConfigSchema extends TSchema | undefined> = {
|
|
79
|
+
readonly id: Id;
|
|
80
|
+
readonly config: ConfigSchema;
|
|
81
|
+
workflow<const LocalId extends string, ArgsSchema extends TSchema, const Mode extends NornWorkflowIsolationMode = "runWorkspace", LocalConfig extends TSchema | undefined = undefined>(definition: NornWorkflowDefinition<LocalId, ArgsSchema, Mode, LocalConfig, {
|
|
82
|
+
readonly id: Id;
|
|
83
|
+
readonly config: ConfigSchema;
|
|
84
|
+
}>): NornWorkflowDeclaration<`${Id}.${LocalId}`, ArgsSchema, Mode, LocalConfig, {
|
|
85
|
+
readonly id: Id;
|
|
86
|
+
readonly config: ConfigSchema;
|
|
87
|
+
}>;
|
|
88
|
+
};
|
|
89
|
+
export declare function workflow<const Id extends string, ArgsSchema extends TSchema, const Mode extends NornWorkflowIsolationMode = "runWorkspace", ConfigSchema extends TSchema | undefined = undefined>(definition: NornWorkflowDefinition<Id, ArgsSchema, Mode, ConfigSchema>): NornWorkflowDeclaration<Id, ArgsSchema, Mode, ConfigSchema, undefined>;
|
|
90
|
+
export declare function workflowScope<const Id extends string, ConfigSchema extends TSchema | undefined = undefined>(input: {
|
|
91
|
+
readonly id: Id;
|
|
126
92
|
readonly config?: ConfigSchema;
|
|
127
|
-
|
|
128
|
-
readonly states?: States;
|
|
129
|
-
};
|
|
130
|
-
export declare function definePluginManifest<const PluginId extends string, const ConfigSchema extends TSchema | undefined = undefined, const Workflows extends NornWorkflowPluginWorkflows = NornWorkflowPluginWorkflows, const States extends NornWorkflowPluginStateTree | undefined = undefined>(input: NornDefinePluginManifestInput<PluginId, ConfigSchema, Workflows, States>): NornWorkflowPluginManifest<PluginId, ConfigSchema, NornQualifiedPluginWorkflows<PluginId, Workflows>, States extends NornWorkflowPluginStateTree ? NornQualifiedPluginStates<PluginId, States> : undefined>;
|
|
93
|
+
}): NornWorkflowScope<Id, ConfigSchema>;
|
|
131
94
|
export type NornRunNext = {
|
|
132
95
|
readonly type: "next";
|
|
133
96
|
readonly workflowId: string;
|
|
134
|
-
readonly
|
|
97
|
+
readonly args: unknown;
|
|
135
98
|
};
|
|
136
99
|
export type NornRunOutcomeMetadata = {
|
|
137
100
|
readonly summary?: string;
|
|
@@ -149,19 +112,12 @@ export type NornRunFail = {
|
|
|
149
112
|
readonly summary: string;
|
|
150
113
|
};
|
|
151
114
|
};
|
|
152
|
-
export type
|
|
115
|
+
export type WorkflowResult = NornRunNext | NornRunComplete | NornRunFail;
|
|
153
116
|
export type NornRunFor<TWorkflow extends NornAnyWorkflowDeclaration> = TWorkflow extends {
|
|
154
117
|
readonly isolation: {
|
|
155
118
|
readonly mode: "project";
|
|
156
119
|
};
|
|
157
120
|
} ? NornProjectRun : NornRun;
|
|
158
|
-
export type NornWorkflowGateImplementation<TWorkflow extends NornAnyWorkflowDeclaration, TConfig> = {
|
|
159
|
-
describe(run: NornRunFor<TWorkflow>, params: NornWorkflowParams<TWorkflow>, config: TConfig): MaybePromise<string>;
|
|
160
|
-
};
|
|
161
|
-
export type NornWorkflowImplementation<TWorkflow extends NornAnyWorkflowDeclaration, TConfig = unknown> = {
|
|
162
|
-
readonly gate?: NornWorkflowGateImplementation<TWorkflow, TConfig>;
|
|
163
|
-
execute(run: NornRunFor<TWorkflow>, params: NornWorkflowParams<TWorkflow>, config: TConfig): MaybePromise<NornWorkflowExecutionResult>;
|
|
164
|
-
};
|
|
165
121
|
export type NornRunStartOptions = {
|
|
166
122
|
readonly id?: string;
|
|
167
123
|
readonly name?: string;
|
|
@@ -206,7 +162,7 @@ export type NornStoppedRunResult = {
|
|
|
206
162
|
};
|
|
207
163
|
export type NornRunInterruption = {
|
|
208
164
|
readonly workflowId: string;
|
|
209
|
-
readonly
|
|
165
|
+
readonly args: unknown;
|
|
210
166
|
readonly description: string;
|
|
211
167
|
readonly fields?: readonly string[];
|
|
212
168
|
};
|
|
@@ -261,29 +217,6 @@ export type NornRunCheckpoint = {
|
|
|
261
217
|
readonly message: string;
|
|
262
218
|
readonly createdAt: string;
|
|
263
219
|
};
|
|
264
|
-
export type NornWorkflowStateReader = {
|
|
265
|
-
get<Schema extends TSchema>(state: NornWorkflowStateDefinition<Schema>): Promise<Static<Schema>>;
|
|
266
|
-
getOptional<Schema extends TSchema>(state: NornWorkflowStateDefinition<Schema>): Promise<Static<Schema> | undefined>;
|
|
267
|
-
};
|
|
268
|
-
export type NornWorkflowState = NornWorkflowStateReader & {
|
|
269
|
-
set<Schema extends TSchema>(state: NornWorkflowStateDefinition<Schema>, value: NoInfer<Static<Schema>>): Promise<void>;
|
|
270
|
-
};
|
|
271
|
-
export type NornWorkflowPluginContext = {
|
|
272
|
-
readonly cwd: string;
|
|
273
|
-
readonly state: NornWorkflowState;
|
|
274
|
-
};
|
|
275
|
-
export type NornWorkflowPluginImplementation<TManifest extends NornAnyWorkflowPluginManifest> = {
|
|
276
|
-
readonly workflows: {
|
|
277
|
-
readonly [Key in keyof TManifest["workflows"]]: NornWorkflowImplementation<TManifest["workflows"][Key], NornWorkflowPluginConfig<TManifest>>;
|
|
278
|
-
};
|
|
279
|
-
};
|
|
280
|
-
export type NornWorkflowPluginImplementationFactory<TManifest extends NornAnyWorkflowPluginManifest> = (context: NornWorkflowPluginContext) => NornWorkflowPluginImplementation<TManifest>;
|
|
281
|
-
export type NornWorkflowPluginImplementationInput<TManifest extends NornAnyWorkflowPluginManifest> = NornWorkflowPluginImplementation<TManifest> | NornWorkflowPluginImplementationFactory<TManifest>;
|
|
282
|
-
export type NornWorkflowPlugin<TManifest extends NornAnyWorkflowPluginManifest = NornAnyWorkflowPluginManifest> = {
|
|
283
|
-
readonly manifest: TManifest;
|
|
284
|
-
readonly implementation: NornWorkflowPluginImplementationInput<TManifest>;
|
|
285
|
-
};
|
|
286
|
-
export declare function definePlugin<TManifest extends NornAnyWorkflowPluginManifest>(manifest: TManifest, implementation: NornWorkflowPluginImplementationInput<TManifest>): NornWorkflowPlugin<TManifest>;
|
|
287
220
|
export type NornCommandRunInput = {
|
|
288
221
|
readonly label: string;
|
|
289
222
|
readonly command: string | readonly [string, ...string[]];
|
|
@@ -295,12 +228,12 @@ export declare const artifactRefSchema: Type.TObject<{
|
|
|
295
228
|
path: Type.TString;
|
|
296
229
|
}>;
|
|
297
230
|
export type NornArtifactRef = StaticDecode<typeof artifactRefSchema>;
|
|
298
|
-
declare const
|
|
231
|
+
declare const emptyWorkflowRefArgsSchema: Type.TObject<{}>;
|
|
299
232
|
declare const workflowReferenceInputSchema: Type.TUnion<[Type.TString, Type.TObject<{
|
|
300
233
|
workflow: Type.TString;
|
|
301
|
-
|
|
234
|
+
forwardArgs: Type.TRecord<"^.*$", Type.TUnknown>;
|
|
302
235
|
}>]>;
|
|
303
|
-
export declare function workflowRefSchema<
|
|
236
|
+
export declare function workflowRefSchema<ArgsSchema extends TSchema = typeof emptyWorkflowRefArgsSchema>(options?: NornWorkflowRefSchemaOptions<ArgsSchema>): TCodec<typeof workflowReferenceInputSchema, NornWorkflowRefOutput<ArgsSchema>>;
|
|
304
237
|
export type NornLogRef = {
|
|
305
238
|
readonly id: string;
|
|
306
239
|
};
|
|
@@ -443,13 +376,12 @@ type NornRunBase = {
|
|
|
443
376
|
workspace: string;
|
|
444
377
|
cwd: string;
|
|
445
378
|
path(relativePath: string): string;
|
|
446
|
-
next(workflowId: string,
|
|
379
|
+
next(workflowId: string, args: unknown): NornRunNext;
|
|
447
380
|
complete(metadata?: NornRunOutcomeMetadata): NornRunComplete;
|
|
448
381
|
fail(metadata: NornRunOutcomeMetadata & {
|
|
449
382
|
readonly summary: string;
|
|
450
383
|
}): NornRunFail;
|
|
451
384
|
resources: import("./resources.ts").NornResources;
|
|
452
|
-
state: NornWorkflowState;
|
|
453
385
|
artifacts: {
|
|
454
386
|
write(path: string, content: string): Promise<NornArtifactRef>;
|
|
455
387
|
read(ref: NornArtifactRef): Promise<string>;
|
|
@@ -465,10 +397,9 @@ type NornRunBase = {
|
|
|
465
397
|
prompt<ResponseSchema extends TSchema>(input: NornAgentSinglePromptInput<ResponseSchema>): Promise<StaticDecode<ResponseSchema>>;
|
|
466
398
|
};
|
|
467
399
|
};
|
|
468
|
-
export type
|
|
469
|
-
readonly
|
|
470
|
-
readonly
|
|
471
|
-
readonly configPath?: string;
|
|
400
|
+
export type NornWorkflowSource = {
|
|
401
|
+
readonly path: string;
|
|
402
|
+
readonly configPath: string;
|
|
472
403
|
};
|
|
473
404
|
export type NornJsonSchema = Record<string, unknown>;
|
|
474
405
|
export type NornWorkflowGateInfo = {
|
|
@@ -480,24 +411,34 @@ export type NornRegisteredWorkflowInfo = {
|
|
|
480
411
|
readonly instructions?: string;
|
|
481
412
|
readonly isEntrypoint: boolean;
|
|
482
413
|
readonly isolation: NornWorkflowIsolation;
|
|
483
|
-
readonly
|
|
414
|
+
readonly scope?: {
|
|
415
|
+
readonly id: string;
|
|
416
|
+
};
|
|
417
|
+
readonly source?: NornWorkflowSource;
|
|
418
|
+
readonly configKey: string;
|
|
484
419
|
};
|
|
485
420
|
export type NornInspectedWorkflowInfo = NornRegisteredWorkflowInfo & {
|
|
486
|
-
readonly
|
|
421
|
+
readonly scope?: {
|
|
422
|
+
readonly id: string;
|
|
423
|
+
readonly configKey: string;
|
|
424
|
+
readonly configSchema: NornJsonSchema | null;
|
|
425
|
+
};
|
|
426
|
+
readonly argsSchema: NornJsonSchema;
|
|
427
|
+
readonly configSchema: NornJsonSchema | null;
|
|
487
428
|
readonly gate: NornWorkflowGateInfo | null;
|
|
488
429
|
};
|
|
489
|
-
export type
|
|
430
|
+
export type NornWorkflowDiagnostic = {
|
|
490
431
|
readonly configPath: string;
|
|
491
|
-
readonly
|
|
492
|
-
readonly
|
|
432
|
+
readonly modulePath: string;
|
|
433
|
+
readonly scopeId: string | null;
|
|
493
434
|
readonly workflowId: string | null;
|
|
494
|
-
readonly stage: "import" | "declaration" | "config" | "
|
|
435
|
+
readonly stage: "import" | "declaration" | "config" | "duplicate" | "schema";
|
|
495
436
|
readonly message: string;
|
|
496
437
|
readonly issues: readonly TLocalizedValidationError[];
|
|
497
438
|
};
|
|
498
439
|
export type NornProjectLoadStatus = {
|
|
499
440
|
readonly isComplete: boolean;
|
|
500
|
-
readonly diagnostics: readonly
|
|
441
|
+
readonly diagnostics: readonly NornWorkflowDiagnostic[];
|
|
501
442
|
};
|
|
502
443
|
export type NornWorkflowCatalogInfo = NornProjectLoadStatus & {
|
|
503
444
|
readonly workflows: readonly NornRegisteredWorkflowInfo[];
|
|
@@ -508,7 +449,9 @@ export type NornWorkflowInspection = NornProjectLoadStatus & {
|
|
|
508
449
|
export type NornProjectInspection = NornProjectLoadStatus & {
|
|
509
450
|
readonly project: NornProjectInfo;
|
|
510
451
|
};
|
|
511
|
-
export type
|
|
452
|
+
export type NornProjectConfigurationInfo = {
|
|
453
|
+
readonly key: string;
|
|
454
|
+
readonly scopeId: string | null;
|
|
512
455
|
readonly configSchema: NornJsonSchema | null;
|
|
513
456
|
readonly config: unknown;
|
|
514
457
|
};
|
|
@@ -519,11 +462,10 @@ export type NornProjectInfo = {
|
|
|
519
462
|
readonly configPath: string;
|
|
520
463
|
readonly configRoot: string;
|
|
521
464
|
readonly configFiles: readonly string[];
|
|
522
|
-
readonly
|
|
465
|
+
readonly configurations: readonly NornProjectConfigurationInfo[];
|
|
466
|
+
readonly modules: readonly NornWorkflowSource[];
|
|
523
467
|
};
|
|
524
468
|
export declare function isWorkflowDeclaration(value: unknown): value is NornAnyWorkflowDeclaration;
|
|
525
|
-
export declare function isWorkflowPlugin(value: unknown): value is NornWorkflowPlugin;
|
|
526
|
-
export declare function isWorkflowPluginManifest(value: unknown): value is NornAnyWorkflowPluginManifest;
|
|
527
469
|
export declare function isWorkflowNext(value: unknown): value is NornRunNext;
|
|
528
470
|
export declare function isWorkflowComplete(value: unknown): value is NornRunComplete;
|
|
529
471
|
export declare function isWorkflowFail(value: unknown): value is NornRunFail;
|
package/dist/api.js
CHANGED
|
@@ -4,103 +4,69 @@ import { Type } from "typebox";
|
|
|
4
4
|
// ../core/src/workflow-transition.ts
|
|
5
5
|
function createWorkflowTransition(input) {
|
|
6
6
|
if (typeof input.workflowId !== "string" || input.workflowId.trim().length === 0) throw new Error("Workflow transition requires a nonempty workflow ID");
|
|
7
|
-
return { type: "next", workflowId: input.workflowId,
|
|
7
|
+
return { type: "next", workflowId: input.workflowId, args: input.args };
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
// src/api.ts
|
|
11
11
|
import { Value } from "typebox/value";
|
|
12
|
-
import { isPlainObject, jsonValueSchema } from "./schema.js";
|
|
12
|
+
import { assertWorkflowMetadata, isPlainObject, jsonValueSchema } from "./schema.js";
|
|
13
13
|
var WORKFLOW_DECLARATION_KIND = "norn.workflow";
|
|
14
|
-
function
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
);
|
|
14
|
+
function workflow(definition) {
|
|
15
|
+
return createWorkflow({ definition, scope: void 0 });
|
|
16
|
+
}
|
|
17
|
+
function createWorkflow(input) {
|
|
18
|
+
const { definition, scope } = input;
|
|
19
|
+
assertDeclarationId(definition.id);
|
|
20
|
+
const callable = (args) => createWorkflowTransition({ workflowId: definition.id, args });
|
|
21
|
+
const result = Object.assign(callable, definition, {
|
|
22
|
+
kind: WORKFLOW_DECLARATION_KIND,
|
|
23
|
+
scope,
|
|
24
|
+
isolation: definition.isolation ?? { mode: "runWorkspace" }
|
|
25
|
+
});
|
|
26
|
+
if (!isWorkflowDeclaration(result)) throw new Error(`Invalid workflow definition: ${definition.id}`);
|
|
27
|
+
assertWorkflowMetadata(result);
|
|
28
|
+
return result;
|
|
29
|
+
}
|
|
30
|
+
function workflowScope(input) {
|
|
31
|
+
assertDeclarationId(input.id);
|
|
32
|
+
const scope = { id: input.id, config: input.config };
|
|
20
33
|
return {
|
|
21
34
|
id: input.id,
|
|
22
35
|
config: input.config,
|
|
23
|
-
|
|
24
|
-
|
|
36
|
+
workflow(definition) {
|
|
37
|
+
assertDeclarationId(definition.id);
|
|
38
|
+
return createWorkflow({ definition: { ...definition, id: `${input.id}.${definition.id}` }, scope });
|
|
39
|
+
}
|
|
25
40
|
};
|
|
26
41
|
}
|
|
27
|
-
function definePlugin(manifest, implementation) {
|
|
28
|
-
return { manifest, implementation };
|
|
29
|
-
}
|
|
30
42
|
var artifactRefSchema = Type.Object({
|
|
31
43
|
path: Type.String()
|
|
32
44
|
});
|
|
33
|
-
var
|
|
45
|
+
var emptyWorkflowRefArgsSchema = Type.Object({});
|
|
34
46
|
var workflowReferenceInputSchema = Type.Union([
|
|
35
47
|
Type.String({ minLength: 1 }),
|
|
36
|
-
Type.Object({ workflow: Type.String({ minLength: 1 }),
|
|
48
|
+
Type.Object({ workflow: Type.String({ minLength: 1 }), forwardArgs: Type.Record(Type.String(), Type.Unknown()) })
|
|
37
49
|
]);
|
|
38
50
|
function workflowRefSchema(options) {
|
|
39
|
-
const contributionSchema = options?.
|
|
51
|
+
const contributionSchema = options?.args ?? emptyWorkflowRefArgsSchema;
|
|
40
52
|
return Type.With(Type.Decode(workflowReferenceInputSchema, (reference) => {
|
|
41
53
|
const workflowId = typeof reference === "string" ? reference : reference.workflow;
|
|
42
|
-
const
|
|
43
|
-
return (
|
|
44
|
-
Value.Assert(contributionSchema,
|
|
45
|
-
if (!isPlainObject(
|
|
46
|
-
Value.Assert(jsonValueSchema,
|
|
47
|
-
return createWorkflowTransition({ workflowId,
|
|
54
|
+
const forwardArgs = typeof reference === "string" ? {} : reference.forwardArgs;
|
|
55
|
+
return (args) => {
|
|
56
|
+
Value.Assert(contributionSchema, args);
|
|
57
|
+
if (!isPlainObject(args)) throw new Error("Workflow reference contributions must be objects");
|
|
58
|
+
Value.Assert(jsonValueSchema, args);
|
|
59
|
+
return createWorkflowTransition({ workflowId, args: { ...forwardArgs, ...args } });
|
|
48
60
|
};
|
|
49
|
-
}), { "x-norn-workflow-ref": {
|
|
50
|
-
}
|
|
51
|
-
function assertLocalDeclarationId(id, kind) {
|
|
52
|
-
if (id.length === 0) throw new Error(`Workflow ${kind} id must not be empty`);
|
|
53
|
-
if (id.includes(".")) throw new Error(`Workflow ${kind} id must not contain dots: ${id}`);
|
|
54
|
-
}
|
|
55
|
-
function resolveDeclarationId(pluginId, path, explicitId, kind, declaredIds) {
|
|
56
|
-
for (const segment of path) assertLocalDeclarationId(segment, kind);
|
|
57
|
-
const id = explicitId ?? [pluginId, ...path].join(".");
|
|
58
|
-
if (explicitId !== void 0) assertPluginQualifiedId(pluginId, explicitId, kind);
|
|
59
|
-
if (declaredIds.has(id)) throw new Error(`Duplicate Norn ${kind} id: ${id}`);
|
|
60
|
-
declaredIds.add(id);
|
|
61
|
-
return id;
|
|
62
|
-
}
|
|
63
|
-
function assertPluginQualifiedId(pluginId, id, kind) {
|
|
64
|
-
if (!id.startsWith(`${pluginId}.`)) throw new Error(`Explicit Norn ${kind} id must start with ${pluginId}.: ${id}`);
|
|
65
|
-
if (id.length === pluginId.length + 1) throw new Error(`Explicit Norn ${kind} id must not be empty after ${pluginId}.`);
|
|
61
|
+
}), { "x-norn-workflow-ref": { contributedArgsSchema: contributionSchema } });
|
|
66
62
|
}
|
|
67
|
-
function
|
|
68
|
-
|
|
69
|
-
const declaration = (params) => createWorkflowTransition({ workflowId: id, params });
|
|
70
|
-
return Object.assign(declaration, { ...workflow, kind: WORKFLOW_DECLARATION_KIND, id, isolation: workflow.isolation ?? { mode: "runWorkspace" } });
|
|
71
|
-
}
|
|
72
|
-
function qualifyStateTree(pluginId, node, path, declaredIds) {
|
|
73
|
-
if (node === void 0) return void 0;
|
|
74
|
-
if (isTypeboxSchema(node)) return { id: resolveDeclarationId(pluginId, path, void 0, "state", declaredIds), schema: node };
|
|
75
|
-
if (path.length > 0 && isWorkflowStateDefinitionInput(node)) {
|
|
76
|
-
return { ...node, id: resolveDeclarationId(pluginId, path, node.id, "state", declaredIds) };
|
|
77
|
-
}
|
|
78
|
-
if (!isPlainObject(node)) throw new Error(`Invalid state declaration: ${[pluginId, ...path].join(".")}`);
|
|
79
|
-
return Object.fromEntries(Object.entries(node).map(([key, child]) => [key, qualifyStateTree(pluginId, child, [...path, key], declaredIds)]));
|
|
63
|
+
function assertDeclarationId(id) {
|
|
64
|
+
if (typeof id !== "string" || id.trim().length === 0 || id.split(".").some((segment) => segment.length === 0)) throw new Error(`Invalid workflow or scope id: ${id}`);
|
|
80
65
|
}
|
|
81
66
|
function isWorkflowDeclaration(value) {
|
|
82
67
|
if (typeof value !== "function") return false;
|
|
83
68
|
const candidate = value;
|
|
84
|
-
return candidate.kind === WORKFLOW_DECLARATION_KIND && typeof candidate.id === "string" && candidate.id.length > 0 && (candidate.instructions === void 0 || typeof candidate.instructions === "string") && typeof candidate.isEntrypoint === "boolean" && Boolean(candidate.
|
|
85
|
-
}
|
|
86
|
-
function isTypeboxSchema(value) {
|
|
87
|
-
return Type.IsUnsafe(value) || Boolean(value && typeof value === "object" && "~kind" in value && typeof value["~kind"] === "string");
|
|
88
|
-
}
|
|
89
|
-
function isWorkflowStateDefinitionInput(value) {
|
|
90
|
-
if (!isPlainObject(value)) return false;
|
|
91
|
-
return (value.id === void 0 || typeof value.id === "string") && isTypeboxSchema(value.schema);
|
|
92
|
-
}
|
|
93
|
-
function isWorkflowPlugin(value) {
|
|
94
|
-
if (!value || typeof value !== "object") return false;
|
|
95
|
-
const candidate = value;
|
|
96
|
-
return isWorkflowPluginManifest(candidate.manifest) && Boolean(candidate.implementation);
|
|
97
|
-
}
|
|
98
|
-
function isWorkflowPluginManifest(value) {
|
|
99
|
-
if (!value || typeof value !== "object") return false;
|
|
100
|
-
const candidate = value;
|
|
101
|
-
if (typeof candidate.id !== "string" || candidate.id.length === 0) return false;
|
|
102
|
-
if (!candidate.workflows || typeof candidate.workflows !== "object") return false;
|
|
103
|
-
return Object.values(candidate.workflows).every(isWorkflowDeclaration);
|
|
69
|
+
return candidate.kind === WORKFLOW_DECLARATION_KIND && typeof candidate.id === "string" && candidate.id.length > 0 && (candidate.instructions === void 0 || typeof candidate.instructions === "string") && typeof candidate.isEntrypoint === "boolean" && Boolean(candidate.args) && typeof candidate.execute === "function" && (candidate.isolation?.mode === "runWorkspace" || candidate.isolation?.mode === "project");
|
|
104
70
|
}
|
|
105
71
|
function isWorkflowNext(value) {
|
|
106
72
|
if (!value || typeof value !== "object") return false;
|
|
@@ -119,13 +85,11 @@ function isWorkflowFail(value) {
|
|
|
119
85
|
}
|
|
120
86
|
export {
|
|
121
87
|
artifactRefSchema,
|
|
122
|
-
definePlugin,
|
|
123
|
-
definePluginManifest,
|
|
124
88
|
isWorkflowComplete,
|
|
125
89
|
isWorkflowDeclaration,
|
|
126
90
|
isWorkflowFail,
|
|
127
91
|
isWorkflowNext,
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
92
|
+
workflow,
|
|
93
|
+
workflowRefSchema,
|
|
94
|
+
workflowScope
|
|
131
95
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
export type { CreateAgentSessionOptions, EventBus, PromptOptions, ToolDefinition } from "@earendil-works/pi-coding-agent";
|
|
1
2
|
export * from "./api.ts";
|
|
2
3
|
export { NornFileCoordinator } from "./files.ts";
|
|
3
4
|
export * from "./resources.ts";
|
|
4
5
|
export * from "./agent-resource-adapter.ts";
|
|
5
|
-
export * from "./state-adapter.ts";
|
package/dist/index.js
CHANGED
package/dist/schema.js
CHANGED
|
@@ -23,9 +23,9 @@ function assertWorkflowReferenceAnnotations(schema) {
|
|
|
23
23
|
if (!isPlainObject(schema)) return;
|
|
24
24
|
if (Object.hasOwn(schema, "x-norn-workflow-ref")) {
|
|
25
25
|
const annotation = schema["x-norn-workflow-ref"];
|
|
26
|
-
if (!isPlainObject(annotation) || !Object.hasOwn(annotation, "
|
|
27
|
-
Value.Assert(Meta["https://json-schema.org/draft/2020-12/schema"], annotation.
|
|
28
|
-
assertWorkflowReferenceAnnotations(annotation.
|
|
26
|
+
if (!isPlainObject(annotation) || !Object.hasOwn(annotation, "contributedArgsSchema")) throw new Error("Invalid workflow reference annotation");
|
|
27
|
+
Value.Assert(Meta["https://json-schema.org/draft/2020-12/schema"], annotation.contributedArgsSchema);
|
|
28
|
+
assertWorkflowReferenceAnnotations(annotation.contributedArgsSchema);
|
|
29
29
|
}
|
|
30
30
|
for (const keyword of ["properties", "patternProperties", "$defs", "definitions", "dependentSchemas"]) {
|
|
31
31
|
const schemas = schema[keyword];
|
package/package.json
CHANGED
package/dist/state-adapter.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { NornAgentResourceAdapter } from "./agent-resource-adapter.ts";
|
|
2
|
-
import type { NornWorkflowState, NornWorkflowStateDefinition } from "./api.ts";
|
|
3
|
-
export type NornStateFieldAccess = {
|
|
4
|
-
readonly field: NornWorkflowStateDefinition;
|
|
5
|
-
readonly access: "read" | "write" | "read-write";
|
|
6
|
-
};
|
|
7
|
-
export declare function StateAdapter(input: {
|
|
8
|
-
readonly state: NornWorkflowState;
|
|
9
|
-
readonly fields: readonly NornStateFieldAccess[];
|
|
10
|
-
}): NornAgentResourceAdapter;
|
package/dist/state-adapter.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
// src/state-adapter.ts
|
|
2
|
-
import { defineTool } from "@earendil-works/pi-coding-agent";
|
|
3
|
-
import { createHash } from "node:crypto";
|
|
4
|
-
import { Type } from "typebox";
|
|
5
|
-
import { inspectSchema } from "./schema.js";
|
|
6
|
-
var pageParameters = {
|
|
7
|
-
offset: Type.Integer({ minimum: 0, description: "Zero-based UTF-16 offset into the serialized JSON. Start at 0." }),
|
|
8
|
-
limit: Type.Integer({ minimum: 1, maximum: 1e4 })
|
|
9
|
-
};
|
|
10
|
-
function StateAdapter(input) {
|
|
11
|
-
const fields = new Map(input.fields.map((grant) => [grant.field.id, grant]));
|
|
12
|
-
if (fields.size !== input.fields.length || fields.size === 0) throw new Error("State attachment requires unique, explicitly selected fields");
|
|
13
|
-
const selectField = (key, access) => {
|
|
14
|
-
const grant = fields.get(key);
|
|
15
|
-
if (!grant || grant.access !== access && grant.access !== "read-write") throw new Error(`State ${access} is not attached: ${key}`);
|
|
16
|
-
return grant.field;
|
|
17
|
-
};
|
|
18
|
-
return {
|
|
19
|
-
name: "norn.state",
|
|
20
|
-
async bind() {
|
|
21
|
-
return {
|
|
22
|
-
tools: [
|
|
23
|
-
defineTool({
|
|
24
|
-
name: "norn_state_list",
|
|
25
|
-
label: "Attached workflow state",
|
|
26
|
-
description: "List only attached workflow-state field IDs, permissions and value schemas. JSON is paginated; use nextOffset until null.",
|
|
27
|
-
parameters: Type.Object(pageParameters),
|
|
28
|
-
async execute(_id, params) {
|
|
29
|
-
return serializePage({ value: [...fields.values()].map(({ field, access }) => ({ id: field.id, access, schema: inspectSchema(field.schema) })), ...params });
|
|
30
|
-
}
|
|
31
|
-
}),
|
|
32
|
-
defineTool({
|
|
33
|
-
name: "norn_state_get",
|
|
34
|
-
label: "Read workflow state",
|
|
35
|
-
description: "Read a selected workflow-state field. Unset fields return isSet:false. JSON is paginated; concurrent writes can change later pages, so compare revision before combining pages.",
|
|
36
|
-
parameters: Type.Object({ key: Type.String(), ...pageParameters }),
|
|
37
|
-
async execute(_id, params) {
|
|
38
|
-
const value = await input.state.getOptional(selectField(params.key, "read"));
|
|
39
|
-
return serializePage({ value: value === void 0 ? { isSet: false } : { isSet: true, value }, ...params });
|
|
40
|
-
}
|
|
41
|
-
}),
|
|
42
|
-
defineTool({
|
|
43
|
-
name: "norn_state_set",
|
|
44
|
-
label: "Write workflow state",
|
|
45
|
-
description: "Set an explicitly writable workflow-state field. Validate the value against its schema from norn_state_list. A get followed by set is not a transaction.",
|
|
46
|
-
parameters: Type.Object({ key: Type.String(), value: Type.Unknown() }),
|
|
47
|
-
async execute(_id, params, signal) {
|
|
48
|
-
signal?.throwIfAborted();
|
|
49
|
-
const field = selectField(params.key, "write");
|
|
50
|
-
await input.state.set(field, params.value);
|
|
51
|
-
return { content: [{ type: "text", text: "Workflow state saved." }], details: {} };
|
|
52
|
-
}
|
|
53
|
-
})
|
|
54
|
-
],
|
|
55
|
-
async dispose() {
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
function serializePage(input) {
|
|
62
|
-
const serialized = JSON.stringify(input.value);
|
|
63
|
-
if (!Number.isInteger(input.offset) || input.offset < 0 || !Number.isInteger(input.limit) || input.limit < 1 || input.limit > 1e4) throw new Error("Invalid state output page");
|
|
64
|
-
const end = Math.min(serialized.length, input.offset + input.limit);
|
|
65
|
-
const details = { text: serialized.slice(input.offset, end), nextOffset: end < serialized.length ? end : null, revision: createHash("sha256").update(serialized).digest("hex") };
|
|
66
|
-
return { content: [{ type: "text", text: JSON.stringify(details) }], details };
|
|
67
|
-
}
|
|
68
|
-
export {
|
|
69
|
-
StateAdapter
|
|
70
|
-
};
|