@opencode_weave/weave 0.6.4 → 0.7.0-preview.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/config/schema.d.ts +9 -0
- package/dist/features/analytics/adherence.d.ts +10 -0
- package/dist/features/analytics/format-metrics.d.ts +10 -0
- package/dist/features/analytics/generate-metrics-report.d.ts +17 -0
- package/dist/features/analytics/git-diff.d.ts +7 -0
- package/dist/features/analytics/index.d.ts +13 -6
- package/dist/features/analytics/plan-parser.d.ts +7 -0
- package/dist/features/analytics/plan-token-aggregator.d.ts +11 -0
- package/dist/features/analytics/session-tracker.d.ts +20 -0
- package/dist/features/analytics/storage.d.ts +13 -1
- package/dist/features/analytics/token-report.d.ts +14 -0
- package/dist/features/analytics/types.d.ts +89 -1
- package/dist/features/builtin-commands/templates/metrics.d.ts +1 -0
- package/dist/features/builtin-commands/templates/run-workflow.d.ts +1 -0
- package/dist/features/builtin-commands/types.d.ts +1 -1
- package/dist/features/workflow/commands.d.ts +17 -0
- package/dist/features/workflow/completion.d.ts +31 -0
- package/dist/features/workflow/constants.d.ts +12 -0
- package/dist/features/workflow/context.d.ts +16 -0
- package/dist/features/workflow/discovery.d.ts +19 -0
- package/dist/features/workflow/engine.d.ts +49 -0
- package/dist/features/workflow/hook.d.ts +47 -0
- package/dist/features/workflow/index.d.ts +15 -0
- package/dist/features/workflow/schema.d.ts +118 -0
- package/dist/features/workflow/storage.d.ts +51 -0
- package/dist/features/workflow/types.d.ts +142 -0
- package/dist/hooks/create-hooks.d.ts +6 -0
- package/dist/index.js +2143 -422
- package/dist/plugin/types.d.ts +1 -1
- package/package.json +1 -1
package/dist/config/schema.d.ts
CHANGED
|
@@ -155,6 +155,10 @@ export declare const CustomAgentsConfigSchema: z.ZodRecord<z.ZodString, z.ZodObj
|
|
|
155
155
|
}, z.core.$strip>>;
|
|
156
156
|
export declare const AnalyticsConfigSchema: z.ZodObject<{
|
|
157
157
|
enabled: z.ZodOptional<z.ZodBoolean>;
|
|
158
|
+
use_fingerprint: z.ZodOptional<z.ZodBoolean>;
|
|
159
|
+
}, z.core.$strip>;
|
|
160
|
+
export declare const WorkflowConfigSchema: z.ZodObject<{
|
|
161
|
+
disabled_workflows: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
158
162
|
}, z.core.$strip>;
|
|
159
163
|
export declare const WeaveConfigSchema: z.ZodObject<{
|
|
160
164
|
$schema: z.ZodOptional<z.ZodString>;
|
|
@@ -234,6 +238,7 @@ export declare const WeaveConfigSchema: z.ZodObject<{
|
|
|
234
238
|
}, z.core.$strip>>;
|
|
235
239
|
analytics: z.ZodOptional<z.ZodObject<{
|
|
236
240
|
enabled: z.ZodOptional<z.ZodBoolean>;
|
|
241
|
+
use_fingerprint: z.ZodOptional<z.ZodBoolean>;
|
|
237
242
|
}, z.core.$strip>>;
|
|
238
243
|
tmux: z.ZodOptional<z.ZodObject<{
|
|
239
244
|
enabled: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -251,6 +256,9 @@ export declare const WeaveConfigSchema: z.ZodObject<{
|
|
|
251
256
|
context_window_warning_threshold: z.ZodOptional<z.ZodNumber>;
|
|
252
257
|
context_window_critical_threshold: z.ZodOptional<z.ZodNumber>;
|
|
253
258
|
}, z.core.$strip>>;
|
|
259
|
+
workflows: z.ZodOptional<z.ZodObject<{
|
|
260
|
+
disabled_workflows: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
261
|
+
}, z.core.$strip>>;
|
|
254
262
|
}, z.core.$strip>;
|
|
255
263
|
export type AgentOverrideConfig = z.infer<typeof AgentOverrideConfigSchema>;
|
|
256
264
|
export type AgentOverrides = z.infer<typeof AgentOverridesSchema>;
|
|
@@ -262,4 +270,5 @@ export type BackgroundConfig = z.infer<typeof BackgroundConfigSchema>;
|
|
|
262
270
|
export type AnalyticsConfig = z.infer<typeof AnalyticsConfigSchema>;
|
|
263
271
|
export type TmuxConfig = z.infer<typeof TmuxConfigSchema>;
|
|
264
272
|
export type ExperimentalConfig = z.infer<typeof ExperimentalConfigSchema>;
|
|
273
|
+
export type WorkflowConfig = z.infer<typeof WorkflowConfigSchema>;
|
|
265
274
|
export type WeaveConfig = z.infer<typeof WeaveConfigSchema>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AdherenceReport } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Calculate plan adherence by comparing planned vs actual file changes.
|
|
4
|
+
*
|
|
5
|
+
* - **coverage**: fraction of planned files that were actually changed (0-1).
|
|
6
|
+
* If no files were planned, coverage = 1 (vacuously complete).
|
|
7
|
+
* - **precision**: fraction of actual changes that were planned (0-1).
|
|
8
|
+
* If no files were changed, precision = 1 (vacuously precise).
|
|
9
|
+
*/
|
|
10
|
+
export declare function calculateAdherence(plannedFiles: string[], actualFiles: string[]): AdherenceReport;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { MetricsReport, SessionSummary } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Format metrics reports and session summaries into a markdown dashboard.
|
|
4
|
+
*
|
|
5
|
+
* @param reports - Array of MetricsReport from readMetricsReports()
|
|
6
|
+
* @param summaries - Array of SessionSummary from readSessionSummaries()
|
|
7
|
+
* @param args - Optional arguments: a plan name to filter, "all" for all reports, or empty for last 5
|
|
8
|
+
* @returns Formatted markdown string
|
|
9
|
+
*/
|
|
10
|
+
export declare function formatMetricsMarkdown(reports: MetricsReport[], summaries: SessionSummary[], args?: string): string;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { WorkState } from "../work-state/types";
|
|
2
|
+
import type { MetricsReport } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Generate a Phase 1 metrics report for a completed plan.
|
|
5
|
+
*
|
|
6
|
+
* Orchestrates:
|
|
7
|
+
* 1. Extract planned files from the plan markdown
|
|
8
|
+
* 2. Get actual changed files via git diff (startSha..HEAD)
|
|
9
|
+
* 3. Calculate adherence (coverage, precision)
|
|
10
|
+
* 4. Aggregate token usage across all sessions for this plan
|
|
11
|
+
* 5. Compute total duration from session summaries
|
|
12
|
+
* 6. Write the report to metrics-reports.jsonl
|
|
13
|
+
*
|
|
14
|
+
* In Phase 1, `quality` and `gaps` are undefined.
|
|
15
|
+
* Returns the report if successful, null on error.
|
|
16
|
+
*/
|
|
17
|
+
export declare function generateMetricsReport(directory: string, state: WorkState): MetricsReport | null;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get the list of files changed between a given SHA and HEAD.
|
|
3
|
+
*
|
|
4
|
+
* Uses `git diff --name-only fromSha..HEAD` and returns relative paths.
|
|
5
|
+
* Returns an empty array on any error (non-git repo, invalid SHA, etc.).
|
|
6
|
+
*/
|
|
7
|
+
export declare function getChangedFiles(directory: string, fromSha: string): string[];
|
|
@@ -1,9 +1,16 @@
|
|
|
1
|
-
export type { ToolUsageEntry, DelegationEntry, SessionSummary, DetectedStack, ProjectFingerprint, Suggestion, InFlightToolCall, TrackedSession, } from "./types";
|
|
2
|
-
export { ANALYTICS_DIR, SESSION_SUMMARIES_FILE, FINGERPRINT_FILE } from "./types";
|
|
3
|
-
export { ensureAnalyticsDir, appendSessionSummary, readSessionSummaries, writeFingerprint, readFingerprint, } from "./storage";
|
|
1
|
+
export type { ToolUsageEntry, DelegationEntry, SessionSummary, TokenUsage, MetricsTokenUsage, AdherenceReport, MetricsReport, DetectedStack, ProjectFingerprint, Suggestion, InFlightToolCall, TrackedSession, } from "./types";
|
|
2
|
+
export { ANALYTICS_DIR, SESSION_SUMMARIES_FILE, FINGERPRINT_FILE, METRICS_REPORTS_FILE, MAX_METRICS_ENTRIES, zeroTokenUsage, } from "./types";
|
|
3
|
+
export { ensureAnalyticsDir, appendSessionSummary, readSessionSummaries, writeFingerprint, readFingerprint, writeMetricsReport, readMetricsReports, } from "./storage";
|
|
4
4
|
export { detectStack, detectPackageManager, detectMonorepo, detectPrimaryLanguage, generateFingerprint, fingerprintProject, getOrCreateFingerprint, } from "./fingerprint";
|
|
5
5
|
export { SessionTracker, createSessionTracker } from "./session-tracker";
|
|
6
6
|
export { generateSuggestions, getSuggestionsForProject } from "./suggestions";
|
|
7
|
+
export { generateTokenReport, getTokenReport } from "./token-report";
|
|
8
|
+
export { formatMetricsMarkdown } from "./format-metrics";
|
|
9
|
+
export { generateMetricsReport } from "./generate-metrics-report";
|
|
10
|
+
export { extractPlannedFiles } from "./plan-parser";
|
|
11
|
+
export { getChangedFiles } from "./git-diff";
|
|
12
|
+
export { calculateAdherence } from "./adherence";
|
|
13
|
+
export { aggregateTokensForPlan } from "./plan-token-aggregator";
|
|
7
14
|
import type { SessionTracker } from "./session-tracker";
|
|
8
15
|
import type { ProjectFingerprint } from "./types";
|
|
9
16
|
/** Return value of createAnalytics — bundles tracker + fingerprint */
|
|
@@ -15,8 +22,8 @@ export interface Analytics {
|
|
|
15
22
|
}
|
|
16
23
|
/**
|
|
17
24
|
* Create all analytics services for a project.
|
|
18
|
-
* Instantiates the session tracker and
|
|
19
|
-
*
|
|
25
|
+
* Instantiates the session tracker and uses the provided fingerprint (if any).
|
|
26
|
+
* Fingerprint generation is the caller's responsibility — pass null to opt out.
|
|
20
27
|
* This is the single entry point called from the plugin's main init.
|
|
21
28
|
*/
|
|
22
|
-
export declare function createAnalytics(directory: string, fingerprint
|
|
29
|
+
export declare function createAnalytics(directory: string, fingerprint: ProjectFingerprint | null): Analytics;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extract all planned file paths from a plan's `## TODOs` section.
|
|
3
|
+
*
|
|
4
|
+
* Parses `**Files**:` lines, splits on commas, strips `(new)` / `Create` prefixes,
|
|
5
|
+
* deduplicates, and returns normalized relative paths.
|
|
6
|
+
*/
|
|
7
|
+
export declare function extractPlannedFiles(planPath: string): string[];
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { MetricsTokenUsage } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Aggregate token usage for a plan by summing across matching session summaries.
|
|
4
|
+
*
|
|
5
|
+
* Reads all session summaries, filters to those whose `sessionId` is in `sessionIds`,
|
|
6
|
+
* and sums their `tokenUsage` fields. Sessions without `tokenUsage` contribute zeros
|
|
7
|
+
* (backward compatibility).
|
|
8
|
+
*
|
|
9
|
+
* Maps from session TokenUsage (inputTokens/outputTokens) to MetricsTokenUsage (input/output).
|
|
10
|
+
*/
|
|
11
|
+
export declare function aggregateTokensForPlan(directory: string, sessionIds: string[]): MetricsTokenUsage;
|
|
@@ -24,6 +24,26 @@ export declare class SessionTracker {
|
|
|
24
24
|
* Track a tool execution end. Records delegation if it was a task tool.
|
|
25
25
|
*/
|
|
26
26
|
trackToolEnd(sessionId: string, toolName: string, callId: string, agent?: string): void;
|
|
27
|
+
/**
|
|
28
|
+
* Set the agent name for a session. Only sets on first call (captures primary agent).
|
|
29
|
+
*/
|
|
30
|
+
setAgentName(sessionId: string, agentName: string): void;
|
|
31
|
+
/**
|
|
32
|
+
* Accumulate dollar cost from a message into the session total.
|
|
33
|
+
*/
|
|
34
|
+
trackCost(sessionId: string, cost: number): void;
|
|
35
|
+
/**
|
|
36
|
+
* Track token usage from a message.updated event.
|
|
37
|
+
* Accumulates all token fields into the session's running totals.
|
|
38
|
+
* Lazily starts the session if needed.
|
|
39
|
+
*/
|
|
40
|
+
trackTokenUsage(sessionId: string, tokens: {
|
|
41
|
+
input?: number;
|
|
42
|
+
output?: number;
|
|
43
|
+
reasoning?: number;
|
|
44
|
+
cacheRead?: number;
|
|
45
|
+
cacheWrite?: number;
|
|
46
|
+
}): void;
|
|
27
47
|
/**
|
|
28
48
|
* End a session and persist the summary. Removes the session from tracking.
|
|
29
49
|
* Returns the generated summary, or null if the session wasn't being tracked.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { SessionSummary, ProjectFingerprint } from "./types";
|
|
1
|
+
import type { SessionSummary, ProjectFingerprint, MetricsReport } from "./types";
|
|
2
2
|
/** Maximum number of session summary entries to keep in the JSONL file */
|
|
3
3
|
export declare const MAX_SESSION_ENTRIES = 1000;
|
|
4
4
|
/**
|
|
@@ -9,6 +9,7 @@ export declare function ensureAnalyticsDir(directory: string): string;
|
|
|
9
9
|
/**
|
|
10
10
|
* Append a session summary to the JSONL file.
|
|
11
11
|
* Auto-creates the analytics directory if needed.
|
|
12
|
+
* Rotates the file to at most MAX_SESSION_ENTRIES when the threshold is exceeded.
|
|
12
13
|
*/
|
|
13
14
|
export declare function appendSessionSummary(directory: string, summary: SessionSummary): boolean;
|
|
14
15
|
/**
|
|
@@ -26,3 +27,14 @@ export declare function writeFingerprint(directory: string, fingerprint: Project
|
|
|
26
27
|
* Returns null if the file doesn't exist or is unparseable.
|
|
27
28
|
*/
|
|
28
29
|
export declare function readFingerprint(directory: string): ProjectFingerprint | null;
|
|
30
|
+
/**
|
|
31
|
+
* Write a metrics report to the JSONL file.
|
|
32
|
+
* Auto-creates the analytics directory if needed.
|
|
33
|
+
* Appends the report and rotates if exceeding MAX_METRICS_ENTRIES.
|
|
34
|
+
*/
|
|
35
|
+
export declare function writeMetricsReport(directory: string, report: MetricsReport): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Read all metrics reports from the JSONL file.
|
|
38
|
+
* Returns an empty array if the file doesn't exist or is unparseable.
|
|
39
|
+
*/
|
|
40
|
+
export declare function readMetricsReports(directory: string): MetricsReport[];
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { SessionSummary } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Generate a human-readable token usage and cost report from session summaries.
|
|
4
|
+
*
|
|
5
|
+
* Sections:
|
|
6
|
+
* 1. Overall Totals — aggregate metrics across all sessions
|
|
7
|
+
* 2. Per-Agent Breakdown — grouped by agentName, sorted by total cost
|
|
8
|
+
* 3. Top 5 Costliest Sessions — most expensive individual sessions
|
|
9
|
+
*/
|
|
10
|
+
export declare function generateTokenReport(summaries: SessionSummary[]): string;
|
|
11
|
+
/**
|
|
12
|
+
* Convenience function: read summaries from disk and generate the report.
|
|
13
|
+
*/
|
|
14
|
+
export declare function getTokenReport(directory: string): string;
|
|
@@ -24,6 +24,21 @@ export interface DelegationEntry {
|
|
|
24
24
|
/** Duration in milliseconds (if completed) */
|
|
25
25
|
durationMs?: number;
|
|
26
26
|
}
|
|
27
|
+
/** Accumulated token usage across all messages in a session */
|
|
28
|
+
export interface TokenUsage {
|
|
29
|
+
/** Total input tokens consumed */
|
|
30
|
+
inputTokens: number;
|
|
31
|
+
/** Total output tokens generated */
|
|
32
|
+
outputTokens: number;
|
|
33
|
+
/** Total reasoning tokens used */
|
|
34
|
+
reasoningTokens: number;
|
|
35
|
+
/** Total cache read tokens */
|
|
36
|
+
cacheReadTokens: number;
|
|
37
|
+
/** Total cache write tokens */
|
|
38
|
+
cacheWriteTokens: number;
|
|
39
|
+
/** Total number of assistant messages processed */
|
|
40
|
+
totalMessages: number;
|
|
41
|
+
}
|
|
27
42
|
/** Summary of a completed session, appended as a JSONL line */
|
|
28
43
|
export interface SessionSummary {
|
|
29
44
|
/** Unique session identifier */
|
|
@@ -42,6 +57,12 @@ export interface SessionSummary {
|
|
|
42
57
|
totalToolCalls: number;
|
|
43
58
|
/** Total number of delegations */
|
|
44
59
|
totalDelegations: number;
|
|
60
|
+
/** Display name of the agent that ran this session (e.g., "Loom (Main Orchestrator)") */
|
|
61
|
+
agentName?: string;
|
|
62
|
+
/** Total dollar cost accumulated across all messages */
|
|
63
|
+
totalCost?: number;
|
|
64
|
+
/** Aggregated token usage across all messages (absent for old entries or sessions with no messages) */
|
|
65
|
+
tokenUsage?: TokenUsage;
|
|
45
66
|
}
|
|
46
67
|
/** Detected language/framework in the project */
|
|
47
68
|
export interface DetectedStack {
|
|
@@ -78,10 +99,71 @@ export interface Suggestion {
|
|
|
78
99
|
/** Human-readable suggestion text */
|
|
79
100
|
text: string;
|
|
80
101
|
/** Category of suggestion */
|
|
81
|
-
category: "tool-usage" | "delegation" | "workflow";
|
|
102
|
+
category: "tool-usage" | "delegation" | "workflow" | "token-usage";
|
|
82
103
|
/** Confidence level */
|
|
83
104
|
confidence: "high" | "medium" | "low";
|
|
84
105
|
}
|
|
106
|
+
/** File name for metrics reports (JSONL format) */
|
|
107
|
+
export declare const METRICS_REPORTS_FILE = "metrics-reports.jsonl";
|
|
108
|
+
/** Maximum number of metrics report entries to keep in the JSONL file */
|
|
109
|
+
export declare const MAX_METRICS_ENTRIES = 100;
|
|
110
|
+
/** Token usage for metrics reports (simplified field names vs session TokenUsage) */
|
|
111
|
+
export interface MetricsTokenUsage {
|
|
112
|
+
/** Total input tokens consumed */
|
|
113
|
+
input: number;
|
|
114
|
+
/** Total output tokens generated */
|
|
115
|
+
output: number;
|
|
116
|
+
/** Total reasoning tokens used */
|
|
117
|
+
reasoning: number;
|
|
118
|
+
/** Total cache read tokens */
|
|
119
|
+
cacheRead: number;
|
|
120
|
+
/** Total cache write tokens */
|
|
121
|
+
cacheWrite: number;
|
|
122
|
+
}
|
|
123
|
+
/** Create a zero-valued MetricsTokenUsage */
|
|
124
|
+
export declare function zeroTokenUsage(): MetricsTokenUsage;
|
|
125
|
+
/** Plan execution adherence metrics */
|
|
126
|
+
export interface AdherenceReport {
|
|
127
|
+
/** Proportion of planned files that actually changed (0-1) */
|
|
128
|
+
coverage: number;
|
|
129
|
+
/** Proportion of actual changes that were planned (0-1) */
|
|
130
|
+
precision: number;
|
|
131
|
+
/** Planned files that actually changed */
|
|
132
|
+
plannedFilesChanged: string[];
|
|
133
|
+
/** Files changed but not in the plan */
|
|
134
|
+
unplannedChanges: string[];
|
|
135
|
+
/** Planned files that did not change */
|
|
136
|
+
missedFiles: string[];
|
|
137
|
+
/** Total number of files in the plan */
|
|
138
|
+
totalPlannedFiles: number;
|
|
139
|
+
/** Total number of files actually changed */
|
|
140
|
+
totalActualFiles: number;
|
|
141
|
+
}
|
|
142
|
+
/** Metrics report for a completed plan */
|
|
143
|
+
export interface MetricsReport {
|
|
144
|
+
/** Plan name (from plan file basename) */
|
|
145
|
+
planName: string;
|
|
146
|
+
/** ISO timestamp when report was generated */
|
|
147
|
+
generatedAt: string;
|
|
148
|
+
/** Adherence metrics */
|
|
149
|
+
adherence: AdherenceReport;
|
|
150
|
+
/** Code quality score (Phase 2 — undefined in Phase 1) */
|
|
151
|
+
quality?: unknown;
|
|
152
|
+
/** Quality gaps (Phase 2 — undefined in Phase 1) */
|
|
153
|
+
gaps?: unknown;
|
|
154
|
+
/** Token usage across all sessions */
|
|
155
|
+
tokenUsage: MetricsTokenUsage;
|
|
156
|
+
/** Total duration of all sessions in milliseconds */
|
|
157
|
+
durationMs: number;
|
|
158
|
+
/** Number of sessions that worked on this plan */
|
|
159
|
+
sessionCount: number;
|
|
160
|
+
/** Git HEAD SHA when work started */
|
|
161
|
+
startSha?: string;
|
|
162
|
+
/** Git HEAD SHA when work ended (optional) */
|
|
163
|
+
endSha?: string;
|
|
164
|
+
/** Session IDs that contributed to this report */
|
|
165
|
+
sessionIds: string[];
|
|
166
|
+
}
|
|
85
167
|
/** Tracks in-flight tool calls for duration measurement */
|
|
86
168
|
export interface InFlightToolCall {
|
|
87
169
|
/** Tool name */
|
|
@@ -103,4 +185,10 @@ export interface TrackedSession {
|
|
|
103
185
|
delegations: DelegationEntry[];
|
|
104
186
|
/** In-flight tool calls keyed by callID */
|
|
105
187
|
inFlight: Record<string, InFlightToolCall>;
|
|
188
|
+
/** Display name of the agent running this session */
|
|
189
|
+
agentName?: string;
|
|
190
|
+
/** Accumulated dollar cost across all messages */
|
|
191
|
+
totalCost: number;
|
|
192
|
+
/** Cumulative token usage across all messages */
|
|
193
|
+
tokenUsage: TokenUsage;
|
|
106
194
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const METRICS_TEMPLATE = "You are being activated by the /metrics command to present Weave analytics data to the user.\n\n## Your Mission\nPresent the injected metrics data in a clear, readable format. The data has already been loaded and formatted by the command hook \u2014 simply relay it to the user.\n\n## Instructions\n\n1. **Read the injected context below** \u2014 it contains pre-formatted metrics markdown\n2. **Present it to the user** as-is \u2014 do NOT re-fetch or recalculate anything\n3. **Answer follow-up questions** about the data if the user asks\n4. If the data indicates analytics is disabled or no data exists, relay that message directly";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const RUN_WORKFLOW_TEMPLATE = "You are being activated by the /run-workflow command to execute a multi-step workflow.\n\n## Your Mission\nThe workflow engine will inject context below with:\n- The workflow definition to use\n- The user's goal for this workflow instance\n- The current step and its prompt\n- Context from any previously completed steps\n\nFollow the injected step prompt. When the step is complete, the workflow engine will\nautomatically advance you to the next step.\n\n## Rules\n- Focus on the current step's task only\n- Signal completion clearly (the workflow engine detects it)\n- Do NOT skip ahead to future steps\n- If you need user input, ask for it and wait";
|
|
@@ -13,4 +13,4 @@ export interface BuiltinCommand {
|
|
|
13
13
|
/** Hint shown for the argument (e.g., "[plan-name]") */
|
|
14
14
|
argumentHint?: string;
|
|
15
15
|
}
|
|
16
|
-
export type BuiltinCommandName = "start-work";
|
|
16
|
+
export type BuiltinCommandName = "start-work" | "token-report" | "metrics" | "run-workflow";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workflow control sub-commands: keyword detection in user messages during active workflows.
|
|
3
|
+
* These are NOT separate slash commands — they're natural language keywords detected in chat.message.
|
|
4
|
+
*/
|
|
5
|
+
export interface WorkflowCommandResult {
|
|
6
|
+
/** Whether a workflow control keyword was detected and handled */
|
|
7
|
+
handled: boolean;
|
|
8
|
+
/** Context to inject into the response */
|
|
9
|
+
contextInjection?: string;
|
|
10
|
+
/** Agent to switch to (if any) */
|
|
11
|
+
switchAgent?: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Check if a user message contains a workflow control keyword and handle it.
|
|
15
|
+
* Only active when a workflow instance is running.
|
|
16
|
+
*/
|
|
17
|
+
export declare function handleWorkflowCommand(message: string, directory: string): WorkflowCommandResult;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { CompletionConfig, CompletionMethod } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Result of checking whether a step's completion condition is met.
|
|
4
|
+
*/
|
|
5
|
+
export interface CompletionCheckResult {
|
|
6
|
+
complete: boolean;
|
|
7
|
+
verdict?: "approve" | "reject";
|
|
8
|
+
artifacts?: Record<string, string>;
|
|
9
|
+
/** Concise summary of step output for context threading */
|
|
10
|
+
summary?: string;
|
|
11
|
+
reason?: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Context provided to completion checkers.
|
|
15
|
+
*/
|
|
16
|
+
export interface CompletionContext {
|
|
17
|
+
/** Last assistant message text (from message.part.updated tracking) */
|
|
18
|
+
lastAssistantMessage?: string;
|
|
19
|
+
/** Last user message text (for user_confirm) */
|
|
20
|
+
lastUserMessage?: string;
|
|
21
|
+
/** Working directory */
|
|
22
|
+
directory: string;
|
|
23
|
+
/** Completion config from the step definition */
|
|
24
|
+
config: CompletionConfig;
|
|
25
|
+
/** Current artifacts in the instance */
|
|
26
|
+
artifacts: Record<string, string>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Check whether a step's completion condition is met.
|
|
30
|
+
*/
|
|
31
|
+
export declare function checkStepCompletion(method: CompletionMethod, context: CompletionContext): CompletionCheckResult;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Root directory for Weave state and plans */
|
|
2
|
+
export { WEAVE_DIR } from "../work-state/constants";
|
|
3
|
+
/** Directory under .weave/ for workflow instance state */
|
|
4
|
+
export declare const WORKFLOWS_STATE_DIR = ".weave/workflows";
|
|
5
|
+
/** File name for individual instance state */
|
|
6
|
+
export declare const INSTANCE_STATE_FILE = "state.json";
|
|
7
|
+
/** Pointer file tracking the currently active workflow instance */
|
|
8
|
+
export declare const ACTIVE_INSTANCE_FILE = "active-instance.json";
|
|
9
|
+
/** Project-level directory for workflow definitions */
|
|
10
|
+
export declare const WORKFLOWS_DIR_PROJECT = ".opencode/workflows";
|
|
11
|
+
/** User-level directory for workflow definitions (under ~/.config/opencode/) */
|
|
12
|
+
export declare const WORKFLOWS_DIR_USER = "workflows";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { WorkflowInstance, WorkflowDefinition, WorkflowStepDefinition } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Resolve template variables in a string.
|
|
4
|
+
* Supports: {{instance.goal}}, {{instance.slug}}, {{artifacts.X}}, {{step.name}}, {{step.id}}
|
|
5
|
+
* Unknown variables are left as-is.
|
|
6
|
+
*/
|
|
7
|
+
export declare function resolveTemplate(template: string, instance: WorkflowInstance, definition: WorkflowDefinition): string;
|
|
8
|
+
/**
|
|
9
|
+
* Build the workflow context header showing goal, step history, and accumulated artifacts.
|
|
10
|
+
*/
|
|
11
|
+
export declare function buildContextHeader(instance: WorkflowInstance, definition: WorkflowDefinition): string;
|
|
12
|
+
/**
|
|
13
|
+
* Build the full context-threaded prompt for a step.
|
|
14
|
+
* Combines: (1) workflow context header, (2) resolved step prompt.
|
|
15
|
+
*/
|
|
16
|
+
export declare function composeStepPrompt(stepDef: WorkflowStepDefinition, instance: WorkflowInstance, definition: WorkflowDefinition): string;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { WorkflowDefinition } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* A workflow definition discovered from the filesystem.
|
|
4
|
+
*/
|
|
5
|
+
export interface DiscoveredWorkflow {
|
|
6
|
+
definition: WorkflowDefinition;
|
|
7
|
+
path: string;
|
|
8
|
+
scope: "project" | "user";
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Load and validate a single workflow definition from a JSONC file path.
|
|
12
|
+
* Returns null if the file can't be read, parsed, or fails validation.
|
|
13
|
+
*/
|
|
14
|
+
export declare function loadWorkflowDefinition(filePath: string): WorkflowDefinition | null;
|
|
15
|
+
/**
|
|
16
|
+
* Discover all valid workflow definitions from project and user directories.
|
|
17
|
+
* Project workflows override user workflows with the same name.
|
|
18
|
+
*/
|
|
19
|
+
export declare function discoverWorkflows(directory: string): DiscoveredWorkflow[];
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { WorkflowDefinition } from "./types";
|
|
2
|
+
import type { CompletionContext } from "./completion";
|
|
3
|
+
/**
|
|
4
|
+
* An action the engine wants the caller to take.
|
|
5
|
+
*/
|
|
6
|
+
export interface EngineAction {
|
|
7
|
+
type: "inject_prompt" | "switch_agent" | "pause" | "complete" | "none";
|
|
8
|
+
/** Context-threaded prompt to inject */
|
|
9
|
+
prompt?: string;
|
|
10
|
+
/** Agent to switch to for the next step */
|
|
11
|
+
agent?: string;
|
|
12
|
+
reason?: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Start a new workflow instance from a definition and goal.
|
|
16
|
+
* Creates the instance, sets it as active, and returns the first step's prompt.
|
|
17
|
+
*/
|
|
18
|
+
export declare function startWorkflow(input: {
|
|
19
|
+
definition: WorkflowDefinition;
|
|
20
|
+
definitionPath: string;
|
|
21
|
+
goal: string;
|
|
22
|
+
sessionId: string;
|
|
23
|
+
directory: string;
|
|
24
|
+
}): EngineAction;
|
|
25
|
+
/**
|
|
26
|
+
* Check the current step's completion and advance if complete.
|
|
27
|
+
* This is called on session.idle events.
|
|
28
|
+
*/
|
|
29
|
+
export declare function checkAndAdvance(input: {
|
|
30
|
+
directory: string;
|
|
31
|
+
context: CompletionContext;
|
|
32
|
+
}): EngineAction;
|
|
33
|
+
/**
|
|
34
|
+
* Pause the active workflow instance.
|
|
35
|
+
*/
|
|
36
|
+
export declare function pauseWorkflow(directory: string, reason?: string): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Resume a paused workflow instance.
|
|
39
|
+
* Returns the current step's context-threaded prompt.
|
|
40
|
+
*/
|
|
41
|
+
export declare function resumeWorkflow(directory: string): EngineAction;
|
|
42
|
+
/**
|
|
43
|
+
* Skip the current step and advance to the next.
|
|
44
|
+
*/
|
|
45
|
+
export declare function skipStep(directory: string): EngineAction;
|
|
46
|
+
/**
|
|
47
|
+
* Abort the active workflow instance.
|
|
48
|
+
*/
|
|
49
|
+
export declare function abortWorkflow(directory: string): boolean;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workflow hook handler: detects /run-workflow commands, parses arguments,
|
|
3
|
+
* manages workflow instances, and drives step transitions on session.idle.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Marker embedded in workflow continuation prompts so the auto-pause guard
|
|
7
|
+
* in plugin-interface.ts can recognize them and NOT pause coexisting WorkState plans.
|
|
8
|
+
*/
|
|
9
|
+
export declare const WORKFLOW_CONTINUATION_MARKER = "<!-- weave:workflow-continuation -->";
|
|
10
|
+
export interface WorkflowHookResult {
|
|
11
|
+
/** Context to inject into the prompt (step prompt with workflow context) */
|
|
12
|
+
contextInjection: string | null;
|
|
13
|
+
/** Agent to switch to for the current step */
|
|
14
|
+
switchAgent: string | null;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Parse /run-workflow arguments into workflow name and optional goal.
|
|
18
|
+
* Argument format: `<workflow-name> "goal text"` or `<workflow-name>` or empty.
|
|
19
|
+
*/
|
|
20
|
+
export declare function parseWorkflowArgs(args: string): {
|
|
21
|
+
workflowName: string | null;
|
|
22
|
+
goal: string | null;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Handle the /run-workflow command.
|
|
26
|
+
* Detects the command via <session-context> tag, parses arguments,
|
|
27
|
+
* and either creates a new instance, resumes an existing one, or lists available definitions.
|
|
28
|
+
*/
|
|
29
|
+
export declare function handleRunWorkflow(input: {
|
|
30
|
+
promptText: string;
|
|
31
|
+
sessionId: string;
|
|
32
|
+
directory: string;
|
|
33
|
+
}): WorkflowHookResult;
|
|
34
|
+
/**
|
|
35
|
+
* Check workflow continuation on session.idle.
|
|
36
|
+
* If an active workflow instance exists and the current step's completion condition is met,
|
|
37
|
+
* advance to the next step and return a continuation prompt.
|
|
38
|
+
*/
|
|
39
|
+
export declare function checkWorkflowContinuation(input: {
|
|
40
|
+
sessionId: string;
|
|
41
|
+
directory: string;
|
|
42
|
+
lastAssistantMessage?: string;
|
|
43
|
+
lastUserMessage?: string;
|
|
44
|
+
}): {
|
|
45
|
+
continuationPrompt: string | null;
|
|
46
|
+
switchAgent: string | null;
|
|
47
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type { StepType, CompletionMethod, StepStatus, WorkflowStatus, OnRejectAction, ArtifactRef, StepArtifacts, CompletionConfig, WorkflowStepDefinition, WorkflowDefinition, StepState, WorkflowInstance, ActiveInstancePointer, } from "./types";
|
|
2
|
+
export { WORKFLOWS_STATE_DIR, INSTANCE_STATE_FILE, ACTIVE_INSTANCE_FILE, WORKFLOWS_DIR_PROJECT, WORKFLOWS_DIR_USER, } from "./constants";
|
|
3
|
+
export { generateInstanceId, generateSlug, createWorkflowInstance, readWorkflowInstance, writeWorkflowInstance, readActiveInstance, setActiveInstance, clearActiveInstance, getActiveWorkflowInstance, listInstances, appendInstanceSessionId, } from "./storage";
|
|
4
|
+
export type { DiscoveredWorkflow } from "./discovery";
|
|
5
|
+
export { loadWorkflowDefinition, discoverWorkflows } from "./discovery";
|
|
6
|
+
export { resolveTemplate, buildContextHeader, composeStepPrompt } from "./context";
|
|
7
|
+
export type { CompletionCheckResult, CompletionContext } from "./completion";
|
|
8
|
+
export { checkStepCompletion } from "./completion";
|
|
9
|
+
export type { EngineAction } from "./engine";
|
|
10
|
+
export { startWorkflow, checkAndAdvance, pauseWorkflow, resumeWorkflow, skipStep, abortWorkflow, } from "./engine";
|
|
11
|
+
export { WORKFLOW_CONTINUATION_MARKER } from "./hook";
|
|
12
|
+
export type { WorkflowHookResult } from "./hook";
|
|
13
|
+
export { parseWorkflowArgs, handleRunWorkflow, checkWorkflowContinuation } from "./hook";
|
|
14
|
+
export type { WorkflowCommandResult } from "./commands";
|
|
15
|
+
export { handleWorkflowCommand } from "./commands";
|