@hivehub/rulebook 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +191 -0
- package/README.md +539 -0
- package/dist/agents/claude-code.d.ts +69 -0
- package/dist/agents/claude-code.d.ts.map +1 -0
- package/dist/agents/claude-code.js +180 -0
- package/dist/agents/claude-code.js.map +1 -0
- package/dist/agents/cursor-agent.d.ts +184 -0
- package/dist/agents/cursor-agent.d.ts.map +1 -0
- package/dist/agents/cursor-agent.js +299 -0
- package/dist/agents/cursor-agent.js.map +1 -0
- package/dist/agents/gemini-cli.d.ts +69 -0
- package/dist/agents/gemini-cli.d.ts.map +1 -0
- package/dist/agents/gemini-cli.js +180 -0
- package/dist/agents/gemini-cli.js.map +1 -0
- package/dist/cli/commands.d.ts +57 -0
- package/dist/cli/commands.d.ts.map +1 -0
- package/dist/cli/commands.js +1370 -0
- package/dist/cli/commands.js.map +1 -0
- package/dist/cli/docs-prompts.d.ts +3 -0
- package/dist/cli/docs-prompts.d.ts.map +1 -0
- package/dist/cli/docs-prompts.js +45 -0
- package/dist/cli/docs-prompts.js.map +1 -0
- package/dist/cli/prompts.d.ts +6 -0
- package/dist/cli/prompts.d.ts.map +1 -0
- package/dist/cli/prompts.js +376 -0
- package/dist/cli/prompts.js.map +1 -0
- package/dist/core/agent-manager.d.ts +89 -0
- package/dist/core/agent-manager.d.ts.map +1 -0
- package/dist/core/agent-manager.js +546 -0
- package/dist/core/agent-manager.js.map +1 -0
- package/dist/core/auto-fixer.d.ts +14 -0
- package/dist/core/auto-fixer.d.ts.map +1 -0
- package/dist/core/auto-fixer.js +207 -0
- package/dist/core/auto-fixer.js.map +1 -0
- package/dist/core/changelog-generator.d.ts +44 -0
- package/dist/core/changelog-generator.d.ts.map +1 -0
- package/dist/core/changelog-generator.js +222 -0
- package/dist/core/changelog-generator.js.map +1 -0
- package/dist/core/cli-bridge.d.ts +113 -0
- package/dist/core/cli-bridge.d.ts.map +1 -0
- package/dist/core/cli-bridge.js +1094 -0
- package/dist/core/cli-bridge.js.map +1 -0
- package/dist/core/config-manager.d.ts +65 -0
- package/dist/core/config-manager.d.ts.map +1 -0
- package/dist/core/config-manager.js +266 -0
- package/dist/core/config-manager.js.map +1 -0
- package/dist/core/coverage-checker.d.ts +14 -0
- package/dist/core/coverage-checker.d.ts.map +1 -0
- package/dist/core/coverage-checker.js +176 -0
- package/dist/core/coverage-checker.js.map +1 -0
- package/dist/core/custom-templates.d.ts +27 -0
- package/dist/core/custom-templates.d.ts.map +1 -0
- package/dist/core/custom-templates.js +122 -0
- package/dist/core/custom-templates.js.map +1 -0
- package/dist/core/dependency-checker.d.ts +21 -0
- package/dist/core/dependency-checker.d.ts.map +1 -0
- package/dist/core/dependency-checker.js +247 -0
- package/dist/core/dependency-checker.js.map +1 -0
- package/dist/core/detector.d.ts +3 -0
- package/dist/core/detector.d.ts.map +1 -0
- package/dist/core/detector.js +1443 -0
- package/dist/core/detector.js.map +1 -0
- package/dist/core/docs-generator.d.ts +9 -0
- package/dist/core/docs-generator.d.ts.map +1 -0
- package/dist/core/docs-generator.js +531 -0
- package/dist/core/docs-generator.js.map +1 -0
- package/dist/core/generator.d.ts +16 -0
- package/dist/core/generator.d.ts.map +1 -0
- package/dist/core/generator.js +561 -0
- package/dist/core/generator.js.map +1 -0
- package/dist/core/gitignore-generator.d.ts +13 -0
- package/dist/core/gitignore-generator.d.ts.map +1 -0
- package/dist/core/gitignore-generator.js +307 -0
- package/dist/core/gitignore-generator.js.map +1 -0
- package/dist/core/health-scorer.d.ts +22 -0
- package/dist/core/health-scorer.d.ts.map +1 -0
- package/dist/core/health-scorer.js +395 -0
- package/dist/core/health-scorer.js.map +1 -0
- package/dist/core/logger.d.ts +116 -0
- package/dist/core/logger.d.ts.map +1 -0
- package/dist/core/logger.js +289 -0
- package/dist/core/logger.js.map +1 -0
- package/dist/core/merger.d.ts +6 -0
- package/dist/core/merger.d.ts.map +1 -0
- package/dist/core/merger.js +131 -0
- package/dist/core/merger.js.map +1 -0
- package/dist/core/migrator.d.ts +19 -0
- package/dist/core/migrator.d.ts.map +1 -0
- package/dist/core/migrator.js +102 -0
- package/dist/core/migrator.js.map +1 -0
- package/dist/core/minimal-scaffolder.d.ts +8 -0
- package/dist/core/minimal-scaffolder.d.ts.map +1 -0
- package/dist/core/minimal-scaffolder.js +51 -0
- package/dist/core/minimal-scaffolder.js.map +1 -0
- package/dist/core/modern-console-new.d.ts +81 -0
- package/dist/core/modern-console-new.d.ts.map +1 -0
- package/dist/core/modern-console-new.js +340 -0
- package/dist/core/modern-console-new.js.map +1 -0
- package/dist/core/modern-console.d.ts +99 -0
- package/dist/core/modern-console.d.ts.map +1 -0
- package/dist/core/modern-console.js +568 -0
- package/dist/core/modern-console.js.map +1 -0
- package/dist/core/openspec-manager.d.ts +133 -0
- package/dist/core/openspec-manager.d.ts.map +1 -0
- package/dist/core/openspec-manager.js +605 -0
- package/dist/core/openspec-manager.js.map +1 -0
- package/dist/core/openspec-migrator.d.ts +27 -0
- package/dist/core/openspec-migrator.d.ts.map +1 -0
- package/dist/core/openspec-migrator.js +255 -0
- package/dist/core/openspec-migrator.js.map +1 -0
- package/dist/core/task-manager.d.ts +65 -0
- package/dist/core/task-manager.d.ts.map +1 -0
- package/dist/core/task-manager.js +318 -0
- package/dist/core/task-manager.js.map +1 -0
- package/dist/core/test-task-manager.d.ts +49 -0
- package/dist/core/test-task-manager.d.ts.map +1 -0
- package/dist/core/test-task-manager.js +121 -0
- package/dist/core/test-task-manager.js.map +1 -0
- package/dist/core/validator.d.ts +21 -0
- package/dist/core/validator.d.ts.map +1 -0
- package/dist/core/validator.js +177 -0
- package/dist/core/validator.js.map +1 -0
- package/dist/core/version-bumper.d.ts +19 -0
- package/dist/core/version-bumper.d.ts.map +1 -0
- package/dist/core/version-bumper.js +180 -0
- package/dist/core/version-bumper.js.map +1 -0
- package/dist/core/watcher.d.ts +9 -0
- package/dist/core/watcher.d.ts.map +1 -0
- package/dist/core/watcher.js +22 -0
- package/dist/core/watcher.js.map +1 -0
- package/dist/core/workflow-generator.d.ts +10 -0
- package/dist/core/workflow-generator.d.ts.map +1 -0
- package/dist/core/workflow-generator.js +279 -0
- package/dist/core/workflow-generator.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +159 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/handlers/archive-task.d.ts +17 -0
- package/dist/mcp/handlers/archive-task.d.ts.map +1 -0
- package/dist/mcp/handlers/archive-task.js +36 -0
- package/dist/mcp/handlers/archive-task.js.map +1 -0
- package/dist/mcp/handlers/create-task.d.ts +17 -0
- package/dist/mcp/handlers/create-task.d.ts.map +1 -0
- package/dist/mcp/handlers/create-task.js +56 -0
- package/dist/mcp/handlers/create-task.js.map +1 -0
- package/dist/mcp/handlers/list-tasks.d.ts +22 -0
- package/dist/mcp/handlers/list-tasks.d.ts.map +1 -0
- package/dist/mcp/handlers/list-tasks.js +42 -0
- package/dist/mcp/handlers/list-tasks.js.map +1 -0
- package/dist/mcp/handlers/show-task.d.ts +25 -0
- package/dist/mcp/handlers/show-task.d.ts.map +1 -0
- package/dist/mcp/handlers/show-task.js +43 -0
- package/dist/mcp/handlers/show-task.js.map +1 -0
- package/dist/mcp/handlers/update-task.d.ts +17 -0
- package/dist/mcp/handlers/update-task.d.ts.map +1 -0
- package/dist/mcp/handlers/update-task.js +35 -0
- package/dist/mcp/handlers/update-task.js.map +1 -0
- package/dist/mcp/handlers/validate-task.d.ts +15 -0
- package/dist/mcp/handlers/validate-task.d.ts.map +1 -0
- package/dist/mcp/handlers/validate-task.js +27 -0
- package/dist/mcp/handlers/validate-task.js.map +1 -0
- package/dist/mcp/rulebook-config.d.ts +22 -0
- package/dist/mcp/rulebook-config.d.ts.map +1 -0
- package/dist/mcp/rulebook-config.js +65 -0
- package/dist/mcp/rulebook-config.js.map +1 -0
- package/dist/mcp/rulebook-server.d.ts +4 -0
- package/dist/mcp/rulebook-server.d.ts.map +1 -0
- package/dist/mcp/rulebook-server.js +246 -0
- package/dist/mcp/rulebook-server.js.map +1 -0
- package/dist/types.d.ts +190 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/file-system.d.ts +9 -0
- package/dist/utils/file-system.d.ts.map +1 -0
- package/dist/utils/file-system.js +51 -0
- package/dist/utils/file-system.js.map +1 -0
- package/dist/utils/git-hooks.d.ts +8 -0
- package/dist/utils/git-hooks.d.ts.map +1 -0
- package/dist/utils/git-hooks.js +440 -0
- package/dist/utils/git-hooks.js.map +1 -0
- package/dist/utils/rulesignore.d.ts +9 -0
- package/dist/utils/rulesignore.d.ts.map +1 -0
- package/dist/utils/rulesignore.js +42 -0
- package/dist/utils/rulesignore.js.map +1 -0
- package/package.json +106 -0
- package/templates/cli/AIDER.md +49 -0
- package/templates/cli/AMAZON_Q.md +25 -0
- package/templates/cli/AUGGIE.md +32 -0
- package/templates/cli/CLAUDE.md +32 -0
- package/templates/cli/CLAUDE_CODE.md +35 -0
- package/templates/cli/CLINE.md +32 -0
- package/templates/cli/CODEBUDDY.md +20 -0
- package/templates/cli/CODEIUM.md +20 -0
- package/templates/cli/CODEX.md +21 -0
- package/templates/cli/CONTINUE.md +34 -0
- package/templates/cli/CURSOR_CLI.md +28 -0
- package/templates/cli/FACTORY.md +18 -0
- package/templates/cli/GEMINI.md +35 -0
- package/templates/cli/KILOCODE.md +18 -0
- package/templates/cli/OPENCODE.md +18 -0
- package/templates/cli/_GENERIC_TEMPLATE.md +29 -0
- package/templates/commands/rulebook-task-apply.md +67 -0
- package/templates/commands/rulebook-task-archive.md +70 -0
- package/templates/commands/rulebook-task-create.md +93 -0
- package/templates/commands/rulebook-task-list.md +42 -0
- package/templates/commands/rulebook-task-show.md +52 -0
- package/templates/commands/rulebook-task-validate.md +53 -0
- package/templates/core/AGENT_AUTOMATION.md +184 -0
- package/templates/core/DAG.md +304 -0
- package/templates/core/DOCUMENTATION_RULES.md +37 -0
- package/templates/core/QUALITY_ENFORCEMENT.md +68 -0
- package/templates/core/RULEBOOK.md +1874 -0
- package/templates/frameworks/ANGULAR.md +36 -0
- package/templates/frameworks/DJANGO.md +83 -0
- package/templates/frameworks/ELECTRON.md +147 -0
- package/templates/frameworks/FLASK.md +38 -0
- package/templates/frameworks/FLUTTER.md +55 -0
- package/templates/frameworks/JQUERY.md +32 -0
- package/templates/frameworks/LARAVEL.md +38 -0
- package/templates/frameworks/NESTJS.md +43 -0
- package/templates/frameworks/NEXTJS.md +127 -0
- package/templates/frameworks/NUXT.md +40 -0
- package/templates/frameworks/RAILS.md +66 -0
- package/templates/frameworks/REACT.md +38 -0
- package/templates/frameworks/REACT_NATIVE.md +47 -0
- package/templates/frameworks/SPRING.md +39 -0
- package/templates/frameworks/SYMFONY.md +36 -0
- package/templates/frameworks/VUE.md +36 -0
- package/templates/frameworks/ZEND.md +35 -0
- package/templates/git/CI_CD_PATTERNS.md +661 -0
- package/templates/git/GITHUB_ACTIONS.md +728 -0
- package/templates/git/GITLAB_CI.md +730 -0
- package/templates/git/GIT_WORKFLOW.md +1157 -0
- package/templates/git/SECRETS_MANAGEMENT.md +585 -0
- package/templates/hooks/COMMIT_MSG.md +530 -0
- package/templates/hooks/POST_CHECKOUT.md +546 -0
- package/templates/hooks/PREPARE_COMMIT_MSG.md +619 -0
- package/templates/hooks/PRE_COMMIT.md +414 -0
- package/templates/hooks/PRE_PUSH.md +601 -0
- package/templates/hooks/csharp-pre-commit.sh +23 -0
- package/templates/hooks/csharp-pre-push.sh +23 -0
- package/templates/hooks/dart-pre-commit.sh +30 -0
- package/templates/hooks/dart-pre-push.sh +25 -0
- package/templates/hooks/elixir-pre-commit.sh +32 -0
- package/templates/hooks/elixir-pre-push.sh +31 -0
- package/templates/hooks/erlang-pre-commit.sh +30 -0
- package/templates/hooks/erlang-pre-push.sh +37 -0
- package/templates/hooks/go-pre-commit.sh +40 -0
- package/templates/hooks/go-pre-push.sh +31 -0
- package/templates/hooks/haskell-pre-commit.sh +41 -0
- package/templates/hooks/haskell-pre-push.sh +37 -0
- package/templates/hooks/java-pre-commit.sh +34 -0
- package/templates/hooks/java-pre-push.sh +24 -0
- package/templates/hooks/kotlin-pre-commit.sh +32 -0
- package/templates/hooks/kotlin-pre-push.sh +16 -0
- package/templates/hooks/php-pre-commit.sh +36 -0
- package/templates/hooks/php-pre-push.sh +26 -0
- package/templates/hooks/python-pre-commit.sh +51 -0
- package/templates/hooks/python-pre-push.sh +25 -0
- package/templates/hooks/ruby-pre-commit.sh +33 -0
- package/templates/hooks/ruby-pre-push.sh +32 -0
- package/templates/hooks/rust-pre-commit.sh +30 -0
- package/templates/hooks/rust-pre-push.sh +30 -0
- package/templates/hooks/scala-pre-commit.sh +32 -0
- package/templates/hooks/scala-pre-push.sh +24 -0
- package/templates/hooks/swift-pre-commit.sh +25 -0
- package/templates/hooks/swift-pre-push.sh +23 -0
- package/templates/hooks/typescript-pre-commit.sh +37 -0
- package/templates/hooks/typescript-pre-push.sh +36 -0
- package/templates/ides/COPILOT.md +37 -0
- package/templates/ides/CURSOR.md +43 -0
- package/templates/ides/JETBRAINS_AI.md +35 -0
- package/templates/ides/REPLIT.md +36 -0
- package/templates/ides/TABNINE.md +29 -0
- package/templates/ides/VSCODE.md +40 -0
- package/templates/ides/WINDSURF.md +36 -0
- package/templates/ides/ZED.md +32 -0
- package/templates/languages/ADA.md +58 -0
- package/templates/languages/C.md +333 -0
- package/templates/languages/CPP.md +743 -0
- package/templates/languages/CSHARP.md +417 -0
- package/templates/languages/DART.md +332 -0
- package/templates/languages/ELIXIR.md +454 -0
- package/templates/languages/ERLANG.md +361 -0
- package/templates/languages/GO.md +645 -0
- package/templates/languages/HASKELL.md +177 -0
- package/templates/languages/JAVA.md +607 -0
- package/templates/languages/JAVASCRIPT.md +631 -0
- package/templates/languages/JULIA.md +97 -0
- package/templates/languages/KOTLIN.md +511 -0
- package/templates/languages/LISP.md +100 -0
- package/templates/languages/LUA.md +74 -0
- package/templates/languages/OBJECTIVEC.md +90 -0
- package/templates/languages/PHP.md +416 -0
- package/templates/languages/PYTHON.md +682 -0
- package/templates/languages/R.md +350 -0
- package/templates/languages/RUBY.md +421 -0
- package/templates/languages/RUST.md +477 -0
- package/templates/languages/SAS.md +73 -0
- package/templates/languages/SCALA.md +348 -0
- package/templates/languages/SOLIDITY.md +580 -0
- package/templates/languages/SQL.md +137 -0
- package/templates/languages/SWIFT.md +466 -0
- package/templates/languages/TYPESCRIPT.md +591 -0
- package/templates/languages/ZIG.md +265 -0
- package/templates/modules/ATLASSIAN.md +255 -0
- package/templates/modules/CONTEXT7.md +54 -0
- package/templates/modules/FIGMA.md +267 -0
- package/templates/modules/GITHUB_MCP.md +64 -0
- package/templates/modules/GRAFANA.md +328 -0
- package/templates/modules/NOTION.md +247 -0
- package/templates/modules/PLAYWRIGHT.md +90 -0
- package/templates/modules/RULEBOOK_MCP.md +156 -0
- package/templates/modules/SERENA.md +337 -0
- package/templates/modules/SUPABASE.md +223 -0
- package/templates/modules/SYNAP.md +69 -0
- package/templates/modules/VECTORIZER.md +63 -0
- package/templates/services/AZURE_BLOB.md +184 -0
- package/templates/services/CASSANDRA.md +239 -0
- package/templates/services/DYNAMODB.md +308 -0
- package/templates/services/ELASTICSEARCH.md +347 -0
- package/templates/services/GCS.md +178 -0
- package/templates/services/INFLUXDB.md +265 -0
- package/templates/services/KAFKA.md +341 -0
- package/templates/services/MARIADB.md +183 -0
- package/templates/services/MEMCACHED.md +242 -0
- package/templates/services/MINIO.md +201 -0
- package/templates/services/MONGODB.md +268 -0
- package/templates/services/MYSQL.md +358 -0
- package/templates/services/NEO4J.md +247 -0
- package/templates/services/ORACLE.md +290 -0
- package/templates/services/POSTGRESQL.md +326 -0
- package/templates/services/RABBITMQ.md +286 -0
- package/templates/services/REDIS.md +292 -0
- package/templates/services/S3.md +298 -0
- package/templates/services/SQLITE.md +294 -0
- package/templates/services/SQLSERVER.md +294 -0
- package/templates/workflows/codespell.yml +31 -0
- package/templates/workflows/cpp-lint.yml +47 -0
- package/templates/workflows/cpp-publish.yml +119 -0
- package/templates/workflows/cpp-test.yml +77 -0
- package/templates/workflows/dotnet-lint.yml +29 -0
- package/templates/workflows/dotnet-publish.yml +40 -0
- package/templates/workflows/dotnet-test.yml +41 -0
- package/templates/workflows/elixir-lint.yml +45 -0
- package/templates/workflows/elixir-publish.yml +49 -0
- package/templates/workflows/elixir-test.yml +54 -0
- package/templates/workflows/erlang-lint.yml +47 -0
- package/templates/workflows/erlang-test.yml +62 -0
- package/templates/workflows/go-lint.yml +39 -0
- package/templates/workflows/go-publish.yml +95 -0
- package/templates/workflows/go-test.yml +59 -0
- package/templates/workflows/java-lint.yml +60 -0
- package/templates/workflows/java-publish.yml +120 -0
- package/templates/workflows/java-test.yml +85 -0
- package/templates/workflows/kotlin-lint.yml +34 -0
- package/templates/workflows/kotlin-publish.yml +56 -0
- package/templates/workflows/kotlin-test.yml +48 -0
- package/templates/workflows/php-lint.yml +39 -0
- package/templates/workflows/php-publish.yml +50 -0
- package/templates/workflows/php-test.yml +54 -0
- package/templates/workflows/python-lint.yml +47 -0
- package/templates/workflows/python-publish.yml +91 -0
- package/templates/workflows/python-test.yml +59 -0
- package/templates/workflows/rust-lint.yml +54 -0
- package/templates/workflows/rust-publish.yml +66 -0
- package/templates/workflows/rust-test.yml +75 -0
- package/templates/workflows/solidity-lint.yml +41 -0
- package/templates/workflows/solidity-test.yml +47 -0
- package/templates/workflows/swift-lint.yml +32 -0
- package/templates/workflows/swift-publish.yml +58 -0
- package/templates/workflows/swift-test.yml +44 -0
- package/templates/workflows/typescript-lint.yml +61 -0
- package/templates/workflows/typescript-publish.yml +60 -0
- package/templates/workflows/typescript-test.yml +73 -0
- package/templates/workflows/zig-lint.yml +27 -0
- package/templates/workflows/zig-test.yml +40 -0
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* claude-code Stream Parser
|
|
3
|
+
*
|
|
4
|
+
* Parses output from claude-code CLI
|
|
5
|
+
* Command: claude --headless "PROMPT"
|
|
6
|
+
* Output: Stream of text with progress indicators
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Parse a single line from claude-code output
|
|
10
|
+
*/
|
|
11
|
+
export function parseClaudeCodeLine(line) {
|
|
12
|
+
try {
|
|
13
|
+
const trimmed = line.trim();
|
|
14
|
+
if (!trimmed)
|
|
15
|
+
return null;
|
|
16
|
+
// Look for progress indicators
|
|
17
|
+
if (trimmed.includes('...') || trimmed.includes('thinking') || trimmed.includes('processing')) {
|
|
18
|
+
return {
|
|
19
|
+
type: 'progress',
|
|
20
|
+
content: trimmed,
|
|
21
|
+
timestamp: Date.now(),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
// Look for tool calls
|
|
25
|
+
if (trimmed.includes('🔧') || trimmed.includes('Tool:') || trimmed.includes('Executing:')) {
|
|
26
|
+
return {
|
|
27
|
+
type: 'tool_call',
|
|
28
|
+
content: trimmed,
|
|
29
|
+
timestamp: Date.now(),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
// Look for completion indicators
|
|
33
|
+
if (trimmed.includes('✅') || trimmed.includes('Complete') || trimmed.includes('Done')) {
|
|
34
|
+
return {
|
|
35
|
+
type: 'completion',
|
|
36
|
+
content: trimmed,
|
|
37
|
+
timestamp: Date.now(),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
// Look for errors
|
|
41
|
+
if (trimmed.includes('❌') || trimmed.includes('Error:') || trimmed.includes('Failed:')) {
|
|
42
|
+
return {
|
|
43
|
+
type: 'error',
|
|
44
|
+
content: trimmed,
|
|
45
|
+
timestamp: Date.now(),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
// Default to text content
|
|
49
|
+
return {
|
|
50
|
+
type: 'text',
|
|
51
|
+
content: trimmed,
|
|
52
|
+
timestamp: Date.now(),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
// Failed to parse line - ignore silently
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Process claude-code stream output with real-time progress
|
|
62
|
+
*/
|
|
63
|
+
export class ClaudeCodeStreamParser {
|
|
64
|
+
accumulatedText = '';
|
|
65
|
+
toolCalls = [];
|
|
66
|
+
sessionId = `claude-${Date.now()}`;
|
|
67
|
+
startTime = Date.now();
|
|
68
|
+
toolCount = 0;
|
|
69
|
+
completed = false;
|
|
70
|
+
completionCallback;
|
|
71
|
+
/**
|
|
72
|
+
* Set callback to be called when completion is detected
|
|
73
|
+
*/
|
|
74
|
+
onComplete(callback) {
|
|
75
|
+
this.completionCallback = callback;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Check if parsing is completed
|
|
79
|
+
*/
|
|
80
|
+
isCompleted() {
|
|
81
|
+
return this.completed;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Process a single event from the stream
|
|
85
|
+
*/
|
|
86
|
+
processEvent(event) {
|
|
87
|
+
switch (event.type) {
|
|
88
|
+
case 'progress':
|
|
89
|
+
this.handleProgressEvent(event);
|
|
90
|
+
break;
|
|
91
|
+
case 'text':
|
|
92
|
+
this.handleTextEvent(event);
|
|
93
|
+
break;
|
|
94
|
+
case 'tool_call':
|
|
95
|
+
this.handleToolCallEvent(event);
|
|
96
|
+
break;
|
|
97
|
+
case 'completion':
|
|
98
|
+
this.handleCompletionEvent(event);
|
|
99
|
+
break;
|
|
100
|
+
case 'error':
|
|
101
|
+
this.handleErrorEvent(event);
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Process multiple lines of stream output
|
|
107
|
+
*/
|
|
108
|
+
processLines(output) {
|
|
109
|
+
const lines = output.split('\n');
|
|
110
|
+
for (const line of lines) {
|
|
111
|
+
const event = parseClaudeCodeLine(line);
|
|
112
|
+
if (event) {
|
|
113
|
+
this.processEvent(event);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Get the final parsed result
|
|
119
|
+
*/
|
|
120
|
+
getResult() {
|
|
121
|
+
return {
|
|
122
|
+
success: !this.completed || this.accumulatedText.length > 0,
|
|
123
|
+
text: this.accumulatedText,
|
|
124
|
+
toolCalls: this.toolCalls,
|
|
125
|
+
duration: Date.now() - this.startTime,
|
|
126
|
+
sessionId: this.sessionId,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
handleProgressEvent(_event) {
|
|
130
|
+
// Progress logged silently
|
|
131
|
+
}
|
|
132
|
+
handleTextEvent(event) {
|
|
133
|
+
// Accumulate text content
|
|
134
|
+
if (event.content && !this.accumulatedText.includes(event.content)) {
|
|
135
|
+
this.accumulatedText += event.content + '\n';
|
|
136
|
+
// Progress logged silently
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
handleToolCallEvent(event) {
|
|
140
|
+
this.toolCount++;
|
|
141
|
+
// Extract tool type and details from content
|
|
142
|
+
let toolType = 'bash';
|
|
143
|
+
const details = event.content;
|
|
144
|
+
if (event.content.includes('read') || event.content.includes('📖')) {
|
|
145
|
+
toolType = 'read';
|
|
146
|
+
}
|
|
147
|
+
else if (event.content.includes('write') || event.content.includes('📝')) {
|
|
148
|
+
toolType = 'write';
|
|
149
|
+
}
|
|
150
|
+
// Tool call logged silently
|
|
151
|
+
this.toolCalls.push({
|
|
152
|
+
type: toolType,
|
|
153
|
+
details,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
handleCompletionEvent(_event) {
|
|
157
|
+
// Completion logged silently
|
|
158
|
+
// Mark as completed and trigger callback
|
|
159
|
+
this.completed = true;
|
|
160
|
+
if (this.completionCallback) {
|
|
161
|
+
this.completionCallback();
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
handleErrorEvent(event) {
|
|
165
|
+
// Error logged silently
|
|
166
|
+
// Update last tool call with error if available
|
|
167
|
+
if (this.toolCalls.length > 0) {
|
|
168
|
+
this.toolCalls[this.toolCalls.length - 1].result = `Error: ${event.content}`;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Parse complete claude-code output
|
|
174
|
+
*/
|
|
175
|
+
export function parseClaudeCodeOutput(output) {
|
|
176
|
+
const parser = new ClaudeCodeStreamParser();
|
|
177
|
+
parser.processLines(output);
|
|
178
|
+
return parser.getResult();
|
|
179
|
+
}
|
|
180
|
+
//# sourceMappingURL=claude-code.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claude-code.js","sourceRoot":"","sources":["../../src/agents/claude-code.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAoBH;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,IAAY;IAC9C,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QAC5B,IAAI,CAAC,OAAO;YAAE,OAAO,IAAI,CAAC;QAE1B,+BAA+B;QAC/B,IAAI,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC;YAC9F,OAAO;gBACL,IAAI,EAAE,UAAU;gBAChB,OAAO,EAAE,OAAO;gBAChB,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;aACtB,CAAC;QACJ,CAAC;QAED,sBAAsB;QACtB,IAAI,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC;YAC1F,OAAO;gBACL,IAAI,EAAE,WAAW;gBACjB,OAAO,EAAE,OAAO;gBAChB,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;aACtB,CAAC;QACJ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9B,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,MAAM,GAAG,UAAU,KAAK,CAAC,OAAO,EAAE,CAAC;QAC/E,CAAC;IACH,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,qBAAqB,CAAC,MAAc;IAClD,MAAM,MAAM,GAAG,IAAI,sBAAsB,EAAE,CAAC;IAC5C,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;IAC5B,OAAO,MAAM,CAAC,SAAS,EAAE,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* cursor-agent Stream Parser
|
|
3
|
+
*
|
|
4
|
+
* Parses stream-json output from cursor-agent CLI
|
|
5
|
+
* Format: Each line is a complete JSON object
|
|
6
|
+
*/
|
|
7
|
+
export interface SystemInitEvent {
|
|
8
|
+
type: 'system';
|
|
9
|
+
subtype: 'init';
|
|
10
|
+
apiKeySource: string;
|
|
11
|
+
cwd: string;
|
|
12
|
+
session_id: string;
|
|
13
|
+
model: string;
|
|
14
|
+
permissionMode: string;
|
|
15
|
+
}
|
|
16
|
+
export interface UserMessageEvent {
|
|
17
|
+
type: 'user';
|
|
18
|
+
message: {
|
|
19
|
+
role: 'user';
|
|
20
|
+
content: Array<{
|
|
21
|
+
type: string;
|
|
22
|
+
text: string;
|
|
23
|
+
}>;
|
|
24
|
+
};
|
|
25
|
+
session_id: string;
|
|
26
|
+
}
|
|
27
|
+
export interface AssistantMessageEvent {
|
|
28
|
+
type: 'assistant';
|
|
29
|
+
message: {
|
|
30
|
+
role: 'assistant';
|
|
31
|
+
content: Array<{
|
|
32
|
+
type: string;
|
|
33
|
+
text: string;
|
|
34
|
+
}>;
|
|
35
|
+
};
|
|
36
|
+
session_id: string;
|
|
37
|
+
timestamp_ms?: number;
|
|
38
|
+
}
|
|
39
|
+
export interface ToolCallStartedEvent {
|
|
40
|
+
type: 'tool_call';
|
|
41
|
+
subtype: 'started';
|
|
42
|
+
tool_call: {
|
|
43
|
+
writeToolCall?: {
|
|
44
|
+
args: {
|
|
45
|
+
path: string;
|
|
46
|
+
contents: string;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
readToolCall?: {
|
|
50
|
+
args: {
|
|
51
|
+
path: string;
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
bashToolCall?: {
|
|
55
|
+
args: {
|
|
56
|
+
command: string;
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
editToolCall?: {
|
|
60
|
+
args: {
|
|
61
|
+
path: string;
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
session_id: string;
|
|
66
|
+
}
|
|
67
|
+
export interface ToolCallCompletedEvent {
|
|
68
|
+
type: 'tool_call';
|
|
69
|
+
subtype: 'completed';
|
|
70
|
+
tool_call: {
|
|
71
|
+
writeToolCall?: {
|
|
72
|
+
result: {
|
|
73
|
+
success?: {
|
|
74
|
+
linesCreated: number;
|
|
75
|
+
fileSize: number;
|
|
76
|
+
};
|
|
77
|
+
error?: string;
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
readToolCall?: {
|
|
81
|
+
result: {
|
|
82
|
+
success?: {
|
|
83
|
+
totalLines: number;
|
|
84
|
+
content: string;
|
|
85
|
+
};
|
|
86
|
+
error?: string;
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
bashToolCall?: {
|
|
90
|
+
result: {
|
|
91
|
+
success?: {
|
|
92
|
+
exitCode: number;
|
|
93
|
+
stdout: string;
|
|
94
|
+
stderr: string;
|
|
95
|
+
};
|
|
96
|
+
error?: string;
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
editToolCall?: {
|
|
100
|
+
result: {
|
|
101
|
+
success?: {
|
|
102
|
+
linesAdded: number;
|
|
103
|
+
linesRemoved: number;
|
|
104
|
+
path: string;
|
|
105
|
+
};
|
|
106
|
+
error?: string;
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
session_id: string;
|
|
111
|
+
}
|
|
112
|
+
export interface ResultEvent {
|
|
113
|
+
type: 'result';
|
|
114
|
+
subtype: 'success' | 'error';
|
|
115
|
+
duration_ms: number;
|
|
116
|
+
duration_api_ms: number;
|
|
117
|
+
is_error: boolean;
|
|
118
|
+
result: string;
|
|
119
|
+
session_id: string;
|
|
120
|
+
request_id: string;
|
|
121
|
+
}
|
|
122
|
+
export type CursorAgentEvent = SystemInitEvent | UserMessageEvent | AssistantMessageEvent | ToolCallStartedEvent | ToolCallCompletedEvent | ResultEvent;
|
|
123
|
+
export interface ParsedResult {
|
|
124
|
+
success: boolean;
|
|
125
|
+
text: string;
|
|
126
|
+
toolCalls: Array<{
|
|
127
|
+
type: 'read' | 'write' | 'bash' | 'edit';
|
|
128
|
+
details: string;
|
|
129
|
+
result?: string;
|
|
130
|
+
}>;
|
|
131
|
+
duration: number;
|
|
132
|
+
sessionId: string;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Parse a single JSON line from cursor-agent stream
|
|
136
|
+
*/
|
|
137
|
+
export declare function parseStreamLine(line: string): CursorAgentEvent | null;
|
|
138
|
+
/**
|
|
139
|
+
* Process cursor-agent stream output with real-time progress
|
|
140
|
+
*/
|
|
141
|
+
export declare class CursorAgentStreamParser {
|
|
142
|
+
private accumulatedText;
|
|
143
|
+
private toolCalls;
|
|
144
|
+
private sessionId;
|
|
145
|
+
private startTime;
|
|
146
|
+
private toolCount;
|
|
147
|
+
private completed;
|
|
148
|
+
private completionCallback?;
|
|
149
|
+
private eventCallback?;
|
|
150
|
+
/**
|
|
151
|
+
* Set callback to be called when result event is received
|
|
152
|
+
*/
|
|
153
|
+
onComplete(callback: () => void): void;
|
|
154
|
+
/**
|
|
155
|
+
* Set callback to be called for each event (for watcher UI)
|
|
156
|
+
*/
|
|
157
|
+
onEvent(callback: (type: 'tool' | 'text' | 'completion', message: string) => void): void;
|
|
158
|
+
/**
|
|
159
|
+
* Check if parsing is completed
|
|
160
|
+
*/
|
|
161
|
+
isCompleted(): boolean;
|
|
162
|
+
/**
|
|
163
|
+
* Process a single event from the stream
|
|
164
|
+
*/
|
|
165
|
+
processEvent(event: CursorAgentEvent): void;
|
|
166
|
+
/**
|
|
167
|
+
* Process multiple lines of stream output
|
|
168
|
+
*/
|
|
169
|
+
processLines(output: string): void;
|
|
170
|
+
/**
|
|
171
|
+
* Get the final parsed result
|
|
172
|
+
*/
|
|
173
|
+
getResult(): ParsedResult;
|
|
174
|
+
private handleSystemEvent;
|
|
175
|
+
private handleUserEvent;
|
|
176
|
+
private handleAssistantEvent;
|
|
177
|
+
private handleToolCallEvent;
|
|
178
|
+
private handleResultEvent;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Parse complete cursor-agent stream output
|
|
182
|
+
*/
|
|
183
|
+
export declare function parseCursorAgentOutput(output: string): ParsedResult;
|
|
184
|
+
//# sourceMappingURL=cursor-agent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cursor-agent.d.ts","sourceRoot":"","sources":["../../src/agents/cursor-agent.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,QAAQ,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE;QACP,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,KAAK,CAAC;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;KAChD,CAAC;IACF,UAA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
*
|
|
4
|
+
* Parses stream-json output from cursor-agent CLI
|
|
5
|
+
* Format: Each line is a complete JSON object
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Parse a single JSON line from cursor-agent stream
|
|
9
|
+
*/
|
|
10
|
+
export function parseStreamLine(line) {
|
|
11
|
+
try {
|
|
12
|
+
const trimmed = line.trim();
|
|
13
|
+
if (!trimmed)
|
|
14
|
+
return null;
|
|
15
|
+
const event = JSON.parse(trimmed);
|
|
16
|
+
return event;
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
// Failed to parse JSON line - ignore silently
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Process cursor-agent stream output with real-time progress
|
|
25
|
+
*/
|
|
26
|
+
export class CursorAgentStreamParser {
|
|
27
|
+
accumulatedText = '';
|
|
28
|
+
toolCalls = [];
|
|
29
|
+
sessionId = '';
|
|
30
|
+
startTime = Date.now();
|
|
31
|
+
toolCount = 0;
|
|
32
|
+
completed = false;
|
|
33
|
+
completionCallback;
|
|
34
|
+
eventCallback;
|
|
35
|
+
/**
|
|
36
|
+
* Set callback to be called when result event is received
|
|
37
|
+
*/
|
|
38
|
+
onComplete(callback) {
|
|
39
|
+
this.completionCallback = callback;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Set callback to be called for each event (for watcher UI)
|
|
43
|
+
*/
|
|
44
|
+
onEvent(callback) {
|
|
45
|
+
this.eventCallback = callback;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Check if parsing is completed
|
|
49
|
+
*/
|
|
50
|
+
isCompleted() {
|
|
51
|
+
return this.completed;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Process a single event from the stream
|
|
55
|
+
*/
|
|
56
|
+
processEvent(event) {
|
|
57
|
+
// Don't log debug info - it interferes with blessed UI
|
|
58
|
+
switch (event.type) {
|
|
59
|
+
case 'system':
|
|
60
|
+
this.handleSystemEvent(event);
|
|
61
|
+
break;
|
|
62
|
+
case 'user':
|
|
63
|
+
this.handleUserEvent(event);
|
|
64
|
+
break;
|
|
65
|
+
case 'assistant':
|
|
66
|
+
this.handleAssistantEvent(event);
|
|
67
|
+
break;
|
|
68
|
+
case 'tool_call':
|
|
69
|
+
this.handleToolCallEvent(event);
|
|
70
|
+
break;
|
|
71
|
+
case 'result':
|
|
72
|
+
this.handleResultEvent(event);
|
|
73
|
+
break;
|
|
74
|
+
default:
|
|
75
|
+
// Unknown event type - ignore
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Process multiple lines of stream output
|
|
80
|
+
*/
|
|
81
|
+
processLines(output) {
|
|
82
|
+
const lines = output.split('\n');
|
|
83
|
+
for (const line of lines) {
|
|
84
|
+
const event = parseStreamLine(line);
|
|
85
|
+
if (event) {
|
|
86
|
+
this.processEvent(event);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Get the final parsed result
|
|
92
|
+
*/
|
|
93
|
+
getResult() {
|
|
94
|
+
return {
|
|
95
|
+
success: true,
|
|
96
|
+
text: this.accumulatedText,
|
|
97
|
+
toolCalls: this.toolCalls,
|
|
98
|
+
duration: Date.now() - this.startTime,
|
|
99
|
+
sessionId: this.sessionId,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
handleSystemEvent(event) {
|
|
103
|
+
if (event.subtype === 'init') {
|
|
104
|
+
this.sessionId = event.session_id;
|
|
105
|
+
// System info logged silently
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
handleUserEvent(event) {
|
|
109
|
+
this.sessionId = event.session_id;
|
|
110
|
+
// User message is just echoed back, no action needed
|
|
111
|
+
}
|
|
112
|
+
handleAssistantEvent(event) {
|
|
113
|
+
this.sessionId = event.session_id;
|
|
114
|
+
// Extract text content from assistant message
|
|
115
|
+
const text = event.message.content
|
|
116
|
+
.filter((c) => c.type === 'text')
|
|
117
|
+
.map((c) => c.text)
|
|
118
|
+
.join('');
|
|
119
|
+
// Accumulate text (stream-partial-output sends incremental deltas)
|
|
120
|
+
if (text && !this.accumulatedText.includes(text)) {
|
|
121
|
+
const previousLength = this.accumulatedText.length;
|
|
122
|
+
this.accumulatedText = text;
|
|
123
|
+
// Log progress every 500 chars to show the agent is working
|
|
124
|
+
if (this.eventCallback && Math.floor(text.length / 500) > Math.floor(previousLength / 500)) {
|
|
125
|
+
const chars = Math.round(text.length / 100) / 10;
|
|
126
|
+
this.eventCallback('text', `Thinking... (${chars}k chars)`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
handleToolCallEvent(event) {
|
|
131
|
+
this.sessionId = event.session_id;
|
|
132
|
+
if (event.subtype === 'started') {
|
|
133
|
+
this.toolCount++;
|
|
134
|
+
const startedEvent = event;
|
|
135
|
+
if (startedEvent.tool_call.writeToolCall) {
|
|
136
|
+
const path = startedEvent.tool_call.writeToolCall.args.path;
|
|
137
|
+
const details = `Write to ${path}`;
|
|
138
|
+
// Send to watcher/CLI with full path
|
|
139
|
+
if (this.eventCallback) {
|
|
140
|
+
this.eventCallback('tool', `[...] Writing ${path}...`);
|
|
141
|
+
}
|
|
142
|
+
this.toolCalls.push({
|
|
143
|
+
type: 'write',
|
|
144
|
+
details,
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
else if (startedEvent.tool_call.readToolCall) {
|
|
148
|
+
const path = startedEvent.tool_call.readToolCall.args.path;
|
|
149
|
+
const details = `Read from ${path}`;
|
|
150
|
+
// Send to watcher/CLI with full path
|
|
151
|
+
if (this.eventCallback) {
|
|
152
|
+
this.eventCallback('tool', `[...] Reading ${path}...`);
|
|
153
|
+
}
|
|
154
|
+
this.toolCalls.push({
|
|
155
|
+
type: 'read',
|
|
156
|
+
details,
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
else if (startedEvent.tool_call.bashToolCall) {
|
|
160
|
+
const cmd = startedEvent.tool_call.bashToolCall.args.command;
|
|
161
|
+
const details = `Execute: ${cmd}`;
|
|
162
|
+
// Send to watcher/CLI with full command
|
|
163
|
+
if (this.eventCallback) {
|
|
164
|
+
this.eventCallback('tool', `[...] Running: ${cmd}`);
|
|
165
|
+
}
|
|
166
|
+
this.toolCalls.push({
|
|
167
|
+
type: 'bash',
|
|
168
|
+
details,
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
else if (startedEvent.tool_call.editToolCall) {
|
|
172
|
+
const path = startedEvent.tool_call.editToolCall.args.path;
|
|
173
|
+
const details = `Edit ${path}`;
|
|
174
|
+
// Send to watcher/CLI with full path
|
|
175
|
+
if (this.eventCallback) {
|
|
176
|
+
this.eventCallback('tool', `[...] Editing ${path}...`);
|
|
177
|
+
}
|
|
178
|
+
this.toolCalls.push({
|
|
179
|
+
type: 'edit',
|
|
180
|
+
details,
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
else if (event.subtype === 'completed') {
|
|
185
|
+
const completedEvent = event;
|
|
186
|
+
if (completedEvent.tool_call.writeToolCall?.result.success) {
|
|
187
|
+
const { linesCreated, fileSize } = completedEvent.tool_call.writeToolCall.result.success;
|
|
188
|
+
const result = `Created ${linesCreated} lines (${fileSize} bytes)`;
|
|
189
|
+
// Log success
|
|
190
|
+
if (this.eventCallback) {
|
|
191
|
+
this.eventCallback('tool', `[OK] Wrote ${linesCreated} lines`);
|
|
192
|
+
}
|
|
193
|
+
// Update the last tool call with result
|
|
194
|
+
if (this.toolCalls.length > 0) {
|
|
195
|
+
this.toolCalls[this.toolCalls.length - 1].result = result;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
else if (completedEvent.tool_call.writeToolCall?.result.error) {
|
|
199
|
+
const error = completedEvent.tool_call.writeToolCall.result.error;
|
|
200
|
+
// Log error
|
|
201
|
+
if (this.eventCallback) {
|
|
202
|
+
this.eventCallback('tool', `[ERR] Write failed: ${error}`);
|
|
203
|
+
}
|
|
204
|
+
if (this.toolCalls.length > 0) {
|
|
205
|
+
this.toolCalls[this.toolCalls.length - 1].result = `Error: ${error}`;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
if (completedEvent.tool_call.readToolCall?.result.success) {
|
|
209
|
+
const { totalLines } = completedEvent.tool_call.readToolCall.result.success;
|
|
210
|
+
const result = `Read ${totalLines} lines`;
|
|
211
|
+
// Log success (more compact)
|
|
212
|
+
if (this.eventCallback) {
|
|
213
|
+
this.eventCallback('tool', `[OK] Read ${totalLines} lines`);
|
|
214
|
+
}
|
|
215
|
+
if (this.toolCalls.length > 0) {
|
|
216
|
+
this.toolCalls[this.toolCalls.length - 1].result = result;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
else if (completedEvent.tool_call.readToolCall?.result.error) {
|
|
220
|
+
const error = completedEvent.tool_call.readToolCall.result.error;
|
|
221
|
+
// Log error
|
|
222
|
+
if (this.eventCallback) {
|
|
223
|
+
this.eventCallback('tool', `[ERR] Read failed: ${error}`);
|
|
224
|
+
}
|
|
225
|
+
if (this.toolCalls.length > 0) {
|
|
226
|
+
this.toolCalls[this.toolCalls.length - 1].result = `Error: ${error}`;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
if (completedEvent.tool_call.bashToolCall?.result.success) {
|
|
230
|
+
const { exitCode } = completedEvent.tool_call.bashToolCall.result.success;
|
|
231
|
+
const result = exitCode === 0 ? 'Success' : `Exit code: ${exitCode}`;
|
|
232
|
+
// Log result
|
|
233
|
+
if (this.eventCallback) {
|
|
234
|
+
if (exitCode === 0) {
|
|
235
|
+
this.eventCallback('tool', `[OK] Command completed`);
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
this.eventCallback('tool', `[WARN] Exit code ${exitCode}`);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
if (this.toolCalls.length > 0) {
|
|
242
|
+
this.toolCalls[this.toolCalls.length - 1].result = result;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
else if (completedEvent.tool_call.bashToolCall?.result.error) {
|
|
246
|
+
const error = completedEvent.tool_call.bashToolCall.result.error;
|
|
247
|
+
// Log failure
|
|
248
|
+
if (this.eventCallback) {
|
|
249
|
+
this.eventCallback('tool', `[ERR] Command failed: ${error}`);
|
|
250
|
+
}
|
|
251
|
+
if (this.toolCalls.length > 0) {
|
|
252
|
+
this.toolCalls[this.toolCalls.length - 1].result = `Failed: ${error}`;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
if (completedEvent.tool_call.editToolCall?.result.success) {
|
|
256
|
+
const { linesAdded, linesRemoved } = completedEvent.tool_call.editToolCall.result.success;
|
|
257
|
+
const result = `+${linesAdded} -${linesRemoved} lines`;
|
|
258
|
+
// Log success
|
|
259
|
+
if (this.eventCallback) {
|
|
260
|
+
this.eventCallback('tool', `[OK] Edited: +${linesAdded} -${linesRemoved}`);
|
|
261
|
+
}
|
|
262
|
+
if (this.toolCalls.length > 0) {
|
|
263
|
+
this.toolCalls[this.toolCalls.length - 1].result = result;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
else if (completedEvent.tool_call.editToolCall?.result.error) {
|
|
267
|
+
const error = completedEvent.tool_call.editToolCall.result.error;
|
|
268
|
+
// Log error
|
|
269
|
+
if (this.eventCallback) {
|
|
270
|
+
this.eventCallback('tool', `[ERR] Edit failed: ${error}`);
|
|
271
|
+
}
|
|
272
|
+
if (this.toolCalls.length > 0) {
|
|
273
|
+
this.toolCalls[this.toolCalls.length - 1].result = `Error: ${error}`;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
handleResultEvent(_event) {
|
|
279
|
+
// Send completion to watcher if callback is set
|
|
280
|
+
if (this.eventCallback) {
|
|
281
|
+
const chars = Math.round(this.accumulatedText.length / 100) / 10; // Convert to KB with 1 decimal
|
|
282
|
+
this.eventCallback('completion', `Done: ${this.toolCalls.length} tools, ${chars}k chars`);
|
|
283
|
+
}
|
|
284
|
+
// Mark as completed and trigger callback
|
|
285
|
+
this.completed = true;
|
|
286
|
+
if (this.completionCallback) {
|
|
287
|
+
this.completionCallback();
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Parse complete cursor-agent stream output
|
|
293
|
+
*/
|
|
294
|
+
export function parseCursorAgentOutput(output) {
|
|
295
|
+
const parser = new CursorAgentStreamParser();
|
|
296
|
+
parser.processLines(output);
|
|
297
|
+
return parser.getResult();
|
|
298
|
+
}
|
|
299
|
+
//# sourceMappingURL=cursor-agent.js.map
|