blun-king-cli 9.1.253 → 9.1.255
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/bin/identity-context-policy.cjs +87 -0
- package/bin/natural-presence-policy.cjs +13 -0
- package/blun.mjs +6 -3
- package/package.json +1 -1
|
@@ -7,11 +7,17 @@ const DEFAULT_MAX_CHARS = 1800;
|
|
|
7
7
|
const MIN_MAX_CHARS = 512;
|
|
8
8
|
const HARD_MAX_CHARS = 2800;
|
|
9
9
|
const SAFE_ID_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/u;
|
|
10
|
+
const TELEGRAM_SUBJECT_RE = /^\d{1,32}$/u;
|
|
11
|
+
const TELEGRAM_CHAT_RE = /^-?\d{1,32}$/u;
|
|
10
12
|
|
|
11
13
|
function enabled(env) {
|
|
12
14
|
return /^(?:1|true)$/iu.test(String(env.BLUN_IDENTITY_CONTEXT ?? '').trim());
|
|
13
15
|
}
|
|
14
16
|
|
|
17
|
+
function autoGraphEnabled(env) {
|
|
18
|
+
return /^(?:1|true)$/iu.test(String(env.BLUN_IDENTITY_AUTO_GRAPH ?? '').trim());
|
|
19
|
+
}
|
|
20
|
+
|
|
15
21
|
function safeId(value) {
|
|
16
22
|
const normalized = String(value ?? '').trim();
|
|
17
23
|
return SAFE_ID_RE.test(normalized) ? normalized : '';
|
|
@@ -55,6 +61,27 @@ function readJson(root, segments) {
|
|
|
55
61
|
}
|
|
56
62
|
}
|
|
57
63
|
|
|
64
|
+
function createJsonOnce(root, segments, value) {
|
|
65
|
+
const target = path.resolve(root, ...segments);
|
|
66
|
+
if (!isInside(root, target)) return false;
|
|
67
|
+
let handle;
|
|
68
|
+
try {
|
|
69
|
+
const parent = path.dirname(target);
|
|
70
|
+
fs.mkdirSync(parent, { recursive: true });
|
|
71
|
+
const realParent = fs.realpathSync(parent);
|
|
72
|
+
if (!isInside(root, realParent)) return false;
|
|
73
|
+
handle = fs.openSync(target, 'wx', 0o600);
|
|
74
|
+
fs.writeFileSync(handle, `${JSON.stringify(value, null, 2)}\n`, 'utf8');
|
|
75
|
+
fs.fsyncSync(handle);
|
|
76
|
+
return true;
|
|
77
|
+
} catch (error) {
|
|
78
|
+
if (error?.code === 'EEXIST') return false;
|
|
79
|
+
return false;
|
|
80
|
+
} finally {
|
|
81
|
+
if (handle !== undefined) fs.closeSync(handle);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
58
85
|
function cleanText(value, maxChars = 240) {
|
|
59
86
|
if (typeof value !== 'string') return '';
|
|
60
87
|
return value.replace(/[\u0000-\u001f\u007f]+/gu, ' ').replace(/\s+/gu, ' ').trim().slice(0, maxChars);
|
|
@@ -123,6 +150,65 @@ function truncateBlock(value, limit) {
|
|
|
123
150
|
return `${value.slice(0, Math.max(0, limit - marker.length)).trimEnd()}${marker}`;
|
|
124
151
|
}
|
|
125
152
|
|
|
153
|
+
function trustedTimestamp(value) {
|
|
154
|
+
const text = cleanText(value, 64);
|
|
155
|
+
if (!text || Number.isNaN(Date.parse(text))) return undefined;
|
|
156
|
+
return text;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function recordChannelIdentity(envelope, env = process.env) {
|
|
160
|
+
if (!autoGraphEnabled(env) || envelope?.source !== 'telegram') return undefined;
|
|
161
|
+
const meta = envelope?.meta;
|
|
162
|
+
if (!meta || typeof meta !== 'object') return undefined;
|
|
163
|
+
const subjectId = String(meta.user_id ?? '').trim();
|
|
164
|
+
const chatId = String(meta.chat_id ?? '').trim();
|
|
165
|
+
if (!TELEGRAM_SUBJECT_RE.test(subjectId) || !TELEGRAM_CHAT_RE.test(chatId)) return undefined;
|
|
166
|
+
|
|
167
|
+
const root = resolveRoot(env);
|
|
168
|
+
if (!root) return undefined;
|
|
169
|
+
const manifest = readJson(root, ['manifest.json']);
|
|
170
|
+
const tenantId = safeId(env.BLUN_IDENTITY_TENANT_ID);
|
|
171
|
+
const manifestTenantId = safeId(manifest?.tenant_id);
|
|
172
|
+
const configuredAgentId = safeId(env.BLUN_AGENT_ID);
|
|
173
|
+
const agentId = configuredAgentId || safeId(manifest?.active_agent_id);
|
|
174
|
+
if (!tenantId || tenantId !== manifestTenantId || !agentId || manifest?.version !== 1) return undefined;
|
|
175
|
+
|
|
176
|
+
const actorId = `telegram-${subjectId}`;
|
|
177
|
+
const groupId = chatId.startsWith('-') ? `telegram-chat-${chatId.slice(1)}` : undefined;
|
|
178
|
+
const displayName = cleanText(meta.user, 120) || actorId;
|
|
179
|
+
const firstSeenAt = trustedTimestamp(meta.ts);
|
|
180
|
+
const created = [];
|
|
181
|
+
if (createJsonOnce(root, ['actors', `${actorId}.json`], {
|
|
182
|
+
version: 1,
|
|
183
|
+
actor_id: actorId,
|
|
184
|
+
provider: 'telegram',
|
|
185
|
+
provider_subject_id: subjectId,
|
|
186
|
+
display_name: displayName,
|
|
187
|
+
kind: meta.is_bot === true || String(meta.is_bot ?? '').toLowerCase() === 'true' ? 'agent' : 'person',
|
|
188
|
+
aliases: [],
|
|
189
|
+
...(firstSeenAt ? { first_seen_at: firstSeenAt } : {}),
|
|
190
|
+
})) created.push('actor');
|
|
191
|
+
if (createJsonOnce(root, ['agents', agentId, 'relationships', `${actorId}.json`], {
|
|
192
|
+
version: 1,
|
|
193
|
+
actor_id: actorId,
|
|
194
|
+
status: 'new',
|
|
195
|
+
summary: '',
|
|
196
|
+
confirmed_preferences: [],
|
|
197
|
+
no_gos: [],
|
|
198
|
+
open_threads: [],
|
|
199
|
+
})) created.push('relationship');
|
|
200
|
+
if (groupId && createJsonOnce(root, ['groups', `${groupId}.json`], {
|
|
201
|
+
version: 1,
|
|
202
|
+
group_id: groupId,
|
|
203
|
+
provider: 'telegram',
|
|
204
|
+
provider_chat_id: chatId,
|
|
205
|
+
display_name: groupId,
|
|
206
|
+
purpose: '',
|
|
207
|
+
relevant_roles: [],
|
|
208
|
+
})) created.push('group');
|
|
209
|
+
return { actor_id: actorId, ...(groupId ? { group_id: groupId } : {}), created };
|
|
210
|
+
}
|
|
211
|
+
|
|
126
212
|
function identitySystemBlock(env = process.env) {
|
|
127
213
|
if (!enabled(env)) return '';
|
|
128
214
|
const root = resolveRoot(env);
|
|
@@ -164,4 +250,5 @@ function identitySystemBlock(env = process.env) {
|
|
|
164
250
|
|
|
165
251
|
module.exports = {
|
|
166
252
|
identitySystemBlock,
|
|
253
|
+
recordChannelIdentity,
|
|
167
254
|
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const NATURAL_PRESENCE_BLOCK = `## Natural presence
|
|
4
|
+
|
|
5
|
+
Keep the loaded soul intact and let it shape the voice. Speak like an ongoing teammate, using only real shared context; never invent history or feelings. During active work, the current task and evidence come first. Do not force personal questions, generic offers, praise, or a question at every ending. Silence and a clean ending are valid.`;
|
|
6
|
+
|
|
7
|
+
function naturalPresenceSystemBlock() {
|
|
8
|
+
return NATURAL_PRESENCE_BLOCK;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
module.exports = {
|
|
12
|
+
naturalPresenceSystemBlock,
|
|
13
|
+
};
|
package/blun.mjs
CHANGED
|
@@ -21438,7 +21438,8 @@ var init_list_directory = __esmMin((() => {
|
|
|
21438
21438
|
//#endregion
|
|
21439
21439
|
//#region ../../packages/agent-core/src/profile/context.ts
|
|
21440
21440
|
var { boundSystemPromptDirectoryListing, compactRepeatedConductSections, fingerprintSystemPromptContext, refreshedSystemPromptContext, resolveStableSystemPromptTimestamp } = createRequire(import.meta.url)("./bin/system-prompt-context-policy.cjs");
|
|
21441
|
-
var { identitySystemBlock } = createRequire(import.meta.url)("./bin/identity-context-policy.cjs");
|
|
21441
|
+
var { identitySystemBlock, recordChannelIdentity } = createRequire(import.meta.url)("./bin/identity-context-policy.cjs");
|
|
21442
|
+
var { naturalPresenceSystemBlock } = createRequire(import.meta.url)("./bin/natural-presence-policy.cjs");
|
|
21442
21443
|
async function prepareSystemPromptContext(kaos, brandHome, options) {
|
|
21443
21444
|
const additionalDirs = normalizeAdditionalDirs(options?.additionalDirs ?? []);
|
|
21444
21445
|
const [cwdListing, agentsMdResult, additionalDirsInfo] = await Promise.all([
|
|
@@ -28384,9 +28385,10 @@ function buildTemplateVars(context, promptVars, tools) {
|
|
|
28384
28385
|
const now = context.now instanceof Date ? context.now.toISOString() : context.now ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
28385
28386
|
const roleBase = context.roleAdditional ?? promptVars["ROLE_ADDITIONAL"] ?? promptVars["roleAdditional"] ?? "";
|
|
28386
28387
|
const roleAdditional = [
|
|
28387
|
-
identitySystemBlock(),
|
|
28388
28388
|
personaSystemBlock(),
|
|
28389
28389
|
soulSystemBlock(),
|
|
28390
|
+
identitySystemBlock(),
|
|
28391
|
+
naturalPresenceSystemBlock(),
|
|
28390
28392
|
conductSystemBlock(),
|
|
28391
28393
|
roleBase
|
|
28392
28394
|
].filter((s) => s.length > 0).join("\n\n");
|
|
@@ -265005,7 +265007,7 @@ var init_agent = __esmMin((() => {
|
|
|
265005
265007
|
return base.length === 0 ? this.runtimeSystemPromptAppend : `${base}\n\n${this.runtimeSystemPromptAppend}`;
|
|
265006
265008
|
}
|
|
265007
265009
|
get fastConversationSystemPrompt() {
|
|
265008
|
-
return [
|
|
265010
|
+
return [personaSystemBlock(), soulSystemBlock(), identitySystemBlock(), naturalPresenceSystemBlock(), conductSystemBlock(), `## Fast conversation mode
|
|
265009
265011
|
|
|
265010
265012
|
- Answer the user's current conversational message directly and concisely.
|
|
265011
265013
|
- Use the language of the user's latest message unless the persona specifies a language override.
|
|
@@ -516449,6 +516451,7 @@ var BlunTUI = class {
|
|
|
516449
516451
|
* steers one FIFO head into the active turn without interrupting it.
|
|
516450
516452
|
*/
|
|
516451
516453
|
injectChannelMessage(envelope, acknowledge) {
|
|
516454
|
+
recordChannelIdentity({ source: "telegram", meta: envelope.meta });
|
|
516452
516455
|
const remoteCommand = channelMessageAddressed(envelope) ? telegramRemoteCommand(envelope.text) : void 0;
|
|
516453
516456
|
if (remoteCommand !== void 0) {
|
|
516454
516457
|
this.injectTelegramRemoteCommand(envelope, remoteCommand, acknowledge);
|