@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.
Files changed (216) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +18 -0
  3. package/dist/abortable/abortable.d.ts +5 -0
  4. package/dist/abortable/abortable.types.d.ts +10 -0
  5. package/dist/abortable/index.d.ts +2 -0
  6. package/dist/agents/agent/agent.constants.d.ts +5 -0
  7. package/dist/agents/agent/agent.d.ts +24 -0
  8. package/dist/agents/agent/agent.types.d.ts +408 -0
  9. package/dist/agents/agent/agent.utils.d.ts +107 -0
  10. package/dist/agents/built-in/user/user-agent.d.ts +32 -0
  11. package/dist/agents/built-in/user/user-agent.types.d.ts +53 -0
  12. package/dist/agents/built-in/user/user-agent.utils.d.ts +2 -0
  13. package/dist/agents/hook-into-agent/hook-into-agent.d.ts +29 -0
  14. package/dist/agents/hooks/hooks.types.d.ts +64 -0
  15. package/dist/agents/hooks/hooks.utils.d.ts +9 -0
  16. package/dist/agents/hooks/index.d.ts +2 -0
  17. package/dist/agents/loader/index.d.ts +4 -0
  18. package/dist/agents/loader/loader.d.ts +49 -0
  19. package/dist/agents/loader/loader.schema.d.ts +270 -0
  20. package/dist/agents/loader/loader.types.d.ts +15 -0
  21. package/dist/conversation-context/conversation-context.d.ts +78 -0
  22. package/dist/conversation-context/conversation-context.types.d.ts +111 -0
  23. package/dist/conversation-context/conversation-context.utils.d.ts +6 -0
  24. package/dist/conversation-context/index.d.ts +3 -0
  25. package/dist/conversation-context/retention/compaction/compaction.constants.d.ts +3 -0
  26. package/dist/conversation-context/retention/compaction/compaction.d.ts +21 -0
  27. package/dist/conversation-context/retention/compaction/compaction.types.d.ts +26 -0
  28. package/dist/conversation-context/retention/compaction/index.d.ts +2 -0
  29. package/dist/conversation-context/retention/index.d.ts +4 -0
  30. package/dist/conversation-context/retention/retention.d.ts +9 -0
  31. package/dist/conversation-context/retention/retention.types.d.ts +90 -0
  32. package/dist/conversation-context/retention/retention.utils.d.ts +3 -0
  33. package/dist/conversation-context/retention/rolling-window/index.d.ts +2 -0
  34. package/dist/conversation-context/retention/rolling-window/rolling-window.d.ts +13 -0
  35. package/dist/conversation-context/retention/rolling-window/rolling-window.types.d.ts +5 -0
  36. package/dist/credentials/backends/json-file.d.ts +21 -0
  37. package/dist/credentials/credentials.constants.d.ts +9 -0
  38. package/dist/credentials/credentials.d.ts +18 -0
  39. package/dist/credentials/credentials.schema.d.ts +102 -0
  40. package/dist/credentials/credentials.types.d.ts +118 -0
  41. package/dist/credentials/credentials.utils.d.ts +30 -0
  42. package/dist/credentials/index.d.ts +6 -0
  43. package/dist/defaults/defaults.d.ts +108 -0
  44. package/dist/defaults/defaults.types.d.ts +51 -0
  45. package/dist/defaults/index.d.ts +2 -0
  46. package/dist/errors/index.d.ts +70 -0
  47. package/dist/flows/built-in/broadcast/broadcast-flow.constants.d.ts +2 -0
  48. package/dist/flows/built-in/broadcast/broadcast-flow.d.ts +30 -0
  49. package/dist/flows/built-in/cycle/cycle-flow.d.ts +53 -0
  50. package/dist/flows/built-in/sequential/sequential-flow.d.ts +25 -0
  51. package/dist/flows/flow/flow.d.ts +79 -0
  52. package/dist/flows/flow/flow.types.d.ts +179 -0
  53. package/dist/flows/flow/flow.utils.d.ts +18 -0
  54. package/dist/flows/hook-into-flow/hook-into-flow.d.ts +30 -0
  55. package/dist/flows/index.d.ts +6 -0
  56. package/dist/flows/loader/index.d.ts +4 -0
  57. package/dist/flows/loader/loader.d.ts +55 -0
  58. package/dist/flows/loader/loader.schema.d.ts +195 -0
  59. package/dist/flows/loader/loader.types.d.ts +27 -0
  60. package/dist/guard/guard.d.ts +17 -0
  61. package/dist/guard/guard.types.d.ts +112 -0
  62. package/dist/guard/index.d.ts +3 -0
  63. package/dist/guard/policies.d.ts +28 -0
  64. package/dist/hooks/built-in/token-tracking/index.d.ts +2 -0
  65. package/dist/hooks/built-in/token-tracking/token-tracking.constants.d.ts +14 -0
  66. package/dist/hooks/built-in/token-tracking/token-tracking.d.ts +87 -0
  67. package/dist/hooks/built-in/token-tracking/token-tracking.types.d.ts +136 -0
  68. package/dist/hooks/hooks.d.ts +10 -0
  69. package/dist/hooks/hooks.types.d.ts +11 -0
  70. package/dist/hooks/index.d.ts +2 -0
  71. package/dist/index.d.ts +50 -0
  72. package/dist/index.js +8961 -0
  73. package/dist/language/index.d.ts +1 -0
  74. package/dist/language/language.types.d.ts +60 -0
  75. package/dist/model/index.d.ts +5 -0
  76. package/dist/model/model.d.ts +63 -0
  77. package/dist/model/model.types.d.ts +85 -0
  78. package/dist/model/model.utils.d.ts +151 -0
  79. package/dist/model/providers/catalog/catalog.d.ts +57 -0
  80. package/dist/model/providers/catalog/catalog.types.d.ts +50 -0
  81. package/dist/model/providers/catalog/catalog.utils.d.ts +15 -0
  82. package/dist/model/providers/catalog/index.d.ts +3 -0
  83. package/dist/model/providers/index.d.ts +7 -0
  84. package/dist/model/providers/listers/copilot.d.ts +10 -0
  85. package/dist/model/providers/listers/index.d.ts +2 -0
  86. package/dist/model/providers/listers/ollama.d.ts +9 -0
  87. package/dist/model/providers/providers.d.ts +69 -0
  88. package/dist/model/providers/providers.types.d.ts +157 -0
  89. package/dist/model/providers/providers.utils.d.ts +16 -0
  90. package/dist/prompts/index.d.ts +4 -0
  91. package/dist/prompts/message-builder.d.ts +89 -0
  92. package/dist/prompts/prompts.types.d.ts +86 -0
  93. package/dist/prompts/template/prompt-template.d.ts +22 -0
  94. package/dist/sandbox/in-sandbox.d.ts +31 -0
  95. package/dist/sandbox/index.d.ts +4 -0
  96. package/dist/sandbox/sandbox.constants.d.ts +31 -0
  97. package/dist/sandbox/sandbox.d.ts +11 -0
  98. package/dist/sandbox/sandbox.types.d.ts +105 -0
  99. package/dist/skills/index.d.ts +4 -0
  100. package/dist/skills/skills.constants.d.ts +10 -0
  101. package/dist/skills/skills.loader.d.ts +46 -0
  102. package/dist/skills/skills.registry.d.ts +18 -0
  103. package/dist/skills/skills.types.d.ts +66 -0
  104. package/dist/skills/skills.utils.d.ts +37 -0
  105. package/dist/strategy/discover/discover.d.ts +16 -0
  106. package/dist/strategy/discover/discover.types.d.ts +70 -0
  107. package/dist/strategy/discover/discover.utils.d.ts +95 -0
  108. package/dist/strategy/discover/index.d.ts +3 -0
  109. package/dist/strategy/exporter/exporter.d.ts +27 -0
  110. package/dist/strategy/exporter/exporter.types.d.ts +6 -0
  111. package/dist/strategy/index.d.ts +10 -0
  112. package/dist/strategy/loader/loader.d.ts +39 -0
  113. package/dist/strategy/loader/loader.types.d.ts +106 -0
  114. package/dist/strategy/loader/loader.utils.d.ts +20 -0
  115. package/dist/strategy/loader/project-loader.d.ts +9 -0
  116. package/dist/strategy/schema.d.ts +1032 -0
  117. package/dist/timeline/index.d.ts +4 -0
  118. package/dist/timeline/projections/conversation-context.d.ts +19 -0
  119. package/dist/timeline/projections/file-state.d.ts +8 -0
  120. package/dist/timeline/projections/index.d.ts +3 -0
  121. package/dist/timeline/timeline.d.ts +11 -0
  122. package/dist/timeline/timeline.types.d.ts +97 -0
  123. package/dist/tools/build-tool-system-prompt.d.ts +41 -0
  124. package/dist/tools/built-in/ask-question/ask-question.d.ts +21 -0
  125. package/dist/tools/built-in/ask-question/index.d.ts +2 -0
  126. package/dist/tools/built-in/create-file/create-file.d.ts +18 -0
  127. package/dist/tools/built-in/create-file/create-file.types.d.ts +11 -0
  128. package/dist/tools/built-in/create-file/index.d.ts +2 -0
  129. package/dist/tools/built-in/delete-file/delete-file.constants.d.ts +14 -0
  130. package/dist/tools/built-in/delete-file/delete-file.d.ts +5 -0
  131. package/dist/tools/built-in/delete-file/delete-file.types.d.ts +26 -0
  132. package/dist/tools/built-in/delete-file/index.d.ts +2 -0
  133. package/dist/tools/built-in/describe-tool.d.ts +61 -0
  134. package/dist/tools/built-in/edit-file/edit-file.d.ts +46 -0
  135. package/dist/tools/built-in/edit-file/edit-file.replacers.d.ts +81 -0
  136. package/dist/tools/built-in/edit-file/edit-file.types.d.ts +59 -0
  137. package/dist/tools/built-in/edit-file/edit-file.utils.d.ts +70 -0
  138. package/dist/tools/built-in/edit-file/index.d.ts +2 -0
  139. package/dist/tools/built-in/glob/glob.constants.d.ts +3 -0
  140. package/dist/tools/built-in/glob/glob.d.ts +25 -0
  141. package/dist/tools/built-in/glob/glob.types.d.ts +31 -0
  142. package/dist/tools/built-in/glob/glob.utils.d.ts +4 -0
  143. package/dist/tools/built-in/glob/index.d.ts +2 -0
  144. package/dist/tools/built-in/launch-strategy/index.d.ts +2 -0
  145. package/dist/tools/built-in/launch-strategy/launch-strategy.d.ts +26 -0
  146. package/dist/tools/built-in/launch-strategy/launch-strategy.types.d.ts +14 -0
  147. package/dist/tools/built-in/list-directory/index.d.ts +2 -0
  148. package/dist/tools/built-in/list-directory/list-directory.constants.d.ts +3 -0
  149. package/dist/tools/built-in/list-directory/list-directory.d.ts +20 -0
  150. package/dist/tools/built-in/list-directory/list-directory.types.d.ts +41 -0
  151. package/dist/tools/built-in/list-directory/list-directory.utils.d.ts +4 -0
  152. package/dist/tools/built-in/list-skills/index.d.ts +2 -0
  153. package/dist/tools/built-in/list-skills/list-skills.d.ts +5 -0
  154. package/dist/tools/built-in/list-skills/list-skills.types.d.ts +10 -0
  155. package/dist/tools/built-in/list-strategy/index.d.ts +2 -0
  156. package/dist/tools/built-in/list-strategy/list-strategy.d.ts +14 -0
  157. package/dist/tools/built-in/list-strategy/list-strategy.types.d.ts +33 -0
  158. package/dist/tools/built-in/load-skill/index.d.ts +2 -0
  159. package/dist/tools/built-in/load-skill/load-skill.d.ts +24 -0
  160. package/dist/tools/built-in/load-skill/load-skill.types.d.ts +15 -0
  161. package/dist/tools/built-in/lsp-request/index.d.ts +2 -0
  162. package/dist/tools/built-in/lsp-request/lsp-request.d.ts +4 -0
  163. package/dist/tools/built-in/lsp-request/lsp-request.schema.d.ts +23 -0
  164. package/dist/tools/built-in/lsp-request/lsp-request.types.d.ts +4 -0
  165. package/dist/tools/built-in/move-file/index.d.ts +2 -0
  166. package/dist/tools/built-in/move-file/move-file.d.ts +21 -0
  167. package/dist/tools/built-in/move-file/move-file.types.d.ts +12 -0
  168. package/dist/tools/built-in/read-file/index.d.ts +2 -0
  169. package/dist/tools/built-in/read-file/read-file.constants.d.ts +1 -0
  170. package/dist/tools/built-in/read-file/read-file.d.ts +32 -0
  171. package/dist/tools/built-in/read-file/read-file.types.d.ts +34 -0
  172. package/dist/tools/built-in/read-file/read-file.utils.d.ts +14 -0
  173. package/dist/tools/built-in/restore-file/index.d.ts +2 -0
  174. package/dist/tools/built-in/restore-file/restore-file.d.ts +16 -0
  175. package/dist/tools/built-in/restore-file/restore-file.types.d.ts +11 -0
  176. package/dist/tools/built-in/run-command/index.d.ts +2 -0
  177. package/dist/tools/built-in/run-command/run-command.constants.d.ts +23 -0
  178. package/dist/tools/built-in/run-command/run-command.d.ts +21 -0
  179. package/dist/tools/built-in/run-command/run-command.types.d.ts +81 -0
  180. package/dist/tools/built-in/run-command/run-command.utils.d.ts +37 -0
  181. package/dist/tools/built-in/search-files/index.d.ts +2 -0
  182. package/dist/tools/built-in/search-files/search-files.constants.d.ts +5 -0
  183. package/dist/tools/built-in/search-files/search-files.d.ts +30 -0
  184. package/dist/tools/built-in/search-files/search-files.types.d.ts +19 -0
  185. package/dist/tools/built-in/search-files/search-files.utils.d.ts +11 -0
  186. package/dist/tools/built-in/todo/todo.d.ts +62 -0
  187. package/dist/tools/built-in/todo/todo.types.d.ts +7 -0
  188. package/dist/tools/built-in/webfetch/webfetch.constants.d.ts +3 -0
  189. package/dist/tools/built-in/webfetch/webfetch.d.ts +33 -0
  190. package/dist/tools/built-in/webfetch/webfetch.types.d.ts +8 -0
  191. package/dist/tools/built-in/webfetch/webfetch.utils.d.ts +19 -0
  192. package/dist/tools/built-in/write-file/index.d.ts +2 -0
  193. package/dist/tools/built-in/write-file/write-file.d.ts +18 -0
  194. package/dist/tools/built-in/write-file/write-file.types.d.ts +11 -0
  195. package/dist/tools/define/define-tool.d.ts +15 -0
  196. package/dist/tools/io/atomic-write.d.ts +37 -0
  197. package/dist/tools/io/audit-sink.d.ts +29 -0
  198. package/dist/tools/io/audit.types.d.ts +115 -0
  199. package/dist/tools/io/audit.utils.d.ts +48 -0
  200. package/dist/tools/io/binary.d.ts +16 -0
  201. package/dist/tools/io/bom.d.ts +15 -0
  202. package/dist/tools/io/diff.d.ts +27 -0
  203. package/dist/tools/io/hash.d.ts +25 -0
  204. package/dist/tools/io/index.d.ts +19 -0
  205. package/dist/tools/io/newline.d.ts +34 -0
  206. package/dist/tools/io/sandbox-error.d.ts +13 -0
  207. package/dist/tools/io/session-file-state.d.ts +68 -0
  208. package/dist/tools/io/stale-file.d.ts +9 -0
  209. package/dist/tools/io/trash.d.ts +57 -0
  210. package/dist/tools/launch-strategy.types.d.ts +38 -0
  211. package/dist/tools/result/index.d.ts +1 -0
  212. package/dist/tools/result/result.d.ts +47 -0
  213. package/dist/tools/tool.constants.d.ts +7 -0
  214. package/dist/tools/tool.registry.d.ts +54 -0
  215. package/dist/tools/tool.types.d.ts +191 -0
  216. 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,3 @@
1
+ export type { ProjectedConversationContext } from "./conversation-context";
2
+ export { projectConversationContext } from "./conversation-context";
3
+ export { projectFileState } from "./file-state";
@@ -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,2 @@
1
+ export type { AskQuestionData } from "./ask-question";
2
+ export { askQuestionParams, createAskQuestionTool } from "./ask-question";
@@ -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,2 @@
1
+ export { createCreateFileTool } from "./create-file";
2
+ export type { CreateFileData, CreateFileToolConfig } from "./create-file.types";
@@ -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,2 @@
1
+ export { createDeleteFileTool } from "./delete-file";
2
+ export type { DeleteFileData, DeleteFileToolConfig } from "./delete-file.types";
@@ -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,2 @@
1
+ export { createEditFileTool } from "./edit-file";
2
+ export type { AppliedEdit, EditFileData, EditFileToolConfig, MatchRange, } from "./edit-file.types";
@@ -0,0 +1,3 @@
1
+ export declare const DEFAULT_EXCLUDE_GLOBS: readonly string[];
2
+ export declare const DEFAULT_MAX_RESULTS = 1000;
3
+ export declare const DEFAULT_TRAVERSAL_DEPTH = 32;
@@ -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>;