@botbotgo/agent-harness 0.0.298 → 0.0.300

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.
Files changed (166) hide show
  1. package/README.md +78 -38
  2. package/README.zh.md +80 -31
  3. package/dist/acp.d.ts +3 -0
  4. package/dist/acp.js +10 -2
  5. package/dist/api.d.ts +14 -2
  6. package/dist/api.js +19 -3
  7. package/dist/cli.d.ts +18 -1
  8. package/dist/cli.js +1408 -319
  9. package/dist/client/acp.d.ts +9 -3
  10. package/dist/client/acp.js +55 -1
  11. package/dist/client/in-process.d.ts +5 -2
  12. package/dist/client/in-process.js +4 -6
  13. package/dist/client/index.d.ts +1 -1
  14. package/dist/client/types.d.ts +6 -5
  15. package/dist/config/agents/direct.yaml +7 -17
  16. package/dist/config/agents/orchestra.yaml +9 -65
  17. package/dist/config/catalogs/embedding-models.yaml +1 -1
  18. package/dist/config/catalogs/stores.yaml +1 -1
  19. package/dist/config/knowledge/knowledge-runtime.yaml +36 -2
  20. package/dist/config/knowledge/procedural-memory-runtime.yaml +78 -0
  21. package/dist/config/{catalogs/models.yaml → models.yaml} +2 -2
  22. package/dist/config/prompts/direct-system.md +16 -0
  23. package/dist/config/prompts/orchestra-system.md +62 -0
  24. package/dist/config/prompts/routing-system.md +14 -0
  25. package/dist/config/runtime/runtime-memory.yaml +39 -5
  26. package/dist/config/runtime/workspace.yaml +7 -16
  27. package/dist/contracts/runtime.d.ts +242 -1
  28. package/dist/contracts/workspace.d.ts +2 -0
  29. package/dist/index.d.ts +5 -3
  30. package/dist/index.js +2 -1
  31. package/dist/init-project.js +178 -33
  32. package/dist/knowledge/contracts.d.ts +5 -0
  33. package/dist/knowledge/module.d.ts +5 -0
  34. package/dist/knowledge/module.js +340 -18
  35. package/dist/package-version.d.ts +1 -1
  36. package/dist/package-version.js +1 -1
  37. package/dist/persistence/file-store.d.ts +5 -1
  38. package/dist/persistence/file-store.js +16 -0
  39. package/dist/persistence/sqlite-store.d.ts +4 -1
  40. package/dist/persistence/sqlite-store.js +88 -14
  41. package/dist/persistence/types.d.ts +4 -1
  42. package/dist/procedural/config.d.ts +63 -0
  43. package/dist/procedural/config.js +125 -0
  44. package/dist/procedural/index.d.ts +2 -0
  45. package/dist/procedural/index.js +1 -0
  46. package/dist/protocol/ag-ui/http.d.ts +3 -0
  47. package/dist/protocol/ag-ui/http.js +10 -0
  48. package/dist/request-events.d.ts +63 -0
  49. package/dist/request-events.js +400 -0
  50. package/dist/resource/isolation.js +11 -0
  51. package/dist/resource/resource-impl.d.ts +1 -0
  52. package/dist/resource/resource-impl.js +103 -12
  53. package/dist/resources/init-templates/agent-context/deep-research.md +5 -0
  54. package/dist/resources/init-templates/prompts/research-analyst-basic.md +1 -0
  55. package/dist/resources/init-templates/prompts/research-analyst-web-search.md +1 -0
  56. package/dist/resources/init-templates/prompts/research-host-deep-research-basic.md +1 -0
  57. package/dist/resources/init-templates/prompts/research-host-deep-research-web-search.md +1 -0
  58. package/dist/resources/init-templates/prompts/research-host-single-agent-basic.md +1 -0
  59. package/dist/resources/init-templates/prompts/research-host-single-agent-web-search.md +1 -0
  60. package/dist/resources/prompts/runtime/browser-capability-disclaimer-recovery.md +1 -0
  61. package/dist/resources/prompts/runtime/default-subagent.md +2 -0
  62. package/dist/resources/prompts/runtime/durable-memory-context.md +7 -0
  63. package/dist/resources/prompts/runtime/execution-with-tool-evidence-retry.md +1 -0
  64. package/dist/resources/prompts/runtime/execution-with-tool-evidence.md +1 -0
  65. package/dist/resources/prompts/runtime/invalid-tool-selection-recovery.md +1 -0
  66. package/dist/resources/prompts/runtime/memory-manager.md +31 -0
  67. package/dist/resources/prompts/runtime/memory-mutation-reconciliation.md +22 -0
  68. package/dist/resources/prompts/runtime/slash-command-skill.md +6 -0
  69. package/dist/resources/prompts/runtime/strict-tool-json.md +1 -0
  70. package/dist/resources/prompts/runtime/workspace-boundary-guidance.md +3 -0
  71. package/dist/resources/prompts/runtime/workspace-relative-path.md +1 -0
  72. package/dist/resources/prompts/runtime/write-todos-descriptive-content.md +1 -0
  73. package/dist/resources/prompts/runtime/write-todos-full-entry.md +1 -0
  74. package/dist/resources/prompts/runtime/write-todos-non-empty-initial-list.md +1 -0
  75. package/dist/resources/tools/_runtime_tool_helpers.mjs +152 -0
  76. package/dist/resources/tools/cancel_request.mjs +21 -0
  77. package/dist/resources/tools/fetch_url.mjs +23 -0
  78. package/dist/resources/tools/http_request.mjs +30 -0
  79. package/dist/resources/tools/inspect_approvals.mjs +27 -0
  80. package/dist/resources/tools/inspect_artifacts.mjs +21 -0
  81. package/dist/resources/tools/inspect_events.mjs +21 -0
  82. package/dist/resources/tools/inspect_requests.mjs +27 -0
  83. package/dist/resources/tools/inspect_sessions.mjs +21 -0
  84. package/dist/resources/tools/list_files.mjs +27 -0
  85. package/dist/resources/tools/read_artifact.mjs +22 -0
  86. package/dist/resources/tools/request_approval.mjs +27 -0
  87. package/dist/resources/tools/run_command.mjs +21 -0
  88. package/dist/resources/tools/schedule_task.mjs +76 -0
  89. package/dist/resources/tools/search_files.mjs +47 -0
  90. package/dist/resources/tools/send_message.mjs +23 -0
  91. package/dist/runtime/adapter/direct-builtin-utility.d.ts +1 -0
  92. package/dist/runtime/adapter/direct-builtin-utility.js +90 -0
  93. package/dist/runtime/adapter/flow/execution-context.d.ts +1 -1
  94. package/dist/runtime/adapter/flow/execution-context.js +1 -1
  95. package/dist/runtime/adapter/flow/invocation-flow.d.ts +1 -0
  96. package/dist/runtime/adapter/flow/invocation-flow.js +9 -1
  97. package/dist/runtime/adapter/flow/invoke-runtime.d.ts +1 -1
  98. package/dist/runtime/adapter/flow/stream-runtime.d.ts +5 -1
  99. package/dist/runtime/adapter/flow/stream-runtime.js +556 -35
  100. package/dist/runtime/adapter/invocation-result.js +3 -2
  101. package/dist/runtime/adapter/local-tool-invocation.d.ts +1 -1
  102. package/dist/runtime/adapter/local-tool-invocation.js +28 -4
  103. package/dist/runtime/adapter/middleware-assembly.js +3 -1
  104. package/dist/runtime/adapter/model/invocation-request.d.ts +4 -1
  105. package/dist/runtime/adapter/model/invocation-request.js +138 -16
  106. package/dist/runtime/adapter/model/message-assembly.js +2 -6
  107. package/dist/runtime/adapter/model/model-providers.js +103 -5
  108. package/dist/runtime/adapter/resilience.js +17 -2
  109. package/dist/runtime/adapter/runtime-adapter-support.d.ts +11 -7
  110. package/dist/runtime/adapter/runtime-adapter-support.js +39 -5
  111. package/dist/runtime/adapter/tool/builtin-middleware-tools.d.ts +63 -1
  112. package/dist/runtime/adapter/tool/builtin-middleware-tools.js +193 -21
  113. package/dist/runtime/adapter/tool/tool-arguments.d.ts +3 -1
  114. package/dist/runtime/adapter/tool/tool-arguments.js +52 -17
  115. package/dist/runtime/adapter/tool-resolution.d.ts +1 -0
  116. package/dist/runtime/adapter/tool-resolution.js +4 -2
  117. package/dist/runtime/agent-runtime-adapter.d.ts +27 -0
  118. package/dist/runtime/agent-runtime-adapter.js +163 -11
  119. package/dist/runtime/harness/events/event-bus.d.ts +1 -0
  120. package/dist/runtime/harness/events/event-bus.js +3 -0
  121. package/dist/runtime/harness/events/event-sink.d.ts +3 -0
  122. package/dist/runtime/harness/events/event-sink.js +16 -7
  123. package/dist/runtime/harness/events/streaming.d.ts +18 -1
  124. package/dist/runtime/harness/events/streaming.js +23 -10
  125. package/dist/runtime/harness/run/inspection.js +26 -5
  126. package/dist/runtime/harness/run/stream-run.d.ts +13 -4
  127. package/dist/runtime/harness/run/stream-run.js +448 -4
  128. package/dist/runtime/harness/run/surface-semantics.js +7 -34
  129. package/dist/runtime/harness/system/runtime-memory-manager.d.ts +3 -0
  130. package/dist/runtime/harness/system/runtime-memory-manager.js +384 -69
  131. package/dist/runtime/harness/system/runtime-memory-policy.d.ts +20 -1
  132. package/dist/runtime/harness/system/runtime-memory-policy.js +65 -17
  133. package/dist/runtime/harness/system/runtime-memory-records.js +100 -0
  134. package/dist/runtime/harness/system/runtime-memory-sync.js +2 -2
  135. package/dist/runtime/harness/system/store.d.ts +4 -0
  136. package/dist/runtime/harness/system/store.js +153 -0
  137. package/dist/runtime/harness.d.ts +9 -1
  138. package/dist/runtime/harness.js +141 -7
  139. package/dist/runtime/maintenance/sqlite-checkpoint-saver.d.ts +8 -3
  140. package/dist/runtime/maintenance/sqlite-checkpoint-saver.js +152 -53
  141. package/dist/runtime/parsing/output-parsing.d.ts +10 -2
  142. package/dist/runtime/parsing/output-parsing.js +223 -16
  143. package/dist/runtime/parsing/stream-event-parsing.d.ts +7 -0
  144. package/dist/runtime/parsing/stream-event-parsing.js +51 -1
  145. package/dist/runtime/scheduling/system-schedule-manager.d.ts +41 -0
  146. package/dist/runtime/scheduling/system-schedule-manager.js +532 -0
  147. package/dist/runtime/support/embedding-models.d.ts +1 -1
  148. package/dist/runtime/support/embedding-models.js +5 -2
  149. package/dist/runtime/support/runtime-factories.js +1 -1
  150. package/dist/runtime/support/runtime-layout.d.ts +3 -0
  151. package/dist/runtime/support/runtime-layout.js +10 -1
  152. package/dist/runtime/support/runtime-prompts.d.ts +30 -0
  153. package/dist/runtime/support/runtime-prompts.js +55 -0
  154. package/dist/runtime/support/vector-stores.d.ts +1 -1
  155. package/dist/runtime/support/vector-stores.js +5 -2
  156. package/dist/upstream-events.js +8 -7
  157. package/dist/utils/bundled-text.d.ts +3 -0
  158. package/dist/utils/bundled-text.js +25 -0
  159. package/dist/utils/id.js +3 -2
  160. package/dist/workspace/agent-binding-compiler.js +53 -13
  161. package/dist/workspace/object-loader.js +64 -2
  162. package/dist/workspace/support/workspace-ref-utils.d.ts +2 -1
  163. package/dist/workspace/support/workspace-ref-utils.js +24 -5
  164. package/dist/workspace/yaml-object-reader.d.ts +1 -0
  165. package/dist/workspace/yaml-object-reader.js +95 -17
  166. package/package.json +11 -5
@@ -5,7 +5,7 @@ import { fileExists, readJson, writeJson } from "../utils/fs.js";
5
5
  import { resolveRuntimeRoot, resolveRuntimeSqlitePath } from "../runtime/support/runtime-layout.js";
6
6
  import { SqliteRequestContextStore } from "./sqlite-request-context-store.js";
7
7
  import { SqliteRequestQueueStore } from "./sqlite-request-queue-store.js";
8
- const RUNTIME_SQLITE_SCHEMA_VERSION = 6;
8
+ const RUNTIME_SQLITE_SCHEMA_VERSION = 7;
9
9
  const RUNTIME_SQLITE_SCHEMA_FAMILY = "agent-harness-runtime";
10
10
  const ACTIVE_REQUEST_STATES = new Set([
11
11
  "queued",
@@ -33,6 +33,8 @@ function parseJson(value) {
33
33
  function toSqliteUrl(filePath) {
34
34
  return `file:${filePath}`;
35
35
  }
36
+ const SQLITE_BUSY_RETRY_ATTEMPTS = 30;
37
+ const SQLITE_BUSY_RETRY_DELAY_MS = 100;
36
38
  function nowIso() {
37
39
  return new Date(Date.now()).toISOString();
38
40
  }
@@ -57,6 +59,24 @@ function throwWrappedRuntimeSqliteError(dbPath, sql, error) {
57
59
  wrapped.cause = error;
58
60
  throw wrapped;
59
61
  }
62
+ function collectErrorMessages(error) {
63
+ const messages = [];
64
+ let current = error;
65
+ while (current instanceof Error) {
66
+ messages.push(current.message);
67
+ current = current.cause;
68
+ }
69
+ if (typeof current === "string" && current.length > 0) {
70
+ messages.push(current);
71
+ }
72
+ return messages;
73
+ }
74
+ function isSqliteBusyError(error) {
75
+ return collectErrorMessages(error).some((message) => /SQLITE_BUSY|database is locked/i.test(message));
76
+ }
77
+ function sleep(ms) {
78
+ return new Promise((resolve) => setTimeout(resolve, ms));
79
+ }
60
80
  function buildWhereClause(filters) {
61
81
  const active = filters.filter(([, value]) => value !== undefined);
62
82
  if (active.length === 0) {
@@ -121,25 +141,36 @@ export class SqlitePersistence {
121
141
  }
122
142
  async rawExecute(sql, args) {
123
143
  const client = await this.getClient();
124
- try {
125
- if (args) {
126
- await client.execute(sql, args);
144
+ for (let attempt = 0;; attempt += 1) {
145
+ try {
146
+ if (args) {
147
+ await client.execute(sql, args);
148
+ return;
149
+ }
150
+ await client.execute(sql);
127
151
  return;
128
152
  }
129
- await client.execute(sql);
130
- }
131
- catch (error) {
132
- throwWrappedRuntimeSqliteError(this.dbPath, sql, error);
153
+ catch (error) {
154
+ if (!isSqliteBusyError(error) || attempt >= SQLITE_BUSY_RETRY_ATTEMPTS) {
155
+ throwWrappedRuntimeSqliteError(this.dbPath, sql, error);
156
+ }
157
+ await sleep(Math.min(SQLITE_BUSY_RETRY_DELAY_MS * (attempt + 1), 1_000));
158
+ }
133
159
  }
134
160
  }
135
161
  async rawSelectAll(sql, args) {
136
162
  const client = await this.getClient();
137
- try {
138
- const result = args ? await client.execute(sql, args) : await client.execute(sql);
139
- return result.rows.map((row) => asRow(row));
140
- }
141
- catch (error) {
142
- throwWrappedRuntimeSqliteError(this.dbPath, sql, error);
163
+ for (let attempt = 0;; attempt += 1) {
164
+ try {
165
+ const result = args ? await client.execute(sql, args) : await client.execute(sql);
166
+ return result.rows.map((row) => asRow(row));
167
+ }
168
+ catch (error) {
169
+ if (!isSqliteBusyError(error) || attempt >= SQLITE_BUSY_RETRY_ATTEMPTS) {
170
+ throwWrappedRuntimeSqliteError(this.dbPath, sql, error);
171
+ }
172
+ await sleep(Math.min(SQLITE_BUSY_RETRY_DELAY_MS * (attempt + 1), 1_000));
173
+ }
143
174
  }
144
175
  }
145
176
  async ensureInitialized() {
@@ -312,6 +343,18 @@ export class SqlitePersistence {
312
343
  await this.rawExecute("CREATE INDEX IF NOT EXISTS request_queue_available_idx ON request_queue(available_at, priority DESC, enqueued_at ASC)");
313
344
  await this.rawExecute("CREATE INDEX IF NOT EXISTS request_queue_claim_idx ON request_queue(claimed_by, lease_expires_at)");
314
345
  await this.rawExecute(`
346
+ CREATE TABLE IF NOT EXISTS request_plan_state (
347
+ request_id TEXT PRIMARY KEY,
348
+ session_id TEXT NOT NULL,
349
+ version INTEGER NOT NULL,
350
+ updated_at TEXT NOT NULL,
351
+ plan_json TEXT NOT NULL,
352
+ FOREIGN KEY (session_id) REFERENCES sessions(session_id),
353
+ FOREIGN KEY (request_id) REFERENCES requests(request_id)
354
+ )
355
+ `);
356
+ await this.rawExecute("CREATE INDEX IF NOT EXISTS request_plan_state_thread_updated_idx ON request_plan_state(session_id, updated_at DESC)");
357
+ await this.rawExecute(`
315
358
  CREATE TABLE IF NOT EXISTS request_control (
316
359
  request_id TEXT PRIMARY KEY,
317
360
  cancel_requested INTEGER NOT NULL DEFAULT 0,
@@ -545,6 +588,22 @@ export class SqlitePersistence {
545
588
  await this.rawExecute("INSERT OR REPLACE INTO runtime_metadata (key, value) VALUES (?, ?)", ["schema_version", String(RUNTIME_SQLITE_SCHEMA_VERSION)]);
546
589
  return;
547
590
  }
591
+ if (version === "6") {
592
+ await this.rawExecute(`
593
+ CREATE TABLE IF NOT EXISTS request_plan_state (
594
+ request_id TEXT PRIMARY KEY,
595
+ session_id TEXT NOT NULL,
596
+ version INTEGER NOT NULL,
597
+ updated_at TEXT NOT NULL,
598
+ plan_json TEXT NOT NULL,
599
+ FOREIGN KEY (session_id) REFERENCES sessions(session_id),
600
+ FOREIGN KEY (request_id) REFERENCES requests(request_id)
601
+ )
602
+ `);
603
+ await this.rawExecute("CREATE INDEX IF NOT EXISTS request_plan_state_thread_updated_idx ON request_plan_state(session_id, updated_at DESC)");
604
+ await this.rawExecute("INSERT OR REPLACE INTO runtime_metadata (key, value) VALUES (?, ?)", ["schema_version", String(RUNTIME_SQLITE_SCHEMA_VERSION)]);
605
+ return;
606
+ }
548
607
  if (version !== String(RUNTIME_SQLITE_SCHEMA_VERSION)) {
549
608
  throw new Error(`Unsupported runtime sqlite schema version ${JSON.stringify(version)} in ${this.dbPath}. Expected ${RUNTIME_SQLITE_SCHEMA_VERSION}.`);
550
609
  }
@@ -964,6 +1023,7 @@ export class SqlitePersistence {
964
1023
  if (!exists) {
965
1024
  return false;
966
1025
  }
1026
+ await this.execute("DELETE FROM request_plan_state WHERE session_id = ?", [sessionId]);
967
1027
  await this.execute("DELETE FROM artifacts WHERE session_id = ?", [sessionId]);
968
1028
  await this.execute("DELETE FROM approvals WHERE session_id = ?", [sessionId]);
969
1029
  await this.execute("DELETE FROM events WHERE session_id = ?", [sessionId]);
@@ -1022,6 +1082,20 @@ export class SqlitePersistence {
1022
1082
  await this.createApproval(updated);
1023
1083
  return updated;
1024
1084
  }
1085
+ async saveRequestPlanState(sessionId, requestId, planState) {
1086
+ await this.execute(`INSERT OR REPLACE INTO request_plan_state
1087
+ (request_id, session_id, version, updated_at, plan_json)
1088
+ VALUES (?, ?, ?, ?, ?)`, [requestId, sessionId, planState.version, planState.updatedAt, JSON.stringify(planState)]);
1089
+ }
1090
+ async getRequestPlanState(sessionId, requestId) {
1091
+ const row = await this.selectOne(`SELECT plan_json
1092
+ FROM request_plan_state
1093
+ WHERE session_id = ? AND request_id = ?`, [sessionId, requestId]);
1094
+ return row?.plan_json ? parseJson(row.plan_json) : null;
1095
+ }
1096
+ async clearRequestPlanState(sessionId, requestId) {
1097
+ await this.execute("DELETE FROM request_plan_state WHERE session_id = ? AND request_id = ?", [sessionId, requestId]);
1098
+ }
1025
1099
  async createRequestArtifact(sessionId, requestId, artifact, content) {
1026
1100
  const filePath = path.join(this.requestDir(sessionId, requestId), artifact.path);
1027
1101
  await mkdir(path.dirname(filePath), { recursive: true });
@@ -1,4 +1,4 @@
1
- import type { ArtifactListing, ArtifactRecord, HarnessEvent, InternalApprovalRecord, InvocationEnvelope, MessageContent, RequestSummary, RuntimeSnapshot, RequestState, SessionRequestRecord, SessionSummary, TranscriptMessage } from "../contracts/types.js";
1
+ import type { ArtifactListing, ArtifactRecord, HarnessEvent, InternalApprovalRecord, InvocationEnvelope, MessageContent, RequestPlanState, RequestSummary, RuntimeSnapshot, RequestState, SessionRequestRecord, SessionSummary, TranscriptMessage } from "../contracts/types.js";
2
2
  export type PersistenceSessionMeta = {
3
3
  sessionId: string;
4
4
  workspaceId: string;
@@ -157,6 +157,9 @@ export interface RuntimePersistence {
157
157
  clearRequestInput(sessionId: string, requestId: string): Promise<void>;
158
158
  createApproval(record: InternalApprovalRecord): Promise<void>;
159
159
  resolveApproval(sessionId: string, requestId: string, approvalId: string, status: InternalApprovalRecord["status"]): Promise<InternalApprovalRecord>;
160
+ saveRequestPlanState(sessionId: string, requestId: string, planState: RequestPlanState): Promise<void>;
161
+ getRequestPlanState(sessionId: string, requestId: string): Promise<RequestPlanState | null>;
162
+ clearRequestPlanState(sessionId: string, requestId: string): Promise<void>;
160
163
  createRequestArtifact(sessionId: string, requestId: string, artifact: ArtifactRecord, content: unknown): Promise<ArtifactRecord>;
161
164
  listRequestArtifacts(sessionId: string, requestId: string): Promise<ArtifactListing>;
162
165
  readRequestArtifact(sessionId: string, requestId: string, artifactPath: string): Promise<unknown>;
@@ -0,0 +1,63 @@
1
+ export type ProceduralMemoryProviderConfig = {
2
+ kind: string;
3
+ options: Record<string, unknown> | null;
4
+ };
5
+ export type ProceduralMemoryBackgroundConfig = {
6
+ enabled: boolean;
7
+ scopeHints: string[];
8
+ maxMessagesPerRequest: number;
9
+ writeOnApprovalResolution: boolean;
10
+ writeOnRequestCompletion: boolean;
11
+ stateStorePath: string;
12
+ };
13
+ export type ProceduralMemoryFormationConfig = {
14
+ backgroundOnly: boolean;
15
+ background: ProceduralMemoryBackgroundConfig | null;
16
+ };
17
+ export type ProceduralMemoryRetrievalConfig = {
18
+ enabled: boolean;
19
+ defaultTopK: number;
20
+ maxPromptItems: number;
21
+ };
22
+ export type ProceduralMemoryMaintenanceScheduleConfig = {
23
+ enabled: boolean;
24
+ everyMinutes: number;
25
+ };
26
+ export type ProceduralMemoryMaintenanceIdleConfig = {
27
+ enabled: boolean;
28
+ minIdleMinutes: number;
29
+ maxRunsPerIdleWindow: number;
30
+ };
31
+ export type ProceduralMemoryMaintenanceConfig = {
32
+ enabled: boolean;
33
+ onWrite: {
34
+ dedupeNearby: boolean;
35
+ updateFrequency: boolean;
36
+ };
37
+ schedule: ProceduralMemoryMaintenanceScheduleConfig | null;
38
+ idle: ProceduralMemoryMaintenanceIdleConfig | null;
39
+ tasks: string[];
40
+ limits: {
41
+ maxRecordsPerRun: number;
42
+ maxClustersPerRun: number;
43
+ };
44
+ decay: {
45
+ enabled: boolean;
46
+ maxAgeDays?: number;
47
+ };
48
+ pruning: {
49
+ minScore?: number;
50
+ minFrequency?: number;
51
+ };
52
+ };
53
+ export type ProceduralMemoryRuntimeConfig = {
54
+ enabled: boolean;
55
+ provider: ProceduralMemoryProviderConfig | null;
56
+ store: Record<string, unknown> | null;
57
+ vectorStore: Record<string, unknown> | null;
58
+ embeddingModel: Record<string, unknown> | null;
59
+ formation: ProceduralMemoryFormationConfig | null;
60
+ retrieval: ProceduralMemoryRetrievalConfig | null;
61
+ maintenance: ProceduralMemoryMaintenanceConfig | null;
62
+ };
63
+ export declare function readProceduralMemoryRuntimeConfig(proceduralMemory: Record<string, unknown> | undefined): ProceduralMemoryRuntimeConfig;
@@ -0,0 +1,125 @@
1
+ function asObject(value) {
2
+ return typeof value === "object" && value !== null && !Array.isArray(value) ? value : undefined;
3
+ }
4
+ function asString(value) {
5
+ return typeof value === "string" && value.trim().length > 0 ? value.trim() : undefined;
6
+ }
7
+ function asStringArray(value) {
8
+ if (!Array.isArray(value)) {
9
+ return undefined;
10
+ }
11
+ const items = value
12
+ .filter((item) => typeof item === "string")
13
+ .map((item) => item.trim())
14
+ .filter((item) => item.length > 0);
15
+ return items.length > 0 ? Array.from(new Set(items)) : undefined;
16
+ }
17
+ function asBoolean(value) {
18
+ return typeof value === "boolean" ? value : undefined;
19
+ }
20
+ function asPositiveInteger(value) {
21
+ return typeof value === "number" && Number.isInteger(value) && value > 0 ? value : undefined;
22
+ }
23
+ function asNumber(value) {
24
+ return typeof value === "number" && Number.isFinite(value) ? value : undefined;
25
+ }
26
+ function readProceduralMemoryRuntimeSpec(source) {
27
+ const typed = asObject(source);
28
+ if (!typed) {
29
+ return undefined;
30
+ }
31
+ const kind = typeof typed.kind === "string" ? typed.kind : undefined;
32
+ const hasTypedEnvelope = typeof typed.apiVersion === "string" || !!asObject(typed.metadata);
33
+ if (kind === "ProceduralMemoryRuntime") {
34
+ return asObject(typed.spec);
35
+ }
36
+ if (hasTypedEnvelope && asObject(typed.spec)) {
37
+ return asObject(typed.spec);
38
+ }
39
+ return typed;
40
+ }
41
+ export function readProceduralMemoryRuntimeConfig(proceduralMemory) {
42
+ const spec = readProceduralMemoryRuntimeSpec(proceduralMemory);
43
+ const enabled = spec?.enabled === true;
44
+ const provider = asObject(spec?.provider);
45
+ const mode = asObject(spec?.mode);
46
+ const trigger = asObject(spec?.trigger);
47
+ const extraction = asObject(spec?.extraction);
48
+ const retrieval = asObject(spec?.retrieval);
49
+ const maintenance = asObject(spec?.maintenance);
50
+ const onWrite = asObject(maintenance?.onWrite);
51
+ const schedule = asObject(maintenance?.schedule);
52
+ const idle = asObject(maintenance?.idle);
53
+ const limits = asObject(maintenance?.limits);
54
+ const decay = asObject(maintenance?.decay);
55
+ const pruning = asObject(maintenance?.pruning);
56
+ return {
57
+ enabled,
58
+ provider: provider
59
+ ? {
60
+ kind: asString(provider.kind) ?? "reme",
61
+ options: Object.keys(provider).filter((key) => key !== "kind").length > 0
62
+ ? Object.fromEntries(Object.entries(provider).filter(([key]) => key !== "kind"))
63
+ : null,
64
+ }
65
+ : null,
66
+ store: asObject(spec?.store) ?? null,
67
+ vectorStore: asObject(spec?.vectorStore) ?? null,
68
+ embeddingModel: asObject(spec?.embeddingModel) ?? null,
69
+ formation: enabled
70
+ ? {
71
+ backgroundOnly: mode?.backgroundOnly !== false,
72
+ background: {
73
+ enabled: true,
74
+ scopeHints: asStringArray(extraction?.focus) ?? ["coding_patterns", "workflow_patterns", "debugging_lessons"],
75
+ maxMessagesPerRequest: asPositiveInteger(extraction?.maxMessagesPerRequest) ?? 60,
76
+ writeOnApprovalResolution: trigger?.onApprovalResolved === true,
77
+ writeOnRequestCompletion: trigger?.onRequestCompleted !== false,
78
+ stateStorePath: asString(asObject(spec?.state)?.cursorPath) ?? "knowledge/procedural-memory-state.json",
79
+ },
80
+ }
81
+ : null,
82
+ retrieval: enabled
83
+ ? {
84
+ enabled: retrieval?.enabled !== false,
85
+ defaultTopK: asPositiveInteger(retrieval?.defaultTopK) ?? 5,
86
+ maxPromptItems: asPositiveInteger(retrieval?.maxPromptItems) ?? 4,
87
+ }
88
+ : null,
89
+ maintenance: enabled
90
+ ? {
91
+ enabled: maintenance?.enabled !== false,
92
+ onWrite: {
93
+ dedupeNearby: onWrite?.dedupeNearby !== false,
94
+ updateFrequency: onWrite?.updateFrequency !== false,
95
+ },
96
+ schedule: schedule
97
+ ? {
98
+ enabled: schedule.enabled !== false,
99
+ everyMinutes: asPositiveInteger(schedule.everyMinutes) ?? 60,
100
+ }
101
+ : null,
102
+ idle: idle
103
+ ? {
104
+ enabled: idle.enabled !== false,
105
+ minIdleMinutes: asPositiveInteger(idle.minIdleMinutes) ?? 20,
106
+ maxRunsPerIdleWindow: asPositiveInteger(idle.maxRunsPerIdleWindow) ?? 1,
107
+ }
108
+ : null,
109
+ tasks: asStringArray(maintenance?.tasks) ?? ["dedupe", "merge_similar", "decay_stale", "prune_low_value"],
110
+ limits: {
111
+ maxRecordsPerRun: asPositiveInteger(limits?.maxRecordsPerRun) ?? 200,
112
+ maxClustersPerRun: asPositiveInteger(limits?.maxClustersPerRun) ?? 50,
113
+ },
114
+ decay: {
115
+ enabled: decay?.enabled !== false,
116
+ ...(asPositiveInteger(decay?.maxAgeDays) ? { maxAgeDays: asPositiveInteger(decay?.maxAgeDays) } : {}),
117
+ },
118
+ pruning: {
119
+ ...(asNumber(pruning?.minScore) !== undefined ? { minScore: asNumber(pruning?.minScore) } : {}),
120
+ ...(asPositiveInteger(pruning?.minFrequency) ? { minFrequency: asPositiveInteger(pruning?.minFrequency) } : {}),
121
+ },
122
+ }
123
+ : null,
124
+ };
125
+ }
@@ -0,0 +1,2 @@
1
+ export { readProceduralMemoryRuntimeConfig } from "./config.js";
2
+ export type { ProceduralMemoryBackgroundConfig, ProceduralMemoryFormationConfig, ProceduralMemoryMaintenanceConfig, ProceduralMemoryMaintenanceIdleConfig, ProceduralMemoryMaintenanceScheduleConfig, ProceduralMemoryProviderConfig, ProceduralMemoryRetrievalConfig, ProceduralMemoryRuntimeConfig, } from "./config.js";
@@ -0,0 +1 @@
1
+ export { readProceduralMemoryRuntimeConfig } from "./config.js";
@@ -42,6 +42,9 @@ export type AgUiEvent = (AgUiBaseEvent & {
42
42
  }) | (AgUiBaseEvent & {
43
43
  type: "THINKING_TEXT_MESSAGE_END";
44
44
  messageId: string;
45
+ }) | (AgUiBaseEvent & {
46
+ type: "STATUS_UPDATE";
47
+ message: string;
45
48
  }) | (AgUiBaseEvent & {
46
49
  type: "TEXT_MESSAGE_START";
47
50
  messageId: string;
@@ -213,6 +213,16 @@ export async function serveAgUiOverHttp(runtime, options = {}) {
213
213
  });
214
214
  }
215
215
  },
216
+ dataListener: async (event) => {
217
+ if (event.type !== "progress.commentary") {
218
+ return;
219
+ }
220
+ await writeSseEvent(response, {
221
+ type: "STATUS_UPDATE",
222
+ timestamp: createTimestamp(),
223
+ message: event.text,
224
+ });
225
+ },
216
226
  onUpstreamEvent: async (event) => {
217
227
  const eventName = readUpstreamEventName(event);
218
228
  const toolName = readUpstreamToolName(event);
@@ -0,0 +1,63 @@
1
+ import type { HarnessEvent, RequestDataEvent, RequestEventSnapshot, RequestExecutionStep, RequestPlanState, RequestResult, RuntimeSurfaceItem, UpstreamRuntimeEvent } from "./contracts/types.js";
2
+ type StreamEventItem = {
3
+ type: "event";
4
+ event: HarnessEvent;
5
+ };
6
+ type StreamContentItem = {
7
+ type: "content";
8
+ sessionId: string;
9
+ requestId: string;
10
+ agentId: string;
11
+ content: string;
12
+ };
13
+ type StreamContentBlocksItem = {
14
+ type: "content-blocks";
15
+ sessionId: string;
16
+ requestId: string;
17
+ agentId: string;
18
+ contentBlocks: unknown[];
19
+ };
20
+ type StreamToolResultItem = {
21
+ type: "tool-result";
22
+ sessionId: string;
23
+ requestId: string;
24
+ agentId: string;
25
+ toolName: string;
26
+ output: unknown;
27
+ isError?: boolean;
28
+ };
29
+ type StreamPlanStateItem = {
30
+ type: "plan-state";
31
+ sessionId: string;
32
+ requestId: string;
33
+ agentId: string;
34
+ planState: RequestPlanState;
35
+ };
36
+ type StreamUpstreamEventItem = {
37
+ type: "upstream-event";
38
+ sessionId: string;
39
+ requestId: string;
40
+ surfaceItem?: RuntimeSurfaceItem;
41
+ event: UpstreamRuntimeEvent;
42
+ };
43
+ type StreamProfileStepItem = {
44
+ type: "profile-step";
45
+ sessionId: string;
46
+ requestId: string;
47
+ step: RequestExecutionStep;
48
+ };
49
+ type StreamResultItem = {
50
+ type: "result";
51
+ result: RequestResult;
52
+ };
53
+ export type RequestSnapshotStreamItem = StreamEventItem | {
54
+ type: "commentary";
55
+ sessionId: string;
56
+ requestId: string;
57
+ agentId: string;
58
+ content: string;
59
+ } | StreamContentItem | StreamContentBlocksItem | StreamToolResultItem | StreamPlanStateItem | StreamUpstreamEventItem | StreamProfileStepItem | StreamResultItem;
60
+ export declare function createInitialRequestEventSnapshot(): RequestEventSnapshot;
61
+ export declare function applyRequestStreamItemToSnapshot(snapshot: RequestEventSnapshot, item: RequestSnapshotStreamItem): RequestEventSnapshot;
62
+ export declare function toRequestDataEvent(item: RequestSnapshotStreamItem): RequestDataEvent | null;
63
+ export {};