@songsid/agend 2.4.0-beta.23 → 2.4.0-beta.24

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 (152) hide show
  1. package/dist/agent-cli-instructions.md +4 -3
  2. package/dist/agent-cli.js +32 -2
  3. package/dist/agent-cli.js.map +1 -1
  4. package/dist/agent-file-read.js +2 -2
  5. package/dist/agent-file-read.js.map +1 -1
  6. package/dist/agent-whats-new.js +11 -1
  7. package/dist/agent-whats-new.js.map +1 -1
  8. package/dist/backend/claude-code.d.ts +15 -0
  9. package/dist/backend/claude-code.js +8 -3
  10. package/dist/backend/claude-code.js.map +1 -1
  11. package/dist/backend/claude-mcp-carry.d.ts +63 -0
  12. package/dist/backend/claude-mcp-carry.js +242 -0
  13. package/dist/backend/claude-mcp-carry.js.map +1 -0
  14. package/dist/build-provenance.json +1 -1
  15. package/dist/channel/mcp-tools.js +7 -6
  16. package/dist/channel/mcp-tools.js.map +1 -1
  17. package/dist/config-validator.js +6 -0
  18. package/dist/config-validator.js.map +1 -1
  19. package/dist/daemon.d.ts +11 -0
  20. package/dist/daemon.js +66 -15
  21. package/dist/daemon.js.map +1 -1
  22. package/dist/dashboard-permissions.d.ts +8 -0
  23. package/dist/dashboard-permissions.js +8 -0
  24. package/dist/dashboard-permissions.js.map +1 -1
  25. package/dist/delivery-outbox.d.ts +15 -1
  26. package/dist/delivery-outbox.js +60 -2
  27. package/dist/delivery-outbox.js.map +1 -1
  28. package/dist/fleet-manager.d.ts +14 -0
  29. package/dist/fleet-manager.js +67 -0
  30. package/dist/fleet-manager.js.map +1 -1
  31. package/dist/general-knowledge/skills/concepts/SKILL.md +22 -9
  32. package/dist/general-knowledge/skills/credential-profiles/SKILL.md +6 -0
  33. package/dist/general-knowledge/skills/fleet-config/SKILL.md +3 -3
  34. package/dist/general-knowledge/skills/instance-lifecycle/SKILL.md +1 -1
  35. package/dist/general-knowledge/skills/task-board/SKILL.md +17 -0
  36. package/dist/general-knowledge/skills/web-appearance/SKILL.md +4 -0
  37. package/dist/general-knowledge/skills/web-dashboard/SKILL.md +21 -3
  38. package/dist/hub/group-policy/resources.d.ts +1 -1
  39. package/dist/instance-lifecycle.d.ts +2 -0
  40. package/dist/instance-lifecycle.js +29 -1
  41. package/dist/instance-lifecycle.js.map +1 -1
  42. package/dist/locale.js +10 -0
  43. package/dist/locale.js.map +1 -1
  44. package/dist/needs-you-hub.d.ts +3 -0
  45. package/dist/needs-you-hub.js +31 -5
  46. package/dist/needs-you-hub.js.map +1 -1
  47. package/dist/needs-you.d.ts +14 -1
  48. package/dist/needs-you.js +5 -0
  49. package/dist/needs-you.js.map +1 -1
  50. package/dist/office-share-page.js +1 -1
  51. package/dist/office-share-page.js.map +1 -1
  52. package/dist/office-share.js +2 -1
  53. package/dist/office-share.js.map +1 -1
  54. package/dist/outbound-handlers.js +29 -6
  55. package/dist/outbound-handlers.js.map +1 -1
  56. package/dist/outbound-schemas.d.ts +3 -0
  57. package/dist/outbound-schemas.js +7 -5
  58. package/dist/outbound-schemas.js.map +1 -1
  59. package/dist/public-web-gateway.js +3 -0
  60. package/dist/public-web-gateway.js.map +1 -1
  61. package/dist/request-context-compatibility.d.ts +20 -0
  62. package/dist/request-context-compatibility.js +74 -0
  63. package/dist/request-context-compatibility.js.map +1 -0
  64. package/dist/request-context-protocol.d.ts +137 -0
  65. package/dist/request-context-protocol.js +38 -0
  66. package/dist/request-context-protocol.js.map +1 -0
  67. package/dist/request-context-store.d.ts +25 -0
  68. package/dist/request-context-store.js +137 -0
  69. package/dist/request-context-store.js.map +1 -0
  70. package/dist/scheduler/db.js +26 -0
  71. package/dist/scheduler/db.js.map +1 -1
  72. package/dist/scheduler/task-board-text.d.ts +2 -0
  73. package/dist/scheduler/task-board-text.js +12 -0
  74. package/dist/scheduler/task-board-text.js.map +1 -1
  75. package/dist/scheduler/task-board.d.ts +102 -2
  76. package/dist/scheduler/task-board.js +242 -24
  77. package/dist/scheduler/task-board.js.map +1 -1
  78. package/dist/scheduler/task-files.d.ts +80 -0
  79. package/dist/scheduler/task-files.js +357 -0
  80. package/dist/scheduler/task-files.js.map +1 -0
  81. package/dist/settings-api.d.ts +2 -0
  82. package/dist/settings-api.js +6 -1
  83. package/dist/settings-api.js.map +1 -1
  84. package/dist/settings-baseline.d.ts +1 -0
  85. package/dist/settings-baseline.js +1 -1
  86. package/dist/settings-baseline.js.map +1 -1
  87. package/dist/settings-effect.d.ts +2 -0
  88. package/dist/settings-effect.js +5 -1
  89. package/dist/settings-effect.js.map +1 -1
  90. package/dist/task-attach-client.d.ts +43 -0
  91. package/dist/task-attach-client.js +125 -0
  92. package/dist/task-attach-client.js.map +1 -0
  93. package/dist/task-board-tool.d.ts +12 -0
  94. package/dist/task-board-tool.js +107 -6
  95. package/dist/task-board-tool.js.map +1 -1
  96. package/dist/task-file-limits.d.ts +15 -0
  97. package/dist/task-file-limits.js +21 -0
  98. package/dist/task-file-limits.js.map +1 -0
  99. package/dist/tool-permissions.d.ts +32 -0
  100. package/dist/tool-permissions.js +63 -0
  101. package/dist/tool-permissions.js.map +1 -1
  102. package/dist/types.d.ts +6 -0
  103. package/dist/ui/agent-details-settings.js +7 -5
  104. package/dist/ui/agent-who-can-use-strings.js +125 -0
  105. package/dist/ui/agent-who-can-use.js +238 -0
  106. package/dist/ui/fleet-office-card.js +23 -5
  107. package/dist/ui/fleet-office-editor.js +5 -5
  108. package/dist/ui/fleet-office-pack.d.ts +10 -0
  109. package/dist/ui/fleet-office-pack.js +65 -2
  110. package/dist/ui/fleet-office-skin.js +42 -8
  111. package/dist/ui/fleet-office-store.js +33 -2
  112. package/dist/ui/fleet-office-vehicles.js +130 -0
  113. package/dist/ui/fleet-office-zones.js +5 -1
  114. package/dist/ui/fleet-office.js +112 -31
  115. package/dist/ui/fleet-task-activity.js +9 -82
  116. package/dist/ui/fleet-task-archive.js +111 -0
  117. package/dist/ui/fleet-task-card.js +6 -4
  118. package/dist/ui/fleet-task-common.js +2 -2
  119. package/dist/ui/fleet-task-edit.js +8 -1
  120. package/dist/ui/fleet-task-files.js +196 -0
  121. package/dist/ui/fleet-task-md.js +98 -0
  122. package/dist/ui/fleet-task-menu.js +1 -1
  123. package/dist/ui/fleet-task-stats.js +2 -2
  124. package/dist/ui/fleet-task-view.js +12 -8
  125. package/dist/ui/fleet-tasks.js +42 -18
  126. package/dist/ui/panel-details.js +3 -1
  127. package/dist/ui/panel-needs.js +3 -3
  128. package/dist/ui/panel-settings.js +15 -1
  129. package/dist/ui/settings-registry.js +1 -0
  130. package/dist/ui/settings-shared-strings.js +9 -0
  131. package/dist/ui/settings-shared.js +6 -1
  132. package/dist/ui/shared/app-i18n.js +2 -2
  133. package/dist/ui/shared/app-needs.js +8 -1
  134. package/dist/ui/shared/app.css +55 -3
  135. package/dist/ui/shared/chat-strings.js +4 -4
  136. package/dist/ui/shared/task-board.css +64 -0
  137. package/dist/web-api.d.ts +3 -0
  138. package/dist/web-api.js +97 -14
  139. package/dist/web-api.js.map +1 -1
  140. package/dist/web-office-acts.d.ts +16 -0
  141. package/dist/web-office-acts.js +27 -9
  142. package/dist/web-office-acts.js.map +1 -1
  143. package/dist/web-office-pack-read.js +1 -1
  144. package/dist/web-office-pack-read.js.map +1 -1
  145. package/dist/web-office-skins.d.ts +5 -3
  146. package/dist/web-office-skins.js +20 -16
  147. package/dist/web-office-skins.js.map +1 -1
  148. package/dist/web-settings-patch.d.ts +27 -0
  149. package/dist/web-settings-patch.js +67 -0
  150. package/dist/web-settings-patch.js.map +1 -1
  151. package/dist/workflow-templates/default.md +1 -0
  152. package/package.json +1 -1
@@ -48,6 +48,7 @@
48
48
  import { t } from "/assets/app-i18n.js";
49
49
  import { frameAt, nameHash } from "./fleet-office-model.js";
50
50
  import { CHAR_DEPTH, LOGICAL, canvasOf, checkSkinPack, own, packPortraitImages, packSceneImages, poseStrip, stripBox, stripCell, stripFrameAt, stripImages, walkStrip } from "./fleet-office-pack.js";
51
+ import { facing } from "./fleet-office-vehicles.js";
51
52
  import { tierColours } from "./fleet-office-levels.js";
52
53
  import { assetUrl } from "/assets/asset-url.js";
53
54
 
@@ -381,13 +382,19 @@ const TAG_FONT = "600 10px system-ui, sans-serif";
381
382
  const COMPACT = { font: "500 9px system-ui, sans-serif", textW: 48, pad: 6, top: 2, h: 11 };
382
383
  const NORMAL = { font: TAG_FONT, textW: TAG_TEXT_W, pad: 10, top: 3, h: 14 };
383
384
  /** The box a name tag under feet at (x, y) takes (what drawTag draws; bubbles keep clear of it, #2513). */
385
+ const tagSizes = new Map();
384
386
  export function tagBox(ctx, x, y, label, compact = false, fit = null) {
385
- const k = compact ? COMPACT : NORMAL;
386
- ctx.save();
387
- ctx.font = k.font;
388
- const t = fitText(ctx, label, k.textW, fit), w = Math.ceil((ctx.measureText ? ctx.measureText(t).width : t.length * 6) + k.pad);
389
- ctx.restore();
390
- return { x: Math.round(x - w / 2), y: y + k.top, w, h: k.h, text: t };
387
+ const k = compact ? COMPACT : NORMAL, key = `${compact ? 1 : 0}${label}`, keep = !!ctx.measureText && !fit; // a fit of its own: measured each time
388
+ let m = keep ? tagSizes.get(key) : null;
389
+ if (!m) {
390
+ ctx.save();
391
+ ctx.font = k.font;
392
+ const t = fitText(ctx, label, k.textW, fit);
393
+ m = { t, w: Math.ceil((ctx.measureText ? ctx.measureText(t).width : t.length * 6) + k.pad) };
394
+ ctx.restore();
395
+ if (keep) { if (tagSizes.size > 500) tagSizes.clear(); tagSizes.set(key, m); }
396
+ }
397
+ return { x: Math.round(x - m.w / 2), y: y + k.top, w: m.w, h: k.h, text: m.t };
391
398
  }
392
399
  /** #2860: what a tag covers with its level badge: on a full tag's top-left corner (clear of the first letter); left of a compact one. */
393
400
  export function tagFootprint(ctx, box, badge, compact = false) {
@@ -658,6 +665,19 @@ export function styleSeats(id) {
658
665
 
659
666
  // ── Skin packs ──
660
667
 
668
+ /**
669
+ * A whole-scene picture (`im`, drawn `w` logical units wide): unsmoothed at 1 device px per picture px or more (pixel
670
+ * art), smoothed (high) when shrunk below that — nearest-neighbour there drops most of its thin lines and keeps others
671
+ * in uneven clusters (a big pack's fit on a phone). Read from the canvas's transform (none: unsmoothed, as before).
672
+ */
673
+ export function sceneSmoothing(ctx, im, w) {
674
+ const t = typeof ctx.getTransform === "function" ? ctx.getTransform() : null;
675
+ const shrunk = !!t && !!im.width && Math.hypot(t.a, t.b) * w < im.width;
676
+ ctx.imageSmoothingEnabled = shrunk;
677
+ if (shrunk) ctx.imageSmoothingQuality = "high";
678
+ return shrunk;
679
+ }
680
+
661
681
  /**
662
682
  * An OfficeSkin from a checked pack (fleet-office-pack.js checkSkinPack) and its loaded pictures (`images`: src → a
663
683
  * drawable image). What it lacks, or a picture not loaded, is drawn by the built-in skins.
@@ -749,12 +769,26 @@ export function spriteSkin(pack, images, base = pixelSkin) {
749
769
  drawBackground(ctx, L, env) {
750
770
  const im = img(pack.background);
751
771
  if (!im) { drawBackground(ctx, L, env); return; }
752
- ctx.save(); ctx.imageSmoothingEnabled = false; ctx.drawImage(im, 0, 0, canvasOf(pack).w, canvasOf(pack).h); ctx.restore();
772
+ ctx.save(); sceneSmoothing(ctx, im, canvasOf(pack).w); ctx.drawImage(im, 0, 0, canvasOf(pack).w, canvasOf(pack).h); ctx.restore();
753
773
  },
754
774
  drawForeground(ctx, L, env) {
755
775
  const im = img(pack.foreground);
756
776
  if (!im) return;
757
- ctx.save(); ctx.imageSmoothingEnabled = false; ctx.drawImage(im, 0, 0, canvasOf(pack).w, canvasOf(pack).h); ctx.restore();
777
+ ctx.save(); sceneSmoothing(ctx, im, canvasOf(pack).w); ctx.drawImage(im, 0, 0, canvasOf(pack).w, canvasOf(pack).h); ctx.restore();
778
+ },
779
+ /** A pack's vehicle where it is (`at`, fleet-office-vehicles.js vehicleAt): its picture for the way it faces
780
+ * (`sprites` by heading; else `sprite`, mirrored going left), playing while it moves, its first frame at a stop. */
781
+ drawVehicle(ctx, v, at, ms, env) {
782
+ const dir = facing(at.heading), by = v.sprites || {};
783
+ const st = by[dir] || (dir === "left" && by.right) || v.sprite || by.right || by.left || by.down || by.up;
784
+ if (!st) return;
785
+ const mirror = !by[dir] && dir === "left";
786
+ strip(ctx, st, at.stop === null ? clipMs(env, `v:${v.id}`, st, ms) : 0, at.x, at.y, at.stop === null ? null : 0, mirror);
787
+ },
788
+ /** Its front edge (`fronts` for the way it faces; going left, `right`'s mirrored), over the riders. */
789
+ drawVehicleFront(ctx, v, at, ms, env) {
790
+ const dir = facing(at.heading), by = v.fronts || {}, st = by[dir] || (dir === "left" && by.right) || null;
791
+ if (st) strip(ctx, st, 0, at.x, at.y, 0, !by[dir] && dir === "left");
758
792
  },
759
793
  drawFurniture(ctx, f, active, ms, env) {
760
794
  if (f.shape) { drawFurniture(ctx, f, active, ms, env); return; }
@@ -26,6 +26,19 @@ const CHOICE_KEY = "agend_org_office", FILTER_KEY = "agend_org_office_filter", S
26
26
  const PLAY_KEY = "agend_org_office_play";
27
27
  /** M-3293: the agents told about their pats and feeds, from this device (a list of names; default: none). */
28
28
  const TELL_KEY = "agend_org_office_tell";
29
+ const MINI_OFF_KEY = "agend_org_office_hide_minimap", NAMES_OFF_KEY = "agend_org_office_hide_names", RENAME_KEY = "agend_org_office_names";
30
+ /** A name this browser gives a person: at most this long; at most RENAME_MAX of them kept. */
31
+ export const RENAME_LEN = 24, RENAME_MAX = 200;
32
+ /** The names this browser gives people ({ instance: name }), kept only when each is a short one-line string. */
33
+ export function renamesOk(v) {
34
+ if (!v || typeof v !== "object" || Array.isArray(v)) return {};
35
+ const out = {};
36
+ for (const [k, n] of Object.entries(v).slice(0, RENAME_MAX)) {
37
+ const s = typeof n === "string" ? n.replace(/[\u0000-\u001f\u007f]/g, "").trim() : "";
38
+ if (k && k.length <= 200 && s && s.length <= RENAME_LEN) out[k] = s;
39
+ }
40
+ return out;
41
+ }
29
42
  const TELL_MAX = 200;
30
43
  /** #2554: "0" when All offices leaves the lobby tile out (default: shown). */
31
44
  const LOBBY_KEY = "agend_org_office_lobby";
@@ -100,10 +113,11 @@ export function actsOk(list, now) {
100
113
  const str = (v) => typeof v === "string" && v.length > 0 && v.length <= 200, num = (v) => typeof v === "number" && Number.isFinite(v);
101
114
  return (Array.isArray(list) ? list : []).filter((a) => a && typeof a === "object" && str(a.instance) && str(a.office) && num(a.until)
102
115
  && (a.x === undefined || num(a.x)) && (a.y === undefined || num(a.y)) && (a.person === undefined || str(a.person))
103
- && (a.say === undefined || (typeof a.say === "string" && a.say.length <= 40)) && (a.pose === undefined || ["idle", "working", "needs", "paused"].includes(a.pose)))
116
+ && (a.say === undefined || (typeof a.say === "string" && a.say.length <= 40)) && (a.pose === undefined || ["idle", "working", "needs", "paused"].includes(a.pose))
117
+ && (a.ride === undefined || str(a.ride)))
104
118
  .map((a) => ({ instance: a.instance, office: a.office, until: a.until - skew, ...(num(a.since) ? { since: a.since } : {}), ...(str(a.state) ? { state: a.state } : {}),
105
119
  ...(num(a.x) && num(a.y) ? { x: a.x, y: a.y } : {}),
106
- ...(a.person ? { person: a.person } : {}), ...(a.say ? { say: a.say } : {}), ...(a.pose ? { pose: a.pose } : {}) }));
120
+ ...(a.person ? { person: a.person } : {}), ...(a.say ? { say: a.say } : {}), ...(a.pose ? { pose: a.pose } : {}), ...(a.ride ? { ride: a.ride } : {}) }));
107
121
  }
108
122
  export function createOfficeStore({ fetch: get = globalThis.fetch, storage } = {}) {
109
123
  const st = () => { try { return storage || globalThis.localStorage || null; } catch { return null; } };
@@ -243,6 +257,23 @@ export function createOfficeStore({ fetch: get = globalThis.fetch, storage } = {
243
257
  /** Whether paused and stopped people are left out of the Office here (default: shown). */
244
258
  hideAsleep: () => read(ASLEEP_KEY) === "1",
245
259
  saveHideAsleep: (v) => write(ASLEEP_KEY, v ? "1" : "0"),
260
+ /** Whether the name tags (and their level badges) are left out of the scene here (default: shown). */
261
+ namesOff: () => read(NAMES_OFF_KEY) === "1",
262
+ saveNamesOff: (v) => write(NAMES_OFF_KEY, v ? "1" : "0"),
263
+ /** Whether the minimap is left out here (default: shown). */
264
+ miniOff: () => read(MINI_OFF_KEY) === "1",
265
+ saveMiniOff: (v) => write(MINI_OFF_KEY, v ? "1" : "0"),
266
+ /** The names this browser gives people ({ instance: name }); only this browser sees them. */
267
+ renames: () => { try { return renamesOk(JSON.parse(read(RENAME_KEY) || "{}")); } catch { return {}; } },
268
+ /** Give `instance` a name here ("" gives back its own); the names as they are now. */
269
+ saveRename: (instance, name) => {
270
+ let all = {};
271
+ try { all = renamesOk(JSON.parse(read(RENAME_KEY) || "{}")); } catch { /* none */ }
272
+ delete all[instance];
273
+ const next = renamesOk(name ? { ...all, [instance]: name } : all);
274
+ write(RENAME_KEY, JSON.stringify(next));
275
+ return next;
276
+ },
246
277
  /** #2568: whether the idle go to bed at night (00:00–06:00 on this device's clock) here (default: off). */
247
278
  nightOn: () => read(NIGHT_KEY) === "1",
248
279
  saveNightOn: (v) => write(NIGHT_KEY, v ? "1" : "0"),
@@ -0,0 +1,130 @@
1
+ // A pack's vehicles (fleet-office-pack.js `vehicles`): a train round a loop of track. Where one is is a function of the
2
+ // wall clock alone, so every page shows it in the same place: it runs round its path at its speed and waits at each
3
+ // stop. People ride by their own choice (an agent's office_set `ride`): they walk to the platform, wait for the train
4
+ // to stop there, board, and ride in a seat (working there, moving with it); they get off only when it stops at a
5
+ // platform, then walk on. Pure — fleet-office.js draws the vehicles and moves the riders (the walkers' `ride`).
6
+
7
+ const LEGS = new WeakMap();
8
+ /** A vehicle's timetable: each leg (a path segment, then its stop's wait), in ms, and the whole lap. */
9
+ function legsOf(v) {
10
+ let t = LEGS.get(v);
11
+ if (t) return t;
12
+ const n = v.path.length, wait = new Map(v.stops.map((s, i) => [s.at, i])), legs = [];
13
+ let at = 0;
14
+ for (let i = 0; i < n; i++) {
15
+ const a = v.path[i], b = v.path[(i + 1) % n], len = Math.hypot(b.x - a.x, b.y - a.y), ms = (len / v.speed) * 1000;
16
+ if (ms > 0) { legs.push({ kind: "run", a, b, from: at, ms }); at += ms; }
17
+ const k = (i + 1) % n;
18
+ if (wait.has(k)) { const si = wait.get(k), s = v.stops[si]; legs.push({ kind: "stop", at: v.path[k], stop: si, from: at, ms: s.seconds * 1000, h: unit(a, b) }); at += s.seconds * 1000; }
19
+ }
20
+ t = { legs, lap: at };
21
+ LEGS.set(v, t);
22
+ return t;
23
+ }
24
+ const unit = (a, b) => { const d = Math.hypot(b.x - a.x, b.y - a.y); return d > 0 ? { x: (b.x - a.x) / d, y: (b.y - a.y) / d } : { x: 1, y: 0 }; };
25
+
26
+ /**
27
+ * Where vehicle `v` is at wall-clock `ms`: { x, y, heading: { x, y } (unit), stop: the stop index it waits at or null,
28
+ * left: ms until it leaves (at a stop) }.
29
+ */
30
+ export function vehicleAt(v, ms) {
31
+ const { legs, lap } = legsOf(v);
32
+ if (!(lap > 0)) return { x: v.path[0].x, y: v.path[0].y, heading: { x: 1, y: 0 }, stop: null, left: 0 };
33
+ const t = ((ms % lap) + lap) % lap;
34
+ for (const g of legs) {
35
+ if (t >= g.from + g.ms) continue;
36
+ const f = (t - g.from) / g.ms;
37
+ if (g.kind === "stop") return { x: g.at.x, y: g.at.y, heading: g.h, stop: g.stop, left: g.ms - (t - g.from) };
38
+ return { x: g.a.x + (g.b.x - g.a.x) * f, y: g.a.y + (g.b.y - g.a.y) * f, heading: unit(g.a, g.b), stop: null, left: 0 };
39
+ }
40
+ const last = legs[legs.length - 1];
41
+ return last.kind === "stop" ? { x: last.at.x, y: last.at.y, heading: last.h, stop: last.stop, left: 0 } : { x: last.b.x, y: last.b.y, heading: unit(last.a, last.b), stop: null, left: 0 };
42
+ }
43
+
44
+ /** Which way a vehicle faces, for its picture: the heading's main axis. */
45
+ export const facing = (h) => (Math.abs(h.x) >= Math.abs(h.y) ? (h.x < 0 ? "left" : "right") : (h.y < 0 ? "up" : "down"));
46
+
47
+ /**
48
+ * Seat `i` of vehicle `v` where it is (`at`, vehicleAt's), its offset (`dx` along the car, `dy` across it, as drawn
49
+ * heading right) placed for the way the car faces: right (dx, dy); left (−dx, dy) — the same deck, mirrored, as the
50
+ * picture is; down (−dy, dx); up (dy, −dx) — the car turned a quarter.
51
+ */
52
+ export function seatAt(v, at, i) {
53
+ const s = v.seats[i] || { dx: 0, dy: 0 }, f = facing(at.heading);
54
+ const [ox, oy] = f === "right" ? [s.dx, s.dy] : f === "left" ? [-s.dx, s.dy] : f === "down" ? [-s.dy, s.dx] : [s.dy, -s.dx];
55
+ return { x: Math.round(at.x + ox), y: Math.round(at.y + oy) };
56
+ }
57
+
58
+ /** How close (logical units) to the platform someone must stand to board, and the least wait left to step on. */
59
+ export const RIDE = { NEAR: 8, BOARD_MS: 400, SETTLE_MS: 60000 };
60
+ /** One lap of vehicle `v`, running and waiting (ms). */
61
+ export const lapMs = (v) => legsOf(v).lap;
62
+
63
+ /**
64
+ * Who is riding, waiting or on their way (one page's own; every page works it out alike from the same clock and acts).
65
+ * step({ wants, vehicles, wall, posOf, homeOf }) once a tick:
66
+ * - `wants`: name → the vehicle id they want to ride, or null (`null` for everyone else in the office);
67
+ * - `vehicles`: id → vehicle; `wall`: the wall clock; `posOf(name)`: where they are ({ x, y, walking }) or null;
68
+ * `homeOf(name)`: their seat (to pick the nearest platform); `sinceOf(name)`: when their ride began (wall clock), so
69
+ * a page opened long after shows them on board, not walking to a train they took long ago; `urgent(name)`: they
70
+ * must get off now (a call: #4415, nothing keeps a caller from the Help desk), where their seat is, between stops too.
71
+ * Returns { targets: name → where to walk now (the platform), board: [{ name, vehicle, seat }], alight: [{ name, at }] };
72
+ * `riding(name)` → { vehicle, seat } while on board; `clear()` forgets everyone and returns who was on board.
73
+ */
74
+ export function createRiders() {
75
+ const by = new Map();
76
+ const near = (a, b) => !!a && !!b && Math.hypot(a.x - b.x, a.y - b.y) <= RIDE.NEAR;
77
+ return {
78
+ step({ wants, vehicles, wall, posOf, homeOf, sinceOf = null, urgent = null }) {
79
+ const targets = new Map(), board = [], alight = [];
80
+ for (const name of [...by.keys()]) if (!wants.has(name)) by.delete(name); // gone from the office
81
+ const used = (vid) => new Set([...by.values()].filter((r) => r.phase === "riding" && r.vehicle === vid).map((r) => r.seat));
82
+ for (const [name, vid] of wants) {
83
+ let r = by.get(name);
84
+ const v = vid ? vehicles.get(vid) : null;
85
+ if (r && r.phase === "riding") {
86
+ const rv = vehicles.get(r.vehicle);
87
+ if (!rv) { // its vehicle is gone: off where they are
88
+ const p = posOf(name);
89
+ if (p) alight.push({ name, at: { x: p.x, y: p.y } });
90
+ by.delete(name); continue;
91
+ }
92
+ const at = vehicleAt(rv, wall);
93
+ if (urgent && urgent(name)) { alight.push({ name, at: seatAt(rv, at, r.seat) }); by.delete(name); continue; }
94
+ if (v && vid === r.vehicle) continue; // riding on
95
+ if (at.stop !== null) { alight.push({ name, at: rv.stops[at.stop].platform }); by.delete(name); }
96
+ continue; // off only at a stop
97
+ }
98
+ if (!v || !v.seats.length || !v.stops.length) { if (r) by.delete(name); continue; }
99
+ // A page opened long after the ride began (more than a lap and the walk ago, `since`): they are on board already.
100
+ const since = sinceOf ? sinceOf(name) : null;
101
+ if (!r && since !== null && wall - since > lapMs(v) + RIDE.SETTLE_MS) {
102
+ const taken = used(vid), seat = v.seats.findIndex((_, i) => !taken.has(i));
103
+ if (seat >= 0) { by.set(name, { phase: "riding", vehicle: vid, seat }); board.push({ name, vehicle: vid, seat }); continue; }
104
+ }
105
+ if (!r || r.vehicle !== vid) {
106
+ const home = homeOf(name) || posOf(name) || v.stops[0].platform;
107
+ let best = 0;
108
+ v.stops.forEach((s, i) => { if (Math.hypot(s.platform.x - home.x, s.platform.y - home.y) < Math.hypot(v.stops[best].platform.x - home.x, v.stops[best].platform.y - home.y)) best = i; });
109
+ r = { phase: "going", vehicle: vid, stop: best };
110
+ by.set(name, r);
111
+ }
112
+ const platform = v.stops[r.stop].platform, here = posOf(name);
113
+ targets.set(name, platform);
114
+ if (r.phase === "going" && here && !here.walking && near(here, platform)) r.phase = "waiting";
115
+ if (r.phase !== "waiting") continue;
116
+ const at = vehicleAt(v, wall);
117
+ if (at.stop !== r.stop || at.left < RIDE.BOARD_MS) continue; // the train is not in (or is leaving)
118
+ const taken = used(vid), seat = v.seats.findIndex((_, i) => !taken.has(i));
119
+ if (seat < 0) continue; // full: wait for the next one
120
+ r.phase = "riding"; r.seat = seat;
121
+ targets.delete(name);
122
+ board.push({ name, vehicle: vid, seat });
123
+ }
124
+ return { targets, board, alight };
125
+ },
126
+ riding(name) { const r = by.get(name); return r && r.phase === "riding" ? { vehicle: r.vehicle, seat: r.seat } : null; },
127
+ phase(name) { const r = by.get(name); return r ? r.phase : null; },
128
+ clear() { const on = [...by].filter(([, r]) => r.phase === "riding").map(([n]) => n); by.clear(); return on; },
129
+ };
130
+ }
@@ -531,6 +531,7 @@ export function createMail({ max = MAIL.MAX } = {}) {
531
531
  export function createWalkers() {
532
532
  const by = new Map();
533
533
  const posAt = (w, now) => {
534
+ if (w.ride) { const p = w.ride(now); return { x: p.x, y: p.y, walking: false, riding: true }; } // on board: where their seat is
534
535
  if (!w.pts) return { x: w.to.x, y: w.to.y, walking: false };
535
536
  const t = (now - w.start) / w.ms;
536
537
  if (t >= 1) return { x: w.to.x, y: w.to.y, walking: false };
@@ -542,7 +543,8 @@ export function createWalkers() {
542
543
  for (const name of [...by.keys()]) if (!targets.has(name)) by.delete(name);
543
544
  for (const [name, to] of targets) {
544
545
  const w = by.get(name);
545
- if (fresh) { by.set(name, { pts: null, to }); continue; }
546
+ if (fresh) { by.set(name, { pts: null, to }); continue; } // a rider too: a new office or style has no such vehicle
547
+ if (w && w.ride) continue; // a rider goes where the vehicle goes (place() gets them off)
546
548
  if (!w || still) { if (!w || w.to.x !== to.x || w.to.y !== to.y) by.set(name, { pts: null, to }); continue; }
547
549
  if (w.to.x === to.x && w.to.y === to.y) continue;
548
550
  const here = posAt(w, now), via = routeVia(graph, { x: here.x, y: here.y }, { x: to.x, y: to.y });
@@ -555,6 +557,8 @@ export function createWalkers() {
555
557
  /** M-3293: `name` set down at `at` (picked up and carried, or just dropped): standing there, no walk; the next sync
556
558
  * walks them from there to their target along the graph, as any walk. */
557
559
  place(name, at) { by.set(name, { pts: null, to: { x: at.x, y: at.y } }); },
560
+ /** On board a vehicle: `seat(now)` is where they are (fleet-office-vehicles.js seatAt); place() gets them off. */
561
+ ride(name, seat) { by.set(name, { ride: seat }); },
558
562
  moving(now) { for (const w of by.values()) if (posAt(w, now).walking) return true; return false; },
559
563
  };
560
564
  }