@galaxy-stack/blackhole-cli 2.3.0 → 3.0.0

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.
Files changed (164) hide show
  1. package/README.md +78 -47
  2. package/dist/application.d.ts.map +1 -1
  3. package/dist/application.js +23 -2
  4. package/dist/application.js.map +1 -1
  5. package/dist/authorization.d.ts +22 -0
  6. package/dist/authorization.d.ts.map +1 -0
  7. package/dist/authorization.js +42 -0
  8. package/dist/authorization.js.map +1 -0
  9. package/dist/cli-meta.d.ts +8 -0
  10. package/dist/cli-meta.d.ts.map +1 -1
  11. package/dist/cli-meta.js +11 -0
  12. package/dist/cli-meta.js.map +1 -1
  13. package/dist/cli.js +51 -27
  14. package/dist/cli.js.map +1 -1
  15. package/dist/config-command.d.ts +11 -14
  16. package/dist/config-command.d.ts.map +1 -1
  17. package/dist/config-command.js +41 -118
  18. package/dist/config-command.js.map +1 -1
  19. package/dist/doctor.d.ts +8 -2
  20. package/dist/doctor.d.ts.map +1 -1
  21. package/dist/doctor.js +11 -15
  22. package/dist/doctor.js.map +1 -1
  23. package/dist/file-index.d.ts +50 -0
  24. package/dist/file-index.d.ts.map +1 -1
  25. package/dist/file-index.js +124 -0
  26. package/dist/file-index.js.map +1 -1
  27. package/dist/harness/boot.d.ts +87 -0
  28. package/dist/harness/boot.d.ts.map +1 -0
  29. package/dist/harness/boot.js +111 -0
  30. package/dist/harness/boot.js.map +1 -0
  31. package/dist/harness/catalogs.d.ts +50 -0
  32. package/dist/harness/catalogs.d.ts.map +1 -0
  33. package/dist/harness/catalogs.js +34 -0
  34. package/dist/harness/catalogs.js.map +1 -0
  35. package/dist/harness/chat.d.ts +90 -0
  36. package/dist/harness/chat.d.ts.map +1 -0
  37. package/dist/harness/chat.js +260 -0
  38. package/dist/harness/chat.js.map +1 -0
  39. package/dist/harness/client.d.ts +72 -0
  40. package/dist/harness/client.d.ts.map +1 -0
  41. package/dist/harness/client.js +173 -0
  42. package/dist/harness/client.js.map +1 -0
  43. package/dist/harness/command.d.ts +22 -0
  44. package/dist/harness/command.d.ts.map +1 -0
  45. package/dist/harness/command.js +142 -0
  46. package/dist/harness/command.js.map +1 -0
  47. package/dist/harness/composer.d.ts +46 -0
  48. package/dist/harness/composer.d.ts.map +1 -0
  49. package/dist/harness/composer.js +127 -0
  50. package/dist/harness/composer.js.map +1 -0
  51. package/dist/harness/conversation.d.ts +75 -0
  52. package/dist/harness/conversation.d.ts.map +1 -0
  53. package/dist/harness/conversation.js +196 -0
  54. package/dist/harness/conversation.js.map +1 -0
  55. package/dist/harness/help.d.ts +56 -0
  56. package/dist/harness/help.d.ts.map +1 -0
  57. package/dist/harness/help.js +85 -0
  58. package/dist/harness/help.js.map +1 -0
  59. package/dist/harness/history.d.ts +108 -0
  60. package/dist/harness/history.d.ts.map +1 -0
  61. package/dist/harness/history.js +268 -0
  62. package/dist/harness/history.js.map +1 -0
  63. package/dist/harness/labels.d.ts +164 -0
  64. package/dist/harness/labels.d.ts.map +1 -0
  65. package/dist/harness/labels.js +271 -0
  66. package/dist/harness/labels.js.map +1 -0
  67. package/dist/harness/locate.d.ts +24 -0
  68. package/dist/harness/locate.d.ts.map +1 -0
  69. package/dist/harness/locate.js +69 -0
  70. package/dist/harness/locate.js.map +1 -0
  71. package/dist/harness/menus.d.ts +74 -0
  72. package/dist/harness/menus.d.ts.map +1 -0
  73. package/dist/harness/menus.js +140 -0
  74. package/dist/harness/menus.js.map +1 -0
  75. package/dist/harness/model-name.d.ts +73 -0
  76. package/dist/harness/model-name.d.ts.map +1 -0
  77. package/dist/harness/model-name.js +101 -0
  78. package/dist/harness/model-name.js.map +1 -0
  79. package/dist/harness/parts.d.ts +239 -0
  80. package/dist/harness/parts.d.ts.map +1 -0
  81. package/dist/harness/parts.js +266 -0
  82. package/dist/harness/parts.js.map +1 -0
  83. package/dist/harness/preset.d.ts +124 -0
  84. package/dist/harness/preset.d.ts.map +1 -0
  85. package/dist/harness/preset.js +197 -0
  86. package/dist/harness/preset.js.map +1 -0
  87. package/dist/harness/process.d.ts +55 -0
  88. package/dist/harness/process.d.ts.map +1 -0
  89. package/dist/harness/process.js +119 -0
  90. package/dist/harness/process.js.map +1 -0
  91. package/dist/harness/screen.d.ts +33 -0
  92. package/dist/harness/screen.d.ts.map +1 -0
  93. package/dist/harness/screen.js +1070 -0
  94. package/dist/harness/screen.js.map +1 -0
  95. package/dist/harness/sessions.d.ts +55 -0
  96. package/dist/harness/sessions.d.ts.map +1 -0
  97. package/dist/harness/sessions.js +92 -0
  98. package/dist/harness/sessions.js.map +1 -0
  99. package/dist/harness/skills.d.ts +90 -0
  100. package/dist/harness/skills.d.ts.map +1 -0
  101. package/dist/harness/skills.js +133 -0
  102. package/dist/harness/skills.js.map +1 -0
  103. package/dist/harness/slash-palette.d.ts +32 -0
  104. package/dist/harness/slash-palette.d.ts.map +1 -0
  105. package/dist/harness/slash-palette.js +48 -0
  106. package/dist/harness/slash-palette.js.map +1 -0
  107. package/dist/harness/slash.d.ts +113 -0
  108. package/dist/harness/slash.d.ts.map +1 -0
  109. package/dist/harness/slash.js +187 -0
  110. package/dist/harness/slash.js.map +1 -0
  111. package/dist/harness/trajectory.d.ts +74 -0
  112. package/dist/harness/trajectory.d.ts.map +1 -0
  113. package/dist/harness/trajectory.js +270 -0
  114. package/dist/harness/trajectory.js.map +1 -0
  115. package/dist/harness/tui.d.ts +28 -0
  116. package/dist/harness/tui.d.ts.map +1 -0
  117. package/dist/harness/tui.js +143 -0
  118. package/dist/harness/tui.js.map +1 -0
  119. package/dist/manual-config.d.ts +23 -10
  120. package/dist/manual-config.d.ts.map +1 -1
  121. package/dist/manual-config.js +45 -37
  122. package/dist/manual-config.js.map +1 -1
  123. package/dist/migrate.d.ts +32 -0
  124. package/dist/migrate.d.ts.map +1 -0
  125. package/dist/migrate.js +155 -0
  126. package/dist/migrate.js.map +1 -0
  127. package/dist/options.d.ts +10 -1
  128. package/dist/options.d.ts.map +1 -1
  129. package/dist/options.js +23 -4
  130. package/dist/options.js.map +1 -1
  131. package/dist/setup.d.ts +14 -10
  132. package/dist/setup.d.ts.map +1 -1
  133. package/dist/setup.js +25 -92
  134. package/dist/setup.js.map +1 -1
  135. package/dist/timeline.d.ts.map +1 -1
  136. package/dist/timeline.js +11 -0
  137. package/dist/timeline.js.map +1 -1
  138. package/dist/web/command.d.ts +5 -1
  139. package/dist/web/command.d.ts.map +1 -1
  140. package/dist/web/command.js +22 -6
  141. package/dist/web/command.js.map +1 -1
  142. package/dist/web/credentials.d.ts +7 -5
  143. package/dist/web/credentials.d.ts.map +1 -1
  144. package/dist/web/credentials.js +13 -48
  145. package/dist/web/credentials.js.map +1 -1
  146. package/dist/web/doctor.d.ts +1 -1
  147. package/dist/web/doctor.d.ts.map +1 -1
  148. package/dist/web/doctor.js +42 -64
  149. package/dist/web/doctor.js.map +1 -1
  150. package/dist/web/options.d.ts +26 -2
  151. package/dist/web/options.d.ts.map +1 -1
  152. package/dist/web/options.js +54 -18
  153. package/dist/web/options.js.map +1 -1
  154. package/dist/web/paths.d.ts +1 -1
  155. package/dist/web/paths.d.ts.map +1 -1
  156. package/dist/web/paths.js +2 -2
  157. package/dist/web/paths.js.map +1 -1
  158. package/dist/web/web.d.ts +38 -16
  159. package/dist/web/web.d.ts.map +1 -1
  160. package/dist/web/web.js +166 -168
  161. package/dist/web/web.js.map +1 -1
  162. package/package.json +5 -4
  163. package/web/brand/lib/client.js +4 -4
  164. package/web/patches/gbh-ui.patch.yml +6 -24
@@ -0,0 +1,113 @@
1
+ /**
2
+ * The `/` palette: what the terminal offers before a line reaches the model.
3
+ *
4
+ * Two sources, one list. The commands the terminal answers itself come from
5
+ * `help.ts` — the table the help panel draws, so the two can never disagree —
6
+ * and the skills come from the session's own catalogue (`skills.ts`), because a
7
+ * skill exists only while the Agent's preset mounts it. Commands come first: they
8
+ * are what the terminal can answer without a turn, and a skill row that shadows
9
+ * one (`/help`) would be a trap.
10
+ *
11
+ * A query ranks by how the name matches, not by where the row happens to sit:
12
+ * an exact name beats a prefix, a prefix beats a word inside the name, a word
13
+ * beats a gap-toothed subsequence, and anything that only appears in the
14
+ * description comes last. Equal matches keep their source order, so the list is
15
+ * stable while the user types.
16
+ */
17
+ import { type LocalCommand } from "./help.js";
18
+ import { type SkillSummary } from "./skills.js";
19
+ /** The character that opens the palette. */
20
+ export declare const SLASH_TRIGGER = "/";
21
+ /** Where a palette row comes from. */
22
+ export type SlashKind = "command" | "skill";
23
+ /** One selectable row of the `/` popup. */
24
+ export interface SlashEntry {
25
+ /** The word after the slash: `mode`, `office-docx`. */
26
+ readonly value: string;
27
+ /** The row's left column, slash included: `/mode`. */
28
+ readonly label: string;
29
+ /** One short sentence: what running it does. */
30
+ readonly description: string;
31
+ /** Commands are answered by the terminal; skills are work for the Agent. */
32
+ readonly kind: SlashKind;
33
+ }
34
+ /** What the palette is built from. */
35
+ export interface SlashSources {
36
+ /** Commands to offer; defaults to the help table plus {@link EXTRA_COMMANDS}. */
37
+ readonly commands?: readonly LocalCommand[];
38
+ /** Skills of the session in view; omitted while the catalogue is still loading. */
39
+ readonly skills?: readonly SkillSummary[];
40
+ }
41
+ /**
42
+ * Commands this terminal answers that the help table does not carry yet.
43
+ * `/mode` is the picker's keyboard-free door: the same list Ctrl+P opens.
44
+ */
45
+ export declare const EXTRA_COMMANDS: readonly LocalCommand[];
46
+ /**
47
+ * Build the list the palette draws.
48
+ * @param sources - extra commands and the session's skills; both optional.
49
+ * @returns frozen rows: the terminal's commands in table order, then the skills.
50
+ */
51
+ export declare function slashEntries(sources?: SlashSources): readonly SlashEntry[];
52
+ /** The palette's reading of the composer. */
53
+ export interface SlashQueryState {
54
+ /** True while the open line is a bare `/word` the popup should follow. */
55
+ readonly active: boolean;
56
+ /** What the user typed after the slash, lowercased, without spaces. */
57
+ readonly query: string;
58
+ }
59
+ /**
60
+ * Read the composer as a palette query.
61
+ *
62
+ * The popup follows one bare word: `/mode` is a query, `/mode ptc` is an argument
63
+ * the user is typing, and a value that already holds a newline is a paragraph.
64
+ * @param text - the composer's whole value.
65
+ * @returns whether the popup applies, and the needle to match.
66
+ */
67
+ export declare function slashQuery(text: string): SlashQueryState;
68
+ /**
69
+ * Rank the rows that answer a query.
70
+ * @param entries - rows from {@link slashEntries}.
71
+ * @param query - the needle, as {@link slashQuery} read it.
72
+ * @returns matching rows, best first; commands win ties, shorter names next, source order last.
73
+ */
74
+ export declare function filterSlash(entries: readonly SlashEntry[], query: string): readonly SlashEntry[];
75
+ /**
76
+ * The popup's whole answer for one composer value.
77
+ * @param text - the composer's value.
78
+ * @param sources - commands and skills to offer.
79
+ * @returns the query state and its ranked rows; empty when the popup is closed.
80
+ */
81
+ export declare function slashMatches(text: string, sources?: SlashSources): {
82
+ readonly state: SlashQueryState;
83
+ readonly rows: readonly SlashEntry[];
84
+ };
85
+ /**
86
+ * Wrap a selection index into the list.
87
+ * @param index - any integer.
88
+ * @param count - how many rows the popup has.
89
+ * @returns an index in `[0, count)`, or 0 for an empty list.
90
+ */
91
+ export declare function clampSlash(index: number, count: number): number;
92
+ /**
93
+ * Move the selection by one keypress, wrapping at both ends.
94
+ * @param index - the row selected now.
95
+ * @param delta - +1 for ↓, -1 for ↑.
96
+ * @param count - how many rows the popup has.
97
+ * @returns the next row to highlight.
98
+ */
99
+ export declare function moveSlash(index: number, delta: number, count: number): number;
100
+ /**
101
+ * Where a row sits after the list changed, so a refresh keeps the selection still.
102
+ * @param entries - the new rows.
103
+ * @param value - the row's `value` that was selected.
104
+ * @returns its index, or 0 when it is gone.
105
+ */
106
+ export declare function slashIndex(entries: readonly SlashEntry[], value: string | undefined): number;
107
+ /**
108
+ * The line that runs one row.
109
+ * @param entry - the selected row.
110
+ * @returns `/mode`, or the `/skill-name` the composer would send.
111
+ */
112
+ export declare function slashLine(entry: SlashEntry): string;
113
+ //# sourceMappingURL=slash.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slash.d.ts","sourceRoot":"","sources":["../../src/harness/slash.ts"],"names":[],"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AK,EAAE,MAAM,GAAG,SAAS,UAAU,EAAE,CAiBhG;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,YAAiB,GAAG;IAAE,QAAQ,CAAC,KAAK,EAAE,eAAe,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,SAAS,UAAU,EAAE,CAAA;CAAE,CAIhJ;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAI/D;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAE7E;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,SAAS,UAAU,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAI5F;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAEnD"}
@@ -0,0 +1,187 @@
1
+ /**
2
+ * The `/` palette: what the terminal offers before a line reaches the model.
3
+ *
4
+ * Two sources, one list. The commands the terminal answers itself come from
5
+ * `help.ts` — the table the help panel draws, so the two can never disagree —
6
+ * and the skills come from the session's own catalogue (`skills.ts`), because a
7
+ * skill exists only while the Agent's preset mounts it. Commands come first: they
8
+ * are what the terminal can answer without a turn, and a skill row that shadows
9
+ * one (`/help`) would be a trap.
10
+ *
11
+ * A query ranks by how the name matches, not by where the row happens to sit:
12
+ * an exact name beats a prefix, a prefix beats a word inside the name, a word
13
+ * beats a gap-toothed subsequence, and anything that only appears in the
14
+ * description comes last. Equal matches keep their source order, so the list is
15
+ * stable while the user types.
16
+ */
17
+ import { LOCAL_COMMANDS } from "./help.js";
18
+ import { skillLine } from "./skills.js";
19
+ /** The character that opens the palette. */
20
+ export const SLASH_TRIGGER = "/";
21
+ /**
22
+ * Commands this terminal answers that the help table does not carry yet.
23
+ * `/mode` is the picker's keyboard-free door: the same list Ctrl+P opens.
24
+ */
25
+ export const EXTRA_COMMANDS = Object.freeze([
26
+ Object.freeze({ name: "mode", summary: "Chọn chế độ agent: Standard / PTC / Tối giản / Creator" }),
27
+ ]);
28
+ /** Commands first, then skills; a name is offered once. */
29
+ function entryOrder(kind) {
30
+ return kind === "command" ? 0 : 1;
31
+ }
32
+ /**
33
+ * Build the list the palette draws.
34
+ * @param sources - extra commands and the session's skills; both optional.
35
+ * @returns frozen rows: the terminal's commands in table order, then the skills.
36
+ */
37
+ export function slashEntries(sources = {}) {
38
+ const commands = [...(sources.commands ?? LOCAL_COMMANDS), ...EXTRA_COMMANDS];
39
+ const seen = new Set();
40
+ const entries = [];
41
+ const push = (entry) => {
42
+ if (entry.value.length === 0 || seen.has(entry.value))
43
+ return;
44
+ seen.add(entry.value);
45
+ entries.push(Object.freeze(entry));
46
+ };
47
+ for (const command of commands)
48
+ push({ value: command.name, label: SLASH_TRIGGER + command.name, description: command.summary, kind: "command" });
49
+ for (const skill of sources.skills ?? [])
50
+ push({ value: skill.name, label: SLASH_TRIGGER + skill.name, description: skillLine(skill), kind: "skill" });
51
+ return Object.freeze(entries);
52
+ }
53
+ /**
54
+ * Read the composer as a palette query.
55
+ *
56
+ * The popup follows one bare word: `/mode` is a query, `/mode ptc` is an argument
57
+ * the user is typing, and a value that already holds a newline is a paragraph.
58
+ * @param text - the composer's whole value.
59
+ * @returns whether the popup applies, and the needle to match.
60
+ */
61
+ export function slashQuery(text) {
62
+ // One line, no spaces: a value that already holds a newline is a paragraph the user is writing,
63
+ // and a value with a space is an argument in progress. Both close the popup.
64
+ if (!text.startsWith(SLASH_TRIGGER) || /\s/u.test(text))
65
+ return { active: false, query: "" };
66
+ return { active: true, query: text.slice(SLASH_TRIGGER.length).toLowerCase() };
67
+ }
68
+ /** Match tiers, smallest first; the number is only ever compared. */
69
+ const SCORE_ANY = 0;
70
+ const SCORE_EXACT = 1;
71
+ const SCORE_PREFIX = 2;
72
+ const SCORE_WORD = 3;
73
+ const SCORE_CONTAINS = 4;
74
+ const SCORE_SUBSEQUENCE = 5;
75
+ const SCORE_DESCRIPTION = 6;
76
+ const NO_MATCH = Number.POSITIVE_INFINITY;
77
+ /** Word separators a kebab-case skill name uses. */
78
+ const WORD_BREAK = /[-_.\s/]+/u;
79
+ /** True when every character of the needle appears in order. */
80
+ function subsequence(haystack, needle) {
81
+ let index = 0;
82
+ for (const character of haystack) {
83
+ if (character === needle[index])
84
+ index += 1;
85
+ if (index === needle.length)
86
+ return true;
87
+ }
88
+ return needle.length === 0;
89
+ }
90
+ /** How well one row answers the needle; larger is worse. */
91
+ function scoreOf(entry, needle) {
92
+ if (needle.length === 0)
93
+ return SCORE_ANY;
94
+ const name = entry.value.toLowerCase();
95
+ if (name === needle)
96
+ return SCORE_EXACT;
97
+ if (name.startsWith(needle))
98
+ return SCORE_PREFIX;
99
+ if (name.split(WORD_BREAK).some(word => word.startsWith(needle)))
100
+ return SCORE_WORD;
101
+ if (name.includes(needle))
102
+ return SCORE_CONTAINS;
103
+ if (subsequence(name, needle))
104
+ return SCORE_SUBSEQUENCE;
105
+ if (entry.description.toLowerCase().includes(needle))
106
+ return SCORE_DESCRIPTION;
107
+ return NO_MATCH;
108
+ }
109
+ /**
110
+ * Rank the rows that answer a query.
111
+ * @param entries - rows from {@link slashEntries}.
112
+ * @param query - the needle, as {@link slashQuery} read it.
113
+ * @returns matching rows, best first; commands win ties, shorter names next, source order last.
114
+ */
115
+ export function filterSlash(entries, query) {
116
+ const needle = query.trim().toLowerCase();
117
+ const scored = [];
118
+ for (const [position, entry] of entries.entries()) {
119
+ const score = scoreOf(entry, needle);
120
+ if (score === NO_MATCH)
121
+ continue;
122
+ scored.push({ entry, score, position });
123
+ }
124
+ // A longer name is a weaker answer to a short needle: "/mod" puts /mode above /model.
125
+ // An empty needle is not a match at all, so it keeps the table's own order.
126
+ const byLength = (left, right) => needle.length === 0 ? 0 : left.entry.value.length - right.entry.value.length;
127
+ scored.sort((left, right) => left.score - right.score
128
+ || entryOrder(left.entry.kind) - entryOrder(right.entry.kind)
129
+ || byLength(left, right)
130
+ || left.position - right.position);
131
+ return Object.freeze(scored.map(item => item.entry));
132
+ }
133
+ /**
134
+ * The popup's whole answer for one composer value.
135
+ * @param text - the composer's value.
136
+ * @param sources - commands and skills to offer.
137
+ * @returns the query state and its ranked rows; empty when the popup is closed.
138
+ */
139
+ export function slashMatches(text, sources = {}) {
140
+ const state = slashQuery(text);
141
+ if (!state.active)
142
+ return { state, rows: Object.freeze([]) };
143
+ return { state, rows: filterSlash(slashEntries(sources), state.query) };
144
+ }
145
+ /**
146
+ * Wrap a selection index into the list.
147
+ * @param index - any integer.
148
+ * @param count - how many rows the popup has.
149
+ * @returns an index in `[0, count)`, or 0 for an empty list.
150
+ */
151
+ export function clampSlash(index, count) {
152
+ if (count <= 0)
153
+ return 0;
154
+ const bounded = index % count;
155
+ return bounded < 0 ? bounded + count : bounded;
156
+ }
157
+ /**
158
+ * Move the selection by one keypress, wrapping at both ends.
159
+ * @param index - the row selected now.
160
+ * @param delta - +1 for ↓, -1 for ↑.
161
+ * @param count - how many rows the popup has.
162
+ * @returns the next row to highlight.
163
+ */
164
+ export function moveSlash(index, delta, count) {
165
+ return clampSlash(clampSlash(index, count) + delta, count);
166
+ }
167
+ /**
168
+ * Where a row sits after the list changed, so a refresh keeps the selection still.
169
+ * @param entries - the new rows.
170
+ * @param value - the row's `value` that was selected.
171
+ * @returns its index, or 0 when it is gone.
172
+ */
173
+ export function slashIndex(entries, value) {
174
+ if (value === undefined)
175
+ return 0;
176
+ const index = entries.findIndex(entry => entry.value === value);
177
+ return index < 0 ? 0 : index;
178
+ }
179
+ /**
180
+ * The line that runs one row.
181
+ * @param entry - the selected row.
182
+ * @returns `/mode`, or the `/skill-name` the composer would send.
183
+ */
184
+ export function slashLine(entry) {
185
+ return SLASH_TRIGGER + entry.value;
186
+ }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1,74 @@
1
+ /**
2
+ * "Luồng chạy": the harness's own session ledger, not a summary of our turns.
3
+ *
4
+ * The web app builds this tab from the durable events of the Session — one row per
5
+ * turn boundary, prompt, assistant message, tool call and context change — so the
6
+ * terminal must read the same log instead of inventing rows from its own turn list.
7
+ * `session/follow` opens with the newest message-aligned snapshot; when that page
8
+ * leaves older history behind, `session.page` walks backwards from the snapshot's
9
+ * cursor (`throughSeq` + `beforeSeq`), which is the one RPC that reads history
10
+ * without activating an Agent (verified against the host descriptor).
11
+ *
12
+ * Rows stay one line each: the panel owns width, this module owns facts.
13
+ */
14
+ import type { FollowRecord, HarnessClient } from "./client.js";
15
+ import { type ModelNames } from "./model-name.js";
16
+ /** The four words the ledger's "Loại" column uses. */
17
+ export type TrajectoryKind = "system" | "user" | "assistant" | "tool";
18
+ /** The Vietnamese label of each kind, as the table prints it. */
19
+ export declare const TRAJECTORY_KIND_LABEL: Readonly<Record<TrajectoryKind, string>>;
20
+ /** One row of the ledger. */
21
+ export interface TrajectoryEvent {
22
+ /** Durable sequence the row was read from; two rows can share one (a tool and its result). */
23
+ readonly seq: number;
24
+ readonly kind: TrajectoryKind;
25
+ /** Short one-line content: the prompt, the prose, the call, the change. */
26
+ readonly text: string;
27
+ /** Event time, epoch milliseconds. */
28
+ readonly time: number;
29
+ /** How long the step took, when the log measures it. */
30
+ readonly durationMs?: number;
31
+ /** Tokens the model reported for this step. */
32
+ readonly tokens?: number;
33
+ /** Tool outcome, once its result is in the log. */
34
+ readonly ok?: boolean;
35
+ }
36
+ /** A page budget and how many older pages are worth walking. */
37
+ export interface TrajectoryOptions {
38
+ /** Messages per page; the follow snapshot and every `session.page` use it. */
39
+ readonly maxMessages?: number;
40
+ /** Older pages to load after the snapshot; 0 reads only the snapshot. */
41
+ readonly pages?: number;
42
+ /** Display names for the model routes the ledger prints. */
43
+ readonly names?: ModelNames;
44
+ }
45
+ /** What one read of the ledger returns. */
46
+ export interface TrajectoryPage {
47
+ readonly rows: readonly TrajectoryEvent[];
48
+ /** True when older history exists beyond the rows returned. */
49
+ readonly hasMore: boolean;
50
+ /** The session cursor the log ended at, when the host reported one. */
51
+ readonly cursor?: number;
52
+ }
53
+ /**
54
+ * Fold durable events into ledger rows.
55
+ *
56
+ * A tool call and its result share one row: the call names the work, the result
57
+ * supplies the outcome and the duration, so the table reads like the app's own
58
+ * trajectory instead of a protocol dump. Plumbing events (job registration, stream
59
+ * internals, seed markers) never become rows.
60
+ * @param records - durable events in sequence order.
61
+ * @param names - display names for the route the model row prints.
62
+ * @returns one row per fact the panel can show.
63
+ */
64
+ export declare function trajectoryEvents(records: readonly FollowRecord[], names?: ModelNames): readonly TrajectoryEvent[];
65
+ /**
66
+ * Read one session's ledger: the follow snapshot, then older pages while they exist.
67
+ * @param client - the authenticated harness connection.
68
+ * @param sessionId - the session whose log is read.
69
+ * @param signal - caller cancellation.
70
+ * @param options - page budget and how many older pages to walk.
71
+ * @returns the rows, whether older history remains, and the cursor they end at.
72
+ */
73
+ export declare function loadTrajectory(client: HarnessClient, sessionId: string, signal: AbortSignal, options?: TrajectoryOptions): Promise<TrajectoryPage>;
74
+ //# sourceMappingURL=trajectory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trajectory.d.ts","sourceRoot":"","sources":["../../src/harness/trajectory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE/D,OAAO,EAAuC,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAEvF,sDAAsD;AACtD,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,MAAM,GAAG,WAAW,GAAG,MAAM,CAAC;AAEtE,iEAAiE;AACjE,eAAO,MAAM,qBAAqB,EAAE,QAAQ,CAAC,MAAM,CAAC,cAAc,EAAE,MAAM,CAAC,CAKzE,CAAC;AAEH,6BAA6B;AAC7B,MAAM,WAAW,eAAe;IAC9B,8FAA8F;IAC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"./labels.js";
2
+ import { DEFAULT_MODEL_NAMES, modelRouteName } from "./model-name.js";
3
+ /** The Vietnamese label of each kind, as the table prints it. */
4
+ export const TRAJECTORY_KIND_LABEL = Object.freeze({
5
+ system: "Hệ thống",
6
+ user: "Người dùng",
7
+ assistant: "Trợ lý",
8
+ tool: "Công cụ",
9
+ });
10
+ function record(value) {
11
+ return typeof value === "object" && value !== null && !Array.isArray(value) ? value : undefined;
12
+ }
13
+ function text(value) {
14
+ return typeof value === "string" && value.length > 0 ? value : undefined;
15
+ }
16
+ function number(value) {
17
+ return typeof value === "number" && Number.isFinite(value) ? value : undefined;
18
+ }
19
+ /** One message's visible text blocks, joined. */
20
+ function messageText(value) {
21
+ const content = record(value)?.["content"];
22
+ if (!Array.isArray(content))
23
+ return typeof content === "string" ? content : "";
24
+ return content.map(part => {
25
+ const block = record(part);
26
+ return block?.["type"] === "text" ? text(block["text"]) ?? "" : "";
27
+ }).join("");
28
+ }
29
+ /** One message's reasoning blocks, joined; a step that only thought still gets a row. */
30
+ function messageReasoning(value) {
31
+ const content = record(value)?.["content"];
32
+ if (!Array.isArray(content))
33
+ return "";
34
+ return content.map(part => {
35
+ const block = record(part);
36
+ return block?.["type"] === "reasoning" ? text(block["text"]) ?? "" : "";
37
+ }).join("");
38
+ }
39
+ /** Tool arguments arrive as a JSON string and are parsed for the row's label. */
40
+ function toolArguments(value) {
41
+ if (typeof value === "string") {
42
+ try {
43
+ const parsed = JSON.parse(value);
44
+ return record(parsed) ?? { raw: value };
45
+ }
46
+ catch {
47
+ return { raw: value };
48
+ }
49
+ }
50
+ return record(value) ?? {};
51
+ }
52
+ /** Collapse whitespace so one row stays one row. */
53
+ function oneLine(value, limit = 400) {
54
+ const flat = value.replace(/\s+/gu, " ").trim();
55
+ return flat.length > limit ? flat.slice(0, limit - 1) + "…" : flat;
56
+ }
57
+ /** The Vietnamese word for a turn's end reason. */
58
+ function endReason(value) {
59
+ const reason = record(value);
60
+ const kind = text(reason?.["kind"]) ?? "completed";
61
+ const failure = text(record(reason?.["error"])?.["message"]);
62
+ const words = { completed: "hoàn thành", aborted: "đã dừng", error: "có lỗi", failed: "thất bại" };
63
+ return words[kind] ?? kind + (failure === undefined ? "" : " · " + failure);
64
+ }
65
+ /**
66
+ * Fold durable events into ledger rows.
67
+ *
68
+ * A tool call and its result share one row: the call names the work, the result
69
+ * supplies the outcome and the duration, so the table reads like the app's own
70
+ * trajectory instead of a protocol dump. Plumbing events (job registration, stream
71
+ * internals, seed markers) never become rows.
72
+ * @param records - durable events in sequence order.
73
+ * @param names - display names for the route the model row prints.
74
+ * @returns one row per fact the panel can show.
75
+ */
76
+ export function trajectoryEvents(records, names = DEFAULT_MODEL_NAMES) {
77
+ const rows = [];
78
+ const toolRows = new Map();
79
+ let turnStartedAt;
80
+ let stepStartedAt;
81
+ for (const item of records) {
82
+ const event = item.event;
83
+ const data = record(event.data);
84
+ if (event.type === "turn/start") {
85
+ turnStartedAt = event.time;
86
+ rows.push({ seq: event.seq, kind: "system", text: "Lượt " + String(number(data?.["turn"]) ?? 1) + " bắt đầu", time: event.time });
87
+ continue;
88
+ }
89
+ if (event.type === "turn/end") {
90
+ const duration = turnStartedAt === undefined ? undefined : Math.max(0, event.time - turnStartedAt);
91
+ rows.push({
92
+ seq: event.seq,
93
+ kind: "system",
94
+ text: "Kết thúc lượt · " + endReason(data?.["reason"]),
95
+ time: event.time,
96
+ ...(duration === undefined ? {} : { durationMs: duration }),
97
+ });
98
+ turnStartedAt = undefined;
99
+ continue;
100
+ }
101
+ if (event.type === "step/start") {
102
+ stepStartedAt = event.time;
103
+ continue;
104
+ }
105
+ if (event.type === "user/message") {
106
+ const source = text(record(data?.["source"])?.["kind"]);
107
+ const body = oneLine(messageText(data));
108
+ if (source === "user") {
109
+ if (body.length > 0)
110
+ rows.push({ seq: event.seq, kind: "user", text: body, time: event.time });
111
+ }
112
+ else {
113
+ rows.push({ seq: event.seq, kind: "system", text: "Ngữ cảnh · " + (source ?? "hệ thống") + (body.length === 0 ? "" : " · " + body.slice(0, 120)), time: event.time });
114
+ }
115
+ continue;
116
+ }
117
+ if (event.type === "assistant/message") {
118
+ const message = record(data?.["message"]);
119
+ const prose = oneLine(messageText(message));
120
+ const reasoning = oneLine(messageReasoning(message));
121
+ const body = prose.length > 0 ? prose : reasoning.length > 0 ? "Suy nghĩ · " + reasoning : "";
122
+ const usage = record(data?.["usage"]);
123
+ const input = number(usage?.["inputTokens"]);
124
+ const output = number(usage?.["outputTokens"]);
125
+ const tokens = input === undefined && output === undefined ? undefined : (input ?? 0) + (output ?? 0);
126
+ const duration = stepStartedAt === undefined ? undefined : Math.max(0, event.time - stepStartedAt);
127
+ rows.push({
128
+ seq: event.seq,
129
+ kind: "assistant",
130
+ text: body.length > 0 ? body : "(không có nội dung)",
131
+ time: event.time,
132
+ ...(duration === undefined ? {} : { durationMs: duration }),
133
+ ...(tokens === undefined ? {} : { tokens }),
134
+ });
135
+ continue;
136
+ }
137
+ if (event.type === "tool/call") {
138
+ const callId = text(data?.["callId"]);
139
+ const name = text(data?.["name"]);
140
+ if (callId === undefined || name === undefined)
141
+ continue;
142
+ toolRows.set(callId, rows.length);
143
+ rows.push({ seq: event.seq, kind: "tool", text: oneLine(toolTitle(name, toolArguments(data?.["arguments"])), 200), time: event.time });
144
+ continue;
145
+ }
146
+ if (event.type === "tool/result") {
147
+ const message = record(data?.["message"]);
148
+ const callId = text(message?.["toolCallId"]);
149
+ const index = callId === undefined ? undefined : toolRows.get(callId);
150
+ const row = index === undefined ? undefined : rows[index];
151
+ if (row === undefined || index === undefined)
152
+ continue;
153
+ const summary = oneLine(cleanToolResult(messageText(message)), 160);
154
+ const ok = message?.["isError"] !== true && data?.["error"] === undefined;
155
+ rows[index] = {
156
+ ...row,
157
+ ok,
158
+ durationMs: Math.max(0, event.time - row.time),
159
+ // A failing call says why on its own row; a successful one keeps the call label,
160
+ // because its output is already the transcript's business.
161
+ ...(ok || summary.length === 0 ? {} : { text: row.text + " → " + summary }),
162
+ };
163
+ continue;
164
+ }
165
+ if (event.type === "command/run") {
166
+ const name = text(data?.["name"]);
167
+ const args = text(data?.["args"]);
168
+ if (name === undefined)
169
+ continue;
170
+ rows.push({ seq: event.seq, kind: "system", text: "Lệnh /" + name + (args === undefined ? "" : " " + args), time: event.time });
171
+ continue;
172
+ }
173
+ if (event.type === "permission/preset") {
174
+ rows.push({ seq: event.seq, kind: "system", text: "Chế độ quyền · " + (text(data?.["preset"]) ?? "?"), time: event.time });
175
+ continue;
176
+ }
177
+ if (event.type === "model/selection") {
178
+ const provider = text(data?.["provider"]);
179
+ const model = text(data?.["model"]);
180
+ const effort = text(data?.["reasoningEffort"]);
181
+ // The route reads as the host's own names ("Galaxy Blackhole/Auto"), never as wire ids.
182
+ const route = modelRouteName(provider, model, names);
183
+ rows.push({ seq: event.seq, kind: "system", text: "Model · " + route + (effort === undefined ? "" : " · " + effort), time: event.time });
184
+ continue;
185
+ }
186
+ if (event.type === "agent-preset/selected") {
187
+ rows.push({ seq: event.seq, kind: "system", text: "Preset · " + (text(data?.["agentPreset"]) ?? "?"), time: event.time });
188
+ continue;
189
+ }
190
+ if (event.type === "working-directory/change") {
191
+ rows.push({ seq: event.seq, kind: "system", text: "Workspace · " + (text(data?.["cwd"]) ?? "?"), time: event.time });
192
+ continue;
193
+ }
194
+ if (event.type === "compaction/start") {
195
+ rows.push({ seq: event.seq, kind: "system", text: "Nén ngữ cảnh…", time: event.time });
196
+ continue;
197
+ }
198
+ if (event.type === "compaction/summary") {
199
+ const tokens = number(data?.["shadowedTokenCount"]);
200
+ rows.push({ seq: event.seq, kind: "system", text: "Nén ngữ cảnh xong" + (tokens === undefined ? "" : " · " + String(tokens) + " token cũ"), time: event.time });
201
+ continue;
202
+ }
203
+ if (event.type === "compaction/end") {
204
+ const failure = text(data?.["error"]);
205
+ rows.push({ seq: event.seq, kind: "system", text: failure === undefined ? "Nén ngữ cảnh xong" : "Nén ngữ cảnh lỗi · " + failure, time: event.time });
206
+ continue;
207
+ }
208
+ if (event.type === "approval/asked") {
209
+ rows.push({ seq: event.seq, kind: "system", text: "Chờ phê duyệt · " + (text(data?.["toolName"]) ?? "công cụ"), time: event.time });
210
+ continue;
211
+ }
212
+ if (event.type === "approval/decided") {
213
+ rows.push({ seq: event.seq, kind: "system", text: "Phê duyệt · " + (text(data?.["outcome"]) ?? "?"), time: event.time });
214
+ }
215
+ }
216
+ return Object.freeze(rows);
217
+ }
218
+ /**
219
+ * Read one session's ledger: the follow snapshot, then older pages while they exist.
220
+ * @param client - the authenticated harness connection.
221
+ * @param sessionId - the session whose log is read.
222
+ * @param signal - caller cancellation.
223
+ * @param options - page budget and how many older pages to walk.
224
+ * @returns the rows, whether older history remains, and the cursor they end at.
225
+ */
226
+ export async function loadTrajectory(client, sessionId, signal, options = {}) {
227
+ const maxMessages = Math.max(1, options.maxMessages ?? 120);
228
+ const pages = Math.max(0, options.pages ?? 3);
229
+ const address = { kind: "session", sessionId };
230
+ let records = [];
231
+ let cursor;
232
+ let hasMore = false;
233
+ // The stream must be closed the moment its snapshot is in hand: this read is a page,
234
+ // not a subscription, and an open follow stream keeps the host watching the session.
235
+ const controller = new AbortController();
236
+ try {
237
+ for await (const frame of client.stream("session/follow", { request: { address, maxMessages } }, AbortSignal.any([signal, controller.signal]))) {
238
+ if (frame.type !== "snapshot")
239
+ continue;
240
+ records = [...(frame.records ?? [])];
241
+ cursor = number(frame.cursor);
242
+ hasMore = frame.hasMore === true;
243
+ break;
244
+ }
245
+ }
246
+ finally {
247
+ controller.abort();
248
+ }
249
+ let walked = 0;
250
+ while (hasMore && walked < pages && cursor !== undefined) {
251
+ const firstSeq = records[0]?.event.seq;
252
+ if (firstSeq === undefined || firstSeq <= 0)
253
+ break;
254
+ try {
255
+ const page = await client.call("session.page", { request: { address, throughSeq: cursor, beforeSeq: firstSeq, maxMessages } }, signal);
256
+ const older = page.records ?? [];
257
+ if (older.length === 0)
258
+ break;
259
+ records = [...older, ...records];
260
+ hasMore = page.hasMore === true;
261
+ walked += 1;
262
+ }
263
+ catch {
264
+ // An older page the host refuses must not hide the page already in hand.
265
+ break;
266
+ }
267
+ }
268
+ return Object.freeze({ rows: trajectoryEvents(records, options.names), hasMore, ...(cursor === undefined ? {} : { cursor }) });
269
+ }
270
+ //# sourceMappingURL=trajectory.js.map