@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,37 @@
1
+ import type { PlatformInfo } from "./run-command.types";
2
+ /** Map `process.platform` to a friendly OS name. */
3
+ export declare function friendlyOsName(platform: NodeJS.Platform): string;
4
+ /**
5
+ * Resolve the shell to use for executing a command string on the
6
+ * current platform.
7
+ *
8
+ * On POSIX systems we prefer the user's `$SHELL` when set, falling
9
+ * back to `/bin/sh`. On Windows we prefer `%ComSpec%`, falling back
10
+ * to `cmd.exe`. The chosen shell is invoked with `-c <command>` on
11
+ * POSIX or `/d /s /c <command>` on Windows.
12
+ */
13
+ export declare function resolveShell(platform: NodeJS.Platform, env?: NodeJS.ProcessEnv): {
14
+ shellPath: string;
15
+ shellFlag: string;
16
+ };
17
+ /**
18
+ * Detect the platform info for the current process. Cached snapshot —
19
+ * call once at factory-creation time.
20
+ */
21
+ export declare function detectPlatformInfo(): PlatformInfo;
22
+ /**
23
+ * Build the model-facing tool description, baking in the detected
24
+ * platform info so the LLM picks correct commands for the host.
25
+ */
26
+ export declare function buildRunCommandDescription(info: PlatformInfo): string;
27
+ /**
28
+ * Truncate a captured stream to `maxBytes` UTF-8 bytes, appending a
29
+ * truncation marker when content was dropped. Operates on the raw
30
+ * Buffer to avoid splitting multi-byte sequences mid-character.
31
+ */
32
+ export declare function truncateOutput(buffer: Buffer, maxBytes: number): {
33
+ text: string;
34
+ truncated: boolean;
35
+ };
36
+ /** True iff `command` matches any pattern in `patterns`. */
37
+ export declare function matchesAnyPattern(command: string, patterns: readonly RegExp[]): boolean;
@@ -0,0 +1,2 @@
1
+ export { createSearchFilesTool } from "./search-files";
2
+ export type { SearchFilesData, SearchFilesMatch, SearchFilesToolConfig, } from "./search-files.types";
@@ -0,0 +1,5 @@
1
+ export declare const DEFAULT_EXCLUDE_GLOBS: readonly string[];
2
+ export declare const DEFAULT_MAX_RESULTS = 100;
3
+ export declare const DEFAULT_CONTEXT_LINES = 0;
4
+ export declare const DEFAULT_MAX_FILE_BYTES: number;
5
+ export declare const DEFAULT_TRAVERSAL_DEPTH = 32;
@@ -0,0 +1,30 @@
1
+ import { z } from "zod";
2
+ import type { ToolDefinition } from "../../tool.types";
3
+ import type { SearchFilesData, SearchFilesToolConfig } from "./search-files.types";
4
+ declare const searchFilesParams: z.ZodObject<{
5
+ query: z.ZodString;
6
+ mode: z.ZodEnum<["path", "text", "regex"]>;
7
+ root: z.ZodOptional<z.ZodString>;
8
+ includeGlobs: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
9
+ excludeGlobs: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
10
+ maxResults: z.ZodOptional<z.ZodNumber>;
11
+ contextLines: z.ZodOptional<z.ZodNumber>;
12
+ }, "strip", z.ZodTypeAny, {
13
+ query: string;
14
+ mode: "path" | "regex" | "text";
15
+ root?: string | undefined;
16
+ excludeGlobs?: string[] | undefined;
17
+ maxResults?: number | undefined;
18
+ includeGlobs?: string[] | undefined;
19
+ contextLines?: number | undefined;
20
+ }, {
21
+ query: string;
22
+ mode: "path" | "regex" | "text";
23
+ root?: string | undefined;
24
+ excludeGlobs?: string[] | undefined;
25
+ maxResults?: number | undefined;
26
+ includeGlobs?: string[] | undefined;
27
+ contextLines?: number | undefined;
28
+ }>;
29
+ export declare function createSearchFilesTool(config?: SearchFilesToolConfig): ToolDefinition<typeof searchFilesParams, SearchFilesData>;
30
+ export {};
@@ -0,0 +1,19 @@
1
+ export interface SearchFilesToolConfig {
2
+ readonly maxResults?: number;
3
+ readonly maxFileBytes?: number;
4
+ readonly maxDepth?: number;
5
+ }
6
+ export interface SearchFilesMatch {
7
+ readonly path: string;
8
+ readonly line?: number;
9
+ readonly column?: number;
10
+ readonly preview: string;
11
+ }
12
+ export interface SearchFilesData {
13
+ readonly mode: "path" | "text" | "regex";
14
+ readonly query: string;
15
+ readonly root: string;
16
+ readonly matches: readonly SearchFilesMatch[];
17
+ readonly truncated: boolean;
18
+ readonly filesScanned: number;
19
+ }
@@ -0,0 +1,11 @@
1
+ import { toolError } from "../../result";
2
+ export declare function toForwardSlash(pathString: string): string;
3
+ export declare function matchesAnyGlob(relPath: string, patterns: readonly string[]): boolean;
4
+ export declare function buildPreview(lines: readonly string[], lineIndex: number, contextLines: number): string;
5
+ export declare function compileRegex(query: string): {
6
+ regex: RegExp;
7
+ error?: undefined;
8
+ } | {
9
+ regex?: undefined;
10
+ error: ReturnType<typeof toolError>;
11
+ };
@@ -0,0 +1,62 @@
1
+ import { z } from "zod";
2
+ import type { ToolDefinition } from "../../tool.types";
3
+ /**
4
+ * Reset the todo state for a raw store key — typically `runId` when supplied
5
+ * or `agentName` for legacy callers. Exposed for tests and embedders.
6
+ */
7
+ export declare function resetTodoStateForAgent(key: string): void;
8
+ /**
9
+ * Reset all todo state across all agents and runs. Exposed for tests.
10
+ */
11
+ export declare function resetAllTodoState(): void;
12
+ declare const todoAddParams: z.ZodObject<{
13
+ content: z.ZodString;
14
+ }, "strip", z.ZodTypeAny, {
15
+ content: string;
16
+ }, {
17
+ content: string;
18
+ }>;
19
+ /**
20
+ * Create the `todo_add` tool, which appends a new pending item to the current
21
+ * todo list and returns its assigned id.
22
+ */
23
+ export declare function createTodoAddTool(): ToolDefinition<typeof todoAddParams>;
24
+ declare const todoRemoveParams: z.ZodObject<{
25
+ id: z.ZodString;
26
+ }, "strip", z.ZodTypeAny, {
27
+ id: string;
28
+ }, {
29
+ id: string;
30
+ }>;
31
+ /**
32
+ * Create the `todo_remove` tool, which deletes a single obsolete todo item.
33
+ */
34
+ export declare function createTodoRemoveTool(): ToolDefinition<typeof todoRemoveParams>;
35
+ declare const todoCompleteParams: z.ZodObject<{
36
+ id: z.ZodString;
37
+ }, "strip", z.ZodTypeAny, {
38
+ id: string;
39
+ }, {
40
+ id: string;
41
+ }>;
42
+ /**
43
+ * Create the `todo_complete` tool, which marks an item complete and returns
44
+ * the next pending item (or a "all done" message).
45
+ */
46
+ export declare function createTodoCompleteTool(): ToolDefinition<typeof todoCompleteParams>;
47
+ declare const todoGetParams: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
48
+ /**
49
+ * Create the `todo_get` tool, which returns the full current todo list.
50
+ */
51
+ export declare function createTodoGetTool(): ToolDefinition<typeof todoGetParams>;
52
+ declare const todoGetNextParams: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
53
+ /**
54
+ * Create the `todo_get_next` tool, which returns the next pending todo item.
55
+ */
56
+ export declare function createTodoGetNextTool(): ToolDefinition<typeof todoGetNextParams>;
57
+ declare const todoClearParams: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
58
+ /**
59
+ * Create the `todo_clear` tool, which removes all items from the current list.
60
+ */
61
+ export declare function createTodoClearTool(): ToolDefinition<typeof todoClearParams>;
62
+ export {};
@@ -0,0 +1,7 @@
1
+ export interface TodoItem {
2
+ readonly id: string;
3
+ readonly content: string;
4
+ status: "pending" | "completed";
5
+ readonly createdAt: string;
6
+ completedAt?: string;
7
+ }
@@ -0,0 +1,3 @@
1
+ export declare const DEFAULT_TIMEOUT_SECONDS = 30;
2
+ export declare const DEFAULT_MAX_CONTENT_LENGTH = 50000;
3
+ export declare const DEFAULT_USER_AGENT = "CommaAgents-WebFetch/1.0";
@@ -0,0 +1,33 @@
1
+ import { z } from "zod";
2
+ import type { ToolDefinition } from "../../tool.types";
3
+ import type { WebFetchToolConfig } from "./webfetch.types";
4
+ declare const webFetchParams: z.ZodObject<{
5
+ url: z.ZodString;
6
+ format: z.ZodDefault<z.ZodOptional<z.ZodEnum<["text", "markdown", "html"]>>>;
7
+ timeout: z.ZodOptional<z.ZodNumber>;
8
+ }, "strip", z.ZodTypeAny, {
9
+ url: string;
10
+ format: "text" | "markdown" | "html";
11
+ timeout?: number | undefined;
12
+ }, {
13
+ url: string;
14
+ format?: "text" | "markdown" | "html" | undefined;
15
+ timeout?: number | undefined;
16
+ }>;
17
+ /**
18
+ * Create a webfetch tool for retrieving and converting web content.
19
+ *
20
+ * @param config - Optional configuration overriding default timeout, content length, and user-agent.
21
+ * @example
22
+ * ```ts
23
+ * const webfetch = createWebFetchTool();
24
+ *
25
+ * // With custom defaults
26
+ * const webfetch = createWebFetchTool({
27
+ * defaultTimeout: 60,
28
+ * maxContentLength: 100_000,
29
+ * });
30
+ * ```
31
+ */
32
+ export declare function createWebFetchTool(config?: WebFetchToolConfig): ToolDefinition<typeof webFetchParams>;
33
+ export {};
@@ -0,0 +1,8 @@
1
+ export interface WebFetchToolConfig {
2
+ /** Default per-request timeout in seconds (default: 30). */
3
+ readonly defaultTimeout?: number;
4
+ /** Maximum length of the returned content in characters (default: 50_000). */
5
+ readonly maxContentLength?: number;
6
+ /** Custom user-agent header (default: "CommaAgents-WebFetch/1.0"). */
7
+ readonly userAgent?: string;
8
+ }
@@ -0,0 +1,19 @@
1
+ import TurndownService from "turndown";
2
+ /**
3
+ * Combine multiple AbortSignals into one. Aborts as soon as any input aborts.
4
+ */
5
+ export declare function mergeAbortSignals(signals: readonly AbortSignal[]): AbortSignal;
6
+ /**
7
+ * Lazily-instantiated Turndown service. Strips script/style noise and
8
+ * uses sensible defaults for LLM-friendly markdown output.
9
+ */
10
+ export declare function getTurndown(): TurndownService;
11
+ /**
12
+ * Strip common Markdown syntax from text, leaving readable plain text.
13
+ * Used for the "text" output format.
14
+ */
15
+ export declare function stripMarkdown(markdown: string): string;
16
+ /**
17
+ * Convert HTML into the requested output format.
18
+ */
19
+ export declare function transformContent(html: string, format: "text" | "markdown" | "html"): string;
@@ -0,0 +1,2 @@
1
+ export { createWriteFileTool } from "./write-file";
2
+ export type { WriteFileData, WriteFileToolConfig } from "./write-file.types";
@@ -0,0 +1,18 @@
1
+ import { z } from "zod";
2
+ import type { ToolDefinition } from "../../tool.types";
3
+ import type { WriteFileData, WriteFileToolConfig } from "./write-file.types";
4
+ declare const writeFileParams: z.ZodObject<{
5
+ path: z.ZodString;
6
+ content: z.ZodString;
7
+ expectedSha256: z.ZodString;
8
+ }, "strip", z.ZodTypeAny, {
9
+ path: string;
10
+ content: string;
11
+ expectedSha256: string;
12
+ }, {
13
+ path: string;
14
+ content: string;
15
+ expectedSha256: string;
16
+ }>;
17
+ export declare function createWriteFileTool(config?: WriteFileToolConfig): ToolDefinition<typeof writeFileParams, WriteFileData>;
18
+ export {};
@@ -0,0 +1,11 @@
1
+ import type { AuditSink } from "../../io/audit.types";
2
+ export interface WriteFileToolConfig {
3
+ readonly defaultAuditSink?: AuditSink;
4
+ }
5
+ export interface WriteFileData {
6
+ readonly path: string;
7
+ readonly beforeSha256: string;
8
+ readonly afterSha256: string;
9
+ readonly sizeBytes: number;
10
+ readonly diff: string;
11
+ }
@@ -0,0 +1,15 @@
1
+ import type { z } from "zod";
2
+ import type { Policy } from "../../guard/guard.types";
3
+ import type { ToolContext, ToolDefinition, ToolResult } from "../tool.types";
4
+ export declare function defineTool<ParameterSchema extends z.ZodType, DataShape = unknown>(config: {
5
+ readonly description: string;
6
+ readonly parameters: ParameterSchema;
7
+ readonly policies?: readonly Policy[];
8
+ /**
9
+ * Optional system prompt contribution from this tool.
10
+ * Injected ONCE into the agent's system prompt at creation time.
11
+ * Can be a static string or a function receiving ToolContext.
12
+ */
13
+ readonly systemPrompt?: string | ((toolContext: ToolContext) => Promise<string> | string);
14
+ readonly execute: (validatedArguments: z.infer<ParameterSchema>, toolContext: ToolContext) => Promise<ToolResult<DataShape>>;
15
+ }): ToolDefinition<ParameterSchema, DataShape>;
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Options for {@link writeAtomic}.
3
+ */
4
+ export interface WriteAtomicOptions {
5
+ /**
6
+ * Mode bits to apply to the final file. When omitted, we preserve the
7
+ * existing target's mode (if present) or fall back to the OS default.
8
+ */
9
+ readonly mode?: number;
10
+ /**
11
+ * Whether to `fsync` the temp file before renaming. Defaults to `true`.
12
+ * Set to `false` only in test harnesses where durability is irrelevant
13
+ * and disk IO is the bottleneck.
14
+ */
15
+ readonly fsync?: boolean;
16
+ }
17
+ /**
18
+ * Atomically write `content` to `absolutePath`.
19
+ *
20
+ * Implementation:
21
+ * 1. Determine the target mode (caller override → existing target → undefined).
22
+ * 2. Write `content` to `<dir>/<basename>.tmp-<8 hex bytes>`.
23
+ * 3. `fsync` the temp file (unless `fsync: false`).
24
+ * 4. `chmod` the temp file to the target mode (if known) — done before
25
+ * rename so the final file appears with the correct permissions
26
+ * atomically.
27
+ * 5. `rename` temp → target. On POSIX this is atomic when both paths
28
+ * are on the same filesystem (always true here — same directory).
29
+ * 6. On any failure, attempt to `unlink` the temp file.
30
+ *
31
+ * The function does **not** create parent directories — callers (e.g.
32
+ * `create_file`) decide whether missing parents are an error.
33
+ *
34
+ * @throws Standard `fs` errors. Sandbox authorization is the caller's
35
+ * responsibility; this helper assumes `absolutePath` is already permitted.
36
+ */
37
+ export declare function writeAtomic(absolutePath: string, content: string | Uint8Array, options?: WriteAtomicOptions): Promise<void>;
@@ -0,0 +1,29 @@
1
+ import type { AuditSink } from "./audit.types";
2
+ /**
3
+ * In-memory audit sink. Used for tests and as a fallback when no
4
+ * `sessionId` is available on the `ToolContext`.
5
+ *
6
+ * `list()` returns a defensive copy so callers cannot mutate the
7
+ * internal buffer.
8
+ */
9
+ export declare function createMemoryAuditSink(): AuditSink;
10
+ /**
11
+ * Options for {@link createFileAuditSink}.
12
+ */
13
+ export interface FileAuditSinkOptions {
14
+ /** Maximum number of bytes to keep per `diff` field. Longer diffs
15
+ * are truncated with a `…(truncated)` marker so a single huge
16
+ * rewrite doesn't bloat the log. Set to `Infinity` to disable. */
17
+ readonly maxDiffBytes?: number;
18
+ }
19
+ /**
20
+ * JSONL-backed audit sink under `<workspaceRoot>/.comma/audit/`.
21
+ *
22
+ * - One file per session: `<sessionId>.jsonl`.
23
+ * - Non-session entries (`sessionId` undefined) are routed to
24
+ * `default.jsonl` so they survive across processes.
25
+ * - Each append: ensures the directory exists, writes the line,
26
+ * then `fsync`s the file. We tolerate the extra syscalls because
27
+ * audit volume is low (one per destructive op).
28
+ */
29
+ export declare function createFileAuditSink(workspaceRoot: string, options?: FileAuditSinkOptions): AuditSink;
@@ -0,0 +1,115 @@
1
+ /**
2
+ * The kind of destructive file operation an audit entry records.
3
+ *
4
+ * - `"create"` — file did not exist before (or was a move target with
5
+ * no prior content).
6
+ * - `"update"` — file existed and was modified in place.
7
+ * - `"delete"` — file existed and was removed (or trashed).
8
+ * - `"move"` — `path` is the source, `toPath` the destination.
9
+ * `beforeSha256` is the source's pre-move hash; `afterSha256` is the
10
+ * destination's hash (typically identical to `beforeSha256` for a
11
+ * plain rename, but recorded explicitly to handle copy-then-delete
12
+ * moves across filesystems).
13
+ */
14
+ export type AuditOperation = "create" | "update" | "delete" | "move";
15
+ /**
16
+ * One row in the audit log. Persisted as a single JSONL line.
17
+ *
18
+ * Fields are typed as `readonly` because audit entries are immutable
19
+ * once appended — replaying the log must produce identical state
20
+ * regardless of how many times it runs.
21
+ */
22
+ export interface AuditEntry {
23
+ /** ISO-8601 timestamp (UTC) when the operation completed. */
24
+ readonly timestamp: string;
25
+ /**
26
+ * Session identifier from `ToolContext.sessionId`. Omitted for
27
+ * non-session callers (in-memory sink only).
28
+ */
29
+ readonly sessionId?: string;
30
+ /** Name of the agent that invoked the tool. */
31
+ readonly agentName: string;
32
+ /** Name of the tool that produced the mutation. */
33
+ readonly toolName: string;
34
+ /** Which kind of mutation this entry records. */
35
+ readonly operation: AuditOperation;
36
+ /**
37
+ * Workspace-relative path of the target. For `"move"`, this is the
38
+ * source path; for everything else, the affected file.
39
+ */
40
+ readonly path: string;
41
+ /** Destination path for `"move"` operations. Omitted otherwise. */
42
+ readonly toPath?: string;
43
+ /**
44
+ * SHA-256 of the file's content before the operation. Omitted for
45
+ * `"create"`. For `"delete"`, this is the hash at deletion time.
46
+ */
47
+ readonly beforeSha256?: string;
48
+ /**
49
+ * SHA-256 of the file's content after the operation. Omitted for
50
+ * `"delete"`. For `"create"` / `"update"` / `"move"`, this is the
51
+ * hash of the newly-written content.
52
+ */
53
+ readonly afterSha256?: string;
54
+ /**
55
+ * Unified diff in standard `diff -u` format. Optional — omitted for
56
+ * `"create"` (no prior content) and `"delete"` (no resulting content).
57
+ * Truncated by the sink if it exceeds the sink's configured limit.
58
+ */
59
+ readonly diff?: string;
60
+ /**
61
+ * `true` if the operation completed successfully. Failed operations
62
+ * are still recorded (for forensics and to keep replay deterministic)
63
+ * but their hash fields will reflect the pre-operation state.
64
+ */
65
+ readonly success: boolean;
66
+ /**
67
+ * Human-readable error message when `success` is false. Structured
68
+ * `ToolError` is *not* serialized — the message is enough for replay
69
+ * and the structured form is already on the `ToolResult`.
70
+ */
71
+ readonly error?: string;
72
+ /**
73
+ * Optional tool-specific metadata that doesn't fit the common fields.
74
+ * Examples: `{ trashedTo }` for `delete_file`, `{ overwrote: true }`
75
+ * for `move_file`, `{ atomic: true, hunkCount: 5 }` for `apply_patch`.
76
+ *
77
+ * Implementations must JSON-serialize this verbatim — keep it simple
78
+ * (strings, numbers, booleans, plain objects/arrays).
79
+ */
80
+ readonly details?: Readonly<Record<string, unknown>>;
81
+ }
82
+ /**
83
+ * Storage interface for audit entries.
84
+ *
85
+ * Implementations:
86
+ * - `createFileAuditSink(workspaceRoot)` — JSONL at
87
+ * `<workspaceRoot>/.comma/audit/<sessionId>.jsonl`.
88
+ * - `createMemoryAuditSink()` — in-memory array, for tests and for
89
+ * non-session callers.
90
+ *
91
+ * The sink is responsible for its own durability guarantees. File
92
+ * sinks fsync per-append; the in-memory sink simply pushes.
93
+ */
94
+ export interface AuditSink {
95
+ /**
96
+ * Append a single entry. Resolves once the entry is durable (for
97
+ * file sinks) or stored (for the in-memory sink).
98
+ */
99
+ append(entry: AuditEntry): Promise<void>;
100
+ /**
101
+ * Return entries for `sessionId`, or all entries when `sessionId`
102
+ * is omitted. Order matches insertion order (oldest → newest).
103
+ *
104
+ * File sinks read from disk on every call — callers that need
105
+ * repeated access should cache the result.
106
+ */
107
+ list(sessionId?: string): Promise<readonly AuditEntry[]>;
108
+ /**
109
+ * Load a specific session's entries. Equivalent to
110
+ * `list(sessionId)` but signals intent ("hydrate this session")
111
+ * and may use a different code path for file sinks (e.g. open
112
+ * the specific JSONL file directly).
113
+ */
114
+ load(sessionId: string): Promise<readonly AuditEntry[]>;
115
+ }
@@ -0,0 +1,48 @@
1
+ import type { ToolContext } from "../tool.types";
2
+ import type { AuditEntry, AuditSink } from "./audit.types";
3
+ /**
4
+ * Build a base audit entry with common fields from tool context.
5
+ *
6
+ * Extracts timestamp, sessionId, and agentName from the context, then
7
+ * merges in the operation-specific fields. The returned object is
8
+ * missing only the `success` field, which is added by the caller.
9
+ *
10
+ * @param context - Tool execution context containing sessionId and agentName
11
+ * @param toolName - Name of the tool performing the operation
12
+ * @param operation - Type of file operation (create, update, delete, move)
13
+ * @param path - Workspace-relative path of the affected file
14
+ * @param additionalFields - Operation-specific fields to merge into the entry
15
+ * @returns Base audit entry without the `success` field
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * const base = buildAuditBase(context, "edit_file", "update", "src/foo.ts", {
20
+ * beforeSha256: "abc...",
21
+ * afterSha256: "def...",
22
+ * diff: "--- a/src/foo.ts\n+++ b/src/foo.ts\n..."
23
+ * });
24
+ * await sink.append({ ...base, success: true });
25
+ * ```
26
+ */
27
+ export declare function buildAuditBase(context: ToolContext, toolName: string, operation: AuditEntry["operation"], path: string, additionalFields?: Partial<Omit<AuditEntry, "timestamp" | "sessionId" | "agentName" | "toolName" | "operation" | "path" | "success">>): Omit<AuditEntry, "success">;
28
+ /**
29
+ * Log a successful audit entry to the sink.
30
+ *
31
+ * No-op if sink is undefined. Swallows errors from the sink append
32
+ * operation since audit failures should not block the main operation.
33
+ *
34
+ * @param sink - Audit sink to write to (may be undefined)
35
+ * @param base - Base audit entry from `buildAuditBase`
36
+ */
37
+ export declare function logAuditSuccess(sink: AuditSink | undefined, base: Omit<AuditEntry, "success">): Promise<void>;
38
+ /**
39
+ * Log a failed audit entry to the sink.
40
+ *
41
+ * No-op if sink is undefined. Swallows errors from the sink append
42
+ * operation since audit failures should not block error handling.
43
+ *
44
+ * @param sink - Audit sink to write to (may be undefined)
45
+ * @param base - Base audit entry from `buildAuditBase`
46
+ * @param error - Human-readable error message
47
+ */
48
+ export declare function logAuditFailure(sink: AuditSink | undefined, base: Omit<AuditEntry, "success">, error: string): Promise<void>;
@@ -0,0 +1,16 @@
1
+ /** Sample size in bytes used for binary detection. */
2
+ export declare const BINARY_DETECTION_SAMPLE_BYTES: number;
3
+ /**
4
+ * Heuristically classify a buffer as binary by scanning the first
5
+ * `BINARY_DETECTION_SAMPLE_BYTES` bytes for a NUL byte.
6
+ *
7
+ * NUL bytes are vanishingly rare in legitimate text encodings
8
+ * (UTF-8, UTF-16 with BOM stripped, Latin-1) but ubiquitous in
9
+ * binary formats (images, compiled artefacts, archives). This matches
10
+ * the heuristic used by `git diff`, `grep`, and most editors.
11
+ *
12
+ * False positives (text files containing NUL) and false negatives
13
+ * (binary files with no NUL in the first 8 KiB) are tolerated by
14
+ * design — the opt-in flow lets the LLM override.
15
+ */
16
+ export declare function isLikelyBinary(buffer: Uint8Array): boolean;
@@ -0,0 +1,15 @@
1
+ /** The UTF-8 BOM as a string. */
2
+ export declare const BOM = "\uFEFF";
3
+ /**
4
+ * `true` if `content` starts with the UTF-8 BOM.
5
+ */
6
+ export declare function hasBom(content: string): boolean;
7
+ /**
8
+ * Return `content` with a leading BOM removed (if present).
9
+ */
10
+ export declare function stripBom(content: string): string;
11
+ /**
12
+ * Return `content` with the BOM re-applied if `hadBom` is true. Idempotent —
13
+ * does not double-prefix when `content` already starts with `\uFEFF`.
14
+ */
15
+ export declare function applyBom(content: string, hadBom: boolean): string;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Options for {@link unifiedDiff}.
3
+ */
4
+ export interface UnifiedDiffOptions {
5
+ /**
6
+ * Path label used for both the `---` and `+++` headers in the diff.
7
+ * Tools pass the workspace-relative path so the diff is portable.
8
+ */
9
+ readonly path: string;
10
+ /**
11
+ * Number of unchanged context lines on each side of a hunk.
12
+ * @default 3
13
+ */
14
+ readonly contextLines?: number;
15
+ }
16
+ /**
17
+ * Produce a unified diff (`diff -u` format) describing the transformation
18
+ * from `before` to `after`.
19
+ *
20
+ * The output is suitable for:
21
+ * - logging in audit entries,
22
+ * - showing the LLM a confirmation of the edit it just made,
23
+ * - feeding into review UIs.
24
+ *
25
+ * Returns an empty string when the inputs are byte-identical.
26
+ */
27
+ export declare function unifiedDiff(before: string, after: string, options: UnifiedDiffOptions): string;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Compute the SHA-256 of an arbitrary buffer / string. Synchronous —
3
+ * intended for in-memory content that has already been read.
4
+ *
5
+ * @param data - The bytes (or UTF-8 string) to hash.
6
+ * @returns Lowercase hex-encoded SHA-256 digest (64 chars).
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * sha256OfBuffer("hello") // "2cf24dba..."
11
+ * ```
12
+ */
13
+ export declare function sha256OfBuffer(data: string | Uint8Array | ArrayBuffer): string;
14
+ /**
15
+ * Compute the SHA-256 of a file on disk.
16
+ *
17
+ * Streams the file into the hasher to avoid loading large files fully
18
+ * into memory.
19
+ *
20
+ * @param absolutePath - Absolute path to the file. The caller is
21
+ * responsible for sandbox authorization.
22
+ * @throws Standard `fs.readFile` errors (`ENOENT`, `EACCES`, …); the
23
+ * tool layer translates these into structured `ToolError`s.
24
+ */
25
+ export declare function sha256OfFile(absolutePath: string): Promise<string>;
@@ -0,0 +1,19 @@
1
+ export type { WriteAtomicOptions } from "./atomic-write";
2
+ export { writeAtomic } from "./atomic-write";
3
+ export type { AuditEntry, AuditOperation, AuditSink } from "./audit.types";
4
+ export { buildAuditBase, logAuditFailure, logAuditSuccess, } from "./audit.utils";
5
+ export type { FileAuditSinkOptions } from "./audit-sink";
6
+ export { createFileAuditSink, createMemoryAuditSink } from "./audit-sink";
7
+ export { BINARY_DETECTION_SAMPLE_BYTES, isLikelyBinary } from "./binary";
8
+ export { applyBom, BOM, hasBom, stripBom } from "./bom";
9
+ export type { UnifiedDiffOptions } from "./diff";
10
+ export { unifiedDiff } from "./diff";
11
+ export { sha256OfBuffer, sha256OfFile } from "./hash";
12
+ export type { NewlineStyle } from "./newline";
13
+ export { applyNewline, detectNewline, toLF } from "./newline";
14
+ export { sandboxErrorToToolError } from "./sandbox-error";
15
+ export type { SessionFileEntry, SessionFileState } from "./session-file-state";
16
+ export { buildSessionFileState, verifySessionFileState, } from "./session-file-state";
17
+ export { STALE_FILE_RECOVERY_HINT } from "./stale-file";
18
+ export type { TrashEntry, TrashMetadata } from "./trash";
19
+ export { clearTrash, listTrash, moveToTrash, restoreFromTrash, trashWorkspaceDir, } from "./trash";