agent-mockingbird 0.0.1
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/.agents/skills/btca-cli/SKILL.md +64 -0
- package/.agents/skills/btca-cli/agents/openai.yaml +3 -0
- package/.agents/skills/frontend-design/SKILL.md +42 -0
- package/.agents/skills/frontend-design/agents/openai.yaml +3 -0
- package/.env.example +36 -0
- package/.githooks/pre-commit +33 -0
- package/.github/workflows/ci.yml +309 -0
- package/.opencode/bun.lock +18 -0
- package/.opencode/package.json +5 -0
- package/.opencode/tools/agent_type_manager.ts +100 -0
- package/.opencode/tools/config_manager.ts +87 -0
- package/.opencode/tools/cron_manager.ts +145 -0
- package/.opencode/tools/memory_get.ts +43 -0
- package/.opencode/tools/memory_remember.ts +53 -0
- package/.opencode/tools/memory_search.ts +48 -0
- package/AGENTS.md +126 -0
- package/MEMORY.md +2 -0
- package/README.md +451 -0
- package/THIRD_PARTY_NOTICES.md +11 -0
- package/agent-mockingbird.config.example.json +135 -0
- package/apps/server/package.json +32 -0
- package/apps/server/src/backend/agents/bootstrapContext.ts +362 -0
- package/apps/server/src/backend/agents/openclawImport.test.ts +133 -0
- package/apps/server/src/backend/agents/openclawImport.ts +797 -0
- package/apps/server/src/backend/agents/opencodeConfig.ts +428 -0
- package/apps/server/src/backend/agents/service.ts +10 -0
- package/apps/server/src/backend/config/example-config.test.ts +20 -0
- package/apps/server/src/backend/config/orchestration.ts +243 -0
- package/apps/server/src/backend/config/policy.ts +158 -0
- package/apps/server/src/backend/config/schema.test.ts +15 -0
- package/apps/server/src/backend/config/schema.ts +391 -0
- package/apps/server/src/backend/config/semantic.test.ts +34 -0
- package/apps/server/src/backend/config/semantic.ts +149 -0
- package/apps/server/src/backend/config/service.test.ts +75 -0
- package/apps/server/src/backend/config/service.ts +207 -0
- package/apps/server/src/backend/config/smoke.ts +77 -0
- package/apps/server/src/backend/config/store.test.ts +123 -0
- package/apps/server/src/backend/config/store.ts +581 -0
- package/apps/server/src/backend/config/testFixtures.ts +5 -0
- package/apps/server/src/backend/config/types.ts +56 -0
- package/apps/server/src/backend/contracts/events.ts +320 -0
- package/apps/server/src/backend/contracts/runtime.ts +111 -0
- package/apps/server/src/backend/cron/executor.ts +435 -0
- package/apps/server/src/backend/cron/repository.ts +170 -0
- package/apps/server/src/backend/cron/service.ts +660 -0
- package/apps/server/src/backend/cron/storage.ts +92 -0
- package/apps/server/src/backend/cron/types.ts +138 -0
- package/apps/server/src/backend/cron/utils.ts +351 -0
- package/apps/server/src/backend/db/client.ts +20 -0
- package/apps/server/src/backend/db/migrate.ts +40 -0
- package/apps/server/src/backend/db/repository.ts +1762 -0
- package/apps/server/src/backend/db/schema.ts +113 -0
- package/apps/server/src/backend/db/usageDashboard.test.ts +102 -0
- package/apps/server/src/backend/db/wipe.ts +13 -0
- package/apps/server/src/backend/defaults.ts +32 -0
- package/apps/server/src/backend/env.ts +48 -0
- package/apps/server/src/backend/heartbeat/activeHours.ts +45 -0
- package/apps/server/src/backend/heartbeat/defaultJob.ts +88 -0
- package/apps/server/src/backend/heartbeat/heartbeat.test.ts +110 -0
- package/apps/server/src/backend/heartbeat/runtimeService.ts +190 -0
- package/apps/server/src/backend/heartbeat/service.ts +176 -0
- package/apps/server/src/backend/heartbeat/state.test.ts +63 -0
- package/apps/server/src/backend/heartbeat/state.ts +167 -0
- package/apps/server/src/backend/heartbeat/types.ts +54 -0
- package/apps/server/src/backend/http/boundedQueue.test.ts +49 -0
- package/apps/server/src/backend/http/boundedQueue.ts +92 -0
- package/apps/server/src/backend/http/parsers.ts +40 -0
- package/apps/server/src/backend/http/router.ts +61 -0
- package/apps/server/src/backend/http/routes/agentRoutes.ts +67 -0
- package/apps/server/src/backend/http/routes/backgroundRoutes.ts +203 -0
- package/apps/server/src/backend/http/routes/chatRoutes.ts +107 -0
- package/apps/server/src/backend/http/routes/configRoutes.ts +602 -0
- package/apps/server/src/backend/http/routes/cronRoutes.ts +221 -0
- package/apps/server/src/backend/http/routes/dashboardRoutes.ts +308 -0
- package/apps/server/src/backend/http/routes/eventRoutes.ts +7 -0
- package/apps/server/src/backend/http/routes/heartbeatRoutes.test.ts +41 -0
- package/apps/server/src/backend/http/routes/heartbeatRoutes.ts +28 -0
- package/apps/server/src/backend/http/routes/index.ts +101 -0
- package/apps/server/src/backend/http/routes/mcpRoutes.ts +213 -0
- package/apps/server/src/backend/http/routes/memoryRoutes.ts +154 -0
- package/apps/server/src/backend/http/routes/runRoutes.ts +310 -0
- package/apps/server/src/backend/http/routes/runtimeRoutes.ts +197 -0
- package/apps/server/src/backend/http/routes/skillRoutes.ts +112 -0
- package/apps/server/src/backend/http/routes/uiRoutes.test.ts +161 -0
- package/apps/server/src/backend/http/routes/uiRoutes.ts +177 -0
- package/apps/server/src/backend/http/routes/usageRoutes.test.ts +104 -0
- package/apps/server/src/backend/http/routes/usageRoutes.ts +767 -0
- package/apps/server/src/backend/http/schemas.ts +64 -0
- package/apps/server/src/backend/http/sse.ts +144 -0
- package/apps/server/src/backend/integration/backend-core.test.ts +2316 -0
- package/apps/server/src/backend/logging/logger.ts +64 -0
- package/apps/server/src/backend/mcp/service.ts +326 -0
- package/apps/server/src/backend/memory/cli.ts +170 -0
- package/apps/server/src/backend/memory/conceptExpansion.test.ts +28 -0
- package/apps/server/src/backend/memory/conceptExpansion.ts +80 -0
- package/apps/server/src/backend/memory/qmdPort.test.ts +54 -0
- package/apps/server/src/backend/memory/qmdPort.ts +61 -0
- package/apps/server/src/backend/memory/records.test.ts +66 -0
- package/apps/server/src/backend/memory/records.ts +229 -0
- package/apps/server/src/backend/memory/service.ts +2012 -0
- package/apps/server/src/backend/memory/sqliteVec.ts +58 -0
- package/apps/server/src/backend/memory/types.ts +104 -0
- package/apps/server/src/backend/opencode/agentMockingbirdPlugin.test.ts +396 -0
- package/apps/server/src/backend/opencode/client.ts +98 -0
- package/apps/server/src/backend/opencode/models.ts +41 -0
- package/apps/server/src/backend/opencode/systemPrompt.test.ts +146 -0
- package/apps/server/src/backend/opencode/systemPrompt.ts +284 -0
- package/apps/server/src/backend/paths.ts +57 -0
- package/apps/server/src/backend/prompts/service.ts +100 -0
- package/apps/server/src/backend/queue/queue.test.ts +189 -0
- package/apps/server/src/backend/queue/service.ts +177 -0
- package/apps/server/src/backend/queue/types.ts +39 -0
- package/apps/server/src/backend/run/service.ts +576 -0
- package/apps/server/src/backend/run/storage.ts +47 -0
- package/apps/server/src/backend/run/types.ts +44 -0
- package/apps/server/src/backend/runtime/errors.ts +61 -0
- package/apps/server/src/backend/runtime/index.ts +72 -0
- package/apps/server/src/backend/runtime/memoryPromptDedup.test.ts +153 -0
- package/apps/server/src/backend/runtime/memoryPromptDedup.ts +76 -0
- package/apps/server/src/backend/runtime/opencodeRuntime/backgroundMethods.ts +765 -0
- package/apps/server/src/backend/runtime/opencodeRuntime/coreMethods.ts +705 -0
- package/apps/server/src/backend/runtime/opencodeRuntime/eventMethods.ts +503 -0
- package/apps/server/src/backend/runtime/opencodeRuntime/memoryMethods.ts +462 -0
- package/apps/server/src/backend/runtime/opencodeRuntime/promptMethods.ts +1167 -0
- package/apps/server/src/backend/runtime/opencodeRuntime/shared.ts +254 -0
- package/apps/server/src/backend/runtime/opencodeRuntime.test.ts +2899 -0
- package/apps/server/src/backend/runtime/opencodeRuntime.ts +135 -0
- package/apps/server/src/backend/runtime/sessionScope.ts +45 -0
- package/apps/server/src/backend/skills/service.ts +442 -0
- package/apps/server/src/backend/workspace/resolve.ts +27 -0
- package/apps/server/src/cli/agent-mockingbird.mjs +2522 -0
- package/apps/server/src/cli/agent-mockingbird.test.ts +68 -0
- package/apps/server/src/cli/runtime-assets.mjs +269 -0
- package/apps/server/src/cli/runtime-assets.test.ts +52 -0
- package/apps/server/src/cli/runtime-layout.mjs +75 -0
- package/apps/server/src/cli/standaloneBuild.test.ts +19 -0
- package/apps/server/src/cli/standaloneBuild.ts +19 -0
- package/apps/server/src/cli/standaloneCronBinary.test.ts +187 -0
- package/apps/server/src/index.ts +178 -0
- package/apps/server/tsconfig.json +12 -0
- package/backlog.md +5 -0
- package/bin/agent-mockingbird +2522 -0
- package/bin/runtime-layout.mjs +75 -0
- package/build-bin.ts +34 -0
- package/build-cli.mjs +37 -0
- package/build.ts +40 -0
- package/bun-env.d.ts +11 -0
- package/bun.lock +888 -0
- package/bunfig.toml +2 -0
- package/components.json +21 -0
- package/config.json +130 -0
- package/deploy/RELEASE_INSTALL.md +112 -0
- package/deploy/docker-compose.yml +42 -0
- package/deploy/systemd/README.md +46 -0
- package/deploy/systemd/agent-mockingbird.service +28 -0
- package/deploy/systemd/opencode.service +25 -0
- package/docs/legacy-config-ui-reference.md +51 -0
- package/docs/memory-e2e-trace-2026-03-04.md +63 -0
- package/docs/memory-ops.md +96 -0
- package/docs/memory-runtime-contract.md +42 -0
- package/docs/memory-tuning-remote-2026-03-04.md +59 -0
- package/docs/opencode-rebase-workflow-plan.md +614 -0
- package/docs/opencode-startup-sync-plan.md +94 -0
- package/docs/vendor-opencode.md +41 -0
- package/drizzle/0000_famous_turbo.sql +49 -0
- package/drizzle/0001_cron_memory_aux.sql +160 -0
- package/drizzle/0002_runtime_session_bindings.sql +28 -0
- package/drizzle/0003_background_runs.sql +27 -0
- package/drizzle/0004_memory_open_write.sql +63 -0
- package/drizzle/0005_signal_channel.sql +47 -0
- package/drizzle/0006_usage_event_dimensions.sql +7 -0
- package/drizzle/meta/0000_snapshot.json +341 -0
- package/drizzle/meta/_journal.json +55 -0
- package/drizzle.config.ts +14 -0
- package/eslint.config.mjs +77 -0
- package/knip.json +18 -0
- package/memory/2026-03-04.md +4 -0
- package/opencode.lock.json +16 -0
- package/package.json +67 -0
- package/packages/agent-mockingbird-installer/README.md +31 -0
- package/packages/agent-mockingbird-installer/bin/agent-mockingbird-installer.mjs +44 -0
- package/packages/agent-mockingbird-installer/opencode.lock.json +16 -0
- package/packages/agent-mockingbird-installer/package.json +23 -0
- package/packages/contracts/package.json +19 -0
- package/packages/contracts/src/agentTypes.ts +122 -0
- package/packages/contracts/src/cron.ts +146 -0
- package/packages/contracts/src/dashboard.ts +378 -0
- package/packages/contracts/src/index.ts +3 -0
- package/packages/contracts/tsconfig.json +4 -0
- package/patches/opencode/0001-Wafflebot-OpenCode-baseline.patch +2341 -0
- package/patches/opencode/0002-Fix-OpenCode-web-entry-and-settings-icons.patch +104 -0
- package/patches/opencode/0003-fix-app-remove-duplicate-sidebar-mount.patch +32 -0
- package/patches/opencode/0004-Add-heartbeat-settings-and-usage-nav.patch +506 -0
- package/patches/opencode/0005-Use-chart-icon-for-usage-nav.patch +38 -0
- package/patches/opencode/0006-Modernize-cron-settings.patch +399 -0
- package/patches/opencode/0007-Rename-waffle-namespaces-to-mockingbird.patch +1110 -0
- package/patches/opencode/0008-Remove-cron-contract-section.patch +178 -0
- package/patches/opencode/0009-Rework-cron-tab-as-operations-console.patch +414 -0
- package/patches/opencode/0010-Refine-heartbeat-settings-controls.patch +208 -0
- package/runtime-assets/opencode-config/opencode.jsonc +25 -0
- package/runtime-assets/opencode-config/package.json +5 -0
- package/runtime-assets/opencode-config/plugins/agent-mockingbird.ts +715 -0
- package/runtime-assets/workspace/.agents/skills/config-auditor/SKILL.md +25 -0
- package/runtime-assets/workspace/.agents/skills/config-editor/SKILL.md +24 -0
- package/runtime-assets/workspace/.agents/skills/cron-manager/SKILL.md +57 -0
- package/runtime-assets/workspace/.agents/skills/memory-ops/SKILL.md +120 -0
- package/runtime-assets/workspace/.agents/skills/runtime-diagnose/SKILL.md +25 -0
- package/runtime-assets/workspace/AGENTS.md +56 -0
- package/runtime-assets/workspace/MEMORY.md +4 -0
- package/scripts/build-release-bundle.sh +66 -0
- package/scripts/check-ship.ts +383 -0
- package/scripts/dev-opencode.sh +17 -0
- package/scripts/dev-stack-opencode.sh +15 -0
- package/scripts/dev-stack.sh +61 -0
- package/scripts/install-systemd.sh +87 -0
- package/scripts/memory-e2e.sh +76 -0
- package/scripts/memory-trace-e2e.sh +141 -0
- package/scripts/migrate-opencode-env.ts +108 -0
- package/scripts/onboard/bootstrap.sh +32 -0
- package/scripts/opencode-swap.ts +78 -0
- package/scripts/opencode-sync.ts +715 -0
- package/scripts/runtime-assets-sync.mjs +83 -0
- package/scripts/setup-git-hooks.ts +39 -0
- package/tsconfig.json +45 -0
- package/tui.json +98 -0
- package/turbo.json +36 -0
- package/vendor/OPENCODE_VENDOR.md +13 -0
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ChatMessagePart,
|
|
3
|
+
MemoryToolCallTrace,
|
|
4
|
+
MessageMemoryTrace,
|
|
5
|
+
} from "@agent-mockingbird/contracts/dashboard";
|
|
6
|
+
import type {
|
|
7
|
+
Config,
|
|
8
|
+
Event as OpencodeEvent,
|
|
9
|
+
Message,
|
|
10
|
+
OpencodeClient,
|
|
11
|
+
Part,
|
|
12
|
+
Session,
|
|
13
|
+
SessionStatus as OpencodeSessionStatus,
|
|
14
|
+
} from "@opencode-ai/sdk/client";
|
|
15
|
+
|
|
16
|
+
import type {
|
|
17
|
+
ConfiguredMcpServer,
|
|
18
|
+
AgentMockingbirdConfig,
|
|
19
|
+
} from "../../config/schema";
|
|
20
|
+
import { getConfigSnapshot } from "../../config/service";
|
|
21
|
+
import type { RuntimeEvent } from "../../contracts/events";
|
|
22
|
+
import type {
|
|
23
|
+
BackgroundRunHandle,
|
|
24
|
+
BackgroundRunStatus,
|
|
25
|
+
ListBackgroundRunsInput,
|
|
26
|
+
PromptBackgroundAsyncInput,
|
|
27
|
+
RuntimeHealthCheckInput,
|
|
28
|
+
RuntimeHealthCheckResult,
|
|
29
|
+
RuntimeInputPart,
|
|
30
|
+
RuntimeMessageAck,
|
|
31
|
+
SendUserMessageInput,
|
|
32
|
+
SpawnBackgroundSessionInput,
|
|
33
|
+
} from "../../contracts/runtime";
|
|
34
|
+
import { createLogger } from "../../logging/logger";
|
|
35
|
+
import type { MemorySearchResult } from "../../memory/types";
|
|
36
|
+
|
|
37
|
+
export type Listener = (event: RuntimeEvent) => void;
|
|
38
|
+
export type AssistantInfo = Extract<Message, { role: "assistant" }>;
|
|
39
|
+
export type OpencodeMessagePartUpdatedEvent = Extract<
|
|
40
|
+
OpencodeEvent,
|
|
41
|
+
{ type: "message.part.updated" }
|
|
42
|
+
>;
|
|
43
|
+
export type OpencodeMessageUpdatedEvent = Extract<
|
|
44
|
+
OpencodeEvent,
|
|
45
|
+
{ type: "message.updated" }
|
|
46
|
+
>;
|
|
47
|
+
export type OpencodeMessagePartDeltaEvent = {
|
|
48
|
+
type: "message.part.delta";
|
|
49
|
+
properties: {
|
|
50
|
+
sessionID: string;
|
|
51
|
+
messageID: string;
|
|
52
|
+
partID: string;
|
|
53
|
+
field: string;
|
|
54
|
+
delta: string;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
export type OpencodePermissionAskedEvent = {
|
|
58
|
+
type: "permission.asked";
|
|
59
|
+
properties: {
|
|
60
|
+
id: string;
|
|
61
|
+
sessionID: string;
|
|
62
|
+
permission: string;
|
|
63
|
+
patterns: string[];
|
|
64
|
+
metadata: Record<string, unknown>;
|
|
65
|
+
always: string[];
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
export type OpencodePermissionRepliedEvent = {
|
|
69
|
+
type: "permission.replied";
|
|
70
|
+
properties: {
|
|
71
|
+
sessionID: string;
|
|
72
|
+
requestID?: string;
|
|
73
|
+
reply?: "once" | "always" | "reject";
|
|
74
|
+
permissionID?: string;
|
|
75
|
+
response?: string;
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
export type OpencodeQuestionAskedEvent = {
|
|
79
|
+
type: "question.asked";
|
|
80
|
+
properties: {
|
|
81
|
+
id: string;
|
|
82
|
+
sessionID: string;
|
|
83
|
+
questions: Array<{
|
|
84
|
+
question: string;
|
|
85
|
+
header: string;
|
|
86
|
+
options: Array<{ label: string; description: string }>;
|
|
87
|
+
multiple?: boolean;
|
|
88
|
+
custom?: boolean;
|
|
89
|
+
}>;
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
export type OpencodeQuestionRepliedEvent = {
|
|
93
|
+
type: "question.replied";
|
|
94
|
+
properties: {
|
|
95
|
+
sessionID: string;
|
|
96
|
+
requestID: string;
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
export type OpencodeQuestionRejectedEvent = {
|
|
100
|
+
type: "question.rejected";
|
|
101
|
+
properties: {
|
|
102
|
+
sessionID: string;
|
|
103
|
+
requestID: string;
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
export type OpencodeRuntimeEvent =
|
|
107
|
+
| OpencodeEvent
|
|
108
|
+
| OpencodeMessagePartDeltaEvent
|
|
109
|
+
| OpencodePermissionAskedEvent
|
|
110
|
+
| OpencodePermissionRepliedEvent
|
|
111
|
+
| OpencodeQuestionAskedEvent
|
|
112
|
+
| OpencodeQuestionRepliedEvent
|
|
113
|
+
| OpencodeQuestionRejectedEvent;
|
|
114
|
+
export type ResolvedModel = { providerId: string; modelId: string };
|
|
115
|
+
export type RuntimeOpencodeConfig =
|
|
116
|
+
AgentMockingbirdConfig["runtime"]["opencode"];
|
|
117
|
+
export type RuntimeAgentCatalog = {
|
|
118
|
+
ids: Set<string>;
|
|
119
|
+
primaryId?: string;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
export interface OpencodeRuntimeOptions {
|
|
123
|
+
defaultProviderId: string;
|
|
124
|
+
defaultModelId: string;
|
|
125
|
+
fallbackModelRefs?: Array<string>;
|
|
126
|
+
client?: OpencodeClient;
|
|
127
|
+
getRuntimeConfig?: () => RuntimeOpencodeConfig;
|
|
128
|
+
getEnabledSkills?: () => Array<string>;
|
|
129
|
+
getEnabledMcps?: () => Array<string>;
|
|
130
|
+
getConfiguredMcpServers?: () => Array<ConfiguredMcpServer>;
|
|
131
|
+
enableEventSync?: boolean;
|
|
132
|
+
enableSmallModelSync?: boolean;
|
|
133
|
+
enableBackgroundSync?: boolean;
|
|
134
|
+
searchMemoryFn?: (
|
|
135
|
+
query: string,
|
|
136
|
+
options?: { maxResults?: number; minScore?: number },
|
|
137
|
+
) => Promise<MemorySearchResult[]>;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export const MODEL_MEMORY_TOOLS = new Set([
|
|
141
|
+
"memory_search",
|
|
142
|
+
"memory_get",
|
|
143
|
+
"memory_remember",
|
|
144
|
+
]);
|
|
145
|
+
export const RUNTIME_HEALTH_PROMPT =
|
|
146
|
+
'Just respond "OK" to this to confirm the gateway is working.';
|
|
147
|
+
export const RUNTIME_HEALTH_OK_PATTERN = /\bok\b/i;
|
|
148
|
+
export const RUNTIME_HEALTH_CACHE_TTL_MS = 5_000;
|
|
149
|
+
export const RUNTIME_HEALTH_TIMEOUT_CAP_MS = 15_000;
|
|
150
|
+
export const OPENCODE_RUNTIME_ID = "opencode";
|
|
151
|
+
export const BACKGROUND_SYNC_INTERVAL_MS = 8_000;
|
|
152
|
+
export const BACKGROUND_SYNC_BATCH_LIMIT = 200;
|
|
153
|
+
export const BACKGROUND_MESSAGE_SYNC_MIN_INTERVAL_MS = 3_000;
|
|
154
|
+
export const SESSION_SYNC_MESSAGE_LIMIT = 10_000;
|
|
155
|
+
const QUEUE_DRAIN_METADATA_KEY = "__queueDrain";
|
|
156
|
+
export const STREAMED_METADATA_CACHE_LIMIT = 10_000;
|
|
157
|
+
export const AGENT_NAME_CACHE_TTL_MS = 5_000;
|
|
158
|
+
export const MEMORY_INJECTION_STATE_TTL_MS = 6 * 60 * 60_000;
|
|
159
|
+
export const MEMORY_INJECTION_STATE_MAX_ENTRIES = 1_000;
|
|
160
|
+
export const BUILTIN_SUBAGENT_IDS = new Set(["general", "explore"]);
|
|
161
|
+
export const BUILTIN_PRIMARY_AGENT_IDS = new Set([
|
|
162
|
+
"build",
|
|
163
|
+
"plan",
|
|
164
|
+
"title",
|
|
165
|
+
"summary",
|
|
166
|
+
"compaction",
|
|
167
|
+
]);
|
|
168
|
+
export type RuntimeHealthSnapshot = Omit<RuntimeHealthCheckResult, "fromCache">;
|
|
169
|
+
export type MemoryInjectionState = {
|
|
170
|
+
fingerprint: string;
|
|
171
|
+
forceReinject: boolean;
|
|
172
|
+
generation: number;
|
|
173
|
+
turn: number;
|
|
174
|
+
injectedKeysByGeneration: string[];
|
|
175
|
+
};
|
|
176
|
+
export type MemoryInjectionStateEntry = {
|
|
177
|
+
state: MemoryInjectionState;
|
|
178
|
+
lastTouchedAt: number;
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
export const logger = createLogger("opencode-runtime");
|
|
182
|
+
|
|
183
|
+
export function shouldQueueWhenBusy(input: SendUserMessageInput): boolean {
|
|
184
|
+
return input.metadata?.heartbeat !== true;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export function isQueueDrainRequest(input: SendUserMessageInput): boolean {
|
|
188
|
+
return input.metadata?.[QUEUE_DRAIN_METADATA_KEY] === true;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export function isPlainObject(
|
|
192
|
+
value: unknown,
|
|
193
|
+
): value is Record<string, unknown> {
|
|
194
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export function normalizeStringArray(values: unknown) {
|
|
198
|
+
if (!Array.isArray(values)) return [];
|
|
199
|
+
const normalized = values
|
|
200
|
+
.map((value) => (typeof value === "string" ? value.trim() : ""))
|
|
201
|
+
.filter(Boolean);
|
|
202
|
+
return [...new Set(normalized)].sort((a, b) => a.localeCompare(b));
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export function shallowEqualStringArrays(
|
|
206
|
+
left: Array<string>,
|
|
207
|
+
right: Array<string>,
|
|
208
|
+
) {
|
|
209
|
+
if (left.length !== right.length) return false;
|
|
210
|
+
for (let index = 0; index < left.length; index += 1) {
|
|
211
|
+
if (left[index] !== right[index]) return false;
|
|
212
|
+
}
|
|
213
|
+
return true;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export function currentMemoryConfig() {
|
|
217
|
+
return getConfigSnapshot().config.runtime.memory;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
export function normalizeUsageDelta(value: unknown): number {
|
|
221
|
+
if (typeof value !== "number" || !Number.isFinite(value)) return 0;
|
|
222
|
+
if (value <= 0) return 0;
|
|
223
|
+
return Math.round(value);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export function normalizeCostDelta(value: unknown): number {
|
|
227
|
+
if (typeof value !== "number" || !Number.isFinite(value)) return 0;
|
|
228
|
+
if (value <= 0) return 0;
|
|
229
|
+
return value;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export type {
|
|
233
|
+
ChatMessagePart,
|
|
234
|
+
Config,
|
|
235
|
+
ListBackgroundRunsInput,
|
|
236
|
+
MemorySearchResult,
|
|
237
|
+
MemoryToolCallTrace,
|
|
238
|
+
Message,
|
|
239
|
+
MessageMemoryTrace,
|
|
240
|
+
OpencodeClient,
|
|
241
|
+
OpencodeEvent,
|
|
242
|
+
OpencodeSessionStatus,
|
|
243
|
+
Part,
|
|
244
|
+
PromptBackgroundAsyncInput,
|
|
245
|
+
RuntimeHealthCheckInput,
|
|
246
|
+
RuntimeHealthCheckResult,
|
|
247
|
+
RuntimeInputPart,
|
|
248
|
+
RuntimeMessageAck,
|
|
249
|
+
SendUserMessageInput,
|
|
250
|
+
Session,
|
|
251
|
+
SpawnBackgroundSessionInput,
|
|
252
|
+
BackgroundRunHandle,
|
|
253
|
+
BackgroundRunStatus,
|
|
254
|
+
};
|