@inceptionstack/roundhouse 0.5.12 → 0.5.13
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/gateway/gateway.ts +5 -0
- package/src/gateway/later-command.ts +1 -1
- package/src/gateway/model-command.ts +2 -1
- package/src/gateway/persona-inject.ts +94 -0
- package/src/gateway/soul.md +35 -0
- package/src/gateway/tools.md +2 -0
- package/src/gateway/user.md +10 -0
- package/src/provisioning/bundle.ts +2 -0
package/package.json
CHANGED
package/src/gateway/gateway.ts
CHANGED
|
@@ -30,6 +30,7 @@ import type { TransportAdapter } from "../transports";
|
|
|
30
30
|
import { hostname } from "node:os";
|
|
31
31
|
import { join } from "node:path";
|
|
32
32
|
import { injectToolsSection } from "./tools-inject";
|
|
33
|
+
import { injectPersonaSection, loadPersona } from "./persona-inject";
|
|
33
34
|
|
|
34
35
|
/** Bot username for command suffix validation (set during gateway init) */
|
|
35
36
|
let _botUsername = "";
|
|
@@ -327,6 +328,9 @@ export class Gateway {
|
|
|
327
328
|
await handleOrAbort(thread, message);
|
|
328
329
|
});
|
|
329
330
|
|
|
331
|
+
// ── Load persona files at startup (cached for process lifetime) ───
|
|
332
|
+
loadPersona();
|
|
333
|
+
|
|
330
334
|
// ── Handle inline keyboard callbacks ───
|
|
331
335
|
this.chat.onAction(MODEL_ACTION_ID, async (event: any) => {
|
|
332
336
|
await handleModelAction({ value: event.value, thread: event.thread });
|
|
@@ -408,6 +412,7 @@ export class Gateway {
|
|
|
408
412
|
|
|
409
413
|
// Inject tools section (after STT enrichment so voice-only messages get it too)
|
|
410
414
|
if (agentMessage.text) {
|
|
415
|
+
agentMessage.text = injectPersonaSection(agentMessage.text);
|
|
411
416
|
agentMessage.text = injectToolsSection(agentMessage.text);
|
|
412
417
|
}
|
|
413
418
|
|
|
@@ -33,7 +33,7 @@ function ensureLaterFile(): void {
|
|
|
33
33
|
|
|
34
34
|
export async function handleLater(ctx: LaterCommandContext): Promise<void> {
|
|
35
35
|
const { thread, text, postWithFallback } = ctx;
|
|
36
|
-
const idea = text.replace(/^\/later
|
|
36
|
+
const idea = text.replace(/^\/later(@\S+)?\s*/i, "").trim();
|
|
37
37
|
|
|
38
38
|
// No argument: show contents
|
|
39
39
|
if (!idea) {
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
import { homedir } from "node:os";
|
|
12
12
|
import { join } from "node:path";
|
|
13
|
-
import { readFileSync, writeFileSync } from "node:fs";
|
|
13
|
+
import { readFileSync, writeFileSync, mkdirSync } from "node:fs";
|
|
14
14
|
|
|
15
15
|
/** Known model aliases → Bedrock model IDs */
|
|
16
16
|
export const MODEL_ALIASES: Record<string, { provider: string; model: string; label: string }> = {
|
|
@@ -58,6 +58,7 @@ function readSettings(): Record<string, any> {
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
function writeSettings(settings: Record<string, any>): void {
|
|
61
|
+
mkdirSync(join(homedir(), ".pi", "agent"), { recursive: true });
|
|
61
62
|
writeFileSync(SETTINGS_PATH, JSON.stringify(settings, null, 2) + "\n");
|
|
62
63
|
}
|
|
63
64
|
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* gateway/persona-inject.ts — Inject <persona> section into agent prompts
|
|
3
|
+
*
|
|
4
|
+
* Reads user.md and soul.md (user-customized or bundled defaults) and
|
|
5
|
+
* prepends them as a structured section so the agent has identity and
|
|
6
|
+
* user context on every turn.
|
|
7
|
+
*
|
|
8
|
+
* Cached with mtime-based invalidation: stat() on each turn (~0.1ms),
|
|
9
|
+
* only re-reads if files have been modified since last load.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { readFileSync, statSync } from "node:fs";
|
|
13
|
+
import { join, dirname } from "node:path";
|
|
14
|
+
import { fileURLToPath } from "node:url";
|
|
15
|
+
import { ROUNDHOUSE_DIR } from "../config";
|
|
16
|
+
|
|
17
|
+
let cachedPersona: string | null = null;
|
|
18
|
+
let lastMtime = 0;
|
|
19
|
+
|
|
20
|
+
const SOUL_PATH = join(ROUNDHOUSE_DIR, "soul.md");
|
|
21
|
+
const USER_PATH = join(ROUNDHOUSE_DIR, "user.md");
|
|
22
|
+
|
|
23
|
+
function getMaxMtime(): number {
|
|
24
|
+
let max = 0;
|
|
25
|
+
try { max = Math.max(max, statSync(SOUL_PATH).mtimeMs); } catch {}
|
|
26
|
+
try { max = Math.max(max, statSync(USER_PATH).mtimeMs); } catch {}
|
|
27
|
+
return max;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function loadFile(filename: string): string {
|
|
31
|
+
const userPath = join(ROUNDHOUSE_DIR, filename);
|
|
32
|
+
const bundledPath = join(dirname(fileURLToPath(import.meta.url)), filename);
|
|
33
|
+
|
|
34
|
+
try {
|
|
35
|
+
return readFileSync(userPath, "utf8");
|
|
36
|
+
} catch {
|
|
37
|
+
try {
|
|
38
|
+
return readFileSync(bundledPath, "utf8");
|
|
39
|
+
} catch {
|
|
40
|
+
return "";
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function buildPersona(): string {
|
|
46
|
+
const soul = loadFile("soul.md").trim();
|
|
47
|
+
const user = loadFile("user.md").trim();
|
|
48
|
+
|
|
49
|
+
if (!soul && !user) return "";
|
|
50
|
+
|
|
51
|
+
const parts: string[] = [];
|
|
52
|
+
if (soul) parts.push(soul);
|
|
53
|
+
if (user) parts.push(user);
|
|
54
|
+
return parts.join("\n\n---\n\n");
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Load persona files and cache the result.
|
|
59
|
+
* Call at gateway startup to eagerly load.
|
|
60
|
+
*/
|
|
61
|
+
export function loadPersona(): void {
|
|
62
|
+
cachedPersona = buildPersona();
|
|
63
|
+
lastMtime = getMaxMtime();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Reload persona from disk. Call after agent edits user.md/soul.md
|
|
68
|
+
* (e.g. from an IPC handler or post-tool-execution hook).
|
|
69
|
+
*/
|
|
70
|
+
export function reloadPersona(): void {
|
|
71
|
+
cachedPersona = buildPersona();
|
|
72
|
+
lastMtime = getMaxMtime();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Prepend a <persona> section to the prompt text.
|
|
77
|
+
* Only injects if soul.md or user.md have content.
|
|
78
|
+
* Auto-reloads if files have been modified since last load.
|
|
79
|
+
*/
|
|
80
|
+
export function injectPersonaSection(text: string): string {
|
|
81
|
+
if (cachedPersona === null) {
|
|
82
|
+
loadPersona();
|
|
83
|
+
} else {
|
|
84
|
+
// Cheap mtime check — auto-reload if agent edited the files
|
|
85
|
+
const currentMtime = getMaxMtime();
|
|
86
|
+
if (currentMtime !== lastMtime) {
|
|
87
|
+
reloadPersona();
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (!cachedPersona) return text;
|
|
91
|
+
// Escape any literal </persona> in content to prevent XML injection
|
|
92
|
+
const safe = cachedPersona.replace(/<\/persona>/gi, "</persona>");
|
|
93
|
+
return `<persona>\n${safe}\n</persona>\n\n${text}`;
|
|
94
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Who You Are
|
|
2
|
+
|
|
3
|
+
_You're not a chatbot. You're a technical partner._
|
|
4
|
+
|
|
5
|
+
## Core Identity
|
|
6
|
+
|
|
7
|
+
**Name:** Loki
|
|
8
|
+
**Role:** Senior engineer and ops partner. You help build, deploy, debug, and maintain software and infrastructure. You have opinions and you share them.
|
|
9
|
+
|
|
10
|
+
## Core Truths
|
|
11
|
+
|
|
12
|
+
**Be genuinely helpful, not performatively helpful.** Skip the filler — just help. Actions speak louder than words.
|
|
13
|
+
|
|
14
|
+
**Have opinions.** When something is a bad pattern, say so. When there's a better approach, recommend it. You're not a yes-machine.
|
|
15
|
+
|
|
16
|
+
**Be resourceful before asking.** Check the docs. Read the file. Try things. _Then_ ask if you're stuck.
|
|
17
|
+
|
|
18
|
+
**Earn trust through competence.** You have access to tools, shell, and infrastructure. Use them wisely. Be careful with destructive operations. Be bold with read operations.
|
|
19
|
+
|
|
20
|
+
**Think holistically.** Consider the broader context — architecture, maintainability, security, user experience.
|
|
21
|
+
|
|
22
|
+
## Boundaries
|
|
23
|
+
|
|
24
|
+
- Ask before destructive operations (deletions, config changes with blast radius)
|
|
25
|
+
- Read freely — list, describe, get operations are safe
|
|
26
|
+
- Private things stay private
|
|
27
|
+
- Never send half-baked replies
|
|
28
|
+
|
|
29
|
+
## Vibe
|
|
30
|
+
|
|
31
|
+
Direct, technical, concise. Think senior engineer talking to senior engineer. Thorough when it matters, brief when it doesn't. No corporate speak.
|
|
32
|
+
|
|
33
|
+
## Continuity
|
|
34
|
+
|
|
35
|
+
Each session, you wake up fresh. Your workspace files _are_ your memory. Read them. Update them.
|
package/src/gateway/tools.md
CHANGED
|
@@ -10,6 +10,8 @@ Do NOT create files directly in `~/` or pollute the home directory. Use subdirec
|
|
|
10
10
|
- `~/.roundhouse/workspace/later.md` — ideas saved via `/later`
|
|
11
11
|
- `~/.roundhouse/workspace/<project>/` — project-specific files if needed
|
|
12
12
|
|
|
13
|
+
> 💡 When looking for things to work on, check `~/.roundhouse/workspace/later.md` for saved ideas and tasks.
|
|
14
|
+
|
|
13
15
|
## roundhouse cron add
|
|
14
16
|
|
|
15
17
|
Schedule recurring or one-shot jobs. The user may ask you to "remind me", "check every X", "do Y later", or "schedule Z".
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# About Your Human
|
|
2
|
+
|
|
3
|
+
- **Name:** (not yet set)
|
|
4
|
+
- **What to call them:** (use their Telegram username until they tell you otherwise)
|
|
5
|
+
- **Timezone:** UTC
|
|
6
|
+
- **Notes:** (learn about them through conversation)
|
|
7
|
+
|
|
8
|
+
## Preferences
|
|
9
|
+
|
|
10
|
+
- (Will be filled in as you learn what they prefer)
|
|
@@ -320,6 +320,8 @@ export function provisionWorkspaceFiles(opts: ProvisionOpts = {}): void {
|
|
|
320
320
|
// Files to provision: [bundled filename, target filename]
|
|
321
321
|
const files: [string, string][] = [
|
|
322
322
|
["tools.md", "tools.md"],
|
|
323
|
+
["soul.md", "soul.md"],
|
|
324
|
+
["user.md", "user.md"],
|
|
323
325
|
];
|
|
324
326
|
|
|
325
327
|
try {
|