@vimhead.dev/norn 0.1.0-tip.35240723931.1 → 0.1.0-tip.35343816255.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 +61 -81
- package/dist/api.js +41 -30
- package/dist/files.js +18 -17
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/resources.d.ts +2 -2
- package/dist/schema.d.ts +10 -4
- package/dist/schema.js +49 -18
- package/dist/state-adapter.d.ts +1 -1
- package/dist/state-adapter.js +3 -3
- package/package.json +2 -7
- package/dist/seer/config.d.ts +0 -17
- package/dist/seer/config.js +0 -45
- package/dist/seer/index.d.ts +0 -1
- package/dist/seer/index.js +0 -11
package/dist/api.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { CreateAgentSessionOptions, EventBus, PromptOptions } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import {
|
|
3
|
-
import type {
|
|
2
|
+
import { Type, type Static, type StaticDecode, type StaticEncode, type TCodec, type TSchema } from "typebox";
|
|
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>;
|
|
6
6
|
export type NornDispose = () => void;
|
|
@@ -12,47 +12,27 @@ export type NornWorkflowIsolationMode = "runWorkspace" | "project";
|
|
|
12
12
|
export type NornWorkflowIsolation<Mode extends NornWorkflowIsolationMode = NornWorkflowIsolationMode> = {
|
|
13
13
|
readonly mode: Mode;
|
|
14
14
|
};
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
type NornWorkflowRefForwardParams = Record<string, unknown> & {
|
|
18
|
-
readonly [nornWorkflowRefForwardParamsBrand]: true;
|
|
19
|
-
};
|
|
20
|
-
export type NornWorkflowRef<ParamsSchema extends z.ZodType = z.ZodType, Id extends string = string, ForwardParams = unknown> = Id & {
|
|
21
|
-
readonly [nornWorkflowRefParamsBrand]: (params: z.input<ParamsSchema> & ForwardParams) => z.input<ParamsSchema> & ForwardParams;
|
|
22
|
-
};
|
|
23
|
-
export type NornWorkflowDeclaration<Id extends string = string, ParamsSchema extends z.ZodType = z.ZodType, IsolationMode extends NornWorkflowIsolationMode = NornWorkflowIsolationMode> = {
|
|
15
|
+
export type NornWorkflowDeclaration<Id extends string = string, ParamsSchema extends TSchema = TSchema, IsolationMode extends NornWorkflowIsolationMode = NornWorkflowIsolationMode> = {
|
|
16
|
+
(params: StaticEncode<ParamsSchema>): NornRunNext;
|
|
24
17
|
readonly kind: typeof WORKFLOW_DECLARATION_KIND;
|
|
25
|
-
readonly id:
|
|
18
|
+
readonly id: Id;
|
|
26
19
|
readonly isEntrypoint: boolean;
|
|
27
20
|
readonly instructions?: string;
|
|
28
21
|
readonly params: ParamsSchema;
|
|
29
22
|
readonly gate?: NornWorkflowAnyGate;
|
|
30
23
|
readonly isolation: NornWorkflowIsolation<IsolationMode>;
|
|
31
24
|
};
|
|
32
|
-
export type NornAnyWorkflowDeclaration = NornWorkflowDeclaration
|
|
33
|
-
export type
|
|
34
|
-
export type NornWorkflowRefSchemaInput<ParamsSchema extends z.ZodType = z.ZodType> = string | {
|
|
35
|
-
readonly id: NornWorkflowRef<ParamsSchema>;
|
|
36
|
-
readonly workflow?: never;
|
|
37
|
-
readonly forwardParams?: never;
|
|
38
|
-
};
|
|
39
|
-
export type NornWorkflowRefSchemaOptions<ParamsSchema extends z.ZodType = z.ZodType> = {
|
|
25
|
+
export type NornAnyWorkflowDeclaration = Pick<NornWorkflowDeclaration, keyof NornWorkflowDeclaration> & ((params: never) => NornRunNext);
|
|
26
|
+
export type NornWorkflowRefSchemaOptions<ParamsSchema extends TSchema = TSchema> = {
|
|
40
27
|
readonly params?: ParamsSchema;
|
|
41
28
|
};
|
|
42
|
-
export type NornWorkflowRefInput
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
export type
|
|
47
|
-
readonly workflow: NornWorkflowRef<ParamsSchema, string, NornWorkflowRefForwardParams>;
|
|
48
|
-
readonly forwardParams: NornWorkflowRefForwardParams;
|
|
49
|
-
};
|
|
50
|
-
export type NornWorkflowParamsInput<TWorkflow extends NornAnyWorkflowDeclaration> = z.input<TWorkflow["params"]>;
|
|
51
|
-
export type NornWorkflowParams<TWorkflow extends NornAnyWorkflowDeclaration> = z.output<TWorkflow["params"]>;
|
|
52
|
-
export type NornWorkflowTargetParamsInput<TWorkflow extends NornWorkflowTarget<any>> = TWorkflow extends NornWorkflowDeclaration<string, infer ParamsSchema> ? z.input<ParamsSchema> : TWorkflow extends NornWorkflowRef<infer ParamsSchema, string, infer ForwardParams> ? z.input<ParamsSchema> & ForwardParams : never;
|
|
53
|
-
export type NornWorkflowGate<ParamsSchema extends z.ZodType> = unknown extends z.input<ParamsSchema> ? NornWorkflowAnyGate : z.input<ParamsSchema> extends Record<string, unknown> ? {
|
|
29
|
+
export type NornWorkflowRefInput = StaticEncode<typeof workflowReferenceInputSchema>;
|
|
30
|
+
export type NornWorkflowRefOutput<ParamsSchema extends TSchema> = (params: StaticEncode<ParamsSchema> & object) => NornRunNext;
|
|
31
|
+
export type NornWorkflowParamsInput<TWorkflow extends NornAnyWorkflowDeclaration> = StaticEncode<TWorkflow["params"]>;
|
|
32
|
+
export type NornWorkflowParams<TWorkflow extends NornAnyWorkflowDeclaration> = StaticDecode<TWorkflow["params"]>;
|
|
33
|
+
export type NornWorkflowGate<ParamsSchema extends TSchema> = unknown extends StaticEncode<ParamsSchema> ? NornWorkflowAnyGate : StaticEncode<ParamsSchema> extends Record<string, unknown> ? {
|
|
54
34
|
readonly enabled: true;
|
|
55
|
-
readonly fields?: readonly Extract<keyof
|
|
35
|
+
readonly fields?: readonly Extract<keyof StaticEncode<ParamsSchema>, string>[];
|
|
56
36
|
} : {
|
|
57
37
|
readonly enabled: true;
|
|
58
38
|
readonly fields?: never;
|
|
@@ -64,7 +44,7 @@ type NornWorkflowInstructions = {
|
|
|
64
44
|
readonly isEntrypoint: false;
|
|
65
45
|
readonly instructions?: string;
|
|
66
46
|
};
|
|
67
|
-
export type NornWorkflowDefinition<Id extends string | undefined = string | undefined, ParamsSchema extends
|
|
47
|
+
export type NornWorkflowDefinition<Id extends string | undefined = string | undefined, ParamsSchema extends TSchema = TSchema, IsolationMode extends NornWorkflowIsolationMode = NornWorkflowIsolationMode> = {
|
|
68
48
|
readonly id?: Id;
|
|
69
49
|
readonly params: ParamsSchema;
|
|
70
50
|
readonly gate?: NornWorkflowGate<ParamsSchema>;
|
|
@@ -72,44 +52,49 @@ export type NornWorkflowDefinition<Id extends string | undefined = string | unde
|
|
|
72
52
|
} & NornWorkflowInstructions;
|
|
73
53
|
export type NornAnyWorkflowDefinition = {
|
|
74
54
|
readonly id?: string;
|
|
75
|
-
readonly params:
|
|
55
|
+
readonly params: TSchema;
|
|
76
56
|
readonly gate?: NornWorkflowAnyGate;
|
|
77
57
|
readonly isolation?: NornWorkflowIsolation;
|
|
78
58
|
} & NornWorkflowInstructions;
|
|
79
|
-
export type NornWorkflowStateDefinition<
|
|
59
|
+
export type NornWorkflowStateDefinition<Schema extends TSchema = TSchema, Id extends string = string> = {
|
|
80
60
|
readonly id: Id;
|
|
81
61
|
readonly description?: string;
|
|
82
|
-
readonly schema:
|
|
62
|
+
readonly schema: Schema;
|
|
83
63
|
};
|
|
84
|
-
export type NornWorkflowStateDefinitionInput<
|
|
64
|
+
export type NornWorkflowStateDefinitionInput<Schema extends TSchema = TSchema, Id extends string | undefined = string | undefined> = {
|
|
85
65
|
readonly id?: Id;
|
|
86
66
|
readonly description?: string;
|
|
87
|
-
readonly schema:
|
|
67
|
+
readonly schema: Schema;
|
|
88
68
|
};
|
|
89
69
|
export type NornWorkflowPluginWorkflows = Record<string, NornAnyWorkflowDefinition>;
|
|
90
70
|
export type NornWorkflowPluginStateTree = {
|
|
91
71
|
readonly [key: string]: NornWorkflowPluginStateTreeNode;
|
|
92
72
|
};
|
|
93
|
-
|
|
73
|
+
type NornStateSchema = TSchema & ({
|
|
74
|
+
readonly "~kind": string;
|
|
75
|
+
} | {
|
|
76
|
+
readonly "~unsafe": unknown;
|
|
77
|
+
});
|
|
78
|
+
export type NornWorkflowPluginStateTreeNode = NornStateSchema | NornWorkflowStateDefinitionInput | NornWorkflowPluginStateTree;
|
|
94
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;
|
|
95
80
|
type NornInvalidGateFields<TWorkflow> = TWorkflow extends {
|
|
96
|
-
readonly params: infer ParamsSchema extends
|
|
81
|
+
readonly params: infer ParamsSchema extends TSchema;
|
|
97
82
|
readonly gate: {
|
|
98
83
|
readonly fields: infer Fields extends readonly string[];
|
|
99
84
|
};
|
|
100
|
-
} ? Exclude<Fields[number], Extract<keyof
|
|
85
|
+
} ? Exclude<Fields[number], Extract<keyof StaticEncode<ParamsSchema>, string>> : never;
|
|
101
86
|
type NornValidatedWorkflowGate<TWorkflow> = [NornInvalidGateFields<TWorkflow>] extends [never] ? unknown : {
|
|
102
87
|
readonly gate: {
|
|
103
|
-
readonly fields: readonly Extract<keyof
|
|
104
|
-
readonly params: infer ParamsSchema extends
|
|
105
|
-
} ? ParamsSchema :
|
|
88
|
+
readonly fields: readonly Extract<keyof StaticEncode<TWorkflow extends {
|
|
89
|
+
readonly params: infer ParamsSchema extends TSchema;
|
|
90
|
+
} ? ParamsSchema : TSchema>, string>[];
|
|
106
91
|
};
|
|
107
92
|
};
|
|
108
93
|
export type NornValidatedWorkflowGates<Workflows> = {
|
|
109
94
|
readonly [Key in keyof Workflows]: NornValidatedWorkflowGate<Workflows[Key]>;
|
|
110
95
|
};
|
|
111
96
|
export type NornQualifiedPluginWorkflow<PluginId extends string, WorkflowKey extends string, TWorkflow extends NornAnyWorkflowDefinition> = TWorkflow extends {
|
|
112
|
-
readonly params: infer ParamsSchema extends
|
|
97
|
+
readonly params: infer ParamsSchema extends TSchema;
|
|
113
98
|
} ? NornWorkflowDeclaration<TWorkflow extends {
|
|
114
99
|
readonly id: infer ExplicitId extends string;
|
|
115
100
|
} ? ExplicitId : `${PluginId}.${WorkflowKey}`, ParamsSchema, TWorkflow extends {
|
|
@@ -121,28 +106,28 @@ export type NornQualifiedPluginWorkflows<PluginId extends string, Workflows exte
|
|
|
121
106
|
readonly [Key in keyof Workflows]: NornQualifiedPluginWorkflow<PluginId, Key & string, Workflows[Key]>;
|
|
122
107
|
};
|
|
123
108
|
export type NornQualifiedPluginStates<PluginId extends string, States, Path extends readonly string[] = []> = {
|
|
124
|
-
readonly [Key in keyof States]: States[Key] extends
|
|
125
|
-
readonly id: infer
|
|
126
|
-
} ?
|
|
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;
|
|
127
112
|
};
|
|
128
|
-
export type NornWorkflowPluginManifest<PluginId extends string = string, ConfigSchema extends
|
|
113
|
+
export type NornWorkflowPluginManifest<PluginId extends string = string, ConfigSchema extends TSchema | undefined = TSchema | undefined, Workflows extends Record<string, NornAnyWorkflowDeclaration> = Record<string, NornAnyWorkflowDeclaration>, States = undefined> = {
|
|
129
114
|
readonly id: PluginId;
|
|
130
115
|
readonly config?: ConfigSchema;
|
|
131
116
|
readonly workflows: Workflows;
|
|
132
117
|
readonly states: States;
|
|
133
118
|
};
|
|
134
|
-
export type NornAnyWorkflowPluginManifest = NornWorkflowPluginManifest<string,
|
|
119
|
+
export type NornAnyWorkflowPluginManifest = NornWorkflowPluginManifest<string, TSchema | undefined, Record<string, NornAnyWorkflowDeclaration>, unknown>;
|
|
135
120
|
export type NornWorkflowPluginConfigSchema<TManifest extends NornAnyWorkflowPluginManifest> = TManifest extends {
|
|
136
|
-
readonly config?: infer ConfigSchema extends
|
|
121
|
+
readonly config?: infer ConfigSchema extends TSchema | undefined;
|
|
137
122
|
} ? ConfigSchema : undefined;
|
|
138
|
-
export type NornWorkflowPluginConfig<TManifest extends NornAnyWorkflowPluginManifest> =
|
|
139
|
-
export type NornDefinePluginManifestInput<PluginId extends string, ConfigSchema extends
|
|
123
|
+
export type NornWorkflowPluginConfig<TManifest extends NornAnyWorkflowPluginManifest> = NornWorkflowPluginConfigSchema<TManifest> extends undefined ? undefined : StaticDecode<NonNullable<NornWorkflowPluginConfigSchema<TManifest>>>;
|
|
124
|
+
export type NornDefinePluginManifestInput<PluginId extends string, ConfigSchema extends TSchema | undefined, Workflows extends NornWorkflowPluginWorkflows, States extends NornWorkflowPluginStateTree | undefined> = {
|
|
140
125
|
readonly id: PluginId;
|
|
141
126
|
readonly config?: ConfigSchema;
|
|
142
127
|
readonly workflows: Workflows & NornValidatedWorkflowGates<Workflows>;
|
|
143
128
|
readonly states?: States;
|
|
144
129
|
};
|
|
145
|
-
export declare function definePluginManifest<const PluginId extends string, const ConfigSchema extends
|
|
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>;
|
|
146
131
|
export type NornRunNext = {
|
|
147
132
|
readonly type: "next";
|
|
148
133
|
readonly workflowId: string;
|
|
@@ -277,11 +262,11 @@ export type NornRunCheckpoint = {
|
|
|
277
262
|
readonly createdAt: string;
|
|
278
263
|
};
|
|
279
264
|
export type NornWorkflowStateReader = {
|
|
280
|
-
get<
|
|
281
|
-
getOptional<
|
|
265
|
+
get<Schema extends TSchema>(state: NornWorkflowStateDefinition<Schema>): Promise<Static<Schema>>;
|
|
266
|
+
getOptional<Schema extends TSchema>(state: NornWorkflowStateDefinition<Schema>): Promise<Static<Schema> | undefined>;
|
|
282
267
|
};
|
|
283
268
|
export type NornWorkflowState = NornWorkflowStateReader & {
|
|
284
|
-
set<
|
|
269
|
+
set<Schema extends TSchema>(state: NornWorkflowStateDefinition<Schema>, value: NoInfer<Static<Schema>>): Promise<void>;
|
|
285
270
|
};
|
|
286
271
|
export type NornWorkflowPluginContext = {
|
|
287
272
|
readonly cwd: string;
|
|
@@ -306,16 +291,16 @@ export type NornCommandRunInput = {
|
|
|
306
291
|
readonly env?: Record<string, string>;
|
|
307
292
|
readonly timeoutMs?: number;
|
|
308
293
|
};
|
|
309
|
-
export declare const artifactRefSchema:
|
|
310
|
-
path:
|
|
311
|
-
}
|
|
312
|
-
export type NornArtifactRef =
|
|
313
|
-
declare const emptyWorkflowRefParamsSchema:
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
}
|
|
318
|
-
export declare function workflowRefSchema<ParamsSchema extends
|
|
294
|
+
export declare const artifactRefSchema: Type.TObject<{
|
|
295
|
+
path: Type.TString;
|
|
296
|
+
}>;
|
|
297
|
+
export type NornArtifactRef = StaticDecode<typeof artifactRefSchema>;
|
|
298
|
+
declare const emptyWorkflowRefParamsSchema: Type.TObject<{}>;
|
|
299
|
+
declare const workflowReferenceInputSchema: Type.TUnion<[Type.TString, Type.TObject<{
|
|
300
|
+
workflow: Type.TString;
|
|
301
|
+
forwardParams: Type.TRecord<"^.*$", Type.TUnknown>;
|
|
302
|
+
}>]>;
|
|
303
|
+
export declare function workflowRefSchema<ParamsSchema extends TSchema = typeof emptyWorkflowRefParamsSchema>(options?: NornWorkflowRefSchemaOptions<ParamsSchema>): TCodec<typeof workflowReferenceInputSchema, NornWorkflowRefOutput<ParamsSchema>>;
|
|
319
304
|
export type NornLogRef = {
|
|
320
305
|
readonly id: string;
|
|
321
306
|
};
|
|
@@ -344,13 +329,13 @@ export type NornAgentCreateSessionInput = {
|
|
|
344
329
|
readonly systemPrompt?: string;
|
|
345
330
|
readonly appendSystemPrompt?: readonly string[];
|
|
346
331
|
};
|
|
347
|
-
export type NornAgentPromptInput<ResponseSchema extends
|
|
332
|
+
export type NornAgentPromptInput<ResponseSchema extends TSchema> = {
|
|
348
333
|
readonly prompt: string;
|
|
349
334
|
readonly response: ResponseSchema;
|
|
350
335
|
readonly maxAttempts?: number;
|
|
351
336
|
readonly options?: PromptOptions;
|
|
352
337
|
};
|
|
353
|
-
export type NornAgentSinglePromptInput<ResponseSchema extends
|
|
338
|
+
export type NornAgentSinglePromptInput<ResponseSchema extends TSchema> = NornAgentCreateSessionInput & NornAgentPromptInput<ResponseSchema>;
|
|
354
339
|
export type NornAgentSessionEvents = EventBus;
|
|
355
340
|
export type NornAgentUsageCost = {
|
|
356
341
|
readonly input: number;
|
|
@@ -426,10 +411,10 @@ export type NornAgentRunRawAttempt = {
|
|
|
426
411
|
readonly sessionFile?: string;
|
|
427
412
|
readonly error?: string;
|
|
428
413
|
};
|
|
429
|
-
export type NornAgentRunResult<ResponseSchema extends
|
|
414
|
+
export type NornAgentRunResult<ResponseSchema extends TSchema> = {
|
|
430
415
|
readonly label: string;
|
|
431
416
|
readonly cwd: string;
|
|
432
|
-
readonly response:
|
|
417
|
+
readonly response: StaticDecode<ResponseSchema>;
|
|
433
418
|
readonly usage: NornAgentUsage;
|
|
434
419
|
readonly raw: {
|
|
435
420
|
readonly text: string;
|
|
@@ -445,7 +430,7 @@ export type NornAgentSession = {
|
|
|
445
430
|
readonly label: string;
|
|
446
431
|
readonly cwd: string;
|
|
447
432
|
readonly events: NornAgentSessionEvents;
|
|
448
|
-
prompt<ResponseSchema extends
|
|
433
|
+
prompt<ResponseSchema extends TSchema>(input: NornAgentPromptInput<ResponseSchema>): Promise<StaticDecode<ResponseSchema>>;
|
|
449
434
|
dispose(): Promise<void>;
|
|
450
435
|
};
|
|
451
436
|
export type NornRun = NornRunBase;
|
|
@@ -458,7 +443,7 @@ type NornRunBase = {
|
|
|
458
443
|
workspace: string;
|
|
459
444
|
cwd: string;
|
|
460
445
|
path(relativePath: string): string;
|
|
461
|
-
next
|
|
446
|
+
next(workflowId: string, params: unknown): NornRunNext;
|
|
462
447
|
complete(metadata?: NornRunOutcomeMetadata): NornRunComplete;
|
|
463
448
|
fail(metadata: NornRunOutcomeMetadata & {
|
|
464
449
|
readonly summary: string;
|
|
@@ -477,7 +462,7 @@ type NornRunBase = {
|
|
|
477
462
|
};
|
|
478
463
|
agents: {
|
|
479
464
|
createSession(input: NornAgentCreateSessionInput): Promise<NornAgentSession>;
|
|
480
|
-
prompt<ResponseSchema extends
|
|
465
|
+
prompt<ResponseSchema extends TSchema>(input: NornAgentSinglePromptInput<ResponseSchema>): Promise<StaticDecode<ResponseSchema>>;
|
|
481
466
|
};
|
|
482
467
|
};
|
|
483
468
|
export type NornWorkflowPluginInfo = {
|
|
@@ -508,11 +493,7 @@ export type NornPluginDiagnostic = {
|
|
|
508
493
|
readonly workflowId: string | null;
|
|
509
494
|
readonly stage: "import" | "declaration" | "config" | "implementation" | "duplicate" | "schema";
|
|
510
495
|
readonly message: string;
|
|
511
|
-
readonly issues: readonly
|
|
512
|
-
readonly path: readonly (string | number)[];
|
|
513
|
-
readonly code: string;
|
|
514
|
-
readonly message: string;
|
|
515
|
-
}[];
|
|
496
|
+
readonly issues: readonly TLocalizedValidationError[];
|
|
516
497
|
};
|
|
517
498
|
export type NornProjectLoadStatus = {
|
|
518
499
|
readonly isComplete: boolean;
|
|
@@ -539,7 +520,6 @@ export type NornProjectInfo = {
|
|
|
539
520
|
readonly configRoot: string;
|
|
540
521
|
readonly configFiles: readonly string[];
|
|
541
522
|
readonly plugins: readonly NornProjectPluginInfo[];
|
|
542
|
-
readonly seerMode: NornResolvedSeerModeConfig | null;
|
|
543
523
|
};
|
|
544
524
|
export declare function isWorkflowDeclaration(value: unknown): value is NornAnyWorkflowDeclaration;
|
|
545
525
|
export declare function isWorkflowPlugin(value: unknown): value is NornWorkflowPlugin;
|
package/dist/api.js
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
// src/api.ts
|
|
2
|
-
import {
|
|
2
|
+
import { Type } from "typebox";
|
|
3
|
+
|
|
4
|
+
// ../core/src/workflow-transition.ts
|
|
5
|
+
function createWorkflowTransition(input) {
|
|
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, params: input.params };
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// src/api.ts
|
|
11
|
+
import { Value } from "typebox/value";
|
|
12
|
+
import { isPlainObject, jsonValueSchema } from "./schema.js";
|
|
3
13
|
var WORKFLOW_DECLARATION_KIND = "norn.workflow";
|
|
4
14
|
function definePluginManifest(input) {
|
|
5
15
|
assertLocalDeclarationId(input.id, "plugin");
|
|
@@ -17,26 +27,26 @@ function definePluginManifest(input) {
|
|
|
17
27
|
function definePlugin(manifest, implementation) {
|
|
18
28
|
return { manifest, implementation };
|
|
19
29
|
}
|
|
20
|
-
var artifactRefSchema =
|
|
21
|
-
path:
|
|
30
|
+
var artifactRefSchema = Type.Object({
|
|
31
|
+
path: Type.String()
|
|
22
32
|
});
|
|
23
|
-
var emptyWorkflowRefParamsSchema =
|
|
33
|
+
var emptyWorkflowRefParamsSchema = Type.Object({});
|
|
34
|
+
var workflowReferenceInputSchema = Type.Union([
|
|
35
|
+
Type.String({ minLength: 1 }),
|
|
36
|
+
Type.Object({ workflow: Type.String({ minLength: 1 }), forwardParams: Type.Record(Type.String(), Type.Unknown()) })
|
|
37
|
+
]);
|
|
24
38
|
function workflowRefSchema(options) {
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return z.toJSONSchema(contributedParams, { io: "input" });
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
});
|
|
39
|
+
const contributionSchema = options?.params ?? emptyWorkflowRefParamsSchema;
|
|
40
|
+
return Type.With(Type.Decode(workflowReferenceInputSchema, (reference) => {
|
|
41
|
+
const workflowId = typeof reference === "string" ? reference : reference.workflow;
|
|
42
|
+
const forwardParams = typeof reference === "string" ? {} : reference.forwardParams;
|
|
43
|
+
return (params) => {
|
|
44
|
+
Value.Assert(contributionSchema, params);
|
|
45
|
+
if (!isPlainObject(params)) throw new Error("Workflow reference contributions must be objects");
|
|
46
|
+
Value.Assert(jsonValueSchema, params);
|
|
47
|
+
return createWorkflowTransition({ workflowId, params: { ...forwardParams, ...params } });
|
|
48
|
+
};
|
|
49
|
+
}), { "x-norn-workflow-ref": { contributedParamsSchema: contributionSchema } });
|
|
40
50
|
}
|
|
41
51
|
function assertLocalDeclarationId(id, kind) {
|
|
42
52
|
if (id.length === 0) throw new Error(`Workflow ${kind} id must not be empty`);
|
|
@@ -56,28 +66,29 @@ function assertPluginQualifiedId(pluginId, id, kind) {
|
|
|
56
66
|
}
|
|
57
67
|
function qualifyWorkflow(pluginId, key, workflow, declaredIds) {
|
|
58
68
|
const id = resolveDeclarationId(pluginId, [key], workflow.id, "workflow", declaredIds);
|
|
59
|
-
|
|
69
|
+
const declaration = (params) => createWorkflowTransition({ workflowId: id, params });
|
|
70
|
+
return Object.assign(declaration, { ...workflow, kind: WORKFLOW_DECLARATION_KIND, id, isolation: workflow.isolation ?? { mode: "runWorkspace" } });
|
|
60
71
|
}
|
|
61
72
|
function qualifyStateTree(pluginId, node, path, declaredIds) {
|
|
62
|
-
if (
|
|
63
|
-
if (
|
|
64
|
-
if (isWorkflowStateDefinitionInput(node)) {
|
|
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)) {
|
|
65
76
|
return { ...node, id: resolveDeclarationId(pluginId, path, node.id, "state", declaredIds) };
|
|
66
77
|
}
|
|
78
|
+
if (!isPlainObject(node)) throw new Error(`Invalid state declaration: ${[pluginId, ...path].join(".")}`);
|
|
67
79
|
return Object.fromEntries(Object.entries(node).map(([key, child]) => [key, qualifyStateTree(pluginId, child, [...path, key], declaredIds)]));
|
|
68
80
|
}
|
|
69
81
|
function isWorkflowDeclaration(value) {
|
|
70
|
-
if (
|
|
82
|
+
if (typeof value !== "function") return false;
|
|
71
83
|
const candidate = value;
|
|
72
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.params) && (candidate.isolation?.mode === "runWorkspace" || candidate.isolation?.mode === "project");
|
|
73
85
|
}
|
|
74
|
-
function
|
|
75
|
-
|
|
76
|
-
const candidate = value;
|
|
77
|
-
return (candidate.id === void 0 || typeof candidate.id === "string") && isZodSchema(candidate.schema);
|
|
86
|
+
function isTypeboxSchema(value) {
|
|
87
|
+
return Type.IsUnsafe(value) || Boolean(value && typeof value === "object" && "~kind" in value && typeof value["~kind"] === "string");
|
|
78
88
|
}
|
|
79
|
-
function
|
|
80
|
-
|
|
89
|
+
function isWorkflowStateDefinitionInput(value) {
|
|
90
|
+
if (!isPlainObject(value)) return false;
|
|
91
|
+
return (value.id === void 0 || typeof value.id === "string") && isTypeboxSchema(value.schema);
|
|
81
92
|
}
|
|
82
93
|
function isWorkflowPlugin(value) {
|
|
83
94
|
if (!value || typeof value !== "object") return false;
|
package/dist/files.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
// src/files.ts
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { basename, dirname as dirname2, join, resolve } from "node:path";
|
|
6
|
-
import { setTimeout as delay } from "node:timers/promises";
|
|
7
|
-
import { z } from "zod";
|
|
1
|
+
// ../core/src/atomic-files.ts
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
import { chmod, mkdir, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
4
|
+
import { dirname } from "node:path";
|
|
8
5
|
|
|
9
6
|
// ../core/src/errors.ts
|
|
10
7
|
function isNodeError(error) {
|
|
@@ -12,9 +9,6 @@ function isNodeError(error) {
|
|
|
12
9
|
}
|
|
13
10
|
|
|
14
11
|
// ../core/src/atomic-files.ts
|
|
15
|
-
import { randomUUID } from "node:crypto";
|
|
16
|
-
import { chmod, mkdir, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
17
|
-
import { dirname } from "node:path";
|
|
18
12
|
async function writeTextAtomically(path, content) {
|
|
19
13
|
await mkdir(dirname(path), { recursive: true });
|
|
20
14
|
let existingMode;
|
|
@@ -35,12 +29,19 @@ async function writeTextAtomically(path, content) {
|
|
|
35
29
|
}
|
|
36
30
|
|
|
37
31
|
// src/files.ts
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
32
|
+
import { createHash, randomUUID as randomUUID2 } from "node:crypto";
|
|
33
|
+
import { lstat, mkdir as mkdir2, mkdtemp, readFile, readdir, realpath, rename as rename2, rm as rm2, rmdir, unlink, writeFile as writeFile2 } from "node:fs/promises";
|
|
34
|
+
import { hostname } from "node:os";
|
|
35
|
+
import { basename, dirname as dirname2, join, resolve } from "node:path";
|
|
36
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
37
|
+
import { Type } from "typebox";
|
|
38
|
+
import { Value } from "typebox/value";
|
|
39
|
+
var ownerSchema = Type.Object({
|
|
40
|
+
token: Type.String({ format: "uuid" }),
|
|
41
|
+
pid: Type.Integer({ exclusiveMinimum: 0 }),
|
|
42
|
+
host: Type.String(),
|
|
43
|
+
target: Type.String()
|
|
44
|
+
}, { additionalProperties: false });
|
|
44
45
|
var NornFileCoordinator = class {
|
|
45
46
|
constructor(input) {
|
|
46
47
|
this.input = input;
|
|
@@ -127,7 +128,7 @@ var NornFileCoordinator = class {
|
|
|
127
128
|
if (entries.length === 0) return;
|
|
128
129
|
if (entries.length !== 1) throw new Error(`Invalid file lock ownership: ${input.lockPath}`);
|
|
129
130
|
const marker = entries[0];
|
|
130
|
-
const owner =
|
|
131
|
+
const owner = Value.Parse(ownerSchema, JSON.parse(await readFile(join(input.lockPath, marker), "utf8")));
|
|
131
132
|
if (marker !== `${owner.token}.json` || owner.target !== input.target || owner.host !== hostname()) {
|
|
132
133
|
throw new Error(`Incompatible file lock ownership: ${input.lockPath}`);
|
|
133
134
|
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/resources.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { z } from "zod";
|
|
2
1
|
import type { NornFileCoordinator } from "./files.ts";
|
|
2
|
+
import type { NornJsonValue } from "./schema.ts";
|
|
3
3
|
export type NornResourceContext = {
|
|
4
4
|
readonly mode: "create" | "open";
|
|
5
5
|
readonly directory: string;
|
|
@@ -8,7 +8,7 @@ export type NornResourceContext = {
|
|
|
8
8
|
export type NornResourceDefinition<T> = {
|
|
9
9
|
readonly name: string;
|
|
10
10
|
readonly kind: string;
|
|
11
|
-
readonly configuration:
|
|
11
|
+
readonly configuration: NornJsonValue;
|
|
12
12
|
initialize(context: NornResourceContext): Promise<T>;
|
|
13
13
|
};
|
|
14
14
|
export type NornResources = {
|
package/dist/schema.d.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { Type, type Static, type TSchema } from "typebox";
|
|
2
|
+
import type { NornAnyWorkflowDeclaration, NornJsonSchema } from "./api.ts";
|
|
3
|
+
export declare const jsonValueSchema: Type.TCyclic<{
|
|
4
|
+
Json: Type.TUnion<[Type.TNull, Type.TBoolean, Type.TNumber, Type.TString, Type.TArray<Type.TRef<"Json">>, Type.TRefine<Type.TRecord<"^.*$", Type.TRef<"Json">>>]>;
|
|
5
|
+
}, "Json">;
|
|
6
|
+
export type NornJsonValue = Static<typeof jsonValueSchema>;
|
|
7
|
+
export declare function inspectSchema(schema: TSchema): NornJsonSchema;
|
|
2
8
|
export declare function assertWorkflowMetadata(workflow: NornAnyWorkflowDeclaration): void;
|
|
3
|
-
export declare function unwrapSchema(schema:
|
|
4
|
-
export declare function schemaShape(schema:
|
|
5
|
-
export declare function schemaType(schema:
|
|
9
|
+
export declare function unwrapSchema(schema: TSchema): TSchema;
|
|
10
|
+
export declare function schemaShape(schema: TSchema): Record<string, TSchema>;
|
|
11
|
+
export declare function schemaType(schema: TSchema): string | undefined;
|
|
6
12
|
export declare function isPlainObject(value: unknown): value is Record<string, unknown>;
|
package/dist/schema.js
CHANGED
|
@@ -1,4 +1,44 @@
|
|
|
1
1
|
// src/schema.ts
|
|
2
|
+
import { Type } from "typebox";
|
|
3
|
+
import { Meta } from "typebox/schema";
|
|
4
|
+
import { Value } from "typebox/value";
|
|
5
|
+
var jsonValueSchema = Type.Cyclic({
|
|
6
|
+
Json: Type.Union([
|
|
7
|
+
Type.Null(),
|
|
8
|
+
Type.Boolean(),
|
|
9
|
+
Type.Number(),
|
|
10
|
+
Type.String(),
|
|
11
|
+
Type.Array(Type.Ref("Json")),
|
|
12
|
+
Type.Refine(Type.Record(Type.String(), Type.Ref("Json")), (value) => Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null)
|
|
13
|
+
])
|
|
14
|
+
}, "Json");
|
|
15
|
+
function inspectSchema(schema) {
|
|
16
|
+
const inspected = JSON.parse(JSON.stringify(schema));
|
|
17
|
+
Value.Assert(Meta["https://json-schema.org/draft/2020-12/schema"], inspected);
|
|
18
|
+
if (!isPlainObject(inspected)) throw new Error("Norn inspection requires an object schema");
|
|
19
|
+
assertWorkflowReferenceAnnotations(inspected);
|
|
20
|
+
return inspected;
|
|
21
|
+
}
|
|
22
|
+
function assertWorkflowReferenceAnnotations(schema) {
|
|
23
|
+
if (!isPlainObject(schema)) return;
|
|
24
|
+
if (Object.hasOwn(schema, "x-norn-workflow-ref")) {
|
|
25
|
+
const annotation = schema["x-norn-workflow-ref"];
|
|
26
|
+
if (!isPlainObject(annotation) || !Object.hasOwn(annotation, "contributedParamsSchema")) throw new Error("Invalid workflow reference annotation");
|
|
27
|
+
Value.Assert(Meta["https://json-schema.org/draft/2020-12/schema"], annotation.contributedParamsSchema);
|
|
28
|
+
assertWorkflowReferenceAnnotations(annotation.contributedParamsSchema);
|
|
29
|
+
}
|
|
30
|
+
for (const keyword of ["properties", "patternProperties", "$defs", "definitions", "dependentSchemas"]) {
|
|
31
|
+
const schemas = schema[keyword];
|
|
32
|
+
if (isPlainObject(schemas)) for (const child of Object.values(schemas)) assertWorkflowReferenceAnnotations(child);
|
|
33
|
+
}
|
|
34
|
+
for (const keyword of ["allOf", "anyOf", "oneOf", "prefixItems"]) {
|
|
35
|
+
const schemas = schema[keyword];
|
|
36
|
+
if (Array.isArray(schemas)) for (const child of schemas) assertWorkflowReferenceAnnotations(child);
|
|
37
|
+
}
|
|
38
|
+
for (const keyword of ["additionalProperties", "unevaluatedProperties", "propertyNames", "items", "contains", "not", "if", "then", "else", "unevaluatedItems", "contentSchema"]) {
|
|
39
|
+
assertWorkflowReferenceAnnotations(schema[keyword]);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
2
42
|
function assertWorkflowMetadata(workflow) {
|
|
3
43
|
if (workflow.instructions !== void 0 && (typeof workflow.instructions !== "string" || workflow.instructions.trim().length === 0)) {
|
|
4
44
|
throw new Error(`Workflow instructions must be a nonempty string: ${workflow.id}`);
|
|
@@ -8,35 +48,26 @@ function assertWorkflowMetadata(workflow) {
|
|
|
8
48
|
}
|
|
9
49
|
}
|
|
10
50
|
function unwrapSchema(schema) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if (["optional", "nullable", "default", "catch", "readonly", "prefault"].includes(def.type ?? "") && def.innerType) {
|
|
15
|
-
current = def.innerType;
|
|
16
|
-
continue;
|
|
17
|
-
}
|
|
18
|
-
return current;
|
|
19
|
-
}
|
|
51
|
+
if (!Type.IsUnion(schema)) return schema;
|
|
52
|
+
const members = schema.anyOf.filter((member) => !Type.IsNull(member));
|
|
53
|
+
return members.length === 1 ? unwrapSchema(members[0]) : schema;
|
|
20
54
|
}
|
|
21
55
|
function schemaShape(schema) {
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
return typeof shape === "function" ? shape() : shape;
|
|
56
|
+
const unwrapped = unwrapSchema(schema);
|
|
57
|
+
return Type.IsObject(unwrapped) ? unwrapped.properties : {};
|
|
25
58
|
}
|
|
26
59
|
function schemaType(schema) {
|
|
27
|
-
|
|
60
|
+
const unwrapped = unwrapSchema(schema);
|
|
61
|
+
return "type" in unwrapped && typeof unwrapped.type === "string" ? unwrapped.type : void 0;
|
|
28
62
|
}
|
|
29
63
|
function isPlainObject(value) {
|
|
30
64
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
31
65
|
}
|
|
32
|
-
function schemaDef(schema) {
|
|
33
|
-
if (!schema || typeof schema !== "object") return {};
|
|
34
|
-
const candidate = schema;
|
|
35
|
-
return candidate._def ?? candidate.def ?? {};
|
|
36
|
-
}
|
|
37
66
|
export {
|
|
38
67
|
assertWorkflowMetadata,
|
|
68
|
+
inspectSchema,
|
|
39
69
|
isPlainObject,
|
|
70
|
+
jsonValueSchema,
|
|
40
71
|
schemaShape,
|
|
41
72
|
schemaType,
|
|
42
73
|
unwrapSchema
|
package/dist/state-adapter.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { NornWorkflowState, NornWorkflowStateDefinition } from "./api.ts";
|
|
2
1
|
import type { NornAgentResourceAdapter } from "./agent-resource-adapter.ts";
|
|
2
|
+
import type { NornWorkflowState, NornWorkflowStateDefinition } from "./api.ts";
|
|
3
3
|
export type NornStateFieldAccess = {
|
|
4
4
|
readonly field: NornWorkflowStateDefinition;
|
|
5
5
|
readonly access: "read" | "write" | "read-write";
|
package/dist/state-adapter.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// src/state-adapter.ts
|
|
2
|
-
import { createHash } from "node:crypto";
|
|
3
2
|
import { defineTool } from "@earendil-works/pi-coding-agent";
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
4
|
import { Type } from "typebox";
|
|
5
|
-
import {
|
|
5
|
+
import { inspectSchema } from "./schema.js";
|
|
6
6
|
var pageParameters = {
|
|
7
7
|
offset: Type.Integer({ minimum: 0, description: "Zero-based UTF-16 offset into the serialized JSON. Start at 0." }),
|
|
8
8
|
limit: Type.Integer({ minimum: 1, maximum: 1e4 })
|
|
@@ -26,7 +26,7 @@ function StateAdapter(input) {
|
|
|
26
26
|
description: "List only attached workflow-state field IDs, permissions and value schemas. JSON is paginated; use nextOffset until null.",
|
|
27
27
|
parameters: Type.Object(pageParameters),
|
|
28
28
|
async execute(_id, params) {
|
|
29
|
-
return serializePage({ value: [...fields.values()].map(({ field, access }) => ({ id: field.id, access, schema:
|
|
29
|
+
return serializePage({ value: [...fields.values()].map(({ field, access }) => ({ id: field.id, access, schema: inspectSchema(field.schema) })), ...params });
|
|
30
30
|
}
|
|
31
31
|
}),
|
|
32
32
|
defineTool({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vimhead.dev/norn",
|
|
3
|
-
"version": "0.1.0-tip.
|
|
3
|
+
"version": "0.1.0-tip.35343816255.1",
|
|
4
4
|
"description": "TypeScript SDK for building agent-driven and code-driven Norn workflows.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -33,10 +33,6 @@
|
|
|
33
33
|
"./schema": {
|
|
34
34
|
"types": "./dist/schema.d.ts",
|
|
35
35
|
"import": "./dist/schema.js"
|
|
36
|
-
},
|
|
37
|
-
"./seer": {
|
|
38
|
-
"types": "./dist/seer/index.d.ts",
|
|
39
|
-
"import": "./dist/seer/index.js"
|
|
40
36
|
}
|
|
41
37
|
},
|
|
42
38
|
"devDependencies": {
|
|
@@ -44,8 +40,7 @@
|
|
|
44
40
|
},
|
|
45
41
|
"dependencies": {
|
|
46
42
|
"@earendil-works/pi-coding-agent": "0.85.1",
|
|
47
|
-
"typebox": "^1.3.
|
|
48
|
-
"zod": "^4.4.3"
|
|
43
|
+
"typebox": "^1.3.33"
|
|
49
44
|
},
|
|
50
45
|
"scripts": {
|
|
51
46
|
"build": "node ../../scripts/build-package.ts"
|
package/dist/seer/config.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export type NornSeerModeConfig = {
|
|
2
|
-
readonly writableRoots: readonly string[];
|
|
3
|
-
};
|
|
4
|
-
export type NornResolvedSeerModeConfig = {
|
|
5
|
-
readonly configPath: string;
|
|
6
|
-
readonly projectRoot: string;
|
|
7
|
-
readonly writableRoots: readonly string[];
|
|
8
|
-
};
|
|
9
|
-
type ResolveSeerModeConfigInput = {
|
|
10
|
-
readonly configPath: string;
|
|
11
|
-
readonly configRoot: string;
|
|
12
|
-
readonly seerMode: NornSeerModeConfig | undefined;
|
|
13
|
-
};
|
|
14
|
-
export declare function resolveSeerModeConfig(input: ResolveSeerModeConfigInput): NornResolvedSeerModeConfig | undefined;
|
|
15
|
-
export declare function assertSeerModeWritablePath(seerMode: NornResolvedSeerModeConfig, cwd: string, path: string): string;
|
|
16
|
-
export declare function isSeerModeWritablePath(seerMode: NornResolvedSeerModeConfig, cwd: string, path: string): boolean;
|
|
17
|
-
export {};
|
package/dist/seer/config.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
// src/seer/config.ts
|
|
2
|
-
import { isAbsolute, relative, resolve, sep } from "node:path";
|
|
3
|
-
function resolveSeerModeConfig(input) {
|
|
4
|
-
if (!input.seerMode) return void 0;
|
|
5
|
-
if (input.seerMode.writableRoots.length === 0) throw new Error("Norn seerMode.writableRoots must not be empty");
|
|
6
|
-
const projectRoot = resolve(input.configRoot);
|
|
7
|
-
const writableRoots = Array.from(new Set(input.seerMode.writableRoots.map((path) => resolveWritableRoot(projectRoot, path))));
|
|
8
|
-
return { configPath: input.configPath, projectRoot, writableRoots };
|
|
9
|
-
}
|
|
10
|
-
function assertSeerModeWritablePath(seerMode, cwd, path) {
|
|
11
|
-
const resolvedPath = resolveSeerModePath(seerMode, cwd, path);
|
|
12
|
-
if (!isSeerModeWritableResolvedPath(seerMode, resolvedPath)) {
|
|
13
|
-
throw new Error(`Path is outside Norn seerMode writable roots: ${path}`);
|
|
14
|
-
}
|
|
15
|
-
return resolvedPath;
|
|
16
|
-
}
|
|
17
|
-
function isSeerModeWritablePath(seerMode, cwd, path) {
|
|
18
|
-
return isSeerModeWritableResolvedPath(seerMode, resolveSeerModePath(seerMode, cwd, path));
|
|
19
|
-
}
|
|
20
|
-
function resolveWritableRoot(projectRoot, path) {
|
|
21
|
-
if (path.length === 0) throw new Error("Norn seerMode writable root must not be empty");
|
|
22
|
-
const resolvedPath = isAbsolute(path) ? resolve(path) : resolve(projectRoot, path);
|
|
23
|
-
if (!isInsideOrEqual(projectRoot, resolvedPath)) throw new Error(`Norn seerMode writable root escapes project root: ${path}`);
|
|
24
|
-
return resolvedPath;
|
|
25
|
-
}
|
|
26
|
-
function resolveSeerModePath(seerMode, cwd, path) {
|
|
27
|
-
if (path.length === 0) throw new Error("Norn seerMode path must not be empty");
|
|
28
|
-
const resolvedCwd = resolve(cwd);
|
|
29
|
-
if (!isInsideOrEqual(seerMode.projectRoot, resolvedCwd)) throw new Error(`Norn seerMode cwd escapes project root: ${cwd}`);
|
|
30
|
-
const resolvedPath = isAbsolute(path) ? resolve(path) : resolve(resolvedCwd, path);
|
|
31
|
-
if (!isInsideOrEqual(seerMode.projectRoot, resolvedPath)) return resolvedPath;
|
|
32
|
-
return resolvedPath;
|
|
33
|
-
}
|
|
34
|
-
function isSeerModeWritableResolvedPath(seerMode, path) {
|
|
35
|
-
return seerMode.writableRoots.some((root) => isInsideOrEqual(root, path));
|
|
36
|
-
}
|
|
37
|
-
function isInsideOrEqual(root, path) {
|
|
38
|
-
const pathFromRoot = relative(root, path);
|
|
39
|
-
return pathFromRoot === "" || !pathFromRoot.startsWith(`..${sep}`) && pathFromRoot !== ".." && !isAbsolute(pathFromRoot);
|
|
40
|
-
}
|
|
41
|
-
export {
|
|
42
|
-
assertSeerModeWritablePath,
|
|
43
|
-
isSeerModeWritablePath,
|
|
44
|
-
resolveSeerModeConfig
|
|
45
|
-
};
|
package/dist/seer/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { assertSeerModeWritablePath, isSeerModeWritablePath, resolveSeerModeConfig, type NornResolvedSeerModeConfig, type NornSeerModeConfig, } from "./config.ts";
|
package/dist/seer/index.js
DELETED