@a4hgehad/weave-mcp 0.8.6 → 0.8.7

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 (130) hide show
  1. package/README.md +23 -8
  2. package/dist/agents/agent-builder.d.ts +49 -0
  3. package/dist/agents/builtin-agents.d.ts +34 -0
  4. package/dist/agents/custom-agent-factory.d.ts +24 -0
  5. package/dist/agents/dynamic-prompt-builder.d.ts +35 -0
  6. package/dist/agents/index.d.ts +12 -0
  7. package/dist/agents/loom/default.d.ts +2 -0
  8. package/dist/agents/loom/index.d.ts +11 -0
  9. package/dist/agents/loom/prompt-composer.d.ts +35 -0
  10. package/dist/agents/model-resolution.d.ts +27 -0
  11. package/dist/agents/pattern/default.d.ts +2 -0
  12. package/dist/agents/pattern/index.d.ts +2 -0
  13. package/dist/agents/prompt-loader.d.ts +9 -0
  14. package/dist/agents/prompt-utils.d.ts +2 -0
  15. package/dist/agents/shuttle/default.d.ts +2 -0
  16. package/dist/agents/shuttle/index.d.ts +2 -0
  17. package/dist/agents/spindle/default.d.ts +2 -0
  18. package/dist/agents/spindle/index.d.ts +2 -0
  19. package/dist/agents/tapestry/default.d.ts +2 -0
  20. package/dist/agents/tapestry/index.d.ts +9 -0
  21. package/dist/agents/tapestry/prompt-composer.d.ts +24 -0
  22. package/dist/agents/thread/default.d.ts +2 -0
  23. package/dist/agents/thread/index.d.ts +2 -0
  24. package/dist/agents/types.d.ts +82 -0
  25. package/dist/agents/warp/default.d.ts +2 -0
  26. package/dist/agents/warp/index.d.ts +2 -0
  27. package/dist/agents/weft/default.d.ts +2 -0
  28. package/dist/agents/weft/index.d.ts +2 -0
  29. package/dist/config/index.d.ts +3 -0
  30. package/dist/config/loader.d.ts +2 -0
  31. package/dist/config/merge.d.ts +3 -0
  32. package/dist/config/schema.d.ts +344 -0
  33. package/dist/create-managers.d.ts +21 -0
  34. package/dist/create-tools.d.ts +16 -0
  35. package/dist/features/analytics/adherence.d.ts +10 -0
  36. package/dist/features/analytics/fingerprint.d.ts +33 -0
  37. package/dist/features/analytics/format-metrics.d.ts +10 -0
  38. package/dist/features/analytics/generate-metrics-report.d.ts +17 -0
  39. package/dist/features/analytics/git-diff.d.ts +7 -0
  40. package/dist/features/analytics/index.d.ts +29 -0
  41. package/dist/features/analytics/plan-parser.d.ts +7 -0
  42. package/dist/features/analytics/plan-token-aggregator.d.ts +11 -0
  43. package/dist/features/analytics/session-tracker.d.ts +68 -0
  44. package/dist/features/analytics/storage.d.ts +40 -0
  45. package/dist/features/analytics/suggestions.d.ts +10 -0
  46. package/dist/features/analytics/token-report.d.ts +14 -0
  47. package/dist/features/analytics/types.d.ts +194 -0
  48. package/dist/features/builtin-commands/commands.d.ts +2 -0
  49. package/dist/features/builtin-commands/index.d.ts +2 -0
  50. package/dist/features/builtin-commands/templates/metrics.d.ts +1 -0
  51. package/dist/features/builtin-commands/templates/run-workflow.d.ts +1 -0
  52. package/dist/features/builtin-commands/templates/start-work.d.ts +1 -0
  53. package/dist/features/builtin-commands/types.d.ts +16 -0
  54. package/dist/features/evals/baseline.d.ts +4 -0
  55. package/dist/features/evals/evaluators/deterministic.d.ts +2 -0
  56. package/dist/features/evals/evaluators/llm-judge.d.ts +2 -0
  57. package/dist/features/evals/executors/model-response.d.ts +2 -0
  58. package/dist/features/evals/executors/prompt-renderer.d.ts +2 -0
  59. package/dist/features/evals/index.d.ts +24 -0
  60. package/dist/features/evals/loader.d.ts +8 -0
  61. package/dist/features/evals/reporter.d.ts +2 -0
  62. package/dist/features/evals/runner.d.ts +7 -0
  63. package/dist/features/evals/schema.d.ts +478 -0
  64. package/dist/features/evals/storage.d.ts +7 -0
  65. package/dist/features/evals/targets/builtin-agent-target.d.ts +2 -0
  66. package/dist/features/evals/types.d.ts +223 -0
  67. package/dist/features/skill-loader/discovery.d.ts +12 -0
  68. package/dist/features/skill-loader/index.d.ts +6 -0
  69. package/dist/features/skill-loader/loader.d.ts +7 -0
  70. package/dist/features/skill-loader/opencode-client.d.ts +2 -0
  71. package/dist/features/skill-loader/resolver.d.ts +6 -0
  72. package/dist/features/skill-loader/types.d.ts +18 -0
  73. package/dist/features/task-system/index.d.ts +6 -0
  74. package/dist/features/task-system/storage.d.ts +38 -0
  75. package/dist/features/task-system/todo-sync.d.ts +38 -0
  76. package/dist/features/task-system/tools/index.d.ts +3 -0
  77. package/dist/features/task-system/tools/task-create.d.ts +9 -0
  78. package/dist/features/task-system/tools/task-list.d.ts +5 -0
  79. package/dist/features/task-system/tools/task-update.d.ts +7 -0
  80. package/dist/features/task-system/types.d.ts +63 -0
  81. package/dist/features/work-state/constants.d.ts +8 -0
  82. package/dist/features/work-state/index.d.ts +5 -0
  83. package/dist/features/work-state/storage.d.ts +53 -0
  84. package/dist/features/work-state/types.d.ts +35 -0
  85. package/dist/features/work-state/validation-types.d.ts +26 -0
  86. package/dist/features/work-state/validation.d.ts +9 -0
  87. package/dist/features/workflow/commands.d.ts +17 -0
  88. package/dist/features/workflow/completion.d.ts +31 -0
  89. package/dist/features/workflow/constants.d.ts +12 -0
  90. package/dist/features/workflow/context.d.ts +16 -0
  91. package/dist/features/workflow/discovery.d.ts +19 -0
  92. package/dist/features/workflow/engine.d.ts +49 -0
  93. package/dist/features/workflow/hook.d.ts +47 -0
  94. package/dist/features/workflow/index.d.ts +15 -0
  95. package/dist/features/workflow/schema.d.ts +118 -0
  96. package/dist/features/workflow/storage.d.ts +51 -0
  97. package/dist/features/workflow/types.d.ts +142 -0
  98. package/dist/hooks/context-window-monitor.d.ts +19 -0
  99. package/dist/hooks/create-hooks.d.ts +40 -0
  100. package/dist/hooks/first-message-variant.d.ts +5 -0
  101. package/dist/hooks/index.d.ts +14 -0
  102. package/dist/hooks/keyword-detector.d.ts +8 -0
  103. package/dist/hooks/pattern-md-only.d.ts +13 -0
  104. package/dist/hooks/rules-injector.d.ts +6 -0
  105. package/dist/hooks/session-token-state.d.ts +42 -0
  106. package/dist/hooks/start-work-hook.d.ts +25 -0
  107. package/dist/hooks/verification-reminder.d.ts +22 -0
  108. package/dist/hooks/work-continuation.d.ts +26 -0
  109. package/dist/hooks/write-existing-file-guard.d.ts +14 -0
  110. package/dist/index.d.ts +5 -0
  111. package/dist/index.js +18 -4
  112. package/dist/managers/background-manager.d.ts +88 -0
  113. package/dist/managers/config-handler.d.ts +54 -0
  114. package/dist/managers/index.d.ts +6 -0
  115. package/dist/managers/skill-mcp-manager.d.ts +30 -0
  116. package/dist/mcp/agent-defaults.d.ts +12 -0
  117. package/dist/mcp/index.d.ts +16 -0
  118. package/dist/mcp/types.d.ts +26 -0
  119. package/dist/plugin/index.d.ts +1 -0
  120. package/dist/plugin/plugin-interface.d.ts +17 -0
  121. package/dist/plugin/types.d.ts +5 -0
  122. package/dist/shared/agent-display-names.d.ts +45 -0
  123. package/dist/shared/index.d.ts +5 -0
  124. package/dist/shared/log.d.ts +11 -0
  125. package/dist/shared/types.d.ts +6 -0
  126. package/dist/shared/version.d.ts +5 -0
  127. package/dist/tools/index.d.ts +4 -0
  128. package/dist/tools/permissions.d.ts +18 -0
  129. package/dist/tools/registry.d.ts +29 -0
  130. package/package.json +1 -1
@@ -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";
@@ -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
+ }
@@ -0,0 +1,19 @@
1
+ export interface ContextWindowState {
2
+ usedTokens: number;
3
+ maxTokens: number;
4
+ sessionId: string;
5
+ }
6
+ export interface ContextWindowThresholds {
7
+ warningPct: number;
8
+ criticalPct: number;
9
+ }
10
+ export type ContextWindowAction = "none" | "warn" | "recover";
11
+ export interface ContextWindowCheckResult {
12
+ action: ContextWindowAction;
13
+ usagePct: number;
14
+ message?: string;
15
+ }
16
+ export declare function checkContextWindow(state: ContextWindowState, thresholds?: ContextWindowThresholds): ContextWindowCheckResult;
17
+ export declare function createContextWindowMonitor(thresholds?: ContextWindowThresholds): {
18
+ check: (state: ContextWindowState) => ContextWindowCheckResult;
19
+ };
@@ -0,0 +1,40 @@
1
+ import type { WeaveConfig } from "../config/schema";
2
+ import { checkContextWindow } from "./context-window-monitor";
3
+ import { getRulesForFile, shouldInjectRules } from "./rules-injector";
4
+ import { shouldApplyVariant, markApplied, markSessionCreated, clearSession } from "./first-message-variant";
5
+ import { processMessageForKeywords } from "./keyword-detector";
6
+ import { checkPatternWrite } from "./pattern-md-only";
7
+ import { buildVerificationReminder } from "./verification-reminder";
8
+ export type CreatedHooks = ReturnType<typeof createHooks>;
9
+ export declare function createHooks(args: {
10
+ pluginConfig: WeaveConfig;
11
+ isHookEnabled: (hookName: string) => boolean;
12
+ directory: string;
13
+ analyticsEnabled?: boolean;
14
+ }): {
15
+ checkContextWindow: ((state: Parameters<typeof checkContextWindow>[0]) => import("./context-window-monitor").ContextWindowCheckResult) | null;
16
+ writeGuard: {
17
+ trackRead: (filePath: string) => void;
18
+ checkWrite: (filePath: string) => import("./write-existing-file-guard").WriteGuardCheckResult;
19
+ } | null;
20
+ shouldInjectRules: typeof shouldInjectRules | null;
21
+ getRulesForFile: typeof getRulesForFile | null;
22
+ firstMessageVariant: {
23
+ shouldApplyVariant: typeof shouldApplyVariant;
24
+ markApplied: typeof markApplied;
25
+ markSessionCreated: typeof markSessionCreated;
26
+ clearSession: typeof clearSession;
27
+ } | null;
28
+ processMessageForKeywords: typeof processMessageForKeywords | null;
29
+ patternMdOnly: typeof checkPatternWrite | null;
30
+ startWork: ((promptText: string, sessionId: string) => import("./start-work-hook").StartWorkResult) | null;
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;
38
+ verificationReminder: typeof buildVerificationReminder | null;
39
+ analyticsEnabled: boolean;
40
+ };
@@ -0,0 +1,5 @@
1
+ export declare function markSessionCreated(sessionId: string): void;
2
+ export declare function markApplied(sessionId: string): void;
3
+ export declare function shouldApplyVariant(sessionId: string): boolean;
4
+ export declare function clearSession(sessionId: string): void;
5
+ export declare function clearAll(): void;
@@ -0,0 +1,14 @@
1
+ export { createHooks } from "./create-hooks";
2
+ export type { CreatedHooks } from "./create-hooks";
3
+ export { checkContextWindow, createContextWindowMonitor } from "./context-window-monitor";
4
+ export type { ContextWindowState, ContextWindowThresholds, ContextWindowCheckResult, ContextWindowAction, } from "./context-window-monitor";
5
+ export { createWriteGuard, createWriteGuardState, trackFileRead, checkWriteAllowed, } from "./write-existing-file-guard";
6
+ export type { WriteGuardState, WriteGuardCheckResult } from "./write-existing-file-guard";
7
+ export { shouldInjectRules, getRulesForFile, buildRulesInjection, getDirectoryFromFilePath, findRulesFile, loadRulesForDirectory, } from "./rules-injector";
8
+ export { shouldApplyVariant, markApplied, markSessionCreated, clearSession, clearAll, } from "./first-message-variant";
9
+ export { detectKeywords, buildKeywordInjection, processMessageForKeywords, DEFAULT_KEYWORD_ACTIONS, } from "./keyword-detector";
10
+ export type { KeywordAction } from "./keyword-detector";
11
+ export { buildVerificationReminder } from "./verification-reminder";
12
+ export type { VerificationInput, VerificationResult } from "./verification-reminder";
13
+ export { setContextLimit, updateUsage, getState, clearSession as clearTokenSession, clear as clearAllTokenState, } from "./session-token-state";
14
+ export type { SessionTokenEntry } from "./session-token-state";
@@ -0,0 +1,8 @@
1
+ export interface KeywordAction {
2
+ keyword: string;
3
+ injection: string;
4
+ }
5
+ export declare const DEFAULT_KEYWORD_ACTIONS: KeywordAction[];
6
+ export declare function detectKeywords(message: string, actions?: KeywordAction[]): KeywordAction[];
7
+ export declare function buildKeywordInjection(detected: KeywordAction[]): string | undefined;
8
+ export declare function processMessageForKeywords(message: string, sessionId: string, actions?: KeywordAction[]): string | undefined;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Guard hook that prevents Pattern agent from writing non-.md files
3
+ * or writing outside the .weave/ directory.
4
+ */
5
+ export interface PatternWriteCheckResult {
6
+ allowed: boolean;
7
+ reason?: string;
8
+ }
9
+ /**
10
+ * Check whether a write/edit operation should be allowed for the given agent.
11
+ * Only blocks writes from the "pattern" agent to non-.md files or files outside .weave/.
12
+ */
13
+ export declare function checkPatternWrite(agentName: string, toolName: string, filePath: string): PatternWriteCheckResult;
@@ -0,0 +1,6 @@
1
+ export declare function findRulesFile(directory: string): string | undefined;
2
+ export declare function loadRulesForDirectory(directory: string): string | undefined;
3
+ export declare function shouldInjectRules(toolName: string): boolean;
4
+ export declare function getDirectoryFromFilePath(filePath: string): string;
5
+ export declare function buildRulesInjection(rulesContent: string, directory: string): string;
6
+ export declare function getRulesForFile(filePath: string): string | undefined;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Per-session token state tracker.
3
+ *
4
+ * Bridges the gap between:
5
+ * - `chat.params` hook → provides model context limit (maxTokens)
6
+ * - `message.updated` event → provides latest input token usage (usedTokens)
7
+ *
8
+ * Uses an in-memory Map keyed by sessionId. State resets on plugin restart,
9
+ * which is acceptable — data rebuilds on the next `chat.params` + `message.updated` pair.
10
+ */
11
+ export interface SessionTokenEntry {
12
+ maxTokens: number;
13
+ usedTokens: number;
14
+ }
15
+ /**
16
+ * Store the model's context limit for a session.
17
+ * Called from the `chat.params` hook when a session starts.
18
+ * Does NOT overwrite existing `usedTokens`.
19
+ */
20
+ export declare function setContextLimit(sessionId: string, maxTokens: number): void;
21
+ /**
22
+ * Update the latest input token usage for a session.
23
+ * Called from `message.updated` events with AssistantMessage tokens.
24
+ * Stores the latest value — NOT cumulative across messages.
25
+ * Does NOT overwrite existing `maxTokens`.
26
+ * Only updates when inputTokens > 0 (guards against partial streaming updates).
27
+ */
28
+ export declare function updateUsage(sessionId: string, inputTokens: number): void;
29
+ /**
30
+ * Get the current token state for a session.
31
+ * Returns undefined if the session is unknown.
32
+ */
33
+ export declare function getState(sessionId: string): SessionTokenEntry | undefined;
34
+ /**
35
+ * Remove a session from the tracker.
36
+ * Called on `session.deleted` events.
37
+ */
38
+ export declare function clearSession(sessionId: string): void;
39
+ /**
40
+ * Clear all session state. Used in tests only.
41
+ */
42
+ export declare function clear(): void;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Start-work hook: detects the /start-work command, resolves the target plan,
3
+ * creates/updates work state, and returns context for injection into the prompt.
4
+ */
5
+ import type { ValidationResult } from "../features/work-state";
6
+ export interface StartWorkInput {
7
+ promptText: string;
8
+ sessionId: string;
9
+ directory: string;
10
+ }
11
+ export interface StartWorkResult {
12
+ /** Context to inject into the prompt (plan path, progress, instructions) */
13
+ contextInjection: string | null;
14
+ /** Agent to switch to (always "tapestry" when command is detected) */
15
+ switchAgent: string | null;
16
+ }
17
+ /**
18
+ * Handle the /start-work command.
19
+ * Returns null contextInjection if this message is not a /start-work command.
20
+ */
21
+ export declare function handleStartWork(input: StartWorkInput): StartWorkResult;
22
+ /**
23
+ * Format validation errors and warnings as a markdown string.
24
+ */
25
+ export declare function formatValidationResults(result: ValidationResult): string;