@yaklabs-ai/plugin-sdk 0.13.5 → 0.13.7

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.
@@ -1,3 +1,5 @@
1
+ import { z } from 'zod';
2
+
1
3
  /**
2
4
  * The ids on a session's active branch: the leaf chain walked parent-ward from
3
5
  * the tip, which a trailing `leaf` marker moves. Empty for an empty log.
@@ -28,6 +30,31 @@ export declare function customEntriesFromEntries<T extends TranscriptSourceEntry
28
30
  readonly branch: "active" | "all";
29
31
  }): readonly T[];
30
32
 
33
+ export declare function matchesWorkBlock(coverage: WorkBlockCoverage, toolResultEntryIds: readonly string[]): boolean;
34
+
35
+ /**
36
+ * Tool names the transcript draws as their own surface, or lifts into the reply, instead of
37
+ * counting them as work in the closed bar (venue `inline` or `turn-tail`, or the parsed
38
+ * `submit_final`). A call to one of these is not a "visible call". The renderer's built-in tool
39
+ * registrations are the source of truth; its parity test fails when this list drifts from them.
40
+ * A tool a plugin registers with a non-activity venue is not listed, so the daemon may count it
41
+ * (a headline can appear on a turn whose bar shows fewer calls than the cutoff only in that
42
+ * corner, and the renderer re-checks its own count before displaying anything).
43
+ */
44
+ export declare const NON_ACTIVITY_TOOL_NAMES: readonly string[];
45
+
46
+ /**
47
+ * The daemon's own run-start record. A run's entries begin here, before the
48
+ * user message that opened it.
49
+ */
50
+ export declare const RUN_STARTED_CUSTOM_TYPE = "session_run_started";
51
+
52
+ /**
53
+ * The daemon's own terminal run record (completed / interrupted / cancelled /
54
+ * failed). A run's entries end here.
55
+ */
56
+ export declare const RUN_TERMINAL_CUSTOM_TYPE = "session_run_state";
57
+
31
58
  /** The fields the customType selector needs off a session entry. */
32
59
  export declare interface TranscriptEntryLike {
33
60
  readonly id: string;
@@ -57,4 +84,86 @@ declare interface TranscriptTreeEntryLike extends TranscriptEntryLike {
57
84
  readonly targetId?: string | null;
58
85
  }
59
86
 
87
+ /**
88
+ * The fields the turn walk reads. Deliberately narrower and looser than
89
+ * {@link TranscriptEntryLike}: the walk answers in INDEXES, so it never needs an
90
+ * `id`, and both callers hold entries typed by their own layer (herd's
91
+ * `TranscriptEntry`, the daemon's branch rows).
92
+ */
93
+ export declare interface TurnBoundaryEntry {
94
+ readonly type?: string;
95
+ readonly customType?: string;
96
+ /** Opaque here; only `message.role === "user"` is read, defensively. */
97
+ readonly message?: unknown;
98
+ }
99
+
100
+ /** One turn's bounds as {@link turnSegments} reports them, both inclusive. */
101
+ export declare interface TurnSegment {
102
+ /** The user message entry that opened the turn. A steer never opens one. */
103
+ readonly openingIndex: number;
104
+ /**
105
+ * The entry the turn settled on. Equal to `openingIndex` when nothing
106
+ * followed the opening message, which is a turn that never settled rather
107
+ * than a turn with an empty body.
108
+ */
109
+ readonly settleIndex: number;
110
+ }
111
+
112
+ /**
113
+ * THE definition of a turn, shared by every reader that has to agree about one:
114
+ * the settled-turn extractors that key a record to a turn, and the replay
115
+ * publisher that offers a stored session's turns as events. Two readers
116
+ * disagreeing here means a replayed "turn" is not the turn production would
117
+ * have extracted.
118
+ *
119
+ * **A turn is a run.** The daemon brackets every run in the transcript
120
+ * ({@link RUN_STARTED_CUSTOM_TYPE} then, at the end,
121
+ * {@link RUN_TERMINAL_CUSTOM_TYPE}), and the user message that opened the run
122
+ * opens the turn. A human steering or a queued message admitted mid-flight is
123
+ * persisted as another `role: "user"` entry INSIDE that bracket, and belongs to
124
+ * the turn it interrupted: it is a correction to work already under way, not a
125
+ * new request. Anchoring on the last user entry instead hands an extractor the
126
+ * steer as the turn's goal and demotes the real request to prior context.
127
+ *
128
+ * A transcript with no run brackets at all (a log older than run bookkeeping, a
129
+ * hand-built fixture) falls back to one turn per user message, which is the
130
+ * most this function can honestly say: with no record of when a run ended,
131
+ * nothing distinguishes a steer from a fresh request.
132
+ *
133
+ * `throughIndex` bounds the walk for a caller holding only a prefix; segments
134
+ * are returned oldest first.
135
+ */
136
+ export declare function turnSegments(entries: readonly TurnBoundaryEntry[], throughIndex?: number): readonly TurnSegment[];
137
+
138
+ export declare const WORK_HEADLINE_MAX_CHARS = 90;
139
+
140
+ /** The longest and shortest stored work headline, in characters. Shorter is filler; longer is a sentence. */
141
+ export declare const WORK_HEADLINE_MIN_CHARS = 12;
142
+
143
+ /**
144
+ * The fewest VISIBLE tool calls a settled turn needs before it earns a work headline (owner
145
+ * ruling, 2026-10-14: "it shouldn't do that if it ran 2 commands but could be helpful if it ran
146
+ * like 15"; the scope card's 10 was accepted). ONE value, read by the writer (the hindsight
147
+ * `work-headline` handler decides whether to spend a model call) and by the closed work bar's
148
+ * renderer (decides whether to show a stored headline), so the two can never disagree about which
149
+ * turns qualify.
150
+ */
151
+ export declare const WORK_HEADLINE_MIN_VISIBLE_CALLS = 10;
152
+
153
+ export declare type WorkBlockCoverage = z.infer<typeof WorkBlockCoverageSchema>;
154
+
155
+ export declare function workBlockCoverage(toolResultEntryIds: readonly string[]): WorkBlockCoverage | undefined;
156
+
157
+ /**
158
+ * Exact ordered completed executions, addressed by persisted tool-result entry IDs.
159
+ * Provider call IDs can repeat across retries and turns; they are never ownership keys.
160
+ */
161
+ export declare const WorkBlockCoverageSchema: z.ZodObject<{
162
+ firstToolResultEntryId: z.ZodString;
163
+ lastToolResultEntryId: z.ZodString;
164
+ toolResultEntryIds: z.ZodArray<z.ZodString>;
165
+ }, z.core.$strict>;
166
+
167
+ export declare function workBlockKey(coverage: WorkBlockCoverage): string;
168
+
60
169
  export { }
@@ -5,6 +5,22 @@ var WorkBlockCoverageSchema = z.strictObject({
5
5
  lastToolResultEntryId: z.string().min(1),
6
6
  toolResultEntryIds: z.array(z.string().min(1)).min(1).max(4096)
7
7
  }).refine((value) => value.firstToolResultEntryId === value.toolResultEntryIds[0] && value.lastToolResultEntryId === value.toolResultEntryIds.at(-1) && new Set(value.toolResultEntryIds).size === value.toolResultEntryIds.length);
8
+ function workBlockCoverage(toolResultEntryIds) {
9
+ const parsed = WorkBlockCoverageSchema.safeParse({
10
+ firstToolResultEntryId: toolResultEntryIds[0],
11
+ lastToolResultEntryId: toolResultEntryIds.at(-1),
12
+ toolResultEntryIds
13
+ });
14
+ return parsed.success ? parsed.data : void 0;
15
+ }
16
+ function workBlockKey(coverage) {
17
+ return JSON.stringify(coverage.toolResultEntryIds);
18
+ }
19
+ function matchesWorkBlock(coverage, toolResultEntryIds) {
20
+ return coverage.toolResultEntryIds.length === toolResultEntryIds.length && coverage.toolResultEntryIds.every((id, index) => id === toolResultEntryIds[index]);
21
+ }
22
+ var RUN_STARTED_CUSTOM_TYPE = "session_run_started";
23
+ var RUN_TERMINAL_CUSTOM_TYPE = "session_run_state";
8
24
  function branchEntryIds(entries) {
9
25
  const last = entries[entries.length - 1];
10
26
  if (last === void 0)
@@ -19,11 +35,77 @@ function branchEntryIds(entries) {
19
35
  return onBranch;
20
36
  }
21
37
  var EMPTY_BRANCH_IDS = /* @__PURE__ */ new Set();
38
+ function isUserMessageEntry(entry) {
39
+ if (entry.type !== "message")
40
+ return false;
41
+ const message = entry.message;
42
+ return typeof message === "object" && message !== null && message.role === "user";
43
+ }
44
+ function runBoundaryOf(entry) {
45
+ if (entry.type !== "custom")
46
+ return void 0;
47
+ if (entry.customType === RUN_STARTED_CUSTOM_TYPE)
48
+ return "started";
49
+ if (entry.customType === RUN_TERMINAL_CUSTOM_TYPE)
50
+ return "terminal";
51
+ return void 0;
52
+ }
53
+ function turnSegments(entries, throughIndex = entries.length - 1) {
54
+ const segments = [];
55
+ let openingIndex;
56
+ let runOpen = false;
57
+ const close = (settleIndex) => {
58
+ if (openingIndex !== void 0 && settleIndex >= openingIndex) {
59
+ segments.push({ openingIndex, settleIndex });
60
+ }
61
+ openingIndex = void 0;
62
+ };
63
+ for (let index = 0; index <= throughIndex; index += 1) {
64
+ const entry = entries[index];
65
+ if (entry === void 0)
66
+ break;
67
+ const boundary = runBoundaryOf(entry);
68
+ if (boundary !== void 0) {
69
+ close(boundary === "terminal" ? index : index - 1);
70
+ runOpen = boundary === "started";
71
+ continue;
72
+ }
73
+ if (!isUserMessageEntry(entry))
74
+ continue;
75
+ if (runOpen && openingIndex !== void 0)
76
+ continue;
77
+ close(index - 1);
78
+ openingIndex = index;
79
+ }
80
+ close(throughIndex);
81
+ return segments;
82
+ }
22
83
  function customEntriesFromEntries(entries, customType, options) {
23
84
  const onBranch = options.branch === "all" ? null : branchEntryIds(entries);
24
85
  return entries.filter((entry) => entry.type === "custom" && entry.customType === customType && (onBranch === null || onBranch.has(entry.id)));
25
86
  }
87
+ var WORK_HEADLINE_MIN_VISIBLE_CALLS = 10;
88
+ var NON_ACTIVITY_TOOL_NAMES = [
89
+ "agent_spawn",
90
+ "send_message",
91
+ "service_connect",
92
+ "ui_render",
93
+ "submit_final"
94
+ ];
95
+ var WORK_HEADLINE_MIN_CHARS = 12;
96
+ var WORK_HEADLINE_MAX_CHARS = 90;
26
97
  export {
98
+ NON_ACTIVITY_TOOL_NAMES,
99
+ RUN_STARTED_CUSTOM_TYPE,
100
+ RUN_TERMINAL_CUSTOM_TYPE,
101
+ WORK_HEADLINE_MAX_CHARS,
102
+ WORK_HEADLINE_MIN_CHARS,
103
+ WORK_HEADLINE_MIN_VISIBLE_CALLS,
104
+ WorkBlockCoverageSchema,
27
105
  branchEntryIds,
28
- customEntriesFromEntries
106
+ customEntriesFromEntries,
107
+ matchesWorkBlock,
108
+ turnSegments,
109
+ workBlockCoverage,
110
+ workBlockKey
29
111
  };