dsh-hindsight-workspace-switch
A per-workspace HindSight switch for the DeepSeek Harness (dsh) composer: a
toggle sits to the left of the model selector in the session input area. Turning
it on means HindSight disabled. When HindSight is not installed, the toggle is
not rendered at all.
How the switch actually turns it off
HindSight's dist/dsh.js is an ordinary Cordis plugin. It does four things, and
all four are registrations:
| What it registers | What it does |
|---|---|
agent/session-start listener |
seeds the memory bank when a session first opens |
agent/pre-step listener |
recalls memory and injects it into the context |
agent/turn-stopping listener |
writes the whole conversation back to the bank |
hindsight_* tools on ctx.tools |
explicit knowledge get/put |
Cordis registrations are reversible effects, and dsh dispatches through
scope filtering: mount the plugin on one agent's scoped context (agent.ctx)
and all four belong to that agent alone; dispose that mount and all four vanish
together. So this plugin does not intercept HindSight — it takes over the
right to mount it:
- It owns the
hindsightrow and imports the originaldist/dsh.jsitself. - When an agent is created, it looks up that agent's workspace and mounts
HindSight onagent.ctxonly in workspaces where the switch is off. - Flipping the switch mounts or unmounts immediately, in sessions already
running in that workspace — no need to wait for the next session.
"Disabled" in full: no recall, no write-back, no hindsight_* tools registered.
What flipping the switch changes
Three separate things happen, on three different timelines. Keeping them apart
explains almost every surprising observation.
1. Tools disappear immediately
Every hindsight_* tool drops out of the tool definitions at once — in sessions
that are already running, not just in new ones. In the composer's context
inspector this shows up as a negative delta on the tool definitions group
(-8 on a typical HindSight install).
This is the fastest, most visible effect, and it is permanent for the rest of
the session: tool definitions are re-read from the registry on every assembly,
so once the mount is disposed, they never come back.
2. No new recall is injected
Unmounting also unbinds the agent/pre-step listener that performs recall, so
no new <hindsight_knowledge> block is produced from that point on. A
session started after the switch went on is completely clean.
3. Blocks already in the log are retired, but not by unmounting
This is the part that surprises people. A block injected during an earlier
turn is already in the session log, and unmounting cannot retroactively remove
something that has been recorded.
dsh makes this structural rather than accidental:
- The session log is append-only. There is no delete, no update, no insert.
Even compaction never removes an event. - The request is derived from that log (
deriveMessages()over the
surface, an ordered projection). There is no "edit the outgoing request"
step — the request is computed. agent/pre-stephands overmessages: claimed, the messages newly claimed
this turn, not the full history. Historical blocks never pass through it.agent/requestis the model-configuration waterfall. Its contract states
plainly that it cannot mutate messages.
So the only sanctioned way to make recorded content invisible to the model is to
append a new event that shadows it:
session.append('user/message', content, {
surfaceOp: { op: 'replace', start: seq, end: seq }, // start === end: one node
sourceEventSeqs: [seq], // every shadowed node
})
start === end retires exactly one node — no LLM summary, no neighbouring
history touched. The old event stays in the log (replayable, auditable); it just
stops appearing on the surface, so deriveMessages() no longer projects it.
When the switch goes on, this plugin sweeps the workspace's live sessions,
finds surface nodes holding a <hindsight_knowledge> block, and retires them
in place. Anything left over after stripping the block is kept; a node that
was nothing but the block is replaced by a short marker.
Two differences from compaction worth knowing:
| This plugin | Compaction | |
|---|---|---|
| Precision | one node | a contiguous span chosen by token pressure |
| Summary | none — content is stripped textually | an LLM-written summary |
| Model call | none | one |
| Collateral | none | neighbouring history is summarised too |
Compaction remains available as an opt-in fallback (compactOnDisable: true)
for the rare case where surface shadowing is not usable.
Why not just filter the request
It is a reasonable instinct: hook agent/pre-step, strip the block from
decision.messages, return the filtered array. That is exactly what
dsh-mask does for PII, and it works —
because dsh-mask's plaintext never enters the log. It guards the entrance.
A residual block is the opposite problem: it is already recorded. Filtering
the entrance cannot evict a tenant.
Token accounting
Both effects above reduce tokens, but on different schedules.
Tool definitions — saved on every request. Tool schemas are part of every
request assembly, so dropping eight of them removes that cost from every
subsequent turn in the session. This is the largest and most reliable saving,
and it starts the moment the switch goes on.
Recall injection — saved once it stops recurring. The injected block is
produced once (Hindsight de-duplicates at the event level; it does not
re-inject on every tool step). But once recorded, it sits in the history and is
projected into every later request. So the saving is twofold:
- Going forward: no new block is produced.
- Retroactively: retiring the existing block removes it from all later
requests in that session.
That second half is the whole reason the surface sweep exists. Without it, a
session that had HindSight on for its first turn would keep paying for that
block for the rest of its life — and the longer the session runs, the more that
adds up.
Two honest caveats:
- KV cache softens the marginal cost. A block sitting early in the history
gets its prefix cached after the first send, so later turns are cheaper than
a naive "× turns" calculation suggests. The saving is still real — and any
cache miss (context edit, session resume) re-prices it at full cost. - New sessions were already clean. If you only care about future
sessions, unmounting alone is enough; the sweep is about not paying for
history you have already decided you do not want.
Install
1. Install the package
dsh plugin --profile web add github:ckcfcc/dsh-hindsight-workspace-switch
or
dsh plugin --profile web add dsh-hindsight-workspace-switch
Because the package declares dsh.bundle, dsh plugin appends it to the
profile's dsh.profile.bundles automatically. No file editing is needed for
this half, and removing the package withdraws the layer just as automatically.
2. Take over the hindsight row
Run the setup script once per profile:
node node_modules/dsh-hindsight-workspace-switch/scripts/setup.mjs --profile web
HindSight's own installer writes its row into $DSH_HOME/cordis.patch.yml, the
home layer, which is applied after every bundle layer. A bundle therefore
cannot override it — which is why this step cannot be folded into
dsh plugin add no matter how the package is declared.
The script backs up the home patch, removes HindSight's row from it, and records
the same row (with the real target) in the profile layer, which sits above
the bundle layer and below the home layer:
# DSH_HINDSIGHT_WORKSPACE_SWITCH_START
- insert:
- id: hindsight
name: dsh-hindsight-workspace-switch
config:
target: file:///C:/Users/ds/.hindsight/coding-agents/dist/dsh.js
# DSH_HINDSIGHT_WORKSPACE_SWITCH_END
The script reads the target out of the block it moves, so it works whether
HindSight was declared as name: "file:///…" or as config.target. Re-running
it is a no-op. Use --dry-run first to see what it would change, or `--target