@qvac/harness 1.0.0-rc.17 → 1.0.0-rc.18

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 CHANGED
@@ -507,6 +507,28 @@ breaking change is listed under Changed and Removed.
507
507
 
508
508
  ### Changed
509
509
 
510
+ - **Breaking:** `@qvac/harness` no longer depends on `@qvac/skills`; the host
511
+ installs the skills version it ships and hands it in.
512
+ `Tools.bundledSkillsDir(bundle)` takes `{ skills, hash }` (what
513
+ `@qvac/skills/bundled` and `@qvac/skills/hash` export) and materializes it
514
+ under a directory keyed on that hash, refusing a tree that does not hash to
515
+ it as before. A `Harness` or a sidecar given no `skillsDir` serves no base
516
+ skills, only the user's overlay, where it used to materialize the bundled
517
+ ones, and `SidecarContext.skillsDir` is then `undefined`. `Tools.product`
518
+ adds `skill` for a `skillCatalog` that lists a skill even with no
519
+ `skillsDir`, so the overlay can be loaded. `@qvac/skills` names the oldest
520
+ harness that loads it as a peer dependency. (#837)
521
+
522
+ ```js
523
+ import { SKILLS } from '@qvac/skills/bundled'
524
+ import { SKILLS_HASH } from '@qvac/skills/hash'
525
+
526
+ // before
527
+ const skillsDir = await Tools.bundledSkillsDir()
528
+ // after
529
+ const skillsDir = await Tools.bundledSkillsDir({ skills: SKILLS, hash: SKILLS_HASH })
530
+ ```
531
+
510
532
  - Importing `@qvac/harness/plugins/image` or `@qvac/harness/plugins/music` no
511
533
  longer needs their peers; constructing `Image` or `Music` without them throws
512
534
  the error naming the plugin and the missing packages. A sidecar host passing no
@@ -248,6 +248,10 @@ declare const HARNESS_ERRORS: {
248
248
  readonly code: 102711;
249
249
  readonly message: () => string;
250
250
  };
251
+ readonly BUNDLED_SKILLS_HASH_INVALID: {
252
+ readonly code: 102712;
253
+ readonly message: (hash: string) => string;
254
+ };
251
255
  };
252
256
  type Errors = typeof HARNESS_ERRORS;
253
257
  export type HarnessErrorName = keyof Errors;
@@ -180,7 +180,11 @@ const HARNESS_ERRORS = {
180
180
  message: () => 'cannot fence the app storage root: the SDK home is unknown'
181
181
  },
182
182
  SLM_TRANSLATION_UNAVAILABLE: { code: 102710, message: () => 'slm translation is unavailable' },
183
- PDF_TEXT_UNAVAILABLE: { code: 102711, message: () => 'PDF text is not available on this device' }
183
+ PDF_TEXT_UNAVAILABLE: { code: 102711, message: () => 'PDF text is not available on this device' },
184
+ BUNDLED_SKILLS_HASH_INVALID: {
185
+ code: 102712,
186
+ message: (hash) => `bundled skills hash ${hash} is not 16 hex characters`
187
+ }
184
188
  };
185
189
  addCodes(Object.fromEntries(Object.entries(HARNESS_ERRORS).map(([name, { code, message }]) => [code, { name, message }])), { name: '@qvac/harness', version: `${Object.keys(HARNESS_ERRORS).length}.0.0` });
186
190
  export class HarnessError extends QvacErrorBase {
@@ -93,7 +93,7 @@ export function isoToSerial(value, date1904) {
93
93
  return { serial, time: match[4] !== undefined };
94
94
  }
95
95
  function formulaError(input, why) {
96
- return new DocsError('INVALID_FORMULA', `${JSON.stringify(input)} is not a formula (${why}); to store it as text use { value: ${JSON.stringify(input)} }`);
96
+ return new DocsError('INVALID_FORMULA', `${JSON.stringify(input)} is not a formula (${why}); to store it as text write ${JSON.stringify(`'${input}`)}`);
97
97
  }
98
98
  function parenthesisProblem(body) {
99
99
  let depth = 0;
@@ -140,15 +140,18 @@ function isCellValue(value) {
140
140
  typeof value === 'boolean' ||
141
141
  (typeof value === 'number' && Number.isFinite(value)));
142
142
  }
143
- function normalizeText(input) {
143
+ function normalizeText(input, style = {}) {
144
144
  if (input.length > 32767) {
145
145
  throw new DocsError('INVALID_VALUE', 'a cell holds at most 32767 characters');
146
146
  }
147
+ if (input.startsWith("'=")) {
148
+ return { content: true, value: input.slice(1), style };
149
+ }
147
150
  if (input.length > 1 && input.startsWith('=')) {
148
151
  checkFormula(input);
149
- return { content: true, formula: input, style: {} };
152
+ return { content: true, formula: input, style };
150
153
  }
151
- return { content: true, value: input, style: {} };
154
+ return { content: true, value: input, style };
152
155
  }
153
156
  function normalizeObject(input) {
154
157
  const { value, formula, date, ...style } = input;
@@ -175,6 +178,9 @@ function normalizeObject(input) {
175
178
  if (!isCellValue(value)) {
176
179
  throw new DocsError('INVALID_VALUE', 'value must be a string, a finite number, a boolean or null');
177
180
  }
181
+ if (typeof value === 'string') {
182
+ return normalizeText(value, style);
183
+ }
178
184
  return { content: true, value, style };
179
185
  }
180
186
  function normalize(input) {
@@ -11,7 +11,7 @@ import { type ImageClamps, type ImageModelSet, type MusicClamps } from '../model
11
11
  export interface SidecarContext {
12
12
  pluginOptions: HarnessPluginOptions;
13
13
  sdkStorage: SdkStorage;
14
- skillsDir: string;
14
+ skillsDir: string | undefined;
15
15
  skillCatalog: SkillCatalogEntry[] | undefined;
16
16
  credentialStore: CredentialStoreFn | undefined;
17
17
  imageModel: string | ImageModelSet | undefined;
@@ -60,16 +60,14 @@ export class HarnessSidecar {
60
60
  HarnessLog.setSink((line, level) => log[level](SCOPE, line));
61
61
  captureConsole(log);
62
62
  await alignSdkConsoleWithHost(hostWantsLogs);
63
- const skillsDir = argv[2] || (await Tools.bundledSkillsDir());
63
+ const skillsDir = argv[2] || undefined;
64
64
  if (argv[11]) {
65
65
  process.env.QVAC_PYTHON_WHEELS_DIR = argv[11];
66
66
  }
67
67
  configureSdkStorage(sdkStorage);
68
68
  process.env.QVAC_PYODIDE_CACHE_DIR = `${sdkStorage.home}/pyodide-cache`;
69
- const skillCatalog = skillsDir ? await loadSkillCatalog(skillsDir) : undefined;
70
- const credentialStore = skillCatalog
71
- ? (key, ctx) => harness?.resolveCredential(key, ctx) ?? null
72
- : undefined;
69
+ const skillCatalog = await loadSkillCatalog(skillsDir ?? null);
70
+ const credentialStore = (key, ctx) => harness?.resolveCredential(key, ctx) ?? null;
73
71
  const tools = Tools.product({
74
72
  sdkHome: sdkStorage.home,
75
73
  skillsDir,
@@ -4,7 +4,6 @@ import { errorMessage } from '../guards.js';
4
4
  import { HarnessLog } from '../log.js';
5
5
  import { modelNameToCapabilityProfile } from '../models/model-catalog.js';
6
6
  import { probeBinVersions } from '../tools/skills/bin-check.js';
7
- import { ensureBundledSkillsDir } from '../tools/skills/bundled-dir.js';
8
7
  import { availableSkills, detectPlatform, loadSkillCatalog, resolveSkillStatuses, skillSupportsPlatform, versionProbeSkills } from '../tools/skills/catalog.js';
9
8
  import { resetCredentialHealth } from '../tools/skills/credential-health.js';
10
9
  import { ensureSkillsOverlayDir } from '../tools/skills/overlay-dir.js';
@@ -98,10 +97,10 @@ export class SkillsHost {
98
97
  return this._allSkills.find((entry) => entry.name === skill)?.env;
99
98
  }
100
99
  async listManagedSkills() {
101
- return listManagedSkills(await this._baseDir(), await ensureSkillsOverlayDir());
100
+ return listManagedSkills(this._baseDir(), await ensureSkillsOverlayDir());
102
101
  }
103
102
  async readSkillFile(name) {
104
- return readSkillFile(await this._baseDir(), await ensureSkillsOverlayDir(), name);
103
+ return readSkillFile(this._baseDir(), await ensureSkillsOverlayDir(), name);
105
104
  }
106
105
  async writeSkillFile(name, content) {
107
106
  const overlay = await this._overlayDir();
@@ -111,7 +110,7 @@ export class SkillsHost {
111
110
  }
112
111
  async copyBaseForEdit(name) {
113
112
  const overlay = await this._overlayDir();
114
- const result = await copyBaseForEdit(await this._baseDir(), overlay, name);
113
+ const result = await copyBaseForEdit(this._baseDir(), overlay, name);
115
114
  if (result.copied) {
116
115
  await this._reload();
117
116
  }
@@ -186,8 +185,8 @@ export class SkillsHost {
186
185
  _installedTools() {
187
186
  return new Set(this._tools().map((tool) => tool.name));
188
187
  }
189
- async _baseDir() {
190
- return this._skillsDir ?? (await ensureBundledSkillsDir());
188
+ _baseDir() {
189
+ return this._skillsDir ?? null;
191
190
  }
192
191
  async _overlayDir() {
193
192
  const overlay = await ensureSkillsOverlayDir();
@@ -197,7 +196,7 @@ export class SkillsHost {
197
196
  return overlay;
198
197
  }
199
198
  async _reload() {
200
- this._allSkills = await loadSkillCatalog(await this._baseDir(), { platform: null });
199
+ this._allSkills = await loadSkillCatalog(this._baseDir(), { platform: null });
201
200
  this._filter();
202
201
  }
203
202
  _filter() {
@@ -6,6 +6,7 @@ import type { CredentialStoreFn } from './skills/auth-resolver.ts';
6
6
  import { ensureBundledSkillsDir } from './skills/bundled-dir.ts';
7
7
  import type { SkillCatalogEntry } from './skills/catalog.ts';
8
8
  export type { ExecInput } from './attachments/staging.ts';
9
+ export type { SkillsBundle } from './skills/bundled-dir.ts';
9
10
  export interface ProductToolsOptions {
10
11
  readonly sdkHome: string;
11
12
  readonly skillsDir?: string | undefined;
@@ -31,7 +31,7 @@ export class Tools {
31
31
  if (skillCatalog) {
32
32
  tools.push(...compileOperationTools(skillCatalog, { httpRequestTool }));
33
33
  }
34
- if (skillsDir) {
34
+ if (skillsDir || skillCatalog?.length) {
35
35
  tools.push(createSkillTool({ skillsDir }));
36
36
  }
37
37
  if (ask) {
@@ -1,2 +1,6 @@
1
- export declare function ensureBundledSkillsDir(): Promise<string>;
1
+ export interface SkillsBundle {
2
+ readonly skills: Readonly<Record<string, string>>;
3
+ readonly hash: string;
4
+ }
5
+ export declare function ensureBundledSkillsDir(bundle: SkillsBundle): Promise<string>;
2
6
  export declare function randomSuffix(): string;
@@ -5,18 +5,21 @@ import process from 'process';
5
5
  import { HarnessError } from '../../errors.js';
6
6
  import { userTmpPath } from '../../tmp-path.js';
7
7
  import { hashBundledSkills } from './bundled-hash.js';
8
- import { SKILLS as BUNDLED_SKILLS } from '@qvac/skills/bundled';
9
- import { SKILLS_HASH as BUNDLED_SKILLS_HASH } from '@qvac/skills/hash';
10
- let inflight = null;
11
- export function ensureBundledSkillsDir() {
12
- inflight ??= materialize().finally(() => {
13
- inflight = null;
14
- });
15
- return inflight;
8
+ const inflight = new Map();
9
+ export function ensureBundledSkillsDir(bundle) {
10
+ if (!/^[0-9a-f]{16}$/.test(bundle.hash)) {
11
+ return Promise.reject(new HarnessError('BUNDLED_SKILLS_HASH_INVALID', [bundle.hash]));
12
+ }
13
+ let pending = inflight.get(bundle.hash);
14
+ if (!pending) {
15
+ pending = materialize(bundle).finally(() => inflight.delete(bundle.hash));
16
+ inflight.set(bundle.hash, pending);
17
+ }
18
+ return pending;
16
19
  }
17
- async function materialize() {
18
- const dir = userTmpPath('qvac-harness-skills-' + BUNDLED_SKILLS_HASH);
19
- if (await validTree(dir)) {
20
+ async function materialize(bundle) {
21
+ const dir = userTmpPath('qvac-harness-skills-' + bundle.hash);
22
+ if (await validTree(dir, bundle.hash)) {
20
23
  return dir;
21
24
  }
22
25
  const staging = `${dir}-staging-${process.pid}-${randomSuffix()}`;
@@ -25,14 +28,14 @@ async function materialize() {
25
28
  await fs.promises.chmod(staging, 0o700);
26
29
  }
27
30
  try {
28
- await writeTree(staging);
29
- if (!(await validTree(staging))) {
31
+ await writeTree(staging, bundle.skills);
32
+ if (!(await validTree(staging, bundle.hash))) {
30
33
  throw new HarnessError('BUNDLED_SKILLS_INVALID', [staging]);
31
34
  }
32
35
  if (await tryRename(staging, dir)) {
33
36
  return dir;
34
37
  }
35
- if (await validTree(dir)) {
38
+ if (await validTree(dir, bundle.hash)) {
36
39
  return dir;
37
40
  }
38
41
  const trash = `${dir}.trash-${process.pid}-${randomSuffix()}`;
@@ -40,7 +43,7 @@ async function materialize() {
40
43
  await fs.promises.rename(dir, trash);
41
44
  }
42
45
  catch (err) {
43
- if (await validTree(dir)) {
46
+ if (await validTree(dir, bundle.hash)) {
44
47
  return dir;
45
48
  }
46
49
  throw occupiedError(dir, err);
@@ -49,7 +52,7 @@ async function materialize() {
49
52
  if (await tryRename(staging, dir)) {
50
53
  return dir;
51
54
  }
52
- if (await validTree(dir)) {
55
+ if (await validTree(dir, bundle.hash)) {
53
56
  return dir;
54
57
  }
55
58
  throw tamperError(dir);
@@ -77,14 +80,14 @@ async function tryRename(from, to) {
77
80
  return false;
78
81
  }
79
82
  }
80
- async function writeTree(dir) {
81
- for (const [relPath, content] of Object.entries(BUNDLED_SKILLS)) {
83
+ async function writeTree(dir, skills) {
84
+ for (const [relPath, content] of Object.entries(skills)) {
82
85
  const target = path.join(dir, relPath);
83
86
  await fs.promises.mkdir(path.dirname(target), { recursive: true });
84
87
  await fs.promises.writeFile(target, content);
85
88
  }
86
89
  }
87
- async function validTree(dir) {
90
+ async function validTree(dir, hash) {
88
91
  try {
89
92
  if (os.platform() !== 'win32') {
90
93
  const stat = await fs.promises.lstat(dir);
@@ -96,7 +99,7 @@ async function validTree(dir) {
96
99
  if (files === null) {
97
100
  return false;
98
101
  }
99
- return hashBundledSkills(files) === BUNDLED_SKILLS_HASH;
102
+ return hashBundledSkills(files) === hash;
100
103
  }
101
104
  catch {
102
105
  return false;
@@ -66,6 +66,6 @@ export interface LoadSkillCatalogOptions {
66
66
  platform?: string | null;
67
67
  overlayDir?: string | null;
68
68
  }
69
- export declare function loadSkillCatalog(skillsDir: string, { platform, overlayDir }?: LoadSkillCatalogOptions): Promise<SkillCatalogEntry[]>;
69
+ export declare function loadSkillCatalog(skillsDir: string | null, { platform, overlayDir }?: LoadSkillCatalogOptions): Promise<SkillCatalogEntry[]>;
70
70
  export declare function mcpReadMethods(catalog: readonly SkillCatalogEntry[]): ReadonlyMap<string, ReadonlySet<string>>;
71
71
  export declare function detectPlatform(): string;
@@ -65,7 +65,7 @@ function stripCredentialChecks(requires) {
65
65
  return rest;
66
66
  }
67
67
  export async function loadSkillCatalog(skillsDir, { platform = detectPlatform(), overlayDir = resolveSkillsOverlayDir() } = {}) {
68
- const byName = await loadRoot(skillsDir);
68
+ const byName = skillsDir ? await loadRoot(skillsDir) : new Map();
69
69
  if (overlayDir) {
70
70
  for (const [name, overlay] of await loadRoot(overlayDir, 'overlay')) {
71
71
  byName.set(name, mergeOverlay(byName.get(name), overlay));
@@ -7,13 +7,13 @@ export interface SkillFileContent {
7
7
  readonly content: string;
8
8
  readonly origin: 'base' | 'overlay';
9
9
  }
10
- export declare function listManagedSkills(baseDir: string, overlayDir: string | null): Promise<ManagedSkill[]>;
11
- export declare function readSkillFile(baseDir: string, overlayDir: string | null, name: string): Promise<SkillFileContent | null>;
10
+ export declare function listManagedSkills(baseDir: string | null, overlayDir: string | null): Promise<ManagedSkill[]>;
11
+ export declare function readSkillFile(baseDir: string | null, overlayDir: string | null, name: string): Promise<SkillFileContent | null>;
12
12
  export declare function writeSkillFile(overlayDir: string, name: string, content: string): Promise<string>;
13
13
  export interface CopyBaseResult {
14
14
  copied: boolean;
15
15
  }
16
- export declare function copyBaseForEdit(baseDir: string, overlayDir: string, name: string): Promise<CopyBaseResult>;
16
+ export declare function copyBaseForEdit(baseDir: string | null, overlayDir: string, name: string): Promise<CopyBaseResult>;
17
17
  export interface DeleteOverlayResult {
18
18
  removed: boolean;
19
19
  }
@@ -26,7 +26,7 @@ async function readIfPresent(file) {
26
26
  }
27
27
  }
28
28
  export async function listManagedSkills(baseDir, overlayDir) {
29
- const base = await dirNames(baseDir);
29
+ const base = baseDir ? await dirNames(baseDir) : new Set();
30
30
  const overlay = overlayDir ? await dirNames(overlayDir) : new Set();
31
31
  const names = [...new Set([...base, ...overlay])].sort((a, b) => a.localeCompare(b));
32
32
  return names.map((name) => {
@@ -46,7 +46,7 @@ export async function readSkillFile(baseDir, overlayDir, name) {
46
46
  return { content: over, origin: 'overlay' };
47
47
  }
48
48
  }
49
- const base = await readIfPresent(path.join(baseDir, name, 'SKILL.md'));
49
+ const base = baseDir ? await readIfPresent(path.join(baseDir, name, 'SKILL.md')) : null;
50
50
  return base !== null ? { content: base, origin: 'base' } : null;
51
51
  }
52
52
  export async function writeSkillFile(overlayDir, name, content) {
@@ -65,8 +65,8 @@ export async function copyBaseForEdit(baseDir, overlayDir, name) {
65
65
  if (await exists(dest)) {
66
66
  return { copied: false };
67
67
  }
68
- const src = path.join(baseDir, name);
69
- if (!(await exists(src))) {
68
+ const src = baseDir && path.join(baseDir, name);
69
+ if (!src || !(await exists(src))) {
70
70
  throw new HarnessError('SKILL_NOT_FOUND', [name]);
71
71
  }
72
72
  await copyDir(src, dest);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qvac/harness",
3
- "version": "1.0.0-rc.17",
3
+ "version": "1.0.0-rc.18",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "bare": ">=1.33.4",
@@ -589,7 +589,6 @@
589
589
  "@qvac/error": "^0.1.1",
590
590
  "@qvac/inference": "^0.23.0",
591
591
  "@qvac/logging": "0.1.1",
592
- "@qvac/skills": "^0.1.20",
593
592
  "@xmldom/xmldom": "^0.9.12",
594
593
  "asenion": "^0.1.0",
595
594
  "b4a": "^1.9.0",
@@ -745,6 +744,7 @@
745
744
  "@qvac/llm-llamacpp": "^0.65.0",
746
745
  "@qvac/ocr-ggml": "^0.31.0",
747
746
  "@qvac/sdk": "^0.23.0",
747
+ "@qvac/skills": "^0.1.20",
748
748
  "@qvac/translation-nmtcpp": "^0.23.0",
749
749
  "@qvac/tts-ggml": "^0.14.0",
750
750
  "@qvac/turbovec-ggml": "^0.3.1",