blun-king-cli 9.1.454 → 9.1.455
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/cognitive-action-checkpoint.cjs +165 -5
- package/blun.mjs +115 -33
- package/package.json +1 -1
|
@@ -14,15 +14,20 @@ const TRIGGER_KINDS = new Set([
|
|
|
14
14
|
]);
|
|
15
15
|
const VERIFICATION_SUBJECTS = new Set(['result', 'verifier']);
|
|
16
16
|
const VERIFICATION_KINDS = new Set(['inspection', 'integrity', 'syntax', 'test', 'reachability']);
|
|
17
|
+
const EXTERNAL_REPORT_SOURCES = new Set(['telegram']);
|
|
17
18
|
const MODEL_KEYS = new Set([
|
|
18
|
-
'revision', 'phase', 'evidenceBasis', 'epistemicState', 'lastVerified', 'nextAction', 'expectedEvidence', 'verificationProof', 'nextTrigger', 'problemFrame', 'updatedAt',
|
|
19
|
+
'revision', 'phase', 'evidenceBasis', 'epistemicState', 'lastVerified', 'nextAction', 'expectedEvidence', 'verificationProof', 'nextTrigger', 'problemFrame', 'externalReportSource', 'updatedAt',
|
|
19
20
|
]);
|
|
20
|
-
const RUNTIME_KEYS = new Set([...MODEL_KEYS, 'evidenceReceipt']);
|
|
21
|
+
const RUNTIME_KEYS = new Set([...MODEL_KEYS, 'evidenceReceipt', 'externalReportOrigin']);
|
|
21
22
|
const PROBLEM_FRAME_KEYS = new Set([
|
|
22
23
|
'successCriterion', 'missingKnowledge', 'candidateActions', 'selectedAction',
|
|
23
24
|
'selectionReason', 'supportChoice', 'risk', 'reversibility', 'decisionBasis',
|
|
24
25
|
]);
|
|
25
26
|
const NEXT_TRIGGER_KEYS = new Set(['kind', 'condition', 'dueAt']);
|
|
27
|
+
const EXTERNAL_REPORT_SELECTOR_KEYS = new Set(['source', 'chatId', 'messageId']);
|
|
28
|
+
const EXTERNAL_REPORT_ORIGIN_KEYS = new Set([
|
|
29
|
+
'source', 'reporter', 'reporterRef', 'eventRef', 'occurredAt',
|
|
30
|
+
]);
|
|
26
31
|
const EVIDENCE_INPUT_KEYS = new Set([
|
|
27
32
|
'turnId', 'toolCallId', 'toolName', 'decision', 'outcome', 'durationMs', 'toolArgs',
|
|
28
33
|
'resultEvidenceKinds', 'resultEvidenceScopes',
|
|
@@ -32,6 +37,7 @@ const REQUIRED_EVIDENCE_INPUT_KEYS = new Set([
|
|
|
32
37
|
]);
|
|
33
38
|
const EVIDENCE_DIGEST_RE = /^[a-f0-9]{16}$/u;
|
|
34
39
|
const EVIDENCE_PRODUCER_REF_RE = /^[a-f0-9]{16}$/u;
|
|
40
|
+
const EXTERNAL_REPORT_REF_RE = /^[a-f0-9]{16}$/u;
|
|
35
41
|
const DECISION_BASIS_RE = /^[a-f0-9]{16}$/u;
|
|
36
42
|
const COMPLETION_CRITERION_REF_RE = /^[a-f0-9]{16}$/u;
|
|
37
43
|
const ISO_TIMESTAMP_RE = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,9})?(?:Z|[+-]\d{2}(?::?\d{2})?)$/u;
|
|
@@ -189,6 +195,131 @@ function evidenceProducerRef(identity) {
|
|
|
189
195
|
.slice(0, 16);
|
|
190
196
|
}
|
|
191
197
|
|
|
198
|
+
function normalizedExternalReportSource(value, field = 'external report source') {
|
|
199
|
+
const source = String(value ?? '').trim();
|
|
200
|
+
if (!EXTERNAL_REPORT_SOURCES.has(source)) throw new TypeError(`${field} is invalid`);
|
|
201
|
+
return source;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function normalizeExternalReportSelector(input) {
|
|
205
|
+
if (!input || typeof input !== 'object' || Array.isArray(input)) {
|
|
206
|
+
throw new TypeError('externalReportSource is required for external_report evidenceBasis');
|
|
207
|
+
}
|
|
208
|
+
for (const key of Object.keys(input)) {
|
|
209
|
+
if (!EXTERNAL_REPORT_SELECTOR_KEYS.has(key)) {
|
|
210
|
+
throw new TypeError(`externalReportSource field is unsupported: ${key}`);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
return Object.freeze({
|
|
214
|
+
source: normalizedExternalReportSource(input.source),
|
|
215
|
+
chatId: bounded(input.chatId, 'externalReportSource chatId', 64),
|
|
216
|
+
messageId: bounded(input.messageId, 'externalReportSource messageId', 64),
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function externalReportSourceFromChannelMeta(meta) {
|
|
221
|
+
if (!meta || typeof meta !== 'object' || Array.isArray(meta)) {
|
|
222
|
+
throw new TypeError('channel metadata is required for external report provenance');
|
|
223
|
+
}
|
|
224
|
+
const reporter = bounded(meta.user ?? meta.user_id, 'external report reporter', 128);
|
|
225
|
+
return Object.freeze({
|
|
226
|
+
source: 'telegram',
|
|
227
|
+
chatId: bounded(meta.chat_id, 'external report chatId', 64),
|
|
228
|
+
messageId: bounded(meta.message_id, 'external report messageId', 64),
|
|
229
|
+
reporter,
|
|
230
|
+
reporterId: bounded(meta.user_id ?? reporter, 'external report reporterId', 128),
|
|
231
|
+
occurredAt: normalizedTimestamp(meta.ts, 'external report occurredAt', true),
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function normalizeRuntimeExternalReportSource(input) {
|
|
236
|
+
if (!input || typeof input !== 'object' || Array.isArray(input)) {
|
|
237
|
+
throw new TypeError('trusted external report source is invalid');
|
|
238
|
+
}
|
|
239
|
+
const reporter = bounded(input.reporter ?? input.reporterId, 'external report reporter', 128);
|
|
240
|
+
return Object.freeze({
|
|
241
|
+
source: normalizedExternalReportSource(input.source),
|
|
242
|
+
chatId: bounded(input.chatId, 'external report chatId', 64),
|
|
243
|
+
messageId: bounded(input.messageId, 'external report messageId', 64),
|
|
244
|
+
reporter,
|
|
245
|
+
reporterId: bounded(input.reporterId ?? reporter, 'external report reporterId', 128),
|
|
246
|
+
occurredAt: normalizedTimestamp(input.occurredAt, 'external report occurredAt', true),
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function externalReportSourcesFromOrigin(origin) {
|
|
251
|
+
if (!origin || typeof origin !== 'object' || !Array.isArray(origin.externalReportSources)) {
|
|
252
|
+
return Object.freeze([]);
|
|
253
|
+
}
|
|
254
|
+
const sources = [];
|
|
255
|
+
const seen = new Set();
|
|
256
|
+
for (const value of origin.externalReportSources) {
|
|
257
|
+
let source;
|
|
258
|
+
try {
|
|
259
|
+
source = normalizeRuntimeExternalReportSource(value);
|
|
260
|
+
} catch {
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
const key = `${source.source}\0${source.chatId}\0${source.messageId}`;
|
|
264
|
+
if (seen.has(key)) continue;
|
|
265
|
+
seen.add(key);
|
|
266
|
+
sources.push(source);
|
|
267
|
+
}
|
|
268
|
+
return Object.freeze(sources.slice(0, 32));
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function normalizedExternalReportRef(value, field) {
|
|
272
|
+
const ref = String(value ?? '').trim();
|
|
273
|
+
if (!EXTERNAL_REPORT_REF_RE.test(ref)) throw new TypeError(`${field} is invalid`);
|
|
274
|
+
return ref;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function normalizeExternalReportOrigin(input) {
|
|
278
|
+
if (!input || typeof input !== 'object' || Array.isArray(input)) {
|
|
279
|
+
throw new TypeError('externalReportOrigin is invalid');
|
|
280
|
+
}
|
|
281
|
+
for (const key of Object.keys(input)) {
|
|
282
|
+
if (!EXTERNAL_REPORT_ORIGIN_KEYS.has(key)) {
|
|
283
|
+
throw new TypeError(`externalReportOrigin field is unsupported: ${key}`);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
return Object.freeze({
|
|
287
|
+
source: normalizedExternalReportSource(input.source, 'externalReportOrigin source'),
|
|
288
|
+
reporter: bounded(input.reporter, 'externalReportOrigin reporter', 128),
|
|
289
|
+
reporterRef: normalizedExternalReportRef(input.reporterRef, 'externalReportOrigin reporterRef'),
|
|
290
|
+
eventRef: normalizedExternalReportRef(input.eventRef, 'externalReportOrigin eventRef'),
|
|
291
|
+
occurredAt: normalizedTimestamp(input.occurredAt, 'externalReportOrigin occurredAt', true),
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
function resolveExternalReportOrigin(selectorInput, runtimeExternalReports) {
|
|
296
|
+
const selector = normalizeExternalReportSelector(selectorInput);
|
|
297
|
+
const reports = Array.isArray(runtimeExternalReports)
|
|
298
|
+
? runtimeExternalReports.map(normalizeRuntimeExternalReportSource)
|
|
299
|
+
: [];
|
|
300
|
+
const report = reports.find((candidate) => candidate.source === selector.source
|
|
301
|
+
&& candidate.chatId === selector.chatId
|
|
302
|
+
&& candidate.messageId === selector.messageId);
|
|
303
|
+
if (report === undefined) {
|
|
304
|
+
throw new TypeError('externalReportSource does not match a trusted external report in the current turn');
|
|
305
|
+
}
|
|
306
|
+
const reporterRef = crypto.createHash('sha256')
|
|
307
|
+
.update(`external-report-reporter:${report.source}\0${report.reporterId}`)
|
|
308
|
+
.digest('hex')
|
|
309
|
+
.slice(0, 16);
|
|
310
|
+
const eventRef = crypto.createHash('sha256')
|
|
311
|
+
.update(`external-report-event:${report.source}\0${report.chatId}\0${report.messageId}\0${reporterRef}\0${report.occurredAt}`)
|
|
312
|
+
.digest('hex')
|
|
313
|
+
.slice(0, 16);
|
|
314
|
+
return Object.freeze({
|
|
315
|
+
source: report.source,
|
|
316
|
+
reporter: report.reporter,
|
|
317
|
+
reporterRef,
|
|
318
|
+
eventRef,
|
|
319
|
+
occurredAt: report.occurredAt,
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
|
|
192
323
|
function normalizedEvidenceProducerRef(value, field = 'evidence producer ref') {
|
|
193
324
|
const ref = String(value ?? '').trim();
|
|
194
325
|
if (!EVIDENCE_PRODUCER_REF_RE.test(ref)) throw new TypeError(`${field} is invalid`);
|
|
@@ -753,7 +884,7 @@ function assertActionCheckpointRevision(current, input) {
|
|
|
753
884
|
return inputRevision;
|
|
754
885
|
}
|
|
755
886
|
|
|
756
|
-
function assertActionCheckpointEvidenceBasis(current, input, runtimeEvidence) {
|
|
887
|
+
function assertActionCheckpointEvidenceBasis(current, input, runtimeEvidence, runtimeExternalReports) {
|
|
757
888
|
const basis = normalizedEvidenceBasis(input?.evidenceBasis);
|
|
758
889
|
const epistemicState = normalizedEpistemicState(input?.epistemicState);
|
|
759
890
|
if (basis === 'runtime_tool') {
|
|
@@ -765,8 +896,15 @@ function assertActionCheckpointEvidenceBasis(current, input, runtimeEvidence) {
|
|
|
765
896
|
throw new TypeError('runtime_tool evidenceBasis requires verified epistemicState');
|
|
766
897
|
}
|
|
767
898
|
}
|
|
768
|
-
if (basis === 'external_report'
|
|
769
|
-
|
|
899
|
+
if (basis === 'external_report') {
|
|
900
|
+
if (epistemicState === 'verified') {
|
|
901
|
+
throw new TypeError('external_report evidenceBasis cannot claim verified epistemicState');
|
|
902
|
+
}
|
|
903
|
+
if (runtimeExternalReports !== undefined) {
|
|
904
|
+
resolveExternalReportOrigin(input?.externalReportSource, runtimeExternalReports);
|
|
905
|
+
}
|
|
906
|
+
} else if (input?.externalReportSource !== undefined) {
|
|
907
|
+
throw new TypeError('externalReportSource requires external_report evidenceBasis');
|
|
770
908
|
}
|
|
771
909
|
if (basis === 'carried_forward') {
|
|
772
910
|
if (!current) throw new TypeError('carried_forward evidenceBasis requires a current checkpoint');
|
|
@@ -817,6 +955,22 @@ function normalizeActionCheckpoint(input, options = {}) {
|
|
|
817
955
|
if (input.nextTrigger !== undefined) checkpoint.nextTrigger = normalizeNextTrigger(input.nextTrigger, phase);
|
|
818
956
|
else if (!replay) throw new TypeError('nextTrigger is required');
|
|
819
957
|
if (input.problemFrame !== undefined) checkpoint.problemFrame = normalizeProblemFrame(input.problemFrame);
|
|
958
|
+
if (input.externalReportSource !== undefined && evidenceBasis !== 'external_report') {
|
|
959
|
+
throw new TypeError('externalReportSource requires external_report evidenceBasis');
|
|
960
|
+
}
|
|
961
|
+
if (evidenceBasis === 'external_report' && options.runtimeExternalReports !== undefined) {
|
|
962
|
+
checkpoint.externalReportOrigin = resolveExternalReportOrigin(
|
|
963
|
+
input.externalReportSource,
|
|
964
|
+
options.runtimeExternalReports,
|
|
965
|
+
);
|
|
966
|
+
} else if (replay && input.externalReportOrigin !== undefined) {
|
|
967
|
+
checkpoint.externalReportOrigin = normalizeExternalReportOrigin(input.externalReportOrigin);
|
|
968
|
+
} else if (evidenceBasis === 'carried_forward'
|
|
969
|
+
&& options.previousCheckpoint?.externalReportOrigin !== undefined) {
|
|
970
|
+
checkpoint.externalReportOrigin = normalizeExternalReportOrigin(
|
|
971
|
+
options.previousCheckpoint.externalReportOrigin,
|
|
972
|
+
);
|
|
973
|
+
}
|
|
820
974
|
const evidenceReceipt = options.runtimeEvidence !== undefined
|
|
821
975
|
? normalizeActionEvidenceReceipt(options.runtimeEvidence)
|
|
822
976
|
: options.preserveRuntimeEvidence === true && input.evidenceReceipt !== undefined
|
|
@@ -891,6 +1045,10 @@ function projectActionCheckpoint(checkpoint) {
|
|
|
891
1045
|
lines.push(`Reversibility: ${frame.reversibility}`);
|
|
892
1046
|
if (frame.decisionBasis !== undefined) lines.push(`Decision basis: ${frame.decisionBasis.join(' | ')}`);
|
|
893
1047
|
}
|
|
1048
|
+
if (value.externalReportOrigin !== undefined) {
|
|
1049
|
+
const report = value.externalReportOrigin;
|
|
1050
|
+
lines.push(`External report origin: ${report.reporter} via ${report.source}; event ${report.eventRef}; occurred ${report.occurredAt}`);
|
|
1051
|
+
}
|
|
894
1052
|
if (value.evidenceReceipt !== undefined) {
|
|
895
1053
|
const receipt = value.evidenceReceipt;
|
|
896
1054
|
lines.push(`Runtime evidence: turn ${receipt.turnId}; ${receipt.completedTools} completed, ${receipt.successfulTools} successful, ${receipt.failedTools} failed; digest ${receipt.digest}`);
|
|
@@ -910,6 +1068,8 @@ module.exports = {
|
|
|
910
1068
|
completionCriterionRef,
|
|
911
1069
|
evidenceProducerRef,
|
|
912
1070
|
emptyActionEvidenceReceipt,
|
|
1071
|
+
externalReportSourceFromChannelMeta,
|
|
1072
|
+
externalReportSourcesFromOrigin,
|
|
913
1073
|
normalizeActionCheckpoint,
|
|
914
1074
|
normalizeVerificationProof,
|
|
915
1075
|
projectActionCheckpoint,
|
package/blun.mjs
CHANGED
|
@@ -21463,7 +21463,7 @@ var { rollbackPersonalityChoice, setPersonalityEnabledAtomic } = createRequire(i
|
|
|
21463
21463
|
var { projectSoulText } = createRequire(import.meta.url)("./bin/soul-organization-policy.cjs");
|
|
21464
21464
|
var { soulFileInstruction } = createRequire(import.meta.url)("./bin/soul-preservation-policy.cjs");
|
|
21465
21465
|
var { readProfilePersona, resolveSoulFile } = createRequire(import.meta.url)("./bin/profile-identity-resolution.cjs");
|
|
21466
|
-
var { advanceActionEvidenceReceipt, assertActionCheckpointEvidenceBasis, assertActionCheckpointRevision, emptyActionEvidenceReceipt, evidenceProducerRef, normalizeActionCheckpoint, projectActionCheckpoint } = createRequire(import.meta.url)("./bin/cognitive-action-checkpoint.cjs");
|
|
21466
|
+
var { advanceActionEvidenceReceipt, assertActionCheckpointEvidenceBasis, assertActionCheckpointRevision, emptyActionEvidenceReceipt, evidenceProducerRef, externalReportSourcesFromOrigin, normalizeActionCheckpoint, projectActionCheckpoint } = createRequire(import.meta.url)("./bin/cognitive-action-checkpoint.cjs");
|
|
21467
21467
|
var { evaluateGoalCompletionEvidence } = createRequire(import.meta.url)("./bin/goal-completion-evidence-policy.cjs");
|
|
21468
21468
|
async function prepareSystemPromptContext(kaos, brandHome, options) {
|
|
21469
21469
|
const additionalDirs = normalizeAdditionalDirs(options?.additionalDirs ?? []);
|
|
@@ -230281,9 +230281,11 @@ var init_goal$1 = __esmMin((() => {
|
|
|
230281
230281
|
if (input.actionCheckpoint !== void 0) {
|
|
230282
230282
|
assertActionCheckpointRevision(undefined, input.actionCheckpoint);
|
|
230283
230283
|
const runtimeEvidence = this.agent.turn.actionEvidenceReceiptForCurrentTurn();
|
|
230284
|
-
|
|
230284
|
+
const runtimeExternalReports = this.agent.turn.externalReportSourcesForCurrentTurn();
|
|
230285
|
+
assertActionCheckpointEvidenceBasis(undefined, input.actionCheckpoint, runtimeEvidence, runtimeExternalReports);
|
|
230285
230286
|
state.actionCheckpoint = normalizeActionCheckpoint(input.actionCheckpoint, {
|
|
230286
|
-
runtimeEvidence
|
|
230287
|
+
runtimeEvidence,
|
|
230288
|
+
runtimeExternalReports
|
|
230287
230289
|
});
|
|
230288
230290
|
}
|
|
230289
230291
|
this.persistState(state);
|
|
@@ -230365,9 +230367,12 @@ var init_goal$1 = __esmMin((() => {
|
|
|
230365
230367
|
if (state.status !== "active") throw new BlunError(ErrorCodes.GOAL_STATUS_INVALID, `Cannot checkpoint a goal in status "${state.status}"`);
|
|
230366
230368
|
assertActionCheckpointRevision(state.actionCheckpoint, input);
|
|
230367
230369
|
const runtimeEvidence = this.agent.turn.actionEvidenceReceiptForCurrentTurn();
|
|
230368
|
-
|
|
230370
|
+
const runtimeExternalReports = this.agent.turn.externalReportSourcesForCurrentTurn();
|
|
230371
|
+
assertActionCheckpointEvidenceBasis(state.actionCheckpoint, input, runtimeEvidence, runtimeExternalReports);
|
|
230369
230372
|
state.actionCheckpoint = normalizeActionCheckpoint(input, {
|
|
230370
|
-
runtimeEvidence
|
|
230373
|
+
runtimeEvidence,
|
|
230374
|
+
runtimeExternalReports,
|
|
230375
|
+
previousCheckpoint: state.actionCheckpoint
|
|
230371
230376
|
});
|
|
230372
230377
|
this.persistState(state, { change: { kind: "progress", actor } });
|
|
230373
230378
|
this.appendGoalUpdate({ actionCheckpoint: state.actionCheckpoint, actor });
|
|
@@ -245792,6 +245797,13 @@ var init_events$1 = __esmMin((() => {
|
|
|
245792
245797
|
phase: _enum(["orient", "plan", "act", "verify", "learn", "wait"]),
|
|
245793
245798
|
evidenceBasis: _enum(["runtime_tool", "user_statement", "external_report", "carried_forward", "legacy_unknown"]),
|
|
245794
245799
|
epistemicState: _enum(["verified", "credible_unverified", "hypothesis", "uncertain_memory", "stale", "unknown", "legacy_unknown"]),
|
|
245800
|
+
externalReportOrigin: object({
|
|
245801
|
+
source: _enum(["telegram"]),
|
|
245802
|
+
reporter: string(),
|
|
245803
|
+
reporterRef: string().regex(/^[a-f0-9]{16}$/u),
|
|
245804
|
+
eventRef: string().regex(/^[a-f0-9]{16}$/u),
|
|
245805
|
+
occurredAt: string()
|
|
245806
|
+
}).strict().optional(),
|
|
245795
245807
|
lastVerified: string(),
|
|
245796
245808
|
nextAction: string(),
|
|
245797
245809
|
expectedEvidence: string(),
|
|
@@ -260311,6 +260323,7 @@ var create_goal_default;
|
|
|
260311
260323
|
var init_create_goal$1 = __esmMin((() => {
|
|
260312
260324
|
create_goal_default = "Create a durable, structured goal that the runtime will pursue across multiple turns.\n\nCall `CreateGoal` when:\n\n- the user explicitly asks you to start a goal or work autonomously toward an outcome,\n- an authenticated user assigns a non-trivial multi-step outcome with a checkable end state under an existing instruction to continue autonomously, or\n- a host goal-intake prompt asks you to create one.\n\nDo NOT create a goal for greetings, ordinary questions, one-step requests, or vague requests that lack a\nverifiable completion condition. A goal needs a checkable end state.\n\nWhen the request is vague, ask the user for the missing completion criterion before creating\nthe goal. If the user clearly insists after you warn them that the wording is vague or risky,\nrespect that and create the goal.\n\nInclude a `completionCriterion` when the user provides one, or when it can be stated without\ninventing new requirements. Keep `objective` concise; reference long task descriptions by file\npath rather than pasting them. Start every created goal with revision 1 and a complete `problemFrame`\ninside `actionCheckpoint`, so the success criterion, missing knowledge, candidate actions, chosen\naction, support choice, risk, reversibility, next action, expected evidence, and exact next trigger survive interruption.\nThis frame is descriptive state only and never grants permission.\n\nCreating a goal fails if one already exists, so use `replace: true` only when the user explicitly\nwants to abandon the current goal and start a new one.\n";
|
|
260313
260325
|
create_goal_default += "\nBind each selected action to the projected durable facts or assumptions it relies on by copying their explicit refs into `decisionBasis`. A stale or unknown decision basis requires replanning before execution.\n";
|
|
260326
|
+
create_goal_default += "\nWhen the checkpoint rests on a forwarded Telegram report, use `external_report` with `credible_unverified` and select the exact visible channel event in `externalReportSource` with its `source`, `chat_id` as `chatId`, and `message_id` as `messageId`. The runtime binds the reporter and event reference; never invent them.\n";
|
|
260314
260327
|
}));
|
|
260315
260328
|
//#endregion
|
|
260316
260329
|
//#region ../../packages/agent-core/src/tools/builtin/goal/serialize.ts
|
|
@@ -260348,6 +260361,11 @@ function createActionCheckpointInputSchema(problemFrameSchema, requireProblemFra
|
|
|
260348
260361
|
phase: _enum(["orient", "plan", "act", "verify", "learn", "wait"]),
|
|
260349
260362
|
evidenceBasis: _enum(["runtime_tool", "user_statement", "external_report", "carried_forward"]),
|
|
260350
260363
|
epistemicState: _enum(["verified", "credible_unverified", "hypothesis", "uncertain_memory", "stale", "unknown"]),
|
|
260364
|
+
externalReportSource: object({
|
|
260365
|
+
source: _enum(["telegram"]),
|
|
260366
|
+
chatId: string().min(1).max(64),
|
|
260367
|
+
messageId: string().min(1).max(64)
|
|
260368
|
+
}).strict().optional(),
|
|
260351
260369
|
lastVerified: string().min(1).max(512),
|
|
260352
260370
|
nextAction: string().min(1).max(512),
|
|
260353
260371
|
expectedEvidence: string().min(1).max(512),
|
|
@@ -261714,6 +261732,12 @@ function explicitToolResultEvidenceScopes(result) {
|
|
|
261714
261732
|
function abandonedToolResultOutput(ended) {
|
|
261715
261733
|
return `Tool call did not complete: ${ended.reason === "cancelled" ? "the turn was cancelled" : ended.reason === "failed" ? `the turn failed${ended.error !== void 0 ? ` (${ended.error.message})` : ""}` : "the turn ended"} before its result was recorded. Do not assume the tool completed successfully.`;
|
|
261716
261734
|
}
|
|
261735
|
+
function durablePromptOrigin(origin) {
|
|
261736
|
+
if (!origin || typeof origin !== "object" || !Object.hasOwn(origin, "externalReportSources")) return origin;
|
|
261737
|
+
const { externalReportSources, ...durableOrigin } = origin;
|
|
261738
|
+
void externalReportSources;
|
|
261739
|
+
return durableOrigin;
|
|
261740
|
+
}
|
|
261717
261741
|
var BLUN_CORE_TOOL_NAMES, BLUN_LEAN_TOOL_NAMES, BLUN_ATTACHMENT_MARKER_RE, BLUN_TELEGRAM_OUTBOUND_TOOL_RE, BLUN_TELEGRAM_CHANNEL_RE, BLUN_TOOL_BUDGET_RATIO, createDeferredToolLoader, mediaToolNamesForTurnText, rankedSupportToolNamesForGoal, rankedToolNamesForTurnText, rememberDeferredToolAfterNotFound, toolSchemaBudgetTokens, projectRecurringCronHistory, TelegramDeliveryLedger, createRuntimeCognitiveTurnLifecycle, cognitiveFocusScopesForTurn, buildCognitiveWorkFocus, buildAttentionQueueItem, LLM_NOT_SET_MESSAGE, GOAL_CONTINUATION_ORIGIN, GOAL_COMPLETION_REMINDER_NAME, GOAL_BLOCKED_REMINDER_NAME, GOAL_RATE_LIMIT_PAUSE_REASON, GOAL_PROVIDER_CONNECTION_PAUSE_PREFIX, GOAL_PROVIDER_AUTH_PAUSE_PREFIX, GOAL_PROVIDER_API_PAUSE_PREFIX, GOAL_MODEL_CONFIG_PAUSE_PREFIX, GOAL_RUNTIME_PAUSE_PREFIX, GOAL_PROVIDER_FILTERED_PAUSE_REASON, GOAL_CONTINUATION_PROMPT, TurnFlow;
|
|
261718
261742
|
var init_turn = __esmMin((() => {
|
|
261719
261743
|
init_dist$4();
|
|
@@ -261803,6 +261827,7 @@ var init_turn = __esmMin((() => {
|
|
|
261803
261827
|
cognitiveToolPolicyByCall = /* @__PURE__ */ new Map();
|
|
261804
261828
|
cognitiveToolBatchesByTurn = /* @__PURE__ */ new Map();
|
|
261805
261829
|
cognitiveActionEvidenceByTurn = /* @__PURE__ */ new Map();
|
|
261830
|
+
cognitiveExternalReportsByTurn = /* @__PURE__ */ new Map();
|
|
261806
261831
|
constructor(agent) {
|
|
261807
261832
|
this.agent = agent;
|
|
261808
261833
|
}
|
|
@@ -261882,6 +261907,23 @@ var init_turn = __esmMin((() => {
|
|
|
261882
261907
|
const turnId = this.currentId;
|
|
261883
261908
|
return this.cognitiveActionEvidenceByTurn.get(turnId) ?? emptyActionEvidenceReceipt(turnId, this.agent.evidenceProducerRef);
|
|
261884
261909
|
}
|
|
261910
|
+
recordExternalReportSources(turnId, origin) {
|
|
261911
|
+
const incoming = externalReportSourcesFromOrigin(origin);
|
|
261912
|
+
if (incoming.length === 0) return;
|
|
261913
|
+
const current = this.cognitiveExternalReportsByTurn.get(turnId) ?? [];
|
|
261914
|
+
const merged = [...current];
|
|
261915
|
+
const seen = new Set(current.map((source) => `${source.source}\0${source.chatId}\0${source.messageId}`));
|
|
261916
|
+
for (const source of incoming) {
|
|
261917
|
+
const key = `${source.source}\0${source.chatId}\0${source.messageId}`;
|
|
261918
|
+
if (seen.has(key)) continue;
|
|
261919
|
+
seen.add(key);
|
|
261920
|
+
merged.push(source);
|
|
261921
|
+
}
|
|
261922
|
+
this.cognitiveExternalReportsByTurn.set(turnId, Object.freeze(merged.slice(-32)));
|
|
261923
|
+
}
|
|
261924
|
+
externalReportSourcesForCurrentTurn() {
|
|
261925
|
+
return this.cognitiveExternalReportsByTurn.get(this.currentId) ?? Object.freeze([]);
|
|
261926
|
+
}
|
|
261885
261927
|
projectCognitiveState(turnId, input) {
|
|
261886
261928
|
try {
|
|
261887
261929
|
const focusScopes = cognitiveFocusScopesForTurn(input);
|
|
@@ -261936,7 +261978,7 @@ var init_turn = __esmMin((() => {
|
|
|
261936
261978
|
this.agent.records.logRecord({
|
|
261937
261979
|
type: "turn.prompt",
|
|
261938
261980
|
input,
|
|
261939
|
-
origin
|
|
261981
|
+
origin: durablePromptOrigin(origin)
|
|
261940
261982
|
});
|
|
261941
261983
|
const buffered = this.agent.fullCompaction.isCompacting;
|
|
261942
261984
|
const turnId = this.launch(input, origin);
|
|
@@ -261955,7 +261997,7 @@ var init_turn = __esmMin((() => {
|
|
|
261955
261997
|
this.agent.records.logRecord({
|
|
261956
261998
|
type: "turn.steer",
|
|
261957
261999
|
input,
|
|
261958
|
-
origin
|
|
262000
|
+
origin: durablePromptOrigin(origin)
|
|
261959
262001
|
});
|
|
261960
262002
|
if (this.activeTurn || this.agent.fullCompaction.isCompacting) {
|
|
261961
262003
|
this.bufferSteer(input, origin);
|
|
@@ -261978,7 +262020,7 @@ var init_turn = __esmMin((() => {
|
|
|
261978
262020
|
this.agent.records.logRecord({
|
|
261979
262021
|
type: "turn.steer",
|
|
261980
262022
|
input,
|
|
261981
|
-
origin
|
|
262023
|
+
origin: durablePromptOrigin(origin)
|
|
261982
262024
|
});
|
|
261983
262025
|
this.bufferSteer(input, origin, this.currentId);
|
|
261984
262026
|
return {
|
|
@@ -262110,6 +262152,9 @@ var init_turn = __esmMin((() => {
|
|
|
262110
262152
|
return this.flushSteerBuffer(turnId, snapshot.throughSequence);
|
|
262111
262153
|
}
|
|
262112
262154
|
bufferSteer(input, origin, targetTurnId) {
|
|
262155
|
+
const active = this.activeTurn;
|
|
262156
|
+
const reportTurnId = targetTurnId ?? (active !== null && active !== "resuming" ? active.turnId : void 0);
|
|
262157
|
+
if (reportTurnId !== void 0) this.recordExternalReportSources(reportTurnId, origin);
|
|
262113
262158
|
this.steerBuffer.push({
|
|
262114
262159
|
sequence: this.nextSteerSequence,
|
|
262115
262160
|
input,
|
|
@@ -262127,7 +262172,7 @@ var init_turn = __esmMin((() => {
|
|
|
262127
262172
|
remaining.push(steer);
|
|
262128
262173
|
continue;
|
|
262129
262174
|
}
|
|
262130
|
-
this.agent.context.appendUserMessage(steer.input, steer.origin);
|
|
262175
|
+
this.agent.context.appendUserMessage(steer.input, durablePromptOrigin(steer.origin));
|
|
262131
262176
|
flushed = true;
|
|
262132
262177
|
}
|
|
262133
262178
|
this.steerBuffer = remaining;
|
|
@@ -262280,6 +262325,8 @@ var init_turn = __esmMin((() => {
|
|
|
262280
262325
|
const telemetryMode = this.telemetryMode();
|
|
262281
262326
|
this.telemetryModeByTurn.set(turnId, telemetryMode);
|
|
262282
262327
|
this.currentStepByTurn.set(turnId, 0);
|
|
262328
|
+
this.recordExternalReportSources(turnId, origin);
|
|
262329
|
+
const persistedOrigin = durablePromptOrigin(origin);
|
|
262283
262330
|
this.agent.telemetry.track("turn_started", {
|
|
262284
262331
|
mode: telemetryMode,
|
|
262285
262332
|
...this.requestProviderProps()
|
|
@@ -262290,9 +262337,9 @@ var init_turn = __esmMin((() => {
|
|
|
262290
262337
|
this.agent.emitEvent({
|
|
262291
262338
|
type: "turn.started",
|
|
262292
262339
|
turnId,
|
|
262293
|
-
origin
|
|
262340
|
+
origin: persistedOrigin
|
|
262294
262341
|
});
|
|
262295
|
-
this.agent.context.appendUserMessage(input,
|
|
262342
|
+
this.agent.context.appendUserMessage(input, persistedOrigin);
|
|
262296
262343
|
this.recordCognitiveStage("startTurn", { turnId, originKind: origin.kind });
|
|
262297
262344
|
const startedAt = Date.now();
|
|
262298
262345
|
let ended;
|
|
@@ -262300,7 +262347,7 @@ var init_turn = __esmMin((() => {
|
|
|
262300
262347
|
let completedStopReason;
|
|
262301
262348
|
let errorEvent;
|
|
262302
262349
|
try {
|
|
262303
|
-
const promptHookEnded = await this.applyUserPromptHook(turnId, input,
|
|
262350
|
+
const promptHookEnded = await this.applyUserPromptHook(turnId, input, persistedOrigin, signal, startedAt);
|
|
262304
262351
|
this.recordCognitiveStage("recordRightsCheck", {
|
|
262305
262352
|
turnId,
|
|
262306
262353
|
decision: origin.kind !== "user" ? "not_applicable" : promptHookEnded?.blocked === true ? "blocked" : "passed",
|
|
@@ -262310,7 +262357,7 @@ var init_turn = __esmMin((() => {
|
|
|
262310
262357
|
ended = promptHookEnded.event;
|
|
262311
262358
|
blockedByUserPromptHook = promptHookEnded.blocked;
|
|
262312
262359
|
} else {
|
|
262313
|
-
const stopReason = await this.runStepLoop(turnId, signal, input,
|
|
262360
|
+
const stopReason = await this.runStepLoop(turnId, signal, input, persistedOrigin);
|
|
262314
262361
|
completedStopReason = stopReason;
|
|
262315
262362
|
ended = {
|
|
262316
262363
|
type: "turn.ended",
|
|
@@ -262389,6 +262436,7 @@ var init_turn = __esmMin((() => {
|
|
|
262389
262436
|
this.currentStepByTurn.delete(turnId);
|
|
262390
262437
|
this.interruptedTelemetryTurnIds.delete(turnId);
|
|
262391
262438
|
this.cognitiveActionEvidenceByTurn.delete(turnId);
|
|
262439
|
+
this.cognitiveExternalReportsByTurn.delete(turnId);
|
|
262392
262440
|
this.stepFailureByTurn.delete(turnId);
|
|
262393
262441
|
await this.agent.records.flush();
|
|
262394
262442
|
return {
|
|
@@ -262922,7 +262970,7 @@ var init_update_goal$1 = __esmMin((() => {
|
|
|
262922
262970
|
update_goal_default = "Update the current autonomous goal. Set `status` only for a lifecycle change. After a coherent work slice, save `actionCheckpoint` with a monotone revision, the last verified result, exact next action, expected evidence, exact `nextTrigger`, and an explicit evidence basis. Persist the exact `nextTrigger` that releases `nextAction`: use `immediate` outside the `wait` phase; while waiting, name the external event, time, dependency, or user decision instead of pretending work can continue. A `time` trigger must include the exact ISO timestamp in `dueAt`; no other trigger kind may include `dueAt`. Use `runtime_tool` only when a successful tool in this turn measured the result; use `user_statement` for a direct user assertion, `external_report` for a report not independently measured here, and `carried_forward` only when the last verified text is unchanged. Classify knowledge as `verified`, `credible_unverified`, `hypothesis`, `uncertain_memory`, `stale`, or `unknown`; never present a weaker state as verified, and preserve the state on carry-forward. Start at revision 1 and increment the currently projected revision by exactly one; stale writers fail closed. This is durable progress state, not permission, and should change only when the facts change. A checkpoint-only call keeps the goal active.\n\n- `active` — resume a paused or blocked goal when the user explicitly asks you to work on that goal.\n- `complete` — the objective is fully satisfied, all files are written, all tests pass, and any stated validation has passed. When the goal has a completion criterion, first save a `verify` checkpoint with `runtime_tool`, `verified`, and a successful runtime evidence receipt.\n- `blocked` — a genuine external condition or required user decision prevents progress.\n- `paused` — set the goal aside for now.\n\nDo not mark complete after a plan or partial result. If useful work remains, checkpoint it and continue. Do not ask for permission merely to execute an already authorized checkpoint; ask only at a real rights boundary or missing user decision.\n";
|
|
262923
262971
|
update_goal_default += "\nBefore completing a goal with a criterion, bind the verified claim to the exact successful current-turn verification call in `verificationProof`, including its `toolCallId`. A write, edit, copy, deploy, or other action is not proof that the changed behavior works, even when it shares a mixed-use tool such as `Bash` with tests. Use `subject: result` for a result, report, measurement, or download. Use `subject: verifier` only when the new or changed test, gate, harness, or detector itself is the completion subject; then bind `sharpnessProof` to a separate successful current-turn counterexample or mutation call. Do not require a red probe for a normal report or measurement.\n";
|
|
262924
262972
|
update_goal_default += "\nCopy the active goal's exact `completionCriterion` into `verificationProof.criterion`. The runtime stores only its bounded reference and refuses completion if the proof belongs to a different or superseded completion criterion.\n";
|
|
262925
|
-
update_goal_default += "\nThe runtime binds fresh verification automatically to the session and agent that produced the successful tool result. Do not invent or copy a producer reference. Preserve forwarded measurements as `external_report` with `credible_unverified` until this agent measures them independently; forwarding is allowed, relabelling them as local verification is not.\n";
|
|
262973
|
+
update_goal_default += "\nThe runtime binds fresh verification automatically to the session and agent that produced the successful tool result. Do not invent or copy a producer reference. Preserve forwarded measurements as `external_report` with `credible_unverified` until this agent measures them independently; forwarding is allowed, relabelling them as local verification is not. For a fresh Telegram report, copy the exact visible channel `source`, `chat_id` as `chatId`, and `message_id` as `messageId` into `externalReportSource`. The runtime, not the model, binds the reporter and event reference. A `carried_forward` checkpoint retains that origin automatically.\n";
|
|
262926
262974
|
update_goal_default += "\nSet the proof `kind` to the exact capability of that call: `inspection` reads or searches, `integrity` compares bytes or hashes, `syntax` parses or type-checks, and `test` runs assertions. None of these alone proves a stronger kind. Use `reachability` only for a successful runtime probe that actually invokes the changed path and emits the exact marker `BLUN_EVIDENCE_KIND=reachability` after its assertions; loading a module without reaching the changed path is not reachability.\n";
|
|
262927
262975
|
update_goal_default += "\nBind each proof `scope` to the exact target measured by that successful call, never to a free-text claim or intended file. Read and search tools derive scope from their target arguments. For shell or command tools, include the same safe token `BLUN_EVIDENCE_SCOPE=<scope>` in the launched non-mutating verification command and emit it only after that exact target succeeds; the runtime requires both sides.\n";
|
|
262928
262976
|
update_goal_default += "\nFor a non-trivial or unfamiliar problem, preserve `problemFrame` with the success criterion, missing knowledge, bounded candidate actions, selected action and reason, support choice, risk, and reversibility. The selected action must match one candidate. Bind each selected action to the projected durable facts or assumptions it relies on by copying their explicit refs into `decisionBasis`. A stale or unknown decision basis requires replanning before execution. Problem framing is descriptive state and never grants permission.\n";
|
|
@@ -265674,9 +265722,9 @@ var init_agent = __esmMin((() => {
|
|
|
265674
265722
|
get rpcMethods() {
|
|
265675
265723
|
return {
|
|
265676
265724
|
prompt: (payload) => {
|
|
265677
|
-
this.turn.promptWithAcceptance(payload.input);
|
|
265725
|
+
this.turn.promptWithAcceptance(payload.input, payload.origin ?? USER_PROMPT_ORIGIN);
|
|
265678
265726
|
},
|
|
265679
|
-
promptAccepted: (payload) => this.turn.promptWithAcceptance(payload.input),
|
|
265727
|
+
promptAccepted: (payload) => this.turn.promptWithAcceptance(payload.input, payload.origin ?? USER_PROMPT_ORIGIN),
|
|
265680
265728
|
runShellCommand: (payload) => this.tools.runShellCommand(payload.command, payload.commandId),
|
|
265681
265729
|
cancelShellCommand: (payload) => this.tools.cancelShellCommand(payload.commandId),
|
|
265682
265730
|
steer: (payload) => {
|
|
@@ -326630,17 +326678,20 @@ var Session = class {
|
|
|
326630
326678
|
async prompt(input) {
|
|
326631
326679
|
await this.promptAccepted(input);
|
|
326632
326680
|
}
|
|
326633
|
-
async promptAccepted(input) {
|
|
326681
|
+
async promptAccepted(input, origin = USER_PROMPT_ORIGIN) {
|
|
326634
326682
|
this.ensureOpen();
|
|
326635
326683
|
const normalized = normalizePromptInput(input);
|
|
326684
|
+
const normalizedOrigin = origin && typeof origin === "object" ? origin : USER_PROMPT_ORIGIN;
|
|
326636
326685
|
const hasPromptAccepted = this.rpc.promptAccepted !== void 0;
|
|
326637
326686
|
return this.trackUserInputAcceptance(normalized, hasPromptAccepted ? () => this.rpc.promptAccepted({
|
|
326638
326687
|
sessionId: this.id,
|
|
326639
|
-
input: normalized
|
|
326688
|
+
input: normalized,
|
|
326689
|
+
origin: normalizedOrigin
|
|
326640
326690
|
}) : async () => {
|
|
326641
326691
|
await this.rpc.prompt({
|
|
326642
326692
|
sessionId: this.id,
|
|
326643
|
-
input: normalized
|
|
326693
|
+
input: normalized,
|
|
326694
|
+
origin: normalizedOrigin
|
|
326644
326695
|
});
|
|
326645
326696
|
return {
|
|
326646
326697
|
accepted: true,
|
|
@@ -327909,7 +327960,8 @@ var SDKRpcClientBase = class {
|
|
|
327909
327960
|
await rpc.prompt({
|
|
327910
327961
|
sessionId: input.sessionId,
|
|
327911
327962
|
agentId,
|
|
327912
|
-
input: input.input
|
|
327963
|
+
input: input.input,
|
|
327964
|
+
origin: input.origin
|
|
327913
327965
|
});
|
|
327914
327966
|
return {
|
|
327915
327967
|
accepted: true,
|
|
@@ -327920,7 +327972,8 @@ var SDKRpcClientBase = class {
|
|
|
327920
327972
|
return rpc.promptAccepted({
|
|
327921
327973
|
sessionId: input.sessionId,
|
|
327922
327974
|
agentId,
|
|
327923
|
-
input: input.input
|
|
327975
|
+
input: input.input,
|
|
327976
|
+
origin: input.origin
|
|
327924
327977
|
});
|
|
327925
327978
|
}
|
|
327926
327979
|
async runShellCommand(input) {
|
|
@@ -419162,12 +419215,14 @@ const CONTEXT_TRUNCATED_MARKER = "\n[Telegram-Kontext gekuerzt]";
|
|
|
419162
419215
|
function createChannelPreambleState() {
|
|
419163
419216
|
return {
|
|
419164
419217
|
sent: false,
|
|
419165
|
-
bufferedByChat: /* @__PURE__ */ new Map()
|
|
419218
|
+
bufferedByChat: /* @__PURE__ */ new Map(),
|
|
419219
|
+
reportSourcesByChat: /* @__PURE__ */ new Map()
|
|
419166
419220
|
};
|
|
419167
419221
|
}
|
|
419168
419222
|
function resetChannelPreambleState(state) {
|
|
419169
419223
|
state.sent = false;
|
|
419170
419224
|
state.bufferedByChat?.clear();
|
|
419225
|
+
state.reportSourcesByChat?.clear();
|
|
419171
419226
|
}
|
|
419172
419227
|
/** Structured metadata is authoritative; old queue envelopes use the tag note. */
|
|
419173
419228
|
function channelMessageAddressed(envelope) {
|
|
@@ -419177,21 +419232,35 @@ function channelMessageAddressed(envelope) {
|
|
|
419177
419232
|
if (addressed === "semantic") return true;
|
|
419178
419233
|
return !envelope.tag.includes("NUR MITLESEN");
|
|
419179
419234
|
}
|
|
419180
|
-
function bufferContext(state, chatId, tag) {
|
|
419235
|
+
function bufferContext(state, chatId, tag, reportSource) {
|
|
419181
419236
|
const buffers = state.bufferedByChat ?? /* @__PURE__ */ new Map();
|
|
419182
419237
|
state.bufferedByChat = buffers;
|
|
419238
|
+
const reportBuffers = state.reportSourcesByChat ?? /* @__PURE__ */ new Map();
|
|
419239
|
+
state.reportSourcesByChat = reportBuffers;
|
|
419183
419240
|
const messages = buffers.get(chatId) ?? [];
|
|
419241
|
+
const reports = reportBuffers.get(chatId) ?? [];
|
|
419184
419242
|
const projectedTag = projectUnaddressedTelegramContext(tag);
|
|
419185
419243
|
const boundedTag = projectedTag.length <= MAX_BUFFERED_CONTEXT_CHARS ? projectedTag : `${projectedTag.slice(0, MAX_BUFFERED_CONTEXT_CHARS - 28)}${CONTEXT_TRUNCATED_MARKER}`;
|
|
419186
419244
|
messages.push(boundedTag);
|
|
419245
|
+
reports.push(reportSource);
|
|
419187
419246
|
let chars = messages.reduce((sum, message) => sum + message.length, 0);
|
|
419188
|
-
while (messages.length > MAX_BUFFERED_CONTEXT_MESSAGES || chars > MAX_BUFFERED_CONTEXT_CHARS)
|
|
419247
|
+
while (messages.length > MAX_BUFFERED_CONTEXT_MESSAGES || chars > MAX_BUFFERED_CONTEXT_CHARS) {
|
|
419248
|
+
chars -= messages.shift()?.length ?? 0;
|
|
419249
|
+
reports.shift();
|
|
419250
|
+
}
|
|
419189
419251
|
buffers.set(chatId, messages);
|
|
419252
|
+
reportBuffers.set(chatId, reports);
|
|
419190
419253
|
}
|
|
419191
419254
|
/** Muted origin prefix for the transcript line, e.g. "Telegram · User". */
|
|
419192
419255
|
function channelOrigin(envelope) {
|
|
419193
419256
|
return `Telegram · ${envelope.meta.user ?? envelope.meta.chat_id}${envelope.meta["priority"] === "urgent" ? " · Dringend" : ""}`;
|
|
419194
419257
|
}
|
|
419258
|
+
function channelPromptOrigin(channelReportSources) {
|
|
419259
|
+
return {
|
|
419260
|
+
kind: "user",
|
|
419261
|
+
externalReportSources: channelReportSources
|
|
419262
|
+
};
|
|
419263
|
+
}
|
|
419195
419264
|
const TELEGRAM_REMOTE_COMMANDS = Object.freeze(["loop", "goal", "idea", "chancenradar", "curiosity", "scout", "reload", "memory", "befehle"]);
|
|
419196
419265
|
function telegramRemoteCommand(text) {
|
|
419197
419266
|
const trimmed = text.trim();
|
|
@@ -419213,24 +419282,35 @@ function telegramRemoteCommand(text) {
|
|
|
419213
419282
|
function injectChannelEnvelope(host, envelope, preamble) {
|
|
419214
419283
|
const origin = channelOrigin(envelope);
|
|
419215
419284
|
const contextOnly = !channelMessageAddressed(envelope);
|
|
419285
|
+
const reportSource = {
|
|
419286
|
+
source: "telegram",
|
|
419287
|
+
chatId: envelope.meta.chat_id,
|
|
419288
|
+
messageId: envelope.meta.message_id,
|
|
419289
|
+
reporter: envelope.meta.user,
|
|
419290
|
+
reporterId: envelope.meta.user_id,
|
|
419291
|
+
occurredAt: envelope.meta.ts
|
|
419292
|
+
};
|
|
419216
419293
|
if (contextOnly) {
|
|
419217
|
-
bufferContext(preamble, envelope.meta.chat_id, envelope.tag);
|
|
419294
|
+
bufferContext(preamble, envelope.meta.chat_id, envelope.tag, reportSource);
|
|
419218
419295
|
host.displayContext?.(envelope.text, origin);
|
|
419219
419296
|
return "buffered";
|
|
419220
419297
|
}
|
|
419221
419298
|
const modelParts = [...preamble.bufferedByChat?.get(envelope.meta.chat_id) ?? [], envelope.tag];
|
|
419299
|
+
const channelReportSources = [...preamble.reportSourcesByChat?.get(envelope.meta.chat_id) ?? [], reportSource];
|
|
419222
419300
|
if (!preamble.sent && envelope.preamble !== void 0 && envelope.preamble.length > 0) {
|
|
419223
419301
|
modelParts.unshift(envelope.preamble);
|
|
419224
419302
|
preamble.sent = true;
|
|
419225
419303
|
}
|
|
419226
419304
|
const modelInput = modelParts.join("\n\n");
|
|
419227
419305
|
if (!host.canDeliver() || host.isBusy()) {
|
|
419228
|
-
host.enqueue(modelInput, envelope.text, origin, contextOnly);
|
|
419306
|
+
host.enqueue(modelInput, envelope.text, origin, contextOnly, channelReportSources);
|
|
419229
419307
|
preamble.bufferedByChat?.delete(envelope.meta.chat_id);
|
|
419308
|
+
preamble.reportSourcesByChat?.delete(envelope.meta.chat_id);
|
|
419230
419309
|
return "queued";
|
|
419231
419310
|
}
|
|
419232
|
-
host.deliverNow(modelInput, envelope.text, origin, contextOnly);
|
|
419311
|
+
host.deliverNow(modelInput, envelope.text, origin, contextOnly, channelReportSources);
|
|
419233
419312
|
preamble.bufferedByChat?.delete(envelope.meta.chat_id);
|
|
419313
|
+
preamble.reportSourcesByChat?.delete(envelope.meta.chat_id);
|
|
419234
419314
|
return "delivered";
|
|
419235
419315
|
}
|
|
419236
419316
|
/** Parse one queue line defensively — a malformed line must never crash the TUI. */
|
|
@@ -517656,10 +517736,10 @@ var BlunTUI = class {
|
|
|
517656
517736
|
injectChannelEnvelope({
|
|
517657
517737
|
canDeliver: () => this.session !== void 0 && this.state.appState.model.trim().length > 0,
|
|
517658
517738
|
isBusy: () => this.state.queuedMessages.length > 0 || this.queueSteerInFlight !== void 0 || this.deferUserMessages || this.streamingUI.hasActiveTurn() || this.state.appState.streamingPhase !== "idle" || this.state.appState.isCompacting,
|
|
517659
|
-
deliverNow: (modelInput, displayText, origin, contextOnly) => {
|
|
517660
|
-
this.sendChannelMessageInternal(this.requireSession(), modelInput, displayText, origin, routedEnvelope.meta.chat_id, routedEnvelope.meta["image_path"], contextOnly, false, acknowledge, false, void 0, directEnvelope !== void 0, directFocus.resumeGranted);
|
|
517739
|
+
deliverNow: (modelInput, displayText, origin, contextOnly, channelReportSources) => {
|
|
517740
|
+
this.sendChannelMessageInternal(this.requireSession(), modelInput, displayText, origin, routedEnvelope.meta.chat_id, routedEnvelope.meta["image_path"], contextOnly, false, acknowledge, false, void 0, directEnvelope !== void 0, directFocus.resumeGranted, channelReportSources);
|
|
517661
517741
|
},
|
|
517662
|
-
enqueue: (modelInput, displayText, origin, contextOnly) => {
|
|
517742
|
+
enqueue: (modelInput, displayText, origin, contextOnly, channelReportSources) => {
|
|
517663
517743
|
const item = {
|
|
517664
517744
|
text: modelInput,
|
|
517665
517745
|
displayText,
|
|
@@ -517667,6 +517747,7 @@ var BlunTUI = class {
|
|
|
517667
517747
|
agentId: this.harness.interactiveAgentId,
|
|
517668
517748
|
mode: "channel",
|
|
517669
517749
|
channelChatId: routedEnvelope.meta.chat_id,
|
|
517750
|
+
channelReportSources: channelReportSources,
|
|
517670
517751
|
channelContextOnly: contextOnly,
|
|
517671
517752
|
channelAcknowledge: acknowledge,
|
|
517672
517753
|
...urgentEnvelope !== void 0 ? { channelUrgent: true } : {},
|
|
@@ -517826,7 +517907,7 @@ var BlunTUI = class {
|
|
|
517826
517907
|
this.failSessionRequest(uiText("blunTui.session.sendFailed", { error: formatErrorMessage$2(error) }));
|
|
517827
517908
|
});
|
|
517828
517909
|
}
|
|
517829
|
-
sendChannelMessageInternal(session, modelInput, displayText, origin, channelChatId, channelImagePath, contextOnly = false, transcriptRendered = false, acknowledge, channelAttention = false, queueKey, channelDirect = false, channelDirectResume = false) {
|
|
517910
|
+
sendChannelMessageInternal(session, modelInput, displayText, origin, channelChatId, channelImagePath, contextOnly = false, transcriptRendered = false, acknowledge, channelAttention = false, queueKey, channelDirect = false, channelDirectResume = false, channelReportSources = []) {
|
|
517830
517911
|
armPersonalMemoryRememberIntent(session.id, displayText, {
|
|
517831
517912
|
permissionMode: this.state.appState.permissionMode,
|
|
517832
517913
|
channel: true
|
|
@@ -517860,7 +517941,7 @@ var BlunTUI = class {
|
|
|
517860
517941
|
type: "text",
|
|
517861
517942
|
text: focusedModelInput
|
|
517862
517943
|
}, imagePart] : focusedModelInput;
|
|
517863
|
-
session.promptAccepted(promptInput).then((result) => {
|
|
517944
|
+
session.promptAccepted(promptInput, channelPromptOrigin(channelReportSources)).then((result) => {
|
|
517864
517945
|
if (result.accepted) {
|
|
517865
517946
|
acknowledge?.();
|
|
517866
517947
|
return;
|
|
@@ -517873,6 +517954,7 @@ var BlunTUI = class {
|
|
|
517873
517954
|
agentId: this.harness.interactiveAgentId,
|
|
517874
517955
|
mode: "channel",
|
|
517875
517956
|
channelChatId,
|
|
517957
|
+
channelReportSources: channelReportSources,
|
|
517876
517958
|
channelContextOnly: contextOnly,
|
|
517877
517959
|
channelTranscriptRendered: true,
|
|
517878
517960
|
channelAcknowledge: acknowledge,
|
|
@@ -518236,7 +518318,7 @@ var BlunTUI = class {
|
|
|
518236
518318
|
const activeSession = this.session ?? session;
|
|
518237
518319
|
if (item.mode === "channel") {
|
|
518238
518320
|
this.harness.withInteractiveAgent(item.agentId ?? "main", () => {
|
|
518239
|
-
this.sendChannelMessageInternal(activeSession, item.text, item.displayText ?? "", item.origin, item.channelChatId, item.channelImagePath, item.channelContextOnly, item.channelTranscriptRendered, item.channelAcknowledge, item.channelAttention, item.queueKey, item.channelDirect, item.channelDirectResume);
|
|
518321
|
+
this.sendChannelMessageInternal(activeSession, item.text, item.displayText ?? "", item.origin, item.channelChatId, item.channelImagePath, item.channelContextOnly, item.channelTranscriptRendered, item.channelAcknowledge, item.channelAttention, item.queueKey, item.channelDirect, item.channelDirectResume, item.channelReportSources);
|
|
518240
518322
|
});
|
|
518241
518323
|
return;
|
|
518242
518324
|
}
|