dhti-cli 1.2.0 → 1.3.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/README.md CHANGED
@@ -30,6 +30,10 @@ Generative AI features are built as [LangServe Apps](https://python.langchain.co
30
30
  #### How (non‑technical / clinical)
31
31
  DHTI includes ready‑to‑use [skills](/.github/skills/) that can prompt agentic platforms (e.g., [AntiGravity](https://antigravity.google/), VSCode, or Claude) to generate the GenAI backends and UI components (elixirs and conches) you need. Test these components with synthetic data in OpenMRS or the CDS‑Hooks sandbox, then hand them off to production teams. Because DHTI follows open standards, that handoff (the “valley of death”) becomes smoother and more predictable. Try the [prompts](/.github/skills/start-dhti/examples/e2e-sample.md) in your preferred agentic platform after cloning this repo.
32
32
 
33
+ Other skills from the open agent skills ecosystem may be useful too! For example, use `npx skills find clinical trial` to find clinical trial related skills. From the results, you can use `npx skills add <skill-name>` to use the skill in your agentic platform. (e.g.`npx skills add anthropics/healthcare@clinical-trial-protocol-skill`)
34
+
35
+ **🤖 [AI-Powered Workflow with GitHub Copilot SDK:](/notes/COPILOT.md) - WIP**
36
+
33
37
  ## Try it out
34
38
  [[Cheatsheet](/notes/cheatsheet.md) | [Download PDF Cheatsheet](https://nuchange.ca/wp-content/uploads/2026/01/dhti_cheatsheet.pdf)]
35
39
 
@@ -113,7 +117,7 @@ You will see the new **patient context aware chatbot** in the patient summary pa
113
117
 
114
118
  | Why | How |
115
119
  | --- | --- |
116
- | I am a clinician! I have no idea how to build GenAI apps. | ✨ DHTI comes with batteries ([skills](/.github/skills/)) included! Use your preferred agentic platform (e.g., [AntiGravity](https://antigravity.google/), [VSCode with Copilot in agent mode](https://code.visualstudio.com/docs/copilot/overview), Claude, [Cursor](https://cursor.com/) and many other) to generate elixirs and conches from [problem-oriented prompts](/prompts/e2e-sample.md) (most of these platforms have a free tier). Test them using synthetic data in OpenMRS or the CDS-Hooks sandbox, then hand them off to production teams. |
120
+ | I am a clinician! I have no idea how to build GenAI apps. | ✨ DHTI comes with batteries ([skills](/.github/skills/)) included! Use your preferred agentic platform (e.g., [AntiGravity](https://antigravity.google/), [VSCode with Copilot in agent mode](https://code.visualstudio.com/docs/copilot/overview), Claude, [Cursor](https://cursor.com/) and many other) to generate elixirs and conches from [problem-oriented prompts](/prompts/e2e-sample.md) (most of these platforms have a free tier). Test them using synthetic data in OpenMRS or the CDS-Hooks sandbox, then hand them off to production teams. You may find useful skills in the open agent skills ecosystem. `npx skills find clinical trial`|
117
121
  | I know LangChain, but I don’t know how to build a chain/agent based on data in our EHR. | [These sample elixirs](https://github.com/dermatologist/dhti-elixir) adopt FHIR and cds-hooks as standards for data retrieval and display. The [base class](https://github.com/dermatologist/dhti-elixir-base) provides reusable artifacts |
118
122
  | I need a simple platform for experimenting. | This repository provides everything to start experimenting fast. The command-line tools help to virtualize and orchestrate your experiments using [Docker](https://www.docker.com/)|
119
123
  | I am a UI designer. I want to design helpful UI for real users. | See [these sample conches](https://github.com/dermatologist/openmrs-esm-dhti). It shows how to build interface components (conches) for [OpenMRS](https://openmrs.org/) an open-source EMR used by many. Read more about [OpenMRS UI](https://o3-docs.openmrs.org/) |
@@ -0,0 +1,54 @@
1
+ import { Command } from '@oclif/core';
2
+ /**
3
+ * Copilot command that uses the GitHub Copilot SDK to interact with DHTI
4
+ * and display results with streaming support.
5
+ */
6
+ export default class Copilot extends Command {
7
+ static description: string;
8
+ static examples: string[];
9
+ static flags: {
10
+ 'clear-history': import("@oclif/core/interfaces").BooleanFlag<boolean>;
11
+ file: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
12
+ model: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
13
+ prompt: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
14
+ skill: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
15
+ };
16
+ /**
17
+ * Detects the appropriate skill based on the prompt content
18
+ * @param prompt - The user's prompt text
19
+ * @returns The detected skill name
20
+ */
21
+ private detectSkill;
22
+ /**
23
+ * Gets the path to the conversation history file
24
+ * @returns The path to the history file
25
+ */
26
+ private getHistoryFilePath;
27
+ /**
28
+ * Loads conversation history from file
29
+ * @returns Array of conversation turns or empty array if no history
30
+ */
31
+ private loadConversationHistory;
32
+ /**
33
+ * Saves conversation history to file
34
+ * @param history - Array of conversation turns to save
35
+ */
36
+ private saveConversationHistory;
37
+ /**
38
+ * Clears the conversation history
39
+ */
40
+ private clearConversationHistory;
41
+ /**
42
+ * Fetches skill content from GitHub if not available locally
43
+ * @param skillName - The name of the skill to fetch
44
+ * @returns The skill content or null if not found
45
+ */
46
+ private fetchSkillFromGitHub;
47
+ /**
48
+ * Loads skill instructions from local or remote source
49
+ * @param skillName - The name of the skill to load
50
+ * @returns The skill content or null if not found
51
+ */
52
+ private loadSkill;
53
+ run(): Promise<void>;
54
+ }
@@ -0,0 +1,300 @@
1
+ import { CopilotClient } from '@github/copilot-sdk';
2
+ import { Command, Flags } from '@oclif/core';
3
+ import chalk from 'chalk';
4
+ import fs from 'node:fs';
5
+ import os from 'node:os';
6
+ import path from 'node:path';
7
+ import { fileURLToPath } from 'node:url';
8
+ /**
9
+ * Copilot command that uses the GitHub Copilot SDK to interact with DHTI
10
+ * and display results with streaming support.
11
+ */
12
+ export default class Copilot extends Command {
13
+ static description = 'Interact with DHTI using GitHub Copilot SDK with streaming responses';
14
+ static examples = [
15
+ '<%= config.bin %> <%= command.id %> --prompt "Start the DHTI stack with langserve"',
16
+ '<%= config.bin %> <%= command.id %> --file ./my-prompt.txt --model gpt-4.1',
17
+ '<%= config.bin %> <%= command.id %> --prompt "Generate a new elixir for patient risk assessment" --skill elixir-generator',
18
+ '<%= config.bin %> <%= command.id %> --clear-history --prompt "Start fresh conversation"',
19
+ '<%= config.bin %> <%= command.id %> --clear-history # Clear history without starting new conversation',
20
+ ];
21
+ static flags = {
22
+ 'clear-history': Flags.boolean({
23
+ default: false,
24
+ description: 'Clear conversation history and start a new session',
25
+ }),
26
+ file: Flags.string({
27
+ char: 'f',
28
+ description: 'Path to a file containing the prompt to send to copilot-sdk',
29
+ exclusive: ['prompt'],
30
+ }),
31
+ model: Flags.string({
32
+ char: 'm',
33
+ default: 'gpt-4.1',
34
+ description: 'Model to use for copilot-sdk interactions',
35
+ }),
36
+ prompt: Flags.string({
37
+ char: 'p',
38
+ description: 'Prompt to send to the copilot-sdk',
39
+ exclusive: ['file'],
40
+ }),
41
+ skill: Flags.string({
42
+ char: 's',
43
+ default: 'auto',
44
+ description: 'Skill to use for copilot-sdk interactions (auto, start-dhti, elixir-generator, conch-generator)',
45
+ }),
46
+ };
47
+ /**
48
+ * Detects the appropriate skill based on the prompt content
49
+ * @param prompt - The user's prompt text
50
+ * @returns The detected skill name
51
+ */
52
+ detectSkill(prompt) {
53
+ const lowerPrompt = prompt.toLowerCase();
54
+ // Check for elixir-related keywords
55
+ if (lowerPrompt.includes('elixir') ||
56
+ lowerPrompt.includes('backend') ||
57
+ lowerPrompt.includes('langserve') ||
58
+ lowerPrompt.includes('genai app')) {
59
+ return 'elixir-generator';
60
+ }
61
+ // Check for conch-related keywords
62
+ if (lowerPrompt.includes('conch') ||
63
+ lowerPrompt.includes('frontend') ||
64
+ lowerPrompt.includes('ui') ||
65
+ lowerPrompt.includes('openmrs')) {
66
+ return 'conch-generator';
67
+ }
68
+ // Default to start-dhti for general setup/orchestration
69
+ return 'start-dhti';
70
+ }
71
+ /**
72
+ * Gets the path to the conversation history file
73
+ * @returns The path to the history file
74
+ */
75
+ getHistoryFilePath() {
76
+ const dhtiDir = path.join(os.homedir(), '.dhti');
77
+ if (!fs.existsSync(dhtiDir)) {
78
+ fs.mkdirSync(dhtiDir, { recursive: true });
79
+ }
80
+ return path.join(dhtiDir, 'copilot-history.json');
81
+ }
82
+ /**
83
+ * Loads conversation history from file
84
+ * @returns Array of conversation turns or empty array if no history
85
+ */
86
+ loadConversationHistory() {
87
+ try {
88
+ const historyPath = this.getHistoryFilePath();
89
+ if (fs.existsSync(historyPath)) {
90
+ const historyData = fs.readFileSync(historyPath, 'utf8');
91
+ return JSON.parse(historyData);
92
+ }
93
+ }
94
+ catch (error) {
95
+ this.warn(chalk.yellow(`Failed to load conversation history: ${error}`));
96
+ }
97
+ return [];
98
+ }
99
+ /**
100
+ * Saves conversation history to file
101
+ * @param history - Array of conversation turns to save
102
+ */
103
+ saveConversationHistory(history) {
104
+ try {
105
+ const historyPath = this.getHistoryFilePath();
106
+ fs.writeFileSync(historyPath, JSON.stringify(history, null, 2), 'utf8');
107
+ }
108
+ catch (error) {
109
+ this.warn(chalk.yellow(`Failed to save conversation history: ${error}`));
110
+ }
111
+ }
112
+ /**
113
+ * Clears the conversation history
114
+ */
115
+ clearConversationHistory() {
116
+ try {
117
+ const historyPath = this.getHistoryFilePath();
118
+ if (fs.existsSync(historyPath)) {
119
+ fs.unlinkSync(historyPath);
120
+ this.log(chalk.green('✓ Conversation history cleared'));
121
+ }
122
+ else {
123
+ this.log(chalk.yellow('No conversation history to clear'));
124
+ }
125
+ }
126
+ catch (error) {
127
+ this.warn(chalk.yellow(`Failed to clear conversation history: ${error}`));
128
+ }
129
+ }
130
+ /**
131
+ * Fetches skill content from GitHub if not available locally
132
+ * @param skillName - The name of the skill to fetch
133
+ * @returns The skill content or null if not found
134
+ */
135
+ async fetchSkillFromGitHub(skillName) {
136
+ try {
137
+ const url = `https://raw.githubusercontent.com/dermatologist/dhti/develop/.agents/skills/${skillName}/SKILL.md`;
138
+ const response = await fetch(url);
139
+ if (!response.ok) {
140
+ return null;
141
+ }
142
+ return response.text();
143
+ }
144
+ catch (error) {
145
+ this.warn(`Failed to fetch skill ${skillName} from GitHub: ${error}`);
146
+ return null;
147
+ }
148
+ }
149
+ /**
150
+ * Loads skill instructions from local or remote source
151
+ * @param skillName - The name of the skill to load
152
+ * @returns The skill content or null if not found
153
+ */
154
+ async loadSkill(skillName) {
155
+ // Resolve skills directory
156
+ const __filename = fileURLToPath(import.meta.url);
157
+ const __dirname = path.dirname(__filename);
158
+ const skillsDir = path.resolve(__dirname, '../../.agents/skills');
159
+ const skillPath = path.join(skillsDir, skillName, 'SKILL.md');
160
+ // Try to load from local directory first
161
+ if (fs.existsSync(skillPath)) {
162
+ try {
163
+ return fs.readFileSync(skillPath, 'utf8');
164
+ }
165
+ catch (error) {
166
+ this.warn(`Failed to read local skill file: ${error}`);
167
+ }
168
+ }
169
+ // If not found locally, try to fetch from GitHub
170
+ this.log(chalk.yellow(`Skill ${skillName} not found locally, fetching from GitHub...`));
171
+ return this.fetchSkillFromGitHub(skillName);
172
+ }
173
+ // eslint-disable-next-line perfectionist/sort-classes
174
+ async run() {
175
+ const { flags } = await this.parse(Copilot);
176
+ // Handle clear-history flag
177
+ if (flags['clear-history']) {
178
+ this.clearConversationHistory();
179
+ // If only clearing history, exit after clearing
180
+ if (!flags.prompt && !flags.file) {
181
+ return;
182
+ }
183
+ }
184
+ // Validate that either prompt or file is provided
185
+ if (!flags.prompt && !flags.file) {
186
+ this.error('Either --prompt or --file must be provided');
187
+ }
188
+ // Get the prompt content
189
+ let promptContent;
190
+ if (flags.file) {
191
+ if (!fs.existsSync(flags.file)) {
192
+ this.error(`File not found: ${flags.file}`);
193
+ }
194
+ try {
195
+ promptContent = fs.readFileSync(flags.file, 'utf8');
196
+ }
197
+ catch (error) {
198
+ this.error(`Failed to read file: ${error}`);
199
+ }
200
+ }
201
+ else {
202
+ promptContent = flags.prompt;
203
+ }
204
+ // Load conversation history
205
+ const conversationHistory = this.loadConversationHistory();
206
+ const hasHistory = conversationHistory.length > 0;
207
+ if (hasHistory) {
208
+ this.log(chalk.cyan(`📜 Loaded ${conversationHistory.length} previous message(s) from history`));
209
+ }
210
+ // Determine which skill to use
211
+ let skillName = flags.skill;
212
+ if (skillName === 'auto') {
213
+ skillName = this.detectSkill(promptContent);
214
+ this.log(chalk.cyan(`Auto-detected skill: ${skillName}`));
215
+ }
216
+ // Load the skill instructions
217
+ const skillContent = await this.loadSkill(skillName);
218
+ if (!skillContent) {
219
+ this.warn(chalk.yellow(`Could not load skill: ${skillName}. Proceeding without skill context.`));
220
+ }
221
+ // Build system message with skill instructions
222
+ let systemMessageContent = 'You are a helpful assistant that can use specific skills to generate components of the DHTI stack based on user prompts.';
223
+ // Add skill-specific instructions
224
+ if (skillContent) {
225
+ systemMessageContent += '\n\n' + skillContent;
226
+ }
227
+ // Add default instruction to use start-dhti skill
228
+ if (skillName !== 'start-dhti') {
229
+ systemMessageContent += '\n\nNote: If the user needs to start the DHTI stack, use the start-dhti skill workflow.';
230
+ }
231
+ // Add conversation history context
232
+ if (hasHistory) {
233
+ systemMessageContent += '\n\n## Previous Conversation\n';
234
+ systemMessageContent += 'Here is the conversation history for context:\n\n';
235
+ for (const turn of conversationHistory) {
236
+ systemMessageContent += `${turn.role === 'user' ? 'User' : 'Assistant'}: ${turn.content}\n\n`;
237
+ }
238
+ systemMessageContent += 'Continue the conversation naturally based on this context.';
239
+ }
240
+ this.log(chalk.green('Initializing GitHub Copilot SDK...'));
241
+ let client = null;
242
+ let assistantResponse = '';
243
+ try {
244
+ // Create copilot client
245
+ client = new CopilotClient();
246
+ // Create a session with streaming enabled
247
+ const session = await client.createSession({
248
+ model: flags.model,
249
+ streaming: true,
250
+ systemMessage: {
251
+ content: systemMessageContent,
252
+ mode: 'append',
253
+ },
254
+ });
255
+ this.log(chalk.green(`Using model: ${flags.model}`));
256
+ this.log(chalk.green(`Using skill: ${skillName}`));
257
+ this.log(chalk.blue('\n--- Copilot Response ---\n'));
258
+ // Handle streaming responses
259
+ let responseStarted = false;
260
+ session.on('assistant.message_delta', (event) => {
261
+ if (!responseStarted) {
262
+ responseStarted = true;
263
+ }
264
+ const content = event.data.deltaContent;
265
+ process.stdout.write(content);
266
+ assistantResponse += content;
267
+ });
268
+ // Handle session idle (response complete)
269
+ session.on('session.idle', () => {
270
+ if (responseStarted) {
271
+ console.log('\n'); // Add newline after response
272
+ }
273
+ });
274
+ // Send the prompt and wait for completion
275
+ await session.sendAndWait({ prompt: promptContent });
276
+ this.log(chalk.blue('\n--- End of Response ---\n'));
277
+ // Save conversation history
278
+ conversationHistory.push({ content: promptContent, role: 'user' });
279
+ if (assistantResponse.trim()) {
280
+ conversationHistory.push({ content: assistantResponse.trim(), role: 'assistant' });
281
+ }
282
+ this.saveConversationHistory(conversationHistory);
283
+ this.log(chalk.dim(`💾 Conversation saved (${conversationHistory.length} messages). Use --clear-history to reset.`));
284
+ }
285
+ catch (error) {
286
+ const errorMessage = error instanceof Error ? error.message : String(error);
287
+ this.error(chalk.red(`Failed to interact with Copilot SDK: ${errorMessage}\n\n`) +
288
+ chalk.yellow('Troubleshooting:\n') +
289
+ chalk.yellow('1. Ensure GitHub Copilot CLI is installed: https://docs.github.com/en/copilot/using-github-copilot/using-github-copilot-in-the-command-line\n') +
290
+ chalk.yellow('2. Authenticate with: copilot auth login\n') +
291
+ chalk.yellow('3. Verify CLI is working: copilot --version\n'));
292
+ }
293
+ finally {
294
+ // Clean up
295
+ if (client) {
296
+ await client.stop();
297
+ }
298
+ }
299
+ }
300
+ }
@@ -175,6 +175,80 @@
175
175
  "conch.js"
176
176
  ]
177
177
  },
178
+ "copilot": {
179
+ "aliases": [],
180
+ "args": {},
181
+ "description": "Interact with DHTI using GitHub Copilot SDK with streaming responses",
182
+ "examples": [
183
+ "<%= config.bin %> <%= command.id %> --prompt \"Start the DHTI stack with langserve\"",
184
+ "<%= config.bin %> <%= command.id %> --file ./my-prompt.txt --model gpt-4.1",
185
+ "<%= config.bin %> <%= command.id %> --prompt \"Generate a new elixir for patient risk assessment\" --skill elixir-generator",
186
+ "<%= config.bin %> <%= command.id %> --clear-history --prompt \"Start fresh conversation\"",
187
+ "<%= config.bin %> <%= command.id %> --clear-history # Clear history without starting new conversation"
188
+ ],
189
+ "flags": {
190
+ "clear-history": {
191
+ "description": "Clear conversation history and start a new session",
192
+ "name": "clear-history",
193
+ "allowNo": false,
194
+ "type": "boolean"
195
+ },
196
+ "file": {
197
+ "char": "f",
198
+ "description": "Path to a file containing the prompt to send to copilot-sdk",
199
+ "exclusive": [
200
+ "prompt"
201
+ ],
202
+ "name": "file",
203
+ "hasDynamicHelp": false,
204
+ "multiple": false,
205
+ "type": "option"
206
+ },
207
+ "model": {
208
+ "char": "m",
209
+ "description": "Model to use for copilot-sdk interactions",
210
+ "name": "model",
211
+ "default": "gpt-4.1",
212
+ "hasDynamicHelp": false,
213
+ "multiple": false,
214
+ "type": "option"
215
+ },
216
+ "prompt": {
217
+ "char": "p",
218
+ "description": "Prompt to send to the copilot-sdk",
219
+ "exclusive": [
220
+ "file"
221
+ ],
222
+ "name": "prompt",
223
+ "hasDynamicHelp": false,
224
+ "multiple": false,
225
+ "type": "option"
226
+ },
227
+ "skill": {
228
+ "char": "s",
229
+ "description": "Skill to use for copilot-sdk interactions (auto, start-dhti, elixir-generator, conch-generator)",
230
+ "name": "skill",
231
+ "default": "auto",
232
+ "hasDynamicHelp": false,
233
+ "multiple": false,
234
+ "type": "option"
235
+ }
236
+ },
237
+ "hasDynamicHelp": false,
238
+ "hiddenAliases": [],
239
+ "id": "copilot",
240
+ "pluginAlias": "dhti-cli",
241
+ "pluginName": "dhti-cli",
242
+ "pluginType": "core",
243
+ "strict": true,
244
+ "enableJsonFlag": false,
245
+ "isESM": true,
246
+ "relativePath": [
247
+ "dist",
248
+ "commands",
249
+ "copilot.js"
250
+ ]
251
+ },
178
252
  "docker": {
179
253
  "aliases": [],
180
254
  "args": {
@@ -808,5 +882,5 @@
808
882
  ]
809
883
  }
810
884
  },
811
- "version": "1.2.0"
885
+ "version": "1.3.0"
812
886
  }
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "dhti-cli",
3
3
  "description": "DHTI CLI",
4
- "version": "1.2.0",
4
+ "version": "1.3.0",
5
5
  "author": "Bell Eapen",
6
6
  "bin": {
7
7
  "dhti-cli": "bin/run.js"
8
8
  },
9
9
  "bugs": "https://github.com/dermatologist/dhti/issues",
10
10
  "dependencies": {
11
+ "@github/copilot-sdk": "^0.1.23",
11
12
  "@langchain/community": "^0.3.53",
12
13
  "@langchain/ollama": "^0.2.3",
13
14
  "@oclif/core": "^4",
@@ -18,7 +19,8 @@
18
19
  "js-yaml": "^4.1.0",
19
20
  "medpromptjs": ">=0.4.3",
20
21
  "ora": "^8.0.1",
21
- "request": "^2.88.2"
22
+ "request": "^2.88.2",
23
+ "vscode-jsonrpc": "^8.2.1"
22
24
  },
23
25
  "devDependencies": {
24
26
  "@oclif/prettier-config": "^0.2.1",