@qvac/harness 1.0.0-rc.5 → 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.
- package/CHANGELOG.md +93 -18
- package/dist-lib/index.d.ts +3 -1
- package/dist-lib/index.js +42 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/inspecting.js +13 -3
- package/dist-lib/lib/capabilities/completion-engine/actors/loading-skill.js +8 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/preparing.js +21 -19
- package/dist-lib/lib/capabilities/completion-engine/actors/resolving.js +11 -4
- package/dist-lib/lib/capabilities/completion-engine/actors/skill-step.js +10 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/stream.js +7 -3
- package/dist-lib/lib/capabilities/completion-engine/actors/streaming.js +5 -16
- package/dist-lib/lib/capabilities/completion-engine/actors/wrap-up.d.ts +1 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/wrap-up.js +9 -11
- package/dist-lib/lib/capabilities/completion-engine/index.d.ts +3 -1
- package/dist-lib/lib/capabilities/completion-engine/index.js +2 -0
- package/dist-lib/lib/capabilities/completion-engine/model-round.d.ts +14 -1
- package/dist-lib/lib/capabilities/completion-engine/model-round.js +52 -0
- package/dist-lib/lib/capabilities/completion-engine/round.d.ts +3 -3
- package/dist-lib/lib/capabilities/completion-engine/turns.js +14 -4
- package/dist-lib/lib/capabilities/sdk-tool.d.ts +9 -1
- package/dist-lib/lib/capabilities/sdk-tool.js +21 -2
- package/dist-lib/lib/capabilities/tool-plan.d.ts +4 -0
- package/dist-lib/lib/capabilities/tool-plan.js +15 -0
- package/dist-lib/lib/connect.js +12 -2
- package/dist-lib/lib/contract/run.d.ts +2 -0
- package/dist-lib/lib/contract-types.d.ts +1 -0
- package/dist-lib/lib/errors.d.ts +4 -0
- package/dist-lib/lib/errors.js +6 -0
- package/dist-lib/lib/hardware/cpu-placement.d.ts +8 -0
- package/dist-lib/lib/hardware/cpu-placement.js +48 -0
- package/dist-lib/lib/helpers/goal-check.d.ts +2 -0
- package/dist-lib/lib/helpers/goal-check.js +18 -0
- package/dist-lib/lib/machine/completion/actions/completion.js +30 -11
- package/dist-lib/lib/machine/completion/context.js +2 -1
- package/dist-lib/lib/machine/completion/rules.d.ts +1 -1
- package/dist-lib/lib/machine/completion/rules.js +7 -8
- package/dist-lib/lib/machine/completion/types.d.ts +1 -0
- package/dist-lib/lib/models/model-pool.d.ts +4 -0
- package/dist-lib/lib/models/model-pool.js +4 -1
- package/dist-lib/lib/prompt.d.ts +2 -1
- package/dist-lib/lib/prompt.js +12 -12
- package/dist-lib/lib/residency/completion-runtime.d.ts +9 -1
- package/dist-lib/lib/residency/completion-runtime.js +29 -26
- package/dist-lib/lib/residency/index.d.ts +4 -0
- package/dist-lib/lib/residency/index.js +6 -1
- package/dist-lib/lib/serve.js +7 -5
- package/dist-lib/lib/tools/http-request.js +1 -0
- package/dist-lib/plugins/mcp/server.js +1 -1
- package/dist-lib/plugins/obsidian/readiness.js +2 -2
- package/dist-lib/plugins/obsidian/vault-read.js +17 -16
- package/dist-lib/plugins/sandbox-windows/prebuilds/win32-arm64/qvac-sandbox.exe +0 -0
- package/dist-lib/plugins/sandbox-windows/prebuilds/win32-x64/qvac-sandbox.exe +0 -0
- package/dist-lib/schema/harness.js +2 -1
- package/dist-lib/spec/hrpc/messages.js +7 -3
- package/dist-lib/spec/hyperschema/index.js +7 -3
- package/dist-lib/spec/hyperschema/schema.json +5 -0
- package/dist-lib/spec/hyperschema/types.d.ts +1 -0
- package/package.json +2 -2
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import ResourcePuddle from 'resource-puddle';
|
|
2
2
|
import { ModelHandle } from './model-handle.ts';
|
|
3
3
|
import { type ModelSrc } from './context.ts';
|
|
4
|
+
import type { CpuPlacement } from '../hardware/cpu-placement.ts';
|
|
4
5
|
import { type ModelAddon } from './model-source.ts';
|
|
5
6
|
import type { GpuFaultState } from './sdk-faults.ts';
|
|
6
7
|
import type { LoadedModelInfo } from '@qvac/sdk';
|
|
@@ -55,6 +56,7 @@ export interface LlmDeviceConfig {
|
|
|
55
56
|
slots?: number;
|
|
56
57
|
contextFor?: (key: string) => number | undefined;
|
|
57
58
|
slotsFor?: (key: string) => number | undefined;
|
|
59
|
+
cpuPlacement?: () => CpuPlacement | undefined;
|
|
58
60
|
}
|
|
59
61
|
export type TrackedLoad = Promise<string> & {
|
|
60
62
|
requestId?: string;
|
|
@@ -89,6 +91,8 @@ export type ModelLifecycleSdk = Pick<SdkModule, 'unloadModel' | 'modelRegistrySe
|
|
|
89
91
|
gpu_layers?: number;
|
|
90
92
|
'main-gpu'?: string;
|
|
91
93
|
openclCacheDir?: string;
|
|
94
|
+
threads?: number;
|
|
95
|
+
'cpu-mask'?: string;
|
|
92
96
|
};
|
|
93
97
|
onProgress?: (progress: Record<string, unknown>) => void;
|
|
94
98
|
}): TrackedLoad;
|
|
@@ -423,6 +423,7 @@ export function createModelPool(loadSdk, notify, { deviceConfig = {}, loads = cr
|
|
|
423
423
|
const openclCache = deviceConfig.device !== 'cpu' && deviceConfig.openclCacheDir
|
|
424
424
|
? deviceConfig.openclCacheDir()
|
|
425
425
|
: undefined;
|
|
426
|
+
const placement = deviceConfig.device === 'cpu' ? deviceConfig.cpuPlacement?.() : undefined;
|
|
426
427
|
const config = definedFields({
|
|
427
428
|
...resolved.llama,
|
|
428
429
|
verbosity: llmVerbosity(),
|
|
@@ -436,7 +437,9 @@ export function createModelPool(loadSdk, notify, { deviceConfig = {}, loads = cr
|
|
|
436
437
|
device: deviceConfig.device,
|
|
437
438
|
gpu_layers: deviceConfig.gpuLayers,
|
|
438
439
|
'main-gpu': mainGpu,
|
|
439
|
-
openclCacheDir: openclCache || undefined
|
|
440
|
+
openclCacheDir: openclCache || undefined,
|
|
441
|
+
threads: resolved.llama?.threads ?? placement?.threads,
|
|
442
|
+
'cpu-mask': placement?.mask
|
|
440
443
|
});
|
|
441
444
|
const pending = { key, model, modelSrc, modelType: 'llamacpp-completion' };
|
|
442
445
|
const chosen = contextSize(model, modelSrc, { opts: resolved, deviceConfig });
|
package/dist-lib/lib/prompt.d.ts
CHANGED
|
@@ -2,9 +2,10 @@ import type { Message, SystemPromptParts } from './contract/index.ts';
|
|
|
2
2
|
export declare const RAG_CITATION_LINE = "After your answer, add one final line naming the files you used, written exactly as [Sources: file-a.pdf, file-b.md] - or [Sources: none] if the excerpts did not answer the question. This line is required, it is the only place square brackets belong, and it is removed before the user sees it.";
|
|
3
3
|
export declare function currentTimeAnnotation(now?: Date): string;
|
|
4
4
|
export declare function lastUserContent(messages: Message[]): string;
|
|
5
|
-
export declare function
|
|
5
|
+
export declare function annotateUserTimes<T extends {
|
|
6
6
|
role: string;
|
|
7
7
|
content: string;
|
|
8
|
+
sentAt?: number | undefined;
|
|
8
9
|
}>(turns: ReadonlyArray<T>, now?: Date): T[];
|
|
9
10
|
export declare function toolGuidelines(name: string): string[];
|
|
10
11
|
export interface SystemPromptInput {
|
package/dist-lib/lib/prompt.js
CHANGED
|
@@ -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
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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 =
|
|
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));
|
package/dist-lib/lib/serve.js
CHANGED
|
@@ -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)) {
|
|
@@ -874,7 +875,7 @@ function completion(harness) {
|
|
|
874
875
|
deferTools: startPayload.deferTools,
|
|
875
876
|
parentRunId: startPayload.parentRunId,
|
|
876
877
|
goal: startPayload.goal,
|
|
877
|
-
messages: (frame.messages ?? []).map(({ role, content, attachments, toolCalls, toolCallId, name, id, context: added }) => ({
|
|
878
|
+
messages: (frame.messages ?? []).map(({ role, content, attachments, toolCalls, toolCallId, name, id, context: added, sentAt }) => ({
|
|
878
879
|
role,
|
|
879
880
|
content,
|
|
880
881
|
attachments: attachments?.length
|
|
@@ -884,7 +885,8 @@ function completion(harness) {
|
|
|
884
885
|
toolCallId: toolCallId ?? undefined,
|
|
885
886
|
name: name ?? undefined,
|
|
886
887
|
id: id || undefined,
|
|
887
|
-
context: added ?? undefined
|
|
888
|
+
context: added ?? undefined,
|
|
889
|
+
sentAt: sentAt || undefined
|
|
888
890
|
})),
|
|
889
891
|
toolConfigs: frame.toolConfigs ?? undefined,
|
|
890
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',
|
|
@@ -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 }
|
|
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
|
|
10
|
-
'-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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)';
|
|
Binary file
|
|
Binary file
|
|
@@ -57,7 +57,8 @@ export function registerHarnessTypes(ns) {
|
|
|
57
57
|
{ name: 'toolCallId', type: 'string' },
|
|
58
58
|
{ name: 'name', type: 'string' },
|
|
59
59
|
{ name: 'id', type: 'string' },
|
|
60
|
-
{ name: 'context', type: 'json' }
|
|
60
|
+
{ name: 'context', type: 'json' },
|
|
61
|
+
{ name: 'sentAt', type: 'uint' }
|
|
61
62
|
]
|
|
62
63
|
});
|
|
63
64
|
ns.register({
|
|
@@ -321,7 +321,7 @@ 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
|
|
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)
|
|
@@ -329,6 +329,7 @@ const encoding7 = {
|
|
|
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
331
|
if (version >= 22 && m.context) c.json.preencode(state, m.context)
|
|
332
|
+
if (version >= 22 && m.sentAt) c.uint.preencode(state, m.sentAt)
|
|
332
333
|
},
|
|
333
334
|
encode(state, m) {
|
|
334
335
|
const flags =
|
|
@@ -337,7 +338,8 @@ const encoding7 = {
|
|
|
337
338
|
((version >= 22 && m.toolCallId) ? 4 : 0) |
|
|
338
339
|
((version >= 22 && m.name) ? 8 : 0) |
|
|
339
340
|
((version >= 22 && m.id) ? 16 : 0) |
|
|
340
|
-
((version >= 22 && m.context) ? 32 : 0)
|
|
341
|
+
((version >= 22 && m.context) ? 32 : 0) |
|
|
342
|
+
((version >= 22 && m.sentAt) ? 64 : 0)
|
|
341
343
|
|
|
342
344
|
encoding5.encode(state, m.role)
|
|
343
345
|
c.string.encode(state, m.content)
|
|
@@ -349,6 +351,7 @@ const encoding7 = {
|
|
|
349
351
|
if (version >= 22 && m.name) c.string.encode(state, m.name)
|
|
350
352
|
if (version >= 22 && m.id) c.string.encode(state, m.id)
|
|
351
353
|
if (version >= 22 && m.context) c.json.encode(state, m.context)
|
|
354
|
+
if (version >= 22 && m.sentAt) c.uint.encode(state, m.sentAt)
|
|
352
355
|
},
|
|
353
356
|
decode(state) {
|
|
354
357
|
const r0 = encoding5.decode(state)
|
|
@@ -363,7 +366,8 @@ const encoding7 = {
|
|
|
363
366
|
toolCallId: (version >= 22 && (flags & 4) !== 0) ? c.string.decode(state) : null,
|
|
364
367
|
name: (version >= 22 && (flags & 8) !== 0) ? c.string.decode(state) : null,
|
|
365
368
|
id: (version >= 22 && (flags & 16) !== 0) ? c.string.decode(state) : null,
|
|
366
|
-
context: (version >= 22 && (flags & 32) !== 0) ? c.json.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
|
|
367
371
|
}
|
|
368
372
|
}
|
|
369
373
|
}
|
|
@@ -321,7 +321,7 @@ 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
|
|
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)
|
|
@@ -329,6 +329,7 @@ const encoding7 = {
|
|
|
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
331
|
if (version >= 22 && m.context) c.json.preencode(state, m.context)
|
|
332
|
+
if (version >= 22 && m.sentAt) c.uint.preencode(state, m.sentAt)
|
|
332
333
|
},
|
|
333
334
|
encode(state, m) {
|
|
334
335
|
const flags =
|
|
@@ -337,7 +338,8 @@ const encoding7 = {
|
|
|
337
338
|
((version >= 22 && m.toolCallId) ? 4 : 0) |
|
|
338
339
|
((version >= 22 && m.name) ? 8 : 0) |
|
|
339
340
|
((version >= 22 && m.id) ? 16 : 0) |
|
|
340
|
-
((version >= 22 && m.context) ? 32 : 0)
|
|
341
|
+
((version >= 22 && m.context) ? 32 : 0) |
|
|
342
|
+
((version >= 22 && m.sentAt) ? 64 : 0)
|
|
341
343
|
|
|
342
344
|
encoding5.encode(state, m.role)
|
|
343
345
|
c.string.encode(state, m.content)
|
|
@@ -349,6 +351,7 @@ const encoding7 = {
|
|
|
349
351
|
if (version >= 22 && m.name) c.string.encode(state, m.name)
|
|
350
352
|
if (version >= 22 && m.id) c.string.encode(state, m.id)
|
|
351
353
|
if (version >= 22 && m.context) c.json.encode(state, m.context)
|
|
354
|
+
if (version >= 22 && m.sentAt) c.uint.encode(state, m.sentAt)
|
|
352
355
|
},
|
|
353
356
|
decode(state) {
|
|
354
357
|
const r0 = encoding5.decode(state)
|
|
@@ -363,7 +366,8 @@ const encoding7 = {
|
|
|
363
366
|
toolCallId: (version >= 22 && (flags & 4) !== 0) ? c.string.decode(state) : null,
|
|
364
367
|
name: (version >= 22 && (flags & 8) !== 0) ? c.string.decode(state) : null,
|
|
365
368
|
id: (version >= 22 && (flags & 16) !== 0) ? c.string.decode(state) : null,
|
|
366
|
-
context: (version >= 22 && (flags & 32) !== 0) ? c.json.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
|
|
367
371
|
}
|
|
368
372
|
}
|
|
369
373
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qvac/harness",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
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.
|
|
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",
|