@botbotgo/agent-harness 0.0.475 → 0.0.476
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 +3 -1234
- package/README.zh.md +3 -1191
- package/dist/acp.js +1 -1
- package/dist/api.js +1 -404
- package/dist/benchmark/checkpoint-resume-cost-benchmark.js +1 -55
- package/dist/benchmark/deepagent-local-model-benchmark.js +2 -35
- package/dist/benchmark/upstream-runtime-ab-benchmark.js +1 -179
- package/dist/cli/chat-interactive.js +25 -244
- package/dist/cli/chat-rendering.js +6 -100
- package/dist/cli/chat-stream.js +23 -512
- package/dist/cli/chat-ui.js +21 -199
- package/dist/cli/chat-workspace.js +2 -210
- package/dist/cli/main.js +21 -428
- package/dist/cli/managed-service-commands.js +9 -63
- package/dist/cli/managed-service.js +2 -137
- package/dist/cli/options-init-chat.js +1 -108
- package/dist/cli/options-runtime.js +1 -158
- package/dist/cli/options-serve.js +1 -282
- package/dist/cli/options.js +2 -19
- package/dist/cli/process-guards.js +1 -139
- package/dist/cli/request-tree.js +7 -296
- package/dist/cli/runtime-commands.js +12 -258
- package/dist/cli/runtime-output.js +16 -155
- package/dist/cli/server-commands.js +16 -270
- package/dist/cli/workspace.js +1 -67
- package/dist/cli.js +1 -7
- package/dist/client/acp.js +1 -1
- package/dist/client/in-process.js +1 -67
- package/dist/client/index.js +1 -2
- package/dist/client/types.js +0 -1
- package/dist/client.js +1 -1
- package/dist/contracts/core.js +1 -1
- package/dist/contracts/runtime-evaluation.js +0 -1
- package/dist/contracts/runtime-memory.js +0 -1
- package/dist/contracts/runtime-observability.js +0 -1
- package/dist/contracts/runtime-requests.js +0 -1
- package/dist/contracts/runtime-scheduling.js +0 -1
- package/dist/contracts/runtime.js +1 -27
- package/dist/contracts/types.js +1 -3
- package/dist/contracts/workspace.js +0 -1
- package/dist/flow/build-flow-graph.js +1 -50
- package/dist/flow/export-mermaid.js +2 -464
- package/dist/flow/export-sequence-mermaid.js +2 -325
- package/dist/flow/flow-graph-normalization.js +1 -214
- package/dist/flow/flow-graph-runtime.js +1 -107
- package/dist/flow/flow-graph-upstream.js +1 -494
- package/dist/flow/index.js +1 -3
- package/dist/flow/types.js +0 -1
- package/dist/index.js +1 -5
- package/dist/init-project.js +1 -1
- package/dist/knowledge/config.js +1 -32
- package/dist/knowledge/contracts.js +0 -1
- package/dist/knowledge/index.js +1 -2
- package/dist/knowledge/module.js +12 -909
- package/dist/knowledge/procedural/config.js +1 -125
- package/dist/knowledge/procedural/index.js +1 -2
- package/dist/knowledge/procedural/manager.js +9 -345
- package/dist/mcp.js +1 -2
- package/dist/package-version.d.ts +1 -1
- package/dist/package-version.js +1 -2
- package/dist/persistence/file-store.js +3 -758
- package/dist/persistence/sqlite-request-context-store.js +5 -54
- package/dist/persistence/sqlite-request-queue-store.js +10 -108
- package/dist/persistence/sqlite-runtime.js +1 -86
- package/dist/persistence/sqlite-store.js +62 -810
- package/dist/persistence/types.js +0 -1
- package/dist/projections/presentation.js +37 -206
- package/dist/projections/request-events.js +2 -502
- package/dist/projections/upstream-events.js +1 -201
- package/dist/protocol/a2a/http-discovery.js +1 -178
- package/dist/protocol/a2a/http-rpc.js +6 -622
- package/dist/protocol/a2a/http.js +1 -138
- package/dist/protocol/a2a/task-state.js +3 -317
- package/dist/protocol/acp/client.js +8 -294
- package/dist/protocol/acp/harness-client.js +1 -218
- package/dist/protocol/acp/http.js +5 -130
- package/dist/protocol/acp/server.js +1 -310
- package/dist/protocol/acp/stdio.js +2 -69
- package/dist/protocol/ag-ui/http.js +3 -378
- package/dist/protocol/mcp/server.js +1 -428
- package/dist/resource/backend/workspace-scoped-backend.js +1 -319
- package/dist/resource/isolation.js +1 -237
- package/dist/resource/mcp/tool-support.js +3 -296
- package/dist/resource/mcp-tool-support.js +1 -2
- package/dist/resource/providers/resource-provider.js +1 -215
- package/dist/resource/resource-impl.js +1 -3
- package/dist/resource/resource-types.js +0 -1
- package/dist/resource/resource.js +1 -1
- package/dist/resource/sources.js +1 -247
- package/dist/resource/tools/function-tool-resolver.js +2 -272
- package/dist/runtime/adapter/compat/deepagent-compat.js +1 -29
- package/dist/runtime/adapter/compat/openai-compatible.js +1 -55
- package/dist/runtime/adapter/direct-builtin-utility.js +2 -90
- package/dist/runtime/adapter/flow/execution-context.js +1 -71
- package/dist/runtime/adapter/flow/invocation-flow.js +8 -425
- package/dist/runtime/adapter/flow/invoke-runtime.js +1 -20
- package/dist/runtime/adapter/flow/stream-runtime.js +11 -1395
- package/dist/runtime/adapter/invocation-result.js +2 -473
- package/dist/runtime/adapter/local-tool-invocation.js +6 -638
- package/dist/runtime/adapter/middleware/context-hygiene.js +1 -83
- package/dist/runtime/adapter/middleware-assembly.js +5 -477
- package/dist/runtime/adapter/model/invocation-request.js +3 -183
- package/dist/runtime/adapter/model/message-assembly.js +1 -28
- package/dist/runtime/adapter/model/model-providers.js +23 -1115
- package/dist/runtime/adapter/model/prompted-json-tool-call-capture.js +1 -40
- package/dist/runtime/adapter/model/prompted-json-tool-policy.js +1 -22
- package/dist/runtime/adapter/resilience.js +1 -104
- package/dist/runtime/adapter/runtime-adapter-support.js +3 -141
- package/dist/runtime/adapter/runtime-shell.js +5 -166
- package/dist/runtime/adapter/stream-event-projection.js +2 -622
- package/dist/runtime/adapter/stream-text-consumption.js +1 -18
- package/dist/runtime/adapter/terminal-status.js +2 -67
- package/dist/runtime/adapter/tool/builtin-middleware-tools.js +6 -627
- package/dist/runtime/adapter/tool/declared-middleware.js +1 -154
- package/dist/runtime/adapter/tool/interrupt-policy.js +1 -34
- package/dist/runtime/adapter/tool/provider-tool.js +1 -25
- package/dist/runtime/adapter/tool/resolved-tool.js +1 -225
- package/dist/runtime/adapter/tool/tool-arguments.js +3 -486
- package/dist/runtime/adapter/tool/tool-hitl.js +1 -346
- package/dist/runtime/adapter/tool/tool-name-mapping.js +1 -128
- package/dist/runtime/adapter/tool/tool-output-artifacts.js +2 -88
- package/dist/runtime/adapter/tool/tool-replay.js +1 -37
- package/dist/runtime/adapter/tool-resolution.js +1 -86
- package/dist/runtime/adapter/upstream-configurable-keys.js +1 -2
- package/dist/runtime/agent-runtime-adapter.js +60 -2338
- package/dist/runtime/agent-runtime-assembly.js +7 -249
- package/dist/runtime/env/runtime-env.js +1 -62
- package/dist/runtime/harness/background-runtime.js +1 -8
- package/dist/runtime/harness/bindings.js +1 -58
- package/dist/runtime/harness/events/event-bus.js +1 -16
- package/dist/runtime/harness/events/event-sink.js +1 -61
- package/dist/runtime/harness/events/events.js +1 -80
- package/dist/runtime/harness/events/listener-runtime.js +1 -13
- package/dist/runtime/harness/events/runtime-event-operations.js +1 -9
- package/dist/runtime/harness/events/streaming.js +1 -100
- package/dist/runtime/harness/events/timeline.js +1 -52
- package/dist/runtime/harness/public-shapes.js +1 -186
- package/dist/runtime/harness/run/artifact-paths.js +1 -15
- package/dist/runtime/harness/run/governance.js +1 -295
- package/dist/runtime/harness/run/helpers.js +1 -71
- package/dist/runtime/harness/run/inspection.js +1 -409
- package/dist/runtime/harness/run/operator-overview.js +1 -80
- package/dist/runtime/harness/run/queue-diagnostics.js +1 -15
- package/dist/runtime/harness/run/recovery.js +1 -162
- package/dist/runtime/harness/run/resources.js +1 -60
- package/dist/runtime/harness/run/resume.js +1 -56
- package/dist/runtime/harness/run/routing.js +1 -48
- package/dist/runtime/harness/run/run-lifecycle.js +1 -66
- package/dist/runtime/harness/run/run-operations.js +1 -217
- package/dist/runtime/harness/run/run-queue.js +1 -43
- package/dist/runtime/harness/run/run-slot-acquisition.js +1 -157
- package/dist/runtime/harness/run/session-records.js +1 -97
- package/dist/runtime/harness/run/start-run.js +1 -120
- package/dist/runtime/harness/run/startup-runtime.js +1 -69
- package/dist/runtime/harness/run/stream-run.js +8 -1418
- package/dist/runtime/harness/run/surface-semantics.js +1 -79
- package/dist/runtime/harness/runtime-defaults.js +1 -39
- package/dist/runtime/harness/system/boundary-analysis.js +1 -234
- package/dist/runtime/harness/system/health-monitor.js +1 -258
- package/dist/runtime/harness/system/inventory.js +1 -129
- package/dist/runtime/harness/system/mem0-ingestion-sync.js +5 -345
- package/dist/runtime/harness/system/policy-engine.js +1 -175
- package/dist/runtime/harness/system/runtime-memory-candidates.js +4 -110
- package/dist/runtime/harness/system/runtime-memory-consolidation.js +1 -51
- package/dist/runtime/harness/system/runtime-memory-manager.js +10 -693
- package/dist/runtime/harness/system/runtime-memory-policy.js +1 -155
- package/dist/runtime/harness/system/runtime-memory-records.js +11 -577
- package/dist/runtime/harness/system/runtime-memory-sync.js +5 -206
- package/dist/runtime/harness/system/session-memory-sync.js +3 -113
- package/dist/runtime/harness/system/skill-requirements.js +1 -112
- package/dist/runtime/harness/system/store.js +9 -365
- package/dist/runtime/harness/tool-gateway/index.js +1 -2
- package/dist/runtime/harness/tool-gateway/policy.js +1 -45
- package/dist/runtime/harness/tool-gateway/validation.js +1 -176
- package/dist/runtime/harness/tool-schema.js +1 -3
- package/dist/runtime/harness.js +3 -1490
- package/dist/runtime/index.js +1 -3
- package/dist/runtime/layout/runtime-layout.js +1 -31
- package/dist/runtime/maintenance/checkpoint-maintenance.js +2 -178
- package/dist/runtime/maintenance/file-checkpoint-saver.js +1 -106
- package/dist/runtime/maintenance/runtime-record-maintenance.js +2 -169
- package/dist/runtime/maintenance/sqlite-checkpoint-saver.js +4 -289
- package/dist/runtime/parsing/output-content.js +10 -550
- package/dist/runtime/parsing/output-parsing.js +1 -4
- package/dist/runtime/parsing/output-recovery.js +3 -213
- package/dist/runtime/parsing/output-tool-args.js +7 -663
- package/dist/runtime/parsing/stream-event-parsing.js +3 -362
- package/dist/runtime/prompts/runtime-prompts.js +4 -73
- package/dist/runtime/scheduling/system-schedule-manager.js +11 -532
- package/dist/runtime/skills/skill-metadata.js +1 -197
- package/dist/runtime/startup-tracing.js +2 -37
- package/dist/runtime/support/compiled-binding.js +1 -290
- package/dist/runtime/support/embedding-models.js +1 -118
- package/dist/runtime/support/harness-support.js +5 -137
- package/dist/runtime/support/llamaindex.js +1 -108
- package/dist/runtime/support/runtime-adapter-options.js +1 -29
- package/dist/runtime/support/runtime-factories.js +1 -51
- package/dist/runtime/support/vector-stores.js +9 -270
- package/dist/scaffold/init-project.js +54 -233
- package/dist/tooling/extensions.js +1 -311
- package/dist/tooling/module-loader.js +1 -55
- package/dist/tools.js +1 -176
- package/dist/utils/agent-display.js +1 -18
- package/dist/utils/bundled-text.js +4 -39
- package/dist/utils/compiled-binding.js +1 -33
- package/dist/utils/fs.js +2 -45
- package/dist/utils/id.js +1 -9
- package/dist/utils/message-content.js +1 -30
- package/dist/utils/object.js +1 -6
- package/dist/workspace/agent-binding-compiler.js +3 -613
- package/dist/workspace/compile.js +1 -472
- package/dist/workspace/framework-contract-validation.js +2 -322
- package/dist/workspace/index.js +1 -1
- package/dist/workspace/object-loader-paths.js +1 -71
- package/dist/workspace/object-loader-readers.js +1 -187
- package/dist/workspace/object-loader.js +1 -754
- package/dist/workspace/resource-compilers.js +1 -374
- package/dist/workspace/support/agent-capabilities.js +1 -37
- package/dist/workspace/support/agent-execution-config.js +1 -44
- package/dist/workspace/support/discovery.js +1 -147
- package/dist/workspace/support/source-collectors.js +1 -30
- package/dist/workspace/support/source-protocols.js +2 -192
- package/dist/workspace/support/workspace-ref-utils.js +1 -362
- package/dist/workspace/tool-hydration.js +1 -280
- package/dist/workspace/validate.js +1 -99
- package/dist/workspace/yaml-object-reader.js +1 -285
- package/package.json +7 -3
|
@@ -1,183 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { summarizeAssistantText } from "../direct-builtin-utility.js";
|
|
5
|
-
import { renderDurableMemoryContextPrompt, renderSlashCommandSkillInstruction, } from "../../prompts/runtime-prompts.js";
|
|
6
|
-
import { hasExplicitResourceReference, } from "../../harness/system/runtime-memory-policy.js";
|
|
7
|
-
const MAX_HISTORY_ASSISTANT_CHARS = 1600;
|
|
8
|
-
const MAX_HISTORY_ASSISTANT_LINES = 40;
|
|
9
|
-
function compactHistoryText(text) {
|
|
10
|
-
const normalized = text.trim();
|
|
11
|
-
if (!normalized) {
|
|
12
|
-
return normalized;
|
|
13
|
-
}
|
|
14
|
-
const summarized = summarizeAssistantText(normalized);
|
|
15
|
-
if (summarized !== normalized) {
|
|
16
|
-
return summarized;
|
|
17
|
-
}
|
|
18
|
-
const lines = normalized.split(/\r?\n/);
|
|
19
|
-
if (normalized.length <= MAX_HISTORY_ASSISTANT_CHARS && lines.length <= MAX_HISTORY_ASSISTANT_LINES) {
|
|
20
|
-
return normalized;
|
|
21
|
-
}
|
|
22
|
-
const head = normalized.slice(0, 1200).trimEnd();
|
|
23
|
-
const tail = normalized.slice(-240).trimStart();
|
|
24
|
-
const omittedChars = Math.max(normalized.length - head.length - tail.length, 0);
|
|
25
|
-
return `${head}\n... [${omittedChars} characters omitted from prior assistant output] ...\n${tail}`;
|
|
26
|
-
}
|
|
27
|
-
function compactHistoryContent(role, content) {
|
|
28
|
-
const normalized = normalizeMessageContent(content);
|
|
29
|
-
if (role !== "assistant" || typeof normalized !== "string") {
|
|
30
|
-
return normalized;
|
|
31
|
-
}
|
|
32
|
-
return compactHistoryText(normalized);
|
|
33
|
-
}
|
|
34
|
-
function renderHistoryTurn(turn) {
|
|
35
|
-
const dropsAssistant = turn.some((item) => {
|
|
36
|
-
if (item.role !== "assistant" || typeof item.content !== "string") {
|
|
37
|
-
return false;
|
|
38
|
-
}
|
|
39
|
-
const compacted = compactHistoryContent(item.role, item.content);
|
|
40
|
-
return typeof compacted === "string" && compacted !== normalizeMessageContent(item.content);
|
|
41
|
-
});
|
|
42
|
-
if (dropsAssistant) {
|
|
43
|
-
return [];
|
|
44
|
-
}
|
|
45
|
-
return turn.flatMap((item) => {
|
|
46
|
-
const content = compactHistoryContent(item.role, item.content);
|
|
47
|
-
if (item.role === "assistant" && typeof item.content === "string" && typeof content === "string" && content !== normalizeMessageContent(item.content)) {
|
|
48
|
-
return [];
|
|
49
|
-
}
|
|
50
|
-
return [{ role: item.role, content }];
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
function dropAssistantMessages(turn) {
|
|
54
|
-
return turn.filter((item) => item.role !== "assistant");
|
|
55
|
-
}
|
|
56
|
-
function inferMessageLanguage(text) {
|
|
57
|
-
const normalized = text
|
|
58
|
-
.replace(/https?:\/\/\S+/giu, " ")
|
|
59
|
-
.trim();
|
|
60
|
-
if (!normalized) {
|
|
61
|
-
return undefined;
|
|
62
|
-
}
|
|
63
|
-
if (/[\p{Script=Han}]/u.test(normalized)) {
|
|
64
|
-
return "zh";
|
|
65
|
-
}
|
|
66
|
-
if (/[A-Za-z]/u.test(normalized)) {
|
|
67
|
-
return "en";
|
|
68
|
-
}
|
|
69
|
-
return undefined;
|
|
70
|
-
}
|
|
71
|
-
function selectRelevantHistoryTurns(groupedHistory, inputText, options = {}) {
|
|
72
|
-
if (groupedHistory.length === 0) {
|
|
73
|
-
return [];
|
|
74
|
-
}
|
|
75
|
-
if (hasExplicitResourceReference(inputText)) {
|
|
76
|
-
return [];
|
|
77
|
-
}
|
|
78
|
-
return groupedHistory
|
|
79
|
-
.slice(-4)
|
|
80
|
-
.filter((turn) => !options.suppressExplicitResourceTurns || !turn.some((item) => item.role === "user" && hasExplicitResourceReference(extractMessageText(item.content))))
|
|
81
|
-
.map((turn) => options.suppressAssistantTurns ? dropAssistantMessages(turn) : turn)
|
|
82
|
-
.filter((turn) => turn.length > 0)
|
|
83
|
-
.slice(-4);
|
|
84
|
-
}
|
|
85
|
-
export function buildAgentMessages(history, input, options = {}) {
|
|
86
|
-
const inputText = extractMessageText(input).trim();
|
|
87
|
-
if (options.suppressHistoryTurns) {
|
|
88
|
-
return [{ role: "user", content: normalizeMessageContent(input) }];
|
|
89
|
-
}
|
|
90
|
-
const groupedHistory = history.reduce((groups, item) => {
|
|
91
|
-
const current = groups.at(-1);
|
|
92
|
-
if (current && current[0]?.requestId === item.requestId) {
|
|
93
|
-
current.push(item);
|
|
94
|
-
return groups;
|
|
95
|
-
}
|
|
96
|
-
groups.push([item]);
|
|
97
|
-
return groups;
|
|
98
|
-
}, []);
|
|
99
|
-
const selectedTurns = selectRelevantHistoryTurns(groupedHistory, inputText, options);
|
|
100
|
-
return [
|
|
101
|
-
...selectedTurns.flatMap((turn) => renderHistoryTurn(turn)),
|
|
102
|
-
{ role: "user", content: normalizeMessageContent(input) },
|
|
103
|
-
];
|
|
104
|
-
}
|
|
105
|
-
function resolveConversationLanguage(history, inputText) {
|
|
106
|
-
const direct = inferMessageLanguage(inputText);
|
|
107
|
-
if (direct) {
|
|
108
|
-
return direct;
|
|
109
|
-
}
|
|
110
|
-
for (let index = history.length - 1; index >= 0; index -= 1) {
|
|
111
|
-
const message = history[index];
|
|
112
|
-
if (message?.role !== "user") {
|
|
113
|
-
continue;
|
|
114
|
-
}
|
|
115
|
-
const detected = inferMessageLanguage(extractMessageText(message.content));
|
|
116
|
-
if (detected) {
|
|
117
|
-
return detected;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
return undefined;
|
|
121
|
-
}
|
|
122
|
-
function buildContextualFollowUpInstruction(inputText, hasDurableMemory) {
|
|
123
|
-
if (!hasDurableMemory || hasExplicitResourceReference(inputText)) {
|
|
124
|
-
return undefined;
|
|
125
|
-
}
|
|
126
|
-
return "Answer the user's current follow-up directly from the recalled context when it remains relevant. If recalled memory conflicts with the current system prompt, runtime policy, recovery instruction, available tool evidence, or the user's current request, ignore the recalled memory for this turn. If the current user turn corrects, revokes, deletes, or replaces recalled memory, treat the user's latest statement as newer than the recalled memory for this turn. Do not frame the reply as a fresh URL or page summary unless the current user turn explicitly includes a new resource to inspect.";
|
|
127
|
-
}
|
|
128
|
-
export function buildSlashCommandSkillInstruction(binding, input) {
|
|
129
|
-
const inputText = extractMessageText(input).trim();
|
|
130
|
-
const match = inputText.match(/^\/([a-z0-9]+(?:-[a-z0-9]+)*)(?:\s+([\s\S]*))?$/i);
|
|
131
|
-
if (!match) {
|
|
132
|
-
return undefined;
|
|
133
|
-
}
|
|
134
|
-
const invokedName = match[1].toLowerCase();
|
|
135
|
-
const argumentText = match[2]?.trim() ?? "";
|
|
136
|
-
const skillPaths = getBindingSkills(binding);
|
|
137
|
-
const matchedSkillPath = skillPaths.find((skillPath) => readSkillMetadata(skillPath).name.toLowerCase() === invokedName);
|
|
138
|
-
if (!matchedSkillPath) {
|
|
139
|
-
return undefined;
|
|
140
|
-
}
|
|
141
|
-
const metadata = readSkillMetadata(matchedSkillPath);
|
|
142
|
-
const skillQualifier = metadata.userInvocable === true ? "user-invocable skill" : "skill";
|
|
143
|
-
const dryRunHint = /\s--dry-run(?:\s|$)/.test(` ${argumentText} `)
|
|
144
|
-
? "This invocation includes `--dry-run`. Perform the real fetch or inspection steps needed for dry-run output. Do not return hypothetical or mock results."
|
|
145
|
-
: undefined;
|
|
146
|
-
return renderSlashCommandSkillInstruction({
|
|
147
|
-
skillQualifier,
|
|
148
|
-
skillName: metadata.name,
|
|
149
|
-
argumentText,
|
|
150
|
-
dryRunHint,
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
export function buildInvocationRequest(binding, history, input, options = {}) {
|
|
154
|
-
const inputText = extractMessageText(input).trim();
|
|
155
|
-
const userInvocableInstruction = buildSlashCommandSkillInstruction(binding, input);
|
|
156
|
-
const memoryInstruction = typeof options.memoryContext === "string" && options.memoryContext.trim().length > 0
|
|
157
|
-
? renderDurableMemoryContextPrompt(options.memoryContext)
|
|
158
|
-
: undefined;
|
|
159
|
-
const messages = buildAgentMessages(history, input, {
|
|
160
|
-
suppressExplicitResourceTurns: Boolean(memoryInstruction) && !hasExplicitResourceReference(inputText),
|
|
161
|
-
suppressAssistantTurns: Boolean(memoryInstruction) && !hasExplicitResourceReference(inputText),
|
|
162
|
-
suppressHistoryTurns: Boolean(memoryInstruction) && !hasExplicitResourceReference(inputText),
|
|
163
|
-
});
|
|
164
|
-
const contextualFollowUpInstruction = buildContextualFollowUpInstruction(inputText, Boolean(memoryInstruction));
|
|
165
|
-
const conversationLanguage = resolveConversationLanguage(history, inputText);
|
|
166
|
-
const languageInstruction = !inferMessageLanguage(inputText) && conversationLanguage
|
|
167
|
-
? {
|
|
168
|
-
zh: "Reply in Chinese for this turn.",
|
|
169
|
-
en: "Reply in English for this turn.",
|
|
170
|
-
}[conversationLanguage]
|
|
171
|
-
: undefined;
|
|
172
|
-
return {
|
|
173
|
-
...(options.state ?? {}),
|
|
174
|
-
...(options.files ? { files: options.files } : {}),
|
|
175
|
-
messages: [
|
|
176
|
-
...(memoryInstruction ? [{ role: "system", content: memoryInstruction }] : []),
|
|
177
|
-
...(contextualFollowUpInstruction ? [{ role: "system", content: contextualFollowUpInstruction }] : []),
|
|
178
|
-
...(languageInstruction ? [{ role: "system", content: languageInstruction }] : []),
|
|
179
|
-
...(userInvocableInstruction ? [{ role: "system", content: userInvocableInstruction }] : []),
|
|
180
|
-
...messages,
|
|
181
|
-
],
|
|
182
|
-
};
|
|
183
|
-
}
|
|
1
|
+
import{getBindingSkills as x}from"../../support/compiled-binding.js";import{extractMessageText as a,normalizeMessageContent as f}from"../../../utils/message-content.js";import{readSkillMetadata as h}from"../../skills/skill-metadata.js";import{summarizeAssistantText as T}from"../direct-builtin-utility.js";import{renderDurableMemoryContextPrompt as S,renderSlashCommandSkillInstruction as I}from"../../prompts/runtime-prompts.js";import{hasExplicitResourceReference as l}from"../../harness/system/runtime-memory-policy.js";const A=1600,v=40;function C(r){const e=r.trim();if(!e)return e;const t=T(e);if(t!==e)return t;const n=e.split(/\r?\n/);if(e.length<=A&&n.length<=v)return e;const s=e.slice(0,1200).trimEnd(),i=e.slice(-240).trimStart(),o=Math.max(e.length-s.length-i.length,0);return`${s}
|
|
2
|
+
... [${o} characters omitted from prior assistant output] ...
|
|
3
|
+
${i}`}function y(r,e){const t=f(e);return r!=="assistant"||typeof t!="string"?t:C(t)}function k(r){return r.some(t=>{if(t.role!=="assistant"||typeof t.content!="string")return!1;const n=y(t.role,t.content);return typeof n=="string"&&n!==f(t.content)})?[]:r.flatMap(t=>{const n=y(t.role,t.content);return t.role==="assistant"&&typeof t.content=="string"&&typeof n=="string"&&n!==f(t.content)?[]:[{role:t.role,content:n}]})}function R(r){return r.filter(e=>e.role!=="assistant")}function p(r){const e=r.replace(/https?:\/\/\S+/giu," ").trim();if(e){if(/[\p{Script=Han}]/u.test(e))return"zh";if(/[A-Za-z]/u.test(e))return"en"}}function M(r,e,t={}){return r.length===0?[]:l(e)?[]:r.slice(-4).filter(n=>!t.suppressExplicitResourceTurns||!n.some(s=>s.role==="user"&&l(a(s.content)))).map(n=>t.suppressAssistantTurns?R(n):n).filter(n=>n.length>0).slice(-4)}function z(r,e,t={}){const n=a(e).trim();if(t.suppressHistoryTurns)return[{role:"user",content:f(e)}];const s=r.reduce((o,c)=>{const u=o.at(-1);return u&&u[0]?.requestId===c.requestId?(u.push(c),o):(o.push([c]),o)},[]);return[...M(s,n,t).flatMap(o=>k(o)),{role:"user",content:f(e)}]}function H(r,e){const t=p(e);if(t)return t;for(let n=r.length-1;n>=0;n-=1){const s=r[n];if(s?.role!=="user")continue;const i=p(a(s.content));if(i)return i}}function w(r,e){if(!(!e||l(r)))return"Answer the user's current follow-up directly from the recalled context when it remains relevant. If recalled memory conflicts with the current system prompt, runtime policy, recovery instruction, available tool evidence, or the user's current request, ignore the recalled memory for this turn. If the current user turn corrects, revokes, deletes, or replaces recalled memory, treat the user's latest statement as newer than the recalled memory for this turn. Do not frame the reply as a fresh URL or page summary unless the current user turn explicitly includes a new resource to inspect."}function b(r,e){const n=a(e).trim().match(/^\/([a-z0-9]+(?:-[a-z0-9]+)*)(?:\s+([\s\S]*))?$/i);if(!n)return;const s=n[1].toLowerCase(),i=n[2]?.trim()??"",c=x(r).find(g=>h(g).name.toLowerCase()===s);if(!c)return;const u=h(c),m=u.userInvocable===!0?"user-invocable skill":"skill",d=/\s--dry-run(?:\s|$)/.test(` ${i} `)?"This invocation includes `--dry-run`. Perform the real fetch or inspection steps needed for dry-run output. Do not return hypothetical or mock results.":void 0;return I({skillQualifier:m,skillName:u.name,argumentText:i,dryRunHint:d})}function P(r,e,t,n={}){const s=a(t).trim(),i=b(r,t),o=typeof n.memoryContext=="string"&&n.memoryContext.trim().length>0?S(n.memoryContext):void 0,c=z(e,t,{suppressExplicitResourceTurns:!!o&&!l(s),suppressAssistantTurns:!!o&&!l(s),suppressHistoryTurns:!!o&&!l(s)}),u=w(s,!!o),m=H(e,s),d=!p(s)&&m?{zh:"Reply in Chinese for this turn.",en:"Reply in English for this turn."}[m]:void 0;return{...n.state??{},...n.files?{files:n.files}:{},messages:[...o?[{role:"system",content:o}]:[],...u?[{role:"system",content:u}]:[],...d?[{role:"system",content:d}]:[],...i?[{role:"system",content:i}]:[],...c]}}export{z as buildAgentMessages,P as buildInvocationRequest,b as buildSlashCommandSkillInstruction};
|
|
@@ -1,28 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { renderDurableMemoryContextPrompt } from "../../prompts/runtime-prompts.js";
|
|
3
|
-
export function buildStateSnapshot(result) {
|
|
4
|
-
const snapshot = { ...result };
|
|
5
|
-
delete snapshot.messages;
|
|
6
|
-
delete snapshot.__interrupt__;
|
|
7
|
-
delete snapshot.structuredResponse;
|
|
8
|
-
delete snapshot.files;
|
|
9
|
-
return Object.keys(snapshot).length > 0 ? snapshot : undefined;
|
|
10
|
-
}
|
|
11
|
-
export function buildRawModelMessages(binding, systemPrompt, history, input, memoryContext) {
|
|
12
|
-
const messages = [];
|
|
13
|
-
if (systemPrompt) {
|
|
14
|
-
messages.push({ role: "system", content: systemPrompt });
|
|
15
|
-
}
|
|
16
|
-
if (memoryContext?.trim()) {
|
|
17
|
-
messages.push({
|
|
18
|
-
role: "system",
|
|
19
|
-
content: renderDurableMemoryContextPrompt(memoryContext),
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
const userInvocableInstruction = buildSlashCommandSkillInstruction(binding, input);
|
|
23
|
-
if (userInvocableInstruction) {
|
|
24
|
-
messages.push({ role: "system", content: userInvocableInstruction });
|
|
25
|
-
}
|
|
26
|
-
messages.push(...buildAgentMessages(history, input));
|
|
27
|
-
return messages;
|
|
28
|
-
}
|
|
1
|
+
import{buildAgentMessages as u,buildSlashCommandSkillInstruction as i}from"./invocation-request.js";import{renderDurableMemoryContextPrompt as d}from"../../prompts/runtime-prompts.js";function p(s){const e={...s};return delete e.messages,delete e.__interrupt__,delete e.structuredResponse,delete e.files,Object.keys(e).length>0?e:void 0}function m(s,e,l,n,o){const t=[];e&&t.push({role:"system",content:e}),o?.trim()&&t.push({role:"system",content:d(o)});const r=i(s,n);return r&&t.push({role:"system",content:r}),t.push(...u(l,n)),t}export{m as buildRawModelMessages,p as buildStateSnapshot};
|