@qvac/harness 1.0.0-rc.4 → 1.0.0-rc.6

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 (73) hide show
  1. package/CHANGELOG.md +115 -18
  2. package/dist-lib/index.d.ts +4 -1
  3. package/dist-lib/index.js +42 -1
  4. package/dist-lib/lib/capabilities/completion-engine/actors/inspecting.js +13 -3
  5. package/dist-lib/lib/capabilities/completion-engine/actors/loading-skill.js +8 -1
  6. package/dist-lib/lib/capabilities/completion-engine/actors/preparing.js +62 -36
  7. package/dist-lib/lib/capabilities/completion-engine/actors/resolving.js +11 -4
  8. package/dist-lib/lib/capabilities/completion-engine/actors/retrieving.js +20 -11
  9. package/dist-lib/lib/capabilities/completion-engine/actors/skill-step.js +10 -1
  10. package/dist-lib/lib/capabilities/completion-engine/actors/stream.js +7 -3
  11. package/dist-lib/lib/capabilities/completion-engine/actors/streaming.js +8 -17
  12. package/dist-lib/lib/capabilities/completion-engine/actors/wrap-up.d.ts +1 -1
  13. package/dist-lib/lib/capabilities/completion-engine/actors/wrap-up.js +12 -12
  14. package/dist-lib/lib/capabilities/completion-engine/driver.js +1 -2
  15. package/dist-lib/lib/capabilities/completion-engine/engine.d.ts +4 -1
  16. package/dist-lib/lib/capabilities/completion-engine/engine.js +14 -1
  17. package/dist-lib/lib/capabilities/completion-engine/index.d.ts +3 -1
  18. package/dist-lib/lib/capabilities/completion-engine/index.js +2 -0
  19. package/dist-lib/lib/capabilities/completion-engine/loop.d.ts +1 -0
  20. package/dist-lib/lib/capabilities/completion-engine/model-round.d.ts +14 -1
  21. package/dist-lib/lib/capabilities/completion-engine/model-round.js +52 -0
  22. package/dist-lib/lib/capabilities/completion-engine/round.d.ts +3 -3
  23. package/dist-lib/lib/capabilities/completion-engine/turns.d.ts +3 -5
  24. package/dist-lib/lib/capabilities/completion-engine/turns.js +29 -25
  25. package/dist-lib/lib/capabilities/sdk-tool.d.ts +9 -1
  26. package/dist-lib/lib/capabilities/sdk-tool.js +21 -2
  27. package/dist-lib/lib/capabilities/tool-plan.d.ts +4 -0
  28. package/dist-lib/lib/capabilities/tool-plan.js +15 -0
  29. package/dist-lib/lib/connect.js +16 -2
  30. package/dist-lib/lib/contract/completion.d.ts +8 -2
  31. package/dist-lib/lib/contract/drive.d.ts +4 -0
  32. package/dist-lib/lib/contract/drive.js +1 -0
  33. package/dist-lib/lib/contract/index.d.ts +2 -0
  34. package/dist-lib/lib/contract/managed-skills.d.ts +1 -0
  35. package/dist-lib/lib/contract/managed-skills.js +1 -0
  36. package/dist-lib/lib/contract/run.d.ts +8 -0
  37. package/dist-lib/lib/contract-types.d.ts +4 -1
  38. package/dist-lib/lib/errors.d.ts +4 -0
  39. package/dist-lib/lib/errors.js +6 -0
  40. package/dist-lib/lib/hardware/cpu-placement.d.ts +8 -0
  41. package/dist-lib/lib/hardware/cpu-placement.js +48 -0
  42. package/dist-lib/lib/helpers/goal-check.d.ts +2 -0
  43. package/dist-lib/lib/helpers/goal-check.js +18 -0
  44. package/dist-lib/lib/machine/completion/actions/completion.js +33 -13
  45. package/dist-lib/lib/machine/completion/context.js +3 -1
  46. package/dist-lib/lib/machine/completion/implementations.js +16 -4
  47. package/dist-lib/lib/machine/completion/machine.d.ts +2 -0
  48. package/dist-lib/lib/machine/completion/rules.d.ts +1 -1
  49. package/dist-lib/lib/machine/completion/rules.js +7 -8
  50. package/dist-lib/lib/machine/completion/types.d.ts +8 -1
  51. package/dist-lib/lib/machine/index.d.ts +2 -0
  52. package/dist-lib/lib/models/model-pool.d.ts +4 -0
  53. package/dist-lib/lib/models/model-pool.js +4 -1
  54. package/dist-lib/lib/prompt.d.ts +2 -1
  55. package/dist-lib/lib/prompt.js +12 -12
  56. package/dist-lib/lib/residency/completion-runtime.d.ts +9 -1
  57. package/dist-lib/lib/residency/completion-runtime.js +29 -26
  58. package/dist-lib/lib/residency/index.d.ts +4 -0
  59. package/dist-lib/lib/residency/index.js +6 -1
  60. package/dist-lib/lib/serve.js +12 -5
  61. package/dist-lib/lib/tools/http-request.js +1 -0
  62. package/dist-lib/lib/wire.js +5 -0
  63. package/dist-lib/plugins/mcp/server.js +1 -1
  64. package/dist-lib/plugins/obsidian/readiness.js +2 -2
  65. package/dist-lib/plugins/obsidian/vault-read.js +17 -16
  66. package/dist-lib/plugins/sandbox-windows/prebuilds/win32-arm64/qvac-sandbox.exe +0 -0
  67. package/dist-lib/plugins/sandbox-windows/prebuilds/win32-x64/qvac-sandbox.exe +0 -0
  68. package/dist-lib/schema/harness.js +5 -2
  69. package/dist-lib/spec/hrpc/messages.js +19 -5
  70. package/dist-lib/spec/hyperschema/index.js +19 -5
  71. package/dist-lib/spec/hyperschema/schema.json +14 -0
  72. package/dist-lib/spec/hyperschema/types.d.ts +3 -1
  73. package/package.json +2 -2
@@ -22,9 +22,10 @@ export const RAG_CITATION_LINE = 'After your answer, add one final line naming t
22
22
  const METADATA_SECTION = `## Message Metadata
23
23
 
24
24
  User messages may include metadata such as [Current local time: ...]. This is contextual information provided by the system, not part of the user's query. Use it only when relevant and never repeat it unless the user asks about the current date or time.`;
25
+ const WEEKDAYS = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
25
26
  export function currentTimeAnnotation(now = new Date()) {
26
27
  const p = (n) => String(n).padStart(2, '0');
27
- const stamp = `${now.getFullYear()}-${p(now.getMonth() + 1)}-${p(now.getDate())} ${p(now.getHours())}:${p(now.getMinutes())}:${p(now.getSeconds())}`;
28
+ const stamp = `${WEEKDAYS[now.getDay()]} ${now.getFullYear()}-${p(now.getMonth() + 1)}-${p(now.getDate())} ${p(now.getHours())}:${p(now.getMinutes())}:${p(now.getSeconds())}`;
28
29
  const offset = -now.getTimezoneOffset();
29
30
  const sign = offset < 0 ? '-' : '+';
30
31
  const abs = Math.abs(offset);
@@ -39,17 +40,16 @@ export function lastUserContent(messages) {
39
40
  }
40
41
  return '';
41
42
  }
42
- export function annotateLastUserTime(turns, now) {
43
- const result = [...turns];
44
- for (let i = result.length - 1; i >= 0; i--) {
45
- const turn = result[i];
46
- if (!turn || turn.role !== 'user') {
47
- continue;
48
- }
49
- result[i] = { ...turn, content: `${currentTimeAnnotation(now)}\n\n${turn.content}` };
50
- break;
51
- }
52
- return result;
43
+ export function annotateUserTimes(turns, now = new Date()) {
44
+ const lastUser = turns.findLastIndex((turn) => turn.role === 'user');
45
+ return turns.map((turn, i) => {
46
+ if (turn.role !== 'user')
47
+ return turn;
48
+ if (!turn.sentAt && i !== lastUser)
49
+ return turn;
50
+ const at = turn.sentAt ? new Date(turn.sentAt) : now;
51
+ return { ...turn, content: `${currentTimeAnnotation(at)}\n\n${turn.content}` };
52
+ });
53
53
  }
54
54
  export function toolGuidelines(name) {
55
55
  if (name === 'exec') {
@@ -1,6 +1,6 @@
1
1
  import type { AbortSignal as BareAbortSignal } from 'bare-abort-controller';
2
2
  import type { CompletionArgs } from '../capabilities/completion-engine/index.ts';
3
- import type { CompletionSdk, ToolDefinition } from '../contract/index.ts';
3
+ import type { CompletionSdk, RoundModelLease, ToolDefinition } from '../contract/index.ts';
4
4
  import type { CompletionContext } from '../../index.ts';
5
5
  import type { CompletionSkillEntry } from '../capabilities/skill-entry.ts';
6
6
  import { type LlmDeviceConfig, type ModelLoadOptions, type ModelLifecycleSdk, type PoolLike } from '../models/model-pool.ts';
@@ -43,6 +43,13 @@ interface RuntimeResidency {
43
43
  }): Promise<boolean>;
44
44
  loadLifecycleSdk(): Promise<ModelLifecycleSdk>;
45
45
  }
46
+ export type RoundResidency = Pick<RuntimeResidency, 'pool' | 'gate' | 'sdk' | 'acquireLease' | 'makeRoomForCompletion' | 'unloadIdleGenerators'>;
47
+ interface RoundTarget {
48
+ model: string;
49
+ key: string;
50
+ loadOpts: ModelLoadOptions;
51
+ signal?: BareAbortSignal | undefined;
52
+ }
46
53
  export interface PreparedRuntime {
47
54
  key: string;
48
55
  args: Partial<CompletionArgs> & {
@@ -50,4 +57,5 @@ export interface PreparedRuntime {
50
57
  };
51
58
  }
52
59
  export declare function prepareCompletionRuntime(residency: RuntimeResidency, request: CompletionRuntimeRequest): Promise<PreparedRuntime>;
60
+ export declare function roundAcquirer(residency: RoundResidency, { model, key, loadOpts, signal }: RoundTarget): (invocationSignal?: BareAbortSignal) => Promise<RoundModelLease>;
53
61
  export {};
@@ -16,7 +16,35 @@ export async function prepareCompletionRuntime(residency, request) {
16
16
  const key = modelKey(model, loadOpts);
17
17
  const resident = isResident(residency.pool, key);
18
18
  HarnessLog.info('completion start', { model, resident, projection: Boolean(projectionModel) });
19
- const acquireRound = async (invocationSignal) => {
19
+ const acquireRound = roundAcquirer(residency, { model, key, loadOpts, signal });
20
+ const remoteRoots = driveOp && grantedDrives?.length ? createRemoteRoots(grantedDrives, driveOp) : [];
21
+ return {
22
+ key,
23
+ args: {
24
+ acquireRound,
25
+ ctxSize: await resolveCtxSize(() => residency.loadLifecycleSdk(), model, {
26
+ opts: loadOpts,
27
+ deviceConfig: residency.deviceConfig()
28
+ }),
29
+ messages: projectionModel ? messages : messages.map(({ attachments, ...turn }) => turn),
30
+ requestMessages: messages,
31
+ tools: withRunTools(residency.tools(), request.tools ?? []),
32
+ skillCatalog: await residency.skills(agent?.id ?? null, model),
33
+ fsRoots: [
34
+ ...(grantedDirs?.length ? await createLocalRoots(grantedDirs) : []),
35
+ ...remoteRoots
36
+ ],
37
+ fsWriteRoots: [
38
+ ...(request.grantedWriteDirs?.length
39
+ ? await createLocalRoots(request.grantedWriteDirs)
40
+ : []),
41
+ ...remoteRoots.filter((root) => root.writable)
42
+ ]
43
+ }
44
+ };
45
+ }
46
+ export function roundAcquirer(residency, { model, key, loadOpts, signal }) {
47
+ return async (invocationSignal) => {
20
48
  const pool = residency.pool;
21
49
  const lease = await residency.acquireLease({
22
50
  pool,
@@ -56,31 +84,6 @@ export async function prepareCompletionRuntime(residency, request) {
56
84
  throw error;
57
85
  }
58
86
  };
59
- const remoteRoots = driveOp && grantedDrives?.length ? createRemoteRoots(grantedDrives, driveOp) : [];
60
- return {
61
- key,
62
- args: {
63
- acquireRound,
64
- ctxSize: await resolveCtxSize(() => residency.loadLifecycleSdk(), model, {
65
- opts: loadOpts,
66
- deviceConfig: residency.deviceConfig()
67
- }),
68
- messages: projectionModel ? messages : messages.map(({ attachments, ...turn }) => turn),
69
- requestMessages: messages,
70
- tools: withRunTools(residency.tools(), request.tools ?? []),
71
- skillCatalog: await residency.skills(agent?.id ?? null, model),
72
- fsRoots: [
73
- ...(grantedDirs?.length ? await createLocalRoots(grantedDirs) : []),
74
- ...remoteRoots
75
- ],
76
- fsWriteRoots: [
77
- ...(request.grantedWriteDirs?.length
78
- ? await createLocalRoots(request.grantedWriteDirs)
79
- : []),
80
- ...remoteRoots.filter((root) => root.writable)
81
- ]
82
- }
83
- };
84
87
  }
85
88
  function withRunTools(builtIn, own) {
86
89
  const names = new Set(own.map((tool) => tool.name));
@@ -180,6 +180,10 @@ export declare class Residency {
180
180
  loadOptions(model: string, agent?: LoadOptionKnobs): ModelLoadOptions;
181
181
  acquireLease({ pool, key, open, signal, prepare, onLoad }: ModelLeaseOptions): Promise<ModelLease | null>;
182
182
  completionRuntime(request: CompletionRuntimeRequest): Promise<import("./completion-runtime.ts").PreparedRuntime>;
183
+ servedRound(model: string): {
184
+ key: string;
185
+ acquireRound: (invocationSignal?: BareAbortSignal) => Promise<import("../contract/completion.ts").RoundModelLease>;
186
+ };
183
187
  makeRoomForCompletion(model: string, { loadOpts, signal, deadlineMs }: RoomOptions): Promise<boolean>;
184
188
  evictWedged(model: string, key: string): Promise<WedgedEviction>;
185
189
  private _evictAfterLeases;
@@ -13,7 +13,7 @@ import { ModelFit } from '../models/model-fit.js';
13
13
  import { createModelStatusCache, invalidateModelStatusCache } from '../models/model-list.js';
14
14
  import { awaitModelCapacity, contextSize, slotCount, createModelPool, evictIdle, evictIdleWhere, evictIdleWithin, evictModel, evictModelWithin, isResident, leaseCount, loadedModels, loadingModels, modelKey, modelOf, releaseModel, resolveLoadOptions, settledEntries, settledModels } from '../models/model-pool.js';
15
15
  import { openclCacheDir } from '../models/opencl-cache.js';
16
- import { prepareCompletionRuntime } from './completion-runtime.js';
16
+ import { prepareCompletionRuntime, roundAcquirer } from './completion-runtime.js';
17
17
  const PLUGIN_EVICT_WAIT_MS = 15_000;
18
18
  const WEDGED_EVICT_WAIT_MS = 10_000;
19
19
  const MODEL_ROOM_WAIT_MS = 300_000;
@@ -822,6 +822,11 @@ export class Residency {
822
822
  releaseWork();
823
823
  }
824
824
  }
825
+ servedRound(model) {
826
+ const loadOpts = this.loadOptions(model);
827
+ const key = modelKey(model, loadOpts);
828
+ return { key, acquireRound: roundAcquirer(this, { model, key, loadOpts }) };
829
+ }
825
830
  async makeRoomForCompletion(model, { loadOpts, signal, deadlineMs = MODEL_ROOM_WAIT_MS }) {
826
831
  if (this._capBytes !== null) {
827
832
  await evictIdleWhere(this._models, this._replacedBy(model));
@@ -91,16 +91,17 @@ function optionalNumber(value) {
91
91
  return value === undefined || typeof value === 'number';
92
92
  }
93
93
  function goalFrom(value) {
94
- const { objective, rounds, ms, tokens, checks } = value;
94
+ const { objective, rounds, ms, tokens, checks, checksProve } = value;
95
95
  if (typeof objective !== 'string' ||
96
96
  !optionalNumber(rounds) ||
97
97
  !optionalNumber(ms) ||
98
98
  !optionalNumber(tokens) ||
99
99
  (checks !== undefined &&
100
- (!Array.isArray(checks) || !checks.every((check) => typeof check === 'string')))) {
100
+ (!Array.isArray(checks) || !checks.every((check) => typeof check === 'string'))) ||
101
+ (checksProve !== undefined && typeof checksProve !== 'boolean')) {
101
102
  throw new TypeError('Invalid goal');
102
103
  }
103
- return { objective, rounds, ms, tokens, checks };
104
+ return { objective, rounds, ms, tokens, checks, checksProve };
104
105
  }
105
106
  function startPayloadFrom(value) {
106
107
  if (!isRecord(value)) {
@@ -175,6 +176,9 @@ function startPayloadFrom(value) {
175
176
  if (typeof value.maxToolRounds === 'number') {
176
177
  payload.maxToolRounds = checkMaxToolRounds(value.maxToolRounds);
177
178
  }
179
+ if (value.replaysContext === true) {
180
+ payload.replaysContext = true;
181
+ }
178
182
  if (value.runLog === null) {
179
183
  payload.runLog = null;
180
184
  }
@@ -865,12 +869,13 @@ function completion(harness) {
865
869
  captureInferenceCalls: frame.captureInferenceCalls ?? undefined,
866
870
  maxToolRounds: startPayload.maxToolRounds,
867
871
  typedText: startPayload.typedText,
872
+ replaysContext: startPayload.replaysContext,
868
873
  knowledge: startPayload.knowledge,
869
874
  planMode: startPayload.planMode,
870
875
  deferTools: startPayload.deferTools,
871
876
  parentRunId: startPayload.parentRunId,
872
877
  goal: startPayload.goal,
873
- messages: (frame.messages ?? []).map(({ role, content, attachments, toolCalls, toolCallId, name, id }) => ({
878
+ messages: (frame.messages ?? []).map(({ role, content, attachments, toolCalls, toolCallId, name, id, context: added, sentAt }) => ({
874
879
  role,
875
880
  content,
876
881
  attachments: attachments?.length
@@ -879,7 +884,9 @@ function completion(harness) {
879
884
  toolCalls: toolCalls ?? undefined,
880
885
  toolCallId: toolCallId ?? undefined,
881
886
  name: name ?? undefined,
882
- id: id || undefined
887
+ id: id || undefined,
888
+ context: added ?? undefined,
889
+ sentAt: sentAt || undefined
883
890
  })),
884
891
  toolConfigs: frame.toolConfigs ?? undefined,
885
892
  grantedDirs: frame.grantedDirs ?? undefined,
@@ -16,6 +16,7 @@ export function createHttpRequestTool({ policyVersion, fetch: fetchImpl, credent
16
16
  name: 'http_request',
17
17
  policyVersion,
18
18
  toolset: 'http-request',
19
+ defer: true,
19
20
  description: 'Make an outbound HTTP or HTTPS request and return the response status and body (truncated) as text. Authorization/Cookie headers are stripped before sending. Stored skill credentials are attached automatically for their allow-listed hosts; `auth` is only needed to force a specific credential key. For APIs and text responses only: a URL that serves a file — PDF, .docx, .xlsx, an image, any binary — comes back as truncated garbage here. Use web_fetch for those; it downloads and attaches the file.',
20
21
  parameters: {
21
22
  type: 'object',
@@ -139,6 +139,8 @@ function toWirePayload(event) {
139
139
  return { type: 'input', text: stringField(event.text), callId: stringField(event.id) };
140
140
  case 'input-rejected':
141
141
  return { type: 'input-rejected', text: stringField(event.reason) };
142
+ case 'context':
143
+ return { type: 'context', callId: stringField(event.id), payload: event.context };
142
144
  case 'goal':
143
145
  return {
144
146
  type: 'goal',
@@ -177,6 +179,7 @@ export function fromWire(event) {
177
179
  'tool-activity',
178
180
  'round-reset',
179
181
  'input',
182
+ 'context',
180
183
  'goal'
181
184
  ].includes(event.type)) {
182
185
  decoded.round = event.round;
@@ -277,6 +280,8 @@ function fromWirePayload(event) {
277
280
  return { type: 'input', text: event.text ?? '', id: event.callId || undefined };
278
281
  case 'input-rejected':
279
282
  return { type: 'input-rejected', reason: event.text ?? '' };
283
+ case 'context':
284
+ return { type: 'context', id: event.callId || undefined, context: objectField(event.payload) };
280
285
  case 'goal': {
281
286
  const { status, turn, checks } = objectField(event.payload);
282
287
  return { type: 'goal', status, turn, text: event.text || undefined, checks };
@@ -104,5 +104,5 @@ export function serverTool(server, listed, credentialStore) {
104
104
  credentialAllowList
105
105
  }, ctx)
106
106
  };
107
- return server.defer ? { ...tool, defer: true, group: server.name } : tool;
107
+ return server.defer === false ? tool : { ...tool, defer: true, group: server.name };
108
108
  }
@@ -6,8 +6,8 @@ export const OBSIDIAN_SKILL_NAME = 'obsidian';
6
6
  export const OBSIDIAN_VAULT_PATH_CREDENTIAL_KEY = 'obsidian_vault_path';
7
7
  export const OBSIDIAN_VAULT_MODE_NOTE = [
8
8
  'Runtime note — Obsidian vault file mode is active (a vault folder is configured):',
9
- '- Run vault commands through the `exec` tool, e.g. `obsidian vault info=path`, `obsidian search query="..."`, `obsidian read path="Folder/Note.md"`.',
10
- '- Start with `obsidian vault info=path` to confirm the configured vault.',
9
+ '- Run vault commands through the `exec` tool, e.g. `obsidian files`, `obsidian search query="..."`, `obsidian read path="Folder/Note.md"`.',
10
+ '- To list what is in the vault, run `obsidian files`. `read` takes a note name or a path inside the vault, never the vault folder.',
11
11
  '- `obsidian vaults` returns only the configured vault folder, not every vault in the Obsidian app.',
12
12
  '- App-only actions (open in app, plugin/sync/theme commands) are unavailable in this mode; they require the official Obsidian CLI connected to the running app.'
13
13
  ].join('\n');
@@ -2,6 +2,14 @@ import fs from 'fs';
2
2
  import path from 'path';
3
3
  import { HarnessError } from '../../lib/errors.js';
4
4
  import { dailyCandidates, ensureWithinRoot, FRONTMATTER_RE, getArg, listFolders, listMarkdownFiles, parseFrontmatter, readFileText, resolveNotePath, todayStamp } from './vault-paths.js';
5
+ function statOrNull(p) {
6
+ try {
7
+ return fs.statSync(p);
8
+ }
9
+ catch {
10
+ return null;
11
+ }
12
+ }
5
13
  export function handleVault(vaultPath) {
6
14
  return JSON.stringify({ name: path.basename(vaultPath), path: vaultPath });
7
15
  }
@@ -17,9 +25,14 @@ export function handleVaults(vaultPath) {
17
25
  }
18
26
  export function handleRead(vaultPath, args) {
19
27
  const notePath = resolveNotePath(vaultPath, args);
20
- if (!notePath || !fs.existsSync(notePath)) {
28
+ const stat = notePath ? statOrNull(notePath) : null;
29
+ if (!notePath || !stat) {
21
30
  throw new HarnessError('OBSIDIAN_NOTE_NOT_FOUND', [args]);
22
31
  }
32
+ if (stat.isDirectory()) {
33
+ const folder = path.relative(path.resolve(vaultPath), notePath).split(path.sep).join('/');
34
+ throw new HarnessError('OBSIDIAN_PATH_IS_FOLDER', [folder]);
35
+ }
23
36
  return readFileText(notePath);
24
37
  }
25
38
  export function handleFiles(vaultPath, args) {
@@ -69,11 +82,7 @@ export function handleSearch(vaultPath, args) {
69
82
  return matches.join('\n') + truncated;
70
83
  }
71
84
  export function handleProperties(vaultPath, args) {
72
- const notePath = resolveNotePath(vaultPath, args);
73
- if (!notePath || !fs.existsSync(notePath)) {
74
- throw new HarnessError('OBSIDIAN_NOTE_NOT_FOUND', [args]);
75
- }
76
- return JSON.stringify(parseFrontmatter(readFileText(notePath)), null, 2);
85
+ return JSON.stringify(parseFrontmatter(handleRead(vaultPath, args)), null, 2);
77
86
  }
78
87
  function countTags(tagCounts, content) {
79
88
  for (const match of content.matchAll(/#([a-zA-Z0-9_/-]+)/g)) {
@@ -98,20 +107,12 @@ export function handleTags(vaultPath) {
98
107
  return sorted.map(([tag, count]) => `#${tag} (${count})`).join('\n') || '(no tags)';
99
108
  }
100
109
  export function handleWordcount(vaultPath, args) {
101
- const notePath = resolveNotePath(vaultPath, args);
102
- if (!notePath || !fs.existsSync(notePath)) {
103
- throw new HarnessError('OBSIDIAN_NOTE_NOT_FOUND', [args]);
104
- }
105
- const body = readFileText(notePath).replace(FRONTMATTER_RE, '').trim();
110
+ const body = handleRead(vaultPath, args).replace(FRONTMATTER_RE, '').trim();
106
111
  const words = body.split(/\s+/).filter(Boolean).length;
107
112
  return `${words} words`;
108
113
  }
109
114
  export function handleOutline(vaultPath, args) {
110
- const notePath = resolveNotePath(vaultPath, args);
111
- if (!notePath || !fs.existsSync(notePath)) {
112
- throw new HarnessError('OBSIDIAN_NOTE_NOT_FOUND', [args]);
113
- }
114
- const headings = readFileText(notePath)
115
+ const headings = handleRead(vaultPath, args)
115
116
  .split('\n')
116
117
  .filter((line) => /^#{1,6}\s/.test(line));
117
118
  return headings.join('\n') || '(no headings)';
@@ -56,7 +56,9 @@ export function registerHarnessTypes(ns) {
56
56
  { name: 'toolCalls', type: 'json' },
57
57
  { name: 'toolCallId', type: 'string' },
58
58
  { name: 'name', type: 'string' },
59
- { name: 'id', type: 'string' }
59
+ { name: 'id', type: 'string' },
60
+ { name: 'context', type: 'json' },
61
+ { name: 'sentAt', type: 'uint' }
60
62
  ]
61
63
  });
62
64
  ns.register({
@@ -168,7 +170,8 @@ export function registerHarnessTypes(ns) {
168
170
  'input',
169
171
  'goal',
170
172
  'fold',
171
- 'input-rejected'
173
+ 'input-rejected',
174
+ 'context'
172
175
  ],
173
176
  strings: true
174
177
  });
@@ -321,13 +321,15 @@ const encoding7 = {
321
321
  preencode(state, m) {
322
322
  encoding5.preencode(state, m.role)
323
323
  c.string.preencode(state, m.content)
324
- state.end++ // max flag is 16 so always one byte
324
+ state.end++ // max flag is 64 so always one byte
325
325
 
326
326
  if (m.attachments) encoding7_2.preencode(state, m.attachments)
327
327
  if (version >= 22 && m.toolCalls) c.json.preencode(state, m.toolCalls)
328
328
  if (version >= 22 && m.toolCallId) c.string.preencode(state, m.toolCallId)
329
329
  if (version >= 22 && m.name) c.string.preencode(state, m.name)
330
330
  if (version >= 22 && m.id) c.string.preencode(state, m.id)
331
+ if (version >= 22 && m.context) c.json.preencode(state, m.context)
332
+ if (version >= 22 && m.sentAt) c.uint.preencode(state, m.sentAt)
331
333
  },
332
334
  encode(state, m) {
333
335
  const flags =
@@ -335,7 +337,9 @@ const encoding7 = {
335
337
  ((version >= 22 && m.toolCalls) ? 2 : 0) |
336
338
  ((version >= 22 && m.toolCallId) ? 4 : 0) |
337
339
  ((version >= 22 && m.name) ? 8 : 0) |
338
- ((version >= 22 && m.id) ? 16 : 0)
340
+ ((version >= 22 && m.id) ? 16 : 0) |
341
+ ((version >= 22 && m.context) ? 32 : 0) |
342
+ ((version >= 22 && m.sentAt) ? 64 : 0)
339
343
 
340
344
  encoding5.encode(state, m.role)
341
345
  c.string.encode(state, m.content)
@@ -346,6 +350,8 @@ const encoding7 = {
346
350
  if (version >= 22 && m.toolCallId) c.string.encode(state, m.toolCallId)
347
351
  if (version >= 22 && m.name) c.string.encode(state, m.name)
348
352
  if (version >= 22 && m.id) c.string.encode(state, m.id)
353
+ if (version >= 22 && m.context) c.json.encode(state, m.context)
354
+ if (version >= 22 && m.sentAt) c.uint.encode(state, m.sentAt)
349
355
  },
350
356
  decode(state) {
351
357
  const r0 = encoding5.decode(state)
@@ -359,7 +365,9 @@ const encoding7 = {
359
365
  toolCalls: (version >= 22 && (flags & 2) !== 0) ? c.json.decode(state) : null,
360
366
  toolCallId: (version >= 22 && (flags & 4) !== 0) ? c.string.decode(state) : null,
361
367
  name: (version >= 22 && (flags & 8) !== 0) ? c.string.decode(state) : null,
362
- id: (version >= 22 && (flags & 16) !== 0) ? c.string.decode(state) : null
368
+ id: (version >= 22 && (flags & 16) !== 0) ? c.string.decode(state) : null,
369
+ context: (version >= 22 && (flags & 32) !== 0) ? c.json.decode(state) : null,
370
+ sentAt: (version >= 22 && (flags & 64) !== 0) ? c.uint.decode(state) : 0
363
371
  }
364
372
  }
365
373
  }
@@ -721,13 +729,14 @@ const encoding12_enum = {
721
729
  input: 'input',
722
730
  goal: 'goal',
723
731
  fold: 'fold',
724
- "input-rejected": 'input-rejected'
732
+ "input-rejected": 'input-rejected',
733
+ context: 'context'
725
734
  }
726
735
 
727
736
  // @harness/completion-event-type enum
728
737
  const encoding12 = {
729
738
  preencode (state, m) {
730
- state.end++ // max enum is 28 so always one byte
739
+ state.end++ // max enum is 29 so always one byte
731
740
  },
732
741
  encode (state, m) {
733
742
  switch (m) {
@@ -815,6 +824,9 @@ const encoding12 = {
815
824
  case 'input-rejected':
816
825
  c.uint.encode(state, 28)
817
826
  break
827
+ case 'context':
828
+ c.uint.encode(state, 29)
829
+ break
818
830
  default:
819
831
  throw new Error('Unknown enum')
820
832
  }
@@ -877,6 +889,8 @@ const encoding12 = {
877
889
  return 'fold'
878
890
  case 28:
879
891
  return 'input-rejected'
892
+ case 29:
893
+ return 'context'
880
894
  default: return null
881
895
  }
882
896
  }
@@ -321,13 +321,15 @@ const encoding7 = {
321
321
  preencode(state, m) {
322
322
  encoding5.preencode(state, m.role)
323
323
  c.string.preencode(state, m.content)
324
- state.end++ // max flag is 16 so always one byte
324
+ state.end++ // max flag is 64 so always one byte
325
325
 
326
326
  if (m.attachments) encoding7_2.preencode(state, m.attachments)
327
327
  if (version >= 22 && m.toolCalls) c.json.preencode(state, m.toolCalls)
328
328
  if (version >= 22 && m.toolCallId) c.string.preencode(state, m.toolCallId)
329
329
  if (version >= 22 && m.name) c.string.preencode(state, m.name)
330
330
  if (version >= 22 && m.id) c.string.preencode(state, m.id)
331
+ if (version >= 22 && m.context) c.json.preencode(state, m.context)
332
+ if (version >= 22 && m.sentAt) c.uint.preencode(state, m.sentAt)
331
333
  },
332
334
  encode(state, m) {
333
335
  const flags =
@@ -335,7 +337,9 @@ const encoding7 = {
335
337
  ((version >= 22 && m.toolCalls) ? 2 : 0) |
336
338
  ((version >= 22 && m.toolCallId) ? 4 : 0) |
337
339
  ((version >= 22 && m.name) ? 8 : 0) |
338
- ((version >= 22 && m.id) ? 16 : 0)
340
+ ((version >= 22 && m.id) ? 16 : 0) |
341
+ ((version >= 22 && m.context) ? 32 : 0) |
342
+ ((version >= 22 && m.sentAt) ? 64 : 0)
339
343
 
340
344
  encoding5.encode(state, m.role)
341
345
  c.string.encode(state, m.content)
@@ -346,6 +350,8 @@ const encoding7 = {
346
350
  if (version >= 22 && m.toolCallId) c.string.encode(state, m.toolCallId)
347
351
  if (version >= 22 && m.name) c.string.encode(state, m.name)
348
352
  if (version >= 22 && m.id) c.string.encode(state, m.id)
353
+ if (version >= 22 && m.context) c.json.encode(state, m.context)
354
+ if (version >= 22 && m.sentAt) c.uint.encode(state, m.sentAt)
349
355
  },
350
356
  decode(state) {
351
357
  const r0 = encoding5.decode(state)
@@ -359,7 +365,9 @@ const encoding7 = {
359
365
  toolCalls: (version >= 22 && (flags & 2) !== 0) ? c.json.decode(state) : null,
360
366
  toolCallId: (version >= 22 && (flags & 4) !== 0) ? c.string.decode(state) : null,
361
367
  name: (version >= 22 && (flags & 8) !== 0) ? c.string.decode(state) : null,
362
- id: (version >= 22 && (flags & 16) !== 0) ? c.string.decode(state) : null
368
+ id: (version >= 22 && (flags & 16) !== 0) ? c.string.decode(state) : null,
369
+ context: (version >= 22 && (flags & 32) !== 0) ? c.json.decode(state) : null,
370
+ sentAt: (version >= 22 && (flags & 64) !== 0) ? c.uint.decode(state) : 0
363
371
  }
364
372
  }
365
373
  }
@@ -721,13 +729,14 @@ const encoding12_enum = {
721
729
  input: 'input',
722
730
  goal: 'goal',
723
731
  fold: 'fold',
724
- "input-rejected": 'input-rejected'
732
+ "input-rejected": 'input-rejected',
733
+ context: 'context'
725
734
  }
726
735
 
727
736
  // @harness/completion-event-type enum
728
737
  const encoding12 = {
729
738
  preencode (state, m) {
730
- state.end++ // max enum is 28 so always one byte
739
+ state.end++ // max enum is 29 so always one byte
731
740
  },
732
741
  encode (state, m) {
733
742
  switch (m) {
@@ -815,6 +824,9 @@ const encoding12 = {
815
824
  case 'input-rejected':
816
825
  c.uint.encode(state, 28)
817
826
  break
827
+ case 'context':
828
+ c.uint.encode(state, 29)
829
+ break
818
830
  default:
819
831
  throw new Error('Unknown enum')
820
832
  }
@@ -877,6 +889,8 @@ const encoding12 = {
877
889
  return 'fold'
878
890
  case 28:
879
891
  return 'input-rejected'
892
+ case 29:
893
+ return 'context'
880
894
  default: return null
881
895
  }
882
896
  }
@@ -261,6 +261,16 @@
261
261
  "name": "id",
262
262
  "type": "string",
263
263
  "version": 22
264
+ },
265
+ {
266
+ "name": "context",
267
+ "type": "json",
268
+ "version": 22
269
+ },
270
+ {
271
+ "name": "sentAt",
272
+ "type": "uint",
273
+ "version": 22
264
274
  }
265
275
  ]
266
276
  },
@@ -661,6 +671,10 @@
661
671
  {
662
672
  "key": "input-rejected",
663
673
  "version": 22
674
+ },
675
+ {
676
+ "key": "context",
677
+ "version": 22
664
678
  }
665
679
  ],
666
680
  "strings": true
@@ -52,6 +52,8 @@ export interface HarnessMessage {
52
52
  toolCallId?: string | null
53
53
  name?: string | null
54
54
  id?: string | null
55
+ context?: unknown | null
56
+ sentAt?: number
55
57
  }
56
58
 
57
59
  export interface HarnessResource {
@@ -103,7 +105,7 @@ export interface HarnessCompletionFrame {
103
105
  runId?: string | null
104
106
  }
105
107
 
106
- export type HarnessCompletionEventType = "content" | "thinking" | "tool-call" | "tool-result" | "approval-ask" | "metrics" | "error" | "aborted" | "attach-ask" | "fetch-ask" | "progress" | "rag-ask" | "question-ask" | "done" | "tool-activity" | "drive-ask" | "inference-call" | "inference-sent" | "run-started" | "run-resumed" | "paused" | "recovery-required" | "round-reset" | "run-log-append" | "input" | "goal" | "fold" | "input-rejected"
108
+ export type HarnessCompletionEventType = "content" | "thinking" | "tool-call" | "tool-result" | "approval-ask" | "metrics" | "error" | "aborted" | "attach-ask" | "fetch-ask" | "progress" | "rag-ask" | "question-ask" | "done" | "tool-activity" | "drive-ask" | "inference-call" | "inference-sent" | "run-started" | "run-resumed" | "paused" | "recovery-required" | "round-reset" | "run-log-append" | "input" | "goal" | "fold" | "input-rejected" | "context"
107
109
 
108
110
  export interface HarnessCompletionEvent {
109
111
  type: HarnessCompletionEventType
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qvac/harness",
3
- "version": "1.0.0-rc.4",
3
+ "version": "1.0.0-rc.6",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "bare": ">=1.34.0",
@@ -592,7 +592,7 @@
592
592
  "bare-stream": "^2.13.3",
593
593
  "bare-subprocess": "^6.1.0",
594
594
  "bare-supervisor": "^0.1.1",
595
- "bare-tls": "^3.1.7",
595
+ "bare-tls": "^3.1.13",
596
596
  "bare-tty": "^5.1.2",
597
597
  "bare-url": "^2.4.5",
598
598
  "bare-worker": "^4.5.0",