drtrace 0.3.0 → 0.5.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 (51) hide show
  1. package/README.md +45 -4
  2. package/agents/CONTRIBUTING.md +0 -0
  3. package/agents/README.md +0 -0
  4. package/agents/daemon-method-selection.md +126 -227
  5. package/agents/integration-guides/cpp-best-practices.md +0 -0
  6. package/agents/integration-guides/cpp-ros-integration.md +0 -0
  7. package/agents/log-analysis.md +3 -89
  8. package/agents/log-help.md +6 -79
  9. package/agents/log-init.md +4 -0
  10. package/agents/log-it.md +4 -0
  11. package/bin/cli.js +98 -0
  12. package/bin/init.js +0 -0
  13. package/dist/bin/cli.js +98 -0
  14. package/dist/browser.d.ts +28 -0
  15. package/dist/browser.js +91 -0
  16. package/dist/cli/grep.d.ts +27 -0
  17. package/dist/cli/grep.js +251 -0
  18. package/dist/cli/status.d.ts +11 -0
  19. package/dist/cli/status.js +78 -0
  20. package/dist/client.d.ts +0 -0
  21. package/dist/client.js +0 -0
  22. package/dist/config-schema.d.ts +0 -0
  23. package/dist/config-schema.js +0 -0
  24. package/dist/config.d.ts +0 -0
  25. package/dist/config.js +0 -0
  26. package/dist/index.d.ts +1 -1
  27. package/dist/index.js +2 -2
  28. package/dist/init.d.ts +2 -0
  29. package/dist/init.js +23 -18
  30. package/dist/logger.d.ts +7 -0
  31. package/dist/logger.js +30 -4
  32. package/dist/node.d.ts +13 -0
  33. package/dist/node.js +67 -0
  34. package/dist/queue.d.ts +0 -0
  35. package/dist/queue.js +0 -0
  36. package/dist/resources/agents/CONTRIBUTING.md +0 -0
  37. package/dist/resources/agents/README.md +0 -0
  38. package/dist/resources/agents/daemon-method-selection.md +126 -227
  39. package/dist/resources/agents/integration-guides/cpp-best-practices.md +0 -0
  40. package/dist/resources/agents/integration-guides/cpp-ros-integration.md +0 -0
  41. package/dist/resources/agents/log-analysis.md +3 -89
  42. package/dist/resources/agents/log-help.md +6 -79
  43. package/dist/resources/agents/log-init.md +4 -0
  44. package/dist/resources/agents/log-it.md +4 -0
  45. package/dist/resources/cpp/drtrace_sink.hpp +1 -0
  46. package/dist/transport.d.ts +0 -0
  47. package/dist/transport.js +5 -1
  48. package/dist/types.d.ts +8 -2
  49. package/dist/types.js +0 -0
  50. package/package.json +22 -5
  51. package/dist/bin/init.js +0 -31
@@ -11,7 +11,7 @@ You must fully embody this agent's persona and follow all activation instruction
11
11
  <step n="1">Load persona from this current agent file (already in context)</step>
12
12
  <step n="2">Remember: You are a Setup Guide Assistant for DrTrace</step>
13
13
  <step n="3">Your primary mission is to walk users through DrTrace setup step-by-step using the help APIs and setup guide, not to guess or skip steps</step>
14
- <step n="4">ALWAYS prefer Method 1 (Python help APIs) then Method 2 (HTTP help endpoints) → then Method 3 (CLI) in that exact order</step>
14
+ <step n="4">When processing a user query, check `agents/daemon-method-selection.md` for details.</step>
15
15
  <step n="5">For each user interaction, clearly state the current step, what to do next, and how to verify it worked</step>
16
16
  <step n="6">When calling help APIs, use:
17
17
  - `start_setup_guide(language, project_root)` to begin or restart a guide
@@ -32,7 +32,7 @@ You must fully embody this agent's persona and follow all activation instruction
32
32
  <r>NEVER skip verification or pretend steps are complete; use the setup guide and help APIs as the source of truth</r>
33
33
  <r>ALWAYS explain what you are doing when progressing steps or troubleshooting issues</r>
34
34
  <r>Display menu items exactly as defined in the menu section and in the order given</r>
35
- <r>Prefer Python APIs, then HTTP endpoints, then CLI in that order; explain fallbacks when switching methods</r>
35
+ <r>Prefer HTTP/curl, then Python SDK, then CLI in that order; explain fallbacks when switching methods</r>
36
36
  </rules>
37
37
  </activation>
38
38
 
@@ -50,6 +50,10 @@ You must fully embody this agent's persona and follow all activation instruction
50
50
  </principles>
51
51
  </persona>
52
52
 
53
+ ## CLI Availability & Filters
54
+
55
+ See [agents/daemon-method-selection.md](agents/daemon-method-selection.md) for CLI availability guidance and the mutually exclusive `message_contains` vs `message_regex` rule (includes CLI/HTTP examples).
56
+
53
57
  <menu title="How can I guide your DrTrace setup?">
54
58
  <item cmd="S" hotkey="S" name="Start setup guide">
55
59
  Begin or restart the step-by-step setup guide for a specific language.
@@ -92,83 +96,6 @@ You must fully embody this agent's persona and follow all activation instruction
92
96
  </agent>
93
97
  ```
94
98
 
95
- ## How to Use DrTrace Help APIs
96
-
97
- **Reference**: See `agents/daemon-method-selection.md` for complete method selection guide.
98
-
99
- **Priority Order**: HTTP/curl (preferred) → Python SDK → CLI (last resort)
100
-
101
- ### Quick Reference: Help API Operations
102
-
103
- | Operation | HTTP (Preferred) | Python SDK |
104
- |-----------|------------------|------------|
105
- | Start guide | `POST /help/guide/start` | `start_setup_guide(language, project_root)` |
106
- | Current step | `GET /help/guide/current` | `get_current_step(project_root)` |
107
- | Complete step | `POST /help/guide/complete` | `complete_step(step_number, project_root)` |
108
- | Troubleshoot | `POST /help/troubleshoot` | `troubleshoot(issue, project_root)` |
109
-
110
- ### HTTP/curl Examples (Preferred)
111
-
112
- ```bash
113
- # Start setup guide
114
- curl -X POST http://localhost:8001/help/guide/start \
115
- -H "Content-Type: application/json" \
116
- -d '{"language": "python", "project_root": "/path/to/project"}'
117
-
118
- # Get current step
119
- curl "http://localhost:8001/help/guide/current?project_root=/path/to/project"
120
-
121
- # Mark step complete
122
- curl -X POST http://localhost:8001/help/guide/complete \
123
- -H "Content-Type: application/json" \
124
- -d '{"step_number": 1, "project_root": "/path/to/project"}'
125
-
126
- # Troubleshoot
127
- curl -X POST http://localhost:8001/help/troubleshoot \
128
- -H "Content-Type: application/json" \
129
- -d '{"issue": "daemon not connecting", "project_root": "/path/to/project"}'
130
- ```
131
-
132
- ### Python SDK Examples (Fallback)
133
-
134
- ```python
135
- from pathlib import Path
136
- from drtrace_service.help_agent_interface import (
137
- start_setup_guide,
138
- get_current_step,
139
- complete_step,
140
- troubleshoot,
141
- )
142
- import asyncio
143
-
144
- project_root = Path(".")
145
-
146
- # Start guide
147
- guide = await start_setup_guide(language="python", project_root=project_root)
148
-
149
- # Get current step
150
- current = await get_current_step(project_root=project_root)
151
-
152
- # Complete step
153
- next_step = await complete_step(step_number=1, project_root=project_root)
154
-
155
- # Troubleshoot
156
- help_text = await troubleshoot("daemon not connecting", project_root=project_root)
157
-
158
- # Non-async context
159
- guide = asyncio.run(start_setup_guide(language="python", project_root=project_root))
160
- ```
161
-
162
- ### Fallback Strategy
163
-
164
- 1. **HTTP/curl (Preferred)**: Simple, no dependencies, works everywhere
165
- 2. **Python SDK (Fallback)**: Rich async features when HTTP unavailable
166
- 3. **CLI (Last Resort)**: `python -m drtrace_service help guide ...`
167
-
168
- **Important**: Always fetch `/openapi.json` first when using HTTP to discover correct endpoints and field names.
169
-
170
- See `agents/daemon-method-selection.md` for complete fallback implementation.
171
-
172
99
  ## Activation Instructions
173
100
 
174
101
  To activate the `log-help` agent in a project:
@@ -30,6 +30,10 @@ You must fully embody this agent's persona and follow all activation instruction
30
30
  </activation>
31
31
 
32
32
  <persona>
33
+
34
+ ## CLI Availability & Filters
35
+
36
+ See [agents/daemon-method-selection.md](agents/daemon-method-selection.md) for CLI availability guidance and the mutually exclusive `message_contains` vs `message_regex` rule (includes CLI/HTTP examples).
33
37
  <role>Setup Specialist</role>
34
38
  <identity>Expert at analyzing project structures and suggesting intelligent DrTrace integration. Reads source files directly to understand project organization, build systems, and existing logging. Provides language-specific setup suggestions with minimal impact on existing code.</identity>
35
39
  <communication_style>Clear and educational. Reads and analyzes project files before suggesting setup. Explains reasoning for each suggestion. Provides structured responses with code examples. Ensures suggestions are non-destructive and compatible with existing setup.</communication_style>
package/agents/log-it.md CHANGED
@@ -52,6 +52,10 @@ You must fully embody this agent's persona and follow all activation instruction
52
52
  </principles>
53
53
  </persona>
54
54
 
55
+ ## CLI Availability & Filters
56
+
57
+ See [agents/daemon-method-selection.md](agents/daemon-method-selection.md) for CLI availability guidance and the mutually exclusive `message_contains` vs `message_regex` rule (includes CLI/HTTP examples).
58
+
55
59
  <menu title="What can I help you log?">
56
60
  <item cmd="L" hotkey="L" name="Log this function">
57
61
  Analyze a specific function and suggest strategic logging points.
package/bin/cli.js ADDED
@@ -0,0 +1,98 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * CLI entry point for drtrace commands
5
+ * This wrapper is copied to dist/bin/cli.js and imports from compiled TypeScript
6
+ */
7
+
8
+ const path = require('path');
9
+
10
+ // Resolve paths relative to the dist directory
11
+ // When copied to dist/bin/cli.js, we need to go up one level to access dist/cli/*
12
+ const { runGrep } = require(path.join(__dirname, '..', 'cli', 'grep'));
13
+ const { runStatus } = require(path.join(__dirname, '..', 'cli', 'status'));
14
+ const { runInitProject } = require(path.join(__dirname, '..', 'init'));
15
+
16
+ const COMMANDS = ['grep', 'status', 'init'];
17
+
18
+ function printMainHelp() {
19
+ console.log(`Usage: drtrace <command> [options]
20
+
21
+ Commands:
22
+ grep Search log messages with pattern matching
23
+ status Check daemon health and configuration
24
+ init Initialize DrTrace project configuration
25
+
26
+ Options:
27
+ -h, --help Show this help message
28
+ -v, --version Show version number
29
+
30
+ Examples:
31
+ drtrace status
32
+ drtrace grep "error"
33
+ drtrace grep -E "error|warning" --since 30m
34
+ drtrace init
35
+
36
+ For command-specific help:
37
+ drtrace <command> --help
38
+ `);
39
+ }
40
+
41
+ function printVersion() {
42
+ const packageJson = require(path.join(__dirname, '..', '..', 'package.json'));
43
+ console.log(`drtrace v${packageJson.version}`);
44
+ }
45
+
46
+ async function main() {
47
+ const args = process.argv.slice(2);
48
+
49
+ if (args.length === 0) {
50
+ printMainHelp();
51
+ return 0;
52
+ }
53
+
54
+ const firstArg = args[0];
55
+
56
+ // Handle global flags
57
+ if (firstArg === '-h' || firstArg === '--help') {
58
+ printMainHelp();
59
+ return 0;
60
+ }
61
+
62
+ if (firstArg === '-v' || firstArg === '--version') {
63
+ printVersion();
64
+ return 0;
65
+ }
66
+
67
+ // Route to command
68
+ const command = firstArg;
69
+ const commandArgs = args.slice(1);
70
+
71
+ switch (command) {
72
+ case 'grep':
73
+ return await runGrep(commandArgs);
74
+
75
+ case 'status':
76
+ return await runStatus(commandArgs);
77
+
78
+ case 'init':
79
+ const projectRoot = commandArgs.find((arg, i) =>
80
+ (args[i - 1] === '--project-root' || args[i - 1] === '-p')
81
+ );
82
+ return await runInitProject(projectRoot);
83
+
84
+ default:
85
+ console.error(`Error: Unknown command '${command}'`);
86
+ console.error('');
87
+ printMainHelp();
88
+ return 2;
89
+ }
90
+ }
91
+
92
+ // Run CLI
93
+ main().then((exitCode) => {
94
+ process.exit(exitCode);
95
+ }).catch((error) => {
96
+ console.error(`Fatal error: ${error.message}`);
97
+ process.exit(1);
98
+ });
package/bin/init.js CHANGED
File without changes
@@ -0,0 +1,98 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * CLI entry point for drtrace commands
5
+ * This wrapper is copied to dist/bin/cli.js and imports from compiled TypeScript
6
+ */
7
+
8
+ const path = require('path');
9
+
10
+ // Resolve paths relative to the dist directory
11
+ // When copied to dist/bin/cli.js, we need to go up one level to access dist/cli/*
12
+ const { runGrep } = require(path.join(__dirname, '..', 'cli', 'grep'));
13
+ const { runStatus } = require(path.join(__dirname, '..', 'cli', 'status'));
14
+ const { runInitProject } = require(path.join(__dirname, '..', 'init'));
15
+
16
+ const COMMANDS = ['grep', 'status', 'init'];
17
+
18
+ function printMainHelp() {
19
+ console.log(`Usage: drtrace <command> [options]
20
+
21
+ Commands:
22
+ grep Search log messages with pattern matching
23
+ status Check daemon health and configuration
24
+ init Initialize DrTrace project configuration
25
+
26
+ Options:
27
+ -h, --help Show this help message
28
+ -v, --version Show version number
29
+
30
+ Examples:
31
+ drtrace status
32
+ drtrace grep "error"
33
+ drtrace grep -E "error|warning" --since 30m
34
+ drtrace init
35
+
36
+ For command-specific help:
37
+ drtrace <command> --help
38
+ `);
39
+ }
40
+
41
+ function printVersion() {
42
+ const packageJson = require(path.join(__dirname, '..', '..', 'package.json'));
43
+ console.log(`drtrace v${packageJson.version}`);
44
+ }
45
+
46
+ async function main() {
47
+ const args = process.argv.slice(2);
48
+
49
+ if (args.length === 0) {
50
+ printMainHelp();
51
+ return 0;
52
+ }
53
+
54
+ const firstArg = args[0];
55
+
56
+ // Handle global flags
57
+ if (firstArg === '-h' || firstArg === '--help') {
58
+ printMainHelp();
59
+ return 0;
60
+ }
61
+
62
+ if (firstArg === '-v' || firstArg === '--version') {
63
+ printVersion();
64
+ return 0;
65
+ }
66
+
67
+ // Route to command
68
+ const command = firstArg;
69
+ const commandArgs = args.slice(1);
70
+
71
+ switch (command) {
72
+ case 'grep':
73
+ return await runGrep(commandArgs);
74
+
75
+ case 'status':
76
+ return await runStatus(commandArgs);
77
+
78
+ case 'init':
79
+ const projectRoot = commandArgs.find((arg, i) =>
80
+ (args[i - 1] === '--project-root' || args[i - 1] === '-p')
81
+ );
82
+ return await runInitProject(projectRoot);
83
+
84
+ default:
85
+ console.error(`Error: Unknown command '${command}'`);
86
+ console.error('');
87
+ printMainHelp();
88
+ return 2;
89
+ }
90
+ }
91
+
92
+ // Run CLI
93
+ main().then((exitCode) => {
94
+ process.exit(exitCode);
95
+ }).catch((error) => {
96
+ console.error(`Fatal error: ${error.message}`);
97
+ process.exit(1);
98
+ });
@@ -0,0 +1,28 @@
1
+ import type { ClientOptions, LogLevel } from './types';
2
+ /**
3
+ * DrTrace client for browser environments.
4
+ *
5
+ * Unlike the Node.js client, this does NOT load configuration from files.
6
+ * All options must be passed explicitly to init().
7
+ */
8
+ export declare class DrTrace {
9
+ private queue;
10
+ private logger;
11
+ private enabled;
12
+ private constructor();
13
+ /**
14
+ * Initialize DrTrace for browser environments.
15
+ * Unlike Node.js, browser does not load config from files.
16
+ * All options must be passed explicitly.
17
+ *
18
+ * @param opts - Client options (applicationId and daemonUrl are required)
19
+ * @throws Error if applicationId or daemonUrl are not provided
20
+ */
21
+ static init(opts: ClientOptions): DrTrace;
22
+ attachToConsole(): void;
23
+ detachFromConsole(): void;
24
+ log(message: string, level?: LogLevel, context?: Record<string, unknown>): void;
25
+ error(message: string, context?: Record<string, unknown>): void;
26
+ shutdown(): Promise<void>;
27
+ }
28
+ export * from './types';
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.DrTrace = void 0;
18
+ const transport_1 = require("./transport");
19
+ const queue_1 = require("./queue");
20
+ const logger_1 = require("./logger");
21
+ /**
22
+ * DrTrace client for browser environments.
23
+ *
24
+ * Unlike the Node.js client, this does NOT load configuration from files.
25
+ * All options must be passed explicitly to init().
26
+ */
27
+ class DrTrace {
28
+ constructor(opts) {
29
+ const transport = new transport_1.Transport({
30
+ daemonUrl: opts.daemonUrl,
31
+ maxRetries: opts.maxRetries ?? 3,
32
+ timeoutMs: 5000,
33
+ });
34
+ this.queue = new queue_1.LogQueue({
35
+ transport,
36
+ batchSize: opts.batchSize ?? 50,
37
+ flushIntervalMs: opts.flushIntervalMs ?? 1000,
38
+ maxQueueSize: opts.maxQueueSize ?? 10000,
39
+ });
40
+ this.queue.start();
41
+ this.enabled = opts.enabled ?? true;
42
+ this.logger = new logger_1.DrTraceLogger({
43
+ queue: this.queue,
44
+ applicationId: opts.applicationId,
45
+ moduleName: opts.moduleName,
46
+ logLevel: (opts.logLevel ?? 'info'),
47
+ });
48
+ }
49
+ /**
50
+ * Initialize DrTrace for browser environments.
51
+ * Unlike Node.js, browser does not load config from files.
52
+ * All options must be passed explicitly.
53
+ *
54
+ * @param opts - Client options (applicationId and daemonUrl are required)
55
+ * @throws Error if applicationId or daemonUrl are not provided
56
+ */
57
+ static init(opts) {
58
+ if (!opts.applicationId) {
59
+ throw new Error('applicationId is required for browser usage');
60
+ }
61
+ if (!opts.daemonUrl) {
62
+ throw new Error('daemonUrl is required for browser usage');
63
+ }
64
+ return new DrTrace(opts);
65
+ }
66
+ attachToConsole() {
67
+ if (!this.enabled)
68
+ return;
69
+ this.logger.attachToConsole();
70
+ }
71
+ detachFromConsole() {
72
+ this.logger.detachFromConsole();
73
+ }
74
+ log(message, level = 'info', context) {
75
+ if (!this.enabled)
76
+ return;
77
+ this.logger.log(level, message, context);
78
+ }
79
+ error(message, context) {
80
+ if (!this.enabled)
81
+ return;
82
+ this.logger.log('error', message, context);
83
+ }
84
+ async shutdown() {
85
+ await this.queue.flush();
86
+ this.queue.stop();
87
+ this.detachFromConsole();
88
+ }
89
+ }
90
+ exports.DrTrace = DrTrace;
91
+ __exportStar(require("./types"), exports);
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Grep command implementation for searching logs with POSIX regex.
3
+ * Matches Python implementation in packages/python/src/drtrace_service/cli/grep.py
4
+ */
5
+ interface GrepOptions {
6
+ pattern: string;
7
+ ignoreCase?: boolean;
8
+ count?: boolean;
9
+ invertMatch?: boolean;
10
+ lineNumber?: boolean;
11
+ extendedRegex?: boolean;
12
+ since?: string;
13
+ applicationId?: string;
14
+ daemonHost?: string;
15
+ daemonPort?: number;
16
+ json?: boolean;
17
+ color?: 'auto' | 'always' | 'never';
18
+ }
19
+ /**
20
+ * Main grep implementation
21
+ */
22
+ export declare function grep(options: GrepOptions): Promise<number>;
23
+ /**
24
+ * Parse CLI arguments and run grep command
25
+ */
26
+ export declare function runGrep(args: string[]): Promise<number>;
27
+ export {};