praisonai 1.2.2 → 1.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent/simple.js +1 -1
- package/dist/cli/commands/auto.d.ts +12 -0
- package/dist/cli/commands/auto.js +109 -0
- package/dist/cli/commands/autonomy.d.ts +5 -0
- package/dist/cli/commands/autonomy.js +152 -0
- package/dist/cli/commands/cache.d.ts +9 -0
- package/dist/cli/commands/cache.js +143 -0
- package/dist/cli/commands/chat.d.ts +14 -0
- package/dist/cli/commands/chat.js +127 -0
- package/dist/cli/commands/checkpoints.d.ts +5 -0
- package/dist/cli/commands/checkpoints.js +236 -0
- package/dist/cli/commands/context.d.ts +11 -0
- package/dist/cli/commands/context.js +182 -0
- package/dist/cli/commands/cost.d.ts +5 -0
- package/dist/cli/commands/cost.js +146 -0
- package/dist/cli/commands/db.d.ts +9 -0
- package/dist/cli/commands/db.js +149 -0
- package/dist/cli/commands/eval.d.ts +17 -0
- package/dist/cli/commands/eval.js +247 -0
- package/dist/cli/commands/external-agents.d.ts +5 -0
- package/dist/cli/commands/external-agents.js +169 -0
- package/dist/cli/commands/fast-context.d.ts +5 -0
- package/dist/cli/commands/fast-context.js +126 -0
- package/dist/cli/commands/flow.d.ts +5 -0
- package/dist/cli/commands/flow.js +141 -0
- package/dist/cli/commands/git.d.ts +5 -0
- package/dist/cli/commands/git.js +178 -0
- package/dist/cli/commands/graph-rag.d.ts +9 -0
- package/dist/cli/commands/graph-rag.js +131 -0
- package/dist/cli/commands/guardrail.d.ts +11 -0
- package/dist/cli/commands/guardrail.js +156 -0
- package/dist/cli/commands/handoff.d.ts +9 -0
- package/dist/cli/commands/handoff.js +133 -0
- package/dist/cli/commands/help.d.ts +8 -0
- package/dist/cli/commands/help.js +167 -0
- package/dist/cli/commands/image.d.ts +13 -0
- package/dist/cli/commands/image.js +192 -0
- package/dist/cli/commands/interactive.d.ts +6 -0
- package/dist/cli/commands/interactive.js +79 -0
- package/dist/cli/commands/jobs.d.ts +5 -0
- package/dist/cli/commands/jobs.js +282 -0
- package/dist/cli/commands/knowledge.d.ts +9 -0
- package/dist/cli/commands/knowledge.js +226 -0
- package/dist/cli/commands/mcp.d.ts +9 -0
- package/dist/cli/commands/mcp.js +243 -0
- package/dist/cli/commands/memory.d.ts +10 -0
- package/dist/cli/commands/memory.js +198 -0
- package/dist/cli/commands/n8n.d.ts +5 -0
- package/dist/cli/commands/n8n.js +137 -0
- package/dist/cli/commands/observability.d.ts +9 -0
- package/dist/cli/commands/observability.js +145 -0
- package/dist/cli/commands/planning.d.ts +9 -0
- package/dist/cli/commands/planning.js +167 -0
- package/dist/cli/commands/prompt-expand.d.ts +11 -0
- package/dist/cli/commands/prompt-expand.js +100 -0
- package/dist/cli/commands/providers.d.ts +9 -0
- package/dist/cli/commands/providers.js +98 -0
- package/dist/cli/commands/query-rewrite.d.ts +12 -0
- package/dist/cli/commands/query-rewrite.js +102 -0
- package/dist/cli/commands/repo-map.d.ts +5 -0
- package/dist/cli/commands/repo-map.js +151 -0
- package/dist/cli/commands/reranker.d.ts +10 -0
- package/dist/cli/commands/reranker.js +144 -0
- package/dist/cli/commands/research.d.ts +12 -0
- package/dist/cli/commands/research.js +108 -0
- package/dist/cli/commands/router.d.ts +11 -0
- package/dist/cli/commands/router.js +142 -0
- package/dist/cli/commands/run.d.ts +14 -0
- package/dist/cli/commands/run.js +111 -0
- package/dist/cli/commands/sandbox.d.ts +5 -0
- package/dist/cli/commands/sandbox.js +135 -0
- package/dist/cli/commands/scheduler.d.ts +5 -0
- package/dist/cli/commands/scheduler.js +260 -0
- package/dist/cli/commands/session.d.ts +9 -0
- package/dist/cli/commands/session.js +238 -0
- package/dist/cli/commands/skills.d.ts +9 -0
- package/dist/cli/commands/skills.js +256 -0
- package/dist/cli/commands/telemetry.d.ts +9 -0
- package/dist/cli/commands/telemetry.js +146 -0
- package/dist/cli/commands/tools.d.ts +9 -0
- package/dist/cli/commands/tools.js +172 -0
- package/dist/cli/commands/vector.d.ts +10 -0
- package/dist/cli/commands/vector.js +171 -0
- package/dist/cli/commands/version.d.ts +8 -0
- package/dist/cli/commands/version.js +68 -0
- package/dist/cli/commands/voice.d.ts +10 -0
- package/dist/cli/commands/voice.js +162 -0
- package/dist/cli/commands/workflow.d.ts +13 -0
- package/dist/cli/commands/workflow.js +184 -0
- package/dist/cli/config/index.d.ts +6 -0
- package/dist/cli/config/index.js +22 -0
- package/dist/cli/config/load.d.ts +20 -0
- package/dist/cli/config/load.js +229 -0
- package/dist/cli/config/resolve.d.ts +28 -0
- package/dist/cli/config/resolve.js +70 -0
- package/dist/cli/config/schema.d.ts +15 -0
- package/dist/cli/config/schema.js +65 -0
- package/dist/cli/features/autonomy-mode.d.ts +98 -0
- package/dist/cli/features/autonomy-mode.js +266 -0
- package/dist/cli/features/background-jobs.d.ts +155 -0
- package/dist/cli/features/background-jobs.js +416 -0
- package/dist/cli/features/checkpoints.d.ts +126 -0
- package/dist/cli/features/checkpoints.js +288 -0
- package/dist/cli/features/cost-tracker.d.ts +101 -0
- package/dist/cli/features/cost-tracker.js +212 -0
- package/dist/cli/features/external-agents.d.ts +115 -0
- package/dist/cli/features/external-agents.js +294 -0
- package/dist/cli/features/fast-context.d.ts +126 -0
- package/dist/cli/features/fast-context.js +310 -0
- package/dist/cli/features/flow-display.d.ts +100 -0
- package/dist/cli/features/flow-display.js +254 -0
- package/dist/cli/features/git-integration.d.ts +138 -0
- package/dist/cli/features/git-integration.js +374 -0
- package/dist/cli/features/index.d.ts +17 -0
- package/dist/cli/features/index.js +102 -0
- package/dist/cli/features/interactive-tui.d.ts +114 -0
- package/dist/cli/features/interactive-tui.js +326 -0
- package/dist/cli/features/n8n-integration.d.ts +108 -0
- package/dist/cli/features/n8n-integration.js +296 -0
- package/dist/cli/features/repo-map.d.ts +101 -0
- package/dist/cli/features/repo-map.js +350 -0
- package/dist/cli/features/sandbox-executor.d.ts +89 -0
- package/dist/cli/features/sandbox-executor.js +314 -0
- package/dist/cli/features/scheduler.d.ts +111 -0
- package/dist/cli/features/scheduler.js +298 -0
- package/dist/cli/features/slash-commands.d.ts +77 -0
- package/dist/cli/features/slash-commands.js +316 -0
- package/dist/cli/index.d.ts +19 -15
- package/dist/cli/index.js +163 -123
- package/dist/cli/output/errors.d.ts +32 -0
- package/dist/cli/output/errors.js +72 -0
- package/dist/cli/output/index.d.ts +6 -0
- package/dist/cli/output/index.js +22 -0
- package/dist/cli/output/json.d.ts +17 -0
- package/dist/cli/output/json.js +54 -0
- package/dist/cli/output/pretty.d.ts +21 -0
- package/dist/cli/output/pretty.js +106 -0
- package/dist/cli/runtime/env.d.ts +12 -0
- package/dist/cli/runtime/env.js +49 -0
- package/dist/cli/runtime/exit.d.ts +11 -0
- package/dist/cli/runtime/exit.js +49 -0
- package/dist/cli/runtime/index.d.ts +6 -0
- package/dist/cli/runtime/index.js +22 -0
- package/dist/cli/runtime/lazy.d.ts +18 -0
- package/dist/cli/runtime/lazy.js +85 -0
- package/dist/cli/spec/cli-spec.d.ts +87 -0
- package/dist/cli/spec/cli-spec.js +478 -0
- package/dist/cli/spec/index.d.ts +4 -0
- package/dist/cli/spec/index.js +20 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +100 -7
- package/dist/memory/auto-memory.d.ts +136 -0
- package/dist/memory/auto-memory.js +301 -0
- package/dist/memory/file-memory.d.ts +88 -0
- package/dist/memory/file-memory.js +287 -0
- package/dist/memory/index.d.ts +2 -0
- package/dist/memory/index.js +11 -1
- package/dist/workflows/loop.d.ts +0 -0
- package/dist/workflows/loop.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Workflow command - Execute a multi-agent workflow
|
|
4
|
+
*/
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
17
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
18
|
+
}) : function(o, v) {
|
|
19
|
+
o["default"] = v;
|
|
20
|
+
});
|
|
21
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
22
|
+
var ownKeys = function(o) {
|
|
23
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
24
|
+
var ar = [];
|
|
25
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
26
|
+
return ar;
|
|
27
|
+
};
|
|
28
|
+
return ownKeys(o);
|
|
29
|
+
};
|
|
30
|
+
return function (mod) {
|
|
31
|
+
if (mod && mod.__esModule) return mod;
|
|
32
|
+
var result = {};
|
|
33
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
34
|
+
__setModuleDefault(result, mod);
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
})();
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.execute = execute;
|
|
40
|
+
const fs = __importStar(require("fs"));
|
|
41
|
+
const path = __importStar(require("path"));
|
|
42
|
+
const resolve_1 = require("../config/resolve");
|
|
43
|
+
const json_1 = require("../output/json");
|
|
44
|
+
const pretty = __importStar(require("../output/pretty"));
|
|
45
|
+
const cli_spec_1 = require("../spec/cli-spec");
|
|
46
|
+
const errors_1 = require("../output/errors");
|
|
47
|
+
/**
|
|
48
|
+
* Simple YAML parser for workflow files
|
|
49
|
+
*/
|
|
50
|
+
function parseWorkflowYaml(content) {
|
|
51
|
+
const result = {};
|
|
52
|
+
const lines = content.split('\n');
|
|
53
|
+
let currentSection = null;
|
|
54
|
+
let currentItem = null;
|
|
55
|
+
let currentKey = null;
|
|
56
|
+
for (const line of lines) {
|
|
57
|
+
if (!line.trim() || line.trim().startsWith('#'))
|
|
58
|
+
continue;
|
|
59
|
+
const indent = line.search(/\S/);
|
|
60
|
+
const trimmed = line.trim();
|
|
61
|
+
// Top-level keys
|
|
62
|
+
if (indent === 0 && trimmed.includes(':')) {
|
|
63
|
+
const colonIdx = trimmed.indexOf(':');
|
|
64
|
+
const key = trimmed.slice(0, colonIdx).trim();
|
|
65
|
+
const value = trimmed.slice(colonIdx + 1).trim();
|
|
66
|
+
if (value) {
|
|
67
|
+
result[key] = value;
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
currentSection = key;
|
|
71
|
+
if (key === 'agents')
|
|
72
|
+
result.agents = {};
|
|
73
|
+
if (key === 'steps')
|
|
74
|
+
result.steps = [];
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
else if (indent > 0 && currentSection) {
|
|
78
|
+
// Handle list items (steps)
|
|
79
|
+
if (trimmed.startsWith('- ')) {
|
|
80
|
+
if (currentSection === 'steps') {
|
|
81
|
+
currentItem = {};
|
|
82
|
+
result.steps.push(currentItem);
|
|
83
|
+
// Parse inline values after -
|
|
84
|
+
const afterDash = trimmed.slice(2).trim();
|
|
85
|
+
if (afterDash.includes(':')) {
|
|
86
|
+
const colonIdx = afterDash.indexOf(':');
|
|
87
|
+
const key = afterDash.slice(0, colonIdx).trim();
|
|
88
|
+
const value = afterDash.slice(colonIdx + 1).trim();
|
|
89
|
+
currentItem[key] = value;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
else if (trimmed.includes(':') && currentItem) {
|
|
94
|
+
const colonIdx = trimmed.indexOf(':');
|
|
95
|
+
const key = trimmed.slice(0, colonIdx).trim();
|
|
96
|
+
const value = trimmed.slice(colonIdx + 1).trim();
|
|
97
|
+
currentItem[key] = value || [];
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return result;
|
|
102
|
+
}
|
|
103
|
+
async function execute(args, options) {
|
|
104
|
+
const workflowFile = args[0];
|
|
105
|
+
if (!workflowFile) {
|
|
106
|
+
if (options.json || options.output === 'json') {
|
|
107
|
+
(0, json_1.printError)(errors_1.ERROR_CODES.MISSING_ARG, 'Please provide a workflow file path');
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
await pretty.error('Please provide a workflow file path');
|
|
111
|
+
}
|
|
112
|
+
process.exit(cli_spec_1.EXIT_CODES.INVALID_ARGUMENTS);
|
|
113
|
+
}
|
|
114
|
+
// Resolve config
|
|
115
|
+
const config = (0, resolve_1.resolveConfig)({
|
|
116
|
+
configPath: options.config,
|
|
117
|
+
profile: options.profile,
|
|
118
|
+
model: options.model,
|
|
119
|
+
verbose: options.verbose
|
|
120
|
+
});
|
|
121
|
+
const startTime = Date.now();
|
|
122
|
+
const outputFormat = options.json ? 'json' : (options.output || 'pretty');
|
|
123
|
+
try {
|
|
124
|
+
// Read and parse workflow file
|
|
125
|
+
const filePath = path.resolve(workflowFile);
|
|
126
|
+
if (!fs.existsSync(filePath)) {
|
|
127
|
+
throw new Error(`Workflow file not found: ${filePath}`);
|
|
128
|
+
}
|
|
129
|
+
const content = fs.readFileSync(filePath, 'utf-8');
|
|
130
|
+
const workflow = parseWorkflowYaml(content);
|
|
131
|
+
if (outputFormat !== 'json') {
|
|
132
|
+
await pretty.heading(`Executing workflow: ${workflow.name || 'Unnamed'}`);
|
|
133
|
+
if (workflow.description) {
|
|
134
|
+
await pretty.info(workflow.description);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
// Execute workflow steps
|
|
138
|
+
const results = {};
|
|
139
|
+
const steps = workflow.steps || [];
|
|
140
|
+
for (const step of steps) {
|
|
141
|
+
if (outputFormat !== 'json') {
|
|
142
|
+
await pretty.info(`Running step: ${step.name}`);
|
|
143
|
+
}
|
|
144
|
+
// For now, we'll simulate step execution
|
|
145
|
+
// In a full implementation, this would create agents and execute tasks
|
|
146
|
+
results[step.name] = {
|
|
147
|
+
status: 'completed',
|
|
148
|
+
output: `Step ${step.name} completed`
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
const duration = Date.now() - startTime;
|
|
152
|
+
if (outputFormat === 'json') {
|
|
153
|
+
(0, json_1.outputJson)((0, json_1.formatSuccess)({
|
|
154
|
+
workflow: workflow.name || 'Unnamed',
|
|
155
|
+
steps: steps.length,
|
|
156
|
+
results
|
|
157
|
+
}, {
|
|
158
|
+
duration_ms: duration,
|
|
159
|
+
model: config.model
|
|
160
|
+
}));
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
await pretty.success(`Workflow completed in ${duration}ms`);
|
|
164
|
+
await pretty.newline();
|
|
165
|
+
await pretty.keyValue({
|
|
166
|
+
'Steps executed': steps.length,
|
|
167
|
+
'Duration': `${duration}ms`
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
catch (error) {
|
|
172
|
+
const cliError = (0, errors_1.normalizeError)(error);
|
|
173
|
+
if (outputFormat === 'json') {
|
|
174
|
+
(0, json_1.outputJson)((0, json_1.formatError)(cliError.code, cliError.message, cliError.details));
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
await pretty.error(cliError.message);
|
|
178
|
+
if (config.verbose && error instanceof Error && error.stack) {
|
|
179
|
+
await pretty.dim(error.stack);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
process.exit(cliError.exitCode);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Config utilities index
|
|
4
|
+
*/
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
17
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
__exportStar(require("./schema"), exports);
|
|
21
|
+
__exportStar(require("./load"), exports);
|
|
22
|
+
__exportStar(require("./resolve"), exports);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Config file loading
|
|
3
|
+
*/
|
|
4
|
+
import { FullConfig } from './schema';
|
|
5
|
+
export interface LoadConfigOptions {
|
|
6
|
+
configPath?: string;
|
|
7
|
+
cwd?: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Load config from file
|
|
11
|
+
*/
|
|
12
|
+
export declare function loadConfigFile(filePath: string): FullConfig;
|
|
13
|
+
/**
|
|
14
|
+
* Load config with resolution order:
|
|
15
|
+
* 1. Explicit config path
|
|
16
|
+
* 2. Project config (current dir and parents)
|
|
17
|
+
* 3. User config (~/.praisonai.yaml)
|
|
18
|
+
* 4. Defaults
|
|
19
|
+
*/
|
|
20
|
+
export declare function loadConfig(options?: LoadConfigOptions): FullConfig;
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Config file loading
|
|
4
|
+
*/
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
17
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
18
|
+
}) : function(o, v) {
|
|
19
|
+
o["default"] = v;
|
|
20
|
+
});
|
|
21
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
22
|
+
var ownKeys = function(o) {
|
|
23
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
24
|
+
var ar = [];
|
|
25
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
26
|
+
return ar;
|
|
27
|
+
};
|
|
28
|
+
return ownKeys(o);
|
|
29
|
+
};
|
|
30
|
+
return function (mod) {
|
|
31
|
+
if (mod && mod.__esModule) return mod;
|
|
32
|
+
var result = {};
|
|
33
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
34
|
+
__setModuleDefault(result, mod);
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
})();
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.loadConfigFile = loadConfigFile;
|
|
40
|
+
exports.loadConfig = loadConfig;
|
|
41
|
+
const fs = __importStar(require("fs"));
|
|
42
|
+
const path = __importStar(require("path"));
|
|
43
|
+
const cli_spec_1 = require("../spec/cli-spec");
|
|
44
|
+
const schema_1 = require("./schema");
|
|
45
|
+
/**
|
|
46
|
+
* Find config file in directory hierarchy
|
|
47
|
+
*/
|
|
48
|
+
function findConfigFile(startDir) {
|
|
49
|
+
let currentDir = startDir;
|
|
50
|
+
while (true) {
|
|
51
|
+
for (const filename of cli_spec_1.CONFIG_FILES) {
|
|
52
|
+
const filePath = path.join(currentDir, filename);
|
|
53
|
+
if (fs.existsSync(filePath)) {
|
|
54
|
+
return filePath;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const parentDir = path.dirname(currentDir);
|
|
58
|
+
if (parentDir === currentDir) {
|
|
59
|
+
break; // Reached root
|
|
60
|
+
}
|
|
61
|
+
currentDir = parentDir;
|
|
62
|
+
}
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Find user config file
|
|
67
|
+
*/
|
|
68
|
+
function findUserConfigFile() {
|
|
69
|
+
const homeDir = process.env.HOME || process.env.USERPROFILE;
|
|
70
|
+
if (!homeDir)
|
|
71
|
+
return null;
|
|
72
|
+
for (const filename of cli_spec_1.CONFIG_FILES) {
|
|
73
|
+
const filePath = path.join(homeDir, filename);
|
|
74
|
+
if (fs.existsSync(filePath)) {
|
|
75
|
+
return filePath;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Parse config file content
|
|
82
|
+
*/
|
|
83
|
+
function parseConfigFile(filePath) {
|
|
84
|
+
const content = fs.readFileSync(filePath, 'utf-8');
|
|
85
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
86
|
+
if (ext === '.json') {
|
|
87
|
+
return JSON.parse(content);
|
|
88
|
+
}
|
|
89
|
+
if (ext === '.yaml' || ext === '.yml') {
|
|
90
|
+
// Simple YAML parsing for basic config
|
|
91
|
+
// For complex YAML, we'd need a proper parser
|
|
92
|
+
return parseSimpleYaml(content);
|
|
93
|
+
}
|
|
94
|
+
throw new Error(`Unsupported config file format: ${ext}`);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Simple YAML parser for basic key-value configs
|
|
98
|
+
* Handles: strings, booleans, numbers, simple objects
|
|
99
|
+
*/
|
|
100
|
+
function parseSimpleYaml(content) {
|
|
101
|
+
const result = {};
|
|
102
|
+
const lines = content.split('\n');
|
|
103
|
+
let currentObject = null;
|
|
104
|
+
let currentKey = null;
|
|
105
|
+
let baseIndent = 0;
|
|
106
|
+
for (const line of lines) {
|
|
107
|
+
// Skip empty lines and comments
|
|
108
|
+
if (!line.trim() || line.trim().startsWith('#')) {
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
const indent = line.search(/\S/);
|
|
112
|
+
const trimmed = line.trim();
|
|
113
|
+
// Check for key: value pattern
|
|
114
|
+
const colonIndex = trimmed.indexOf(':');
|
|
115
|
+
if (colonIndex === -1)
|
|
116
|
+
continue;
|
|
117
|
+
const key = trimmed.slice(0, colonIndex).trim();
|
|
118
|
+
const value = trimmed.slice(colonIndex + 1).trim();
|
|
119
|
+
if (indent === 0) {
|
|
120
|
+
// Top-level key
|
|
121
|
+
if (value === '' || value === '{}') {
|
|
122
|
+
// Start of nested object
|
|
123
|
+
currentObject = {};
|
|
124
|
+
currentKey = key;
|
|
125
|
+
baseIndent = indent;
|
|
126
|
+
result[key] = currentObject;
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
result[key] = parseYamlValue(value);
|
|
130
|
+
currentObject = null;
|
|
131
|
+
currentKey = null;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
else if (currentObject !== null && indent > baseIndent) {
|
|
135
|
+
// Nested key
|
|
136
|
+
if (value === '' || value === '{}') {
|
|
137
|
+
// Nested object within nested object
|
|
138
|
+
const nestedObj = {};
|
|
139
|
+
currentObject[key] = nestedObj;
|
|
140
|
+
// For simplicity, we only support one level of nesting in profiles
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
currentObject[key] = parseYamlValue(value);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return result;
|
|
148
|
+
}
|
|
149
|
+
function parseYamlValue(value) {
|
|
150
|
+
// Remove quotes
|
|
151
|
+
if ((value.startsWith('"') && value.endsWith('"')) ||
|
|
152
|
+
(value.startsWith("'") && value.endsWith("'"))) {
|
|
153
|
+
return value.slice(1, -1);
|
|
154
|
+
}
|
|
155
|
+
// Boolean
|
|
156
|
+
if (value === 'true')
|
|
157
|
+
return true;
|
|
158
|
+
if (value === 'false')
|
|
159
|
+
return false;
|
|
160
|
+
// Number
|
|
161
|
+
const num = Number(value);
|
|
162
|
+
if (!isNaN(num) && value !== '')
|
|
163
|
+
return num;
|
|
164
|
+
return value;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Load config from file
|
|
168
|
+
*/
|
|
169
|
+
function loadConfigFile(filePath) {
|
|
170
|
+
try {
|
|
171
|
+
const parsed = parseConfigFile(filePath);
|
|
172
|
+
if (!(0, schema_1.validateConfig)(parsed)) {
|
|
173
|
+
throw new Error('Invalid config format');
|
|
174
|
+
}
|
|
175
|
+
return parsed;
|
|
176
|
+
}
|
|
177
|
+
catch (error) {
|
|
178
|
+
throw new Error(`Failed to load config from ${filePath}: ${error instanceof Error ? error.message : String(error)}`);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Load config with resolution order:
|
|
183
|
+
* 1. Explicit config path
|
|
184
|
+
* 2. Project config (current dir and parents)
|
|
185
|
+
* 3. User config (~/.praisonai.yaml)
|
|
186
|
+
* 4. Defaults
|
|
187
|
+
*/
|
|
188
|
+
function loadConfig(options = {}) {
|
|
189
|
+
const configs = [schema_1.DEFAULT_CONFIG];
|
|
190
|
+
// User config
|
|
191
|
+
const userConfigPath = findUserConfigFile();
|
|
192
|
+
if (userConfigPath) {
|
|
193
|
+
try {
|
|
194
|
+
configs.push(loadConfigFile(userConfigPath));
|
|
195
|
+
}
|
|
196
|
+
catch {
|
|
197
|
+
// Ignore user config errors
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
// Project config
|
|
201
|
+
const cwd = options.cwd || process.cwd();
|
|
202
|
+
const projectConfigPath = findConfigFile(cwd);
|
|
203
|
+
if (projectConfigPath) {
|
|
204
|
+
try {
|
|
205
|
+
configs.push(loadConfigFile(projectConfigPath));
|
|
206
|
+
}
|
|
207
|
+
catch {
|
|
208
|
+
// Ignore project config errors
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
// Explicit config path
|
|
212
|
+
if (options.configPath) {
|
|
213
|
+
configs.push(loadConfigFile(options.configPath));
|
|
214
|
+
}
|
|
215
|
+
// Merge all configs
|
|
216
|
+
const result = { ...schema_1.DEFAULT_CONFIG };
|
|
217
|
+
for (const config of configs) {
|
|
218
|
+
if (config.model !== undefined)
|
|
219
|
+
result.model = config.model;
|
|
220
|
+
if (config.verbose !== undefined)
|
|
221
|
+
result.verbose = config.verbose;
|
|
222
|
+
if (config.stream !== undefined)
|
|
223
|
+
result.stream = config.stream;
|
|
224
|
+
if (config.profiles !== undefined) {
|
|
225
|
+
result.profiles = { ...result.profiles, ...config.profiles };
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return result;
|
|
229
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Config resolution with profiles and CLI overrides
|
|
3
|
+
*/
|
|
4
|
+
export interface ResolvedConfig {
|
|
5
|
+
model: string;
|
|
6
|
+
verbose: boolean;
|
|
7
|
+
stream: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface ResolveOptions {
|
|
10
|
+
configPath?: string;
|
|
11
|
+
profile?: string;
|
|
12
|
+
model?: string;
|
|
13
|
+
verbose?: boolean;
|
|
14
|
+
stream?: boolean;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Resolve final config with precedence:
|
|
18
|
+
* 1. CLI flags (highest)
|
|
19
|
+
* 2. Environment variables
|
|
20
|
+
* 3. Profile settings
|
|
21
|
+
* 4. Config file
|
|
22
|
+
* 5. Defaults (lowest)
|
|
23
|
+
*/
|
|
24
|
+
export declare function resolveConfig(options?: ResolveOptions): ResolvedConfig;
|
|
25
|
+
/**
|
|
26
|
+
* Get available profile names
|
|
27
|
+
*/
|
|
28
|
+
export declare function getAvailableProfiles(configPath?: string): string[];
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Config resolution with profiles and CLI overrides
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.resolveConfig = resolveConfig;
|
|
7
|
+
exports.getAvailableProfiles = getAvailableProfiles;
|
|
8
|
+
const load_1 = require("./load");
|
|
9
|
+
const env_1 = require("../runtime/env");
|
|
10
|
+
const schema_1 = require("./schema");
|
|
11
|
+
/**
|
|
12
|
+
* Resolve final config with precedence:
|
|
13
|
+
* 1. CLI flags (highest)
|
|
14
|
+
* 2. Environment variables
|
|
15
|
+
* 3. Profile settings
|
|
16
|
+
* 4. Config file
|
|
17
|
+
* 5. Defaults (lowest)
|
|
18
|
+
*/
|
|
19
|
+
function resolveConfig(options = {}) {
|
|
20
|
+
// Load base config from files
|
|
21
|
+
const fileConfig = (0, load_1.loadConfig)({ configPath: options.configPath });
|
|
22
|
+
// Load env config
|
|
23
|
+
const envConfig = (0, env_1.loadEnvConfig)();
|
|
24
|
+
// Get profile config if specified
|
|
25
|
+
let profileConfig = {};
|
|
26
|
+
const profileName = options.profile || envConfig.profile;
|
|
27
|
+
if (profileName && fileConfig.profiles?.[profileName]) {
|
|
28
|
+
profileConfig = fileConfig.profiles[profileName];
|
|
29
|
+
}
|
|
30
|
+
// Resolve with precedence
|
|
31
|
+
const resolved = {
|
|
32
|
+
model: schema_1.DEFAULT_CONFIG.model,
|
|
33
|
+
verbose: schema_1.DEFAULT_CONFIG.verbose,
|
|
34
|
+
stream: schema_1.DEFAULT_CONFIG.stream
|
|
35
|
+
};
|
|
36
|
+
// Apply file config
|
|
37
|
+
if (fileConfig.model !== undefined)
|
|
38
|
+
resolved.model = fileConfig.model;
|
|
39
|
+
if (fileConfig.verbose !== undefined)
|
|
40
|
+
resolved.verbose = fileConfig.verbose;
|
|
41
|
+
if (fileConfig.stream !== undefined)
|
|
42
|
+
resolved.stream = fileConfig.stream;
|
|
43
|
+
// Apply profile config
|
|
44
|
+
if (profileConfig.model !== undefined)
|
|
45
|
+
resolved.model = profileConfig.model;
|
|
46
|
+
if (profileConfig.verbose !== undefined)
|
|
47
|
+
resolved.verbose = profileConfig.verbose;
|
|
48
|
+
if (profileConfig.stream !== undefined)
|
|
49
|
+
resolved.stream = profileConfig.stream;
|
|
50
|
+
// Apply env config
|
|
51
|
+
if (envConfig.model !== undefined)
|
|
52
|
+
resolved.model = envConfig.model;
|
|
53
|
+
if (envConfig.verbose !== undefined)
|
|
54
|
+
resolved.verbose = envConfig.verbose;
|
|
55
|
+
// Apply CLI flags (highest precedence)
|
|
56
|
+
if (options.model !== undefined)
|
|
57
|
+
resolved.model = options.model;
|
|
58
|
+
if (options.verbose !== undefined)
|
|
59
|
+
resolved.verbose = options.verbose;
|
|
60
|
+
if (options.stream !== undefined)
|
|
61
|
+
resolved.stream = options.stream;
|
|
62
|
+
return resolved;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Get available profile names
|
|
66
|
+
*/
|
|
67
|
+
function getAvailableProfiles(configPath) {
|
|
68
|
+
const config = (0, load_1.loadConfig)({ configPath });
|
|
69
|
+
return Object.keys(config.profiles || {});
|
|
70
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Config schema definitions
|
|
3
|
+
*/
|
|
4
|
+
import { ConfigSchema } from '../spec/cli-spec';
|
|
5
|
+
export interface ProfileConfig {
|
|
6
|
+
model?: string;
|
|
7
|
+
verbose?: boolean;
|
|
8
|
+
stream?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface FullConfig extends ConfigSchema {
|
|
11
|
+
profiles?: Record<string, ProfileConfig>;
|
|
12
|
+
}
|
|
13
|
+
export declare const DEFAULT_CONFIG: FullConfig;
|
|
14
|
+
export declare function validateConfig(config: unknown): config is FullConfig;
|
|
15
|
+
export declare function mergeConfigs(...configs: Partial<FullConfig>[]): FullConfig;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Config schema definitions
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DEFAULT_CONFIG = void 0;
|
|
7
|
+
exports.validateConfig = validateConfig;
|
|
8
|
+
exports.mergeConfigs = mergeConfigs;
|
|
9
|
+
exports.DEFAULT_CONFIG = {
|
|
10
|
+
model: 'openai/gpt-4o-mini',
|
|
11
|
+
verbose: false,
|
|
12
|
+
stream: false,
|
|
13
|
+
profiles: {}
|
|
14
|
+
};
|
|
15
|
+
function validateConfig(config) {
|
|
16
|
+
if (typeof config !== 'object' || config === null) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
const c = config;
|
|
20
|
+
if (c.model !== undefined && typeof c.model !== 'string') {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
if (c.verbose !== undefined && typeof c.verbose !== 'boolean') {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
if (c.stream !== undefined && typeof c.stream !== 'boolean') {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
if (c.profiles !== undefined) {
|
|
30
|
+
if (typeof c.profiles !== 'object' || c.profiles === null) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
for (const profile of Object.values(c.profiles)) {
|
|
34
|
+
if (typeof profile !== 'object' || profile === null) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
const p = profile;
|
|
38
|
+
if (p.model !== undefined && typeof p.model !== 'string') {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
if (p.verbose !== undefined && typeof p.verbose !== 'boolean') {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
if (p.stream !== undefined && typeof p.stream !== 'boolean') {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
function mergeConfigs(...configs) {
|
|
52
|
+
const result = { ...exports.DEFAULT_CONFIG };
|
|
53
|
+
for (const config of configs) {
|
|
54
|
+
if (config.model !== undefined)
|
|
55
|
+
result.model = config.model;
|
|
56
|
+
if (config.verbose !== undefined)
|
|
57
|
+
result.verbose = config.verbose;
|
|
58
|
+
if (config.stream !== undefined)
|
|
59
|
+
result.stream = config.stream;
|
|
60
|
+
if (config.profiles !== undefined) {
|
|
61
|
+
result.profiles = { ...result.profiles, ...config.profiles };
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return result;
|
|
65
|
+
}
|