@opencode_weave/weave 0.6.4 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/dist/config/schema.d.ts +9 -0
  2. package/dist/features/analytics/adherence.d.ts +10 -0
  3. package/dist/features/analytics/format-metrics.d.ts +10 -0
  4. package/dist/features/analytics/generate-metrics-report.d.ts +17 -0
  5. package/dist/features/analytics/git-diff.d.ts +7 -0
  6. package/dist/features/analytics/index.d.ts +13 -6
  7. package/dist/features/analytics/plan-parser.d.ts +7 -0
  8. package/dist/features/analytics/plan-token-aggregator.d.ts +11 -0
  9. package/dist/features/analytics/session-tracker.d.ts +20 -0
  10. package/dist/features/analytics/storage.d.ts +13 -1
  11. package/dist/features/analytics/token-report.d.ts +14 -0
  12. package/dist/features/analytics/types.d.ts +89 -1
  13. package/dist/features/builtin-commands/templates/metrics.d.ts +1 -0
  14. package/dist/features/builtin-commands/templates/run-workflow.d.ts +1 -0
  15. package/dist/features/builtin-commands/types.d.ts +1 -1
  16. package/dist/features/workflow/commands.d.ts +17 -0
  17. package/dist/features/workflow/completion.d.ts +31 -0
  18. package/dist/features/workflow/constants.d.ts +12 -0
  19. package/dist/features/workflow/context.d.ts +16 -0
  20. package/dist/features/workflow/discovery.d.ts +19 -0
  21. package/dist/features/workflow/engine.d.ts +49 -0
  22. package/dist/features/workflow/hook.d.ts +47 -0
  23. package/dist/features/workflow/index.d.ts +15 -0
  24. package/dist/features/workflow/schema.d.ts +118 -0
  25. package/dist/features/workflow/storage.d.ts +51 -0
  26. package/dist/features/workflow/types.d.ts +142 -0
  27. package/dist/hooks/create-hooks.d.ts +6 -0
  28. package/dist/index.js +2206 -428
  29. package/dist/plugin/types.d.ts +1 -1
  30. package/package.json +1 -1
@@ -0,0 +1,118 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * Zod schema for step completion configuration in workflow definitions.
4
+ */
5
+ export declare const CompletionConfigSchema: z.ZodObject<{
6
+ method: z.ZodEnum<{
7
+ user_confirm: "user_confirm";
8
+ plan_created: "plan_created";
9
+ plan_complete: "plan_complete";
10
+ review_verdict: "review_verdict";
11
+ agent_signal: "agent_signal";
12
+ }>;
13
+ plan_name: z.ZodOptional<z.ZodString>;
14
+ keywords: z.ZodOptional<z.ZodArray<z.ZodString>>;
15
+ }, z.core.$strip>;
16
+ /**
17
+ * Zod schema for artifact references.
18
+ */
19
+ export declare const ArtifactRefSchema: z.ZodObject<{
20
+ name: z.ZodString;
21
+ description: z.ZodOptional<z.ZodString>;
22
+ }, z.core.$strip>;
23
+ /**
24
+ * Zod schema for step artifact declarations.
25
+ */
26
+ export declare const StepArtifactsSchema: z.ZodObject<{
27
+ inputs: z.ZodOptional<z.ZodArray<z.ZodObject<{
28
+ name: z.ZodString;
29
+ description: z.ZodOptional<z.ZodString>;
30
+ }, z.core.$strip>>>;
31
+ outputs: z.ZodOptional<z.ZodArray<z.ZodObject<{
32
+ name: z.ZodString;
33
+ description: z.ZodOptional<z.ZodString>;
34
+ }, z.core.$strip>>>;
35
+ }, z.core.$strip>;
36
+ /**
37
+ * Zod schema for a workflow step definition.
38
+ */
39
+ export declare const WorkflowStepSchema: z.ZodObject<{
40
+ id: z.ZodString;
41
+ name: z.ZodString;
42
+ type: z.ZodEnum<{
43
+ interactive: "interactive";
44
+ autonomous: "autonomous";
45
+ gate: "gate";
46
+ }>;
47
+ agent: z.ZodString;
48
+ prompt: z.ZodString;
49
+ completion: z.ZodObject<{
50
+ method: z.ZodEnum<{
51
+ user_confirm: "user_confirm";
52
+ plan_created: "plan_created";
53
+ plan_complete: "plan_complete";
54
+ review_verdict: "review_verdict";
55
+ agent_signal: "agent_signal";
56
+ }>;
57
+ plan_name: z.ZodOptional<z.ZodString>;
58
+ keywords: z.ZodOptional<z.ZodArray<z.ZodString>>;
59
+ }, z.core.$strip>;
60
+ artifacts: z.ZodOptional<z.ZodObject<{
61
+ inputs: z.ZodOptional<z.ZodArray<z.ZodObject<{
62
+ name: z.ZodString;
63
+ description: z.ZodOptional<z.ZodString>;
64
+ }, z.core.$strip>>>;
65
+ outputs: z.ZodOptional<z.ZodArray<z.ZodObject<{
66
+ name: z.ZodString;
67
+ description: z.ZodOptional<z.ZodString>;
68
+ }, z.core.$strip>>>;
69
+ }, z.core.$strip>>;
70
+ on_reject: z.ZodOptional<z.ZodEnum<{
71
+ pause: "pause";
72
+ fail: "fail";
73
+ }>>;
74
+ }, z.core.$strip>;
75
+ /**
76
+ * Zod schema for a complete workflow definition file.
77
+ */
78
+ export declare const WorkflowDefinitionSchema: z.ZodObject<{
79
+ name: z.ZodString;
80
+ description: z.ZodOptional<z.ZodString>;
81
+ version: z.ZodNumber;
82
+ steps: z.ZodArray<z.ZodObject<{
83
+ id: z.ZodString;
84
+ name: z.ZodString;
85
+ type: z.ZodEnum<{
86
+ interactive: "interactive";
87
+ autonomous: "autonomous";
88
+ gate: "gate";
89
+ }>;
90
+ agent: z.ZodString;
91
+ prompt: z.ZodString;
92
+ completion: z.ZodObject<{
93
+ method: z.ZodEnum<{
94
+ user_confirm: "user_confirm";
95
+ plan_created: "plan_created";
96
+ plan_complete: "plan_complete";
97
+ review_verdict: "review_verdict";
98
+ agent_signal: "agent_signal";
99
+ }>;
100
+ plan_name: z.ZodOptional<z.ZodString>;
101
+ keywords: z.ZodOptional<z.ZodArray<z.ZodString>>;
102
+ }, z.core.$strip>;
103
+ artifacts: z.ZodOptional<z.ZodObject<{
104
+ inputs: z.ZodOptional<z.ZodArray<z.ZodObject<{
105
+ name: z.ZodString;
106
+ description: z.ZodOptional<z.ZodString>;
107
+ }, z.core.$strip>>>;
108
+ outputs: z.ZodOptional<z.ZodArray<z.ZodObject<{
109
+ name: z.ZodString;
110
+ description: z.ZodOptional<z.ZodString>;
111
+ }, z.core.$strip>>>;
112
+ }, z.core.$strip>>;
113
+ on_reject: z.ZodOptional<z.ZodEnum<{
114
+ pause: "pause";
115
+ fail: "fail";
116
+ }>>;
117
+ }, z.core.$strip>>;
118
+ }, z.core.$strip>;
@@ -0,0 +1,51 @@
1
+ import type { WorkflowDefinition, WorkflowInstance, ActiveInstancePointer } from "./types";
2
+ /**
3
+ * Generate a unique instance ID.
4
+ * Format: wf_{8 random hex chars} (e.g., "wf_a1b2c3d4").
5
+ */
6
+ export declare function generateInstanceId(): string;
7
+ /**
8
+ * Generate a URL-safe slug from a goal string.
9
+ * Lowercase, spaces to hyphens, strip non-alphanumeric, truncate to 50 chars.
10
+ */
11
+ export declare function generateSlug(goal: string): string;
12
+ /**
13
+ * Create a fresh WorkflowInstance for a definition + goal.
14
+ */
15
+ export declare function createWorkflowInstance(definition: WorkflowDefinition, definitionPath: string, goal: string, sessionId: string): WorkflowInstance;
16
+ /**
17
+ * Read a workflow instance by ID. Returns null if not found or invalid.
18
+ */
19
+ export declare function readWorkflowInstance(directory: string, instanceId: string): WorkflowInstance | null;
20
+ /**
21
+ * Write a workflow instance to its state directory.
22
+ * Creates directories as needed.
23
+ */
24
+ export declare function writeWorkflowInstance(directory: string, instance: WorkflowInstance): boolean;
25
+ /**
26
+ * Read the active instance pointer. Returns null if no active instance.
27
+ */
28
+ export declare function readActiveInstance(directory: string): ActiveInstancePointer | null;
29
+ /**
30
+ * Set the active instance pointer.
31
+ */
32
+ export declare function setActiveInstance(directory: string, instanceId: string): boolean;
33
+ /**
34
+ * Clear the active instance pointer (without deleting the instance).
35
+ */
36
+ export declare function clearActiveInstance(directory: string): boolean;
37
+ /**
38
+ * Get the active workflow instance (resolves pointer -> reads instance).
39
+ * Returns null if no active instance or instance not found.
40
+ */
41
+ export declare function getActiveWorkflowInstance(directory: string): WorkflowInstance | null;
42
+ /**
43
+ * List all instance IDs (for status/history commands).
44
+ * Returns IDs sorted alphabetically.
45
+ */
46
+ export declare function listInstances(directory: string): string[];
47
+ /**
48
+ * Append a session ID to an instance's session_ids.
49
+ * Returns the updated instance, or null if the instance doesn't exist.
50
+ */
51
+ export declare function appendInstanceSessionId(directory: string, instanceId: string, sessionId: string): WorkflowInstance | null;
@@ -0,0 +1,142 @@
1
+ /**
2
+ * Step execution types: interactive (needs user input), autonomous (runs without user),
3
+ * gate (requires APPROVE/REJECT verdict).
4
+ */
5
+ export type StepType = "interactive" | "autonomous" | "gate";
6
+ /**
7
+ * How a step's completion is detected.
8
+ */
9
+ export type CompletionMethod = "user_confirm" | "plan_created" | "plan_complete" | "review_verdict" | "agent_signal";
10
+ /**
11
+ * Per-step status in a workflow instance.
12
+ */
13
+ export type StepStatus = "pending" | "active" | "awaiting_user" | "completed" | "failed" | "skipped";
14
+ /**
15
+ * Instance-level workflow status.
16
+ */
17
+ export type WorkflowStatus = "running" | "paused" | "completed" | "failed" | "cancelled";
18
+ /**
19
+ * What happens when a gate step rejects.
20
+ */
21
+ export type OnRejectAction = "pause" | "fail";
22
+ /**
23
+ * Reference to an artifact that a step consumes or produces.
24
+ */
25
+ export interface ArtifactRef {
26
+ name: string;
27
+ description?: string;
28
+ }
29
+ /**
30
+ * Artifact input/output declarations for a step.
31
+ */
32
+ export interface StepArtifacts {
33
+ inputs?: ArtifactRef[];
34
+ outputs?: ArtifactRef[];
35
+ }
36
+ /**
37
+ * Configuration for how a step's completion is detected.
38
+ */
39
+ export interface CompletionConfig {
40
+ method: CompletionMethod;
41
+ /** For plan_created/plan_complete: the plan name to check */
42
+ plan_name?: string;
43
+ /** For user_confirm: custom keywords to detect */
44
+ keywords?: string[];
45
+ }
46
+ /**
47
+ * A single step in a workflow definition (template).
48
+ */
49
+ export interface WorkflowStepDefinition {
50
+ /** Unique step ID within the workflow (e.g., "gather", "plan-review") */
51
+ id: string;
52
+ /** Human-readable step name */
53
+ name: string;
54
+ /** Step execution type */
55
+ type: StepType;
56
+ /** Agent to activate for this step */
57
+ agent: string;
58
+ /** Prompt template with {{instance.goal}}, {{artifacts.X}} variables */
59
+ prompt: string;
60
+ /** How to detect step completion */
61
+ completion: CompletionConfig;
62
+ /** Artifact declarations */
63
+ artifacts?: StepArtifacts;
64
+ /** For gate steps: what to do on reject */
65
+ on_reject?: OnRejectAction;
66
+ }
67
+ /**
68
+ * A workflow definition (reusable template).
69
+ * Stored as JSONC in .opencode/workflows/ or ~/.config/opencode/workflows/.
70
+ */
71
+ export interface WorkflowDefinition {
72
+ /** Workflow name matching the filename (e.g., "secure-feature") */
73
+ name: string;
74
+ /** Human-readable description */
75
+ description?: string;
76
+ /** Schema version for future migration */
77
+ version: number;
78
+ /** Ordered list of steps */
79
+ steps: WorkflowStepDefinition[];
80
+ }
81
+ /**
82
+ * Per-step state in a workflow instance.
83
+ */
84
+ export interface StepState {
85
+ /** Step ID matching the definition */
86
+ id: string;
87
+ /** Current step status */
88
+ status: StepStatus;
89
+ /** ISO timestamp when the step became active */
90
+ started_at?: string;
91
+ /** ISO timestamp when the step completed/failed/skipped */
92
+ completed_at?: string;
93
+ /** For gate steps: the verdict */
94
+ verdict?: "approve" | "reject";
95
+ /** Error message if failed */
96
+ error?: string;
97
+ /** Artifacts produced by this step */
98
+ artifacts?: Record<string, string>;
99
+ /** Summary of what this step produced (for context threading) */
100
+ summary?: string;
101
+ }
102
+ /**
103
+ * A workflow instance — a specific execution of a workflow definition,
104
+ * bound to a user goal with accumulated artifacts and step states.
105
+ */
106
+ export interface WorkflowInstance {
107
+ /** Unique instance ID (e.g., "wf_a1b2c3d4") */
108
+ instance_id: string;
109
+ /** ID of the workflow definition (matches definition name) */
110
+ definition_id: string;
111
+ /** Human-readable workflow name */
112
+ definition_name: string;
113
+ /** Path to the workflow definition file */
114
+ definition_path: string;
115
+ /** The user's goal — what they're trying to accomplish */
116
+ goal: string;
117
+ /** URL-safe slug derived from the goal (for plan filenames, etc.) */
118
+ slug: string;
119
+ /** Current workflow-level status */
120
+ status: WorkflowStatus;
121
+ /** ISO timestamp when the instance was created */
122
+ started_at: string;
123
+ /** ISO timestamp when the instance completed/failed/cancelled */
124
+ ended_at?: string;
125
+ /** Session IDs that have participated in this instance */
126
+ session_ids: string[];
127
+ /** ID of the currently active step */
128
+ current_step_id: string;
129
+ /** Per-step state */
130
+ steps: Record<string, StepState>;
131
+ /** Accumulated artifacts from completed steps (name -> value) */
132
+ artifacts: Record<string, string>;
133
+ /** Why the workflow is paused (if paused) */
134
+ pause_reason?: string;
135
+ }
136
+ /**
137
+ * Pointer file content — tracks which instance is currently active.
138
+ * Stored at .weave/workflows/active-instance.json.
139
+ */
140
+ export interface ActiveInstancePointer {
141
+ instance_id: string;
142
+ }
@@ -29,6 +29,12 @@ export declare function createHooks(args: {
29
29
  patternMdOnly: typeof checkPatternWrite | null;
30
30
  startWork: ((promptText: string, sessionId: string) => import("./start-work-hook").StartWorkResult) | null;
31
31
  workContinuation: ((sessionId: string) => import("./work-continuation").ContinuationResult) | null;
32
+ workflowStart: ((promptText: string, sessionId: string) => import("../features/workflow").WorkflowHookResult) | null;
33
+ workflowContinuation: ((sessionId: string, lastAssistantMessage?: string, lastUserMessage?: string) => {
34
+ continuationPrompt: string | null;
35
+ switchAgent: string | null;
36
+ }) | null;
37
+ workflowCommand: ((message: string) => import("../features/workflow").WorkflowCommandResult) | null;
32
38
  verificationReminder: typeof buildVerificationReminder | null;
33
39
  analyticsEnabled: boolean;
34
40
  };