@vellumai/assistant 0.8.8-dev.202606061043.373bc8f → 0.8.8-dev.202606061135.a446a08
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/package.json +1 -1
- package/src/__tests__/conversation-runtime-assembly.test.ts +4 -1
- package/src/__tests__/empty-response-hook.test.ts +1 -1
- package/src/__tests__/history-repair-hook.test.ts +1 -1
- package/src/__tests__/memory-v2-static-injector.test.ts +44 -0
- package/src/__tests__/title-generate-hook.test.ts +1 -1
- package/src/__tests__/tool-error-hook.test.ts +1 -1
- package/src/__tests__/tool-result-truncate-hook.test.ts +1 -1
- package/src/daemon/conversation-agent-loop.ts +14 -1
- package/src/daemon/conversation-runtime-assembly.ts +24 -13
- package/src/daemon/conversation.ts +8 -0
- package/src/plugins/defaults/compaction/package.json +0 -1
- package/src/plugins/defaults/empty-response/package.json +0 -1
- package/src/plugins/defaults/history-repair/package.json +0 -1
- package/src/plugins/defaults/index.ts +133 -22
- package/src/plugins/defaults/memory-retrieval/injectors.ts +47 -11
- package/src/plugins/defaults/memory-v3-shadow/package.json +0 -1
- package/src/plugins/defaults/title-generate/package.json +0 -1
- package/src/plugins/defaults/tool-error/package.json +0 -1
- package/src/plugins/defaults/tool-result-truncate/package.json +0 -1
- package/src/plugins/defaults/compaction/register.ts +0 -24
- package/src/plugins/defaults/empty-response/register.ts +0 -23
- package/src/plugins/defaults/history-repair/register.ts +0 -24
- package/src/plugins/defaults/memory-v3-shadow/register.ts +0 -26
- package/src/plugins/defaults/title-generate/register.ts +0 -35
- package/src/plugins/defaults/tool-error/register.ts +0 -23
- package/src/plugins/defaults/tool-result-truncate/register.ts +0 -24
package/package.json
CHANGED
|
@@ -123,6 +123,7 @@ function seedActiveSurfaceConversation(
|
|
|
123
123
|
data: SurfaceData,
|
|
124
124
|
channelCapabilities?: ChannelCapabilities,
|
|
125
125
|
commandIntent?: { type: string; payload?: string; languageCode?: string },
|
|
126
|
+
currentTurnIsNonInteractive?: boolean,
|
|
126
127
|
): void {
|
|
127
128
|
setConversation(conversationId, {
|
|
128
129
|
conversationId,
|
|
@@ -136,6 +137,7 @@ function seedActiveSurfaceConversation(
|
|
|
136
137
|
>([[surfaceId, { surfaceType: "dynamic_page", data }]]),
|
|
137
138
|
channelCapabilities: channelCapabilities ?? undefined,
|
|
138
139
|
commandIntent,
|
|
140
|
+
currentTurnIsNonInteractive,
|
|
139
141
|
} as never);
|
|
140
142
|
}
|
|
141
143
|
|
|
@@ -825,7 +827,6 @@ describe("applyRuntimeInjections — injection mode", () => {
|
|
|
825
827
|
const fullOptions = {
|
|
826
828
|
unifiedTurnContext:
|
|
827
829
|
"<turn_context>\ncurrent_time: 2026-03-04 (Tuesday) 12:00:00 +00:00 (UTC)\ninterface: telegram\n</turn_context>",
|
|
828
|
-
isNonInteractive: true,
|
|
829
830
|
// Guardian trust so the personal-memory gate admits the actor regardless
|
|
830
831
|
// of the telegram channel capabilities under test, letting the reminder
|
|
831
832
|
// gate hinge purely on PKB content presence.
|
|
@@ -853,6 +854,8 @@ describe("applyRuntimeInjections — injection mode", () => {
|
|
|
853
854
|
{ html: "<div>test</div>" },
|
|
854
855
|
channelCapabilities,
|
|
855
856
|
{ type: "start" },
|
|
857
|
+
// Non-interactive turn so the `<non_interactive_context>` branch fires.
|
|
858
|
+
true,
|
|
856
859
|
);
|
|
857
860
|
});
|
|
858
861
|
afterEach(() => {
|
|
@@ -31,7 +31,7 @@ import {
|
|
|
31
31
|
REFUSAL_NUDGE_TEXT,
|
|
32
32
|
} from "../plugins/defaults/empty-response/hooks/stop.js";
|
|
33
33
|
import stop from "../plugins/defaults/empty-response/hooks/stop.js";
|
|
34
|
-
import { defaultEmptyResponsePlugin } from "../plugins/defaults/
|
|
34
|
+
import { defaultEmptyResponsePlugin } from "../plugins/defaults/index.js";
|
|
35
35
|
import { runHook } from "../plugins/pipeline.js";
|
|
36
36
|
import {
|
|
37
37
|
registerPlugin,
|
|
@@ -21,8 +21,8 @@ import type {
|
|
|
21
21
|
UserPromptSubmitContext,
|
|
22
22
|
} from "../plugin-api/types.js";
|
|
23
23
|
import userPromptSubmit from "../plugins/defaults/history-repair/hooks/user-prompt-submit.js";
|
|
24
|
-
import { defaultHistoryRepairPlugin } from "../plugins/defaults/history-repair/register.js";
|
|
25
24
|
import { repairHistory } from "../plugins/defaults/history-repair/terminal.js";
|
|
25
|
+
import { defaultHistoryRepairPlugin } from "../plugins/defaults/index.js";
|
|
26
26
|
import { runHook } from "../plugins/pipeline.js";
|
|
27
27
|
import {
|
|
28
28
|
registerPlugin,
|
|
@@ -195,4 +195,48 @@ describe("memory-v2-static injector", () => {
|
|
|
195
195
|
expect(block!.id).toBe("memory-v2-static");
|
|
196
196
|
expect(block!.text).toContain("## Essentials");
|
|
197
197
|
});
|
|
198
|
+
|
|
199
|
+
test("skips (re)injection when the <info> block is carried in a flattened history block", async () => {
|
|
200
|
+
// Regression: when a historical user message's separate injection content
|
|
201
|
+
// blocks get collapsed into one text block (observed after a daemon restart
|
|
202
|
+
// / plugin hot-reload rebuilt the rendered history mid-conversation — the
|
|
203
|
+
// blocks are joined with "\n"), the `<info>` wrapper is no longer its own
|
|
204
|
+
// block but a newline-delimited section inside a larger block. Presence
|
|
205
|
+
// detection must still recognize it; otherwise the injector re-injects a
|
|
206
|
+
// duplicate `<info>` onto the new tail (the double-injection bug).
|
|
207
|
+
seedEssentials("Alice prefers VS Code.");
|
|
208
|
+
const ctx = makeContext();
|
|
209
|
+
const flattenedFirstUser = [
|
|
210
|
+
"<workspace>\nRoot: /ws\nFiles: a.md\n</workspace>",
|
|
211
|
+
"<turn_context>\ncurrent_time: now\n</turn_context>",
|
|
212
|
+
"<memory>\nactivated page summary\n</memory>",
|
|
213
|
+
"<info>\n## Essentials\n\nAlice prefers VS Code.\n</info>",
|
|
214
|
+
"what should we do next?",
|
|
215
|
+
].join("\n");
|
|
216
|
+
const runMessages: Message[] = [
|
|
217
|
+
{ role: "user", content: [{ type: "text", text: flattenedFirstUser }] },
|
|
218
|
+
{ role: "assistant", content: [{ type: "text", text: "On it." }] },
|
|
219
|
+
{ role: "user", content: [{ type: "text", text: "great, continue" }] },
|
|
220
|
+
];
|
|
221
|
+
expect(await memoryV2StaticInjector.produce(ctx, runMessages)).toBeNull();
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
test("still injects when a user message opens an <info> tag without closing it", async () => {
|
|
225
|
+
// False-positive guard: the wrapper matcher requires BOTH the opening and
|
|
226
|
+
// closing tags, so user prose that merely opens an injection-like tag must
|
|
227
|
+
// not be mistaken for a carried block and suppress injection.
|
|
228
|
+
seedEssentials("Alice prefers VS Code.");
|
|
229
|
+
const ctx = makeContext();
|
|
230
|
+
const runMessages: Message[] = [
|
|
231
|
+
{
|
|
232
|
+
role: "user",
|
|
233
|
+
content: [
|
|
234
|
+
{ type: "text", text: "<info>\n is this how the tag works?" },
|
|
235
|
+
],
|
|
236
|
+
},
|
|
237
|
+
];
|
|
238
|
+
const block = await memoryV2StaticInjector.produce(ctx, runMessages);
|
|
239
|
+
expect(block).not.toBeNull();
|
|
240
|
+
expect(block!.id).toBe("memory-v2-static");
|
|
241
|
+
});
|
|
198
242
|
});
|
|
@@ -51,9 +51,9 @@ import type {
|
|
|
51
51
|
StopContext,
|
|
52
52
|
UserPromptSubmitContext,
|
|
53
53
|
} from "../plugin-api/types.js";
|
|
54
|
+
import { defaultTitleGeneratePlugin } from "../plugins/defaults/index.js";
|
|
54
55
|
import stop from "../plugins/defaults/title-generate/hooks/stop.js";
|
|
55
56
|
import userPromptSubmit from "../plugins/defaults/title-generate/hooks/user-prompt-submit.js";
|
|
56
|
-
import { defaultTitleGeneratePlugin } from "../plugins/defaults/title-generate/register.js";
|
|
57
57
|
import { runHook } from "../plugins/pipeline.js";
|
|
58
58
|
import {
|
|
59
59
|
registerPlugin,
|
|
@@ -18,10 +18,10 @@ import { beforeEach, describe, expect, test } from "bun:test";
|
|
|
18
18
|
|
|
19
19
|
import { HOOKS } from "../plugin-api/constants.js";
|
|
20
20
|
import type { PluginLogger, PostToolUseContext } from "../plugin-api/types.js";
|
|
21
|
+
import { defaultToolErrorPlugin } from "../plugins/defaults/index.js";
|
|
21
22
|
import postToolUse, {
|
|
22
23
|
TOOL_ERROR_NUDGE_TEXT,
|
|
23
24
|
} from "../plugins/defaults/tool-error/hooks/post-tool-use.js";
|
|
24
|
-
import { defaultToolErrorPlugin } from "../plugins/defaults/tool-error/register.js";
|
|
25
25
|
import { runHook } from "../plugins/pipeline.js";
|
|
26
26
|
import {
|
|
27
27
|
registerPlugin,
|
|
@@ -16,8 +16,8 @@ import { beforeEach, describe, expect, test } from "bun:test";
|
|
|
16
16
|
|
|
17
17
|
import { HOOKS } from "../plugin-api/constants.js";
|
|
18
18
|
import type { PluginLogger, PostToolUseContext } from "../plugin-api/types.js";
|
|
19
|
+
import { defaultToolResultTruncatePlugin } from "../plugins/defaults/index.js";
|
|
19
20
|
import postToolUse from "../plugins/defaults/tool-result-truncate/hooks/post-tool-use.js";
|
|
20
|
-
import { defaultToolResultTruncatePlugin } from "../plugins/defaults/tool-result-truncate/register.js";
|
|
21
21
|
import {
|
|
22
22
|
truncateToolResult,
|
|
23
23
|
TRUNCATION_SUFFIX,
|
|
@@ -321,6 +321,16 @@ export interface AgentLoopConversationContext {
|
|
|
321
321
|
* conversation. Per-turn mutable, mirroring {@link currentRequestId}.
|
|
322
322
|
*/
|
|
323
323
|
currentCallSite?: LLMCallSite;
|
|
324
|
+
/**
|
|
325
|
+
* Whether the in-flight turn has no human present to answer clarification
|
|
326
|
+
* questions, set at turn start from the resolved interactivity signal
|
|
327
|
+
* (`options?.isInteractive` override, falling back to `hasNoClient` /
|
|
328
|
+
* `headlessLock`). Read back from the live conversation by runtime assembly
|
|
329
|
+
* to drive the `<non_interactive_context>` branch and the `background-turn`
|
|
330
|
+
* injector, so the orchestrator does not thread it per turn. Per-turn
|
|
331
|
+
* mutable, mirroring {@link currentCallSite}.
|
|
332
|
+
*/
|
|
333
|
+
currentTurnIsNonInteractive?: boolean;
|
|
324
334
|
|
|
325
335
|
readonly agentLoop: AgentLoop;
|
|
326
336
|
readonly provider: Provider;
|
|
@@ -742,6 +752,10 @@ export async function runAgentLoopImpl(
|
|
|
742
752
|
|
|
743
753
|
const isInteractiveResolved =
|
|
744
754
|
options?.isInteractive ?? (!ctx.hasNoClient && !ctx.headlessLock);
|
|
755
|
+
// Expose the turn's interactivity to plugin pipeline/injector contexts (read
|
|
756
|
+
// by buildPluginTurnContext) so runtime assembly can drive the
|
|
757
|
+
// `<non_interactive_context>` branch and the background-turn injector.
|
|
758
|
+
ctx.currentTurnIsNonInteractive = !isInteractiveResolved;
|
|
745
759
|
const diskPressureDecision = classifyDiskPressureTurnPolicy(
|
|
746
760
|
getDiskPressureStatus(),
|
|
747
761
|
{
|
|
@@ -1302,7 +1316,6 @@ export async function runAgentLoopImpl(
|
|
|
1302
1316
|
// Shared injection options — reused whenever we need to re-inject after reduction.
|
|
1303
1317
|
const injectionOpts = {
|
|
1304
1318
|
unifiedTurnContext: unifiedTurnContextStr,
|
|
1305
|
-
isNonInteractive: !isInteractiveResolved,
|
|
1306
1319
|
isBackgroundConversation: isBackgroundConversationType(
|
|
1307
1320
|
turnStartConversation?.conversationType,
|
|
1308
1321
|
),
|
|
@@ -1820,23 +1820,22 @@ function applyInjectionBlock(
|
|
|
1820
1820
|
*
|
|
1821
1821
|
* Most fields flow through to the per-injector {@link TurnInjectionInputs}
|
|
1822
1822
|
* bag attached to the {@link TurnContext} the caller provides (or to an
|
|
1823
|
-
* ephemeral {@link TurnContext} synthesized for test call sites).
|
|
1824
|
-
* number of fields drive hardcoded branches that live outside the injector
|
|
1825
|
-
* chain — `isNonInteractive` — because it is orchestrator-owned content that
|
|
1826
|
-
* never made sense as a plugin-overridable default injector.
|
|
1823
|
+
* ephemeral {@link TurnContext} synthesized for test call sites).
|
|
1827
1824
|
*
|
|
1828
1825
|
* The active workspace surface, the channel capabilities, the active document
|
|
1829
|
-
* list, the channel command context, the voice call-control prompt,
|
|
1830
|
-
* transport hints are not on this bag:
|
|
1831
|
-
* from the live conversation itself
|
|
1832
|
-
* the document store keyed by
|
|
1833
|
-
* `
|
|
1834
|
-
*
|
|
1826
|
+
* list, the channel command context, the voice call-control prompt, the
|
|
1827
|
+
* transport hints, and the turn's interactivity are not on this bag:
|
|
1828
|
+
* `applyRuntimeInjections` resolves them from the live conversation itself
|
|
1829
|
+
* (its surface state, `channelCapabilities`, the document store keyed by
|
|
1830
|
+
* `conversationId`, its `commandIntent`, its `voiceCallControlPrompt`, its
|
|
1831
|
+
* `transportHints`, and its `currentTurnIsNonInteractive` respectively — the
|
|
1832
|
+
* last driving the `<non_interactive_context>` branch and the `background-turn`
|
|
1833
|
+
* injector), so the orchestrator does not compute or thread any of them per
|
|
1834
|
+
* turn.
|
|
1835
1835
|
*/
|
|
1836
1836
|
export interface RuntimeInjectionOptions {
|
|
1837
1837
|
unifiedTurnContext?: string | null;
|
|
1838
1838
|
subagentStatusBlock?: string | null;
|
|
1839
|
-
isNonInteractive?: boolean;
|
|
1840
1839
|
/**
|
|
1841
1840
|
* True when the active conversation's type is "background" or "scheduled".
|
|
1842
1841
|
* Forwarded to {@link TurnInjectionInputs.isBackgroundConversation} so the
|
|
@@ -1907,6 +1906,7 @@ function buildTurnInjectionInputs(
|
|
|
1907
1906
|
options: RuntimeInjectionOptions,
|
|
1908
1907
|
channelCapabilities: ChannelCapabilities | null,
|
|
1909
1908
|
activeDocuments: TurnInjectionInputs["activeDocuments"],
|
|
1909
|
+
isNonInteractive: boolean,
|
|
1910
1910
|
): TurnInjectionInputs {
|
|
1911
1911
|
return {
|
|
1912
1912
|
mode: options.mode,
|
|
@@ -1915,7 +1915,7 @@ function buildTurnInjectionInputs(
|
|
|
1915
1915
|
channelCapabilities,
|
|
1916
1916
|
slackChronologicalMessages: options.slackChronologicalMessages,
|
|
1917
1917
|
slackActiveThreadFocusBlock: options.slackActiveThreadFocusBlock,
|
|
1918
|
-
isNonInteractive
|
|
1918
|
+
isNonInteractive,
|
|
1919
1919
|
isBackgroundConversation: options.isBackgroundConversation,
|
|
1920
1920
|
activeDocuments,
|
|
1921
1921
|
};
|
|
@@ -2033,6 +2033,16 @@ export async function applyRuntimeInjections(
|
|
|
2033
2033
|
const transportHints =
|
|
2034
2034
|
findConversationOrSubagent(conversationId)?.transportHints ?? null;
|
|
2035
2035
|
|
|
2036
|
+
// Source the turn's interactivity from the live conversation rather than a
|
|
2037
|
+
// per-turn option. The orchestrator resolves it once at turn start (the
|
|
2038
|
+
// `isInteractive` override, falling back to the conversation's client /
|
|
2039
|
+
// headless state) and records it on the conversation, so the same value
|
|
2040
|
+
// drives the `<non_interactive_context>` branch and the `background-turn`
|
|
2041
|
+
// injector on every assembly call within the turn.
|
|
2042
|
+
const isNonInteractive =
|
|
2043
|
+
findConversationOrSubagent(conversationId)?.currentTurnIsNonInteractive ??
|
|
2044
|
+
false;
|
|
2045
|
+
|
|
2036
2046
|
// Build the per-injector inputs and attach them to the caller's
|
|
2037
2047
|
// TurnContext (without mutating it). When the caller didn't supply one,
|
|
2038
2048
|
// synthesize a minimal fallback so the chain still runs — test call sites
|
|
@@ -2042,6 +2052,7 @@ export async function applyRuntimeInjections(
|
|
|
2042
2052
|
options,
|
|
2043
2053
|
channelCapabilities,
|
|
2044
2054
|
activeDocuments,
|
|
2055
|
+
isNonInteractive,
|
|
2045
2056
|
);
|
|
2046
2057
|
const turnCtx: TurnContext = options.turnContext
|
|
2047
2058
|
? { ...options.turnContext, injectionInputs }
|
|
@@ -2197,7 +2208,7 @@ export async function applyRuntimeInjections(
|
|
|
2197
2208
|
|
|
2198
2209
|
// For non-interactive conversations (scheduled jobs, work items), instruct the
|
|
2199
2210
|
// model to never ask for clarification — there is no human present to answer.
|
|
2200
|
-
if (
|
|
2211
|
+
if (isNonInteractive) {
|
|
2201
2212
|
const userTail = result[result.length - 1];
|
|
2202
2213
|
if (userTail && userTail.role === "user") {
|
|
2203
2214
|
result = [
|
|
@@ -246,6 +246,14 @@ export class Conversation {
|
|
|
246
246
|
/** @internal */ loadedHistoryPersonalMemoryAllowed?: boolean;
|
|
247
247
|
/** @internal */ voiceCallControlPrompt?: string;
|
|
248
248
|
/** @internal */ transportHints?: string[];
|
|
249
|
+
/**
|
|
250
|
+
* Whether the in-flight turn has no human present to answer clarification
|
|
251
|
+
* questions, set at turn start from the resolved interactivity signal.
|
|
252
|
+
* Read back by runtime assembly to drive the `<non_interactive_context>`
|
|
253
|
+
* branch and the `background-turn` injector.
|
|
254
|
+
* @internal
|
|
255
|
+
*/
|
|
256
|
+
currentTurnIsNonInteractive?: boolean;
|
|
249
257
|
/** @internal */ assistantId?: string;
|
|
250
258
|
/** @internal */ commandIntent?: {
|
|
251
259
|
type: string;
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* First-party default plugins — definitions and centralized registration.
|
|
3
3
|
*
|
|
4
|
-
* Each default
|
|
5
|
-
*
|
|
6
|
-
* and at test time, even when no
|
|
4
|
+
* Each default contributes the hooks for one of the assistant's built-in
|
|
5
|
+
* behaviors (history repair, title generation, tool-error coaching, …) so the
|
|
6
|
+
* lifecycle is always populated at boot and at test time, even when no
|
|
7
|
+
* third-party plugins are loaded. A `Plugin` is the manifest (name/version,
|
|
8
|
+
* sourced from the sibling `package.json`) plus its hook map; the hook
|
|
9
|
+
* implementations live in each `defaults/<name>/hooks/` directory.
|
|
7
10
|
*
|
|
8
11
|
* Consumers:
|
|
9
12
|
*
|
|
@@ -16,32 +19,140 @@
|
|
|
16
19
|
* production-parity state (e.g. `conversation-agent-loop.test.ts`); those
|
|
17
20
|
* call {@link resetPluginRegistryAndRegisterDefaults}.
|
|
18
21
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* every module has finished initializing, so importing this aggregator does no
|
|
23
|
-
* registration work.
|
|
22
|
+
* The plugin definitions below are plain `const`s, so importing this module
|
|
23
|
+
* does no registration work — registration is driven by
|
|
24
|
+
* {@link registerDefaultPlugins} at call time.
|
|
24
25
|
*/
|
|
25
26
|
|
|
26
27
|
import { registerPlugin, resetPluginRegistryForTests } from "../registry.js";
|
|
27
28
|
import { type Plugin, PluginExecutionError } from "../types.js";
|
|
28
|
-
import
|
|
29
|
-
import
|
|
30
|
-
import
|
|
31
|
-
import
|
|
32
|
-
import
|
|
33
|
-
import
|
|
34
|
-
import
|
|
29
|
+
import compactionPkg from "./compaction/package.json" with { type: "json" };
|
|
30
|
+
import emptyResponseStop from "./empty-response/hooks/stop.js";
|
|
31
|
+
import emptyResponsePkg from "./empty-response/package.json" with { type: "json" };
|
|
32
|
+
import historyRepairUserPromptSubmit from "./history-repair/hooks/user-prompt-submit.js";
|
|
33
|
+
import historyRepairPkg from "./history-repair/package.json" with { type: "json" };
|
|
34
|
+
import memoryV3PostCompact from "./memory-v3-shadow/hooks/post-compact.js";
|
|
35
|
+
import memoryV3UserPromptSubmit from "./memory-v3-shadow/hooks/user-prompt-submit.js";
|
|
36
|
+
import memoryV3Pkg from "./memory-v3-shadow/package.json" with { type: "json" };
|
|
37
|
+
import titleGenerateStop from "./title-generate/hooks/stop.js";
|
|
38
|
+
import titleGenerateUserPromptSubmit from "./title-generate/hooks/user-prompt-submit.js";
|
|
39
|
+
import titleGeneratePkg from "./title-generate/package.json" with { type: "json" };
|
|
40
|
+
import toolErrorPostToolUse from "./tool-error/hooks/post-tool-use.js";
|
|
41
|
+
import toolErrorPkg from "./tool-error/package.json" with { type: "json" };
|
|
42
|
+
import toolResultTruncatePostToolUse from "./tool-result-truncate/hooks/post-tool-use.js";
|
|
43
|
+
import toolResultTruncatePkg from "./tool-result-truncate/package.json" with { type: "json" };
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* `compaction` — compaction is implemented in `compaction/compact.ts` as
|
|
47
|
+
* `defaultCompact`, which the agent loop calls directly. The plugin stays
|
|
48
|
+
* registered as a placeholder so it keeps a presence in the defaults list
|
|
49
|
+
* while we decide how plugins should surface compaction; it contributes no
|
|
50
|
+
* hooks today.
|
|
51
|
+
*/
|
|
52
|
+
export const defaultCompactionPlugin: Plugin = {
|
|
53
|
+
manifest: {
|
|
54
|
+
name: compactionPkg.name,
|
|
55
|
+
version: compactionPkg.version,
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* `empty-response` — a `stop` hook that re-queries the model when a turn
|
|
61
|
+
* yields with no tool calls but came back empty (or as a provider refusal).
|
|
62
|
+
*/
|
|
63
|
+
export const defaultEmptyResponsePlugin: Plugin = {
|
|
64
|
+
manifest: {
|
|
65
|
+
name: emptyResponsePkg.name,
|
|
66
|
+
version: emptyResponsePkg.version,
|
|
67
|
+
},
|
|
68
|
+
hooks: {
|
|
69
|
+
stop: emptyResponseStop,
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* `history-repair` — a `user-prompt-submit` hook that normalizes the working
|
|
75
|
+
* message history (tool-use/tool-result pairing, role alternation) before the
|
|
76
|
+
* agent loop hands it to the provider.
|
|
77
|
+
*/
|
|
78
|
+
export const defaultHistoryRepairPlugin: Plugin = {
|
|
79
|
+
manifest: {
|
|
80
|
+
name: historyRepairPkg.name,
|
|
81
|
+
version: historyRepairPkg.version,
|
|
82
|
+
},
|
|
83
|
+
hooks: {
|
|
84
|
+
"user-prompt-submit": historyRepairUserPromptSubmit,
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* `memory-v3-shadow` — houses the memory-v3 shadow/live orchestration engine
|
|
90
|
+
* (`memory-v3-shadow/`) and its injector. The `user-prompt-submit` /
|
|
91
|
+
* `post-compact` hooks are no-op scaffolding for the eventual convergence,
|
|
92
|
+
* when v3 injection moves off the loop-driven chain and into these hooks.
|
|
93
|
+
*/
|
|
94
|
+
export const memoryV3ShadowPlugin: Plugin = {
|
|
95
|
+
manifest: {
|
|
96
|
+
name: memoryV3Pkg.name,
|
|
97
|
+
version: memoryV3Pkg.version,
|
|
98
|
+
},
|
|
99
|
+
hooks: {
|
|
100
|
+
"user-prompt-submit": memoryV3UserPromptSubmit,
|
|
101
|
+
"post-compact": memoryV3PostCompact,
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* `title-generate` — two pure-trigger hooks that delegate the title work to
|
|
107
|
+
* the conversation-title service: `user-prompt-submit` (first-pass title) and
|
|
108
|
+
* `stop` (second-pass regeneration once the topic is established).
|
|
109
|
+
*/
|
|
110
|
+
export const defaultTitleGeneratePlugin: Plugin = {
|
|
111
|
+
manifest: {
|
|
112
|
+
name: titleGeneratePkg.name,
|
|
113
|
+
version: titleGeneratePkg.version,
|
|
114
|
+
},
|
|
115
|
+
hooks: {
|
|
116
|
+
"user-prompt-submit": titleGenerateUserPromptSubmit,
|
|
117
|
+
stop: titleGenerateStop,
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* `tool-error` — a `post-tool-use` hook that coaches the model to retry or
|
|
123
|
+
* report a failed tool call, bounded per tool. The coaching is surfaced via
|
|
124
|
+
* `additionalContext`, leaving the tool result's own content untouched.
|
|
125
|
+
*/
|
|
126
|
+
export const defaultToolErrorPlugin: Plugin = {
|
|
127
|
+
manifest: {
|
|
128
|
+
name: toolErrorPkg.name,
|
|
129
|
+
version: toolErrorPkg.version,
|
|
130
|
+
},
|
|
131
|
+
hooks: {
|
|
132
|
+
"post-tool-use": toolErrorPostToolUse,
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* `tool-result-truncate` — a `post-tool-use` hook that tail-drops an oversized
|
|
138
|
+
* tool result down to a character budget derived from the model's context
|
|
139
|
+
* window before the result is sent to the provider.
|
|
140
|
+
*/
|
|
141
|
+
export const defaultToolResultTruncatePlugin: Plugin = {
|
|
142
|
+
manifest: {
|
|
143
|
+
name: toolResultTruncatePkg.name,
|
|
144
|
+
version: toolResultTruncatePkg.version,
|
|
145
|
+
},
|
|
146
|
+
hooks: {
|
|
147
|
+
"post-tool-use": toolResultTruncatePostToolUse,
|
|
148
|
+
},
|
|
149
|
+
};
|
|
35
150
|
|
|
36
151
|
/**
|
|
37
152
|
* Full set of first-party default plugins. Used by
|
|
38
153
|
* {@link registerDefaultPlugins} to drive the registration loop; the array
|
|
39
|
-
* order is the registration order, which
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* Returned by a function rather than a top-level `const` so the array
|
|
43
|
-
* contents are read at call time, after every imported plugin identifier is
|
|
44
|
-
* guaranteed initialized.
|
|
154
|
+
* order is the registration order, which fixes hook-chain order (defaults run
|
|
155
|
+
* ahead of any later-registered user plugins).
|
|
45
156
|
*/
|
|
46
157
|
function getAllDefaultPlugins(): readonly Plugin[] {
|
|
47
158
|
return [
|
|
@@ -454,11 +454,19 @@ const MEMORY_V2_STATIC_BLOCK_MATCHERS: readonly InjectionMatcher[] = [
|
|
|
454
454
|
|
|
455
455
|
/**
|
|
456
456
|
* Whether a block matching any of the given matchers is already present in the
|
|
457
|
-
* turn's working messages
|
|
458
|
-
*
|
|
459
|
-
*
|
|
460
|
-
*
|
|
461
|
-
*
|
|
457
|
+
* turn's working messages — used to skip re-injection of a block the history
|
|
458
|
+
* already carries.
|
|
459
|
+
*
|
|
460
|
+
* Recognizes both the canonical standalone form (a text block that IS the
|
|
461
|
+
* wrapper) and the "flattened" form where the wrapper sits as a newline-
|
|
462
|
+
* delimited section inside a larger text block (see {@link textCarriesInjection}).
|
|
463
|
+
*
|
|
464
|
+
* Detection is intentionally BROADER than `stripUserTextBlocksByPrefix`, which
|
|
465
|
+
* stays whole-block-only: re-injection must be suppressed even when a historical
|
|
466
|
+
* user message's separate injection blocks have been collapsed into one text
|
|
467
|
+
* block, whereas the strip must never delete a block that also holds the user's
|
|
468
|
+
* own text. (A flattened block is summarized away at the next compaction, where
|
|
469
|
+
* fresh injection resumes.)
|
|
462
470
|
*/
|
|
463
471
|
function hasInjectedUserTextBlock(
|
|
464
472
|
runMessages: Message[] | undefined,
|
|
@@ -471,16 +479,44 @@ function hasInjectedUserTextBlock(
|
|
|
471
479
|
message.content.some(
|
|
472
480
|
(block) =>
|
|
473
481
|
block.type === "text" &&
|
|
474
|
-
matchers.some((m) =>
|
|
475
|
-
typeof m === "string"
|
|
476
|
-
? block.text.startsWith(m)
|
|
477
|
-
: block.text.startsWith(m.prefix) &&
|
|
478
|
-
block.text.endsWith(m.suffix),
|
|
479
|
-
),
|
|
482
|
+
matchers.some((m) => textCarriesInjection(block.text, m)),
|
|
480
483
|
),
|
|
481
484
|
);
|
|
482
485
|
}
|
|
483
486
|
|
|
487
|
+
/**
|
|
488
|
+
* Whether `text` carries an injected block matching `matcher`, recognizing both
|
|
489
|
+
* the canonical standalone form (the text IS the wrapper) and a "flattened"
|
|
490
|
+
* form where the wrapper sits as a newline-delimited section inside a larger
|
|
491
|
+
* text block.
|
|
492
|
+
*
|
|
493
|
+
* The flattened form arises when a historical user message's separate injection
|
|
494
|
+
* content blocks get collapsed into a single text block joined with "\n" —
|
|
495
|
+
* observed when a daemon restart / plugin hot-reload rebuilt the rendered
|
|
496
|
+
* history mid-conversation. Without recognizing it, the standalone-only check
|
|
497
|
+
* returns false for the carried block and the injector re-injects a duplicate
|
|
498
|
+
* `<workspace>` / `<info>` onto the new tail.
|
|
499
|
+
*
|
|
500
|
+
* Anchoring on line boundaries ("\n" before the opening tag, and "\n" or the
|
|
501
|
+
* block edge after the closing tag) keeps the false-positive surface as narrow
|
|
502
|
+
* as the standalone check: ordinary prose would have to contain the exact
|
|
503
|
+
* wrapper as its own line-delimited section to be mistaken for an injection. The
|
|
504
|
+
* `{ prefix, suffix }` form still requires BOTH tags, so a message that opens
|
|
505
|
+
* (but never closes) an injection-like tag never suppresses injection.
|
|
506
|
+
*/
|
|
507
|
+
function textCarriesInjection(
|
|
508
|
+
text: string,
|
|
509
|
+
matcher: InjectionMatcher,
|
|
510
|
+
): boolean {
|
|
511
|
+
if (typeof matcher === "string") {
|
|
512
|
+
return text.startsWith(matcher) || text.includes(`\n${matcher}`);
|
|
513
|
+
}
|
|
514
|
+
const { prefix, suffix } = matcher;
|
|
515
|
+
const hasOpen = text.startsWith(prefix) || text.includes(`\n${prefix}`);
|
|
516
|
+
const hasClose = text.endsWith(suffix) || text.includes(`${suffix}\n`);
|
|
517
|
+
return hasOpen && hasClose;
|
|
518
|
+
}
|
|
519
|
+
|
|
484
520
|
/**
|
|
485
521
|
* Render the PKB context block — wraps the raw content in
|
|
486
522
|
* `<knowledge_base>...</knowledge_base>` while escaping any closing tags
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Default `compaction` plugin.
|
|
3
|
-
*
|
|
4
|
-
* Compaction is implemented in `./compact.ts` as {@link defaultCompact}, which
|
|
5
|
-
* the agent loop calls directly with a {@link CompactionContext}. The plugin
|
|
6
|
-
* stays registered as a placeholder so it keeps a presence in the defaults
|
|
7
|
-
* list while we decide how plugins should surface compaction; it contributes
|
|
8
|
-
* no contract slot today.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import { type Plugin } from "../../types.js";
|
|
12
|
-
import pkg from "./package.json" with { type: "json" };
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Manifest for the default compaction plugin. The registration happens in
|
|
16
|
-
* `daemon/external-plugins-bootstrap.ts` before {@link bootstrapPlugins} fires
|
|
17
|
-
* plugin `init()` hooks.
|
|
18
|
-
*/
|
|
19
|
-
export const defaultCompactionPlugin: Plugin = {
|
|
20
|
-
manifest: {
|
|
21
|
-
name: pkg.name,
|
|
22
|
-
version: pkg.version,
|
|
23
|
-
},
|
|
24
|
-
};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Default `empty-response` plugin.
|
|
3
|
-
*
|
|
4
|
-
* Contributes a `stop` hook that re-queries the model when a turn yields with
|
|
5
|
-
* no tool calls but came back empty (or as a provider refusal). The decision
|
|
6
|
-
* logic lives in `./hooks/stop.ts`. Defaults register before user plugins, so
|
|
7
|
-
* this runs at the front of the `stop` hook chain.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { type Plugin } from "../../types.js";
|
|
11
|
-
import stop from "./hooks/stop.js";
|
|
12
|
-
import pkg from "./package.json" with { type: "json" };
|
|
13
|
-
|
|
14
|
-
/** Singleton plugin — the registry rejects duplicate registrations by name. */
|
|
15
|
-
export const defaultEmptyResponsePlugin: Plugin = {
|
|
16
|
-
manifest: {
|
|
17
|
-
name: pkg.name,
|
|
18
|
-
version: pkg.version,
|
|
19
|
-
},
|
|
20
|
-
hooks: {
|
|
21
|
-
stop,
|
|
22
|
-
},
|
|
23
|
-
};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Default `history-repair` plugin.
|
|
3
|
-
*
|
|
4
|
-
* Contributes a `user-prompt-submit` hook that normalizes the working message
|
|
5
|
-
* history (tool-use/tool-result pairing, role alternation) before the agent
|
|
6
|
-
* loop hands it to the provider. The repair implementation lives in
|
|
7
|
-
* `./terminal.ts`; the hook in `./hooks/user-prompt-submit.ts` wires it into
|
|
8
|
-
* the lifecycle. Defaults register before user plugins, so this normalization
|
|
9
|
-
* runs at the front of the hook chain.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import { type Plugin } from "../../types.js";
|
|
13
|
-
import userPromptSubmit from "./hooks/user-prompt-submit.js";
|
|
14
|
-
import pkg from "./package.json" with { type: "json" };
|
|
15
|
-
|
|
16
|
-
export const defaultHistoryRepairPlugin: Plugin = {
|
|
17
|
-
manifest: {
|
|
18
|
-
name: pkg.name,
|
|
19
|
-
version: pkg.version,
|
|
20
|
-
},
|
|
21
|
-
hooks: {
|
|
22
|
-
"user-prompt-submit": userPromptSubmit,
|
|
23
|
-
},
|
|
24
|
-
};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Default `memory-v3-shadow` plugin.
|
|
3
|
-
*
|
|
4
|
-
* Houses the memory-v3 shadow/live orchestration engine (this directory) and
|
|
5
|
-
* its injector (`./injector.ts`). The injector is still consumed by the static
|
|
6
|
-
* chain in `memory-retrieval/injector-chain.ts`; the `user-prompt-submit` /
|
|
7
|
-
* `post-compact` hooks below are no-op scaffolding for the eventual
|
|
8
|
-
* convergence, when v3 injection moves off the loop-driven chain and into these
|
|
9
|
-
* lifecycle hooks. See each hook file for the convergence note.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import { type Plugin } from "../../types.js";
|
|
13
|
-
import postCompact from "./hooks/post-compact.js";
|
|
14
|
-
import userPromptSubmit from "./hooks/user-prompt-submit.js";
|
|
15
|
-
import pkg from "./package.json" with { type: "json" };
|
|
16
|
-
|
|
17
|
-
export const memoryV3ShadowPlugin: Plugin = {
|
|
18
|
-
manifest: {
|
|
19
|
-
name: pkg.name,
|
|
20
|
-
version: pkg.version,
|
|
21
|
-
},
|
|
22
|
-
hooks: {
|
|
23
|
-
"user-prompt-submit": userPromptSubmit,
|
|
24
|
-
"post-compact": postCompact,
|
|
25
|
-
},
|
|
26
|
-
};
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Default `title-generate` plugin.
|
|
3
|
-
*
|
|
4
|
-
* Contributes two hooks, both pure triggers that delegate the title work to
|
|
5
|
-
* the service (`memory/conversation-title-service.ts`):
|
|
6
|
-
*
|
|
7
|
-
* - `user-prompt-submit` (`./hooks/user-prompt-submit.ts`) — first-pass title
|
|
8
|
-
* generation from the submitted prompt.
|
|
9
|
-
* - `stop` (`./hooks/stop.ts`) — second-pass regeneration once the
|
|
10
|
-
* conversation reaches its third user turn, for a title that reflects the
|
|
11
|
-
* established topic.
|
|
12
|
-
*
|
|
13
|
-
* Persistence and the resulting `conversation_title_updated` / `sync_changed`
|
|
14
|
-
* broadcast are owned by the title service.
|
|
15
|
-
*
|
|
16
|
-
* Registered via a side-effect import from
|
|
17
|
-
* `daemon/external-plugins-bootstrap.ts` so it is present in the registry
|
|
18
|
-
* by the time {@link bootstrapPlugins} runs.
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
import { type Plugin } from "../../types.js";
|
|
22
|
-
import stop from "./hooks/stop.js";
|
|
23
|
-
import userPromptSubmit from "./hooks/user-prompt-submit.js";
|
|
24
|
-
import pkg from "./package.json" with { type: "json" };
|
|
25
|
-
|
|
26
|
-
export const defaultTitleGeneratePlugin: Plugin = {
|
|
27
|
-
manifest: {
|
|
28
|
-
name: pkg.name,
|
|
29
|
-
version: pkg.version,
|
|
30
|
-
},
|
|
31
|
-
hooks: {
|
|
32
|
-
"user-prompt-submit": userPromptSubmit,
|
|
33
|
-
stop,
|
|
34
|
-
},
|
|
35
|
-
};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Default `tool-error` plugin.
|
|
3
|
-
*
|
|
4
|
-
* Contributes a `post-tool-use` hook that coaches the model to retry or report
|
|
5
|
-
* a failed tool call, bounded per tool so an unrecoverable error doesn't churn.
|
|
6
|
-
* The coaching is surfaced via `additionalContext` (a separate provider-only
|
|
7
|
-
* block), leaving the tool result's own content untouched. The decision logic
|
|
8
|
-
* lives in `./hooks/post-tool-use.ts`.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import { type Plugin } from "../../types.js";
|
|
12
|
-
import postToolUse from "./hooks/post-tool-use.js";
|
|
13
|
-
import pkg from "./package.json" with { type: "json" };
|
|
14
|
-
|
|
15
|
-
export const defaultToolErrorPlugin: Plugin = {
|
|
16
|
-
manifest: {
|
|
17
|
-
name: pkg.name,
|
|
18
|
-
version: pkg.version,
|
|
19
|
-
},
|
|
20
|
-
hooks: {
|
|
21
|
-
"post-tool-use": postToolUse,
|
|
22
|
-
},
|
|
23
|
-
};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Default `tool-result-truncate` plugin.
|
|
3
|
-
*
|
|
4
|
-
* Contributes a `post-tool-use` hook that tail-drops an oversized tool result
|
|
5
|
-
* down to a character budget derived from the model's context window before
|
|
6
|
-
* the result is sent to the provider. The truncation implementation lives in
|
|
7
|
-
* `./terminal.ts`; the hook in `./hooks/post-tool-use.ts` wires it into the
|
|
8
|
-
* lifecycle. Defaults register before user plugins, so this runs at the front
|
|
9
|
-
* of the hook chain.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import { type Plugin } from "../../types.js";
|
|
13
|
-
import postToolUse from "./hooks/post-tool-use.js";
|
|
14
|
-
import pkg from "./package.json" with { type: "json" };
|
|
15
|
-
|
|
16
|
-
export const defaultToolResultTruncatePlugin: Plugin = {
|
|
17
|
-
manifest: {
|
|
18
|
-
name: pkg.name,
|
|
19
|
-
version: pkg.version,
|
|
20
|
-
},
|
|
21
|
-
hooks: {
|
|
22
|
-
"post-tool-use": postToolUse,
|
|
23
|
-
},
|
|
24
|
-
};
|