@nomadop/session-watcher-dsh 0.0.0-stage → 0.10.1

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.
@@ -0,0 +1,23 @@
1
+ ---
2
+ name: sw-explain
3
+ description: Use when the user asks what a Session Watcher metric means (br, mf, pp, u, wall, sweet, valley) or runs /sw-explain — explains the requested metric in plain language and contextualizes it for the current session.
4
+ ---
5
+
6
+ # Explain a Session Watcher metric
7
+
8
+ When the user asks about a metric:
9
+
10
+ 1. Call `watcher_status`. Read `br`, `u` (the arm it puts the session on), the lamp and the wallet clock's `phase` from the reply's `reading`; a false `reading.reliable` means the session is still measuring, so say that instead of quoting values. `mf`, `pp`, `wall` and `sweet / valley` are not in `reading`: point the user at where the host shows them, in Claude Code the dashboard at the URL the reply carries, in DSH the SW Meter tab. `mf` is the hero chart's movable reading; the others are landmarks with no numeric readout.
11
+ 2. Explain the requested metric in plain language.
12
+ 3. Contextualize against the flat-valley / AM-GM bound where relevant.
13
+
14
+ ## Metric glossary
15
+
16
+ - **br (bill premium)** — how far the bill sits above its cost at the sweet spot, as a fraction. `BR_AMBER` and `BR_RED` are the zone boundaries. `br = mf × pp`.
17
+ - **mf (movable fraction)** — the share of cost that timing can affect. AM-GM caps it at `√2−1`, which is also why the reminder interval has a natural floor. Whatever sits above that share is cost no restart timing can reach.
18
+ - **pp** — the timing-penalty shape term `(u−1)²/(2u)`; minimized at u=1 (the sweet spot).
19
+ - **u** — normalized position, accumulated causally: each API call adds the fraction of a restart interval that the conditions in force for it imply, so u only moves forward and loading more files never walks it back. Short of a whole interval = left arm (cost still falling, so the lamp stays white or green); one whole interval = sweet; beyond it = past sweet. The lamp's colour is arm-gated this way; the carry-rent reminder is not, because it reads accumulated rent instead of the position. `uInst`, the `(x−1)/dhat` ratio, is reported beside the causal `u` as a diagnostic that nothing acts on.
20
+ - **wall** — where continuing costs more per turn than a full restart.
21
+ - **sweet / valley** — the cost-curve minimum, reported as `xSweet` and read off the reference skeleton fitted across the session's own path; the valley around it is flat (small timing penalty).
22
+
23
+ Frame reassuringly where the numbers allow it: the movable fraction bounds how much of the bill timing can reach at all, and the valley around the sweet spot is flat, so a moderate `br` on the left arm carries no urgency. `br` itself has no ceiling — `pp` grows without bound on the late arm.
@@ -0,0 +1,43 @@
1
+ # Turn Notes
2
+
3
+ What each note says. Reading and filling the two files is the `protocol` that `get_turn_skeleton` returns; this file governs content only.
4
+
5
+ ## Reading the skeleton
6
+
7
+ The skeleton is a sequence of turn blocks. Each block opens with a head row carrying a `T` line ordinal and a `U :` label, followed by sampled assistant rows. A block whose turn did assistant work of its own then closes with an aggregate row and a labelled `NOTE[T]: ____` slot. A block that closes without that pair asks for no note, and its rows may still include an assistant one — a bare command echo and the harness's acknowledgement of the user's own local command both reach you this way.
8
+
9
+ Example block:
10
+
11
+ ```
12
+ T 12 | U : 所以你的意思是当前行为没处理 harness U 吗?
13
+ T 18 | A : 查了两处,harness U 只在 scripts/ 两条互不一致的正则里…
14
+ T 26 | A : …所以按 turn 采样,护栏落在 turn 的行数上而不是行长度上。
15
+ | A×5 · 7 tools: bookmark-service.js,turn.js
16
+ | NOTE[12]: ____
17
+ ```
18
+
19
+ **The skeleton anchors your own context; it is not the evidence.** You are the agent that lived these turns, so their full text is already in your context. The block samples the turn: the first assistant message head-cut, the last tail-cut, and an aggregate row whose counts and basenames come from the tool trace and are indexed without you. Locate the turn in your context and write the note from the whole of it.
20
+
21
+ **A turn runs from its `U` head to the row before the next block's `U` head.** A sub-agent's returned result, a tool result, a skill payload — none of these opens a turn; the block's last `A` row is the last thing this turn said, and the note covers everything up to it.
22
+
23
+ ## What to write in each note
24
+
25
+ The note covers what the **assistant** did in that turn, at the length the turn earns: a one-line span yields a one-clause note. Never restate the user's message: the `U` row already carries it and the user's decision, so open on the assistant's first act.
26
+
27
+ Reader: a fresh agent that will never see this conversation. Per turn its only decision is: pull this turn in full, or move on. The note carries the bearing; the turn carries the evidence.
28
+
29
+ Register: a commit message body — terse, fragments correct. The note is itself the searched text, so compression drops function words and keeps the subject: copy commands, identifiers, numbers, versions and error strings EXACTLY, because they are both the record and the words a later query is made of. A number is copied from a row of the turn, never recounted; a tally you cannot point at, leave out. "fix notes.md append seam — heading glued onto unterminated body line", not "I went ahead and fixed the seam".
30
+
31
+ **Write what no retrieval holds.** Retrieval is by name or by pulling this turn, and the note treats each differently.
32
+
33
+ A **named artifact** the turn left behind — a commit, a plan, a backlog row, an ADR, a step the skill prescribes — is reachable by its name from anywhere, so what it carries the note leaves to it: an identifier the commit message names is the commit's, and the note writes the sha. Write what the artifact does not hold: what was chosen, what was turned down, and the reason.
34
+ "adopt W_amber=0.4; reject 0.6 — overshoot already absorbed by W coordinate"
35
+ "reject per-episode quota — starves small classes; switch to global joint selection"
36
+
37
+ **What only this turn's rows hold** — a review's return, a probe script and what it measured, a fact established or ruled out by reading, an error string, a user correction — reaches a later reader only if this note makes them pull the turn. Carry its bearing: what came back, what was found, what was done with it.
38
+
39
+ **Close every note on where the turn's last row left things**: committed or not, what returned before it and what was done with it, what was handed to the user.
40
+
41
+ Write each note in the dominant language of its turn.
42
+
43
+ Keep every **scope word** — negation, restriction, condition: not / never / only / except / if, 不 / 没 / 只 / 若. A dropped scope word inverts the reader's decision. This overrides brevity.
@@ -0,0 +1,61 @@
1
+ ---
2
+ name: sw-handoff
3
+ description: Use when the user runs /sw-handoff or wants to carry over context before the context reset the host offers — prepares a structured handoff (keep/discard file decision + summary + next task) and returns a load token for the next segment.
4
+ ---
5
+
6
+ # Session Watcher Handoff
7
+
8
+ Prepare a handoff package so the next session can resume without re-reading what its first task needs, and without carrying what that task will not open.
9
+
10
+ ## Steps
11
+
12
+ 1. **Get turn skeleton** via the `get_turn_skeleton` tool → `{ snapshot_id, skeleton_path, notes_path, protocol }`. Follow the `protocol` sentence it returns; it states how the two files are filled.
13
+
14
+ - **The call fails** — an error instead of that shape, whatever its cause. Stop this run: report to the user that the turn skeleton could not be captured; do not produce or submit notes, and do not go on to `prepare_handoff`.
15
+
16
+ 2. **Produce turn notes** you MUST follow [`NOTES.md`](NOTES.md) exactly for what each note says. Write them inline — do not delegate to a subagent.
17
+
18
+ 3. **Submit notes** via the `submit_turn_notes` tool with `snapshot_id`. The tool reads `notes_path` itself.
19
+
20
+ - **`invalid_notes`** — each `issues` entry names a `t`, and each one is one section of `notes_path`. Edit those sections and submit again, at most **three** times (four submissions in all). If the last one still rejects, stop and report to the user; do not loop.
21
+
22
+ The other three codes stop this run. Report the error to the user and take no further step:
23
+ - **`stale_snapshot`** — snapshot is no longer current. Stop: report to the user; do not re-fetch the skeleton or re-produce notes.
24
+ - **`invalid_snapshot`** — the capture's source identity or required metadata is invalid, including a transcript that cannot be read. Stop: report to the user.
25
+ - **`storage_unavailable`** (`retryable: true`) — store temporarily unavailable. Stop: report to the user; they may re-run the skill when ready.
26
+
27
+ 4. **Fetch bucket data** via the `get_bucket_summary` tool.
28
+
29
+ If `metrics.br < 0.05` AND few turns: note "Context is still light — handoff may not be necessary yet, but proceeding as requested."
30
+
31
+ 5. **Select paths to keep.** The kept set is what the next task must have in hand before it can act. Candidates are the bucket summary plus any path this segment used that the bucket lacks. For each candidate, name the act of `next_task` that opens it; a candidate with no such act is not kept, whatever this segment did with it.
32
+ - The repo outlives the context reset and the conversation does not, so a file the next session can read on demand is kept only where that first act needs it in hand: the file the task edits, the test that guards it, the artifact under discussion.
33
+ - A blob under review is read by its reviewer, so what the next task needs is the review's return and the sources it cites.
34
+ - Read each candidate's `tokens` from the bucket summary and total them before prepare. Where one path carries more than half that total, state which act needs all of it, or keep its `symbols` alone.
35
+
36
+ Always: `userOverride` decides that path; a `keep:` list in the arguments is kept verbatim; symbols come from `activeSymbols` into `paths_to_keep[].symbols`; memories, `CONTEXT.md`, `CLAUDE.md` stay off the list.
37
+
38
+ Before prepare, tell the user the kept total, each kept path with the act that opens it, and every edited or repeatedly read bucket path left out.
39
+
40
+ 6. **Select skills** — `skills_to_keep`: only skills actively guiding the workflow or required by next_task. Skip one-shot completed skills. Never include `sw-load` — it drives the load flow itself and is always invoked automatically. If the user's `keep:` list includes skill names, use those directly.
41
+
42
+ 7. **Write the summary** you MUST following [`SUMMARY.md`](SUMMARY.md) exactly. Redact secrets as `[REDACTED]`
43
+
44
+ 8. **Prepare** via the `prepare_handoff` tool with:
45
+ - `paths_to_keep`: array from step 5
46
+ - `skills_to_keep`: array from step 6
47
+ - `summary`: from step 7
48
+ - `next_task`: the user's stated next step if the arguments give one; otherwise the line of work this segment was on, not a single step of it.
49
+ - `observed_segment`: segment value from step 4
50
+
51
+ Check `resolved_paths` in the response — where a path resolved wrong, re-issue with the absolute path.
52
+
53
+ **Revise an existing handoff** (fix paths, update summary): pass its `load_token` with only the parameters being changed; a passed `paths_to_keep` is the whole kept list, `skills_to_keep: []` clears the skills and `next_task: ""` clears the next task. Report whichever `load_token` comes back — an undelivered handoff keeps its token, a delivered one is immutable, so the revision is a new handoff under a new token.
54
+
55
+ The tools are the only path to the handoff: when the `prepare_handoff` call returns an error instead of a reply, report the failure to the user.
56
+
57
+ 9. **Report to user:** "Handoff prepared. Kept `<kept_tokens>` tokens. Token: `<token>`. Please use the context reset the host offers when ready."
58
+
59
+ ### Completion criterion
60
+
61
+ Done when: `prepare_handoff` returned a `load_token`, you relayed it to the user, and the user acknowledged.
@@ -0,0 +1,34 @@
1
+ # Handoff Summary Template
2
+
3
+ Two principles govern what goes in the summary:
4
+
5
+ 1. **State, not history.** The next session needs where we ARE and how to RESUME. Commits record what happened — reference them by hash, don't retell them.
6
+ 2. **Underivable only.** If git log, grep, reading the code, or a turn note you just wrote answers it, leave it out. The summary carries intent, reasoning, and conversation-only state.
7
+
8
+ Use these section headers exactly. Write `(none)` for empty sections — never omit or pad.
9
+
10
+ ---
11
+
12
+ ## Objective
13
+
14
+ [One sentence: the goal we're working toward.]
15
+
16
+ ## Working state
17
+
18
+ [High-level only — paths_to_keep already tells the next session which files/symbols to read. Here: how the pieces connect, current behavior vs intended, remaining gap. No file:function lists, no "we did X".]
19
+
20
+ ## Discussion context
21
+
22
+ [User-side and unresolved context — a turn note records what the assistant did, not what it was told. Omit entirely if the session was purely mechanical.]
23
+
24
+ - **User corrections**: where the user redirected approach, and what they said
25
+ - **Constraints from conversation**: verbal rules not yet in code or CLAUDE.md
26
+ - **Open questions**: unresolved points needing user input
27
+
28
+ ## Active constraints
29
+
30
+ [Invariants the next session must respect — the choice and 1-line WHY. Locked interfaces.]
31
+
32
+ ## Blockers / risks
33
+
34
+ [Only unresolved items affecting next_task.]
@@ -0,0 +1,45 @@
1
+ ---
2
+ name: sw-load
3
+ description: "Use when the user provides a handoff token, asks to resume or continue previous work, the host's handoff notice announces a handoff, or you are about to call load_handoff."
4
+ ---
5
+
6
+ # Session Watcher Load Handoff
7
+
8
+ Restore a previous session's handoff package into context so work can resume.
9
+
10
+ ## Steps
11
+
12
+ 1. **Load the handoff.** Resolve a token from the skill `args`, from the user's message, or from the host's own handoff notice, which names pending handoffs by token: the Claude Code SessionStart hook's additionalContext, or the message DSH injects when the agent starts or resumes. Then call the `load_handoff` tool, whose schema carries the three ways in.
13
+
14
+ A token you were handed is the one path that proceeds without asking. Any other way in — a free-text match, an auto-match, or several tokens offered at once — means listing what came back with each one's age and task preview and letting the user pick before you go on. Nothing found → tell the user the token is expired or invalid, and ask for direction.
15
+
16
+ 2. **Read the kept paths.** Relative paths resolve against CWD, then `project_dir`.
17
+
18
+ One strategy per entry, the first row that applies:
19
+
20
+ | Entry has | Read at load |
21
+ |---|---|
22
+ | `lines` | each range |
23
+ | `resolvedSymbols` | the `(lines a-b)` each string carries |
24
+ | neither | the file's first 40 lines; with `symbols`, also `grep -n` each name in the file to place the entry points |
25
+
26
+ Each read is the host's file-reading tool over a line range of the kept file. Each call names one file. Issue every read for every entry in one message — each further turn re-reads the whole accumulated context.
27
+
28
+ Unresolvable path → tell the user, skip. Empty `paths_to_keep` → ask the user what they are working on.
29
+
30
+ 3. **Place the summary in its lineage.** `lineage` runs oldest to newest. The sessions the budget left out are collapsed into runs marked `omitted`, ahead of the newest sessions' headlines, and the budget may keep none. When the next task or what is already in context needs the headlines of an omitted run, `lineage_headlines` with that run's numbers as `k` (`S2-S5` is `2-5`) reads them; read a run for that need only, not by default. The injected page holds the newest turns and is already in context. From the page, list the turns whose `A:` note bears on the next task, by their `S{k}:{T}` address. When a headline bears on the next task and the page does not reach that member, call `turn_page` with that member's label as `before`; a session inside an omitted run is `S{k}`, `k` being its own number. That list is what step 5 reports.
31
+
32
+ 4. **Load the kept skills** — invoke each name in `skills_to_keep` through the host's skill tool. A skill named only in the summary text is invoked after the user agrees.
33
+
34
+ 5. **Present, then hold.** One `git status --short && git log -1 --oneline`, then write, from the kept paths and that output:
35
+ - Objective, one line
36
+ - Working state — each claim the summary makes about the current state, set against what the kept paths and the git output show: matches, differs (say how), or reaches neither (say unverified)
37
+ - Next task and its entry points — the `neither` entries with where their symbols sit, and the turns step 3 named
38
+ - Blockers and risks
39
+ - The kept paths now in context and the load token you used
40
+
41
+ Then stop and wait for the user to confirm or correct it. The next task's first act begins after the reply.
42
+
43
+ ### Completion criterion
44
+
45
+ Done when the kept paths are in context, the state is presented in the shape step 5 gives, and the user has replied confirming or correcting it.
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,5 @@
1
+ - insert:
2
+ - id: session-watcher
3
+ name: '@nomadop/session-watcher-dsh'
4
+ - id: tool-session-query
5
+ name: '@deepseek-ai/dsh-tool-session-query'
package/package.json CHANGED
@@ -1,6 +1,31 @@
1
1
  {
2
2
  "name": "@nomadop/session-watcher-dsh",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.10.1",
4
+ "description": "Session Watcher as a DeepSeek Harness host plugin",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "exports": {
8
+ ".": "./dist/index.js",
9
+ "./client": "./dist/client.js"
10
+ },
11
+ "files": [
12
+ "dist/",
13
+ "dsh.bundle.patch.yml"
14
+ ],
15
+ "publishConfig": {
16
+ "access": "public"
17
+ },
18
+ "peerDependencies": {
19
+ "@deepseek-ai/dsh-compaction": ">=0.2.0-rc.1",
20
+ "@deepseek-ai/dsh-llm": ">=0.2.0-rc.1",
21
+ "@deepseek-ai/dsh-tools": ">=0.2.0-rc.1"
22
+ },
23
+ "dsh": {
24
+ "client": {
25
+ "platform": "web"
26
+ },
27
+ "bundle": {
28
+ "patch": "./dsh.bundle.patch.yml"
29
+ }
30
+ }
31
+ }