@cdoing/core 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agents/coordinator.d.ts +114 -0
- package/dist/agents/coordinator.d.ts.map +1 -0
- package/dist/agents/coordinator.js +158 -0
- package/dist/agents/coordinator.js.map +1 -0
- package/dist/context-providers/clipboard.d.ts +13 -0
- package/dist/context-providers/clipboard.d.ts.map +1 -0
- package/dist/context-providers/clipboard.js +53 -0
- package/dist/context-providers/clipboard.js.map +1 -0
- package/dist/context-providers/codebase.d.ts +46 -0
- package/dist/context-providers/codebase.d.ts.map +1 -0
- package/dist/context-providers/codebase.js +273 -0
- package/dist/context-providers/codebase.js.map +1 -0
- package/dist/context-providers/diff.d.ts +18 -0
- package/dist/context-providers/diff.d.ts.map +1 -0
- package/dist/context-providers/diff.js +63 -0
- package/dist/context-providers/diff.js.map +1 -0
- package/dist/context-providers/docs.d.ts +21 -0
- package/dist/context-providers/docs.d.ts.map +1 -0
- package/dist/context-providers/docs.js +180 -0
- package/dist/context-providers/docs.js.map +1 -0
- package/dist/context-providers/file-include.d.ts +13 -0
- package/dist/context-providers/file-include.d.ts.map +1 -0
- package/dist/context-providers/file-include.js +82 -0
- package/dist/context-providers/file-include.js.map +1 -0
- package/dist/context-providers/folder.d.ts +19 -0
- package/dist/context-providers/folder.d.ts.map +1 -0
- package/dist/context-providers/folder.js +130 -0
- package/dist/context-providers/folder.js.map +1 -0
- package/dist/context-providers/git.d.ts +19 -0
- package/dist/context-providers/git.d.ts.map +1 -0
- package/dist/context-providers/git.js +74 -0
- package/dist/context-providers/git.js.map +1 -0
- package/dist/context-providers/index.d.ts +26 -0
- package/dist/context-providers/index.d.ts.map +1 -0
- package/dist/context-providers/index.js +37 -0
- package/dist/context-providers/index.js.map +1 -0
- package/dist/context-providers/open-files.d.ts +25 -0
- package/dist/context-providers/open-files.d.ts.map +1 -0
- package/dist/context-providers/open-files.js +134 -0
- package/dist/context-providers/open-files.js.map +1 -0
- package/dist/context-providers/problems.d.ts +24 -0
- package/dist/context-providers/problems.d.ts.map +1 -0
- package/dist/context-providers/problems.js +97 -0
- package/dist/context-providers/problems.js.map +1 -0
- package/dist/context-providers/registry.d.ts +61 -0
- package/dist/context-providers/registry.d.ts.map +1 -0
- package/dist/context-providers/registry.js +92 -0
- package/dist/context-providers/registry.js.map +1 -0
- package/dist/context-providers/terminal.d.ts +25 -0
- package/dist/context-providers/terminal.d.ts.map +1 -0
- package/dist/context-providers/terminal.js +55 -0
- package/dist/context-providers/terminal.js.map +1 -0
- package/dist/context-providers/tree.d.ts +29 -0
- package/dist/context-providers/tree.d.ts.map +1 -0
- package/dist/context-providers/tree.js +172 -0
- package/dist/context-providers/tree.js.map +1 -0
- package/dist/context-providers/types.d.ts +72 -0
- package/dist/context-providers/types.d.ts.map +1 -0
- package/dist/context-providers/types.js +10 -0
- package/dist/context-providers/types.js.map +1 -0
- package/dist/context-providers/url.d.ts +27 -0
- package/dist/context-providers/url.d.ts.map +1 -0
- package/dist/context-providers/url.js +131 -0
- package/dist/context-providers/url.js.map +1 -0
- package/dist/effort/index.d.ts +78 -0
- package/dist/effort/index.d.ts.map +1 -0
- package/dist/effort/index.js +146 -0
- package/dist/effort/index.js.map +1 -0
- package/dist/hooks/index.d.ts +47 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +151 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/index.d.ts +75 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +152 -0
- package/dist/index.js.map +1 -0
- package/dist/indexing/chunker.d.ts +25 -0
- package/dist/indexing/chunker.d.ts.map +1 -0
- package/dist/indexing/chunker.js +217 -0
- package/dist/indexing/chunker.js.map +1 -0
- package/dist/indexing/database.d.ts +49 -0
- package/dist/indexing/database.d.ts.map +1 -0
- package/dist/indexing/database.js +287 -0
- package/dist/indexing/database.js.map +1 -0
- package/dist/indexing/index.d.ts +9 -0
- package/dist/indexing/index.d.ts.map +1 -0
- package/dist/indexing/index.js +13 -0
- package/dist/indexing/index.js.map +1 -0
- package/dist/indexing/indexer.d.ts +63 -0
- package/dist/indexing/indexer.d.ts.map +1 -0
- package/dist/indexing/indexer.js +352 -0
- package/dist/indexing/indexer.js.map +1 -0
- package/dist/indexing/recent-edits-cache.d.ts +77 -0
- package/dist/indexing/recent-edits-cache.d.ts.map +1 -0
- package/dist/indexing/recent-edits-cache.js +123 -0
- package/dist/indexing/recent-edits-cache.js.map +1 -0
- package/dist/indexing/types.d.ts +39 -0
- package/dist/indexing/types.d.ts.map +1 -0
- package/dist/indexing/types.js +6 -0
- package/dist/indexing/types.js.map +1 -0
- package/dist/mcp/index.d.ts +33 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +37 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/manager.d.ts +123 -0
- package/dist/mcp/manager.d.ts.map +1 -0
- package/dist/mcp/manager.js +331 -0
- package/dist/mcp/manager.js.map +1 -0
- package/dist/oauth.d.ts +33 -0
- package/dist/oauth.d.ts.map +1 -0
- package/dist/oauth.js +312 -0
- package/dist/oauth.js.map +1 -0
- package/dist/permissions/index.d.ts +216 -0
- package/dist/permissions/index.d.ts.map +1 -0
- package/dist/permissions/index.js +938 -0
- package/dist/permissions/index.js.map +1 -0
- package/dist/plan/index.d.ts +20 -0
- package/dist/plan/index.d.ts.map +1 -0
- package/dist/plan/index.js +24 -0
- package/dist/plan/index.js.map +1 -0
- package/dist/plan/manager.d.ts +101 -0
- package/dist/plan/manager.d.ts.map +1 -0
- package/dist/plan/manager.js +170 -0
- package/dist/plan/manager.js.map +1 -0
- package/dist/rules/index.d.ts +28 -0
- package/dist/rules/index.d.ts.map +1 -0
- package/dist/rules/index.js +31 -0
- package/dist/rules/index.js.map +1 -0
- package/dist/rules/manager.d.ts +77 -0
- package/dist/rules/manager.d.ts.map +1 -0
- package/dist/rules/manager.js +279 -0
- package/dist/rules/manager.js.map +1 -0
- package/dist/rules/types.d.ts +34 -0
- package/dist/rules/types.d.ts.map +1 -0
- package/dist/rules/types.js +9 -0
- package/dist/rules/types.js.map +1 -0
- package/dist/sandbox/filesystem.d.ts +20 -0
- package/dist/sandbox/filesystem.d.ts.map +1 -0
- package/dist/sandbox/filesystem.js +141 -0
- package/dist/sandbox/filesystem.js.map +1 -0
- package/dist/sandbox/index.d.ts +4 -0
- package/dist/sandbox/index.d.ts.map +1 -0
- package/dist/sandbox/index.js +8 -0
- package/dist/sandbox/index.js.map +1 -0
- package/dist/sandbox/manager.d.ts +47 -0
- package/dist/sandbox/manager.d.ts.map +1 -0
- package/dist/sandbox/manager.js +220 -0
- package/dist/sandbox/manager.js.map +1 -0
- package/dist/sandbox/network.d.ts +14 -0
- package/dist/sandbox/network.d.ts.map +1 -0
- package/dist/sandbox/network.js +87 -0
- package/dist/sandbox/network.js.map +1 -0
- package/dist/sandbox/types.d.ts +42 -0
- package/dist/sandbox/types.d.ts.map +1 -0
- package/dist/sandbox/types.js +25 -0
- package/dist/sandbox/types.js.map +1 -0
- package/dist/tools/ast-edit.d.ts +57 -0
- package/dist/tools/ast-edit.d.ts.map +1 -0
- package/dist/tools/ast-edit.js +443 -0
- package/dist/tools/ast-edit.js.map +1 -0
- package/dist/tools/code-verify.d.ts +8 -0
- package/dist/tools/code-verify.d.ts.map +1 -0
- package/dist/tools/code-verify.js +159 -0
- package/dist/tools/code-verify.js.map +1 -0
- package/dist/tools/codebase-search.d.ts +17 -0
- package/dist/tools/codebase-search.d.ts.map +1 -0
- package/dist/tools/codebase-search.js +104 -0
- package/dist/tools/codebase-search.js.map +1 -0
- package/dist/tools/file-delete.d.ts +26 -0
- package/dist/tools/file-delete.d.ts.map +1 -0
- package/dist/tools/file-delete.js +179 -0
- package/dist/tools/file-delete.js.map +1 -0
- package/dist/tools/file-edit.d.ts +10 -0
- package/dist/tools/file-edit.d.ts.map +1 -0
- package/dist/tools/file-edit.js +138 -0
- package/dist/tools/file-edit.js.map +1 -0
- package/dist/tools/file-read.d.ts +12 -0
- package/dist/tools/file-read.d.ts.map +1 -0
- package/dist/tools/file-read.js +211 -0
- package/dist/tools/file-read.js.map +1 -0
- package/dist/tools/file-run.d.ts +10 -0
- package/dist/tools/file-run.d.ts.map +1 -0
- package/dist/tools/file-run.js +179 -0
- package/dist/tools/file-run.js.map +1 -0
- package/dist/tools/file-write.d.ts +10 -0
- package/dist/tools/file-write.d.ts.map +1 -0
- package/dist/tools/file-write.js +134 -0
- package/dist/tools/file-write.js.map +1 -0
- package/dist/tools/glob-search.d.ts +8 -0
- package/dist/tools/glob-search.d.ts.map +1 -0
- package/dist/tools/glob-search.js +108 -0
- package/dist/tools/glob-search.js.map +1 -0
- package/dist/tools/grep-search.d.ts +8 -0
- package/dist/tools/grep-search.d.ts.map +1 -0
- package/dist/tools/grep-search.js +139 -0
- package/dist/tools/grep-search.js.map +1 -0
- package/dist/tools/list-dir.d.ts +16 -0
- package/dist/tools/list-dir.d.ts.map +1 -0
- package/dist/tools/list-dir.js +183 -0
- package/dist/tools/list-dir.js.map +1 -0
- package/dist/tools/multi-edit.d.ts +16 -0
- package/dist/tools/multi-edit.d.ts.map +1 -0
- package/dist/tools/multi-edit.js +163 -0
- package/dist/tools/multi-edit.js.map +1 -0
- package/dist/tools/notebook-edit.d.ts +31 -0
- package/dist/tools/notebook-edit.d.ts.map +1 -0
- package/dist/tools/notebook-edit.js +321 -0
- package/dist/tools/notebook-edit.js.map +1 -0
- package/dist/tools/registry.d.ts +16 -0
- package/dist/tools/registry.d.ts.map +1 -0
- package/dist/tools/registry.js +41 -0
- package/dist/tools/registry.js.map +1 -0
- package/dist/tools/shell-exec.d.ts +12 -0
- package/dist/tools/shell-exec.d.ts.map +1 -0
- package/dist/tools/shell-exec.js +261 -0
- package/dist/tools/shell-exec.js.map +1 -0
- package/dist/tools/sub-agent-manager.d.ts +57 -0
- package/dist/tools/sub-agent-manager.d.ts.map +1 -0
- package/dist/tools/sub-agent-manager.js +153 -0
- package/dist/tools/sub-agent-manager.js.map +1 -0
- package/dist/tools/sub-agent-status.d.ts +12 -0
- package/dist/tools/sub-agent-status.d.ts.map +1 -0
- package/dist/tools/sub-agent-status.js +59 -0
- package/dist/tools/sub-agent-status.js.map +1 -0
- package/dist/tools/sub-agent-terminate.d.ts +12 -0
- package/dist/tools/sub-agent-terminate.d.ts.map +1 -0
- package/dist/tools/sub-agent-terminate.js +55 -0
- package/dist/tools/sub-agent-terminate.js.map +1 -0
- package/dist/tools/sub-agent.d.ts +34 -0
- package/dist/tools/sub-agent.d.ts.map +1 -0
- package/dist/tools/sub-agent.js +140 -0
- package/dist/tools/sub-agent.js.map +1 -0
- package/dist/tools/system-info.d.ts +24 -0
- package/dist/tools/system-info.d.ts.map +1 -0
- package/dist/tools/system-info.js +220 -0
- package/dist/tools/system-info.js.map +1 -0
- package/dist/tools/todo.d.ts +16 -0
- package/dist/tools/todo.d.ts.map +1 -0
- package/dist/tools/todo.js +144 -0
- package/dist/tools/todo.js.map +1 -0
- package/dist/tools/types.d.ts +20 -0
- package/dist/tools/types.d.ts.map +1 -0
- package/dist/tools/types.js +3 -0
- package/dist/tools/types.js.map +1 -0
- package/dist/tools/view-diff.d.ts +11 -0
- package/dist/tools/view-diff.d.ts.map +1 -0
- package/dist/tools/view-diff.js +88 -0
- package/dist/tools/view-diff.js.map +1 -0
- package/dist/tools/view-repo-map.d.ts +18 -0
- package/dist/tools/view-repo-map.d.ts.map +1 -0
- package/dist/tools/view-repo-map.js +245 -0
- package/dist/tools/view-repo-map.js.map +1 -0
- package/dist/tools/web-fetch.d.ts +13 -0
- package/dist/tools/web-fetch.d.ts.map +1 -0
- package/dist/tools/web-fetch.js +106 -0
- package/dist/tools/web-fetch.js.map +1 -0
- package/dist/tools/web-search.d.ts +10 -0
- package/dist/tools/web-search.d.ts.map +1 -0
- package/dist/tools/web-search.js +106 -0
- package/dist/tools/web-search.js.map +1 -0
- package/dist/utils/gitignore.d.ts +10 -0
- package/dist/utils/gitignore.d.ts.map +1 -0
- package/dist/utils/gitignore.js +104 -0
- package/dist/utils/gitignore.js.map +1 -0
- package/dist/utils/lazy-apply.d.ts +45 -0
- package/dist/utils/lazy-apply.d.ts.map +1 -0
- package/dist/utils/lazy-apply.js +164 -0
- package/dist/utils/lazy-apply.js.map +1 -0
- package/dist/utils/memory.d.ts +36 -0
- package/dist/utils/memory.d.ts.map +1 -0
- package/dist/utils/memory.js +136 -0
- package/dist/utils/memory.js.map +1 -0
- package/dist/utils/path-matching.d.ts +24 -0
- package/dist/utils/path-matching.d.ts.map +1 -0
- package/dist/utils/path-matching.js +116 -0
- package/dist/utils/path-matching.js.map +1 -0
- package/dist/utils/path-safety.d.ts +13 -0
- package/dist/utils/path-safety.d.ts.map +1 -0
- package/dist/utils/path-safety.js +54 -0
- package/dist/utils/path-safety.js.map +1 -0
- package/dist/utils/project-config.d.ts +18 -0
- package/dist/utils/project-config.d.ts.map +1 -0
- package/dist/utils/project-config.js +76 -0
- package/dist/utils/project-config.js.map +1 -0
- package/dist/utils/search-match.d.ts +63 -0
- package/dist/utils/search-match.d.ts.map +1 -0
- package/dist/utils/search-match.js +426 -0
- package/dist/utils/search-match.js.map +1 -0
- package/dist/utils/shell-paths.d.ts +17 -0
- package/dist/utils/shell-paths.d.ts.map +1 -0
- package/dist/utils/shell-paths.js +107 -0
- package/dist/utils/shell-paths.js.map +1 -0
- package/dist/utils/streaming-diff.d.ts +45 -0
- package/dist/utils/streaming-diff.d.ts.map +1 -0
- package/dist/utils/streaming-diff.js +230 -0
- package/dist/utils/streaming-diff.js.map +1 -0
- package/dist/utils/todo.d.ts +47 -0
- package/dist/utils/todo.d.ts.map +1 -0
- package/dist/utils/todo.js +102 -0
- package/dist/utils/todo.js.map +1 -0
- package/package.json +23 -0
- package/src/agents/coordinator.ts +240 -0
- package/src/context-providers/clipboard.ts +48 -0
- package/src/context-providers/codebase.ts +274 -0
- package/src/context-providers/diff.ts +66 -0
- package/src/context-providers/docs.ts +160 -0
- package/src/context-providers/file-include.ts +54 -0
- package/src/context-providers/folder.ts +106 -0
- package/src/context-providers/git.ts +72 -0
- package/src/context-providers/index.ts +26 -0
- package/src/context-providers/open-files.ts +113 -0
- package/src/context-providers/problems.ts +100 -0
- package/src/context-providers/registry.ts +99 -0
- package/src/context-providers/terminal.ts +58 -0
- package/src/context-providers/tree.ts +161 -0
- package/src/context-providers/types.ts +84 -0
- package/src/context-providers/url.ts +138 -0
- package/src/effort/index.ts +177 -0
- package/src/hooks/index.ts +148 -0
- package/src/index.ts +114 -0
- package/src/indexing/README.md +267 -0
- package/src/indexing/chunker.ts +206 -0
- package/src/indexing/database.ts +299 -0
- package/src/indexing/index.ts +15 -0
- package/src/indexing/indexer.ts +383 -0
- package/src/indexing/recent-edits-cache.ts +150 -0
- package/src/indexing/types.ts +44 -0
- package/src/mcp/index.ts +33 -0
- package/src/mcp/manager.ts +385 -0
- package/src/oauth.ts +330 -0
- package/src/permissions/index.ts +1011 -0
- package/src/plan/index.ts +20 -0
- package/src/plan/manager.ts +233 -0
- package/src/rules/index.ts +28 -0
- package/src/rules/manager.ts +276 -0
- package/src/rules/types.ts +40 -0
- package/src/sandbox/filesystem.ts +135 -0
- package/src/sandbox/index.ts +9 -0
- package/src/sandbox/manager.ts +213 -0
- package/src/sandbox/network.ts +101 -0
- package/src/sandbox/types.ts +63 -0
- package/src/tools/ast-edit.ts +493 -0
- package/src/tools/code-verify.ts +143 -0
- package/src/tools/codebase-search.ts +117 -0
- package/src/tools/file-delete.ts +155 -0
- package/src/tools/file-edit.ts +115 -0
- package/src/tools/file-read.ts +195 -0
- package/src/tools/file-run.ts +158 -0
- package/src/tools/file-write.ts +104 -0
- package/src/tools/glob-search.ts +80 -0
- package/src/tools/grep-search.ts +120 -0
- package/src/tools/list-dir.ts +172 -0
- package/src/tools/multi-edit.ts +138 -0
- package/src/tools/notebook-edit.ts +342 -0
- package/src/tools/registry.ts +43 -0
- package/src/tools/shell-exec.ts +251 -0
- package/src/tools/sub-agent-manager.ts +183 -0
- package/src/tools/sub-agent-status.ts +67 -0
- package/src/tools/sub-agent-terminate.ts +62 -0
- package/src/tools/sub-agent.ts +162 -0
- package/src/tools/system-info.ts +248 -0
- package/src/tools/todo.ts +149 -0
- package/src/tools/types.ts +21 -0
- package/src/tools/view-diff.ts +99 -0
- package/src/tools/view-repo-map.ts +249 -0
- package/src/tools/web-fetch.ts +118 -0
- package/src/tools/web-search.ts +129 -0
- package/src/utils/gitignore.ts +73 -0
- package/src/utils/lazy-apply.ts +189 -0
- package/src/utils/memory.ts +124 -0
- package/src/utils/path-matching.ts +84 -0
- package/src/utils/path-safety.ts +19 -0
- package/src/utils/project-config.ts +41 -0
- package/src/utils/search-match.ts +495 -0
- package/src/utils/shell-paths.ts +79 -0
- package/src/utils/streaming-diff.ts +260 -0
- package/src/utils/todo.ts +115 -0
- package/tsconfig.json +18 -0
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Streaming Diff — generates and emits diff chunks in real-time as edits are applied.
|
|
3
|
+
*
|
|
4
|
+
* Instead of computing the entire diff at once and returning it,
|
|
5
|
+
* StreamingDiff emits line-level diff events via a callback, enabling
|
|
6
|
+
* UIs to render changes incrementally (e.g., green/red highlighting as
|
|
7
|
+
* each hunk is processed).
|
|
8
|
+
*
|
|
9
|
+
* Supports three strategies:
|
|
10
|
+
* 1. Deterministic — line-by-line Myers diff (always correct, synchronous)
|
|
11
|
+
* 2. Unified diff — parse and stream hunk-by-hunk from a unified diff string
|
|
12
|
+
* 3. Streaming — emit chunks as they arrive from an LLM token stream
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export interface DiffChunk {
|
|
16
|
+
type: "context" | "add" | "remove" | "hunk-header" | "file-header";
|
|
17
|
+
content: string;
|
|
18
|
+
lineNumber?: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type DiffChunkCallback = (chunk: DiffChunk) => void;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Compute a line-level diff between two strings and emit chunks via callback.
|
|
25
|
+
* Uses a simple LCS-based diff algorithm.
|
|
26
|
+
*/
|
|
27
|
+
export function streamDeterministicDiff(
|
|
28
|
+
oldContent: string,
|
|
29
|
+
newContent: string,
|
|
30
|
+
filePath: string,
|
|
31
|
+
onChunk: DiffChunkCallback,
|
|
32
|
+
): void {
|
|
33
|
+
const oldLines = oldContent.split("\n");
|
|
34
|
+
const newLines = newContent.split("\n");
|
|
35
|
+
|
|
36
|
+
// Emit file headers
|
|
37
|
+
onChunk({ type: "file-header", content: `--- a/${filePath}` });
|
|
38
|
+
onChunk({ type: "file-header", content: `+++ b/${filePath}` });
|
|
39
|
+
|
|
40
|
+
// Compute LCS for line-level diff
|
|
41
|
+
const diff = computeLineDiff(oldLines, newLines);
|
|
42
|
+
|
|
43
|
+
// Group into hunks
|
|
44
|
+
const hunks = groupIntoHunks(diff, oldLines.length, newLines.length);
|
|
45
|
+
|
|
46
|
+
for (const hunk of hunks) {
|
|
47
|
+
onChunk({
|
|
48
|
+
type: "hunk-header",
|
|
49
|
+
content: `@@ -${hunk.oldStart + 1},${hunk.oldCount} +${hunk.newStart + 1},${hunk.newCount} @@`,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
for (const entry of hunk.entries) {
|
|
53
|
+
onChunk(entry);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
interface DiffEntry {
|
|
59
|
+
type: "context" | "add" | "remove";
|
|
60
|
+
content: string;
|
|
61
|
+
oldLine?: number;
|
|
62
|
+
newLine?: number;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
interface Hunk {
|
|
66
|
+
oldStart: number;
|
|
67
|
+
oldCount: number;
|
|
68
|
+
newStart: number;
|
|
69
|
+
newCount: number;
|
|
70
|
+
entries: DiffChunk[];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Simple line diff using longest common subsequence.
|
|
75
|
+
*/
|
|
76
|
+
function computeLineDiff(oldLines: string[], newLines: string[]): DiffEntry[] {
|
|
77
|
+
const m = oldLines.length;
|
|
78
|
+
const n = newLines.length;
|
|
79
|
+
|
|
80
|
+
// Build LCS table
|
|
81
|
+
const dp: number[][] = Array.from({ length: m + 1 }, () => new Array(n + 1).fill(0));
|
|
82
|
+
for (let i = 1; i <= m; i++) {
|
|
83
|
+
for (let j = 1; j <= n; j++) {
|
|
84
|
+
if (oldLines[i - 1] === newLines[j - 1]) {
|
|
85
|
+
dp[i][j] = dp[i - 1][j - 1] + 1;
|
|
86
|
+
} else {
|
|
87
|
+
dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Backtrack to produce diff
|
|
93
|
+
const result: DiffEntry[] = [];
|
|
94
|
+
let i = m, j = n;
|
|
95
|
+
|
|
96
|
+
while (i > 0 || j > 0) {
|
|
97
|
+
if (i > 0 && j > 0 && oldLines[i - 1] === newLines[j - 1]) {
|
|
98
|
+
result.unshift({ type: "context", content: oldLines[i - 1], oldLine: i, newLine: j });
|
|
99
|
+
i--;
|
|
100
|
+
j--;
|
|
101
|
+
} else if (j > 0 && (i === 0 || dp[i][j - 1] >= dp[i - 1][j])) {
|
|
102
|
+
result.unshift({ type: "add", content: newLines[j - 1], newLine: j });
|
|
103
|
+
j--;
|
|
104
|
+
} else {
|
|
105
|
+
result.unshift({ type: "remove", content: oldLines[i - 1], oldLine: i });
|
|
106
|
+
i--;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return result;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Group diff entries into hunks with context lines.
|
|
115
|
+
*/
|
|
116
|
+
function groupIntoHunks(diff: DiffEntry[], oldTotal: number, newTotal: number, contextLines: number = 3): Hunk[] {
|
|
117
|
+
if (diff.length === 0) return [];
|
|
118
|
+
|
|
119
|
+
// Find ranges of changes
|
|
120
|
+
const changeIndices: number[] = [];
|
|
121
|
+
for (let i = 0; i < diff.length; i++) {
|
|
122
|
+
if (diff[i].type !== "context") {
|
|
123
|
+
changeIndices.push(i);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (changeIndices.length === 0) return [];
|
|
128
|
+
|
|
129
|
+
// Group changes that are within contextLines*2 of each other
|
|
130
|
+
const groups: Array<{ start: number; end: number }> = [];
|
|
131
|
+
let groupStart = changeIndices[0];
|
|
132
|
+
let groupEnd = changeIndices[0];
|
|
133
|
+
|
|
134
|
+
for (let i = 1; i < changeIndices.length; i++) {
|
|
135
|
+
if (changeIndices[i] - groupEnd <= contextLines * 2 + 1) {
|
|
136
|
+
groupEnd = changeIndices[i];
|
|
137
|
+
} else {
|
|
138
|
+
groups.push({ start: groupStart, end: groupEnd });
|
|
139
|
+
groupStart = changeIndices[i];
|
|
140
|
+
groupEnd = changeIndices[i];
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
groups.push({ start: groupStart, end: groupEnd });
|
|
144
|
+
|
|
145
|
+
// Build hunks with context
|
|
146
|
+
const hunks: Hunk[] = [];
|
|
147
|
+
for (const group of groups) {
|
|
148
|
+
const hunkStart = Math.max(0, group.start - contextLines);
|
|
149
|
+
const hunkEnd = Math.min(diff.length - 1, group.end + contextLines);
|
|
150
|
+
|
|
151
|
+
const entries: DiffChunk[] = [];
|
|
152
|
+
let oldStart = Infinity, newStart = Infinity;
|
|
153
|
+
let oldCount = 0, newCount = 0;
|
|
154
|
+
|
|
155
|
+
for (let i = hunkStart; i <= hunkEnd; i++) {
|
|
156
|
+
const d = diff[i];
|
|
157
|
+
const lineNum = d.oldLine ?? d.newLine;
|
|
158
|
+
|
|
159
|
+
if (d.type === "context") {
|
|
160
|
+
entries.push({ type: "context", content: ` ${d.content}`, lineNumber: lineNum });
|
|
161
|
+
if (d.oldLine !== undefined && d.oldLine < oldStart) oldStart = d.oldLine;
|
|
162
|
+
if (d.newLine !== undefined && d.newLine < newStart) newStart = d.newLine;
|
|
163
|
+
oldCount++;
|
|
164
|
+
newCount++;
|
|
165
|
+
} else if (d.type === "remove") {
|
|
166
|
+
entries.push({ type: "remove", content: `-${d.content}`, lineNumber: d.oldLine });
|
|
167
|
+
if (d.oldLine !== undefined && d.oldLine < oldStart) oldStart = d.oldLine;
|
|
168
|
+
oldCount++;
|
|
169
|
+
} else {
|
|
170
|
+
entries.push({ type: "add", content: `+${d.content}`, lineNumber: d.newLine });
|
|
171
|
+
if (d.newLine !== undefined && d.newLine < newStart) newStart = d.newLine;
|
|
172
|
+
newCount++;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (oldStart === Infinity) oldStart = 1;
|
|
177
|
+
if (newStart === Infinity) newStart = 1;
|
|
178
|
+
|
|
179
|
+
hunks.push({
|
|
180
|
+
oldStart: oldStart - 1,
|
|
181
|
+
oldCount,
|
|
182
|
+
newStart: newStart - 1,
|
|
183
|
+
newCount,
|
|
184
|
+
entries,
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return hunks;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Stream a unified diff string hunk-by-hunk via callback.
|
|
193
|
+
*/
|
|
194
|
+
export function streamUnifiedDiff(diffText: string, onChunk: DiffChunkCallback): void {
|
|
195
|
+
const lines = diffText.split("\n");
|
|
196
|
+
|
|
197
|
+
for (const line of lines) {
|
|
198
|
+
if (line.startsWith("---") || line.startsWith("+++")) {
|
|
199
|
+
onChunk({ type: "file-header", content: line });
|
|
200
|
+
} else if (line.startsWith("@@")) {
|
|
201
|
+
onChunk({ type: "hunk-header", content: line });
|
|
202
|
+
} else if (line.startsWith("+")) {
|
|
203
|
+
onChunk({ type: "add", content: line });
|
|
204
|
+
} else if (line.startsWith("-")) {
|
|
205
|
+
onChunk({ type: "remove", content: line });
|
|
206
|
+
} else {
|
|
207
|
+
onChunk({ type: "context", content: line });
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* StreamingDiffAccumulator — collects tokens from an LLM stream and emits
|
|
214
|
+
* diff chunks as complete lines are formed. Used for real-time diff display
|
|
215
|
+
* while the model is still generating.
|
|
216
|
+
*/
|
|
217
|
+
export class StreamingDiffAccumulator {
|
|
218
|
+
private buffer: string = "";
|
|
219
|
+
private onChunk: DiffChunkCallback;
|
|
220
|
+
private lineNumber: number = 1;
|
|
221
|
+
|
|
222
|
+
constructor(onChunk: DiffChunkCallback) {
|
|
223
|
+
this.onChunk = onChunk;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/** Feed a token from the LLM stream */
|
|
227
|
+
addToken(token: string): void {
|
|
228
|
+
this.buffer += token;
|
|
229
|
+
|
|
230
|
+
// Emit complete lines
|
|
231
|
+
while (this.buffer.includes("\n")) {
|
|
232
|
+
const newlineIdx = this.buffer.indexOf("\n");
|
|
233
|
+
const line = this.buffer.substring(0, newlineIdx);
|
|
234
|
+
this.buffer = this.buffer.substring(newlineIdx + 1);
|
|
235
|
+
this.emitLine(line);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/** Flush any remaining content */
|
|
240
|
+
flush(): void {
|
|
241
|
+
if (this.buffer.length > 0) {
|
|
242
|
+
this.emitLine(this.buffer);
|
|
243
|
+
this.buffer = "";
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
private emitLine(line: string): void {
|
|
248
|
+
if (line.startsWith("---") || line.startsWith("+++")) {
|
|
249
|
+
this.onChunk({ type: "file-header", content: line });
|
|
250
|
+
} else if (line.startsWith("@@")) {
|
|
251
|
+
this.onChunk({ type: "hunk-header", content: line });
|
|
252
|
+
} else if (line.startsWith("+")) {
|
|
253
|
+
this.onChunk({ type: "add", content: line, lineNumber: this.lineNumber++ });
|
|
254
|
+
} else if (line.startsWith("-")) {
|
|
255
|
+
this.onChunk({ type: "remove", content: line, lineNumber: this.lineNumber++ });
|
|
256
|
+
} else {
|
|
257
|
+
this.onChunk({ type: "context", content: line, lineNumber: this.lineNumber++ });
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Todo/Task Manager
|
|
3
|
+
*
|
|
4
|
+
* Allows the LLM to create, update, and track tasks during a session.
|
|
5
|
+
* Tasks have a status: pending, in_progress, completed, or blocked.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export type TodoStatus = "pending" | "in_progress" | "completed" | "blocked";
|
|
9
|
+
|
|
10
|
+
export interface TodoItem {
|
|
11
|
+
id: string;
|
|
12
|
+
subject: string;
|
|
13
|
+
description?: string;
|
|
14
|
+
status: TodoStatus;
|
|
15
|
+
createdAt: number;
|
|
16
|
+
updatedAt: number;
|
|
17
|
+
blockedBy?: string[];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export class TodoStore {
|
|
21
|
+
private todos: Map<string, TodoItem> = new Map();
|
|
22
|
+
private nextId = 1;
|
|
23
|
+
|
|
24
|
+
/** Create a new todo item */
|
|
25
|
+
create(subject: string, description?: string): TodoItem {
|
|
26
|
+
const id = String(this.nextId++);
|
|
27
|
+
const todo: TodoItem = {
|
|
28
|
+
id,
|
|
29
|
+
subject,
|
|
30
|
+
description,
|
|
31
|
+
status: "pending",
|
|
32
|
+
createdAt: Date.now(),
|
|
33
|
+
updatedAt: Date.now(),
|
|
34
|
+
};
|
|
35
|
+
this.todos.set(id, todo);
|
|
36
|
+
return todo;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Get a todo by ID */
|
|
40
|
+
get(id: string): TodoItem | undefined {
|
|
41
|
+
return this.todos.get(id);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Update a todo's status */
|
|
45
|
+
updateStatus(id: string, status: TodoStatus): TodoItem | undefined {
|
|
46
|
+
const todo = this.todos.get(id);
|
|
47
|
+
if (todo) {
|
|
48
|
+
todo.status = status;
|
|
49
|
+
todo.updatedAt = Date.now();
|
|
50
|
+
}
|
|
51
|
+
return todo;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Update a todo's details */
|
|
55
|
+
update(id: string, updates: Partial<Pick<TodoItem, "subject" | "description" | "status" | "blockedBy">>): TodoItem | undefined {
|
|
56
|
+
const todo = this.todos.get(id);
|
|
57
|
+
if (todo) {
|
|
58
|
+
if (updates.subject !== undefined) todo.subject = updates.subject;
|
|
59
|
+
if (updates.description !== undefined) todo.description = updates.description;
|
|
60
|
+
if (updates.status !== undefined) todo.status = updates.status;
|
|
61
|
+
if (updates.blockedBy !== undefined) todo.blockedBy = updates.blockedBy;
|
|
62
|
+
todo.updatedAt = Date.now();
|
|
63
|
+
}
|
|
64
|
+
return todo;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Delete a todo */
|
|
68
|
+
delete(id: string): boolean {
|
|
69
|
+
return this.todos.delete(id);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Get all todos */
|
|
73
|
+
getAll(): TodoItem[] {
|
|
74
|
+
return Array.from(this.todos.values()).sort((a, b) => {
|
|
75
|
+
// Sort by status priority: in_progress > pending > blocked > completed
|
|
76
|
+
const statusOrder: Record<TodoStatus, number> = {
|
|
77
|
+
in_progress: 0,
|
|
78
|
+
pending: 1,
|
|
79
|
+
blocked: 2,
|
|
80
|
+
completed: 3,
|
|
81
|
+
};
|
|
82
|
+
const statusDiff = statusOrder[a.status] - statusOrder[b.status];
|
|
83
|
+
if (statusDiff !== 0) return statusDiff;
|
|
84
|
+
return a.createdAt - b.createdAt;
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Get todos by status */
|
|
89
|
+
getByStatus(status: TodoStatus): TodoItem[] {
|
|
90
|
+
return this.getAll().filter(t => t.status === status);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Get summary counts */
|
|
94
|
+
getSummary(): { pending: number; in_progress: number; completed: number; blocked: number; total: number } {
|
|
95
|
+
const todos = this.getAll();
|
|
96
|
+
return {
|
|
97
|
+
pending: todos.filter(t => t.status === "pending").length,
|
|
98
|
+
in_progress: todos.filter(t => t.status === "in_progress").length,
|
|
99
|
+
completed: todos.filter(t => t.status === "completed").length,
|
|
100
|
+
blocked: todos.filter(t => t.status === "blocked").length,
|
|
101
|
+
total: todos.length,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Clear all todos */
|
|
106
|
+
clear(): void {
|
|
107
|
+
this.todos.clear();
|
|
108
|
+
this.nextId = 1;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** Check if there are any active (non-completed) todos */
|
|
112
|
+
hasActiveTodos(): boolean {
|
|
113
|
+
return this.getAll().some(t => t.status !== "completed");
|
|
114
|
+
}
|
|
115
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"outDir": "dist",
|
|
6
|
+
"rootDir": "src",
|
|
7
|
+
"strict": true,
|
|
8
|
+
"esModuleInterop": true,
|
|
9
|
+
"skipLibCheck": true,
|
|
10
|
+
"declaration": true,
|
|
11
|
+
"declarationMap": true,
|
|
12
|
+
"sourceMap": true,
|
|
13
|
+
"resolveJsonModule": true,
|
|
14
|
+
"types": ["node"]
|
|
15
|
+
},
|
|
16
|
+
"include": ["src/**/*"],
|
|
17
|
+
"exclude": ["node_modules", "dist"]
|
|
18
|
+
}
|