@cfbender/cesium 0.7.1 → 0.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cfbender/cesium",
3
- "version": "0.7.1",
3
+ "version": "0.7.3",
4
4
  "description": "Beautiful self-contained HTML artifacts from your opencode agent.",
5
5
  "keywords": [
6
6
  "agent",
package/src/index.ts CHANGED
@@ -12,6 +12,7 @@ import { createStyleguideTool } from "./tools/styleguide.ts";
12
12
  import { createCritiqueTool } from "./tools/critique.ts";
13
13
  import { createStopTool } from "./tools/stop.ts";
14
14
  import { generateBlockFieldReference } from "./prompt/field-reference.ts";
15
+ import { recordSessionModel } from "./session-model.ts";
15
16
 
16
17
  const rawFragment = await readFile(
17
18
  join(dirname(fileURLToPath(import.meta.url)), "prompt/system-fragment.md"),
@@ -37,6 +38,11 @@ export const CesiumPlugin: Plugin = async (ctx): Promise<Hooks> => {
37
38
  "experimental.chat.system.transform": async (_input, output) => {
38
39
  output.system.push(PROMPT_FRAGMENT);
39
40
  },
41
+ "chat.params": async (input, _output) => {
42
+ // Record the model resolved for this session so tool handlers can stamp
43
+ // it onto generated artifacts. Latest call wins (model can change mid-session).
44
+ recordSessionModel(input.sessionID, input.model.providerID, input.model.id);
45
+ },
40
46
  };
41
47
  };
42
48
 
@@ -896,12 +896,21 @@ export function getClientJs(): string {
896
896
 
897
897
  menu.hidden = false;
898
898
  var menuRect = menu.getBoundingClientRect();
899
- var top = rect.bottom + window.scrollY + 6;
900
- var left = rect.right + window.scrollX - menuRect.width;
899
+ // The menu uses position: fixed, so coordinates are viewport-relative —
900
+ // do NOT add window.scrollX/scrollY here, or the menu gets parked at
901
+ // (rect + scrollY) which is off-screen as soon as the user scrolls.
902
+ var top = rect.bottom + 6;
903
+ var left = rect.right - menuRect.width;
901
904
  // Clamp to viewport
902
905
  var vpW = window.innerWidth || document.documentElement.clientWidth;
906
+ var vpH = window.innerHeight || document.documentElement.clientHeight;
903
907
  if (left + menuRect.width > vpW - 8) left = vpW - menuRect.width - 8;
904
908
  if (left < 8) left = 8;
909
+ // If the menu would fall below the viewport, flip above the selection.
910
+ if (top + menuRect.height > vpH - 8) {
911
+ top = rect.top - menuRect.height - 6;
912
+ }
913
+ if (top < 8) top = 8;
905
914
  menu.style.top = top + "px";
906
915
  menu.style.left = left + "px";
907
916
 
@@ -1134,14 +1134,24 @@ body { position: relative; }
1134
1134
  z-index: 50;
1135
1135
  }
1136
1136
  /* When annotate is active and viewport has room for page + rail side-by-side,
1137
- shift .page leftward so its right edge (and the .cs-anchor-affordance-block
1138
- button parked at right: 8px of each annotatable block) does not slide under
1139
- the rail. Required viewport width: 1120 (page) + 24 (gap) + 280 (rail) +
1140
- 24 (right gutter) = 1448px. */
1137
+ shift the content area leftward so its right edge (and the
1138
+ .cs-anchor-affordance-block button parked at right: 8px of each annotatable
1139
+ block) does not slide under the rail.
1140
+
1141
+ Artifacts have no .page wrapper — content sits directly in <body>. So we
1142
+ shrink the body content via padding-right. The legacy .page rule remains so
1143
+ the same shift works on index pages.
1144
+
1145
+ Required viewport width: 1120 (page) + 24 (gap) + 280 (rail) + 24 (right
1146
+ gutter) = 1448px. */
1141
1147
  @media (min-width: 1448px) {
1148
+ body.cs-annotate-active,
1149
+ body:has(.cs-annotate-scaffold) {
1150
+ padding-right: 328px; /* rail width (280) + outer gutter (24) + inner gap (24) */
1151
+ }
1142
1152
  body.cs-annotate-active .page,
1143
1153
  body:has(.cs-annotate-scaffold) .page {
1144
- margin-right: 328px; /* rail width (280) + outer gutter (24) + inner gap (24) */
1154
+ margin-right: 0;
1145
1155
  margin-left: auto;
1146
1156
  }
1147
1157
  }
@@ -0,0 +1,23 @@
1
+ // Tracks the model in use per opencode session.
2
+ //
3
+ // opencode's `chat.params` hook fires before each LLM request with the resolved
4
+ // Model. We record `providerID/id` keyed by sessionID so that tool handlers
5
+ // (publish/ask/annotate) can stamp the generating model onto every artifact's
6
+ // metadata footer. The map is process-local and resets on plugin reload.
7
+
8
+ const sessionModels = new Map<string, string>();
9
+
10
+ export function recordSessionModel(sessionID: string, providerID: string, modelID: string): void {
11
+ if (!sessionID || !providerID || !modelID) return;
12
+ sessionModels.set(sessionID, `${providerID}/${modelID}`);
13
+ }
14
+
15
+ export function getSessionModel(sessionID: string | undefined | null): string | null {
16
+ if (!sessionID) return null;
17
+ return sessionModels.get(sessionID) ?? null;
18
+ }
19
+
20
+ /** Test-only: clear all recorded session models. */
21
+ export function resetSessionModels(): void {
22
+ sessionModels.clear();
23
+ }
@@ -26,6 +26,7 @@ import {
26
26
  type LifecycleConfig,
27
27
  } from "../server/lifecycle.ts";
28
28
  import { buildTerminalSummary, resolveDisplayHost } from "./publish.ts";
29
+ import { getSessionModel } from "../session-model.ts";
29
30
 
30
31
  export interface AnnotateToolOverrides {
31
32
  loadConfig?: () => CesiumConfig;
@@ -84,7 +85,7 @@ export function createAnnotateTool(
84
85
  tags: tool.schema.array(tool.schema.string()).optional(),
85
86
  expiresAt: tool.schema.string().optional(),
86
87
  },
87
- async execute(args, _context) {
88
+ async execute(args, context) {
88
89
  // 1. Validate top-level input shape
89
90
  const validation = validateAnnotateInput(args);
90
91
  if (!validation.ok) {
@@ -181,8 +182,8 @@ export function createAnnotateTool(
181
182
  summary: input.summary ?? null,
182
183
  tags: input.tags ?? [],
183
184
  createdAt: createdAt.toISOString(),
184
- model: null,
185
- sessionId: null,
185
+ model: getSessionModel(context.sessionID),
186
+ sessionId: context.sessionID ?? null,
186
187
  projectSlug: identity.slug,
187
188
  projectName: identity.name,
188
189
  cwd: ctx.directory,
package/src/tools/ask.ts CHANGED
@@ -25,6 +25,7 @@ import {
25
25
  type LifecycleConfig,
26
26
  } from "../server/lifecycle.ts";
27
27
  import { buildTerminalSummary, resolveDisplayHost } from "./publish.ts";
28
+ import { getSessionModel } from "../session-model.ts";
28
29
 
29
30
  export interface AskToolOverrides {
30
31
  loadConfig?: () => CesiumConfig;
@@ -106,7 +107,7 @@ export function createAskTool(
106
107
  expiresAt: tool.schema.string().optional(),
107
108
  requireAll: tool.schema.boolean().optional(),
108
109
  },
109
- async execute(args, _context) {
110
+ async execute(args, context) {
110
111
  // 1. Validate input
111
112
  const validation = validateAskInput(args);
112
113
  if (!validation.ok) {
@@ -193,8 +194,8 @@ export function createAskTool(
193
194
  summary: input.summary ?? null,
194
195
  tags: input.tags ?? [],
195
196
  createdAt: createdAt.toISOString(),
196
- model: null,
197
- sessionId: null,
197
+ model: getSessionModel(context.sessionID),
198
+ sessionId: context.sessionID ?? null,
198
199
  projectSlug: identity.slug,
199
200
  projectName: identity.name,
200
201
  cwd: ctx.directory,
@@ -31,6 +31,7 @@ import {
31
31
  type RunningInfo,
32
32
  type LifecycleConfig,
33
33
  } from "../server/lifecycle.ts";
34
+ import { getSessionModel } from "../session-model.ts";
34
35
 
35
36
  export interface PublishToolOverrides {
36
37
  loadConfig?: () => CesiumConfig;
@@ -107,7 +108,7 @@ export function createPublishTool(
107
108
  tags: tool.schema.array(tool.schema.string()).optional(),
108
109
  supersedes: tool.schema.string().optional(),
109
110
  },
110
- async execute(args, _context) {
111
+ async execute(args, context) {
111
112
  // 1. Validate input
112
113
  const validation = validatePublishInput(args);
113
114
  if (!validation.ok) {
@@ -190,8 +191,8 @@ export function createPublishTool(
190
191
  summary: input.summary ?? null,
191
192
  tags: input.tags ?? [],
192
193
  createdAt: createdAt.toISOString(),
193
- model: null,
194
- sessionId: null,
194
+ model: getSessionModel(context.sessionID),
195
+ sessionId: context.sessionID ?? null,
195
196
  projectSlug: identity.slug,
196
197
  projectName: identity.name,
197
198
  cwd: ctx.directory,