indusagi-coding-agent 0.2.3 → 0.2.5
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/CHANGELOG.md +25 -0
- package/LICENSE +661 -0
- package/README.md +95 -1
- package/dist/entry.js +3205 -1585
- package/dist/guardrails.js +47 -515
- package/dist/index.js +3232 -1671
- package/package.json +8 -7
- package/dist/types/addons/addons.test.d.ts +0 -21
- package/dist/types/addons/contract.d.ts +0 -640
- package/dist/types/addons/dispatch/event-dispatcher.d.ts +0 -140
- package/dist/types/addons/dispatch/index.d.ts +0 -23
- package/dist/types/addons/dispatch/tool-interceptor.d.ts +0 -128
- package/dist/types/addons/host.d.ts +0 -246
- package/dist/types/addons/index.d.ts +0 -51
- package/dist/types/addons/manifest.d.ts +0 -56
- package/dist/types/addons/sandbox.d.ts +0 -103
- package/dist/types/addons/surface.d.ts +0 -42
- package/dist/types/boot/auth-vault.d.ts +0 -29
- package/dist/types/boot/boot.d.ts +0 -26
- package/dist/types/boot/boot.test.d.ts +0 -15
- package/dist/types/boot/contract.d.ts +0 -236
- package/dist/types/boot/index.d.ts +0 -20
- package/dist/types/boot/invocation.d.ts +0 -40
- package/dist/types/boot/invocation.test.d.ts +0 -8
- package/dist/types/boot/runners/addon-wiring.d.ts +0 -103
- package/dist/types/boot/runners/addon-wiring.test.d.ts +0 -19
- package/dist/types/boot/runners/checkpoint.d.ts +0 -133
- package/dist/types/boot/runners/checkpoint.test.d.ts +0 -12
- package/dist/types/boot/runners/delegate-runner.d.ts +0 -89
- package/dist/types/boot/runners/delegate-runner.test.d.ts +0 -13
- package/dist/types/boot/runners/index.d.ts +0 -13
- package/dist/types/boot/runners/link-runner.d.ts +0 -20
- package/dist/types/boot/runners/memdir.d.ts +0 -103
- package/dist/types/boot/runners/memdir.test.d.ts +0 -12
- package/dist/types/boot/runners/oneshot-runner.d.ts +0 -19
- package/dist/types/boot/runners/read-state.d.ts +0 -82
- package/dist/types/boot/runners/read-state.test.d.ts +0 -10
- package/dist/types/boot/runners/registry.d.ts +0 -30
- package/dist/types/boot/runners/repl-runner.d.ts +0 -19
- package/dist/types/boot/runners/session-persist.test.d.ts +0 -10
- package/dist/types/boot/runners/session.d.ts +0 -65
- package/dist/types/boot/runners/session.test.d.ts +0 -10
- package/dist/types/boot/stages.d.ts +0 -92
- package/dist/types/boot/upgrade/apply.d.ts +0 -45
- package/dist/types/boot/upgrade/index.d.ts +0 -13
- package/dist/types/boot/upgrade/upgrades.d.ts +0 -126
- package/dist/types/briefing/briefing.test.d.ts +0 -15
- package/dist/types/briefing/compose.d.ts +0 -37
- package/dist/types/briefing/context-docs.d.ts +0 -38
- package/dist/types/briefing/context-docs.test.d.ts +0 -18
- package/dist/types/briefing/contract.d.ts +0 -686
- package/dist/types/briefing/index.d.ts +0 -29
- package/dist/types/briefing/macros.d.ts +0 -206
- package/dist/types/briefing/skills.d.ts +0 -67
- package/dist/types/capability-deck/bridge-ledger/index.d.ts +0 -25
- package/dist/types/capability-deck/bridge-ledger/key.d.ts +0 -65
- package/dist/types/capability-deck/bridge-ledger/ledger.d.ts +0 -129
- package/dist/types/capability-deck/bridge-ledger/network.d.ts +0 -115
- package/dist/types/capability-deck/builtin-bridge.d.ts +0 -114
- package/dist/types/capability-deck/capability-deck.test.d.ts +0 -18
- package/dist/types/capability-deck/cards/bg-process-card.d.ts +0 -99
- package/dist/types/capability-deck/cards/index.d.ts +0 -37
- package/dist/types/capability-deck/cards/memory-card.d.ts +0 -68
- package/dist/types/capability-deck/cards/plan-file.d.ts +0 -56
- package/dist/types/capability-deck/cards/plan-tools.d.ts +0 -97
- package/dist/types/capability-deck/cards/plan-tools.test.d.ts +0 -9
- package/dist/types/capability-deck/cards/saas-card.d.ts +0 -78
- package/dist/types/capability-deck/cards/task-card.d.ts +0 -106
- package/dist/types/capability-deck/cards/todo-card.d.ts +0 -78
- package/dist/types/capability-deck/cards/workflow-card.d.ts +0 -55
- package/dist/types/capability-deck/cards/workflow-card.test.d.ts +0 -12
- package/dist/types/capability-deck/checkpoint.int.test.d.ts +0 -25
- package/dist/types/capability-deck/contract.d.ts +0 -317
- package/dist/types/capability-deck/index.d.ts +0 -46
- package/dist/types/capability-deck/manifest.d.ts +0 -60
- package/dist/types/capability-deck/provision.d.ts +0 -76
- package/dist/types/capability-deck/read-edit-gate.int.test.d.ts +0 -21
- package/dist/types/channels/channels.test.d.ts +0 -15
- package/dist/types/channels/contract.d.ts +0 -489
- package/dist/types/channels/framer.d.ts +0 -49
- package/dist/types/channels/index.d.ts +0 -24
- package/dist/types/channels/link/dialog.d.ts +0 -138
- package/dist/types/channels/link/driver.d.ts +0 -81
- package/dist/types/channels/link/index.d.ts +0 -13
- package/dist/types/channels/link/server.d.ts +0 -70
- package/dist/types/channels/oneshot.d.ts +0 -37
- package/dist/types/channels/ops.d.ts +0 -89
- package/dist/types/channels/session-ops.d.ts +0 -80
- package/dist/types/conductor/bash-guard.d.ts +0 -106
- package/dist/types/conductor/bash-guard.test.d.ts +0 -17
- package/dist/types/conductor/catalog/catalog.d.ts +0 -87
- package/dist/types/conductor/catalog/index.d.ts +0 -14
- package/dist/types/conductor/catalog/matcher.d.ts +0 -47
- package/dist/types/conductor/conductor.d.ts +0 -189
- package/dist/types/conductor/conductor.test.d.ts +0 -10
- package/dist/types/conductor/contract.d.ts +0 -774
- package/dist/types/conductor/diagnostics.d.ts +0 -183
- package/dist/types/conductor/diagnostics.test.d.ts +0 -10
- package/dist/types/conductor/index.d.ts +0 -26
- package/dist/types/conductor/permission-gate.integration.test.d.ts +0 -22
- package/dist/types/conductor/permission-wiring.test.d.ts +0 -14
- package/dist/types/conductor/permissions.d.ts +0 -217
- package/dist/types/conductor/permissions.test.d.ts +0 -12
- package/dist/types/conductor/plan-mode.integration.test.d.ts +0 -23
- package/dist/types/conductor/post-edit-diagnostics.test.d.ts +0 -13
- package/dist/types/conductor/signal-hub/hub.d.ts +0 -83
- package/dist/types/conductor/signal-hub/index.d.ts +0 -19
- package/dist/types/conductor/signal-hub/translate.d.ts +0 -77
- package/dist/types/conductor/skill-parse/index.d.ts +0 -10
- package/dist/types/conductor/skill-parse/parse.d.ts +0 -67
- package/dist/types/conductor/submit.test.d.ts +0 -28
- package/dist/types/conductor/transcript-store/index.d.ts +0 -16
- package/dist/types/conductor/transcript-store/serialize.d.ts +0 -106
- package/dist/types/conductor/transcript-store/serialize.test.d.ts +0 -10
- package/dist/types/conductor/transcript-store/store.d.ts +0 -188
- package/dist/types/console/components/AgentsView.d.ts +0 -41
- package/dist/types/console/components/BackgroundAgents.d.ts +0 -63
- package/dist/types/console/components/BackgroundAgents.test.d.ts +0 -8
- package/dist/types/console/components/Banner.d.ts +0 -110
- package/dist/types/console/components/Composer.d.ts +0 -37
- package/dist/types/console/components/StatusBar.d.ts +0 -42
- package/dist/types/console/components/TerminalConsole.d.ts +0 -32
- package/dist/types/console/components/WorkingIndicator.d.ts +0 -44
- package/dist/types/console/components/WorkingIndicator.test.d.ts +0 -9
- package/dist/types/console/components/banner-sweep.d.ts +0 -55
- package/dist/types/console/components/banner.test.d.ts +0 -9
- package/dist/types/console/components/welcome.d.ts +0 -115
- package/dist/types/console/components/welcome.test.d.ts +0 -9
- package/dist/types/console/console.test.d.ts +0 -19
- package/dist/types/console/contract.d.ts +0 -598
- package/dist/types/console/index.d.ts +0 -34
- package/dist/types/console/input/complete.d.ts +0 -120
- package/dist/types/console/input/dir-reader.d.ts +0 -28
- package/dist/types/console/input/index.d.ts +0 -24
- package/dist/types/console/input/input.test.d.ts +0 -14
- package/dist/types/console/input/keymap.d.ts +0 -193
- package/dist/types/console/input/paste.d.ts +0 -131
- package/dist/types/console/mount.d.ts +0 -53
- package/dist/types/console/overlays/approval-queue.d.ts +0 -71
- package/dist/types/console/overlays/approval.d.ts +0 -104
- package/dist/types/console/overlays/approval.test.d.ts +0 -17
- package/dist/types/console/overlays/auth.d.ts +0 -31
- package/dist/types/console/overlays/boards.d.ts +0 -55
- package/dist/types/console/overlays/host.d.ts +0 -45
- package/dist/types/console/overlays/index.d.ts +0 -15
- package/dist/types/console/overlays/pickers.d.ts +0 -37
- package/dist/types/console/overlays/sessions.d.ts +0 -29
- package/dist/types/console/reducer.d.ts +0 -51
- package/dist/types/console/slash/builtins.d.ts +0 -33
- package/dist/types/console/slash/commands/dynamic.d.ts +0 -57
- package/dist/types/console/slash/commands/dynamic.test.d.ts +0 -9
- package/dist/types/console/slash/commands/integrations.d.ts +0 -28
- package/dist/types/console/slash/commands/integrations.test.d.ts +0 -18
- package/dist/types/console/slash/commands/shared.d.ts +0 -72
- package/dist/types/console/slash/commands/transcript.d.ts +0 -24
- package/dist/types/console/slash/commands/transcript.test.d.ts +0 -10
- package/dist/types/console/slash/commands/workbench.d.ts +0 -21
- package/dist/types/console/slash/commands/workbench.test.d.ts +0 -10
- package/dist/types/console/slash/index.d.ts +0 -34
- package/dist/types/console/slash/registry.d.ts +0 -90
- package/dist/types/console/slash/resolve.d.ts +0 -109
- package/dist/types/console/slash/slash.test.d.ts +0 -18
- package/dist/types/console/startup.d.ts +0 -119
- package/dist/types/console/theme/adapter.d.ts +0 -79
- package/dist/types/console/theme/index.d.ts +0 -18
- package/dist/types/console/theme/palette.d.ts +0 -77
- package/dist/types/console/theme/resolve.d.ts +0 -45
- package/dist/types/console/theme/theme.test.d.ts +0 -16
- package/dist/types/console/theme/tokens.d.ts +0 -62
- package/dist/types/entry.d.ts +0 -17
- package/dist/types/guardrails.d.ts +0 -33
- package/dist/types/index.d.ts +0 -24
- package/dist/types/insight/channel.d.ts +0 -45
- package/dist/types/insight/contract.d.ts +0 -411
- package/dist/types/insight/index.d.ts +0 -26
- package/dist/types/insight/insight.test.d.ts +0 -17
- package/dist/types/insight/recorder.d.ts +0 -63
- package/dist/types/insight/redaction.d.ts +0 -44
- package/dist/types/insight/replay.d.ts +0 -77
- package/dist/types/insight/sampling.d.ts +0 -84
- package/dist/types/insight/serialize.d.ts +0 -54
- package/dist/types/insight/sinks/console.d.ts +0 -36
- package/dist/types/insight/sinks/file.d.ts +0 -37
- package/dist/types/insight/sinks/index.d.ts +0 -16
- package/dist/types/insight/sinks/stream.d.ts +0 -53
- package/dist/types/kit/clipboard-image.d.ts +0 -40
- package/dist/types/kit/external-editor.d.ts +0 -35
- package/dist/types/kit/image.d.ts +0 -102
- package/dist/types/kit/index.d.ts +0 -29
- package/dist/types/kit/kit.test.d.ts +0 -13
- package/dist/types/kit/shell.d.ts +0 -50
- package/dist/types/kit/tool-fetch.d.ts +0 -165
- package/dist/types/launch/catalog.d.ts +0 -51
- package/dist/types/launch/contract.d.ts +0 -387
- package/dist/types/launch/credentials.d.ts +0 -112
- package/dist/types/launch/index.d.ts +0 -28
- package/dist/types/launch/invocation/attachments.d.ts +0 -72
- package/dist/types/launch/invocation/flags.d.ts +0 -59
- package/dist/types/launch/invocation/index.d.ts +0 -23
- package/dist/types/launch/invocation/read.d.ts +0 -52
- package/dist/types/launch/invocation/usage.d.ts +0 -25
- package/dist/types/launch/launch.test.d.ts +0 -20
- package/dist/types/launch/oauth.d.ts +0 -101
- package/dist/types/launch/packages.d.ts +0 -75
- package/dist/types/launch/packages.test.d.ts +0 -15
- package/dist/types/launch/pickers.d.ts +0 -97
- package/dist/types/runtime-bridge/bridges/_drive.d.ts +0 -74
- package/dist/types/runtime-bridge/bridges/builtins.d.ts +0 -77
- package/dist/types/runtime-bridge/bridges/claude-cli.d.ts +0 -37
- package/dist/types/runtime-bridge/bridges/codex-cli.d.ts +0 -27
- package/dist/types/runtime-bridge/bridges/index.d.ts +0 -15
- package/dist/types/runtime-bridge/bridges/indusagi-cli.d.ts +0 -36
- package/dist/types/runtime-bridge/broker.d.ts +0 -182
- package/dist/types/runtime-bridge/contract.d.ts +0 -436
- package/dist/types/runtime-bridge/index.d.ts +0 -21
- package/dist/types/runtime-bridge/runtime-bridge.test.d.ts +0 -17
- package/dist/types/runtime-bridge/sink.d.ts +0 -59
- package/dist/types/sessions/contract.d.ts +0 -79
- package/dist/types/sessions/index.d.ts +0 -11
- package/dist/types/sessions/library.d.ts +0 -95
- package/dist/types/sessions/sessions.test.d.ts +0 -11
- package/dist/types/settings/contract.d.ts +0 -175
- package/dist/types/settings/index.d.ts +0 -13
- package/dist/types/settings/manager.d.ts +0 -109
- package/dist/types/settings/settings.test.d.ts +0 -16
- package/dist/types/transcript-export/index.d.ts +0 -20
- package/dist/types/transcript-export/publish.d.ts +0 -81
- package/dist/types/transcript-export/sgr.d.ts +0 -90
- package/dist/types/transcript-export/template.d.ts +0 -64
- package/dist/types/transcript-export/theme-bridge.d.ts +0 -99
- package/dist/types/transcript-export/transcript-export.test.d.ts +0 -16
- package/dist/types/window-budget/budget/estimate.d.ts +0 -47
- package/dist/types/window-budget/budget/gate.d.ts +0 -37
- package/dist/types/window-budget/budget/index.d.ts +0 -14
- package/dist/types/window-budget/budget/slice.d.ts +0 -38
- package/dist/types/window-budget/condenser.d.ts +0 -73
- package/dist/types/window-budget/contract.d.ts +0 -182
- package/dist/types/window-budget/index.d.ts +0 -17
- package/dist/types/window-budget/microcompact.d.ts +0 -68
- package/dist/types/window-budget/microcompact.test.d.ts +0 -16
- package/dist/types/window-budget/rehydrate.d.ts +0 -56
- package/dist/types/window-budget/summarize/condense.d.ts +0 -70
- package/dist/types/window-budget/summarize/index.d.ts +0 -12
- package/dist/types/window-budget/summarize/prompt.d.ts +0 -56
- package/dist/types/window-budget/window-budget.test.d.ts +0 -18
- package/dist/types/workflow-engine/agent-runner.d.ts +0 -105
- package/dist/types/workflow-engine/agent-runner.test.d.ts +0 -8
- package/dist/types/workflow-engine/display.d.ts +0 -148
- package/dist/types/workflow-engine/display.test.d.ts +0 -1
- package/dist/types/workflow-engine/engine.d.ts +0 -183
- package/dist/types/workflow-engine/engine.test.d.ts +0 -1
- package/dist/types/workflow-engine/index.d.ts +0 -21
- package/dist/types/workflow-engine/parse.d.ts +0 -64
- package/dist/types/workflow-engine/parse.test.d.ts +0 -1
- package/dist/types/workflow-engine/structured-output.d.ts +0 -51
- package/dist/types/workflow-engine/structured-output.test.d.ts +0 -1
- package/dist/types/workspace/brand.d.ts +0 -26
- package/dist/types/workspace/index.d.ts +0 -11
- package/dist/types/workspace/locator.d.ts +0 -50
- package/dist/types/workspace/runtime-detect.d.ts +0 -56
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* publishTranscript — render a session transcript to a standalone, self-contained
|
|
3
|
-
* HTML document.
|
|
4
|
-
*
|
|
5
|
-
* The publisher takes a list of transcript entries (each carrying a framework
|
|
6
|
-
* message) and produces one HTML string with no external dependencies: prose is
|
|
7
|
-
* rendered to HTML with `marked`, fenced code is syntax-highlighted with
|
|
8
|
-
* `highlight.js`, terminal-styled tool output is painted to spans by
|
|
9
|
-
* {@link paintSgr}, and all colors come from a {@link ThemeBridge} over an
|
|
10
|
-
* {@link ExportTheme}. Markdown and highlighting are run *here*, at publish time,
|
|
11
|
-
* so the rendered HTML is baked into the page payload and the page needs no
|
|
12
|
-
* client-side parser to display — the page ships ready to read.
|
|
13
|
-
*
|
|
14
|
-
* The two third-party libraries this layer leans on are MIT (`marked`) and
|
|
15
|
-
* BSD-3-Clause (`highlight.js`); their license notices are preserved verbatim in
|
|
16
|
-
* the emitted document (the `MARKED_LIB` / `HIGHLIGHT_LIB` shell slots) as the
|
|
17
|
-
* licenses require, while the libraries themselves are used, never reimplemented.
|
|
18
|
-
*/
|
|
19
|
-
import { type ImageContent, type PublishOptions, type TextContent } from "../briefing/contract";
|
|
20
|
-
/**
|
|
21
|
-
* The conversational role a published turn carries. Mirrors the conductor's node
|
|
22
|
-
* roles but is declared locally so the publisher depends only on the briefing
|
|
23
|
-
* contract, not on the conductor subsystem.
|
|
24
|
-
*/
|
|
25
|
-
export type PublishRole = "user" | "assistant" | "tool" | "system" | "condense" | "note";
|
|
26
|
-
/**
|
|
27
|
-
* One transcript node the publisher consumes. Structurally a subset of the
|
|
28
|
-
* conductor's persisted entry: a `role` for attribution and a `message` carrying
|
|
29
|
-
* the framework content this node renders. The `message` is read with narrow
|
|
30
|
-
* structural access so the publisher never imports the framework message union.
|
|
31
|
-
*/
|
|
32
|
-
export interface PublishEntry {
|
|
33
|
-
/** Attribution role for this node. */
|
|
34
|
-
readonly role: PublishRole;
|
|
35
|
-
/** The framework message payload to render. */
|
|
36
|
-
readonly message: PublishMessage;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* The narrow view of a framework message the publisher reads. Covers the three
|
|
40
|
-
* concrete message roles' content shapes plus the tool-call linkage a tool result
|
|
41
|
-
* carries, without redeclaring the whole framework union.
|
|
42
|
-
*/
|
|
43
|
-
export interface PublishMessage {
|
|
44
|
-
/** The framework message role. */
|
|
45
|
-
readonly role: string;
|
|
46
|
-
/** The message content — a bare string or a list of content parts. */
|
|
47
|
-
readonly content: string | readonly MessagePart[];
|
|
48
|
-
/** Present on tool-result messages; links the node to its originating call. */
|
|
49
|
-
readonly toolCallId?: string;
|
|
50
|
-
/** Present on tool-result messages; the invoked tool's display name. */
|
|
51
|
-
readonly toolName?: string;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* The content-part union the publisher renders. Text and image parts alias the
|
|
55
|
-
* framework's; thinking and tool-call parts are read structurally so the
|
|
56
|
-
* assistant turn can surface a call's name and arguments.
|
|
57
|
-
*/
|
|
58
|
-
export type MessagePart = TextContent | ImageContent | {
|
|
59
|
-
readonly type: "thinking";
|
|
60
|
-
readonly thinking: string;
|
|
61
|
-
} | {
|
|
62
|
-
readonly type: "toolCall";
|
|
63
|
-
readonly id: string;
|
|
64
|
-
readonly name: string;
|
|
65
|
-
readonly arguments: Readonly<Record<string, unknown>>;
|
|
66
|
-
};
|
|
67
|
-
/**
|
|
68
|
-
* Render a session transcript to a standalone HTML document.
|
|
69
|
-
*
|
|
70
|
-
* Configures the markdown + highlight pipeline, renders every entry to a turn,
|
|
71
|
-
* serializes the turns into a base64 payload, resolves the theme through a
|
|
72
|
-
* {@link ThemeBridge}, and fills the page shell. The returned string is a complete
|
|
73
|
-
* `<!doctype html>` document with all styling, content, and the preserved library
|
|
74
|
-
* notices inlined — it can be written to disk and opened directly.
|
|
75
|
-
*
|
|
76
|
-
* @param entries the transcript nodes to publish, in display order
|
|
77
|
-
* @param opts optional theme, title, output directory, and widget overrides
|
|
78
|
-
* @returns the rendered standalone HTML document
|
|
79
|
-
* @throws a {@link briefingFault} of kind `"publish"` if assembly fails
|
|
80
|
-
*/
|
|
81
|
-
export declare function publishTranscript(entries: readonly PublishEntry[], opts?: PublishOptions): string;
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SGR painter — a table-driven ANSI Select-Graphic-Rendition state machine that
|
|
3
|
-
* converts a terminal byte stream into a sequence of styled HTML spans.
|
|
4
|
-
*
|
|
5
|
-
* Terminal programs encode color and emphasis with CSI sequences of the form
|
|
6
|
-
* `ESC [ p1 ; p2 ; … m` (the trailing `m` is the SGR final byte). The parameters
|
|
7
|
-
* are small integers whose meaning is fixed by ECMA-48 / ISO 6429: `0` resets,
|
|
8
|
-
* `1`/`3`/`4` switch on weight/italic/underline, `30`–`37` and `90`–`97` set the
|
|
9
|
-
* foreground from the sixteen-color palette, `40`–`47` and `100`–`107` set the
|
|
10
|
-
* background, and the two extended introducers `38`/`48` pull a 256-index or a
|
|
11
|
-
* 24-bit triple out of the following parameters.
|
|
12
|
-
*
|
|
13
|
-
* Rather than a long `switch`, the semantics live in a *table*: each handled code
|
|
14
|
-
* maps to an {@link SgrMutation} — the partial {@link SgrState} that code imposes —
|
|
15
|
-
* and the painter folds the matched mutation over the running state. Extending the
|
|
16
|
-
* machine is adding a row, never editing control flow. The two extended
|
|
17
|
-
* introducers are the only parametric cases and are handled by a small reader
|
|
18
|
-
* that consumes their trailing parameters.
|
|
19
|
-
*
|
|
20
|
-
* The pipeline is three stages:
|
|
21
|
-
* 1. {@link tokenizeSgr} splits the raw stream into an alternation of text runs
|
|
22
|
-
* and SGR parameter lists ({@link SgrToken}s).
|
|
23
|
-
* 2. {@link foldSgr} folds an SGR parameter list into the running
|
|
24
|
-
* {@link SgrState} using the {@link SGR_CODE_TABLE} dispatch table.
|
|
25
|
-
* 3. {@link paintSgr} drives the two over the whole stream, wrapping each text
|
|
26
|
-
* run in a `<span>` whose class list and inline color style reflect the state
|
|
27
|
-
* in force.
|
|
28
|
-
*
|
|
29
|
-
* The {@link SgrState} / {@link SgrToken} / {@link SgrMutation} vocabulary is the
|
|
30
|
-
* briefing contract's; the SGR code meanings are the published standard's.
|
|
31
|
-
*/
|
|
32
|
-
import { type SgrMutation, type SgrState, type SgrToken } from "../briefing/contract";
|
|
33
|
-
/**
|
|
34
|
-
* The read-only public view of the SGR dispatch table — each fixed-meaning SGR
|
|
35
|
-
* code mapped to the {@link SgrMutation} it imposes. Exported so callers can
|
|
36
|
-
* introspect the handled code space (the extended `38`/`48` introducers are not
|
|
37
|
-
* present here; they are parametric and resolved by the painter).
|
|
38
|
-
*/
|
|
39
|
-
export declare const SGR_CODE_TABLE: ReadonlyMap<number, SgrMutation>;
|
|
40
|
-
/**
|
|
41
|
-
* Fold one SGR parameter list into a running {@link SgrState}, returning the next
|
|
42
|
-
* state.
|
|
43
|
-
*
|
|
44
|
-
* Walks the parameters left to right. A fixed-meaning code is resolved through
|
|
45
|
-
* the {@link CODE_TABLE} and its mutation merged over the state. The two extended
|
|
46
|
-
* introducers `38` (foreground) and `48` (background) are handled inline: the
|
|
47
|
-
* reader consumes their trailing `5;n` or `2;r;g;b` parameters and the resolved
|
|
48
|
-
* color is written to the matching channel. An empty list is the bare `ESC[m`
|
|
49
|
-
* form and is treated as a reset, matching terminal behavior.
|
|
50
|
-
*
|
|
51
|
-
* Pure: the input state is never mutated; a fresh object is returned.
|
|
52
|
-
*
|
|
53
|
-
* @param state the style in force before this sequence
|
|
54
|
-
* @param params the numeric parameter list of one SGR sequence
|
|
55
|
-
*/
|
|
56
|
-
export declare function foldSgr(state: SgrState, params: readonly number[]): SgrState;
|
|
57
|
-
/**
|
|
58
|
-
* Split a raw terminal stream into an ordered list of {@link SgrToken}s.
|
|
59
|
-
*
|
|
60
|
-
* Scans for CSI sequences of the form `ESC [ … m`. Each such sequence becomes an
|
|
61
|
-
* `sgr` token carrying its parsed numeric parameters (an empty selector yields an
|
|
62
|
-
* empty list, the bare-reset form). The runs of ordinary characters between
|
|
63
|
-
* sequences become `text` tokens. Non-SGR control sequences — any CSI whose final
|
|
64
|
-
* byte is not `m`, plus bare escapes — are dropped: they carry cursor and screen
|
|
65
|
-
* commands that have no place in flowed HTML, so swallowing them keeps the output
|
|
66
|
-
* clean while preserving every printable character.
|
|
67
|
-
*
|
|
68
|
-
* Empty `text` runs are never emitted, so the token stream is dense.
|
|
69
|
-
*
|
|
70
|
-
* @param input the raw ANSI/terminal byte stream
|
|
71
|
-
*/
|
|
72
|
-
export declare function tokenizeSgr(input: string): SgrToken[];
|
|
73
|
-
/**
|
|
74
|
-
* Paint an ANSI/terminal byte stream into a string of styled HTML spans.
|
|
75
|
-
*
|
|
76
|
-
* Drives the three stages end to end: tokenize the stream, fold each SGR sequence
|
|
77
|
-
* into the running {@link SgrState}, and wrap each intervening text run in a span
|
|
78
|
-
* reflecting the state in force when that run was emitted. Text is HTML-escaped;
|
|
79
|
-
* non-SGR control sequences are dropped; runs under the neutral state are emitted
|
|
80
|
-
* without a wrapping span. The result is safe to splice directly into a transcript
|
|
81
|
-
* page.
|
|
82
|
-
*
|
|
83
|
-
* The state resets to {@link SGR_INITIAL_STATE} only on an explicit reset code (or
|
|
84
|
-
* a bare `ESC[m`); it otherwise persists across text runs, so a color set once
|
|
85
|
-
* stays in force until changed, exactly as a terminal renders it.
|
|
86
|
-
*
|
|
87
|
-
* @param input the raw ANSI/terminal byte stream to convert
|
|
88
|
-
* @returns an HTML fragment of escaped text and styled `<span>`s
|
|
89
|
-
*/
|
|
90
|
-
export declare function paintSgr(input: string): string;
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Page-shell template — the standalone HTML/CSS scaffold the transcript publisher
|
|
3
|
-
* fills.
|
|
4
|
-
*
|
|
5
|
-
* This module is a freshly authored single-file page: its own element names
|
|
6
|
-
* (`<main class="xscript">`, `.turn`, `.turn-tag`, `.turn-body`, `.tool-frame`,
|
|
7
|
-
* `.aside-note`), its own stylesheet, and its own `{{TOKEN}}` placeholder names —
|
|
8
|
-
* the {@link SHELL_SLOTS} values from the briefing contract
|
|
9
|
-
* (`THEME_VARS`/`PAGE_SURFACE`/…/`MARKED_LIB`/`HIGHLIGHT_LIB`). None of the class
|
|
10
|
-
* names, DOM structure, placeholder tokens, or color values are carried over from
|
|
11
|
-
* any prior export template.
|
|
12
|
-
*
|
|
13
|
-
* The publisher computes a value for every slot and calls {@link fill} to splice
|
|
14
|
-
* them in. The page is self-contained: theme colors arrive as CSS custom
|
|
15
|
-
* properties in `:root`, the markdown and syntax-highlight libraries are inlined,
|
|
16
|
-
* the session payload is embedded as base64, and a small client renderer
|
|
17
|
-
* (the `SCRIPT` slot) hydrates the transcript on load.
|
|
18
|
-
*/
|
|
19
|
-
import { type ShellSlot } from "../briefing/contract";
|
|
20
|
-
/**
|
|
21
|
-
* The page stylesheet, emitted into the `STYLES` slot. Reads its colors from the
|
|
22
|
-
* `--x-*` custom properties the `THEME_VARS` slot defines, so re-theming is a
|
|
23
|
-
* matter of changing the variables, not the rules. Class names are this page's
|
|
24
|
-
* own (`xscript`, `turn`, `tool-frame`, `aside-note`, the `sgr-*` family the
|
|
25
|
-
* painter emits, and the highlight `xhl` block).
|
|
26
|
-
*/
|
|
27
|
-
export declare const PAGE_STYLES: string;
|
|
28
|
-
/**
|
|
29
|
-
* The client-side renderer, emitted into the `SCRIPT` slot. Decodes the base64
|
|
30
|
-
* session payload, walks its turns, and renders each into the `.xscript` root
|
|
31
|
-
* using the inlined `marked` (markdown) and `highlight.js` (code) libraries. Code
|
|
32
|
-
* fences are highlighted into the page's own `xhl-*` classes; prose is parsed by
|
|
33
|
-
* marked. Pre-rendered tool widgets and SGR-painted text arrive already-HTML in
|
|
34
|
-
* the payload and are inserted verbatim.
|
|
35
|
-
*/
|
|
36
|
-
export declare const CLIENT_SCRIPT: string;
|
|
37
|
-
/**
|
|
38
|
-
* The HTML page shell carrying every {@link SHELL_SLOTS} placeholder as a
|
|
39
|
-
* `{{TOKEN}}` marker. {@link fill} replaces each marker with its computed value.
|
|
40
|
-
* The structure: a themed `:root`, the inlined stylesheet, the two vendored
|
|
41
|
-
* libraries, the base64 payload bound to `window.__XSCRIPT_PAYLOAD__`, and the
|
|
42
|
-
* client renderer that hydrates `#xscript-root`.
|
|
43
|
-
*/
|
|
44
|
-
export declare const PAGE_SHELL = "<!doctype html>\n<html lang=\"en\">\n<head>\n<meta charset=\"utf-8\" />\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n<title>Session Transcript</title>\n<style>\n:root {\n{{THEME_VARS}}\n --x-page-surface: {{PAGE_SURFACE}};\n --x-card-surface: {{CARD_SURFACE}};\n --x-note-surface: {{NOTE_SURFACE}};\n}\n{{STYLES}}\n</style>\n</head>\n<body>\n<main class=\"xscript\">\n <header class=\"xscript-head\">\n <h1>Session Transcript</h1>\n <div class=\"xscript-meta\">Self-contained HTML export</div>\n </header>\n <div id=\"xscript-root\"></div>\n</main>\n<script>\n/* {{MARKED_LIB}} */\n</script>\n<script>\n/* {{HIGHLIGHT_LIB}} */\n</script>\n<script>\nwindow.__XSCRIPT_PAYLOAD__ = \"{{PAYLOAD}}\";\n</script>\n<script>\n{{SCRIPT}}\n</script>\n</body>\n</html>";
|
|
45
|
-
/**
|
|
46
|
-
* The map a {@link fill} call supplies — one value per {@link ShellSlot} token. A
|
|
47
|
-
* value may be omitted, in which case its placeholder is replaced with the empty
|
|
48
|
-
* string (so a partial fill leaves no stray `{{TOKEN}}` in the output).
|
|
49
|
-
*/
|
|
50
|
-
export type SlotValues = Partial<Record<ShellSlot, string>>;
|
|
51
|
-
/**
|
|
52
|
-
* Replace every `{{TOKEN}}` placeholder in a template with the value supplied for
|
|
53
|
-
* that slot, returning the filled string.
|
|
54
|
-
*
|
|
55
|
-
* Walks the known {@link SHELL_SLOTS} (not an open scan), so only sanctioned
|
|
56
|
-
* placeholders are substituted and a stray `{{…}}` in user content is left
|
|
57
|
-
* untouched. Each token is replaced globally; a slot with no supplied value
|
|
58
|
-
* collapses to the empty string. The replacement is value-literal — a `$` in a
|
|
59
|
-
* value does not trigger regex backreference expansion.
|
|
60
|
-
*
|
|
61
|
-
* @param template the shell carrying `{{TOKEN}}` markers
|
|
62
|
-
* @param values the per-slot values to splice in
|
|
63
|
-
*/
|
|
64
|
-
export declare function fill(template: string, values: SlotValues): string;
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ThemeBridge — the color service behind the HTML transcript export.
|
|
3
|
-
*
|
|
4
|
-
* Everything the publisher needs to turn an {@link ExportTheme} token bag into
|
|
5
|
-
* concrete page colors lives here: parsing CSS colors into {@link Rgb}, measuring
|
|
6
|
-
* a color's WCAG relative luminance through a precomputed lookup table, deciding
|
|
7
|
-
* whether the theme reads {@link ThemeMode} light or dark, deriving lighter/darker
|
|
8
|
-
* surface variants from a base, and projecting the whole theme to the CSS custom
|
|
9
|
-
* properties the page shell consumes.
|
|
10
|
-
*
|
|
11
|
-
* Two facts are interface-dictated and kept faithful:
|
|
12
|
-
* - The WCAG relative-luminance formula — linearize each sRGB channel with the
|
|
13
|
-
* gamma piecewise curve, then weight `0.2126 R + 0.7152 G + 0.0722 B`. The
|
|
14
|
-
* per-channel linearization is precomputed once into {@link buildLuminanceLut}
|
|
15
|
-
* (a {@link LuminanceLut}) so a luminance read is three table lookups plus a
|
|
16
|
-
* weighted sum, never a `pow` per pixel.
|
|
17
|
-
* - Readable foreground selection — given a background, pick the foreground
|
|
18
|
-
* (from the theme's own ink choices) whose contrast against that background is
|
|
19
|
-
* the larger, so text on any derived surface stays legible.
|
|
20
|
-
*
|
|
21
|
-
* Every default color the bridge falls back to is this rebuild's own
|
|
22
|
-
* {@link FALLBACK_EXPORT_THEME} (a deep-slate palette), never a legacy export's
|
|
23
|
-
* magic constant.
|
|
24
|
-
*/
|
|
25
|
-
import { type ExportTheme, type LuminanceLut, type Rgb, type ThemeBridge, type ThemeMode } from "../briefing/contract";
|
|
26
|
-
/**
|
|
27
|
-
* Build the 256-entry sRGB→linear lookup table the WCAG relative-luminance
|
|
28
|
-
* formula needs for each channel.
|
|
29
|
-
*
|
|
30
|
-
* For a channel value `v` in `0–255`, normalize to `s = v / 255`, then apply the
|
|
31
|
-
* standard gamma-expansion: `s ≤ 0.03928 ? s / 12.92 : ((s + 0.055) / 1.055) ^
|
|
32
|
-
* 2.4`. The table holds the linearized value at each integer channel so a
|
|
33
|
-
* luminance read avoids the per-call `pow`. The math is the published standard's;
|
|
34
|
-
* the table is this module's.
|
|
35
|
-
*/
|
|
36
|
-
export declare function buildLuminanceLut(): Float64Array;
|
|
37
|
-
/**
|
|
38
|
-
* Parse a CSS color string into its {@link Rgb} channels. Recognizes `#rgb`,
|
|
39
|
-
* `#rrggbb` (and their alpha-bearing `#rgba` / `#rrggbbaa` forms, alpha dropped)
|
|
40
|
-
* and the functional `rgb(r, g, b)` / `rgba(r, g, b, a)` notations. Any
|
|
41
|
-
* unrecognized input resolves to `null`, which the bridge treats as "fall back to
|
|
42
|
-
* the theme default" rather than throwing.
|
|
43
|
-
*
|
|
44
|
-
* @param color a CSS color string
|
|
45
|
-
*/
|
|
46
|
-
export declare function parseColor(color: string): Rgb | null;
|
|
47
|
-
/** Render an {@link Rgb} back to a `#rrggbb` CSS string. */
|
|
48
|
-
export declare function formatColor(rgb: Rgb): string;
|
|
49
|
-
/**
|
|
50
|
-
* The concrete {@link ThemeBridge}. Holds a resolved {@link ExportTheme} and a
|
|
51
|
-
* {@link LuminanceLut}, and serves every color query the publisher makes against
|
|
52
|
-
* them. Pure with respect to its inputs — construction resolves the theme once and
|
|
53
|
-
* the methods only read.
|
|
54
|
-
*/
|
|
55
|
-
export declare class DefaultThemeBridge implements ThemeBridge {
|
|
56
|
-
readonly theme: ExportTheme;
|
|
57
|
-
private readonly lut;
|
|
58
|
-
/**
|
|
59
|
-
* @param theme an {@link ExportTheme} to serve; defaults to the rebuild's own
|
|
60
|
-
* {@link FALLBACK_EXPORT_THEME}.
|
|
61
|
-
* @param lut the luminance lookup table to read; defaults to the shared
|
|
62
|
-
* module-level table.
|
|
63
|
-
*/
|
|
64
|
-
constructor(theme?: ExportTheme, lut?: LuminanceLut);
|
|
65
|
-
/** The WCAG relative luminance (0–1) of a CSS color; unparseable input reads 0. */
|
|
66
|
-
luminance(color: string): number;
|
|
67
|
-
/** Whether the theme's page surface reads light or dark. */
|
|
68
|
-
mode(): ThemeMode;
|
|
69
|
-
/**
|
|
70
|
-
* Derive a surface variant from a base color. The `amount` is a signed lightness
|
|
71
|
-
* delta in channel space; the sign is honored directly so a caller can lighten
|
|
72
|
-
* (`+`) or darken (`−`) explicitly. When `amount` is `0` the base is returned
|
|
73
|
-
* formatted but unchanged. Unparseable bases fall through to the theme's card
|
|
74
|
-
* surface so a derivation never yields an empty string.
|
|
75
|
-
*
|
|
76
|
-
* @param base the base CSS color to adjust
|
|
77
|
-
* @param amount signed lightness delta (positive lightens, negative darkens)
|
|
78
|
-
*/
|
|
79
|
-
deriveSurface(base: string, amount: number): string;
|
|
80
|
-
/**
|
|
81
|
-
* Pick the more readable of the theme's two ink colors for a given background by
|
|
82
|
-
* comparing each ink's WCAG contrast against it and returning the higher. This
|
|
83
|
-
* is the bridge's own readable-foreground chooser — used when text sits on a
|
|
84
|
-
* derived surface whose lightness is not known ahead of time.
|
|
85
|
-
*
|
|
86
|
-
* @param background the surface the text will sit on
|
|
87
|
-
*/
|
|
88
|
-
readableInk(background: string): string;
|
|
89
|
-
/** Project the theme to its CSS custom properties, keyed by token name. */
|
|
90
|
-
toCssVars(): Readonly<Record<string, string>>;
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Build a {@link ThemeBridge} over an optional {@link ExportTheme}. The convenience
|
|
94
|
-
* factory the publisher calls; omitting the theme yields a bridge over the
|
|
95
|
-
* rebuild's own fallback palette.
|
|
96
|
-
*
|
|
97
|
-
* @param theme an export palette to serve, or undefined for the fallback
|
|
98
|
-
*/
|
|
99
|
-
export declare function createThemeBridge(theme?: ExportTheme): ThemeBridge;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Transcript-export subsystem — Phase 9 behavioral tests.
|
|
3
|
-
*
|
|
4
|
-
* Three concerns, exercised purely (no disk, no network):
|
|
5
|
-
* 1. {@link paintSgr} — the table-driven SGR machine turns an ANSI string
|
|
6
|
-
* (bold + red foreground + a 256-color index) into HTML spans carrying this
|
|
7
|
-
* page's own `sgr-*` classes and resolved colors, and a reset returns the
|
|
8
|
-
* text to a bare (span-less) run.
|
|
9
|
-
* 2. {@link DefaultThemeBridge} — picks a readable foreground for a dark and a
|
|
10
|
-
* light background through the WCAG luminance LUT, and never resolves to a
|
|
11
|
-
* forbidden upstream color (#343541 / rgb(24,24,30)).
|
|
12
|
-
* 3. {@link publishTranscript} — renders a small transcript to a self-contained
|
|
13
|
-
* HTML string carrying the new token/class names, the marked-rendered
|
|
14
|
-
* markdown, and none of the upstream magic colors.
|
|
15
|
-
*/
|
|
16
|
-
export {};
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Token estimation — the heuristic "meter stick" for the window-budget
|
|
3
|
-
* subsystem.
|
|
4
|
-
*
|
|
5
|
-
* Before we can decide whether the transcript is over budget (gate.ts) or where
|
|
6
|
-
* to slice it (slice.ts), we need a cheap, deterministic estimate of how many
|
|
7
|
-
* tokens each {@link AgentMessage} occupies. We do *not* call a tokenizer; we
|
|
8
|
-
* walk the serialized content and apply a small, transparent weighting model.
|
|
9
|
-
*
|
|
10
|
-
* Design notes (clean-room, deliberately distinct from any chars/4 + flat-image
|
|
11
|
-
* baseline):
|
|
12
|
-
* - The estimate is computed over a *serialization* of each message's
|
|
13
|
-
* payload, not over a JSON blob of the whole object — structural framing
|
|
14
|
-
* (braces, quotes, field names) is accounted for with small per-block adds
|
|
15
|
-
* rather than being measured character-for-character.
|
|
16
|
-
* - Constants below are this module's OWN tunables (a fractional
|
|
17
|
-
* bytes-per-token divisor plus per-block framing adds and a flat image
|
|
18
|
-
* cost). They are intentionally not the legacy fingerprint values.
|
|
19
|
-
* - The estimator is conservative (rounds up, adds framing) so the gate fires
|
|
20
|
-
* a little early rather than a little late — overflowing the window is worse
|
|
21
|
-
* than condensing one turn sooner than strictly necessary.
|
|
22
|
-
*/
|
|
23
|
-
import type { AgentMessage } from "../contract.js";
|
|
24
|
-
/**
|
|
25
|
-
* Estimate the token cost of one message in isolation. Exposed so the slice
|
|
26
|
-
* planner can build a prefix-sum without re-deriving the per-message weight.
|
|
27
|
-
*
|
|
28
|
-
* Cost = `ceil(serialized_chars / CHARS_PER_TOKEN)` + framing tokens +
|
|
29
|
-
* `images * IMAGE_TOKENS`. Always `>= 0` and biased high (conservative).
|
|
30
|
-
*/
|
|
31
|
-
export declare function estimateMessageTokens(message: AgentMessage): number;
|
|
32
|
-
/**
|
|
33
|
-
* Estimate the total token cost of a transcript: the sum of every message's
|
|
34
|
-
* {@link estimateMessageTokens}. This is a pure heuristic — the gate prefers a
|
|
35
|
-
* provider-anchored figure when one exists, and only falls back to this.
|
|
36
|
-
*/
|
|
37
|
-
export declare function estimateTokens(messages: AgentMessage[]): number;
|
|
38
|
-
/**
|
|
39
|
-
* Build a FORWARD prefix-sum array of per-message token estimates.
|
|
40
|
-
*
|
|
41
|
-
* Returns an array of length `messages.length + 1` where `result[i]` is the
|
|
42
|
-
* total estimated tokens of `messages[0 .. i)` (so `result[0] === 0` and
|
|
43
|
-
* `result[messages.length] === estimateTokens(messages)`). This monotonically
|
|
44
|
-
* non-decreasing array is exactly what {@link planSlice} binary-searches to find
|
|
45
|
-
* the cut boundary in O(log n).
|
|
46
|
-
*/
|
|
47
|
-
export declare function prefixTokens(messages: AgentMessage[]): number[];
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Budget gate — the trigger predicate for the window-budget subsystem.
|
|
3
|
-
*
|
|
4
|
-
* {@link isOverBudget} answers the single question "is the transcript large
|
|
5
|
-
* enough that we should condense before the next turn?" by comparing a token
|
|
6
|
-
* estimate against a window-relative threshold derived from the model's
|
|
7
|
-
* `contextWindow` and the caller-supplied {@link BudgetPolicy}.
|
|
8
|
-
*
|
|
9
|
-
* The threshold is computed as:
|
|
10
|
-
*
|
|
11
|
-
* limit = (contextWindow - reserveTokens?) * triggerRatio
|
|
12
|
-
*
|
|
13
|
-
* i.e. optional fixed headroom is carved off the window first, then the
|
|
14
|
-
* remaining capacity is scaled by the window-relative trigger ratio. This keeps
|
|
15
|
-
* the trigger free of baked-in token counts — `triggerRatio` lives in `(0, 1]`
|
|
16
|
-
* and `reserveTokens` is an optional config value, never a fingerprint constant.
|
|
17
|
-
*/
|
|
18
|
-
import type { AgentMessage, BudgetPolicy, Model } from "../contract.js";
|
|
19
|
-
import type { Api } from "indusagi/ai";
|
|
20
|
-
/**
|
|
21
|
-
* Compute the absolute token limit at which condensing should fire for a given
|
|
22
|
-
* model and policy. Exposed for callers that want the number itself (e.g. to
|
|
23
|
-
* display headroom) rather than just the boolean.
|
|
24
|
-
*
|
|
25
|
-
* `reserveTokens` (when present) is subtracted from the window before the ratio
|
|
26
|
-
* is applied; the result is floored at `0` so a misconfigured reserve larger
|
|
27
|
-
* than the window can never yield a negative limit.
|
|
28
|
-
*/
|
|
29
|
-
export declare function budgetLimit(model: Model<Api>, policy: BudgetPolicy): number;
|
|
30
|
-
/**
|
|
31
|
-
* Decide whether the transcript is over budget for the given model and policy.
|
|
32
|
-
*
|
|
33
|
-
* Uses the heuristic {@link estimateTokens} over the serialized transcript and
|
|
34
|
-
* compares it to {@link budgetLimit}. Returns `true` once the estimate strictly
|
|
35
|
-
* exceeds the limit — the signal the conductor uses to kick off a condense.
|
|
36
|
-
*/
|
|
37
|
-
export declare function isOverBudget(messages: AgentMessage[], model: Model<Api>, policy: BudgetPolicy): boolean;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Window-budget / budget — pure budget math.
|
|
3
|
-
*
|
|
4
|
-
* The arithmetic core of the window-budget subsystem, free of I/O, prompts, and
|
|
5
|
-
* model calls:
|
|
6
|
-
* - {@link estimateTokens} / {@link estimateMessageTokens} / {@link prefixTokens}
|
|
7
|
-
* — heuristic token measurement and the forward cumulative-token array.
|
|
8
|
-
* - {@link isOverBudget} / {@link budgetLimit} — the window-relative trigger.
|
|
9
|
-
* - {@link planSlice} — forward prefix-sum + binary-search cut planning that
|
|
10
|
-
* never splits a tool_call from its tool_result.
|
|
11
|
-
*/
|
|
12
|
-
export { estimateMessageTokens, estimateTokens, prefixTokens } from "./estimate.js";
|
|
13
|
-
export { budgetLimit, isOverBudget } from "./gate.js";
|
|
14
|
-
export { planSlice } from "./slice.js";
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Slice planner — decides *where* to cut the transcript when it is over budget.
|
|
3
|
-
*
|
|
4
|
-
* {@link planSlice} partitions a transcript into a `dropped` prefix (older
|
|
5
|
-
* messages destined for a summary) and a `kept` suffix (the verbatim recent
|
|
6
|
-
* tail), choosing the boundary so the tail holds roughly `policy.keepRecent`
|
|
7
|
-
* tokens. It does this with a FORWARD prefix-sum + BINARY SEARCH (not a backward
|
|
8
|
-
* accumulate-and-snap):
|
|
9
|
-
*
|
|
10
|
-
* 1. Build the cumulative-token array `prefix` (forward, monotonic).
|
|
11
|
-
* 2. The total is `prefix[n]`; we want the tail to be ~`keepRecent` tokens, so
|
|
12
|
-
* the *ideal* cut sits at the first index `i` whose suffix
|
|
13
|
-
* `prefix[n] - prefix[i]` has fallen to `<= keepRecent`. Equivalently, the
|
|
14
|
-
* first `i` with `prefix[i] >= prefix[n] - keepRecent`. That predicate is
|
|
15
|
-
* monotonic in `i`, so we BINARY-SEARCH the lower bound of the threshold
|
|
16
|
-
* `prefix[n] - keepRecent` over `prefix`.
|
|
17
|
-
* 3. Snap the resulting index FORWARD to the nearest *legal* boundary so we
|
|
18
|
-
* never land between a tool_call and its matching tool_result. A boundary
|
|
19
|
-
* is legal iff the message it lands on is not a `toolResult` (a tool result
|
|
20
|
-
* always belongs with the assistant turn that issued the call, so the tail
|
|
21
|
-
* may never begin with one).
|
|
22
|
-
*
|
|
23
|
-
* If the whole transcript already fits within `keepRecent`, or snapping forward
|
|
24
|
-
* consumes everything, the cut is `0` (nothing condensable — keep it all).
|
|
25
|
-
*/
|
|
26
|
-
import type { AgentMessage, BudgetPolicy, CondensePlan } from "../contract.js";
|
|
27
|
-
/**
|
|
28
|
-
* Plan the condense slice for a transcript under a {@link BudgetPolicy}.
|
|
29
|
-
*
|
|
30
|
-
* Chooses the cut via forward prefix-sum + binary search for the boundary that
|
|
31
|
-
* keeps ~`policy.keepRecent` recent tokens, then snaps that boundary forward to
|
|
32
|
-
* a legal point (never between a tool_call and its tool_result).
|
|
33
|
-
*
|
|
34
|
-
* @returns a {@link CondensePlan} with the chosen `cut`, the `kept` tail
|
|
35
|
-
* (`messages.slice(cut)`) and the `dropped` head (`messages.slice(0, cut)`).
|
|
36
|
-
* `cut === 0` when nothing is condensable.
|
|
37
|
-
*/
|
|
38
|
-
export declare function planSlice(messages: AgentMessage[], policy: BudgetPolicy): CondensePlan;
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Window-budget — the condenser factory (the conductor-consumable seam).
|
|
3
|
-
*
|
|
4
|
-
* {@link createCondenser} ties the three pure pieces together into a single
|
|
5
|
-
* function the conductor can drop into its auto-compaction hook:
|
|
6
|
-
*
|
|
7
|
-
* 1. **Gate** — {@link isOverBudget} asks "is this transcript large enough to
|
|
8
|
-
* condense?" against the bound model's window and the {@link BudgetPolicy}.
|
|
9
|
-
* 2. **Slice** — {@link planSlice} splits the transcript into a `dropped` head
|
|
10
|
-
* (older turns to fold away) and a verbatim `kept` tail, never cutting
|
|
11
|
-
* between a `toolCall` and its `toolResult`.
|
|
12
|
-
* 3. **Condense** — {@link summarize} turns the dropped head into one synthetic
|
|
13
|
-
* digest message (scope `"session"`), via the injectable model completer.
|
|
14
|
-
*
|
|
15
|
-
* The returned value is a {@link Condenser} — structurally a conductor
|
|
16
|
-
* `CondenseFn` `(messages) => AgentMessage[] | Promise<AgentMessage[]>`:
|
|
17
|
-
* - When over budget it returns `[summaryMessage, ...kept]` (a strictly smaller
|
|
18
|
-
* transcript: one digest in place of the dropped prefix, plus the recent tail).
|
|
19
|
-
* - Otherwise it returns the input list unchanged (the no-op identity the
|
|
20
|
-
* conductor expects when nothing needs doing).
|
|
21
|
-
*
|
|
22
|
-
* It is **network-free-testable**: with no `model` bound the gate cannot measure a
|
|
23
|
-
* window, so the condenser is an identity transform; inject a {@link CompleteFn}
|
|
24
|
-
* stub (and a `model`) to drive the summary path with no real API call.
|
|
25
|
-
*
|
|
26
|
-
* Branch-archival is *not* a second engine — {@link condenseScope} forwards to the
|
|
27
|
-
* shared {@link summarize} core pinned to scope `"branch"`. {@link condense} is the
|
|
28
|
-
* matching session-scope entrypoint. Both are re-exported here so callers can
|
|
29
|
-
* summarize a slice directly without building a full {@link Condenser}.
|
|
30
|
-
*/
|
|
31
|
-
import type { AgentMessage, BudgetPolicy, CondenserDeps, Condenser, Summary } from "./contract.js";
|
|
32
|
-
import { condenseScope, type SummarizeDeps } from "./summarize/index.js";
|
|
33
|
-
/**
|
|
34
|
-
* The fallback {@link BudgetPolicy} when the caller supplies none. These are
|
|
35
|
-
* ordinary configuration defaults — a window-relative ratio plus a token tail —
|
|
36
|
-
* computed from the model's own context window rather than fixed magic numbers.
|
|
37
|
-
* - `triggerRatio` 0.75 — condense once ~three-quarters of the window is used.
|
|
38
|
-
* - `keepRecent` 6000 — keep roughly the last 6k tokens of turns verbatim.
|
|
39
|
-
* - `reserveTokens` 2048 — carve a little headroom off the window first.
|
|
40
|
-
*
|
|
41
|
-
* Exported as {@link AUTO_CONDENSE_POLICY} so the conductor's token gate and the
|
|
42
|
-
* session runner's slice planner share **one** policy — the value the auto-path
|
|
43
|
-
* trigger ({@link isOverBudget}) compares against must equal the value the slice
|
|
44
|
-
* planner ({@link planSlice}) cuts with, or the gate and the cut disagree.
|
|
45
|
-
*/
|
|
46
|
-
export declare const AUTO_CONDENSE_POLICY: BudgetPolicy;
|
|
47
|
-
/**
|
|
48
|
-
* Build a {@link Condenser} from a {@link CondenserDeps} bundle. The result plugs
|
|
49
|
-
* straight into the conductor's `CondenseFn` seam.
|
|
50
|
-
*
|
|
51
|
-
* Behavior of the returned condenser, given a transcript `messages`:
|
|
52
|
-
* - If no `model` is bound (so the window is unknown), or the transcript is
|
|
53
|
-
* **not** over budget, return `messages` **unchanged**.
|
|
54
|
-
* - Otherwise {@link planSlice} the transcript; if there is nothing to drop
|
|
55
|
-
* (`cut === 0`) return it unchanged; else {@link summarize} the dropped head
|
|
56
|
-
* (scope `"session"`) and return `[summary.message, ...plan.kept]`.
|
|
57
|
-
*
|
|
58
|
-
* All dependencies are optional, so `createCondenser()` yields a working,
|
|
59
|
-
* network-free condenser (a no-op until a model and policy are supplied).
|
|
60
|
-
*/
|
|
61
|
-
export declare function createCondenser(deps?: CondenserDeps): Condenser;
|
|
62
|
-
/**
|
|
63
|
-
* Session-scope summarization: fold a slice of dropped messages into one digest
|
|
64
|
-
* for the active session. A thin wrapper over the shared {@link summarize} core
|
|
65
|
-
* pinned to scope `"session"` (the default), so callers don't pass the flag.
|
|
66
|
-
*/
|
|
67
|
-
export declare function condense(messages: AgentMessage[], deps?: Omit<SummarizeDeps, "scope">): Promise<Summary>;
|
|
68
|
-
/**
|
|
69
|
-
* Branch-scope summarization: archive an abandoned branch into one digest. Folds
|
|
70
|
-
* branch-summarization into the same machinery behind the scope flag — re-exported
|
|
71
|
-
* from the summarize subsystem so this module is the single condenser entrypoint.
|
|
72
|
-
*/
|
|
73
|
-
export { condenseScope };
|