@animalabs/agent-framework 0.26.1 → 0.27.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 +57 -7
- package/dist/src/agent.d.ts +263 -22
- package/dist/src/agent.d.ts.map +1 -1
- package/dist/src/agent.js +531 -54
- package/dist/src/agent.js.map +1 -1
- package/dist/src/api/server.d.ts.map +1 -1
- package/dist/src/api/server.js +1 -2
- package/dist/src/api/server.js.map +1 -1
- package/dist/src/auto-continue.d.ts +33 -0
- package/dist/src/auto-continue.d.ts.map +1 -0
- package/dist/src/auto-continue.js +35 -0
- package/dist/src/auto-continue.js.map +1 -0
- package/dist/src/code-execution/isolate/scripts.d.ts +11 -0
- package/dist/src/code-execution/isolate/scripts.d.ts.map +1 -1
- package/dist/src/code-execution/isolate/scripts.js +5 -1
- package/dist/src/code-execution/isolate/scripts.js.map +1 -1
- package/dist/src/framework.d.ts +829 -156
- package/dist/src/framework.d.ts.map +1 -1
- package/dist/src/framework.js +3906 -1008
- package/dist/src/framework.js.map +1 -1
- package/dist/src/gate/event-gate.d.ts +309 -46
- package/dist/src/gate/event-gate.d.ts.map +1 -1
- package/dist/src/gate/event-gate.js +2117 -395
- package/dist/src/gate/event-gate.js.map +1 -1
- package/dist/src/gate/index.d.ts +2 -2
- package/dist/src/gate/index.d.ts.map +1 -1
- package/dist/src/gate/index.js +1 -1
- package/dist/src/gate/index.js.map +1 -1
- package/dist/src/gate/recipe-reconcile.d.ts +103 -0
- package/dist/src/gate/recipe-reconcile.d.ts.map +1 -0
- package/dist/src/gate/recipe-reconcile.js +325 -0
- package/dist/src/gate/recipe-reconcile.js.map +1 -0
- package/dist/src/gate/types.d.ts +68 -8
- package/dist/src/gate/types.d.ts.map +1 -1
- package/dist/src/index.d.ts +6 -4
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +5 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/mcpl/channel-registry.d.ts +433 -113
- package/dist/src/mcpl/channel-registry.d.ts.map +1 -1
- package/dist/src/mcpl/channel-registry.js +1152 -434
- package/dist/src/mcpl/channel-registry.js.map +1 -1
- package/dist/src/mcpl/conversation-router.d.ts +16 -8
- package/dist/src/mcpl/conversation-router.d.ts.map +1 -1
- package/dist/src/mcpl/conversation-router.js +29 -15
- package/dist/src/mcpl/conversation-router.js.map +1 -1
- package/dist/src/mcpl/convert-block.d.ts.map +1 -1
- package/dist/src/mcpl/convert-block.js +14 -2
- package/dist/src/mcpl/convert-block.js.map +1 -1
- package/dist/src/mcpl/hook-orchestrator.d.ts +7 -1
- package/dist/src/mcpl/hook-orchestrator.d.ts.map +1 -1
- package/dist/src/mcpl/hook-orchestrator.js +32 -7
- package/dist/src/mcpl/hook-orchestrator.js.map +1 -1
- package/dist/src/mcpl/index.d.ts +5 -1
- package/dist/src/mcpl/index.d.ts.map +1 -1
- package/dist/src/mcpl/index.js +4 -0
- package/dist/src/mcpl/index.js.map +1 -1
- package/dist/src/mcpl/inference-router.d.ts +14 -2
- package/dist/src/mcpl/inference-router.d.ts.map +1 -1
- package/dist/src/mcpl/inference-router.js +73 -28
- package/dist/src/mcpl/inference-router.js.map +1 -1
- package/dist/src/mcpl/prose-grammar.d.ts +4 -0
- package/dist/src/mcpl/prose-grammar.d.ts.map +1 -1
- package/dist/src/mcpl/prose-grammar.js +6 -0
- package/dist/src/mcpl/prose-grammar.js.map +1 -1
- package/dist/src/mcpl/protocol-family.d.ts.map +1 -1
- package/dist/src/mcpl/protocol-family.js +3 -0
- package/dist/src/mcpl/protocol-family.js.map +1 -1
- package/dist/src/mcpl/push-coalescer.d.ts +20 -2
- package/dist/src/mcpl/push-coalescer.d.ts.map +1 -1
- package/dist/src/mcpl/push-coalescer.js +33 -11
- package/dist/src/mcpl/push-coalescer.js.map +1 -1
- package/dist/src/mcpl/reference-fetcher.d.ts +63 -42
- package/dist/src/mcpl/reference-fetcher.d.ts.map +1 -1
- package/dist/src/mcpl/reference-fetcher.js +177 -145
- package/dist/src/mcpl/reference-fetcher.js.map +1 -1
- package/dist/src/mcpl/references.d.ts +380 -46
- package/dist/src/mcpl/references.d.ts.map +1 -1
- package/dist/src/mcpl/references.js +737 -78
- package/dist/src/mcpl/references.js.map +1 -1
- package/dist/src/mcpl/server-connection.d.ts +82 -3
- package/dist/src/mcpl/server-connection.d.ts.map +1 -1
- package/dist/src/mcpl/server-connection.js +132 -7
- package/dist/src/mcpl/server-connection.js.map +1 -1
- package/dist/src/mcpl/tool-lifecycle.d.ts +11 -0
- package/dist/src/mcpl/tool-lifecycle.d.ts.map +1 -1
- package/dist/src/mcpl/tool-lifecycle.js +21 -0
- package/dist/src/mcpl/tool-lifecycle.js.map +1 -1
- package/dist/src/mcpl/tool-presence.d.ts +259 -0
- package/dist/src/mcpl/tool-presence.d.ts.map +1 -0
- package/dist/src/mcpl/tool-presence.js +628 -0
- package/dist/src/mcpl/tool-presence.js.map +1 -0
- package/dist/src/mcpl/tool-result-normalize.d.ts +9 -3
- package/dist/src/mcpl/tool-result-normalize.d.ts.map +1 -1
- package/dist/src/mcpl/tool-result-normalize.js +14 -6
- package/dist/src/mcpl/tool-result-normalize.js.map +1 -1
- package/dist/src/mcpl/tool-signature.d.ts +39 -0
- package/dist/src/mcpl/tool-signature.d.ts.map +1 -0
- package/dist/src/mcpl/tool-signature.js +292 -0
- package/dist/src/mcpl/tool-signature.js.map +1 -0
- package/dist/src/mcpl/toolset-host.d.ts +200 -0
- package/dist/src/mcpl/toolset-host.d.ts.map +1 -0
- package/dist/src/mcpl/toolset-host.js +621 -0
- package/dist/src/mcpl/toolset-host.js.map +1 -0
- package/dist/src/mcpl/toolsets-module.d.ts +80 -0
- package/dist/src/mcpl/toolsets-module.d.ts.map +1 -0
- package/dist/src/mcpl/toolsets-module.js +431 -0
- package/dist/src/mcpl/toolsets-module.js.map +1 -0
- package/dist/src/mcpl/transport.d.ts +2 -2
- package/dist/src/mcpl/transport.d.ts.map +1 -1
- package/dist/src/mcpl/transport.js +3 -2
- package/dist/src/mcpl/transport.js.map +1 -1
- package/dist/src/mcpl/types.d.ts +21 -1
- package/dist/src/mcpl/types.d.ts.map +1 -1
- package/dist/src/mcpl/types.js.map +1 -1
- package/dist/src/mcpl/visible-content.d.ts +7 -9
- package/dist/src/mcpl/visible-content.d.ts.map +1 -1
- package/dist/src/mcpl/visible-content.js +21 -9
- package/dist/src/mcpl/visible-content.js.map +1 -1
- package/dist/src/module-registry.d.ts +23 -8
- package/dist/src/module-registry.d.ts.map +1 -1
- package/dist/src/module-registry.js +68 -15
- package/dist/src/module-registry.js.map +1 -1
- package/dist/src/modules/discord/index.js +1 -1
- package/dist/src/modules/discord/index.js.map +1 -1
- package/dist/src/modules/history/index.d.ts +2 -1
- package/dist/src/modules/history/index.d.ts.map +1 -1
- package/dist/src/modules/history/index.js +51 -17
- package/dist/src/modules/history/index.js.map +1 -1
- package/dist/src/modules/history/semantic.d.ts +108 -6
- package/dist/src/modules/history/semantic.d.ts.map +1 -1
- package/dist/src/modules/history/semantic.js +273 -57
- package/dist/src/modules/history/semantic.js.map +1 -1
- package/dist/src/modules/workspace/direct-write.d.ts +181 -0
- package/dist/src/modules/workspace/direct-write.d.ts.map +1 -0
- package/dist/src/modules/workspace/direct-write.js +384 -0
- package/dist/src/modules/workspace/direct-write.js.map +1 -0
- package/dist/src/modules/workspace/edit-text.d.ts +26 -12
- package/dist/src/modules/workspace/edit-text.d.ts.map +1 -1
- package/dist/src/modules/workspace/edit-text.js +58 -28
- package/dist/src/modules/workspace/edit-text.js.map +1 -1
- package/dist/src/modules/workspace/effects.d.ts +10 -0
- package/dist/src/modules/workspace/effects.d.ts.map +1 -1
- package/dist/src/modules/workspace/effects.js +1 -1
- package/dist/src/modules/workspace/effects.js.map +1 -1
- package/dist/src/modules/workspace/index.d.ts +246 -27
- package/dist/src/modules/workspace/index.d.ts.map +1 -1
- package/dist/src/modules/workspace/index.js +1216 -236
- package/dist/src/modules/workspace/index.js.map +1 -1
- package/dist/src/modules/workspace/read-page.d.ts +41 -0
- package/dist/src/modules/workspace/read-page.d.ts.map +1 -0
- package/dist/src/modules/workspace/read-page.js +213 -0
- package/dist/src/modules/workspace/read-page.js.map +1 -0
- package/dist/src/modules/workspace/result-text.d.ts +67 -0
- package/dist/src/modules/workspace/result-text.d.ts.map +1 -0
- package/dist/src/modules/workspace/result-text.js +94 -0
- package/dist/src/modules/workspace/result-text.js.map +1 -0
- package/dist/src/modules/workspace/text.d.ts +29 -12
- package/dist/src/modules/workspace/text.d.ts.map +1 -1
- package/dist/src/modules/workspace/text.js +35 -33
- package/dist/src/modules/workspace/text.js.map +1 -1
- package/dist/src/modules/workspace/types.d.ts +41 -17
- package/dist/src/modules/workspace/types.d.ts.map +1 -1
- package/dist/src/modules/workspace/types.js.map +1 -1
- package/dist/src/sent-rows.d.ts +59 -0
- package/dist/src/sent-rows.d.ts.map +1 -0
- package/dist/src/sent-rows.js +145 -0
- package/dist/src/sent-rows.js.map +1 -0
- package/dist/src/silent-heartbeat.d.ts +17 -10
- package/dist/src/silent-heartbeat.d.ts.map +1 -1
- package/dist/src/silent-heartbeat.js.map +1 -1
- package/dist/src/stable-hash.d.ts +3 -0
- package/dist/src/stable-hash.d.ts.map +1 -0
- package/dist/src/stable-hash.js +15 -0
- package/dist/src/stable-hash.js.map +1 -0
- package/dist/src/stored-injections.d.ts +99 -0
- package/dist/src/stored-injections.d.ts.map +1 -0
- package/dist/src/stored-injections.js +106 -0
- package/dist/src/stored-injections.js.map +1 -0
- package/dist/src/text-as-stored.d.ts +4 -3
- package/dist/src/text-as-stored.d.ts.map +1 -1
- package/dist/src/text-as-stored.js +4 -3
- package/dist/src/text-as-stored.js.map +1 -1
- package/dist/src/thinking-drops.d.ts +81 -0
- package/dist/src/thinking-drops.d.ts.map +1 -0
- package/dist/src/thinking-drops.js +103 -0
- package/dist/src/thinking-drops.js.map +1 -0
- package/dist/src/tool-image-ledger.d.ts +9 -8
- package/dist/src/tool-image-ledger.d.ts.map +1 -1
- package/dist/src/tool-image-ledger.js +9 -8
- package/dist/src/tool-image-ledger.js.map +1 -1
- package/dist/src/tool-presentation.d.ts.map +1 -1
- package/dist/src/tool-presentation.js +3 -1
- package/dist/src/tool-presentation.js.map +1 -1
- package/dist/src/tool-result-guard.d.ts +4 -2
- package/dist/src/tool-result-guard.d.ts.map +1 -1
- package/dist/src/tool-result-guard.js +21 -6
- package/dist/src/tool-result-guard.js.map +1 -1
- package/dist/src/tool-result-history.d.ts +186 -21
- package/dist/src/tool-result-history.d.ts.map +1 -1
- package/dist/src/tool-result-history.js +428 -89
- package/dist/src/tool-result-history.js.map +1 -1
- package/dist/src/tune-out/coordinator.d.ts +17 -9
- package/dist/src/tune-out/coordinator.d.ts.map +1 -1
- package/dist/src/tune-out/coordinator.js +84 -37
- package/dist/src/tune-out/coordinator.js.map +1 -1
- package/dist/src/types/agent.d.ts +186 -7
- package/dist/src/types/agent.d.ts.map +1 -1
- package/dist/src/types/events.d.ts +19 -2
- package/dist/src/types/events.d.ts.map +1 -1
- package/dist/src/types/framework.d.ts +24 -3
- package/dist/src/types/framework.d.ts.map +1 -1
- package/dist/src/types/module.d.ts +90 -7
- package/dist/src/types/module.d.ts.map +1 -1
- package/dist/src/types/trace.d.ts +57 -2
- package/dist/src/types/trace.d.ts.map +1 -1
- package/package.json +4 -3
- package/src/agent.ts +593 -60
- package/src/api/server.ts +1 -2
- package/src/auto-continue.ts +42 -0
- package/src/code-execution/isolate/scripts.ts +11 -3
- package/src/framework.ts +4004 -1026
- package/src/gate/event-gate.ts +2315 -389
- package/src/gate/index.ts +2 -1
- package/src/gate/recipe-reconcile.ts +355 -0
- package/src/gate/types.ts +70 -8
- package/src/index.ts +7 -4
- package/src/mcpl/channel-registry.ts +1220 -467
- package/src/mcpl/conversation-router.ts +34 -16
- package/src/mcpl/convert-block.ts +14 -1
- package/src/mcpl/hook-orchestrator.ts +33 -6
- package/src/mcpl/index.ts +6 -1
- package/src/mcpl/inference-router.ts +79 -34
- package/src/mcpl/prose-grammar.ts +7 -0
- package/src/mcpl/protocol-family.ts +2 -0
- package/src/mcpl/push-coalescer.ts +51 -13
- package/src/mcpl/reference-fetcher.ts +201 -162
- package/src/mcpl/references.ts +852 -78
- package/src/mcpl/server-connection.ts +145 -7
- package/src/mcpl/tool-lifecycle.ts +21 -0
- package/src/mcpl/tool-presence.ts +650 -0
- package/src/mcpl/tool-result-normalize.ts +18 -6
- package/src/mcpl/tool-signature.ts +285 -0
- package/src/mcpl/toolset-host.ts +637 -0
- package/src/mcpl/toolsets-module.ts +451 -0
- package/src/mcpl/transport.ts +3 -2
- package/src/mcpl/types.ts +22 -1
- package/src/mcpl/visible-content.ts +22 -9
- package/src/module-registry.ts +77 -24
- package/src/modules/discord/index.ts +1 -1
- package/src/modules/history/index.ts +48 -18
- package/src/modules/history/semantic.ts +308 -54
- package/src/modules/workspace/direct-write.ts +425 -0
- package/src/modules/workspace/edit-text.ts +82 -35
- package/src/modules/workspace/effects.ts +1 -1
- package/src/modules/workspace/index.ts +1274 -241
- package/src/modules/workspace/read-page.ts +222 -0
- package/src/modules/workspace/result-text.ts +119 -0
- package/src/modules/workspace/text.ts +58 -32
- package/src/modules/workspace/types.ts +41 -17
- package/src/sent-rows.ts +162 -0
- package/src/silent-heartbeat.ts +17 -10
- package/src/stable-hash.ts +14 -0
- package/src/stored-injections.ts +131 -0
- package/src/text-as-stored.ts +4 -3
- package/src/thinking-drops.ts +141 -0
- package/src/tool-image-ledger.ts +9 -8
- package/src/tool-presentation.ts +3 -1
- package/src/tool-result-guard.ts +19 -6
- package/src/tool-result-history.ts +488 -88
- package/src/tune-out/coordinator.ts +80 -37
- package/src/types/agent.ts +189 -7
- package/src/types/events.ts +19 -2
- package/src/types/framework.ts +21 -3
- package/src/types/module.ts +86 -7
- package/src/types/trace.ts +58 -2
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import type { ToolResult } from '../../types/events.js';
|
|
2
|
+
import { answerText, fieldLine, sectionLead, sectionText, textAnswer } from './result-text.js';
|
|
3
|
+
import { type FileText, MAX_LINE_CHARS, numberedLine, safeCut } from './text.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* One page of a read, held to the result limit as its text measures it: a
|
|
7
|
+
* model reads the page's text (result-text.ts), and what passes the caller's
|
|
8
|
+
* limit doesn't reach it whole. A model's result spills into a file, cut, and
|
|
9
|
+
* a script gets ResultTooLarge in its place. So a page stops before its text
|
|
10
|
+
* would pass the limit, and its note says where to continue. A script's
|
|
11
|
+
* answer carries the page's fields, its content among them, beside its text,
|
|
12
|
+
* and the limit counts the text alone. A script's limit counts each character
|
|
13
|
+
* at the six bytes it takes at most in the answer, and no character but a
|
|
14
|
+
* control character takes more than three, so the text and the fields
|
|
15
|
+
* together pass what the script takes only on a page of more than half that
|
|
16
|
+
* limit (about 3.7 million characters at the default 128 MiB of script
|
|
17
|
+
* memory) holding control characters.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/** How many lines a read shows when it isn't given a limit. */
|
|
21
|
+
export const DEFAULT_READ_LINE_LIMIT = 2000;
|
|
22
|
+
|
|
23
|
+
/** What a read says about the text it shows, besides the lines themselves. */
|
|
24
|
+
export function textNotes(file: FileText): string[] {
|
|
25
|
+
const notes: string[] = [];
|
|
26
|
+
if (file.crlfEnds > 0) {
|
|
27
|
+
// A line whose own text ends in a CR shows its line end's CR too (fileText).
|
|
28
|
+
const kept = file.crKept > 0
|
|
29
|
+
? `, except on ${file.crKept} ${file.crKept === 1 ? 'line whose own text ends in a CR, which shows' : 'lines whose own text ends in a CR, which show'} both CRs`
|
|
30
|
+
: '';
|
|
31
|
+
notes.push(file.lfEnds > 0
|
|
32
|
+
? `Line ends are mixed, ${file.crlfEnds} CRLF and ${file.lfEnds} LF, and a CRLF end is shown without its CR${kept}. An edit matches text as read shows it, and keeps each line's end.`
|
|
33
|
+
: `Line ends are CRLF, shown without the CR${kept}. An edit matches text as read shows it, and keeps the CRLF ends.`);
|
|
34
|
+
}
|
|
35
|
+
if (file.bom) notes.push('The file starts with a UTF-8 BOM, which isn\'t shown. An edit keeps it.');
|
|
36
|
+
if (!file.utf8) notes.push(NOT_UTF8);
|
|
37
|
+
return notes;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const NOT_UTF8 = 'The file isn\'t valid UTF-8: each invalid byte sequence shows as U+FFFD. Edit refuses this file, and write replaces it whole.';
|
|
41
|
+
|
|
42
|
+
const joined = (notes: Array<string | null>): string | undefined => {
|
|
43
|
+
const kept = notes.filter((n): n is string => n !== null);
|
|
44
|
+
return kept.length > 0 ? kept.join(' ') : undefined;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/** A page's fields: a line page's or a character page's, and its content, numbered lines or raw text. */
|
|
48
|
+
type Page = { path: string; content: string; note?: string } & Record<string, string | number | null | undefined>;
|
|
49
|
+
|
|
50
|
+
/** A page's text: its fields, one to a line in their order, and then its content under its label. */
|
|
51
|
+
function pageText(page: Page): string {
|
|
52
|
+
const header = Object.entries(page)
|
|
53
|
+
.filter((entry): entry is [string, string | number | null] => entry[0] !== 'content' && entry[1] !== undefined)
|
|
54
|
+
.map(([key, value]) => fieldLine(key, value));
|
|
55
|
+
return answerText(header, [sectionText('content', page.content)]);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** A page as read answers it: its text for the model, and its fields for a script. */
|
|
59
|
+
const pageAnswer = (page: Page): ToolResult => textAnswer(pageText(page), page);
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Lines from `offset` (1-based), at most `limit` of them, each numbered and a
|
|
63
|
+
* long one cut with the offsetChars and limitChars that read the rest. The
|
|
64
|
+
* page is the longest whose text fits within `maxChars`; where none fits
|
|
65
|
+
* with its first line as a page shows it, that line is cut shorter, at the
|
|
66
|
+
* most the page has room for. Where the page's last line is cut, its note
|
|
67
|
+
* names where that line's rest starts and how long it is, since reading on in
|
|
68
|
+
* order starts there: before the next line, or, on the page that ends the
|
|
69
|
+
* file, before the file is read whole. A page whose own fields and least
|
|
70
|
+
* content pass `maxChars` still moves on, and passes it. With no `maxChars`,
|
|
71
|
+
* for a call made in process, which takes the data itself, the page holds to
|
|
72
|
+
* `limit` alone and shows every line whole.
|
|
73
|
+
*/
|
|
74
|
+
export function linePage(path: string, file: FileText, offset: number, limit: number, maxChars: number | undefined, extraNotes: string[] = []): ToolResult {
|
|
75
|
+
const { lines, starts } = file;
|
|
76
|
+
const total = lines.length;
|
|
77
|
+
const first = offset - 1;
|
|
78
|
+
const notes = [...textNotes(file), ...extraNotes];
|
|
79
|
+
if (first >= total) {
|
|
80
|
+
// Nothing to show: an empty file, or an offset past the last line. No
|
|
81
|
+
// range is claimed, and the line count says where the file ends.
|
|
82
|
+
const note = joined([
|
|
83
|
+
// Reading an empty file from its start is reading it whole.
|
|
84
|
+
first > 0 ? `Line ${first + 1} is past the end: the file has ${total} line${total === 1 ? '' : 's'}.` : null,
|
|
85
|
+
...notes,
|
|
86
|
+
]);
|
|
87
|
+
return pageAnswer({ path, totalLines: total, ...(note !== undefined ? { note } : {}), content: '' });
|
|
88
|
+
}
|
|
89
|
+
const last = Math.min(first + limit, total);
|
|
90
|
+
const shown = (i: number, maxLineChars = MAX_LINE_CHARS) =>
|
|
91
|
+
numberedLine(lines[i], i + 1, maxLineChars,
|
|
92
|
+
(cut) => `read the rest with offsetChars=${starts[i] + cut} and limitChars=${lines[i].length - cut}`);
|
|
93
|
+
// Where the rest of line i starts in the stored text, shown at most
|
|
94
|
+
// maxLineChars long, as its marker says; null for a line shown whole.
|
|
95
|
+
const restOf = (i: number, maxLineChars: number): number | null =>
|
|
96
|
+
lines[i].length > maxLineChars ? starts[i] + safeCut(lines[i], maxLineChars) : null;
|
|
97
|
+
// The rest's length is what's left of the line as a page shows it, so a
|
|
98
|
+
// character read of it ends where the line does.
|
|
99
|
+
const cutLine = (to: number, rest: number) =>
|
|
100
|
+
`Line ${to} is cut: read its rest with offsetChars=${rest} and limitChars=${starts[to - 1]! + lines[to - 1]!.length - rest}`;
|
|
101
|
+
const limitNote = (to: number, rest: number | null) =>
|
|
102
|
+
`Truncated at ${limit} lines (file has ${total}).${rest === null ? '' : ` ${cutLine(to, rest)}.`} Use offset/limit to read more.`;
|
|
103
|
+
const budgetNote = (to: number, rest: number | null) =>
|
|
104
|
+
`Stopped at line ${to} to stay within the ${maxChars}-character result limit (file has ${total}). `
|
|
105
|
+
+ (rest === null ? `Continue with offset=${to + 1}.` : `${cutLine(to, rest)}, then continue with offset=${to + 1}.`);
|
|
106
|
+
const page = (to: number, content: string, note: string | undefined): Page => ({
|
|
107
|
+
path, totalLines: total, fromLine: first + 1, toLine: to, ...(note !== undefined ? { note } : {}), content,
|
|
108
|
+
});
|
|
109
|
+
if (maxChars === undefined) {
|
|
110
|
+
const whole = lines.slice(first, last).map((line, k) => numberedLine(line, first + k + 1, Infinity)).join('\n');
|
|
111
|
+
return pageAnswer(page(last, whole, joined([last < total ? limitNote(last, null) : null, ...notes])));
|
|
112
|
+
}
|
|
113
|
+
// The note of the page that ends at line `to`, its last line shown at most
|
|
114
|
+
// lastMax long: the page that ends where it was asked to, at the file's end
|
|
115
|
+
// or the line limit, says so, and any other says it stopped for the limit.
|
|
116
|
+
const noteAt = (to: number, lastMax = MAX_LINE_CHARS) => {
|
|
117
|
+
const rest = restOf(to - 1, lastMax);
|
|
118
|
+
const endNote = to < total ? limitNote(to, rest) : rest === null ? null : `${cutLine(to, rest)}.`;
|
|
119
|
+
return joined([to === last ? endNote : budgetNote(to, rest), ...notes]);
|
|
120
|
+
};
|
|
121
|
+
// A page's text's length: its fields' and note's, measured with no content,
|
|
122
|
+
// and its content's, under the content's label. A page here has a line.
|
|
123
|
+
const lengthAt = (to: number, contentChars: number, note: string | undefined) =>
|
|
124
|
+
pageText(page(to, '', note)).length + sectionLead('content') + contentChars;
|
|
125
|
+
// The page is the longest that fits. Its length isn't monotone in its
|
|
126
|
+
// lines: the page that ends the file carries no stop note, the one at the
|
|
127
|
+
// line limit a shorter one than a stop, and one whose last line is cut a
|
|
128
|
+
// longer one. But every page carries `notes` and a longer page shows more,
|
|
129
|
+
// so once a page passes the limit with those alone, no longer one fits.
|
|
130
|
+
const shownLines: string[] = [];
|
|
131
|
+
let contentChars = 0;
|
|
132
|
+
let best = 0;
|
|
133
|
+
for (let i = first; i < last; i++) {
|
|
134
|
+
const line = shown(i);
|
|
135
|
+
shownLines.push(line);
|
|
136
|
+
// Each line after the first comes after a line feed.
|
|
137
|
+
contentChars += line.length + (i > first ? 1 : 0);
|
|
138
|
+
if (lengthAt(i + 1, contentChars, noteAt(i + 1)) <= maxChars) best = shownLines.length;
|
|
139
|
+
else if (lengthAt(i + 1, contentChars, joined(notes)) > maxChars) break;
|
|
140
|
+
}
|
|
141
|
+
if (best > 0) {
|
|
142
|
+
shownLines.length = best;
|
|
143
|
+
return pageAnswer(page(first + best, shownLines.join('\n'), noteAt(first + best)));
|
|
144
|
+
}
|
|
145
|
+
// No page fits with its first line as a page shows it: the loop tried that
|
|
146
|
+
// page first, since a read's limit is at least 1, and it is pageWith(top).
|
|
147
|
+
// So the line is cut shorter, at the most the page has room for, and ends
|
|
148
|
+
// the page: its note names where the line's rest starts and how long it is,
|
|
149
|
+
// since that comes next. Each cut is measured on the page itself, since its
|
|
150
|
+
// note names the cut. Every cut below `top` shows a marker. A longer cut
|
|
151
|
+
// adds a character of text at least, and the offsets only grow, but the
|
|
152
|
+
// rest's length is in the marker and in the note, so where it loses a digit
|
|
153
|
+
// the page loses two characters: it can be one character shorter than the
|
|
154
|
+
// page a cut before. The search takes the page as growing with the cut.
|
|
155
|
+
// Such a dip is one cut, and the next is many cuts away, so the longest cut
|
|
156
|
+
// that fits is the one the search finds or, past a dip, at most two cuts
|
|
157
|
+
// further, four code units at most, and those are tried too.
|
|
158
|
+
const pageWith = (chars: number) => page(first + 1, shown(first, chars), noteAt(first + 1, chars));
|
|
159
|
+
const fitsAt = (chars: number) => pageText(pageWith(chars)).length <= maxChars;
|
|
160
|
+
const top = Math.min(lines[first].length, MAX_LINE_CHARS);
|
|
161
|
+
let fits = 0;
|
|
162
|
+
let over = top;
|
|
163
|
+
while (over - fits > 1) {
|
|
164
|
+
const mid = Math.floor((fits + over) / 2);
|
|
165
|
+
if (fitsAt(mid)) fits = mid; else over = mid;
|
|
166
|
+
}
|
|
167
|
+
// The search ends with `fits + 1` measured as too long, or as `top`.
|
|
168
|
+
const found = fits;
|
|
169
|
+
for (let chars = found + 2; chars <= found + 4 && chars < top; chars++) if (fitsAt(chars)) fits = chars;
|
|
170
|
+
return pageAnswer(pageWith(fits));
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const splitsPair = (text: string, at: number): boolean =>
|
|
174
|
+
at > 0 && at < text.length
|
|
175
|
+
&& text.charCodeAt(at - 1) >= 0xd800 && text.charCodeAt(at - 1) <= 0xdbff
|
|
176
|
+
&& text.charCodeAt(at) >= 0xdc00 && text.charCodeAt(at) <= 0xdfff;
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Raw text from `offsetChars`, at most `limitChars` code units (one more to
|
|
180
|
+
* keep a surrogate pair whole), stopped sooner where its page's text would
|
|
181
|
+
* pass `maxChars`, if there is one.
|
|
182
|
+
*/
|
|
183
|
+
export function characterPage(path: string, file: FileText, offsetChars: number, limitChars: number, maxChars: number | undefined, extraNotes: string[] = []): ToolResult {
|
|
184
|
+
const text = file.raw;
|
|
185
|
+
const start = Math.min(offsetChars, text.length);
|
|
186
|
+
if (splitsPair(text, start)) {
|
|
187
|
+
return { success: false, isError: true, error: 'offsetChars splits a surrogate pair; use nextOffsetChars from the previous page.' };
|
|
188
|
+
}
|
|
189
|
+
let end = start + Math.min(limitChars, text.length - start);
|
|
190
|
+
if (splitsPair(text, end)) end++;
|
|
191
|
+
const notes = [...(file.utf8 ? [] : [NOT_UTF8]), ...extraNotes];
|
|
192
|
+
// A page that stops short of what it was asked for gives what's left of
|
|
193
|
+
// that as limitChars, so a reader that follows its notes ends where it
|
|
194
|
+
// asked to: at a cut line's end, for the rest a line page's note names.
|
|
195
|
+
const stoppedNote = (to: number, left: number) =>
|
|
196
|
+
`Stopped at character ${to} to stay within the ${maxChars}-character result limit; read the rest of what you asked for with offsetChars=${to} and limitChars=${left}.`;
|
|
197
|
+
const page = (to: number, note: string | undefined): Page => ({
|
|
198
|
+
path,
|
|
199
|
+
totalChars: text.length,
|
|
200
|
+
offsetChars: start,
|
|
201
|
+
nextOffsetChars: to < text.length ? to : null,
|
|
202
|
+
...(note !== undefined ? { note } : {}),
|
|
203
|
+
content: text.slice(start, to),
|
|
204
|
+
});
|
|
205
|
+
const whole = page(end, joined(notes));
|
|
206
|
+
if (maxChars === undefined || pageText(whole).length <= maxChars) return pageAnswer(whole);
|
|
207
|
+
// As many characters as fit beside the rest of the page, which takes the
|
|
208
|
+
// most with the largest offset it could stop at and the most left. A page
|
|
209
|
+
// moves by whole characters, a surrogate pair at once, so it never stops
|
|
210
|
+
// inside one.
|
|
211
|
+
const overhead = pageText({ ...page(end, joined([stoppedNote(end, end - start), ...notes])), nextOffsetChars: end, content: '' }).length + sectionLead('content');
|
|
212
|
+
const step = (at: number) => (splitsPair(text, at + 1) ? 2 : 1);
|
|
213
|
+
let to = Math.min(end, start + Math.max(0, maxChars - overhead));
|
|
214
|
+
if (splitsPair(text, to)) to--;
|
|
215
|
+
// A page always moves on, by one character at least, though a limit too
|
|
216
|
+
// small for the page's own fields and its first character then passes it:
|
|
217
|
+
// with room for one code unit, a surrogate pair is still taken whole. Where
|
|
218
|
+
// that reaches the page's own end, it holds all it was asked for, so it
|
|
219
|
+
// names no stop.
|
|
220
|
+
if (to === start) to = Math.min(end, start + step(start));
|
|
221
|
+
return pageAnswer(page(to, joined([to < end ? stoppedNote(to, end - to) : null, ...notes])));
|
|
222
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import type { ToolResult } from '../../types/events.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The text a model reads of read's, grep's, edit's and edit_many's answers:
|
|
5
|
+
* a header of the answer's own fields, one `key: value` to a line in the
|
|
6
|
+
* fields' order, then its sections, each a `--- label ---` line and the lines
|
|
7
|
+
* under it, an empty one left out. The answer's fields themselves reach a
|
|
8
|
+
* script as its structuredContent (ToolResult.structured), and a page or a
|
|
9
|
+
* receipt is held to the call's result limit as this text measures it.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/** The characters Unicode says end a line (UAX #14's mandatory breaks): LF, VT, FF, CR, NEL, U+2028 and U+2029. */
|
|
13
|
+
const LINE_BREAK = /[\n\v\f\r\u0085\u2028\u2029]/;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A value as a header line, a section's label or a listed line writes it: as
|
|
17
|
+
* it is, or, where it holds a line break or starts with a quote, as a JSON
|
|
18
|
+
* string. A path can hold a line break, and so can a note naming it or a line
|
|
19
|
+
* of a file grep matched; written as it is, it would start a line that reads
|
|
20
|
+
* as one of the answer's own. A value written as it is never starts with a
|
|
21
|
+
* quote, so one that does is always the quoted form, which gives back exactly
|
|
22
|
+
* what the value holds: without that, a value that is itself a JSON string,
|
|
23
|
+
* such as a line of a file reading `"a\nb"`, would read as the quoted form of
|
|
24
|
+
* another. JSON leaves NEL, U+2028 and U+2029 as they are, so they're escaped
|
|
25
|
+
* too.
|
|
26
|
+
*/
|
|
27
|
+
export function shownValue(value: string | number | boolean | null): string {
|
|
28
|
+
if (typeof value !== 'string') return String(value);
|
|
29
|
+
if (!value.startsWith('"') && !LINE_BREAK.test(value)) return value;
|
|
30
|
+
return JSON.stringify(value).replace(/[\u0085\u2028\u2029]/g, (c) => `\\u${c.charCodeAt(0).toString(16).padStart(4, '0')}`);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** A header line: a field's key and its value as shownValue writes it. */
|
|
34
|
+
export const fieldLine = (key: string, value: string | number | boolean | null): string => `${key}: ${shownValue(value)}`;
|
|
35
|
+
|
|
36
|
+
/** A section's text, its label and then its lines; an empty section is no text. */
|
|
37
|
+
export const sectionText = (label: string, body: string): string => (body === '' ? '' : `--- ${label} ---\n${body}`);
|
|
38
|
+
|
|
39
|
+
/** The answer's text: its header lines and then its sections, each on lines of its own. */
|
|
40
|
+
export const answerText = (header: string[], sections: string[] = []): string =>
|
|
41
|
+
[...header, ...sections.filter((section) => section !== '')].join('\n');
|
|
42
|
+
|
|
43
|
+
/** How much a section with any lines adds to its answer's text before them: the line feed before its label, and the label's line. */
|
|
44
|
+
export const sectionLead = (label: string): number => `\n--- ${label} ---\n`.length;
|
|
45
|
+
|
|
46
|
+
/** A success whose text is what the model reads and whose fields reach a script as its structuredContent. */
|
|
47
|
+
export const textAnswer = (text: string, structured: Record<string, unknown>): ToolResult =>
|
|
48
|
+
({ success: true, data: [{ type: 'text', text }], structured });
|
|
49
|
+
|
|
50
|
+
/** A grep result: the matches of one version of a file. */
|
|
51
|
+
export interface GrepResult {
|
|
52
|
+
file: string;
|
|
53
|
+
state?: string;
|
|
54
|
+
version: string;
|
|
55
|
+
lineEndings?: string;
|
|
56
|
+
matches: Array<{ line: number; text: string; context?: string[] }>;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** What grep found, as its structuredContent holds it. */
|
|
60
|
+
export interface GrepAnswer {
|
|
61
|
+
pattern: string;
|
|
62
|
+
results: GrepResult[];
|
|
63
|
+
totalMatches: number;
|
|
64
|
+
note?: string;
|
|
65
|
+
skipped?: Array<{ file: string; reason: string; size?: number; mimeType?: string }>;
|
|
66
|
+
incomplete?: Array<{ path: string; reason: string }>;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* grep's text: its pattern, match count and note, then a section for each
|
|
71
|
+
* version of a file it matched, labelled with the file, the version, the
|
|
72
|
+
* file's state where grep gives one and its line ends where it has them, then
|
|
73
|
+
* what it skipped and where its search was incomplete. As grep writes them, a
|
|
74
|
+
* match's line reads `N:text`, and where the call asked for context, each
|
|
75
|
+
* line around it reads `N-text`: matches whose context meets or overlaps are
|
|
76
|
+
* one run of lines, each line once, and `--` stands between runs with lines
|
|
77
|
+
* left out between them. Each match's context starts `contextBefore` lines
|
|
78
|
+
* before it, or at the file's first line. A line's text is written through
|
|
79
|
+
* shownValue, since more of the answer follows it.
|
|
80
|
+
*/
|
|
81
|
+
export function grepText(answer: GrepAnswer, contextBefore: number): string {
|
|
82
|
+
const header = [fieldLine('pattern', answer.pattern), fieldLine('totalMatches', answer.totalMatches)];
|
|
83
|
+
if (answer.note !== undefined) header.push(fieldLine('note', answer.note));
|
|
84
|
+
const sections = answer.results.map((result) => {
|
|
85
|
+
const label = `${shownValue(result.file)}: ${result.version}`
|
|
86
|
+
+ (result.state !== undefined ? ` (${result.state})` : '')
|
|
87
|
+
+ (result.lineEndings !== undefined ? `; lineEndings: ${result.lineEndings}` : '');
|
|
88
|
+
const lines: string[] = [];
|
|
89
|
+
const matched = new Set(result.matches.map((match) => match.line));
|
|
90
|
+
// The last line written: matches come in line order, so a window that
|
|
91
|
+
// meets or overlaps the run before it goes on from there.
|
|
92
|
+
let last = 0;
|
|
93
|
+
for (const match of result.matches) {
|
|
94
|
+
if (match.context === undefined) {
|
|
95
|
+
lines.push(`${String(match.line).padStart(6)}:${shownValue(match.text)}`);
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
const first = Math.max(1, match.line - contextBefore);
|
|
99
|
+
match.context.forEach((text, k) => {
|
|
100
|
+
const n = first + k;
|
|
101
|
+
if (n <= last) return;
|
|
102
|
+
if (last > 0 && n > last + 1) lines.push('--');
|
|
103
|
+
lines.push(`${String(n).padStart(6)}${matched.has(n) ? ':' : '-'}${shownValue(text)}`);
|
|
104
|
+
last = n;
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
return sectionText(label, lines.join('\n'));
|
|
108
|
+
});
|
|
109
|
+
if (answer.skipped !== undefined) {
|
|
110
|
+
sections.push(sectionText('skipped', answer.skipped.map((skip) => {
|
|
111
|
+
const facts = [...(skip.size !== undefined ? [`${skip.size} bytes`] : []), ...(skip.mimeType !== undefined ? [skip.mimeType] : [])];
|
|
112
|
+
return `${shownValue(skip.file)}: ${shownValue(skip.reason)}${facts.length ? ` (${facts.join(', ')})` : ''}`;
|
|
113
|
+
}).join('\n')));
|
|
114
|
+
}
|
|
115
|
+
if (answer.incomplete !== undefined) {
|
|
116
|
+
sections.push(sectionText('incomplete', answer.incomplete.map((gap) => `${shownValue(gap.path)}: ${shownValue(gap.reason)}`).join('\n')));
|
|
117
|
+
}
|
|
118
|
+
return answerText(header, sections);
|
|
119
|
+
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { isUtf8 } from 'node:buffer';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* answers use them.
|
|
4
|
+
* A stored file's text as read shows it and grep searches it, and lines
|
|
5
|
+
* numbered the way `cat -n` numbers them, with a long one cut. Read, grep and
|
|
6
|
+
* edit's answers use them.
|
|
5
7
|
*/
|
|
6
8
|
|
|
7
9
|
/** Whether the bytes open with a UTF-8 byte order mark. */
|
|
@@ -9,6 +11,57 @@ export function hasBom(bytes: Uint8Array): boolean {
|
|
|
9
11
|
return bytes.length >= 3 && bytes[0] === 0xef && bytes[1] === 0xbb && bytes[2] === 0xbf;
|
|
10
12
|
}
|
|
11
13
|
|
|
14
|
+
export interface FileText {
|
|
15
|
+
/** The bytes decoded as UTF-8, as character paging reads them: a BOM and every CR kept. */
|
|
16
|
+
raw: string;
|
|
17
|
+
/**
|
|
18
|
+
* Its lines, as read shows them and grep searches them: without the BOM, a
|
|
19
|
+
* CR before a line feed dropped, and a final line end ending the last line
|
|
20
|
+
* rather than starting an empty one. So "a\r\nb\r\n" is two lines, and an
|
|
21
|
+
* empty text has none. A line whose own text ends in a CR keeps its line
|
|
22
|
+
* end's CR too, as stored: an edit reads a CR before a line feed in its old
|
|
23
|
+
* text as part of the line end, so text copied from "a\r" and the next line
|
|
24
|
+
* would lose the CR that is the line's own.
|
|
25
|
+
*/
|
|
26
|
+
lines: string[];
|
|
27
|
+
/** Where each line starts in `raw`. */
|
|
28
|
+
starts: number[];
|
|
29
|
+
bom: boolean;
|
|
30
|
+
/** How many line ends were CRLF, and how many a bare LF. */
|
|
31
|
+
crlfEnds: number;
|
|
32
|
+
lfEnds: number;
|
|
33
|
+
/** How many lines with a CRLF end keep its CR, since their own text ends in a CR. */
|
|
34
|
+
crKept: number;
|
|
35
|
+
/** Whether the bytes are valid UTF-8; where they aren't, `raw` holds U+FFFD. */
|
|
36
|
+
utf8: boolean;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function fileText(bytes: Buffer): FileText {
|
|
40
|
+
const raw = bytes.toString('utf-8');
|
|
41
|
+
const bom = hasBom(bytes);
|
|
42
|
+
const lines: string[] = [];
|
|
43
|
+
const starts: number[] = [];
|
|
44
|
+
let crlfEnds = 0;
|
|
45
|
+
let lfEnds = 0;
|
|
46
|
+
let crKept = 0;
|
|
47
|
+
// A BOM decodes to the single code unit U+FEFF.
|
|
48
|
+
for (let at = bom ? 1 : 0; at < raw.length;) {
|
|
49
|
+
const lf = raw.indexOf('\n', at);
|
|
50
|
+
starts.push(at);
|
|
51
|
+
if (lf === -1) {
|
|
52
|
+
lines.push(raw.slice(at));
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
const crlf = lf > at && raw.charCodeAt(lf - 1) === 13;
|
|
56
|
+
if (crlf) crlfEnds++; else lfEnds++;
|
|
57
|
+
const keepsCr = crlf && lf - 1 > at && raw.charCodeAt(lf - 2) === 13;
|
|
58
|
+
if (keepsCr) crKept++;
|
|
59
|
+
lines.push(raw.slice(at, crlf && !keepsCr ? lf - 1 : lf));
|
|
60
|
+
at = lf + 1;
|
|
61
|
+
}
|
|
62
|
+
return { raw, lines, starts, bom, crlfEnds, lfEnds, crKept, utf8: isUtf8(bytes) };
|
|
63
|
+
}
|
|
64
|
+
|
|
12
65
|
/** How long a line read shows before it cuts the line. */
|
|
13
66
|
export const MAX_LINE_CHARS = 2000;
|
|
14
67
|
|
|
@@ -26,43 +79,16 @@ export function safeCut(value: string, at: number): number {
|
|
|
26
79
|
/**
|
|
27
80
|
* One line numbered the way `cat -n` numbers it: a six-wide number, a tab and
|
|
28
81
|
* the line. A line longer than `maxChars` is cut, saying how many characters
|
|
29
|
-
* it holds past the cut,
|
|
82
|
+
* it holds past the cut, or, where `readOn` is given, how to read them.
|
|
30
83
|
*/
|
|
31
84
|
export function numberedLine(line: string, n: number, maxChars = MAX_LINE_CHARS, readOn?: (cut: number) => string): string {
|
|
32
85
|
const number = String(n).padStart(6);
|
|
33
86
|
if (line.length <= maxChars) return `${number}\t${line}`;
|
|
34
87
|
const cut = safeCut(line, maxChars);
|
|
35
|
-
return `${number}\t${line.slice(0, cut)} [… ${line.length - cut} more chars
|
|
88
|
+
return `${number}\t${line.slice(0, cut)} [… ${readOn ? readOn(cut) : `${line.length - cut} more chars`}]`;
|
|
36
89
|
}
|
|
37
90
|
|
|
38
91
|
/** Lines numbered from `start`, each as numberedLine shows it. */
|
|
39
92
|
export function numbered(lines: string[], start: number, maxChars = MAX_LINE_CHARS): string {
|
|
40
93
|
return lines.map((line, i) => numberedLine(line, start + i, maxChars)).join('\n');
|
|
41
94
|
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* How many characters a string takes inside JSON's quotes, as JSON.stringify
|
|
45
|
-
* writes it: a quote, a backslash or a control character is escaped, and so
|
|
46
|
-
* is a lone surrogate.
|
|
47
|
-
*/
|
|
48
|
-
export function jsonLength(value: string): number {
|
|
49
|
-
let length = 0;
|
|
50
|
-
for (let i = 0; i < value.length; i++) length += jsonCharLength(value, i);
|
|
51
|
-
return length;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/** The JSON length of the code unit at `i`, as jsonLength counts it. */
|
|
55
|
-
export function jsonCharLength(value: string, i: number): number {
|
|
56
|
-
const c = value.charCodeAt(i);
|
|
57
|
-
if (c === 0x22 || c === 0x5c) return 2;
|
|
58
|
-
if (c < 0x20) return c === 0x08 || c === 0x09 || c === 0x0a || c === 0x0c || c === 0x0d ? 2 : 6;
|
|
59
|
-
if (c >= 0xd800 && c <= 0xdbff) {
|
|
60
|
-
const next = value.charCodeAt(i + 1);
|
|
61
|
-
return next >= 0xdc00 && next <= 0xdfff ? 1 : 6;
|
|
62
|
-
}
|
|
63
|
-
if (c >= 0xdc00 && c <= 0xdfff) {
|
|
64
|
-
const before = i > 0 ? value.charCodeAt(i - 1) : 0;
|
|
65
|
-
return before >= 0xd800 && before <= 0xdbff ? 1 : 6;
|
|
66
|
-
}
|
|
67
|
-
return 1;
|
|
68
|
-
}
|
|
@@ -20,24 +20,44 @@ export interface MountConfig {
|
|
|
20
20
|
* Where the mount's tools get what they read (default: 'chronicle').
|
|
21
21
|
* - 'chronicle': the workspace keeps the mount's files in its store, where
|
|
22
22
|
* writes and edits land first, and takes in disk's changes under the
|
|
23
|
-
* three-way rule as
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* and none of its files go into the store. No scan or watcher
|
|
23
|
+
* three-way rule as `read`, listings, searches, syncs and scans reach
|
|
24
|
+
* them. Its tools read the store's copy.
|
|
25
|
+
* - 'direct': for a checkout, such as a git one, whose history is its
|
|
26
|
+
* own. Every read, listing and search is disk's own copy as it is when
|
|
27
|
+
* it runs, and none of its files go into the store. No scan or watcher
|
|
29
28
|
* runs, so no call waits behind one, and `sync`, `materialize` and the
|
|
30
|
-
* watch settings have nothing to act on.
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
29
|
+
* watch settings have nothing to act on. Not with `watch` other than
|
|
30
|
+
* 'never', `watchDebounceMs`, `watchRootPollMs`, a `wakeOnChange` that
|
|
31
|
+
* would wake (true, or a non-empty list) or `autoMaterialize: true`:
|
|
32
|
+
* each of those would never act, and the workspace refuses the mount.
|
|
33
|
+
* Writable, as any mount with no `mode` is, its `write`, `edit`,
|
|
34
|
+
* `edit_many` and `delete` land on disk when they answer, or don't
|
|
35
|
+
* happen: a file is staged beside itself in `.workspace-staged-<id>` and
|
|
36
|
+
* renamed over itself, keeping its mode, so no reader sees half of it;
|
|
37
|
+
* an edit is applied to disk's text as it is now, and again on top of a
|
|
38
|
+
* change another writer makes meanwhile; and `edit_many` checks every
|
|
39
|
+
* edit before writing its files one by one, naming each file's outcome
|
|
40
|
+
* if a write fails partway. A file with other hard links gets a file of
|
|
41
|
+
* its own at its path, and the others keep the old text; a file this
|
|
42
|
+
* process may not write is refused. Nothing is synced, so a power loss
|
|
43
|
+
* can lose a write its answer called landed. An undo or other move of
|
|
44
|
+
* the store's head leaves the files as they are, and at the agent's next
|
|
45
|
+
* start the framework tells it once that writes from turns its history
|
|
46
|
+
* no longer holds are still on disk. Where each agent's latest write
|
|
47
|
+
* lies is saved at a clean stop, in a record no branch switch rewinds,
|
|
48
|
+
* so a restart on another branch still tells it, and after a crash a
|
|
49
|
+
* move away from the writes since then isn't told. The framework's own
|
|
50
|
+
* files, its
|
|
51
|
+
* tool-result spills, saved payloads and fetched references, never go to
|
|
52
|
+
* a mount configured direct. Its `ignore`
|
|
35
53
|
* has a default (see there). Paths, links, its `include`, other mounts'
|
|
36
54
|
* directories, size limits and the walk cap hold as on a 'chronicle'
|
|
37
|
-
* mount. Its tools read beneath whatever directory is at its
|
|
38
|
-
* root, with no check against the one a
|
|
39
|
-
*
|
|
40
|
-
*
|
|
55
|
+
* mount. Its tools read and write beneath whatever directory is at its
|
|
56
|
+
* root when each call starts, with no check against the one a
|
|
57
|
+
* 'chronicle' run of it last agreed with, so a root repointed through a
|
|
58
|
+
* link is read and written where it leads now. Where that root now lies
|
|
59
|
+
* elsewhere than the last start placed it, each call nests in it, as a
|
|
60
|
+
* start would now, every mount
|
|
41
61
|
* configured beneath its path, where that path leads beneath its root,
|
|
42
62
|
* and every other mount whose root, as that start placed it, lies
|
|
43
63
|
* beneath where its root lies now, or whose configured path lies
|
|
@@ -52,7 +72,10 @@ export interface MountConfig {
|
|
|
52
72
|
* them pending, or an intent the workspace can't read, which may hold one
|
|
53
73
|
* of those. They stay in view, and the workspace says so on stderr and
|
|
54
74
|
* through the framework's ops alerts, naming them and the ways to start it
|
|
55
|
-
* direct.
|
|
75
|
+
* direct. Until a start finds none held, it takes no writes, edits or
|
|
76
|
+
* deletions, so what's held only shrinks: a `sync` of a held path takes
|
|
77
|
+
* disk's copy, and a `materialize` naming the mount writes the store's.
|
|
78
|
+
* It runs unwatched, and walks by the direct kind's default
|
|
56
79
|
* ignore list where its config names none; `ls` without a path, and
|
|
57
80
|
* `status`, give its `backend` as 'chronicle' and that list. A mount that
|
|
58
81
|
* ran direct and runs as 'chronicle' again takes in what disk changed
|
|
@@ -290,7 +313,8 @@ export interface MountConfig {
|
|
|
290
313
|
/**
|
|
291
314
|
* If true, writes/edits/deletes via the module's tools materialize to the
|
|
292
315
|
* filesystem immediately (not just into Chronicle tree state). Required for
|
|
293
|
-
* any mount shared across agents as a communication channel
|
|
316
|
+
* any store-backed mount shared across agents as a communication channel (a
|
|
317
|
+
* direct mount's writes reach disk without it, and it's refused there) — without it,
|
|
294
318
|
* another agent's watcher on the same directory sees nothing. The watcher
|
|
295
319
|
* suppresses its own echoes, so this doesn't cause self-wake loops.
|
|
296
320
|
*/
|