ai-prompt-orchestrator-cli 0.0.0-stage → 1.0.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 +21 -0
- package/README.md +87 -2
- package/package.json +10 -3
- package/src/index.js +132 -0
- package/test/index.test.js +27 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Suman Mehta
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,88 @@
|
|
|
1
|
-
#
|
|
1
|
+
# AI Prompt Orchestrator CLI
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Seamlessly merge local context with AI prompts for flawless automation**
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/ai-prompt-orchestrator-cli)
|
|
6
|
+
[](https://github.com/yourusername/ai-prompt-orchestrator-cli/blob/main/LICENSE)
|
|
7
|
+
[](https://nodejs.org/)
|
|
8
|
+
[](https://github.com/yourusername/ai-prompt-orchestrator-cli/actions)
|
|
9
|
+
[](https://codecov.io/gh/yourusername/ai-prompt-orchestrator-cli)
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install -g ai-prompt-orchestrator-cli
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Quick Start
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
# Create a prompt template (prompt.txt)
|
|
23
|
+
cat > prompt.txt <<'EOF'
|
|
24
|
+
Write a summary for the following article:
|
|
25
|
+
|
|
26
|
+
{{article}}
|
|
27
|
+
EOF
|
|
28
|
+
|
|
29
|
+
# Create a JSON context file (ctx.json)
|
|
30
|
+
cat > ctx.json <<'EOF'
|
|
31
|
+
{
|
|
32
|
+
"article": "Artificial intelligence is transforming software development..."
|
|
33
|
+
}
|
|
34
|
+
EOF
|
|
35
|
+
|
|
36
|
+
# Run the orchestrator
|
|
37
|
+
ai-prompt-orchestrator --prompt prompt.txt --context ctx.json
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
The command prints the fully‑rendered prompt to **stdout**.
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## Architecture Flowchart
|
|
45
|
+
|
|
46
|
+
```mermaid
|
|
47
|
+
flowchart TD
|
|
48
|
+
A[CLI Invocation] --> B{Is Prompt Remote?}
|
|
49
|
+
B -- Yes --> C[HTTP(S) Fetch]
|
|
50
|
+
B -- No --> D[Read Local File]
|
|
51
|
+
C --> E[Load Template]
|
|
52
|
+
D --> E[Load Template]
|
|
53
|
+
E --> F[Read Context JSON]
|
|
54
|
+
F --> G[Placeholder Substitution]
|
|
55
|
+
G --> H{Output Destination}
|
|
56
|
+
H -- stdout --> I[Print]
|
|
57
|
+
H -- file --> J[Write File]
|
|
58
|
+
I --> K[Exit 0]
|
|
59
|
+
J --> K[Exit 0]
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## Test Results
|
|
65
|
+
|
|
66
|
+
## 🧪 Real-World Test Telemetry
|
|
67
|
+
|
|
68
|
+
> [!NOTE]
|
|
69
|
+
> Verified automatically using Node.js native test runner (`node:test` & `node:assert/strict`).
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
▶ node --test
|
|
73
|
+
✔ CLI substitutes placeholders from JSON context (114.447213ms)
|
|
74
|
+
ℹ tests 1
|
|
75
|
+
ℹ suites 0
|
|
76
|
+
ℹ pass 1
|
|
77
|
+
ℹ fail 0
|
|
78
|
+
ℹ cancelled 0
|
|
79
|
+
ℹ skipped 0
|
|
80
|
+
ℹ todo 0
|
|
81
|
+
ℹ duration_ms 221.666441
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## License
|
|
87
|
+
|
|
88
|
+
MIT License (c) 2026 Suman Mehta
|
package/package.json
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ai-prompt-orchestrator-cli",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Advanced AI Prompt Orchestrator & Local Context CLI Tool",
|
|
6
|
+
"bin": {
|
|
7
|
+
"ai-prompt-orchestrator": "./src/index.js"
|
|
8
|
+
},
|
|
9
|
+
"engines": {
|
|
10
|
+
"node": ">=20"
|
|
11
|
+
},
|
|
12
|
+
"license": "MIT"
|
|
6
13
|
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { readFile, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { existsSync } from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import { request as httpsRequest } from 'node:https';
|
|
7
|
+
import http from 'node:http';
|
|
8
|
+
import { spawnSync } from 'node:child_process';
|
|
9
|
+
import { exit } from 'node:process';
|
|
10
|
+
|
|
11
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
12
|
+
const __dirname = path.dirname(__filename);
|
|
13
|
+
|
|
14
|
+
function printHelp() {
|
|
15
|
+
console.log(`ai-prompt-orchestrator
|
|
16
|
+
|
|
17
|
+
Usage: ai-prompt-orchestrator --prompt <path|url> --context <json-file> [--output <file>]
|
|
18
|
+
|
|
19
|
+
Options:
|
|
20
|
+
--prompt Path to a local prompt file or an http/https URL containing the template.
|
|
21
|
+
--context JSON file that provides key/value pairs for placeholder substitution.
|
|
22
|
+
--output Optional file to write the final prompt. If omitted, the prompt is printed to stdout.
|
|
23
|
+
-h, --help Show this help message.
|
|
24
|
+
`);
|
|
25
|
+
exit(0);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function parseArgs() {
|
|
29
|
+
const args = process.argv.slice(2);
|
|
30
|
+
const options = {};
|
|
31
|
+
for (let i = 0; i < args.length; i++) {
|
|
32
|
+
const arg = args[i];
|
|
33
|
+
if (arg === '-h' || arg === '--help') printHelp();
|
|
34
|
+
if (arg === '--prompt') options.prompt = args[++i];
|
|
35
|
+
else if (arg === '--context') options.context = args[++i];
|
|
36
|
+
else if (arg === '--output') options.output = args[++i];
|
|
37
|
+
else {
|
|
38
|
+
console.error(`Unknown argument: ${arg}`);
|
|
39
|
+
exit(1);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (!options.prompt || !options.context) {
|
|
43
|
+
console.error('Both --prompt and --context are required.');
|
|
44
|
+
exit(1);
|
|
45
|
+
}
|
|
46
|
+
return options;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function isHttpUrl(str) {
|
|
50
|
+
try {
|
|
51
|
+
const u = new URL(str);
|
|
52
|
+
return u.protocol === 'http:' || u.protocol === 'https:';
|
|
53
|
+
} catch {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function fetchRemote(url) {
|
|
59
|
+
return new Promise((resolve, reject) => {
|
|
60
|
+
const lib = url.startsWith('https') ? httpsRequest : http.request;
|
|
61
|
+
const req = lib(url, res => {
|
|
62
|
+
if (res.statusCode && res.statusCode >= 400) {
|
|
63
|
+
reject(new Error(`Failed to fetch ${url}: ${res.statusCode}`));
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
let data = '';
|
|
67
|
+
res.setEncoding('utf8');
|
|
68
|
+
res.on('data', chunk => (data += chunk));
|
|
69
|
+
res.on('end', () => resolve(data));
|
|
70
|
+
});
|
|
71
|
+
req.on('error', reject);
|
|
72
|
+
req.end();
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
async function loadPrompt(source) {
|
|
77
|
+
if (isHttpUrl(source)) {
|
|
78
|
+
return await fetchRemote(source);
|
|
79
|
+
}
|
|
80
|
+
const fullPath = path.isAbsolute(source) ? source : path.resolve(process.cwd(), source);
|
|
81
|
+
if (!existsSync(fullPath)) {
|
|
82
|
+
throw new Error(`Prompt file not found: ${fullPath}`);
|
|
83
|
+
}
|
|
84
|
+
return await readFile(fullPath, 'utf8');
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async function loadContext(contextPath) {
|
|
88
|
+
const fullPath = path.isAbsolute(contextPath) ? contextPath : path.resolve(process.cwd(), contextPath);
|
|
89
|
+
if (!existsSync(fullPath)) {
|
|
90
|
+
throw new Error(`Context file not found: ${fullPath}`);
|
|
91
|
+
}
|
|
92
|
+
const raw = await readFile(fullPath, 'utf8');
|
|
93
|
+
try {
|
|
94
|
+
return JSON.parse(raw);
|
|
95
|
+
} catch (e) {
|
|
96
|
+
throw new Error('Context file must be valid JSON');
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function substitute(template, context) {
|
|
101
|
+
return template.replace(/{{\s*([\w.-]+)\s*}}/g, (_, key) => {
|
|
102
|
+
if (Object.prototype.hasOwnProperty.call(context, key)) {
|
|
103
|
+
return String(context[key]);
|
|
104
|
+
}
|
|
105
|
+
return `{{${key}}}`; // leave untouched if missing
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async function main() {
|
|
110
|
+
const opts = parseArgs();
|
|
111
|
+
try {
|
|
112
|
+
const [template, context] = await Promise.all([
|
|
113
|
+
loadPrompt(opts.prompt),
|
|
114
|
+
loadContext(opts.context)
|
|
115
|
+
]);
|
|
116
|
+
const result = substitute(template, context);
|
|
117
|
+
if (opts.output) {
|
|
118
|
+
const outPath = path.isAbsolute(opts.output) ? opts.output : path.resolve(process.cwd(), opts.output);
|
|
119
|
+
await writeFile(outPath, result, 'utf8');
|
|
120
|
+
} else {
|
|
121
|
+
console.log(result);
|
|
122
|
+
}
|
|
123
|
+
exit(0);
|
|
124
|
+
} catch (err) {
|
|
125
|
+
console.error('Error:', err.message);
|
|
126
|
+
exit(1);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
131
|
+
main();
|
|
132
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { writeFile, readFile, rm } from 'node:fs/promises';
|
|
4
|
+
import { spawnSync } from 'node:child_process';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
|
|
7
|
+
const cliPath = path.resolve(import.meta.dirname, '..', 'src', 'index.js');
|
|
8
|
+
|
|
9
|
+
test('CLI substitutes placeholders from JSON context', async (t) => {
|
|
10
|
+
const tmpDir = await import('node:fs/promises').then(fs => fs.mkdtemp(path.join(import.meta.dirname, 'tmp-')));
|
|
11
|
+
const promptPath = path.join(tmpDir, 'prompt.txt');
|
|
12
|
+
const contextPath = path.join(tmpDir, 'context.json');
|
|
13
|
+
|
|
14
|
+
const promptContent = 'Hello {{name}}, your task is {{task}}.';
|
|
15
|
+
const contextContent = JSON.stringify({ name: 'Alice', task: 'review code' }, null, 2);
|
|
16
|
+
|
|
17
|
+
await writeFile(promptPath, promptContent, 'utf8');
|
|
18
|
+
await writeFile(contextPath, contextContent, 'utf8');
|
|
19
|
+
|
|
20
|
+
const result = spawnSync('node', [cliPath, '--prompt', promptPath, '--context', contextPath], { encoding: 'utf8' });
|
|
21
|
+
|
|
22
|
+
assert.equal(result.status, 0, 'process should exit with code 0');
|
|
23
|
+
assert.equal(result.stdout.trim(), 'Hello Alice, your task is review code.');
|
|
24
|
+
|
|
25
|
+
// Clean up
|
|
26
|
+
await rm(tmpDir, { recursive: true, force: true });
|
|
27
|
+
});
|