@osolmaz/pi-workflows 0.13.1 → 0.13.3
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 +9 -7
- package/dist/builtins/autodoc.workflow.d.ts +5 -5
- package/dist/builtins/autoimplement.workflow.d.ts +69 -61
- package/dist/builtins/autoimplement.workflow.js +47 -8
- package/dist/builtins/autoimplement.workflow.js.map +1 -1
- package/dist/builtins/autoplan.workflow.d.ts +11 -5
- package/dist/builtins/autoplan.workflow.js +68 -32
- package/dist/builtins/autoplan.workflow.js.map +1 -1
- package/dist/builtins/catalog.js +4 -4
- package/dist/builtins/change-verification.workflow.d.ts +1 -1
- package/dist/builtins/plain-summary.workflow.d.ts +1 -1
- package/dist/builtins/plain-summary.workflow.js +35 -24
- package/dist/builtins/plain-summary.workflow.js.map +1 -1
- package/dist/builtins/plan-approval.workflow.d.ts +1 -1
- package/dist/builtins/plan-change.workflow.d.ts +25 -23
- package/dist/builtins/sanity-check.workflow.d.ts +3 -3
- package/dist/builtins/sanity-check.workflow.js +19 -22
- package/dist/builtins/sanity-check.workflow.js.map +1 -1
- package/dist/builtins/workspace-preparation.workflow.d.ts +1 -1
- package/dist/controllers/index.d.ts +2 -2
- package/dist/controllers/index.js.map +1 -1
- package/dist/controllers/sqlite.js +88 -61
- package/dist/controllers/sqlite.js.map +1 -1
- package/dist/controllers/types.d.ts +34 -0
- package/dist/controllers/workflow-engine-scheduler.d.ts +5 -1
- package/dist/controllers/workflow-engine-scheduler.js +83 -1
- package/dist/controllers/workflow-engine-scheduler.js.map +1 -1
- package/dist/controllers/workflows.d.ts +8 -1
- package/dist/controllers/workflows.js +36 -0
- package/dist/controllers/workflows.js.map +1 -1
- package/dist/extension/controller-host.d.ts +2 -1
- package/dist/extension/controller-host.js +1 -1
- package/dist/extension/controller-host.js.map +1 -1
- package/dist/extension/decision-channels.js +45 -7
- package/dist/extension/decision-channels.js.map +1 -1
- package/dist/extension/follow-up-coordinator.d.ts +27 -0
- package/dist/extension/follow-up-coordinator.js +131 -0
- package/dist/extension/follow-up-coordinator.js.map +1 -0
- package/dist/extension/index.d.ts +9 -0
- package/dist/extension/index.js +462 -76
- package/dist/extension/index.js.map +1 -1
- package/dist/extension/recorder.d.ts +1 -1
- package/dist/extension/recorder.js +8 -8
- package/dist/extension/recorder.js.map +1 -1
- package/dist/extension/session-events.d.ts +2 -3
- package/dist/extension/session-events.js +11 -10
- package/dist/extension/session-events.js.map +1 -1
- package/dist/extension/widget.js +9 -0
- package/dist/extension/widget.js.map +1 -1
- package/dist/state/database.d.ts +2 -1
- package/dist/state/database.js +11 -13
- package/dist/state/database.js.map +1 -1
- package/dist/state/json.js +6 -1
- package/dist/state/json.js.map +1 -1
- package/dist/state/mutation.d.ts +1 -1
- package/dist/state/mutation.js.map +1 -1
- package/dist/state/prune.d.ts +18 -0
- package/dist/state/prune.js +373 -0
- package/dist/state/prune.js.map +1 -0
- package/dist/state/schema.d.ts +1 -1
- package/dist/state/schema.js +130 -13
- package/dist/state/schema.js.map +1 -1
- package/dist/viewer/cli.d.ts +3 -1
- package/dist/viewer/cli.js +55 -4
- package/dist/viewer/cli.js.map +1 -1
- package/dist/viewer/render.js +19 -1
- package/dist/viewer/render.js.map +1 -1
- package/dist/viewer/session-reducer.d.ts +0 -1
- package/dist/viewer/session-reducer.js +2 -24
- package/dist/viewer/session-reducer.js.map +1 -1
- package/dist/workflows/composition.d.ts +2 -0
- package/dist/workflows/composition.js +15 -0
- package/dist/workflows/composition.js.map +1 -1
- package/dist/workflows/definition.d.ts +6 -3
- package/dist/workflows/definition.js +3 -0
- package/dist/workflows/definition.js.map +1 -1
- package/dist/workflows/engine.d.ts +6 -1
- package/dist/workflows/engine.js +303 -36
- package/dist/workflows/engine.js.map +1 -1
- package/dist/workflows/human-decision.d.ts +1 -0
- package/dist/workflows/human-decision.js +25 -9
- package/dist/workflows/human-decision.js.map +1 -1
- package/dist/workflows/index.d.ts +3 -1
- package/dist/workflows/index.js +2 -0
- package/dist/workflows/index.js.map +1 -1
- package/dist/workflows/json-patch.d.ts +47 -0
- package/dist/workflows/json-patch.js +298 -0
- package/dist/workflows/json-patch.js.map +1 -0
- package/dist/workflows/schema.js +29 -1
- package/dist/workflows/schema.js.map +1 -1
- package/dist/workflows/settings.d.ts +128 -0
- package/dist/workflows/settings.js +199 -0
- package/dist/workflows/settings.js.map +1 -0
- package/dist/workflows/store.d.ts +81 -3
- package/dist/workflows/store.js +1563 -50
- package/dist/workflows/store.js.map +1 -1
- package/dist/workflows/tool-input.d.ts +22 -0
- package/dist/workflows/tool-input.js +43 -0
- package/dist/workflows/tool-input.js.map +1 -1
- package/dist/workflows/types.d.ts +41 -6
- package/docs/2026-08-25-workflow-follow-ups.md +132 -0
- package/docs/2026-08-25-workflow-settings.md +169 -0
- package/docs/DEFERRED_TURNS.md +6 -0
- package/docs/DESIGN_PHILOSOPHY.md +2 -0
- package/docs/SQLITE_STATE.md +36 -17
- package/docs/WORKFLOW_COMPOSITION.md +15 -0
- package/docs/WORKFLOW_STEP_MESSAGES.md +4 -2
- package/docs/plans/2026-08-25-autoplan-user-intent-capture-plan.md +107 -0
- package/docs/plans/2026-08-25-live-workflow-settings-plan.md +532 -0
- package/docs/plans/2026-08-25-workflow-run-storage-plan.md +67 -0
- package/docs/session-event-journal.md +2 -3
- package/docs/tui-viewer.md +7 -6
- package/docs/workflows.md +58 -10
- package/examples/workflows/live-settings.workflow.ts +93 -0
- package/herdr-plugin.toml +1 -1
- package/package.json +1 -1
- package/src/builtins/autoimplement.workflow.ts +56 -8
- package/src/builtins/autoplan.workflow.ts +80 -32
- package/src/builtins/catalog.ts +4 -4
- package/src/builtins/plain-summary.workflow.ts +38 -40
- package/src/builtins/sanity-check.workflow.ts +19 -22
- package/src/controllers/index.ts +6 -0
- package/src/controllers/sqlite.ts +132 -72
- package/src/controllers/types.ts +40 -0
- package/src/controllers/workflow-engine-scheduler.ts +103 -1
- package/src/controllers/workflows.ts +68 -0
- package/src/extension/controller-host.ts +6 -1
- package/src/extension/decision-channels.ts +47 -7
- package/src/extension/follow-up-coordinator.ts +151 -0
- package/src/extension/index.ts +540 -89
- package/src/extension/recorder.ts +10 -8
- package/src/extension/session-events.ts +15 -13
- package/src/extension/widget.ts +8 -0
- package/src/state/database.ts +12 -12
- package/src/state/json.ts +6 -1
- package/src/state/mutation.ts +4 -1
- package/src/state/prune.ts +502 -0
- package/src/state/schema.ts +130 -13
- package/src/viewer/cli.ts +52 -5
- package/src/viewer/render.ts +43 -1
- package/src/viewer/session-reducer.ts +2 -29
- package/src/workflows/composition.ts +19 -0
- package/src/workflows/definition.ts +19 -5
- package/src/workflows/engine.ts +365 -36
- package/src/workflows/human-decision.ts +41 -11
- package/src/workflows/index.ts +43 -0
- package/src/workflows/json-patch.ts +375 -0
- package/src/workflows/schema.ts +31 -1
- package/src/workflows/settings.ts +430 -0
- package/src/workflows/store.ts +2268 -121
- package/src/workflows/tool-input.ts +58 -0
- package/src/workflows/types.ts +43 -5
|
@@ -30,6 +30,32 @@ const updateSchema = Type.Object(
|
|
|
30
30
|
const outputSchema = Type.Unknown({
|
|
31
31
|
description: "Step output matching the expected shape; required when action is submit",
|
|
32
32
|
});
|
|
33
|
+
const scopeIdSchema = Type.String({
|
|
34
|
+
description: "Settings scope id; defaults to the active node scope",
|
|
35
|
+
});
|
|
36
|
+
const expectedChangeNumberSchema = Type.Integer({
|
|
37
|
+
minimum: 0,
|
|
38
|
+
description: "Optional settings change number for an atomic compare-and-change",
|
|
39
|
+
});
|
|
40
|
+
const patchOperationSchema = Type.Object(
|
|
41
|
+
{
|
|
42
|
+
op: Type.String({ enum: ["add", "remove", "replace", "move", "copy", "test"] }),
|
|
43
|
+
path: Type.String(),
|
|
44
|
+
from: Type.Optional(Type.String()),
|
|
45
|
+
value: Type.Optional(Type.Unknown()),
|
|
46
|
+
},
|
|
47
|
+
noExtraProperties,
|
|
48
|
+
);
|
|
49
|
+
const patchSchema = Type.Array(patchOperationSchema, {
|
|
50
|
+
maxItems: 256,
|
|
51
|
+
description: "RFC 6902 JSON Patch operations",
|
|
52
|
+
});
|
|
53
|
+
const followUpPromptSchema = Type.String({
|
|
54
|
+
minLength: 1,
|
|
55
|
+
maxLength: 65536,
|
|
56
|
+
description: "Normal user prompt to send after successful workflow completion",
|
|
57
|
+
});
|
|
58
|
+
const followUpIdSchema = Type.String({ description: "Queued follow-up id" });
|
|
33
59
|
|
|
34
60
|
export const WorkflowActionSchemas = {
|
|
35
61
|
list: Type.Object(
|
|
@@ -62,6 +88,32 @@ export const WorkflowActionSchemas = {
|
|
|
62
88
|
},
|
|
63
89
|
noExtraProperties,
|
|
64
90
|
),
|
|
91
|
+
"change-settings": Type.Object(
|
|
92
|
+
{
|
|
93
|
+
action: Type.Literal("change-settings"),
|
|
94
|
+
runId: Type.Optional(runIdSchema),
|
|
95
|
+
scopeId: Type.Optional(scopeIdSchema),
|
|
96
|
+
expectedChangeNumber: Type.Optional(expectedChangeNumberSchema),
|
|
97
|
+
patch: patchSchema,
|
|
98
|
+
},
|
|
99
|
+
noExtraProperties,
|
|
100
|
+
),
|
|
101
|
+
"queue-follow-up": Type.Object(
|
|
102
|
+
{
|
|
103
|
+
action: Type.Literal("queue-follow-up"),
|
|
104
|
+
runId: Type.Optional(runIdSchema),
|
|
105
|
+
prompt: followUpPromptSchema,
|
|
106
|
+
},
|
|
107
|
+
noExtraProperties,
|
|
108
|
+
),
|
|
109
|
+
"remove-follow-up": Type.Object(
|
|
110
|
+
{
|
|
111
|
+
action: Type.Literal("remove-follow-up"),
|
|
112
|
+
runId: Type.Optional(runIdSchema),
|
|
113
|
+
followUpId: followUpIdSchema,
|
|
114
|
+
},
|
|
115
|
+
noExtraProperties,
|
|
116
|
+
),
|
|
65
117
|
update: Type.Object(
|
|
66
118
|
{
|
|
67
119
|
action: Type.Literal("update"),
|
|
@@ -107,6 +159,12 @@ const workflowInputParsers = {
|
|
|
107
159
|
resume: (value) => parseToolInput(WorkflowActionSchemas.resume, value, "workflow"),
|
|
108
160
|
cancel: (value) => parseToolInput(WorkflowActionSchemas.cancel, value, "workflow"),
|
|
109
161
|
answer: (value) => parseToolInput(WorkflowActionSchemas.answer, value, "workflow"),
|
|
162
|
+
"change-settings": (value) =>
|
|
163
|
+
parseToolInput(WorkflowActionSchemas["change-settings"], value, "workflow"),
|
|
164
|
+
"queue-follow-up": (value) =>
|
|
165
|
+
parseToolInput(WorkflowActionSchemas["queue-follow-up"], value, "workflow"),
|
|
166
|
+
"remove-follow-up": (value) =>
|
|
167
|
+
parseToolInput(WorkflowActionSchemas["remove-follow-up"], value, "workflow"),
|
|
110
168
|
update: (value) => parseToolInput(WorkflowActionSchemas.update, value, "workflow"),
|
|
111
169
|
submit: (value) => parseToolInput(WorkflowActionSchemas.submit, value, "workflow"),
|
|
112
170
|
} satisfies Record<keyof typeof WorkflowActionSchemas, ToolInputParser<WorkflowToolInput>>;
|
package/src/workflows/types.ts
CHANGED
|
@@ -5,11 +5,17 @@ export type MaybePromise<T> = T | Promise<T>;
|
|
|
5
5
|
* validators). `outputs` maps node ids to their accepted outputs; `results`
|
|
6
6
|
* maps node ids to the full result record of their latest attempt.
|
|
7
7
|
*/
|
|
8
|
-
export type WorkflowNodeContext<TInput = unknown> = {
|
|
8
|
+
export type WorkflowNodeContext<TInput = unknown, TSettings = unknown> = {
|
|
9
9
|
input: TInput;
|
|
10
10
|
outputs: Record<string, unknown>;
|
|
11
11
|
results: Record<string, WorkflowNodeResult>;
|
|
12
12
|
state: WorkflowRunState;
|
|
13
|
+
/** Fixed settings value captured when this node attempt started, when declared. */
|
|
14
|
+
settings?: TSettings;
|
|
15
|
+
/** Stable root or included-workflow settings scope for this attempt. */
|
|
16
|
+
settingsScopeId?: string;
|
|
17
|
+
/** Accepted settings change number captured by this attempt. */
|
|
18
|
+
settingsChangeNumber?: number;
|
|
13
19
|
/**
|
|
14
20
|
* Aborted when the node times out or the run is cancelled. Long-running
|
|
15
21
|
* callbacks should observe it (pass it to fetch/spawn or check
|
|
@@ -130,6 +136,8 @@ export type AgentNodeDefinition = SubmittedAgentNodeDefinition | AssistantAgentN
|
|
|
130
136
|
export type ComputeNodeDefinition = WorkflowNodeCommon & {
|
|
131
137
|
nodeType: "compute";
|
|
132
138
|
run: (context: WorkflowNodeContext) => MaybePromise<unknown>;
|
|
139
|
+
/** Marks a pure route selector that may rerun before route settlement. */
|
|
140
|
+
settingsRoute?: true;
|
|
133
141
|
};
|
|
134
142
|
|
|
135
143
|
/** A durable user-facing message addressed by the runtime to the run's origin session. */
|
|
@@ -471,10 +479,13 @@ export type WorkflowExitDefinition<TOutput = unknown> = {
|
|
|
471
479
|
export type WorkflowExitMap = Record<string, WorkflowExitDefinition>;
|
|
472
480
|
|
|
473
481
|
export type WorkflowInputOf<TWorkflow> =
|
|
474
|
-
TWorkflow extends WorkflowDefinition<infer TInput, any, any> ? TInput : unknown;
|
|
482
|
+
TWorkflow extends WorkflowDefinition<infer TInput, any, any, any> ? TInput : unknown;
|
|
483
|
+
|
|
484
|
+
export type WorkflowSettingsOf<TWorkflow> =
|
|
485
|
+
TWorkflow extends WorkflowDefinition<any, any, any, infer TSettings> ? TSettings : unknown;
|
|
475
486
|
|
|
476
487
|
export type WorkflowExitOutputs<TWorkflow> =
|
|
477
|
-
TWorkflow extends WorkflowDefinition<any, infer TExits, any>
|
|
488
|
+
TWorkflow extends WorkflowDefinition<any, infer TExits, any, any>
|
|
478
489
|
? {
|
|
479
490
|
[K in keyof TExits]: TExits[K] extends WorkflowExitDefinition<infer TOutput>
|
|
480
491
|
? TOutput
|
|
@@ -490,12 +501,14 @@ export type WorkflowIncludedResult<TWorkflow> = {
|
|
|
490
501
|
}[keyof WorkflowExitOutputs<TWorkflow>];
|
|
491
502
|
|
|
492
503
|
export type WorkflowIncludeDefinition<
|
|
493
|
-
TWorkflow extends WorkflowDefinition<any, any, any> = WorkflowDefinition<any, any, any>,
|
|
504
|
+
TWorkflow extends WorkflowDefinition<any, any, any, any> = WorkflowDefinition<any, any, any, any>,
|
|
494
505
|
> = {
|
|
495
506
|
/** Imported child definition or dynamic discovered name/path. */
|
|
496
507
|
workflow: TWorkflow | string;
|
|
497
508
|
/** Pure parent-to-child input mapping, evaluated on every mount entry. */
|
|
498
509
|
input?: (context: WorkflowNodeContext) => MaybePromise<WorkflowInputOf<TWorkflow>>;
|
|
510
|
+
/** Optional explicit initial settings mapping for this child invocation. */
|
|
511
|
+
settings?: (context: WorkflowNodeContext) => MaybePromise<WorkflowSettingsOf<TWorkflow>>;
|
|
499
512
|
/** Optional direct definition that supplies the contract for a dynamic reference. */
|
|
500
513
|
contract?: TWorkflow;
|
|
501
514
|
};
|
|
@@ -528,8 +541,11 @@ export type WorkflowDefinition<
|
|
|
528
541
|
TInput = any,
|
|
529
542
|
TExits extends WorkflowExitMap = WorkflowExitMap,
|
|
530
543
|
TIncludes extends WorkflowIncludeMap = WorkflowIncludeMap,
|
|
544
|
+
TSettings = any,
|
|
531
545
|
> = {
|
|
532
546
|
name: string;
|
|
547
|
+
/** Optional workflow-owned JSON settings that can change during a run. */
|
|
548
|
+
settings?: import("./settings.js").WorkflowSettingsDefinition<TSettings, TInput>;
|
|
533
549
|
/** Module URL used to attest directly imported child workflow files. */
|
|
534
550
|
source?: string;
|
|
535
551
|
/** Stable public input-and-exit contract identity for compatible overrides. */
|
|
@@ -605,6 +621,12 @@ export type WorkflowStepRecord = {
|
|
|
605
621
|
assistantMessage?: AssistantMessageReceipt;
|
|
606
622
|
/** For agent steps recorded inside a Pi conversation. */
|
|
607
623
|
conversation?: ConversationRange;
|
|
624
|
+
/** Fixed settings scope used by this attempt. */
|
|
625
|
+
settingsScopeId?: string;
|
|
626
|
+
/** Fixed accepted-through settings number used by this attempt. */
|
|
627
|
+
settingsChangeNumber?: number;
|
|
628
|
+
/** SHA-256 hash of the fixed settings JSON used by this attempt. */
|
|
629
|
+
settingsHash?: string;
|
|
608
630
|
};
|
|
609
631
|
|
|
610
632
|
export type WorkflowRunStatus =
|
|
@@ -674,6 +696,9 @@ export type WorkflowRunState = {
|
|
|
674
696
|
currentNode?: string;
|
|
675
697
|
currentAttemptId?: string;
|
|
676
698
|
currentNodeStartedAt?: string;
|
|
699
|
+
currentSettingsScopeId?: string;
|
|
700
|
+
currentSettingsChangeNumber?: number;
|
|
701
|
+
currentSettingsHash?: string;
|
|
677
702
|
statusDetail?: string;
|
|
678
703
|
/** Redacted verified-human receipt carried by a continuation run. */
|
|
679
704
|
humanDecision?: HumanDecisionReceipt;
|
|
@@ -690,6 +715,7 @@ export type WorkflowNodeSnapshot = {
|
|
|
690
715
|
statusDetail?: string;
|
|
691
716
|
summary?: string;
|
|
692
717
|
expectedOutput?: AgentExpectedOutput;
|
|
718
|
+
settingsRoute?: true;
|
|
693
719
|
actionExecution?: "function" | "shell";
|
|
694
720
|
mountPath?: string[];
|
|
695
721
|
localNodeId?: string;
|
|
@@ -711,6 +737,19 @@ export type WorkflowDefinitionSnapshot = {
|
|
|
711
737
|
nodes: Record<string, WorkflowNodeSnapshot>;
|
|
712
738
|
edges: WorkflowEdge[];
|
|
713
739
|
composition?: WorkflowCompositionSnapshot;
|
|
740
|
+
settings?: WorkflowSettingsSnapshot;
|
|
741
|
+
settingsScopes?: Array<{
|
|
742
|
+
mountPath: string[];
|
|
743
|
+
settings: WorkflowSettingsSnapshot;
|
|
744
|
+
}>;
|
|
745
|
+
};
|
|
746
|
+
|
|
747
|
+
export type WorkflowSettingsSnapshot = {
|
|
748
|
+
description?: string;
|
|
749
|
+
paths: Array<{
|
|
750
|
+
path: string;
|
|
751
|
+
permissions: Partial<Record<"read" | "add" | "remove" | "replace", string[]>>;
|
|
752
|
+
}>;
|
|
714
753
|
};
|
|
715
754
|
|
|
716
755
|
export type WorkflowTraceEvent = {
|
|
@@ -760,7 +799,6 @@ export type WorkflowSessionEventType =
|
|
|
760
799
|
| "assistant_event"
|
|
761
800
|
| "message_finished"
|
|
762
801
|
| "tool_execution_started"
|
|
763
|
-
| "tool_execution_updated"
|
|
764
802
|
| "tool_execution_finished";
|
|
765
803
|
|
|
766
804
|
/** One normalized temporal Pi event in `session/events.ndjson`. */
|