@shuind/dsh-codex-harness 0.2.11 → 0.2.13

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/lib/client.js CHANGED
@@ -14,6 +14,11 @@ window.__ModuleLoader__.load({
14
14
  /** User-selectable Codex context controls use whole K-token units. */
15
15
  const CODEX_CONTEXT_UNIT = 1e3;
16
16
  const CODEX_CONTEXT_MAX = 1e6;
17
+ const CODEX_PRESET_IDS = /* @__PURE__ */ new Set(["codex", "codex-collaboration"]);
18
+ /** The bundled preset and legacy Codex sessions share the same Web controls. */
19
+ function isCodexPresetId(value) {
20
+ return value !== void 0 && CODEX_PRESET_IDS.has(value);
21
+ }
17
22
  //#endregion
18
23
  //#region lib/types/prompt.js
19
24
  /** Default plugin-owned Codex operating prompt. */
@@ -77,21 +82,23 @@ window.__ModuleLoader__.load({
77
82
  }
78
83
  /** Infer the request-phase clock from the existing conversation snapshot. */
79
84
  function awaitingModelStartedAt(snapshot) {
80
- if (!snapshot.running || snapshot.runningCalls.length > 0) return void 0;
85
+ if (!snapshot.running || (snapshot.runningCalls?.length ?? 0) > 0) return void 0;
86
+ if (snapshot.turnTimings === void 0) return void 0;
81
87
  let latest;
82
88
  for (const timing of snapshot.turnTimings.values()) if (timing.endTime === void 0) latest = timing.startTime;
83
89
  return latest;
84
90
  }
85
91
  /** Infer the first non-empty model token timestamp from the current snapshot. */
86
92
  function modelReplyStartedAt(snapshot) {
87
- if (!snapshot.running || snapshot.runningCalls.length > 0) return void 0;
93
+ if (!snapshot.running || (snapshot.runningCalls?.length ?? 0) > 0) return void 0;
94
+ if (snapshot.turnTimings === void 0) return void 0;
88
95
  let openTurn;
89
96
  for (const [turn, timing] of snapshot.turnTimings) if (timing.endTime === void 0) openTurn = {
90
97
  turn,
91
98
  startTime: timing.startTime
92
99
  };
93
100
  if (openTurn === void 0) return void 0;
94
- if (snapshot.partial !== null && snapshot.partial.turn === openTurn.turn) {
101
+ if (snapshot.partial !== void 0 && snapshot.partial !== null && snapshot.partial.turn === openTurn.turn) {
95
102
  const partialReplyStartedAt = snapshot.partial.replyStartedAt;
96
103
  if (partialReplyStartedAt !== void 0) return partialReplyStartedAt;
97
104
  }
@@ -979,6 +986,139 @@ window.__ModuleLoader__.load({
979
986
  ]
980
987
  });
981
988
  }
989
+ /** Detect the host meter so the fallback does not duplicate its ring button. */
990
+ function hasHostContextMeter() {
991
+ if (typeof document === "undefined") return false;
992
+ return [...document.querySelectorAll("button[aria-haspopup=\"dialog\"]")].some((button) => button.querySelectorAll("circle").length >= 2);
993
+ }
994
+ function useHostContextMeter() {
995
+ const [available, setAvailable] = (0, react.useState)(false);
996
+ (0, react.useEffect)(() => {
997
+ if (typeof document === "undefined" || document.body === null) return void 0;
998
+ const refresh = () => {
999
+ setAvailable(hasHostContextMeter());
1000
+ };
1001
+ refresh();
1002
+ const observer = new MutationObserver(refresh);
1003
+ observer.observe(document.body, {
1004
+ subtree: true,
1005
+ childList: true,
1006
+ attributes: true,
1007
+ attributeFilter: ["aria-expanded"]
1008
+ });
1009
+ return () => observer.disconnect();
1010
+ }, []);
1011
+ return available;
1012
+ }
1013
+ /** Keep context configuration reachable before the host has a pressure meter. */
1014
+ function ContextSizeFallback({ sessionId, useSessions, useProjection, useSettings, setSetting, unsetSetting, t }) {
1015
+ const agentPreset = useSessions((state) => state.byId[sessionId]?.agentPreset);
1016
+ const hostMeter = useHostContextMeter();
1017
+ const contextWindow = contextWindowFromProjection(useProjection);
1018
+ const snapshot = useSettings((state) => state);
1019
+ const configured = snapshot.value?.contextWindow;
1020
+ const valueK = Math.min(CODEX_CONTEXT_MAX / CODEX_CONTEXT_UNIT, Math.max(1, Math.round((configured ?? contextWindow) / CODEX_CONTEXT_UNIT)));
1021
+ const [open, setOpen] = (0, react.useState)(false);
1022
+ const rootRef = (0, react.useRef)(null);
1023
+ (0, react.useEffect)(() => {
1024
+ if (!open) return void 0;
1025
+ const onPointerDown = (event) => {
1026
+ if (event.target instanceof Node && rootRef.current?.contains(event.target) === true) return;
1027
+ setOpen(false);
1028
+ };
1029
+ const onKeyDown = (event) => {
1030
+ if (event.key === "Escape") setOpen(false);
1031
+ };
1032
+ document.addEventListener("pointerdown", onPointerDown);
1033
+ document.addEventListener("keydown", onKeyDown);
1034
+ return () => {
1035
+ document.removeEventListener("pointerdown", onPointerDown);
1036
+ document.removeEventListener("keydown", onKeyDown);
1037
+ };
1038
+ }, [open]);
1039
+ if (!isCodexPresetId(agentPreset) || hostMeter) return null;
1040
+ return (0, react_jsx_runtime.jsxs)("span", {
1041
+ ref: rootRef,
1042
+ style: {
1043
+ position: "relative",
1044
+ display: "inline-flex",
1045
+ alignItems: "center"
1046
+ },
1047
+ children: [(0, react_jsx_runtime.jsxs)("button", {
1048
+ type: "button",
1049
+ "aria-label": `${t("contextSize")}: ${valueK}K`,
1050
+ "aria-haspopup": "dialog",
1051
+ "aria-expanded": open,
1052
+ disabled: snapshot.writable === false,
1053
+ title: t("contextSize"),
1054
+ onMouseDown: (event) => {
1055
+ event.preventDefault();
1056
+ },
1057
+ onClick: () => {
1058
+ setOpen((value) => !value);
1059
+ },
1060
+ style: {
1061
+ boxSizing: "border-box",
1062
+ display: "inline-flex",
1063
+ alignItems: "center",
1064
+ gap: 3,
1065
+ height: 28,
1066
+ border: 0,
1067
+ borderRadius: 7,
1068
+ padding: "0 6px",
1069
+ color: configured === void 0 ? "var(--dsw-alias-label-secondary)" : "var(--dsw-static-blue-500)",
1070
+ background: open ? "var(--dsw-alias-interactive-bg-hover)" : "transparent",
1071
+ cursor: snapshot.writable === false ? "default" : "pointer",
1072
+ font: "inherit",
1073
+ fontSize: 12,
1074
+ lineHeight: "20px",
1075
+ fontWeight: configured === void 0 ? 400 : 600,
1076
+ whiteSpace: "nowrap"
1077
+ },
1078
+ children: [(0, react_jsx_runtime.jsxs)("span", { children: [valueK, "K"] }), (0, react_jsx_runtime.jsx)("svg", {
1079
+ viewBox: "0 0 12 12",
1080
+ width: "12",
1081
+ height: "12",
1082
+ "aria-hidden": true,
1083
+ children: (0, react_jsx_runtime.jsx)("path", {
1084
+ d: "M3 4.5 6 7.5 9 4.5",
1085
+ fill: "none",
1086
+ stroke: "currentColor",
1087
+ strokeWidth: "1.25",
1088
+ strokeLinecap: "round",
1089
+ strokeLinejoin: "round"
1090
+ })
1091
+ })]
1092
+ }), open && (0, react_jsx_runtime.jsx)("div", {
1093
+ role: "dialog",
1094
+ "aria-label": t("contextSize"),
1095
+ style: {
1096
+ position: "absolute",
1097
+ right: 0,
1098
+ bottom: "calc(100% + 8px)",
1099
+ zIndex: 20,
1100
+ boxSizing: "border-box",
1101
+ width: 300,
1102
+ maxWidth: "calc(100vw - 24px)",
1103
+ padding: "10px 12px 12px",
1104
+ border: "1px solid var(--dsw-alias-border-l2)",
1105
+ borderRadius: 10,
1106
+ color: "var(--dsw-alias-label-primary)",
1107
+ background: "var(--dsw-alias-bg-base)",
1108
+ boxShadow: "var(--dsw-shadow-lv2)"
1109
+ },
1110
+ children: (0, react_jsx_runtime.jsx)(ContextSizeControl, {
1111
+ contextWindow,
1112
+ sessionId,
1113
+ useSessions,
1114
+ useSettings,
1115
+ setSetting,
1116
+ unsetSetting,
1117
+ t
1118
+ })
1119
+ })]
1120
+ });
1121
+ }
982
1122
  function elapsedSeconds(startedAt, now) {
983
1123
  return Math.max(0, Math.floor((now - startedAt) / 1e3));
984
1124
  }
@@ -1080,57 +1220,13 @@ window.__ModuleLoader__.load({
1080
1220
  const preferred = statuses.filter(isTurnStatus);
1081
1221
  return preferred.findLast(hasLayout) ?? preferred.at(-1) ?? statuses.filter((status) => status.closest("[data-chat-flow]") !== null).findLast(hasLayout) ?? statuses.filter((status) => status.closest("[data-chat-flow]") !== null).at(-1) ?? null;
1082
1222
  }
1083
- function findTurnStatus() {
1084
- return selectTurnStatus([...document.querySelectorAll("[role=\"status\"]")]);
1085
- }
1086
- function useTurnStatusPosition(target) {
1087
- const [position, setPosition] = (0, react.useState)(null);
1088
- (0, react.useLayoutEffect)(() => {
1089
- if (target === null) {
1090
- setPosition(null);
1091
- return;
1092
- }
1093
- const update = () => {
1094
- if (!target.isConnected) {
1095
- setPosition(null);
1096
- return;
1097
- }
1098
- const rect = target.getBoundingClientRect();
1099
- if (rect.width === 0 && rect.height === 0) {
1100
- setPosition(null);
1101
- return;
1102
- }
1103
- setPosition({
1104
- left: Math.round(rect.right + 10),
1105
- top: Math.round(rect.top + (rect.height - 26) / 2)
1106
- });
1107
- };
1108
- update();
1109
- window.addEventListener("resize", update);
1110
- window.addEventListener("scroll", update, true);
1111
- const observer = typeof ResizeObserver === "undefined" ? void 0 : new ResizeObserver(update);
1112
- observer?.observe(target);
1113
- return () => {
1114
- window.removeEventListener("resize", update);
1115
- window.removeEventListener("scroll", update, true);
1116
- observer?.disconnect();
1117
- };
1118
- }, [target]);
1119
- return position;
1120
- }
1121
1223
  function useLegacyHostTargets() {
1122
- const [targets, setTargets] = (0, react.useState)({
1123
- contextDialog: null,
1124
- turnStatus: null
1125
- });
1224
+ const [targets, setTargets] = (0, react.useState)({ contextDialog: null });
1126
1225
  (0, react.useEffect)(() => {
1127
1226
  if (typeof document === "undefined" || document.body === null) return void 0;
1128
1227
  const refresh = () => {
1129
- const next = {
1130
- contextDialog: findContextMeterDialog(),
1131
- turnStatus: findTurnStatus()
1132
- };
1133
- setTargets((current) => current.contextDialog === next.contextDialog && current.turnStatus === next.turnStatus ? current : next);
1228
+ const next = { contextDialog: findContextMeterDialog() };
1229
+ setTargets((current) => current.contextDialog === next.contextDialog ? current : next);
1134
1230
  };
1135
1231
  refresh();
1136
1232
  const observer = new MutationObserver(refresh);
@@ -1146,11 +1242,10 @@ window.__ModuleLoader__.load({
1146
1242
  }
1147
1243
  /** Bridges plugin UI into DOM sites rendered by the legacy conversation host. */
1148
1244
  function LegacyOverlay(props) {
1149
- const { sessionId, useSession, useSessions, useProjection, useSettings, setSetting, unsetSetting, t } = props;
1150
- const { contextDialog, turnStatus } = useLegacyHostTargets();
1151
- const turnStatusPosition = useTurnStatusPosition(turnStatus);
1245
+ const { sessionId, useSessions, useProjection, useSettings, setSetting, unsetSetting, t } = props;
1246
+ const { contextDialog } = useLegacyHostTargets();
1152
1247
  const contextWindow = contextWindowFromProjection(useProjection);
1153
- return (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [contextDialog !== null && (0, react_dom.createPortal)((0, react_jsx_runtime.jsx)(ContextSizeControl, {
1248
+ return (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: contextDialog !== null && (0, react_dom.createPortal)((0, react_jsx_runtime.jsx)(ContextSizeControl, {
1154
1249
  contextWindow,
1155
1250
  sessionId,
1156
1251
  useSessions,
@@ -1158,15 +1253,19 @@ window.__ModuleLoader__.load({
1158
1253
  setSetting,
1159
1254
  unsetSetting,
1160
1255
  t
1161
- }), contextDialog, "codex-context-size"), turnStatusPosition !== null && typeof document !== "undefined" && document.body !== null && (0, react_dom.createPortal)((0, react_jsx_runtime.jsx)(ActivityLine, {
1162
- sessionId,
1163
- useSession,
1164
- useSessions,
1165
- useProjection,
1166
- useSettings,
1167
- t,
1168
- position: turnStatusPosition
1169
- }), document.body, "codex-activity")] });
1256
+ }), contextDialog, "codex-context-size") });
1257
+ }
1258
+ /** Stable composer fallback for hosts whose transient turn-status node is absent. */
1259
+ function ActivityDock(props) {
1260
+ return (0, react_jsx_runtime.jsx)("div", {
1261
+ style: {
1262
+ display: "flex",
1263
+ alignItems: "center",
1264
+ minHeight: 28,
1265
+ padding: "4px 10px"
1266
+ },
1267
+ children: (0, react_jsx_runtime.jsx)(ActivityLine, { ...props })
1268
+ });
1170
1269
  }
1171
1270
  const inject = [
1172
1271
  "commandUi",
@@ -1221,6 +1320,20 @@ window.__ModuleLoader__.load({
1221
1320
  locale: NS,
1222
1321
  inject: injected
1223
1322
  }, FastModeFallback));
1323
+ ctx.slots.inject(FAST_FALLBACK_SLOT, () => ctx.slots.register({
1324
+ name: FAST_FALLBACK_SLOT,
1325
+ id: "codex-context-size-fallback",
1326
+ order: 1,
1327
+ locale: NS,
1328
+ inject: injected
1329
+ }, ContextSizeFallback));
1330
+ ctx.slots.inject("conversation.composer.dock", () => ctx.slots.register({
1331
+ name: "conversation.composer.dock",
1332
+ id: "codex-activity-fallback",
1333
+ order: 5,
1334
+ locale: NS,
1335
+ inject: injected
1336
+ }, ActivityDock));
1224
1337
  ctx.slots.inject(LEGACY_OVERLAY_SLOT, () => ctx.slots.register({
1225
1338
  name: LEGACY_OVERLAY_SLOT,
1226
1339
  id: "codex-legacy-overlay",
@@ -1,6 +1,10 @@
1
1
  /** Client-only inference used while the host activity projection frame is in flight. */
2
2
  import type { ConversationSnapshot } from '@deepseek-ai/dsh-client-runtime/client';
3
- export type ActivitySessionSnapshot = Pick<ConversationSnapshot, 'running' | 'partial' | 'runningCalls' | 'turnTimings'> & {
3
+ export type ActivitySessionSnapshot = Pick<ConversationSnapshot, 'running'> & {
4
+ /** Optional because older/newer hosts can publish the shell snapshot before the chat slice. */
5
+ readonly partial?: ConversationSnapshot['partial'];
6
+ readonly runningCalls?: ConversationSnapshot['runningCalls'];
7
+ readonly turnTimings?: ConversationSnapshot['turnTimings'];
4
8
  /** Optional for hosts that predate the assembled Chat snapshot. */
5
9
  readonly chat?: ConversationSnapshot['chat'];
6
10
  };
@@ -5,7 +5,9 @@ export function sameModelActivity(left, right) {
5
5
  }
6
6
  /** Infer the request-phase clock from the existing conversation snapshot. */
7
7
  export function awaitingModelStartedAt(snapshot) {
8
- if (!snapshot.running || snapshot.runningCalls.length > 0)
8
+ if (!snapshot.running || (snapshot.runningCalls?.length ?? 0) > 0)
9
+ return undefined;
10
+ if (snapshot.turnTimings === undefined)
9
11
  return undefined;
10
12
  let latest;
11
13
  for (const timing of snapshot.turnTimings.values()) {
@@ -16,7 +18,9 @@ export function awaitingModelStartedAt(snapshot) {
16
18
  }
17
19
  /** Infer the first non-empty model token timestamp from the current snapshot. */
18
20
  export function modelReplyStartedAt(snapshot) {
19
- if (!snapshot.running || snapshot.runningCalls.length > 0)
21
+ if (!snapshot.running || (snapshot.runningCalls?.length ?? 0) > 0)
22
+ return undefined;
23
+ if (snapshot.turnTimings === undefined)
20
24
  return undefined;
21
25
  let openTurn;
22
26
  for (const [turn, timing] of snapshot.turnTimings) {
@@ -25,7 +29,7 @@ export function modelReplyStartedAt(snapshot) {
25
29
  }
26
30
  if (openTurn === undefined)
27
31
  return undefined;
28
- if (snapshot.partial !== null && snapshot.partial.turn === openTurn.turn) {
32
+ if (snapshot.partial !== undefined && snapshot.partial !== null && snapshot.partial.turn === openTurn.turn) {
29
33
  const partialReplyStartedAt = snapshot.partial.replyStartedAt;
30
34
  if (partialReplyStartedAt !== undefined)
31
35
  return partialReplyStartedAt;
@@ -1,8 +1,8 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  /** Browser controls for Codex requests and the editable operating prompt. */
3
- import { useEffect, useLayoutEffect, useState } from 'react';
3
+ import { useEffect, useRef, useState } from 'react';
4
4
  import { createPortal } from 'react-dom';
5
- import { CODEX_CONTEXT_MAX, CODEX_CONTEXT_UNIT } from "../context.js";
5
+ import { CODEX_CONTEXT_MAX, CODEX_CONTEXT_UNIT, isCodexPresetId } from "../context.js";
6
6
  import { DEFAULT_CODEX_PERSONA, DEFAULT_CODEX_SYSTEM_PROMPT, DEFAULT_DSH_CORE_SOURCE_PROMPT, DEFAULT_DSH_CORE_WEB_PROMPT, } from "../prompt.js";
7
7
  import { modelActivity, sameModelActivity } from "./activity.js";
8
8
  const NS = 'codex';
@@ -412,6 +412,97 @@ function ContextSizeControl({ contextWindow, sessionId: _sessionId, useSessions:
412
412
  fontSize: 11,
413
413
  }, children: t('contextRestore') }))] }));
414
414
  }
415
+ /** Detect the host meter so the fallback does not duplicate its ring button. */
416
+ function hasHostContextMeter() {
417
+ if (typeof document === 'undefined')
418
+ return false;
419
+ return [...document.querySelectorAll('button[aria-haspopup="dialog"]')]
420
+ .some(button => button.querySelectorAll('circle').length >= 2);
421
+ }
422
+ function useHostContextMeter() {
423
+ const [available, setAvailable] = useState(false);
424
+ useEffect(() => {
425
+ if (typeof document === 'undefined' || document.body === null)
426
+ return undefined;
427
+ const refresh = () => { setAvailable(hasHostContextMeter()); };
428
+ refresh();
429
+ const observer = new MutationObserver(refresh);
430
+ observer.observe(document.body, {
431
+ subtree: true,
432
+ childList: true,
433
+ attributes: true,
434
+ attributeFilter: ['aria-expanded'],
435
+ });
436
+ return () => observer.disconnect();
437
+ }, []);
438
+ return available;
439
+ }
440
+ /** Keep context configuration reachable before the host has a pressure meter. */
441
+ function ContextSizeFallback({ sessionId, useSessions, useProjection, useSettings, setSetting, unsetSetting, t, }) {
442
+ const agentPreset = useSessions(state => state.byId[sessionId]?.agentPreset);
443
+ const hostMeter = useHostContextMeter();
444
+ const contextWindow = contextWindowFromProjection(useProjection);
445
+ const snapshot = useSettings(state => state);
446
+ const configured = snapshot.value?.contextWindow;
447
+ const valueK = Math.min(CODEX_CONTEXT_MAX / CODEX_CONTEXT_UNIT, Math.max(1, Math.round((configured ?? contextWindow) / CODEX_CONTEXT_UNIT)));
448
+ const [open, setOpen] = useState(false);
449
+ const rootRef = useRef(null);
450
+ useEffect(() => {
451
+ if (!open)
452
+ return undefined;
453
+ const onPointerDown = (event) => {
454
+ if (event.target instanceof Node && rootRef.current?.contains(event.target) === true)
455
+ return;
456
+ setOpen(false);
457
+ };
458
+ const onKeyDown = (event) => {
459
+ if (event.key === 'Escape')
460
+ setOpen(false);
461
+ };
462
+ document.addEventListener('pointerdown', onPointerDown);
463
+ document.addEventListener('keydown', onKeyDown);
464
+ return () => {
465
+ document.removeEventListener('pointerdown', onPointerDown);
466
+ document.removeEventListener('keydown', onKeyDown);
467
+ };
468
+ }, [open]);
469
+ if (!isCodexPresetId(agentPreset) || hostMeter)
470
+ return null;
471
+ return (_jsxs("span", { ref: rootRef, style: { position: 'relative', display: 'inline-flex', alignItems: 'center' }, children: [_jsxs("button", { type: "button", "aria-label": `${t('contextSize')}: ${valueK}K`, "aria-haspopup": "dialog", "aria-expanded": open, disabled: snapshot.writable === false, title: t('contextSize'), onMouseDown: event => { event.preventDefault(); }, onClick: () => { setOpen(value => !value); }, style: {
472
+ boxSizing: 'border-box',
473
+ display: 'inline-flex',
474
+ alignItems: 'center',
475
+ gap: 3,
476
+ height: 28,
477
+ border: 0,
478
+ borderRadius: 7,
479
+ padding: '0 6px',
480
+ color: configured === undefined
481
+ ? 'var(--dsw-alias-label-secondary)'
482
+ : 'var(--dsw-static-blue-500)',
483
+ background: open ? 'var(--dsw-alias-interactive-bg-hover)' : 'transparent',
484
+ cursor: snapshot.writable === false ? 'default' : 'pointer',
485
+ font: 'inherit',
486
+ fontSize: 12,
487
+ lineHeight: '20px',
488
+ fontWeight: configured === undefined ? 400 : 600,
489
+ whiteSpace: 'nowrap',
490
+ }, children: [_jsxs("span", { children: [valueK, "K"] }), _jsx("svg", { viewBox: "0 0 12 12", width: "12", height: "12", "aria-hidden": true, children: _jsx("path", { d: "M3 4.5 6 7.5 9 4.5", fill: "none", stroke: "currentColor", strokeWidth: "1.25", strokeLinecap: "round", strokeLinejoin: "round" }) })] }), open && (_jsx("div", { role: "dialog", "aria-label": t('contextSize'), style: {
491
+ position: 'absolute',
492
+ right: 0,
493
+ bottom: 'calc(100% + 8px)',
494
+ zIndex: 20,
495
+ boxSizing: 'border-box',
496
+ width: 300,
497
+ maxWidth: 'calc(100vw - 24px)',
498
+ padding: '10px 12px 12px',
499
+ border: '1px solid var(--dsw-alias-border-l2)',
500
+ borderRadius: 10,
501
+ color: 'var(--dsw-alias-label-primary)',
502
+ background: 'var(--dsw-alias-bg-base)',
503
+ boxShadow: 'var(--dsw-shadow-lv2)',
504
+ }, children: _jsx(ContextSizeControl, { contextWindow: contextWindow, sessionId: sessionId, useSessions: useSessions, useSettings: useSettings, setSetting: setSetting, unsetSetting: unsetSetting, t: t }) }))] }));
505
+ }
415
506
  function elapsedSeconds(startedAt, now) {
416
507
  return Math.max(0, Math.floor((now - startedAt) / 1_000));
417
508
  }
@@ -511,56 +602,14 @@ export function selectTurnStatus(statuses) {
511
602
  ?? statuses.filter(status => status.closest('[data-chat-flow]') !== null).at(-1)
512
603
  ?? null;
513
604
  }
514
- function findTurnStatus() {
515
- return selectTurnStatus([...document.querySelectorAll('[role="status"]')]);
516
- }
517
- function useTurnStatusPosition(target) {
518
- const [position, setPosition] = useState(null);
519
- useLayoutEffect(() => {
520
- if (target === null) {
521
- setPosition(null);
522
- return undefined;
523
- }
524
- const update = () => {
525
- if (!target.isConnected) {
526
- setPosition(null);
527
- return;
528
- }
529
- const rect = target.getBoundingClientRect();
530
- if (rect.width === 0 && rect.height === 0) {
531
- setPosition(null);
532
- return;
533
- }
534
- setPosition({
535
- left: Math.round(rect.right + 10),
536
- top: Math.round(rect.top + (rect.height - 26) / 2),
537
- });
538
- };
539
- update();
540
- window.addEventListener('resize', update);
541
- window.addEventListener('scroll', update, true);
542
- const observer = typeof ResizeObserver === 'undefined' ? undefined : new ResizeObserver(update);
543
- observer?.observe(target);
544
- return () => {
545
- window.removeEventListener('resize', update);
546
- window.removeEventListener('scroll', update, true);
547
- observer?.disconnect();
548
- };
549
- }, [target]);
550
- return position;
551
- }
552
605
  function useLegacyHostTargets() {
553
- const [targets, setTargets] = useState({ contextDialog: null, turnStatus: null });
606
+ const [targets, setTargets] = useState({ contextDialog: null });
554
607
  useEffect(() => {
555
608
  if (typeof document === 'undefined' || document.body === null)
556
609
  return undefined;
557
610
  const refresh = () => {
558
- const next = {
559
- contextDialog: findContextMeterDialog(),
560
- turnStatus: findTurnStatus(),
561
- };
562
- setTargets(current => current.contextDialog === next.contextDialog
563
- && current.turnStatus === next.turnStatus ? current : next);
611
+ const next = { contextDialog: findContextMeterDialog() };
612
+ setTargets(current => current.contextDialog === next.contextDialog ? current : next);
564
613
  };
565
614
  refresh();
566
615
  const observer = new MutationObserver(refresh);
@@ -576,11 +625,14 @@ function useLegacyHostTargets() {
576
625
  }
577
626
  /** Bridges plugin UI into DOM sites rendered by the legacy conversation host. */
578
627
  function LegacyOverlay(props) {
579
- const { sessionId, useSession, useSessions, useProjection, useSettings, setSetting, unsetSetting, t, } = props;
580
- const { contextDialog, turnStatus } = useLegacyHostTargets();
581
- const turnStatusPosition = useTurnStatusPosition(turnStatus);
628
+ const { sessionId, useSessions, useProjection, useSettings, setSetting, unsetSetting, t, } = props;
629
+ const { contextDialog } = useLegacyHostTargets();
582
630
  const contextWindow = contextWindowFromProjection(useProjection);
583
- return (_jsxs(_Fragment, { children: [contextDialog !== null && createPortal(_jsx(ContextSizeControl, { contextWindow: contextWindow, sessionId: sessionId, useSessions: useSessions, useSettings: useSettings, setSetting: setSetting, unsetSetting: unsetSetting, t: t }), contextDialog, 'codex-context-size'), turnStatusPosition !== null && typeof document !== 'undefined' && document.body !== null && createPortal(_jsx(ActivityLine, { sessionId: sessionId, useSession: useSession, useSessions: useSessions, useProjection: useProjection, useSettings: useSettings, t: t, position: turnStatusPosition }), document.body, 'codex-activity')] }));
631
+ return (_jsx(_Fragment, { children: contextDialog !== null && createPortal(_jsx(ContextSizeControl, { contextWindow: contextWindow, sessionId: sessionId, useSessions: useSessions, useSettings: useSettings, setSetting: setSetting, unsetSetting: unsetSetting, t: t }), contextDialog, 'codex-context-size') }));
632
+ }
633
+ /** Stable composer fallback for hosts whose transient turn-status node is absent. */
634
+ function ActivityDock(props) {
635
+ return (_jsx("div", { style: { display: 'flex', alignItems: 'center', minHeight: 28, padding: '4px 10px' }, children: _jsx(ActivityLine, { ...props }) }));
584
636
  }
585
637
  export const inject = ['commandUi', 'sessions', 'slots', 'locale', 'settingsScope'];
586
638
  /** Mount request controls and the plugin settings card through shared slots. */
@@ -624,6 +676,20 @@ export function apply(ctx) {
624
676
  locale: NS,
625
677
  inject: injected,
626
678
  }, FastModeFallback));
679
+ ctx.slots.inject(FAST_FALLBACK_SLOT, () => ctx.slots.register({
680
+ name: FAST_FALLBACK_SLOT,
681
+ id: 'codex-context-size-fallback',
682
+ order: 1,
683
+ locale: NS,
684
+ inject: injected,
685
+ }, ContextSizeFallback));
686
+ ctx.slots.inject('conversation.composer.dock', () => ctx.slots.register({
687
+ name: 'conversation.composer.dock',
688
+ id: 'codex-activity-fallback',
689
+ order: 5,
690
+ locale: NS,
691
+ inject: injected,
692
+ }, ActivityDock));
627
693
  ctx.slots.inject(LEGACY_OVERLAY_SLOT, () => ctx.slots.register({
628
694
  name: LEGACY_OVERLAY_SLOT,
629
695
  id: 'codex-legacy-overlay',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shuind/dsh-codex-harness",
3
- "version": "0.2.11",
3
+ "version": "0.2.13",
4
4
  "description": "Codex coding preset with customizable prompts and tools for DSH.",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",