@hackbuild/agents-views 0.1.1 → 0.1.2

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.
@@ -149,7 +149,7 @@ var HackbuildAgentsViews = (function(exports) {
149
149
  /** The note under the utility rows while no switch is pending. */
150
150
  const DRIVES_NOTE = "each act scores by how much it would ease what it needs. it usually picks the best one and sticks with what it is doing.";
151
151
  /** One gauge row per key, rebuilt only when the keys change. */
152
- function rows(doc, r, label, items) {
152
+ function rows$1(doc, r, label, items) {
153
153
  const keys = items.map((i) => i.k).join("\n");
154
154
  if (keys !== r.keys) {
155
155
  r.keys = keys;
@@ -221,14 +221,14 @@ var HackbuildAgentsViews = (function(exports) {
221
221
  v: Number.isFinite(v) ? Math.max(0, v) : 0
222
222
  }));
223
223
  const max = Math.max(1, ...u.map((x) => x.v));
224
- rows(doc, ur, "utility", u.map((x) => ({
224
+ rows$1(doc, ur, "utility", u.map((x) => ({
225
225
  ...x,
226
226
  max,
227
227
  cur: x.k === cur
228
228
  })));
229
229
  note.textContent = s.pending ? `next: ${s.pending.id} in ${Math.round(s.pending.inMs)} ms` : o.note ?? "each act scores by how much it would ease what it needs. it usually picks the best one and sticks with what it is doing.";
230
230
  const pink = new Set(s.pink ?? []);
231
- rows(doc, dr, "drive", Object.entries(s.drives).map(([k, v]) => ({
231
+ rows$1(doc, dr, "drive", Object.entries(s.drives).map(([k, v]) => ({
232
232
  k,
233
233
  v: clamp01(v),
234
234
  max: 1,
@@ -252,7 +252,7 @@ var HackbuildAgentsViews = (function(exports) {
252
252
  const h = o.height ?? 160;
253
253
  let sel = o.who.find((x) => x.id === o.selected) ?? o.who[0];
254
254
  const hd = el(doc, "div", "hb-inset-hd");
255
- const title = el(doc, "span", "hb-inset-title", "eye");
255
+ const title = el(doc, "span", "hb-inset-title", o.title ?? "eye");
256
256
  const aux = el(doc, "span", "hb-hd-aux");
257
257
  const whoGroup = el(doc, "span", "hb-inset-who");
258
258
  whoGroup.setAttribute("role", "group");
@@ -390,6 +390,199 @@ var HackbuildAgentsViews = (function(exports) {
390
390
  }
391
391
  });
392
392
  }
393
+ // src/map-inset.ts
394
+ const token = (c, name, or) => {
395
+ return (typeof getComputedStyle === "function" ? getComputedStyle(c).getPropertyValue(name).trim() : "") || or;
396
+ };
397
+ /** Draws one frame of the map; returns the mode line, as "212 cells seen". */
398
+ function drawMap(canvas, m) {
399
+ const g = canvas.getContext("2d");
400
+ if (!g) return "";
401
+ const W = canvas.width;
402
+ const H = canvas.height;
403
+ const s = Math.min(W, H) / (m.half * 2);
404
+ const ox = (W - s * m.half * 2) / 2;
405
+ const oy = (H - s * m.half * 2) / 2;
406
+ const pink = token(canvas, "--hb-pink", "#fe0386");
407
+ g.fillStyle = token(canvas, "--hb-paper-sunk", "#efe9db");
408
+ g.fillRect(0, 0, W, H);
409
+ const cw = m.half * 2 * s / m.cols;
410
+ const ch = m.half * 2 * s / m.rows;
411
+ const free = token(canvas, "--hb-paper-raised", "#fffdf7");
412
+ const wall = token(canvas, "--hb-ink", "#1a1a1a");
413
+ let seen = 0;
414
+ for (let k = 0; k < m.cells.length; k++) {
415
+ const v = m.cells[k];
416
+ if (!v) continue;
417
+ seen++;
418
+ g.fillStyle = v === 2 ? wall : free;
419
+ g.fillRect(ox + k % m.cols * cw, oy + Math.floor(k / m.cols) * ch, Math.ceil(cw), Math.ceil(ch));
420
+ }
421
+ const px = (x) => ox + (x + m.half) * s;
422
+ const pz = (z) => oy + (z + m.half) * s;
423
+ g.strokeStyle = pink;
424
+ g.lineWidth = 1.5;
425
+ g.beginPath();
426
+ m.trail.forEach((p, i) => i ? g.lineTo(px(p.x), pz(p.z)) : g.moveTo(px(p.x), pz(p.z)));
427
+ g.stroke();
428
+ g.fillStyle = pink;
429
+ g.beginPath();
430
+ g.arc(px(m.at.x), pz(m.at.z), 4, 0, Math.PI * 2);
431
+ g.fill();
432
+ return `${seen} cells seen`;
433
+ }
434
+ /** Makes `host` the map card; call `frame()` to draw. */
435
+ function mapInset(host, o) {
436
+ const size = o.size ?? 160;
437
+ return eyeInset(host, {
438
+ who: [{
439
+ id: "map",
440
+ label: o.label ?? "map",
441
+ title: "the map he built"
442
+ }],
443
+ draw: (c) => drawMap(c, o.map()),
444
+ title: o.label ?? "map",
445
+ width: size,
446
+ height: size
447
+ });
448
+ }
449
+ // src/plan-log.ts
450
+ const VIA = {
451
+ reflex: "rules",
452
+ cache: "reused",
453
+ model: "model",
454
+ planner: "planner"
455
+ };
456
+ const call = (s) => `${s.tool}(${s.args.map(String).join(", ")})`;
457
+ /** A plan book keeping at most `max` steps and thoughts (default 200). */
458
+ function planBook(o = {}) {
459
+ const max = o.max ?? 200;
460
+ const now = o.now ?? (() => Date.now());
461
+ let s = {
462
+ plan: "",
463
+ via: "",
464
+ goals: [],
465
+ thoughts: [],
466
+ steps: []
467
+ };
468
+ return {
469
+ push(e) {
470
+ if (e.type === "plan" && "plan" in e) {
471
+ const p = e.plan;
472
+ s = {
473
+ ...s,
474
+ via: VIA[e.via] ?? e.via,
475
+ plan: `${p.think ? `${p.think}. ` : ""}${p.do.map(call).join(", ") || "no steps"}`
476
+ };
477
+ return true;
478
+ }
479
+ if (e.type === "step" && "result" in e) {
480
+ const r = e.result;
481
+ s = {
482
+ ...s,
483
+ steps: [...s.steps.slice(1 - max), {
484
+ t: now(),
485
+ line: `${call(r.step)}: ${r.text}`,
486
+ ok: r.ok
487
+ }]
488
+ };
489
+ return true;
490
+ }
491
+ return false;
492
+ },
493
+ think(kind, line) {
494
+ s = {
495
+ ...s,
496
+ thoughts: [...s.thoughts.slice(1 - max), {
497
+ t: now(),
498
+ kind,
499
+ line
500
+ }]
501
+ };
502
+ },
503
+ setGoals(lines) {
504
+ s = {
505
+ ...s,
506
+ goals: [...lines]
507
+ };
508
+ },
509
+ state: () => s,
510
+ clear() {
511
+ s = {
512
+ plan: "",
513
+ via: "",
514
+ goals: [],
515
+ thoughts: [],
516
+ steps: []
517
+ };
518
+ }
519
+ };
520
+ }
521
+ const clock = (t) => new Date(t).toTimeString().slice(0, 8);
522
+ /** Fills an `ol.hb-racklog` with step rows, newest at the foot. */
523
+ function rows(list, steps) {
524
+ const doc = list.ownerDocument;
525
+ const follow = list.scrollHeight - list.scrollTop - list.clientHeight < 8;
526
+ list.classList.toggle("is-empty", !steps.length);
527
+ list.replaceChildren(...steps.map((x) => {
528
+ const li = el(doc, "li", `hb-racklog-row is-${x.ok ? "ok" : "warn"}`);
529
+ li.append(el(doc, "time", "hb-racklog-t", clock(x.t)), el(doc, "span", "hb-racklog-line", x.line), el(doc, "span", "hb-racklog-level", x.ok ? "ok" : "warn"));
530
+ return li;
531
+ }));
532
+ if (follow) list.scrollTop = list.scrollHeight;
533
+ }
534
+ function logList(doc, label, empty) {
535
+ const list = el(doc, "ol", "hb-racklog is-empty");
536
+ list.setAttribute("role", "log");
537
+ list.setAttribute("aria-live", "polite");
538
+ list.setAttribute("aria-label", label);
539
+ list.dataset.empty = empty;
540
+ list.tabIndex = 0;
541
+ return list;
542
+ }
543
+ /** The step log: one rack log row per tool call. */
544
+ function stepLog(host, o = {}) {
545
+ const list = logList(host.ownerDocument, o.label ?? "steps", o.empty ?? "no steps yet.");
546
+ host.replaceChildren(list);
547
+ return {
548
+ update: (steps) => rows(list, steps),
549
+ dispose: () => host.replaceChildren()
550
+ };
551
+ }
552
+ /** The plan log: last plan with who made it, goals, thoughts, and the step log under them. */
553
+ function planLog(host, o = {}) {
554
+ const doc = host.ownerDocument;
555
+ const col = stack(host);
556
+ const plan = panel(doc, "last plan");
557
+ const planText = el(doc, "p", "hb-note", o.empty ?? "none yet. give an order.");
558
+ const goals = el(doc, "ul", "hb-list");
559
+ plan.root.append(planText, goals);
560
+ const thoughts = panel(doc, "thoughts");
561
+ const thoughtList = el(doc, "ul", "hb-list");
562
+ thoughts.root.append(thoughtList);
563
+ const steps = panel(doc, "steps");
564
+ const list = logList(doc, "steps", "no steps yet.");
565
+ steps.root.append(list);
566
+ col.append(plan.root, thoughts.root, ...o.steps === false ? [] : [steps.root]);
567
+ host.replaceChildren(col);
568
+ return {
569
+ update(s) {
570
+ plan.aux.textContent = s.via;
571
+ planText.textContent = s.plan || (o.empty ?? "none yet. give an order.");
572
+ goals.hidden = !s.goals.length;
573
+ goals.replaceChildren(...s.goals.map((g) => el(doc, "li", "", `goal ${g}`)));
574
+ thoughts.root.hidden = !s.thoughts.length;
575
+ thoughts.aux.textContent = s.thoughts.length ? String(s.thoughts.length) : "";
576
+ thoughtList.replaceChildren(...s.thoughts.slice(-8).reverse().map((x) => {
577
+ const li = el(doc, "li");
578
+ li.append(el(doc, "b", "", x.kind), doc.createTextNode(` ${x.line}`));
579
+ return li;
580
+ }));
581
+ rows(list, s.steps);
582
+ },
583
+ dispose: () => host.replaceChildren()
584
+ };
585
+ }
393
586
  // src/single.ts
394
587
  if (typeof customElements !== "undefined") defineViews();
395
588
  exports.ASSOCIATIONS_NOTE = ASSOCIATIONS_NOTE;
@@ -398,8 +591,13 @@ var HackbuildAgentsViews = (function(exports) {
398
591
  exports.associationsState = associationsState;
399
592
  exports.associationsTable = associationsTable;
400
593
  exports.defineViews = defineViews;
594
+ exports.drawMap = drawMap;
401
595
  exports.drivesBars = drivesBars;
402
596
  exports.drivesBarsState = drivesBarsState;
403
597
  exports.eyeInset = eyeInset;
598
+ exports.mapInset = mapInset;
599
+ exports.planBook = planBook;
600
+ exports.planLog = planLog;
601
+ exports.stepLog = stepLog;
404
602
  return exports;
405
603
  })({});
@@ -30,6 +30,8 @@ export interface EyeInsetOptions {
30
30
  height?: number;
31
31
  /** the canvas, when a renderer owns it already (a three WebGLRenderer's) */
32
32
  canvas?: HTMLCanvasElement;
33
+ /** the head title (default "eye") */
34
+ title?: string;
33
35
  /** the user picked another who */
34
36
  onWho?: (id: string) => void;
35
37
  }
package/dist/eye-inset.js CHANGED
@@ -16,7 +16,7 @@ export function eyeInset(host, o) {
16
16
  let sel = o.who.find((x) => x.id === o.selected) ?? o.who[0];
17
17
  // the head as hackbuild-ui's HbInset with who: title, the who switch (.hb-inset-who), the mode line
18
18
  const hd = el(doc, "div", "hb-inset-hd");
19
- const title = el(doc, "span", "hb-inset-title", "eye");
19
+ const title = el(doc, "span", "hb-inset-title", o.title ?? "eye");
20
20
  const aux = el(doc, "span", "hb-hd-aux");
21
21
  const whoGroup = el(doc, "span", "hb-inset-who");
22
22
  whoGroup.setAttribute("role", "group");
package/dist/index.d.ts CHANGED
@@ -2,3 +2,5 @@ export * from "./associations-table.js";
2
2
  export * from "./drives-bars.js";
3
3
  export * from "./elements.js";
4
4
  export * from "./eye-inset.js";
5
+ export * from "./map-inset.js";
6
+ export * from "./plan-log.js";
package/dist/index.js CHANGED
@@ -6,3 +6,5 @@ export * from "./associations-table.js";
6
6
  export * from "./drives-bars.js";
7
7
  export * from "./elements.js";
8
8
  export * from "./eye-inset.js";
9
+ export * from "./map-inset.js";
10
+ export * from "./plan-log.js";
@@ -0,0 +1,34 @@
1
+ import { type EyeInsetHandle } from "./eye-inset.js";
2
+ /** The map as the view reads it. */
3
+ export interface MapState {
4
+ /** cells across and down */
5
+ cols: number;
6
+ rows: number;
7
+ /** row major, 0 unknown, 1 free, 2 blocked */
8
+ cells: ArrayLike<number>;
9
+ /** half the floor's side in metres; the map spans x and z from -half to half */
10
+ half: number;
11
+ /** points walked, in metres */
12
+ trail: readonly {
13
+ x: number;
14
+ z: number;
15
+ }[];
16
+ /** where the body is */
17
+ at: {
18
+ x: number;
19
+ z: number;
20
+ };
21
+ }
22
+ /** Draws one frame of the map; returns the mode line, as "212 cells seen". */
23
+ export declare function drawMap(canvas: HTMLCanvasElement, m: MapState): string;
24
+ /** Options of `mapInset`. */
25
+ export interface MapInsetOptions {
26
+ /** the map now; read on every `frame()` */
27
+ map: () => MapState;
28
+ /** canvas side in pixels (default 160) */
29
+ size?: number;
30
+ /** the head title (default "map") */
31
+ label?: string;
32
+ }
33
+ /** Makes `host` the map card; call `frame()` to draw. */
34
+ export declare function mapInset(host: HTMLElement, o: MapInsetOptions): EyeInsetHandle;
@@ -0,0 +1,60 @@
1
+ // MapInset: the map a body builds from its own depth, drawn as an inset on
2
+ // the stage. Ported from the room original: a grid of cells (unknown, free,
3
+ // blocked) over the floor, the trail walked in pink and the body as a pink
4
+ // dot. Colours come from the hackbuild-ui tokens on the canvas, so the map
5
+ // follows the theme. The card is an EyeInset with one who.
6
+ import { eyeInset } from "./eye-inset.js";
7
+ const token = (c, name, or) => {
8
+ const v = typeof getComputedStyle === "function" ? getComputedStyle(c).getPropertyValue(name).trim() : "";
9
+ return v || or;
10
+ };
11
+ /** Draws one frame of the map; returns the mode line, as "212 cells seen". */
12
+ export function drawMap(canvas, m) {
13
+ const g = canvas.getContext("2d");
14
+ if (!g)
15
+ return "";
16
+ const W = canvas.width;
17
+ const H = canvas.height;
18
+ const s = Math.min(W, H) / (m.half * 2);
19
+ const ox = (W - s * m.half * 2) / 2;
20
+ const oy = (H - s * m.half * 2) / 2;
21
+ const pink = token(canvas, "--hb-pink", "#fe0386");
22
+ g.fillStyle = token(canvas, "--hb-paper-sunk", "#efe9db");
23
+ g.fillRect(0, 0, W, H);
24
+ const cw = (m.half * 2 * s) / m.cols;
25
+ const ch = (m.half * 2 * s) / m.rows;
26
+ const free = token(canvas, "--hb-paper-raised", "#fffdf7");
27
+ const wall = token(canvas, "--hb-ink", "#1a1a1a");
28
+ let seen = 0;
29
+ for (let k = 0; k < m.cells.length; k++) {
30
+ const v = m.cells[k];
31
+ if (!v)
32
+ continue;
33
+ seen++;
34
+ g.fillStyle = v === 2 ? wall : free;
35
+ g.fillRect(ox + (k % m.cols) * cw, oy + Math.floor(k / m.cols) * ch, Math.ceil(cw), Math.ceil(ch));
36
+ }
37
+ const px = (x) => ox + (x + m.half) * s;
38
+ const pz = (z) => oy + (z + m.half) * s;
39
+ g.strokeStyle = pink;
40
+ g.lineWidth = 1.5;
41
+ g.beginPath();
42
+ m.trail.forEach((p, i) => (i ? g.lineTo(px(p.x), pz(p.z)) : g.moveTo(px(p.x), pz(p.z))));
43
+ g.stroke();
44
+ g.fillStyle = pink;
45
+ g.beginPath();
46
+ g.arc(px(m.at.x), pz(m.at.z), 4, 0, Math.PI * 2);
47
+ g.fill();
48
+ return `${seen} cells seen`;
49
+ }
50
+ /** Makes `host` the map card; call `frame()` to draw. */
51
+ export function mapInset(host, o) {
52
+ const size = o.size ?? 160;
53
+ return eyeInset(host, {
54
+ who: [{ id: "map", label: o.label ?? "map", title: "the map he built" }],
55
+ draw: (c) => drawMap(c, o.map()),
56
+ title: o.label ?? "map",
57
+ width: size,
58
+ height: size,
59
+ });
60
+ }
@@ -0,0 +1,76 @@
1
+ /** One step as the log shows it. */
2
+ export interface StepLine {
3
+ /** ms since epoch */
4
+ t: number;
5
+ line: string;
6
+ ok: boolean;
7
+ }
8
+ /** A thought it had with no order: a mutter, or a reflection on what it attends to. */
9
+ export interface ThoughtLine {
10
+ t: number;
11
+ kind: string;
12
+ line: string;
13
+ }
14
+ /** What PlanLog draws. Built with `planBook`, or by hand. */
15
+ export interface PlanLogState {
16
+ /** the last plan in one line, "" for none */
17
+ plan: string;
18
+ /** who made it: rules, reused, model */
19
+ via: string;
20
+ goals: readonly string[];
21
+ thoughts: readonly ThoughtLine[];
22
+ steps: readonly StepLine[];
23
+ }
24
+ /** The parts of a @hackbuild/agent event the book reads. */
25
+ export type PlanEventLike = {
26
+ type: "plan";
27
+ via: string;
28
+ plan: {
29
+ think?: string;
30
+ do: readonly {
31
+ tool: string;
32
+ args: readonly unknown[];
33
+ }[];
34
+ };
35
+ } | {
36
+ type: "step";
37
+ result: {
38
+ ok: boolean;
39
+ text: string;
40
+ step: {
41
+ tool: string;
42
+ args: readonly unknown[];
43
+ };
44
+ };
45
+ } | {
46
+ type: string;
47
+ };
48
+ /** The book behind PlanLog and StepLog: push agent events, thoughts and goals; read `state()`. */
49
+ export interface PlanBook {
50
+ /** Takes a plan or a step event; true when the state changed. */
51
+ push(e: PlanEventLike): boolean;
52
+ think(kind: string, line: string): void;
53
+ setGoals(lines: readonly string[]): void;
54
+ state(): PlanLogState;
55
+ clear(): void;
56
+ }
57
+ /** A plan book keeping at most `max` steps and thoughts (default 200). */
58
+ export declare function planBook(o?: {
59
+ max?: number;
60
+ now?: () => number;
61
+ }): PlanBook;
62
+ /** What `stepLog` and `planLog` return. */
63
+ export interface LogHandle<S> {
64
+ update(state: S): void;
65
+ dispose(): void;
66
+ }
67
+ /** The step log: one rack log row per tool call. */
68
+ export declare function stepLog(host: HTMLElement, o?: {
69
+ empty?: string;
70
+ label?: string;
71
+ }): LogHandle<readonly StepLine[]>;
72
+ /** The plan log: last plan with who made it, goals, thoughts, and the step log under them. */
73
+ export declare function planLog(host: HTMLElement, o?: {
74
+ steps?: boolean;
75
+ empty?: string;
76
+ }): LogHandle<PlanLogState>;
@@ -0,0 +1,106 @@
1
+ // PlanLog and StepLog: what an agent decided and what each step did.
2
+ // Ported from the room originals' mind tab: the last plan with who made it
3
+ // (rules, a reused plan or the model), the goals kept until done, the
4
+ // thoughts it had on its own (mutters, reflections), and a step log, one
5
+ // row per tool call with ok or warn at the right edge. The rows are
6
+ // hackbuild-ui's rack log (.hb-racklog).
7
+ import { el, panel, stack } from "./dom.js";
8
+ const VIA = { reflex: "rules", cache: "reused", model: "model", planner: "planner" };
9
+ const call = (s) => `${s.tool}(${s.args.map(String).join(", ")})`;
10
+ /** A plan book keeping at most `max` steps and thoughts (default 200). */
11
+ export function planBook(o = {}) {
12
+ const max = o.max ?? 200;
13
+ const now = o.now ?? (() => Date.now());
14
+ let s = { plan: "", via: "", goals: [], thoughts: [], steps: [] };
15
+ return {
16
+ push(e) {
17
+ if (e.type === "plan" && "plan" in e) {
18
+ const p = e.plan;
19
+ s = { ...s, via: VIA[e.via] ?? e.via, plan: `${p.think ? `${p.think}. ` : ""}${p.do.map(call).join(", ") || "no steps"}` };
20
+ return true;
21
+ }
22
+ if (e.type === "step" && "result" in e) {
23
+ const r = e.result;
24
+ s = { ...s, steps: [...s.steps.slice(1 - max), { t: now(), line: `${call(r.step)}: ${r.text}`, ok: r.ok }] };
25
+ return true;
26
+ }
27
+ return false;
28
+ },
29
+ think(kind, line) {
30
+ s = { ...s, thoughts: [...s.thoughts.slice(1 - max), { t: now(), kind, line }] };
31
+ },
32
+ setGoals(lines) {
33
+ s = { ...s, goals: [...lines] };
34
+ },
35
+ state: () => s,
36
+ clear() {
37
+ s = { plan: "", via: "", goals: [], thoughts: [], steps: [] };
38
+ },
39
+ };
40
+ }
41
+ const clock = (t) => new Date(t).toTimeString().slice(0, 8);
42
+ /** Fills an `ol.hb-racklog` with step rows, newest at the foot. */
43
+ function rows(list, steps) {
44
+ const doc = list.ownerDocument;
45
+ const follow = list.scrollHeight - list.scrollTop - list.clientHeight < 8;
46
+ list.classList.toggle("is-empty", !steps.length);
47
+ list.replaceChildren(...steps.map((x) => {
48
+ const li = el(doc, "li", `hb-racklog-row is-${x.ok ? "ok" : "warn"}`);
49
+ li.append(el(doc, "time", "hb-racklog-t", clock(x.t)), el(doc, "span", "hb-racklog-line", x.line), el(doc, "span", "hb-racklog-level", x.ok ? "ok" : "warn"));
50
+ return li;
51
+ }));
52
+ if (follow)
53
+ list.scrollTop = list.scrollHeight;
54
+ }
55
+ function logList(doc, label, empty) {
56
+ const list = el(doc, "ol", "hb-racklog is-empty");
57
+ list.setAttribute("role", "log");
58
+ list.setAttribute("aria-live", "polite");
59
+ list.setAttribute("aria-label", label);
60
+ list.dataset.empty = empty;
61
+ list.tabIndex = 0;
62
+ return list;
63
+ }
64
+ /** The step log: one rack log row per tool call. */
65
+ export function stepLog(host, o = {}) {
66
+ const list = logList(host.ownerDocument, o.label ?? "steps", o.empty ?? "no steps yet.");
67
+ host.replaceChildren(list);
68
+ return { update: (steps) => rows(list, steps), dispose: () => host.replaceChildren() };
69
+ }
70
+ /** The plan log: last plan with who made it, goals, thoughts, and the step log under them. */
71
+ export function planLog(host, o = {}) {
72
+ const doc = host.ownerDocument;
73
+ const col = stack(host);
74
+ const plan = panel(doc, "last plan");
75
+ const planText = el(doc, "p", "hb-note", o.empty ?? "none yet. give an order.");
76
+ const goals = el(doc, "ul", "hb-list");
77
+ plan.root.append(planText, goals);
78
+ const thoughts = panel(doc, "thoughts");
79
+ const thoughtList = el(doc, "ul", "hb-list");
80
+ thoughts.root.append(thoughtList);
81
+ const steps = panel(doc, "steps");
82
+ const list = logList(doc, "steps", "no steps yet.");
83
+ steps.root.append(list);
84
+ col.append(plan.root, thoughts.root, ...(o.steps === false ? [] : [steps.root]));
85
+ host.replaceChildren(col);
86
+ return {
87
+ update(s) {
88
+ plan.aux.textContent = s.via;
89
+ planText.textContent = s.plan || (o.empty ?? "none yet. give an order.");
90
+ goals.hidden = !s.goals.length;
91
+ goals.replaceChildren(...s.goals.map((g) => el(doc, "li", "", `goal ${g}`)));
92
+ thoughts.root.hidden = !s.thoughts.length;
93
+ thoughts.aux.textContent = s.thoughts.length ? String(s.thoughts.length) : "";
94
+ thoughtList.replaceChildren(...s.thoughts
95
+ .slice(-8)
96
+ .reverse()
97
+ .map((x) => {
98
+ const li = el(doc, "li");
99
+ li.append(el(doc, "b", "", x.kind), doc.createTextNode(` ${x.line}`));
100
+ return li;
101
+ }));
102
+ rows(list, s.steps);
103
+ },
104
+ dispose: () => host.replaceChildren(),
105
+ };
106
+ }
package/dist/vue.d.ts CHANGED
@@ -2,6 +2,8 @@ import { type PropType } from "vue";
2
2
  import { type AssociationsState } from "./associations-table.js";
3
3
  import { type DrivesBarsState } from "./drives-bars.js";
4
4
  import { type EyeWho } from "./eye-inset.js";
5
+ import { type MapState } from "./map-inset.js";
6
+ import { type PlanLogState, type StepLine } from "./plan-log.js";
5
7
  /** The behavior block, utility rows (current in pink) and drive rows. */
6
8
  export declare const DrivesBars: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
7
9
  state: {
@@ -107,3 +109,75 @@ export declare const EyeInset: import("vue").DefineComponent<import("vue").Extra
107
109
  width: number;
108
110
  height: number;
109
111
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
112
+ /** The plan log: last plan, goals, thoughts and steps. `steps: false` leaves the step log out. */
113
+ export declare const PlanLog: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
114
+ state: {
115
+ type: PropType<PlanLogState>;
116
+ required: true;
117
+ };
118
+ steps: {
119
+ type: BooleanConstructor;
120
+ default: boolean;
121
+ };
122
+ }>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
123
+ [key: string]: any;
124
+ }>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
125
+ state: {
126
+ type: PropType<PlanLogState>;
127
+ required: true;
128
+ };
129
+ steps: {
130
+ type: BooleanConstructor;
131
+ default: boolean;
132
+ };
133
+ }>> & Readonly<{}>, {
134
+ steps: boolean;
135
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
136
+ /** The step log: one rack log row per tool call. */
137
+ export declare const StepLog: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
138
+ steps: {
139
+ type: PropType<readonly StepLine[]>;
140
+ required: true;
141
+ };
142
+ empty: {
143
+ type: StringConstructor;
144
+ default: string;
145
+ };
146
+ }>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
147
+ [key: string]: any;
148
+ }>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
149
+ steps: {
150
+ type: PropType<readonly StepLine[]>;
151
+ required: true;
152
+ };
153
+ empty: {
154
+ type: StringConstructor;
155
+ default: string;
156
+ };
157
+ }>> & Readonly<{}>, {
158
+ empty: string;
159
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
160
+ /** The map card. `map` returns the map; call the exposed `frame()` to draw it (a template ref). */
161
+ export declare const MapInset: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
162
+ map: {
163
+ type: PropType<() => MapState>;
164
+ required: true;
165
+ };
166
+ size: {
167
+ type: NumberConstructor;
168
+ default: number;
169
+ };
170
+ }>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
171
+ [key: string]: any;
172
+ }>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
173
+ map: {
174
+ type: PropType<() => MapState>;
175
+ required: true;
176
+ };
177
+ size: {
178
+ type: NumberConstructor;
179
+ default: number;
180
+ };
181
+ }>> & Readonly<{}>, {
182
+ size: number;
183
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
package/dist/vue.js CHANGED
@@ -4,6 +4,8 @@ import { defineComponent, h, onBeforeUnmount, onMounted, ref, watch } from "vue"
4
4
  import { associationsTable } from "./associations-table.js";
5
5
  import { drivesBars } from "./drives-bars.js";
6
6
  import { eyeInset } from "./eye-inset.js";
7
+ import { mapInset } from "./map-inset.js";
8
+ import { planLog, stepLog } from "./plan-log.js";
7
9
  /** The behavior block, utility rows (current in pink) and drive rows. */
8
10
  export const DrivesBars = defineComponent({
9
11
  name: "DrivesBars",
@@ -80,3 +82,59 @@ export const EyeInset = defineComponent({
80
82
  return () => h("figure", { ref: root });
81
83
  },
82
84
  });
85
+ /** The plan log: last plan, goals, thoughts and steps. `steps: false` leaves the step log out. */
86
+ export const PlanLog = defineComponent({
87
+ name: "PlanLog",
88
+ props: {
89
+ state: { type: Object, required: true },
90
+ steps: { type: Boolean, default: true },
91
+ },
92
+ setup(props) {
93
+ const root = ref(null);
94
+ let view = null;
95
+ onMounted(() => {
96
+ view = planLog(root.value, { steps: props.steps });
97
+ view.update(props.state);
98
+ });
99
+ watch(() => props.state, (s) => view?.update(s));
100
+ onBeforeUnmount(() => view?.dispose());
101
+ return () => h("div", { ref: root });
102
+ },
103
+ });
104
+ /** The step log: one rack log row per tool call. */
105
+ export const StepLog = defineComponent({
106
+ name: "StepLog",
107
+ props: {
108
+ steps: { type: Array, required: true },
109
+ empty: { type: String, default: "no steps yet." },
110
+ },
111
+ setup(props) {
112
+ const root = ref(null);
113
+ let view = null;
114
+ onMounted(() => {
115
+ view = stepLog(root.value, { empty: props.empty });
116
+ view.update(props.steps);
117
+ });
118
+ watch(() => props.steps, (s) => view?.update(s));
119
+ onBeforeUnmount(() => view?.dispose());
120
+ return () => h("div", { ref: root });
121
+ },
122
+ });
123
+ /** The map card. `map` returns the map; call the exposed `frame()` to draw it (a template ref). */
124
+ export const MapInset = defineComponent({
125
+ name: "MapInset",
126
+ props: {
127
+ map: { type: Function, required: true },
128
+ size: { type: Number, default: 160 },
129
+ },
130
+ setup(props, { expose }) {
131
+ const root = ref(null);
132
+ let view = null;
133
+ onMounted(() => {
134
+ view = mapInset(root.value, { map: () => props.map(), size: props.size });
135
+ });
136
+ onBeforeUnmount(() => view?.dispose());
137
+ expose({ frame: () => view?.frame() });
138
+ return () => h("figure", { ref: root });
139
+ },
140
+ });
package/llms.md CHANGED
@@ -109,6 +109,12 @@ function defineViews(registry?: CustomElementRegistry): void
109
109
 
110
110
  Defines the three elements once; safe to call again.
111
111
 
112
+ ```ts
113
+ function drawMap(canvas: HTMLCanvasElement, m: MapState): string
114
+ ```
115
+
116
+ Draws one frame of the map; returns the mode line, as "212 cells seen".
117
+
112
118
  ```ts
113
119
  const DRIVES_NOTE: "each act scores by how much it would ease what it needs. it usually picks the best one and sticks with what it is doing."
114
120
  ```
@@ -232,6 +238,7 @@ interface EyeInsetOptions {
232
238
  height?: number;
233
239
  onWho?: (id: string) => void;
234
240
  selected?: string;
241
+ title?: string;
235
242
  who: readonly EyeWho[];
236
243
  width?: number;
237
244
  }
@@ -275,6 +282,112 @@ interface LearnerStateLike {
275
282
 
276
283
  The @hackbuild/drives LearnerState shape (CueLearner.toJSON()).
277
284
 
285
+ ```ts
286
+ interface LogHandle<S> {
287
+ dispose(): void;
288
+ update(state: S): void;
289
+ }
290
+ ```
291
+
292
+ What `stepLog` and `planLog` return.
293
+
294
+ ```ts
295
+ function mapInset(host: HTMLElement, o: MapInsetOptions): EyeInsetHandle
296
+ ```
297
+
298
+ Makes `host` the map card; call `frame()` to draw.
299
+
300
+ ```ts
301
+ interface MapInsetOptions {
302
+ label?: string;
303
+ map: () => MapState;
304
+ size?: number;
305
+ }
306
+ ```
307
+
308
+ Options of `mapInset`.
309
+
310
+ ```ts
311
+ interface MapState {
312
+ at: { x: number; z: number };
313
+ cells: ArrayLike<number>;
314
+ cols: number;
315
+ half: number;
316
+ rows: number;
317
+ trail: readonly { x: number; z: number }[];
318
+ }
319
+ ```
320
+
321
+ The map as the view reads it.
322
+
323
+ ```ts
324
+ function planBook(o?: { max?: number; now?: () => number }): PlanBook
325
+ ```
326
+
327
+ A plan book keeping at most `max` steps and thoughts (default 200).
328
+
329
+ ```ts
330
+ interface PlanBook {
331
+ clear(): void;
332
+ push(e: PlanEventLike): boolean;
333
+ setGoals(lines: readonly string[]): void;
334
+ state(): PlanLogState;
335
+ think(kind: string, line: string): void;
336
+ }
337
+ ```
338
+
339
+ The book behind PlanLog and StepLog: push agent events, thoughts and goals; read `state()`.
340
+
341
+ ```ts
342
+ type PlanEventLike = { plan: { do: readonly { args: readonly unknown[]; tool: string }[]; think?: string }; type: "plan"; via: string } | { result: { ok: boolean; step: { args: readonly unknown[]; tool: string }; text: string }; type: "step" } | { type: string }
343
+ ```
344
+
345
+ The parts of a @hackbuild/agent event the book reads.
346
+
347
+ ```ts
348
+ function planLog(host: HTMLElement, o?: { empty?: string; steps?: boolean }): LogHandle<PlanLogState>
349
+ ```
350
+
351
+ The plan log: last plan with who made it, goals, thoughts, and the step log under them.
352
+
353
+ ```ts
354
+ interface PlanLogState {
355
+ goals: readonly string[];
356
+ plan: string;
357
+ steps: readonly StepLine[];
358
+ thoughts: readonly ThoughtLine[];
359
+ via: string;
360
+ }
361
+ ```
362
+
363
+ What PlanLog draws.
364
+
365
+ ```ts
366
+ interface StepLine {
367
+ line: string;
368
+ ok: boolean;
369
+ t: number;
370
+ }
371
+ ```
372
+
373
+ One step as the log shows it.
374
+
375
+ ```ts
376
+ function stepLog(host: HTMLElement, o?: { empty?: string; label?: string }): LogHandle<readonly StepLine[]>
377
+ ```
378
+
379
+ The step log: one rack log row per tool call.
380
+
381
+ ```ts
382
+ interface ThoughtLine {
383
+ kind: string;
384
+ line: string;
385
+ t: number;
386
+ }
387
+ ```
388
+
389
+ A thought it had with no order: a mutter, or a reflection on what it attends to.
390
+
278
391
  ### @hackbuild/agents-views/vue
279
392
 
280
393
  ```ts
@@ -295,6 +408,24 @@ const EyeInset: DefineComponent<ExtractPropTypes<{ draw: { required: true; type:
295
408
 
296
409
  The eye card.
297
410
 
411
+ ```ts
412
+ const MapInset: DefineComponent<ExtractPropTypes<{ map: { required: true; type: PropType<() => MapState> }; size: { default: number; type: NumberConstructor } }>, () => VNode<RendererNode, RendererElement, { [key: string]: any }>, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, ToResolvedProps<ExtractPropTypes<{ map: { required: true; type: PropType<() => MapState> }; size: { default: number; type: NumberConstructor } }>, {}>, { size: number }, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>
413
+ ```
414
+
415
+ The map card.
416
+
417
+ ```ts
418
+ const PlanLog: DefineComponent<ExtractPropTypes<{ state: { required: true; type: PropType<PlanLogState> }; steps: { default: boolean; type: BooleanConstructor } }>, () => VNode<RendererNode, RendererElement, { [key: string]: any }>, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, ToResolvedProps<ExtractPropTypes<{ state: { required: true; type: PropType<PlanLogState> }; steps: { default: boolean; type: BooleanConstructor } }>, {}>, { steps: boolean }, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>
419
+ ```
420
+
421
+ The plan log: last plan, goals, thoughts and steps.
422
+
423
+ ```ts
424
+ const StepLog: DefineComponent<ExtractPropTypes<{ empty: { default: string; type: StringConstructor }; steps: { required: true; type: PropType<readonly StepLine[]> } }>, () => VNode<RendererNode, RendererElement, { [key: string]: any }>, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, ToResolvedProps<ExtractPropTypes<{ empty: { default: string; type: StringConstructor }; steps: { required: true; type: PropType<readonly StepLine[]> } }>, {}>, { empty: string }, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>
425
+ ```
426
+
427
+ The step log: one rack log row per tool call.
428
+
298
429
  ## Examples
299
430
 
300
431
  ### quick start
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hackbuild/agents-views",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Views that bind the agents packages to the hackbuild-ui class layer: the behaviour, utility and drive bars, the cues by acts associations table, and the eye inset. Each ships as a Vue component and as a custom element.",
5
5
  "type": "module",
6
6
  "license": "MIT",