@comma-agents/core 2.0.0-rc.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/LICENSE +21 -0
- package/README.md +18 -0
- package/dist/abortable/abortable.d.ts +5 -0
- package/dist/abortable/abortable.types.d.ts +10 -0
- package/dist/abortable/index.d.ts +2 -0
- package/dist/agents/agent/agent.constants.d.ts +5 -0
- package/dist/agents/agent/agent.d.ts +24 -0
- package/dist/agents/agent/agent.types.d.ts +408 -0
- package/dist/agents/agent/agent.utils.d.ts +107 -0
- package/dist/agents/built-in/user/user-agent.d.ts +32 -0
- package/dist/agents/built-in/user/user-agent.types.d.ts +53 -0
- package/dist/agents/built-in/user/user-agent.utils.d.ts +2 -0
- package/dist/agents/hook-into-agent/hook-into-agent.d.ts +29 -0
- package/dist/agents/hooks/hooks.types.d.ts +64 -0
- package/dist/agents/hooks/hooks.utils.d.ts +9 -0
- package/dist/agents/hooks/index.d.ts +2 -0
- package/dist/agents/loader/index.d.ts +4 -0
- package/dist/agents/loader/loader.d.ts +49 -0
- package/dist/agents/loader/loader.schema.d.ts +270 -0
- package/dist/agents/loader/loader.types.d.ts +15 -0
- package/dist/conversation-context/conversation-context.d.ts +78 -0
- package/dist/conversation-context/conversation-context.types.d.ts +111 -0
- package/dist/conversation-context/conversation-context.utils.d.ts +6 -0
- package/dist/conversation-context/index.d.ts +3 -0
- package/dist/conversation-context/retention/compaction/compaction.constants.d.ts +3 -0
- package/dist/conversation-context/retention/compaction/compaction.d.ts +21 -0
- package/dist/conversation-context/retention/compaction/compaction.types.d.ts +26 -0
- package/dist/conversation-context/retention/compaction/index.d.ts +2 -0
- package/dist/conversation-context/retention/index.d.ts +4 -0
- package/dist/conversation-context/retention/retention.d.ts +9 -0
- package/dist/conversation-context/retention/retention.types.d.ts +90 -0
- package/dist/conversation-context/retention/retention.utils.d.ts +3 -0
- package/dist/conversation-context/retention/rolling-window/index.d.ts +2 -0
- package/dist/conversation-context/retention/rolling-window/rolling-window.d.ts +13 -0
- package/dist/conversation-context/retention/rolling-window/rolling-window.types.d.ts +5 -0
- package/dist/credentials/backends/json-file.d.ts +21 -0
- package/dist/credentials/credentials.constants.d.ts +9 -0
- package/dist/credentials/credentials.d.ts +18 -0
- package/dist/credentials/credentials.schema.d.ts +102 -0
- package/dist/credentials/credentials.types.d.ts +118 -0
- package/dist/credentials/credentials.utils.d.ts +30 -0
- package/dist/credentials/index.d.ts +6 -0
- package/dist/defaults/defaults.d.ts +108 -0
- package/dist/defaults/defaults.types.d.ts +51 -0
- package/dist/defaults/index.d.ts +2 -0
- package/dist/errors/index.d.ts +70 -0
- package/dist/flows/built-in/broadcast/broadcast-flow.constants.d.ts +2 -0
- package/dist/flows/built-in/broadcast/broadcast-flow.d.ts +30 -0
- package/dist/flows/built-in/cycle/cycle-flow.d.ts +53 -0
- package/dist/flows/built-in/sequential/sequential-flow.d.ts +25 -0
- package/dist/flows/flow/flow.d.ts +79 -0
- package/dist/flows/flow/flow.types.d.ts +179 -0
- package/dist/flows/flow/flow.utils.d.ts +18 -0
- package/dist/flows/hook-into-flow/hook-into-flow.d.ts +30 -0
- package/dist/flows/index.d.ts +6 -0
- package/dist/flows/loader/index.d.ts +4 -0
- package/dist/flows/loader/loader.d.ts +55 -0
- package/dist/flows/loader/loader.schema.d.ts +195 -0
- package/dist/flows/loader/loader.types.d.ts +27 -0
- package/dist/guard/guard.d.ts +17 -0
- package/dist/guard/guard.types.d.ts +112 -0
- package/dist/guard/index.d.ts +3 -0
- package/dist/guard/policies.d.ts +28 -0
- package/dist/hooks/built-in/token-tracking/index.d.ts +2 -0
- package/dist/hooks/built-in/token-tracking/token-tracking.constants.d.ts +14 -0
- package/dist/hooks/built-in/token-tracking/token-tracking.d.ts +87 -0
- package/dist/hooks/built-in/token-tracking/token-tracking.types.d.ts +136 -0
- package/dist/hooks/hooks.d.ts +10 -0
- package/dist/hooks/hooks.types.d.ts +11 -0
- package/dist/hooks/index.d.ts +2 -0
- package/dist/index.d.ts +50 -0
- package/dist/index.js +8961 -0
- package/dist/language/index.d.ts +1 -0
- package/dist/language/language.types.d.ts +60 -0
- package/dist/model/index.d.ts +5 -0
- package/dist/model/model.d.ts +63 -0
- package/dist/model/model.types.d.ts +85 -0
- package/dist/model/model.utils.d.ts +151 -0
- package/dist/model/providers/catalog/catalog.d.ts +57 -0
- package/dist/model/providers/catalog/catalog.types.d.ts +50 -0
- package/dist/model/providers/catalog/catalog.utils.d.ts +15 -0
- package/dist/model/providers/catalog/index.d.ts +3 -0
- package/dist/model/providers/index.d.ts +7 -0
- package/dist/model/providers/listers/copilot.d.ts +10 -0
- package/dist/model/providers/listers/index.d.ts +2 -0
- package/dist/model/providers/listers/ollama.d.ts +9 -0
- package/dist/model/providers/providers.d.ts +69 -0
- package/dist/model/providers/providers.types.d.ts +157 -0
- package/dist/model/providers/providers.utils.d.ts +16 -0
- package/dist/prompts/index.d.ts +4 -0
- package/dist/prompts/message-builder.d.ts +89 -0
- package/dist/prompts/prompts.types.d.ts +86 -0
- package/dist/prompts/template/prompt-template.d.ts +22 -0
- package/dist/sandbox/in-sandbox.d.ts +31 -0
- package/dist/sandbox/index.d.ts +4 -0
- package/dist/sandbox/sandbox.constants.d.ts +31 -0
- package/dist/sandbox/sandbox.d.ts +11 -0
- package/dist/sandbox/sandbox.types.d.ts +105 -0
- package/dist/skills/index.d.ts +4 -0
- package/dist/skills/skills.constants.d.ts +10 -0
- package/dist/skills/skills.loader.d.ts +46 -0
- package/dist/skills/skills.registry.d.ts +18 -0
- package/dist/skills/skills.types.d.ts +66 -0
- package/dist/skills/skills.utils.d.ts +37 -0
- package/dist/strategy/discover/discover.d.ts +16 -0
- package/dist/strategy/discover/discover.types.d.ts +70 -0
- package/dist/strategy/discover/discover.utils.d.ts +95 -0
- package/dist/strategy/discover/index.d.ts +3 -0
- package/dist/strategy/exporter/exporter.d.ts +27 -0
- package/dist/strategy/exporter/exporter.types.d.ts +6 -0
- package/dist/strategy/index.d.ts +10 -0
- package/dist/strategy/loader/loader.d.ts +39 -0
- package/dist/strategy/loader/loader.types.d.ts +106 -0
- package/dist/strategy/loader/loader.utils.d.ts +20 -0
- package/dist/strategy/loader/project-loader.d.ts +9 -0
- package/dist/strategy/schema.d.ts +1032 -0
- package/dist/timeline/index.d.ts +4 -0
- package/dist/timeline/projections/conversation-context.d.ts +19 -0
- package/dist/timeline/projections/file-state.d.ts +8 -0
- package/dist/timeline/projections/index.d.ts +3 -0
- package/dist/timeline/timeline.d.ts +11 -0
- package/dist/timeline/timeline.types.d.ts +97 -0
- package/dist/tools/build-tool-system-prompt.d.ts +41 -0
- package/dist/tools/built-in/ask-question/ask-question.d.ts +21 -0
- package/dist/tools/built-in/ask-question/index.d.ts +2 -0
- package/dist/tools/built-in/create-file/create-file.d.ts +18 -0
- package/dist/tools/built-in/create-file/create-file.types.d.ts +11 -0
- package/dist/tools/built-in/create-file/index.d.ts +2 -0
- package/dist/tools/built-in/delete-file/delete-file.constants.d.ts +14 -0
- package/dist/tools/built-in/delete-file/delete-file.d.ts +5 -0
- package/dist/tools/built-in/delete-file/delete-file.types.d.ts +26 -0
- package/dist/tools/built-in/delete-file/index.d.ts +2 -0
- package/dist/tools/built-in/describe-tool.d.ts +61 -0
- package/dist/tools/built-in/edit-file/edit-file.d.ts +46 -0
- package/dist/tools/built-in/edit-file/edit-file.replacers.d.ts +81 -0
- package/dist/tools/built-in/edit-file/edit-file.types.d.ts +59 -0
- package/dist/tools/built-in/edit-file/edit-file.utils.d.ts +70 -0
- package/dist/tools/built-in/edit-file/index.d.ts +2 -0
- package/dist/tools/built-in/glob/glob.constants.d.ts +3 -0
- package/dist/tools/built-in/glob/glob.d.ts +25 -0
- package/dist/tools/built-in/glob/glob.types.d.ts +31 -0
- package/dist/tools/built-in/glob/glob.utils.d.ts +4 -0
- package/dist/tools/built-in/glob/index.d.ts +2 -0
- package/dist/tools/built-in/launch-strategy/index.d.ts +2 -0
- package/dist/tools/built-in/launch-strategy/launch-strategy.d.ts +26 -0
- package/dist/tools/built-in/launch-strategy/launch-strategy.types.d.ts +14 -0
- package/dist/tools/built-in/list-directory/index.d.ts +2 -0
- package/dist/tools/built-in/list-directory/list-directory.constants.d.ts +3 -0
- package/dist/tools/built-in/list-directory/list-directory.d.ts +20 -0
- package/dist/tools/built-in/list-directory/list-directory.types.d.ts +41 -0
- package/dist/tools/built-in/list-directory/list-directory.utils.d.ts +4 -0
- package/dist/tools/built-in/list-skills/index.d.ts +2 -0
- package/dist/tools/built-in/list-skills/list-skills.d.ts +5 -0
- package/dist/tools/built-in/list-skills/list-skills.types.d.ts +10 -0
- package/dist/tools/built-in/list-strategy/index.d.ts +2 -0
- package/dist/tools/built-in/list-strategy/list-strategy.d.ts +14 -0
- package/dist/tools/built-in/list-strategy/list-strategy.types.d.ts +33 -0
- package/dist/tools/built-in/load-skill/index.d.ts +2 -0
- package/dist/tools/built-in/load-skill/load-skill.d.ts +24 -0
- package/dist/tools/built-in/load-skill/load-skill.types.d.ts +15 -0
- package/dist/tools/built-in/lsp-request/index.d.ts +2 -0
- package/dist/tools/built-in/lsp-request/lsp-request.d.ts +4 -0
- package/dist/tools/built-in/lsp-request/lsp-request.schema.d.ts +23 -0
- package/dist/tools/built-in/lsp-request/lsp-request.types.d.ts +4 -0
- package/dist/tools/built-in/move-file/index.d.ts +2 -0
- package/dist/tools/built-in/move-file/move-file.d.ts +21 -0
- package/dist/tools/built-in/move-file/move-file.types.d.ts +12 -0
- package/dist/tools/built-in/read-file/index.d.ts +2 -0
- package/dist/tools/built-in/read-file/read-file.constants.d.ts +1 -0
- package/dist/tools/built-in/read-file/read-file.d.ts +32 -0
- package/dist/tools/built-in/read-file/read-file.types.d.ts +34 -0
- package/dist/tools/built-in/read-file/read-file.utils.d.ts +14 -0
- package/dist/tools/built-in/restore-file/index.d.ts +2 -0
- package/dist/tools/built-in/restore-file/restore-file.d.ts +16 -0
- package/dist/tools/built-in/restore-file/restore-file.types.d.ts +11 -0
- package/dist/tools/built-in/run-command/index.d.ts +2 -0
- package/dist/tools/built-in/run-command/run-command.constants.d.ts +23 -0
- package/dist/tools/built-in/run-command/run-command.d.ts +21 -0
- package/dist/tools/built-in/run-command/run-command.types.d.ts +81 -0
- package/dist/tools/built-in/run-command/run-command.utils.d.ts +37 -0
- package/dist/tools/built-in/search-files/index.d.ts +2 -0
- package/dist/tools/built-in/search-files/search-files.constants.d.ts +5 -0
- package/dist/tools/built-in/search-files/search-files.d.ts +30 -0
- package/dist/tools/built-in/search-files/search-files.types.d.ts +19 -0
- package/dist/tools/built-in/search-files/search-files.utils.d.ts +11 -0
- package/dist/tools/built-in/todo/todo.d.ts +62 -0
- package/dist/tools/built-in/todo/todo.types.d.ts +7 -0
- package/dist/tools/built-in/webfetch/webfetch.constants.d.ts +3 -0
- package/dist/tools/built-in/webfetch/webfetch.d.ts +33 -0
- package/dist/tools/built-in/webfetch/webfetch.types.d.ts +8 -0
- package/dist/tools/built-in/webfetch/webfetch.utils.d.ts +19 -0
- package/dist/tools/built-in/write-file/index.d.ts +2 -0
- package/dist/tools/built-in/write-file/write-file.d.ts +18 -0
- package/dist/tools/built-in/write-file/write-file.types.d.ts +11 -0
- package/dist/tools/define/define-tool.d.ts +15 -0
- package/dist/tools/io/atomic-write.d.ts +37 -0
- package/dist/tools/io/audit-sink.d.ts +29 -0
- package/dist/tools/io/audit.types.d.ts +115 -0
- package/dist/tools/io/audit.utils.d.ts +48 -0
- package/dist/tools/io/binary.d.ts +16 -0
- package/dist/tools/io/bom.d.ts +15 -0
- package/dist/tools/io/diff.d.ts +27 -0
- package/dist/tools/io/hash.d.ts +25 -0
- package/dist/tools/io/index.d.ts +19 -0
- package/dist/tools/io/newline.d.ts +34 -0
- package/dist/tools/io/sandbox-error.d.ts +13 -0
- package/dist/tools/io/session-file-state.d.ts +68 -0
- package/dist/tools/io/stale-file.d.ts +9 -0
- package/dist/tools/io/trash.d.ts +57 -0
- package/dist/tools/launch-strategy.types.d.ts +38 -0
- package/dist/tools/result/index.d.ts +1 -0
- package/dist/tools/result/result.d.ts +47 -0
- package/dist/tools/tool.constants.d.ts +7 -0
- package/dist/tools/tool.registry.d.ts +54 -0
- package/dist/tools/tool.types.d.ts +191 -0
- package/package.json +48 -0
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export type { ProjectedConversationContext } from "./projections";
|
|
2
|
+
export { projectConversationContext, projectFileState, } from "./projections";
|
|
3
|
+
export { createTimeline } from "./timeline";
|
|
4
|
+
export type { Timeline, TimelineEvent, TimelineFilter, } from "./timeline.types";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ModelMessage } from "ai";
|
|
2
|
+
import { type ConversationRecord } from "../../conversation-context";
|
|
3
|
+
import type { TimelineEvent } from "../timeline.types";
|
|
4
|
+
export interface ProjectedConversationContext {
|
|
5
|
+
readonly records: readonly ConversationRecord[];
|
|
6
|
+
readonly messages: readonly ModelMessage[];
|
|
7
|
+
readonly length: number;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Project agent-call events into canonical conversation records.
|
|
11
|
+
*
|
|
12
|
+
* @param events - Timeline events to project.
|
|
13
|
+
* @param agentName - Optional agent name to filter by.
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* const context = projectConversationContext(events, "assistant");
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare function projectConversationContext(events: readonly TimelineEvent[], agentName?: string): ProjectedConversationContext;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { SessionFileState } from "../../tools/io/session-file-state";
|
|
2
|
+
import type { TimelineEvent } from "../timeline.types";
|
|
3
|
+
/**
|
|
4
|
+
* Pure projection: Replays timeline events to build a SessionFileState.
|
|
5
|
+
* This is the exact spiritual successor of `buildSessionFileState` from the tools package,
|
|
6
|
+
* retargeted to project from `tool_mutation` events in the timeline.
|
|
7
|
+
*/
|
|
8
|
+
export declare function projectFileState(events: readonly TimelineEvent[]): SessionFileState;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Timeline, TimelineEvent, TimelineFilter } from "./timeline.types";
|
|
2
|
+
/**
|
|
3
|
+
* Filter an array of timeline events based on common filter parameters.
|
|
4
|
+
* Implemented as a pure helper in accordance with ts-patterns.
|
|
5
|
+
*/
|
|
6
|
+
export declare function filterEvents(events: readonly TimelineEvent[], filter?: TimelineFilter): readonly TimelineEvent[];
|
|
7
|
+
/**
|
|
8
|
+
* Construct a fresh in-memory Timeline stream.
|
|
9
|
+
* Uses a closure to capture state privately.
|
|
10
|
+
*/
|
|
11
|
+
export declare function createTimeline(initialEvents?: readonly TimelineEvent[]): Timeline;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { ConversationRecord, ConversationRetentionEvent } from "../conversation-context";
|
|
2
|
+
/**
|
|
3
|
+
* Union type representing any event recorded on a strategy run's timeline.
|
|
4
|
+
* All events are immutable, timestamped, and conform to this common schema.
|
|
5
|
+
*/
|
|
6
|
+
export type TimelineEvent = {
|
|
7
|
+
readonly type: "run_started";
|
|
8
|
+
readonly ts: string;
|
|
9
|
+
readonly strategyPath: string;
|
|
10
|
+
readonly strategyName: string;
|
|
11
|
+
readonly cwd: string;
|
|
12
|
+
readonly initialInput?: string;
|
|
13
|
+
readonly manifestPath?: string;
|
|
14
|
+
readonly modelOverride?: string;
|
|
15
|
+
} | {
|
|
16
|
+
readonly type: "run_completed";
|
|
17
|
+
readonly ts: string;
|
|
18
|
+
readonly status: "completed" | "error" | "cancelled";
|
|
19
|
+
readonly error?: {
|
|
20
|
+
readonly code: string;
|
|
21
|
+
readonly message: string;
|
|
22
|
+
};
|
|
23
|
+
} | {
|
|
24
|
+
readonly type: "agent_call";
|
|
25
|
+
readonly ts: string;
|
|
26
|
+
readonly record: ConversationRecord;
|
|
27
|
+
} | {
|
|
28
|
+
readonly type: "conversation_retention";
|
|
29
|
+
readonly ts: string;
|
|
30
|
+
readonly event: ConversationRetentionEvent;
|
|
31
|
+
} | {
|
|
32
|
+
readonly type: "user_input";
|
|
33
|
+
readonly ts: string;
|
|
34
|
+
readonly agentName: string;
|
|
35
|
+
readonly text: string;
|
|
36
|
+
readonly source: "human" | "agent";
|
|
37
|
+
} | {
|
|
38
|
+
readonly type: "tool_mutation";
|
|
39
|
+
readonly ts: string;
|
|
40
|
+
readonly agentName: string;
|
|
41
|
+
readonly toolName: string;
|
|
42
|
+
readonly operation: "create" | "update" | "delete" | "move";
|
|
43
|
+
readonly path: string;
|
|
44
|
+
readonly toPath?: string;
|
|
45
|
+
readonly beforeSha256?: string;
|
|
46
|
+
readonly afterSha256?: string;
|
|
47
|
+
readonly diff?: string;
|
|
48
|
+
readonly success: boolean;
|
|
49
|
+
readonly error?: string;
|
|
50
|
+
readonly details?: Readonly<Record<string, unknown>>;
|
|
51
|
+
} | {
|
|
52
|
+
readonly type: "step_started";
|
|
53
|
+
readonly ts: string;
|
|
54
|
+
readonly stepName: string;
|
|
55
|
+
readonly flowName?: string;
|
|
56
|
+
readonly agentName?: string;
|
|
57
|
+
readonly index?: number;
|
|
58
|
+
} | {
|
|
59
|
+
readonly type: "step_completed";
|
|
60
|
+
readonly ts: string;
|
|
61
|
+
readonly stepName: string;
|
|
62
|
+
readonly flowName?: string;
|
|
63
|
+
readonly agentName?: string;
|
|
64
|
+
readonly index?: number;
|
|
65
|
+
} | {
|
|
66
|
+
readonly type: "permission_decision";
|
|
67
|
+
readonly ts: string;
|
|
68
|
+
readonly decision: "allow" | "deny" | "allow-session" | "deny-session";
|
|
69
|
+
readonly agentName?: string;
|
|
70
|
+
readonly toolName?: string;
|
|
71
|
+
readonly resource?: string;
|
|
72
|
+
};
|
|
73
|
+
/** Filter parameters for querying events from a Timeline. */
|
|
74
|
+
export interface TimelineFilter {
|
|
75
|
+
/** Keep only events matching this exact type. */
|
|
76
|
+
readonly type?: TimelineEvent["type"];
|
|
77
|
+
/** Keep only events produced by or involving this agent. */
|
|
78
|
+
readonly agentName?: string;
|
|
79
|
+
/** Keep only events occurring after this ISO-8601 UTC timestamp. */
|
|
80
|
+
readonly since?: string;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Closure-based Timeline stream.
|
|
84
|
+
* Tracks strategy run progress as an append-only sequence of immutable events.
|
|
85
|
+
*/
|
|
86
|
+
export interface Timeline {
|
|
87
|
+
/** Append an event to the timeline. Throws if the event is malformed. */
|
|
88
|
+
append(event: TimelineEvent): void;
|
|
89
|
+
/** Retrieve a read-only list of events, optionally matching a filter. */
|
|
90
|
+
events(filter?: TimelineFilter): readonly TimelineEvent[];
|
|
91
|
+
/** Total number of events currently in the timeline. */
|
|
92
|
+
readonly size: number;
|
|
93
|
+
/** Clears all events from the timeline. */
|
|
94
|
+
clear(): void;
|
|
95
|
+
/** Iterator support for walking events. */
|
|
96
|
+
[Symbol.iterator](): Iterator<TimelineEvent>;
|
|
97
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { ToolContext, ToolDefinition } from "./tool.types";
|
|
2
|
+
/**
|
|
3
|
+
* Options for building tool system prompt contributions.
|
|
4
|
+
*/
|
|
5
|
+
interface BuildToolSystemPromptOptions {
|
|
6
|
+
/** The tool definitions to collect system prompts from. */
|
|
7
|
+
readonly toolDefinitions: Readonly<Record<string, ToolDefinition>>;
|
|
8
|
+
/** ToolContext passed to dynamic systemPrompt functions. */
|
|
9
|
+
readonly toolContext: ToolContext;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Collect and merge system prompt contributions from all tools.
|
|
13
|
+
*
|
|
14
|
+
* Tools can contribute via:
|
|
15
|
+
* - Static string: `systemPrompt: "Always use JSON format."`
|
|
16
|
+
* - Dynamic function: `systemPrompt: async (ctx) => \`CWD: ${ctx.guard.cwd}\``
|
|
17
|
+
*
|
|
18
|
+
* The contributions are merged into a single string, with each tool's
|
|
19
|
+
* contribution prefixed by `## tool-name` for clarity. Only tools with
|
|
20
|
+
* a `systemPrompt` field are included.
|
|
21
|
+
*
|
|
22
|
+
* @returns Merged system prompt string, or undefined if no tools have contributions.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* const toolDefs = { read_file: { systemPrompt: "..." }, ... };
|
|
27
|
+
* const prompt = await buildToolSystemPrompt({ toolDefs, toolContext });
|
|
28
|
+
* // => "## read_file\n..." or undefined
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare function buildToolSystemPrompt(options: BuildToolSystemPromptOptions): Promise<string | undefined>;
|
|
32
|
+
/**
|
|
33
|
+
* Merge multiple system prompt strings into one.
|
|
34
|
+
*
|
|
35
|
+
* Handles undefined values and ensures proper separation between sections.
|
|
36
|
+
* The order of the input array is preserved.
|
|
37
|
+
*
|
|
38
|
+
* @returns Merged string, or undefined if all inputs are undefined/empty.
|
|
39
|
+
*/
|
|
40
|
+
export declare function mergeSystemPrompts(prompts: readonly (string | undefined)[]): string | undefined;
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { ToolDefinition } from "../../tool.types";
|
|
3
|
+
export declare const askQuestionParams: z.ZodObject<{
|
|
4
|
+
question: z.ZodString;
|
|
5
|
+
}, "strip", z.ZodTypeAny, {
|
|
6
|
+
question: string;
|
|
7
|
+
}, {
|
|
8
|
+
question: string;
|
|
9
|
+
}>;
|
|
10
|
+
export interface AskQuestionData {
|
|
11
|
+
readonly response: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Create the `ask_question` tool.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* const askQuestion = createAskQuestionTool();
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare function createAskQuestionTool(): ToolDefinition<typeof askQuestionParams, AskQuestionData>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { ToolDefinition } from "../../tool.types";
|
|
3
|
+
import type { CreateFileData, CreateFileToolConfig } from "./create-file.types";
|
|
4
|
+
declare const createFileParams: z.ZodObject<{
|
|
5
|
+
path: z.ZodString;
|
|
6
|
+
content: z.ZodString;
|
|
7
|
+
createParentDirectories: z.ZodOptional<z.ZodBoolean>;
|
|
8
|
+
}, "strip", z.ZodTypeAny, {
|
|
9
|
+
path: string;
|
|
10
|
+
content: string;
|
|
11
|
+
createParentDirectories?: boolean | undefined;
|
|
12
|
+
}, {
|
|
13
|
+
path: string;
|
|
14
|
+
content: string;
|
|
15
|
+
createParentDirectories?: boolean | undefined;
|
|
16
|
+
}>;
|
|
17
|
+
export declare function createCreateFileTool(config?: CreateFileToolConfig): ToolDefinition<typeof createFileParams, CreateFileData>;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { AuditSink } from "../../io/audit.types";
|
|
2
|
+
export interface CreateFileToolConfig {
|
|
3
|
+
readonly defaultAuditSink?: AuditSink;
|
|
4
|
+
}
|
|
5
|
+
export interface CreateFileData {
|
|
6
|
+
readonly created: true;
|
|
7
|
+
readonly path: string;
|
|
8
|
+
readonly sha256: string;
|
|
9
|
+
readonly sizeBytes: number;
|
|
10
|
+
readonly diff: string;
|
|
11
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const deleteFileParams: z.ZodObject<{
|
|
3
|
+
path: z.ZodString;
|
|
4
|
+
expectedSha256: z.ZodOptional<z.ZodString>;
|
|
5
|
+
permanent: z.ZodOptional<z.ZodBoolean>;
|
|
6
|
+
}, "strip", z.ZodTypeAny, {
|
|
7
|
+
path: string;
|
|
8
|
+
expectedSha256?: string | undefined;
|
|
9
|
+
permanent?: boolean | undefined;
|
|
10
|
+
}, {
|
|
11
|
+
path: string;
|
|
12
|
+
expectedSha256?: string | undefined;
|
|
13
|
+
permanent?: boolean | undefined;
|
|
14
|
+
}>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ToolDefinition } from "../../tool.types";
|
|
2
|
+
import { deleteFileParams } from "./delete-file.constants";
|
|
3
|
+
import type { DeleteFileData, DeleteFileToolConfig } from "./delete-file.types";
|
|
4
|
+
/** Create the `delete_file` tool. */
|
|
5
|
+
export declare function createDeleteFileTool(config?: DeleteFileToolConfig): ToolDefinition<typeof deleteFileParams, DeleteFileData>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { AuditSink } from "../../io/audit.types";
|
|
2
|
+
/** Configuration for `delete_file`. */
|
|
3
|
+
export interface DeleteFileToolConfig {
|
|
4
|
+
/** Default audit sink when `toolContext.auditSink` is undefined. */
|
|
5
|
+
readonly defaultAuditSink?: AuditSink;
|
|
6
|
+
}
|
|
7
|
+
/** Structured payload returned by `delete_file`. */
|
|
8
|
+
export interface DeleteFileData {
|
|
9
|
+
/** Always `true` on success. */
|
|
10
|
+
readonly deleted: true;
|
|
11
|
+
/** Workspace-relative path of the deleted file (echoed). */
|
|
12
|
+
readonly path: string;
|
|
13
|
+
/** SHA-256 of the file's content at deletion time. */
|
|
14
|
+
readonly beforeSha256: string;
|
|
15
|
+
/** Byte length of the deleted content. */
|
|
16
|
+
readonly sizeBytes: number;
|
|
17
|
+
/** Unified diff from file → /dev/null. */
|
|
18
|
+
readonly diff: string;
|
|
19
|
+
/**
|
|
20
|
+
* Absolute path of the trash entry, when the delete was recoverable.
|
|
21
|
+
* Omitted when `permanent: true`.
|
|
22
|
+
*/
|
|
23
|
+
readonly trashedTo?: string;
|
|
24
|
+
/** Whether the delete was permanent (no recovery). */
|
|
25
|
+
readonly permanent: boolean;
|
|
26
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { ToolErrorKind } from "../tool.types";
|
|
2
|
+
/** Single input parameter description. */
|
|
3
|
+
export interface DescribeToolInput {
|
|
4
|
+
/** Parameter name as it appears in the JSON schema. */
|
|
5
|
+
readonly name: string;
|
|
6
|
+
/** Human-readable type, e.g. `"string"`, `"number"`, `"object<string, string>"`. */
|
|
7
|
+
readonly type: string;
|
|
8
|
+
/** Whether the parameter is required. Optional parameters render their default when supplied. */
|
|
9
|
+
readonly required: boolean;
|
|
10
|
+
/** Default value when omitted, rendered as text. Only used when `required: false`. */
|
|
11
|
+
readonly defaultValue?: string;
|
|
12
|
+
/** One-line description of the parameter's semantics. */
|
|
13
|
+
readonly description: string;
|
|
14
|
+
}
|
|
15
|
+
/** Single error-kind row. */
|
|
16
|
+
export interface DescribeToolError {
|
|
17
|
+
/** A {@link ToolErrorKind} this tool may emit. */
|
|
18
|
+
readonly kind: ToolErrorKind;
|
|
19
|
+
/** Why this kind fires and what the model should do next. */
|
|
20
|
+
readonly description: string;
|
|
21
|
+
}
|
|
22
|
+
/** Input to {@link describeTool}. */
|
|
23
|
+
export interface DescribeToolOptions {
|
|
24
|
+
/**
|
|
25
|
+
* One-line purpose sentence (no trailing period required — the helper
|
|
26
|
+
* will not add one). Multi-line purposes are allowed; each entry is
|
|
27
|
+
* rendered as its own paragraph above the `Inputs:` section.
|
|
28
|
+
*/
|
|
29
|
+
readonly purpose: string | readonly string[];
|
|
30
|
+
/** Inputs in declaration order. */
|
|
31
|
+
readonly inputs: readonly DescribeToolInput[];
|
|
32
|
+
/**
|
|
33
|
+
* One or more lines describing the structured `data` payload returned
|
|
34
|
+
* on success. The string `"data"` should NOT be repeated — the helper
|
|
35
|
+
* prefixes the section with `Outputs (\`data\`):`.
|
|
36
|
+
*/
|
|
37
|
+
readonly outputs: string | readonly string[];
|
|
38
|
+
/** Error kinds this tool may surface. */
|
|
39
|
+
readonly errors: readonly DescribeToolError[];
|
|
40
|
+
/**
|
|
41
|
+
* Optional usage examples. Each entry is rendered verbatim on its own
|
|
42
|
+
* line under the `Examples:` heading.
|
|
43
|
+
*/
|
|
44
|
+
readonly examples?: readonly string[];
|
|
45
|
+
/**
|
|
46
|
+
* Optional free-form notes (cross-references to protocols, host
|
|
47
|
+
* platform info for run_command, etc.). Each entry becomes its own
|
|
48
|
+
* line under `Notes:`.
|
|
49
|
+
*/
|
|
50
|
+
readonly notes?: readonly string[];
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Render a tool description in the canonical built-in format.
|
|
54
|
+
*
|
|
55
|
+
* Layout (sections emitted in fixed order):
|
|
56
|
+
* Purpose → Inputs → Outputs → Errors → Examples → Notes.
|
|
57
|
+
* Token-efficient plain-text — no Markdown, no XML — so every provider
|
|
58
|
+
* sees the same content. Deterministic: same options produce the same
|
|
59
|
+
* string, which backs the snapshot test catching accidental drift.
|
|
60
|
+
*/
|
|
61
|
+
export declare function describeTool(options: DescribeToolOptions): string;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { ToolDefinition } from "../../tool.types";
|
|
3
|
+
import type { EditFileData, EditFileToolConfig } from "./edit-file.types";
|
|
4
|
+
export declare const editFileParams: z.ZodObject<{
|
|
5
|
+
path: z.ZodString;
|
|
6
|
+
expectedSha256: z.ZodOptional<z.ZodString>;
|
|
7
|
+
edits: z.ZodArray<z.ZodObject<{
|
|
8
|
+
oldText: z.ZodString;
|
|
9
|
+
newText: z.ZodString;
|
|
10
|
+
expectedOccurrences: z.ZodOptional<z.ZodNumber>;
|
|
11
|
+
}, "strip", z.ZodTypeAny, {
|
|
12
|
+
oldText: string;
|
|
13
|
+
newText: string;
|
|
14
|
+
expectedOccurrences?: number | undefined;
|
|
15
|
+
}, {
|
|
16
|
+
oldText: string;
|
|
17
|
+
newText: string;
|
|
18
|
+
expectedOccurrences?: number | undefined;
|
|
19
|
+
}>, "many">;
|
|
20
|
+
}, "strip", z.ZodTypeAny, {
|
|
21
|
+
path: string;
|
|
22
|
+
edits: {
|
|
23
|
+
oldText: string;
|
|
24
|
+
newText: string;
|
|
25
|
+
expectedOccurrences?: number | undefined;
|
|
26
|
+
}[];
|
|
27
|
+
expectedSha256?: string | undefined;
|
|
28
|
+
}, {
|
|
29
|
+
path: string;
|
|
30
|
+
edits: {
|
|
31
|
+
oldText: string;
|
|
32
|
+
newText: string;
|
|
33
|
+
expectedOccurrences?: number | undefined;
|
|
34
|
+
}[];
|
|
35
|
+
expectedSha256?: string | undefined;
|
|
36
|
+
}>;
|
|
37
|
+
/**
|
|
38
|
+
* Create the `edit_file` tool.
|
|
39
|
+
*
|
|
40
|
+
* @param config - Optional configuration overriding the default audit sink.
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* const editFile = createEditFileTool();
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare function createEditFileTool(config?: EditFileToolConfig): ToolDefinition<typeof editFileParams, EditFileData>;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/** A candidate substring of the snapshot that should be treated as the match. */
|
|
2
|
+
export type ReplacerCandidate = string;
|
|
3
|
+
/**
|
|
4
|
+
* A replacer generator. Yields zero or more candidate substrings of
|
|
5
|
+
* `content` that should be treated as matches for `find`. The caller
|
|
6
|
+
* filters to candidates that actually appear in `content` and picks
|
|
7
|
+
* one as the match.
|
|
8
|
+
*/
|
|
9
|
+
export type Replacer = (content: string, find: string) => Generator<ReplacerCandidate, void, unknown>;
|
|
10
|
+
/**
|
|
11
|
+
* Exact match (the strictest replacer). Yields `find` itself if it appears
|
|
12
|
+
* in `content`, otherwise nothing. Equivalent to the original behaviour;
|
|
13
|
+
* kept in the chain so the same code path covers exact and fallback cases.
|
|
14
|
+
*/
|
|
15
|
+
export declare const exactReplacer: Replacer;
|
|
16
|
+
/**
|
|
17
|
+
* Line-trimmed match. Strips leading/trailing whitespace from each line
|
|
18
|
+
* before comparison so the LLM's slightly-off indentation is forgiven.
|
|
19
|
+
* Yields the *actual* unchanged substring of `content` that lines up,
|
|
20
|
+
* so the eventual replacement preserves the file's original whitespace.
|
|
21
|
+
*/
|
|
22
|
+
export declare const lineTrimmedReplacer: Replacer;
|
|
23
|
+
/**
|
|
24
|
+
* Block-anchor match. When `find` has ≥3 lines, find blocks in
|
|
25
|
+
* `content` whose first and last lines (trimmed) equal the first and
|
|
26
|
+
* last lines of `find` (trimmed). The middle is allowed to differ —
|
|
27
|
+
* use this when the LLM gave us the right "envelope" but maybe wrote
|
|
28
|
+
* the body slightly differently.
|
|
29
|
+
*
|
|
30
|
+
* Only emitted when there is exactly one block-anchor candidate, to
|
|
31
|
+
* avoid silently picking the wrong location.
|
|
32
|
+
*/
|
|
33
|
+
export declare const blockAnchorReplacer: Replacer;
|
|
34
|
+
/**
|
|
35
|
+
* Whitespace-normalized match for SINGLE-LINE finds only. Collapses all
|
|
36
|
+
* whitespace runs in both content and find to single spaces (trimmed),
|
|
37
|
+
* then looks for the normalized find as a normalized line. Yields the
|
|
38
|
+
* original (unchanged) line.
|
|
39
|
+
*
|
|
40
|
+
* Kept conservative — only handles single-line finds because multi-line
|
|
41
|
+
* whitespace normalization gets ambiguous and merges with
|
|
42
|
+
* `lineTrimmedReplacer`'s territory.
|
|
43
|
+
*/
|
|
44
|
+
export declare const whitespaceNormalizedReplacer: Replacer;
|
|
45
|
+
/**
|
|
46
|
+
* The default chain, applied in order. The first replacer to yield a
|
|
47
|
+
* unique candidate wins. Order matters: stricter strategies come first
|
|
48
|
+
* so that exact LLM intent is preferred over heuristic recovery.
|
|
49
|
+
*
|
|
50
|
+
* The chain is intentionally short (4 replacers, not OpenCode's 9).
|
|
51
|
+
* Each extra replacer is another opportunity for a heuristic to
|
|
52
|
+
* "succeed" on something the LLM didn't actually mean — over-eager
|
|
53
|
+
* fallbacks risk silently editing the wrong block. These four cover
|
|
54
|
+
* the trivial cases (indentation drift, single-line whitespace, block
|
|
55
|
+
* envelopes) without venturing into Levenshtein territory.
|
|
56
|
+
*/
|
|
57
|
+
export declare const DEFAULT_REPLACER_CHAIN: readonly Replacer[];
|
|
58
|
+
/**
|
|
59
|
+
* Try the replacer chain in order and return the first unique candidate
|
|
60
|
+
* substring that appears in `content`. Returns `undefined` if no
|
|
61
|
+
* replacer yielded a candidate, or if every replacer that yielded
|
|
62
|
+
* something yielded multiple distinct candidates (ambiguous).
|
|
63
|
+
*
|
|
64
|
+
* Distinguishes:
|
|
65
|
+
* - "no candidates" → caller emits `old_text_not_found`.
|
|
66
|
+
* - "ambiguous" (multiple distinct candidates from a replacer) →
|
|
67
|
+
* caller emits `multiple_matches` with the candidates so the LLM
|
|
68
|
+
* can disambiguate.
|
|
69
|
+
*
|
|
70
|
+
* @param content - The current file snapshot (normalized to LF).
|
|
71
|
+
* @param find - The LLM-supplied `oldText` (normalized to LF).
|
|
72
|
+
* @param replacers - Override the default chain (used by tests).
|
|
73
|
+
*/
|
|
74
|
+
export declare function findFallbackMatch(content: string, find: string, replacers?: readonly Replacer[]): {
|
|
75
|
+
match: string;
|
|
76
|
+
replacerName: string;
|
|
77
|
+
isExact: boolean;
|
|
78
|
+
} | {
|
|
79
|
+
ambiguous: readonly string[];
|
|
80
|
+
replacerName: string;
|
|
81
|
+
} | undefined;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { AuditSink } from "../../io/audit.types";
|
|
2
|
+
export interface EditFileToolConfig {
|
|
3
|
+
/**
|
|
4
|
+
* Default audit sink to use when `ctx.auditSink` is undefined. Tests
|
|
5
|
+
* typically pass `createMemoryAuditSink()` so they can assert on
|
|
6
|
+
* audit entries; production callers should rely on the
|
|
7
|
+
* `buildAgentToolSet` injection path.
|
|
8
|
+
*/
|
|
9
|
+
readonly defaultAuditSink?: AuditSink;
|
|
10
|
+
}
|
|
11
|
+
export interface AppliedEdit {
|
|
12
|
+
/** Index of the edit in the input array. */
|
|
13
|
+
readonly editIndex: number;
|
|
14
|
+
/** Number of occurrences replaced. */
|
|
15
|
+
readonly occurrences: number;
|
|
16
|
+
/**
|
|
17
|
+
* True when the exact substring match failed and a fallback replacer
|
|
18
|
+
* recovered the edit (line-trimmed, whitespace-normalized, or block
|
|
19
|
+
* anchor). Surfaces in the tool's text output so the LLM can spot when
|
|
20
|
+
* its `oldText` was approximate and tighten it next time.
|
|
21
|
+
*/
|
|
22
|
+
readonly usedFallback?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Name of the replacer that produced the match. Always present;
|
|
25
|
+
* `"exactReplacer"` for the strict path.
|
|
26
|
+
*/
|
|
27
|
+
readonly replacerName?: string;
|
|
28
|
+
/**
|
|
29
|
+
* The actual substring of the file that was matched and replaced.
|
|
30
|
+
* Populated only when a fallback was used so the caller can show the
|
|
31
|
+
* LLM exactly what got swapped (the LLM's `oldText` is approximate by
|
|
32
|
+
* definition in that case).
|
|
33
|
+
*/
|
|
34
|
+
readonly matchedText?: string;
|
|
35
|
+
}
|
|
36
|
+
export interface MatchRange {
|
|
37
|
+
/** 1-indexed inclusive line where the match starts. */
|
|
38
|
+
readonly startLine: number;
|
|
39
|
+
/** 1-indexed inclusive line where the match ends. */
|
|
40
|
+
readonly endLine: number;
|
|
41
|
+
/** Logical (LF, no-BOM) character offset of match start. */
|
|
42
|
+
readonly startOffset: number;
|
|
43
|
+
/** Logical character offset of match end (exclusive). */
|
|
44
|
+
readonly endOffset: number;
|
|
45
|
+
}
|
|
46
|
+
export interface EditFileData {
|
|
47
|
+
/** Workspace-relative path (echoed). */
|
|
48
|
+
readonly path: string;
|
|
49
|
+
/** SHA-256 of the file's contents before the edits. */
|
|
50
|
+
readonly beforeSha256: string;
|
|
51
|
+
/** SHA-256 of the file's contents after the edits. */
|
|
52
|
+
readonly afterSha256: string;
|
|
53
|
+
/** Byte length of the post-edit content. */
|
|
54
|
+
readonly sizeBytes: number;
|
|
55
|
+
/** Per-edit application summary. */
|
|
56
|
+
readonly appliedEdits: readonly AppliedEdit[];
|
|
57
|
+
/** Unified diff from `before` → `after`. Empty string when unchanged. */
|
|
58
|
+
readonly diff: string;
|
|
59
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { AppliedEdit } from "./edit-file.types";
|
|
2
|
+
interface PlannedReplacement {
|
|
3
|
+
readonly editIndex: number;
|
|
4
|
+
readonly startOffset: number;
|
|
5
|
+
readonly endOffset: number;
|
|
6
|
+
readonly newText: string;
|
|
7
|
+
}
|
|
8
|
+
/** Outcome details for a single edit, surfaced into the AppliedEdit return. */
|
|
9
|
+
interface EditMatchOutcome {
|
|
10
|
+
/** The actual substring matched in the snapshot (post-fallback if used). */
|
|
11
|
+
readonly matchedText: string;
|
|
12
|
+
/** Which replacer in the chain produced this match. */
|
|
13
|
+
readonly replacerName: string;
|
|
14
|
+
/** True iff the match was found via exact substring lookup (no fallback). */
|
|
15
|
+
readonly isExact: boolean;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Compute 1-indexed line numbers spanning a (start, end) character offset
|
|
19
|
+
* pair in `text`. End is exclusive; an edit ending at a newline counts
|
|
20
|
+
* the line containing that newline.
|
|
21
|
+
*/
|
|
22
|
+
export declare function offsetsToLineRange(text: string, startOffset: number, endOffset: number): {
|
|
23
|
+
startLine: number;
|
|
24
|
+
endLine: number;
|
|
25
|
+
};
|
|
26
|
+
/** Find every occurrence of `needle` in `haystack` and return start offsets. */
|
|
27
|
+
export declare function findAllOccurrences(haystack: string, needle: string): number[];
|
|
28
|
+
/**
|
|
29
|
+
* Locate every occurrence of each edit's `oldText` in the snapshot, verify
|
|
30
|
+
* match counts, and build the planned replacements list.
|
|
31
|
+
*
|
|
32
|
+
* Matching is tiered:
|
|
33
|
+
*
|
|
34
|
+
* 1. **Exact substring.** The strict legacy behaviour — `oldText` is
|
|
35
|
+
* matched character-for-character. If found, use it.
|
|
36
|
+
* 2. **Fallback chain.** If exact match yields zero hits, the
|
|
37
|
+
* `DEFAULT_REPLACER_CHAIN` (line-trimmed → whitespace-normalized →
|
|
38
|
+
* block-anchor) is tried in priority order. The first replacer to
|
|
39
|
+
* produce a *unique* candidate substring of the snapshot wins.
|
|
40
|
+
* `expectedOccurrences > 1` disables fallback entirely (because the
|
|
41
|
+
* LLM is asking for batch replacement of a literal string).
|
|
42
|
+
*
|
|
43
|
+
* Returns `{ planned, appliedEdits }` on success, or a `ToolError`-shaped
|
|
44
|
+
* object on failure. `AppliedEdit` carries a `usedFallback` flag and the
|
|
45
|
+
* `replacerName` so callers can surface the heuristic to the LLM.
|
|
46
|
+
*/
|
|
47
|
+
export declare function locateEditOccurrences(snapshot: string, edits: readonly {
|
|
48
|
+
oldText: string;
|
|
49
|
+
newText: string;
|
|
50
|
+
expectedOccurrences?: number;
|
|
51
|
+
}[], filePath: string): {
|
|
52
|
+
planned: PlannedReplacement[];
|
|
53
|
+
appliedEdits: AppliedEdit[];
|
|
54
|
+
} | {
|
|
55
|
+
errorKind: "old_text_not_found" | "multiple_matches";
|
|
56
|
+
errorMessage: string;
|
|
57
|
+
errorDetails: Record<string, unknown>;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Detect overlapping replacement ranges. Returns the conflicting edit indices
|
|
61
|
+
* if any overlap is found, or `undefined` if all ranges are disjoint.
|
|
62
|
+
*/
|
|
63
|
+
export declare function detectOverlappingEdits(planned: readonly PlannedReplacement[]): number[] | undefined;
|
|
64
|
+
/**
|
|
65
|
+
* Apply all planned replacements deterministically (descending by start offset).
|
|
66
|
+
* Each replacement splices into a working copy of the snapshot.
|
|
67
|
+
*/
|
|
68
|
+
export declare function applyReplacements(snapshot: string, planned: readonly PlannedReplacement[]): string;
|
|
69
|
+
/** Re-export for outcome reporting. */
|
|
70
|
+
export type { EditMatchOutcome };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { ToolDefinition } from "../../tool.types";
|
|
3
|
+
import type { GlobData, GlobToolConfig } from "./glob.types";
|
|
4
|
+
export declare const globParams: z.ZodObject<{
|
|
5
|
+
pattern: z.ZodString;
|
|
6
|
+
root: z.ZodOptional<z.ZodString>;
|
|
7
|
+
excludeGlobs: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
8
|
+
maxResults: z.ZodOptional<z.ZodNumber>;
|
|
9
|
+
}, "strip", z.ZodTypeAny, {
|
|
10
|
+
pattern: string;
|
|
11
|
+
root?: string | undefined;
|
|
12
|
+
excludeGlobs?: string[] | undefined;
|
|
13
|
+
maxResults?: number | undefined;
|
|
14
|
+
}, {
|
|
15
|
+
pattern: string;
|
|
16
|
+
root?: string | undefined;
|
|
17
|
+
excludeGlobs?: string[] | undefined;
|
|
18
|
+
maxResults?: number | undefined;
|
|
19
|
+
}>;
|
|
20
|
+
/**
|
|
21
|
+
* Create a Glob Tool to find both files and folders matching a glob pattern.
|
|
22
|
+
*
|
|
23
|
+
* @param config - Config options for limits like maxResults and maxDepth.
|
|
24
|
+
*/
|
|
25
|
+
export declare function createGlobTool(config?: GlobToolConfig): ToolDefinition<typeof globParams, GlobData>;
|