@fabriccode/weave 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 (120) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +309 -0
  3. package/dist/agents/agent-builder.d.ts +24 -0
  4. package/dist/agents/builtin-agents.d.ts +32 -0
  5. package/dist/agents/custom-agent-factory.d.ts +24 -0
  6. package/dist/agents/dynamic-prompt-builder.d.ts +35 -0
  7. package/dist/agents/index.d.ts +12 -0
  8. package/dist/agents/loom/default.d.ts +2 -0
  9. package/dist/agents/loom/index.d.ts +11 -0
  10. package/dist/agents/loom/prompt-composer.d.ts +35 -0
  11. package/dist/agents/model-resolution.d.ts +27 -0
  12. package/dist/agents/pattern/default.d.ts +2 -0
  13. package/dist/agents/pattern/index.d.ts +2 -0
  14. package/dist/agents/prompt-loader.d.ts +9 -0
  15. package/dist/agents/prompt-utils.d.ts +2 -0
  16. package/dist/agents/shuttle/default.d.ts +2 -0
  17. package/dist/agents/shuttle/index.d.ts +2 -0
  18. package/dist/agents/spindle/default.d.ts +2 -0
  19. package/dist/agents/spindle/index.d.ts +2 -0
  20. package/dist/agents/tapestry/default.d.ts +2 -0
  21. package/dist/agents/tapestry/index.d.ts +9 -0
  22. package/dist/agents/tapestry/prompt-composer.d.ts +24 -0
  23. package/dist/agents/thread/default.d.ts +2 -0
  24. package/dist/agents/thread/index.d.ts +2 -0
  25. package/dist/agents/types.d.ts +82 -0
  26. package/dist/agents/warp/default.d.ts +2 -0
  27. package/dist/agents/warp/index.d.ts +2 -0
  28. package/dist/agents/weft/default.d.ts +2 -0
  29. package/dist/agents/weft/index.d.ts +2 -0
  30. package/dist/config/index.d.ts +3 -0
  31. package/dist/config/loader.d.ts +2 -0
  32. package/dist/config/merge.d.ts +3 -0
  33. package/dist/config/schema.d.ts +274 -0
  34. package/dist/create-managers.d.ts +21 -0
  35. package/dist/create-tools.d.ts +16 -0
  36. package/dist/features/analytics/adherence.d.ts +10 -0
  37. package/dist/features/analytics/fingerprint.d.ts +33 -0
  38. package/dist/features/analytics/format-metrics.d.ts +10 -0
  39. package/dist/features/analytics/generate-metrics-report.d.ts +17 -0
  40. package/dist/features/analytics/git-diff.d.ts +7 -0
  41. package/dist/features/analytics/index.d.ts +29 -0
  42. package/dist/features/analytics/plan-parser.d.ts +7 -0
  43. package/dist/features/analytics/plan-token-aggregator.d.ts +11 -0
  44. package/dist/features/analytics/session-tracker.d.ts +68 -0
  45. package/dist/features/analytics/storage.d.ts +40 -0
  46. package/dist/features/analytics/suggestions.d.ts +10 -0
  47. package/dist/features/analytics/token-report.d.ts +14 -0
  48. package/dist/features/analytics/types.d.ts +194 -0
  49. package/dist/features/builtin-commands/commands.d.ts +2 -0
  50. package/dist/features/builtin-commands/index.d.ts +2 -0
  51. package/dist/features/builtin-commands/templates/metrics.d.ts +1 -0
  52. package/dist/features/builtin-commands/templates/run-workflow.d.ts +1 -0
  53. package/dist/features/builtin-commands/templates/start-work.d.ts +1 -0
  54. package/dist/features/builtin-commands/types.d.ts +16 -0
  55. package/dist/features/evals/baseline.d.ts +4 -0
  56. package/dist/features/evals/evaluators/deterministic.d.ts +2 -0
  57. package/dist/features/evals/evaluators/llm-judge.d.ts +2 -0
  58. package/dist/features/evals/executors/model-response.d.ts +2 -0
  59. package/dist/features/evals/executors/prompt-renderer.d.ts +2 -0
  60. package/dist/features/evals/index.d.ts +24 -0
  61. package/dist/features/evals/loader.d.ts +8 -0
  62. package/dist/features/evals/reporter.d.ts +2 -0
  63. package/dist/features/evals/runner.d.ts +7 -0
  64. package/dist/features/evals/schema.d.ts +478 -0
  65. package/dist/features/evals/storage.d.ts +7 -0
  66. package/dist/features/evals/targets/builtin-agent-target.d.ts +2 -0
  67. package/dist/features/evals/types.d.ts +223 -0
  68. package/dist/features/skill-loader/discovery.d.ts +12 -0
  69. package/dist/features/skill-loader/fabric-client.d.ts +2 -0
  70. package/dist/features/skill-loader/index.d.ts +6 -0
  71. package/dist/features/skill-loader/loader.d.ts +7 -0
  72. package/dist/features/skill-loader/resolver.d.ts +6 -0
  73. package/dist/features/skill-loader/types.d.ts +18 -0
  74. package/dist/features/work-state/constants.d.ts +8 -0
  75. package/dist/features/work-state/index.d.ts +5 -0
  76. package/dist/features/work-state/storage.d.ts +53 -0
  77. package/dist/features/work-state/types.d.ts +35 -0
  78. package/dist/features/work-state/validation-types.d.ts +26 -0
  79. package/dist/features/work-state/validation.d.ts +9 -0
  80. package/dist/features/workflow/commands.d.ts +17 -0
  81. package/dist/features/workflow/completion.d.ts +31 -0
  82. package/dist/features/workflow/constants.d.ts +12 -0
  83. package/dist/features/workflow/context.d.ts +16 -0
  84. package/dist/features/workflow/discovery.d.ts +19 -0
  85. package/dist/features/workflow/engine.d.ts +49 -0
  86. package/dist/features/workflow/hook.d.ts +47 -0
  87. package/dist/features/workflow/index.d.ts +15 -0
  88. package/dist/features/workflow/schema.d.ts +118 -0
  89. package/dist/features/workflow/storage.d.ts +51 -0
  90. package/dist/features/workflow/types.d.ts +142 -0
  91. package/dist/hooks/context-window-monitor.d.ts +19 -0
  92. package/dist/hooks/create-hooks.d.ts +40 -0
  93. package/dist/hooks/first-message-variant.d.ts +5 -0
  94. package/dist/hooks/index.d.ts +14 -0
  95. package/dist/hooks/keyword-detector.d.ts +8 -0
  96. package/dist/hooks/pattern-md-only.d.ts +13 -0
  97. package/dist/hooks/rules-injector.d.ts +6 -0
  98. package/dist/hooks/session-token-state.d.ts +42 -0
  99. package/dist/hooks/start-work-hook.d.ts +25 -0
  100. package/dist/hooks/verification-reminder.d.ts +22 -0
  101. package/dist/hooks/work-continuation.d.ts +26 -0
  102. package/dist/hooks/write-existing-file-guard.d.ts +14 -0
  103. package/dist/index.d.ts +5 -0
  104. package/dist/index.js +5585 -0
  105. package/dist/managers/background-manager.d.ts +88 -0
  106. package/dist/managers/config-handler.d.ts +54 -0
  107. package/dist/managers/index.d.ts +6 -0
  108. package/dist/managers/skill-mcp-manager.d.ts +30 -0
  109. package/dist/plugin/index.d.ts +1 -0
  110. package/dist/plugin/plugin-interface.d.ts +17 -0
  111. package/dist/plugin/types.d.ts +5 -0
  112. package/dist/shared/agent-display-names.d.ts +31 -0
  113. package/dist/shared/index.d.ts +5 -0
  114. package/dist/shared/log.d.ts +11 -0
  115. package/dist/shared/types.d.ts +6 -0
  116. package/dist/shared/version.d.ts +5 -0
  117. package/dist/tools/index.d.ts +4 -0
  118. package/dist/tools/permissions.d.ts +18 -0
  119. package/dist/tools/registry.d.ts +29 -0
  120. package/package.json +55 -0
@@ -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 .fabric/workflows/ or ~/.config/fabric/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;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Verification reminder hook: builds a prompt that reminds the orchestrator
3
+ * to verify completed work, optionally delegating to Weft for review.
4
+ */
5
+ export interface VerificationInput {
6
+ /** Name of the plan being executed, if any */
7
+ planName?: string;
8
+ /** Progress of the current plan */
9
+ progress?: {
10
+ total: number;
11
+ completed: number;
12
+ };
13
+ }
14
+ export interface VerificationResult {
15
+ /** Verification prompt to inject, or null if not applicable */
16
+ verificationPrompt: string | null;
17
+ }
18
+ /**
19
+ * Build a verification reminder prompt to inject after task completion.
20
+ * Returns a structured reminder for the orchestrator to verify work.
21
+ */
22
+ export declare function buildVerificationReminder(input: VerificationInput): VerificationResult;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Work continuation hook: checks if there's an active plan with remaining tasks
3
+ * and returns a continuation prompt to keep the executor going.
4
+ */
5
+ /**
6
+ * Marker embedded in continuation prompts so that `chat.message` can distinguish
7
+ * continuation-injected messages from user-initiated messages.
8
+ * When a user message arrives WITHOUT this marker (and is not a /start-work command),
9
+ * the plugin auto-pauses work to prevent the infinite continuation loop.
10
+ */
11
+ export declare const CONTINUATION_MARKER = "<!-- weave:continuation -->";
12
+ /** Maximum consecutive continuations without progress before auto-pausing */
13
+ export declare const MAX_STALE_CONTINUATIONS = 3;
14
+ export interface ContinuationInput {
15
+ sessionId: string;
16
+ directory: string;
17
+ }
18
+ export interface ContinuationResult {
19
+ /** Continuation prompt to inject, or null if no active work / plan complete */
20
+ continuationPrompt: string | null;
21
+ }
22
+ /**
23
+ * Check if there's active work that should continue.
24
+ * Returns a continuation prompt if the plan has remaining tasks, null otherwise.
25
+ */
26
+ export declare function checkContinuation(input: ContinuationInput): ContinuationResult;
@@ -0,0 +1,14 @@
1
+ export interface WriteGuardState {
2
+ readFiles: Set<string>;
3
+ }
4
+ export declare function createWriteGuardState(): WriteGuardState;
5
+ export declare function trackFileRead(state: WriteGuardState, filePath: string): void;
6
+ export interface WriteGuardCheckResult {
7
+ allowed: boolean;
8
+ warning?: string;
9
+ }
10
+ export declare function checkWriteAllowed(state: WriteGuardState, filePath: string): WriteGuardCheckResult;
11
+ export declare function createWriteGuard(state: WriteGuardState): {
12
+ trackRead: (filePath: string) => void;
13
+ checkWrite: (filePath: string) => WriteGuardCheckResult;
14
+ };
@@ -0,0 +1,5 @@
1
+ import type { Plugin } from "@fabriccode/plugin";
2
+ declare const WeavePlugin: Plugin;
3
+ export default WeavePlugin;
4
+ export type { WeaveConfig } from "./config/schema";
5
+ export type { WeaveAgentName } from "./agents/types";