@nomadop/session-watcher-dsh 0.10.0 → 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.
- package/dist/client.js +6 -3
- package/dist/index.js +92 -4
- package/dist/skills/sw-explain/SKILL.md +1 -1
- package/dist/skills/sw-load/SKILL.md +1 -1
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -49,7 +49,8 @@ function resultSignalState(result) {
|
|
|
49
49
|
return result === null || result.state === "bootstrapping" ? "reading" : result.kind === "unreachable" ? "unreachable" : result.state;
|
|
50
50
|
}
|
|
51
51
|
var en = {
|
|
52
|
-
|
|
52
|
+
// The host's view strip truncates a long tab label, so this one is short; the product name heads the dock as `dock.title`.
|
|
53
|
+
"view.label": "SW Meter",
|
|
53
54
|
"state.unobserved": "Session Watcher is not observing this session.",
|
|
54
55
|
"state.bootstrapping": "Session Watcher is reading this session\u2026",
|
|
55
56
|
"state.failed": "Session Watcher could not measure this session: {message}",
|
|
@@ -61,6 +62,7 @@ var en = {
|
|
|
61
62
|
"signal.unobserved": "unobserved",
|
|
62
63
|
"signal.failed": "failed",
|
|
63
64
|
"signal.unreachable": "unreachable",
|
|
65
|
+
"dock.title": "Session Watcher",
|
|
64
66
|
"dock.label": "Session Watcher readings",
|
|
65
67
|
"dock.pill": "Session Watcher: {summary}",
|
|
66
68
|
"dock.separator": ", ",
|
|
@@ -85,7 +87,7 @@ var en = {
|
|
|
85
87
|
"dock.growth": "Growth per call"
|
|
86
88
|
};
|
|
87
89
|
var zh = {
|
|
88
|
-
"view.label": "
|
|
90
|
+
"view.label": "SW Meter",
|
|
89
91
|
"state.unobserved": "Session Watcher \u672A\u5728\u89C2\u6D4B\u6B64\u4F1A\u8BDD\u3002",
|
|
90
92
|
"state.bootstrapping": "Session Watcher \u6B63\u5728\u8BFB\u53D6\u6B64\u4F1A\u8BDD\u2026",
|
|
91
93
|
"state.failed": "Session Watcher \u65E0\u6CD5\u6D4B\u91CF\u6B64\u4F1A\u8BDD\uFF1A{message}",
|
|
@@ -97,6 +99,7 @@ var zh = {
|
|
|
97
99
|
"signal.unobserved": "\u672A\u89C2\u6D4B",
|
|
98
100
|
"signal.failed": "\u5931\u8D25",
|
|
99
101
|
"signal.unreachable": "\u65E0\u6CD5\u8FDE\u63A5",
|
|
102
|
+
"dock.title": "Session Watcher",
|
|
100
103
|
"dock.label": "Session Watcher \u8BFB\u6570",
|
|
101
104
|
"dock.pill": "Session Watcher\uFF1A{summary}",
|
|
102
105
|
"dock.separator": "\uFF0C",
|
|
@@ -18584,7 +18587,7 @@ function createDock({ useAnchoredPosition: useAnchoredPosition2, useDismissOnOut
|
|
|
18584
18587
|
h3(
|
|
18585
18588
|
"div",
|
|
18586
18589
|
{ key: "title", className: "sw-title" },
|
|
18587
|
-
h3("span", { className: "sw-title-label" }, lamp, t("
|
|
18590
|
+
h3("span", { className: "sw-title-label" }, lamp, t("dock.title")),
|
|
18588
18591
|
h3("span", { className: "sw-title-value", "data-tone": failing ? "error" : void 0 }, rateLamp === null ? word : t(`dock.zone.${status.lamp}`))
|
|
18589
18592
|
),
|
|
18590
18593
|
h3("div", { key: "rule", className: "sw-title-rule" })
|
package/dist/index.js
CHANGED
|
@@ -584,6 +584,7 @@ var GC_HANDOFF_MAX_AGE_DAYS = 90;
|
|
|
584
584
|
var HANDOFF_MAX_PATHS = 50;
|
|
585
585
|
var HANDOFF_MAX_SUMMARY_CHARS = 1e4;
|
|
586
586
|
var HANDOFF_MAX_NEXT_TASK_CHARS = 2e3;
|
|
587
|
+
var LINEAGE_HEADLINE_TOKEN_BUDGET = 3e3;
|
|
587
588
|
var HANDOFF_HOOK_TTL_DAYS = 7;
|
|
588
589
|
var HANDOFF_HOOK_MAX_DISPLAY = 3;
|
|
589
590
|
var HANDOFF_HOOK_QUERY_LIMIT = HANDOFF_HOOK_MAX_DISPLAY + 1;
|
|
@@ -10099,7 +10100,7 @@ function deletePricingOverride(model) {
|
|
|
10099
10100
|
// package.json
|
|
10100
10101
|
var package_default = {
|
|
10101
10102
|
name: "@nomadop/session-watcher",
|
|
10102
|
-
version: "0.10.
|
|
10103
|
+
version: "0.10.1",
|
|
10103
10104
|
description: "Local Claude Code context-cost monitor, transcript replay, buckets, and handoff",
|
|
10104
10105
|
type: "module",
|
|
10105
10106
|
license: "MIT",
|
|
@@ -12760,6 +12761,53 @@ function lineageHeadlines({ store, lineage }) {
|
|
|
12760
12761
|
return buildTurnBrowse({ store, lineage }).sections.map(({ label, headline }) => ({ label, headline }));
|
|
12761
12762
|
}
|
|
12762
12763
|
|
|
12764
|
+
// lib/lineage-headlines.js
|
|
12765
|
+
var positionOf = (entry) => Number(entry.label.slice(1));
|
|
12766
|
+
var runOf2 = (from, to) => ({ label: from === to ? `S${from}` : `S${from}-S${to}`, omitted: true });
|
|
12767
|
+
function collapseRuns(entries) {
|
|
12768
|
+
const runs = [];
|
|
12769
|
+
let from = null;
|
|
12770
|
+
let to = null;
|
|
12771
|
+
for (const entry of entries) {
|
|
12772
|
+
const n = positionOf(entry);
|
|
12773
|
+
if (to !== null && n === to + 1) {
|
|
12774
|
+
to = n;
|
|
12775
|
+
continue;
|
|
12776
|
+
}
|
|
12777
|
+
if (to !== null) runs.push(runOf2(from, to));
|
|
12778
|
+
from = to = n;
|
|
12779
|
+
}
|
|
12780
|
+
if (to !== null) runs.push(runOf2(from, to));
|
|
12781
|
+
return runs;
|
|
12782
|
+
}
|
|
12783
|
+
function boundLineageHeadlines(entries, budget = LINEAGE_HEADLINE_TOKEN_BUDGET) {
|
|
12784
|
+
let start2 = entries.length;
|
|
12785
|
+
while (start2 > 0 && estimateWireTokens({ lineage: entries.slice(start2 - 1) }, DEFAULT_CTP) <= budget) {
|
|
12786
|
+
start2--;
|
|
12787
|
+
}
|
|
12788
|
+
return [...collapseRuns(entries.slice(0, start2)), ...entries.slice(start2)];
|
|
12789
|
+
}
|
|
12790
|
+
var ITEM = "[1-9][0-9]*(?:-[1-9][0-9]*)?";
|
|
12791
|
+
var POSITIONS = new RegExp(`^${ITEM}(?:,${ITEM})*$`);
|
|
12792
|
+
function parseLineagePositions(text) {
|
|
12793
|
+
if (typeof text !== "string" || !POSITIONS.test(text)) return null;
|
|
12794
|
+
const ranges = text.split(",").map((item) => {
|
|
12795
|
+
const [from, to = from] = item.split("-").map(Number);
|
|
12796
|
+
return [from, to];
|
|
12797
|
+
});
|
|
12798
|
+
return ranges.some(([from, to]) => from > to) ? null : ranges;
|
|
12799
|
+
}
|
|
12800
|
+
function selectLineagePositions(entries, ranges) {
|
|
12801
|
+
const positions = entries.map(positionOf);
|
|
12802
|
+
const inside = ([from, to], n) => n >= from && n <= to;
|
|
12803
|
+
const covered = ranges.every((range) => {
|
|
12804
|
+
const [from, to] = range;
|
|
12805
|
+
return positions.filter((n) => inside(range, n)).length === to - from + 1;
|
|
12806
|
+
});
|
|
12807
|
+
if (!covered) return null;
|
|
12808
|
+
return entries.filter((_, i2) => ranges.some((range) => inside(range, positions[i2])));
|
|
12809
|
+
}
|
|
12810
|
+
|
|
12763
12811
|
// lib/wire.js
|
|
12764
12812
|
function statusWire(status) {
|
|
12765
12813
|
const { sourceLocator, ...rest } = status;
|
|
@@ -12865,7 +12913,7 @@ async function loadedHandoffPayload(core, { store, turnPageBuilder, dialogueSour
|
|
|
12865
12913
|
const sessions = fromHandoff({ store, handoffId: core.handoff_id });
|
|
12866
12914
|
return {
|
|
12867
12915
|
...core,
|
|
12868
|
-
lineage: lineageHeadlines({ store, lineage: sessions }),
|
|
12916
|
+
lineage: boundLineageHeadlines(lineageHeadlines({ store, lineage: sessions })),
|
|
12869
12917
|
...turnPageWire(await turnPageBuilder({ store, lineage: sessions, dialogueSource, dialogueProjection, notice }))
|
|
12870
12918
|
};
|
|
12871
12919
|
} catch (err2) {
|
|
@@ -13120,6 +13168,7 @@ var NO_HANDOFF_LOADED = Object.freeze({
|
|
|
13120
13168
|
});
|
|
13121
13169
|
var STALE_CURSOR_MESSAGE = "That before boundary resolves to nothing in this lineage. Omit before to start again from the newest page, or take a session label from the load reply's lineage.";
|
|
13122
13170
|
var SCOPE_ABSENT_MESSAGE = "That S{k}:{T} scope names a turn this lineage does not contain. Call turn_locate for a current scope, or omit scope to cover the whole lineage.";
|
|
13171
|
+
var UNUSABLE_POSITIONS_MESSAGE = "k must be positions of this lineage: numbers and closed ranges separated by commas, such as 3, 2-5 or 1,4-6, with no spaces and no S prefix, and each number must name a session that has a headline. Take them from the labels of the load reply's lineage, where S2-S5 is 2-5.";
|
|
13123
13172
|
var PAGE_IS_THE_FALLBACK = "Read the lineage with turn_page instead \u2014 it paginates deterministically over the same sessions and needs no query.";
|
|
13124
13173
|
function withPageRecovery(result) {
|
|
13125
13174
|
if (result?.error === "turn_page_unavailable") {
|
|
@@ -13154,6 +13203,12 @@ function withLocateRecovery(result, { hitRecovery } = {}) {
|
|
|
13154
13203
|
}
|
|
13155
13204
|
return result;
|
|
13156
13205
|
}
|
|
13206
|
+
function withHeadlinesRecovery(result) {
|
|
13207
|
+
if (result?.error === "lineage_headlines_unavailable") {
|
|
13208
|
+
return { ...result, recovery: "Call lineage_headlines again; it reads the store afresh on every call." };
|
|
13209
|
+
}
|
|
13210
|
+
return result;
|
|
13211
|
+
}
|
|
13157
13212
|
function withLoadRecovery(result) {
|
|
13158
13213
|
if (result?.error === "handoff_delivery_unavailable") {
|
|
13159
13214
|
return { ...result, recovery: "The delivery record could not be written, so this response carries no content. Call load_handoff again with the same token once the store is writable." };
|
|
@@ -13161,6 +13216,9 @@ function withLoadRecovery(result) {
|
|
|
13161
13216
|
if (result?.turn_page_error) {
|
|
13162
13217
|
return { ...result, recovery: "The handoff loaded and the rest of this response is complete; only its turn page and the lineage headlines beside it failed to build. Call turn_page to obtain the page." };
|
|
13163
13218
|
}
|
|
13219
|
+
if (result?.lineage?.some((entry) => entry.omitted)) {
|
|
13220
|
+
return { ...result, recovery: "The older sessions of the lineage are collapsed into runs marked omitted, each run labelled by its first and last session. lineage_headlines reads the headlines of a run when the next task or what is already in context needs them: pass the run's numbers as k, where S2-S5 is 2-5." };
|
|
13221
|
+
}
|
|
13164
13222
|
return result;
|
|
13165
13223
|
}
|
|
13166
13224
|
|
|
@@ -13486,6 +13544,24 @@ function createTurnReadService({
|
|
|
13486
13544
|
if (process.env.SW_DEBUG) console.error("[turn_locate_tool]", err2);
|
|
13487
13545
|
return withLocateRecovery({ error: "locate_unavailable" });
|
|
13488
13546
|
}
|
|
13547
|
+
},
|
|
13548
|
+
// The lineage resolves first, then `k`, then the headline reads: a caller that loaded nothing meets
|
|
13549
|
+
// no_handoff_loaded whatever it passed, and a `k` that cannot parse costs no turn-note read. The throw
|
|
13550
|
+
// stays outside the try so that it is not mistaken for a store failure.
|
|
13551
|
+
async lineageHeadlines({ k } = {}) {
|
|
13552
|
+
try {
|
|
13553
|
+
const lineage = forLoadedHandoff({ store: store(), sessionId: sessionId() });
|
|
13554
|
+
if (lineage.length === 0) return NO_HANDOFF_LOADED;
|
|
13555
|
+
const ranges = parseLineagePositions(k);
|
|
13556
|
+
if (ranges !== null) {
|
|
13557
|
+
const selected = selectLineagePositions(lineageHeadlines({ store: store(), lineage }), ranges);
|
|
13558
|
+
if (selected !== null) return { lineage: selected };
|
|
13559
|
+
}
|
|
13560
|
+
} catch (err2) {
|
|
13561
|
+
if (process.env.SW_DEBUG) console.error("[lineage_headlines_tool]", err2);
|
|
13562
|
+
return withHeadlinesRecovery({ error: "lineage_headlines_unavailable", retryable: true });
|
|
13563
|
+
}
|
|
13564
|
+
throw new Error(UNUSABLE_POSITIONS_MESSAGE);
|
|
13489
13565
|
}
|
|
13490
13566
|
};
|
|
13491
13567
|
}
|
|
@@ -13511,6 +13587,9 @@ function assertBefore(before) {
|
|
|
13511
13587
|
function assertScope(scope) {
|
|
13512
13588
|
if (scope !== void 0 && !TURN_ADDRESS_RE.test(scope)) throw new Error("scope must be an S{k}:{T} turn address");
|
|
13513
13589
|
}
|
|
13590
|
+
function assertPositions(k) {
|
|
13591
|
+
if (parseLineagePositions(k) === null) throw new Error(UNUSABLE_POSITIONS_MESSAGE);
|
|
13592
|
+
}
|
|
13514
13593
|
function assertQuery(q) {
|
|
13515
13594
|
if (typeof q !== "string" || q.trim() === "" || q.length > HISTORY_EXCERPT_CHARS) {
|
|
13516
13595
|
throw new Error(`q must be a non-blank string of at most ${HISTORY_EXCERPT_CHARS} characters`);
|
|
@@ -13641,7 +13720,7 @@ function createTools({
|
|
|
13641
13720
|
}),
|
|
13642
13721
|
tool({
|
|
13643
13722
|
name: "load_handoff",
|
|
13644
|
-
description: "Retrieve a prepared handoff package by token, by free-text search, or \u2014 with neither given \u2014 by auto-match over undelivered handoffs of this project from other sessions. A retrieved package carries the lineage behind it as
|
|
13723
|
+
description: "Retrieve a prepared handoff package by token, by free-text search, or \u2014 with neither given \u2014 by auto-match over undelivered handoffs of this project from other sessions. A retrieved package carries the lineage behind it, oldest to newest, as the headlines of the newest sessions within a budget, ahead of them the older sessions collapsed into runs marked omitted, beside the newest page of its turns.",
|
|
13645
13724
|
parameters: {
|
|
13646
13725
|
load_token: { type: "string", description: "Semantic token from prepare_handoff (exact match)" },
|
|
13647
13726
|
query: { type: "string", description: "Free-text search when the token is unknown; returns top matches" },
|
|
@@ -13666,7 +13745,7 @@ function createTools({
|
|
|
13666
13745
|
name: "turn_page",
|
|
13667
13746
|
description: "Read a page of the history turns carried by the handoff loaded into this session, newest first.",
|
|
13668
13747
|
parameters: {
|
|
13669
|
-
before: { type: "string", description: "Where to read back from: an S{k}:{T} cursor from the next_before of the handoff load reply or of a previous page, which ends the page before that turn; or a bare S{k} session label from the load reply's lineage, which starts at that session's end. Omit for the newest page." }
|
|
13748
|
+
before: { type: "string", description: "Where to read back from: an S{k}:{T} cursor from the next_before of the handoff load reply or of a previous page, which ends the page before that turn; or a bare S{k} session label from the load reply's lineage, which starts at that session's end; a session inside an omitted run is addressed as S{k}, k being its own number. Omit for the newest page." }
|
|
13670
13749
|
},
|
|
13671
13750
|
check: ({ before }) => assertBefore(before),
|
|
13672
13751
|
run: (args2, entry) => turnReads(entry).turnPage(args2)
|
|
@@ -13692,6 +13771,15 @@ function createTools({
|
|
|
13692
13771
|
},
|
|
13693
13772
|
check: ({ q }) => assertQuery(q),
|
|
13694
13773
|
run: (args2, entry) => turnReads(entry).turnLocate(args2)
|
|
13774
|
+
}),
|
|
13775
|
+
tool({
|
|
13776
|
+
name: "lineage_headlines",
|
|
13777
|
+
description: "Read the headlines of chosen sessions of the lineage behind the handoff loaded into this session, such as an omitted run of the load reply's lineage. Returns one entry per chosen lineage member, oldest to newest.",
|
|
13778
|
+
parameters: {
|
|
13779
|
+
k: { type: "string", required: true, description: 'Positions in the lineage, as numbers and closed ranges separated by commas, such as "3", "2-5" or "1,4-6". Each number is the k of an S{k} label and must name a session that has a headline.' }
|
|
13780
|
+
},
|
|
13781
|
+
check: ({ k }) => assertPositions(k),
|
|
13782
|
+
run: (args2, entry) => turnReads(entry).lineageHeadlines(args2)
|
|
13695
13783
|
})
|
|
13696
13784
|
];
|
|
13697
13785
|
}
|
|
@@ -7,7 +7,7 @@ description: Use when the user asks what a Session Watcher metric means (br, mf,
|
|
|
7
7
|
|
|
8
8
|
When the user asks about a metric:
|
|
9
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
|
|
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
11
|
2. Explain the requested metric in plain language.
|
|
12
12
|
3. Contextualize against the flat-valley / AM-GM bound where relevant.
|
|
13
13
|
|
|
@@ -27,7 +27,7 @@ Restore a previous session's handoff package into context so work can resume.
|
|
|
27
27
|
|
|
28
28
|
Unresolvable path → tell the user, skip. Empty `paths_to_keep` → ask the user what they are working on.
|
|
29
29
|
|
|
30
|
-
3. **Place the summary in its lineage.** `lineage` runs oldest to newest,
|
|
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
31
|
|
|
32
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
33
|
|