@qvac/harness 0.8.6 → 0.8.8

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 (61) hide show
  1. package/CHANGELOG.md +1298 -507
  2. package/dist-lib/index.d.ts +11 -0
  3. package/dist-lib/index.js +102 -25
  4. package/dist-lib/lib/capabilities/completion.d.ts +5 -4
  5. package/dist-lib/lib/capabilities/completion.js +132 -64
  6. package/dist-lib/lib/capabilities/tool-selection.d.ts +1 -3
  7. package/dist-lib/lib/capabilities/tool-selection.js +2 -4
  8. package/dist-lib/lib/capabilities/tool-turns.d.ts +0 -1
  9. package/dist-lib/lib/capabilities/tool-turns.js +0 -6
  10. package/dist-lib/lib/connect.js +3 -0
  11. package/dist-lib/lib/contract-types.d.ts +2 -0
  12. package/dist-lib/lib/helpers/tool-call-markup.d.ts +1 -0
  13. package/dist-lib/lib/helpers/tool-call-markup.js +3 -0
  14. package/dist-lib/lib/models/context-choice.d.ts +15 -0
  15. package/dist-lib/lib/models/context-choice.js +55 -0
  16. package/dist-lib/lib/models/model-pool.d.ts +3 -1
  17. package/dist-lib/lib/models/model-pool.js +8 -11
  18. package/dist-lib/lib/models/sdk-faults.d.ts +1 -0
  19. package/dist-lib/lib/models/sdk-faults.js +6 -0
  20. package/dist-lib/lib/office/engine/pptx/picture-area.d.ts +23 -0
  21. package/dist-lib/lib/office/engine/pptx/picture-area.js +84 -0
  22. package/dist-lib/lib/office/engine/pptx/presentation.d.ts +2 -0
  23. package/dist-lib/lib/office/engine/pptx/presentation.js +55 -17
  24. package/dist-lib/lib/office/engine/pptx/types.d.ts +1 -0
  25. package/dist-lib/lib/office/engine/xlsx/workbook.d.ts +1 -0
  26. package/dist-lib/lib/office/engine/xlsx/workbook.js +34 -3
  27. package/dist-lib/lib/serve.js +6 -1
  28. package/dist-lib/lib/spawn.js +4 -10
  29. package/dist-lib/lib/tools/exec.d.ts +4 -1
  30. package/dist-lib/lib/tools/exec.js +55 -11
  31. package/dist-lib/lib/tools/file-glob.js +1 -0
  32. package/dist-lib/lib/tools/grep.js +1 -0
  33. package/dist-lib/lib/tools/office/ops.js +1 -1
  34. package/dist-lib/lib/tools/office.js +29 -6
  35. package/dist-lib/lib/tools/read-files.js +1 -0
  36. package/dist-lib/lib/tools/skill.js +6 -4
  37. package/dist-lib/lib/tools/skills/catalog.d.ts +2 -0
  38. package/dist-lib/lib/tools/skills/catalog.js +4 -0
  39. package/dist-lib/lib/tools/skills/cli-schema-check.d.ts +1 -0
  40. package/dist-lib/lib/tools/skills/cli-schema-check.js +3 -0
  41. package/dist-lib/lib/tools/skills/cli-schema-load.js +10 -0
  42. package/dist-lib/lib/tools/skills/cli-schema-types.d.ts +2 -0
  43. package/dist-lib/lib/tools/skills/cli-schema.js +6 -3
  44. package/dist-lib/lib/tools/skills/frontmatter-parser.d.ts +2 -0
  45. package/dist-lib/lib/tools/skills/frontmatter-parser.js +4 -0
  46. package/dist-lib/lib/tools/skills/manifest-parse.d.ts +1 -0
  47. package/dist-lib/lib/tools/skills/manifest-parse.js +12 -0
  48. package/dist-lib/lib/tools/skills/mention-name.d.ts +6 -0
  49. package/dist-lib/lib/tools/skills/mention-name.js +6 -0
  50. package/dist-lib/lib/tools/skills/mention.d.ts +2 -3
  51. package/dist-lib/lib/tools/skills/mention.js +5 -6
  52. package/dist-lib/lib/tools/weather-lookup.js +1 -0
  53. package/dist-lib/lib/tools/web-fetch.js +1 -0
  54. package/dist-lib/lib/tools/web-search.js +1 -0
  55. package/dist-lib/schema/harness.js +4 -2
  56. package/dist-lib/spec/hrpc/messages.js +18 -8
  57. package/dist-lib/spec/hyperschema/index.js +18 -8
  58. package/dist-lib/spec/hyperschema/schema.json +11 -1
  59. package/dist-lib/spec/hyperschema/types.d.ts +3 -1
  60. package/package.json +5 -7
  61. package/worker/harness-sidecar.mjs +2 -1
@@ -25,6 +25,7 @@ export interface Admission {
25
25
  release(): void;
26
26
  }
27
27
  export type BeforeLoad = (load: PendingLoad) => Promise<Admission | undefined>;
28
+ export type ChooseContext = (load: PendingLoad, tier: number) => Promise<number>;
28
29
  export interface LlmDeviceConfig {
29
30
  device?: 'cpu' | 'gpu';
30
31
  gpuLayers?: number;
@@ -157,9 +158,10 @@ export interface ModelPoolOptions {
157
158
  deviceConfig?: LlmDeviceConfig;
158
159
  loads?: LoadTracker;
159
160
  beforeLoad?: BeforeLoad;
161
+ chooseContext?: ChooseContext;
160
162
  hold?: HoldFn;
161
163
  }
162
- export declare function createModelPool(loadSdk: LoadSdk, notify: NotifyFn, { deviceConfig, loads, beforeLoad, hold }?: ModelPoolOptions): ModelPuddle;
164
+ export declare function createModelPool(loadSdk: LoadSdk, notify: NotifyFn, { deviceConfig, loads, beforeLoad, chooseContext, hold }?: ModelPoolOptions): ModelPuddle;
163
165
  export interface EmbedPoolOptions {
164
166
  faults: GpuFaultState;
165
167
  batchSize?: number;
@@ -357,12 +357,12 @@ export function loadClockGuard(model, sdk, { now = () => Date.now(), monoMs = mo
357
357
  };
358
358
  return { race };
359
359
  }
360
- export function createModelPool(loadSdk, notify, { deviceConfig = {}, loads = createLoadTracker(), beforeLoad, hold } = {}) {
360
+ export function createModelPool(loadSdk, notify, { deviceConfig = {}, loads = createLoadTracker(), beforeLoad, chooseContext, hold } = {}) {
361
361
  const load = async (key, model, opts) => {
362
362
  const sdk = await loadSdk();
363
363
  const modelSrc = await resolveModelSrc(sdk, model);
364
364
  const resolved = resolveLoadOptions(opts, deviceConfig);
365
- const ctxSize = resolved.ctxSize || defaultContextSize(modelSrc, customContextLength(model));
365
+ const tier = defaultContextSize(modelSrc, customContextLength(model));
366
366
  const projectionModelSrc = resolved.projectionModel
367
367
  ? await resolveModelSrc(sdk, resolved.projectionModel)
368
368
  : undefined;
@@ -376,11 +376,10 @@ export function createModelPool(loadSdk, notify, { deviceConfig = {}, loads = cr
376
376
  const openclCache = deviceConfig.device !== 'cpu' && deviceConfig.openclCacheDir
377
377
  ? deviceConfig.openclCacheDir()
378
378
  : undefined;
379
- const modelConfig = definedFields({
379
+ const config = definedFields({
380
380
  verbosity: llmVerbosity(),
381
381
  tools: true,
382
382
  stop_sequences: RUNAWAY_STOP_SEQUENCES,
383
- ctx_size: ctxSize,
384
383
  'cache-type-k': kvCache.k,
385
384
  'cache-type-v': kvCache.v,
386
385
  projectionModelSrc,
@@ -389,15 +388,13 @@ export function createModelPool(loadSdk, notify, { deviceConfig = {}, loads = cr
389
388
  'main-gpu': mainGpu,
390
389
  openclCacheDir: openclCache || undefined
391
390
  });
391
+ const pending = { key, model, modelSrc, modelType: 'llamacpp-completion' };
392
+ const ctxSize = resolved.ctxSize ||
393
+ (chooseContext ? await chooseContext({ ...pending, modelConfig: config }, tier) : tier);
394
+ const modelConfig = { ...config, ctx_size: ctxSize };
392
395
  const { projectionModelSrc: projection, ...loggedConfig } = modelConfig;
393
396
  hlog('llm load config', { model, projection: Boolean(projection), ...loggedConfig });
394
- const admission = await beforeLoad?.({
395
- key,
396
- model,
397
- modelSrc,
398
- modelType: 'llamacpp-completion',
399
- modelConfig
400
- });
397
+ const admission = await beforeLoad?.({ ...pending, modelConfig });
401
398
  const loadStarted = Date.now();
402
399
  const modelId = await loadClockGuard(model, sdk)
403
400
  .race(loads.track(sdk.loadModel({
@@ -1,6 +1,7 @@
1
1
  import type { EmbedDevice } from './embed-config.ts';
2
2
  export declare function isSdkGpuDeviceLostError(err: unknown): boolean;
3
3
  export declare function isSdkModelWedgedError(err: unknown): boolean;
4
+ export declare function isGrammarOverrunError(err: unknown): boolean;
4
5
  export declare function isContextOverflowError(err: unknown): boolean;
5
6
  export type GpuFaultDecision = 'reload' | 'fallback';
6
7
  interface GpuFaultEscalation {
@@ -16,6 +16,12 @@ export function isSdkModelWedgedError(err) {
16
16
  }
17
17
  return /failed to (decode next token|eval chunk)/i.test(message);
18
18
  }
19
+ export function isGrammarOverrunError(err) {
20
+ if (typeof err !== 'object' || err === null)
21
+ return false;
22
+ const message = 'message' in err ? err.message : undefined;
23
+ return typeof message === 'string' && /empty grammar stack/i.test(message);
24
+ }
19
25
  export function isContextOverflowError(err) {
20
26
  if (typeof err !== 'object' || err === null)
21
27
  return false;
@@ -0,0 +1,23 @@
1
+ import type { Box } from './inherit.ts';
2
+ import type { SlideSize } from './template.ts';
3
+ export type Role = 'slot' | 'blank' | 'body' | 'picture' | 'other';
4
+ export interface Size {
5
+ readonly width: number;
6
+ readonly height: number;
7
+ }
8
+ export interface Placed {
9
+ readonly box: Box;
10
+ readonly role: Role;
11
+ }
12
+ export interface Beside<T> {
13
+ readonly shape: T;
14
+ readonly box: Box;
15
+ }
16
+ export interface Area<T> {
17
+ readonly box: Box;
18
+ readonly cleared: readonly T[];
19
+ readonly beside: Beside<T> | null;
20
+ }
21
+ export declare function framed(slide: SlideSize): Box;
22
+ export declare function fitted(size: Size, area: Box): Box;
23
+ export declare function pictureArea<T extends Placed>(slide: SlideSize, shapes: readonly T[]): Area<T>;
@@ -0,0 +1,84 @@
1
+ const FRAME = 0.8;
2
+ const MARGIN = 0.03;
3
+ const MIN_BAND = 0.15;
4
+ const MIN_SPLIT = 0.5;
5
+ export function framed(slide) {
6
+ return {
7
+ x: Math.round((slide.width * (1 - FRAME)) / 2),
8
+ y: Math.round((slide.height * (1 - FRAME)) / 2),
9
+ width: Math.round(slide.width * FRAME),
10
+ height: Math.round(slide.height * FRAME)
11
+ };
12
+ }
13
+ export function fitted(size, area) {
14
+ const scale = Math.min(area.width / size.width, area.height / size.height);
15
+ const width = Math.round(size.width * scale);
16
+ const height = Math.round(size.height * scale);
17
+ return {
18
+ x: area.x + Math.round((area.width - width) / 2),
19
+ y: area.y + Math.round((area.height - height) / 2),
20
+ width,
21
+ height
22
+ };
23
+ }
24
+ function bandBelow(slide, shapes, margin) {
25
+ const top = Math.max(...shapes.map(({ box }) => box.y + box.height)) + margin;
26
+ const band = {
27
+ x: margin,
28
+ y: top,
29
+ width: slide.width - 2 * margin,
30
+ height: slide.height - top - margin
31
+ };
32
+ return band.height >= slide.height * MIN_BAND ? band : null;
33
+ }
34
+ function halves(box, gap) {
35
+ if (box.width >= box.height) {
36
+ const half = Math.round((box.width - gap) / 2);
37
+ const rest = box.width - half - gap;
38
+ return [
39
+ { ...box, width: half },
40
+ { ...box, x: box.x + half + gap, width: rest }
41
+ ];
42
+ }
43
+ const half = Math.round((box.height - gap) / 2);
44
+ const rest = box.height - half - gap;
45
+ return [
46
+ { ...box, height: half },
47
+ { ...box, y: box.y + half + gap, height: rest }
48
+ ];
49
+ }
50
+ function split(shape, gap) {
51
+ const [kept, freed] = halves(shape.box, gap);
52
+ const box = shape.role === 'picture' ? fitted(shape.box, kept) : kept;
53
+ return { box: freed, cleared: [], beside: { shape, box } };
54
+ }
55
+ function largest(shapes) {
56
+ return shapes.reduce((best, shape) => !best || shape.box.width * shape.box.height > best.box.width * best.box.height ? shape : best, undefined);
57
+ }
58
+ function overlaps(a, b) {
59
+ return a.x < b.x + b.width && b.x < a.x + a.width && a.y < b.y + b.height && b.y < a.y + a.height;
60
+ }
61
+ function place(slide, shapes) {
62
+ const slot = shapes.find((shape) => shape.role === 'slot');
63
+ if (slot) {
64
+ return { box: slot.box, cleared: [slot], beside: null };
65
+ }
66
+ const whole = { box: framed(slide), cleared: [], beside: null };
67
+ if (!shapes.length) {
68
+ return whole;
69
+ }
70
+ const margin = Math.round(slide.height * MARGIN);
71
+ const band = bandBelow(slide, shapes, margin);
72
+ if (band) {
73
+ return { box: band, cleared: [], beside: null };
74
+ }
75
+ const bodies = shapes.filter((shape) => shape.role === 'body');
76
+ const wide = bodies.filter((shape) => shape.box.width >= slide.width * MIN_SPLIT);
77
+ const shared = largest(wide) ?? largest(shapes.filter((shape) => shape.role === 'picture')) ?? largest(bodies);
78
+ return shared ? split(shared, margin) : whole;
79
+ }
80
+ export function pictureArea(slide, shapes) {
81
+ const area = place(slide, shapes.filter((shape) => shape.role !== 'blank'));
82
+ const covered = shapes.filter((shape) => shape.role === 'blank' && overlaps(shape.box, area.box));
83
+ return { ...area, cleared: [...area.cleared, ...covered] };
84
+ }
@@ -50,5 +50,7 @@ export declare class Presentation {
50
50
  private chartOf;
51
51
  private chartPart;
52
52
  private box;
53
+ private narrow;
54
+ private pictureArea;
53
55
  private pictureBox;
54
56
  }
@@ -12,6 +12,7 @@ import * as fit from './fit.js';
12
12
  import * as template from './template.js';
13
13
  import * as slides from './slides.js';
14
14
  import * as notes from './notes.js';
15
+ import { fitted, framed, pictureArea } from './picture-area.js';
15
16
  import { pick, describe, layoutName, layoutType, BODY_TYPES } from './read.js';
16
17
  import { SHAPE_ORDER, shapesOf, placeholderFrom, pictureElement, textBoxElement, tableElement, chartFrameElement, setBackground, nextShapeId } from './shapes.js';
17
18
  const { a: A, p: P, r: R, p14: P14 } = xml.ns;
@@ -154,16 +155,19 @@ function checkSlideText(doc, at, opts) {
154
155
  }
155
156
  }
156
157
  }
157
- function fitted(info, current) {
158
- const scale = Math.min(current.width / info.width, current.height / info.height);
159
- const width = Math.round(info.width * scale);
160
- const height = Math.round(info.height * scale);
161
- return {
162
- x: current.x + Math.round((current.width - width) / 2),
163
- y: current.y + Math.round((current.height - height) / 2),
164
- width,
165
- height
166
- };
158
+ function roleOf(shape) {
159
+ const { el, kind, placeholder } = shape;
160
+ if (kind === 'picture') {
161
+ return 'picture';
162
+ }
163
+ if (el.localName !== 'sp' || !placeholder || !BODY_TYPES.has(placeholder)) {
164
+ return 'other';
165
+ }
166
+ const txBody = xml.child(el, P, 'txBody');
167
+ if (txBody && text.readParagraphs(txBody).some((p) => p.text.trim())) {
168
+ return placeholder === 'subTitle' ? 'other' : 'body';
169
+ }
170
+ return placeholder === 'obj' ? 'slot' : 'blank';
167
171
  }
168
172
  function tableBody(tc) {
169
173
  const existing = xml.child(tc, A, 'txBody');
@@ -366,6 +370,9 @@ export class Presentation {
366
370
  const layoutDoc = this.package.xml(layout);
367
371
  const doc = slideFromLayout(layoutDoc);
368
372
  checkSlideText(doc, at, opts);
373
+ if (opts.image !== undefined) {
374
+ probe(opts.image);
375
+ }
369
376
  this.insertSlide({ doc, layout, at, ids: all.map((e) => e.id), before: all[at]?.el ?? null });
370
377
  if (opts.title !== undefined) {
371
378
  this.setText({ slide: at, shape: 'title' }, opts.title);
@@ -373,14 +380,25 @@ export class Presentation {
373
380
  if (opts.body !== undefined) {
374
381
  this.setText({ slide: at, shape: 'body' }, opts.body);
375
382
  }
376
- return { index: at, layout: layoutName(layoutDoc), shapes: shapesOf(doc).map(describe) };
383
+ if (opts.image !== undefined) {
384
+ this.addPicture(at, opts.image);
385
+ }
386
+ const shapes = shapesOf(this.package.xml(slides.slideAt(this.deck, at).part));
387
+ return { index: at, layout: layoutName(layoutDoc), shapes: shapes.map(describe) };
377
388
  }
378
389
  addPicture(slide, bytes, opts = {}) {
379
390
  const entry = slides.slideAt(this.deck, slide);
380
- const box = this.pictureBox(probe(bytes), opts);
391
+ const area = this.pictureArea(entry.part, opts);
392
+ const box = this.pictureBox(probe(bytes), opts, area.box);
381
393
  const { rId } = media.addImage(this.package, bytes, { source: entry.part, dir: '../media' });
382
394
  const doc = this.package.xml(entry.part);
383
395
  const id = nextShapeId(doc);
396
+ for (const shape of area.cleared) {
397
+ xml.remove(shape.el);
398
+ }
399
+ if (area.beside) {
400
+ this.narrow(entry.part, area.beside);
401
+ }
384
402
  this.spTree(entry.part).appendChild(pictureElement(doc, { id, rId, box, name: opts.name, description: opts.description }));
385
403
  this.package.touch(entry.part);
386
404
  return { id, ...box };
@@ -722,14 +740,34 @@ export class Presentation {
722
740
  }
723
741
  return box;
724
742
  }
725
- pictureBox(info, opts) {
743
+ narrow(part, { shape, box }) {
744
+ writeXfrm(shape.el, box);
745
+ const txBody = xml.child(shape.el, P, 'txBody');
746
+ const estimate = txBody ? this.estimate(part, shape.el, txBody) : null;
747
+ if (txBody && estimate?.overflow) {
748
+ applyAutofit(txBody, estimate);
749
+ }
750
+ }
751
+ pictureArea(part, opts) {
752
+ if (opts.x !== undefined || opts.y !== undefined) {
753
+ return { box: framed(this.slideSize), cleared: [], beside: null };
754
+ }
755
+ const shapes = shapesOf(this.package.xml(part)).flatMap((shape) => {
756
+ if (shape.group !== null || SKIPPED_PLACEHOLDERS.has(shape.placeholder ?? '')) {
757
+ return [];
758
+ }
759
+ const box = inherit.box({ pkg: this.package, slide: part, el: shape.el });
760
+ return box ? [{ el: shape.el, box, role: roleOf(shape) }] : [];
761
+ });
762
+ return pictureArea(this.slideSize, shapes);
763
+ }
764
+ pictureBox(info, opts, area) {
726
765
  checkPlacement(opts);
727
- const slide = this.slideSize;
728
766
  const ratio = info.height / info.width;
729
767
  let { width, height } = opts;
730
768
  if (width === undefined && height === undefined) {
731
769
  const natural = { width: info.width * EMU_PER_PIXEL, height: info.height * EMU_PER_PIXEL };
732
- const scale = Math.min(1, (slide.width * 0.8) / natural.width, (slide.height * 0.8) / natural.height);
770
+ const scale = Math.min(1, area.width / natural.width, area.height / natural.height);
733
771
  width = Math.round(natural.width * scale);
734
772
  height = Math.round(natural.height * scale);
735
773
  }
@@ -742,8 +780,8 @@ export class Presentation {
742
780
  if (!width || !height) {
743
781
  throw new DocsError('INVALID_BOX', 'the picture would have no visible size');
744
782
  }
745
- const x = opts.x ?? Math.max(0, Math.round((slide.width - width) / 2));
746
- const y = opts.y ?? Math.max(0, Math.round((slide.height - height) / 2));
783
+ const x = opts.x ?? Math.max(0, area.x + Math.round((area.width - width) / 2));
784
+ const y = opts.y ?? Math.max(0, area.y + Math.round((area.height - height) / 2));
747
785
  return { x, y, width, height };
748
786
  }
749
787
  }
@@ -61,6 +61,7 @@ export interface AddSlideOptions {
61
61
  at?: number;
62
62
  title?: TextInput;
63
63
  body?: TextInput;
64
+ image?: Uint8Array;
64
65
  }
65
66
  export interface AddedSlide {
66
67
  index: number;
@@ -156,6 +156,7 @@ export declare class Workbook {
156
156
  private ownCharts;
157
157
  private rangeValues;
158
158
  private besideData;
159
+ private rowsBelowDrawings;
159
160
  private drawingOf;
160
161
  private ensureDrawing;
161
162
  }
@@ -2,6 +2,7 @@ import { Package } from '../opc/package.js';
2
2
  import * as xml from '../xml.js';
3
3
  import * as media from '../opc/media.js';
4
4
  import { probe } from '../image.js';
5
+ import { points } from '../units.js';
5
6
  import * as refs from './refs.js';
6
7
  import * as formula from './formula.js';
7
8
  import { Sheet, SHEET_ORDER } from './sheet.js';
@@ -170,6 +171,12 @@ function pictureAnchor(doc, anchor, spec) {
170
171
  root.appendChild(d('clientData'));
171
172
  return root;
172
173
  }
174
+ function markerCell(marker) {
175
+ return {
176
+ row: Number(xml.text(xml.child(marker, XDR, 'row'))),
177
+ col: Number(xml.text(xml.child(marker, XDR, 'col')))
178
+ };
179
+ }
173
180
  function nextDrawingId(doc) {
174
181
  return (Math.max(0, ...xml.descendants(doc, XDR, 'cNvPr').map((el) => Number(el.getAttribute('id')) || 0)) + 1);
175
182
  }
@@ -421,7 +428,7 @@ export class Workbook {
421
428
  const target = this.sheet(sheet);
422
429
  const info = probe(bytes);
423
430
  const o = isRecord(opts) ? opts : {};
424
- const at = refs.parse(o.cell === undefined ? 'A1' : o.cell);
431
+ const at = o.cell === undefined ? this.besideData(target) : refs.parse(o.cell);
425
432
  const size = imageSize(o, info);
426
433
  const drawing = this.ensureDrawing(target);
427
434
  const { rId } = media.addImage(this.package, bytes, { source: drawing, dir: '../media' });
@@ -791,7 +798,8 @@ export class Workbook {
791
798
  const from = xml.child(anchor, XDR, 'from');
792
799
  const info = chart.readChart(this.package.xml(rel.part));
793
800
  if (from) {
794
- info.cell = refs.cell(Number(xml.text(xml.child(from, XDR, 'row'))), Number(xml.text(xml.child(from, XDR, 'col'))));
801
+ const { row, col } = markerCell(from);
802
+ info.cell = refs.cell(row, col);
795
803
  }
796
804
  out.push(info);
797
805
  }
@@ -823,7 +831,30 @@ export class Workbook {
823
831
  }
824
832
  besideData(sheet) {
825
833
  const used = sheet.usedRange();
826
- return used ? { row: used.top, col: used.right + 2 } : { row: 0, col: 0 };
834
+ const col = used ? used.right + 2 : 0;
835
+ return { row: Math.max(used ? used.top : 0, ...this.rowsBelowDrawings(sheet, col)), col };
836
+ }
837
+ rowsBelowDrawings(sheet, col) {
838
+ const drawing = this.drawingOf(sheet);
839
+ if (!drawing) {
840
+ return [];
841
+ }
842
+ const format = xml.child(sheet.root, X, 'sheetFormatPr');
843
+ const rowHeight = points(Number(format?.getAttribute('defaultRowHeight') ?? 15));
844
+ return xml.children(this.package.root(drawing), XDR).flatMap((anchor) => {
845
+ const from = xml.child(anchor, XDR, 'from');
846
+ if (!from || markerCell(from).col !== col) {
847
+ return [];
848
+ }
849
+ const to = xml.child(anchor, XDR, 'to');
850
+ if (to) {
851
+ return [markerCell(to).row + 2];
852
+ }
853
+ const ext = xml.child(anchor, XDR, 'ext');
854
+ return ext
855
+ ? [markerCell(from).row + Math.ceil(Number(ext.getAttribute('cy')) / rowHeight) + 1]
856
+ : [];
857
+ });
827
858
  }
828
859
  drawingOf(sheet) {
829
860
  const ref = xml.child(sheet.root, X, 'drawing');
@@ -8,7 +8,7 @@ import HRPC from '../spec/hrpc/index.js';
8
8
  import { isCapability } from './capabilities/invoke.js';
9
9
  import { CUSTOM_TASK_TYPES } from './models/model-catalog.js';
10
10
  import { unsupportedKvCacheDeletion } from './capabilities/kv-cache.js';
11
- import { errorMessage } from './guards.js';
11
+ import { errorMessage, isRecord } from './guards.js';
12
12
  import { hlog } from './log.js';
13
13
  import { pushQueue } from './queue.js';
14
14
  import { TextCoalescer } from './helpers/text-coalescer.js';
@@ -236,6 +236,7 @@ function toWireSkill(skill) {
236
236
  }));
237
237
  return {
238
238
  name: skill.name,
239
+ displayName: skill.displayName || undefined,
239
240
  description: skill.description,
240
241
  tools: skill.tools,
241
242
  credentials: skill.credentials,
@@ -525,10 +526,14 @@ function completion(harness) {
525
526
  model: frame.model ?? '',
526
527
  agent: frame.agent ?? {},
527
528
  cacheKey: frame.cacheKey ?? undefined,
529
+ session: frame.session ?? undefined,
528
530
  thinkingDefault: frame.thinkingDefault ?? undefined,
529
531
  generationParams: frame.generationParams ?? undefined,
530
532
  responseFormat: frame.responseFormat ?? undefined,
531
533
  captureInferenceCalls: frame.captureInferenceCalls ?? undefined,
534
+ typedText: isRecord(frame.payload) && typeof frame.payload.typedText === 'string'
535
+ ? frame.payload.typedText
536
+ : undefined,
532
537
  messages: (frame.messages ?? []).map(({ role, content, attachments }) => ({
533
538
  role,
534
539
  content,
@@ -46,9 +46,8 @@ export function spawnHarness(opts) {
46
46
  batchSize: opts.embedBatchSize
47
47
  });
48
48
  return connectHarness(async () => {
49
- const { default: Sidecar } = await import('bare-sidecar');
50
- const { wrap } = await import('bare-stow/host');
51
- const sidecar = new Sidecar(opts.entry, [
49
+ const { default: launch } = await import('bare-supervisor/runner/sidecar');
50
+ const { ipc, exit } = launch(opts.entry, [
52
51
  opts.skillsDir ?? '',
53
52
  JSON.stringify(opts.sdkStorage),
54
53
  JSON.stringify(embedConfig),
@@ -60,13 +59,8 @@ export function spawnHarness(opts) {
60
59
  opts.musicClamps ? JSON.stringify(opts.musicClamps) : '',
61
60
  opts.wheelsDir ?? '',
62
61
  opts.gpuStats === undefined ? '' : JSON.stringify(opts.gpuStats)
63
- ]);
64
- sidecar.stdout.on('data', (data) => logger?.info('harness', data.toString().trimEnd()));
65
- sidecar.stderr.on('data', (data) => logger?.warn('harness', data.toString().trimEnd()));
66
- const ipc = wrap(sidecar);
67
- const died = new Promise((resolve) => {
68
- sidecar.once('exit', (code) => resolve(`harness exited (${code}) before ready`));
69
- });
62
+ ], logger);
63
+ const died = exit.then((code) => `harness exited (${code}) before ready`);
70
64
  const failure = await Promise.race([ipc.ready.then(() => null), died]);
71
65
  if (failure) {
72
66
  throw new Error(failure);
@@ -14,6 +14,7 @@ export interface ExecToolOptions {
14
14
  readonly pythonNetwork?: boolean;
15
15
  readonly credentialStore?: CredentialStoreFn;
16
16
  readonly skillSettings?: SkillSettingsFn;
17
+ readonly skillEnv?: SkillEnvFn;
17
18
  readonly realpath?: Realpath;
18
19
  readonly deniedRoots?: readonly string[];
19
20
  readonly skillsDir?: string;
@@ -23,4 +24,6 @@ export interface ScriptRun {
23
24
  trusted: boolean;
24
25
  }
25
26
  export declare function resolveScriptRun(rawArgs: Record<string, unknown>, skillsDir: string | undefined): ScriptRun | ExecError | null;
26
- export declare function createExecTool({ spawn, killProcess, loadPyodide, disablePyodide, pythonNetwork, credentialStore, skillSettings, realpath, deniedRoots, skillsDir }?: ExecToolOptions): ToolDefinition;
27
+ export type SkillEnvFn = (skill: string) => Readonly<Record<string, string>> | undefined;
28
+ export declare function declaredEnv(declared: Readonly<Record<string, string>> | undefined, session: string | undefined): Record<string, string>;
29
+ export declare function createExecTool({ spawn, killProcess, loadPyodide, disablePyodide, pythonNetwork, credentialStore, skillSettings, skillEnv, realpath, deniedRoots, skillsDir }?: ExecToolOptions): ToolDefinition;
@@ -6,7 +6,7 @@ import { namedHosts } from './exec/adapters/python/named-hosts.js';
6
6
  import { pythonReachesNetwork } from './exec/adapters/python/net-shim.js';
7
7
  import { createShellAdapter } from './exec/adapters/shell/shell-adapter.js';
8
8
  import { routeObsidianCommand } from './exec/obsidian/route.js';
9
- import { MAX_OUTPUT_CHARS_LIMIT } from './exec/runner.js';
9
+ import { MAX_OUTPUT_CHARS, MAX_OUTPUT_CHARS_LIMIT, TRUNCATED_OUTPUT_SUFFIX } from './exec/runner.js';
10
10
  import { bareBin, firstCommandToken, sanitizeCommand } from './exec/scope.js';
11
11
  import { FILES_NEED_PYTHON_ERROR, isPythonSourceShaped, PACKAGES_NEED_PYTHON_ERROR, pythonRedirectError, startsLikePython, videoToolError } from './exec/shell-guidance.js';
12
12
  import { shellArgv } from './exec/shell-argv.js';
@@ -47,6 +47,30 @@ function shellEffect(command, toolOps) {
47
47
  }
48
48
  return matched.every((op) => op.annotation(argv) === 'read') ? 'read' : 'write';
49
49
  }
50
+ function shellOutputCap(command, toolOps) {
51
+ const { ops, argv } = resolveShellOps(command, toolOps);
52
+ const caps = ops.map((op) => op.outputCap(argv)).filter((cap) => cap !== undefined);
53
+ return caps.length > 0 ? Math.min(...caps) : undefined;
54
+ }
55
+ function noteCeiling(result, ceiling) {
56
+ if (!result || typeof result !== 'object')
57
+ return result;
58
+ const out = { ...result };
59
+ for (const stream of ['stdout', 'stderr']) {
60
+ const text = out[stream];
61
+ if (typeof text === 'string' && text.endsWith(TRUNCATED_OUTPUT_SUFFIX)) {
62
+ out[stream] =
63
+ text.slice(0, -TRUNCATED_OUTPUT_SUFFIX.length) +
64
+ `… [truncated at this skill's ${ceiling}-character limit for this command; a larger maxOutputChars does not apply]`;
65
+ }
66
+ }
67
+ return out;
68
+ }
69
+ function cappedOutput(requested, ceiling) {
70
+ if (ceiling === undefined)
71
+ return requested;
72
+ return Math.min(requested ?? MAX_OUTPUT_CHARS, ceiling);
73
+ }
50
74
  function resolveExecution({ adapters, fallback }, args, ctx) {
51
75
  for (const adapter of adapters) {
52
76
  const plan = adapter.resolve(args, ctx);
@@ -289,18 +313,33 @@ function checkExecutionScope(args, { toolOps, disablePyodide, sandbox, network }
289
313
  }
290
314
  return checkShellScope(command, toolOps);
291
315
  }
292
- async function skillsEnv(skillSettings, ctx) {
316
+ async function skillsEnv(skillSettings, skillEnv, ctx) {
293
317
  const skills = ctx?.skills ?? [];
294
318
  if (skills.length === 0) {
295
319
  return undefined;
296
320
  }
297
321
  const env = {};
298
322
  for (const skill of skills) {
299
- Object.assign(env, settingsEnv(skill, await skillSettings(skill, ctx?.agentId)));
323
+ if (skillSettings) {
324
+ Object.assign(env, settingsEnv(skill, await skillSettings(skill, ctx?.agentId)));
325
+ }
326
+ Object.assign(env, declaredEnv(skillEnv?.(skill), ctx?.session));
300
327
  }
301
328
  return Object.keys(env).length > 0 ? env : undefined;
302
329
  }
303
- export function createExecTool({ spawn, killProcess, loadPyodide, disablePyodide = false, pythonNetwork = !disablePyodide && pythonReachesNetwork(), credentialStore, skillSettings, realpath = defaultRealpath, deniedRoots, skillsDir } = {}) {
330
+ export function declaredEnv(declared, session) {
331
+ const env = {};
332
+ for (const [name, value] of Object.entries(declared ?? {})) {
333
+ if (!value.includes('${session}')) {
334
+ env[name] = value;
335
+ }
336
+ else if (session) {
337
+ env[name] = value.replaceAll('${session}', session);
338
+ }
339
+ }
340
+ return env;
341
+ }
342
+ export function createExecTool({ spawn, killProcess, loadPyodide, disablePyodide = false, pythonNetwork = !disablePyodide && pythonReachesNetwork(), credentialStore, skillSettings, skillEnv, realpath = defaultRealpath, deniedRoots, skillsDir } = {}) {
304
343
  const adapters = [createPythonAdapter(disablePyodide, loadPyodide, pythonNetwork)];
305
344
  const fallback = createShellAdapter({ spawn, killProcess, loadRuntime: bareRuntime });
306
345
  return {
@@ -349,7 +388,7 @@ export function createExecTool({ spawn, killProcess, loadPyodide, disablePyodide
349
388
  },
350
389
  maxOutputChars: {
351
390
  type: 'number',
352
- description: 'Optional stdout/stderr cap in characters (default 8192, max 65536). Raise when reading long content, e.g. a full note.'
391
+ description: 'Optional stdout/stderr cap in characters (default 8192, max 65536). Raise when reading long content, e.g. a full note. A skill may cap one of its commands lower; the truncation note says so, and raising this does not lift that cap.'
353
392
  },
354
393
  script: {
355
394
  type: 'string',
@@ -564,10 +603,12 @@ export function createExecTool({ spawn, killProcess, loadPyodide, disablePyodide
564
603
  timeout = Math.min(timeout, remaining);
565
604
  }
566
605
  }
567
- const maxOutputChars = parsePositiveInt(rawArgs.maxOutputChars, 'maxOutputChars', MAX_OUTPUT_CHARS_LIMIT);
568
- if (maxOutputChars && typeof maxOutputChars === 'object') {
569
- return maxOutputChars;
606
+ const requestedCap = parsePositiveInt(rawArgs.maxOutputChars, 'maxOutputChars', MAX_OUTPUT_CHARS_LIMIT);
607
+ if (requestedCap && typeof requestedCap === 'object') {
608
+ return requestedCap;
570
609
  }
610
+ const ceiling = shellOutputCap(command, ctx?.toolOps);
611
+ const maxOutputChars = cappedOutput(requestedCap, ceiling);
571
612
  if (!isPythonLanguage(rawArgs.language)) {
572
613
  const obsidian = await routeObsidianCommand(command, ctx, {
573
614
  credentialStore,
@@ -581,7 +622,7 @@ export function createExecTool({ spawn, killProcess, loadPyodide, disablePyodide
581
622
  return obsidian;
582
623
  }
583
624
  }
584
- const skillEnv = skillSettings ? await skillsEnv(skillSettings, ctx) : undefined;
625
+ const childEnv = await skillsEnv(skillSettings, skillEnv, ctx);
585
626
  try {
586
627
  const execution = resolveExecution({ adapters, fallback }, rawArgs, {
587
628
  attach: ctx?.attach,
@@ -593,13 +634,16 @@ export function createExecTool({ spawn, killProcess, loadPyodide, disablePyodide
593
634
  approval: ctx?.approval,
594
635
  confirmConnect: ctx?.askUser ? connectAsker(ctx.askUser) : undefined
595
636
  });
596
- return await execution.run({
637
+ const result = await execution.run({
597
638
  cwd,
598
639
  timeoutMs: timeout,
599
640
  maxOutputChars,
600
641
  signal: ctx?.signal,
601
- env: skillEnv
642
+ env: childEnv
602
643
  });
644
+ return ceiling !== undefined && maxOutputChars === ceiling
645
+ ? noteCeiling(result, ceiling)
646
+ : result;
603
647
  }
604
648
  catch (err) {
605
649
  const error = err instanceof Error ? err : new Error(String(err));
@@ -57,6 +57,7 @@ export function createFileGlobTool({ realpath = defaultRealpath, deniedRoots } =
57
57
  required: ['pattern']
58
58
  },
59
59
  effect: () => 'read',
60
+ stableRead: true,
60
61
  autoApprove: true,
61
62
  rootsRequired: true,
62
63
  validate(rawArgs) {
@@ -99,6 +99,7 @@ export function createGrepTool({ realpath = defaultRealpath, deniedRoots } = {})
99
99
  required: ['queries']
100
100
  },
101
101
  effect: () => 'read',
102
+ stableRead: true,
102
103
  autoApprove: true,
103
104
  rootsRequired: true,
104
105
  validate(rawArgs) {