@qvac/core 0.6.3 → 1.0.0-rc.0

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 (65) hide show
  1. package/CHANGELOG.md +10 -1
  2. package/README.md +4 -12
  3. package/dist-lib/lib/api/host-run-log.d.ts +43 -0
  4. package/dist-lib/lib/api/host-run-log.js +97 -0
  5. package/dist-lib/lib/api/index.d.ts +3 -0
  6. package/dist-lib/lib/api/index.js +9 -0
  7. package/dist-lib/lib/api/instrument.js +33 -2
  8. package/dist-lib/lib/assistant/harness.d.ts +4 -1
  9. package/dist-lib/lib/assistant/history.d.ts +7 -2
  10. package/dist-lib/lib/assistant/history.js +34 -3
  11. package/dist-lib/lib/assistant/host-run-log.d.ts +3 -0
  12. package/dist-lib/lib/assistant/host-run-log.js +48 -0
  13. package/dist-lib/lib/assistant.d.ts +2 -0
  14. package/dist-lib/lib/assistant.js +817 -412
  15. package/dist-lib/lib/core/async-iterable.js +1 -1
  16. package/dist-lib/lib/core/chat-activity.d.ts +1 -1
  17. package/dist-lib/lib/core/chat-activity.js +16 -1
  18. package/dist-lib/lib/core/chat-search.js +11 -4
  19. package/dist-lib/lib/core/chunk.d.ts +3 -3
  20. package/dist-lib/lib/core/chunk.js +6 -2
  21. package/dist-lib/lib/core/files/rag/limits.d.ts +0 -1
  22. package/dist-lib/lib/core/files/rag/limits.js +0 -1
  23. package/dist-lib/lib/core/harness-loan.js +4 -0
  24. package/dist-lib/lib/core/host-run-log-store.d.ts +114 -0
  25. package/dist-lib/lib/core/host-run-log-store.js +976 -0
  26. package/dist-lib/lib/core/prompt-history.js +3 -1
  27. package/dist-lib/lib/core/transcript-visibility.d.ts +19 -0
  28. package/dist-lib/lib/core/transcript-visibility.js +47 -0
  29. package/dist-lib/lib/core.d.ts +2 -0
  30. package/dist-lib/lib/core.js +36 -2
  31. package/dist-lib/lib/custom-model-pusher.js +9 -5
  32. package/dist-lib/lib/mesh-scoped-engine.js +5 -0
  33. package/dist-lib/lib/run-transcript.d.ts +10 -3
  34. package/dist-lib/lib/run-transcript.js +23 -5
  35. package/dist-lib/lib/task.js +6 -1
  36. package/dist-lib/schema/content.d.ts +1 -0
  37. package/dist-lib/schema/content.js +15 -3
  38. package/dist-lib/schema/engine.js +90 -3
  39. package/dist-lib/schema/indexes.js +10 -1
  40. package/dist-lib/schema/qvac.js +10 -2
  41. package/dist-lib/spec/bind.js +15 -0
  42. package/dist-lib/spec/calls.js +5 -0
  43. package/dist-lib/spec/capabilities.d.ts +10 -0
  44. package/dist-lib/spec/hrpc/hrpc.json +164 -99
  45. package/dist-lib/spec/hrpc/index.js +260 -200
  46. package/dist-lib/spec/hrpc/messages.js +1202 -898
  47. package/dist-lib/spec/hyperschema/index.js +1202 -898
  48. package/dist-lib/spec/hyperschema/schema.json +265 -0
  49. package/dist-lib/spec/hyperschema/types.d.ts +65 -3
  50. package/dist-lib/spec/mesh/hyperdb/messages.js +385 -241
  51. package/dist-lib/spec/mesh/hyperdispatch/messages.js +138 -12
  52. package/dist-lib/spec/mesh/hyperschema/index.js +138 -12
  53. package/dist-lib/spec/mesh/hyperschema/schema.json +79 -1
  54. package/dist-lib/spec/mesh/hyperschema/types.d.ts +19 -3
  55. package/package.json +3 -7
  56. package/dist-lib/lib/collabora/convert.d.ts +0 -9
  57. package/dist-lib/lib/collabora/convert.js +0 -65
  58. package/dist-lib/lib/collabora/entry.d.ts +0 -1
  59. package/dist-lib/lib/collabora/entry.js +0 -42
  60. package/dist-lib/lib/collabora/protocol.d.ts +0 -15
  61. package/dist-lib/lib/collabora/protocol.js +0 -31
  62. package/dist-lib/lib/collabora/worker.d.ts +0 -5
  63. package/dist-lib/lib/collabora/worker.js +0 -177
  64. package/dist-lib/lib/core/files/rag/extract/office-collabora.d.ts +0 -2
  65. package/dist-lib/lib/core/files/rag/extract/office-collabora.js +0 -8
package/CHANGELOG.md CHANGED
@@ -13,6 +13,14 @@ release.
13
13
 
14
14
  ## [Unreleased]
15
15
 
16
+ ## [0.6.4] - 2026-09-30
17
+
18
+ ### Removed
19
+
20
+ - The collabora office adapter and its `@qvac/core/rag/extract/office` export.
21
+ Office extraction is `extractOfficeText` from `@qvac/harness/office`, passed
22
+ through the `extractors.office` option. (#285)
23
+
16
24
  ## [0.6.3] - 2026-09-30
17
25
 
18
26
  ### Changed
@@ -1151,7 +1159,8 @@ Published under the `release-0.1` dist-tag.
1151
1159
  await assistant.ready()
1152
1160
  ```
1153
1161
 
1154
- [Unreleased]: https://github.com/tetherto/qvac-core/compare/v0.6.3...HEAD
1162
+ [Unreleased]: https://github.com/tetherto/qvac-core/compare/v0.6.4...HEAD
1163
+ [0.6.4]: https://github.com/tetherto/qvac-core/compare/v0.6.3...v0.6.4
1155
1164
  [0.6.3]: https://github.com/tetherto/qvac-core/compare/v0.6.2...v0.6.3
1156
1165
  [0.6.2]: https://github.com/tetherto/qvac-core/compare/v0.6.1...v0.6.2
1157
1166
  [0.6.1]: https://github.com/tetherto/qvac-core/compare/v0.6.0...v0.6.1
package/README.md CHANGED
@@ -687,18 +687,10 @@ feature checklist vs core v1.
687
687
 
688
688
  ### Office documents
689
689
 
690
- Word-processor documents (`.docx`, `.doc`, `.docm`, `.dot`, `.dotx`, `.odt`,
691
- `.fodt`, `.ott`) decode through an engine the host supplies rather than a
692
- declared dependency: the package pulls all thirteen platform prebuilds at
693
- ~350MB each, so declaring it would cost every install 4.3GB. In this repo,
694
- fetch the one for this machine before exercising `/knowledge add report.docx`:
695
-
696
- ```sh
697
- bun run engine:collabora
698
- ```
699
-
700
- **There is no equivalent for an installed `duck`.** Nothing fetches the engine
701
- for you, so those formats fail to index outside this repo, even though
690
+ Core ships no office decoder. Word-processor documents (`.docx`, `.doc`,
691
+ `.odt`, …) index only when the host passes one through the `extractors.office`
692
+ option — the app injects `extractOfficeText` from `@qvac/harness/office`.
693
+ `duck` injects none, so those formats fail to index there even though
702
694
  `/knowledge add` accepts them. Everything else it accepts — `.pdf`, `.txt`,
703
695
  `.md`, `.rtf`, `.html`, `.csv`, `.json` and the rest — works from any install.
704
696
 
@@ -0,0 +1,43 @@
1
+ import { type EngineBoot, type EngineStep } from '@qvac/harness/run-log';
2
+ import type { CapabilityHandlers } from '../../spec/capabilities.d.ts';
3
+ import { type MeshPool } from './current-mesh.ts';
4
+ import type { HostRunLogExport } from '../core/host-run-log-store.ts';
5
+ export interface HostRunLogOperations {
6
+ begin(input: {
7
+ meshId: string;
8
+ runId: string;
9
+ }): Promise<{
10
+ generation: string;
11
+ boot?: EngineBoot;
12
+ digestKey: Uint8Array;
13
+ }>;
14
+ append(input: {
15
+ meshId: string;
16
+ runId: string;
17
+ generation: string;
18
+ step: EngineStep;
19
+ }): Promise<void>;
20
+ release(input: {
21
+ meshId: string;
22
+ runId: string;
23
+ generation: string;
24
+ }): Promise<void>;
25
+ exportRun(input: {
26
+ meshId: string;
27
+ runId: string;
28
+ }): Promise<HostRunLogExport>;
29
+ }
30
+ export interface HostRunLogTopicOperations {
31
+ advertise(descriptor: HostRunLogExport): Promise<void>;
32
+ unadvertise(input: {
33
+ meshId: string;
34
+ runId: string;
35
+ }): Promise<void>;
36
+ }
37
+ export interface HostRunLogApiOptions {
38
+ pool: MeshPool;
39
+ deviceId: Buffer | null;
40
+ hostRunLogs: HostRunLogOperations;
41
+ topics: HostRunLogTopicOperations;
42
+ }
43
+ export declare function createHostRunLogApi({ pool, deviceId, hostRunLogs, topics }: HostRunLogApiOptions): Pick<CapabilityHandlers, 'hostRunLogBegin' | 'hostRunLogAppend' | 'hostRunLogRelease' | 'hostRunLogShare' | 'hostRunLogUnshare'>;
@@ -0,0 +1,97 @@
1
+ import b4a from 'b4a';
2
+ import { validateEngineBoot } from '@qvac/harness/run-log';
3
+ import { isRecord } from '../guards.js';
4
+ import { listChunks, listRunRequests } from '../core/chunk.js';
5
+ import { requireMesh } from './current-mesh.js';
6
+ export function createHostRunLogApi({ pool, deviceId, hostRunLogs, topics }) {
7
+ return {
8
+ hostRunLogBegin: async (input) => {
9
+ const mesh = await requireMesh(pool, input.meshId);
10
+ await requireOwnedRunRequest(mesh, { deviceId, runId: input.runId, resumableOnly: true });
11
+ const lease = await hostRunLogs.begin(input);
12
+ try {
13
+ if (typeof lease.generation !== 'string' || !lease.generation) {
14
+ throw new Error('Host run-log store returned an invalid generation lease');
15
+ }
16
+ if (!(lease.digestKey instanceof Uint8Array) || lease.digestKey.byteLength !== 32) {
17
+ throw new Error('Host run-log store returned an invalid request digest key');
18
+ }
19
+ if (lease.boot !== undefined) {
20
+ validateEngineBoot(lease.boot);
21
+ if (!lease.boot.metadata || lease.boot.metadata.runId !== input.runId) {
22
+ throw new Error('Host run-log store returned a boot for another run');
23
+ }
24
+ }
25
+ return {
26
+ generation: lease.generation,
27
+ digestKey: b4a.from(lease.digestKey),
28
+ boot: lease.boot
29
+ };
30
+ }
31
+ catch (error) {
32
+ try {
33
+ await hostRunLogs.release({ ...input, generation: lease.generation });
34
+ }
35
+ catch (releaseError) {
36
+ throw new AggregateError([error, releaseError], 'Host run-log lease was invalid and could not be released');
37
+ }
38
+ throw error;
39
+ }
40
+ },
41
+ hostRunLogAppend: async (input) => {
42
+ await requireMesh(pool, input.meshId);
43
+ if (!input.generation) {
44
+ throw new TypeError('Host run-log generation is required');
45
+ }
46
+ if (!isEngineStep(input.step)) {
47
+ throw new TypeError('Host run-log step is invalid');
48
+ }
49
+ await hostRunLogs.append({ ...input, step: input.step });
50
+ return { ok: true };
51
+ },
52
+ hostRunLogRelease: async (input) => {
53
+ await hostRunLogs.release(input);
54
+ return { ok: true };
55
+ },
56
+ hostRunLogShare: async (input) => {
57
+ const mesh = await requireMesh(pool, input.meshId);
58
+ await requireOwnedRunRequest(mesh, { deviceId, runId: input.runId });
59
+ const descriptor = await hostRunLogs.exportRun(input);
60
+ await topics.advertise(descriptor);
61
+ return {
62
+ meshId: descriptor.meshId,
63
+ runId: descriptor.runId,
64
+ publicKey: b4a.toString(b4a.from(descriptor.publicKey), 'base64url'),
65
+ discoveryKey: b4a.toString(b4a.from(descriptor.discoveryKey), 'base64url'),
66
+ encryptionKey: b4a.toString(b4a.from(descriptor.encryptionKey), 'base64url'),
67
+ physicalLength: descriptor.physicalLength,
68
+ logicalLength: descriptor.logicalLength,
69
+ nextSeq: descriptor.nextSeq
70
+ };
71
+ },
72
+ hostRunLogUnshare: async (input) => {
73
+ await topics.unadvertise(input);
74
+ return { ok: true };
75
+ }
76
+ };
77
+ }
78
+ function isEngineStep(value) {
79
+ return isRecord(value);
80
+ }
81
+ async function requireOwnedRunRequest(mesh, { deviceId, runId, resumableOnly }) {
82
+ if (!deviceId) {
83
+ throw new Error('This device has no run-log execution identity');
84
+ }
85
+ const requests = await listRunRequests(mesh, deviceId);
86
+ const request = requests.find((candidate) => candidate.runId === runId);
87
+ if (!request) {
88
+ throw new Error(`Run ${runId} is not assigned to this device in the named mesh`);
89
+ }
90
+ if (resumableOnly) {
91
+ const statuses = await listChunks(mesh, { chatId: request.chatId, type: 'run-status' });
92
+ if (statuses.some((chunk) => chunk.runId === runId &&
93
+ ['completed', 'failed', 'canceled'].includes(chunk.runStatus?.state ?? ''))) {
94
+ throw new Error(`Run ${runId} has already settled and cannot be resumed`);
95
+ }
96
+ }
97
+ }
@@ -5,6 +5,7 @@ import type { Mesh } from '../core/mesh.ts';
5
5
  import type { MeshPool } from './current-mesh.ts';
6
6
  import { type DiagnosticsSource } from './diagnostics.ts';
7
7
  import { type InferenceCallReader } from './inference-calls.ts';
8
+ import { type HostRunLogOperations, type HostRunLogTopicOperations } from './host-run-log.ts';
8
9
  import { type LogSource } from './logs.ts';
9
10
  import { type MeshStatusSource } from './mesh.ts';
10
11
  import { type NetworkSource } from './network.ts';
@@ -39,6 +40,8 @@ interface ApiDeps {
39
40
  previewModelSource?: CustomModelPreviewSource | null;
40
41
  speak?: ((request: AssistantSpeakRequest) => Promise<AssistantSpeakResponse>) | null;
41
42
  speakStream?: ((text: AsyncIterable<string>) => AsyncIterable<AssistantSpeakResponse>) | null;
43
+ hostRunLogs?: HostRunLogOperations | null;
44
+ hostRunLogTopics?: HostRunLogTopicOperations | null;
42
45
  deviceHost?: {
43
46
  removeWriter: (writerKey: Buffer, deviceId: Buffer, mesh: Mesh) => Promise<void>;
44
47
  renameLocal: (name: string) => Promise<void>;
@@ -13,6 +13,7 @@ import { createDevicesApi } from './devices.js';
13
13
  import { createDiagnosticsApi } from './diagnostics.js';
14
14
  import { createInferenceCallsApi } from './inference-calls.js';
15
15
  import { createExecutionApi } from './execution.js';
16
+ import { createHostRunLogApi } from './host-run-log.js';
16
17
  import { createKnowledgeApi } from './knowledge.js';
17
18
  import { createFilesApi } from './files.js';
18
19
  import { createLocalFilesApi } from './local-files.js';
@@ -78,6 +79,14 @@ export function createApi(deps = {}) {
78
79
  })
79
80
  : null),
80
81
  ...(mesh && deps.deviceId ? createExecutionApi(mesh, deps.deviceId) : null),
82
+ ...(mesh && deps.hostRunLogs && deps.hostRunLogTopics
83
+ ? createHostRunLogApi({
84
+ pool: mesh,
85
+ deviceId: deps.deviceId ?? null,
86
+ hostRunLogs: deps.hostRunLogs,
87
+ topics: deps.hostRunLogTopics
88
+ })
89
+ : null),
81
90
  ...(mesh ? createSyncApi(mesh) : null),
82
91
  ...(mesh ? createToolConfigsApi(mesh) : null),
83
92
  ...(mesh ? createToolActivityApi(mesh, deps.deviceId ?? null) : null),
@@ -18,7 +18,7 @@ function isHandler(value) {
18
18
  function wrap(name, handler) {
19
19
  return function (...args) {
20
20
  const started = Date.now();
21
- const request = summarize(args[0]);
21
+ const request = summarize(name, args[0]);
22
22
  let result;
23
23
  try {
24
24
  result = handler.apply(this, args);
@@ -69,13 +69,44 @@ function count(value) {
69
69
  }
70
70
  return null;
71
71
  }
72
- function summarize(request) {
72
+ function summarize(name, request) {
73
73
  if (!isRecord(request))
74
74
  return '';
75
+ if (name.startsWith('hostRunLog')) {
76
+ return summarizeHostRunLogRequest(name, request);
77
+ }
75
78
  return Object.entries(request)
76
79
  .map(([key, value]) => `${key}=${scalar(value)}`)
77
80
  .join(' ');
78
81
  }
82
+ function summarizeHostRunLogRequest(name, request) {
83
+ const fields = [];
84
+ for (const key of ['meshId', 'runId']) {
85
+ if (request[key] !== undefined) {
86
+ fields.push(`${key}=${scalar(request[key])}`);
87
+ }
88
+ }
89
+ if (name === 'hostRunLogAppend') {
90
+ fields.push(...summarizeStep(request.step));
91
+ }
92
+ return fields.join(' ');
93
+ }
94
+ function summarizeStep(step) {
95
+ if (!isRecord(step)) {
96
+ return [];
97
+ }
98
+ const fields = [];
99
+ for (const key of ['seq', 'expectedLength']) {
100
+ const value = step[key];
101
+ if (typeof value === 'number' && Number.isFinite(value)) {
102
+ fields.push(`${key}=${value}`);
103
+ }
104
+ }
105
+ if (Array.isArray(step.records)) {
106
+ fields.push(`recordCount=${step.records.length}`);
107
+ }
108
+ return fields;
109
+ }
79
110
  function scalar(value) {
80
111
  if (value === null || value === undefined) {
81
112
  return String(value);
@@ -1,5 +1,5 @@
1
1
  import type { AbortSignal } from 'bare-abort-controller';
2
- import type { ApprovalCall, CompletionEvent, DeleteModelSummary, MemoryBudget, ModelSourcePreview, PreviewModelSourceContext } from '@qvac/harness';
2
+ import type { ApprovalCall, CompletionEvent, DeleteModelSummary, HostRunLog, MemoryBudget, ModelSourcePreview, PreviewModelSourceContext } from '@qvac/harness';
3
3
  import type { ManagedSkill, SkillFileContent } from '@qvac/harness/lib/tools/skills/overlay-crud.ts';
4
4
  import type { SkillCatalogOptions, SkillManagementHooks } from '../core.ts';
5
5
  import type { DriveOpFn, GrantedDrive } from '@qvac/harness/lib/tools/fs/remote.ts';
@@ -76,6 +76,9 @@ export interface ImageProgress {
76
76
  }
77
77
  export interface Harness {
78
78
  completion(context: {
79
+ runId?: string;
80
+ runLog?: HostRunLog;
81
+ resume?: boolean;
79
82
  model: string;
80
83
  agent: AssistantAgent;
81
84
  messages: ChatMessage[];
@@ -10,8 +10,13 @@ export interface StaleToolRuns {
10
10
  questionChunkIds: Set<string>;
11
11
  }
12
12
  export declare function listHistoryChunks(engine: Pick<ScopedCapabilities, 'listChunks'>, chatId: string): Promise<AssistantChunk[]>;
13
- export declare function latestAttemptStarts(chunks: ReadonlyArray<AssistantChunk>): Map<string, number>;
14
- export declare function beforeLatestAttempt(chunk: AssistantChunk, starts: Map<string, number>): boolean;
13
+ export interface LatestAttemptStart {
14
+ seq: number;
15
+ resumed: boolean;
16
+ cutoff?: number;
17
+ }
18
+ export declare function latestAttemptStarts(chunks: ReadonlyArray<AssistantChunk>): Map<string, LatestAttemptStart>;
19
+ export declare function beforeLatestAttempt(chunk: AssistantChunk, starts: ReadonlyMap<string, LatestAttemptStart | number>): boolean;
15
20
  export interface CompactOptions {
16
21
  readonly signal?: AbortSignal;
17
22
  readonly onFold?: () => Promise<void> | void;
@@ -4,6 +4,7 @@ import { isAudioAttachment } from '../core/audio-attachment.js';
4
4
  import { isDocumentAttachment, isPdfAttachment } from '../core/document-attachment.js';
5
5
  import { groupAttachmentsByMessage } from '../core/files/index.js';
6
6
  import { IMAGE_MIMES } from '../core/image/normalize.js';
7
+ import { visibleTranscriptTextChunks } from '../core/transcript-visibility.js';
7
8
  import { compactionTurn, foldCompactedChunks } from '../compaction.js';
8
9
  import b4a from 'b4a';
9
10
  import { isRecord } from '../guards.js';
@@ -27,19 +28,27 @@ export function latestAttemptStarts(chunks) {
27
28
  for (const chunk of chunks) {
28
29
  if (chunk.type !== 'run-status' || !chunk.runId)
29
30
  continue;
30
- if (TERMINAL_STATES.has(chunk.runStatus?.state ?? ''))
31
+ if (chunk.runStatus?.state !== 'executing') {
31
32
  continue;
33
+ }
32
34
  if (chunk.runStatus?.progress?.phase === 'compacting') {
33
35
  continue;
34
36
  }
35
- starts.set(chunk.runId, chunk.seq);
37
+ const resumed = chunk.resumed === true;
38
+ const previous = starts.get(chunk.runId);
39
+ const cutoff = resumed ? previous?.cutoff : chunk.seq;
40
+ starts.set(chunk.runId, { seq: chunk.seq, resumed, cutoff });
36
41
  }
37
42
  return starts;
38
43
  }
39
44
  export function beforeLatestAttempt(chunk, starts) {
40
45
  if (!chunk.runId)
41
46
  return false;
42
- const start = starts.get(chunk.runId);
47
+ const attempt = starts.get(chunk.runId);
48
+ if (attempt === undefined) {
49
+ return false;
50
+ }
51
+ const start = typeof attempt === 'number' ? attempt : attempt.cutoff;
43
52
  return start !== undefined && chunk.seq < start;
44
53
  }
45
54
  export function couldNameSenders(chunks) {
@@ -83,6 +92,7 @@ export function historyFromChunks(chunks, stale = {}, senderNames = new Map()) {
83
92
  const staleQuestionChunkIds = stale.questionChunkIds ?? new Set();
84
93
  const folded = foldCompactedChunks(chunks);
85
94
  const source = folded.chunks;
95
+ const visibleTextIds = new Set(visibleTranscriptTextChunks(source).map((chunk) => chunk.id));
86
96
  const attachments = [];
87
97
  const userMessages = [];
88
98
  for (const chunk of source) {
@@ -96,6 +106,7 @@ export function historyFromChunks(chunks, stale = {}, senderNames = new Map()) {
96
106
  const byMessage = groupAttachmentsByMessage(attachments, userMessages);
97
107
  const history = [];
98
108
  const replayedSkills = new Set();
109
+ const replayedToolResults = new Set();
99
110
  if (folded.summary) {
100
111
  history.push({ role: 'user', content: compactionTurn(folded.summary) });
101
112
  }
@@ -155,6 +166,9 @@ export function historyFromChunks(chunks, stale = {}, senderNames = new Map()) {
155
166
  if (beforeLatestAttempt(chunk, attemptStarts)) {
156
167
  continue;
157
168
  }
169
+ if (isRepeatedToolResult(chunk, replayedToolResults)) {
170
+ continue;
171
+ }
158
172
  const { result } = chunk.toolResult;
159
173
  const loaded = isRecord(result) ? result.name : undefined;
160
174
  if (typeof loaded === 'string' && !replayedSkills.has(loaded)) {
@@ -171,6 +185,9 @@ export function historyFromChunks(chunks, stale = {}, senderNames = new Map()) {
171
185
  if (beforeLatestAttempt(chunk, attemptStarts)) {
172
186
  continue;
173
187
  }
188
+ if (isRepeatedToolResult(chunk, replayedToolResults)) {
189
+ continue;
190
+ }
174
191
  const produced = attachmentTurn(chunk.toolResult.name, chunk.toolResult.result);
175
192
  if (produced) {
176
193
  history.push({ role: 'tool', content: produced });
@@ -186,10 +203,24 @@ export function historyFromChunks(chunks, stale = {}, senderNames = new Map()) {
186
203
  if (beforeLatestAttempt(chunk, attemptStarts)) {
187
204
  continue;
188
205
  }
206
+ if (!visibleTextIds.has(chunk.id)) {
207
+ continue;
208
+ }
189
209
  anchor(chunk.runId).content += chunk.content.text;
190
210
  }
191
211
  return history.filter((turn) => turn.role === 'user' || turn.content.length > 0);
192
212
  }
213
+ function isRepeatedToolResult(chunk, seen) {
214
+ if (!chunk.runId || typeof chunk.round !== 'number' || !chunk.callId) {
215
+ return false;
216
+ }
217
+ const key = JSON.stringify([chunk.runId, chunk.round, chunk.callId]);
218
+ if (seen.has(key)) {
219
+ return true;
220
+ }
221
+ seen.add(key);
222
+ return false;
223
+ }
193
224
  export function inputAvailableToRun(chunk, requestSeq) {
194
225
  const userInput = Boolean(chunk.userMessage || (chunk.attachment && !chunk.runId));
195
226
  return !userInput || chunk.seq < requestSeq;
@@ -0,0 +1,3 @@
1
+ import type { HostRunLog } from '@qvac/harness';
2
+ import type { ScopedCapabilities } from '../mesh-scoped-engine.ts';
3
+ export declare function createHostRunLogAdapter(engine: ScopedCapabilities): HostRunLog;
@@ -0,0 +1,48 @@
1
+ import { isRecord } from '../guards.js';
2
+ function isEngineBoot(value) {
3
+ return isRecord(value);
4
+ }
5
+ export function createHostRunLogAdapter(engine) {
6
+ let leasedRunId;
7
+ let lease;
8
+ let release = null;
9
+ function assertLease(runId, generation) {
10
+ if (!lease || leasedRunId !== runId || lease.generation !== generation) {
11
+ throw new Error('Host run-log adapter received a stale lease operation');
12
+ }
13
+ return lease;
14
+ }
15
+ return {
16
+ async begin(runId) {
17
+ if (lease) {
18
+ if (leasedRunId !== runId || release) {
19
+ throw new Error('Host run-log adapter cannot begin another run');
20
+ }
21
+ return lease;
22
+ }
23
+ const response = await engine.hostRunLogBegin({ runId });
24
+ const normalized = {
25
+ generation: response.generation,
26
+ digestKey: response.digestKey,
27
+ boot: isEngineBoot(response.boot) ? response.boot : undefined
28
+ };
29
+ leasedRunId = runId;
30
+ lease = normalized;
31
+ return normalized;
32
+ },
33
+ async append(runId, generation, step) {
34
+ assertLease(runId, generation);
35
+ await engine.hostRunLogAppend({ runId, generation, step });
36
+ },
37
+ async release(runId, generation) {
38
+ assertLease(runId, generation);
39
+ if (!release) {
40
+ release = engine.hostRunLogRelease({ runId, generation }).then(() => undefined, (error) => {
41
+ release = null;
42
+ throw error;
43
+ });
44
+ }
45
+ await release;
46
+ }
47
+ };
48
+ }
@@ -170,7 +170,9 @@ export declare class QvacAssistant extends ReadyResource {
170
170
  private _injectKnowledge;
171
171
  private _writeUnreadNotice;
172
172
  private _isHandled;
173
+ private _recordRunBoundaryStatus;
173
174
  private _execute;
175
+ private _executePrimary;
174
176
  private _invokeCapability;
175
177
  private _loadToolConfigs;
176
178
  private _loadFsGrants;