@thehammer/danx-session-telemetry 0.1.17 → 0.1.19

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.
@@ -11,36 +11,43 @@
11
11
  *
12
12
  * Claude Code's `SubagentStart` / `SubagentStop` hooks carry strictly more (an
13
13
  * `agent_type` before the sub-agent has written anything, and — the part this
14
- * module cannot supply — a FINISH). Those hooks ship from the danxbot plugin in
15
- * the claude-plugins repo, and DX-3284 builds them, next. They were not built in
16
- * DX-2954 itself, but not because a plugin change cannot ship from a danxbot
17
- * card: DX-2954's own `transcript_path` change shipped as claude-plugins
18
- * `c0c134d`. Keying the running set solely on them before they exist would ship
19
- * a set that is permanently empty (`subagent_count` 0 on every dispatch, a
20
- * REGRESSION against the transcript-derived counter this replaced).
14
+ * module cannot supply — a FINISH). They ship from the danxbot plugin in the
15
+ * claude-plugins repo (DX-3284, `danxbot/scripts/activity-report.mjs`), run the
16
+ * `activity` subcommand of `@thehammer/danx-dashboard-mcp`, and reach the server
17
+ * through `POST /api/plan-sessions/me/activity` — which writes the SAME
18
+ * `dispatch_activities` rows through the same one server writer.
21
19
  *
22
- * So the transcript is the producer, and the hooks are an ENRICHMENT layered on
23
- * the same rows:
20
+ * The transcript stays the producer because it needs no hook to be installed: a
21
+ * session with no plugin, and every WORKER dispatch, still gets a start row for
22
+ * each sub-agent from here. The hooks are an ENRICHMENT layered on the same rows:
24
23
  *
25
24
  * | Signal | Sub-agent start | Sub-agent finish | Background script |
26
25
  * |---|---|---|---|
27
26
  * | Transcript (here) | file discovered | dispatch terminal (`finishOpenActivities`) | not visible |
28
- * | Hooks (DX-3284) | `SubagentStart` | `SubagentStop` | `PostToolUse` start; end at dispatch terminal (no documented completion event) |
27
+ * | Hooks (DX-3284, operator sessions) | `SubagentStart` | `SubagentStop` | `PostToolUse` start; end at dispatch terminal (no documented completion event) |
29
28
  *
30
- * **Until DX-3284 lands, "running" over-counts.** With no finish signal, every
31
- * sub-agent this dispatch ever started stays in the running set until the
32
- * dispatch itself ends, and the silent-too-long warning fires
33
- * `RUNNING_ACTIVITY_SILENT_AFTER_MS` after a sub-agent that has in fact
34
- * finished. `SubagentStop` is what closes that gap.
29
+ * **Where "running" closes.** An operator session's sub-agent closes at its
30
+ * `SubagentStop` hook. A WORKER dispatch has no hook reporting yet
31
+ * (`/me/activity` refuses a worker's session id as `session_is_worker`), so its
32
+ * sub-agents stay in the running set until the dispatch itself ends, and the
33
+ * silent-too-long warning fires `RUNNING_ACTIVITY_SILENT_AFTER_MS` after a
34
+ * sub-agent that has in fact finished. A worker-side `SubagentStop` report is the
35
+ * fix, and is not built.
35
36
  *
36
37
  * ## Why the two producers cannot double-count
37
38
  *
38
39
  * Every row is an upsert keyed `(dispatch_id, kind, activity_id)`, and BOTH
39
40
  * producers derive `activity_id` from the same thing: the sub-agent's transcript
40
- * file basename. The watcher has it directly; a hook has it as the basename of
41
- * its `transcript_path`. That is also the key the ledger credits the sub-agent's
42
- * tokens under, which is how per-sub-agent tokens join to the running set
43
- * without this table carrying a token column.
41
+ * file basename, `agent-<agent_id>`. The watcher has it directly; a hook has the
42
+ * `agent_id` and builds the same basename from it (`subagentActivityId` in
43
+ * danx-dashboard-mcp's `activity.ts`, which also strips an `agent-` prefix the hooks docs show
44
+ * on some `agent_id`s so both forms reach this key). A hook's `transcript_path` is NOT the
45
+ * sub-agent's file — on these events it is the MAIN session's transcript, and only
46
+ * `SubagentStop` also carries the sub-agent's own as `agent_transcript_path`,
47
+ * which the subcommand uses to refuse a key that disagrees. That basename is also
48
+ * the key the ledger credits the sub-agent's tokens under, which is how
49
+ * per-sub-agent tokens join to the running set without this table carrying a
50
+ * token column.
44
51
  *
45
52
  * ## What this module deliberately does NOT do
46
53
  *
@@ -49,7 +56,7 @@
49
56
  * indistinguishable from a slow one. Guessing a finish from an idle gap would
50
57
  * mark a long-thinking sub-agent as complete. So open rows are closed exactly
51
58
  * once, at the dispatch's own terminal transition (`finishOpenActivities`),
52
- * unless DX-3284's `SubagentStop` hook closes a row first.
59
+ * unless the `SubagentStop` hook (DX-3284) closes a row first.
53
60
  */
54
61
  import type { ActivityChange } from "./stats-wire.js";
55
62
  import type { EntryMeta, SourceDiscoveredInfo } from "./session-log-watcher.js";
@@ -111,9 +111,9 @@ export interface SessionLogWatcherOptions {
111
111
  * This is the transcript-side producer of the dispatch's running set. It
112
112
  * reports the sub-agent's ledger source key, which is the same value its
113
113
  * `dispatch_activities.activity_id` and its per-source token total join on —
114
- * so a hook-side producer reporting the same sub-agent by its
115
- * `transcript_path` resolves to this same id and upserts the SAME row rather
116
- * than a duplicate.
114
+ * so a hook-side producer reporting the same sub-agent by its `agent_id`
115
+ * (`agent-` + the id, DX-3284) resolves to this same id and upserts the SAME
116
+ * row rather than a duplicate.
117
117
  *
118
118
  * Fired once per source, from the discovery pass, for sub-agent files only —
119
119
  * never for the main transcript, which is the dispatch itself, not an activity
@@ -61,12 +61,14 @@ export type SourceCursorReports = Record<string, SourceCursorReport>;
61
61
  * DX-2954 — the running set's two kinds. `agent` is a sub-agent, produced from
62
62
  * the TRANSCRIPT: one row per sub-agent transcript file the session-log watcher
63
63
  * discovers (`packages/danx-session-telemetry/src/activity-observer.ts`; orchestrator decision, DX-2954
64
- * comment 8004). `bash` is a background script; nothing produces it yet — the
65
- * hook-side producer (`PostToolUse` on a backgrounded Bash call) is DX-3284's.
66
- * No hook event observes a background shell FINISHING (verified against the
67
- * hooks reference — see the Step 0 note on DX-2954), so an open row of either
68
- * kind is closed by the dispatch's own terminal write, never by inferring an
69
- * end from transcript lines.
64
+ * comment 8004), and — for an operator session — from the plugin's
65
+ * `SubagentStart` / `SubagentStop` hooks, which add the finish. `bash` is a
66
+ * background script, produced only by the plugin's `PostToolUse` hook on a
67
+ * backgrounded Bash call (DX-3284; the transcript cannot see it). No hook event
68
+ * observes a background shell FINISHING (verified against the hooks reference —
69
+ * see the Step 0 note on DX-2954), so an open `bash` row is closed by the
70
+ * dispatch's own terminal write, never by inferring an end from transcript
71
+ * lines.
70
72
  */
71
73
  export declare const ACTIVITY_KINDS: readonly ["agent", "bash"];
72
74
  export type ActivityKind = (typeof ACTIVITY_KINDS)[number];
@@ -76,12 +78,13 @@ export type ActivityKind = (typeof ACTIVITY_KINDS)[number];
76
78
  * fires twice, or a batch resent after a failed flush, must not duplicate it.
77
79
  *
78
80
  * `activityId` for a sub-agent is its transcript file's basename
79
- * (`agent-<hash>`) — the SAME value the ledger credits its tokens under as
81
+ * (`agent-<agent_id>`) — the SAME value the ledger credits its tokens under as
80
82
  * `source`, which is how per-sub-agent tokens join to the running set without
81
- * this table carrying a token column. Any future producer (DX-3284's hooks)
82
- * must derive it the same way — the basename of the hook's `transcript_path`,
83
- * never the hook's `agent_id` — or it upserts a duplicate row. For a
84
- * background script it is the Bash call's `tool_use_id`.
83
+ * this table carrying a token column. A hook producer builds it from the hook's
84
+ * `agent_id` as `agent-${agent_id}` (never the bare `agent_id`, and never from
85
+ * `transcript_path`, which on these events is the MAIN session's transcript) or
86
+ * it upserts a duplicate row. For a background script it is the Bash call's
87
+ * `tool_use_id`.
85
88
  */
86
89
  export interface ActivityChange {
87
90
  kind: ActivityKind;
@@ -9,12 +9,14 @@ export const STATS_BATCH_CAP = 500;
9
9
  * DX-2954 — the running set's two kinds. `agent` is a sub-agent, produced from
10
10
  * the TRANSCRIPT: one row per sub-agent transcript file the session-log watcher
11
11
  * discovers (`packages/danx-session-telemetry/src/activity-observer.ts`; orchestrator decision, DX-2954
12
- * comment 8004). `bash` is a background script; nothing produces it yet — the
13
- * hook-side producer (`PostToolUse` on a backgrounded Bash call) is DX-3284's.
14
- * No hook event observes a background shell FINISHING (verified against the
15
- * hooks reference — see the Step 0 note on DX-2954), so an open row of either
16
- * kind is closed by the dispatch's own terminal write, never by inferring an
17
- * end from transcript lines.
12
+ * comment 8004), and — for an operator session — from the plugin's
13
+ * `SubagentStart` / `SubagentStop` hooks, which add the finish. `bash` is a
14
+ * background script, produced only by the plugin's `PostToolUse` hook on a
15
+ * backgrounded Bash call (DX-3284; the transcript cannot see it). No hook event
16
+ * observes a background shell FINISHING (verified against the hooks reference —
17
+ * see the Step 0 note on DX-2954), so an open `bash` row is closed by the
18
+ * dispatch's own terminal write, never by inferring an end from transcript
19
+ * lines.
18
20
  */
19
21
  export const ACTIVITY_KINDS = ["agent", "bash"];
20
22
  export function chunkEntries(entries, cap = STATS_BATCH_CAP) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thehammer/danx-session-telemetry",
3
- "version": "0.1.17",
3
+ "version": "0.1.19",
4
4
  "description": "Shared Claude Code transcript collector (DX-2962) — incremental JSONL tailing for the danxbot worker and the danx-dashboard-mcp desktop bridge, so both run identical collector code.",
5
5
  "license": "MIT",
6
6
  "type": "module",