network-ai 4.13.1 → 4.15.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/INTEGRATION_GUIDE.md +2 -2
- package/QUICKSTART.md +9 -0
- package/README.md +13 -4
- package/SKILL.md +1 -1
- package/bin/console.ts +769 -0
- package/dist/bin/console.d.ts +18 -0
- package/dist/bin/console.d.ts.map +1 -0
- package/dist/bin/console.js +799 -0
- package/dist/bin/console.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +30 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/agent-runtime.d.ts +310 -0
- package/dist/lib/agent-runtime.d.ts.map +1 -0
- package/dist/lib/agent-runtime.js +630 -0
- package/dist/lib/agent-runtime.js.map +1 -0
- package/dist/lib/console-ui.d.ts +134 -0
- package/dist/lib/console-ui.d.ts.map +1 -0
- package/dist/lib/console-ui.js +276 -0
- package/dist/lib/console-ui.js.map +1 -0
- package/dist/lib/goal-decomposer.d.ts +216 -0
- package/dist/lib/goal-decomposer.d.ts.map +1 -0
- package/dist/lib/goal-decomposer.js +549 -0
- package/dist/lib/goal-decomposer.js.map +1 -0
- package/dist/lib/phase-pipeline.js +1 -1
- package/dist/lib/phase-pipeline.js.map +1 -1
- package/dist/lib/strategy-agent.d.ts +320 -0
- package/dist/lib/strategy-agent.d.ts.map +1 -0
- package/dist/lib/strategy-agent.js +601 -0
- package/dist/lib/strategy-agent.js.map +1 -0
- package/package.json +7 -3
- package/scripts/postinstall.js +21 -0
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Console UI — Interactive terminal dashboard for Network-AI
|
|
3
|
+
*
|
|
4
|
+
* A TUI (text user interface) built with Node.js builtins (readline + ANSI
|
|
5
|
+
* escape codes). Zero external dependencies.
|
|
6
|
+
*
|
|
7
|
+
* Features:
|
|
8
|
+
* - Live event feed with timestamped entries
|
|
9
|
+
* - Status bar (agents, budget, FSM state)
|
|
10
|
+
* - Command input with auto-completion
|
|
11
|
+
* - Approval prompts (approve/deny inline)
|
|
12
|
+
* - Color-coded output
|
|
13
|
+
*
|
|
14
|
+
* @module ConsoleUI
|
|
15
|
+
* @version 1.0.0
|
|
16
|
+
*/
|
|
17
|
+
import { EventEmitter } from 'events';
|
|
18
|
+
/** ANSI color/style codes */
|
|
19
|
+
export declare const ansi: {
|
|
20
|
+
reset: string;
|
|
21
|
+
bold: string;
|
|
22
|
+
dim: string;
|
|
23
|
+
italic: string;
|
|
24
|
+
underline: string;
|
|
25
|
+
black: string;
|
|
26
|
+
red: string;
|
|
27
|
+
green: string;
|
|
28
|
+
yellow: string;
|
|
29
|
+
blue: string;
|
|
30
|
+
magenta: string;
|
|
31
|
+
cyan: string;
|
|
32
|
+
white: string;
|
|
33
|
+
gray: string;
|
|
34
|
+
bgBlack: string;
|
|
35
|
+
bgRed: string;
|
|
36
|
+
bgGreen: string;
|
|
37
|
+
bgYellow: string;
|
|
38
|
+
bgBlue: string;
|
|
39
|
+
bgMagenta: string;
|
|
40
|
+
bgCyan: string;
|
|
41
|
+
bgWhite: string;
|
|
42
|
+
clearScreen: string;
|
|
43
|
+
clearLine: string;
|
|
44
|
+
cursorHome: string;
|
|
45
|
+
hideCursor: string;
|
|
46
|
+
showCursor: string;
|
|
47
|
+
};
|
|
48
|
+
/** Status data displayed in the header bar */
|
|
49
|
+
export interface ConsoleStatus {
|
|
50
|
+
version: string;
|
|
51
|
+
agents: {
|
|
52
|
+
active: number;
|
|
53
|
+
total: number;
|
|
54
|
+
};
|
|
55
|
+
budget: {
|
|
56
|
+
usedPercent: number;
|
|
57
|
+
};
|
|
58
|
+
fsm: {
|
|
59
|
+
state: string;
|
|
60
|
+
};
|
|
61
|
+
pendingApprovals: number;
|
|
62
|
+
}
|
|
63
|
+
/** A feed entry displayed in the live feed */
|
|
64
|
+
export interface FeedEntry {
|
|
65
|
+
time: string;
|
|
66
|
+
icon: string;
|
|
67
|
+
message: string;
|
|
68
|
+
level: 'info' | 'warn' | 'error' | 'success' | 'approval';
|
|
69
|
+
}
|
|
70
|
+
/** Command handler function */
|
|
71
|
+
export type CommandHandler = (args: string, ui: ConsoleUI) => Promise<void> | void;
|
|
72
|
+
/** Console UI options */
|
|
73
|
+
export interface ConsoleUIOptions {
|
|
74
|
+
/** Title shown in the header */
|
|
75
|
+
title?: string;
|
|
76
|
+
/** Version string */
|
|
77
|
+
version?: string;
|
|
78
|
+
/** Custom prompt string (default: '> ') */
|
|
79
|
+
prompt?: string;
|
|
80
|
+
/** Maximum feed entries to keep (default: 200) */
|
|
81
|
+
maxFeedEntries?: number;
|
|
82
|
+
/** Input stream (default: process.stdin) */
|
|
83
|
+
input?: NodeJS.ReadableStream;
|
|
84
|
+
/** Output stream (default: process.stdout) */
|
|
85
|
+
output?: NodeJS.WritableStream;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Interactive terminal UI for Network-AI agent runtime.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```typescript
|
|
92
|
+
* const ui = new ConsoleUI({ title: 'Network-AI', version: '4.13.1' });
|
|
93
|
+
* ui.command('status', (args, ui) => { ui.log('All systems operational'); });
|
|
94
|
+
* ui.command('approve', async (args, ui) => { ... });
|
|
95
|
+
* await ui.start();
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
export declare class ConsoleUI extends EventEmitter {
|
|
99
|
+
private readonly opts;
|
|
100
|
+
private rl;
|
|
101
|
+
private commands;
|
|
102
|
+
private feed;
|
|
103
|
+
private status;
|
|
104
|
+
private running;
|
|
105
|
+
constructor(opts?: ConsoleUIOptions);
|
|
106
|
+
/** Register a command handler */
|
|
107
|
+
command(name: string, handler: CommandHandler, description?: string): void;
|
|
108
|
+
/** Update the status bar */
|
|
109
|
+
updateStatus(partial: Partial<ConsoleStatus>): void;
|
|
110
|
+
/** Add an entry to the live feed */
|
|
111
|
+
log(message: string, level?: FeedEntry['level']): void;
|
|
112
|
+
/** Get all feed entries */
|
|
113
|
+
getFeed(): ReadonlyArray<FeedEntry>;
|
|
114
|
+
/** Clear the feed */
|
|
115
|
+
clearFeed(): void;
|
|
116
|
+
/** Get current status */
|
|
117
|
+
getStatus(): Readonly<ConsoleStatus>;
|
|
118
|
+
/** Start the interactive console */
|
|
119
|
+
start(): Promise<void>;
|
|
120
|
+
/** Stop the console */
|
|
121
|
+
stop(): void;
|
|
122
|
+
/** Whether the console is currently running */
|
|
123
|
+
get isRunning(): boolean;
|
|
124
|
+
/** Show the help text */
|
|
125
|
+
showHelp(): void;
|
|
126
|
+
/** Render the header/status bar */
|
|
127
|
+
renderHeader(): void;
|
|
128
|
+
private write;
|
|
129
|
+
private renderPrompt;
|
|
130
|
+
private writeFeedEntry;
|
|
131
|
+
private budgetColor;
|
|
132
|
+
private handleInput;
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=console-ui.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"console-ui.d.ts","sourceRoot":"","sources":["../../lib/console-ui.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAQtC,6BAA6B;AAC7B,eAAO,MAAM,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkChB,CAAC;AAoBF,8CAA8C;AAC9C,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAC1C,MAAM,EAAE;QAAE,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC;IAChC,GAAG,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IACvB,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAED,8CAA8C;AAC9C,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,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AAO,CAAU,GAAG,IAAI;IA6B9D,2BAA2B;IAC3B,OAAO,IAAI,aAAa,CAAC,SAAS,CAAC;IAInC,qBAAqB;IACrB,SAAS,IAAI,IAAI;IASjB,yBAAyB;IACzB,SAAS,IAAI,QAAQ,CAAC,aAAa,CAAC;IAIpC,oCAAoC;IAC9B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAkC5B,uBAAuB;IACvB,IAAI,IAAI,IAAI;IAUZ,+CAA+C;IAC/C,IAAI,SAAS,IAAI,OAAO,CAAyB;IAEjD,yBAAyB;IACzB,QAAQ,IAAI,IAAI;IAShB,mCAAmC;IACnC,YAAY,IAAI,IAAI;IAwBpB,OAAO,CAAC,KAAK;IAKb,OAAO,CAAC,YAAY;IAMpB,OAAO,CAAC,cAAc;IAKtB,OAAO,CAAC,WAAW;YAOL,WAAW;CAqB1B"}
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Console UI — Interactive terminal dashboard for Network-AI
|
|
4
|
+
*
|
|
5
|
+
* A TUI (text user interface) built with Node.js builtins (readline + ANSI
|
|
6
|
+
* escape codes). Zero external dependencies.
|
|
7
|
+
*
|
|
8
|
+
* Features:
|
|
9
|
+
* - Live event feed with timestamped entries
|
|
10
|
+
* - Status bar (agents, budget, FSM state)
|
|
11
|
+
* - Command input with auto-completion
|
|
12
|
+
* - Approval prompts (approve/deny inline)
|
|
13
|
+
* - Color-coded output
|
|
14
|
+
*
|
|
15
|
+
* @module ConsoleUI
|
|
16
|
+
* @version 1.0.0
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.ConsoleUI = exports.ansi = void 0;
|
|
20
|
+
const readline_1 = require("readline");
|
|
21
|
+
const events_1 = require("events");
|
|
22
|
+
// ============================================================================
|
|
23
|
+
// ANSI HELPERS
|
|
24
|
+
// ============================================================================
|
|
25
|
+
const ESC = '\x1b[';
|
|
26
|
+
/** ANSI color/style codes */
|
|
27
|
+
exports.ansi = {
|
|
28
|
+
reset: `${ESC}0m`,
|
|
29
|
+
bold: `${ESC}1m`,
|
|
30
|
+
dim: `${ESC}2m`,
|
|
31
|
+
italic: `${ESC}3m`,
|
|
32
|
+
underline: `${ESC}4m`,
|
|
33
|
+
// Foreground
|
|
34
|
+
black: `${ESC}30m`,
|
|
35
|
+
red: `${ESC}31m`,
|
|
36
|
+
green: `${ESC}32m`,
|
|
37
|
+
yellow: `${ESC}33m`,
|
|
38
|
+
blue: `${ESC}34m`,
|
|
39
|
+
magenta: `${ESC}35m`,
|
|
40
|
+
cyan: `${ESC}36m`,
|
|
41
|
+
white: `${ESC}37m`,
|
|
42
|
+
gray: `${ESC}90m`,
|
|
43
|
+
// Background
|
|
44
|
+
bgBlack: `${ESC}40m`,
|
|
45
|
+
bgRed: `${ESC}41m`,
|
|
46
|
+
bgGreen: `${ESC}42m`,
|
|
47
|
+
bgYellow: `${ESC}43m`,
|
|
48
|
+
bgBlue: `${ESC}44m`,
|
|
49
|
+
bgMagenta: `${ESC}45m`,
|
|
50
|
+
bgCyan: `${ESC}46m`,
|
|
51
|
+
bgWhite: `${ESC}47m`,
|
|
52
|
+
// Cursor
|
|
53
|
+
clearScreen: `${ESC}2J${ESC}H`,
|
|
54
|
+
clearLine: `${ESC}2K`,
|
|
55
|
+
cursorHome: `${ESC}H`,
|
|
56
|
+
hideCursor: `${ESC}?25l`,
|
|
57
|
+
showCursor: `${ESC}?25h`,
|
|
58
|
+
};
|
|
59
|
+
/** Apply color to text */
|
|
60
|
+
function color(text, ...codes) {
|
|
61
|
+
return codes.join('') + text + exports.ansi.reset;
|
|
62
|
+
}
|
|
63
|
+
/** Format a timestamp for display */
|
|
64
|
+
function timeStamp() {
|
|
65
|
+
const now = new Date();
|
|
66
|
+
const h = String(now.getHours()).padStart(2, '0');
|
|
67
|
+
const m = String(now.getMinutes()).padStart(2, '0');
|
|
68
|
+
const s = String(now.getSeconds()).padStart(2, '0');
|
|
69
|
+
return `${h}:${m}:${s}`;
|
|
70
|
+
}
|
|
71
|
+
// ============================================================================
|
|
72
|
+
// CONSOLE UI
|
|
73
|
+
// ============================================================================
|
|
74
|
+
/**
|
|
75
|
+
* Interactive terminal UI for Network-AI agent runtime.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* const ui = new ConsoleUI({ title: 'Network-AI', version: '4.13.1' });
|
|
80
|
+
* ui.command('status', (args, ui) => { ui.log('All systems operational'); });
|
|
81
|
+
* ui.command('approve', async (args, ui) => { ... });
|
|
82
|
+
* await ui.start();
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
class ConsoleUI extends events_1.EventEmitter {
|
|
86
|
+
opts;
|
|
87
|
+
rl = null;
|
|
88
|
+
commands = new Map();
|
|
89
|
+
feed = [];
|
|
90
|
+
status = {
|
|
91
|
+
version: '0.0.0',
|
|
92
|
+
agents: { active: 0, total: 0 },
|
|
93
|
+
budget: { usedPercent: 0 },
|
|
94
|
+
fsm: { state: 'idle' },
|
|
95
|
+
pendingApprovals: 0,
|
|
96
|
+
};
|
|
97
|
+
running = false;
|
|
98
|
+
constructor(opts = {}) {
|
|
99
|
+
super();
|
|
100
|
+
this.opts = {
|
|
101
|
+
title: opts.title ?? 'Network-AI',
|
|
102
|
+
version: opts.version ?? '0.0.0',
|
|
103
|
+
prompt: opts.prompt ?? '> ',
|
|
104
|
+
maxFeedEntries: opts.maxFeedEntries ?? 200,
|
|
105
|
+
input: opts.input ?? process.stdin,
|
|
106
|
+
output: opts.output ?? process.stdout,
|
|
107
|
+
};
|
|
108
|
+
this.status.version = this.opts.version;
|
|
109
|
+
// Register built-in commands
|
|
110
|
+
this.command('help', (_args, ui) => { ui.showHelp(); }, 'Show available commands');
|
|
111
|
+
this.command('clear', (_args, ui) => { ui.clearFeed(); }, 'Clear the event feed');
|
|
112
|
+
this.command('exit', () => { this.stop(); }, 'Exit the console');
|
|
113
|
+
this.command('quit', () => { this.stop(); }, 'Exit the console');
|
|
114
|
+
}
|
|
115
|
+
/** Register a command handler */
|
|
116
|
+
command(name, handler, description = '') {
|
|
117
|
+
this.commands.set(name.toLowerCase(), { handler, description });
|
|
118
|
+
}
|
|
119
|
+
/** Update the status bar */
|
|
120
|
+
updateStatus(partial) {
|
|
121
|
+
Object.assign(this.status, partial);
|
|
122
|
+
}
|
|
123
|
+
/** Add an entry to the live feed */
|
|
124
|
+
log(message, level = 'info') {
|
|
125
|
+
const icons = {
|
|
126
|
+
info: color('ℹ', exports.ansi.cyan),
|
|
127
|
+
warn: color('⚠', exports.ansi.yellow),
|
|
128
|
+
error: color('✗', exports.ansi.red),
|
|
129
|
+
success: color('✓', exports.ansi.green),
|
|
130
|
+
approval: color('⏳', exports.ansi.magenta),
|
|
131
|
+
};
|
|
132
|
+
const entry = {
|
|
133
|
+
time: timeStamp(),
|
|
134
|
+
icon: icons[level],
|
|
135
|
+
message,
|
|
136
|
+
level,
|
|
137
|
+
};
|
|
138
|
+
this.feed.push(entry);
|
|
139
|
+
if (this.feed.length > this.opts.maxFeedEntries) {
|
|
140
|
+
this.feed.shift();
|
|
141
|
+
}
|
|
142
|
+
this.emit('feed', entry);
|
|
143
|
+
// Print inline if running
|
|
144
|
+
if (this.running) {
|
|
145
|
+
this.writeFeedEntry(entry);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/** Get all feed entries */
|
|
149
|
+
getFeed() {
|
|
150
|
+
return this.feed;
|
|
151
|
+
}
|
|
152
|
+
/** Clear the feed */
|
|
153
|
+
clearFeed() {
|
|
154
|
+
this.feed = [];
|
|
155
|
+
if (this.running) {
|
|
156
|
+
this.write(exports.ansi.clearScreen);
|
|
157
|
+
this.renderHeader();
|
|
158
|
+
this.renderPrompt();
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
/** Get current status */
|
|
162
|
+
getStatus() {
|
|
163
|
+
return { ...this.status };
|
|
164
|
+
}
|
|
165
|
+
/** Start the interactive console */
|
|
166
|
+
async start() {
|
|
167
|
+
if (this.running)
|
|
168
|
+
return;
|
|
169
|
+
this.running = true;
|
|
170
|
+
this.rl = (0, readline_1.createInterface)({
|
|
171
|
+
input: this.opts.input,
|
|
172
|
+
output: this.opts.output,
|
|
173
|
+
prompt: this.opts.prompt,
|
|
174
|
+
terminal: true,
|
|
175
|
+
});
|
|
176
|
+
this.renderHeader();
|
|
177
|
+
this.renderPrompt();
|
|
178
|
+
this.rl.on('line', async (line) => {
|
|
179
|
+
const trimmed = line.trim();
|
|
180
|
+
if (trimmed) {
|
|
181
|
+
await this.handleInput(trimmed);
|
|
182
|
+
}
|
|
183
|
+
if (this.running) {
|
|
184
|
+
this.renderPrompt();
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
this.rl.on('close', () => {
|
|
188
|
+
this.running = false;
|
|
189
|
+
this.emit('exit');
|
|
190
|
+
});
|
|
191
|
+
return new Promise((resolve) => {
|
|
192
|
+
this.once('exit', resolve);
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
/** Stop the console */
|
|
196
|
+
stop() {
|
|
197
|
+
this.running = false;
|
|
198
|
+
if (this.rl) {
|
|
199
|
+
this.rl.close();
|
|
200
|
+
this.rl = null;
|
|
201
|
+
}
|
|
202
|
+
this.write(color('\nGoodbye.\n', exports.ansi.dim));
|
|
203
|
+
this.emit('exit');
|
|
204
|
+
}
|
|
205
|
+
/** Whether the console is currently running */
|
|
206
|
+
get isRunning() { return this.running; }
|
|
207
|
+
/** Show the help text */
|
|
208
|
+
showHelp() {
|
|
209
|
+
this.write('\n' + color(' Available Commands:', exports.ansi.bold, exports.ansi.cyan) + '\n');
|
|
210
|
+
for (const [name, { description }] of this.commands) {
|
|
211
|
+
const desc = description ? color(` — ${description}`, exports.ansi.dim) : '';
|
|
212
|
+
this.write(` ${color(name, exports.ansi.green)}${desc}\n`);
|
|
213
|
+
}
|
|
214
|
+
this.write('\n');
|
|
215
|
+
}
|
|
216
|
+
/** Render the header/status bar */
|
|
217
|
+
renderHeader() {
|
|
218
|
+
const s = this.status;
|
|
219
|
+
const divider = color('─'.repeat(60), exports.ansi.dim);
|
|
220
|
+
this.write('\n');
|
|
221
|
+
this.write(` ${color(this.opts.title, exports.ansi.bold, exports.ansi.cyan)} ` +
|
|
222
|
+
color(`v${s.version}`, exports.ansi.dim) + '\n');
|
|
223
|
+
this.write(divider + '\n');
|
|
224
|
+
this.write(` Agents: ${color(String(s.agents.active), exports.ansi.green)}/${s.agents.total}` +
|
|
225
|
+
` │ Budget: ${this.budgetColor(s.budget.usedPercent)}` +
|
|
226
|
+
` │ FSM: ${color(s.fsm.state, exports.ansi.yellow)}` +
|
|
227
|
+
(s.pendingApprovals > 0
|
|
228
|
+
? ` │ ${color(`${s.pendingApprovals} pending`, exports.ansi.magenta, exports.ansi.bold)}`
|
|
229
|
+
: '') +
|
|
230
|
+
'\n');
|
|
231
|
+
this.write(divider + '\n');
|
|
232
|
+
}
|
|
233
|
+
// ------- Internals -------
|
|
234
|
+
write(text) {
|
|
235
|
+
const out = this.opts.output;
|
|
236
|
+
out.write(text);
|
|
237
|
+
}
|
|
238
|
+
renderPrompt() {
|
|
239
|
+
if (this.rl) {
|
|
240
|
+
this.rl.prompt();
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
writeFeedEntry(entry) {
|
|
244
|
+
const time = color(`[${entry.time}]`, exports.ansi.dim);
|
|
245
|
+
this.write(`\r${exports.ansi.clearLine} ${time} ${entry.icon} ${entry.message}\n`);
|
|
246
|
+
}
|
|
247
|
+
budgetColor(pct) {
|
|
248
|
+
const text = `${pct}%`;
|
|
249
|
+
if (pct >= 80)
|
|
250
|
+
return color(text, exports.ansi.red, exports.ansi.bold);
|
|
251
|
+
if (pct >= 50)
|
|
252
|
+
return color(text, exports.ansi.yellow);
|
|
253
|
+
return color(text, exports.ansi.green);
|
|
254
|
+
}
|
|
255
|
+
async handleInput(input) {
|
|
256
|
+
const parts = input.split(/\s+/);
|
|
257
|
+
const cmd = parts[0].toLowerCase();
|
|
258
|
+
const args = parts.slice(1).join(' ');
|
|
259
|
+
const handler = this.commands.get(cmd);
|
|
260
|
+
if (!handler) {
|
|
261
|
+
this.write(color(` Unknown command: ${cmd}. Type 'help' for available commands.\n`, exports.ansi.red));
|
|
262
|
+
this.emit('unknown-command', cmd, args);
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
try {
|
|
266
|
+
await handler.handler(args, this);
|
|
267
|
+
}
|
|
268
|
+
catch (err) {
|
|
269
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
270
|
+
this.write(color(` Error: ${msg}\n`, exports.ansi.red));
|
|
271
|
+
}
|
|
272
|
+
this.emit('command', cmd, args);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
exports.ConsoleUI = ConsoleUI;
|
|
276
|
+
//# sourceMappingURL=console-ui.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"console-ui.js","sourceRoot":"","sources":["../../lib/console-ui.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;;AAEH,uCAA2E;AAC3E,mCAAsC;AAEtC,+EAA+E;AAC/E,eAAe;AACf,+EAA+E;AAE/E,MAAM,GAAG,GAAG,OAAO,CAAC;AAEpB,6BAA6B;AAChB,QAAA,IAAI,GAAG;IAClB,KAAK,EAAE,GAAG,GAAG,IAAI;IACjB,IAAI,EAAE,GAAG,GAAG,IAAI;IAChB,GAAG,EAAE,GAAG,GAAG,IAAI;IACf,MAAM,EAAE,GAAG,GAAG,IAAI;IAClB,SAAS,EAAE,GAAG,GAAG,IAAI;IAErB,aAAa;IACb,KAAK,EAAE,GAAG,GAAG,KAAK;IAClB,GAAG,EAAE,GAAG,GAAG,KAAK;IAChB,KAAK,EAAE,GAAG,GAAG,KAAK;IAClB,MAAM,EAAE,GAAG,GAAG,KAAK;IACnB,IAAI,EAAE,GAAG,GAAG,KAAK;IACjB,OAAO,EAAE,GAAG,GAA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,IAAI,CAAC,CAAC;IAClC,CAAC;CACF;AA7ND,8BA6NC"}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Goal Decomposer — LLM-powered goal → task DAG → parallel execution
|
|
3
|
+
*
|
|
4
|
+
* Provides the `runTeam()` one-liner: describe a goal in plain English,
|
|
5
|
+
* specify which agents to use, and let an LLM plan the task graph.
|
|
6
|
+
* Execution respects all Network-AI guardrails (budgets, permissions, audit).
|
|
7
|
+
*
|
|
8
|
+
* Zero external dependencies — LLM calls go through the adapter system.
|
|
9
|
+
*
|
|
10
|
+
* @module GoalDecomposer
|
|
11
|
+
* @version 1.0.0
|
|
12
|
+
*/
|
|
13
|
+
import { EventEmitter } from 'events';
|
|
14
|
+
import type { AgentPayload, AgentContext, AgentResult } from '../types/agent-adapter';
|
|
15
|
+
/** A single node in the task DAG */
|
|
16
|
+
export interface TaskNode {
|
|
17
|
+
/** Unique task identifier */
|
|
18
|
+
id: string;
|
|
19
|
+
/** Human-readable description of the task */
|
|
20
|
+
description: string;
|
|
21
|
+
/** Agent ID (or pool/template) to execute this task */
|
|
22
|
+
agent: string;
|
|
23
|
+
/** Action to invoke on the agent */
|
|
24
|
+
action: string;
|
|
25
|
+
/** Parameters for the action */
|
|
26
|
+
params: Record<string, unknown>;
|
|
27
|
+
/** IDs of tasks that must complete before this one starts */
|
|
28
|
+
dependencies: string[];
|
|
29
|
+
/** Priority (higher = more urgent) */
|
|
30
|
+
priority: number;
|
|
31
|
+
/** Execution status */
|
|
32
|
+
status: 'pending' | 'running' | 'completed' | 'failed' | 'skipped';
|
|
33
|
+
/** Result after execution */
|
|
34
|
+
result?: AgentResult;
|
|
35
|
+
/** Error message if failed */
|
|
36
|
+
error?: string;
|
|
37
|
+
/** Timestamps */
|
|
38
|
+
startedAt?: number;
|
|
39
|
+
completedAt?: number;
|
|
40
|
+
}
|
|
41
|
+
/** Directed acyclic graph of tasks */
|
|
42
|
+
export interface TaskDAG {
|
|
43
|
+
/** The original goal */
|
|
44
|
+
goal: string;
|
|
45
|
+
/** All task nodes */
|
|
46
|
+
nodes: TaskNode[];
|
|
47
|
+
/** Adjacency list: taskId → downstream task IDs */
|
|
48
|
+
edges: Map<string, string[]>;
|
|
49
|
+
/** When the DAG was created */
|
|
50
|
+
createdAt: number;
|
|
51
|
+
}
|
|
52
|
+
/** Configuration for an agent available to the team */
|
|
53
|
+
export interface TeamAgent {
|
|
54
|
+
/** Agent ID (must match an adapter-registered agent or be resolvable by the executor) */
|
|
55
|
+
id: string;
|
|
56
|
+
/** What this agent can do (fed to LLM for planning) */
|
|
57
|
+
role: string;
|
|
58
|
+
/** Which adapter handles this agent */
|
|
59
|
+
adapter?: string;
|
|
60
|
+
/** Default action to invoke */
|
|
61
|
+
defaultAction?: string;
|
|
62
|
+
/** Default parameters */
|
|
63
|
+
defaultParams?: Record<string, unknown>;
|
|
64
|
+
}
|
|
65
|
+
/** Function that invokes an LLM to produce a decomposition plan */
|
|
66
|
+
export type PlannerFunction = (goal: string, agents: TeamAgent[], context?: Record<string, unknown>) => Promise<PlannedTask[]>;
|
|
67
|
+
/** Output from the planner (LLM-generated) */
|
|
68
|
+
export interface PlannedTask {
|
|
69
|
+
id: string;
|
|
70
|
+
description: string;
|
|
71
|
+
agent: string;
|
|
72
|
+
action: string;
|
|
73
|
+
params: Record<string, unknown>;
|
|
74
|
+
dependencies: string[];
|
|
75
|
+
priority?: number;
|
|
76
|
+
}
|
|
77
|
+
/** Function that executes a single task via the adapter system */
|
|
78
|
+
export type ExecutorFunction = (agentId: string, payload: AgentPayload, context: AgentContext) => Promise<AgentResult>;
|
|
79
|
+
/** Options for `runTeam` */
|
|
80
|
+
export interface RunTeamOptions {
|
|
81
|
+
/** Maximum number of tasks to run in parallel (default: 5) */
|
|
82
|
+
concurrency?: number;
|
|
83
|
+
/** Timeout per task in ms (default: 30000) */
|
|
84
|
+
taskTimeout?: number;
|
|
85
|
+
/** Timeout for the entire run in ms (default: 300000) */
|
|
86
|
+
totalTimeout?: number;
|
|
87
|
+
/** Whether to continue executing tasks after one fails (default: false) */
|
|
88
|
+
continueOnFailure?: boolean;
|
|
89
|
+
/** Session ID for context propagation */
|
|
90
|
+
sessionId?: string;
|
|
91
|
+
/** Arbitrary metadata passed to agent contexts */
|
|
92
|
+
metadata?: Record<string, unknown>;
|
|
93
|
+
/** Maximum LLM retries for planning (default: 1) */
|
|
94
|
+
plannerRetries?: number;
|
|
95
|
+
/** Callback for approval before execution starts */
|
|
96
|
+
approvalCallback?: (dag: TaskDAG) => Promise<boolean>;
|
|
97
|
+
}
|
|
98
|
+
/** Final result from a team run */
|
|
99
|
+
export interface TeamResult {
|
|
100
|
+
/** Whether the overall goal was achieved */
|
|
101
|
+
success: boolean;
|
|
102
|
+
/** The task graph that was executed */
|
|
103
|
+
dag: TaskDAG;
|
|
104
|
+
/** Aggregated results from all completed tasks */
|
|
105
|
+
results: Map<string, AgentResult>;
|
|
106
|
+
/** Summary of what happened */
|
|
107
|
+
summary: string;
|
|
108
|
+
/** Total execution time in ms */
|
|
109
|
+
durationMs: number;
|
|
110
|
+
/** Count of tasks by status */
|
|
111
|
+
stats: {
|
|
112
|
+
total: number;
|
|
113
|
+
completed: number;
|
|
114
|
+
failed: number;
|
|
115
|
+
skipped: number;
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
/** Events emitted during a team run */
|
|
119
|
+
export interface TeamRunnerEvents {
|
|
120
|
+
'dag:created': (dag: TaskDAG) => void;
|
|
121
|
+
'task:start': (node: TaskNode) => void;
|
|
122
|
+
'task:complete': (node: TaskNode, result: AgentResult) => void;
|
|
123
|
+
'task:fail': (node: TaskNode, error: string) => void;
|
|
124
|
+
'task:skip': (node: TaskNode, reason: string) => void;
|
|
125
|
+
'run:complete': (result: TeamResult) => void;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Validate that a set of planned tasks forms a valid DAG (no cycles, valid refs).
|
|
129
|
+
* @throws Error if the graph contains cycles or invalid dependency references
|
|
130
|
+
*/
|
|
131
|
+
export declare function validateDAG(tasks: PlannedTask[]): void;
|
|
132
|
+
/**
|
|
133
|
+
* Compute topological layers — tasks in the same layer can execute in parallel.
|
|
134
|
+
* Returns arrays of task IDs grouped by execution layer.
|
|
135
|
+
*/
|
|
136
|
+
export declare function topologicalLayers(tasks: PlannedTask[]): string[][];
|
|
137
|
+
/**
|
|
138
|
+
* Create a planner function that uses an LLM (via executor) to decompose goals.
|
|
139
|
+
*
|
|
140
|
+
* The planner sends a structured prompt to the specified agent and parses
|
|
141
|
+
* the JSON response into PlannedTask[]. Falls back gracefully on parse errors.
|
|
142
|
+
*
|
|
143
|
+
* @param executor - Function to call the LLM agent
|
|
144
|
+
* @param plannerAgent - Agent ID for the LLM that does planning
|
|
145
|
+
* @param plannerAdapter - Adapter name (optional, defaults to agent's adapter)
|
|
146
|
+
*/
|
|
147
|
+
export declare function createLLMPlanner(executor: ExecutorFunction, plannerAgent: string): PlannerFunction;
|
|
148
|
+
/**
|
|
149
|
+
* Parse JSON from an LLM response string, handling markdown fences and preamble.
|
|
150
|
+
*/
|
|
151
|
+
export declare function parsePlanJSON(text: string): PlannedTask[];
|
|
152
|
+
/**
|
|
153
|
+
* LLM-powered goal decomposition engine.
|
|
154
|
+
*
|
|
155
|
+
* Takes a natural language goal, creates a task DAG via an LLM planner,
|
|
156
|
+
* validates the graph, and returns a ready-to-execute TaskDAG.
|
|
157
|
+
*/
|
|
158
|
+
export declare class GoalDecomposer {
|
|
159
|
+
private planner;
|
|
160
|
+
constructor(planner: PlannerFunction);
|
|
161
|
+
/**
|
|
162
|
+
* Decompose a goal into a validated TaskDAG.
|
|
163
|
+
* @param goal - Natural language description of the goal
|
|
164
|
+
* @param agents - Available team agents
|
|
165
|
+
* @param context - Optional context to feed to the planner
|
|
166
|
+
* @param retries - Number of retries on planning failure (default: 1)
|
|
167
|
+
*/
|
|
168
|
+
decompose(goal: string, agents: TeamAgent[], context?: Record<string, unknown>, retries?: number): Promise<TaskDAG>;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Executes a TaskDAG by running tasks in parallel layers, respecting
|
|
172
|
+
* dependencies, concurrency limits, and timeouts.
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```typescript
|
|
176
|
+
* const runner = new TeamRunner(executor);
|
|
177
|
+
* const result = await runner.run(dag, { concurrency: 3 });
|
|
178
|
+
* console.log(result.summary);
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
181
|
+
export declare class TeamRunner extends EventEmitter {
|
|
182
|
+
private executor;
|
|
183
|
+
constructor(executor: ExecutorFunction);
|
|
184
|
+
/**
|
|
185
|
+
* Execute a TaskDAG with parallel scheduling.
|
|
186
|
+
*/
|
|
187
|
+
run(dag: TaskDAG, options?: RunTeamOptions): Promise<TeamResult>;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Decompose a goal into tasks and execute them with a team of agents.
|
|
191
|
+
*
|
|
192
|
+
* This is the main entry point — one line to go from goal to results:
|
|
193
|
+
*
|
|
194
|
+
* ```typescript
|
|
195
|
+
* const result = await runTeam(
|
|
196
|
+
* "Build a REST API for user management",
|
|
197
|
+
* [
|
|
198
|
+
* { id: "architect", role: "System design and API specification" },
|
|
199
|
+
* { id: "coder", role: "Write TypeScript code" },
|
|
200
|
+
* { id: "reviewer", role: "Code review and quality checks" },
|
|
201
|
+
* ],
|
|
202
|
+
* { planner, executor }
|
|
203
|
+
* );
|
|
204
|
+
* ```
|
|
205
|
+
*
|
|
206
|
+
* @param goal - Natural language description of what to achieve
|
|
207
|
+
* @param agents - Team of agents available for task execution
|
|
208
|
+
* @param config - Planner (LLM decomposition) and executor (agent invocation) functions
|
|
209
|
+
* @param options - Optional concurrency, timeout, and failure handling settings
|
|
210
|
+
* @returns Full result with DAG, individual results, and stats
|
|
211
|
+
*/
|
|
212
|
+
export declare function runTeam(goal: string, agents: TeamAgent[], config: {
|
|
213
|
+
planner: PlannerFunction;
|
|
214
|
+
executor: ExecutorFunction;
|
|
215
|
+
}, options?: RunTeamOptions): Promise<TeamResult>;
|
|
216
|
+
//# sourceMappingURL=goal-decomposer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"goal-decomposer.d.ts","sourceRoot":"","sources":["../../lib/goal-decomposer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAMtF,oCAAoC;AACpC,MAAM,WAAW,QAAQ;IACvB,6BAA6B;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,6CAA6C;IAC7C,WAAW,EAAE,MAAM,CAAC;IACpB,uDAAuD;IACvD,KAAK,EAAE,MAAM,CAAC;IACd,oCAAoC;IACpC,MAAM,EAAE,MAAM,CAAC;IACf,gCAAgC;IAChC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,6DAA6D;IAC7D,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,sCAAsC;IACtC,QAAQ,EAAE,MAAM,CAAC;IACjB,uBAAuB;IACvB,MAAM,EAAE,SAAS,GAAG,SAAS,GAAG,WAAW,GAAG,QAAQ,GAAG,SAAS,CAAC;IACnE,6BAA6B;IAC7B,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,8BAA8B;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,iBAAiB;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,sCAAsC;AACtC,MAAM,WAAW,OAAO;IACtB,wBAAwB;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,qBAAqB;IACrB,KAAK,EAAE,QAAQ,EAAE,CAAC;IAClB,mDAAmD;IACnD,KAAK,EAAE,GAAG,CAAC,MAAM,EA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