@lucasreiners/lead 0.1.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.
- package/README.md +337 -0
- package/dist/agents/agent-builder.d.ts +30 -0
- package/dist/agents/architect/index.d.ts +4 -0
- package/dist/agents/builtin-agents.d.ts +32 -0
- package/dist/agents/code-analyst/index.d.ts +4 -0
- package/dist/agents/cto/index.d.ts +11 -0
- package/dist/agents/custom-agent-factory.d.ts +27 -0
- package/dist/agents/dynamic-prompt-builder.d.ts +22 -0
- package/dist/agents/engineer/index.d.ts +4 -0
- package/dist/agents/executor/index.d.ts +6 -0
- package/dist/agents/guardian/index.d.ts +4 -0
- package/dist/agents/index.d.ts +17 -0
- package/dist/agents/lead/index.d.ts +11 -0
- package/dist/agents/lead-dev/index.d.ts +6 -0
- package/dist/agents/model-resolution.d.ts +44 -0
- package/dist/agents/prompt-loader.d.ts +30 -0
- package/dist/agents/prompt-utils.d.ts +12 -0
- package/dist/agents/researcher/index.d.ts +4 -0
- package/dist/agents/reviewer/index.d.ts +4 -0
- package/dist/agents/scout/index.d.ts +4 -0
- package/dist/agents/tech-lead/index.d.ts +11 -0
- package/dist/agents/tester/index.d.ts +4 -0
- package/dist/agents/types.d.ts +37 -0
- package/dist/config/continuation.d.ts +13 -0
- package/dist/config/index.d.ts +6 -0
- package/dist/config/loader.d.ts +12 -0
- package/dist/config/merge.d.ts +8 -0
- package/dist/config/scaffold.d.ts +12 -0
- package/dist/config/schema.d.ts +140 -0
- package/dist/create-managers.d.ts +32 -0
- package/dist/create-tools.d.ts +24 -0
- package/dist/domain/plans/index.d.ts +2 -0
- package/dist/domain/policy/policy-result.d.ts +23 -0
- package/dist/domain/session/index.d.ts +41 -0
- package/dist/domain/workflows/index.d.ts +4 -0
- package/dist/domain/workflows/workflow-completion.d.ts +9 -0
- package/dist/domain/workflows/workflow-context.d.ts +9 -0
- package/dist/domain/workflows/workflow-repository.d.ts +19 -0
- package/dist/domain/workflows/workflow-service.d.ts +32 -0
- package/dist/features/skill-loader/discovery.d.ts +36 -0
- package/dist/features/skill-loader/index.d.ts +6 -0
- package/dist/features/skill-loader/loader.d.ts +15 -0
- package/dist/features/skill-loader/opencode-client.d.ts +6 -0
- package/dist/features/skill-loader/resolver.d.ts +8 -0
- package/dist/features/skill-loader/types.d.ts +14 -0
- package/dist/features/work-state/constants.d.ts +4 -0
- package/dist/features/work-state/index.d.ts +5 -0
- package/dist/features/work-state/storage.d.ts +20 -0
- package/dist/features/work-state/types.d.ts +16 -0
- package/dist/features/work-state/validation-types.d.ts +8 -0
- package/dist/features/work-state/validation.d.ts +6 -0
- package/dist/features/workflow/commands.d.ts +10 -0
- package/dist/features/workflow/completion.d.ts +5 -0
- package/dist/features/workflow/constants.d.ts +8 -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 +19 -0
- package/dist/features/workflow/hook.d.ts +45 -0
- package/dist/features/workflow/index.d.ts +9 -0
- package/dist/features/workflow/schema.d.ts +43 -0
- package/dist/features/workflow/storage.d.ts +7 -0
- package/dist/features/workflow/types.d.ts +89 -0
- package/dist/hooks/architect-md-only.d.ts +11 -0
- package/dist/hooks/compaction-recovery.d.ts +20 -0
- package/dist/hooks/compaction-todo-preserver.d.ts +21 -0
- package/dist/hooks/context-window-monitor.d.ts +26 -0
- package/dist/hooks/create-hooks.d.ts +45 -0
- package/dist/hooks/first-message-variant.d.ts +23 -0
- package/dist/hooks/index.d.ts +28 -0
- package/dist/hooks/keyword-detector.d.ts +17 -0
- package/dist/hooks/rules-injector.d.ts +16 -0
- package/dist/hooks/session-token-state.d.ts +31 -0
- package/dist/hooks/start-implementation-hook.d.ts +26 -0
- package/dist/hooks/start-work-hook.d.ts +26 -0
- package/dist/hooks/todo-continuation-enforcer.d.ts +22 -0
- package/dist/hooks/todo-description-override.d.ts +10 -0
- package/dist/hooks/todo-writer.d.ts +20 -0
- package/dist/hooks/verification-reminder.d.ts +21 -0
- package/dist/hooks/work-continuation.d.ts +23 -0
- package/dist/hooks/write-existing-file-guard.d.ts +34 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +3811 -0
- package/dist/infrastructure/fs/config-fs-loader.d.ts +6 -0
- package/dist/managers/background-manager.d.ts +48 -0
- package/dist/managers/config-handler.d.ts +31 -0
- package/dist/managers/index.d.ts +6 -0
- package/dist/managers/skill-mcp-manager.d.ts +31 -0
- package/dist/plugin/index.d.ts +2 -0
- package/dist/plugin/plugin-interface.d.ts +7 -0
- package/dist/plugin/types.d.ts +18 -0
- package/dist/runtime/opencode/plugin-adapter.d.ts +17 -0
- package/dist/shared/agent-display-names.d.ts +3 -0
- package/dist/shared/index.d.ts +6 -0
- package/dist/shared/log.d.ts +9 -0
- package/dist/shared/resolve-safe-path.d.ts +7 -0
- package/dist/shared/types.d.ts +3 -0
- package/dist/shared/version.d.ts +1 -0
- package/package.json +39 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { WorkflowInstance, WorkflowStepDefinition, WorkflowDefinition } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Substitute template variables in a prompt string.
|
|
4
|
+
* Supported variables:
|
|
5
|
+
* {{instance.goal}} — user's stated goal
|
|
6
|
+
* {{instance.slug}} — URL-safe slug of goal
|
|
7
|
+
* {{instance.instance_id}} — workflow instance ID
|
|
8
|
+
* {{artifacts.X}} — artifact value by name
|
|
9
|
+
* {{step.id}} — current step ID
|
|
10
|
+
* {{step.name}} — current step name
|
|
11
|
+
*/
|
|
12
|
+
export declare function substituteTemplateVars(template: string, instance: WorkflowInstance, stepDef: WorkflowStepDefinition): string;
|
|
13
|
+
/**
|
|
14
|
+
* Build the full step context prompt including goal, step info, and previous artifacts.
|
|
15
|
+
*/
|
|
16
|
+
export declare function buildStepContext(instance: WorkflowInstance, stepDef: WorkflowStepDefinition, definition: WorkflowDefinition): string;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { DiscoveredWorkflow } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Parse and validate a workflow definition from a JSONC file.
|
|
4
|
+
* Returns null if invalid.
|
|
5
|
+
*/
|
|
6
|
+
export declare function parseWorkflowFile(filePath: string, scope: DiscoveredWorkflow["scope"]): DiscoveredWorkflow | null;
|
|
7
|
+
export interface DiscoverWorkflowsOptions {
|
|
8
|
+
projectDirectory: string;
|
|
9
|
+
customDirs?: string[];
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Discover workflow definitions from:
|
|
13
|
+
* 1. User: ~/.config/opencode/workflows/
|
|
14
|
+
* 2. Project: {project}/.opencode/workflows/
|
|
15
|
+
* 3. Custom dirs (from config)
|
|
16
|
+
*
|
|
17
|
+
* Later scopes override earlier ones by workflow name.
|
|
18
|
+
*/
|
|
19
|
+
export declare function discoverWorkflows(options: DiscoverWorkflowsOptions): DiscoveredWorkflow[];
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { WorkflowDefinition, EngineAction, CompletionContext } from "./types";
|
|
2
|
+
export interface StartWorkflowInput {
|
|
3
|
+
definition: WorkflowDefinition;
|
|
4
|
+
definitionPath: string;
|
|
5
|
+
goal: string;
|
|
6
|
+
sessionId: string;
|
|
7
|
+
directory: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function startWorkflow(input: StartWorkflowInput): EngineAction;
|
|
10
|
+
export interface CheckAndAdvanceInput {
|
|
11
|
+
directory: string;
|
|
12
|
+
context: Omit<CompletionContext, "config" | "artifacts">;
|
|
13
|
+
definition: WorkflowDefinition;
|
|
14
|
+
}
|
|
15
|
+
export declare function checkAndAdvance(input: CheckAndAdvanceInput): EngineAction;
|
|
16
|
+
export declare function pauseWorkflow(directory: string, reason?: string): boolean;
|
|
17
|
+
export declare function resumeWorkflow(directory: string, definition: WorkflowDefinition): EngineAction;
|
|
18
|
+
export declare function skipStep(directory: string, definition: WorkflowDefinition): EngineAction;
|
|
19
|
+
export declare function abortWorkflow(directory: string): boolean;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { EngineAction } from "./types";
|
|
2
|
+
export interface RunWorkflowInput {
|
|
3
|
+
promptText: string;
|
|
4
|
+
sessionId: string;
|
|
5
|
+
directory: string;
|
|
6
|
+
customDirs?: string[];
|
|
7
|
+
}
|
|
8
|
+
export interface RunWorkflowResult {
|
|
9
|
+
handled: boolean;
|
|
10
|
+
action?: EngineAction;
|
|
11
|
+
message?: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Parse /run-workflow args: `<workflow-name> "goal text"` or `<workflow-name> goal text`
|
|
15
|
+
*/
|
|
16
|
+
export declare function parseWorkflowArgs(args: string): {
|
|
17
|
+
workflowName: string | null;
|
|
18
|
+
goal: string | null;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Handle /run-workflow command.
|
|
22
|
+
* Supports starting new workflows and resuming active ones.
|
|
23
|
+
*/
|
|
24
|
+
export declare function handleRunWorkflow(input: RunWorkflowInput): Promise<RunWorkflowResult>;
|
|
25
|
+
export interface WorkflowContinuationInput {
|
|
26
|
+
sessionId: string;
|
|
27
|
+
directory: string;
|
|
28
|
+
lastAssistantMessage?: string;
|
|
29
|
+
lastUserMessage?: string;
|
|
30
|
+
customDirs?: string[];
|
|
31
|
+
}
|
|
32
|
+
export interface WorkflowContinuationResult {
|
|
33
|
+
continuationPrompt: string | null;
|
|
34
|
+
switchAgent: string | null;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Check if active workflow step is complete and advance.
|
|
38
|
+
* Called on session.idle hook.
|
|
39
|
+
*/
|
|
40
|
+
export declare function checkWorkflowContinuation(input: WorkflowContinuationInput): Promise<WorkflowContinuationResult>;
|
|
41
|
+
/**
|
|
42
|
+
* Handle inline workflow commands in user messages.
|
|
43
|
+
* Returns a result message or null if not a workflow command.
|
|
44
|
+
*/
|
|
45
|
+
export declare function handleWorkflowCommand(message: string, directory: string): string | null;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type { StepType, CompletionMethod, StepStatus, WorkflowStatus, OnRejectAction, CompletionConfig, StepArtifactRef, StepArtifacts, WorkflowStepDefinition, WorkflowDefinition, StepState, WorkflowInstance, ActiveInstancePointer, CompletionContext, CompletionCheckResult, EngineAction, DiscoveredWorkflow, } from "./types";
|
|
2
|
+
export { WorkflowDefinitionSchema } from "./schema";
|
|
3
|
+
export { discoverWorkflows } from "./discovery";
|
|
4
|
+
export { saveWorkflowInstance, loadWorkflowInstance, loadActiveInstance, setActiveInstance, clearActiveInstance, listInstanceIds, } from "./storage";
|
|
5
|
+
export { buildStepContext, substituteTemplateVars } from "./context";
|
|
6
|
+
export { checkStepCompletion } from "./completion";
|
|
7
|
+
export { startWorkflow, checkAndAdvance, pauseWorkflow, resumeWorkflow, skipStep, abortWorkflow, } from "./engine";
|
|
8
|
+
export { handleRunWorkflow, checkWorkflowContinuation, handleWorkflowCommand, parseWorkflowArgs, } from "./hook";
|
|
9
|
+
export { executeWorkflowCommand } from "./commands";
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const WorkflowDefinitionSchema: z.ZodObject<{
|
|
3
|
+
name: z.ZodString;
|
|
4
|
+
description: z.ZodOptional<z.ZodString>;
|
|
5
|
+
version: z.ZodLiteral<1>;
|
|
6
|
+
steps: z.ZodArray<z.ZodObject<{
|
|
7
|
+
id: z.ZodString;
|
|
8
|
+
name: z.ZodString;
|
|
9
|
+
type: z.ZodEnum<{
|
|
10
|
+
interactive: "interactive";
|
|
11
|
+
autonomous: "autonomous";
|
|
12
|
+
gate: "gate";
|
|
13
|
+
}>;
|
|
14
|
+
agent: z.ZodString;
|
|
15
|
+
prompt: z.ZodString;
|
|
16
|
+
completion: z.ZodObject<{
|
|
17
|
+
method: z.ZodEnum<{
|
|
18
|
+
user_confirm: "user_confirm";
|
|
19
|
+
plan_created: "plan_created";
|
|
20
|
+
plan_complete: "plan_complete";
|
|
21
|
+
review_verdict: "review_verdict";
|
|
22
|
+
agent_signal: "agent_signal";
|
|
23
|
+
}>;
|
|
24
|
+
plan_name: z.ZodOptional<z.ZodString>;
|
|
25
|
+
keywords: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
26
|
+
}, z.core.$strip>;
|
|
27
|
+
artifacts: z.ZodOptional<z.ZodObject<{
|
|
28
|
+
inputs: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
29
|
+
name: z.ZodString;
|
|
30
|
+
description: z.ZodOptional<z.ZodString>;
|
|
31
|
+
}, z.core.$strip>>>;
|
|
32
|
+
outputs: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
33
|
+
name: z.ZodString;
|
|
34
|
+
description: z.ZodOptional<z.ZodString>;
|
|
35
|
+
}, z.core.$strip>>>;
|
|
36
|
+
}, z.core.$strip>>;
|
|
37
|
+
on_reject: z.ZodOptional<z.ZodEnum<{
|
|
38
|
+
pause: "pause";
|
|
39
|
+
fail: "fail";
|
|
40
|
+
}>>;
|
|
41
|
+
}, z.core.$strip>>;
|
|
42
|
+
}, z.core.$strip>;
|
|
43
|
+
export type WorkflowDefinitionInput = z.input<typeof WorkflowDefinitionSchema>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { WorkflowInstance } from "./types";
|
|
2
|
+
export declare function saveWorkflowInstance(dir: string, instance: WorkflowInstance): void;
|
|
3
|
+
export declare function loadWorkflowInstance(dir: string, instanceId: string): WorkflowInstance | null;
|
|
4
|
+
export declare function loadActiveInstance(dir: string): WorkflowInstance | null;
|
|
5
|
+
export declare function setActiveInstance(dir: string, instanceId: string): void;
|
|
6
|
+
export declare function clearActiveInstance(dir: string): void;
|
|
7
|
+
export declare function listInstanceIds(dir: string): string[];
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
export type StepType = "interactive" | "autonomous" | "gate";
|
|
2
|
+
export type CompletionMethod = "user_confirm" | "plan_created" | "plan_complete" | "review_verdict" | "agent_signal";
|
|
3
|
+
export type StepStatus = "pending" | "active" | "awaiting_user" | "completed" | "failed" | "skipped";
|
|
4
|
+
export type WorkflowStatus = "running" | "paused" | "completed" | "failed" | "cancelled";
|
|
5
|
+
export type OnRejectAction = "pause" | "fail";
|
|
6
|
+
export interface CompletionConfig {
|
|
7
|
+
method: CompletionMethod;
|
|
8
|
+
plan_name?: string;
|
|
9
|
+
keywords?: string[];
|
|
10
|
+
}
|
|
11
|
+
export interface StepArtifactRef {
|
|
12
|
+
name: string;
|
|
13
|
+
description?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface StepArtifacts {
|
|
16
|
+
inputs?: StepArtifactRef[];
|
|
17
|
+
outputs?: StepArtifactRef[];
|
|
18
|
+
}
|
|
19
|
+
export interface WorkflowStepDefinition {
|
|
20
|
+
id: string;
|
|
21
|
+
name: string;
|
|
22
|
+
type: StepType;
|
|
23
|
+
agent: string;
|
|
24
|
+
prompt: string;
|
|
25
|
+
completion: CompletionConfig;
|
|
26
|
+
artifacts?: StepArtifacts;
|
|
27
|
+
on_reject?: OnRejectAction;
|
|
28
|
+
}
|
|
29
|
+
export interface WorkflowDefinition {
|
|
30
|
+
name: string;
|
|
31
|
+
description?: string;
|
|
32
|
+
version: number;
|
|
33
|
+
steps: WorkflowStepDefinition[];
|
|
34
|
+
}
|
|
35
|
+
export interface StepState {
|
|
36
|
+
id: string;
|
|
37
|
+
status: StepStatus;
|
|
38
|
+
started_at?: string;
|
|
39
|
+
completed_at?: string;
|
|
40
|
+
verdict?: "approve" | "reject";
|
|
41
|
+
error?: string;
|
|
42
|
+
artifacts?: Record<string, string>;
|
|
43
|
+
summary?: string;
|
|
44
|
+
}
|
|
45
|
+
export interface WorkflowInstance {
|
|
46
|
+
instance_id: string;
|
|
47
|
+
definition_id: string;
|
|
48
|
+
definition_name: string;
|
|
49
|
+
definition_path: string;
|
|
50
|
+
goal: string;
|
|
51
|
+
slug: string;
|
|
52
|
+
status: WorkflowStatus;
|
|
53
|
+
started_at: string;
|
|
54
|
+
ended_at?: string;
|
|
55
|
+
session_ids: string[];
|
|
56
|
+
current_step_id: string;
|
|
57
|
+
steps: Record<string, StepState>;
|
|
58
|
+
artifacts: Record<string, string>;
|
|
59
|
+
pause_reason?: string;
|
|
60
|
+
}
|
|
61
|
+
export interface ActiveInstancePointer {
|
|
62
|
+
instance_id: string;
|
|
63
|
+
}
|
|
64
|
+
export interface CompletionContext {
|
|
65
|
+
lastAssistantMessage?: string;
|
|
66
|
+
lastUserMessage?: string;
|
|
67
|
+
directory: string;
|
|
68
|
+
config: CompletionConfig;
|
|
69
|
+
artifacts: Record<string, string>;
|
|
70
|
+
}
|
|
71
|
+
export interface CompletionCheckResult {
|
|
72
|
+
complete: boolean;
|
|
73
|
+
verdict?: "approve" | "reject";
|
|
74
|
+
artifacts?: Record<string, string>;
|
|
75
|
+
summary?: string;
|
|
76
|
+
reason?: string;
|
|
77
|
+
}
|
|
78
|
+
export type EngineActionType = "inject_prompt" | "switch_agent" | "pause" | "complete" | "none";
|
|
79
|
+
export interface EngineAction {
|
|
80
|
+
type: EngineActionType;
|
|
81
|
+
prompt?: string;
|
|
82
|
+
agent?: string;
|
|
83
|
+
reason?: string;
|
|
84
|
+
}
|
|
85
|
+
export interface DiscoveredWorkflow {
|
|
86
|
+
definition: WorkflowDefinition;
|
|
87
|
+
path: string;
|
|
88
|
+
scope: "project" | "user";
|
|
89
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { PolicyResult } from "../domain/policy/policy-result";
|
|
2
|
+
export interface ArchitectGuardInput {
|
|
3
|
+
toolName: string;
|
|
4
|
+
args: Record<string, unknown>;
|
|
5
|
+
agentName?: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Check if an architect tool call violates the md-only rule.
|
|
9
|
+
* Returns deny if architect tries to write outside .lead/ or to non-.md files.
|
|
10
|
+
*/
|
|
11
|
+
export declare function checkArchitectWrite(input: ArchitectGuardInput): PolicyResult;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compaction recovery hook.
|
|
3
|
+
* After context compaction, injects a recovery prompt with active work context.
|
|
4
|
+
* This ensures the agent doesn't lose track of ongoing work.
|
|
5
|
+
*/
|
|
6
|
+
export interface CompactionRecoveryOptions {
|
|
7
|
+
/** Current session ID */
|
|
8
|
+
sessionId: string;
|
|
9
|
+
/** Working directory */
|
|
10
|
+
directory: string;
|
|
11
|
+
}
|
|
12
|
+
export interface CompactionRecoveryResult {
|
|
13
|
+
/** Recovery prompt to inject, or null if no active work */
|
|
14
|
+
recoveryPrompt: string | null;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Build a recovery prompt after context compaction.
|
|
18
|
+
* Summarizes the current work state so the agent knows what it was doing.
|
|
19
|
+
*/
|
|
20
|
+
export declare function checkCompactionRecovery(options: CompactionRecoveryOptions): CompactionRecoveryResult;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compaction todo preserver.
|
|
3
|
+
* During session compaction, preserves active todo state so it isn't lost.
|
|
4
|
+
*/
|
|
5
|
+
import type { TodoItem } from "./todo-continuation-enforcer";
|
|
6
|
+
/**
|
|
7
|
+
* Save the current todo state for a session before compaction.
|
|
8
|
+
*/
|
|
9
|
+
export declare function saveTodoStateForCompaction(sessionId: string, todos: TodoItem[]): void;
|
|
10
|
+
/**
|
|
11
|
+
* Get the preserved todo state for a session after compaction.
|
|
12
|
+
*/
|
|
13
|
+
export declare function getPreservedTodoState(sessionId: string): TodoItem[] | null;
|
|
14
|
+
/**
|
|
15
|
+
* Clear the preserved todo state for a session.
|
|
16
|
+
*/
|
|
17
|
+
export declare function clearPreservedTodoState(sessionId: string): void;
|
|
18
|
+
/**
|
|
19
|
+
* Build a prompt that reminds the agent of its preserved todo state after compaction.
|
|
20
|
+
*/
|
|
21
|
+
export declare function buildTodoPreservationPrompt(sessionId: string): string | null;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context window monitor.
|
|
3
|
+
* Warns when token usage approaches model context limits.
|
|
4
|
+
*/
|
|
5
|
+
export interface TokenUsage {
|
|
6
|
+
inputTokens: number;
|
|
7
|
+
outputTokens: number;
|
|
8
|
+
contextWindow: number;
|
|
9
|
+
}
|
|
10
|
+
export type ContextWindowSeverity = "ok" | "warning" | "critical";
|
|
11
|
+
export interface ContextWindowCheckResult {
|
|
12
|
+
severity: ContextWindowSeverity;
|
|
13
|
+
usagePercent: number;
|
|
14
|
+
message?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface ContextWindowThresholds {
|
|
17
|
+
/** Percentage at which to warn (default 0.75) */
|
|
18
|
+
warningPercent?: number;
|
|
19
|
+
/** Percentage at which to issue critical warning (default 0.9) */
|
|
20
|
+
criticalPercent?: number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Check if token usage is approaching context window limits.
|
|
24
|
+
* Returns severity and an optional warning message.
|
|
25
|
+
*/
|
|
26
|
+
export declare function checkContextWindow(usage: TokenUsage, thresholds?: ContextWindowThresholds): ContextWindowCheckResult;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { checkContextWindow } from "./context-window-monitor";
|
|
2
|
+
import { createWriteGuard } from "./write-existing-file-guard";
|
|
3
|
+
import { shouldApplyVariant, markApplied, markSessionCreated, clearSession } from "./first-message-variant";
|
|
4
|
+
import { processMessageForKeywords } from "./keyword-detector";
|
|
5
|
+
import { checkArchitectWrite } from "./architect-md-only";
|
|
6
|
+
import { handleStartImplementation } from "./start-implementation-hook";
|
|
7
|
+
import { checkContinuation } from "./work-continuation";
|
|
8
|
+
import { checkCompactionRecovery } from "./compaction-recovery";
|
|
9
|
+
import { buildVerificationReminder } from "./verification-reminder";
|
|
10
|
+
import { applyTodoDescriptionOverride } from "./todo-description-override";
|
|
11
|
+
import { checkStaleTodos } from "./todo-continuation-enforcer";
|
|
12
|
+
import { buildTodoPreservationPrompt } from "./compaction-todo-preserver";
|
|
13
|
+
import { captureToDoWrite } from "./todo-writer";
|
|
14
|
+
import { updateTokenState } from "./session-token-state";
|
|
15
|
+
import type { LeadConfig } from "../config/schema";
|
|
16
|
+
import type { ResolvedContinuationConfig } from "../config/continuation";
|
|
17
|
+
export interface CreateHooksArgs {
|
|
18
|
+
pluginConfig: LeadConfig;
|
|
19
|
+
continuation: ResolvedContinuationConfig;
|
|
20
|
+
directory: string;
|
|
21
|
+
}
|
|
22
|
+
export interface CreatedHooks {
|
|
23
|
+
checkContextWindow: typeof checkContextWindow;
|
|
24
|
+
createWriteGuard: typeof createWriteGuard;
|
|
25
|
+
shouldApplyVariant: typeof shouldApplyVariant;
|
|
26
|
+
markApplied: typeof markApplied;
|
|
27
|
+
markSessionCreated: typeof markSessionCreated;
|
|
28
|
+
clearSession: typeof clearSession;
|
|
29
|
+
processMessageForKeywords: typeof processMessageForKeywords;
|
|
30
|
+
checkArchitectWrite: typeof checkArchitectWrite;
|
|
31
|
+
handleStartImplementation: typeof handleStartImplementation;
|
|
32
|
+
checkContinuation: typeof checkContinuation;
|
|
33
|
+
checkCompactionRecovery: typeof checkCompactionRecovery;
|
|
34
|
+
buildVerificationReminder: typeof buildVerificationReminder;
|
|
35
|
+
applyTodoDescriptionOverride: typeof applyTodoDescriptionOverride;
|
|
36
|
+
checkStaleTodos: typeof checkStaleTodos;
|
|
37
|
+
buildTodoPreservationPrompt: typeof buildTodoPreservationPrompt;
|
|
38
|
+
captureToDoWrite: typeof captureToDoWrite;
|
|
39
|
+
updateTokenState: typeof updateTokenState;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Create all hook instances, respecting disabled_hooks configuration.
|
|
43
|
+
* Disabled hooks return null in the returned object.
|
|
44
|
+
*/
|
|
45
|
+
export declare function createHooks(args: CreateHooksArgs): CreatedHooks;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* First message variant.
|
|
3
|
+
* Applies variant prompts to the first message in a session.
|
|
4
|
+
* Ensures that special context is only injected once per session.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Check if a variant prompt should be applied for this session and agent.
|
|
8
|
+
* Returns true only on the first message in a new session.
|
|
9
|
+
*/
|
|
10
|
+
export declare function shouldApplyVariant(sessionId: string, _agentName?: string): boolean;
|
|
11
|
+
/** Mark that the variant has been applied for this session */
|
|
12
|
+
export declare function markApplied(sessionId: string): void;
|
|
13
|
+
/** Mark that a session has been created (becomes eligible for variant) */
|
|
14
|
+
export declare function markSessionCreated(sessionId: string): void;
|
|
15
|
+
/** Clear tracking state for a session (e.g., when session ends) */
|
|
16
|
+
export declare function clearSession(sessionId: string): void;
|
|
17
|
+
/** Get the current state of session tracking (for testing) */
|
|
18
|
+
export declare function getSessionState(): {
|
|
19
|
+
appliedSessions: Set<string>;
|
|
20
|
+
createdSessions: Set<string>;
|
|
21
|
+
};
|
|
22
|
+
/** Reset all state (for testing) */
|
|
23
|
+
export declare function resetSessionState(): void;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export { createHooks } from "./create-hooks";
|
|
2
|
+
export type { CreateHooksArgs, CreatedHooks } from "./create-hooks";
|
|
3
|
+
export { checkContextWindow } from "./context-window-monitor";
|
|
4
|
+
export type { TokenUsage, ContextWindowSeverity, ContextWindowCheckResult, ContextWindowThresholds, } from "./context-window-monitor";
|
|
5
|
+
export { createWriteGuard } from "./write-existing-file-guard";
|
|
6
|
+
export type { WriteGuard, WriteGuardCheckResult } from "./write-existing-file-guard";
|
|
7
|
+
export { shouldInjectRules, getRulesForFile } from "./rules-injector";
|
|
8
|
+
export { shouldApplyVariant, markApplied, markSessionCreated, clearSession, } from "./first-message-variant";
|
|
9
|
+
export { processMessageForKeywords } from "./keyword-detector";
|
|
10
|
+
export type { DetectedKeyword, KeywordDetectionResult } from "./keyword-detector";
|
|
11
|
+
export { checkArchitectWrite } from "./architect-md-only";
|
|
12
|
+
export type { ArchitectGuardInput } from "./architect-md-only";
|
|
13
|
+
export { handleStartImplementation } from "./start-implementation-hook";
|
|
14
|
+
export type { StartImplementationOptions, StartImplementationResult } from "./start-implementation-hook";
|
|
15
|
+
export { checkContinuation } from "./work-continuation";
|
|
16
|
+
export type { WorkContinuationOptions, WorkContinuationResult } from "./work-continuation";
|
|
17
|
+
export { checkCompactionRecovery } from "./compaction-recovery";
|
|
18
|
+
export type { CompactionRecoveryOptions, CompactionRecoveryResult } from "./compaction-recovery";
|
|
19
|
+
export { buildVerificationReminder } from "./verification-reminder";
|
|
20
|
+
export type { VerificationReminderOptions, VerificationReminderResult, } from "./verification-reminder";
|
|
21
|
+
export { applyTodoDescriptionOverride } from "./todo-description-override";
|
|
22
|
+
export { checkStaleTodos } from "./todo-continuation-enforcer";
|
|
23
|
+
export type { TodoItem, TodoContinuationResult } from "./todo-continuation-enforcer";
|
|
24
|
+
export { saveTodoStateForCompaction, getPreservedTodoState, clearPreservedTodoState, buildTodoPreservationPrompt, } from "./compaction-todo-preserver";
|
|
25
|
+
export { updateTokenState, getTokenState, resetTokenState } from "./session-token-state";
|
|
26
|
+
export type { TokenStateEntry } from "./session-token-state";
|
|
27
|
+
export { captureToDoWrite } from "./todo-writer";
|
|
28
|
+
export type { TodoWriterHookInput, TodoWriterHookResult } from "./todo-writer";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keyword detector.
|
|
3
|
+
* Detects workflow-related keywords in user messages.
|
|
4
|
+
*/
|
|
5
|
+
export type DetectedKeyword = "run-workflow" | "implement" | "workflow-pause" | "workflow-skip" | "workflow-abort" | "workflow-status" | "workflow-resume";
|
|
6
|
+
export interface KeywordDetectionResult {
|
|
7
|
+
/** All detected keywords */
|
|
8
|
+
keywords: DetectedKeyword[];
|
|
9
|
+
/** The primary (first detected) keyword */
|
|
10
|
+
primary?: DetectedKeyword;
|
|
11
|
+
/** Arguments following the primary keyword */
|
|
12
|
+
args?: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Process a user message and detect workflow-related keywords.
|
|
16
|
+
*/
|
|
17
|
+
export declare function processMessageForKeywords(message: string): KeywordDetectionResult;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface RulesInjectorResult {
|
|
2
|
+
/** Combined rules content to inject */
|
|
3
|
+
content: string;
|
|
4
|
+
/** Paths of rules files that matched */
|
|
5
|
+
matchedRules: string[];
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Check if a tool/file combination should receive rules injection.
|
|
9
|
+
* Rules are injected for file-reading and file-writing tools.
|
|
10
|
+
*/
|
|
11
|
+
export declare function shouldInjectRules(toolName: string, _filePath?: string): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Get rules content matching the given file path from the rules directory.
|
|
14
|
+
* Rules files in `.opencode/rules/` with names that match the file's extension or path.
|
|
15
|
+
*/
|
|
16
|
+
export declare function getRulesForFile(filePath: string, directory: string): Promise<RulesInjectorResult>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session token state tracker.
|
|
3
|
+
* Tracks token usage per session for context window monitoring.
|
|
4
|
+
*/
|
|
5
|
+
export interface TokenStateEntry {
|
|
6
|
+
sessionId: string;
|
|
7
|
+
inputTokens: number;
|
|
8
|
+
outputTokens: number;
|
|
9
|
+
contextWindow: number;
|
|
10
|
+
lastUpdatedAt: Date;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Update token usage for a session.
|
|
14
|
+
*/
|
|
15
|
+
export declare function updateTokenState(sessionId: string, delta: {
|
|
16
|
+
inputTokens?: number;
|
|
17
|
+
outputTokens?: number;
|
|
18
|
+
contextWindow?: number;
|
|
19
|
+
}): TokenStateEntry;
|
|
20
|
+
/**
|
|
21
|
+
* Get current token state for a session.
|
|
22
|
+
*/
|
|
23
|
+
export declare function getTokenState(sessionId: string): TokenStateEntry | null;
|
|
24
|
+
/**
|
|
25
|
+
* Reset token state for a session.
|
|
26
|
+
*/
|
|
27
|
+
export declare function resetTokenState(sessionId: string): void;
|
|
28
|
+
/**
|
|
29
|
+
* Get all tracked sessions.
|
|
30
|
+
*/
|
|
31
|
+
export declare function getAllTokenStates(): TokenStateEntry[];
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Start-implementation hook.
|
|
3
|
+
* Handles the `/implement` command.
|
|
4
|
+
* Finds the plan file, creates work state, and returns a prompt directing executor to begin.
|
|
5
|
+
*/
|
|
6
|
+
export interface StartImplementationOptions {
|
|
7
|
+
/** The command arguments (plan name or path) */
|
|
8
|
+
args: string;
|
|
9
|
+
/** Current session ID */
|
|
10
|
+
sessionId: string;
|
|
11
|
+
/** Working directory */
|
|
12
|
+
directory: string;
|
|
13
|
+
/** Optional git SHA at start */
|
|
14
|
+
startSha?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface StartImplementationResult {
|
|
17
|
+
/** Prompt to inject into the session */
|
|
18
|
+
prompt: string | null;
|
|
19
|
+
/** Error message if the command failed */
|
|
20
|
+
error?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Handle the /implement command.
|
|
24
|
+
* Finds the plan file and creates work state with reference to it.
|
|
25
|
+
*/
|
|
26
|
+
export declare function handleStartImplementation(options: StartImplementationOptions): Promise<StartImplementationResult>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Start-work hook.
|
|
3
|
+
* Handles the `/implement` command.
|
|
4
|
+
* Finds the plan file, creates work state, and returns a prompt directing executor to begin.
|
|
5
|
+
*/
|
|
6
|
+
export interface StartWorkOptions {
|
|
7
|
+
/** The command arguments (plan name or path) */
|
|
8
|
+
args: string;
|
|
9
|
+
/** Current session ID */
|
|
10
|
+
sessionId: string;
|
|
11
|
+
/** Working directory */
|
|
12
|
+
directory: string;
|
|
13
|
+
/** Optional git SHA at start */
|
|
14
|
+
startSha?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface StartWorkResult {
|
|
17
|
+
/** Prompt to inject into the session */
|
|
18
|
+
prompt: string | null;
|
|
19
|
+
/** Error message if the command failed */
|
|
20
|
+
error?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Handle the /implement command.
|
|
24
|
+
* Finds the plan file and creates work state with reference to it.
|
|
25
|
+
*/
|
|
26
|
+
export declare function handleStartWork(options: StartWorkOptions): Promise<StartWorkResult>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Todo continuation enforcer.
|
|
3
|
+
* Detects stale in_progress todos and prompts the agent to complete or update them.
|
|
4
|
+
*/
|
|
5
|
+
export interface TodoItem {
|
|
6
|
+
content: string;
|
|
7
|
+
status: "pending" | "in_progress" | "completed" | "cancelled";
|
|
8
|
+
priority: "high" | "medium" | "low";
|
|
9
|
+
}
|
|
10
|
+
export interface TodoContinuationResult {
|
|
11
|
+
/** Whether stale in_progress todos were detected */
|
|
12
|
+
hasStale: boolean;
|
|
13
|
+
/** Prompt to inject if stale todos detected */
|
|
14
|
+
prompt: string | null;
|
|
15
|
+
/** The stale todos that were found */
|
|
16
|
+
staleTodos: TodoItem[];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Check for stale in_progress todos and return a prompt if found.
|
|
20
|
+
* A stale todo is one that has been in_progress but the agent hasn't completed it.
|
|
21
|
+
*/
|
|
22
|
+
export declare function checkStaleTodos(todos: TodoItem[]): TodoContinuationResult;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Todo description override.
|
|
3
|
+
* Overrides the TodoWrite tool description with more specific guidance
|
|
4
|
+
* for the executor agent's todo discipline.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Apply todo description override for the TodoWrite tool.
|
|
8
|
+
* Returns the modified description if applicable.
|
|
9
|
+
*/
|
|
10
|
+
export declare function applyTodoDescriptionOverride(toolName: string, originalDescription: string): string;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Todo writer hook.
|
|
3
|
+
* Intercepts todo write operations for state tracking and validation.
|
|
4
|
+
*/
|
|
5
|
+
import type { TodoItem } from "./todo-continuation-enforcer";
|
|
6
|
+
export interface TodoWriterHookInput {
|
|
7
|
+
toolName: string;
|
|
8
|
+
args: Record<string, unknown>;
|
|
9
|
+
sessionId: string;
|
|
10
|
+
}
|
|
11
|
+
export interface TodoWriterHookResult {
|
|
12
|
+
/** Whether this was a todo write operation */
|
|
13
|
+
captured: boolean;
|
|
14
|
+
/** The todo items that were written */
|
|
15
|
+
todos?: TodoItem[];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Intercept a tool call and capture todo state if it's a TodoWrite operation.
|
|
19
|
+
*/
|
|
20
|
+
export declare function captureToDoWrite(input: TodoWriterHookInput): TodoWriterHookResult;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Verification reminder.
|
|
3
|
+
* Reminds agents to run verification steps after implementation tasks.
|
|
4
|
+
*/
|
|
5
|
+
export interface VerificationReminderOptions {
|
|
6
|
+
/** The tool that was just executed */
|
|
7
|
+
toolName: string;
|
|
8
|
+
/** The agent that executed it */
|
|
9
|
+
agentName?: string;
|
|
10
|
+
/** Working directory */
|
|
11
|
+
directory: string;
|
|
12
|
+
}
|
|
13
|
+
export interface VerificationReminderResult {
|
|
14
|
+
/** Reminder text to inject, or null if not applicable */
|
|
15
|
+
reminderText: string | null;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Build a verification reminder after implementation tool use.
|
|
19
|
+
* Only fires for lead-dev/engineer agents after write/edit/bash tools.
|
|
20
|
+
*/
|
|
21
|
+
export declare function buildVerificationReminder(options: VerificationReminderOptions): VerificationReminderResult;
|