@animalabs/agent-framework 0.27.0 → 0.28.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/README.md +56 -15
- package/dist/src/agent.d.ts +29 -2
- package/dist/src/agent.d.ts.map +1 -1
- package/dist/src/agent.js +69 -11
- package/dist/src/agent.js.map +1 -1
- package/dist/src/api/server.d.ts.map +1 -1
- package/dist/src/api/server.js +4 -2
- package/dist/src/api/server.js.map +1 -1
- package/dist/src/auto-continue.d.ts +3 -2
- package/dist/src/auto-continue.d.ts.map +1 -1
- package/dist/src/auto-continue.js +4 -3
- package/dist/src/auto-continue.js.map +1 -1
- package/dist/src/cut-off-round.d.ts +24 -0
- package/dist/src/cut-off-round.d.ts.map +1 -0
- package/dist/src/cut-off-round.js +87 -0
- package/dist/src/cut-off-round.js.map +1 -0
- package/dist/src/framework.d.ts +304 -89
- package/dist/src/framework.d.ts.map +1 -1
- package/dist/src/framework.js +2577 -678
- package/dist/src/framework.js.map +1 -1
- package/dist/src/gate/event-gate.d.ts +99 -3
- package/dist/src/gate/event-gate.d.ts.map +1 -1
- package/dist/src/gate/event-gate.js +538 -13
- package/dist/src/gate/event-gate.js.map +1 -1
- package/dist/src/gate/index.d.ts +2 -1
- package/dist/src/gate/index.d.ts.map +1 -1
- package/dist/src/gate/index.js +1 -0
- package/dist/src/gate/index.js.map +1 -1
- package/dist/src/gate/reply-judge.d.ts +116 -0
- package/dist/src/gate/reply-judge.d.ts.map +1 -0
- package/dist/src/gate/reply-judge.js +467 -0
- package/dist/src/gate/reply-judge.js.map +1 -0
- package/dist/src/gate/types.d.ts +161 -0
- package/dist/src/gate/types.d.ts.map +1 -1
- package/dist/src/heartbeat/heartbeat.d.ts +184 -0
- package/dist/src/heartbeat/heartbeat.d.ts.map +1 -0
- package/dist/src/heartbeat/heartbeat.js +752 -0
- package/dist/src/heartbeat/heartbeat.js.map +1 -0
- package/dist/src/heartbeat/reminder-time.d.ts +5 -0
- package/dist/src/heartbeat/reminder-time.d.ts.map +1 -0
- package/dist/src/heartbeat/reminder-time.js +107 -0
- package/dist/src/heartbeat/reminder-time.js.map +1 -0
- package/dist/src/index.d.ts +4 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/mcpl/capability-mask.d.ts.map +1 -1
- package/dist/src/mcpl/capability-mask.js +3 -2
- package/dist/src/mcpl/capability-mask.js.map +1 -1
- package/dist/src/mcpl/channel-registry.d.ts.map +1 -1
- package/dist/src/mcpl/channel-registry.js +2 -1
- package/dist/src/mcpl/channel-registry.js.map +1 -1
- package/dist/src/mcpl/inbound-source.d.ts +26 -10
- package/dist/src/mcpl/inbound-source.d.ts.map +1 -1
- package/dist/src/mcpl/inbound-source.js +40 -69
- package/dist/src/mcpl/inbound-source.js.map +1 -1
- package/dist/src/mcpl/server-connection.d.ts +18 -8
- package/dist/src/mcpl/server-connection.d.ts.map +1 -1
- package/dist/src/mcpl/server-connection.js +50 -10
- package/dist/src/mcpl/server-connection.js.map +1 -1
- package/dist/src/mcpl/tags.d.ts +9 -2
- package/dist/src/mcpl/tags.d.ts.map +1 -1
- package/dist/src/mcpl/tags.js +12 -2
- package/dist/src/mcpl/tags.js.map +1 -1
- package/dist/src/mcpl/tool-presence.d.ts +66 -14
- package/dist/src/mcpl/tool-presence.d.ts.map +1 -1
- package/dist/src/mcpl/tool-presence.js +134 -65
- package/dist/src/mcpl/tool-presence.js.map +1 -1
- package/dist/src/mcpl/tool-signature.d.ts +10 -3
- package/dist/src/mcpl/tool-signature.d.ts.map +1 -1
- package/dist/src/mcpl/tool-signature.js +47 -18
- package/dist/src/mcpl/tool-signature.js.map +1 -1
- package/dist/src/mcpl/toolset-host.d.ts +88 -37
- package/dist/src/mcpl/toolset-host.d.ts.map +1 -1
- package/dist/src/mcpl/toolset-host.js +207 -108
- package/dist/src/mcpl/toolset-host.js.map +1 -1
- package/dist/src/mcpl/toolsets-module.d.ts +14 -11
- package/dist/src/mcpl/toolsets-module.d.ts.map +1 -1
- package/dist/src/mcpl/toolsets-module.js +141 -49
- package/dist/src/mcpl/toolsets-module.js.map +1 -1
- package/dist/src/mcpl/types.d.ts +3 -1
- package/dist/src/mcpl/types.d.ts.map +1 -1
- package/dist/src/mcpl/types.js.map +1 -1
- package/dist/src/module-registry.d.ts +4 -1
- package/dist/src/module-registry.d.ts.map +1 -1
- package/dist/src/module-registry.js +9 -2
- package/dist/src/module-registry.js.map +1 -1
- package/dist/src/modules/history/index.d.ts.map +1 -1
- package/dist/src/modules/history/index.js +22 -11
- package/dist/src/modules/history/index.js.map +1 -1
- package/dist/src/modules/workspace/answers.d.ts +22 -0
- package/dist/src/modules/workspace/answers.d.ts.map +1 -0
- package/dist/src/modules/workspace/answers.js +123 -0
- package/dist/src/modules/workspace/answers.js.map +1 -0
- package/dist/src/modules/workspace/branch-intent.d.ts +5 -3
- package/dist/src/modules/workspace/branch-intent.d.ts.map +1 -1
- package/dist/src/modules/workspace/branch-intent.js +6 -2
- package/dist/src/modules/workspace/branch-intent.js.map +1 -1
- package/dist/src/modules/workspace/direct-write.d.ts +3 -0
- package/dist/src/modules/workspace/direct-write.d.ts.map +1 -1
- package/dist/src/modules/workspace/direct-write.js +57 -24
- package/dist/src/modules/workspace/direct-write.js.map +1 -1
- package/dist/src/modules/workspace/disk-agreement.d.ts +33 -11
- package/dist/src/modules/workspace/disk-agreement.d.ts.map +1 -1
- package/dist/src/modules/workspace/disk-agreement.js +48 -17
- package/dist/src/modules/workspace/disk-agreement.js.map +1 -1
- package/dist/src/modules/workspace/edit-text.d.ts +2 -1
- package/dist/src/modules/workspace/edit-text.d.ts.map +1 -1
- package/dist/src/modules/workspace/edit-text.js +4 -2
- package/dist/src/modules/workspace/edit-text.js.map +1 -1
- package/dist/src/modules/workspace/effects.d.ts.map +1 -1
- package/dist/src/modules/workspace/effects.js +20 -13
- package/dist/src/modules/workspace/effects.js.map +1 -1
- package/dist/src/modules/workspace/index.d.ts +62 -51
- package/dist/src/modules/workspace/index.d.ts.map +1 -1
- package/dist/src/modules/workspace/index.js +934 -531
- package/dist/src/modules/workspace/index.js.map +1 -1
- package/dist/src/modules/workspace/observe.d.ts +75 -63
- package/dist/src/modules/workspace/observe.d.ts.map +1 -1
- package/dist/src/modules/workspace/observe.js +366 -180
- package/dist/src/modules/workspace/observe.js.map +1 -1
- package/dist/src/modules/workspace/read-page.d.ts.map +1 -1
- package/dist/src/modules/workspace/read-page.js +7 -1
- package/dist/src/modules/workspace/read-page.js.map +1 -1
- package/dist/src/modules/workspace/reconcile.d.ts.map +1 -1
- package/dist/src/modules/workspace/reconcile.js +26 -16
- package/dist/src/modules/workspace/reconcile.js.map +1 -1
- package/dist/src/modules/workspace/result-text.d.ts +1 -0
- package/dist/src/modules/workspace/result-text.d.ts.map +1 -1
- package/dist/src/modules/workspace/result-text.js.map +1 -1
- package/dist/src/modules/workspace/sync.d.ts +9 -0
- package/dist/src/modules/workspace/sync.d.ts.map +1 -1
- package/dist/src/modules/workspace/sync.js +14 -0
- package/dist/src/modules/workspace/sync.js.map +1 -1
- package/dist/src/modules/workspace/types.d.ts +96 -43
- package/dist/src/modules/workspace/types.d.ts.map +1 -1
- package/dist/src/modules/workspace/types.js.map +1 -1
- package/dist/src/modules/workspace/watcher.d.ts.map +1 -1
- package/dist/src/modules/workspace/watcher.js +8 -3
- package/dist/src/modules/workspace/watcher.js.map +1 -1
- package/dist/src/prose-drafts.d.ts +4 -3
- package/dist/src/prose-drafts.d.ts.map +1 -1
- package/dist/src/prose-drafts.js +3 -2
- package/dist/src/prose-drafts.js.map +1 -1
- package/dist/src/reasoning-loss-notice.d.ts +23 -0
- package/dist/src/reasoning-loss-notice.d.ts.map +1 -0
- package/dist/src/reasoning-loss-notice.js +50 -0
- package/dist/src/reasoning-loss-notice.js.map +1 -0
- package/dist/src/reasoning-loss.d.ts +24 -0
- package/dist/src/reasoning-loss.d.ts.map +1 -0
- package/dist/src/reasoning-loss.js +102 -0
- package/dist/src/reasoning-loss.js.map +1 -0
- package/dist/src/send-tools.d.ts +3 -2
- package/dist/src/send-tools.d.ts.map +1 -1
- package/dist/src/send-tools.js +3 -2
- package/dist/src/send-tools.js.map +1 -1
- package/dist/src/sent-rows.js +1 -1
- package/dist/src/thinking-drops.d.ts +4 -11
- package/dist/src/thinking-drops.d.ts.map +1 -1
- package/dist/src/thinking-drops.js +7 -14
- package/dist/src/thinking-drops.js.map +1 -1
- package/dist/src/tool-args.d.ts +12 -0
- package/dist/src/tool-args.d.ts.map +1 -1
- package/dist/src/tool-args.js +35 -1
- package/dist/src/tool-args.js.map +1 -1
- package/dist/src/tool-result-guard.d.ts +8 -4
- package/dist/src/tool-result-guard.d.ts.map +1 -1
- package/dist/src/tool-result-guard.js +23 -11
- package/dist/src/tool-result-guard.js.map +1 -1
- package/dist/src/tune-out/tools.d.ts +4 -1
- package/dist/src/tune-out/tools.d.ts.map +1 -1
- package/dist/src/types/agent.d.ts +40 -9
- package/dist/src/types/agent.d.ts.map +1 -1
- package/dist/src/types/events.d.ts +18 -8
- package/dist/src/types/events.d.ts.map +1 -1
- package/dist/src/types/framework.d.ts +15 -0
- package/dist/src/types/framework.d.ts.map +1 -1
- package/dist/src/types/module.d.ts +5 -2
- package/dist/src/types/module.d.ts.map +1 -1
- package/dist/src/types/trace.d.ts +34 -1
- package/dist/src/types/trace.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/agent.ts +72 -11
- package/src/api/server.ts +4 -2
- package/src/auto-continue.ts +4 -3
- package/src/cut-off-round.ts +98 -0
- package/src/framework.ts +2694 -700
- package/src/gate/event-gate.ts +579 -15
- package/src/gate/index.ts +8 -0
- package/src/gate/reply-judge.ts +512 -0
- package/src/gate/types.ts +164 -1
- package/src/heartbeat/heartbeat.ts +804 -0
- package/src/heartbeat/reminder-time.ts +107 -0
- package/src/index.ts +4 -0
- package/src/mcpl/capability-mask.ts +3 -2
- package/src/mcpl/channel-registry.ts +2 -1
- package/src/mcpl/inbound-source.ts +42 -69
- package/src/mcpl/server-connection.ts +56 -16
- package/src/mcpl/tags.ts +13 -2
- package/src/mcpl/tool-presence.ts +133 -67
- package/src/mcpl/tool-signature.ts +51 -20
- package/src/mcpl/toolset-host.ts +197 -107
- package/src/mcpl/toolsets-module.ts +143 -49
- package/src/mcpl/types.ts +3 -1
- package/src/module-registry.ts +8 -2
- package/src/modules/history/index.ts +22 -12
- package/src/modules/workspace/answers.ts +133 -0
- package/src/modules/workspace/branch-intent.ts +10 -5
- package/src/modules/workspace/direct-write.ts +58 -23
- package/src/modules/workspace/disk-agreement.ts +52 -21
- package/src/modules/workspace/edit-text.ts +7 -5
- package/src/modules/workspace/effects.ts +21 -12
- package/src/modules/workspace/index.ts +927 -541
- package/src/modules/workspace/observe.ts +381 -177
- package/src/modules/workspace/read-page.ts +7 -1
- package/src/modules/workspace/reconcile.ts +27 -15
- package/src/modules/workspace/result-text.ts +2 -0
- package/src/modules/workspace/sync.ts +16 -0
- package/src/modules/workspace/types.ts +96 -43
- package/src/modules/workspace/watcher.ts +8 -3
- package/src/prose-drafts.ts +4 -3
- package/src/reasoning-loss-notice.ts +62 -0
- package/src/reasoning-loss.ts +120 -0
- package/src/send-tools.ts +3 -2
- package/src/sent-rows.ts +1 -1
- package/src/thinking-drops.ts +10 -16
- package/src/tool-args.ts +34 -1
- package/src/tool-result-guard.ts +26 -11
- package/src/tune-out/tools.ts +4 -1
- package/src/types/agent.ts +40 -9
- package/src/types/events.ts +18 -8
- package/src/types/framework.ts +15 -0
- package/src/types/module.ts +5 -2
- package/src/types/trace.ts +36 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ToolResult } from '../../types/events.js';
|
|
2
2
|
import { answerText, fieldLine, sectionLead, sectionText, textAnswer } from './result-text.js';
|
|
3
3
|
import { type FileText, MAX_LINE_CHARS, numberedLine, safeCut } from './text.js';
|
|
4
|
+
import { didNothing } from './answers.js';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* One page of a read, held to the result limit as its text measures it: a
|
|
@@ -184,7 +185,12 @@ export function characterPage(path: string, file: FileText, offsetChars: number,
|
|
|
184
185
|
const text = file.raw;
|
|
185
186
|
const start = Math.min(offsetChars, text.length);
|
|
186
187
|
if (splitsPair(text, start)) {
|
|
187
|
-
return {
|
|
188
|
+
return {
|
|
189
|
+
success: false,
|
|
190
|
+
isError: true,
|
|
191
|
+
error: didNothing('read', `"offsetChars" ${start} falls between the two halves of a surrogate pair, one character in UTF-16. `
|
|
192
|
+
+ `Give ${start - 1} or ${start + 1}; a page's nextOffsetChars never splits one.`),
|
|
193
|
+
};
|
|
188
194
|
}
|
|
189
195
|
let end = start + Math.min(limitChars, text.length - start);
|
|
190
196
|
if (splitsPair(text, end)) end++;
|
|
@@ -53,9 +53,11 @@ import {
|
|
|
53
53
|
sameRootIdentity,
|
|
54
54
|
} from './disk-agreement.js';
|
|
55
55
|
import type { BranchIntent, BranchIntents, ConflictKind, ConflictRecord, DiskCounterpart } from './branch-intent.js';
|
|
56
|
+
import { storedBytes, type StoredBytes } from './sync.js';
|
|
56
57
|
import {
|
|
57
58
|
IGNORED,
|
|
58
59
|
type MountView,
|
|
60
|
+
NOT_A_DIRECTORY,
|
|
59
61
|
OTHER_MOUNT,
|
|
60
62
|
ROOT_REPLACED,
|
|
61
63
|
type Walk,
|
|
@@ -75,6 +77,7 @@ import {
|
|
|
75
77
|
withinIncludes,
|
|
76
78
|
} from './observe.js';
|
|
77
79
|
import { EffectFailed, type Expect, chainOf, chmodContained, narrowedTo, syncDirectories, unlinkContained, writeContained } from './effects.js';
|
|
80
|
+
import { errnoWords } from './answers.js';
|
|
78
81
|
|
|
79
82
|
export type EntryState =
|
|
80
83
|
| 'synced'
|
|
@@ -486,7 +489,7 @@ function inTheWay(reason: string | undefined, deletion: boolean): string | null
|
|
|
486
489
|
}
|
|
487
490
|
// A deletion below a file finds nothing there to unlink, so only a write
|
|
488
491
|
// meets this one.
|
|
489
|
-
if (reason ===
|
|
492
|
+
if (reason === NOT_A_DIRECTORY) {
|
|
490
493
|
return 'disk has a file or a symlink where this path needs a directory, and no push writes below one, forced or not — ' +
|
|
491
494
|
'move or remove it on disk and materialize again, or write the file under another path';
|
|
492
495
|
}
|
|
@@ -506,7 +509,7 @@ function inTheWay(reason: string | undefined, deletion: boolean): string | null
|
|
|
506
509
|
* to pass.
|
|
507
510
|
*/
|
|
508
511
|
function forcedWay(note: string | undefined, deletion: boolean, forced: string): string {
|
|
509
|
-
if (note ===
|
|
512
|
+
if (note === `cannot open (${errnoWords('EACCES')})`) return `, or, if disk lets the workspace ${deletion ? 'unlink' : 'write'} the file, ${forced}`;
|
|
510
513
|
return '';
|
|
511
514
|
}
|
|
512
515
|
|
|
@@ -914,8 +917,8 @@ async function gather(store: JsStore, agreement: DiskAgreement, mount: MountRunt
|
|
|
914
917
|
byDesign = OTHER_MOUNT;
|
|
915
918
|
} else if (!opts.named) {
|
|
916
919
|
const slash = path.lastIndexOf('/');
|
|
917
|
-
const above = slash < 0 ? undefined : passedOverAt(path.slice(0, slash), mount.view.ignore, mount.view.others);
|
|
918
|
-
const own = above === undefined && !walk ? passedOverAt(path, mount.view.ignore, mount.view.others) : undefined;
|
|
920
|
+
const above = slash < 0 ? undefined : passedOverAt(path.slice(0, slash), mount.view.ignore, mount.view.others, true);
|
|
921
|
+
const own = above === undefined && !walk ? passedOverAt(path, mount.view.ignore, mount.view.others, false) : undefined;
|
|
919
922
|
byDesign = above ?? own;
|
|
920
923
|
} else if (scope.kind === 'dir') {
|
|
921
924
|
byDesign = passedOverBetween(scope.dir, path, ignoreBeneath(scope.dir, mount.view.ignore), mount.view.others);
|
|
@@ -1028,9 +1031,13 @@ export async function reconcilePass(
|
|
|
1028
1031
|
}
|
|
1029
1032
|
|
|
1030
1033
|
// The evidence about to be recorded describes the root it was gathered
|
|
1031
|
-
// under, which is recorded first
|
|
1032
|
-
//
|
|
1033
|
-
|
|
1034
|
+
// under, which is recorded first, so no crash can leave evidence without
|
|
1035
|
+
// its root. Once a root is recorded, every pass that found it offers it,
|
|
1036
|
+
// evidence or none: the same root on a new device, or with its first
|
|
1037
|
+
// birth time, is recorded again (recordRootIdentity writes nothing
|
|
1038
|
+
// otherwise), and a quiet mount's passes are where an old record learns
|
|
1039
|
+
// its birth time.
|
|
1040
|
+
if (gathered.rootIdentity && (agreement.rootIdentity(mount.name) !== undefined || planned.some((x) => x.verdict.adopt !== undefined || x.verdict.p !== undefined))) {
|
|
1034
1041
|
agreement.recordRootIdentity(mount.name, gathered.rootIdentity);
|
|
1035
1042
|
}
|
|
1036
1043
|
|
|
@@ -1386,12 +1393,12 @@ export async function pushPaths(
|
|
|
1386
1393
|
continue;
|
|
1387
1394
|
}
|
|
1388
1395
|
const priorP = p && (p.kind === 'absent' || p.kind === 'content') ? p : null;
|
|
1389
|
-
const
|
|
1396
|
+
const stored = storedBytes(store, s.hash);
|
|
1390
1397
|
const forcedMode = mount.modesObserved && s.mode !== undefined && s.mode !== (d.kind === 'file' ? d.mode : undefined) ? s.mode : undefined;
|
|
1391
1398
|
const agreedMode = priorP?.kind === 'content' ? priorP.mode : undefined;
|
|
1392
|
-
if (
|
|
1399
|
+
if ('bytes' in stored) {
|
|
1393
1400
|
plans.push({
|
|
1394
|
-
path, kind: 'write', blob, hash: s.hash, prior: priorP, before: agreement.get(mount.name, path), expect,
|
|
1401
|
+
path, kind: 'write', blob: stored.bytes, hash: s.hash, prior: priorP, before: agreement.get(mount.name, path), expect,
|
|
1395
1402
|
...(forcedMode !== undefined ? { apply: forcedMode } : {}),
|
|
1396
1403
|
...(forcedMode !== undefined && d.kind === 'file' && agreedMode !== d.mode ? { overDisk: true as const } : {}),
|
|
1397
1404
|
...(s.mode !== undefined ? { storeMode: s.mode } : {}),
|
|
@@ -1400,7 +1407,7 @@ export async function pushPaths(
|
|
|
1400
1407
|
...(agreedMode !== undefined ? { priorMode: agreedMode } : {}),
|
|
1401
1408
|
...(d.kind === 'file' && d.mode !== undefined ? { seenMode: d.mode } : {}),
|
|
1402
1409
|
});
|
|
1403
|
-
} else result.skipped.push({ path, reason:
|
|
1410
|
+
} else result.skipped.push({ path, reason: unstoredCopy(stored) });
|
|
1404
1411
|
continue;
|
|
1405
1412
|
}
|
|
1406
1413
|
if (v.mode === 'adopt' && s && d.kind === 'file') {
|
|
@@ -1426,7 +1433,7 @@ export async function pushPaths(
|
|
|
1426
1433
|
}
|
|
1427
1434
|
// Whatever the verdict learned about disk (an agreement, a resolved
|
|
1428
1435
|
// intent) is recorded before anything is pushed over it, and the root it
|
|
1429
|
-
// was learned under before that
|
|
1436
|
+
// was learned under before that, as a pass does.
|
|
1430
1437
|
if (v.p !== undefined) agreement.recordRootIdentity(mount.name, root.identity);
|
|
1431
1438
|
if (v.p === 'forget') agreement.forget(mount.name, path);
|
|
1432
1439
|
else if (v.p !== undefined) agreement.set(mount.name, path, v.p, { afterCommittedState: true });
|
|
@@ -1551,11 +1558,12 @@ export async function pushPaths(
|
|
|
1551
1558
|
plans.push({ path, kind: 'unlink', prior, before: agreement.get(mount.name, path), expect });
|
|
1552
1559
|
continue;
|
|
1553
1560
|
}
|
|
1554
|
-
const
|
|
1555
|
-
if (!
|
|
1556
|
-
result.skipped.push({ path, reason:
|
|
1561
|
+
const stored = storedBytes(store, s.hash);
|
|
1562
|
+
if (!('bytes' in stored)) {
|
|
1563
|
+
result.skipped.push({ path, reason: unstoredCopy(stored) });
|
|
1557
1564
|
continue;
|
|
1558
1565
|
}
|
|
1566
|
+
const blob = stored.bytes;
|
|
1559
1567
|
// The store's mode goes to disk with its bytes where the file is new,
|
|
1560
1568
|
// the push is forced, or disk still has the mode they last agreed on. A
|
|
1561
1569
|
// push that completes our own unconfirmed one, whose bytes landed, is a
|
|
@@ -1774,3 +1782,7 @@ export async function pushPaths(
|
|
|
1774
1782
|
agreement.maybeCheckpoint();
|
|
1775
1783
|
return result;
|
|
1776
1784
|
}
|
|
1785
|
+
|
|
1786
|
+
function unstoredCopy(stored: Exclude<StoredBytes, { bytes: Buffer }>): string {
|
|
1787
|
+
return 'missing' in stored ? 'the workspace copy is missing from the store' : `the workspace copy is unreadable in the store (${stored.unreadable})`;
|
|
1788
|
+
}
|
|
@@ -30,6 +30,8 @@ export function shownValue(value: string | number | boolean | null): string {
|
|
|
30
30
|
return JSON.stringify(value).replace(/[\u0085\u2028\u2029]/g, (c) => `\\u${c.charCodeAt(0).toString(16).padStart(4, '0')}`);
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
export type DiskState = 'done' | 'waits for materialize' | 'waits for materialize with applyDeletions' | 'in conflict with disk';
|
|
34
|
+
|
|
33
35
|
/** A header line: a field's key and its value as shownValue writes it. */
|
|
34
36
|
export const fieldLine = (key: string, value: string | number | boolean | null): string => `${key}: ${shownValue(value)}`;
|
|
35
37
|
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import { createHash } from 'node:crypto';
|
|
9
|
+
import type { JsStore } from '@animalabs/chronicle';
|
|
9
10
|
|
|
10
11
|
export const DEFAULT_MAX_FILE_SIZE = 5 * 1024 * 1024; // 5MB
|
|
11
12
|
|
|
@@ -18,3 +19,18 @@ export function hashContent(content: string | Buffer): string {
|
|
|
18
19
|
hash.update(content);
|
|
19
20
|
return hash.digest('hex');
|
|
20
21
|
}
|
|
22
|
+
|
|
23
|
+
export type StoredBytes = { bytes: Buffer } | { missing: true } | { unreadable: string };
|
|
24
|
+
|
|
25
|
+
export function storedBytes(store: JsStore, hash: string): StoredBytes {
|
|
26
|
+
try {
|
|
27
|
+
const blob = store.getBlob(hash);
|
|
28
|
+
return blob ? { bytes: blob } : { missing: true };
|
|
29
|
+
} catch (error) {
|
|
30
|
+
if (store.isClosed()) throw error;
|
|
31
|
+
// Chronicle's getBlob throws, rather than answering null, for a blob file
|
|
32
|
+
// it can't read whole or whose format, checksum or hash doesn't check out,
|
|
33
|
+
// such as one a write cut short left truncated.
|
|
34
|
+
return { unreadable: error instanceof Error ? error.message : String(error) };
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -58,7 +58,7 @@ export interface MountConfig {
|
|
|
58
58
|
* link is read and written where it leads now. Where that root now lies
|
|
59
59
|
* elsewhere than the last start placed it, each call nests in it, as a
|
|
60
60
|
* start would now, every mount
|
|
61
|
-
* configured beneath its path, where that path leads beneath its root,
|
|
61
|
+
* configured on or beneath its path, where that path leads beneath its root,
|
|
62
62
|
* and every other mount whose root, as that start placed it, lies
|
|
63
63
|
* beneath where its root lies now, or whose configured path lies
|
|
64
64
|
* beneath a directory that start found there. A mount configured
|
|
@@ -101,10 +101,32 @@ export interface MountConfig {
|
|
|
101
101
|
/** Poll interval in ms for checking watched root identity changes (default: 2000) */
|
|
102
102
|
watchRootPollMs?: number;
|
|
103
103
|
/**
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
104
|
+
* Patterns in these of gitignore's forms, each covering the files
|
|
105
|
+
* gitignore's reading of it covers, with three differences: names compare
|
|
106
|
+
* exactly, as git's do with `core.ignorecase` off (its default folds case
|
|
107
|
+
* on macOS and Windows); "?" matches one character where git's matches
|
|
108
|
+
* one byte, so the two differ on names outside ASCII; and on a mount that
|
|
109
|
+
* follows links, a link to a directory counts as a directory, where git
|
|
110
|
+
* reads every link as a file:
|
|
111
|
+
* - A name, matched at any depth: ".git", "node_modules". Within a name,
|
|
112
|
+
* "*" matches any run of characters and "?" any one: "*.pyc",
|
|
113
|
+
* "npm-debug.log*".
|
|
114
|
+
* - A trailing "/" matches only a directory: "build/" covers every
|
|
115
|
+
* directory named build, with what lies beneath it, and no file of that
|
|
116
|
+
* name.
|
|
117
|
+
* - A leading or inner "/" makes a path from the mount's root: "/dist"
|
|
118
|
+
* covers only the root's dist, and "a/b" only the root's a/b.
|
|
119
|
+
* - "**" as the first segment, before one name, matches that name at any
|
|
120
|
+
* depth, as the name alone does; with a trailing "/**" as well, it reads
|
|
121
|
+
* as the name with a trailing "/".
|
|
122
|
+
* - A trailing "/**" covers a directory from the root and what lies
|
|
123
|
+
* beneath it: "node_modules/**" covers only the root's node_modules, and
|
|
124
|
+
* no file of that name.
|
|
125
|
+
* The module refuses, when it's built, a pattern of any other form, such as
|
|
126
|
+
* a leading "!" or "#", a "[", a "\", a trailing space, "**" anywhere
|
|
127
|
+
* else, or an empty, "." or ".." segment, naming the pattern and why. A
|
|
128
|
+
* "?" can stand for a "[" or "\" in a name.
|
|
129
|
+
*
|
|
108
130
|
* A sync without a path and the watcher pass over what the list covers,
|
|
109
131
|
* and over entries with an editor's swap or backup file name whatever it
|
|
110
132
|
* says, a directory with what lies beneath it: `.name.swp` and `.name.swx`
|
|
@@ -124,13 +146,17 @@ export interface MountConfig {
|
|
|
124
146
|
ignore?: string[];
|
|
125
147
|
/**
|
|
126
148
|
* The files this mount holds, when it holds only some of what is under its
|
|
127
|
-
* path:
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
149
|
+
* path: patterns in `ignore`'s forms, read for files, and a `[` read as
|
|
150
|
+
* itself, so `[id].tsx` names that file. A pattern that matches
|
|
151
|
+
* only directories, with a trailing `/` or `/**`, covers what lies beneath a
|
|
152
|
+
* directory it matches: `fixtures/` every file beneath a directory named
|
|
153
|
+
* fixtures, at any depth, and `docs/**` or `/docs/` every file beneath the
|
|
154
|
+
* root's docs. Any other pattern covers a file by its own name, at any
|
|
155
|
+
* depth, or by its path from the root (`/gate.json`, `src/*.ts`). Unlike
|
|
156
|
+
* `ignore`, such a pattern covers nothing beneath a directory it matches,
|
|
157
|
+
* since each file is covered by its own name or path: `["gate.json"]` holds
|
|
158
|
+
* every file named `gate.json`, and no other file beneath a directory of
|
|
159
|
+
* that name.
|
|
134
160
|
*
|
|
135
161
|
* It's the mount's boundary for content: no workspace path reads, stores,
|
|
136
162
|
* serves or writes back a file it doesn't cover, and no tool lists,
|
|
@@ -199,31 +225,62 @@ export interface MountConfig {
|
|
|
199
225
|
* A path in a nested mount's directory is that mount's, whatever this
|
|
200
226
|
* include covers: every tool gives the answer that names the mount holding
|
|
201
227
|
* it and the path to use there. Through a link a mount follows, a place in
|
|
202
|
-
* that directory is named only where it's a directory, or a file
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
*
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
*
|
|
214
|
-
*
|
|
215
|
-
*
|
|
216
|
-
*
|
|
217
|
-
* directory
|
|
218
|
-
*
|
|
219
|
-
*
|
|
220
|
-
*
|
|
221
|
-
*
|
|
222
|
-
*
|
|
223
|
-
* mount
|
|
224
|
-
*
|
|
225
|
-
*
|
|
226
|
-
*
|
|
228
|
+
* that directory is named only where it's a directory, or a file covered,
|
|
229
|
+
* with no file on its way, by that mount's own include and by the include
|
|
230
|
+
* of each other nested mount whose directory may hold it, from the
|
|
231
|
+
* innermost out to the first that surely holds it, and is otherwise
|
|
232
|
+
* refused as leaving the mount. A listing, or a pass, names a file there
|
|
233
|
+
* only where those includes cover it. On a mount that doesn't follow
|
|
234
|
+
* links, a link on a path's way is refused, as on any such mount
|
|
235
|
+
* (followSymlinks).
|
|
236
|
+
* Every check compares a path with a nested mount's directory level by
|
|
237
|
+
* level, as any disk may compare names: in either Unicode normalization
|
|
238
|
+
* form and in any case, as fully as a disk that folds names may compare
|
|
239
|
+
* them, at every level, whatever the disk does there, and reading nothing
|
|
240
|
+
* from the disk to do so. Start places each root the same way, so a mount
|
|
241
|
+
* configured through a link, or in a spelling, other than disk's is found
|
|
242
|
+
* nested. So a path, a walk or the workspace's history that names the
|
|
243
|
+
* directory in any spelling a disk may take for it reaches that mount,
|
|
244
|
+
* whether or not the directory is on disk yet, and so does a link whose
|
|
245
|
+
* target spells it otherwise. Where a link leads into the directory, the
|
|
246
|
+
* place beneath it is judged, and named, as disk spells it. A path that names the directory itself keeps what lies
|
|
247
|
+
* beneath as given, since that is the nested mount's to name. Where a disk
|
|
248
|
+
* keeps apart two names the comparison joins, it errs toward the nested
|
|
249
|
+
* mount, in where start places a mount as in every check: a name in
|
|
250
|
+
* another case, on a disk that tells case apart; a name in the other
|
|
251
|
+
* normalization form, on a disk that keeps the forms apart; and a name the
|
|
252
|
+
* comparison folds with it that a disk keeps apart, such as `ss` beside a
|
|
253
|
+
* nested `ß`, or one that differs from it only by a default-ignorable code
|
|
254
|
+
* point, such as a soft hyphen, on a disk that keeps those. Such a
|
|
255
|
+
* directory, or file, is no mount's, and every tool that names it is
|
|
256
|
+
* refused as a path that may lie in the nested mount, with the two
|
|
257
|
+
* spellings the workspace can't tell apart, and, for a link, where it
|
|
258
|
+
* leads, when that lies in this mount. The answer gives a step for each
|
|
259
|
+
* thing the caller may have meant: that mount's path to use; for a new
|
|
260
|
+
* file of this mount's, a path outside both spellings; and for one already
|
|
261
|
+
* there, whoever runs the workspace renaming one of the two spellings.
|
|
262
|
+
* Where start placed the nested mount only by a guess, comparing the real
|
|
263
|
+
* roots, as for two mounts' roots configured in spellings it can't tell
|
|
264
|
+
* apart, a path there is a guess too, however exactly it matches, and the
|
|
265
|
+
* answer names that directory as the path spells it, with the nested
|
|
266
|
+
* directory's spelling only in the step for a new file, names no host
|
|
267
|
+
* path, and asks for the configuration to be checked. Three cases fall
|
|
268
|
+
* outside this, as for any nested mount, and a fourth on a direct one: on a
|
|
269
|
+
* disk whose folding goes past the comparison's, which joins names that
|
|
270
|
+
* differ only by default-ignorable code points, in normalization form or in
|
|
271
|
+
* case, in full case folding, as Linux's casefold does, a name the
|
|
272
|
+
* comparison keeps apart can reach the directory; a second path to the
|
|
273
|
+
* directory that isn't a link, such as a bind mount, isn't found to lead
|
|
274
|
+
* there, though a walk passes over it, knowing each nested root by which
|
|
275
|
+
* directory it is; a nested mount whose root moves while running, as
|
|
276
|
+
* `acceptRoot` takes, stays placed where it was until the next start, but
|
|
277
|
+
* for the calls of a direct mount whose root has moved and on or beneath
|
|
278
|
+
* whose path it's configured, which place it where it lies; and where a
|
|
279
|
+
* direct mount's root is repointed between a read's parse and its open, or
|
|
280
|
+
* a write's parse and its staging, a race left to whoever writes the disk,
|
|
281
|
+
* a mount nested in it by its directories alone, since its real root holds
|
|
282
|
+
* that root, can have the read serve a path in its directory, or the write
|
|
283
|
+
* land there.
|
|
227
284
|
*
|
|
228
285
|
* Text the host registers for a path (`registerGeneratedTextFile`) is
|
|
229
286
|
* served there whatever the include says, since it isn't one of the
|
|
@@ -237,12 +294,8 @@ export interface MountConfig {
|
|
|
237
294
|
* include covers it.
|
|
238
295
|
*
|
|
239
296
|
* Left out, the mount holds everything under its path. Given, it's a list
|
|
240
|
-
* of at least one
|
|
241
|
-
*
|
|
242
|
-
* with a `/` that isn't such a glob, a `*` anywhere but a leading `*.` or
|
|
243
|
-
* that trailing `/**`, an empty, `.` or `..` segment, and, where `\` is the
|
|
244
|
-
* platform's separator, a `\`. Any other pattern is a file name, matched
|
|
245
|
-
* literally, so `[id].tsx` names the file of that name.
|
|
297
|
+
* of at least one pattern, and the module refuses one `ignore` would
|
|
298
|
+
* refuse but for a `[`.
|
|
246
299
|
*/
|
|
247
300
|
include?: string[];
|
|
248
301
|
/**
|
|
@@ -126,10 +126,15 @@ export class MountWatcher {
|
|
|
126
126
|
// another mount's directory, the mount's ignore list and editors' swap
|
|
127
127
|
// and backup files. chokidar 4
|
|
128
128
|
// compares a string given here with the whole absolute path, so the
|
|
129
|
-
// list itself would match nothing.
|
|
130
|
-
|
|
129
|
+
// list itself would match nothing. It asks without stats before it
|
|
130
|
+
// stats a path, asking again with them before it watches the path, and
|
|
131
|
+
// when a path it watches is removed. So where it gives no kind, no
|
|
132
|
+
// directory-only pattern matches: a directory one matches never passed
|
|
133
|
+
// the check with its stats, so it is never watched, and its removal
|
|
134
|
+
// never reported.
|
|
135
|
+
ignored: (path: string, stats?: Stats) => {
|
|
131
136
|
const relative = this.toRelative(path);
|
|
132
|
-
return relative !== null && passedOverAt(relative, ignore, this.others) !== undefined;
|
|
137
|
+
return relative !== null && passedOverAt(relative, ignore, this.others, stats?.isDirectory() ?? false) !== undefined;
|
|
133
138
|
},
|
|
134
139
|
// Its filter for editors' files tested the whole path, so a directory
|
|
135
140
|
// with a dot in its name hid every `*.swp` beneath it, and the walk
|
package/src/prose-drafts.ts
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
* Held prose drafts: a resident's plain speech that was not sent.
|
|
3
3
|
*
|
|
4
4
|
* Plain speech is held back for reasons that are right in themselves: an
|
|
5
|
-
* explicit send
|
|
6
|
-
*
|
|
5
|
+
* explicit send suppresses plain speech aimed where it may have posted, in
|
|
6
|
+
* its round and the turn's later ones (so a "sent it" postscript is not
|
|
7
|
+
* posted twice), a turn may have no destination, and a
|
|
7
8
|
* malformed or unresolvable routing prefix bounces. Before drafts, the held words were
|
|
8
9
|
* kept only as a count (or, in explicit mode, as one in-memory latest-wins
|
|
9
10
|
* clipboard): the law was right, and the penalty was amnesia. A draft keeps
|
|
@@ -53,7 +54,7 @@ export const PROSE_DRAFT_RECORD_TYPE = 'framework/prose-draft';
|
|
|
53
54
|
|
|
54
55
|
/** Why words were held instead of sent. */
|
|
55
56
|
export type DraftReason =
|
|
56
|
-
/** An explicit send in
|
|
57
|
+
/** An explicit send in its turn may have posted where the speech was going. */
|
|
57
58
|
| 'explicit-send'
|
|
58
59
|
/** The speech had no destination (no route this turn, or a failed envelope). */
|
|
59
60
|
| 'no-destination'
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { safeSlice } from './safe-slice.js';
|
|
2
|
+
|
|
3
|
+
export type ReasoningLossCause = 'tools' | 'system' | 'model';
|
|
4
|
+
|
|
5
|
+
export type ReasoningLossAnchor = { text: string } | { toolCall: string };
|
|
6
|
+
|
|
7
|
+
export interface ReasoningLossNoticeInput {
|
|
8
|
+
agentName: string;
|
|
9
|
+
scope:
|
|
10
|
+
| { kind: 'all'; through?: ReasoningLossAnchor; thisTurn: boolean }
|
|
11
|
+
| { kind: 'some'; count: number; first?: ReasoningLossAnchor; unplaced?: boolean; thisTurn: boolean };
|
|
12
|
+
causes: readonly ReasoningLossCause[];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const ANCHOR_CHARS = 80;
|
|
16
|
+
|
|
17
|
+
const CAUSE_WORDS: Record<ReasoningLossCause, string> = {
|
|
18
|
+
tools: 'your tools changed',
|
|
19
|
+
system: 'your system prompt changed',
|
|
20
|
+
model: 'your model changed',
|
|
21
|
+
};
|
|
22
|
+
const CAUSE_ORDER: readonly ReasoningLossCause[] = ['tools', 'system', 'model'];
|
|
23
|
+
|
|
24
|
+
export function reasoningLossNotice(input: ReasoningLossNoticeInput): string {
|
|
25
|
+
const causes = CAUSE_ORDER.filter((c) => input.causes.includes(c)).map((c) => CAUSE_WORDS[c]);
|
|
26
|
+
const because = causes.length > 0 ? `, because ${joinAnd(causes)}` : '';
|
|
27
|
+
const scope = input.scope;
|
|
28
|
+
let lost: string;
|
|
29
|
+
let reread: string;
|
|
30
|
+
if (scope.kind === 'all') {
|
|
31
|
+
const through = scope.through ? anchorWords(scope.through) : undefined;
|
|
32
|
+
const among = scope.thisTurn ? ", this turn's earlier steps among them," : '';
|
|
33
|
+
lost = through
|
|
34
|
+
? `The reasoning behind your replies up to the one ${through}${among} is no longer in your context${because}.`
|
|
35
|
+
: `The reasoning behind your earlier replies${among} is no longer in your context${because}.`;
|
|
36
|
+
reread = 'Re-read before relying on an earlier decision.';
|
|
37
|
+
} else {
|
|
38
|
+
const one = scope.count === 1 && !scope.unplaced;
|
|
39
|
+
const replies = scope.unplaced
|
|
40
|
+
? `at least ${scope.count} of your replies`
|
|
41
|
+
: one ? 'one of your replies' : `${scope.count} of your replies`;
|
|
42
|
+
const named = scope.first && !scope.unplaced ? anchorWords(scope.first) : undefined;
|
|
43
|
+
const first = named ? (one ? `, the one ${named}` : `, the first being the one ${named}`) : '';
|
|
44
|
+
const among = scope.thisTurn ? (one ? ', an earlier step of this turn' : ", this turn's earlier steps among them") : '';
|
|
45
|
+
lost = `Some of your earlier reasoning is no longer in your context: the reasoning behind ${replies}${first}${among}${because}.`;
|
|
46
|
+
reread = named ? 'Re-read before relying on a decision made since then.' : 'Re-read before relying on an earlier decision.';
|
|
47
|
+
}
|
|
48
|
+
return `[reasoning] ${input.agentName}: ${lost} Their words are still here. ${reread}`;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function anchorWords(anchor: ReasoningLossAnchor): string | undefined {
|
|
52
|
+
if ('toolCall' in anchor) return anchor.toolCall ? `that called \`${anchor.toolCall}\`` : undefined;
|
|
53
|
+
const text = anchor.text.replace(/\s+/g, ' ').trim();
|
|
54
|
+
if (!text) return undefined;
|
|
55
|
+
const clipped = text.length > ANCHOR_CHARS ? `${safeSlice(text, 0, ANCHOR_CHARS).trimEnd()}…` : text;
|
|
56
|
+
return `beginning "${clipped}"`;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function joinAnd(parts: readonly string[]): string {
|
|
60
|
+
if (parts.length <= 1) return parts.join('');
|
|
61
|
+
return `${parts.slice(0, -1).join(', ')} and ${parts[parts.length - 1]}`;
|
|
62
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import type { ContentBlock } from '@animalabs/membrane';
|
|
2
|
+
import type { MessageId, ThinkingStrip } from '@animalabs/context-manager';
|
|
3
|
+
import { ThinkingLossIncidents, type PlacedDrop } from './thinking-drops.js';
|
|
4
|
+
import {
|
|
5
|
+
reasoningLossNotice,
|
|
6
|
+
type ReasoningLossAnchor,
|
|
7
|
+
type ReasoningLossCause,
|
|
8
|
+
} from './reasoning-loss-notice.js';
|
|
9
|
+
|
|
10
|
+
export interface StoredReplyReader {
|
|
11
|
+
getMessage(id: MessageId): { sequence: number; content: readonly ContentBlock[] } | null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface ReasoningLossTurn {
|
|
15
|
+
start?: { branch: string; sequence: number };
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const HEAD_CAUSES: Partial<Record<NonNullable<ThinkingStrip['changed']>[number], ReasoningLossCause>> = {
|
|
19
|
+
tools: 'tools',
|
|
20
|
+
system: 'system',
|
|
21
|
+
model: 'model',
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export class ReasoningLossTeller {
|
|
25
|
+
private readonly told = new Map<string, Map<string, Set<MessageId>>>();
|
|
26
|
+
private readonly drops = new ThinkingLossIncidents();
|
|
27
|
+
|
|
28
|
+
forStrip(
|
|
29
|
+
agentName: string,
|
|
30
|
+
branch: string,
|
|
31
|
+
strip: ThinkingStrip,
|
|
32
|
+
turn: ReasoningLossTurn,
|
|
33
|
+
store: StoredReplyReader,
|
|
34
|
+
): string | undefined {
|
|
35
|
+
const told = this.toldFor(agentName, branch);
|
|
36
|
+
const taken = strip.newly
|
|
37
|
+
.map((id) => ({ id, sequence: store.getMessage(id)?.sequence }))
|
|
38
|
+
.sort((a, b) => (a.sequence ?? Infinity) - (b.sequence ?? Infinity));
|
|
39
|
+
const replies = taken.filter((r) => !told.has(r.id));
|
|
40
|
+
if (replies.length === 0) return undefined;
|
|
41
|
+
const thisTurn = replies.some((r) => isThisTurn(r.sequence, branch, turn));
|
|
42
|
+
if (strip.cause === 'head') {
|
|
43
|
+
const causes = (strip.changed ?? [])
|
|
44
|
+
.map((c) => HEAD_CAUSES[c])
|
|
45
|
+
.filter((c): c is ReasoningLossCause => c !== undefined);
|
|
46
|
+
const newest = taken.filter((r) => r.sequence !== undefined).at(-1);
|
|
47
|
+
const through = newest ? anchorOf(store.getMessage(newest.id)?.content) : undefined;
|
|
48
|
+
const amongThisTurn = taken.some((r) => isThisTurn(r.sequence, branch, turn));
|
|
49
|
+
for (const r of replies) told.add(r.id);
|
|
50
|
+
return reasoningLossNotice({ agentName, scope: { kind: 'all', ...(through ? { through } : {}), thisTurn: amongThisTurn }, causes });
|
|
51
|
+
}
|
|
52
|
+
if (strip.cause !== 'first' && !taken.some((r) => isThisTurn(r.sequence, branch, turn))) return undefined;
|
|
53
|
+
const first = anchorOf(store.getMessage(replies[0]!.id)?.content);
|
|
54
|
+
for (const r of replies) told.add(r.id);
|
|
55
|
+
return reasoningLossNotice({
|
|
56
|
+
agentName,
|
|
57
|
+
scope: { kind: 'some', count: replies.length, ...(first ? { first } : {}), thisTurn },
|
|
58
|
+
causes: [],
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
forDrops(
|
|
63
|
+
agentName: string,
|
|
64
|
+
branch: string,
|
|
65
|
+
placed: readonly PlacedDrop[],
|
|
66
|
+
turn: ReasoningLossTurn,
|
|
67
|
+
store: StoredReplyReader,
|
|
68
|
+
): string | undefined {
|
|
69
|
+
const replies = new Map<MessageId, number>();
|
|
70
|
+
const rounds = new Set<number>();
|
|
71
|
+
let blocks = 0;
|
|
72
|
+
for (const drop of placed) {
|
|
73
|
+
if (drop.kind === 'unplaced') continue;
|
|
74
|
+
blocks++;
|
|
75
|
+
if (drop.kind === 'round') rounds.add(drop.round);
|
|
76
|
+
else for (const body of drop.bodies) replies.set(body.messageId, body.sequence);
|
|
77
|
+
}
|
|
78
|
+
const unplaced = blocks < placed.length;
|
|
79
|
+
const count = replies.size + rounds.size;
|
|
80
|
+
const ordered = [...replies].sort((a, b) => a[1] - b[1]);
|
|
81
|
+
const thisTurn = rounds.size > 0 || ordered.some(([, sequence]) => isThisTurn(sequence, branch, turn));
|
|
82
|
+
const first = ordered.length > 0 && !unplaced ? anchorOf(store.getMessage(ordered[0]![0])?.content) : undefined;
|
|
83
|
+
if (this.drops.observe(agentName, blocks, branch) === undefined) return undefined;
|
|
84
|
+
const told = this.toldFor(agentName, branch);
|
|
85
|
+
for (const id of replies.keys()) told.add(id);
|
|
86
|
+
return reasoningLossNotice({
|
|
87
|
+
agentName,
|
|
88
|
+
scope: { kind: 'some', count, ...(first ? { first } : {}), ...(unplaced ? { unplaced: true } : {}), thisTurn },
|
|
89
|
+
causes: [],
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
forget(agentName: string): void {
|
|
94
|
+
this.told.delete(agentName);
|
|
95
|
+
this.drops.forget(agentName);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
private toldFor(agentName: string, branch: string): Set<MessageId> {
|
|
99
|
+
let branches = this.told.get(agentName);
|
|
100
|
+
if (!branches) this.told.set(agentName, (branches = new Map()));
|
|
101
|
+
let told = branches.get(branch);
|
|
102
|
+
if (!told) branches.set(branch, (told = new Set()));
|
|
103
|
+
return told;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function isThisTurn(sequence: number | undefined, branch: string, turn: ReasoningLossTurn): boolean {
|
|
108
|
+
return sequence !== undefined && turn.start?.branch === branch && sequence > turn.start.sequence;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function anchorOf(content: readonly ContentBlock[] | undefined): ReasoningLossAnchor | undefined {
|
|
112
|
+
if (!content) return undefined;
|
|
113
|
+
for (const block of content) {
|
|
114
|
+
if (block.type === 'text' && typeof block.text === 'string' && block.text.trim() !== '') return { text: block.text };
|
|
115
|
+
}
|
|
116
|
+
for (const block of content) {
|
|
117
|
+
if (block.type === 'tool_use' && typeof block.name === 'string' && block.name !== '') return { toolCall: block.name };
|
|
118
|
+
}
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
package/src/send-tools.ts
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
* Tools whose call delivers the resident's message to a channel or person,
|
|
3
3
|
* by bare name (an MCPL server's `<prefix>--` stripped). The framework reads
|
|
4
4
|
* a call of one as an explicit send that silences the round's auto-routed
|
|
5
|
-
* prose; the history module's semantic index reads
|
|
6
|
-
* what the resident wrote to someone, whether or not
|
|
5
|
+
* prose where it may have posted; the history module's semantic index reads
|
|
6
|
+
* its message argument as what the resident wrote to someone, whether or not
|
|
7
|
+
* it was delivered.
|
|
7
8
|
*/
|
|
8
9
|
export const SEND_TOOLS = new Set(['channel_publish', 'send_message', 'reply_message', 'send_dm']);
|
|
9
10
|
|
package/src/sent-rows.ts
CHANGED
|
@@ -152,7 +152,7 @@ export function roundRows(
|
|
|
152
152
|
* the two alike (read from the provider on 2026-10-23: Haiku 5.5 with the drop control, on an enforcing API-key
|
|
153
153
|
* organization and on a subscription account, reported no drop for either, and dropped both replies' blocks when an
|
|
154
154
|
* earlier user message changed). The store's own fields beside them, such as
|
|
155
|
-
* `toolName`, don't reach the provider on membrane's native path, the only one noted (membrane 0.
|
|
155
|
+
* `toolName`, don't reach the provider on membrane's native path, the only one noted (membrane 0.8.0's XML
|
|
156
156
|
* formatter reads `toolName`, and an XML stream is never noted).
|
|
157
157
|
*/
|
|
158
158
|
function normalizedResult(block: ContentBlock): unknown {
|