niahere 0.2.46 → 0.2.47
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/package.json +1 -1
- package/src/core/consolidator.ts +5 -12
- package/src/core/runner.ts +50 -6
- package/src/core/summarizer.ts +3 -6
package/package.json
CHANGED
package/src/core/consolidator.ts
CHANGED
|
@@ -18,10 +18,8 @@
|
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
20
|
import { Message } from "../db/models";
|
|
21
|
-
import {
|
|
22
|
-
import { runJobWithClaude } from "./runner";
|
|
21
|
+
import { runTask } from "./runner";
|
|
23
22
|
import { log } from "../utils/log";
|
|
24
|
-
import { homedir } from "os";
|
|
25
23
|
import type { SessionMessage } from "../types";
|
|
26
24
|
|
|
27
25
|
/** Track sessions already consolidated to prevent double runs. */
|
|
@@ -83,15 +81,10 @@ Do NOT message the user about this. Save silently and report a brief summary of
|
|
|
83
81
|
|
|
84
82
|
/** Run the consolidation agent loop. */
|
|
85
83
|
async function runConsolidation(transcript: string, source: string): Promise<void> {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
if (output.error) {
|
|
91
|
-
log.error({ source, error: output.error }, "consolidator: extraction failed");
|
|
92
|
-
} else {
|
|
93
|
-
log.info({ source, resultChars: output.agentText.length }, "consolidator: done");
|
|
94
|
-
}
|
|
84
|
+
await runTask({
|
|
85
|
+
name: "consolidator",
|
|
86
|
+
prompt: buildConsolidationPrompt(transcript, source),
|
|
87
|
+
});
|
|
95
88
|
}
|
|
96
89
|
|
|
97
90
|
/**
|
package/src/core/runner.ts
CHANGED
|
@@ -9,6 +9,9 @@ import { getConfig } from "../utils/config";
|
|
|
9
9
|
import { buildSystemPrompt } from "../chat/identity";
|
|
10
10
|
import { scanAgents } from "./agents";
|
|
11
11
|
import { truncate, formatToolUse } from "../utils/format-activity";
|
|
12
|
+
import { getMcpServers } from "../mcp";
|
|
13
|
+
import { ActiveEngine } from "../db/models";
|
|
14
|
+
import { log } from "../utils/log";
|
|
12
15
|
|
|
13
16
|
export type ActivityCallback = (line: string) => void;
|
|
14
17
|
|
|
@@ -87,14 +90,21 @@ export async function runJobWithClaude(
|
|
|
87
90
|
};
|
|
88
91
|
}
|
|
89
92
|
|
|
93
|
+
const options: Record<string, unknown> = {
|
|
94
|
+
systemPrompt,
|
|
95
|
+
cwd,
|
|
96
|
+
permissionMode: "bypassPermissions",
|
|
97
|
+
sessionId,
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const mcpServers = getMcpServers();
|
|
101
|
+
if (mcpServers) {
|
|
102
|
+
options.mcpServers = mcpServers;
|
|
103
|
+
}
|
|
104
|
+
|
|
90
105
|
const handle = query({
|
|
91
106
|
prompt: singleMessage() as any,
|
|
92
|
-
options:
|
|
93
|
-
systemPrompt,
|
|
94
|
-
cwd,
|
|
95
|
-
permissionMode: "bypassPermissions",
|
|
96
|
-
sessionId,
|
|
97
|
-
} as any,
|
|
107
|
+
options: options as any,
|
|
98
108
|
});
|
|
99
109
|
|
|
100
110
|
let agentText = "";
|
|
@@ -178,6 +188,40 @@ export async function runJobWithClaude(
|
|
|
178
188
|
return { agentText, sessionId: actualSessionId };
|
|
179
189
|
}
|
|
180
190
|
|
|
191
|
+
// ---------------------------------------------------------------------------
|
|
192
|
+
// Background task runner — tracked one-shot agent with full Nia personality
|
|
193
|
+
// ---------------------------------------------------------------------------
|
|
194
|
+
|
|
195
|
+
export interface TaskOptions {
|
|
196
|
+
/** Task name — used for ActiveEngine tracking as _system/{name}. */
|
|
197
|
+
name: string;
|
|
198
|
+
/** The prompt/instruction for the task. */
|
|
199
|
+
prompt: string;
|
|
200
|
+
/** System prompt override. Defaults to buildSystemPrompt("job"). */
|
|
201
|
+
systemPrompt?: string;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Run a background agent task with ActiveEngine tracking and MCP tools.
|
|
206
|
+
* Use for consolidator, summarizer, and any future background work.
|
|
207
|
+
*/
|
|
208
|
+
export async function runTask(opts: TaskOptions): Promise<RunnerOutput> {
|
|
209
|
+
const room = `_system/${opts.name}`;
|
|
210
|
+
await ActiveEngine.register(room, "system").catch(() => {});
|
|
211
|
+
try {
|
|
212
|
+
const systemPrompt = opts.systemPrompt || buildSystemPrompt("job");
|
|
213
|
+
const output = await runJobWithClaude(systemPrompt, opts.prompt, homedir());
|
|
214
|
+
if (output.error) {
|
|
215
|
+
log.error({ task: opts.name, error: output.error }, "task failed");
|
|
216
|
+
} else {
|
|
217
|
+
log.info({ task: opts.name, resultChars: output.agentText.length }, "task completed");
|
|
218
|
+
}
|
|
219
|
+
return output;
|
|
220
|
+
} finally {
|
|
221
|
+
await ActiveEngine.unregister(room).catch(() => {});
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
181
225
|
// ---------------------------------------------------------------------------
|
|
182
226
|
// Public API
|
|
183
227
|
// ---------------------------------------------------------------------------
|
package/src/core/summarizer.ts
CHANGED
|
@@ -11,10 +11,8 @@
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import { Message, Session } from "../db/models";
|
|
14
|
-
import {
|
|
15
|
-
import { runJobWithClaude } from "./runner";
|
|
14
|
+
import { runTask } from "./runner";
|
|
16
15
|
import { log } from "../utils/log";
|
|
17
|
-
import { homedir } from "os";
|
|
18
16
|
import type { SessionMessage } from "../types";
|
|
19
17
|
|
|
20
18
|
/** Track sessions already summarized to prevent double runs. */
|
|
@@ -46,10 +44,9 @@ export async function summarizeSession(sessionId: string, room: string): Promise
|
|
|
46
44
|
|
|
47
45
|
log.info({ sessionId, room, messageCount: messages.length }, "summarizer: generating session summary");
|
|
48
46
|
|
|
49
|
-
const systemPrompt = buildSystemPrompt("job");
|
|
50
47
|
const transcript = formatTranscript(messages);
|
|
51
48
|
|
|
52
|
-
const
|
|
49
|
+
const prompt = `Job: session-summary (triggered by session idle in ${room})
|
|
53
50
|
|
|
54
51
|
Generate a brief session summary. This will be shown to your future self at the start of the next session for continuity.
|
|
55
52
|
|
|
@@ -64,7 +61,7 @@ Write a 2-4 sentence summary covering:
|
|
|
64
61
|
|
|
65
62
|
Keep it concise — a handoff note, not a report. Output ONLY the summary text.`;
|
|
66
63
|
|
|
67
|
-
const output = await
|
|
64
|
+
const output = await runTask({ name: "summarizer", prompt });
|
|
68
65
|
|
|
69
66
|
if (output.error) {
|
|
70
67
|
log.error({ sessionId, room, error: output.error }, "summarizer: failed");
|