@shuind/dsh-codex-harness 0.2.12 → 0.2.14

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
@@ -82,21 +82,23 @@ window.__ModuleLoader__.load({
82
82
  }
83
83
  /** Infer the request-phase clock from the existing conversation snapshot. */
84
84
  function awaitingModelStartedAt(snapshot) {
85
- 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;
86
87
  let latest;
87
88
  for (const timing of snapshot.turnTimings.values()) if (timing.endTime === void 0) latest = timing.startTime;
88
89
  return latest;
89
90
  }
90
91
  /** Infer the first non-empty model token timestamp from the current snapshot. */
91
92
  function modelReplyStartedAt(snapshot) {
92
- 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;
93
95
  let openTurn;
94
96
  for (const [turn, timing] of snapshot.turnTimings) if (timing.endTime === void 0) openTurn = {
95
97
  turn,
96
98
  startTime: timing.startTime
97
99
  };
98
100
  if (openTurn === void 0) return void 0;
99
- if (snapshot.partial !== null && snapshot.partial.turn === openTurn.turn) {
101
+ if (snapshot.partial !== void 0 && snapshot.partial !== null && snapshot.partial.turn === openTurn.turn) {
100
102
  const partialReplyStartedAt = snapshot.partial.replyStartedAt;
101
103
  if (partialReplyStartedAt !== void 0) return partialReplyStartedAt;
102
104
  }
@@ -1218,13 +1220,57 @@ window.__ModuleLoader__.load({
1218
1220
  const preferred = statuses.filter(isTurnStatus);
1219
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;
1220
1222
  }
1223
+ function findTurnStatus() {
1224
+ return selectTurnStatus([...document.querySelectorAll("[role=\"status\"]")]);
1225
+ }
1226
+ function useTurnStatusPosition(target) {
1227
+ const [position, setPosition] = (0, react.useState)(null);
1228
+ (0, react.useLayoutEffect)(() => {
1229
+ if (target === null) {
1230
+ setPosition(null);
1231
+ return;
1232
+ }
1233
+ const update = () => {
1234
+ if (!target.isConnected) {
1235
+ setPosition(null);
1236
+ return;
1237
+ }
1238
+ const rect = target.getBoundingClientRect();
1239
+ if (rect.width === 0 && rect.height === 0) {
1240
+ setPosition(null);
1241
+ return;
1242
+ }
1243
+ setPosition({
1244
+ left: Math.round(rect.right + 10),
1245
+ top: Math.round(rect.top + (rect.height - 26) / 2)
1246
+ });
1247
+ };
1248
+ update();
1249
+ window.addEventListener("resize", update);
1250
+ window.addEventListener("scroll", update, true);
1251
+ const observer = typeof ResizeObserver === "undefined" ? void 0 : new ResizeObserver(update);
1252
+ observer?.observe(target);
1253
+ return () => {
1254
+ window.removeEventListener("resize", update);
1255
+ window.removeEventListener("scroll", update, true);
1256
+ observer?.disconnect();
1257
+ };
1258
+ }, [target]);
1259
+ return position;
1260
+ }
1221
1261
  function useLegacyHostTargets() {
1222
- const [targets, setTargets] = (0, react.useState)({ contextDialog: null });
1262
+ const [targets, setTargets] = (0, react.useState)({
1263
+ contextDialog: null,
1264
+ turnStatus: null
1265
+ });
1223
1266
  (0, react.useEffect)(() => {
1224
1267
  if (typeof document === "undefined" || document.body === null) return void 0;
1225
1268
  const refresh = () => {
1226
- const next = { contextDialog: findContextMeterDialog() };
1227
- setTargets((current) => current.contextDialog === next.contextDialog ? current : next);
1269
+ const next = {
1270
+ contextDialog: findContextMeterDialog(),
1271
+ turnStatus: findTurnStatus()
1272
+ };
1273
+ setTargets((current) => current.contextDialog === next.contextDialog && current.turnStatus === next.turnStatus ? current : next);
1228
1274
  };
1229
1275
  refresh();
1230
1276
  const observer = new MutationObserver(refresh);
@@ -1240,10 +1286,11 @@ window.__ModuleLoader__.load({
1240
1286
  }
1241
1287
  /** Bridges plugin UI into DOM sites rendered by the legacy conversation host. */
1242
1288
  function LegacyOverlay(props) {
1243
- const { sessionId, useSessions, useProjection, useSettings, setSetting, unsetSetting, t } = props;
1244
- const { contextDialog } = useLegacyHostTargets();
1289
+ const { sessionId, useSession, useSessions, useProjection, useSettings, setSetting, unsetSetting, t } = props;
1290
+ const { contextDialog, turnStatus } = useLegacyHostTargets();
1291
+ const turnStatusPosition = useTurnStatusPosition(turnStatus);
1245
1292
  const contextWindow = contextWindowFromProjection(useProjection);
1246
- return (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: contextDialog !== null && (0, react_dom.createPortal)((0, react_jsx_runtime.jsx)(ContextSizeControl, {
1293
+ return (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [contextDialog !== null && (0, react_dom.createPortal)((0, react_jsx_runtime.jsx)(ContextSizeControl, {
1247
1294
  contextWindow,
1248
1295
  sessionId,
1249
1296
  useSessions,
@@ -1251,19 +1298,15 @@ window.__ModuleLoader__.load({
1251
1298
  setSetting,
1252
1299
  unsetSetting,
1253
1300
  t
1254
- }), contextDialog, "codex-context-size") });
1255
- }
1256
- /** Stable composer fallback for hosts whose transient turn-status node is absent. */
1257
- function ActivityDock(props) {
1258
- return (0, react_jsx_runtime.jsx)("div", {
1259
- style: {
1260
- display: "flex",
1261
- alignItems: "center",
1262
- minHeight: 28,
1263
- padding: "4px 10px"
1264
- },
1265
- children: (0, react_jsx_runtime.jsx)(ActivityLine, { ...props })
1266
- });
1301
+ }), contextDialog, "codex-context-size"), turnStatusPosition !== null && typeof document !== "undefined" && document.body !== null && (0, react_dom.createPortal)((0, react_jsx_runtime.jsx)(ActivityLine, {
1302
+ sessionId,
1303
+ useSession,
1304
+ useSessions,
1305
+ useProjection,
1306
+ useSettings,
1307
+ t,
1308
+ position: turnStatusPosition
1309
+ }), document.body, "codex-activity")] });
1267
1310
  }
1268
1311
  const inject = [
1269
1312
  "commandUi",
@@ -1325,13 +1368,6 @@ window.__ModuleLoader__.load({
1325
1368
  locale: NS,
1326
1369
  inject: injected
1327
1370
  }, ContextSizeFallback));
1328
- ctx.slots.inject("conversation.composer.dock", () => ctx.slots.register({
1329
- name: "conversation.composer.dock",
1330
- id: "codex-activity-fallback",
1331
- order: 5,
1332
- locale: NS,
1333
- inject: injected
1334
- }, ActivityDock));
1335
1371
  ctx.slots.inject(LEGACY_OVERLAY_SLOT, () => ctx.slots.register({
1336
1372
  name: LEGACY_OVERLAY_SLOT,
1337
1373
  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,6 +1,6 @@
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, useRef, useState } from 'react';
3
+ import { useEffect, useLayoutEffect, useRef, useState } from 'react';
4
4
  import { createPortal } from 'react-dom';
5
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";
@@ -602,14 +602,56 @@ export function selectTurnStatus(statuses) {
602
602
  ?? statuses.filter(status => status.closest('[data-chat-flow]') !== null).at(-1)
603
603
  ?? null;
604
604
  }
605
+ function findTurnStatus() {
606
+ return selectTurnStatus([...document.querySelectorAll('[role="status"]')]);
607
+ }
608
+ function useTurnStatusPosition(target) {
609
+ const [position, setPosition] = useState(null);
610
+ useLayoutEffect(() => {
611
+ if (target === null) {
612
+ setPosition(null);
613
+ return undefined;
614
+ }
615
+ const update = () => {
616
+ if (!target.isConnected) {
617
+ setPosition(null);
618
+ return;
619
+ }
620
+ const rect = target.getBoundingClientRect();
621
+ if (rect.width === 0 && rect.height === 0) {
622
+ setPosition(null);
623
+ return;
624
+ }
625
+ setPosition({
626
+ left: Math.round(rect.right + 10),
627
+ top: Math.round(rect.top + (rect.height - 26) / 2),
628
+ });
629
+ };
630
+ update();
631
+ window.addEventListener('resize', update);
632
+ window.addEventListener('scroll', update, true);
633
+ const observer = typeof ResizeObserver === 'undefined' ? undefined : new ResizeObserver(update);
634
+ observer?.observe(target);
635
+ return () => {
636
+ window.removeEventListener('resize', update);
637
+ window.removeEventListener('scroll', update, true);
638
+ observer?.disconnect();
639
+ };
640
+ }, [target]);
641
+ return position;
642
+ }
605
643
  function useLegacyHostTargets() {
606
- const [targets, setTargets] = useState({ contextDialog: null });
644
+ const [targets, setTargets] = useState({ contextDialog: null, turnStatus: null });
607
645
  useEffect(() => {
608
646
  if (typeof document === 'undefined' || document.body === null)
609
647
  return undefined;
610
648
  const refresh = () => {
611
- const next = { contextDialog: findContextMeterDialog() };
612
- setTargets(current => current.contextDialog === next.contextDialog ? current : next);
649
+ const next = {
650
+ contextDialog: findContextMeterDialog(),
651
+ turnStatus: findTurnStatus(),
652
+ };
653
+ setTargets(current => current.contextDialog === next.contextDialog
654
+ && current.turnStatus === next.turnStatus ? current : next);
613
655
  };
614
656
  refresh();
615
657
  const observer = new MutationObserver(refresh);
@@ -625,14 +667,11 @@ function useLegacyHostTargets() {
625
667
  }
626
668
  /** Bridges plugin UI into DOM sites rendered by the legacy conversation host. */
627
669
  function LegacyOverlay(props) {
628
- const { sessionId, useSessions, useProjection, useSettings, setSetting, unsetSetting, t, } = props;
629
- const { contextDialog } = useLegacyHostTargets();
670
+ const { sessionId, useSession, useSessions, useProjection, useSettings, setSetting, unsetSetting, t, } = props;
671
+ const { contextDialog, turnStatus } = useLegacyHostTargets();
672
+ const turnStatusPosition = useTurnStatusPosition(turnStatus);
630
673
  const contextWindow = contextWindowFromProjection(useProjection);
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 }) }));
674
+ 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')] }));
636
675
  }
637
676
  export const inject = ['commandUi', 'sessions', 'slots', 'locale', 'settingsScope'];
638
677
  /** Mount request controls and the plugin settings card through shared slots. */
@@ -683,13 +722,6 @@ export function apply(ctx) {
683
722
  locale: NS,
684
723
  inject: injected,
685
724
  }, 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));
693
725
  ctx.slots.inject(LEGACY_OVERLAY_SLOT, () => ctx.slots.register({
694
726
  name: LEGACY_OVERLAY_SLOT,
695
727
  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.12",
3
+ "version": "0.2.14",
4
4
  "description": "Codex coding preset with customizable prompts and tools for DSH.",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",